A text sentiment classification method for multiple fields

By combining word embedding, ALBERT model and LDA model in text emotion classification, and integrating K-means clustering algorithm to extract text topic information, the problem of insufficient accuracy of text emotion classification in the existing technology is solved, and cross-domain emotion classification is realized. The speed and accuracy are improved.

CN117390131BActive Publication Date: 2024-09-24WUXI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310815104.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-04
Publication Date
2024-09-24
Estimated Expiration
2043-07-04

AI Technical Summary

Technical Problem

Existing text sentiment classification methods have insufficient accuracy in identifying text labels, resulting in inaccurate sentiment analysis results and inability to effectively express the meaning of the text.

Method used

A multi-domain text sentiment classification method is used to preprocess the text data with labels in the target domain, and use word embedding, segment embedding and position embedding to vectorize the text data, combine the ALBERT model and LDA model, and integrate K-means Clustering algorithm extracts text topic information, and finally calculates emotion probability through Softmax classifier for cross-domain emotion classification.

Benefits of technology

It achieves the rapid and accurate acquisition of emotion labels in the target field, improves the accuracy of emotion analysis results, solves the problem of low accuracy of the traditional LDA model in small samples, and improves the text emotion classification model through the fusion of the ALBERT model. performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117390131B
    Figure CN117390131B
Patent Text Reader

Abstract

The invention discloses a text sentiment classification method for multiple fields, comprising: obtaining labeled text data of a target field and preprocessing it, training a word embedding layer, embedding an LDA model for extracting text topic information in an ALBERT model, and fusing a K-means clustering algorithm in the LDA model; inputting a word vector sequence into the LDA model for unsupervised training, extracting text topic information, and obtaining a topic feature vector of a "document-topic" distribution; inputting the topic feature vector into a K-means clustering algorithm for secondary clustering, and outputting an optimal topic feature vector using cosine similarity; iteratively sampling through a Gibbs sampling method, and obtaining a "topic-word" distribution and a "comment-topic" distribution after the LDA model converges; training a text sentiment classification model, calculating the sentiment probability of a sentiment classification label through the trained text sentiment classification model, and taking the label with the largest sentiment probability as a target data label, thereby realizing cross-field text sentiment classification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of sentiment classification, and in particular to a text sentiment classification method for multiple fields. Background Art

[0002] The information that document-level sentiment analysis can provide is relatively limited. The text labels identified by existing text sentiment polarity classification methods have low accuracy, resulting in the inability of the classified labels to accurately express the meaning of the text, which is not conducive to sentiment analysis of the text. Summary of the invention

[0003] The present invention provides a text sentiment classification method for multiple fields, which is used to classify the sentiment polarity of text and improve the accuracy of sentiment analysis results.

[0004] To achieve the above effects, the technical solution of the present invention is as follows:

[0005] A text sentiment classification method for multiple fields includes the following steps:

[0006] S1: Obtain labeled text data in the target domain and preprocess it, input the preprocessed text data into the word embedding layer preset by the text sentiment classification model, and vectorize the text data using word embedding, segment embedding, and position embedding to obtain a word vector sequence, wherein the word vector sequence includes a word vector, a segment vector, and a position vector;

[0007] The text sentiment classification model consists of a word embedding layer, an ALBERT model, a multi-task layer and a classifier connected in sequence;

[0008] S2: Train the word embedding layer, embed the LDA model for text topic information extraction into the ALBERT model, and integrate the K-means clustering algorithm into the LDA model;

[0009] S3: Input the word vector sequence into the LDA model for unsupervised training, extract the text topic information, and obtain the topic feature vector of the "document-topic" distribution;

[0010] S4: After the topic feature vector is input into the K-means clustering algorithm for secondary clustering, the cosine similarity is used to output the optimal topic feature vector; the Gibbs sampling method is used for iterative sampling, and the "topic-word" distribution and "comment-topic" distribution are obtained after the LDA model converges;

[0011] S5: Train the text sentiment classification model. Calculate the sentiment probability of the sentiment classification label through the trained text sentiment classification model, and use the label with the largest sentiment probability as the target data label, so as to achieve cross-domain text sentiment classification.

[0012] A deep learning method is implemented to simultaneously learn cross-domain knowledge from multiple fields and transfer it to the target domain, so that the model can quickly and accurately obtain sentiment labels in the target domain.

[0013] Furthermore, after step S1, the method further includes: constructing a dictionary: taking the token sequence and the special characters used in the training as the dictionary; and reserving 99 unused placeholders, namely [unused1] to [unused99].

[0014] Furthermore, the preprocessing in step S1 is specifically as follows:

[0015] Normalize text data and remove URL links, remove stop words, and replace emojis with their original text form.

[0016] Furthermore, the normalization process is: obtaining text data from the network, annotating the text data with sentiment polarity, and then deleting empty data, deleting duplicate data, deleting non-text data, and deleting meaningless symbol data.

[0017] Furthermore, in step S1, the text data is vectorized using word embedding, segment embedding, and position embedding to obtain a word vector sequence, specifically:

[0018] Input the text data as the input vector to the word embedding layer and output the feature vector W ij ; Eigenvector W ij Input to the ALBERT model to extract context features and output the representation feature vector corresponding to each input vector , the characterizing feature vector is a sequence of word vectors.

[0019] Furthermore, the text sentiment classification model is composed of a word embedding layer, an ALBERT model, a multi-task layer and a classifier connected in sequence; specifically:

[0020] Word embedding layer: as input, it realizes text vectorization; after the preprocessed text data is embedded in words, segments, positions and topics, each word is mapped into four output feature vectors; the feature vectors are: word vector, segment vector, position vector, topic feature vector;

[0021] ALBERT model: It consists of a bidirectional Transformer network structure. The feature vector output by the word embedding layer is used as the input of the ALBERT model. The feature vector output by the word embedding layer is used by the ALBERT model to extract contextual features for target domain data detection and output the corresponding representation feature vector for each input vector. The LDA model is used to extract topic information from the input text.

[0022] Multi-task layer: The ALBERT model learns parameters on a large amount of unlabeled data through the sentence order prediction SOP and masked language model tasks; the sentence order prediction SOP task and the masked language model task are retained, and the sentiment classification task is added; the masked language model (MLM) task means that the ALBERT model randomly extracts 15% of the words in the input text for masking (Mask), and the masked words have an 80% probability of being replaced with the [MASK] symbol, a 10% probability of being replaced with any word in the data set, and a 10% probability of not making any changes. The masked language model (MLM) task is to solve the problem of semantic single items; the [CLS] output by the ALBERT model is used as the input of the sentiment classification (SC) task; through Dropout, a part of the hidden nodes in the ALBERT model are randomly discarded to reduce the number of features and prevent overfitting;

[0023] Softmax classifier: The Softmax classifier sets the weight probability in the interval [0,1]. The vector representation is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network to obtain the distribution of sentiment probability.

[0024] Furthermore, the training of the word embedding layer in step S2 specifically includes the following steps:

[0025] S21: Obtain unlabeled text data, use Jieba word segmentation to split each sentence in the unlabeled text data into a single word sequence;

[0026] S22: Use the WordPiece model to convert the word sequence into a WordPiece vector sequence;

[0027] S23: Determine whether there is a new sentence input. If there is a new sentence input, use the WordPiece model to convert the new sentence into a WordPiece vector sequence; if there is no new sentence input, terminate;

[0028] S24: Determine whether the sequence length of each sentence in the unlabeled text data exceeds the value of the maximum sequence length. If the length exceeds the maximum sequence length, truncate the sentence into a front sequence and a back sequence, and retain the front sequence; perform a padding operation on the sentences whose length is less than the maximum sequence length;

[0029] S25: Encode each sentence pair in the label text data, traverse the WordPiece vector sequence, and add [CLS] and [SEP] characters at the beginning and end of each sentence respectively;

[0030] S26: Output a token sequence with [CLS] and [SEP] characters, superimpose the position vector of each word with the word vector, perform position encoding on each word in order according to the length of the sentence, and obtain the output result of the position encoding; sum the word vector, segment vector, and position vector to obtain a word vector summation result containing position information, and obtain a trained word embedding layer.

[0031] Furthermore, step S4 is specifically as follows:

[0032] The word vector sequence is input into the LDA model for unsupervised training. The common features of the sample vectors are extracted using the latent Dirichlet distribution to obtain intermediate variables. The intermediate variables generated by the LDA model are input into the K-means clustering algorithm to assign a topic feature vector that can represent the features of the entire group of vectors to each group of word vectors; the topic feature vector is fused with the word vector, segment vector and position vector output by the word embedding layer to obtain a fused vector, which is input into the ALBERT model to output cosine similarity. Cosine similarity evaluates similarity by calculating the cosine value of the angle between two vectors; cosine similarity plots the fused vector into the two-dimensional vector space according to the coordinate value;

[0033] Text data express, is the number of comments, is a comment vector that conforms to the “comment-topic” distribution; the implicit topic share assigned to each comment is , each comment contains Sentences, words, each with a potential theme; is the word vector form of the comment text; is the “topic-word” distribution, K is the number of topics; and Respectively represent the hyperparameters of the “comment-topic” and “topic-word” distributions subject to the prior Dirichlet distribution; the “comment-topic” distribution formula P is:

[0034] .

[0035] Furthermore, step S5 is specifically as follows:

[0036] The word vector, segment vector, position vector and topic feature vector output by the LDA model are input into the ALBERT model to construct a Softmax classifier, and the weights are probabilized in the interval [0,1] to achieve the classification of sentiment polarity; the vector representation is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network to obtain the sentiment probability distribution; the first word [CLS] of the sentence is taken for the classification task using the Softmax classifier; the trained text sentiment classification model calculates the sentiment probability of the sentiment classification label and takes the label with the largest sentiment probability as the target data label, thereby achieving cross-domain text sentiment classification.

[0037] Furthermore, the vector representation is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network to obtain the sentiment probability distribution, specifically:

[0038] The vector representation T is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network. , we get the distribution of emotion probability P:

[0039] In the formula, and is the parameter vector and bias to be learned; the sentiment polarity with the highest probability is taken as the prediction result; Softmax classifier P i The calculation formula is:

[0040] In the formula, is a vector, and is an element in the vector matrix, is the dimension of the matrix.

[0041] Compared with the prior art, the technical solution of the present invention has the following beneficial effects:

[0042] A deep learning method is implemented to simultaneously learn cross-domain knowledge from multiple fields and transfer it to the target domain, so that the model can quickly and accurately obtain sentiment labels in the target domain.

[0043] The present invention is used to classify the sentiment polarity of text and improve the accuracy of sentiment analysis results; the text vector learned by the ALBERT pre-training model is used as the input of the LDA model, which solves the problem that the traditional LDA model cannot extract sentiment features in combination with the context. The LDA model is combined with the K-means clustering algorithm to improve the problem of low accuracy of the LDA model in small samples. At the same time, the topic feature vector output by the LDA model is fused with the word vector of the ALBERT model, which greatly improves the performance of the text sentiment classification model. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The drawings are only used for illustrative purposes and are not to be construed as limitations of the present invention. To better illustrate the present embodiment, some parts of the drawings may be omitted, enlarged, or reduced, and do not represent the size of actual products. For those skilled in the art, it is understandable that some well-known structures and their descriptions may be omitted in the drawings.

[0045] Figure 1 A schematic diagram of a text sentiment classification method provided by an embodiment of the present invention;

[0046] Figure 2 is a flow chart of the text word embedding layer training method of the present invention;

[0047] Figure 3 It is a flow chart for implementing the training method of the text sentiment classification model of the present invention;

[0048] Figure 4 It is a schematic diagram of the overall architecture of the text sentiment classification model according to an embodiment of the present invention;

[0049] Figure 5 It is a structural schematic diagram of the LDA model + K-means clustering algorithm of the text sentiment classification model of the present invention;

[0050] Figure 6 It is a schematic diagram of the structure of the Transformer network of the present invention;

[0051] Figure 7 Schematic diagram of the ALBERT model architecture according to an embodiment of the present invention;

[0052] Figure 8 is a line graph of the model effect under different proportions of training sets in the embodiment of the present invention;

[0053] Fig. 9 It is a line graph of the change in accuracy of different models under different epochs in the embodiment of the present invention. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0055] Example

[0056] For easier understanding, see Figure 1 An embodiment of a text sentiment classification method for multiple fields provided by the present invention comprises the following steps:

[0057] S1: Obtain labeled text data in the target domain and preprocess it, input the preprocessed text data into the word embedding layer preset by the text sentiment classification model, and vectorize the text data using word embedding, segment embedding, and position embedding to obtain a word vector sequence (i.e., a feature vector output by the word embedding layer), wherein the word vector sequence includes a word vector, a segment vector, and a position vector;

[0058] The text sentiment classification model consists of a word embedding layer, an ALBERT model, a multi-task layer and a classifier connected in sequence;

[0059] S2: Train the word embedding layer, embed the LDA model for text topic information extraction into the ALBERT model, and integrate the K-means clustering algorithm into the LDA model;

[0060] S3: Input the word vector sequence into the LDA model for unsupervised training, extract the text topic information, and obtain the topic feature vector of the "document-topic" distribution; that is, the LDA model uses the cosine similarity (cosine distance) between the high-frequency word distribution and comments of each topic to calculate the topic feature vector;

[0061] S4: After the topic feature vector is input into the K-means clustering algorithm for secondary clustering, the cosine similarity is used to output the optimal topic feature vector to obtain more accurate topic sentiment information; through the Gibbs sampling method, the "topic-word" distribution and "comment-topic" distribution are obtained after the LDA model converges;

[0062] S5: Train the text sentiment classification model. Calculate the sentiment probability of the sentiment classification label through the trained text sentiment classification model, and use the label with the largest sentiment probability as the target data label, so as to achieve cross-domain text sentiment classification.

[0063] The pre-training model reduces the training time and computing cost; the user's emotions are complex, and the comment text contains many implicit emotions such as sarcasm, which cannot be distinguished by traditional machine learning; and deep learning requires a large number of samples and high computing power, resulting in high training costs. The method of the present invention can be applied to the sentiment classification of texts such as , which helps relevant departments to more accurately grasp the public opinion trend of public events.

[0064] It is understandable that the ALBERT model is an improvement on the BERT model, which reduces the size of the model by reducing parameters. The word embedding layer of the ALBERT model is a matrix, the input is the size of the dictionary, that is, 30K, and the output is equal to the number of hidden layer units, that is, H; therefore, the word embedding layer can learn a total of parameters; ALBERT's input contains word vector information, paragraph information (paragraph vector), position vector, and CLS and SEP tags are added at the beginning and end of the text input respectively.

[0065] The present invention realizes text secondary clustering by embedding the LDA model in the ALBERT model, which greatly improves the classification effect of the model; the specific structure of the LDA model is as follows Figure 5 As shown; in order to improve the utilization rate of the topic information extracted by the LDA model, the present invention integrates the K-means clustering algorithm in the LDA model, and uses the "document-topic" distribution extracted by the LDA model as the input of the K-means clustering algorithm; after the potential topic information of the "document-topic" distribution in the LDA model is secondary clustered by the K-means clustering algorithm, the cosine similarity is used to output the optimal topic feature vector; due to the limitations of the LDA model itself, the output topic feature vector is independent of the text sentence and the order of words, and the ALBERT model has modules such as position embedding that can fully consider the overall semantic information of the context, the relationship between the position order of words, and the number of times the words appear in the text, so the present invention uses the matrix generated by the dimensionality reduction of the word embedding layer of the ALBERT model as the input of the LDA model to improve the sentiment topic extraction capability of the LDA model.

[0066] It should be noted that the LDA model is a Bayesian model that assigns a keyword to each document in the text data in the form of a probability distribution. Each keyword is updated through continuous iterations, and text classification and topic clustering are performed based on the "comment-topic" distribution. The LDA model is a probabilistic graphical model with a clear hierarchical structure. The outermost layers are the document collection layer, document layer, and word layer.

[0067] It should be noted that the basic logic of the K-means clustering algorithm is to first define the number of centroids, and then assign the objects to the nearest centroids through continuous cycles; in each step, it is necessary to recalculate new centroids and then reallocate the objects until no changes are made; in order to improve the utilization rate of LDA to extract topic information, the present invention integrates the K-means clustering algorithm into the LDA model, and uses the "document-topic" distribution extracted by LDA as the input of the K-means clustering algorithm.

[0068] As a preferred technical solution, in this embodiment, step S1 also includes: building a dictionary: using the token sequence and special characters used in training as the dictionary; reserving 99 unused placeholders, namely [unused1] to [unused99], and adding new words using 99 placeholders without destroying the embedding of the text sentiment classification model, such as using [unused1] to represent a space; wherein the special characters are [PAD], [CLS], [SEP], [MASK], [UNK], etc.

[0069] As a preferred technical solution, in this embodiment, the preprocessing in step S1 is specifically: normalizing the text data, removing URL links, removing stop words, and replacing emoticons with their original text forms. The text data is divided into a training set and a test set, wherein the training set randomly extracts 90% of the positive and negative emotional text data, and the test set is the remaining 10%, to ensure that the data is not repeated and more accurately reflect the classification effect.

[0070] As a preferred technical solution, in this embodiment, the normalization processing is: obtaining text data from the network, manually annotating the text data with sentiment polarity, and then deleting empty data, deleting duplicate data, deleting non-text data, and deleting meaningless symbol data.

[0071] As a preferred technical solution, in this embodiment, in step S1, the text data is vectorized using word embedding, segment embedding and position embedding to obtain a word vector sequence, specifically:

[0072] Input the text data as the input vector to the word embedding layer and output the feature vector W ij ; Eigenvector W ij Input to the ALBERT model to extract context features and output the representation feature vector corresponding to each input vector , the characterizing feature vector is a sequence of word vectors.

[0073] As a preferred technical solution, in this embodiment, Figure 4 , the text sentiment classification model consists of a word embedding layer, an ALBERT model, a multi-task layer and a classifier connected in sequence; specifically:

[0074] Word embedding layer: as input, realize text vectorization; after the preprocessed text data is word embedded (word embedding), segment embedded (position embedding), position embedded (segment embedding) and topic embedded, each word is mapped into 4 output feature vectors; the feature vectors are: word vector, segment vector, position vector, topic feature vector;

[0075] ALBERT model: It consists of a bidirectional Transformer network structure. The feature vector output by the word embedding layer is used as the input of the ALBERT model. The feature vector output by the word embedding layer is used by the ALBERT model to extract contextual features for target domain data detection and output the corresponding representation feature vector for each input vector. The LDA model is used to extract topic information from the input text.

[0076] Multi-task layer: The ALBERT model learns parameters on a large amount of unlabeled data through the sentence order prediction SOP and masked language model (MLM) tasks; the sentence order prediction SOP task and masked language model (MLM) task of the original ALBERT model are retained, and the sentiment classification (SC) task is added; the masked language model (MLM) task means that the ALBERT model randomly extracts 15% of the words in the input text for masking (Mask), and the masked words have an 80% probability of being replaced with the [MASK] symbol and a 10% probability of being replaced with the words in the dataset. For any word, there is a 10% probability that no change will be made. The masked language model (MLM) task is to solve the problem of single semantic items. The [CLS] output by the ALBERT model is used as the input of the sentiment classification (SC) task. Through Dropout, a part of the hidden nodes in the ALBERT model is randomly discarded to reduce the number of features and prevent overfitting. The present invention combines ALBERT with LDA and K-means models to form an ALBERT-LDA-K-means (text classification) model, which is used to classify the sentiment polarity of comments.

[0077] Softmax classifier: The Softmax classifier sets the weight probability in the interval [0,1]. The vector representation is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network to obtain the distribution of sentiment probability.

[0078] It should be noted that the ALBERT model structure is as follows Figure 7 As shown, Trm represents the Transformer network of the ALBERT model. E represents the feature vector, T Represents vector representation; the ALBERT model consists of an encoder structure of a bidirectional Transformer network, where the Transformer network structure is as follows Figure 6As shown in the figure, ALBERT can be unsupervised pre-trained on large-scale datasets to obtain a large number of prior parameters, and then further trained on labeled datasets in a certain field. A large number of experiments have shown that when the amount of data is insufficient, fine-tuning the pre-trained model will transfer the sentiment parameters learned in pre-training to a small sample dataset to obtain better classification results. ALBERT is a model composed of 12 encoder modules of the Transformer network stacked together; each encoder inputs token embedding, segment embedding, and position embedding; the input embedding in the Transformer network model is split into token embedding and segment embedding; the position encoding in the Transformer network is changed to position embedding.

[0079] As a preferred technical solution, in this embodiment, Figure 2 , step S2 is to train the word embedding layer, specifically including the following steps:

[0080] S21: Obtain a large amount of unlabeled text data through crawlers and open source libraries, and use Jieba word segmentation to split each sentence in the unlabeled text data into a single word sequence;

[0081] S22: Use the WordPiece model to convert the word sequence into a WordPiece vector sequence;

[0082] S23: Determine whether there is a new sentence input. If there is a new sentence input, use the WordPiece model to convert the new sentence into a WordPiece vector sequence; if there is no new sentence input, terminate;

[0083] S24: Determine whether the sequence length of each sentence in the unlabeled text data exceeds the value of the maximum sequence length (max_seq_length). If the length exceeds the maximum sequence length (max_seq_length), the sentence is truncated into a front sequence and a back sequence, and the front sequence is retained; for sentences whose length is less than the maximum sequence length (max_seq_length), a padding operation is performed;

[0084] S25: Encode each sentence pair in the label text data, traverse the WordPiece vector sequence, and add [CLS] and [SEP] characters at the beginning and end of each sentence respectively;

[0085] S26: Output a token sequence with [CLS] and [SEP] characters, superimpose the position vector of each word with the word vector, perform position encoding on each word in order according to the length of the sentence, and obtain the output result of the position encoding; sum the word vector, segment vector, and position vector to obtain a word vector summation result containing position information, and obtain a trained word embedding layer.

[0086] It should be noted that after obtaining a summation result of word vectors containing position information, the input word embedding of the text sentiment classification model is completed, and the word vectors are deeply operated to learn the text sequence parameter information of the data set. Token means tag in lexical analysis. In natural language processing, generally speaking, Token represents "word"; in natural language preprocessing, a very important step is to segment the collected sentences and decompose a sentence into a list of "words".

[0087] Among them, the position code only contains the position information of the word and has nothing to do with the contextual semantics of the sentence. For different input sequences, although the contents of the input sequences are different, their position codes are the same, so the result vector of the position code has nothing to do with what words are transmitted in the actual sentence. Regardless of the content of the transmitted data, their position codes are the same.

[0088] As a preferred technical solution, in this embodiment, step S4 is specifically as follows: input the vector data set output by the word embedding layer into the LDA model + K-means clustering algorithm; the present invention realizes text secondary clustering by embedding the LDA model + K-means clustering algorithm in the ALBERT model, which greatly improves the classification effect of the model. Input the word vector sequence into the LDA model for unsupervised training, use the latent Dirichlet distribution to extract the common features of the sample vectors, obtain intermediate variables, input the intermediate variables generated by the LDA model into the K-means clustering algorithm, and assign a topic feature vector that can represent the features of the entire group of vectors to each group of word vectors; fuse the topic feature vector with the word vector, segment vector and position vector output by the word embedding layer to obtain a fused vector, input the fused vector into the ALBERT model, and output cosine similarity (also known as cosine similarity). Cosine similarity evaluates the similarity by calculating the cosine value of the angle between two vectors; cosine similarity plots the fused vector into the two-dimensional vector space according to the coordinate value;

[0089] Take comments as an example. Figure 5 , the single circle in the LDA model structure represents the latent variable, the double circle represents the observable variable, the rectangle represents repeated sampling (the letter in the lower right corner is the number of repeated sampling), and the arrow represents the dependency between two variables. The text data (i.e., the comment vector set) is represented by express, is the number of comments, is a comment vector that conforms to the “comment-topic” distribution; the implicit topic share assigned to each comment is , each comment contains Sentences, words, each with a potential theme; is the word vector form of the comment text; is the “topic-word” distribution, K is the number of topics; and Respectively represent the hyperparameters of the “comment-topic” and “topic-word” distributions subject to the prior Dirichlet distribution; the “comment-topic” distribution formula P is:

[0090] .

[0091] As a preferred technical solution, in this embodiment, step S5 is specifically as follows: the word vector, segment vector, position vector and topic feature vector output by the LDA model are input into the ALBERT model, a Softmax classifier is constructed, and the weight is probabilized in the interval [0,1] to realize the classification of sentiment polarity; the vector representation is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network to obtain the sentiment probability distribution; the first word [CLS] of the sentence is taken to perform the classification task using the Softmax classifier; the trained text sentiment classification model calculates the sentiment probability of the sentiment classification label, and takes the label with the largest sentiment probability as the target data label, thereby realizing cross-domain text sentiment classification.

[0092] As a preferred technical solution, in this embodiment, the vector representation is mapped to the emotion classification space through the self-attention mechanism of the Transformer network to obtain the emotion probability distribution, specifically:

[0093] The vector representation T is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network. , we get the distribution of emotion probability P:

[0094] In the formula, and is the parameter vector and bias to be learned; the sentiment polarity with the highest probability is taken as the prediction result; Softmax classifier P i The calculation formula is:

[0095] In the formula, is a vector, and is an element in the vector matrix, is the dimension of the matrix.

[0096] As a preferred technical solution, in this embodiment, the encoder of the ALBERT model uses a Transformer network, such as Figure 6 , the text data is converted into a word vector sequence through the word embedding layer as the input of the Transformer network in the ALBERT model; because the self-attention mechanism of the Transformer network cannot model the position information of the input text data, the text data is encoded as input and the text position information is added after positional encoding (Positional Encoding) after input; then, in order to solve the problem of memory bias in the process of information transmission, the input word vector sequence is input as a residual connection to the residual connection & normalization layer; in order to reduce the difficulty of training and make the text sentiment classification model pay more attention to differential information, the Transformer network adds the input of the text sentiment classification model with the output of the previous layer, and then performs layer normalization; at the same time, the input sequence is input into the multi-head attention mechanism (Multi-HeadAttention) of the Transformer network as keys, value, and query, and the formula is as follows:

[0097]

[0098] Where K, V, and Q refer to the key matrix (keys), value matrix (value), and query matrix (query), respectively. All three are the same input word vector matrix; the number of multi-head attention mechanisms in each Transformer network is, the text sentiment classification model contains 12 encoders, and each encoder contains 12 multi-head attention mechanism blocks; is a weight matrix; the Softmax classifier calculates the weight coefficient of a word to other words, and uses the grammatical structure and semantic information learned by the Transformer network to classify the text sentiment; in the text sentiment classification model, the output formula of the self-attention mechanism of the Transformer network is as follows:

[0099]

[0100] In the formula, is a reconciliation factor used to stabilize the module training gradient; Figure 6 , the output of the first residual connection & normalization layer is used as the input of the feedforward neural network, and the output of the feedforward neural network is output after passing through the next residual connection & normalization layer; is the number of superimposed layers. The ALBERT model uses a total of 12 layers. The Transformer network can extract text features in parallel and then map the text features to the sample tag space through the fully connected layer.

[0101] The word vector matrix is ​​input into the Transformer network, and the parameter of the self-attention mechanism of the Transformer network is 4H; first, through the self-attention mechanism of the multi-head Transformer network, Q (query), K (key), and V (value) are projected once respectively, and the dimension of each projection is 64. The number of heads A is multiplied by the dimension 64 to get H; the heads of the three projection matrices of Q, K, and V are merged to get an H×H matrix, and after getting the output, they are projected again to get an H×H matrix; then through the multi-layer perceptron (MLP) part, the MLP contains two fully connected layers, the first layer inputs H and outputs 4H, and the second layer inputs 4H and outputs H, that is, the size of each matrix is ​​H×4H, and two are 8H 2 ; These are the parameters of a Transformer network block. After multiplying the number of encoders L, the total number of parameters is the word embedding layer parameters plus the bidirectional Transformer network parameters, which is .

[0102] The representation necklace output by the Transformer network is used for training tasks; for the word prediction task, 15% of the tokens in the sentence are randomly masked, and the masked tokens have a 10% probability of being replaced by other tokens, a 10% probability of not making any changes, and an 80% probability of being replaced by the [MASK] character; then the final hidden vector output at the masked token position is passed through the Softmax classifier to predict the masked token; for the sentence coherence prediction task, specifically, its positive example is the same as NSP, but the negative example is constructed by selecting two consecutive sentences in a document and swapping their order; in this way, the two sentences will have the same topic, and the text sentiment classification model will learn more about the coherence between sentences; for sentence-level prediction (SOP); SOP focuses on inter-sentence coherence and is used to solve the problem of inefficient NSP loss in predicting the next word.

[0103] It can be understood that the model structures of ALBERT and BERT are both composed of multiple superpositions of Transformer network layers; ALBERT adds two mechanisms, decomposition embedding parameterization and cross-layer parameter sharing, on the basis of the BERT model; Decomposition embedding parameterization: adding parameter intermediaries to unbind the sizes of the hidden layer and the vocabulary word embedding layer in the original BERT, the method is to decompose the larger embedding matrix into two small matrices, and modify the hidden layer and the word embedding layer in BERT to 768 hidden layers and 128 word embedding layers; Cross-layer parameter sharing: the parameters of each layer in the hidden layer are consistent, and the method used in the present invention is to share all parameters across layers;

[0104] ALBERT model parameters The calculation formula is:

[0105]

[0106] In the formula, H represents the hidden layer dimension, E represents the word vector dimension, and V represents the vocabulary size. In the BERT model, the hidden layer dimension and the word embedding dimension are both 768. In the ALBERT model, the word embedding dimension is reduced to 128. Therefore, the addition of the word embedding factorization mechanism greatly reduces the number of parameters of the BERT model.

[0107] In the Token Embedding part, add the [CLS] symbol at the beginning of each sentence and the [SEP] symbol at the end of each sentence; the [CLS] vector is later used as the input of the binary classification task, but [CLS] does not represent the semantic information of the entire sentence; in the Segment Embedding part, use the [SEP] symbol added in the Token Embedding part to separate two sentences, the words before the [SEP] symbol are represented by "0", and the words after the [SEP] symbol are represented by "1"; this is used to learn the parameters of sentence order; in the Position Embedding part, number each word in the sentence from "0" to "511"; this is used to learn the parameters of word position;

[0108] Because the pre-training of the text sentiment classification model uses a large number of unlabeled data sets, an unsupervised method is used for training; the training method proposed in the present invention uses an unsupervised objective function for training, namely, an autoencoder model; the original text data set is damaged, and then the text is predicted and restored with reference to the context information.

[0109] Compared with Bi-LSTM, using Transformer network as encoder can stack deeper layers and better parallel processing; and linear Transformer network is less susceptible to the influence of masked marks than LSTM. It only needs to reduce the weight of masked marks through the self-attention mechanism of Transformer network, while LSTM is similar to a black box model, and it is difficult to determine how it handles masked marks internally; using only Transformer network to learn a large number of token-level feature parameters is not enough to build a text sentiment classification model with strong enough migration; therefore, some sentence-level patterns are added for learning; for the initial training of text sentiment classification model, a large number of unlabeled samples are used to train the pre-built text sentiment classification model for the first time, and the data set is input into the word embedding layer network for unsupervised training; a small number of labeled samples of target domain and target task are input into the text sentiment classification model, where the text sentiment classification model identifies which domain the sample belongs to, and uses the labels in the sample to learn the relevant features of the target domain and target task to obtain a trained sentiment classification model;

[0110] As a preferred technical solution, in this embodiment, in order to verify the effect of ALBERT model + LDA model + K-means clustering algorithm, the present invention iteratively trains 5 comparison models 10 times on the same text data, and records the test set accuracy, recall rate and F1 value of each iteration, which can intuitively reflect the advantages and disadvantages of the model. The selected comparison models are:

[0111] 1) CNN: Convolutional neural network is a special feed-forward neural network. The model uses word2vec representation based on text and uses two serial convolutional layers to capture local semantic features. A time-varying max pooling layer is placed on top of the last convolutional layer to select global semantic features. A fully connected layer with dropout is used to summarize the features.

[0112] 2) LSTM: Long Short-Term Memory, uses Word2vec to train word vectors, uses the long short-term memory network to extract text semantic information, and then uses the Softmax classifier to classify the sentiment polarity.

[0113] 3) BERT-base: Uses a bidirectional Transformer network structure to extract text features and implement sentiment classification. The model parameters use the original parameters of bert-base-chinese released by Google.

[0114] 4) BERT-LDA: The feature vector output by BERT is used as the input of the LDA model. The topic feature vector output by the LDA model is then fused with the feature vector output by BERT word embedding. Sentiment classification is performed after iterative training.

[0115] 5) ALBERT-base: A BERT model optimized through layer parameter sharing, sentence coherence, and reduced embedding dimension. The text feature information extracted by the word embedding layer is input into the fully connected layer and classified by the Softmax classifier.

[0116] As a preferred technical solution, in this embodiment, the relationship between the proportion of the training set to the total text data and the model effect is as follows: Figure 8 It can be seen that the model can still achieve good training results when the training set is small. The reason is that ALBERT has learned a lot of useful parameters in the pre-training stage. With the increase of training sets, the accuracy and recall model effects are significantly improved. Therefore, the present invention divides the training set and the test set according to a ratio of 9:1. The experimental results of the five groups of comparative experiments under the same experimental environment are shown in Table 1:

[0117] Table 1 Experimental results under different models

[0118]

[0119] As can be seen from Table 1, the three parameters of the text sentiment classification model proposed in the present invention are better than those of CNN, LSTM, BERT-base, BERT-LDA and ALBERT-base models in the comment text data. LSTM solves the gradient vanishing and gradient exploding problems of traditional deep learning for long text training to a certain extent, so the accuracy of the LSTM algorithm in the long text sentiment classification task is slightly higher than that of CNN. Since the BERT model uses a new bidirectional Transformer network structure and is pre-trained with massive Chinese and foreign text data, it fundamentally solves the problem of parameter forgetting of traditional deep learning algorithms and learns a large amount of parameter information of text grammatical structure. Therefore, the classification effect of the model with BERT structure is better than that of the traditional convolutional neural network (CNN) and the long short-term memory neural network (LSTM) model based on word embedding. The text sentiment classification model proposed in the present invention integrates the text topic feature vector output by the LDA-K-means clustering algorithm on the basis of the ALBERT model, which enhances the ability of the text sentiment classification model to obtain sentiment information, so the accuracy rate in the sentiment classification task is higher than that of the ALBERT model. Compared with the BERT model, the new algorithm that integrates the topic feature vector has an accuracy improvement of 3.85%, a recall improvement of 5.92%, and an F1 value improvement of 6.36%. The present invention experimentally analyzes the accuracy change trend of the text sentiment classification model and five groups of comparison models when the number of iterations ranges from 0 to 10. The relationship between the number of experimental iterations and the accuracy is shown in Figure 2. Fig. 9 As shown:

[0120] from Fig. 9 It can be seen that this method has a faster loss convergence than other models, and has achieved good results on both the training set and the test set. In particular, when the number of iterations is small, the text sentiment classification model can obtain better classification results, which is not available in traditional deep learning. Compared with other models, as the number of iterations continues to increase, the accuracy of the text sentiment classification model converges quickly and steadily. The text sentiment classification model has learned the optimal parameters in the 8th iteration. In summary, the ALBERT model + LDA model + K-means clustering algorithm proposed in the present invention has greatly improved the evaluation indicators such as precision and recall in the field of sentiment analysis compared with other models.

[0121] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the embodiments of the present invention. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the embodiments here. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the claims of the present invention.

Claims

1. A text sentiment classification method for multiple fields, characterized in that: The following steps are involved: S1: Obtain labeled text data in the target domain and preprocess it, input the preprocessed text data into the word embedding layer preset by the text sentiment classification model, and vectorize the text data using word embedding, segment embedding, and position embedding to obtain a word vector sequence, wherein the word vector sequence includes a word vector, a segment vector, and a position vector; The text sentiment classification model consists of a word embedding layer, an ALBERT model, a multi-task layer and a classifier connected in sequence; S2: Train the word embedding layer, embed the LDA model for text topic information extraction into the ALBERT model, and integrate the K-means clustering algorithm into the LDA model; S3: Input the word vector sequence into the LDA model for unsupervised training, extract the text topic information, and obtain the topic feature vector of "document-topic" distribution; S4: After the topic feature vector is input into the K-means clustering algorithm for secondary clustering, the cosine similarity is used to output the optimal topic feature vector; the Gibbs sampling method is used for iterative sampling, and the "topic-word" distribution and "comment-topic" distribution are obtained after the LDA model converges; S5: Train the text sentiment classification model, calculate the sentiment probability of the sentiment classification label through the trained text sentiment classification model, and use the label with the largest sentiment probability as the target data label, so as to achieve cross-domain text sentiment classification; Wherein, step S4 is specifically as follows: The word vector sequence is input into the LDA model for unsupervised training. The common features of the sample vectors are extracted using the latent Dirichlet distribution to obtain intermediate variables. The intermediate variables generated by the LDA model are input into the K-means clustering algorithm to assign a topic feature vector that can represent the features of the entire group of vectors to each group of word vectors; the topic feature vector is fused with the word vector, segment vector and position vector output by the word embedding layer to obtain a fused vector, which is input into the ALBERT model to output cosine similarity. Cosine similarity evaluates similarity by calculating the cosine value of the angle between two vectors; cosine similarity plots the fused vector into the two-dimensional vector space according to the coordinate value; Text data express, is the number of comments, is a comment vector, which conforms to the "comment-topic" distribution; the implicit topic share assigned to each comment is , each comment contains Sentences, words, each with a potential theme; is the word vector form of the comment text; is the "topic-word" distribution, K is the number of topics; and Respectively represent the hyperparameters of the "comment-topic" and "topic-word" distributions subject to the prior Dirichlet distribution; the "comment-topic" distribution formula P is: 。 2. A text sentiment classification method for multiple fields according to claim 1, characterized in that: The step S1 also includes: constructing a dictionary: taking the token sequence and the special characters used in the training as the dictionary; reserving 99 unused placeholders, namely [unused1] to [unused99].

3. A text sentiment classification method for multiple fields according to claim 1, characterized in that: The preprocessing in step S1 is specifically as follows: Normalize text data and remove URL links, remove stop words, and replace emojis with their original text form.

4. A text sentiment classification method for multiple fields according to claim 3, characterized in that: The normalization process is as follows: obtaining text data from the network, annotating the text data with sentiment polarity, and then deleting empty data, deleting duplicate data, deleting non-text data, and deleting meaningless symbol data.

5. A text sentiment classification method for multiple fields according to claim 1, characterized in that: In step S1, the text data is vectorized using word embedding, segment embedding, and position embedding to obtain a word vector sequence, specifically: Input the text data as the input vector to the word embedding layer and output the feature vector W ij ; Eigenvector W ij Input to the ALBERT model to extract context features and output the representation feature vector corresponding to each input vector , the characterizing feature vector is a sequence of word vectors.

6. A text sentiment classification method for multiple fields according to claim 1, characterized in that: The text sentiment classification model consists of a word embedding layer, an ALBERT model, a multi-task layer and a classifier connected in sequence; specifically: Word embedding layer: as input, it realizes text vectorization; after the preprocessed text data is embedded in words, segments, positions and topics, each word is mapped into four output feature vectors; the feature vectors are: word vector, segment vector, position vector, topic feature vector; ALBERT model: It consists of a bidirectional Transformer network structure. The feature vector output by the word embedding layer is used as the input of the ALBERT model. The feature vector output by the word embedding layer is used by the ALBERT model to extract contextual features for target domain data detection and output the corresponding representation feature vector for each input vector. The LDA model is used to extract topic information from the input text. Multi-task layer: The ALBERT model learns parameters on a large amount of unlabeled data through the sentence order prediction SOP and masked language model tasks; the sentence order prediction SOP task and the masked language model task are retained, and the sentiment classification task is added; the masked language model task means that the ALBERT model randomly extracts 15% of the words in the input text for masking, and the masked words have an 80% probability of being replaced with the [MASK] symbol, a 10% probability of being replaced with any word in the data set, and a 10% probability of not making any changes; the [CLS] output by the ALBERT model is used as the input of the sentiment classification task; through Dropout, a part of the hidden nodes in the ALBERT model are randomly discarded to reduce the number of features and prevent overfitting; Softmax classifier: The Softmax classifier sets the weight probability in the interval [0,1]. The vector representation is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network to obtain the distribution of sentiment probability.

7. A text sentiment classification method for multiple fields according to claim 1, characterized in that: Step S2 is to train the word embedding layer, specifically including the following steps: S21: Obtain unlabeled text data, use Jieba word segmentation to split each sentence in the unlabeled text data into a single word sequence; S22: Use the WordPiece model to convert the word sequence into a WordPiece vector sequence; S23: Determine whether there is a new sentence input. If there is a new sentence input, use the WordPiece model to convert the new sentence into a WordPiece vector sequence; if there is no new sentence input, terminate; S24: Determine whether the sequence length of each sentence in the unlabeled text data exceeds the value of the maximum sequence length. If the length exceeds the maximum sequence length, the sentence is truncated into a front sequence and a back sequence, and the front sequence is retained; for sentences whose length is less than the maximum sequence length, a padding operation is performed; S25: Encode each sentence pair in the label text data, traverse the WordPiece vector sequence, and add [CLS] and [SEP] characters at the beginning and end of each sentence respectively; S26: Output a token sequence with [CLS] and [SEP] characters, superimpose the position vector of each word with the word vector, perform position encoding on each word in order according to the length of the sentence, and obtain the output result of the position encoding; sum the word vector, segment vector, and position vector to obtain a word vector summation result containing position information, and obtain a trained word embedding layer.

8. A text sentiment classification method for multiple fields according to claim 1, characterized in that: Step S5 is specifically as follows: The word vector, segment vector, position vector and topic feature vector output by the LDA model are input into the ALBERT model to construct a Softmax classifier, and the weights are probabilized in the interval [0,1] to achieve the classification of sentiment polarity; the vector representation is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network to obtain the sentiment probability distribution; the first word [CLS] of the sentence is taken for the classification task using the Softmax classifier; the trained text sentiment classification model calculates the sentiment probability of the sentiment classification label and takes the label with the largest sentiment probability as the target data label, thereby achieving cross-domain text sentiment classification.

9. A text sentiment classification method for multiple fields according to claim 8, characterized in that: The vector representation is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network to obtain the sentiment probability distribution, specifically: The vector representation T is mapped to the sentiment classification space through the self-attention mechanism of the Transformer network. , we get the distribution of emotion probability P: In the formula, and is the parameter vector and bias to be learned; the sentiment polarity with the highest probability is taken as the prediction result; Softmax classifier P i The calculation formula is: In the formula, is a vector, and is an element in the vector matrix, is the dimension of the matrix.