Text classification method, device and equipment and computer readable storage medium

The contextual and local semantic information of the text is extracted through the bidirectional long short-term memory network, multiple conditional random fields and LDA models, and matrix splicing is performed based on keywords, which solves the problem of high cost of text classification in the existing technology, and achieves reduced training costs and improved Effect on classification accuracy.

CN118673140APending Publication Date: 2024-09-20BEIJING CO WHEELS TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202310271220.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-16
Publication Date
2024-09-20

AI Technical Summary

Technical Problem

The cost of text classification in the existing technology is relatively high, mainly because the neural network model training requires a large amount of annotated data, resulting in high training costs.

Method used

Using a two-way long short-term memory network, multiple conditional random fields and LDA models, the contextual information and local semantic information of the text are obtained through word vector files, combined with keyword extraction, matrix splicing is performed to generate fused semantic information, and the pre-trained text is input Classification model performs classification.

Benefits of technology

On the premise of ensuring the accuracy of text classification, it reduces the labeling requirements for training data, significantly reduces training costs and time, and at the same time improves the role of keywords in classification results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118673140A
    Figure CN118673140A
Patent Text Reader

Abstract

The invention relates to a text classification method, device and equipment and a computer readable storage medium. The method comprises the steps of obtaining a word vector file of text data; inputting the word vector file into a bidirectional long-short term memory network for coding, and outputting context information of text data; the context information of the text data is input into the multi-conditional random field, local semantic information of the text data is obtained, and the local semantic information is used for representing structure information of the text data; inputting the context information of the text data into an LDA model for keyword extraction to obtain keyword information of the text data; performing matrix splicing on the local semantic information of the text data and the keyword matrix of the text data to obtain fused semantic information of the text data; and inputting the fused semantic information into a pre-trained text classification model, and outputting a text category with the maximum probability as a text classification result of the text data. According to the method, the training cost and the training time are greatly reduced on the premise of ensuring the text classification accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of natural language processing, and in particular to a text classification method, apparatus, device and computer-readable storage medium. Background Art

[0002] In natural language processing, text classification is a task to classify the sentiment of a given text, and then provide a functional response based on the result of text classification. For example, to classify the domain of a user-initiated command, it is necessary to identify whether it is a question-and-answer task, or to identify the user's intention, such as weather query, song search, random chat, etc.

[0003] Most existing technologies obtain the key features of text through neural networks, such as attention mechanism or convolutional neural network and other technologies to extract key features of text. However, when training the neural network model, a large amount of training corpus needs to be annotated, and the model training cost is high, resulting in a high cost of text classification. Summary of the invention

[0004] In order to solve the above technical problems, the present disclosure provides a text classification method, apparatus, device and computer-readable storage medium to reduce the cost of text classification.

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

[0006] Get the word vector file of text data;

[0007] Input the word vector file into a bidirectional long short-term memory network for encoding, and output context information of the text data;

[0008] Inputting the context information of the text data into a multiple conditional random field to obtain local semantic information of the text data, wherein the local semantic information is used to represent structural information of the text data;

[0009] Inputting the context information of the text data into the LDA model to extract keywords, thereby obtaining keyword information of the text data;

[0010] Performing matrix concatenation of the local semantic information of the text data and the keyword matrix of the text data to obtain fused semantic information of the text data;

[0011] The fused semantic information is input into a pre-trained text classification model, and the text category with the highest probability is output as the text classification result of the text data.

[0012] In some embodiments, the step of inputting the context information of the text data into an LDA model to extract keywords and obtain keyword information of the text data includes:

[0013] Calculate the weight value of each topic in at least one preset topic corresponding to the context information based on the LDA algorithm, each preset topic including the probability distribution of at least one word;

[0014] Sorting at least one preset topic in descending order of the weight value, and selecting a preset number of preset topics with the highest ranking as target topics;

[0015] According to the probability distribution of the words contained in the target topic, a candidate keyword set is formed;

[0016] The context information is traversed, and words appearing in the keyword set are extracted as keywords to obtain keyword information of the text data.

[0017] In some embodiments, the step of obtaining a word vector file of text data includes:

[0018] Get the text to be classified;

[0019] Performing a word segmentation operation on the text to be classified and removing stop words in the text to be classified to obtain text data;

[0020] The text data is trained with word vectors using an open source tool to obtain a word vector file for the text data.

[0021] In some embodiments, the step of inputting the word vector file into a bidirectional long short-term memory network for encoding and outputting the context information of the text data includes:

[0022] Use a forward long short-term memory network to encode each word in the word vector file to obtain sequence information from left to right;

[0023] Encode each word in the word vector file using a reverse long short-term memory network to obtain sequence information from right to left;

[0024] The context information of the text data is obtained by splicing the sequence information from left to right and the sequence information from right to left to output.

[0025] In some embodiments, inputting the context information of the text data into multiple conditional random fields to obtain local semantic information of the text data includes:

[0026] Calculating the marginal distribution probability of the context information of the text data relative to a preset label sequence, wherein the preset label is used to indicate whether the text data belongs to a range of a text category corresponding to the preset label;

[0027] The marginal distribution probabilities corresponding to each of the preset labels are concatenated in a matrix to obtain local semantic information of the text data, wherein the marginal distribution probabilities represent the possibility that the text data belongs to the range of the text category corresponding to the preset label.

[0028] In some embodiments, the calculating the marginal distribution probability of the context information of the text data relative to a preset tag sequence includes:

[0029] Calculating the sum of a transition score and an emission score of the context information of the text data relative to a preset tag sequence;

[0030] Performing normalization calculation on the sum of the transition score and the emission score of the preset tag sequence to obtain a normalized calculation result;

[0031] The marginal distribution probability of the normalized calculation result relative to the preset label sequence is calculated.

[0032] In some embodiments, the matrix concatenating the local semantic information of the text data with the keyword matrix of the text data to obtain the fused semantic information of the text data includes:

[0033] Determine, according to a preset configuration parameter of a user, a splicing direction of a matrix corresponding to the preset configuration parameter;

[0034] Obtaining the first number of elements of the local semantic information in the splicing direction and the second number of elements of the keyword matrix in the splicing direction;

[0035] The local semantic information of the text data is matrix-joined with the keyword matrix of the text data to obtain fused semantic information of the text data, wherein the number of elements of the fused semantic information in the joining direction is the sum of the first number of elements and the second number of elements. In a second aspect, an embodiment of the present disclosure provides a text classification device, comprising:

[0036] The acquisition module is used to obtain the word vector file of text data;

[0037] A first input module is used to input the word vector file into a bidirectional long short-term memory network for encoding, and output context information of the text data;

[0038] A second input module, used for inputting the context information of the text data into a multiple conditional random field to obtain local semantic information of the text data, wherein the local semantic information is used to represent the structural information of the text data;

[0039] A third input module is used to input the context information of the text data into the LDA model to extract keywords, so as to obtain keyword information of the text data;

[0040] A splicing module, used for performing matrix splicing on the local semantic information of the text data and the keyword matrix of the text data to obtain fused semantic information of the text data;

[0041] The classification module is used to input the fused semantic information into a pre-trained text classification model and output the text category with the highest probability as the text classification result of the text data.

[0042] In a third aspect, an embodiment of the present disclosure provides an electronic device, including:

[0043] Memory;

[0044] Processor; and

[0045] Computer programs;

[0046] The computer program is stored in the memory and is configured to be executed by the processor to implement the method as described in the first aspect.

[0047] 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 is executed by a processor to implement the method described in the first aspect.

[0048] The text classification method, apparatus, device and computer-readable storage medium provided by the embodiments of the present disclosure use an LDA model to extract keywords from the text, and use matrix splicing to make the relevant information of the keywords play a greater role in the final classification result. The training data does not need to be labeled, which greatly reduces the training cost and training time while ensuring the accuracy of text classification. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0051] Figure 1 A flow chart of a text classification method provided in an embodiment of the present disclosure;

[0052] Figure 2 A schematic diagram of an application scenario provided by an embodiment of the present disclosure;

[0053] Figure 3 A schematic diagram of a bidirectional long short-term memory network provided in an embodiment of the present disclosure;

[0054] Figure 4 A text structure diagram provided for an embodiment of the present disclosure;

[0055] Figure 5 A flowchart of a text classification method provided by another embodiment of the present disclosure;

[0056] Figure 6 A linear chain conditional random field probability undirected graph provided by an embodiment of the present disclosure;

[0057] Figure 7 A schematic diagram of the structure of a text classification device provided in an embodiment of the present disclosure;

[0058] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0059] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.

[0060] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.

[0061] The present disclosure provides a text classification method, which is described below in conjunction with a specific embodiment.

[0062] Figure 1 A flowchart of a text classification method provided in an embodiment of the present disclosure. The method can be applied to Figure 2The application scenario shown. This scenario includes a bidirectional long short-term memory network, a conditional random field (CRF layer) and an LDA model (topic model). The processing result of the text after the context sequence word embedding is input into the bidirectional long short-term memory network. The output of the bidirectional long short-term memory network is further input into the conditional random field and the LDA model respectively, and the output of the conditional random field is weighted according to the keyword extraction result of the LDA model, and finally input into the classifier to obtain the final classification result. This method can be applied to any device with data processing function, such as car computers, smart phones, PDAs, tablet computers, laptops, all-in-one machines, intelligent driving devices, etc. It can be understood that the text classification method provided in the embodiments of the present disclosure can also be applied in other scenarios.

[0063] Combine the following Figure 2 The application scenario shown is Figure 1 The text classification method shown in FIG. 1 is introduced, and the specific steps of the method are as follows:

[0064] S101, obtaining a word vector file of text data.

[0065] Text data usually exists in the form of text. Converting text data into word vectors containing richer semantic information makes it easier to analyze and process it through neural network models or standard machine learning algorithms.

[0066] In some embodiments, the words in the text can be converted into digital vectors by word embedding. The word embedding process is to embed a high-dimensional space with the dimension of all words into a continuous vector space with lower dimension. Each word or phrase is mapped to a vector in the real number field, and the result of word embedding generates a word vector.

[0067] S102, inputting the word vector file into a bidirectional long short-term memory network for encoding, and outputting the context information of the text data.

[0068] Long Short-Term Memory (LSTM) is a time-recurrent neural network that is suitable for processing and predicting important events with very long intervals and delays in time series. The LSTM model can better capture long-distance dependencies because LSTM can learn which information to remember and which information to forget through the training process. However, when using LSTM to model sentences, it is impossible to encode information from the back to the front. When classifying texts in a more fine-grained manner, such as the five-category task of strong praise, weak praise, neutral, weak derogatory, and strong derogatory, it is necessary to pay attention to the interaction between sentiment words, degree words, and negative words. Specifically, in the text "This restaurant is so dirty, it's not as good as the one next door", the word "not good" after "dirty" is a modification of the degree of "dirty".

[0069] Figure 3 A schematic diagram of a bidirectional long short-term memory network provided by an embodiment of the present disclosure. Figure 3 As shown in the figure, the forward LSTM obtains a result vector after 6 time steps, and the reverse LSTM also obtains another result vector after 6 time steps. The two result vectors are concatenated to obtain the final BiLSTM output result.

[0070] In the disclosed embodiment, a bidirectional long short-term memory network (Bi-directional Long Short-Term Memory, BiLSTM) is introduced to process the word vector file. A single-layer BiLSTM is composed of two LSTMs, one of which processes the word vector file forward and the other processes the word vector file backward. After the processing is completed, the outputs of the two LSTMs are spliced ​​together to obtain the BiLSTM output of the word vector file, that is, the context information of the text data, which contains the bidirectional semantic dependency information of the text data.

[0071] S103: Input the context information of the text data into multiple conditional random fields to obtain local semantic information of the text data.

[0072] The local semantic information is used to represent the structural information of the text data.

[0073] Conditional Random Fields (CRF) is a discriminative model that evolved from the maximum entropy hidden Markov model. The maximum entropy Markov model combines the advantages of the maximum entropy model and the hidden Markov model. It is a probabilistic directed graph. Although it breaks the observation independence assumption of the hidden Markov model, there is local normalization, which will cause the labeling bias problem. In order to solve the labeling bias problem, the conditional random field is a probabilistic undirected graph, which is a natural global normalization.

[0074] The CRF layer can capture the structural dependencies in the sentence to correct the output of the BiLSTM layer. Specifically, the contextual information of the text data is input into multiple conditional random fields to obtain the dependencies between adjacent words in the sentence, which is the process of performing soft selection on continuous sequences of words or spans. Usually in the text, the opinion expression associated with the opinion is often a coherent opinion span, and the opinion expression can be composed of multiple text spans rather than single words scattered in the sentence. Figure 4 A text structure diagram provided by an embodiment of the present disclosure. Figure 4 In the sentence shown, the opinion expression "usually good" is one word away from "food", which expresses a positive view on "food"; while another opinion expression "certainly isn't relaxing" is adjacent to "place", which expresses a negative view on "place". At the same time, degree expressions such as "usually" and "certainly" are also associated with opinions.

[0075] Therefore, CRF is introduced locally to capture the structural dependencies in sentences, which can accurately model and extract these structural information, and perform a soft selection on continuous word sequences or spans, which is different from the traditional attention mechanism that only weights single discrete words, and then the context information of the text data output by the BiLSTM layer in the above steps can be corrected to obtain more accurate local semantic information of the text data. This local semantic information refers to the information extracted from the text data from a local perspective, rather than the local information of the text data.

[0076] S104: Input the context information of the text data into an LDA model to extract keywords, thereby obtaining keyword information of the text data.

[0077] LDA (Latent Dirichlet Allocation) is a very representative topic model. It can be used to identify the hidden topic information in the text. It is often used in text classification to infer the topic distribution of the text. In short, the LDA algorithm can give the topic corresponding to each text in the text set in the form of probability distribution. At the same time, it is a typical bag-of-words model, that is, a text is composed of a group of words, and there is no order relationship between words.

[0078] Specifically, several preset topics are obtained, each of which is represented by a set of N words*probabilities. For the K topics to which the specified text data belongs, the words contained in the K topics are assigned to the document, and the candidate keywords of the text data are obtained. If the word obtained after the text data is segmented is among the candidate keywords, the word is extracted as a keyword.

[0079] For example, for the text "What will the weather be like in Beijing tomorrow?", after extracting three keywords through LDA, we can get the three keywords "tomorrow", "Beijing", and "weather", and these three keywords are all discriminative words in the text.

[0080] In some embodiments, training the LDA model includes: preprocessing the training text, filtering stop words and interference words in the training text, etc.; each topic is represented by a set of N words and their probabilities, each text belongs to k topics, and the words contained in the k topics are assigned to the document to obtain a document containing several candidate keywords; for the input training text, a topic is extracted from the topic distribution output by the LDA model to be trained, and a word is randomly extracted from the word distribution corresponding to the extracted topic, and this step is repeated until each word in the document is traversed, and the document-topic distribution and topic-word distribution can be obtained according to the extracted topic and the number of occurrences of the extracted word; the product of the two distributions is calculated, and the specific formula can be expressed as: P (word|document) = P (word|topic) P (topic|document). Observe whether the calculation result conforms to the distribution of the training text, so as to adjust the parameters of the LDA model.

[0081] The LDA model is an unsupervised model, and the training data does not need to be labeled. Unlike previous neural networks, it can greatly reduce the training time.

[0082] S105 , performing matrix splicing on the local semantic information of the text data and the keyword information of the text data to obtain fused semantic information of the text data.

[0083] The local semantic information of the text data and the keyword information of the text data obtained in the above steps are usually in the form of a matrix. Based on the matrix operation rules, the two are concatenated to obtain the fused semantic information of the text data.

[0084] In this step, the keyword information can weight the corresponding part of the local semantic information, so that the keywords in the text data play a greater role in the result of text classification.

[0085] S106: Input the fused semantic information into a pre-trained text classification model, and output the text category with the highest probability as the text classification result of the text data.

[0086] Specifically, the network is trained by comparing the category output of the text discriminated by the classifier with the actual category to obtain a trained text classification model, and the trained text classification model is used to classify and predict the sentiment polarity of the text data.

[0087] The text classification model may be a Softmax classifier. The result obtained by the Softmax classifier may be the probabilities corresponding to multiple text categories, and the text category with the highest probability is taken as the classification result of the text data.

[0088] The disclosed embodiment obtains a word vector file of text data; inputs the word vector file into a bidirectional long short-term memory network for encoding, and outputs context information of the text data; inputs the context information of the text data into a multiple conditional random field to obtain local semantic information of the text data, and the local semantic information is used to characterize structural information of the text data; inputs the context information of the text data into an LDA model for keyword extraction to obtain keyword information of the text data; performs matrix splicing on the local semantic information of the text data and the keyword matrix of the text data to obtain fused semantic information of the text data; inputs the fused semantic information into a pre-trained text classification model, and outputs the text category with the highest probability as the text classification result of the text data. Keywords of the text are extracted by using the LDA model. The LDA model is an unsupervised model, and the training data does not need to be labeled, which greatly reduces the training cost and training time while ensuring the accuracy of text classification.

[0089] At the same time, the embodiment of the present disclosure extracts keywords from text data through the LDA model, and matrix-splices the keyword information with the local semantic information so that the keywords can weight the corresponding parts of the local semantic information, thereby enabling the key information to play a greater role in the final text classification results, thereby helping to improve the accuracy of text classification.

[0090] Based on the above embodiment, the word vector file of the text data is obtained, including: obtaining the text to be classified; performing word segmentation operation on the text to be classified, and removing stop words in the text to be classified to obtain text data; performing word vector training on the text data through an open source tool to obtain the word vector file of the text data.

[0091] The text to be classified is the original text that has not been processed. Specifically, it can be text converted from a user's voice command, or text from the Internet obtained using technologies such as crawlers.

[0092] Word segmentation is a basic step in text processing and the basis of human-computer natural language interaction. Unlike English, there are no word boundaries in Chinese sentences. Therefore, when performing Chinese natural language processing, word segmentation is usually required first. The effect of word segmentation will directly affect the effect of text processing such as part of speech and syntax.

[0093] In some embodiments, Jieba components are used to segment the text to be classified into several words to complete the word segmentation operation. Jieba Chinese word segmentation component can be used for Chinese sentence / part-of-speech segmentation, part-of-speech tagging, unregistered word recognition, and supports functions such as user dictionaries. The component is mainly based on the search algorithm of directed acyclic graphs. Through dynamic programming, the joint probability of the cutting combination of words from back to front is maximized, thereby performing word segmentation as accurately as possible. After completing the word segmentation, the stop words in the corpus are further removed to obtain text data. Stop words are words that have no effect on the text classification results.

[0094] Further, the text data is trained with word vectors through an open source tool to obtain a word vector file of the text data. In some embodiments, the text data can be trained with word vectors through an open source tool Glove to obtain a word vector file. Let the tth sentence in the text be x t , the vector of the i-th word in the sentence is represented by w i ∈R d , the length of the sentence is s, then the sentence can be expressed as:

[0095] x t =[w1;w2;w3…w s ]

[0096] After the word vector training process is performed on the text data, the word vector file is represented as follows:

[0097] v t =[x1; x2; x3…x n ]

[0098] Where n is the length of the text data.

[0099] The disclosed embodiment improves the efficiency and accuracy of the text classification method by preprocessing the text to be classified, performing word segmentation and removing stop words.

[0100] Figure 5 This is a flow chart of a text classification method provided by another embodiment of the present disclosure. Figure 5 As shown, the method includes the following steps:

[0101] S501, obtaining a word vector file of text data.

[0102] S502: Input the word vector file into a bidirectional long short-term memory network for encoding, and output the context information of the text data.

[0103] Specifically, each word in the word vector file is encoded using a forward long short-term memory network to obtain sequence information from left to right; each word in the word vector file is encoded using a reverse long short-term memory network to obtain sequence information from right to left; the sequence information from left to right and the sequence information from right to left are spliced ​​to obtain the context information of the text data for output.

[0104] Use forward LSTM to encode each word w in the word vector file to obtain sequence information from left to right Use reverse LSTM to encode each word w in the word vector file to obtain sequence information from left to right The specific calculation method of LSTM is as follows:

[0105] i t =σ(W i [h t-1 ,v t ]+b i )

[0106] o t =σ(W o [h t-1 ,v t ]+b o )

[0107] f t =σ(W f [h t-1 ,v t ]+b f )

[0108]

[0109]

[0110] h t =ot ⊙tanh(c t )

[0111] Among them, the storage unit c t Used to save historical information at the current moment; i t is the input gate, which determines the amount of change in the information in the storage unit caused by the input vector at the current moment; t is the output gate, which is used to control the output amount of information in the current storage unit; f t is the forget gate, which determines the influence of the historical information at the previous moment on the information in the current storage unit. i , W o , W f ,

[0112] are weight matrices of different types, is the bias vector, d1+d2 and d represent the input vector dimension and hidden state of LSTM respectively, ⊙ represents element multiplication, σ represents the sigmoid function, and h t is the final output.

[0113] Bi-LSTM performs calculations and updates in two directions. The hidden state obtained after Bi-LSTM operation is used as the final word representation of the context, that is, the context information of the text data, which is expressed as:

[0114]

[0115] S503: Calculate the marginal distribution probability of the context information of the text data relative to a preset label sequence, where the preset label is used to indicate whether the text data belongs to a range of a text category corresponding to the preset label.

[0116] Specifically, the sum of the transition score and the emission score of the context information of the text data relative to the preset label sequence is calculated; the sum of the transition score and the emission score of the preset label sequence is normalized to obtain a normalized calculation result; and the marginal distribution probability of the normalized calculation result relative to the preset label sequence is calculated.

[0117] The latent labels introduced in the CRF layer show whether each word in the text data affects a specific aspect of sentiment. Specifically, a latent binary variable z∈{0,1} is introduced to indicate whether each word in the text data is part of the opinion range.

[0118] First, the context information h of sentence x is t1 Input the linear layer and return a vector with the length of the label size. Calculate the sum of the Bi-LSTM transfer score and the emission score. The formula is expressed as:

[0119]

[0120] Where T is the transfer matrix. Before training the model, the scores of the transfer matrix can be randomly initialized. These scores will be updated with the iteration process of training, that is, the CRF layer can learn the constraints on the score calculation by itself. Indicates that from label z t to z t+1 The transfer score, representing the transfer from label z t to z t+1 The transition probability. Represents label z t The emission score at the tth position represents the mapping of the corresponding word vector to the label z at this time t The scalarized probability of .

[0121] Furthermore, the above scores are normalized to obtain:

[0122]

[0123] It can be understood that in the binary variable z∈{0,1}, the marginal probability on the "1" label represents the influence of the word in the current context on the sentiment of the corresponding aspect word. According to the marginal probability calculation method, the marginal distribution probability of the context information of the text data relative to the preset label sequence is obtained, which is expressed as:

[0124]

[0125] S504: Perform matrix concatenation on the marginal distribution probabilities corresponding to each of the preset tags to obtain local semantic information of the text data.

[0126] The marginal distribution probability represents the possibility that the text data belongs to the range of the text category corresponding to the preset label.

[0127] The local semantic information of text data is expressed as:

[0128] q=[s1;s2;...;s a ]

[0129] Where a is the number of conditional random fields in the multiple conditional random fields.

[0130] In some embodiments, a linear chain conditional random field is used in the multiple conditional random fields, and its corresponding definition is as follows: Let X = (X1, X2, ..., X n ), Y=(Y1,Y2,…,Y n ) are all linear random variable sequences. For example, under the condition of a given random variable sequence X, the conditional probability distribution of the random variable sequence Y satisfies the Markov property, as shown in the formula:

[0131] P(Y i |X,Y1,…,Y i-1 ,Y i+1 ,…,Y n )=P(Y i |X,Y i-1 ,Y i+1 )

[0132] Where i = 1, 2, ..., n (when i = 1 and n, only one side is considered), then P(Y|X) is called a linear chain conditional random field. In the labeling problem, X represents the input observation sequence and Y represents the corresponding output tag sequence or state sequence. Figure 6 A linear chain conditional random field probability undirected graph is provided for an embodiment of the present disclosure, and the graph represents the joint probability distribution of a random variable sequence Y under the condition of a given random variable sequence X.

[0133] S505. Calculate the weight value of each topic in at least one preset topic corresponding to the context information based on the LDA algorithm, where each preset topic includes a probability distribution of at least one word.

[0134] As mentioned above, the LDA algorithm can give the topic corresponding to each text in the text set in the form of probability distribution. Probability distribution is used to describe the probability law of random variable values, that is, the LDA algorithm can give multiple preset topics corresponding to the text data, as well as the weight of each preset topic corresponding to the text data.

[0135] Among them, each preset topic refers to a defined professional field or interest field, such as aerospace, biomedicine, information technology, etc., specifically refers to a set of words related to the field, or a probability distribution of a series of words related to the field.

[0136] S506: Sort at least one preset topic in descending order of the weight value, and select a preset number of preset topics with top rankings as target topics.

[0137] The weight value represents the relevance between the text data and the topic. The larger the weight value, the higher the relevance between the text data and a preset topic, and the greater the possibility that the text data belongs to the preset topic; the smaller the weight value, the lower the relevance between the text data and a preset topic, and the lower the possibility that the text data belongs to the preset topic. Therefore, a preset number of preset topics with higher weight values ​​are selected as target topics, so as to effectively capture the keywords corresponding to the preset topics.

[0138] S507: Construct a candidate keyword set according to the probability distribution of the words included in the target topic.

[0139] The target topic selected through the above steps is the preset topic with a high degree of relevance to the text data, and the words contained in each preset topic are words belonging to the topic. Therefore, each word in the candidate keyword set composed of the words contained in the target topic is highly relevant to the text data.

[0140] S508: traverse the context information, extract the words appearing in the keyword set as keywords, and obtain keyword information of the text data.

[0141] The text data is obtained after the data to be classified has been preprocessed by word segmentation, etc. If the words in the text data appear in the candidate keyword set, the words in the text data are extracted. It can be understood that the LDA model processes the context information obtained in the above steps to achieve the functions of S505 to S508, and finally outputs the keyword information corresponding to the text information.

[0142] S509 , performing matrix concatenation of the local semantic information of the text data and the global semantic information of the text data to obtain fused semantic information of the text data.

[0143] Specifically, the splicing direction of the matrix corresponding to the preset configuration parameters is determined according to the preset configuration parameters of the user; the first number of elements of the local semantic information in the splicing direction and the second number of elements of the global semantic information in the splicing direction are obtained; the local semantic information of the text data and the global semantic information of the text data are matrix-spliced ​​to obtain fused semantic information of the text data, wherein the number of elements of the fused semantic information in the splicing direction is the sum of the first number of elements and the second number of elements.

[0144] For matrix splicing, it is necessary to determine the matrix splicing direction first. Take the splicing of two 2*2 matrices as an example. The splicing direction is horizontal or vertical, that is, splicing by row and splicing by column. Each matrix has two elements in the horizontal and vertical directions respectively. When the splicing direction is horizontal, the matrix is ​​spliced ​​by row. The number of elements in the horizontal direction, that is, each row of the spliced ​​matrix should be 4, which is the sum of the number of elements in the horizontal direction of the two spliced ​​matrices, while the number of elements in the vertical direction is still 2. Similarly, when the splicing direction is vertical, the matrix is ​​spliced ​​by column. The number of elements in the vertical direction, that is, each column of the spliced ​​matrix should be 4, which is the sum of the number of elements in the horizontal direction of the two spliced ​​matrices, while the number of elements in the horizontal direction is still 2.

[0145] It can be understood that in the embodiment of the present disclosure, the number of elements in the two matrices of local semantic information and global semantic information in each direction is not limited, and the above matrix splicing process is only used as an example, not a limitation of the embodiment of the present disclosure.

[0146] S510: Input the fused semantic information into a pre-trained text classification model, and output the text category with the highest probability as the text classification result of the text data.

[0147] Specifically, the fused semantic information is input into a Softmax classifier, and the probability that the text data belongs to each text category is output; and the text category with the largest probability is selected and output as the text classification result of the text data.

[0148] The keyword information of the text data and the local semantic information q of the output text data of the CRF layer are concatenated into a matrix to obtain the fused semantic information o, which is passed to the sentiment classification layer. The probability of the text data belonging to each text category is output by the Softmax classifier for final classification, as shown below:

[0149] p=softmax(wo+b)

[0150] Among them, w and b are the parameters of the softmax function.

[0151] The disclosed embodiment fully extracts semantic context information through a bidirectional long short-term memory network, obtains text structure information through a conditional random field, and then captures keyword information through an LDA model, so that key features in the text can play a greater role in text classification, thereby effectively improving the accuracy of text classification.

[0152] Figure 7 The text classification device provided in the embodiment of the present disclosure is a schematic diagram of the structure of the text classification device. The text classification device can be any device with data processing function as described in the above embodiment, or the text classification device can be a component or assembly in any device with data processing function. The text classification device provided in the embodiment of the present disclosure can execute the processing flow provided in the text classification method embodiment, such as Figure 7As shown, the text classification device 70 includes: an acquisition module 71, a first input module 72, a second input module 73, a third input module 74, a splicing module 75, and a classification module 76; wherein the acquisition module 71 is used to acquire a word vector file of text data; the first input module 72 is used to input the word vector file into a bidirectional long short-term memory network for encoding, and output the context information of the text data; the second input module 73 is used to input the context information of the text data into a multiple conditional random field to obtain local semantic information of the text data, and the local semantic information is used to characterize the structural information of the text data; the third input module 74 is used to input the context information of the text data into an LDA model for keyword extraction to obtain keyword information of the text data; the splicing module 75 is used to perform matrix splicing of the local semantic information of the text data with the keyword matrix of the text data to obtain fused semantic information of the text data; the classification module 76 is used to input the fused semantic information into a pre-trained text classification model, and output the text category with the highest probability as the text classification result of the text data.

[0153] Optionally, the third input module 74 includes a first calculation unit 741, a sorting unit 742, a construction unit 743, and an extraction unit 744; wherein the first calculation unit 741 is used to calculate the weight value of each topic in at least one preset topic corresponding to the context information based on the LDA algorithm, and each preset topic includes the probability distribution of at least one word; the sorting unit 742 is used to sort at least one preset topic in order from large to small according to the weight value, and select a preset number of preset topics with the top ranking as target topics; the construction unit 743 is used to construct a candidate keyword set according to the probability distribution of words contained in the target topic; the extraction unit 744 is used to traverse the context information, extract the words appearing in the keyword set as keywords, and obtain the keyword information of the text data.

[0154] Optionally, the acquisition module 71 includes a first acquisition unit 711, a preprocessing unit 712, and a training unit 713; wherein the first acquisition unit 711 is used to acquire the text to be classified; the preprocessing unit 712 is used to perform word segmentation on the text to be classified, and remove stop words in the text to be classified to obtain text data; the training unit 713 is used to perform word vector training on the text data through an open source tool to obtain a word vector file of the text data.

[0155] Optionally, optionally, the first input module 72 includes a first encoding unit 721, a second encoding unit 722, and a first splicing unit 723; wherein the first encoding unit 721 is used to use a forward long short-term memory network to encode each word in the word vector file to obtain sequence information from left to right; the second encoding unit 722 is used to use a reverse long short-term memory network to encode each word in the word vector file to obtain sequence information from right to left; the first splicing unit 723 is used to splice the sequence information from left to right and the sequence information from right to left to obtain the context information of the text data for output.

[0156] Optionally, the second input module 73 includes a second calculation unit 731 and a second splicing unit 732; the second calculation unit 731 is used to calculate the marginal distribution probability of the context information of the text data relative to a preset label sequence, and the preset label is used to indicate whether the text data belongs to the range of the text category corresponding to the preset label; the second splicing unit 732 is used to splice the marginal distribution probabilities corresponding to each of the preset labels to obtain local semantic information of the text data.

[0157] Optionally, the second calculation unit 731 is specifically used to calculate the sum of the transition score and the emission score of the context information of the text data relative to a preset label sequence; perform normalization calculation on the sum of the transition score and the emission score of the preset label sequence to obtain a normalized calculation result; and calculate the marginal distribution probability of the normalized calculation result relative to the preset label sequence.

[0158] Optionally, the splicing module 75 includes a determination unit 751, a second acquisition unit 752, and a third splicing unit 753; wherein the determination unit 751 is used to determine the splicing direction of the matrix corresponding to the preset configuration parameters according to the user's preset configuration parameters; the second acquisition unit 752 is used to obtain the first number of elements of the local semantic information in the splicing direction and the second number of elements of the keyword matrix in the splicing direction; the third splicing unit 753 is used to perform matrix splicing on the local semantic information of the text data and the keyword matrix of the text data to obtain fused semantic information of the text data, wherein the number of elements of the fused semantic information in the splicing direction is the sum of the first number of elements and the second number of elements.

[0159] Figure 7 The text classification device of the illustrated embodiment can be used to execute the technical solution of the above-mentioned method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0160] In addition, an embodiment of the present disclosure also provides a vehicle, which includes the text classification device as described in the above embodiment.

[0161] Figure 8 Schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. The electronic device may be a device with data processing function as described in the above embodiment. The electronic device provided in an embodiment of the present disclosure may execute the processing flow provided in an embodiment of the text classification method, such as Figure 8 As shown, the electronic device 80 includes: a memory 81, a processor 82, a computer program and a communication interface 83; wherein the computer program is stored in the memory 81 and is configured so that the processor 82 executes the text classification method as described above.

[0162] In addition, an embodiment of the present disclosure further provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement the text classification method described in the above embodiment.

[0163] In addition, an embodiment of the present disclosure further provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, the text classification method as described above is implemented.

[0164] 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, but not limited to, 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).

[0165] 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.

[0166] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0167] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A text classification method, characterized in that: The method comprises: Get the word vector file of text data; Input the word vector file into a bidirectional long short-term memory network for encoding, and output context information of the text data; Inputting the context information of the text data into a multiple conditional random field to obtain local semantic information of the text data, wherein the local semantic information is used to represent structural information of the text data; Inputting the context information of the text data into the LDA model to extract keywords, thereby obtaining keyword information of the text data; Performing matrix concatenation of the local semantic information of the text data and the keyword matrix of the text data to obtain fused semantic information of the text data; The fused semantic information is input into a pre-trained text classification model, and the text category with the highest probability is output as the text classification result of the text data.

2. The method according to claim 1, characterized in that The step of inputting the context information of the text data into the LDA model to extract keywords and obtain keyword information of the text data includes: Calculate the weight value of each topic in at least one preset topic corresponding to the context information based on the LDA algorithm, each preset topic including the probability distribution of at least one word; Sorting at least one preset topic in descending order of the weight value, and selecting a preset number of preset topics with the highest ranking as target topics; According to the probability distribution of the words contained in the target topic, a candidate keyword set is formed; The context information is traversed, and words appearing in the keyword set are extracted as keywords to obtain keyword information of the text data.

3. The method according to claim 1, characterized in that The step of obtaining a word vector file of text data includes: Get the text to be classified; Performing a word segmentation operation on the text to be classified and removing stop words in the text to be classified to obtain text data; The text data is trained with word vectors using an open source tool to obtain a word vector file for the text data.

4. The method according to claim 1, characterized in that: The step of inputting the word vector file into a bidirectional long short-term memory network for encoding and outputting the context information of the text data comprises: Use a forward long short-term memory network to encode each word in the word vector file to obtain sequence information from left to right; Encode each word in the word vector file using a reverse long short-term memory network to obtain sequence information from right to left; The context information of the text data is obtained by splicing the sequence information from left to right and the sequence information from right to left to output.

5. The method according to claim 1, characterized in that The method according to claim 1, characterized in that the step of inputting the context information of the text data into multiple conditional random fields to obtain local semantic information of the text data comprises: Calculating the marginal distribution probability of the context information of the text data relative to a preset label sequence, wherein the preset label is used to indicate whether the text data belongs to a range of a text category corresponding to the preset label; The marginal distribution probabilities corresponding to each of the preset labels are concatenated in a matrix to obtain local semantic information of the text data, wherein the marginal distribution probabilities represent the possibility that the text data belongs to the range of the text category corresponding to the preset label.

6. The method according to claim 5, characterized in that The calculating the marginal distribution probability of the context information of the text data relative to a preset tag sequence includes: Calculating the sum of a transition score and an emission score of the context information of the text data relative to a preset tag sequence; Performing normalization calculation on the sum of the transition score and the emission score of the preset tag sequence to obtain a normalized calculation result; The marginal distribution probability of the normalized calculation result relative to the preset label sequence is calculated.

7. The method according to claim 1, characterized in that The step of performing matrix concatenation of the local semantic information of the text data and the keyword matrix of the text data to obtain fused semantic information of the text data includes: Determine, according to a preset configuration parameter of a user, a splicing direction of a matrix corresponding to the preset configuration parameter; Obtaining the first number of elements of the local semantic information in the splicing direction and the second number of elements of the keyword matrix in the splicing direction; The local semantic information of the text data is matrix-joined with the keyword matrix of the text data to obtain fused semantic information of the text data, wherein the number of elements of the fused semantic information in the joining direction is the sum of the first number of elements and the second number of elements.

8. A text classification device, characterized in that: The device comprises: The acquisition module is used to obtain the word vector file of text data; A first input module is used to input the word vector file into a bidirectional long short-term memory network for encoding, and output context information of the text data; A second input module, used for inputting the context information of the text data into a multiple conditional random field to obtain local semantic information of the text data, wherein the local semantic information is used to represent the structural information of the text data; A third input module is used to input the context information of the text data into the LDA model to extract keywords, so as to obtain keyword information of the text data; A splicing module, used for performing matrix splicing on the local semantic information of the text data and the keyword matrix of the text data to obtain fused semantic information of the text data; The classification module is used to input the fused semantic information into a pre-trained text classification model and output the text category with the highest probability as the text classification result of the text data.

9. An electronic device, characterized in that: include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement the method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Conflict detection method and system for standard online collaborative compilation platform

    CN120278125A

  • A conflict detection method and system for a standard online collaborative compilation platform

    CN120278125B