Small-sample fine-grained sentiment analysis method based on large language model
Through the method of generating and reasoning to enhance text, the problem that the existing technology is difficult to understand the rules of fine-grained sentiment analysis in the small sample scenario is solved, and the performance of the model in the small sample scenario and the accuracy of fine-grained sentiment analysis is improved.
Patent Information
- Application Number
- CN202410919788.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-07-10
AI Technical Summary
The prior art is difficult to effectively understand the rules of fine-grained sentiment analysis in a small sample scenario, resulting in the generated answer format not being standard or containing incorrect emotional elements, and the inability to accurately extract fine-grained emotional information, especially when processing short comments.
By obtaining the data set and constructing the original text label pair, generating enhanced text in cross-or incremental manner, using large language models to infer implicit information of enhanced text, building an enhanced training set, and fine-tuning the pre-trained language model to obtain a sentiment analysis model based on the pre-trained language model.
It improves the performance of the model in a small sample scenario, can more accurately understand and extract fine-grained emotional information, enhances the processing ability of short comments, and improves the accuracy of fine-grained emotional analysis.
Smart Images

Figure CN119597913A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing technology, and in particular to a method, device, equipment and readable storage medium for fine-grained sentiment analysis of a small number of samples based on a large language model. Background Art
[0002] Existing fine-grained sentiment analysis (ABSA) mostly uses generative methods. PARAPHRASE refines the fine-grained sentiment analysis task into a paraphrase generation process that utilizes label semantic information; DLO achieves dataset-level data enhancement by considering the impact of quaternion order in templates on model performance; ILO achieves instance-level data enhancement by selecting an appropriate template for each instance; Although existing generative methods have achieved good results under full supervision settings, fine-grained sentiment analysis tasks in few-sample scenarios are still challenging; Varia et al. use instruction fine-tuning and multi-task learning to solve the five subtasks involved in fine-grained sentiment analysis in few-sample scenarios at one time with a unified method.
[0003] Existing research uses a pre-trained language model (T5) to design question-answer templates and extracts sentiment elements from the generated sentences, which brings about a new paradigm for analyzing sentiment in a generative way; however, due to the scarcity of labeled data used to guide adjustment or contextual learning, this trained generative model cannot understand the rules of ABSA well in a few-sample scenario, resulting in the model sometimes generating unexpected answers, either in a non-standard format or containing incorrect sentiment elements, resulting in the inability to extract correct fine-grained sentiment information from online reviews; in addition, the ABSA dataset contains many short comments with no or little information, which will affect the model's prediction of the correct sentiment elements. The existing technology has not paid attention to extracting sentiment elements from short comments, resulting in low accuracy of model predictions, thereby affecting the accuracy of fine-grained sentiment analysis with few samples. Summary of the invention
[0004] To this end, the technical problem to be solved by the present invention is to overcome the problem in the prior art that due to the scarcity of labeled data used to guide adjustment or contextual learning, the trained generative model cannot understand the rules of ABSA well in a few-sample scenario, resulting in a non-standard model generation format or containing erroneous sentiment elements, making it impossible to extract correct fine-grained sentiment information from online comments; and failing to pay attention to extracting sentiment elements from short comments, resulting in low accuracy of model prediction, thereby affecting the accuracy of fine-grained sentiment analysis of a few samples.
[0005] To solve the above technical problems, the present invention provides a small sample fine-grained sentiment analysis method based on a large language model, comprising:
[0006] Acquire a data set, and divide the data set into an original training set and an original test set; construct multiple original text label pairs based on the original text set and the original label set in the original training set; wherein each original text label pair includes an original text and its corresponding original label; each original label includes one or more quadruplets; the quadruplet is a sentiment quadruplet consisting of aspect terms, aspect categories, sentiment polarity, and opinion words;
[0007] If the original label in the current original text label pair contains a four-tuple, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in a cross manner to generate each newly added text corresponding to the current original text label pair; if the original label in the current original text label pair contains multiple four-tuples, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in an incremental manner to generate each newly added text corresponding to the current original text label pair;
[0008] Based on the designed label determination prompt, the original text corresponding to the current original text label pair is compared with each newly added text, and the newly added emotional element corresponding to each newly added text is determined, thereby determining the label of each newly added text, and constructing each newly added text label pair corresponding to the current original text label pair;
[0009] Each original text label pair and its corresponding newly added text label pair are used as each enhanced text label pair, and an enhanced training set is constructed;
[0010] According to the questions in the information reasoning prompts based on the designed thinking chain, the large language model is used to obtain the answers to the questions in turn, thereby inferring the implicit information of the enhanced text corresponding to each enhanced text label in the enhanced training set;
[0011] Based on the enhanced training set and implicit information of the enhanced text corresponding to each enhanced text label in the enhanced training set, a target training set is obtained;
[0012] Based on the designed input templates of each fine-grained sentiment analysis subtask, each text and implicit information of each text in the target training set is converted into each input sequence of each fine-grained sentiment analysis subtask; based on the designed output templates of each fine-grained sentiment analysis subtask, each label in the target training set is converted into each output sequence of each fine-grained sentiment analysis subtask; the pre-trained language model is fine-tuned using each input sequence and each output sequence of each fine-grained sentiment analysis subtask to obtain a sentiment analysis model based on the pre-trained language model.
[0013] Preferably, the various text generation prompts designed include:
[0014] The first text generation prompt is to replace the aspect terms in the current original text with new aspect terms based on the original tags corresponding to the current original text; wherein the new aspect terms are synonyms of the aspect terms in the current original text;
[0015] The second text generation prompt and the third text generation prompt are based on the original label corresponding to the current original text, and use the new opinion word to replace the opinion word in the current original text; wherein, in the second text generation prompt, the new opinion word is a synonym of the semantics of the opinion word in the current original text; and in the third text generation prompt, the new opinion word is an antonym of the semantics of the opinion word in the current original text.
[0016] Preferably, if the original label in the current original text label pair contains a four-tuple, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in a cross manner to generate each newly added text corresponding to the current original text label pair, including:
[0017] If the original label in the current original text label pair contains a four-tuple, then according to the first text generation prompt, the second text generation prompt, and the third text generation prompt, the aspect terms or opinion words of the original comment text in the current original text are modified to generate the first additional text, the second additional text, and the third additional text corresponding to the current original text label pair;
[0018] The first newly added text corresponding to the current original text label pair obtained by using the first text generation prompt is intersected with the second newly added text corresponding to the current original text label pair obtained by using the second text generation prompt, to obtain a fourth newly added text corresponding to the current original text label pair; wherein the aspect terms of the fourth newly added text are the aspect terms obtained by the first text generation prompt, and the opinion words of the fourth newly added text are the opinion words obtained by the second text generation prompt;
[0019] The first newly added text corresponding to the current original text label pair obtained by using the first text generation prompt is intersected with the third newly added text corresponding to the current original text label pair obtained by using the third text generation prompt to obtain a fifth newly added text corresponding to the current original text label pair; wherein the aspect terms of the fifth newly added text are the aspect terms obtained by using the first text generation prompt, and the opinion words of the fifth newly added text are the opinion words obtained by using the third text generation prompt;
[0020] The first newly added text, the second newly added text, the third newly added text, the fourth newly added text and the fifth newly added text are newly added texts corresponding to the current original text label pair.
[0021] Preferably, if the original label in the current original text label pair contains multiple quadruplets, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in an incremental manner to generate each newly added text corresponding to the current original text label pair, including:
[0022] Select the first text generation prompt and the second text generation prompt; based on the first text generation prompt, modify the first aspect term of the original text in the current original text label pair to obtain the first newly added text corresponding to the current original text label pair; based on the second text generation prompt, modify the first opinion word of the first newly added text corresponding to the current original text label pair to obtain the second newly added text corresponding to the current original text label pair; based on the first text generation prompt, modify the second aspect term of the second newly added text corresponding to the current original text label pair to obtain the third newly added text corresponding to the current original text label pair; based on the second text generation prompt, modify the second opinion word of the third newly added text corresponding to the current original text label pair to obtain the fourth newly added text corresponding to the current original text label pair;
[0023] The modification is performed incrementally in sequence until all aspects of terms and opinion words in the original text of the current original text label pair are replaced, thereby obtaining each newly added text of the current original text label pair.
[0024] Preferably, the questions in the information reasoning prompt based on the designed thinking chain are answered in sequence by using a large language model, thereby inferring the implicit information of the enhanced text corresponding to each enhanced text label in the enhanced training set, including:
[0025] The designed information reasoning based on thought chain includes: a first question, a first answer, a second question and a second answer; wherein the first question is the content of any enhanced text; the first answer is a simple understanding of the content of the current enhanced text using a large language model; the second question is to add background knowledge of the current enhanced text to the content of the current enhanced text; the second answer is a simple answer to the content of the current enhanced text with background knowledge added using a large language model;
[0026] The content of the second answer is the implicit information of the current enhanced text; the implicit information of the enhanced text corresponding to each enhanced text label pair in the enhanced training set is inferred in sequence.
[0027] Preferably, the fine-grained sentiment analysis subtasks include: aspect term extraction, aspect extraction and sentiment classification, target aspect sentiment detection, aspect-level sentiment triple extraction and aspect-level sentiment quadruple extraction.
[0028] Preferably, after obtaining the sentiment analysis model based on the pre-trained language model, the method further includes:
[0029] Based on any text in the original test set, according to the designed information reasoning prompts based on thought chains, the implicit information of the current text is inferred using the large language model;
[0030] Determine the current fine-grained sentiment analysis subtask that needs to be executed; according to the designed input template of the current fine-grained sentiment analysis subtask, convert the current text and implicit information of the current text into an input sequence of the current fine-grained sentiment analysis subtask;
[0031] The input sequence of the current fine-grained sentiment analysis subtask is input into the sentiment analysis model based on the pre-trained language model, and the output sequence corresponding to the sentiment element label of the current text is output. The sentiment element label corresponding to the current text is predicted based on the designed output template of the current fine-grained sentiment analysis subtask.
[0032] The present invention also provides a small sample fine-grained sentiment analysis device based on a large language model, comprising:
[0033] Data acquisition module: acquires a data set and divides the data set into an original training set and a test set; constructs a plurality of original text label pairs based on the original text set and the original label set in the original training set; wherein each original text label pair includes an original text and its corresponding original label; each original label includes one or more quadruplets;
[0034] Data enhancement module: If the original label in the current original text label pair contains a quadruple, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in a cross manner to generate each newly added text corresponding to the current original text label pair; if the original label in the current original text label pair contains multiple quadruple, then based on the various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in an incremental manner to generate each newly added text of the current original text label pair; based on the designed label determination prompts, the original text corresponding to the current original text label pair is compared with each newly added text to determine the newly added emotional element corresponding to each newly added text, thereby determining the label of each newly added text, and constructing each newly added text label pair corresponding to the current original text label pair; each original text label pair and its corresponding each newly added text label pair are used as each enhanced text label pair, and an enhanced training set is constructed;
[0035] Information enhancement module: Based on the questions in the information reasoning prompts designed based on the thought chain, the large language model is used to obtain the answers to the questions in turn, thereby inferring the implicit information of the enhanced text corresponding to each enhanced text label pair in the enhanced training set; based on the enhanced training set and the implicit information of the enhanced text corresponding to each enhanced text label pair in the enhanced training set, the target training set is obtained;
[0036] Model building module: Based on the designed input templates of each fine-grained sentiment analysis subtask, each text and implicit information of each text in the target training set is converted into each input sequence of each fine-grained sentiment analysis subtask; based on the designed output templates of each fine-grained sentiment analysis subtask, each label in the target training set is converted into each output sequence of each fine-grained sentiment analysis subtask; the pre-trained language model is trained using each input sequence and each output sequence of each fine-grained sentiment analysis subtask to obtain a sentiment analysis model based on the pre-trained language model.
[0037] The present invention also provides a small sample fine-grained sentiment analysis device based on a large language model, comprising:
[0038] Memory for storing computer programs;
[0039] A processor is used to implement the steps of the method for fine-grained sentiment analysis with a small number of samples based on a large language model as described above when executing the computer program.
[0040] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned method for fine-grained sentiment analysis of a small number of samples based on a large language model are implemented.
[0041] The above technical solution of the present invention has the following beneficial effects compared with the prior art:
[0042] The invention discloses a method for fine-grained sentiment analysis based on a large language model with a small number of samples. The method utilizes the generation and reasoning capabilities of the large language model to enhance text data from the perspectives of quantity and information. Quantity enhancement is to use the large language model to enhance the quantity of each original text in the original training set. First, various designed text generation prompts are used. Then, according to the number of quadruple groups in the corresponding labels of different original texts, a crossover or incremental method is selected to generate multiple enhanced texts. Then, the label determination prompt is used to determine the labels of the newly generated multiple enhanced texts, and finally an enhanced training data set is obtained. Information enhancement is to use the large language model to enhance the information of each enhanced text. The information reasoning method based on the designed chain of thought (CoT) is used to infer the implicit information of the text (information not clearly expressed in the text). In the training stage, the purpose of data enhancement is to improve the generalization ability, robustness and performance of the model by transforming and expanding the existing data, so that the model can well understand the rules of ABSA in the small sample scenario and learn more knowledge in the training stage. The purpose of information enhancement is to obtain the information of short comments, so as to improve the accuracy and effectiveness of the model prediction and the accuracy of the fine-grained sentiment analysis with a small number of samples. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to make the content of the present invention more clearly understood, the present invention is further described in detail below according to specific embodiments of the present invention in conjunction with the accompanying drawings, wherein:
[0044] Figure 1 It is a framework diagram of a small sample fine-grained sentiment analysis method based on a large language model provided by the present invention;
[0045] Figure 2 It is a text generation graph based on the cross-method;
[0046] Figure 3 It is a text generation graph based on the incremental method;
[0047] Figure 4 It is a schematic diagram of a small-sample fine-grained sentiment analysis device based on a large language model provided by the present invention. DETAILED DESCRIPTION
[0048] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0049] Reference Figure 1 As shown, the present invention provides a method for fine-grained sentiment analysis based on a small number of samples and a large language model; specifically, it includes: S1: Get the data set and divide it into the original training set and the original test set ; Based on the original training set The original text collection in and the original tag set , construct multiple raw text label pairs, Indicates original text label pairs; wherein each original text label pair includes an original text and its corresponding original label; each original label includes one or more quadruplets; the quadruplet is a sentiment quadruplet consisting of an aspect term (AT), an aspect category (AC), a sentiment polarity (SP) and an opinion word (OT); Among them, all texts in the present invention are review texts; S2: Based on the designed various text generation prompts, modify the aspect terms or opinion words of the original text in the current original text label pair, so as to generate various new texts corresponding to the current original text label pair; Among them, the various text generation prompts designed include: The first text generation prompt is to replace the aspect terms in the current original text with new aspect terms based on the original tags corresponding to the current original text; wherein the new aspect terms are synonyms of the aspect terms in the current original text; The second text generation prompt and the third text generation prompt are based on the original label corresponding to the current original text, and use the new opinion word to replace the opinion word in the current original text; wherein, in the second text generation prompt, the new opinion word is a synonym of the opinion word in the current original text; and in the third text generation prompt, the new opinion word is an antonym of the opinion word in the current original text; In order to maintain the balance and diversity of data, two methods, crossover and increment, are designed according to the number of different quadruple groups contained in the label. The specific implementation methods are as follows: Reference Figure 2 As shown, if the original label in the current original text label pair contains a four-tuple, then according to the first text generation prompt, the second text generation prompt, and the third text generation prompt, the aspect terms or opinion words of the original comment text in the current original text are modified to generate the first new text, the second new text, and the third new text corresponding to the current original text label pair; The first newly added text corresponding to the current original text label pair obtained by using the first text generation prompt is intersected with the second newly added text corresponding to the current original text label pair obtained by using the second text generation prompt, to obtain a fourth newly added text corresponding to the current original text label pair; wherein the aspect terms of the fourth newly added text are the aspect terms obtained by the first text generation prompt, and the opinion words of the fourth newly added text are the opinion words obtained by the second text generation prompt; The first newly added text corresponding to the current original text label pair obtained by using the first text generation prompt is intersected with the third newly added text corresponding to the current original text label pair obtained by using the third text generation prompt to obtain a fifth newly added text corresponding to the current original text label pair; wherein the aspect terms of the fifth newly added text are the aspect terms obtained by using the first text generation prompt, and the opinion words of the fifth newly added text are the opinion words obtained by using the third text generation prompt; The first newly added text, the second newly added text, the third newly added text, the fourth newly added text and the fifth newly added text are newly added texts corresponding to the current original text label pair; The above process is that when the number of quadruplets is 1, three new text and label pairs are generated using the first text generation prompt, the second text generation prompt, the third text generation prompt and the label determination prompt, and then the three new text label pairs are cross-combined to obtain two new text label pairs; Reference Figure 3 As shown, if the original label in the current original text label pair contains multiple quadruplets, the first text generation prompt and the second text generation prompt are selected; based on the first text generation prompt, the first aspect term of the original text in the current original text label pair is modified to obtain the first newly added text corresponding to the current original text label pair; based on the second text generation prompt, the first opinion word of the first newly added text corresponding to the current original text label pair is modified to obtain the second newly added text corresponding to the current original text label pair; based on the first text generation prompt, the second aspect term of the second newly added text corresponding to the current original text label pair is modified to obtain the third newly added text corresponding to the current original text label pair; based on the second text generation prompt, the second opinion word of the third newly added text corresponding to the current original text label pair is modified to obtain the fourth newly added text corresponding to the current original text label pair; Modify incrementally in sequence until all aspects of terms and opinion words in the original text of the current original text label pair are replaced, thereby obtaining each newly added text of the current original text label pair; The above process is that when the number of quadruplets is greater than 1, only the first text generation prompt, the second text generation prompt and the label determination prompt are used to continuously generate new text and label pairs in an incremental manner; Based on the designed label determination prompt, the original text corresponding to the current original text label pair is compared with each newly added text, and the newly added emotional element corresponding to each newly added text is determined, thereby determining the label of each newly added text, and constructing each newly added text label pair corresponding to the current original text label pair; Take each original text label pair and its corresponding newly added text label pair as each enhanced text label pair, and construct an enhanced training set ; Among them, S2 is for data enhancement. The purpose of data enhancement is to improve the generalization ability, robustness and performance of the model by transforming and expanding the existing data; at the same time, let the model learn more knowledge during the training stage; S3: Based on the questions in the designed information reasoning prompt based on the thinking chain, the large language model is used to obtain the answers to the questions in turn, thereby inferring the implicit information of the enhanced text corresponding to each enhanced text label in the enhanced training set; represents a collection of enhanced texts; Table enhancement tag collection; represents a set of enhanced text label pairs; The information reasoning prompts designed based on the thought chain include: a first question, a first answer, a second question and a second answer; wherein the first question is the content of any enhanced text; the first answer is a simple understanding of the content of the current enhanced text using a large language model; the second question is to add background knowledge of the current enhanced text to the content of the current enhanced text; the second answer is a simple answer to the content of the current enhanced text with background knowledge added using a large language model (LLM); The content of the second answer is the implicit information of the current enhanced text; the implicit information of the enhanced text corresponding to each enhanced text label pair in the enhanced training set is inferred in sequence; Based on the enhanced training set and the implicit information of the enhanced text corresponding to each enhanced text label in the enhanced training set, the target training set is obtained. ; represents the target training text set; Target training label set; Target training implicit information collection; Among them, in order to use LLM to gradually infer the implicit information of the text (information that is not clearly expressed in the sentence), an information reasoning prompt based on the thinking chain is designed, which is mainly divided into two steps: the first step requires LLM to briefly understand the sentence, that is, the first question requires LLM to briefly understand the sentence and obtains LLM's reply as the first answer; the second step adds some background knowledge, and infers implicit information based on the answer output of the first step of LLM, that is, the second question adds some background knowledge on this basis, and infers the implicit information of the text based on the first answer to obtain the second answer; wherein, the background knowledge is content related to the current enhanced text; In a specific embodiment of the present invention, the field to which the current enhanced text belongs is used as the background knowledge of the current enhanced text. The specific rules of information reasoning prompts based on the thought chain are shown in Table 1. According to Table 1, it can be translated into the content shown in Table 2. Table 1 Information reasoning tips based on thought chain Question 1: Given the text "Original Review Text", what is your understanding of the text? Keep your answers short. –Answer 1: {LLM response} Question 2: The text "Original Review Text" is a comment from the restaurant field. "Answer 1" What does the sentence imply ? answer briefly. –Answer 2: {LLM response} Table 2 Translation of information reasoning prompts based on thought chain Question 1: Given the text "Original Text", what is your understanding of the text? Keep your answer brief. -First answer: {LLM response} Second question: The text "original review text" is a review from the restaurant domain; what does the sentence "first answer" mean? Simple answer. - Second answer: {LLM response} Assuming that the selected review text is “THE SERVICE IS AMAZING, I've had different waiters and they were all nice, which is a rare thing in local.”, the implicit information reasoning process of the current review text is shown in Table 3; according to Table 3, it can be translated into the content shown in Table 4; Table 3 Implicit information reasoning of review text Question 1: Given the text "THE SERVICE IS AMAZING , i 've had different waiters and they were all nice , which is a rare thingin local .", what is your understanding of the text? Keep your answers short. –Answer 1: {The sentence expresses a positive opinion about the service, mentioning the speaker's experience with multiplefriendly waiters.} Question 2: The text "THE SERVICE IS AMAZING , i 've had different waiters and they were all nice , which is a rare thing inlocal ." is a comment from the restaurant field. "The sentence expresses a positive opinion about the service, mentioning the speaker's experience with multiple friendly waiters." What does the sentence imply ? answer briefly. –Answer 2: {The service is very good and the waiters were friendly.} Table 4 Translation of implicit information inference of review text Question 1: Considering "The service was great, I had different waiters and they were all very nice, which is rare in this area.", what is your understanding of the text? Keep your answer short. – First answer: {This sentence expresses a positive view of service and refers to the speaker’s experience with several friendly waiters.} Question 2: "The service was great, I had different waiters and they were all very nice, which is rare in the area." This is a review from the restaurant industry. "This sentence expresses a positive view of the service and mentions the speaker's experience with multiple friendly waiters." What does this sentence mean? Simple answer. – Answer 2: {The service was good and the waiter was very friendly.} Among them, by enhancing the information of the comment text through LLM, it is possible to obtain the information of short comments, and then extract emotional elements from the short comments, improve the accuracy of model prediction, and increase the accuracy of small-sample fine-grained sentiment analysis; S4: Based on the designed input templates of each ABSA subtask, each text and implicit information of each text in the target training set is converted into each input sequence of each ABSA subtask; based on the designed output templates of each ABSA subtask, each label in the target training set is converted into each output sequence of each ABSA subtask; the pre-trained language model is fine-tuned using each input sequence and each output sequence of each ABSA subtask to obtain a sentiment analysis model based on the pre-trained language model; wherein the ABSA subtasks include: aspect term extraction, aspect extraction and sentiment classification, target aspect sentiment detection, aspect-level sentiment triple extraction and aspect-level sentiment quadruple extraction; the designed input templates and output templates of each ABSA subtask are shown in Table 5 and Table 6 respectively; Table 5 Input templates for the five ABSA subtasks ABSA Sub-Tasks Input Template Aspect Term Extraction (AE) Given the text: $Review Text, what are the aspect terms in it? Aspect Extraction and Sentiment Classification (AESC) Given the text: $Review Text, what are the aspect terms and their sentiments? Implicit information:$Implicit Information Target Aspect Sentence Detection (TASD) Given the text: $Review Text, what are the aspect terms, sentiments and categories? Implicitinformation: $Implicit Information Aspect Level Sentiment Triple Extraction (ASTE) Given the text: $Review Text, what are the aspect terms, opinionterms and sentiments? Implicitinformation: $Implicit Information Aspect-Level Sentiment Quadruple Extraction (ASQP) Given the text: $Review Text, what are the aspect terms, opinion terms, sentiments and categories?Implicit information: $Implicit Information Table 6 Output templates for the five ABSA subtasks ABSA Sub-Tasks Output Template Aspect Term Extraction (AE) $AT Aspect Extraction and Sentiment Classification (AESC) $AT is $SP Target Aspect Sentence Detection (TASD) $AT is $SP indicates $AC is $SP Aspect Level Sentiment Triple Extraction (ASTE) $AT is $OT indicates it is $SP Aspect-Level Sentiment Quadruple Extraction (ASQP) $AT is $OT indicates $AC is $SP Taking the complex ASQP task as an example, its input template is: "Given the text: $Review Text, what are the aspect terms, opinion terms, sentiments and categories ? Implicit information: $Implicit Information"; the output template is "$AT is $OT indicates $AC is $SP", where if the aspect term is empty, it is replaced by "it", and the sentiment polarity "Positive", "Negative" and "Neutral" are replaced by "good", "bad" and "ok" respectively; The input template is designed to make better use of the comment text and its corresponding implicit information (to guide the model), rather than simply concatenating them as input; the output template is designed to make better use of the semantic information in the label, rather than simply outputting structured information; When fine-tuning the pre-trained language model using each input sequence and each output sequence of each ABSA subtask to obtain a sentiment analysis model based on the pre-trained language model, the loss function of the fine-tuning process is The expression is:
[0094]
[0095] Where M represents the total number of subtasks; x t represents the input sequence corresponding to the t-th subtask, which is composed of the target training text set T Aug The target text and target training implicit information set T corresponding to the t-th subtask in implicit The target text corresponding to the t-th subtask is used as the input text corresponding to the t-th subtask; y i represents the i-th word of the output sequence, which consists of the label corresponding to the current target text in the target training label set; n represents the length of the output sequence; θ represents the model parameter set; p represents the probability;
[0096] S5: S2-S4 is the training phase. After the training phase is completed and the sentiment analysis model based on the pre-trained language model is obtained, there is a testing phase including:
[0097] Based on any text in the original test set, according to the designed information reasoning prompts based on thought chains, the implicit information of the current text is inferred using the large language model; Combined with the designed information reasoning prompts based on thinking chain, the target test set D is obtained test ;
[0098] Determine the current ABSA subtask that needs to be executed; according to the designed input template of the current ABSA subtask, convert the current text and implicit information of the current text into the input sequence of the current ABSA subtask;
[0099] Input the input sequence of the current ABSA subtask into the sentiment analysis model based on the pre-trained language model, output the output sequence corresponding to the sentiment element label of the current text, and predict the sentiment element label corresponding to the current text according to the designed output template of the current ABSA subtask; wherein the sentiment element label is a collective term for the results of all subtask predictions;
[0100] In the test phase, the prediction results of different subtasks are different (the result predicted by task one may be one element, and the result predicted by task two may be three elements); taking the most complex sentiment quadruple extraction in the present invention as an example, the sentiment analysis model (QAIE model) based on the pre-trained language model provided by the present invention aims to predict the sentiment quadruple.
[0101] In order to verify that the sentiment analysis model (QAIE model) based on the pre-trained language model provided by the present invention has better completion effect on the set five ABSA subtasks, in three benchmark data sets, three data volume settings of k=5, k=10 and k=20 and five ABSA subtasks are compared with the existing methods, and the specific results are shown in Table 7 below;
[0102] Table 7 Comparison of experimental results
[0103]
[0104] The framework for fine-grained sentiment analysis based on a large language model for a small number of samples provided by the present invention is the first work to introduce a large language model into fine-grained sentiment analysis for a small number of samples. It utilizes the generation and reasoning capabilities of the large language model to enhance text data from both the quantity and information perspectives, and mainly includes two stages: training and testing.
[0105] The training stage includes: quantity enhancement and information enhancement; the quantity enhancement is to use a large language model to enhance the quantity of each original text in the original training set, firstly, various designed texts are used to generate prompts, and then, according to the number of quadruplets in the corresponding labels of different original texts, a crossover or incremental method is selected to generate multiple enhanced texts, and then the prompts are determined by using labels to determine the labels of the newly generated multiple enhanced texts, and finally an enhanced training data set is obtained; the information enhancement is to use a large language model to enhance the information of each enhanced text, and use the designed information reasoning method based on the chain of thought (CoT) to infer the implicit information of the text (information that is not obvious in the text);
[0106] In the training phase, the purpose of data augmentation is to improve the generalization, robustness, and performance of the model by transforming and expanding the existing data, so that the model can understand the rules of ABSA well in the few-sample scenario and learn more knowledge in the training phase; the purpose of information augmentation is to obtain information about short comments, thereby improving the accuracy of model prediction and the precision of few-sample fine-grained sentiment analysis;
[0107] The testing phase includes: for each text in the original test set, the corresponding implicit information is obtained through information enhancement to obtain the target test set, and then the current text and its corresponding implicit information are spliced into the instruction input template and input into the model to extract the emotional elements in the current text;
[0108] When the amount of data is limited, the model can also predict the emotional elements of the comment text well; at the same time, the generative method assisted by the large language model provided by the present invention achieves better performance indicators than the existing baseline method; the evaluation indicator used by the present invention in the experiment is F1-Score, and the larger the value, the better the effect of emotional prediction; it can be seen from Table 7 that the performance indicators obtained by using the generative method based on the large language model provided are better than the generative baseline method in five fine-grained emotional tasks and multiple few-sample settings; it shows the effectiveness and superiority of the proposed method, and also shows that the model has considerable application prospects in fine-grained sentiment analysis in natural language processing.
[0109] Reference Figure 4 As shown, a specific embodiment of the present invention also provides a small sample fine-grained sentiment analysis device based on a large language model, including:
[0110] Data acquisition module 100: Acquire a data set, divide the data set into an original training set and a test set; construct multiple original text label pairs based on the original text set and the original label set in the original training set; wherein each original text label pair includes an original text and its corresponding original label; each original label includes one or more quadruplets;
[0111] Data enhancement module 200: based on various designed text generation prompts, modify the aspect terms or opinion words of the original text in the current original text label pair, so as to generate each newly added text corresponding to the current original text label pair; wherein, if the original label in the current original text label pair contains a four-tuple, based on various designed text generation prompts, combined with a cross-method, obtain each newly added text corresponding to the current original text label pair; if the original label in the current original text label pair contains multiple four-tuples, select N kinds of text generation prompts from various designed text generation prompts, and generate each newly added text of the current original text label pair in an incremental manner; based on the designed label determination prompt, compare the original text corresponding to the current original text label pair with each newly added text, determine the newly added emotional element corresponding to each newly added text, thereby determining the label of each newly added text, and construct each newly added text label pair corresponding to the current original text label pair; use each original text label pair and its corresponding each newly added text label pair as each enhanced text label pair, and construct an enhanced training set;
[0112] Information enhancement module 300: according to each question in the designed information reasoning prompt based on the thought chain, using the large language model, the corresponding answer of each question is obtained in turn, so as to infer the implicit information of the enhanced text corresponding to each enhanced text label pair in the enhanced training set; based on the enhanced training set and the implicit information of the enhanced text corresponding to each enhanced text label pair in the enhanced training set, the target training set is obtained;
[0113] Model building module 400: Based on the designed input templates of each ABSA subtask, each text and implicit information of each text in the target training set is converted into each input sequence of each ABSA subtask; based on the designed output templates of each ABSA subtask, each label in the target training set is converted into each output sequence of each ABSA subtask; the pre-trained language model is trained using each input sequence and each output sequence of each ABSA subtask to obtain a sentiment analysis model based on the pre-trained language model;
[0114] The device of this embodiment is used to implement the aforementioned small-sample fine-grained sentiment analysis method based on a large language model. Therefore, the specific implementation method of the small-sample fine-grained sentiment analysis device based on a large language model can be seen in the embodiment part of the small-sample fine-grained sentiment analysis method based on a large language model in the previous text. For example, the data acquisition module 100, the data enhancement module 200, the information enhancement module 300, and the model construction module 400 are respectively used to implement S1 to S4 in the above-mentioned small-sample fine-grained sentiment analysis method based on a large language model. Therefore, its specific implementation method can refer to the description of the corresponding various parts of the embodiment, which will not be repeated here.
[0115] The specific embodiment of the present invention also provides a small sample fine-grained sentiment analysis device based on a large language model, including:
[0116] A memory is used to store a computer program; a processor is used to implement the steps of the above-mentioned method for fine-grained sentiment analysis with a small number of samples based on a large language model when executing the computer program.
[0117] A specific embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned methods for fine-grained sentiment analysis with a small number of samples based on a large language model are implemented.
[0118] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0119] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0120] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0121] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0122] Obviously, the above embodiments are merely examples for the purpose of clear explanation and are not intended to limit the implementation methods. 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 implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the present invention.
Claims
1. A small sample fine-grained sentiment analysis method based on a large language model, characterized in that: include: Obtain a data set and divide the data set into an original training set and an original test set; Based on the original text set and the original label set in the original training set, multiple original text label pairs are constructed; wherein each original text label pair contains an original text and its corresponding original label; each original label contains one or more quadruplets; the quadruplet is a sentiment quadruplet consisting of aspect terms, aspect categories, sentiment polarity and opinion words; If the original label in the current original text label pair contains a four-tuple, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in a cross manner to generate each newly added text corresponding to the current original text label pair; if the original label in the current original text label pair contains multiple four-tuples, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in an incremental manner to generate each newly added text corresponding to the current original text label pair; Based on the designed label determination prompt, the original text corresponding to the current original text label pair is compared with each newly added text, and the newly added emotional element corresponding to each newly added text is determined, thereby determining the label of each newly added text, and constructing each newly added text label pair corresponding to the current original text label pair; Each original text label pair and its corresponding newly added text label pair are used as each enhanced text label pair, and an enhanced training set is constructed; According to the questions in the information reasoning prompts based on the designed thinking chain, the large language model is used to obtain the answers to the questions in turn, thereby inferring the implicit information of the enhanced text corresponding to each enhanced text label in the enhanced training set; Based on the enhanced training set and implicit information of the enhanced text corresponding to each enhanced text label in the enhanced training set, a target training set is obtained; Based on the designed input templates of each fine-grained sentiment analysis subtask, each text and implicit information of each text in the target training set is converted into each input sequence of each fine-grained sentiment analysis subtask; based on the designed output templates of each fine-grained sentiment analysis subtask, each label in the target training set is converted into each output sequence of each fine-grained sentiment analysis subtask; the pre-trained language model is fine-tuned using each input sequence and each output sequence of each fine-grained sentiment analysis subtask to obtain a sentiment analysis model based on the pre-trained language model.
2. According to the method of claim 1, a small sample fine-grained sentiment analysis method based on a large language model is characterized in that: The various text generation prompts designed include: The first text generation prompt is to replace the aspect terms in the current original text with new aspect terms based on the original tags corresponding to the current original text; wherein the new aspect terms are synonyms of the aspect terms in the current original text; The second text generation prompt and the third text generation prompt are based on the original label corresponding to the current original text, and use the new opinion word to replace the opinion word in the current original text; wherein, in the second text generation prompt, the new opinion word is a synonym of the semantics of the opinion word in the current original text; and in the third text generation prompt, the new opinion word is an antonym of the semantics of the opinion word in the current original text.
3. The method for fine-grained sentiment analysis based on a small number of samples based on a large language model according to claim 2, characterized in that: If the original label in the current original text label pair contains a four-tuple, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in a cross manner to generate each newly added text corresponding to the current original text label pair, including: If the original label in the current original text label pair contains a four-tuple, then according to the first text generation prompt, the second text generation prompt, and the third text generation prompt, the aspect terms or opinion words of the original comment text in the current original text are modified to generate the first additional text, the second additional text, and the third additional text corresponding to the current original text label pair; The first newly added text corresponding to the current original text label pair obtained by using the first text generation prompt is intersected with the second newly added text corresponding to the current original text label pair obtained by using the second text generation prompt, to obtain a fourth newly added text corresponding to the current original text label pair; wherein the aspect terms of the fourth newly added text are the aspect terms obtained by the first text generation prompt, and the opinion words of the fourth newly added text are the opinion words obtained by the second text generation prompt; The first newly added text corresponding to the current original text label pair obtained by using the first text generation prompt is intersected with the third newly added text corresponding to the current original text label pair obtained by using the third text generation prompt to obtain a fifth newly added text corresponding to the current original text label pair; wherein the aspect terms of the fifth newly added text are the aspect terms obtained by using the first text generation prompt, and the opinion words of the fifth newly added text are the opinion words obtained by using the third text generation prompt; The first newly added text, the second newly added text, the third newly added text, the fourth newly added text and the fifth newly added text are newly added texts corresponding to the current original text label pair.
4. The method for fine-grained sentiment analysis based on a small number of samples based on a large language model according to claim 2, characterized in that: If the original label in the current original text label pair contains multiple quadruplets, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in an incremental manner to generate each newly added text corresponding to the current original text label pair, including: Select the first text generation prompt and the second text generation prompt; based on the first text generation prompt, modify the first aspect term of the original text in the current original text label pair to obtain the first newly added text corresponding to the current original text label pair; based on the second text generation prompt, modify the first opinion word of the first newly added text corresponding to the current original text label pair to obtain the second newly added text corresponding to the current original text label pair; based on the first text generation prompt, modify the second aspect term of the second newly added text corresponding to the current original text label pair to obtain the third newly added text corresponding to the current original text label pair; based on the second text generation prompt, modify the second opinion word of the third newly added text corresponding to the current original text label pair to obtain the fourth newly added text corresponding to the current original text label pair; The modification is performed incrementally in sequence until all aspects of terms and opinion words in the original text of the current original text label pair are replaced, thereby obtaining each newly added text of the current original text label pair.
5. The method for fine-grained sentiment analysis based on a small number of samples and a large language model according to claim 1, characterized in that: According to the questions in the information reasoning prompt based on the designed thinking chain, the large language model is used to obtain the answers corresponding to each question in turn, so as to infer the implicit information of the enhanced text corresponding to each enhanced text label in the enhanced training set, including: The designed information reasoning based on thought chain includes: a first question, a first answer, a second question and a second answer; wherein the first question is the content of any enhanced text; the first answer is a simple understanding of the content of the current enhanced text using a large language model; the second question is to add background knowledge of the current enhanced text to the content of the current enhanced text; the second answer is a simple answer to the content of the current enhanced text with background knowledge added using a large language model; The content of the second answer is the implicit information of the current enhanced text; the implicit information of the enhanced text corresponding to each enhanced text label pair in the enhanced training set is inferred in sequence.
6. The method for fine-grained sentiment analysis based on a small number of samples based on a large language model according to claim 1, characterized in that: The fine-grained sentiment analysis subtasks include: aspect term extraction, aspect extraction and sentiment classification, target aspect sentiment detection, aspect-level sentiment triple extraction and aspect-level sentiment quadruple extraction.
7. The method for fine-grained sentiment analysis based on a small number of samples based on a large language model according to claim 1, characterized in that: After obtaining the sentiment analysis model based on the pre-trained language model, it also includes: Based on any text in the original test set, according to the designed information reasoning prompts based on thought chains, the implicit information of the current text is inferred using the large language model; Determine the current fine-grained sentiment analysis subtask that needs to be executed; according to the designed input template of the current fine-grained sentiment analysis subtask, convert the current text and implicit information of the current text into an input sequence of the current fine-grained sentiment analysis subtask; The input sequence of the current fine-grained sentiment analysis subtask is input into the sentiment analysis model based on the pre-trained language model, and the output sequence corresponding to the sentiment element label of the current text is output. The sentiment element label corresponding to the current text is predicted based on the designed output template of the current fine-grained sentiment analysis subtask.
8. A small sample fine-grained sentiment analysis device based on a large language model, characterized in that: include: Data acquisition module: obtains the data set and divides the data set into the original training set and the test set; Based on the original text set and the original label set in the original training set, a plurality of original text label pairs are constructed; wherein each of the original text label pairs includes an original text and its corresponding original label; and each of the original labels includes one or more quadruplets; Data enhancement module: If the original label in the current original text label pair contains a quadruple, then based on the designed various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in a cross manner to generate each newly added text corresponding to the current original text label pair; if the original label in the current original text label pair contains multiple quadruple, then based on the various text generation prompts, the aspect terms or opinion words of the original text in the current original text label pair are modified in an incremental manner to generate each newly added text of the current original text label pair; based on the designed label determination prompts, the original text corresponding to the current original text label pair is compared with each newly added text to determine the newly added emotional element corresponding to each newly added text, thereby determining the label of each newly added text, and constructing each newly added text label pair corresponding to the current original text label pair; each original text label pair and its corresponding each newly added text label pair are used as each enhanced text label pair, and an enhanced training set is constructed; Information enhancement module: Based on the questions in the information reasoning prompts designed based on the thought chain, the large language model is used to obtain the answers to the questions in turn, thereby inferring the implicit information of the enhanced text corresponding to each enhanced text label pair in the enhanced training set; based on the enhanced training set and the implicit information of the enhanced text corresponding to each enhanced text label pair in the enhanced training set, the target training set is obtained; Model building module: Based on the designed input templates of each fine-grained sentiment analysis subtask, each text and implicit information of each text in the target training set is converted into each input sequence of each fine-grained sentiment analysis subtask; based on the designed output templates of each fine-grained sentiment analysis subtask, each label in the target training set is converted into each output sequence of each fine-grained sentiment analysis subtask; the pre-trained language model is trained using each input sequence and each output sequence of each fine-grained sentiment analysis subtask to obtain a sentiment analysis model based on the pre-trained language model.
9. A small sample fine-grained sentiment analysis device based on a large language model, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of a method for fine-grained sentiment analysis with a small number of samples based on a large language model as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the steps of the method for fine-grained sentiment analysis of a small number of samples based on a large language model are implemented as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Construction method of unified generation framework for aspect-level sentiment analysis
CN115455976A
Emotion analysis method and device and big language model training method and device
CN117436438A
Fine-grained emotion element extraction method and system
CN117892719A
Method and apparatus for natural language processing and model training, device and storage medium
WO2024074100A1