Emotion analysis method for online community comment text

By combining the ERNIE, CNN and BiLSTM models and the multi-head attention mechanism for sentiment analysis, the problem of low efficiency and insufficient feature extraction of online community review text sentiment analysis in the existing technology is solved, and a more efficient and accurate sentiment classification is achieved.

CN118606473APending Publication Date: 2024-09-06HEFEI UNIV OF TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410750581.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

Existing sentiment analysis technology is inefficient when processing online community comment texts, is difficult to accurately capture complex emotional information, and has insufficient feature extraction.

Method used

The ERNIE model is used as the pre-training layer, combined with the CNN and BiLSTM models for local and global feature extraction, and a multi-head attention mechanism is introduced in the self-attention layer, linear transformation and non-linear activation are performed through the fully connected and classification layers, and finally emotional Classification.

Benefits of technology

It improves the accuracy and precision of emotion classification, enhances the feature expression ability of the model, and achieves more efficient and precise emotion analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606473A
    Figure CN118606473A
Patent Text Reader

Abstract

The invention discloses an online community comment text-oriented sentiment analysis method, which comprises the following steps of: 1, collecting and preprocessing data, and 2, constructing a sentiment classification model which comprises a pre-training layer, a global feature extraction layer, a self-attention layer, a local feature extraction layer, a maximum pooling layer, a feature fusion layer, a full connection layer and a classification layer. And 3, training an emotion classification model based on the preprocessed data set, and inputting to-be-classified data into the model to obtain an emotion classification result. The problems of insufficient feature extraction, difficulty in complex emotion information capture and the like in an existing method can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of natural language processing, and specifically is a sentiment analysis method for online community comment text. Background Art

[0002] With the rapid development of the Internet and social media, users have posted a large number of comments in various online communities. These comments contain emotional information about products, services, events, etc. Analyzing this emotional information has important application value in market research, brand management, and public opinion monitoring. However, existing sentiment analysis techniques still have some shortcomings. Although deep learning models perform well in sentiment analysis, they still face problems such as insufficient feature extraction and difficulty in capturing complex sentiment information. These problems make existing sentiment analysis methods inefficient in processing online community comment texts and difficult to accurately capture complex sentiment information. Summary of the invention

[0003] The present invention aims to solve the deficiencies of the above-mentioned prior art and propose a sentiment analysis method for online community comment texts, in the hope of more accurately and efficiently analyzing the sentiment information in the comment texts, thereby improving the effect and reliability of sentiment analysis.

[0004] In order to achieve the above-mentioned purpose, the present invention adopts the following technical scheme:

[0005] The sentiment analysis method for online community comment text of the present invention is characterized in that it is performed according to the following steps:

[0006] Step 1: Obtain a dataset of online community text sentiment and preprocess the dataset to obtain a preprocessed dataset D = {(X1, y1), (X2, y2), ..., (X k ,y k ),...,(X m ,y m )}, where X k represents the kth text sample after preprocessing; y k Represents X k The corresponding sentiment label, m represents the total number of text samples in the dataset D, and there are R sentiment categories in total;

[0007] Step 2: Build a sentiment classification model and classify X k Process and get the kth text sample X k The probability score P k ;

[0008] Step 3: Training of sentiment classification model:

[0009] Step 3.1: Use formula (4) to construct the loss function L:

[0010]

[0011] In formula (4), R is the number of categories of sentiment labels, y k,r Yes k is the probability of the rth category;

[0012] Step 3.2: Use the gradient descent method to train the sentiment classification model and calculate the loss function L until the loss function L converges or the training reaches the maximum number of iterations, thereby obtaining the optimal sentiment classification model for outputting the corresponding sentiment type for the input online community comment text.

[0013] The sentiment analysis method for online community comment texts described in the present invention is also characterized in that the sentiment classification model in step 2 includes: a pre-training layer, a local feature extraction layer, a maximum pooling layer, a global feature extraction layer, a self-attention layer, a feature fusion layer, a full connection and classification layer;

[0014] Step 2.1: The pre-training layer uses the pre-trained language model ERNIE to train X k Vectorize and get the kth text sample X k The contextual semantic vector sequence S k ={s 1,k ,s 2,k ...,s i,k ,…,s n,k}, where S i,k Represents the kth text sample X k The contextual semantic vector of the i-th word; n represents the k-th text sample X k The total number of upper and lower semantic vectors;

[0015] Step 2.2: The local feature extraction layer uses the CNN model to extract S k Process and get the kth text sample X k The local eigenvector F k ={f 1,k ,f 2,k ,...,f i,k ,…,f n,k}, where f i,k Indicates i,k Local features of

[0016] Step 2.3, the maximum pooling layer uses the maximum pooling operation to F k Processing is performed to obtain the kth pooling feature vector in, represents f i,k Pooling features;

[0017] Step 2.4: The global feature extraction layer uses the BiLSTM model to extract S k Process and get the kth text sample X k The global eigenvector H k ={h 1,k ,h 2,k ,...,h i,k ,…,h n,k}, where h i,k represents f i,k The global characteristics of

[0018] Step 2.5: The self-attention layer uses a multi-head self-attention mechanism to k Processing is performed to obtain the k-th multi-head attention feature vector Z k ={z 1,k ,z 2,k ,...,z i,k ,…,z n,k}, where z i,k represents f i,k Multi-head attention features;

[0019] Step 2.6: The feature fusion layer pair Z k and Connect and get the kth concatenated feature vector C k ={c 1,k ,c 2,k ,...,c i,k ,…,c n,k}, where c i,k represents f i,k The splicing features of

[0020] Step 2.7: The fully connected layer uses formula (1) to calculate C k Perform a linear transformation to obtain the kth linear eigenvector in, Indicates c i,j Linear characteristics of

[0021]

[0022] In formula (6), W c represents the weight of the fully connected layer, b c represents the bias of the fully connected layer;

[0023] The fully connected layer uses formula (2) to vector Perform nonlinear activation to obtain the kth nonlinearly activated feature vector U k = {u1,k ,u 2,k ,...,u i,k ,…,u n,k}, where u i,k Represents the features after the i-th nonlinear activation;

[0024]

[0025] In formula (7), ReLu represents the nonlinear activation function;

[0026] Step 2.8: The classification layer uses formula (3) to classify U k Classify and get the kth text sample X k Category score E k ={e 1,k ,e 2,k ,...,e i,k ,…,e n,k}, where e i,k Represents the kth text sample X k The category probability score corresponding to the i-th eigenvector of ;

[0027] E k =W e ·U k +b e (3)

[0028] In formula (8), W e represents the weight of the classification layer, b e represents the bias of the classification layer;

[0029] The classification layer uses the Softmax function to k Convert and get the kth text sample X k The probability score P k =[p k,1 ,p k,2 ,...,p k,r ,…,p k,R ], where p k,r Represents X k The probability of belonging to the rth category.

[0030] An electronic device of the present invention includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the sentiment analysis method, and the processor is configured to execute the program stored in the memory.

[0031] The present invention provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and the computer program executes the steps of the sentiment analysis method when executed by a processor.

[0032] Compared with the prior art, the present invention has the following beneficial effects:

[0033] 1. The present invention adopts an innovative method of combining the ERNIE model with the CNN and BiLSTM models to improve the effect of sentiment analysis of online community comment texts. The ERNIE model can more accurately capture the semantic relationships in the text, especially has better processing capabilities for polysemous words and context-related words, while the introduced CNN model can effectively extract local features, and the BiLSTM model can memorize and process long-distance dependencies. The combination of the two can provide a more comprehensive feature representation. By combining these three models, the present invention not only improves the accuracy of sentiment classification, but also enhances the feature expression ability of the model, thereby achieving more efficient and more accurate sentiment analysis.

[0034] 2. The present invention enhances the feature expression capability to achieve efficient sentiment classification, introduces a multi-head attention mechanism in the self-attention layer, and inputs the fused features into the fully connected layer for linear transformation and nonlinear activation, and finally performs sentiment classification through the classification layer. Through this comprehensive processing method, the model's ability to recognize text sentiment is enhanced, the accuracy and precision of sentiment classification are improved, and the efficiency of sentiment classification is improved, so it can handle complex sentiment classification tasks. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 It is the sentiment classification model diagram of the present invention;

[0036] Figure 2 A diagram of a text sentiment analysis method using a sentiment classification model according to the present invention. DETAILED DESCRIPTION

[0037] In this example, a sentiment analysis method for online community comment text is to use the ERNIE model in the sentiment classification model as the pre-training layer, CNN as the local feature extraction layer, and BiLSTM as the global feature extraction layer, so as to consider the global and local feature extraction of the text, and then obtain accurate data feature representation by enhancing the feature expression ability to provide more accurate sentiment classification results. Figure 1 As shown in the figure, a sentiment analysis method for online community comment text is carried out in the following steps:

[0038] Step 1: Obtain a dataset D of online community text sentiment; collect user comment data from online communities, clean the collected data, remove duplicate, invalid or low-quality comments, perform preprocessing operations such as word segmentation, stop word removal and lemma restoration on the cleaned comments, and obtain the preprocessed dataset D = {(X1, y1), (X2, y2), ..., (X k ,yk ),...,(X m ,y m )}, where X k represents the kth text sample after preprocessing; y k Represents X k The corresponding sentiment label, m represents the total number of text samples in the dataset D, and there are R sentiment categories in total.

[0039] Step 2: Figure 2 As shown, a sentiment classification model is constructed, including: pre-training layer, local feature extraction layer, maximum pooling layer, global feature extraction layer, self-attention layer, feature fusion layer, full connection and classification layer;

[0040] Step 2.1: The pre-training layer uses the pre-trained language model ERNIE to train the pre-processed text dataset D k Vectorize and get the kth text sample X k The contextual semantic vector sequence S k ={s 1,k ,s 2,k ...,s i,k ,…,s n,k}, where s i,k Represents the kth text sample X k The contextual semantic vector of the i-th word; n represents the k-th text sample X k The total number of contextual semantic vectors; ERNIE can capture the dependencies of long texts and understand the contextual information of the entire sentence. This enables ERNIE to achieve significant performance improvements in natural language processing tasks compared to other pre-trained models.

[0041] Step 2.2: Local feature extraction layer uses CNN model to extract S k Through convolution operation, the phrase features and local dependencies in the text are extracted to obtain the kth text sample X k The local eigenvector F k ={f 1,k ,f 2,k ,...,f i,k ,…,f n,k}, where f i,k Indicates i,k Local features of

[0042] Step 2.3, the maximum pooling layer uses the maximum pooling operation on F k Processing is performed to obtain the kth pooling feature vector in, represents f i,kThe maximum pooling operation can retain the most significant local features, reduce feature dimensions, and reduce computational complexity.

[0043] Step 2.4: The global feature extraction layer uses the BiLSTM model to extract S k Processing, performing maximum pooling operation, reducing feature dimensions, retaining important information, and obtaining the kth text sample X k The global eigenvector H k ={h 1,k ,h 2,k ,...,h i,k ,…,h n,k}, where h i,k represents f i,k The global characteristics of

[0044] Step 2.4: Self-attention layer uses a multi-head self-attention mechanism to k Processing is performed to capture important information in the text and obtain the kth multi-head attention feature vector Z k ={z 1,k ,z 2,k ,...,z i,k ,…,z n,k}, where z i,k represents f i,k Multi-head attention features.

[0045] Step 2.5: Feature fusion layer pair Z k and Connect and get the kth concatenated feature vector C k ={c 1,k ,c 2,k ,...,c i,k ,…,c n,k}, where c i,k represents f i,k By combining local and global features, the model can capture various information in the text more comprehensively, making the model more robust to diverse inputs when facing complex and changeable online community comments.

[0046] Step 2.6: The fully connected layer performs linear transformation and nonlinear activation on the fused feature vector to further extract important features. The fully connected layer uses formula (1) to transform C k Perform a linear transformation to obtain the kth linear eigenvector in, Indicates c i,k Linear characteristics of

[0047]

[0048] In formula (1), W c represents the weight of the fully connected layer, b c represents the bias of the fully connected layer;

[0049] The fully connected layer uses formula (2) to transform the vector Perform nonlinear activation to obtain the kth nonlinearly activated feature vector U k = {u 1,k ,u 2,k ,...,u i,k ,…,u n,k}, where u i,k Represents the features after the i-th nonlinear activation;

[0050]

[0051] In formula (2), ReLu represents a nonlinear activation function.

[0052] Step 2.7: The classification layer uses formula (3) to k Classify and get the kth text sample X k Category score E k ={e 1,k ,e 2,k ,...,e i,k ,…,e n,k}, where e i,k Represents the kth text sample X k The category probability score corresponding to the i-th eigenvector of ;

[0053] E k =W e ·U k +b e (3)

[0054] In formula (3), W e represents the weight of the classification layer, b e Represents the bias of the classification layer;

[0055] The classification layer uses the Softmax function to transform E to obtain the probability score P k =[p k,1 ,p k,2 ,...,p k,r ,…,p k,R ],. Among them, p k,r Represents the kth text sample X k The probability of belonging to the rth category.

[0056] Step 3: Training of sentiment classification model:

[0057] Step 3.1: Use formula (4) to construct the loss function L:

[0058]

[0059] In formula (4), R is the number of categories of sentiment labels, p k,r Yes k is the probability of the rth category; y k,r Yes k is the probability of the rth category.

[0060] Step 3.2: Use the gradient descent method to train the sentiment classification model, calculate the loss function L, set the maximum number of iterations epoch_number = 100, until the loss function L converges or the training reaches the maximum number of iterations, so as to obtain the optimal sentiment classification model, which is used to output the corresponding sentiment type for the input online community comment text.

[0061] In this embodiment, an electronic device includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the above method, and the processor is configured to execute the program stored in the memory.

[0062] In this embodiment, a computer-readable storage medium stores a computer program on the computer-readable storage medium, and the computer program executes the steps of the above method when executed by a processor.

Claims

1. A sentiment analysis method for online community comment text, characterized in that: The steps are as follows: Step 1: Obtain a dataset of online community text sentiment and preprocess the dataset to obtain a preprocessed dataset D = {(X1, y1), (X2, y2), ..., (X k ,y k )..,.,(X m ,y m )}, where X k represents the kth text sample after preprocessing; y k Represents X k The corresponding sentiment label, m represents the total number of text samples in the dataset D, and there are R sentiment categories in total; Step 2: Build a sentiment classification model and classify X k Process and get the kth text sample X k The probability score P k ; Step 3: Training of sentiment classification model: Step 3.1: Use formula (4) to construct the loss function L: In formula (4), R is the number of categories of sentiment labels, y k,r Yes k is the probability of the rth category; Step 3.2: Use the gradient descent method to train the sentiment classification model and calculate the loss function L until the loss function L converges or the training reaches the maximum number of iterations, thereby obtaining the optimal sentiment classification model for outputting the corresponding sentiment type for the input online community comment text.

2. A sentiment analysis method for online community comment text according to claim 1, characterized in that: The sentiment classification model in step 2 includes: a pre-training layer, a local feature extraction layer, a maximum pooling layer, a global feature extraction layer, a self-attention layer, a feature fusion layer, a full connection and classification layer; Step 2.1: The pre-training layer uses the pre-trained language model ERNIE to train X k Vectorize and get the kth text sample X k The contextual semantic vector sequence S k ={s 1,k ,s 2,k …,s i,k ..,.,s n,k }, where s i,k Represents the kth text sample X k The contextual semantic vector of the i-th word; n represents the k-th text sample X k The total number of upper and lower semantic vectors; Step 2.2: The local feature extraction layer uses the CNN model to extract S k Process and get the kth text sample X k The local eigenvector F k ={f 1,k , f 2,k , ..., f i,k , ..., f n,k }, where f i,k Indicates i,k Local features of Step 2.3, the maximum pooling layer uses the maximum pooling operation to F k Processing is performed to obtain the kth pooling feature vector in, represents f i,k Pooling features; Step 2.4: The global feature extraction layer uses the BiLSTM model to extract S k Process and get the kth text sample X k The global eigenvector H k ={h 1,k ,h 2,k ..,.,h i,k , ..., h n,k }, where h i,k represents f i,k The global characteristics of Step 2.5: The self-attention layer uses a multi-head self-attention mechanism to k Processing is performed to obtain the k-th multi-head attention feature vector Z k ={z 1,k , z 2,k , ..., z i,k , ..., z n,k }, where z i,k represents f i,k Multi-head attention features; Step 2.6: The feature fusion layer pair z k and Connect and get the kth concatenated feature vector C k ={c 1,k , c 2,k ..,.,c i,k , ..., C n,k }, where C i,k represents f i,k The splicing features of Step 2.7: The fully connected layer uses formula (1) to calculate C k Perform a linear transformation to obtain the kth linear eigenvector in, Indicates c i,k Linear characteristics of In formula (6), W c represents the weight of the fully connected layer, b c represents the bias of the fully connected layer; The fully connected layer uses formula (2) to vector Perform nonlinear activation to obtain the kth nonlinearly activated feature vector U k = {u 1,k ,u 2,k , ..., u i,k , ..., u n,k }, where u i,k Represents the features after the i-th nonlinear activation; In formula (7), ReLu represents the nonlinear activation function; Step 2.8: The classification layer uses formula (3) to classify U k Classify and get the kth text sample X k Category score E k ={e 1,k , e 2,k , ..., e i,k, ..., e n,k }, where e i,k Represents the kth text sample X k The category probability score corresponding to the i-th eigenvector of ; HAVE BEEN k =W e ·U k +b e (3) In formula (8), W e represents the weight of the classification layer, b e represents the bias of the classification layer; The classification layer uses the Softmax function to k Convert and get the kth text sample X k The probability score P k =[p k,1 , p k,2 , ..., p k,r , ..., p k,R ], where p k,r Represents X k The probability of belonging to the rth category.

3. An electronic device, comprising a memory and a processor, characterized in that: The memory is used to store a program that supports the processor to execute the sentiment analysis method described in claim 1 or 2, and the processor is configured to execute the program stored in the memory.

4. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the sentiment analysis method according to claim 1 or 2 are executed.

Citation Information

Patent Citations

  • Text classification method based on self-attention mechanism and BiGRU

    CN113312483A

  • Chinese sentiment analysis method and system based on multi-granularity convolution feature fusion

    CN117688944A

  • Social network text sentiment analysis method

    CN117851595A

  • Semantic sentiment analysis method fusing in-depth features and time sequence models

    US11194972B1