Sentiment analysis method and apparatus and large language model training method and apparatus

By generating the target text containing the task prompt text, the large language model is guided to perform sentiment analysis on the analytical objects, and the problem of inaccurate sentiment analysis results in the prior art is solved, and the high accuracy of object-level sentiment analysis is achieved.

WO2025086680A1PCT designated stage expired Publication Date: 2025-05-01BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/100224
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-10-27
Filing Date
2024-06-19
Publication Date
2025-05-01

AI Technical Summary

Technical Problem

Existing emotion analysis methods are difficult to accurately identify the emotional expressions of different objects, resulting in inaccurate emotions analysis results.

Method used

By generating target text containing task prompt text, the large language model is guided to perform sentiment analysis on the object to be analyzed, and object-level sentiment analysis is realized.

Benefits of technology

It improves the accuracy of sentiment analysis results and can more accurately identify the emotional polarity of different objects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024100224_01052025_PF_FP_ABST
    Figure CN2024100224_01052025_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed are a sentiment analysis method and apparatus, a large language model training method and apparatus, an electronic device, a storage medium, a computer program product and a computer program. The sentiment analysis method comprises: acquiring first target text; extracting from the first target text an object to be analyzed; generating second target text on the basis of the first target text and said object, wherein the second target text comprises task prompt text, and the task prompt text is used for prompting a large language model to execute a sentiment analysis task on said object on the basis of the first target text; and inputting the second target text into the large language model to obtain the sentiment polarity of said object.
Need to check novelty before this filing date? Find Prior Art

Description

Sentiment analysis method, large language model training method and device

[0001] CROSS-REFERENCE TO RELATED APPLICATIONS

[0002] This application claims priority to Chinese patent application No. 2023114154790 filed in China on October 27, 2023, the entire contents of which are incorporated herein by reference. Technical Field

[0003] The present disclosure relates to the field of computer technology, specifically to artificial intelligence fields such as deep learning, natural language processing, and large models, and more specifically to a sentiment analysis method, a training method for a large language model, an apparatus, an electronic device, a storage medium, a computer program product, and a computer program. Background Art

[0004] Sentiment analysis holds great promise in natural language processing applications. For example, user reviews on internet platforms can be used to assess user satisfaction with a product or service. Similarly, public reviews on internet platforms can be used to understand public perceptions and sentiments toward a company's brand.

[0005] Summary of the Invention

[0006] The present disclosure provides a sentiment analysis method, a large language model training method, an apparatus, an electronic device, a storage medium, a computer program product, and a computer program. The specific solution is as follows:

[0007] According to an embodiment of an aspect of the present disclosure, a sentiment analysis method is provided, comprising:

[0008] Get the first target text;

[0009] Extracting the object to be analyzed from the first target text;

[0010] Generate a second target text based on the first target text and the object to be analyzed; wherein the second target text includes a task prompt text, and the task prompt text is used to prompt the large language model to perform a sentiment analysis task on the object to be analyzed based on the first target text;

[0011] The second target text is input into the large language model to obtain the sentiment polarity of the object to be analyzed.

[0012] According to a second aspect of the present disclosure, a method for training a large language model is provided, comprising:

[0013] Obtain a first training sample; wherein the first training sample includes a first sample text and a task prompt text, wherein the task prompt text is used to prompt the initial large language model to perform a sentiment analysis task on the object to be analyzed in the first sample text;

[0014] Input the first training sample into the initial large language model to obtain the predicted sentiment polarity;

[0015] According to the difference between the predicted sentiment polarity and the actual sentiment polarity corresponding to the object to be analyzed, the initial large language model is trained to obtain a large language model.

[0016] According to a third aspect of the present disclosure, there is provided a sentiment analysis device, comprising:

[0017] A first acquisition module, configured to acquire a first target text;

[0018] An extraction module, configured to extract an object to be analyzed from the first target text;

[0019] A generation module is configured to generate a second target text based on the first target text and the object to be analyzed; wherein the second target text includes a task prompt text, which is used to prompt the large language model to perform a sentiment analysis task on the object to be analyzed based on the first target text;

[0020] The second acquisition module is used to input the second target text into the large language model to obtain the sentiment polarity of the object to be analyzed.

[0021] According to a fourth aspect of the present disclosure, there is provided a large language model training apparatus, comprising:

[0022] A first acquisition module is configured to acquire a first training sample, wherein the first training sample includes a first sample text and a task prompt text, wherein the task prompt text is configured to prompt the initial large language model to perform a sentiment analysis task on an object to be analyzed in the first sample text;

[0023] A second acquisition module is used to input the first training sample into the initial large language model to obtain a predicted sentiment polarity;

[0024] The first training module is used to train the initial large language model according to the difference between the predicted emotional polarity and the actual emotional polarity corresponding to the object to be analyzed, so as to obtain the large language model.

[0025] According to a fifth aspect of the present disclosure, there is provided an electronic device, including:

[0026] at least one processor; and

[0027] a memory communicatively connected to the at least one processor; wherein,

[0028] 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 the above-mentioned first aspect embodiment, or can execute the large language model training method described in the above-mentioned second aspect embodiment.

[0029] According to a sixth aspect embodiment of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the sentiment analysis method according to the above-mentioned first aspect embodiment, or to execute the large language model training method according to the above-mentioned second aspect embodiment.

[0030] According to a seventh aspect embodiment of the present disclosure, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the steps of the sentiment analysis method described in the first aspect embodiment, or implements the steps of the large language model training method described in the second aspect embodiment.

[0031] According to an eighth aspect embodiment of the present disclosure, a computer program is provided, comprising computer program code. When the computer program code is run on a computer, the computer is caused to execute the steps of the sentiment analysis method described in the first aspect embodiment, or implement the steps of the large language model training method described in the second aspect embodiment.

[0032] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] The accompanying drawings are provided to facilitate a better understanding of the present invention and do not constitute a limitation of the present disclosure.

[0034] FIG1 is a flow chart of a sentiment analysis method according to an embodiment of the present disclosure;

[0035] FIG2 is a flow chart of a sentiment analysis method provided by another embodiment of the present disclosure;

[0036] FIG3 is a flow chart of a sentiment analysis method provided by another embodiment of the present disclosure;

[0037] FIG4 is a flow chart of a method for training a large language model according to an embodiment of the present disclosure;

[0038] FIG5 is a flow chart of a method for training an object extraction model according to an embodiment of the present disclosure;

[0039] FIG6 is a schematic diagram of BIO annotation provided by an embodiment of the present disclosure;

[0040] FIG7 is a schematic diagram of a model training process provided by an embodiment of the present disclosure;

[0041] FIG8 is a schematic diagram of a model reasoning process provided by an embodiment of the present disclosure;

[0042] FIG9 is a schematic diagram of the structure of a sentiment analysis device provided by an embodiment of the present disclosure;

[0043] FIG10 is a schematic diagram of the structure of a large language model training device provided by an embodiment of the present disclosure;

[0044] FIG11 is a block diagram of an electronic device for implementing the sentiment analysis method according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0045] The following description of exemplary embodiments of the present disclosure is made in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding. These details should be considered as merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0046] It should be noted that the acquisition, storage, use, and processing of data in the disclosed technical solution comply with the relevant provisions of national laws and regulations and do not violate public order and good morals.

[0047] The following describes the sentiment analysis method, large language model training method, device, electronic device, storage medium, computer program product and computer program of the embodiments of the present disclosure with reference to the accompanying drawings.

[0048] Artificial intelligence (AI) is the study of how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). It encompasses both hardware and software technologies. AI hardware technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, and big data processing. AI software technologies encompass computer vision, speech recognition, natural language processing, as well as deep learning, big data processing, and knowledge graphs.

[0049] Deep learning is a new research direction in machine learning. It studies the inherent patterns and representational hierarchies of sample data. The information gained from this learning process is highly helpful for interpreting data such as text, images, and sound. Its ultimate goal is to enable machines to acquire human-like analytical learning capabilities and recognize data such as text, images, and sound.

[0050] Natural language processing is an important direction in the fields of computer science and artificial intelligence. The content of NLP research includes but is not limited to the following branches: text classification, information extraction, automatic summarization, intelligent question answering, topic recommendation, machine translation, keyword recognition, knowledge base construction, deep text representation, named entity recognition, text generation, text analysis (lexical, syntactic, grammatical, etc.), speech recognition and synthesis, etc.

[0051] Large language models (also called large models) generally refer to large-scale neural networks that are trained to process, understand, and generate language text.

[0052] In some embodiments, sentiment analysis methods mainly focus on the overall sentiment tendency of the text, but ignore the accurate identification of the sentiment expressions of different objects, resulting in inaccurate sentiment analysis results.

[0053] Based on this, the first embodiment of the present disclosure provides a sentiment analysis method, which guides a large language model to perform sentiment analysis on the object to be analyzed based on the task prompt text, realizes object-level sentiment analysis, and can process large-scale data, with a wide range of applications.

[0054] FIG1 is a flow chart of a sentiment analysis method provided by an embodiment of the present disclosure.

[0055] The sentiment analysis method of the embodiment of the present disclosure can be executed by the sentiment analysis device of the embodiment of the present disclosure. The device can be configured in an electronic device, and can guide the large language model to perform sentiment analysis on the object to be analyzed through task prompt text, thereby analyzing the sentiment polarity of different objects and realizing object-level sentiment analysis.

[0056] Among them, the electronic device can be any device with computing capabilities, such as a personal computer, mobile terminal, server, etc. The mobile terminal can be, for example, a vehicle-mounted device, a mobile phone, a tablet computer, a personal digital assistant, a wearable device, and other hardware devices with various operating systems, touch screens and / or display screens.

[0057] As shown in FIG1 , the sentiment analysis method includes the following steps 101 to 104 .

[0058] Step 101: Obtain a first target text.

[0059] In the embodiment of the present disclosure, the first target text may be collected from an Internet platform, or may be extracted from a questionnaire, or may be obtained through other means.

[0060] In some embodiments, the first target text may be a review text for a certain product, an event, or a certain brand.

[0061] Step 102: extract the object to be analyzed from the first target text.

[0062] In the embodiments of the present disclosure, a pre-trained object extraction model can be used to extract the object to be analyzed from the first target text, or the parts of speech and dictionary of each word in the first target text can be used to extract the object to be analyzed from the first target text, or other methods can be used to extract the object to be analyzed from the first target text, and the embodiments of the present disclosure are not limited to this.

[0063] For example, if the first target text is "Brand A's shampoo is quite good.", the object to be analyzed extracted from the text is "Brand A".

[0064] In the disclosed embodiment, the objects to be analyzed in the first target text may be one or more, without limitation. For example, if the first target text is "Brand A's shampoo is better than Brand B's," the objects to be analyzed extracted from the text are "Brand A" and "Brand B."

[0065] Step 103: Generate a second target text based on the first target text and the object to be analyzed.

[0066] In the disclosed embodiment, the second target text may include the first target text, a task prompt text, and the like. The task prompt text may be used to prompt the large language model to perform a sentiment analysis task on the object to be analyzed based on the first target text. That is, the task prompt text may be used to prompt the large language model to analyze the sentiment polarity of the first target text with respect to the object to be analyzed. It can be seen that the task prompt text clearly indicates the object to be analyzed that requires sentiment analysis and prompts the large language model to predict the sentiment polarity of the object to be analyzed.

[0067] In the disclosed embodiments, emotion polarity may refer to the relative strength of positive and negative emotions in an emotional experience. If the strength of positive emotion is greater than the strength of negative emotion, the emotion polarity is positive; if the strength of positive emotion is less than the strength of negative emotion, the emotion polarity is negative; if the strength of positive emotion is equal to the strength of negative emotion, the emotion polarity is neutral or neutral.

[0068] In the disclosed embodiment, the emotional polarity may include positive (ie, favorable, supportive), negative (ie, negative), neutral (no obvious emotional polarity), etc.

[0069] In the embodiment of the present disclosure, the analysis of sentiment polarity may be a process of analyzing, processing, summarizing, and reasoning about text with sentimental overtones.

[0070] In the embodiment of the present disclosure, a task prompt text may be constructed based on the object to be analyzed, and a second target text may be generated based on the first target text and the task prompt text.

[0071] For example, if the first target text is "Brand A's shampoo is quite good.", the second target text can be "Brand A's shampoo is quite good. The sentiment polarity of this text towards Brand A is", or the second target text can be "Brand A's shampoo is quite good. The sentiment polarity of this text towards Brand A is", etc.

[0072] In some embodiments, sentiment polarity, sentiment tendency, sentiment category, etc. can be replaced with each other.

[0073] Step 104: Input the second target text into the large language model to obtain the sentiment polarity of the object to be analyzed.

[0074] In the embodiment of the present disclosure, the second target text is input into the large language model for feature extraction and decoding to obtain the sentiment polarity of the object to be analyzed.

[0075] For example, a second target text may be "Brand A's shampoo is quite good. The sentiment polarity of this text towards Brand A is". By inputting this second target text into the large language model, it can be obtained that the sentiment polarity of Brand A is positive, that is, "The sentiment polarity of this text towards Brand A is positive".

[0076] In some embodiments, the large language model may be a BERT (Bidirectional Encoder Representations from Transformers) model. By performing sentiment analysis using the BERT model, the sentiment context may be considered, thereby improving the accuracy of the object-level sentiment analysis results.

[0077] In the disclosed embodiment, the object to be analyzed is extracted from a first target text. Based on the first target text and the object to be analyzed, a second target text containing a task prompt text is generated. The second target text is then processed using a large language model to determine the sentiment polarity of the object to be analyzed. Thus, by extracting objects from the first target text, the object requiring sentiment analysis is determined. The large language model is then guided to perform sentiment analysis on the object to be analyzed based on the task prompt text, achieving object-level sentiment analysis and improving the accuracy of the sentiment analysis results.

[0078] FIG2 is a flow chart of a sentiment analysis method provided in another embodiment of the present disclosure.

[0079] As shown in FIG2 , the sentiment analysis method includes the following steps 201 to 206 .

[0080] Step 201: Obtain a first target text.

[0081] In the embodiment of the present disclosure, step 201 can be implemented in any of the embodiments of the present disclosure, which is not limited and will not be described in detail.

[0082] Step 202: Input the first target text into the object extraction model to obtain a label sequence of the first target text output by the object extraction model.

[0083] In the embodiment of the present disclosure, the object extraction model may be a sequence labeling model, and the first target text may be input into the object extraction model for feature extraction and decoding to obtain a label sequence of the first target text output by the object extraction model.

[0084] The label sequence may be a sequence in a BIO (B-begin, I-inside, O-outside) annotation format, and the label sequence may include a label for each character in the first target text, and the label may be used to indicate the category of the character.

[0085] To facilitate distinction, in the embodiment of the present disclosure, different types of objects to be analyzed may be distinguished by different labels, such as ORG for organizations, bra for brands, peo for people, and so on.

[0086] For example, if the first target text is "Brand A's shampoo is quite good", the corresponding label sequence is "B-bra I-bra I-bra OOOOOOOO".

[0087] In some embodiments, the object extraction model can be a BERT-CRF (Conditional Random Fields) model, which can perform feature extraction and sequence labeling on the first target text. BERT can extract features from the first target text to obtain a feature vector, and input the feature vector into a CRF. The CRF can decode the feature vector to obtain the probability of each character in the first target text belonging to each label, thereby determining the label sequence of the first target text.

[0088] The text entity extraction method based on the BERT-CRF model can utilize the contextual information of BERT and the sequence modeling capability of CRF to better capture the contextual features and semantic associations of entities, thereby improving the accuracy and robustness of object extraction.

[0089] In some embodiments, the object extraction model may be a BiLSTM (Bidirectional Long Short-Term Memory)-CRF model.

[0090] Step 203: Determine target characters in the first target text that are labeled as target tags according to the tag sequence.

[0091] In the embodiment of the present disclosure, characters in the first target text that are labeled as target tags may be determined as target characters. For example, taking the BIO annotation as an example, target tags may be tags that begin with "B" or "I".

[0092] Step 204: Determine the object to be analyzed based on the target character.

[0093] In the embodiment of the present disclosure, target characters corresponding to adjacent tags for representing entities may be combined to obtain an object to be analyzed.

[0094] For example, if the first target text is "Brand A's shampoo is quite good", the corresponding label sequence is "B-bra I-bra I-bra OOOOOOOO". It can be seen that "B-bra I-bra I-bra" is the target label, and the characters corresponding to these three labels are combined in sequence to obtain the object to be analyzed "Brand A".

[0095] For example, if the first target text is "Brand A shampoo is better than Brand B", the corresponding label sequence is "B-bra I-bra I-bra OOOOO B-bra I-bra I-bra OOO". The character combination corresponding to the first three labels in the label sequence is the object to be analyzed "Brand A", and the character combination corresponding to the ninth label, tenth label, and eleventh label in the label sequence is "Brand B".

[0096] In some embodiments, a part-of-speech tagging model may be used to perform part-of-speech tagging on the first target text to obtain the part-of-speech of each word in the first target text, and the word whose part of speech is a noun among the word is determined as a candidate word. Each candidate word is then matched with a word in a preset dictionary. If the degree of match between a candidate word and any word in the preset dictionary is greater than a preset matching degree threshold, the candidate word may be determined as an object to be analyzed. The preset dictionary may include multiple objects that can be subjected to sentiment analysis.

[0097] In some embodiments, the preset dictionary may include objects in multiple fields that can be subjected to sentiment analysis, or the preset dictionary may include objects in the field to which the first target text belongs that can be subjected to sentiment analysis, which is not limited.

[0098] Therefore, the objects to be analyzed can be extracted based on the part of speech of each word in the first target text and the dictionary, which enriches the extraction method of the objects to be analyzed and can meet diverse needs.

[0099] Step 205: Generate a second target text based on the first target text and the object to be analyzed.

[0100] Step 206: Input the second target text into the large language model to obtain the sentiment polarity of the object to be analyzed.

[0101] In the embodiment of the present disclosure, steps 205 and 206 may be implemented in any of the embodiments of the present disclosure, which is not limited and will not be described in detail.

[0102] In the embodiment of the present disclosure, the object extraction model can be used to extract the object to be analyzed from the first target text, thereby improving the extraction efficiency and accuracy of the object to be analyzed, and further improving the accuracy of the sentiment analysis results.

[0103] FIG3 is a flow chart of a sentiment analysis method provided in another embodiment of the present disclosure.

[0104] As shown in FIG3 , the sentiment analysis method includes the following steps 301 to 305 .

[0105] Step 301: Obtain a first target text.

[0106] Step 302: extract the object to be analyzed from the first target text.

[0107] In the embodiment of the present disclosure, steps 301 and 302 may be implemented in any of the embodiments of the present disclosure, which is not limited and will not be described in detail.

[0108] Step 303: Add the object to be analyzed to a preset position in a preset task prompt template to obtain a task prompt text.

[0109] In the embodiment of the present disclosure, the task prompt template may include location information of the object to be analyzed, sentiment analysis task information, etc., which can be determined according to actual needs.

[0110] For example, the task prompt template can be "The sentiment polarity of this text to [the object to be analyzed] is", or "The sentiment polarity of this text to [the object to be analyzed] is", or "The sentiment polarity of [the object to be analyzed] in this text is", etc.

[0111] In the embodiment of the present disclosure, the object to be analyzed can be added to a preset position in the task prompt template to obtain the task prompt text. The preset position can be the position of the object that needs to be sentimentally analyzed.

[0112] It is understandable that if there are multiple objects to be analyzed, each object to be analyzed can be added to a preset position in the task prompt template to obtain a task prompt text for each object to be analyzed.

[0113] For example, the first target text is "Brand A's shampoo is better than Brand B's", and the objects to be analyzed extracted from the text are "Brand A" and "Brand B", and the task prompt template is "This text is for [object to be analyzed]". Add "Brand A" and "Brand B" to the position of the object to be analyzed in the task prompt template respectively, and get two task prompt texts: "This text is for Brand A" and "This text is for Brand B", or add "Brand A" and "Brand B" to the task prompt template, and get a task prompt text "This text is for Brand A, and is for Brand B".

[0114] Step 304: concatenate the first target text and the task prompt text to obtain a second target text.

[0115] In the embodiment of the present disclosure, the first target text and the task prompt text may be spliced ​​together according to a preset splicing rule to obtain a second target text. For example, the task prompt text may be spliced ​​together with the first target text to obtain the second target text.

[0116] Step 305: Input the second target text into the large language model to obtain the sentiment polarity of the object to be analyzed.

[0117] In the embodiment of the present disclosure, step 305 can be implemented in any of the embodiments of the present disclosure, which is not limited and will not be described in detail.

[0118] In the disclosed embodiment, the object to be analyzed can be added to a preset position in a preset task prompt template to generate task prompt text, and the first target text and the task prompt text are then concatenated to generate a second target text. This improves the efficiency of generating the second target text based on the object to be analyzed and the task prompt template, and allows the task prompt text in the second target text to guide the model in performing sentiment analysis on the object to be analyzed.

[0119] In one embodiment of the present disclosure, a target domain prompt text matching the first target text may be obtained, and a second target text may be generated based on the first target text, the object to be analyzed, and the target domain prompt text, thereby adding a domain limitation prompt to the second target text.

[0120] The second target text may include the first target text, target domain prompt text, task prompt text, etc. The target domain prompt text may include the target domain to which the first target text belongs, so that the target domain prompt text can be used to prompt the large language model that the domain to which the first target text belongs is the target domain.

[0121] In the embodiment of the present disclosure, the target domain prompt text may be preset. For example, for a sentiment analysis task in a specific field, the target domain prompt text in the field may be preset.

[0122] In some embodiments, different field prompt texts can be pre-set for different fields, the field of the first target text can be identified to determine the target field to which the first target text belongs, and the field prompt text of the target field can be obtained from the field prompt texts of multiple fields, that is, the target field prompt text is obtained.

[0123] Therefore, based on the domain prompt texts in different fields, sentiment analysis of the first target texts in different fields can be achieved.

[0124] In some embodiments, the object to be analyzed can be added to a preset position in a preset task prompt template to obtain task prompt text. The first target text, the target domain prompt text, and the task prompt text can be spliced ​​together in a preset splicing order to obtain a second target text. Thus, the second target text can be spliced ​​together in different splicing orders, enriching the form of the second target text.

[0125] In some embodiments, the target domain prompt text, the first target text, and the task prompt text are spliced ​​in sequence, or the first target text, the target domain prompt text, and the task prompt text are spliced ​​in sequence.

[0126] For example, the first target text is "Brand A's shampoo is quite good.", the task prompt text is "This text is about Brand A", and the target domain prompt text is "This is a product review". The target domain prompt text, the first target text, and the task prompt text are spliced ​​together to obtain the second target text "This is a product review: Brand A's shampoo is quite good. This text is about Brand A".

[0127] In the disclosed embodiment, a second target text is generated based on the first target text, the object to be analyzed, and the target domain prompt text. Thus, a domain-specific prompt can be added to the second target text. The task prompt text, combined with the target domain prompt text, can guide the large language model to analyze the sentiment polarity of the object to be analyzed in the target domain. By introducing relevant domain information into the second target text, the model's understanding of the domain-specific text can be enhanced, improving the accuracy of the model's sentiment analysis results.

[0128] In order to further improve the accuracy of the model sentiment analysis results, in one embodiment of the present disclosure, generating a second target text based on the first target text, the object to be analyzed and the target domain prompt text may include: matching the first target text with terms in the term library corresponding to the target domain to determine the target term associated with the first target text, and generating the second target text based on the semantics of the first target text, the object to be analyzed, the target domain prompt text and the target term.

[0129] The terminology library corresponding to the target domain may include multiple terms in the target domain and the semantics of each term.

[0130] In the embodiment of the present disclosure, the object to be analyzed can be spliced ​​with a preset task prompt template to obtain a task prompt text, and the first target text, target field prompt text, task prompt text and target term can be spliced ​​according to a preset splicing format to obtain a second target text.

[0131] In some embodiments, the format of the second target text may be "This is a text of [target field]: first target text. The semantics of [target term] associated with this text is [semantics of target term]. This text is for [object to be analyzed]".

[0132] Therefore, on the basis of the domain limitation prompts and task prompts contained in the second target text, hints of domain-specific term semantics are added, so that the model can better understand the domain-specific semantics and further improve the accuracy of the model's sentiment analysis results.

[0133] The sentiment analysis method of the embodiment of the present disclosure can be widely applied in many fields, such as:

[0134] (1) Social media analysis: Object-level sentiment analysis can be performed on posts, comments, and replies on social media. For example, in social media marketing, companies can analyze users’ sentiment towards their brands, products, or services to better understand user feedback, adjust marketing strategies, and improve products.

[0135] (2) Customer Service and User Feedback Analysis: In the field of customer service and user feedback, it can help companies analyze the emotional inclinations and attitudes of customers or users. By conducting sentiment analysis on specific objects, companies can quickly understand users' satisfaction and opinions on specific products, services, or companies. This can help companies identify problems, improve product quality, enhance customer service experience, and respond to user needs and feedback in a timely manner.

[0136] (3) Emotion-driven recommendation systems: These systems provide users with more personalized recommendations that are in line with their emotional preferences. By analyzing users’ emotional expressions towards different objects, recommendation systems can recommend suitable products, movies, music, or other content based on their emotional tendencies, thereby improving user experience and satisfaction.

[0137] To implement the above embodiment, a second embodiment of the present disclosure provides a method for training a large language model. FIG4 is a flow chart of the method for training a large language model provided by an embodiment of the present disclosure.

[0138] As shown in FIG4 , the large language model training method includes the following steps 401 to 403 .

[0139] Step 401: Obtain a first training sample.

[0140] In the embodiment of the present disclosure, the first training sample may include a first sample text and a task prompt text, wherein the task prompt text may be used to prompt the initial large language model to analyze the sentiment polarity of the object to be analyzed in the first sample text.

[0141] In the disclosed embodiment, the object to be analyzed and the sentiment polarity of the object to be analyzed in the first sample text can be labeled to obtain a candidate sample, and the true sentiment polarity of the object to be analyzed labeled in the candidate sample can be masked to obtain a first training sample.

[0142] For example, if a candidate sample is "Brand A's clothes are very comfortable to wear. This text is positive for Brand A," a masking operation is performed on the sentiment polarity "positive" in this candidate sample to obtain the first training sample "Brand A's clothes are very comfortable to wear. This text is [mask] for Brand A." The first sample text in this first training sample is "Brand A's clothes are very comfortable to wear.", and the task prompt is "This text is [mask] for Brand A." The true value of [mask] is the manually labeled result [positive].

[0143] Step 402: Input the first training sample into the initial large language model to obtain predicted sentiment polarity.

[0144] In the embodiment of the present disclosure, the first training sample may be input into the initial large language model, and the initial large language model may perform feature extraction and decoding on the first training sample to obtain a predicted sentiment polarity.

[0145] Step 403 : Based on the difference between the predicted sentiment polarity and the actual sentiment polarity corresponding to the object to be analyzed, the initial large language model is trained to obtain a large language model.

[0146] In the disclosed embodiment, the model loss can be determined based on the difference between the predicted sentiment polarity and the actual sentiment polarity corresponding to the object to be analyzed, the parameters of the initial large language model can be adjusted based on the model loss, and the initial large language model with adjusted parameters can be continued to be trained until the training end conditions are met to obtain a large language model.

[0147] In some embodiments, a large language model can be constructed using basic BERT. The sentiment polarity of the first sample text relative to the object to be analyzed can be masked, making it the target that the model needs to learn. For example, "Brand A's clothes are very comfortable to wear. This text is [mask] for Brand A," where the true value of [mask] is the manually labeled result [positive]. This matches the MLM (Mask Language Model) in the BERT pre-training task. Therefore, training can continue by modeling the MLM task.

[0148] During training, model parameters can be adjusted by minimizing the difference between predicted and true sentiment polarity. This allows the large language model to learn contextual information and sentiment-related features of the text, improving the accuracy of the model's sentiment analysis results.

[0149] In the disclosed embodiment, a first training sample containing task prompt text can be used to train an initial large language model to obtain a large language model. Thus, the task prompt text tells the model the task to be performed, guiding the model to analyze the sentiment polarity of the object to be analyzed. Thus, the large language model can analyze the sentiment polarity of different objects, achieving object-level sentiment analysis and improving the accuracy of the model's sentiment analysis results.

[0150] In one embodiment of the present disclosure, obtaining a first training sample may include obtaining a first sample text, extracting an object to be analyzed from the first sample text, and generating a first training sample based on the first sample text and the object to be analyzed. Thus, by extracting objects from the first sample text and determining the object to be analyzed, the efficiency of labeling the object to be analyzed is improved. Furthermore, by generating the first training sample based on the extracted object to be analyzed, the efficiency of constructing the first training sample is improved.

[0151] In the embodiment of the present disclosure, a pre-trained object extraction model can be used to extract the object to be analyzed from the first sample text, or a preset dictionary and the parts of speech of each word in the first sample text can be used to extract the object to be analyzed from the first sample text. The detailed process can be found in the above-mentioned method of extracting the object to be analyzed from the first target text, which will not be repeated here.

[0152] Thus, the object to be analyzed is extracted from the first sample text using the object extraction model, thereby improving the accuracy of object extraction.

[0153] In the disclosed embodiment, a task prompt text may be generated according to the object to be analyzed and a preset task prompt template, and the first sample text and the task prompt text may be spliced ​​according to a preset splicing rule to obtain a first training sample.

[0154] For example, a first sample text is "Brand a's clothes are very comfortable to wear.", the object to be analyzed is "Brand a", and the task prompt template is "This text is [mask] for [Object to be analyzed]". The object to be analyzed is added to the preset position in the task prompt template to obtain the task prompt text "This text is [mask] for Brand a". The first sample text is spliced ​​with the task prompt text to obtain the first training sample "Brand a's clothes are very comfortable to wear. This text is [mask] for Brand a".

[0155] In some embodiments, a target domain prompt text can be obtained and a first training sample can be generated based on the first sample text, the object to be analyzed, and the target domain prompt text. Thus, a domain-limiting prompt can be added to the first training sample to guide the model to learn in a specific domain, thereby increasing the model's understanding of the domain-specific text and improving the accuracy of the model's sentiment analysis results.

[0156] Among them, the method for obtaining the target field prompt text is similar to the method for obtaining the target field prompt text in the above embodiment. The method for generating the first training sample based on the first sample text, the object to be analyzed and the target field prompt text is similar to the method for generating the second target text based on the first target text, the object to be analyzed and the target field prompt text in the above embodiment, so it will not be repeated here.

[0157] In some embodiments, the first sample text can be matched with terms in the term library corresponding to the target domain to determine the target term associated with the first sample text, and a first training sample can be generated based on the semantics of the first sample text, the object to be analyzed, the target domain prompt text and the target term.

[0158] Among them, the method of generating the first training sample based on the semantics of the first sample text, the object to be analyzed, the target field prompt text and the target term is similar to the method of generating the second target text based on the semantics of the first target text, the object to be analyzed, the target field prompt text and the target term in the above embodiment, so it will not be repeated here.

[0159] Therefore, on the basis of the domain-limiting prompts and task prompts contained in the first training sample, the prompts of domain-specific term semantics are added, so that the model can better understand the domain-specific semantics and further improve the accuracy of the model's sentiment analysis results.

[0160] FIG5 is a flow chart of a method for training an object extraction model according to an embodiment of the present disclosure.

[0161] As shown in FIG5 , the training method of the object extraction model includes the following steps 501 to 503 .

[0162] Step 501: Obtain a second training sample.

[0163] In the embodiment of the present disclosure, the second training sample may include a second sample text and a true label sequence of the second sample text.

[0164] The second training sample may be obtained by marking objects in the second sample text that require sentiment analysis.

[0165] In the embodiment of the present disclosure, the objects that need to be sentimentally analyzed in the second sample text can be manually annotated to obtain the original sample text, and then the BIO annotation method can be used to annotate the objects to be analyzed to obtain the true label sequence of the second sample text.

[0166] For example, the second sample text is “Brand a’s clothes are very comfortable to wear”, and the true label sequence is “B-bra I-bra I-bra OOOOOOOO”, as shown in Figure 6.

[0167] Since the model has requirements on the format of input data, such as input data length, the original sample text can be converted into a format suitable for model input, and the original sample can be preprocessed, such as segmenting the original sample text into character levels, adding starting characters such as "[CLS]" and ending characters such as "[SEP]", performing padding operations, truncation operations, etc.

[0168] For example, if the original sample text is relatively long, a truncation operation can be performed, such as dividing the original sample text into multiple second sample texts according to the model length requirements; if the original sample text is relatively short, a padding operation can be performed, such as padding the original sample text with characters to obtain a second sample text that meets the length requirements.

[0169] Step 502: Input the second sample text into the initial object extraction model to obtain a predicted label sequence.

[0170] In the disclosed embodiment, the second sample text may be input into the initial object extraction model, and the initial object extraction model may be used to perform feature extraction and context encoding on the second sample text to obtain a feature vector, and the feature vector may be decoded to obtain a predicted label sequence.

[0171] In some embodiments, the object extraction model can employ a BERT-CRF model. During implementation, a pre-trained BERT model can be used to input the pre-processed text sequence into the BERT model for feature extraction, resulting in a feature vector. The BERT model can embed each character into a word, generating a context-sensitive word vector representation. These word vectors are then passed through a multi-layer Transformer network for feature extraction and context encoding.

[0172] Based on the output of the BERT model, the hidden states of different layers can be selected as feature representations. These feature vectors can be reduced in dimension through simple linear transformation to reduce model parameters and computational complexity.

[0173] After feature extraction, the feature vector is fed into the CRF layer for sequence labeling. The CRF layer classifies each character into a label, determining whether it belongs to an entity category. Because the CRF layer considers the dependencies between sequence labels, it can improve the accuracy of object extraction by globally optimizing the entire labeled sequence.

[0174] Step 503: Train the initial object extraction model based on the difference between the predicted label sequence and the true label sequence to obtain an object extraction model.

[0175] In the disclosed embodiment, the probability that the predicted label sequence is the true label sequence can be determined based on the probability that each character in the second sample text belongs to each label. A model loss can also be determined based on the probability that the predicted label sequence is the true label sequence. Based on the model loss, the parameters of the initial object extraction model are adjusted. The initial object extraction model with adjusted parameters is then trained until the training termination condition is met, thereby obtaining an object extraction model. Thus, by determining the model loss based on the probability that the predicted label sequence is the true label sequence, the training efficiency of the model can be improved.

[0176] In some embodiments, the probability of each character belonging to the true label can be determined based on the probability that each character in the second sample text belongs to each label, and the product of the probabilities of each character belonging to the true label is determined as the probability that the predicted label sequence is the true label sequence, thereby determining the model loss based on the probability that the predicted label sequence is the true label sequence.

[0177] In some embodiments, the score of each possible label sequence can be determined based on the probability that each character in the second sample text belongs to each label, and the model loss can be determined based on the score of the true label sequence and the sum of the scores of all possible label sequences. For each possible label sequence, the score corresponding to the label sequence can be determined based on the probability that each character in the second sample text belongs to the label of that character in the label sequence, and the probability that the label of each character in the label sequence is transferred from the label of the previous character to the label of that character.

[0178] For example, the model loss can be calculated using the following formula (1): L = -log(P(Y|X)) (1)

[0179] Where L represents the model loss, X represents the input sequence (i.e., the second sample text), Y represents the true label sequence, and P(Y|X) represents the conditional probability of the true label sequence Y given the input sequence X.

[0180] Where P(Y|X) can be calculated using the following formula (2):

[0181] Among them, score(X,Y) represents the score of the model for the given input sequence X and the true label sequence Y. Represents all possible tag sequences. Among them, score(X,Y) can be decomposed into two parts: emission probabilities and transition probabilities, so the following formula (3) can be used to calculate score(X,Y):

[0182] Where n represents the length of the input sequence X, Y i Indicates the label of the i-th character, Y i-1 Indicates the label of the i-1th character, emission(X,i,Y i ) indicates that the i-th character belongs to label Y i The probability of transition(Y i-1 ,Y i ) indicates that the i-1 Transfer to Y i probability.

[0183] In the embodiment of the present disclosure, the initial object extraction model is trained using the second training sample to obtain an object extraction model, so that the object extraction model can be used to extract objects in the text that require sentiment analysis, thereby improving the accuracy of object extraction.

[0184] To facilitate understanding of the above embodiment, the following description is made in conjunction with Figures 7 and 8 . Figure 7 is a schematic diagram of a model training process provided by an embodiment of the present disclosure. Figure 8 is a schematic diagram of a model reasoning process provided by an embodiment of the present disclosure.

[0185] As shown in FIG7 , the model training process includes the following steps 701 to 705 .

[0186] Step 701: Collect domain-related data.

[0187] Step 702: manually label the data.

[0188] In the disclosed embodiment, data annotation is performed manually to mark the objects to be analyzed and the sentiment polarity of the objects to be analyzed.

[0189] Step 703: construct an object extraction model.

[0190] In the embodiment of the present disclosure, an object extraction model may be constructed using manually labeled objects to be analyzed.

[0191] Among them, the training method of the object extraction model can be found in the above embodiment, so it will not be repeated here.

[0192] Step 704: Obtain a prompt pattern.

[0193] Among them, prompt patterns may include field prompt text, task prompt templates, etc.

[0194] Step 705: construct a sentiment analysis model.

[0195] In the embodiment of the present disclosure, the sentiment analysis model corresponds to the large language model in the above embodiment, and can construct training samples based on the proposed pattern and the extracted objects to be analyzed.

[0196] Among them, the training method of the sentiment analysis model can refer to the training method of the large language model in the above embodiment, so it will not be repeated here.

[0197] As shown in FIG8 , the model inference process includes the following steps 801 to 804 .

[0198] Step 801: input target text.

[0199] Step 802: extract the object to be analyzed from the target text.

[0200] In the embodiment of the present disclosure, an object extraction model may be used to extract the object to be analyzed from the target text.

[0201] Step 803: splice the objects to be analyzed into a sample format.

[0202] In the embodiment of the present disclosure, the target text, the object to be analyzed, and the prompt pattern are spliced ​​together to obtain a spliced ​​text.

[0203] Step 804: Determine the sentiment polarity of the object to be analyzed.

[0204] In the embodiment of the present disclosure, the spliced ​​text can be input into a sentiment analysis model to obtain the sentiment polarity of the object to be analyzed.

[0205] In the embodiments of the present disclosure, the object extraction model and the sentiment analysis model can be trained separately, for example, the object extraction model can be trained first and then the sentiment analysis model, or the sentiment analysis model can be trained first and then the object extraction model, or the object extraction model and the sentiment analysis model can be trained at the same time.

[0206] Alternatively, the object extraction model and the sentiment analysis model can be trained jointly. The parameters of the two models can be adjusted according to the model loss of the object extraction model and the model loss of the sentiment analysis model, thereby improving the model training efficiency and enabling the sentiment analysis model to better learn semantic information.

[0207] To implement the above embodiment, a third embodiment of the present disclosure provides a sentiment analysis device. FIG9 is a schematic diagram of the structure of the sentiment analysis device provided in an embodiment of the present disclosure.

[0208] As shown in FIG9 , the sentiment analysis device 900 includes:

[0209] A first acquisition module 910 is used to acquire a first target text;

[0210] An extraction module 920 is used to extract an object to be analyzed from the first target text;

[0211] A generating module 930 is configured to generate a second target text based on the first target text and the object to be analyzed; wherein the second target text includes a task prompt text, which is used to prompt the large language model to perform a sentiment analysis task on the object to be analyzed based on the first target text;

[0212] The second acquisition module 940 is configured to input the second target text into the large language model to obtain the sentiment polarity of the object to be analyzed.

[0213] In some embodiments, the extraction module 920 is configured to:

[0214] Inputting the first target text into the object extraction model to obtain a label sequence of the first target text output by the object extraction model;

[0215] Determine, according to the label sequence, a target character in the first target text whose label is a target label;

[0216] According to the target characters, determine the object to be analyzed.

[0217] In some embodiments, the extraction module 920 is configured to:

[0218] Performing part-of-speech tagging on the first target text to obtain the part of speech of each word in the first target text;

[0219] According to the part of speech of each participle, determine the candidate participles from the participles;

[0220] The candidate segmented words are matched with the segmented words in the preset dictionary to determine the object to be analyzed from the candidate segmented words.

[0221] In some embodiments, the generating module 930 is configured to:

[0222] Add the object to be analyzed to a preset position in a preset task prompt template to obtain a task prompt text;

[0223] The first target text and the task prompt text are concatenated to obtain the second target text.

[0224] In some embodiments, the generating module 930 is configured to:

[0225] Obtaining a target domain prompt text; wherein the target domain prompt text is used to prompt the domain to which the first target text of the large language model belongs is the target domain;

[0226] A second target text is generated according to the first target text, the object to be analyzed and the target domain prompt text.

[0227] In some embodiments, the generating module 930 is configured to:

[0228] Add the object to be analyzed to a preset position in a preset task prompt template to obtain a task prompt text;

[0229] According to a preset splicing order, the first target text, the target domain prompt text and the task prompt text are spliced ​​together to obtain a second target text.

[0230] In some embodiments, the generating module 930 is configured to:

[0231] Matching the first target text with terms in a term library corresponding to the target domain to determine target terms associated with the first target text;

[0232] A second target text is generated according to the semantics of the first target text, the object to be analyzed, the target domain prompt text and the target term.

[0233] In some embodiments, the generating module 930 is configured to:

[0234] Identifying the domain of the first target text to determine the target domain to which the first target text belongs;

[0235] Obtains a target field prompt text from field prompt texts of multiple fields.

[0236] It should be noted that the explanation of the above-mentioned sentiment analysis method embodiment is also applicable to the sentiment analysis device of this embodiment, so it will not be repeated here.

[0237] In the disclosed embodiment, the object to be analyzed is extracted from a first target text. Based on the first target text and the object to be analyzed, a second target text containing a task prompt text is generated. The second target text is then processed using a large language model to determine the sentiment polarity of the object to be analyzed. Thus, by extracting objects from the first target text, the object requiring sentiment analysis is determined. The task prompt text guides the model to perform sentiment analysis on the object to be analyzed, achieving object-level sentiment analysis and improving the accuracy of the sentiment analysis results.

[0238] To implement the above embodiment, a fourth embodiment of the present disclosure provides a large language model training device. FIG10 is a schematic diagram of the structure of a large language model training device provided by an embodiment of the present disclosure.

[0239] As shown in FIG10 , the large language model training apparatus 1000 includes:

[0240] A first acquisition module 1010 is configured to acquire a first training sample, wherein the first training sample includes a first sample text and a task prompt text, wherein the task prompt text is configured to prompt the initial large language model to perform a sentiment analysis task on an object to be analyzed in the first sample text;

[0241] A second acquisition module 1020 is configured to input the first training sample into the initial large language model to obtain a predicted sentiment polarity;

[0242] The first training module 1030 is configured to train the initial large language model according to the difference between the predicted sentiment polarity and the actual sentiment polarity corresponding to the object to be analyzed, thereby obtaining a large language model.

[0243] In some embodiments, the first acquisition module 1010 is configured to:

[0244] Get the first sample text;

[0245] Extracting an object to be analyzed from the first sample text;

[0246] A first training sample is generated according to the first sample text and the object to be analyzed.

[0247] In some embodiments, the first acquisition module 1010 is configured to:

[0248] Obtaining a target domain prompt text; wherein the target domain prompt text is used to indicate that the domain to which the first sample text of the initial large language model belongs is the target domain;

[0249] A first training sample is generated according to the first sample text, the object to be analyzed and the target domain prompt text.

[0250] In some embodiments, the first acquisition module 1010 is configured to:

[0251] Inputting the first sample text into the object extraction model to obtain a label sequence of the first sample text output by the object extraction model;

[0252] Determine, according to the label sequence, a target character in the first sample text whose label is a target label;

[0253] According to the target characters, determine the object to be analyzed.

[0254] In some embodiments, the apparatus may further comprise:

[0255] A third acquisition module is configured to acquire a second training sample, wherein the second training sample includes a second sample text and a true label sequence of the second sample text;

[0256] A fourth acquisition module is used to input the second sample text into the initial object extraction model to obtain a predicted label sequence;

[0257] The second training module is used to train the initial object extraction model according to the difference between the predicted label sequence and the true label sequence to obtain the object extraction model.

[0258] In some embodiments, the second training module is configured to:

[0259] Determine the probability that the predicted label sequence is the true label sequence based on the probability that each character in the second sample text belongs to each label;

[0260] Determine the model loss based on the probability that the predicted label sequence is the true label sequence;

[0261] According to the model loss, the initial object extraction model is trained to obtain the object extraction model.

[0262] It should be noted that the explanation of the aforementioned embodiment of the large language model training method is also applicable to the large language model training device of this embodiment, so it will not be repeated here.

[0263] In the disclosed embodiment, a first training sample containing task prompt text can be used to train an initial large language model to obtain a large language model. Thus, the task prompt text tells the model the task to be performed, guiding the large language model to analyze the sentiment polarity of the object to be analyzed. Thus, the large language model can analyze the sentiment polarity of different objects, achieving object-level sentiment analysis and improving the accuracy of the model's sentiment analysis results.

[0264] According to an embodiment of the present disclosure, an electronic device, a readable storage medium, a computer program product, and a computer program are further provided.

[0265] A fifth aspect of the present disclosure provides an electronic device, including:

[0266] at least one processor; and

[0267] a memory communicatively connected to the at least one processor; wherein,

[0268] 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 the embodiment of the first aspect, or can execute the training method of the large language model described in the embodiment of the second aspect. Figure 11 shows a schematic block diagram of an electronic device 1100 that can be used to implement an embodiment of the present disclosure. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the embodiments of the present disclosure described and / or required herein.

[0269] As shown in FIG11 , the device 1100 includes a computing unit 1101 that can perform various appropriate actions and processes based on a computer program stored in a ROM (Read-Only Memory) 1102 or a computer program loaded from a storage unit 1108 into a RAM (Random Access Memory) 1103. Various programs and data required for the operation of the device 1100 may also be stored in the RAM 1103. The computing unit 1101, the ROM 1102, and the RAM 1103 are connected to each other via a bus 1104. An I / O (Input / Output) interface 1105 is also connected to the bus 1104.

[0270] Various components in device 1100 are connected to I / O interface 1105, including an input unit 1106, such as a keyboard and mouse; an output unit 1107, such as various types of displays and speakers; a storage unit 1108, such as a magnetic disk and optical disk; and a communication unit 1109, such as a network card, a modem, a wireless communication transceiver, etc. Communication unit 1109 allows device 1100 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0271] The computing unit 1101 can be various general-purpose and / or specialized processing components with processing and computing capabilities. Some examples of the computing unit 1101 include, but are not limited to, a CPU (Central Processing Unit), a GPU (Graphic Processing Unit), various specialized AI (Artificial Intelligence) computing chips, various computing units that run machine learning model algorithms, a DSP (Digital Signal Processor), and any suitable processor, controller, microcontroller, etc. The computing unit 1101 performs the various methods and processes described above, such as the sentiment analysis method. For example, in some embodiments, the sentiment analysis method can be implemented as a computer software program that is tangibly embodied in a machine-readable medium, such as the storage unit 1108. In some embodiments, part or all of the computer program can be loaded and / or installed on the device 1100 via the ROM 1102 and / or the communication unit 1109. When the computer program is loaded into the RAM 1103 and executed by the computing unit 1101, one or more steps of the sentiment analysis method described above can be performed. Alternatively, in other embodiments, the computing unit 1101 may be configured to perform the sentiment analysis method in any other appropriate manner (eg, by means of firmware).

[0272] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application-Specific Standard Products), SOCs (System on Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special-purpose or general-purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0273] The program code for implementing the method of the embodiment of the present disclosure can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the program code is executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0274] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or apparatus. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, RAM, ROM, EPROM (Electrically Programmable Read-Only-Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0275] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0276] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: LAN (Local Area Network), WAN (Wide Area Network), the Internet, and blockchain networks.

[0277] A computer system may include a client and a server. The client and server are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host, a host product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosts and VPS (Virtual Private Server) services. The server may also be a server in a distributed system or a server integrated with blockchain.

[0278] It should be noted that the electronic device provided in the fifth aspect embodiment of the present disclosure for implementing the sentiment analysis method embodiment or the large language model training method embodiment of the present disclosure is similar in structure to the above-mentioned electronic device, so it will not be repeated here.

[0279] According to an embodiment of the present disclosure, a sixth aspect embodiment of the present disclosure provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute the sentiment analysis method according to the above-mentioned first aspect embodiment, or to execute the large language model training method according to the above-mentioned second aspect embodiment.

[0280] According to an embodiment of the present disclosure, the seventh aspect embodiment of the present disclosure provides a computer program product, including a computer program. When the instruction processor in the computer program product executes, it executes the steps of the sentiment analysis method proposed in the above-mentioned first aspect embodiment of the present disclosure, or executes the steps of the large language model training method proposed in the above-mentioned second aspect embodiment of the present disclosure.

[0281] According to an embodiment of the present disclosure, an eighth aspect embodiment of the present disclosure provides a computer program, including computer program code. When the computer program code is run on a computer, the computer executes the steps of the sentiment analysis method described in the first aspect embodiment, or implements the steps of the large language model training method described in the second aspect embodiment.

[0282] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved. This is not limited herein.

[0283] The above specific embodiments do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure shall be included within the scope of protection of this disclosure.

[0284] It should be noted that the explanations of the sentiment analysis method and the training method of the large language model in the aforementioned embodiments are also applicable to the device, computer-readable storage medium, computer program product and computer program of the embodiments of the present disclosure, and will not be repeated here.

[0285] All embodiments of the present disclosure may be implemented individually or in combination with other embodiments, and are all considered to be within the scope of protection claimed by the present disclosure.

Claims

1. A sentiment analysis method, comprising: Get the first target text; Extracting an object to be analyzed from the first target text; Generate a second target text according to the first target text and the object to be analyzed; wherein the second target text includes a task prompt text, and the task prompt text is used to prompt the large language model to perform a sentiment analysis task on the object to be analyzed based on the first target text; The second target text is input into the large language model to obtain the sentiment polarity of the object to be analyzed.

2. The method of claim 1, wherein: The step of extracting the object to be analyzed from the first target text includes: Inputting the first target text into an object extraction model to obtain a label sequence of the first target text output by the object extraction model; Determine, according to the tag sequence, a target character in the first target text whose tag is a target tag; The object to be analyzed is determined according to the target character.

3. The method of claim 1, wherein: The step of extracting the object to be analyzed from the first target text includes: Performing part-of-speech tagging on the first target text to obtain the part-of-speech of each word in the first target text; Determine candidate participles from the participles according to the part of speech of each participle; The candidate participles are matched with participles in a preset dictionary to determine the object to be analyzed from the candidate participles.

4. The method according to any one of claims 1 to 3, wherein: The step of generating a second target text according to the first target text and the object to be analyzed includes: Adding the object to be analyzed to a preset position in a preset task prompt template to obtain the task prompt text; The first target text and the task prompt text are concatenated to obtain the second target text.

5. The method according to any one of claims 1 to 3, wherein: The step of generating a second target text according to the first target text and the object to be analyzed includes: Acquire a target domain prompt text; wherein the target domain prompt text is used to prompt the large language model that the domain to which the first target text belongs is the target domain; The second target text is generated according to the first target text, the object to be analyzed and the target domain prompt text. Mark text.

6. The method of claim 5, wherein: The step of generating the second target text according to the first target text, the object to be analyzed and the target domain prompt text includes: Adding the object to be analyzed to a preset position in a preset task prompt template to obtain the task prompt text; The first target text, the target domain prompt text and the task prompt text are spliced ​​in a preset splicing order to obtain the second target text.

7. The method of claim 5, wherein: The step of generating the second target text according to the first target text, the object to be analyzed and the target domain prompt text includes: Matching the first target text with terms in a term library corresponding to the target field to determine target terms associated with the first target text; The second target text is generated according to the first target text, the object to be analyzed, the target domain prompt text and the semantics of the target term.

8. The method according to any one of claims 5 to 7, wherein: The step of obtaining the target field prompt text includes: Identifying the domain of the first target text to determine the target domain to which the first target text belongs; The target domain prompt text of the target domain is obtained from the domain prompt texts of multiple domains.

9. A method for training a large language model, comprising: Acquire a first training sample; wherein the first training sample includes a first sample text and a task prompt text, and the task prompt text is used to prompt the initial large language model to perform a sentiment analysis task on the object to be analyzed in the first sample text; Inputting the first training sample into the initial large language model to obtain predicted sentiment polarity; The initial large language model is trained according to the difference between the predicted emotion polarity and the actual emotion polarity corresponding to the object to be analyzed to obtain a large language model.

10. The method of claim 9, wherein: The obtaining of the first training sample comprises: Obtaining the first sample text; Extracting an object to be analyzed from the first sample text; The first training sample is generated according to the first sample text and the object to be analyzed.

11. The method of claim 10, wherein: The step of generating the first training sample according to the first sample text and the object to be analyzed includes: Acquire a target domain prompt text; wherein the target domain prompt text is used to prompt the initial large language model that the domain to which the first sample text belongs is the target domain; The first training sample is generated according to the first sample text, the object to be analyzed and the target domain prompt text.

12. The method according to claim 10 or 11, wherein: The step of extracting the object to be analyzed from the first sample text includes: Inputting the first sample text into an object extraction model to obtain a label sequence of the first sample text output by the object extraction model; Determine, according to the tag sequence, a target character whose label is a target label in the first sample text; The object to be analyzed is determined according to the target character.

13. The method of claim 12, wherein: The object extraction model is trained by the following steps: Acquire a second training sample; wherein the second training sample includes a second sample text and a true label sequence of the second sample text; Inputting the second sample text into the initial object extraction model to obtain a predicted label sequence; The initial object extraction model is trained according to the difference between the predicted label sequence and the true label sequence to obtain the object extraction model.

14. The method of claim 13, wherein: The step of training the initial object extraction model according to the difference between the predicted label sequence and the true label sequence to obtain the object extraction model comprises: Determining the probability that the predicted label sequence is the true label sequence according to the probability that each character in the second sample text belongs to each label; Determining a model loss according to a probability that the predicted label sequence is the true label sequence; The initial object extraction model is trained according to the model loss to obtain the object extraction model.

15. A sentiment analysis device, comprising: A first acquisition module, used to acquire a first target text; An extraction module, used for extracting an object to be analyzed from the first target text; A generating module is used to generate a second target text according to the first target text and the object to be analyzed; wherein, The second target text includes a task prompt text, and the task prompt text is used to prompt the large language model to perform a sentiment analysis task on the object to be analyzed based on the first target text; The second acquisition module is used to input the second target text into the large language model to obtain the sentiment polarity of the object to be analyzed.

16. The device of claim 15, wherein: The extraction module is used for: Inputting the first target text into an object extraction model to obtain a label sequence of the first target text output by the object extraction model; Determine, according to the tag sequence, a target character in the first target text whose tag is a target tag; The object to be analyzed is determined according to the target character.

17. The device of claim 15, wherein: The extraction module is used for: Performing part-of-speech tagging on the first target text to obtain the part-of-speech of each word in the first target text; Determine candidate participles from the participles according to the part of speech of each participle; The candidate participles are matched with participles in a preset dictionary to determine the object to be analyzed from the candidate participles.

18. The device according to any one of claims 15 to 17, wherein: The generating module is used for: Adding the object to be analyzed to a preset position in a preset task prompt template to obtain the task prompt text; The first target text and the task prompt text are concatenated to obtain the second target text.

19. The device according to any one of claims 15 to 17, wherein: The generating module is used for: Acquire a target domain prompt text; wherein the target domain prompt text is used to prompt the large language model that the domain to which the first target text belongs is the target domain; The second target text is generated according to the first target text, the object to be analyzed and the target domain prompt text.

20. The device of claim 19, wherein: The generating module is used for: Adding the object to be analyzed to a preset position in a preset task prompt template to obtain the task prompt text; The first target text, the target domain prompt text and the task prompt text are spliced ​​in a preset splicing order to obtain the second target text.

21. The apparatus of claim 19, wherein: The generating module is used for: Matching the first target text with terms in a term library corresponding to the target field to determine target terms associated with the first target text; The second target text is generated according to the first target text, the object to be analyzed, the target domain prompt text and the semantics of the target term.

22. The device according to any one of claims 19 to 21, wherein: The generating module is used for: Identifying the domain of the first target text to determine the target domain to which the first target text belongs; The target domain prompt text of the target domain is obtained from the domain prompt texts of multiple domains.

23. A training device for a large language model, comprising: A first acquisition module is used to acquire a first training sample; wherein the first training sample includes a first sample text and a task prompt text, and the task prompt text is used to prompt the initial large language model to perform a sentiment analysis task on the object to be analyzed in the first sample text; A second acquisition module is used to input the first training sample into the initial large language model to obtain a predicted sentiment polarity; The first training module is used to train the initial large language model according to the difference between the predicted emotion polarity and the actual emotion polarity corresponding to the object to be analyzed, so as to obtain a large language model.

24. The device of claim 23, wherein: The first acquisition module is used to: Obtaining the first sample text; Extracting an object to be analyzed from the first sample text; The first training sample is generated according to the first sample text and the object to be analyzed.

25. The device of claim 24, wherein: The first acquisition module is used to: Acquire a target domain prompt text; wherein the target domain prompt text is used to prompt the initial large language model that the domain to which the first sample text belongs is the target domain; The first training sample is generated according to the first sample text, the object to be analyzed and the target domain prompt text.

26. The apparatus of claim 24, wherein: The first acquisition module is used to: The first sample text is input into the object extraction model to obtain the first sample text output by the object extraction model. The tag sequence of this text; Determine, according to the tag sequence, a target character whose label is a target label in the first sample text; The object to be analyzed is determined according to the target character.

27. The apparatus of claim 26, further comprising: A third acquisition module is used to acquire a second training sample; wherein the second training sample includes a second sample text and a true label sequence of the second sample text; A fourth acquisition module, used for inputting the second sample text into an initial object extraction model to obtain a predicted label sequence; The second training module is used to train the initial object extraction model according to the difference between the predicted label sequence and the true label sequence to obtain the object extraction model.

28. The apparatus of claim 27, wherein: The second training module is used to: Determining the probability that the predicted label sequence is the true label sequence according to the probability that each character in the second sample text belongs to each label; Determining a model loss according to a probability that the predicted label sequence is the true label sequence; The initial object extraction model is trained according to the model loss to obtain the object extraction model.

29. An electronic device comprising: at least one processor; as well as 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 to 8, or can execute the training method of a large language model described in any one of claims 9 to 14.

30. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable the computer to execute the sentiment analysis method according to any one of claims 1 to 8, or to execute the large language model training method according to any one of claims 9 to 14.

31. A computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the sentiment analysis method described in any one of claims 1 to 8, or implements the steps of the large language model training method described in any one of claims 9 to 14.

32. A computer program, comprising a computer program code, which, when executed on a computer, enables the computer to execute the steps of the sentiment analysis method described in any one of claims 1 to 8, or implement the steps of the large language model training method described in any one of claims 9 to 14.

Citation Information

Patent Citations

  • Emotion analysis method and system, computer terminal and storage medium

    CN110705300A

  • Information analysis method and device, electronic equipment and computer readable storage medium

    CN113609390A

  • Language model training method and device, electronic equipment and storage medium

    CN114841274A

  • Language model training method and device, electronic equipment and storage medium

    CN115062718A

  • Emotion analysis method and device and big language model training method and device

    CN117436438A