A deep learning method for Chinese sentence text sentiment analysis based on contrastive learning
By combining the comparative learning method of Chinese text word segmentation and emotion dictionary, the accuracy and interpretability of Chinese text sentiment analysis are improved, and the problem of insufficient interpretability of deep learning models in Chinese text sentiment analysis is solved, and it is suitable for a variety of deep neural network models.
Patent Information
- Application Number
- CN202410851594.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2044-06-27
AI Technical Summary
In the prior art, in the sentiment analysis of Chinese texts, there are problems such as insufficient interpretability of deep learning models and complex matching links of emotional dictionaries, and it is difficult to accurately understand the emotional polarity of emerging vocabulary.
Combining Chinese text word segmentation and emotion dictionary, we strengthen the feature results of ordinary text sequence input and emotion dictionary enhancement through contrast learning, and construct a deep learning Chinese sentence text sentiment analysis method based on contrast learning, and use the BERT model and multi-head attention mechanism for feature extraction and classification.
It improves the accuracy and interpretability of sentiment analysis in Chinese text, simplifies the sentiment analysis process, and is suitable for a variety of deep neural network models.
Smart Images

Figure CN118747219B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of text sentiment analysis, and in particular to a deep learning Chinese sentence text sentiment analysis method based on contrastive learning. Background Art
[0002] Text sentiment analysis is a key research subtask in natural language processing, aiming to identify sentiment within a given text sequence. IoT textual content, such as reviews of services, movies, products, and hot news, as well as shared experiences and blog posts, contains rich emotional information. Sentiment analysis of this textual content can provide a deeper understanding of user preferences, product strengths and weaknesses, and trends in public opinion. Sentiment analysis can be categorized into aspect-level, sentence-level, and paragraph-level levels. Aspect-level sentiment analysis examines the sentiment of more fine-grained words, while paragraph-level analysis targets sentiment analysis of longer text sequences such as news and blog posts. Sentences are the primary form of emotional expression in online commentary and social media discussions.
[0003] Sentiment analysis of Chinese text primarily involves three methods: analysis based on sentiment dictionaries, analysis based on machine learning, and the rapidly developing deep learning-based analysis method. Sentiment analysis based on sentiment dictionaries was first proposed by Whissell et al. Currently, English sentiment dictionaries include SentiWordNet. For sentiment analysis of Chinese text, Chinese scholars have compiled and assembled Chinese sentiment dictionaries such as the National Taiwan University Sentiment Dictionary, HowNet, and the Sentiment Lexicon Ontology. Analysis based on sentiment dictionaries places high demands on the quality and scalability of the dictionary. In the ever-changing online text environment, sentiment analysis based solely on sentiment dictionaries struggles to determine the sentiment polarity of emerging words, making it difficult to correctly understand the overall sentiment polarity of a sentence.
[0004] Research in text sentiment analysis is also focused on supervised machine learning methods such as support vector machines, K-nearest neighbors, decision trees, and random forests, which utilize manual feature extraction. These machine learning methods rely on complex feature engineering and specialized classifiers, making feature extraction more noisy when applied to online commentary. With the iterative advancement of hardware and software technologies, the computing power of deep learning has significantly increased. Its powerful generalization capabilities enable it to automatically proofread, learn, and extract text features, eliminating the need for manual feature extraction. Deep learning neural networks are also flourishing, with recurrent neural networks, convolutional neural networks, bidirectional recurrent neural networks, bidirectional convolutional neural networks, and graph neural networks all achieving significant improvements in various downstream tasks.
[0005] Contrastive learning, a deep learning approach that has rapidly developed in recent years, was first applied in the computer vision field for image classification. Later, researchers began to apply contrastive learning to natural language processing, with gradual exploration and application in areas such as text semantic similarity, text classification, and sentiment analysis. Contrastive learning can help deep learning models learn more robust and discriminative feature representations, thereby improving the model's performance on downstream tasks.
[0006] Chinese text sentiment analysis based on deep learning. Due to the unique nature of deep learning network models, its learning parameters are like a black box. While the learning accuracy is high, in some cases, the results are difficult to interpret. To address the lack of interpretability of deep learning networks, a method can be used to combine Chinese text segmentation with sentiment lexicons. For iteratively evolving internet terms, the accuracy and interpretability can be improved by supplementing the sentiment lexicon. Then, through comparative learning, the features of the normal text sequence input and the results of the sentiment lexicon reinforcement learning are reinforced. This allows the model to learn the sentiment polarity of a sentence without going through the steps of Chinese analysis and sentiment lexicon matching.
[0007] Therefore, it is an urgent problem for those skilled in the art to propose a deep learning Chinese sentence text sentiment analysis method based on contrastive learning to solve the difficulties existing in the existing technology. Summary of the Invention
[0008] In view of this, the present invention provides a deep learning method for sentiment analysis of Chinese sentences based on contrastive learning. This method combines Chinese text word segmentation with a sentiment dictionary. For iteratively evolving internet slang, the accuracy and interpretability can be improved by supplementing the sentiment dictionary. Contrastive learning is then used to enhance the features of ordinary text sequence input and sentiment dictionary-enhanced learning, allowing the model to learn the sentiment polarity of sentences without going through the Chinese analysis and sentiment dictionary matching stages.
[0009] In order to achieve the above object, the present invention adopts the following technical solutions:
[0010] A deep learning Chinese sentence text sentiment analysis method based on contrastive learning includes the following steps:
[0011] S1. Data acquisition step: obtaining Chinese text sequences;
[0012] S2, data preprocessing step: segment the Chinese text sequence obtained in S1 to obtain a set of sentiment words after segmentation, including adjectives, verbs and adverbs;
[0013] S3, part-of-speech determination step: query the sentiment word set obtained in S2 after segmentation in the sentiment dictionary, and mark the sentiment words with sentiment polarity;
[0014] S4, text encoding step: combining the sentiment dictionary matching information with sentiment polarity obtained in S3 with the original text, and encoding the combined text;
[0015] S5. Pooling layer optimization step: Construct a BERT deep learning framework with a binary classification classifier for the pooling output layer and train the BERT deep learning framework using the cross entropy loss function;
[0016] S6, contrastive learning network step: connect the output of the pooling layer to the multi-layer perceptron input of the predictor, perform contrastive learning on the output of the predictor and the output of the pooling layer in S4, set the loss function to Euclidean distance, and train epochs.
[0017] The above method is optional. The specific content of the word segmentation in S2 is as follows:
[0018] Use the LTP word segmentation tool to extract adjectives, verbs, and adverbs to obtain a set of sentiment words after word segmentation. In the above method, optionally, the specific steps in S3 include:
[0019] S301: Obtain the sentiment polarity of the corresponding word according to the word segmentation set, and Query and build a sentiment word polarity set:
[0020] Among them, the sentiment dictionary library adopts the sentiment dictionary library of National Taiwan University of China, w is the sentiment word, is the sentiment polarity of word w, Label the set for sentiment polarity;
[0021] S302: For sentiment words that are not found in the sentiment dictionary, a custom supplemented sentiment dictionary is used:
[0022]
[0023] in, A custom set of sentiment combinations. A set of sentiment dictionaries supplemented for custom scenarios;
[0024] S303: For the sentiment words that are not found in the sentiment dictionary and the supplementary dictionary, the sentiment polarity is set to neutral, and 0.5 is used to represent the neutral sentiment polarity value:
[0025]
[0026] In the above method, optionally, the specific contents of S4 include:
[0027] S401: The original sentence text sequence is fused with the sentiment phrase polarity set matched with the sentiment dictionary after word segmentation, and encoded using the BertTokenizer encoder of the BERT model. The concat combination operation is performed again based on the BertTokenizer encoding result to obtain the fused encoding:
[0028]
[0029] in, Encode the original text sequence, Information encoding for sentiment lexicon enhancement;
[0030] S402: Input the fused code obtained in S401 to the Encoder layer, and divide the input fused code into three equal parts: , then the fused code after the three equal divisions is input into the attention layer, and multiple data are calculated in parallel based on multi-head attention. The multi-head attention calculation formula includes:
[0031]
[0032] And capture the correlation coefficients between words on multiple dimensions:
[0033]
[0034] Among them, the output of the attention is subjected to a 10% Dropout operation, and p is set to 0.1:
[0035]
[0036] S403: Input the attention network output obtained in S402 into the fully connected layer to obtain the fully connected features. , where W is the fully connected layer vector parameter, b is the linear change bias parameter of the fully connected layer, and GELU is used as the activation function:
[0037]
[0038] S404: Input the activation layer feature vector obtained in S403 into the pooling layer, perform full connection layer dimensionality reduction on the feature, set the output dimension, normalize it again, and perform random Dropout on the normalized feature:
[0039]
[0040] in, is the parameter vector of the pooling layer, is the linearly changing bias vector of the pooling layer, h is the feature vector output by the previous layer, is the feature vector after dimension reduction in the pooling layer.
[0041] In the above method, optionally, the specific contents of S5 include:
[0042] S501: For the output of S4, take out the first [CLS] vector information from the vector, enter a fully connected layer, and then use As an activation function, the output is centered at zero, that is, the mean is 0, and a feature vector is obtained that aggregates different types of features around the zero point. The process formula is expressed as follows:
[0043]
[0044] in
[0045] S502: Set a linear classifier and output a binary classification result, indicating two emotional polarities. In the classification result, if the first value is greater than the second value, it indicates that the emotional polarity is negative; otherwise, it indicates a positive emotional polarity:
[0046]
[0047] in, Learn parameters for the classifier linear feature vector, is the bias parameter of the binary linear classifier, is the classification result vector, the vector dimension is 1 and the length is 2, p is the classification result, and the result value is 0 or 1, representing the first and second categories respectively;
[0048] S503: Compare the result of the previous step input with the sentiment polarity labeling corresponding to the training sample, use cross entropy as the loss function, and perform backpropagation on the model:
[0049]
[0050] y is the classification value marked in the dataset, set to 0 or 1, representing the extreme negative sentiment and the extreme positive sentiment, respectively;
[0051] S504: Perform 20 epochs of training.
[0052] In the above method, optionally, the specific contents of S6 include:
[0053] Input two different data into the network model for learning, compare the features of the two, and make the feature similarity between the positive sample pairs closer, while the feature similarity between the negative sample pairs farther away.
[0054] Through the above technical solution, it can be seen that compared with the existing technology, the deep learning Chinese sentence text sentiment analysis method based on contrastive learning of the present invention has the following beneficial effects:
[0055] 1) Existing technical solutions do not address the need for enhanced contrastive learning between deep neural network models and traditional sentiment dictionaries, requiring the construction of complex multimodal sentiment scenarios for comparative analysis. This paper proposes a simplified and effective method for contrastive learning models in sentiment analysis.
[0056] 2) The present invention is universal and can be used to replace the current neural network with other deep neural networks for comparative learning;
[0057] 3) This paper proposes an effective deep learning-based comparative learning sentiment analysis method for Chinese texts, which integrates the accurate basis of traditional sentiment dictionaries and improves the accuracy and interpretability of the Chinese text sentiment analysis model. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0059] Figure 1 A flowchart of a deep learning Chinese sentence text sentiment analysis method based on contrastive learning provided by the present invention;
[0060] Figure 2 The structure diagram of the deep learning network for Chinese text sentiment analysis provided by the present invention;
[0061] Figure 3 This is a structural diagram of the multi-layer perceptron of the predictor provided by the present invention. DETAILED DESCRIPTION
[0062] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only 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 making creative efforts are within the scope of protection of the present invention.
[0063] In this application, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. The terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or apparatus comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or apparatus comprising the element.
[0064] The present invention can be used in a variety of general-purpose or special-purpose computing device environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multi-processor devices, and distributed computing environments including any of the above.
[0065] Reference Figure 1 As shown, the present invention discloses a deep learning Chinese sentence text sentiment analysis method based on contrastive learning, comprising the following steps:
[0066] S1. Data acquisition step: obtaining Chinese text sequences;
[0067] S2, data preprocessing step: segment the Chinese text sequence obtained in S1 to obtain a set of sentiment words after segmentation, including adjectives, verbs and adverbs;
[0068] S3, part-of-speech determination step: query the sentiment word set obtained in S2 after segmentation in the sentiment dictionary, and mark the sentiment words with sentiment polarity;
[0069] S4, text encoding step: combining the sentiment dictionary matching information with sentiment polarity obtained in S3 with the original text, and encoding the combined text;
[0070] S5. Pooling layer optimization step: Construct a BERT deep learning framework with a binary classification classifier for the pooling output layer and train the BERT deep learning framework using the cross entropy loss function;
[0071] S6, contrastive learning network step: connect the output of the pooling layer to the multi-layer perceptron input of the predictor, perform contrastive learning on the output of the predictor and the output of the pooling layer in S4, set the loss function to Euclidean distance, and train epochs.
[0072] Furthermore, the specific content of the word segmentation in S2 is as follows:
[0073] Use the LTP word segmentation tool to extract adjectives (a), verbs (v), and adverbs (d) to obtain the sentiment word set after word segmentation. .
[0074] Furthermore, the specific steps in S3 include:
[0075] S301: Obtain the sentiment polarity of the corresponding word according to the word segmentation set, query from the sentiment dictionary R and construct a sentiment word polarity set:
[0076]
[0077] Among them, the sentiment dictionary library uses the sentiment dictionary of National Taiwan University of China, w is the sentiment word, is the sentiment polarity of word w, Label the set for sentiment polarity;
[0078] S302: For sentiment words that are not found in the sentiment dictionary, a custom supplemented sentiment dictionary is used:
[0079]
[0080] in, A custom set of sentiment combinations. A set of sentiment dictionaries supplemented for custom scenarios;
[0081] The custom-added sentiment dictionary is a sentiment annotation library for emerging network terms;
[0082] S303: For the sentiment words that are not found in the sentiment dictionary and the supplementary dictionary, the sentiment polarity is set to neutral, and 0.5 is used to represent the neutral sentiment polarity value:
[0083] .
[0084] Furthermore, the specific contents of S4 include:
[0085] S401: The original sentence text sequence is fused with the sentiment phrase polarity set matched with the sentiment dictionary after word segmentation, and encoded using the BertTokenizer encoder of the BERT model. The concat combination operation is performed again based on the BertTokenizer encoding result to obtain the fused encoding:
[0086]
[0087] in, Encode the original text sequence, Information encoding for sentiment lexicon enhancement;
[0088] S402: Input the fused code obtained in S401 to the Encoder layer, and divide the input fused code into three equal parts: , then the fused code after the three equal divisions is input into the attention layer, and multiple data are calculated in parallel based on multi-head attention. The multi-head attention calculation formula includes:
[0089]
[0090] And capture the correlation coefficients between words on multiple dimensions:
[0091]
[0092] Among them, the output of the attention is subjected to a 10% Dropout operation, and p is set to 0.1:
[0093]
[0094] S403: Input the attention network output obtained in S402 into the fully connected layer to obtain the fully connected features.
[0095] , where W is the fully connected layer vector parameter, b is the linear change bias parameter of the fully connected layer, and GELU is used as the activation function:
[0096]
[0097]
[0098] S404: Input the activation layer feature vector obtained in S403 into the pooling layer, perform full connection layer dimensionality reduction on the feature, set the output dimension, normalize it again, and perform random Dropout on the normalized feature:
[0099]
[0100] in, is the parameter vector of the pooling layer, is the linearly changing bias vector of the pooling layer, h is the feature vector output by the previous layer, is the feature vector after dimension reduction in the pooling layer.
[0101] Specifically, the output of S403 is input to the pooling layer, and the feature is subjected to full connection layer dimensionality reduction, the output dimension is set to 768, and then layer normalization is performed to make the feature distribution more stable. Finally, a random 10% dropout is performed on the normalized feature: the BERT model can handle long sequence inputs. For the sentiment polarity labeling data set matched with the sentiment dictionary, there is no need to use other neural networks for encoding. The deep learning neural network structure is as follows: Figure 2 As shown;
[0102] Furthermore, the specific contents of S5 include:
[0103] S501: For the output of S4, take out the first [CLS] vector information from the vector, enter a fully connected layer, and then use As an activation function, the output is centered at zero, that is, the mean is 0, to prevent the problem of gradient disappearance. The process formula is as follows:
[0104]
[0105] in
[0106] S502: Set a linear classifier and output a binary classification result, indicating two emotional polarities. In the classification result, if the first value is greater than the second value, it indicates that the emotional polarity is negative; otherwise, it indicates a positive emotional polarity:
[0107]
[0108] in, .
[0109] S503: Compare the result of the previous step input with the sentiment polarity labeling corresponding to the training sample, use cross entropy as the loss function, and perform backpropagation on the model:
[0110]
[0111] S504: Perform training for no less than 20 epochs.
[0112] Furthermore, the specific contents of S6 include:
[0113] That is, two different data are input into the network model for learning, and the features of the two are compared. The feature similarity between the positive sample pairs is close, and the feature similarity between the negative sample pairs is far apart.
[0114] Specifically, S601: modify the linear classifier of S502 so that the output of S501 is used as a positive sample feature, and the feature parameters output from this process are no longer back-propagated:
[0115]
[0116] S602: Establish a new process, obtain the information of S201, and encode it using the encoder BertTokenizer of the BERT model. ,Will Input to the encoder layer consistent with S402, and perform subsequent consistent steps until S502, input the output feature vector of S501 into the predictor of a multi-layer perceptron;
[0117]
[0118] in q is the output of the previous layer The characteristic dimension of
[0119] S603: Construct a multi-layer perceptron predictor so that the feature Align to make the representation of the two in the feature space as aggregated as possible. The multi-layer perceptron is set as follows, with the structure as follows Figure 3 As shown:
[0120]
[0121] in
[0122] S604: Comparative learning is performed on the predicted features and the feature vectors after sentiment dictionary enhancement learning. The two are a pair of positive samples. The loss function is designed to make the feature vectors of the two converge as much as possible in the feature space:
[0123]
[0124] S605: After training for no less than 20 epochs, the output of the comparative learning network is Input into the linear classifier consistent with S502.
[0125]
[0126] This paper focuses on sentiment analysis of text sequences from Chinese online reviews. To address the incompleteness, imprecision, and internet slang characteristics of online review text, we use a sentiment lexicon and a locally extended online sentiment lexicon for data augmentation. By combining deep learning with a contrastive learning network, we propose a deep learning-based Chinese text sentiment analysis method based on contrastive learning. This method is primarily validated on two Chinese text sentiment review datasets, weibo_senti_100k and waimai_10k, publicly available on Kaggle. The number of positive and negative sentiment polarities is shown in Table 1. The baseline models used for comparison are the Bert_wwm (BERT Whole Word Mask) model and the Bert-Chinese-base (Google) model. Table 2 shows the comparative experimental results.
[0127]
[0128] Each embodiment in this specification is described in a progressive manner. The same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple. For relevant parts, refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without expending creative work.
[0129] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein may be implemented by electronic hardware, computer software, or a combination of both.
[0130] To clearly illustrate the interchangeability of hardware and software, the above descriptions have generally described the components and steps of each example by function. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Professionals may use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of the present invention.
[0131] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to one 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 invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A deep learning Chinese sentence text sentiment analysis method based on contrastive learning, characterized by: The following steps are involved: S1. Data acquisition step: obtaining Chinese text sequences; S2, data preprocessing step: segment the Chinese text sequence obtained in S1 to obtain a set of sentiment words after segmentation, including adjectives, verbs and adverbs; S3, emotional color determination step: query the emotional word set obtained in S2 after segmentation in the emotional dictionary, and mark the emotional words with emotional polarity; S4, text encoding step: combining the sentiment dictionary matching information with sentiment polarity obtained in S3 with the original text, and encoding the combined text; S5. Pooling layer optimization step: Construct a BERT deep learning framework with a binary classification classifier for the pooling output layer and train the BERT deep learning framework using the cross entropy loss function; S6, contrastive learning network step: connect the output of the pooling layer to the multi-layer perceptron input of the predictor, perform contrastive learning on the output of the predictor and the output of the pooling layer in S5, set the loss function to Euclidean distance, and train epochs.
2. The method for deep learning Chinese sentence text sentiment analysis based on contrastive learning according to claim 1 is characterized in that: The specific content of the word segmentation in S2 is as follows: Use the LTP word segmentation tool to extract adjectives, verbs, and adverbs, and obtain the sentiment word set S after word segmentation. l ={LTP.seg adj (S),LTP.seg verb (S),LTP.seg adverb (S)}.
3. The method for deep learning Chinese sentence text sentiment analysis based on contrastive learning according to claim 2 is characterized in that: The specific steps in S3 include: S301: Obtain the sentiment polarity of the corresponding word according to the word segmentation set, query from the sentiment dictionary R and construct a sentiment word polarity set: S senti ={(w,r w )},w∈R,r w ∈R; Among them, the emotional dictionary library uses the NTUSD emotional dictionary library, w is the emotional word, r w is the sentiment polarity of word w, r w ∈{0,1},S senti Label the set for sentiment polarity; S302: For sentiment words that are not found in the sentiment dictionary, a custom supplemented sentiment dictionary is used: Among them, S ' senti For the customized emotion combination relationship set, R ' A set of sentiment dictionaries supplemented for custom scenarios; S303: For the sentiment words that are not found in the sentiment dictionary and the supplementary dictionary, the sentiment polarity is set to neutral, and 0.5 is used to represent the neutral sentiment polarity value: S senti_mid ={(w 1_mid ,r w_mid1 ),(w 2_mid ,r w_mid2 ),…,(w n_mid ,r w_midn )},r w_mid ∈{0,0.5,1}。 4. The method for deep learning Chinese sentence text sentiment analysis based on contrastive learning according to claim 3 is characterized in that: The specific contents of S4 include: S401: The original sentence text sequence is fused with the sentiment phrase polarity set matched with the sentiment dictionary after word segmentation, and encoded using the BertTokenizer encoder of the BERT model. The concat combination operation is performed again based on the BertTokenizer encoding result to obtain the fused encoding: Among them, E s Encode the original text sequence, Information encoding for sentiment lexicon enhancement; S402: Input the fused code obtained in S401 into the Encoder layer, divide the input fused code into three equal parts: Query, Key, Value, and then input the three-part fused code into the attention layer. Based on multi-head attention, multiple data are calculated in parallel, where the multi-head attention calculation formula includes: And capture the correlation coefficients between words on multiple dimensions: MultiHead(Q K,V)=Concat(head1,…,head h )W O ; Among them, the output of the attention is subjected to a 10% Dropout operation, and p is set to 0.1: S403: Input the attention network output obtained in S402 into the fully connected layer to obtain the fully connected features. h f =hW+b, where W is the fully connected layer vector parameter, b is the linearly changing bias parameter of the fully connected layer, and GELU is used as the activation function: S404: Input the activation layer feature vector obtained in S403 into the pooling layer, perform full connection layer dimensionality reduction on the feature, set the output dimension, normalize it again, and perform random Dropout on the normalized feature: h o =h g W1+b1; Where W1∈R q×768 is the parameter vector of the pooling layer, b1∈R 1×768 is the linearly changing bias vector of the pooling layer, h g is the feature vector output by the previous layer, h o is the feature vector after dimension reduction in the pooling layer.
5. The method for deep learning Chinese sentence text sentiment analysis based on contrastive learning according to claim 4 is characterized in that: The specific contents of S5 include: S501: For the output of S4, take out the first [CLS] vector information from the vector, enter a fully connected layer, and then use Tanh as the activation function to center the output at zero, that is, the mean is 0, and obtain a feature vector that aggregates different types of features around the zero point. The process formula is expressed as follows: h p =h o W2+b2; h P =tanh(h P ); where W2∈R 768×768 , b2∈R 1×768 ; S502: Set a linear classifier and output a binary classification result, indicating two emotional polarities. In the classification result, if the first value is greater than the second value, it indicates that the emotional polarity is negative; otherwise, it indicates a positive emotional polarity: <h2 style=";text-align:left;direction:ltr">h<h2 style=";text-align:left;direction:ltr"> c <h2 style=";text-align:left;direction:ltr"> =h<h2 style=";text-align:left;direction:ltr"> p <h2 style=";text-align:left;direction:ltr"> W3+b3; Where W3∈R 768×2 Learn parameters for the classifier linear feature vector, b3∈R 1×2 is the bias parameter of the binary linear classifier, h c is the classification result vector, the vector dimension is 1 and the length is 2, p is the classification result, and the result value is 0 or 1, representing the first and second categories respectively; S503: Compare the output of the previous step with the sentiment polarity labels corresponding to the training samples, use cross entropy as the loss function, and perform backpropagation on the model: Loss(y,p)=-[y·log(p)+(1-y)·log(1-p)]; y is the classification value marked in the dataset, set to 0 or 1, indicating negative or positive extreme sentiment, respectively; S504: Perform 20 epochs of training.
6. The method for deep learning Chinese sentence text sentiment analysis based on contrastive learning according to claim 5 is characterized in that: The specific contents of S6 include: Input two different data into the network model for learning, compare the features of the two, and make the feature similarity between the positive sample pairs closer, while the feature similarity between the negative sample pairs farther away.
Citation Information
Patent Citations
Attribute-level sentiment analysis method based on deep learning
CN114662498A
User information enhanced long text fine-grained sentiment analysis method
CN117688185A