Emotion analysis method and device, computer equipment and medium
By using the method of using large language models to calculate the loss value and sorting examples in emotional analysis, the problem of unstable results in the model of the model in the emotional analysis is solved, and more accurate emotional predictions have been achieved, which has a positive impact on applications such as life insurance sales.
Patent Information
- Application Number
- CN202411387278.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-01-24
AI Technical Summary
The existing large language models have sensitive problems in sentiment analysis, which leads to unstable results when processing input examples and cannot accurately predict user emotions.
By obtaining emotional analysis data sets, pre -processing example text, using pre -trained large language models to calculate the loss value of input text, sort out examples based on the loss value, and generate guidance instructions, combined with cross -entropy loss and curriculum learning ideas, optimize examples to select the example selection And sorting.
It improves the accuracy and stability of emotional analysis, forms more accurate emotional prediction results, and helps greater help to application scenarios such as life insurance.
Smart Images

Figure CN119357398A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of artificial intelligence technology, natural language processing technology and financial technology, and in particular to a sentiment analysis method, device, computer equipment and medium. Background Art
[0002] Large language models (LLMs), such as GPT-3 and ChatGPT, have the ability to simulate human natural language capabilities and have made great progress in the field of natural language processing. They have promoted the development of various applications such as machine translation, text summarization, and dialogue systems. With the continuous development of natural language processing application fields, LLMs play a role in various practical scenarios in various ways (such as generation, understanding, and reasoning), providing intelligent, personalized, and efficient services. Due to the large number of parameters of LLMs, a new learning paradigm has emerged, namely in-context learning (ICL) without gradient backpropagation. In ICL, LLMs predict the test prompt based only on context examples of some fixed templates. ICL has become a new trend in evaluating and inferring the capabilities of LLMs, which enables LLMs to perform complex tasks such as solving mathematical reasoning problems. These powerful capabilities have been widely verified and have become an emerging feature of large language models. However, ICL has the problem of oversensitivity when processing input examples. Examples of different templates or the order of examples may have an impact on the output results. Therefore, solving the oversensitivity problem has become an important challenge for ICL in actual production. Some previous methods mostly select examples independently, ignoring the relationship between examples and not considering the potential correlation between examples. This localized example selection method may cause the model to lack a global view during the learning process, limiting the model's use of the interactive information between different examples.
[0003] For example, in actual business, by performing sentiment analysis on the text records of users' life insurance sales calls, we can better classify the target groups, form more accurate user portraits, and formulate targeted sales strategies for different groups, thereby improving the success rate of sales business. However, when using large language models (LLMs), existing business models often only randomly select a few examples from the sample set based on some indicators and splice them together with the query as the input of the model. This approach is highly dependent on the randomness of example selection, and it is difficult to improve the prediction accuracy, resulting in distortion of data analysis and the inability to obtain accurate user portraits, thereby limiting the ability to improve life insurance sales performance. Summary of the invention
[0004] The present invention provides an artificial intelligence sentiment analysis method, device, computer equipment and medium to solve the current technical problem that it is impossible to accurately predict the user's sentiment based on input text.
[0005] In a first aspect, a sentiment analysis method is provided, comprising:
[0006] Acquire a sentiment analysis data set, wherein the sentiment analysis data set consists of a plurality of examples, and the examples include a test text and a true sentiment label corresponding to the test text;
[0007] Preprocessing each example in the sentiment analysis data set to obtain input text;
[0008] Inputting each word of each input text into a pre-trained large language model, and calculating the loss value of each input text based on the predicted value output by the large language model;
[0009] Based on the loss values of the input texts, the instances corresponding to the input texts are sorted, and a guidance instruction is generated based on the sorting result;
[0010] The text to be queried is obtained, and the guiding instruction is concatenated with the text to be queried and then input into the large language model to obtain a sentiment analysis result.
[0011] In a second aspect, a sentiment analysis device is provided, comprising:
[0012] A data acquisition module is used to acquire a sentiment analysis data set, wherein the sentiment analysis data set is composed of a plurality of examples, and the examples include a test text and a real sentiment label corresponding to the test text;
[0013] A preprocessing module, used to preprocess each example in the sentiment analysis data set to obtain input text;
[0014] A loss value calculation module, used for inputting each word of each input text into a pre-trained large language model, and calculating the loss value of each input text based on the predicted value output by the large language model;
[0015] A sorting module, used to sort the instances corresponding to the input texts based on the loss values of the input texts, and generate guidance instructions based on the sorting results;
[0016] The sentiment analysis module is used to obtain the text to be queried, splice the guiding instruction with the text to be queried, and input the spliced instructions into the large language model to obtain a sentiment analysis result.
[0017] In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned sentiment analysis method when executing the computer program.
[0018] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned sentiment analysis method are implemented.
[0019] In the scheme implemented by the above-mentioned sentiment analysis method, device, computer equipment and storage medium, a sentiment analysis data set is first obtained, wherein the sentiment analysis data set is composed of multiple examples, and the examples include test texts and real sentiment labels corresponding to the test texts; then, each example in the sentiment analysis data set is preprocessed to obtain an input text; then, each word unit of each input text is input into a pre-trained large language model, and based on the predicted value output by the large language model, the loss value of each input text is calculated; then, based on the loss value of each input text, the instances corresponding to each input text are sorted, and a guide instruction is generated based on the sorting result; finally, the text to be queried is obtained, and the guide instruction is spliced with the text to be queried and then input into the large language model to obtain a sentiment analysis result. In the present invention, examples are searched and sorted using an indicator based on cross entropy loss and the idea of curriculum learning, and then the guide instruction generated after sorting is spliced with the text to be queried, which can form a more accurate sentiment prediction and provide greater help to life insurance sales. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0021] Figure 1 is a schematic diagram of an application environment of a sentiment analysis method according to an embodiment of the present invention;
[0022] Figure 2 is a flow chart of a sentiment analysis method according to an embodiment of the present invention;
[0023] Figure 3 yes Figure 1 A schematic flow chart of a specific implementation of step S20;
[0024] Figure 4 yes Figure 1 A schematic flow chart of a specific implementation of step S30;
[0025] Figure 5 yes Figure 4 A schematic flow chart of a specific implementation of step S40;
[0026] Figure 6 is a structural schematic diagram of a sentiment analysis device in one embodiment of the present invention;
[0027] Figure 7 is a schematic diagram of a structure of a computer device in one embodiment of the present invention;
[0028] Figure 8 It is another structural schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0029] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0030] The sentiment analysis method provided by the embodiment of the present invention can be applied in Figure 1 In an application environment, the client communicates with the server through a network. The server can obtain a sentiment analysis data set through the client, wherein the sentiment analysis data set consists of multiple examples, the examples including a test text and a real sentiment label corresponding to the test text; preprocess each example in the sentiment analysis data set to obtain an input text; input each word of each input text into a pre-trained large language model, and calculate the loss value of each input text based on the predicted value output by the large language model; sort the instances corresponding to each input text based on the loss value of each input text, and generate a guide instruction based on the sorting result; obtain the text to be queried, splice the guide instruction with the text to be queried, and input it into the large language model to obtain the sentiment analysis result. In the present invention, the index based on the cross entropy loss and the idea of course learning are used to search and sort the examples, and then the guide instruction generated after sorting is spliced with the text to be queried, which can form a more accurate sentiment prediction and play a greater role in life insurance sales. Among them, the client can be but not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server can be implemented with an independent server or a server cluster consisting of multiple servers. The present invention is described in detail below through specific embodiments.
[0031] See also Figure 2 As shown, Figure 2 A flow chart of a sentiment analysis method provided by an embodiment of the present invention includes the following steps:
[0032] S10: Acquire a sentiment analysis dataset, wherein the sentiment analysis dataset consists of a plurality of examples, and the examples include a test text and a true sentiment label corresponding to the test text.
[0033] In this embodiment, a subset of sample size M is randomly selected from the sentiment analysis sample set, and each example is specified to include a test text and a real sentiment label corresponding to the test text. For example, a specific example is as follows: the input is "this movie is very good", and its corresponding real sentiment label is "positive sentiment". The present invention trains the model in a supervised learning manner, so that the output of the model can be closer to the actual situation. Similar to the invisible model training, the prediction of the model is processed from left to right, that is, the real situation label plays a certain output constraint role and guides the model to output.
[0034] Optionally, the sentiment analysis data set can be obtained from historical data, for example, a subset of sample size M is randomly selected from the sentiment analysis sample set, and the subset is used as the sentiment analysis data set. The data in the sentiment analysis sample set can be obtained from the sales staff's daily call records or text records to ensure the accuracy of the labels of the sentiment analysis data set, so that the output of the subsequent model can be closer to the actual situation.
[0035] S20: Preprocess each example in the sentiment analysis data set to obtain input text.
[0036] In this embodiment, in order to make the model have a unified input format and avoid the model being unable to accurately recognize the input features, it is necessary to first preprocess each example in the sentiment analysis data set. The purpose of preprocessing is to naturally associate the test text in the example with the real sentiment label, and then combine them into the model.
[0037] Optional, see Figure 3 , the step S20 specifically includes:
[0038] S21: Obtaining a preset text template, wherein the text template is used to describe the corresponding relationship between a test text and a real emotion label of the test text;
[0039] S22: Assembling each example in the sentiment analysis data set with the text template to obtain an input text with a set format.
[0040] In this embodiment, a text template is preset, and the text template is used to describe the corresponding relationship between the test text and the real sentiment label, so as to naturally associate the test text with the real sentiment label. For example, a text template is: "In this review "text", the sentiment is label." Therefore, after obtaining the test text and the real sentiment label corresponding to the test text, you only need to fill the test text and the real sentiment label into the template to quickly obtain the input text of the set form. For example, the example is a test text and a real sentiment label. For example: the test text is "This movie is good to watch", and the label is "positive sentiment". It can be seen that these two sentences are not naturally associated together, and the template is a mapping package, which artificially specifies the association between the test text and a real sentiment label. For example, the template is: "For this "test text", its corresponding label is "real sentiment label"", then the above example (test text is "This movie is good to watch", label is "positive sentiment") after being assembled with the template forms the input text: For this "This movie is good to watch", its corresponding label is "positive sentiment", so that the test text and the real sentiment label can be naturally associated.
[0041] S30: Inputting each word of each input text into a pre-trained large language model, and calculating the loss value of each input text based on the predicted value output by the large language model.
[0042] In this embodiment, since the larger language model pre-training distribution is closer to the downstream task samples, the smaller the cross entropy loss is, and the better the ICL performance as an example is, in order to measure the difference between the distribution of the downstream task samples and the large model pre-training distribution, the present invention uses the cross entropy loss to specifically measure this feature. Specifically, the present invention puts an example into a specified template and inputs it into the model. The model calculates the hidden state of each token of the input sequence and outputs a predicted value. Then, the cross entropy loss value of each token is calculated according to the method of calculating the cross entropy loss of the generation task, and finally the overall loss value is obtained.
[0043] Optional, see Figure 4 , the step S30 specifically includes:
[0044] S31: inputting each word unit of each input text into a pre-trained large language model to obtain the next predicted word unit corresponding to each word unit;
[0045] S32: Calculate the cross entropy loss value of each word-gram based on the predicted next word-gram of the word-gram and the next actual word-gram of the word-gram;
[0046] S33: Calculate the loss value of the input text based on the cross entropy of each word unit of the input text.
[0047] In this embodiment, large language models usually contain billions or even hundreds of billions of parameters, and they are able to learn complex language patterns and features by training on large-scale text data. Such models are not only able to perform tasks such as text summarization, translation, and sentiment analysis, but also have contextual learning and step-by-step reasoning capabilities, enabling them to perform well in specific tasks and even perform new tasks by understanding task instructions without explicit samples.
[0048] Optionally, the large language model (LLM) can be one of GPT-4, BERT, XLNet, T5, and RoBERTa, which have good effects in the field of natural language processing. Among them, GPT-4 is one of the largest language models at present, with 235 billion parameters, and can generate high-quality natural language text. BERT is a pre-trained language model based on a bidirectional encoder, with a parameter volume of 300 million, which is mainly used in natural language processing tasks. XLNet is a pre-trained language model using global autoregression and self-attention mechanisms, which is suitable for a variety of natural language processing tasks. T5 adopts the "Text-to-Text Transfer Transformer" (T5) framework, which can perform transfer learning on multiple natural language processing tasks. RoBERTa is an improvement and optimization of the BERT model, which can be used for multiple natural language processing tasks. The present invention does not limit the specific type of the large language model, and it only needs to meet the prediction function of the present invention.
[0049] Further, in an embodiment of the present invention, when the large language model makes a prediction, the cross-entropy loss function is used to predict the loss value corresponding to each input text. Specifically, in the broad field of machine learning and deep learning, the loss function plays a vital role. It serves as a standard for evaluating the difference between the model prediction value and the true value, and guides the direction of model training. Among the many loss functions, the cross-entropy loss function is widely used because of its superior performance in dealing with classification problems. The cross-entropy loss function is mainly used to evaluate the difference between the probability distribution predicted by the model and the true probability distribution. In the classification task, the model usually outputs the predicted probability of each category, and the cross-entropy loss function guides the update of the model parameters by comparing the difference between these predicted probabilities and the true label (usually in the form of one-hot encoding). The advantage of the cross-entropy loss function is that it can converge quickly because it directly measures the difference between the predicted probability and the true label, rather than the absolute error between the predicted value and the actual value. This difference measurement method enables the model to adjust parameters faster during the training process to achieve more accurate predictions.
[0050] The method for calculating the cross entropy loss of the generation task includes the cross entropy loss function of the single-label classification task and the cross entropy loss function of the multi-label classification task. The cross entropy loss function of the single-label classification task for the binary classification task is as follows: In the binary classification problem, the predicted probabilities of the model output are p (the probability of belonging to category 1) and 1-p (the probability of belonging to category 0), and the true label is y (when the sample belongs to category 1, y=1; when the sample belongs to category 0, y=0). For a single sample, the calculation formula of the cross entropy loss is L=-ylog(p)-(1-y)log(1-p). The cross entropy loss function of the label classification task for the multi-classification task is as follows: For the multi-classification problem, the softmax function is usually used to convert the original score output by the model into a probability distribution, and then the cross entropy loss is calculated for each category, and finally the total loss is summed up. The independent and identically distributed cross entropy loss function of the multi-label classification task is as follows: In the multi-label classification task, each sample can have multiple labels. In this case, the sigmoid function is used as the output of the last layer of the network, and each neuron in the last layer is regarded as the probability that the sample contains a certain label. For a certain category in multi-label classification, the true distribution is a binomial distribution with possible values of 0 or 1, and the distribution predicted by the network can be understood as the probability that the label is 1. The cross entropy is calculated as follows: The cross entropy loss function of a certain category is L = -yilog(pi)-(1-yi)log(1-pi), where yi is the i-th element in the one-hot encoding vector of the true label, and pi is the i-th element in the probability distribution vector predicted by the model.
[0051] In general, the cross entropy loss function is an important tool to measure the difference between the model prediction and the true label. By minimizing the cross entropy loss, the model performance can be effectively optimized. The present invention preferably uses the cross entropy loss function of the single-label classification task to calculate the loss value.
[0052] Specifically, the calculation process of the loss value in the embodiment of the present invention is substantially similar to the training of the next tokenprediction (NTP) by the cross entropy function according to the modeling of the large language model. The large language model first divides the input text into the smallest word units. For example, "this movie is good" can be divided into three word units "this", "movie" and "good". The next word unit is predicted by the current word unit. If the degree of consistency between the predicted value and the actual value is higher, the loss value is smaller, the accuracy of the model is higher, and the ICL performance as an example is better. Therefore, the embodiment of the present invention measures whether the example is suitable as part of the guidance instruction by calculating the loss value.
[0053] Optionally, the step S33 specifically includes:
[0054] Based on the cross entropy loss value of each word unit of the input text, an average value of the cross entropy loss value of each word unit of the input text is calculated;
[0055] Based on the average value, a loss value of the input text is obtained.
[0056] In this embodiment, after calculating the cross-entropy loss value of each word unit, the cross-entropy loss value of a single input text is measured by taking the average of the cross-entropy loss values of each word unit, thereby being able to more reasonably evaluate the prediction ability of the large language model for a single input text, and ensuring that the selected examples can more accurately guide the large language model to make predictions.
[0057] S40: sorting the instances corresponding to the input texts based on the loss values of the input texts, and generating guidance instructions based on the sorting results.
[0058] In this embodiment, in order to obtain guidance instructions with higher guidance accuracy, after obtaining the loss value of each input text, the examples corresponding to each input text are sorted according to the loss value of each input text, and then the guidance instructions are generated according to the sorting results.
[0059] Optional, see Figure 5 , the step S40 specifically includes:
[0060] S41: based on the loss values of the input texts, screening the examples corresponding to the input texts to screen out a sample group that meets the preset loss value requirements;
[0061] S42: sorting the instances corresponding to the input texts in the sample group in a manner of decreasing loss values;
[0062] S43: Based on the sorting result, the examples in the sample group are spliced to obtain a guiding instruction.
[0063] In this embodiment, in order to avoid the interference of the examples corresponding to the input text with a large loss value on the final prediction of the large language model, it is first necessary to screen the examples corresponding to each input text according to the loss value, screen out the samples that do not meet the loss value requirements, obtain the required sample group, and then sort the examples of the sample group according to the loss value size and splice them to obtain the required guidance instructions. Exemplarily, after obtaining the loss value of each sample in the subset, a group of samples with the smallest loss value is selected, and the samples are sorted from large to small according to the size of the loss value difference between the samples to obtain the final guidance instruction (prompt). In the field of artificial intelligence (AI), "prompt" refers to text or instructions that provide input to the model to guide it to generate a specific output. It is a text paragraph provided by the user when interacting with the model, which is used to describe the information, answers, text, etc. that the user wants to obtain from the model. The purpose of the prompt is to guide the model to produce the required response in order to better control the generated output. For a large language model, the prompt can be a short question, a complete paragraph, or a set of instructions, depending on the user's needs and scenarios. When generating text, the model will try to understand the prompt and generate a corresponding response based on its understanding. Prompt directly affects the content, style and quality of the text generated by the model. In this embodiment, prompt also directly affects the output of the subsequent sentiment prediction label. Each group of examples is concatenated in the following form to obtain prompt: \n represents the separator, E is the final assembly input, that is, the guide instruction, e 1、 e 2、 e n are various examples, It means to splice together.
[0064] Optionally, the step S41 specifically includes:
[0065] Get the preset loss value threshold;
[0066] The loss value of each input text is compared with the preset loss value threshold, and examples corresponding to input texts with loss values less than the preset loss value threshold are screened out to obtain a sample group that meets the preset loss value requirements.
[0067] In this embodiment, the preset loss value threshold can be set according to actual needs. The higher the accuracy requirement, the smaller the preset loss value threshold. Specifically, the present invention first obtains the preset loss value threshold, and then compares the loss value of each input text with the threshold. If it is greater than the threshold, it means that the example corresponding to the input text is unqualified. At this time, it is directly screened. If it is not greater than the threshold, it is retained. Finally, the multiple examples retained constitute a sample group that meets the preset loss value requirements, which can better assist the large language model in the output of sentiment prediction labels.
[0068] S50: Obtain the text to be queried, concatenate the guide instruction with the text to be queried, and input the concatenated instructions into the large language model to obtain a sentiment analysis result.
[0069] In this embodiment, after the guidance instruction is obtained, all subsequent query texts can be subjected to sentiment analysis according to the guidance instruction, thereby obtaining more accurate sentiment analysis results, which is more helpful for life insurance sales. In specific implementation, the guidance instruction can be spliced with the query text, and then input into the large language model together. For example, the splicing form of the guidance instruction and the query text is: That is, prompt is concatenated in front of the query text y, and the large language model is input to obtain the predicted label of the query text y, that is, the sentiment analysis result.
[0070] Optionally, the step S50 specifically includes:
[0071] Obtaining the text to be queried, and splicing the guide instruction to the front of the text to be queried to obtain an input instruction;
[0072] The input instruction is input into the large language model to predict the sentiment analysis result through the large language model.
[0073] In this embodiment, the sentiment analysis results can be defined according to actual conditions. Before model training, the sentiment analysis results can be defined in advance in the form of labels, such as labels including negative sentiment, positive sentiment, etc., and then when using the large language model for calculation, first obtain the text to be queried, and then concatenate the prompt in front of the text to be queried, and then input them into the large language model together. The large language model can more accurately output sentiment analysis results that conform to the actual situation.
[0074] In order to better apply the idea of model learning to ICL, the embodiment of the present invention introduces the concept of curriculum learning, and draws on the idea of curriculum learning to determine the order of examples. The idea of curriculum learning is to gradually introduce more and more complex examples so that the model can gradually learn and adapt to more challenging tasks. In ICL, the embodiment of the present invention adopts a similar idea to sort examples in a progressive manner according to the difficulty or complexity of the examples. Combined with the characteristics of ICL, the embodiment of the present invention applies the concept of curriculum learning to the example selection process. Through the gradual introduction of examples, the model can gradually understand and adapt to different types of contexts and task requirements. In this way, the model can continuously improve its ability in more challenging examples, so as to better cope with complex natural language processing tasks. By combining ICL with curriculum learning, it is expected that the model can learn and reason more effectively, and improve its understanding and processing capabilities for diverse and complex problems. This comprehensive method can enhance the expressiveness and adaptability of the model, and improve its performance and robustness in practical applications. In view of this, the embodiment of the present invention uses the ICL example selection index as a difficulty measurer for curriculum learning, and uses it to judge the order of selected examples.
[0075] In order to measure the difference between the distribution of downstream task samples and the pre-trained distribution of the large model, the embodiment of the present invention uses cross-entropy loss to specifically measure this feature. Specifically, the embodiment of the present invention puts an example into a specified template and inputs it into the model. The model calculates the hidden state of each token in the input sequence and outputs a logical value. Next, the embodiment of the present invention calculates the cross entropy of each token according to the method of calculating the cross entropy loss for the generated task and averages the final loss value. The present invention believes that the closer the downstream task sample is to the pre-trained distribution of the large model, the smaller its cross entropy loss, and the better the ICL performance as an example. And the embodiment of the present invention also regards the loss value as the amount of learning that the model needs to learn, so the embodiment of the present invention also uses the loss as a criterion for example sorting. Therefore, the sentiment analysis method provided by the present invention has the following innovations:
[0076] 1. We chose to use the big model itself to make judgments directly without introducing more external models in the example selection indicators. The advantage of this is that it reduces interference and makes the judgment more accurate and reasonable. Through the internal mechanism and language ability of the big model, we can better understand and explain the relevance of each example to a given task without being interfered by external models. This method gives full play to the advantages of the big model itself and improves the accuracy and stability of example selection.
[0077] 2. In order to further improve ICL, the embodiment of the present invention introduces the idea of curriculum learning, and regards the selection and sorting of examples as a learning process of the model. The selection and sorting of examples are regarded as a process in which the model gradually adapts to and learns from examples of different difficulty levels. Similar to curriculum learning, more and more complex examples are gradually introduced to allow the model to gradually master more challenging tasks. From this learning perspective, the selection and sorting of examples can be better guided, so that the model can learn and improve in a targeted manner. By combining curriculum learning with ICL, the learning process of the model can be better guided, and its understanding and processing capabilities of different examples can be improved. This comprehensive approach enables the model to continue to grow in ever-changing examples and gradually adapt to various complex natural language processing tasks. In this way, it is expected to improve the effect of ICL and further improve the application capabilities of large language models.
[0078] It can be seen that in the above scheme, using the cross-entropy loss-based indicator and the idea of curriculum learning to search and sort examples, and then splicing the guidance instructions generated after sorting with the text to be queried, can form a more accurate sentiment prediction and play a greater role in life insurance sales.
[0079] At the same time, the above solution directly uses the big model itself to make judgments without introducing more external models. In the example selection index, the advantage of doing so is that it reduces interference, making the judgment more accurate and reasonable. Through the internal mechanism and language ability of the big model, it can better understand and explain the relevance of each example to the given task without being interfered by external models. This method gives full play to the inherent advantages of the big model and improves the accuracy and stability of example selection.
[0080] In addition, in order to further improve ICL, the present invention introduces the idea of curriculum learning, and regards the selection and sorting of examples as a learning process of the model. The present invention regards the selection and sorting of examples as a process in which the model gradually adapts to and learns examples of different difficulty levels. Similar to curriculum learning, the present invention gradually introduces more and more complex examples, allowing the model to gradually master more challenging tasks. Through this learning perspective, the selection and sorting of examples can be better guided, so that the model can learn and improve in a targeted manner. By combining curriculum learning and ICL, the learning process of the model can be better guided, and its understanding and processing capabilities of different examples can be improved. This comprehensive approach enables the model to continue to grow in ever-changing examples and gradually adapt to various complex natural language processing tasks.
[0081] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0082] In one embodiment, a sentiment analysis device is provided, which corresponds one-to-one to the sentiment analysis method in the above embodiment. Figure 6 As shown, the sentiment analysis device includes a data acquisition module 101, a preprocessing module 102, a loss value calculation module 103, a sorting module 104 and a sentiment analysis module 105. The detailed description of each functional module is as follows:
[0083] The data acquisition module 101 is used to acquire a sentiment analysis data set, wherein the sentiment analysis data set is composed of a plurality of examples, and the examples include a test text and a real sentiment label corresponding to the test text;
[0084] A preprocessing module 102 is used to preprocess each example in the sentiment analysis data set to obtain an input text;
[0085] A loss value calculation module 103, used for inputting each word of each input text into a pre-trained large language model, and calculating the loss value of each input text based on the prediction value output by the large language model;
[0086] A sorting module 104, configured to sort the instances corresponding to the input texts based on the loss values of the input texts, and generate a guiding instruction based on the sorting result;
[0087] The sentiment analysis module 105 is used to obtain the text to be queried, concatenate the guide instruction with the text to be queried, and input the concatenated instructions into the large language model to obtain a sentiment analysis result.
[0088] In one embodiment, the preprocessing module 102 is specifically configured to:
[0089] Obtaining a preset text template, wherein the text template is used to describe the corresponding relationship between the test text and the real emotion label of the test text;
[0090] Each example in the sentiment analysis data set is assembled with the text template to obtain an input text with a set form.
[0091] In one embodiment, the loss value calculation module 103 is specifically used to:
[0092] Input each word unit of each input text into a pre-trained large language model to obtain the next predicted word unit corresponding to each word unit;
[0093] Calculate the cross entropy loss value of each word-gram based on the predicted next word-gram of the word-gram and the next actual word-gram of the word-gram;
[0094] Based on the cross entropy of each word unit of the input text, the loss value of the input text is calculated.
[0095] In one embodiment, the loss value calculation module 103 is further used to:
[0096] Based on the cross entropy loss value of each word unit of the input text, an average value of the cross entropy loss value of each word unit of the input text is calculated;
[0097] Based on the average value, a loss value of the input text is obtained.
[0098] In one embodiment, the sorting module 104 is specifically configured to:
[0099] Based on the loss values of the input texts, the examples corresponding to the input texts are screened to select a sample group that meets the preset loss value requirements;
[0100] Sorting the instances corresponding to the input texts in the sample group in a manner of decreasing loss values;
[0101] Based on the sorting result, each of the examples in the sample group is spliced to obtain a guiding instruction.
[0102] In one embodiment, the sorting module 104 is further configured to:
[0103] Get the preset loss value threshold;
[0104] The loss value of each input text is compared with the preset loss value threshold, and examples corresponding to input texts with loss values less than the preset loss value threshold are screened out to obtain a sample group that meets the preset loss value requirements.
[0105] In some embodiments, the sentiment analysis module 105 is specifically configured to:
[0106] Obtaining the text to be queried, and splicing the guide instruction to the front of the text to be queried to obtain an input instruction;
[0107] The input instruction is input into the large language model to predict the sentiment analysis result through the large language model.
[0108] The present invention provides a sentiment analysis device, which uses an indicator based on cross entropy loss and the idea of curriculum learning to search and sort examples, and then splices the guidance instructions generated after sorting with the text to be queried, which can form a more accurate sentiment prediction and provide greater help to life insurance sales.
[0109] At the same time, the above solution directly uses the big model itself to make judgments without introducing more external models. In the example selection index, the advantage of doing so is that it reduces interference, making the judgment more accurate and reasonable. Through the internal mechanism and language ability of the big model, it can better understand and explain the relevance of each example to the given task without being interfered by external models. This method gives full play to the inherent advantages of the big model and improves the accuracy and stability of example selection.
[0110] In addition, in order to further improve ICL, the present invention introduces the idea of curriculum learning, and regards the selection and sorting of examples as a learning process of the model. The present invention regards the selection and sorting of examples as a process in which the model gradually adapts to and learns examples of different difficulty levels. Similar to curriculum learning, the present invention gradually introduces more and more complex examples, allowing the model to gradually master more challenging tasks. Through this learning perspective, the selection and sorting of examples can be better guided, so that the model can learn and improve in a targeted manner. By combining curriculum learning and ICL, the learning process of the model can be better guided, and its understanding and processing capabilities of different examples can be improved. This comprehensive approach enables the model to continue to grow in ever-changing examples and gradually adapt to various complex natural language processing tasks.
[0111] For the specific definition of the sentiment analysis device, please refer to the definition of the sentiment analysis method above, which will not be repeated here. Each module in the above sentiment analysis device can be implemented in whole or in part by software, hardware and a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0112] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client through a network connection. When the computer program is executed by the processor, it implements the functions or steps of a sentiment analysis method service side.
[0113] In one embodiment, a computer device is provided. The computer device may be a client, and its internal structure diagram may be as follows: Figure 8As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, it implements the functions or steps of a client side of a sentiment analysis method.
[0114] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0115] Acquire a sentiment analysis data set, wherein the sentiment analysis data set consists of a plurality of examples, and the examples include a test text and a true sentiment label corresponding to the test text;
[0116] Preprocessing each example in the sentiment analysis data set to obtain input text;
[0117] Inputting each word of each input text into a pre-trained large language model, and calculating the loss value of each input text based on the predicted value output by the large language model;
[0118] Based on the loss values of the input texts, the instances corresponding to the input texts are sorted, and a guidance instruction is generated based on the sorting result;
[0119] The text to be queried is obtained, and the guiding instruction is concatenated with the text to be queried and then input into the large language model to obtain a sentiment analysis result.
[0120] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0121] Acquire a sentiment analysis data set, wherein the sentiment analysis data set consists of a plurality of examples, and the examples include a test text and a true sentiment label corresponding to the test text;
[0122] Preprocessing each example in the sentiment analysis data set to obtain input text;
[0123] Inputting each word of each input text into a pre-trained large language model, and calculating the loss value of each input text based on the predicted value output by the large language model;
[0124] Based on the loss values of the input texts, the instances corresponding to the input texts are sorted, and a guidance instruction is generated based on the sorting result;
[0125] The text to be queried is obtained, and the guiding instruction is concatenated with the text to be queried and then input into the large language model to obtain a sentiment analysis result.
[0126] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can refer to the relevant descriptions on the server side and the client side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0127] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0128] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0129] It should be noted that if software tools or components other than those of the Company appear in the embodiments of the present application, they are only used for illustration and do not represent actual use. The above-described embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the above-mentioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the above-mentioned embodiments can still be modified, or some of the technical features thereof can be replaced by equivalents; and these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A sentiment analysis method, characterized in that: include: Acquire a sentiment analysis data set, wherein the sentiment analysis data set consists of a plurality of examples, and the examples include a test text and a true sentiment label corresponding to the test text; Preprocessing each example in the sentiment analysis data set to obtain input text; Inputting each word of each input text into a pre-trained large language model, and calculating the loss value of each input text based on the predicted value output by the large language model; Based on the loss values of the input texts, the instances corresponding to the input texts are sorted, and a guidance instruction is generated based on the sorting result; The text to be queried is obtained, and the guiding instruction is concatenated with the text to be queried and then input into the large language model to obtain a sentiment analysis result.
2. The sentiment analysis method according to claim 1, characterized in that: The preprocessing of each example in the sentiment analysis data set to obtain input text includes: Obtaining a preset text template, wherein the text template is used to describe the corresponding relationship between the test text and the real emotion label of the test text; Each example in the sentiment analysis data set is assembled with the text template to obtain an input text with a set form.
3. The sentiment analysis method according to claim 1 or 2, characterized in that: The step of inputting each word of each input text into a pre-trained large language model, and calculating the loss value of each input text based on the predicted value output by the large language model, comprises: Input each word unit of each input text into a pre-trained large language model to obtain the next predicted word unit corresponding to each word unit; Calculate the cross entropy loss value of each word-gram based on the predicted next word-gram of the word-gram and the next actual word-gram of the word-gram; Based on the cross entropy of each word unit of the input text, the loss value of the input text is calculated.
4. The sentiment analysis method according to claim 3, characterized in that: The step of calculating the loss value of the input text based on the cross entropy loss value of each word unit of the input text comprises: Based on the cross entropy loss value of each word unit of the input text, an average value of the cross entropy loss value of each word unit of the input text is calculated; Based on the average value, a loss value of the input text is obtained.
5. The sentiment analysis method according to claim 1, characterized in that: The step of sorting the instances corresponding to the input texts based on the loss values of the input texts and generating the guidance instructions based on the sorting results includes: Based on the loss values of the input texts, the examples corresponding to the input texts are screened to select a sample group that meets the preset loss value requirements; Sorting the instances corresponding to the input texts in the sample group in a manner of decreasing loss values; Based on the sorting result, each of the examples in the sample group is spliced to obtain a guiding instruction.
6. The sentiment analysis method according to any one of claims 1 to 5, characterized in that: The step of screening the examples corresponding to the input texts based on the loss values of the input texts to screen out a sample group meeting the preset loss value requirements includes: Get the preset loss value threshold; The loss value of each input text is compared with the preset loss value threshold, and examples corresponding to input texts with loss values less than the preset loss value threshold are screened out to obtain a sample group that meets the preset loss value requirements.
7. The sentiment analysis method according to any one of claims 1 to 5, characterized in that: The step of obtaining the text to be queried, splicing the guide instruction with the text to be queried, and inputting the spliced text into the large language model to obtain a sentiment analysis result includes: Obtaining the text to be queried, and splicing the guide instruction to the front of the text to be queried to obtain an input instruction; The input instruction is input into the large language model to predict the sentiment analysis result through the large language model.
8. A sentiment analysis device, characterized in that: include: A data acquisition module is used to acquire a sentiment analysis data set, wherein the sentiment analysis data set is composed of a plurality of examples, and the examples include a test text and a real sentiment label corresponding to the test text; A preprocessing module, used to preprocess each example in the sentiment analysis data set to obtain input text; A loss value calculation module, used for inputting each word of each input text into a pre-trained large language model, and calculating the loss value of each input text based on the predicted value output by the large language model; A sorting module, used to sort the instances corresponding to the input texts based on the loss values of the input texts, and generate guidance instructions based on the sorting results; The sentiment analysis module is used to obtain the text to be queried, splice the guiding instruction with the text to be queried, and input the spliced instructions into the large language model to obtain a sentiment analysis result.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the sentiment analysis method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the sentiment analysis method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Emotion analysis method based on emergency scene
CN120804331A