Social network corpus sentiment classification method based on prompt learning
By employing a cue-based learning approach that combines automatically and manually constructed cues, and utilizing a pre-trained Chinese language model and a BiLSTM model, the dependence of Chinese sentiment classification on large-scale labeled data was resolved, achieving efficient text sentiment classification with limited labeled data.
Patent Information
- Application Number
- CN202310187249.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-01
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2043-03-01
AI Technical Summary
Existing technologies require large-scale, high-quality labeled datasets for Chinese emotion classification tasks, which makes data labeling time-consuming and labor-intensive. In addition, there are few publicly available large-scale, high-quality datasets, which limits the performance of mainstream models.
We employ a prompt-based learning approach, combining automatically and manually constructed hybrid prompts. We utilize a pre-trained Chinese language model and a BiLStm model, transform word embedding representations using a word2vec model, and construct a mapping vocabulary to reduce the difficulty of model prediction, thereby achieving efficient classification with limited labeled data.
In scenarios with limited labeled data, it achieved good text sentiment classification results, reduced the dependence on high-quality, large-scale labeled datasets, and improved model performance.
Smart Images

Figure CN116257631B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing, and more specifically, to a method for sentiment classification of social network corpora based on cue learning. Background Technology
[0002] With the development of mobile internet, mobile-based media and social platforms have also developed rapidly. People share their daily lives and opinions on various social platforms while commenting on others' posts. This textual data contains people's daily emotions and their sentimental biases towards events. Therefore, by analyzing the sentiment trends in textual corpora from social networks, we can uncover netizens' attitudes and emotional tendencies towards certain issues.
[0003] Currently, deep learning has been widely applied in fields such as image processing, speech recognition, and text processing, solving various problems and achieving good results. However, the effectiveness of these models depends on large-scale, high-quality labeled data. Furthermore, manually labeling large-scale data is time-consuming and labor-intensive, making it difficult to obtain ideal labeled data for model training. In the field of Chinese sentiment classification, there are very few publicly available large-scale, high-quality datasets. Current mainstream sentiment classification models, such as TextRNN, TextCNN, and TextRCNN, all require large-scale, high-quality labeled datasets for training. Summary of the Invention
[0004] To overcome at least one of the shortcomings of the prior art, this application provides a sentiment classification method for social network corpora based on cue learning.
[0005] Firstly, a sentiment classification method for social network corpora based on cue learning is provided, including:
[0006] Identify target cues for the text to be categorized;
[0007] Create manual suggestions for the text to be categorized;
[0008] Combine target hints and manual hints to create a hybrid hint;
[0009] The mixed prompts and the text to be classified are input into a Chinese pre-trained language model to obtain the prediction results; the prediction results include the probability that the text to be classified is predicted to be multiple characters;
[0010] Construct a mapping vocabulary; the mapping vocabulary includes multiple text types, and each text type includes multiple characters representing the text type;
[0011] Based on the prediction results and the mapping vocabulary, the text type of the text to be classified is determined.
[0012] In one embodiment, determining the target cue for the text to be categorized includes:
[0013] Encode the text to be classified to obtain the feature vector of the text to be classified;
[0014] The feature vector is decoded to obtain the target prompt of the text to be classified.
[0015] In one embodiment, the text to be classified is encoded to obtain a feature vector of the text to be classified, including:
[0016] The text to be classified is converted into a word embedding representation using the word2vec model;
[0017] The word embedding representation is input into the BiLstm model for encoding to obtain the feature vector of the text to be classified.
[0018] In one embodiment, constructing manual suggestions for the text to be categorized includes:
[0019] Create multiple manual prompts;
[0020] For each manual prompt, the Chinese pre-trained language model is fine-tuned based on the manual prompt and the text training set. The fine-tuned Chinese pre-trained language model is evaluated using the text test set to obtain an evaluation score.
[0021] Manual suggestions are used to determine the text to be categorized based on the evaluation score.
[0022] In one embodiment, the text type of the text to be classified is determined based on the prediction results and the mapping vocabulary, including:
[0023] Based on the mapping vocabulary, calculate the average probability of all characters in the prediction results being predicted as the same text type in the text to be classified.
[0024] The text type corresponding to the maximum value in the average is the text type of the text to be classified.
[0025] Secondly, a cue-based learning-based social network corpus sentiment classification device is provided, comprising:
[0026] The target suggestion determination module is used to determine the target suggestions for the text to be classified.
[0027] The manual suggestion building module is used to create manual suggestions for text to be categorized;
[0028] The hybrid prompt module is used to combine target prompts and manual prompts to form hybrid prompts;
[0029] The prediction result acquisition module is used to input the mixed prompts and the text to be classified into the Chinese pre-trained language model to obtain the prediction result; the prediction result includes the probability that the text to be classified is predicted to be multiple characters;
[0030] The mapping vocabulary building module is used to build the mapping vocabulary; the mapping vocabulary includes multiple text types, and each text type includes multiple characters representing the text type;
[0031] The text type determination module is used to determine the text type of the text to be classified based on the prediction results and the mapping vocabulary.
[0032] In one embodiment, the target prompting and determining module is further configured to:
[0033] Encode the text to be classified to obtain the feature vector of the text to be classified;
[0034] The feature vector is decoded to obtain the target prompt of the text to be classified.
[0035] In one embodiment, the target prompting and determining module is further configured to:
[0036] The text to be classified is converted into a word embedding representation using the word2vec model;
[0037] The word embedding representation is input into the BiLstm model for encoding to obtain the feature vector of the text to be classified.
[0038] In one embodiment, manually prompting the build module is also used for:
[0039] Create multiple manual prompts;
[0040] For each manual prompt, the Chinese pre-trained language model is fine-tuned based on the manual prompt and the text training set. The fine-tuned Chinese pre-trained language model is evaluated using the text test set to obtain an evaluation score.
[0041] Manual suggestions are used to determine the text to be categorized based on the evaluation score.
[0042] In one embodiment, the text type determination module is also used for:
[0043] Based on the mapping vocabulary, calculate the average probability of all characters in the prediction results being predicted as the same text type in the text to be classified.
[0044] The text type corresponding to the maximum value in the average is the text type of the text to be classified.
[0045] Compared with the prior art, this application has the following beneficial effects:
[0046] (1) This application proposes a suggestion construction method that combines automatic suggestions and manual suggestion construction, which can achieve better classification results in scenarios with a small amount of labeled data and reduce the dependence of text sentiment classification tasks on high-quality large-scale labeled datasets.
[0047] (2) This application collects as many words as possible related to the four types of emotions manually, and selects the first character of each word to construct a mapping word list. This can better apply the cue learning method to Chinese scenarios, reduce the difficulty of the model to predict a word at the same time, and improve the performance of the model. Attached Figure Description
[0048] This application can be better understood by referring to the description given below in conjunction with the accompanying drawings, which, together with the detailed description below, are incorporated in and form part of this specification. In the drawings:
[0049] Figure 1 A flowchart illustrating a cue-based learning-based sentiment classification method for social network corpora according to an embodiment of this application is shown.
[0050] Figure 2 A structural block diagram of a social network corpus emotion classification device based on cue learning according to an embodiment of this application is shown. Detailed Implementation
[0051] Exemplary embodiments of the present application will be described below with reference to the accompanying drawings. For clarity and brevity, not all features of the actual embodiments are described in the specification. However, it should be understood that many embodiment-specific decisions can be made in the development of any such actual embodiment to achieve the developer’s specific objectives, and these decisions may vary as the embodiments differ.
[0052] It should also be noted that, in order to avoid obscuring this application with unnecessary details, only the device structure closely related to the solution according to this application is shown in the accompanying drawings, while other details that are not closely related to this application are omitted.
[0053] It should be understood that this application is not limited to the described embodiments by virtue of the following description with reference to the accompanying drawings. In this document, embodiments may be combined with each other, features may be substituted or borrowed between different embodiments, and one or more features may be omitted in one embodiment, where feasible.
[0054] In view of the problem that mainstream natural language processing emotion classification tasks require large-scale high-quality data sets, this application constructs a module for automatically generating prompts, which can automatically generate prompts according to the text to be classified. A hybrid prompt method of splicing manual prompts and automatic prompts is adopted, so that the hybrid prompts have the advantages of manual prompts and automatic prompts. In addition, by manually collecting words related to the four emotions of happiness, sadness, anger, and surprise, the first characters of the words are used to construct a mapping vocabulary table, and the output results of the model are mapped to four labels through the mapping vocabulary table. This application focuses on emotion classification of large-scale social network text information, and can achieve good classification results in scenarios with a small amount of labeled data, reducing the dependence of text emotion classification tasks on high-quality large-scale labeled data sets.
[0055] An embodiment of this application provides a method for classifying emotions in social network corpus based on prompt learning. Figure 1 The flowchart of the method for classifying emotions in social network corpus based on prompt learning according to an embodiment of this application is shown. The method includes:
[0056] Step S1, determine the target prompt of the text to be classified.
[0057] Step S2, construct a manual prompt for the text to be classified. For example, "Text + is really making me {mask}", "Text + feels so {mask}", where mask refers to the result that the model needs to predict, similar to a placeholder, indicating to the model that there is a character covered here and the model needs to guess what the covered character is. The result of the model is the probability of all words in the vocabulary table.
[0058] Step S3, splice the target prompt and the manual prompt to form a hybrid prompt.
[0059] Step S4, input the hybrid prompt and the text to be classified into a Chinese pre-trained language model to obtain a prediction result; the prediction result includes the probability that the text to be classified is predicted as multiple characters.
[0060] In this step, the Chinese pre-trained language model uses the Chinese pre-trained language model of bert-base-chinese. The prediction result can be, for example, the probability that the text to be classified is predicted as the character "开" of "开心", the character "快" of "快乐", the character "伤" of "伤心", and the character "痛" of "痛苦".
[0061] Step S5, construct a mapping vocabulary table; the mapping vocabulary table includes multiple text types, and each text type includes multiple characters representing the text type.
[0062] Here, we can first manually collect a subset of words expressing each of the four emotions—happiness, sadness, anger, and surprise—from Chinese contexts. Utilizing the language reasoning capabilities of the BERT-based Chinese language model, we can iteratively search for similar words using this subset as a foundation. All collected words are categorized into four text types: happiness, sadness, anger, and surprise. A mapping word list is constructed using the first character of each word. Predicting two consecutive characters is more difficult than predicting a single character; therefore, the first character of each word is used to construct the mapping word list.
[0063] Step S6: Determine the text type of the text to be classified based on the prediction results and the mapping vocabulary.
[0064] In this embodiment, considering that automatic prompting has advantages such as wide applicability, strong generalization ability, and stable performance in most tasks, but automatic prompting methods may be local optima in many cases; manual prompting has excellent performance in some cases, but this method requires the participation of experienced experts and is unstable, this embodiment combines the advantages of both prompting methods. In addition, by manually collecting as many emotion-related words as possible and selecting the first character of each word to construct a mapping vocabulary, the prompting learning method can be well applied to Chinese scenarios, reducing the difficulty for the model to predict a word (two characters) at the same time, thereby improving the model's performance.
[0065] In one embodiment, determining the target cue for the text to be categorized includes:
[0066] First, the text to be classified is encoded to obtain its feature vector. Specifically, the text to be classified is converted into a word embedding representation using the word2vec model. The word embedding representation is then input into the BiLstm model for encoding to obtain the feature vector of the text to be classified.
[0067] Then, the feature vector is decoded to obtain the target prompt for the text to be classified. Here, the BiLSTM model is used to decode the feature vector, decoding one character at a time, iterating to obtain the target prompt.
[0068] In one embodiment, constructing manual suggestions for the text to be categorized includes:
[0069] First, construct multiple manual prompts; here, multiple manual prompts are designed manually, such as "text + really makes me {mask}".
[0070] Then, for each manual prompt, the pre-trained Chinese language model bert-base-chinese is fine-tuned based on the manual prompt and the text training set. The fine-tuned pre-trained Chinese language model is evaluated using the text test set to obtain an evaluation score, which can be the accuracy rate. Here, for each manual prompt, different text training sets can be used to obtain the fine-tuned pre-trained Chinese language model and the evaluation score.
[0071] Finally, manual suggestions are determined based on the evaluation scores. Here, the average evaluation score of the Chinese pre-trained language model corresponding to different text training sets is calculated as the final evaluation score of the manual suggestion; the manual suggestion corresponding to the highest final evaluation score is selected as the best manual suggestion.
[0072] In one embodiment, the text type of the text to be classified is determined based on the prediction results and the mapping vocabulary, including:
[0073] First, based on the mapping vocabulary, calculate the average probability of all characters in the prediction results being predicted as belonging to the same text type. For example, if the prediction results are the probability of the text being predicted as "open" in "happy", "fast" in "joyful", "hurt" in "sad", and "painful", calculate the average A of the probability of the text being predicted as "open" in "happy" and "fast" in "joyful", where A is the average value corresponding to the text type "happy". Calculate the average B of the probability of the text being predicted as "hurt" in "sad" and "painful", where B is the average value corresponding to the text type "sad".
[0074] Then, the text type corresponding to the maximum value among the averages is the text type of the text to be classified. Comparing A and B, if A is greater than B, then the text type of the text to be classified is "happy".
[0075] Employing the same inventive concept as the cue-based learning-based social network corpus sentiment classification method, this embodiment also provides a corresponding cue-based learning-based social network corpus sentiment classification device. Figure 2 A structural block diagram of a social network corpus emotion classification device based on cue learning according to an embodiment of this application is shown, including:
[0076] Target cue determination module 21 is used to determine target cues for the text to be classified.
[0077] Manual suggestion building module 22 is used to build manual suggestions for the text to be categorized;
[0078] The hybrid prompt module 23 is used to combine target prompts and manual prompts to form hybrid prompts;
[0079] The prediction result acquisition module 24 is configured to input the mixed prompt and the text to be classified into a Chinese pre-trained language model to obtain a prediction result; the prediction result includes the probabilities that the text to be classified is predicted as multiple words.
[0080] Here, the Chinese pre-trained language model uses the Chinese pre-trained language model of bert-base-chinese. The prediction result can be, for example, the probability that the text to be classified is predicted as the character '开' of '开心', the character '快' of '快乐', the character '伤' of '伤心', and the character '痛' of '痛苦'.
[0081] The mapping vocabulary construction module 25 is configured to construct a mapping vocabulary; the mapping vocabulary includes multiple text types, and each text type includes multiple characters representing the text type.
[0082] Here, first, a part of the words that can express the four emotions of happiness, sadness, anger, and surprise in the Chinese context can be collected manually. Using the language inference ability of bert-base-chinese, these words are used as a basis to iteratively find similar words. All the collected words are divided into four text types: happiness, sadness, anger, and surprise, and the first character of the selected words is used to construct the mapping vocabulary. The difficulty of the model predicting two consecutive characters is higher than predicting one character, so the first character of each word is used here to construct the mapping vocabulary.
[0083] The text type determination module 26 is configured to determine the text type of the text to be classified according to the prediction result and the mapping vocabulary.
[0084] In this embodiment, the social network corpus emotion classification method based on prompt learning focuses on the emotion classification of large-scale social network text information, can achieve a good classification effect in the scenario of a small amount of labeled data, and reduces the dependence of the text emotion classification task on a high-quality large-scale labeled data set.
[0085] In one embodiment, the target prompt determination module 21 is further configured to:
[0086] Encode the text to be classified to obtain a feature vector of the text to be classified;
[0087] Decode the feature vector to obtain the target prompt of the text to be classified.
[0088] In one embodiment, the target prompt determination module 21 is further configured to:
[0089] Convert the text to be classified into a word embedding representation through a word2vec model;
[0090] Input the word embedding representation into a BiLstm model for encoding to obtain a feature vector of the text to be classified.
[0091] In one embodiment, the manual prompting construction module 22 is also used for:
[0092] Create multiple manual prompts;
[0093] For each manual prompt, the Chinese pre-trained language model is fine-tuned based on the manual prompt and the text training set. The fine-tuned Chinese pre-trained language model is evaluated using the text test set to obtain an evaluation score.
[0094] Manual suggestions are used to determine the text to be categorized based on the evaluation score.
[0095] In one embodiment, the text type determination module 26 is further configured to:
[0096] Based on the mapping vocabulary, calculate the average probability of all characters in the prediction results being predicted as the same text type in the text to be classified.
[0097] The text type corresponding to the maximum value in the average is the text type of the text to be classified.
[0098] The above descriptions are merely various embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for classifying sentiment of social network corpus based on prompt learning, characterized in that, The method comprises the following steps: determining a target prompt of the text to be classified; constructing a manual prompt of the text to be classified; splicing the target prompt and the manual prompt to form a mixed prompt; inputting the mixed prompt and the text to be classified into a Chinese pre-trained language model to obtain a prediction result; the prediction result comprises probabilities of the text to be classified being predicted as multiple words; constructing a mapping word table; the mapping word table comprises multiple text types, and each text type comprises multiple words representing the text type; determining a text type of the text to be classified according to the prediction result and the mapping word table; the method of determining the target prompt of the text to be classified comprises: encoding the text to be classified to obtain a feature vector of the text to be classified; converting the text to be classified into a word embedding representation through a word2vec model; inputting the word embedding representation into a BiLstm model for encoding to obtain the feature vector of the text to be classified; decoding the feature vector to obtain the target prompt of the text to be classified; decoding the feature vector by using the BiLstm model, decoding one word at a time, and iterating to obtain the target prompt.
2. The method of claim 1, wherein, the method of constructing the manual prompt of the text to be classified comprises: constructing multiple manual prompts; for each manual prompt, fine-tuning the Chinese pre-trained language model based on the manual prompt and a text training set, evaluating the fine-tuned Chinese pre-trained language model by using a text test set to obtain an evaluation score; determining the manual prompt of the text to be classified according to the evaluation score.
3. The method of claim 1, wherein, the method of determining the text type of the text to be classified according to the prediction result and the mapping word table comprises: calculating, according to the mapping word table, an average value of probabilities of all words in the prediction result being predicted as the same text type of the text to be classified; the text type corresponding to the maximum value in the average value is the text type of the text to be classified. 4.A social network corpus sentiment classification device based on prompt learning, characterized in that, The method comprises the following steps: a target prompt determination module for determining a target prompt of the text to be classified; a manual prompt construction module for constructing a manual prompt of the text to be classified; a mixed prompt construction module for splicing the target prompt and the manual prompt to form a mixed prompt; a prediction result acquisition module for inputting the mixed prompt and the text to be classified into a Chinese pre-trained language model to obtain a prediction result; the prediction result comprises probabilities of the text to be classified being predicted as multiple words; a mapping word table construction module for constructing a mapping word table; the mapping word table comprises multiple text types, and each text type comprises multiple words representing the text type; a text type determination module for determining a text type of the text to be classified according to the prediction result and the mapping word table; the target prompt determination module is further used for: encoding the text to be classified to obtain a feature vector of the text to be classified; converting the text to be classified into a word embedding representation through a word2vec model; inputting the word embedding representation into a BiLstm model for encoding to obtain the feature vector of the text to be classified; The feature vector is decoded to obtain a target prompt of the text to be classified; the BiLstm model is used to decode the feature vector, one word is decoded each time, and iteration is performed to obtain the target prompt.
5. The apparatus of claim 4, wherein, The manual prompt construction module is further configured to: construct a plurality of manual prompts; for each manual prompt, fine-tune a Chinese pre-training language model based on the manual prompt and a text training set, evaluate the fine-tuned Chinese pre-training language model by using a text test set, and obtain an evaluation score; determine the manual prompt of the text to be classified according to the evaluation score.
6. The apparatus of claim 4, wherein, The text type determination module is further configured to: calculate, according to the mapping word table, an average value of probabilities of all words in the prediction result being predicted as the same text type of the text to be classified; the text type corresponding to the maximum value in the average value is the text type of the text to be classified.
Citation Information
Patent Citations
Chinese short text classification method based on prompt learning
CN115169340A
Text recognition method and device, medium and program product
CN115248846A