Emotion analysis method, device and system and medium
By using diverse prompt templates and voting algorithms in financial text sentiment analysis, combined with large language models, the problems of high labeling costs and insufficient generalization capabilities in the existing technology are solved, and a high-accurate sentiment analysis of financial texts are achieved.
Patent Information
- Application Number
- CN202411058338.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-11-08
AI Technical Summary
Existing financial text sentiment analysis methods are difficult to achieve accurate sentiment analysis while balancing the cost of labeling data. Especially since the construction of emotional dictionary requires the participation of domain experts and ignores context semantic differences, the supervised learning method requires a large amount of labeling data and lacks generalization ability. .
By obtaining the target text to be analyzed, generating prompt text based on several prompt templates, combining with large language models for sentiment analysis, and using voting algorithms to determine the final emotional label, reducing the annotation cost and workload, and improving the model's sentiment analysis task in financial text adaptability and accuracy in.
It reduces the annotation cost and workload, improves the accuracy and reliability of sentiment analysis of financial texts, enhances the adaptability and generalization capabilities of the model, and alleviates the hallucination problems of large language models.
Smart Images

Figure CN118916491A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of financial technology, and in particular to a sentiment analysis method, device, system and medium. Background Art
[0002] In recent years, a large amount of text data with emotions has emerged on the Internet, and more and more fields have shown the need for text sentiment analysis. Sentiment analysis has a high degree of field relevance, that is, feature words have different emotional attributes in different fields. Financial text sentiment analysis refers to the task of analyzing the sentiment tendency of text data in the financial field. Since sentiment tendency can affect market sentiment and investment decisions, sentiment analysis of financial text has very important application value.
[0003] Traditional solutions for sentiment analysis of financial texts are usually based on sentiment dictionaries or supervised learning methods. The method based on sentiment dictionaries is an unsupervised learning method that does not require model training and has low computational costs. However, the construction of sentiment dictionaries requires the participation of domain experts, and the quality of the dictionary directly affects the results of sentiment analysis. In addition, it usually only considers the number and polarity of sentiment words, while ignoring the subtle differences in contextual semantics. Supervised learning methods require a large amount of annotated financial text data to train sentiment classification models, which not only has high labor costs, but also the language and sentiment in the financial field are often affected by factors such as market fluctuations, changes in financial news, and industry-specific terminology. Therefore, the trained model may encounter the problem of insufficient generalization ability when processing new financial texts. Therefore, how to achieve accurate sentiment analysis of financial texts while balancing the cost of annotating data is an urgent problem to be solved. Summary of the invention
[0004] In view of the above-mentioned deficiencies in the prior art, the object of the present invention is to provide a sentiment analysis method, device, system and medium that can be applied to financial technology or other related fields. Its main purpose is to control the labeling cost in financial sentiment analysis tasks while improving the accuracy of sentiment analysis.
[0005] The technical solution of the present invention is as follows:
[0006] A first aspect of the present invention provides a sentiment analysis method, comprising:
[0007] Get the target text to be analyzed;
[0008] Generate corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set, wherein the prompt texts are used to prompt the large language model to perform sentiment analysis based on the target text;
[0009] Inputting the prompt set into a large language model, predicting and outputting a number of emotion tags, and obtaining a predicted emotion tag set;
[0010] The final emotion label of the target text is determined from the predicted emotion label set according to a voting algorithm.
[0011] In one embodiment, before generating corresponding prompt texts according to the target text and a plurality of prompt templates and obtaining a prompt set, the method further comprises:
[0012] Confirm the current sentiment analysis scenario of the target text.
[0013] In one embodiment, generating corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set includes:
[0014] Confirming a corresponding prompt template library according to the current sentiment analysis scenario, wherein the prompt template library stores a plurality of prompt templates associated with the sentiment analysis scenario;
[0015] A plurality of prompt templates are matched in the prompt template library, and corresponding prompt texts are generated according to the matched prompt templates and the target text to obtain a prompt set.
[0016] In one embodiment, the matching of several prompt templates in the prompt template library specifically includes:
[0017] A number of prompt templates are randomly selected from the prompt template library.
[0018] In one embodiment, the matching of several prompt templates in the prompt template library includes:
[0019] Obtaining the adaptability score of each prompt template in the prompt template library;
[0020] The first several prompt templates are selected according to the ranking of the adaptability scores of the prompt templates to obtain a prompt set.
[0021] In one embodiment, determining the final emotion tag of the target text from the predicted emotion tag set according to a voting algorithm includes:
[0022] Counting the number of each type of label in the predicted emotion label set;
[0023] The label with the largest number is confirmed as the final sentiment label of the target text.
[0024] In one embodiment, the large language model is an OpenChineseLLaMA model.
[0025] A second aspect of the present invention provides a sentiment analysis device, comprising:
[0026] An acquisition module is used to acquire the target text to be analyzed;
[0027] A prompt set generation module, used to generate corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set, wherein the prompt texts are used to prompt the large language model to perform sentiment analysis based on the target text;
[0028] An input analysis module, used for inputting the prompt set into a large language model, predicting and outputting a number of emotion tags, and obtaining a predicted emotion tag set;
[0029] The tag confirmation module is used to determine the final emotion tag of the target text from the predicted emotion tag set according to a voting algorithm.
[0030] A third aspect of the present invention provides a sentiment analysis system, the system comprising at least one processor; and
[0031] a memory communicatively connected to the at least one processor; wherein,
[0032] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the above-mentioned sentiment analysis method.
[0033] A fourth aspect of the present invention provides a non-volatile computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by one or more processors, the one or more processors can perform the above-mentioned sentiment analysis method.
[0034] Beneficial effects: The present invention discloses a sentiment analysis method, device, system and medium. Compared with the prior art, the embodiment of the present invention obtains a target text to be analyzed; generates corresponding prompt text according to the target text and several prompt templates to obtain a prompt set, and the prompt text is used to prompt a large language model to perform sentiment analysis based on the target text; inputs the prompt set into the large language model, predicts and outputs several sentiment tags, and obtains a predicted sentiment tag set; and determines the final sentiment tag of the target text from the predicted sentiment tag set according to a voting algorithm. By introducing a variety of prompt templates, the annotation cost and workload are reduced, and the adaptability and accuracy of the large language model in the sentiment analysis task can also be improved. Moreover, by determining the final sentiment tag from multiple sentiment tag prediction results through a voting algorithm, the hallucination problem existing in the large language model can be alleviated, and the reliability and stability of the sentiment analysis results can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0036] Figure 1 A flow chart of a sentiment analysis method provided by an embodiment of the present invention;
[0037] Figure 2 A flow chart of step S104 in the sentiment analysis method provided in an embodiment of the present invention;
[0038] Figure 3 A flow chart of constructing a prompt set in the sentiment analysis method provided by an embodiment of the present invention;
[0039] Figure 4 A flow chart of step S202 in the sentiment analysis method provided in an embodiment of the present invention;
[0040] Figure 5 A schematic diagram of the functional modules of the sentiment analysis device provided by an embodiment of the present invention;
[0041] Figure 6 A schematic diagram of the hardware structure of the sentiment analysis system provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail below. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. The embodiments of the present invention are described below in conjunction with the accompanying drawings.
[0043] In recent years, a large amount of text data with emotions has emerged on the Internet, and more and more fields have shown the need for text sentiment analysis. Sentiment analysis has a high degree of field relevance, that is, feature words have different emotional attributes in different fields. Financial text sentiment analysis refers to the task of analyzing the sentiment tendency of text data in the financial field. Since sentiment tendency can affect market sentiment and investment decisions, sentiment analysis of financial text has very important application value.
[0044] Traditional solutions for sentiment analysis of financial texts are usually based on sentiment lexicon methods: using a pre-built sentiment lexicon that contains words and sentiment-related polarities (such as positive or negative). For a given text, the number and polarity of sentiment words can be calculated, and the overall sentiment tendency can be determined based on this information. Or supervised learning methods: using machine learning algorithms such as support vector machines (SVM), Naive Bayes, and deep learning models to learn sentiment classification models from a large amount of annotated financial text data.
[0045] Among the two existing methods, the method based on sentiment dictionary is an unsupervised learning method, which does not require model training and has low computational cost. However, the construction of sentiment dictionary requires the participation of domain experts, and the quality of the dictionary directly affects the results of sentiment analysis. Moreover, it usually only considers the number and polarity of sentiment words, while ignoring the subtle differences in contextual semantics. For example, a word in a sentence may have different sentiment tendencies in different contexts, so the accuracy of sentiment analysis is not enough; while the supervised learning method requires a large amount of annotated financial text data to train the sentiment classification model, which not only has high labor costs, but also the language and sentiment in the financial field are often affected by factors such as market fluctuations, changes in financial news, and industry-specific terminology. Therefore, the trained model may encounter the problem of insufficient generalization ability when processing new financial texts. Therefore, how to achieve accurate sentiment analysis of financial texts while balancing the cost of annotating data is an urgent problem to be solved.
[0046] In order to solve the above problems, the present invention proposes a sentiment analysis method, please refer to Figure 1 , Figure 1 A flowchart of an embodiment of the sentiment analysis method provided by the present invention. The system architecture of the sentiment analysis method provided in this embodiment may include a first terminal device, a second terminal device, a third terminal device, a network and a server. The network is used to provide a medium for a communication link between the first terminal device, the second terminal device, the third terminal device and the server. The network may include various connection types, such as wired and / or wireless communication links, etc.
[0047] The user may use the first terminal device, the second terminal device, and the third terminal device to interact with the server through the network to receive or send messages, etc. Various communication client applications may be installed on the first terminal device, the second terminal device, and the third terminal device, such as knowledge reading applications, web browser applications, search applications, instant messaging tools, email clients, and / or social platform software, etc. (only as examples).
[0048] The first terminal device, the second terminal device, and the third terminal device may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0049] The server may be a server that provides various services, such as a background management server that provides support for the content browsed by the user using the first terminal device, the second terminal device, and the third terminal device (for example only). The background management server may analyze and process the received data such as the user request, and feed back the processing results (such as web pages, information, or data obtained or generated according to the user request) to the terminal device. The server may be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server for a distributed system, or a server combined with a blockchain.
[0050] It should be noted that the sentiment analysis method provided in the embodiment of the present invention can generally be executed by the first terminal device, the second terminal device or the third terminal device. Correspondingly, the sentiment analysis device provided in the embodiment of the present invention can also be set in the first terminal device, the second terminal device or the third terminal device.
[0051] Alternatively, the sentiment analysis method provided in the embodiment of the present invention may also be generally performed by a server. Accordingly, the sentiment analysis device provided in the embodiment of the present invention may generally be arranged in a server. The sentiment analysis method provided in the embodiment of the present invention may also be performed by a server or server cluster that is different from the server and can communicate with the first terminal device, the second terminal device, the third terminal device and / or the server. Accordingly, the sentiment analysis device provided in the embodiment of the present invention may also be arranged in a server or server cluster that is different from the server and can communicate with the first terminal device, the second terminal device, the third terminal device and / or the server.
[0052] It should be understood that the numbers of the above terminal devices, networks and servers are only illustrative. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0053] like Figure 1 As shown, the sentiment analysis method provided in this embodiment specifically includes the following steps:
[0054] S101: Obtain a target text to be analyzed.
[0055] In this embodiment, the target text to be analyzed can be obtained from a variety of channels, such as financial news, social media posts, investor forums, company reports, and telephone conference records. In the sentiment analysis in the financial field, the target text is a financial text, such as a comment text posted by a user on a financial social platform for a specific financial product or market event. This comment text may contain the user's views and emotions on a specific financial product or market event, such as "I am very disappointed with the customer service of Company A. If this situation does not improve, I am worried that it will affect their brand image", "Although the overall market has fallen, I am optimistic about the long-term potential of the xx sector", etc. The user's emotional tendency can be obtained through sentiment analysis to provide a reliable basis for personalized product recommendations or decisions.
[0056] S102: Generate corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set, wherein the prompt texts are used to prompt a large language model to perform sentiment analysis based on the target text.
[0057] In this embodiment, according to the characteristics of the financial field and the requirements of the sentiment analysis task, a plurality of different prompt templates are pre-designed to cover various financial text sentiment expressions and contexts. After the target text is obtained, a plurality of different prompt templates are combined to generate corresponding prompt texts, thereby obtaining a prompt set. Specifically, when generating corresponding prompt texts based on the target text and each prompt template, the target text can be added to a preset position in the prompt template to obtain the corresponding prompt text. The prompt text is used to prompt the large language model to perform sentiment analysis based on the target text. The object that needs to be sentimentally analyzed is clearly pointed out in the prompt text, such as a financial product or financial event, and the large language model is prompted in the prompt text to predict the sentiment polarity of the current target text to the object.
[0058] In the specific implementation, it is assumed that the target text to be analyzed is T, and the sample text and the corresponding sentiment label are Sample text ={t1,t2,t3,...} and =Sample label {l1, l2, l3...} is a set of sentiment labels. For example, taking five prompt texts as an example, the constructed prompt set Prompt = {p1, p2, p3, p4, p5} is as follows:
[0059] (1) p1 = "You are a text sentiment analysis assistant in the financial field. You need to classify the sentiment of the input text into the following categories: positive, neutral or negative. The input is the text to be analyzed for sentiment, and the output is its sentiment category. Here are some examples: Input: {t1} Output: {l1}." Input: {T} Output:"
[0060] (2) p2 = "As a sentiment analysis expert in the financial field, you need to classify the sentiment of a given text and divide it into one of the following sentiment categories: positive, neutral, or negative. The following is an example:
[0061] {t2}Is this sentence positive, neutral, or negative? {l2}
[0062] {T} Is this sentence positive, neutral, or negative? "
[0063] (3) p3 = "You are a professional financial consultant. Your task is to judge the sentiment of a given text for your client and classify it as positive, neutral or negative. Please refer to the following example for sentiment classification:
[0064] Text: {t3}
[0065] Category: {l3}
[0066] Text: {T}"
[0067] (4) p4 = “As a professional financial sentiment assessment expert, your task is to classify the sentiment based on the given text and divide it into positive, neutral or negative.
[0068] Please perform sentiment analysis on the following text and classify it into the defined categories.
[0069] Please present the sentiment classification as a label, for example: positive, neutral, or negative.
[0070] The sentiment classification of the sentence “{t4}” is {l4}.
[0071] The sentiment classification of sentence "T" is"
[0072] (5) p5 = "Please classify the sentiment of the input text. There are three types of category labels: positive, neutral, or negative. The results of sentiment classification should be presented in the form of labels, such as positive, neutral, or negative. Do not output other content. The following is an example:
[0073] Input: {t5}
[0074] Output: {l5}
[0075] Input: {T}
[0076] Output:
[0077] ”
[0078] In this embodiment, by introducing diverse prompt texts, the adaptability and accuracy of the large language model in the task of sentiment analysis of financial texts can be improved. By constructing contextual prompts, the large language model can learn how to perform sentiment analysis in texts in new fields in context. Only a small amount of manually labeled data is required. In each prompt text, only 1 to 2 task examples need to be sampled, thus greatly reducing the labor cost and workload of labeling.
[0079] S103, inputting the prompt set into a large language model, predicting and outputting a number of emotion tags, and obtaining a predicted emotion tag set,
[0080] In this embodiment, the constructed prompt set with diversified prompt texts is input into the large language model. The large language model has powerful language understanding and context perception capabilities. By introducing appropriate context prompts and utilizing the context perception capabilities of the large language model, the text in the financial field can be better understood and analyzed, and then the sentiment tags corresponding to the number of prompt texts are predicted and output to obtain a predicted sentiment tag set. The accuracy of sentiment analysis of financial texts is improved by making full use of the capabilities of the large language model and context information.
[0081] In specific implementation, the prompt texts in the prompt set Prompt = {p1, p2, p3, p4, p5} are input into the large language model to obtain the predicted emotional label set Predict = {r1, r2, r3, r4, r5}. The large language model can recognize emotional expressions and predict the emotional category of the text by learning context and context.
[0082] The large language model in this embodiment is specifically the OpenChineseLLaMA model, which is a Chinese large language model base generated by incremental pre-training of the Chinese data set based on LLaMA-7B. LLaMA is an open and efficient basic language model, and is also the most widely used basic model in the current open source ChatGPT reproduction. The LLaMA network structure is based on the transformer architecture, and various improvements have been made to improve model performance, such as:
[0083] Pre-normalization: To improve the stability of training, the input of each transformer sublayer is normalized instead of the output;
[0084] SwiGLU activation function: replace ReLU nonlinearity with SwiGLU activation function to improve performance, and use 2 / 3 / 4d dimensions instead of 4d in PaLM;
[0085] Rotated embeddings: The absolute position embeddings are removed and instead rotated position embeddings (RoPE) are added at each layer of the network.
[0086] Therefore, the OpenChineseLLaMA model can capture long-distance dependencies in the text and perform effective contextual understanding through the self-attention mechanism. In addition, through large-scale pre-training on unlabeled data, the model can automatically learn rich language knowledge without specific task guidance. When applied to sentiment analysis, it can identify and understand the emotional tendencies in the text, achieving accurate and efficient sentiment analysis.
[0087] S104: Determine a final emotion tag of the target text from the predicted emotion tag set according to a voting algorithm.
[0088] In this embodiment, for the predicted emotion tag set obtained by the large language model for the input prompt set, the final emotion tag of the target text is determined from all the emotion tags predicted by the model based on the voting algorithm. Specifically, the voting algorithm can adopt two methods: hard voting or soft voting, in which hard voting is that the model outputs a most likely emotion tag for each prompt text, and then votes based on these tags to select the emotion tag with the most occurrences as the final emotion tag. Soft voting is that the model outputs the probability or confidence of each emotion tag, and then these probabilities or confidences are weighted to vote, and the category with the highest probability is selected as the final prediction result. By using the voting mechanism to count the emotion tags output by the model, the illusion problem of the large language model (i.e., the emotion classification that does not exist may be output) can be alleviated. The voting mechanism can effectively filter abnormal results and improve the reliability and stability of the emotion analysis results.
[0089] In one embodiment, Figure 2 As shown, determining the final emotion label of the target text from the predicted emotion label set according to the voting algorithm includes:
[0090] S201, counting the number of each type of label in the predicted emotion label set;
[0091] S202: Confirm the tag with the largest number as the final sentiment tag of the target text.
[0092] In this embodiment, the voting algorithm specifically adopts a hard voting method to count the number of positive, negative, and neutral labels in the predicted sentiment label set Predict = {r1, r2, r3, r4, r5}, and the label with the largest number is the final predicted sentiment label. This voting mechanism can increase the robustness of the model and reduce the impact of individual prediction errors on the final result.
[0093] In one embodiment, before generating corresponding prompt texts according to the target text and a plurality of prompt templates and obtaining a prompt set, the method further comprises:
[0094] Confirm the current sentiment analysis scenario of the target text.
[0095] In this embodiment, since the characteristics of the prompt texts in different sentiment analysis scenarios are different, the setting of the prompt template can be combined with different sentiment analysis scenarios. Before constructing the prompt set, the current sentiment analysis scenario of the target text is first confirmed, that is, what kind of sentiment analysis is desired to be performed on the target text, such as a time-based sentiment analysis scenario, an event-based sentiment analysis scenario, a comparison-based sentiment analysis scenario, a prediction-based sentiment analysis scenario, a sentiment intensity-based sentiment analysis scenario, a user feedback-based sentiment analysis scenario, etc., so that the subsequently constructed prompt set can be flexibly adjusted as needed to adapt to sentiment analysis in different scenarios. This makes the model more adaptable and scalable when facing new sentiment classification problems, without the need to retrain the model or perform large-scale data annotation.
[0096] In one embodiment, Figure 3 As shown, the corresponding prompt text is generated according to the target text and a plurality of prompt templates to obtain a prompt set, including:
[0097] S301, confirming a corresponding prompt template library according to a current sentiment analysis scenario, wherein the prompt template library stores a plurality of prompt templates associated with the sentiment analysis scenario;
[0098] S302: Match a number of prompt templates in the prompt template library, generate corresponding prompt texts according to the matched prompt templates and the target text, and obtain a prompt set.
[0099] In this embodiment, a plurality of prompt template libraries are pre-set in the database, each prompt template library corresponds to a sentiment analysis scenario, and a plurality of prompt templates associated with the sentiment analysis scenario are stored therein. For example, in the prompt template library corresponding to the event-based sentiment analysis scenario, the stored prompt templates may include: "In the context of [specific event], examine this text. Please judge whether its sentiment tendency is positive, negative or neutral based on the content of the text.", "Read this text and consider the impact of [specific event]. Evaluate whether the sentiment expressed in the text is positive, negative or neutral.", "Analyze the following text paragraph, which is related to [specific event]. Please classify the sentiment of the text as positive, negative or neutral.", "Read this text, which discusses [a specific event]. Please weigh and determine whether the sentiment of the text is positive, negative, or neutral." And so on. Similarly, the prompt template library for other scenarios also stores a variety of prompt templates. The corresponding prompt template library is confirmed according to the current sentiment analysis scenario, and several prompt templates are matched from the prompt template library. According to the matched prompt template and the target text, corresponding prompt text is generated to obtain a prompt set, so that the constructed prompt set can be closely integrated with the sentiment analysis scenario. The generated prompt text can provide the large language model with a more accurate prompt context that fits the scenario better, thereby improving the accuracy of sentiment label prediction and scenario adaptability while saving annotation costs.
[0100] In one embodiment, the matching of several prompt templates in the prompt template library specifically includes:
[0101] A number of prompt templates are randomly selected from the prompt template library.
[0102] In this embodiment, after confirming the prompt template library of the current scene, several prompt templates are randomly selected from the prompt template library based on the quantity requirement of the prompt text, such as simple random sampling, randomly selecting a template from the template library, and each template has the same probability of being selected; or weighted random sampling, giving different selection probabilities according to the importance of the template or the previous performance, and the template with high importance has a higher probability of being selected; or stratified sampling, the templates in the template library can be classified according to certain features (such as emotional tendency, text type, etc.), and stratified sampling can be used to ensure that each category of template has a chance to be selected, etc. The randomly selected prompt template can provide a variety of contextual prompts to help the model better understand the emotional tendency of the text, and the randomly selected template can reduce the deviation caused by the model using the same prompt template for a long time, so that the model learns to perform sentiment analysis under different prompts, thereby improving its adaptability to various text changes and improving the generalization ability of the model.
[0103] In one embodiment, Figure 4As shown, the plurality of prompt templates are matched in the prompt template library, including:
[0104] S401, obtaining the adaptability score of each prompt template in the prompt template library;
[0105] S402: Select the first several prompt templates according to the ranking of the adaptability scores of the prompt templates to obtain a prompt set.
[0106] In this embodiment, each prompt template in the prompt template library has an adaptability score, which serves as an evaluation indicator of the prompt template and can be used to measure the effect and applicability of the prompt template when performing sentiment analysis tasks on various types of texts. The adaptability score can be obtained in multiple dimensions: historical performance dimension, that is, the performance of the prompt template in past sentiment analysis tasks, such as accuracy, recall rate and F1 score, etc.; task relevance dimension, that is, the relevance of the template content to the theme or field of the current financial text; information richness dimension, whether the information provided by the template helps the model better understand the sentiment context of the text; model feedback dimension, after using the template, the quality and consistency feedback of the model output, etc., through the weighted evaluation results of multiple dimensions to obtain the adaptability score, so that after confirming the prompt template library of the current scene, the adaptability score of each prompt template in the prompt template library can be obtained and sorted, and the prompt template with the highest adaptability score can be selected. By giving priority to the best performing template, the computing resources of the model can be more effectively utilized and the accuracy of the model prediction can be improved. Although the prompt template with a higher adaptability score is given priority, since multiple templates are still selected from the prompt template library, a certain diversity is maintained, which helps the model to maintain stable performance when facing different situations. Preferably, in order to avoid the model being overly dependent on a specific type of template, other templates that may be equally effective or more effective in some cases are ignored. Therefore, the adaptability score of each prompt template can be updated regularly or irregularly, and new prompt templates can be introduced regularly or irregularly to maintain the diversity and adaptability of the model.
[0107] Compared with the prior art, the embodiments of the present invention do not require a large amount of annotated data. Traditional methods usually require a large amount of annotated data for model fine-tuning when migrating to new fields or languages. However, in the embodiments of the present invention, contextual prompts are constructed to allow the large language model to learn how to perform sentiment analysis in the text of the new field in the context. Only a small amount of manually annotated data is required, which greatly reduces the annotation cost and workload; and the prompt set can be flexibly increased or modified as needed to adapt to different sentiment analysis tasks and data sources, which makes the model more adaptable and scalable when facing new sentiment classification problems, without the need to retrain the model or perform large-scale data annotation; and based on the powerful language understanding and context perception capabilities of the large language model, by introducing appropriate contextual prompts, the embodiments of the present invention can utilize the capabilities of the large language model to better understand and analyze texts in the financial field, thereby improving the accuracy and effect of sentiment analysis; and by using a voting mechanism to count the sentiment tags output by the model, the hallucination problem of the large language model can be alleviated. The voting mechanism can effectively filter abnormal results and improve the reliability and stability of sentiment analysis results. Therefore, by making full use of the capabilities and contextual information of the large language model and combining flexible prompt set construction and voting mechanism, the embodiments of the present invention effectively solve the problems of labeled data requirements, domain adaptability and result reliability in financial sentiment analysis tasks, and have strong practicality and performance advantages.
[0108] It should be noted that there is not necessarily a certain order between the above-mentioned steps. A person skilled in the art can understand, based on the description of the embodiments of the present invention, that in different embodiments, the above-mentioned steps may have different execution orders, that is, they may be executed in parallel, may be executed interchangeably, and so on.
[0109] Another embodiment of the present invention provides a sentiment analysis device, such as Figure 5 As shown, the device 1 comprises:
[0110] An acquisition module 11 is used to acquire a target text to be analyzed;
[0111] A prompt set generation module 12 is used to generate corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set, wherein the prompt texts are used to prompt the large language model to perform sentiment analysis based on the target text;
[0112] An input analysis module 13 is used to input the prompt set into a large language model, predict and output a number of emotion tags, and obtain a predicted emotion tag set;
[0113] The tag confirmation module 14 is used to determine the final emotion tag of the target text from the predicted emotion tag set according to a voting algorithm.
[0114] The module referred to in the present invention refers to a series of computer program instruction segments that can perform specific functions, which are more suitable for describing the sentiment analysis execution process than programs. For the specific implementation methods of each module, please refer to the corresponding method embodiments above, which will not be repeated here.
[0115] In one embodiment, the device 1 further comprises:
[0116] The scene confirmation module is used to confirm the current sentiment analysis scene of the target text.
[0117] In one embodiment, the prompt set generating module 12 includes:
[0118] A template library confirmation unit, used to confirm a corresponding prompt template library according to a current sentiment analysis scenario, wherein the prompt template library stores a plurality of prompt templates associated with the sentiment analysis scenario;
[0119] The template matching unit is used to match a plurality of prompt templates in the prompt template library, generate corresponding prompt texts according to the matched prompt templates and the target text, and obtain a prompt set.
[0120] In one embodiment, the template matching unit is specifically used to:
[0121] A number of prompt templates are randomly selected from the prompt template library.
[0122] In one embodiment, the template matching unit includes:
[0123] A score acquisition unit, used to acquire the adaptability score of each prompt template in the prompt template library;
[0124] The sorting and selecting unit is used to select the first several prompt templates according to the sorting of the adaptability scores of the prompt templates to obtain a prompt set.
[0125] In one embodiment, the label confirmation module 14 includes:
[0126] A statistical unit, used to count the number of each type of label in the predicted emotion label set;
[0127] The tag confirmation unit is used to confirm the tag with the largest number as the final sentiment tag of the target text.
[0128] In one embodiment, the large language model is an OpenChineseLLaMA model.
[0129] Another embodiment of the present invention provides a sentiment analysis system. Figure 6 As shown, the system 10 includes:
[0130] One or more processors 110 and memory 120, Figure 6 A processor 110 is used as an example for description. The processor 110 and the memory 120 may be connected via a bus or other means. Figure 6 The example of connecting through bus is taken in the following.
[0131] The processor 110 is used to complete various control logics of the system 10, and it can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine) or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or any combination of these components. In addition, the processor 110 can also be any traditional processor, microprocessor or state machine. The processor 110 can also be implemented as a combination of computing devices, for example, a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a DSP and / or any other such configuration.
[0132] The memory 120, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions corresponding to the sentiment analysis method in the embodiment of the present invention. The processor 110 executes various functional applications and data processing of the system 10 by running the non-volatile software programs, instructions and units stored in the memory 120, that is, implements the sentiment analysis method in the above method embodiment.
[0133] The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required by at least one function; the data storage area may store data created according to the use of the system 10, etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 120 may optionally include a memory remotely arranged relative to the processor 110, and these remote memories may be connected to the system 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0134] One or more units are stored in the memory 120, and when executed by one or more processors 110, the sentiment analysis method in any of the above method embodiments is executed, for example, the following steps are executed:
[0135] Get the target text to be analyzed;
[0136] Generate corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set, wherein the prompt texts are used to prompt the large language model to perform sentiment analysis based on the target text;
[0137] Inputting the prompt set into a large language model, predicting and outputting a number of emotion tags, and obtaining a predicted emotion tag set;
[0138] The final emotion label of the target text is determined from the predicted emotion label set according to a voting algorithm.
[0139] In one embodiment, before generating corresponding prompt texts according to the target text and a plurality of prompt templates and obtaining a prompt set, the method further comprises:
[0140] Confirm the current sentiment analysis scenario of the target text.
[0141] In one embodiment, generating corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set includes:
[0142] Confirming a corresponding prompt template library according to the current sentiment analysis scenario, wherein the prompt template library stores a plurality of prompt templates associated with the sentiment analysis scenario;
[0143] A plurality of prompt templates are matched in the prompt template library, and corresponding prompt texts are generated according to the matched prompt templates and the target text to obtain a prompt set.
[0144] In one embodiment, the matching of several prompt templates in the prompt template library specifically includes:
[0145] A number of prompt templates are randomly selected from the prompt template library.
[0146] In one embodiment, the matching of several prompt templates in the prompt template library includes:
[0147] Obtaining the adaptability score of each prompt template in the prompt template library;
[0148] The first several prompt templates are selected according to the ranking of the adaptability scores of the prompt templates to obtain a prompt set.
[0149] In one embodiment, determining the final emotion tag of the target text from the predicted emotion tag set according to a voting algorithm includes:
[0150] Counting the number of each type of label in the predicted emotion label set;
[0151] The label with the largest number is confirmed as the final sentiment label of the target text.
[0152] In one embodiment, the large language model is an OpenChineseLLaMA model.
[0153] An embodiment of the present invention provides a non-volatile computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by one or more processors, the sentiment analysis method in any of the above method embodiments is executed, for example, the following steps are performed:
[0154] Get the target text to be analyzed;
[0155] Generate corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set, wherein the prompt texts are used to prompt the large language model to perform sentiment analysis based on the target text;
[0156] Inputting the prompt set into a large language model, predicting and outputting a number of emotion tags, and obtaining a predicted emotion tag set;
[0157] The final emotion label of the target text is determined from the predicted emotion label set according to a voting algorithm.
[0158] In one embodiment, before generating corresponding prompt texts according to the target text and a plurality of prompt templates and obtaining a prompt set, the method further comprises:
[0159] Confirm the current sentiment analysis scenario of the target text.
[0160] In one embodiment, generating corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set includes:
[0161] Confirming a corresponding prompt template library according to the current sentiment analysis scenario, wherein the prompt template library stores a plurality of prompt templates associated with the sentiment analysis scenario;
[0162] A plurality of prompt templates are matched in the prompt template library, and corresponding prompt texts are generated according to the matched prompt templates and the target text to obtain a prompt set.
[0163] In one embodiment, the matching of several prompt templates in the prompt template library specifically includes:
[0164] A number of prompt templates are randomly selected from the prompt template library.
[0165] In one embodiment, the matching of several prompt templates in the prompt template library includes:
[0166] Obtaining the adaptability score of each prompt template in the prompt template library;
[0167] The first several prompt templates are selected according to the ranking of the adaptability scores of the prompt templates to obtain a prompt set.
[0168] In one embodiment, determining the final emotion tag of the target text from the predicted emotion tag set according to a voting algorithm includes:
[0169] Counting the number of each type of label in the predicted emotion label set;
[0170] The label with the largest number is confirmed as the final sentiment label of the target text.
[0171] In one embodiment, the large language model is an OpenChineseLLaMA model.
[0172] As an example, non-volatile storage media can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) as external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM, (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The disclosed memory components or memories of the operating environment described herein are intended to include one or more of these and / or any other suitable types of memory.
[0173] In summary, the present invention discloses a sentiment analysis method, device, system and medium, the method includes: obtaining a target text to be analyzed; generating corresponding prompt texts according to the target text and several prompt templates to obtain a prompt set, the prompt text is used to prompt a large language model to perform sentiment analysis based on the target text; inputting the prompt set into the large language model, predicting and outputting several sentiment tags, and obtaining a predicted sentiment tag set; determining the final sentiment tag of the target text from the predicted sentiment tag set according to a voting algorithm. By introducing a variety of prompt templates, the annotation cost and workload are reduced, and the adaptability and accuracy of the large language model in the sentiment analysis task can also be improved. By determining the final sentiment tag from multiple sentiment tag prediction results through a voting algorithm, the hallucination problem existing in the large language model can be alleviated, and the reliability and stability of the sentiment analysis results can be improved.
[0174] Of course, those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware (such as a processor, a controller, etc.) through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium, and the computer program can include the processes of the above-mentioned method embodiments when executed. The storage medium can be a memory, a disk, a floppy disk, a flash memory, an optical storage device, etc.
[0175] It should be understood that the application of the present invention is not limited to the above examples. For ordinary technicians in this field, improvements or changes can be made based on the above description. All these improvements and changes should fall within the scope of protection of the claims attached to the present invention.
Claims
1. A sentiment analysis method, characterized in that: include: Get the target text to be analyzed; Generate corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set, wherein the prompt texts are used to prompt the large language model to perform sentiment analysis based on the target text; Inputting the prompt set into a large language model, predicting and outputting a number of emotion tags, and obtaining a predicted emotion tag set; The final emotion label of the target text is determined from the predicted emotion label set according to a voting algorithm.
2. The sentiment analysis method according to claim 1, characterized in that: Before generating corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set, the method further includes: Confirm the current sentiment analysis scenario of the target text.
3. The sentiment analysis method according to claim 2, characterized in that: The step of generating corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set includes: Confirming a corresponding prompt template library according to the current sentiment analysis scenario, wherein the prompt template library stores a plurality of prompt templates associated with the sentiment analysis scenario; A plurality of prompt templates are matched in the prompt template library, and corresponding prompt texts are generated according to the matched prompt templates and the target text to obtain a prompt set.
4. The sentiment analysis method according to claim 3, characterized in that: The matching of several prompt templates in the prompt template library specifically includes: A number of prompt templates are randomly selected from the prompt template library.
5. The sentiment analysis method according to claim 3, characterized in that: The matching of several prompt templates in the prompt template library includes: Obtaining the adaptability score of each prompt template in the prompt template library; The first several prompt templates are selected according to the ranking of the adaptability scores of the prompt templates to obtain a prompt set.
6. The sentiment analysis method according to claim 5, characterized in that: Determining the final emotion label of the target text from the predicted emotion label set according to the voting algorithm includes: Counting the number of each type of label in the predicted emotion label set; The label with the largest number is confirmed as the final sentiment label of the target text.
7. The sentiment analysis method according to any one of claims 1 to 6, characterized in that: The large language model is the OpenChineseLLaMA model.
8. A sentiment analysis device, characterized in that: include: An acquisition module is used to acquire the target text to be analyzed; A prompt set generation module, used to generate corresponding prompt texts according to the target text and a plurality of prompt templates to obtain a prompt set, wherein the prompt texts are used to prompt the large language model to perform sentiment analysis based on the target text; An input analysis module, used for inputting the prompt set into a large language model, predicting and outputting a number of emotion tags, and obtaining a predicted emotion tag set; The tag confirmation module is used to determine the final emotion tag of the target text from the predicted emotion tag set according to a voting algorithm.
9. A sentiment analysis system, characterized in that: The system includes at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the sentiment analysis method described in any one of claims 1-7.
10. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores computer-executable instructions, which, when executed by one or more processors, enable the one or more processors to execute the sentiment analysis method described in any one of claims 1-7.
Citation Information
Patent Citations
Data classification method and device, equipment and storage medium
CN116701636A
Emotion analysis method and device and big language model training method and device
CN117436438A
Text classification method and device, electronic equipment and computer readable storage medium
CN117493558A
Artificial intelligence device for common sense reasoning for visual question answering and control method thereof
US20240242029A1
Cited By
Financial product text generation method and device, electronic equipment and storage medium
CN119294380A
Financial product text generation method, device, electronic device and storage medium
CN119294380B
User comment fine-grained analysis method based on large language model
CN119760140A
A fine-grained parsing method for user reviews based on large language model
CN119760140B
User tag determination method, electronic equipment and storage medium
CN119961455A
