Text classification method and device, equipment, medium and product

By extracting and calculating the matching words and their influencing parameters in the text, and optimizing the classification results in combination with the preset rule base, the problem of long time consumption and high resources in text classification in the existing technology is solved, and efficient and accurate text in weak context is achieved. Classification.

CN118733776APending Publication Date: 2024-10-01BAIRONG ZHIXIN (BEIJING) TECH CO LTD
View PDF -1 Cites 0 Cited by

Patent Information

Application Number
CN202410870660.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-10-01

Smart Images

  • Figure CN118733776A_ABST
    Figure CN118733776A_ABST
Patent Text Reader

Abstract

The invention provides a text classification method and apparatus, a device, a medium and a product. The method comprises the steps of obtaining a to-be-classified text and a preset classification word library; in the to-be-classified text, extracting words contained in the preset classification word bank as matched words; obtaining at least one classification identifier and a total influence parameter value corresponding to the at least one classification identifier according to the matched word, the classification identifier of the matched word and the classification influence parameter; and selecting a classification identifier corresponding to the total influence parameter value meeting a first preset condition as a classification result of the to-be-classified text. Therefore, the key classification words of the to-be-classified text are extracted, and the classification result matched with the to-be-classified text is accurately and objectively selected from the key classification words by utilizing the classification influence parameters, so that the method does not need to depend on the context, and is more efficient, accurate, flexible and extensible.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present disclosure relate to the field of natural language processing technology, and in particular to text classification methods, devices, equipment, media, and products. Background Art

[0002] Text classification is a basic and important task in Natural Language Processing (NLP), which involves automatically classifying and labeling text (or other entities) according to a certain classification system or standard.

[0003] There are three main types of existing text classification methods: text feature representation, shallow learning models, and deep learning models. All three methods are suitable for strong semantic scenarios, such as sentiment classification and topic classification. These methods require a full grasp of the contextual information of the text, that is, a complete paragraph or chapter is required as the basis for processing. In addition, in order to ensure the accuracy and generalization ability of the model, a large amount of training data is also required as support. Generally speaking, the required amount of data should be more than 100,000 texts. At the same time, since these methods involve complex computing processes, they require greater computing power support, such as high-performance GPUs or high-configuration CPUs. However, it is worth noting that these methods are usually time-consuming. Specifically, it may take months to collect and organize training data sets, it may take dozens of hours to train a machine learning text classification model, and it may take several days to dozens of days to train a deep learning text classification model. Summary of the invention

[0004] The embodiments of the present disclosure provide a text classification method, apparatus, device, medium, and product.

[0005] In a first aspect, an embodiment of the present disclosure provides a text classification method, the method comprising:

[0006] Obtaining a text to be classified and a preset classification word library, wherein the preset classification word library stores classification words, classification identifiers of the classification words, and classification influencing parameters;

[0007] Extracting words contained in the preset classification word library from the text to be classified as matching words;

[0008] Obtaining at least one classification identifier and a total impact parameter value corresponding to the at least one classification identifier according to the matching words, the classification identifiers of the matching words, and the classification impact parameters;

[0009] A classification identifier corresponding to the total impact parameter value that meets the first preset condition is selected as the classification result of the text to be classified.

[0010] In some optional implementations, the step of selecting the classification identifier corresponding to the total impact parameter value that satisfies the first preset condition as the classification result of the text to be classified includes:

[0011] In the text to be classified, words contained in a preset rule library are extracted as matching rule words; wherein the preset rule library is used to store rule words and influence parameter calculation rules corresponding to the rule words, and the influence parameter calculation rules are rules for reassigning the total influence parameter value;

[0012] For each rule word, according to the influence parameter calculation rule corresponding to the rule word, the total influence parameter value corresponding to the at least one classification identifier is reassigned to obtain an updated influence parameter value corresponding to the at least one classification identifier;

[0013] The classification identifier corresponding to the update influencing parameter value that meets the second preset condition is selected as the classification result of the text to be classified.

[0014] In some optional implementations, the preset classification word library is generated by the following word library construction operation:

[0015] Acquire a text sample set, wherein the text sample set includes a plurality of text samples with annotated classification results;

[0016] For each text sample, annotate the words in the text sample using the classification result of the text sample annotation;

[0017] According to the classification results of the words and annotations in the plurality of text samples, a plurality of classification words and classification identifiers and classification influence parameters of the plurality of classification words are obtained;

[0018] The multiple classification words and the classification identifiers and classification influence parameters of the multiple classification words are correspondingly stored in the preset classification word library.

[0019] In some optional implementations, for each text sample, labeling the words in the text sample using the classification result of the text sample labeling includes:

[0020] Performing word segmentation processing on each text sample to generate a word segmentation sequence of the text sample, wherein the classification result of each word segmentation annotation in the word segmentation sequence is the classification result of the text sample to which the word segmentation belongs; and

[0021] The step of obtaining a plurality of classified words and classification identifiers and classification influence parameters of the plurality of classified words according to the classification results of the words and annotations in the plurality of text samples includes:

[0022] Extracting non-repeated words from the word segmentation sequences of the plurality of text samples to obtain classified words;

[0023] For each classification word, the occurrence frequency of each classification word under different annotated classification results is counted to obtain the classification result probability distribution of the classification word; the classification result with the highest occurrence frequency in the classification result probability distribution of the classification word is determined as the classification identifier of the classification word;

[0024] For each classified word, the cross entropy of the classified word is calculated according to the probability distribution of the classification result of the classified word;

[0025] The cross entropies of the multiple classification words are normalized to obtain classification influence parameters of the multiple classification words.

[0026] In some optional implementations, for each classified word, calculating the cross entropy of the classified word according to the probability distribution of the classification result of the classified word includes:

[0027] For each classification word, use the formula Calculating the cross entropy of the classified words;

[0028] Among them, loss is the cross entropy of the classification words, c is the number of types of the classification results of the classification words, and y i is the unique hot encoding representation of the i-th classification result of the classification word, p i is the occurrence frequency of the classification word in the i-th classification result, where i is an integer between 0 and c-1.

[0029] In some optional implementations, the normalizing the cross entropy of the multiple classification words to obtain the classification influence parameters of the multiple classification words includes:

[0030] Deleting the classification words whose cross entropy is less than a preset threshold among the multiple classification words;

[0031] For each classification word, the classification impact parameter of each classification word is calculated using the following normalization formula:

[0032] weight n =(loss n -min(loss)) / (max(loss)-min(loss));

[0033] Among them, weight n Indicates the classification impact parameter for the nth classification word, loss n represents the cross entropy of the nth classification word, min(loss) represents the minimum value among the cross entropies of the multiple classification words, and max(loss) represents the maximum value among the cross entropies of the multiple classification words.

[0034] In a second aspect, an embodiment of the present disclosure provides a text classification device, the device comprising:

[0035] A first acquisition module is used to acquire the text to be classified and a preset classification word library, wherein the preset classification word library stores classification words, classification identifiers of the classification words, and classification influencing parameters;

[0036] A first extraction module is used to extract words contained in a preset classification word library from the text to be classified as matching words;

[0037] A statistical module, configured to obtain at least one classification identifier and a total impact parameter value corresponding to the at least one classification identifier according to the matching words, the classification identifiers of the matching words and the classification impact parameters;

[0038] A result module is used to select a classification identifier corresponding to a total impact parameter value that meets a first preset condition as a classification result of the text to be classified.

[0039] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by one or more processors, implements the method described in any implementation manner in the first aspect.

[0040] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the method described in any implementation manner in the first aspect.

[0041] In order to realize text classification in a weak context environment, the text classification method, device, equipment, medium and product provided by the embodiments of the present disclosure are firstly obtained by obtaining the text to be classified and the preset classification word library, wherein the preset classification word library stores classification words, classification identifiers and classification influence parameters of the classification words; then, in the text to be classified, the words contained in the preset classification word library are extracted as matching words; then, according to the matching words, the classification identifiers and classification influence parameters of the matching words, at least one classification identifier and the total influence parameter value corresponding to the at least one classification identifier are obtained; finally, the classification identifier corresponding to the total influence parameter value that meets the first preset condition is selected as the classification result of the text to be classified. In this way, the key classification words of the text to be classified are extracted, and the classification influence parameters are used to accurately and objectively select the classification result matching the text to be classified from multiple key classification words, which not only does not need to rely on the context, but is also more efficient, accurate, flexible and scalable. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Other features, objects and advantages of the present disclosure will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings. The drawings are only for the purpose of illustrating specific embodiments and are not to be considered as limiting the present disclosure. In the drawings:

[0043] Figure 1 is an exemplary system architecture diagram in which an embodiment of the present disclosure may be applied;

[0044] Figure 2 is a flowchart of an embodiment of a text classification method according to the present disclosure;

[0045] Figure 3 is a flow chart of constructing a preset classification word library according to the text classification method disclosed in the present invention;

[0046] Figure 4 is a structural schematic diagram of an embodiment of a text classification device according to the present disclosure;

[0047] Figure 5 It is a structural diagram of a computer system of an electronic device suitable for implementing an embodiment of the present disclosure. DETAILED DESCRIPTION

[0048] The present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.

[0049] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0050] The information, data and signals involved in this disclosure are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data comply with the relevant laws, regulations and standards of relevant countries and regions.

[0051] There are three main types of existing text classification methods:

[0052] 1. Text feature representation

[0053] Text feature representation is to convert text into a form that is easy for computers to process and reduce information loss. Common methods include BOW (Bag of Words), N-gram model, TF-IDF (Term Frequency-Inverse Document Frequency), word2vec (word to vector), and Glove (Global Vectors for Word Representation).

[0054] Among them, BOW uses vectors to represent text and ignores word order; N-gram incorporates information about adjacent word phrases; TF-IDF models text using word frequency and inverse document frequency; Word2vec uses local context information to obtain word vectors; and Glove combines local context and global statistical features.

[0055] 2. Shallow Learning Model

[0056] Shallow learning models learn predefined feature representations, among which artificial features are difficult. Common models include PGM (Probabilistic Graphical Model, including NB (Naive Bayes), HMM (Hidden Markov Model), KNN (K-Nearest Neighbors), etc. In general, shallow models learn predefined feature representations and perform better than deep learning models on small-scale data.

[0057] 3. Deep Learning Model

[0058] Deep learning models include ReNN-based (Recurrent Neural Network-based), MLP-based (Multilayer Perceptron-based), RNN-based (Recurrent Neural Network-based), LSTM (Long Short-Term Memory), CNN-based (Convolutional Neural Network-based), etc.

[0059] Among them, ReNN-based recursively learns text semantics and syntactic tree structure without artificial features; MLP-based consists of input layer, hidden layer, and output layer, and is applied to paragraph vectors; RNN-based processes time series and solves long-distance dependency problems; LSTM alleviates the gradient disappearance problem and effectively captures the word association characteristics of text context; CNN-based uses convolutional filters to extract text features and perform convolution operations.

[0060] The three types of methods mentioned above are all suitable for strong semantic scenarios, such as sentiment classification and topic classification. These methods emphasize the in-depth grasp of text context information, so they need to be based on complete paragraphs or chapters. In addition, in order to ensure the accuracy and generalization ability of the model, it is necessary to rely on a large amount of training data as support. Generally speaking, the required amount of data should reach more than 100,000 texts. At the same time, given that these methods involve complex computing processes, they require strong computing power support, such as high-performance GPUs or high-configuration CPUs. However, it should be noted that these methods are usually time-consuming. Specifically, it may take months to collect and organize training data sets, it may take dozens of hours to train a machine learning text classification model, and the training of a deep learning text classification model may take several days to dozens of days.

[0061] To solve the above problems, Figure 1 An exemplary system architecture 100 is shown to which embodiments of the text classification method, apparatus, device, medium, and product of the present disclosure can be applied.

[0062] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0063] The user can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send data messages, etc. Various communication client applications can be installed on the terminal devices 101, 102, 103, such as text classification applications, voice recognition applications, short video social applications, audio and video conferencing applications, video live broadcast applications, document editing applications, input method applications, web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0064] Terminal devices 101, 102, 103 can be hardware or software. When terminal devices 101, 102, 103 are hardware, they can be various electronic devices with display screens, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Compression Standard Audio Layer 3), MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Compression Standard Audio Layer 4) players, laptop computers and desktop computers, etc. When terminal devices 101, 102, 103 are software, they can be installed in the terminal devices listed above. It can be implemented as multiple software or software modules (for example, to provide text classification services), or it can be implemented as a single software or software module. No specific limitation is made here.

[0065] In some cases, the text classification method provided by the present disclosure may be executed by the terminal devices 101, 102, 103, and accordingly, the text classification apparatus may be disposed in the terminal devices 101, 102, 103. In this case, the system architecture 100 may not include the server 105.

[0066] In some cases, the text classification method provided by the present disclosure can be jointly executed by the terminal devices 101, 102, 103 and the server 105. For example, the step of "obtaining the text to be classified and the preset classification word library, the preset classification word library correspondingly stores the classification words, the classification identification and the classification influence parameters of the classification words" can be executed by the terminal devices 101, 102, 103, and the steps of "obtaining at least one classification identification and the total influence parameter value corresponding to the at least one classification identification according to the matching words, the classification identification and the classification influence parameters of the matching words" can be executed by the server 105. The present disclosure does not limit this. Accordingly, the text classification device can also be respectively set in the terminal devices 101, 102, 103 and the server 105.

[0067] In some cases, the text classification method provided by the present disclosure may be executed by the server 105 , and accordingly, the text classification device may also be set in the server 105 . In this case, the system architecture 100 may not include the terminal devices 101 , 102 , and 103 .

[0068] It should be noted that the server 105 can be hardware or software. When the server 105 is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or it can be implemented as a single server. When the server 105 is software, it can be implemented as multiple software or software modules (for example, for providing distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.

[0069] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0070] In a strong semantic environment, each symbol or word has a definite and consistent meaning that is not easily misunderstood or interpreted in multiple ways. For example, mathematical symbols and computer programming languages ​​usually have strong semantics because their definitions are precise and consistent throughout the system. Weak semantics refers to a language or symbol system in which the relationship between symbols and the meanings they represent is vague or fluid and is easily affected by context. In a weak semantic environment, the same symbol or word may have different interpretations in different contexts. Natural languages ​​usually have weak semantics because the use of language is influenced by factors such as context, culture, personal experience, and emotion.

[0071] Continue to refer Figure 2 , which shows a process 200 of an embodiment of a text classification method according to the present disclosure. The method can use the information in the preset classification word library to efficiently and accurately classify the text to be classified. It can be applied to various scenarios that require text classification, such as classifying address text into home address, work address, school address, etc. or classifying company names and trademark names into other weak semantic scenarios such as agriculture, entertainment, real estate, etc., to provide strong support for the development of related fields. Specifically, the text classification method includes the following steps:

[0072] Step 201, obtaining the text to be classified and the preset classification word library.

[0073] The text to be classified is the target content that needs to be classified, and the preset classification word library is the reference for text classification. The preset classification word library stores classification words, and each word is marked with a corresponding classification identifier and classification influence parameter. The classification influence parameter can be set according to factors such as the frequency of occurrence of the word in each classification text and its importance to the classification, so as to measure the contribution of the word in the classification process.

[0074] When building a preset classification word library, you can refer to the existing text sample library and annotation information, and use statistical analysis, machine learning and other methods to mine the word segments of each text sample and assign corresponding classification influence parameters, which are not limited here. In this way, you can use the preset classification word library to assist in the classification of the text to be classified.

[0075] Step 202: extract words contained in a preset classification word library from the text to be classified as matching words.

[0076] Traverse each word in the text to be classified and compare it with the words in the preset classification word library. If there are identical words, record them as matching words. In this way, the text to be classified can be associated with the classification words in the preset classification word library, providing the necessary basis for subsequent classification processing. At the same time, by extracting matching words, you can further understand the content characteristics of the text to be classified, which helps to better understand its classification.

[0077] For example, the text to be classified is "305, Unit X, Building X, Anzhen West Li, Anzhen Street, Chaoyang District, Beijing", and the preset classification word library stores the classification words "Chaoyang District, Xili, Building, Community, Unit". The extracted matching words and their annotations in the preset classification word library are shown below.

[0078] Table 1:

[0079] Classification words Classification mark Classification influence parameters Chaoyang District Work address 0.1 Xili Home address 0.6 unit Home address 0.9

[0080] Table 1

[0081] As a possible implementation, the above step 202 may be implemented by string matching, regular expression, etc., which is not limited here.

[0082] Step 203: Obtain at least one classification identifier and a total impact parameter value corresponding to the at least one classification identifier according to the matching words, the classification identifiers of the matching words and the classification impact parameters.

[0083] Since each classification mark may correspond to multiple matching words, the more matching words the classification mark corresponds to, the closer the subject of the text to be classified is to the classification mark. Since different words have different influences on classification, it is necessary to combine the classification influence parameters to count the classification marks.

[0084] For example, the classification impact parameters of each matching word corresponding to the same classification identifier are cumulatively calculated to obtain each classification identifier and its corresponding total impact parameter value. For a specific example, according to the matching words obtained in Table 1, they correspond to two classification identifiers, namely "home address" and "work address". The classification impact parameters corresponding to different classification identifiers are cumulatively calculated to obtain the total impact parameter value of each classification identifier. The results are shown in Table 2 below:

[0085] Classification mark Total impact parameter value Home address 0.6+0.9=1.5 Work address 0.1

[0086] Table 2

[0087] Alternatively, other statistical calculation methods may be used to calculate the classification influence parameter corresponding to each classification mark, which is not limited here. In this way, the total influence parameter of each classification mark in the text to be classified can be obtained, thereby reflecting the importance of different classification marks in the text to be classified. Optionally, the total influence parameter value can be further normalized as needed to make it more comparable and interpretable.

[0088] Step 204: Select the classification identifier corresponding to the total impact parameter value that meets the first preset condition as the classification result of the text to be classified.

[0089] The first preset condition is used to specify how to select the most suitable classification identifier based on the total impact parameter value. For example, the first preset condition can specify to compare the total impact parameter values ​​of each classification, and select the classification identifier whose total impact parameter value meets the preset range as the classification result of the text to be classified.

[0090] In some examples, the preset range is the maximum value, and the classification identifier with the largest total impact parameter value is selected as the classification result of the text to be classified. For example, in the case of Table 2, the total impact parameter value of "home address" is the largest, so "home address" is selected as the classification result of the text to be classified. It should be understood that the maximum value is not used as a limitation of the preset range, and the preset range can be set as needed. When determining the classification with the largest total impact parameter value, a variety of methods can be used, such as comparing size methods, using sorting algorithms, etc. The specific implementation method can be selected according to actual needs and technical conditions, and is not limited here.

[0091] In some examples, the preset range can also be a range that meets a certain threshold. When the total impact parameter value of a classification identifier exceeds the preset threshold, it is used as the classification result of the text to be classified. Such a design can further increase the accuracy and reliability of the classification result and avoid classification errors caused by mismatching or too small a classification impact parameter value.

[0092] In addition, if there are multiple classification identifiers in the text to be classified and their total influence parameter values ​​meet the preset conditions, they can be further screened according to other factors. For example, the classification identifier with the most stable and most discriminatory classification influence parameter value can be selected as the final result, or a selection can be made according to a preset priority order, etc., which is not limited here.

[0093] As a possible implementation, the above step 204 may include the following steps 2041 to 2043:

[0094] Step 2041, extracting words contained in a preset rule base from the text to be classified as matching rule words.

[0095] The preset rule base is used to store rule words and the influence parameter calculation rules corresponding to the rule words. The influence parameter calculation rules are rules for re-assigning the total influence parameter value, which can be constructed based on data analysis or manual experience and are intended to improve the accuracy and efficiency of classification.

[0096] As a possible implementation, the rule words in the preset rule library can be in any text form such as a string, expression, etc. For example, taking address classification as an example, the rule word is "eastward\d{1,3} meters", and the influence parameter calculation rule corresponding to the rule word is "multiply the total influence parameter value of all matching words before the location by the coefficient ɑ".

[0097] Traverse each word in the text to be classified, compare the words in the text to be classified with the words in the preset rule library, and if there are identical words, record the identical words as rule words. In this way, the text to be classified can be associated with the words in the preset rule library, providing the necessary basis for subsequent classification processing.

[0098] Step 2042: for each rule word, according to the influence parameter calculation rule corresponding to the rule word, reassign the total influence parameter value corresponding to at least one classification identifier to obtain an updated influence parameter value corresponding to at least one classification identifier.

[0099] For example, when the regular word "eastward\d{1,3} meters" is detected, the execution of "multiplying the total impact parameter value of all matching words before the position by the coefficient ɑ" is triggered.

[0100] Each reassignment will improve the accuracy of the final classification result to a certain extent. Usually, after reassigning more than 10 regular words, the classification accuracy can be improved by 3-5 percentage points. In this way, with only a small amount of manpower and computing power, a text classifier with an accuracy rate of >80% can be quickly obtained, greatly improving the accuracy of text classification.

[0101] Step 2043: Select the classification identifier corresponding to the update influencing parameter value that meets the second preset condition as the classification result of the text to be classified.

[0102] Similar to the first preset condition, the second preset condition is used to specify how to select the most suitable classification identifier according to the update impact parameter value. For example, the second preset condition can specify to compare the update impact parameter values ​​of each classification, and select the classification identifier whose total impact parameter value meets the preset range as the classification result of the text to be classified. In some examples, the preset range can be a user-defined range such as a maximum value, a range that meets a certain threshold, etc., which is not limited here.

[0103] In this way, by using step 2041 to step 2043, the total impact parameter value is reassigned using rule words, which can further significantly improve the accuracy of the classification result.

[0104] In practical applications, the text to be classified may involve multiple categories, or the boundaries between categories may not be clear. After obtaining the classification results, we can further combine contextual information, semantic understanding and other means to verify and optimize the classification results to improve the accuracy and reliability of the classification.

[0105] Specifically, after obtaining the preliminary classification results, contextual information can be used to assist in the judgment. By analyzing the context of the text, the theme and intention of the text can be better understood, and then the classification to which it belongs can be judged whether it is accurate. For example, if the context of an article on the development of science and technology mainly discusses the medical field, it may be more appropriate to classify it as medical technology. Secondly, semantic understanding technology can be used to improve the accuracy of classification. Semantic understanding technology can help us deeply understand the meaning of the text and the relationship between the meanings, so as to more accurately judge the category to which it belongs. For example, for a text involving multiple topics, we can use semantic understanding technology to identify the main and secondary topics, and readjust the classification results based on these topics. In addition, some other technical means can be used to assist the classification work. For example, machine learning algorithms can be used to automatically learn and identify features and patterns in the text, so as to more accurately judge the category to which it belongs. The specific verification method is not limited here.

[0106] In summary, for the text classification problem under weak semantic conditions, the text classification method provided by the above embodiments of the present disclosure can at least achieve the following technical effects:

[0107] (1) Compared with the data volume required for classification of related technologies, which can reach 100,000 texts, the data volume required by the present disclosure is significantly reduced. For example, text classification can be achieved by constructing thousands of classification words in a preset classification vocabulary, which significantly reduces the requirement for the number of samples.

[0108] (2) Since the classification process mainly relies on a preset classification vocabulary and does not rely on the contextual information of the text, the present disclosure can process text data more independently and accurately.

[0109] (3) Compared with traditional deep learning and machine learning methods, due to its simple computational logic, it has significant advantages in computing speed and resource consumption, and requires less computing power, so that on a home computer with an ordinary CPU, it only takes a few days from data collection to modeling, greatly improving work efficiency and convenience.

[0110] Continue to refer Figure 3 The preset classification word library in the text classification method provided in the above embodiment of the present disclosure can be generated by the word library construction operation shown in the following steps 301 to 306:

[0111] Step 301, obtaining a text sample set.

[0112] The text sample set contains multiple text samples with annotated classification results. The text samples can be texts related to the classification task that have been collected in advance by relevant personnel, or they can be texts from various channels, such as public datasets on the Internet or documents in certain fields. In order to ensure the accuracy of classification, we usually select representative and widely covered sample sets to cover as many classification scenarios and text features as possible. After obtaining the text samples, the classification results are annotated on them.

[0113] Step 302: for each text sample, use the classification result of the text sample annotation to annotate the words in the text sample.

[0114] For each text sample, word segmentation processing is performed to generate a word segmentation sequence of the text sample, establish a corresponding relationship of "text sample-word segmentation sequence", and then mark the classification result of the text sample to which the word segmentation belongs as the classification result of each word segmentation mark in the word segmentation sequence.

[0115] Among them, word segmentation is a basic task in natural language processing, which can segment continuous text into independent word units. In the word segmentation process, advanced word segmentation algorithms (such as jieba tool, a very popular Chinese text segmentation Python library) can be used to ensure that each word can be accurately identified and the classification results of the text sample to which it belongs are annotated.

[0116] For example, the text sample 1 "305, X Building, X Unit, Anzhen West Village, Anzhen Street, Chaoyang District, Beijing" is labeled with the classification result "home address". After word segmentation, the word segmentation sequence is obtained as "305, X Building, X Unit, Anzhen West Village, Chaoyang District, Beijing". The text sample 2 "X Jianguo Road, Chaoyang District, Beijing" is labeled with the classification result "work address". After word segmentation, the word segmentation sequence is obtained as "X Jianguo Road, Chaoyang District, Beijing". The text sample 3 "X Jianguomenwai Street, Chaoyang District, Beijing" is labeled with the classification result "work address". After word segmentation, the word segmentation sequence is obtained as "X Jianguomenwai Street, Chaoyang District, Beijing".

[0117] Step 303: obtaining a plurality of classified words and classification identifiers and classification influence parameters of the plurality of classified words according to the classification results of the words and annotations in the plurality of text samples.

[0118] Specifically, step 303 may include the following steps 3031 to 3034:

[0119] Step 3031: extract non-repeated words from the word segmentation sequences of multiple text samples to obtain classified words.

[0120] For example, multiple word segmentation sequences include the words "Beijing, Chaoyang District, Anzhen, Street, Anzhen, Xili, X, Building, X, Unit, 305, Beijing, Chaoyang District, Jianguo, Road, No. X, Beijing, Chaoyang District, Jianguo, Outside, Street, No. X", then, remove the repeated words and get the classified words "Beijing, Chaoyang District, Anzhen, Street, Xili, Building, X, Unit, 305, Jianguo, Road, Outside, Street".

[0121] Step 3032: for each classification word, count the occurrence frequency of each classification word under different annotated classification results to obtain the classification result probability distribution of the classification word; and determine the classification result with the highest occurrence frequency in the classification result probability distribution of the classification word as the classification identifier of the classification word.

[0122] For example, the classification results of the classification term "Chaoyang District" are: the classification result of sample 1 is "home address", the classification result of sample 2 is "work address", and the classification result of sample 3 is "work address".

[0123] That is, "home address" appears once, and "work address" appears twice. The frequency of occurrence of "Chaoyang District" in different classification results is counted, that is, the frequency of occurrence of "Chaoyang District" in the classification result "home address" is 1 / 3, and the frequency of occurrence in the classification result "work address" is 2 / 3, and the probability distribution of the classification results of the classification words is obtained, as shown in Table 3 below:

[0124] Home address Work address Chaoyang District 1 / 3 2 / 3

[0125] Table 3

[0126] The classification result with the highest occurrence frequency of each classification word is determined as the classification mark of the classification word. If a classification word appears frequently in a classification result, it is likely to have a high correlation with the classification result, so it is used as the classification mark.

[0127] Step 3033: For each classified word, the cross entropy of the classified word is calculated according to the probability distribution of the classification result of the classified word.

[0128] Cross entropy indicates the accuracy of each word classification result. The smaller the cross entropy, the more accurate the word classification. Cross entropy can quantify the difference between the probability distribution predicted by the model and the true probability distribution. After calculating the cross entropy, the classification influence parameter of each classification result can be determined on this basis. The more accurate the classification result, the higher the word segmentation influence parameter of the classified word.

[0129] The cross entropy can be calculated by various commonly used calculation methods. Preferably, for each classified word, the formula Calculating the cross entropy of the classified words;

[0130] Among them, loss is the cross entropy of the classification words, c is the number of types of the classification results of the classification words, and y i is the unique hot encoding representation of the i-th classification result of the classification word, p i is the occurrence frequency of the classification word in the i-th classification result, where i is an integer between 0 and c-1.

[0131] One-Hot Encoding, also known as one-bit efficient encoding, is a commonly used encoding method to convert categorical variables into a format that can be better processed by machine learning algorithms. In one-hot encoding, each categorical value is represented as a binary vector with a length equal to the total number of categorical values, where only one position has a value of 1 and the rest of the positions have values ​​of 0.

[0132] For example, suppose there is a classification term "Chaoyang District", which has three classification results: "home address", "work address" and "commercial address". Using one-hot encoding, we can represent these classification result tables as the following vectors: "home address" is represented as [1,0,0]; "work address" is represented as [0,1,0]; "commercial address" is represented as [0,0,1].

[0133] Thus, for example, the cross entropy loss of the above classification term "Chaoyang District" in Table 3 is <朝阳区>=[1,0]log(1 / 3)+[0,1]log(2 / 3).

[0134] Step 3034, normalize the cross entropy of the multiple classification words to obtain the classification influence parameters of the multiple classification words.

[0135] Normalization is a commonly used data processing method, which can convert numerical values ​​of different dimensions and ranges into relative values ​​on the same scale, making it easier for us to compare and analyze.

[0136] As a possible implementation, the above step 3034 includes the following steps 30341 to 30342:

[0137] Step 30341, deleting the classification words whose cross entropy is less than a preset threshold among the multiple classification words.

[0138] Delete the classification words whose cross entropy is less than the preset threshold in the above classification word set to reduce the influence of classification words with inaccurate classification results on subsequent normalization. For example, the cross entropies of multiple classification words are 4.7, 2.6, 5.3, and 0.06 respectively, and the preset threshold is 1, then filter out the classification words with a cross entropy of 0.06 so that they will not affect the normalization results.

[0139] Step 30342: For each classified word, calculate its classification impact parameter using the following normalization formula:

[0140] weight n =(loss n -min(loss)) / (max(loss)-min(loss));

[0141] Among them, weight n Indicates the classification impact parameter for the nth classification word, loss n represents the cross entropy of the nth classification word, min(loss) represents the minimum value among the cross entropies of the multiple classification words, and max(loss) represents the maximum value among the cross entropies of the multiple classification words.

[0142] In this way, through steps 30341 to 30342, for each classification word, the classification influence parameter under a unified scale can be effectively obtained.

[0143] In summary, through steps 3031 to 3034, the classification words are first extracted, and then their corresponding classification representations and classification influence parameters are obtained one by one, and the classification words in the preset classification vocabulary are automatically constructed according to the text samples, which is highly efficient.

[0144] Step 304: store the multiple classification words and the classification identifiers and classification influencing parameters of the multiple classification words in the preset classification word library in a corresponding manner.

[0145] Step 303 can obtain multiple classification words and their classification identifiers and classification influencing parameters, and store the classification words, classification identifiers, and classification influencing parameters in a blank preset classification word library in a one-to-one correspondence, so as to obtain a complete preset classification word library.

[0146] In summary, through step 301 to step 304, a preset classification word library can be constructed, which is applied to the previous embodiment to realize text classification under weak semantic conditions, and realize text classification independently, accurately and efficiently.

[0147] Further references Figure 4 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a text classification device. Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0148] like Figure 4 As shown, the text classification device 400 of this embodiment includes: a first acquisition module 401 , a first extraction module 402 , a statistics module 403 and a result module 404 .

[0149] The first acquisition module 401 is used to acquire the text to be classified and a preset classification word library, wherein the preset classification word library stores classification words, classification identifiers of the classification words, and classification influencing parameters;

[0150] A first extraction module 402 is used to extract words contained in a preset classification word library from the text to be classified as matching words;

[0151] A statistical module 403, configured to obtain at least one classification identifier and a total impact parameter value corresponding to the at least one classification identifier according to the matching words, the classification identifiers of the matching words and the classification impact parameters;

[0152] The result module 404 is used to select the classification mark corresponding to the total influence parameter value that meets the first preset condition as the classification result of the text to be classified.

[0153] In this embodiment, the specific processing of the text classification device 400 and the technical effects thereof can be referred to in Figure 2 The relevant descriptions of step 201, step 202, step 203 and step 204 in the corresponding embodiment are not repeated here.

[0154] In some optional implementations, the result module 404 includes:

[0155] The second extraction unit 405 is used to extract words contained in a preset rule base from the text to be classified as matching rule words; wherein the preset rule base is used to store rule words and influence parameter calculation rules corresponding to the rule words, and the influence parameter calculation rules are rules for re-assigning the total influence parameter value;

[0156] A re-assignment unit 406, configured to re-assign the total impact parameter value corresponding to the at least one classification identifier according to the impact parameter calculation rule corresponding to the rule word for each rule word, so as to obtain an updated impact parameter value corresponding to the at least one classification identifier;

[0157] The accurate result unit 407 is used to select the classification identifier corresponding to the update influencing parameter value that meets the second preset condition as the classification result of the text to be classified.

[0158] In some optional implementations, the preset classification word library is generated by the following word library construction operation:

[0159] Acquire a text sample set, wherein the text sample set includes a plurality of text samples with annotated classification results;

[0160] For each text sample, annotate the words in the text sample using the classification result of the text sample annotation;

[0161] According to the classification results of the words and annotations in the plurality of text samples, a plurality of classification words and classification identifiers and classification influence parameters of the plurality of classification words are obtained;

[0162] The multiple classification words and the classification identifiers and classification influence parameters of the multiple classification words are correspondingly stored in the preset classification word library.

[0163] In some optional implementations, for each text sample, labeling the words in the text sample using the classification result of the text sample labeling includes:

[0164] Performing word segmentation processing on each text sample to generate a word segmentation sequence of the text sample, wherein the classification result of each word segmentation annotation in the word segmentation sequence is the classification result of the text sample to which the word segmentation belongs; and

[0165] The step of obtaining a plurality of classified words and classification identifiers and classification influence parameters of the plurality of classified words according to the classification results of the words and annotations in the plurality of text samples includes:

[0166] Extracting non-repeated words from the word segmentation sequences of the plurality of text samples to obtain classified words;

[0167] For each classification word, the occurrence frequency of each classification word under different annotated classification results is counted to obtain the classification result probability distribution of the classification word; the classification result with the highest occurrence frequency in the classification result probability distribution of the classification word is determined as the classification identifier of the classification word;

[0168] For each classified word, the cross entropy of the classified word is calculated according to the probability distribution of the classification result of the classified word;

[0169] The cross entropies of the multiple classification words are normalized to obtain classification influence parameters of the multiple classification words.

[0170] In some optional implementations, for each classified word, calculating the cross entropy of the classified word according to the probability distribution of the classification result of the classified word includes:

[0171] For each classification word, use the formula Calculating the cross entropy of the classified words;

[0172] Among them, loss is the cross entropy of the classification words, c is the number of types of the classification results of the classification words, and y i is the unique hot encoding representation of the i-th classification result of the classification word, p i is the occurrence frequency of the classification word in the i-th classification result, where i is an integer between 0 and c-1.

[0173] In some optional implementations, the normalizing the cross entropy of the multiple classification words to obtain the classification influence parameters of the multiple classification words includes:

[0174] Deleting the classification words whose cross entropy is less than a preset threshold among the multiple classification words;

[0175] For each classification word, the classification impact parameter of each classification word is calculated using the following normalization formula:

[0176] weight n =(loss n -min(loss)) / (max(loss)-min(loss));

[0177] Among them, weight n Indicates the classification impact parameter for the nth classification word, loss n represents the cross entropy of the nth classification word, min(loss) represents the minimum value among the cross entropies of the multiple classification words, and max(loss) represents the maximum value among the cross entropies of the multiple classification words.

[0178] It should be noted that the implementation details and technical effects of each module and unit in the text classification device provided in the embodiment of the present disclosure can be referred to the description of other embodiments in the present disclosure, and will not be repeated here.

[0179] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 suitable for implementing the electronic device of the present disclosure. Figure 5 The computer system 500 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0180] like Figure 5 As shown, the computer system 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 to a random access memory (RAM) 503. Various programs and data required for the operation of the computer system 500 are also stored in the RAM 503. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0181] Typically, the following devices may be connected to the I / O interface 505: input devices 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, etc.; output devices 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 508 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 509. The communication devices 509 may allow the computer system 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 The computer system 500 of an electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0182] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0183] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0184] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0185] The computer readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device implements the following Figure 2 The illustrated embodiment and its optional implementations illustrate a text classification method.

[0186] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0187] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0188] The units or modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a unit or module does not, in some cases, limit the unit itself. For example, the first acquisition module may also be described as "a classification identifier corresponding to the largest total influence parameter value among the total influence parameter values ​​of different categories of the text to be classified, as the classification result of the text to be classified".

[0189] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.