A method and device for constructing a text sentiment analysis model

By using template learning methods in the training of text sentiment analysis model, inserting template text to generate target sample text, the problem that text sentiment analysis model in the prior art cannot accurately analyze text global semantics, and improves the accuracy of the analysis.

CN115081458BActive Publication Date: 2025-05-23GUANGZHOU YOUMI INFORMATION TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210674237.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-15
Publication Date
2025-05-23
Estimated Expiration
2042-06-15

AI Technical Summary

Technical Problem

Existing text sentiment analysis models cannot accurately analyze text global semantics, resulting in low analysis accuracy.

Method used

The training method of template learning is adopted, and the target sample text is generated by inserting the template text into the initial sample text to train the sentiment analysis model and improve the training effect and accuracy of the model.

Benefits of technology

It improves the accuracy of text sentiment analysis and enhances the ability of sentiment analysis model to understand the global semantics of text.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115081458B_ABST
    Figure CN115081458B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for constructing a text sentiment analysis model, including: inserting a template text containing target characters for referring to unknown emotions into a number of initial sample texts to obtain target sample texts; inputting each target sample text into the sentiment analysis model to obtain a sentiment analysis result corresponding to each target sample text; judging whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all target sample texts and the sentiment annotation results corresponding to all initial sample texts; if not, correcting the model parameters, and re-performing the above-mentioned operation of inputting each target sample text into the sentiment analysis model and judging whether the sentiment analysis model meets the convergence condition, until a target sentiment analysis model that meets the convergence condition is obtained. It can be seen that the implementation of the present invention can train the sentiment analysis model using the template learning training method, improve the training effect of the sentiment analysis model, and thus improve the accuracy of text sentiment analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of semantic analysis, and in particular to a method and device for constructing a text sentiment analysis model. Background Art

[0002] In real life, there are a large number of comments on people and events on the Internet participated by a large number of users. In order to obtain the public opinion on a certain thing, a text sentiment analysis model can be used to perform text sentiment analysis on a large number of comments on the Internet about the thing. The current text sentiment analysis model mainly extracts sentiment keywords from the text based on a series of pre-established sentiment dictionaries, and finally confirms the sentiment tendency of the text based on the sentiment keywords. However, it is found in practice that the existing text sentiment analysis model cannot accurately analyze the global semantics of the text. For example, the keywords extracted from the text "The dishes made by restaurant A are really unpalatable" and the text "The dishes made by restaurant B are not unpalatable" are both "unpalatable". The text sentiment analysis model will determine that "the dishes made by restaurants A and B are both unpalatable". Obviously, the analysis accuracy of the existing text sentiment analysis model is low. It can be seen that how to build a new text sentiment analysis model to improve the accuracy of text sentiment analysis is particularly important. Summary of the invention

[0003] The technical problem to be solved by the present invention is to provide a method and device for constructing a text sentiment analysis model, which can train the sentiment analysis model using a template learning training method, thereby improving the training effect of the sentiment analysis model and further improving the accuracy of text sentiment analysis.

[0004] In order to solve the above technical problems, the first aspect of the present invention discloses a method for constructing a text sentiment analysis model, the method comprising:

[0005] Determine a number of initial sample texts with annotation information;

[0006] Inserting a template text matching the initial sample text at a preset position of each of the initial sample texts to obtain a plurality of target sample texts for model training, wherein the template text includes a target character for representing an unknown emotion;

[0007] Input each of the target sample texts into the sentiment analysis model to be trained, so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain a sentiment analysis result corresponding to each of the target sample texts, wherein the sentiment analysis result corresponding to each of the target sample texts includes a prediction result of a target character in the target sample text, and the prediction result is a sentiment prediction result of the corresponding target sample text;

[0008] According to the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts, judging whether the sentiment analysis model meets the convergence condition;

[0009] When the judgment result is no, the model parameters of the sentiment analysis model are corrected, and the operation of inputting each of the target sample texts into the sentiment analysis model to be trained is re-executed so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain the sentiment analysis result corresponding to each of the target sample texts, and the operation of judging whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts is performed, until a target sentiment analysis model that meets the convergence condition is obtained, and the target sentiment analysis model is used to analyze the text sentiment of the text to be analyzed.

[0010] As an optional implementation, in the first aspect of the present invention, judging whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts includes:

[0011] For each of the target sample texts, determining a matching degree between a sentiment analysis result corresponding to the target sample text and a sentiment annotation result corresponding to the corresponding initial sample text as a matching degree corresponding to the target sample text;

[0012] Calculating the analysis accuracy of the sentiment analysis model according to the matching degrees corresponding to all the target sample texts;

[0013] Determining whether the analysis accuracy is greater than or equal to a preset accuracy threshold;

[0014] When the judgment result is yes, it is determined that the sentiment analysis model meets the convergence condition, and when the judgment result is no, it is determined that the sentiment analysis model does not meet the convergence condition.

[0015] As an optional implementation, in the first aspect of the present invention, each of the emotion prediction results of the target sample text includes one or more sub-prediction results and probability information corresponding to each of the sub-prediction results;

[0016] And, for each of the target sample texts, determining the matching degree between the sentiment analysis result corresponding to the target sample text and the sentiment annotation result corresponding to the corresponding initial sample text comprises:

[0017] For each of the target sample texts, determining a sub-prediction result whose corresponding probability information in the emotion prediction result of the target sample text satisfies a preset probability condition as a target emotion prediction result of the target sample text;

[0018] For each of the target sample texts, a matching degree between a target emotion prediction result of the target sample text and an emotion annotation result corresponding to a corresponding initial sample text is determined as the matching degree corresponding to the target sample text.

[0019] As an optional implementation, in the first aspect of the present invention, the sentiment analysis model analyzes the text content of each of the target sample texts to obtain a sentiment analysis result corresponding to each of the target sample texts, including:

[0020] The encoding structure corresponding to the sentiment analysis model performs an encoding operation on each of the target sample texts to obtain an encoding result corresponding to each of the target sample texts, wherein the encoding result corresponding to each of the target sample texts includes a text vector corresponding to the target sample text, a position vector corresponding to the target sample text, and a sentence vector corresponding to the target sample text;

[0021] The vector processing structure corresponding to the sentiment analysis model analyzes the encoding result corresponding to each target sample text to obtain the sentiment analysis result corresponding to the target sample text;

[0022] The encoding structure corresponding to the sentiment analysis model performs an encoding operation on each of the target sample texts to obtain an encoding result corresponding to each of the target sample texts, including:

[0023] The encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in each target sample text; or, the encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in the initial sample text of each target sample text and the semantic information corresponding to each text element except the target character in the template text of the target sample text, wherein the semantic information corresponding to each text element in the template text includes sub-semantic information corresponding to the text element in one or more part-of-speech dimensions corresponding to the text element;

[0024] The encoding structure generates a position vector corresponding to the target sample text and a sentence vector corresponding to the target sample text according to the position information corresponding to each text element in each target sample text in the target sample text, wherein the sentence vector corresponding to each target sample text is used to represent the sentence to which each text element in the target sample text belongs in the target sample text.

[0025] As an optional implementation, in the first aspect of the present invention, the determining of a plurality of initial sample texts with annotation information includes:

[0026] Get some initial texts for model training;

[0027] For each of the initial texts, according to at least one preset annotation mark, a text feature corresponding to each annotation mark is extracted from the text to obtain the text content corresponding to each annotation mark;

[0028] According to preset splicing characters and / or splicing sequence, a splicing operation is performed on the text contents corresponding to all the annotation marks extracted from each of the initial texts to obtain a plurality of initial sample texts with annotation information.

[0029] As an optional embodiment, in the first aspect of the present invention, the method further comprises:

[0030] Determine the text keywords that meet the preset confirmation conditions in each of the initial sample texts, and determine the template text that matches the initial sample text according to the text keywords of each of the initial sample texts;

[0031] The step of determining the template text that matches each of the initial sample texts according to the text keywords of the initial sample texts includes:

[0032] Determining the emotional complexity corresponding to each of the initial sample texts according to the text keywords of the initial sample texts;

[0033] For each of the initial sample texts, an original template text that matches the emotion complexity corresponding to the initial sample text among a plurality of preset original template texts is determined as a target template text corresponding to the initial sample text, wherein the original template text includes a first-category template text and / or a second-category template text, the information to be supplemented corresponding to the first-category template text is emotion degree information, and the information to be supplemented corresponding to the second-category template text is emotion description information;

[0034] According to the text keywords of each of the initial sample texts, a keyword replacement operation is performed on other text contents in the target template text corresponding to the initial sample text except the information to be supplemented, so as to obtain a template text matching the initial sample text.

[0035] As an optional implementation manner, in the first aspect of the present invention, before inputting each of the target sample texts into the sentiment analysis model so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain the sentiment analysis result corresponding to each of the target sample texts, the method further includes:

[0036] For each of the target sample texts, determining whether the text length of the target sample text is greater than a preset length threshold, and if so, performing a preprocessing operation on the target sample text to update the target sample text;

[0037] The preprocessing operation on the target sample text includes:

[0038] According to the text element information corresponding to each text structure in the target sample text, at least one target text structure satisfying the preprocessing condition is determined from all the text structures of the target sample text, wherein the text elements contained in each of the target text structures include at least one essential element and at least one non-essential element;

[0039] For each non-essential element of each target text structure of the target sample text, determine whether the influence of the non-essential element on the text information of the target text structure is less than a preset influence degree; when it is determined that the influence of the non-essential element on the text information of the target text structure is less than the preset influence degree, remove the non-essential element, wherein the text information includes text semantics and / or text sentiment.

[0040] A second aspect of the present invention discloses a device for constructing a text sentiment analysis model, the device comprising:

[0041] A determination module, used to determine a number of initial sample texts with annotation information;

[0042] An inserting module, used for inserting a template text matching the initial sample text at a preset position of each of the initial sample texts, to obtain a plurality of target sample texts for model training, wherein the template texts include target characters for referring to unknown emotions;

[0043] An input module, used for inputting each of the target sample texts into the sentiment analysis model to be trained, so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain a sentiment analysis result corresponding to each of the target sample texts, wherein the sentiment analysis result corresponding to each of the target sample texts includes a prediction result of a target character in the target sample text, and the prediction result is a sentiment prediction result of the corresponding target sample text;

[0044] A judgment module, used to judge whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts;

[0045] A correction module is used to correct the model parameters of the sentiment analysis model when the judgment module determines that the sentiment analysis model does not meet the convergence condition, and trigger the input module to re-execute the operation of inputting each of the target sample texts into the sentiment analysis model to be trained so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain the sentiment analysis result corresponding to each of the target sample texts, and trigger the judgment module to execute the operation of judging whether the sentiment analysis model meets the convergence condition based on the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts, until a target sentiment analysis model that meets the convergence condition is obtained, and the target sentiment analysis model is used to analyze the text sentiment of the text to be analyzed.

[0046] As an optional implementation, in the second aspect of the present invention, the judgment module judges whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts in a specific manner including:

[0047] For each of the target sample texts, determining a matching degree between a sentiment analysis result corresponding to the target sample text and a sentiment annotation result corresponding to the corresponding initial sample text as a matching degree corresponding to the target sample text;

[0048] Calculating the analysis accuracy of the sentiment analysis model according to the matching degrees corresponding to all the target sample texts;

[0049] Determining whether the analysis accuracy is greater than or equal to a preset accuracy threshold;

[0050] When the judgment result is yes, it is determined that the sentiment analysis model meets the convergence condition, and when the judgment result is no, it is determined that the sentiment analysis model does not meet the convergence condition.

[0051] As an optional implementation, in the second aspect of the present invention, each of the emotion prediction results of the target sample text includes one or more sub-prediction results and probability information corresponding to each of the sub-prediction results;

[0052] And, the specific manner in which the judgment module determines, for each target sample text, the degree of match between the sentiment analysis result corresponding to the target sample text and the sentiment annotation result corresponding to the corresponding initial sample text includes:

[0053] For each of the target sample texts, determining a sub-prediction result whose corresponding probability information in the emotion prediction result of the target sample text satisfies a preset probability condition as a target emotion prediction result of the target sample text;

[0054] For each of the target sample texts, a matching degree between a target emotion prediction result of the target sample text and an emotion annotation result corresponding to a corresponding initial sample text is determined as the matching degree corresponding to the target sample text.

[0055] As an optional implementation, in the second aspect of the present invention, the sentiment analysis model analyzes the text content of each of the target sample texts, and the specific manner of obtaining the sentiment analysis result corresponding to each of the target sample texts includes:

[0056] The encoding structure corresponding to the sentiment analysis model performs an encoding operation on each of the target sample texts to obtain an encoding result corresponding to each of the target sample texts, wherein the encoding result corresponding to each of the target sample texts includes a text vector corresponding to the target sample text, a position vector corresponding to the target sample text, and a sentence vector corresponding to the target sample text;

[0057] The vector processing structure corresponding to the sentiment analysis model analyzes the encoding result corresponding to each target sample text to obtain the sentiment analysis result corresponding to the target sample text;

[0058] The encoding structure corresponding to the sentiment analysis model performs encoding operation on each of the target sample texts, and the specific manner of obtaining the encoding result corresponding to each of the target sample texts includes:

[0059] The encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in each target sample text; or, the encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in the initial sample text of each target sample text and the semantic information corresponding to each text element except the target character in the template text of the target sample text, wherein the semantic information corresponding to each text element in the template text includes sub-semantic information corresponding to the text element in one or more part-of-speech dimensions corresponding to the text element;

[0060] The encoding structure generates a position vector corresponding to the target sample text and a sentence vector corresponding to the target sample text according to the position information corresponding to each text element in each target sample text in the target sample text, wherein the sentence vector corresponding to each target sample text is used to represent the sentence to which each text element in the target sample text belongs in the target sample text.

[0061] As an optional implementation, in the second aspect of the present invention, the specific manner in which the determination module determines the plurality of initial sample texts with the annotation information includes:

[0062] Get some initial texts for model training;

[0063] For each of the initial texts, according to at least one preset annotation mark, a text feature corresponding to each annotation mark is extracted from the text to obtain the text content corresponding to each annotation mark;

[0064] According to preset splicing characters and / or splicing sequence, a splicing operation is performed on the text contents corresponding to all the annotation marks extracted from each of the initial texts to obtain a plurality of initial sample texts with annotation information.

[0065] As an optional implementation, in the second aspect of the present invention, the determination module is further used to determine the text keywords that meet the preset confirmation conditions in each of the initial sample texts, and determine the template text that matches the initial sample text according to the text keywords of each of the initial sample texts;

[0066] The specific manner in which the determination module determines the template text that matches the initial sample text according to the text keywords of each initial sample text includes:

[0067] Determining the emotional complexity corresponding to each of the initial sample texts according to the text keywords of the initial sample texts;

[0068] For each of the initial sample texts, an original template text that matches the emotion complexity corresponding to the initial sample text among a plurality of preset original template texts is determined as a target template text corresponding to the initial sample text, wherein the original template text includes a first-category template text and / or a second-category template text, the information to be supplemented corresponding to the first-category template text is emotion degree information, and the information to be supplemented corresponding to the second-category template text is emotion description information;

[0069] According to the text keywords of each of the initial sample texts, a keyword replacement operation is performed on other text contents in the target template text corresponding to the initial sample text except the information to be supplemented, so as to obtain a template text matching the initial sample text.

[0070] As an optional implementation, in the second aspect of the present invention, the judgment module is further used to input each of the target sample texts into the sentiment analysis model in the input module so that the sentiment analysis model analyzes the text content of each of the target sample texts, and before obtaining the sentiment analysis result corresponding to each of the target sample texts, for each of the target sample texts, judge whether the text length of the target sample text is greater than a preset length threshold;

[0071] And, the device also includes:

[0072] A preprocessing module, for each of the target sample texts, when the judgment module judges that the text length of the target sample text is greater than a preset length threshold, performing a preprocessing operation on the target sample text to update the target sample text;

[0073] The specific manner in which the preprocessing module performs preprocessing operations on the target sample text includes:

[0074] According to the text element information corresponding to each text structure in the target sample text, at least one target text structure satisfying the preprocessing condition is determined from all the text structures of the target sample text, wherein the text elements contained in each of the target text structures include at least one essential element and at least one non-essential element;

[0075] For each non-essential element of each target text structure of the target sample text, determine whether the influence of the non-essential element on the text information of the target text structure is less than a preset influence degree; when it is determined that the influence of the non-essential element on the text information of the target text structure is less than the preset influence degree, remove the non-essential element, wherein the text information includes text semantics and / or text sentiment.

[0076] The third aspect of the present invention discloses another device for constructing a text sentiment analysis model, the device comprising:

[0077] A memory storing executable program code;

[0078] a processor coupled to the memory;

[0079] The processor calls the executable program code stored in the memory to execute the method for constructing a text sentiment analysis model disclosed in the first aspect of the present invention.

[0080] The fourth aspect of the present invention discloses a computer storage medium, which stores computer instructions. When the computer instructions are called, they are used to execute the method for constructing a text sentiment analysis model disclosed in the first aspect of the present invention.

[0081] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:

[0082] In an embodiment of the present invention, a plurality of initial sample texts with annotation information are determined; a template text matching the initial sample text is inserted at a preset position of each initial sample text to obtain a plurality of target sample texts for model training, wherein the template text includes a target character for referring to an unknown emotion; each target sample text is input into a sentiment analysis model to be trained so that the sentiment analysis model analyzes the text content of each target sample text to obtain a sentiment analysis result corresponding to each target sample text, wherein the sentiment analysis result corresponding to each target sample text includes a prediction result of a target character in the target sample text, and the prediction result is a sentiment prediction result of the corresponding target sample text; and a plurality of target sample texts are trained according to the sentiment analysis results corresponding to all target sample texts. The results and the sentiment annotation results corresponding to all the initial sample texts are used to judge whether the sentiment analysis model meets the convergence conditions; when the judgment result is no, the model parameters of the sentiment analysis model are corrected, and the above-mentioned operation of inputting each target sample text into the sentiment analysis model to be trained is re-executed, so that the sentiment analysis model analyzes the text content of each target sample text to obtain the sentiment analysis result corresponding to each target sample text, and the operation of judging whether the sentiment analysis model meets the convergence conditions according to the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts is performed, until a target sentiment analysis model that meets the convergence conditions is obtained, and the target sentiment analysis model is used to analyze the text sentiment of the text to be analyzed. It can be seen that the implementation of the present invention can insert template text into the initial sample text used for model training, so as to guide the sentiment analysis model to be trained to analyze the initial sample text and predict the sentiment represented by the unknown characters in the template text, that is, the sentiment analysis model is trained using the template learning training method, which improves the degree of matching between the model training method and the characteristics of the sentiment analysis model itself, reduces the situation where the model's own characteristics must be adjusted or abandoned during model training due to the mismatch between the downstream tasks of the model training and the model's own characteristics, improves the training effect and training efficiency of the sentiment analysis model, and thus improves the accuracy of text sentiment analysis. BRIEF DESCRIPTION OF THE DRAWINGS

[0083] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0084] Figure 1 It is a flowchart of a method for constructing a text sentiment analysis model disclosed in an embodiment of the present invention;

[0085] Figure 2 It is a flowchart of another method for constructing a text sentiment analysis model disclosed in an embodiment of the present invention;

[0086] Figure 3 It is a structural schematic diagram of a device for constructing a text sentiment analysis model disclosed in an embodiment of the present invention;

[0087] Figure 4 It is a structural schematic diagram of another device for constructing a text sentiment analysis model disclosed in an embodiment of the present invention;

[0088] Figure 5 It is a structural schematic diagram of another device for constructing a text sentiment analysis model disclosed in an embodiment of the present invention. DETAILED DESCRIPTION

[0089] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0090] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, product or end including a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, products or ends.

[0091] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0092] The present invention discloses a method and device for constructing a text sentiment analysis model, which can insert a template text into an initial sample text used for model training to guide the sentiment analysis model to be trained to analyze the initial sample text and predict the sentiment represented by unknown characters in the template text, that is, to train the sentiment analysis model using a template learning training method, thereby improving the matching degree between the model training method and the characteristics of the sentiment analysis model itself, reducing the situation where the characteristics of the model itself must be adjusted or abandoned during model training due to the mismatch between the downstream tasks of the model training and the characteristics of the model itself, improving the training effect and training efficiency of the sentiment analysis model, and thereby improving the accuracy of text sentiment analysis. The following are detailed descriptions.

[0093] Embodiment 1

[0094] See also Figure 1 , Figure 1 : is a flow chart of a method for constructing a text sentiment analysis model disclosed in an embodiment of the present invention. Figure 1 The method for constructing a text sentiment analysis model described above can be applied to the construction process of a sentiment analysis model based on any architecture, and the embodiments of the present invention are not limited thereto. Figure 1 As shown, the method for constructing the text sentiment analysis model may include the following operations:

[0095] 101. Determine a number of initial sample texts with annotation information.

[0096] In the embodiment of the present invention, the annotation information of each initial sample text may include one or more of the text title, text type, specific text content, text length, text source, emotional subject, emotional object, emotional annotation result, etc. of the initial sample text. This can improve the richness of the annotation information of the initial sample text, thereby improving the analysis accuracy of the sample text by the sentiment analysis model.

[0097] As an optional implementation, determining a number of initial sample texts with annotation information may include:

[0098] Get some initial texts for model training;

[0099] For each initial text, according to at least one preset annotation mark, extract the text features corresponding to each annotation mark from the text to obtain the text content corresponding to each annotation mark;

[0100] According to preset splicing characters and / or splicing sequence, a splicing operation is performed on the text contents corresponding to all the annotation marks extracted from each initial text to obtain a plurality of initial sample texts with annotation information.

[0101] In this optional implementation, the annotation identifier may include one or more of a title identifier, a type identifier, a specific content identifier, a length identifier, a source identifier, an emotion subject identifier, an emotion object identifier, and the like.

[0102] For example, for one of the initial texts, its annotation information includes {'title (text title)': movie review, 'content (text specific content)': this movie is really good...}. If "." is used as the concatenation character, the initial sample text obtained after concatenation is {'text': movie review. This movie is really good...}

[0103] It can be seen that the implementation of this optional implementation method can, after extracting the text content corresponding to multiple annotation identifiers, splice the text content corresponding to all annotation identifiers to obtain the initial sample text, so that the sentiment analysis model can uniformly process the text content corresponding to all annotation identifiers, thereby improving the efficiency of the sentiment analysis model in processing the sample text, and can improve the correlation between the text content corresponding to different annotation identifiers of the same sample text during the model training process, which is conducive to the sentiment analysis model to accurately analyze the overall semantics of the sample text and improve the training effect of the sentiment analysis model.

[0104] 102. Insert a template text that matches each initial sample text at a preset position of the initial sample text to obtain a plurality of target sample texts for model training.

[0105] In the embodiment of the present invention, the template text includes target characters for representing unknown emotions.

[0106] For example, for the above initial sample text {'text': movie review. This movie is really good...}, the template text is "The sentiment of this text is [MASK]", where [MASK] is a target character used to represent unknown sentiment. The template text is inserted before the initial sample text to obtain the target sample text {'text': The sentiment of this text is [MASK], movie review. This movie is really good...}.

[0107] 103. Input each target sample text into the sentiment analysis model to be trained, so that the sentiment analysis model analyzes the text content of each target sample text to obtain a sentiment analysis result corresponding to each target sample text.

[0108] In the embodiment of the present invention, the sentiment analysis result corresponding to each target sample text includes the prediction result of the target character in the target sample text, and the prediction result is the sentiment prediction result of the corresponding target sample text. Optionally, the sentiment prediction result of each target sample text includes one or more sub-prediction results and probability information corresponding to each sub-prediction result.

[0109] In the embodiment of the present invention, preferably, the sentiment analysis model can be a Bert model, and further optionally, the sentiment analysis model is a single Bert model, that is, there is only one Transformer structure in the Bert model. This can improve the matching degree between the downstream tasks of model training and the characteristics of the sentiment analysis model itself.

[0110] As an optional implementation, the sentiment analysis model analyzes the text content of each target sample text to obtain a sentiment analysis result corresponding to each target sample text, which may include:

[0111] The encoding structure corresponding to the sentiment analysis model performs an encoding operation on each target sample text to obtain an encoding result corresponding to each target sample text, wherein the encoding result corresponding to each target sample text includes a text vector corresponding to the target sample text, a position vector corresponding to the target sample text, and a sentence vector corresponding to the target sample text;

[0112] The vector processing structure corresponding to the sentiment analysis model analyzes the encoding result corresponding to each target sample text to obtain the sentiment analysis result corresponding to the target sample text.

[0113] It can be seen that implementing this optional implementation method can predict the sentiment of the sample text based on the text vector, position vector and sentence vector of the sample text, which is beneficial to improving the correlation between different words and different sentences in the same sample text during the model training process, thereby facilitating the sentiment analysis model to accurately analyze the overall semantics of the sample text and improve the training effect of the sentiment analysis model.

[0114] In this optional implementation, optionally, when the sentiment analysis model is a Bert model, the vector processing structure includes at least a Transformer structure, and further optionally, the vector processing structure may also include an average pooling structure, thereby improving the accuracy of the model analysis.

[0115] In this optional implementation, further optionally, the encoding structure corresponding to the sentiment analysis model performs an encoding operation on each target sample text to obtain an encoding result corresponding to each target sample text, which may include:

[0116] The encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in each target sample text; or, the encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in the initial sample text of each target sample text and the semantic information corresponding to each text element except the target character in the template text of the target sample text, wherein the semantic information corresponding to each text element in the template text includes sub-semantic information corresponding to the text element in one or more part-of-speech dimensions corresponding to the text element;

[0117] The encoding structure generates a position vector corresponding to each target sample text and a sentence vector corresponding to the target sample text according to the position information corresponding to each text element in the target sample text, wherein the sentence vector corresponding to each target sample text is used to represent the sentence to which each text element in the target sample text belongs in the target sample text.

[0118] It can be seen that implementing this optional implementation method can also generate text vectors by encoding mapping information to improve encoding efficiency, and generate word embedding vectors through semantic information to improve the accuracy and uniformity of text encoding, reduce the complexity of text vectors, and improve the diversity of sentiment analysis model encoding methods.

[0119] In this optional embodiment, optionally, the encoding structure may include a vocabulary mapping structure and / or a word embedding vector construction structure of the sentiment analysis model, further optionally, the word embedding vector construction structure may be an LSTM structure, and further optionally, the word embedding vector construction structure may be a double-layer LSTM structure.

[0120] Further optionally, the encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in the initial sample text of each target sample text and the semantic information corresponding to each text element except the target character in the template text of the target sample text, which may include:

[0121] The vocabulary mapping structure of the encoding structure corresponding to the sentiment analysis model generates a first text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in the initial sample text of each target sample text, and the word embedding vector construction structure of the encoding structure generates a word embedding vector corresponding to the template text according to the semantic information corresponding to each text element except the target character in the template text of each target sample text, as the second text vector corresponding to the target sample text; the encoding structure determines the text vector corresponding to each target sample text according to the first text vector corresponding to each target sample text and the second text vector corresponding to the target sample text.

[0122] For example, the mapping encoding information corresponding to "you" and "good" are "4" and "6" respectively, so the text vector of "hello" is [4,6]; the sub-semantic information of "girl" in its part-of-speech dimension age and gender corresponds to "0" and "1" respectively, so the word embedding vector corresponding to "girl" is [0,1].

[0123] It can be seen that implementing this optional implementation can improve the accuracy and diversity of generating text vectors.

[0124] 104. According to the sentiment analysis results corresponding to all target sample texts and the sentiment labeling results corresponding to all initial sample texts, it is determined whether the sentiment analysis model meets the convergence condition.

[0125] As an optional implementation, judging whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all target sample texts and the sentiment annotation results corresponding to all initial sample texts may include:

[0126] For each target sample text, determining the matching degree between the sentiment analysis result corresponding to the target sample text and the sentiment annotation result corresponding to the corresponding initial sample text as the matching degree corresponding to the target sample text;

[0127] Calculate the analysis accuracy of the sentiment analysis model based on the matching degree of all target sample texts;

[0128] Determine whether the analysis accuracy is greater than or equal to a preset accuracy threshold;

[0129] When the judgment result is yes, it is determined that the sentiment analysis model meets the convergence condition, and when the judgment result is no, it is determined that the sentiment analysis model does not meet the convergence condition.

[0130] It can be seen that implementing this optional implementation method can calculate the analysis accuracy of the sentiment analysis model based on the matching degree between the sentiment analysis result corresponding to each target sample text and the sentiment annotation result corresponding to the corresponding initial sample text, thereby improving the accuracy and reliability of judging whether the sentiment analysis model meets the convergence conditions.

[0131] In this optional implementation, optionally, the matching degree may be a difference degree, a contrast degree, or an accuracy degree, and further optionally, the matching degree may include an emotion degree matching degree and / or an emotion type matching degree.

[0132] In this optional implementation, further optionally, for each target sample text, determining the degree of match between the sentiment analysis result corresponding to the target sample text and the sentiment annotation result corresponding to the corresponding initial sample text may include:

[0133] For each target sample text, a sub-prediction result whose corresponding probability information in the emotion prediction result of the target sample text satisfies a preset probability condition is determined as a target emotion prediction result of the target sample text;

[0134] For each target sample text, the matching degree between the target emotion prediction result of the target sample text and the emotion annotation result corresponding to the corresponding initial sample text is determined as the matching degree corresponding to the target sample text.

[0135] It can be seen that the implementation of this optional implementation method can also select the prediction result whose probability information meets the preset probability conditions from the multiple prediction results output by the sentiment analysis model as the final prediction result, thereby reducing the interference of unnecessary prediction results on the calculation of analysis accuracy, and improving the accuracy of the analysis accuracy of the sentiment analysis model, which is beneficial to improving the training effect of the sentiment analysis model.

[0136] In this optional implementation, further optionally, calculating the analysis accuracy of the sentiment analysis model according to the matching degrees corresponding to all target sample texts may include:

[0137] Determine the calculation weight corresponding to each target sample text according to the probability information corresponding to the target emotion prediction result of each target sample text;

[0138] The analysis accuracy of the sentiment analysis model is calculated based on the matching degrees corresponding to all target sample texts and the calculation weights corresponding to all target sample texts.

[0139] It can be seen that implementing this optional implementation method can also calculate the analysis accuracy of the sentiment analysis model in combination with the probability information in the prediction results output by the sentiment analysis model, thereby improving the comprehensiveness of the sentiment analysis model accuracy calculation dimension, and thereby improving the accuracy of calculating the sentiment analysis model analysis accuracy.

[0140] In this optional implementation, further optionally, the sentiment analysis result corresponding to each target sample text includes a sentiment analysis vector corresponding to the target sample text, and the sentiment analysis vector corresponding to each target sample text includes a subvector corresponding to each text element in the target sample text, wherein the vector information of the subvector corresponding to the target character in each target sample text includes a prediction result of the target character;

[0141] And, for each target sample text, before determining the sub-prediction result whose corresponding probability information in the emotion prediction result of the target sample text satisfies the preset probability condition as the target emotion prediction result of the target sample text, the method may further include:

[0142] For each target sample text, according to the position of the target character in the target sample text, the vector information of the subvector corresponding to the target character is determined from the sentiment analysis vector corresponding to the target sample text as the sentiment prediction result of the target sample text.

[0143] It can be seen that implementing this optional implementation method can also filter out unnecessary information in the sentiment analysis results output by the sentiment analysis model, thereby improving the reliability and accuracy of calculating the analysis accuracy of the sentiment analysis model.

[0144] 105. When the judgment result of step 104 is no, correct the model parameters of the sentiment analysis model, and re-execute step 103 and step 104.

[0145] 106. When the judgment result of step 104 is yes, the current process ends and a target sentiment analysis model that meets the convergence condition is obtained. The target sentiment analysis model is used to analyze the text sentiment of the text to be analyzed.

[0146] In an optional embodiment, before inputting each target sample text into the sentiment analysis model so that the sentiment analysis model analyzes the text content of each target sample text to obtain the sentiment analysis result corresponding to each target sample text, the method may further include:

[0147] For each target sample text, it is determined whether the text length of the target sample text is greater than a preset length threshold. If so, a preprocessing operation is performed on the target sample text to update the target sample text.

[0148] It can be seen that implementing this optional embodiment can perform preprocessing operations on the sample text when the text length of the sample text is too long, reducing the situation where the sentiment analysis model cannot analyze the sample text due to the sample text being too long, thereby improving the reliability of training the sentiment analysis model.

[0149] In this optional embodiment, as an optional implementation, the preprocessing operation on the target sample text may include:

[0150] According to the text element information corresponding to each text structure in the target sample text, at least one target text structure satisfying the preprocessing condition is determined from all the text structures of the target sample text, wherein the text elements contained in each target text structure include at least one essential element and at least one non-essential element;

[0151] For each non-essential element of each target text structure of the target sample text, determine whether the influence of the non-essential element on the text information of the target text structure is less than a preset influence degree; when it is determined that the influence of the non-essential element on the text information of the target text structure is less than the preset influence degree, remove the non-essential element, wherein the text information includes text semantics and / or text sentiment.

[0152] In this optional implementation, the element type of the non-essential element may include a symbol type and / or a text type, and the symbol type may include a punctuation mark type and / or an emoticon mark type.

[0153] For example, if a target sample text {'text': the sentiment of this text is [MASK], movie review. I went to the cinema to watch The Great Wall, this movie is really good...} contains repeated punctuation marks "," and the text "go to the cinema" which has little influence on the text information, the above content can be removed to obtain a new target sample text {'text': the sentiment of this text is [MASK], movie review. I watched The Great Wall, this movie is really good...}.

[0154] It can be seen that the implementation of this optional implementation method can remove non-essential elements when the text length of the sample text is long and the impact of non-essential elements on the text information is low, thereby reducing the occurrence of necessary elements being lost due to non-essential elements occupying too much space, which is beneficial to improving the accuracy of the sentiment analysis model on the sentiment analysis of the sample text, and can also improve the efficiency of the sentiment analysis model in analyzing the sentiment of the sample text.

[0155] In yet another optional embodiment, before judging whether the sentiment analysis model satisfies the convergence condition according to the sentiment analysis results corresponding to all target sample texts and the sentiment annotation results corresponding to all initial sample texts, the method may further include:

[0156] For each initial sample text, a form conversion operation is performed on the emotion annotation result corresponding to the initial sample text according to the text form of the template text matched by the initial sample text, so as to update the emotion annotation result corresponding to the initial sample text.

[0157] For example, for the above initial sample text {'text': movie review. This movie is really good...}, the sentiment labeling result is {'label': positive}, and the template text is "the sentiment of this text is [MASK]", then the sentiment labeling result obtained after form conversion can be {'label': the sentiment of this text is good} or {'label': the sentiment of this text is good, movie review. This movie is really good...}.

[0158] It can be seen that the implementation of the embodiment of the present invention can insert the template text into the initial sample text used for model training, so as to guide the sentiment analysis model to be trained to analyze the initial sample text and predict the sentiments represented by unknown characters in the template text, that is, the sentiment analysis model is trained using the template learning training method, which improves the degree of matching between the model training method and the characteristics of the sentiment analysis model itself, reduces the situation where the model's own characteristics must be adjusted or abandoned during model training due to the mismatch between the downstream tasks of the model training and the model's own characteristics, improves the training effect and training efficiency of the sentiment analysis model, and thus improves the accuracy of text sentiment analysis.

[0159] Embodiment 2

[0160] See also Figure 2 , Figure 2 is a flow chart of another method for constructing a text sentiment analysis model disclosed in an embodiment of the present invention. Figure 2 The method for constructing a text sentiment analysis model described above can be applied to the construction process of a sentiment analysis model based on any architecture, and the embodiments of the present invention are not limited thereto. Figure 2 As shown, the method for constructing the text sentiment analysis model may include the following operations:

[0161] 201. Determine a number of initial sample texts with annotation information.

[0162] 202. Determine text keywords that meet preset confirmation conditions in each initial sample text.

[0163] As an optional implementation, determining the text keywords satisfying the preset confirmation condition in each initial sample text may include:

[0164] Perform word segmentation on each initial sample text to obtain all initial keywords in each initial sample text;

[0165] For each initial keyword in each initial sample text, determine whether the keyword type of the initial keyword matches at least one pre-set confirmation keyword type, and when the determination result is yes, determine the initial keyword as a text keyword that meets the confirmation condition;

[0166] Optionally, the confirmation keyword type may include an entity word type and / or a sentiment word type.

[0167] It can be seen that the implementation of this optional implementation mode can also extract entity words and sentiment words as confirmation keywords after the initial sample text is segmented, thereby improving the matching degree between the extracted confirmation keywords and the sentiment complexity.

[0168] 203. Determine a template text that matches each initial sample text according to the text keywords of the initial sample text.

[0169] As an optional implementation, determining the template text that matches each initial sample text according to the text keywords of the initial sample text may include:

[0170] Determine the emotional complexity corresponding to each initial sample text according to the text keywords of the initial sample text;

[0171] For each initial sample text, an original template text that matches the emotion complexity corresponding to the initial sample text among a plurality of preset original template texts is determined as a target template text corresponding to the initial sample text, wherein the original template text includes a first-category template text and / or a second-category template text, the information to be supplemented corresponding to the first-category template text is emotion degree information, and the information to be supplemented corresponding to the second-category template text is emotion description information;

[0172] According to the text keywords of each initial sample text, a keyword replacement operation is performed on other text contents in the target template text corresponding to the initial sample text except the information to be supplemented, so as to obtain a template text matching the initial sample text.

[0173] Specifically, when the emotional complexity corresponding to the initial sample text is low, the first type of template text can be used as its corresponding target template text, for example, {the food in this restaurant [MASK] is delicious}, and the information to be supplemented [MASK] is emotional degree information, such as "very", "no", etc.; when the emotional complexity corresponding to the initial sample text is high, the second type of template text can be used as its corresponding target template text, for example, {her feelings towards her hometown are [MASK]}, and the information to be supplemented [MASK] is emotional description information, such as "miss", "good", "bad", "bored", etc.

[0174] It can be seen that implementing this optional implementation method can determine the template text of the initial sample text according to the emotional complexity of the initial sample text, thereby improving the matching degree between the template text and the initial sample text, and by performing keyword replacement operations on the original template text, it can improve the generation efficiency of the template text and further improve the matching degree between the template text and the initial sample text.

[0175] 204. Insert a template text that matches each initial sample text at a preset position of the initial sample text to obtain a plurality of target sample texts for model training.

[0176] 205. Input each target sample text into the sentiment analysis model to be trained, so that the sentiment analysis model analyzes the text content of each target sample text to obtain a sentiment analysis result corresponding to each target sample text.

[0177] 206. According to the sentiment analysis results corresponding to all target sample texts and the sentiment labeling results corresponding to all initial sample texts, it is determined whether the sentiment analysis model meets the convergence condition.

[0178] 207. When the judgment result of step 206 is no, correct the model parameters of the sentiment analysis model, and re-execute step 205 and execute step 206.

[0179] 208. When the judgment result of step 206 is yes, the current process ends and a target sentiment analysis model that meets the convergence condition is obtained. The target sentiment analysis model is used to analyze the text sentiment of the text to be analyzed.

[0180] In the embodiment of the present invention, for other descriptions of step 201, step 204, step 205, step 206, step 207, and step 208, please refer to the detailed description of step 101 to step 106 in embodiment 1, and the embodiment of the present invention will not be repeated here.

[0181] It can be seen that the implementation of the embodiment of the present invention can insert template text into the initial sample text used for model training, so as to guide the sentiment analysis model to be trained to analyze the initial sample text and predict the sentiment represented by the unknown characters in the template text, that is, the sentiment analysis model is trained using the training method of template learning, which improves the matching degree between the model training method and the characteristics of the sentiment analysis model itself, reduces the situation where the characteristics of the model itself must be adjusted or abandoned during model training due to the mismatch between the downstream tasks of the model training and the characteristics of the model itself, improves the training effect and training efficiency of the sentiment analysis model, and thus improves the accuracy of text sentiment analysis. In addition, the template text of the initial sample text is determined according to the text keywords in the initial sample text, which improves the diversity of the inserted template text and the matching degree between the template text and the initial sample text, which is beneficial to improving the analysis accuracy of the sample text by the sentiment analysis model.

[0182] Embodiment 3

[0183] See also Figure 3 , Figure 3 : is a schematic diagram of a structure of a device for constructing a text sentiment analysis model disclosed in an embodiment of the present invention. Figure 3The described apparatus for constructing a text sentiment analysis model can be applied to the construction process of a sentiment analysis model based on any architecture, and the embodiments of the present invention are not limited thereto. Figure 3 As shown, the device for constructing the text sentiment analysis model may include:

[0184] A determination module 301 is used to determine a number of initial sample texts with annotation information;

[0185] Insertion module 302, used for inserting a template text matching the initial sample text into a preset position of each initial sample text to obtain a plurality of target sample texts for model training, wherein the template text includes a target character for representing an unknown emotion;

[0186] An input module 303 is used to input each target sample text into the sentiment analysis model to be trained, so that the sentiment analysis model analyzes the text content of each target sample text to obtain a sentiment analysis result corresponding to each target sample text, wherein the sentiment analysis result corresponding to each target sample text includes a prediction result of a target character in the target sample text, and the prediction result is a sentiment prediction result of the corresponding target sample text;

[0187] A judgment module 304 is used to judge whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all target sample texts and the sentiment labeling results corresponding to all initial sample texts;

[0188] The correction module 305 is used to correct the model parameters of the sentiment analysis model when the judgment module 304 judges that the sentiment analysis model does not meet the convergence conditions, and trigger the input module 303 to re-execute the above-mentioned operation of inputting each target sample text into the sentiment analysis model to be trained, so that the sentiment analysis model analyzes the text content of each target sample text to obtain the sentiment analysis result corresponding to each target sample text, and trigger the judgment module 304 to execute the above-mentioned operation of judging whether the sentiment analysis model meets the convergence conditions based on the sentiment analysis results corresponding to all target sample texts and the sentiment labeling results corresponding to all initial sample texts, until a target sentiment analysis model that meets the convergence conditions is obtained, and the target sentiment analysis model is used to analyze the text sentiment of the text to be analyzed.

[0189] It can be seen that implementation Figure 3The described device can insert template text into the initial sample text used for model training to guide the sentiment analysis model to be trained to analyze the initial sample text and predict the sentiment represented by unknown characters in the template text, that is, to train the sentiment analysis model using the training method of template learning, thereby improving the degree of matching between the model training method and the characteristics of the sentiment analysis model itself, reducing the situation in which the characteristics of the model itself must be adjusted or abandoned during model training due to the mismatch between the downstream tasks of the model training and the characteristics of the model itself, thereby improving the training effect and training efficiency of the sentiment analysis model, and thereby improving the accuracy of text sentiment analysis.

[0190] In an optional embodiment, if Figure 3 As shown, the specific method of judging module 304 judging whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all target sample texts and the sentiment annotation results corresponding to all initial sample texts may include:

[0191] For each target sample text, determining the matching degree between the sentiment analysis result corresponding to the target sample text and the sentiment annotation result corresponding to the corresponding initial sample text as the matching degree corresponding to the target sample text;

[0192] Calculate the analysis accuracy of the sentiment analysis model based on the matching degree of all target sample texts;

[0193] Determine whether the analysis accuracy is greater than or equal to a preset accuracy threshold;

[0194] When the judgment result is yes, it is determined that the sentiment analysis model meets the convergence condition, and when the judgment result is no, it is determined that the sentiment analysis model does not meet the convergence condition.

[0195] It can be seen that the implementation Figure 3 The described device can also calculate the analysis accuracy of the sentiment analysis model based on the matching degree between the sentiment analysis result corresponding to each target sample text and the sentiment annotation result corresponding to the corresponding initial sample text, thereby improving the accuracy and reliability of judging whether the sentiment analysis model meets the convergence conditions.

[0196] In another optional embodiment, Figure 3 As shown, the sentiment prediction result of each target sample text includes one or more sub-prediction results and probability information corresponding to each sub-prediction result;

[0197] Furthermore, the specific manner in which the judgment module 304 determines, for each target sample text, the degree of match between the sentiment analysis result corresponding to the target sample text and the sentiment annotation result corresponding to the corresponding initial sample text may include:

[0198] For each target sample text, a sub-prediction result whose corresponding probability information in the emotion prediction result of the target sample text satisfies a preset probability condition is determined as a target emotion prediction result of the target sample text;

[0199] For each target sample text, the matching degree between the target emotion prediction result of the target sample text and the emotion annotation result corresponding to the corresponding initial sample text is determined as the matching degree corresponding to the target sample text.

[0200] It can be seen that implementation Figure 3 The described device can also select a prediction result whose probability information meets a preset probability condition from multiple prediction results output by the sentiment analysis model as the final prediction result, thereby reducing the interference of unnecessary prediction results on the calculation and analysis accuracy, and improving the accuracy of the analysis accuracy of the sentiment analysis model, which is conducive to improving the training effect of the sentiment analysis model.

[0201] In yet another optional embodiment, Figure 3 As shown, the sentiment analysis model analyzes the text content of each target sample text, and the specific method of obtaining the sentiment analysis result corresponding to each target sample text may include:

[0202] The encoding structure corresponding to the sentiment analysis model performs an encoding operation on each target sample text to obtain an encoding result corresponding to each target sample text, wherein the encoding result corresponding to each target sample text includes a text vector corresponding to the target sample text, a position vector corresponding to the target sample text, and a sentence vector corresponding to the target sample text;

[0203] The vector processing structure corresponding to the sentiment analysis model analyzes the encoding result corresponding to each target sample text to obtain the sentiment analysis result corresponding to the target sample text;

[0204] The encoding structure corresponding to the sentiment analysis model performs an encoding operation on each target sample text, and a specific method of obtaining an encoding result corresponding to each target sample text may include:

[0205] The encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in each target sample text; or, the encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in the initial sample text of each target sample text and the semantic information corresponding to each text element except the target character in the template text of the target sample text, wherein the semantic information corresponding to each text element in the template text includes sub-semantic information corresponding to the text element in one or more part-of-speech dimensions corresponding to the text element;

[0206] The encoding structure generates a position vector corresponding to each target sample text and a sentence vector corresponding to the target sample text according to the position information corresponding to each text element in the target sample text, wherein the sentence vector corresponding to each target sample text is used to represent the sentence to which each text element in the target sample text belongs in the target sample text.

[0207] It can be seen that implementation Figure 3 The described device can also predict the sentiment of the sample text based on the text vector, position vector and sentence vector of the sample text, which is beneficial to improving the correlation between different words and different sentences in the same sample text during the model training process, thereby facilitating the sentiment analysis model to accurately analyze the overall semantics of the sample text and improve the training effect of the sentiment analysis model. In addition, by encoding mapping information to generate text vectors, the encoding efficiency can be improved, and by generating word embedding vectors through semantic information, the accuracy and uniformity of text encoding can be improved, the complexity of text vectors can be reduced, and the diversity of encoding methods of sentiment analysis models can be improved.

[0208] In yet another optional embodiment, Figure 3 As shown, the specific method of determining module 301 to determine a number of initial sample texts with annotation information may include:

[0209] Get some initial texts for model training;

[0210] For each initial text, according to at least one preset annotation mark, extract the text features corresponding to each annotation mark from the text to obtain the text content corresponding to each annotation mark;

[0211] According to preset splicing characters and / or splicing sequence, a splicing operation is performed on the text contents corresponding to all the annotation marks extracted from each initial text to obtain a plurality of initial sample texts with annotation information.

[0212] It can be seen that implementation Figure 3 The described device can, after extracting text contents corresponding to multiple annotation identifiers, splice the text contents corresponding to all annotation identifiers to obtain an initial sample text, so that the sentiment analysis model can uniformly process the text contents corresponding to all annotation identifiers, thereby improving the efficiency of the sentiment analysis model in processing sample texts, and can improve the correlation between text contents corresponding to different annotation identifiers of the same sample text during the model training process, which is conducive to the sentiment analysis model to accurately analyze the overall semantics of the sample text and improve the training effect of the sentiment analysis model.

[0213] In yet another optional embodiment, Figure 3As shown, the determination module 301 is further used to determine the text keywords that meet the preset confirmation conditions in each initial sample text, and determine the template text that matches the initial sample text according to the text keywords of each initial sample text;

[0214] The specific manner in which the determination module 301 determines the template text that matches each initial sample text according to the text keywords of the initial sample text may include:

[0215] Determine the emotional complexity corresponding to each initial sample text according to the text keywords of the initial sample text;

[0216] For each initial sample text, an original template text that matches the emotion complexity corresponding to the initial sample text among a plurality of preset original template texts is determined as a target template text corresponding to the initial sample text, wherein the original template text includes a first-category template text and / or a second-category template text, the information to be supplemented corresponding to the first-category template text is emotion degree information, and the information to be supplemented corresponding to the second-category template text is emotion description information;

[0217] According to the text keywords of each initial sample text, a keyword replacement operation is performed on other text contents in the target template text corresponding to the initial sample text except the information to be supplemented, so as to obtain a template text matching the initial sample text.

[0218] It can be seen that implementation Figure 3 The described device can also determine the template text of the initial sample text based on the text keywords in the initial sample text, thereby improving the diversity of the inserted template text and the matching degree between the template text and the initial sample text, which is beneficial to improving the analysis accuracy of the sentiment analysis model on the sample text, and by performing keyword replacement operations on the original template text, it can improve the generation efficiency of the template text and further improve the matching degree between the template text and the initial sample text.

[0219] In yet another optional embodiment, Figure 4 As shown, the judgment module 304 is further used to input each target sample text into the sentiment analysis model in the input module 303, so that the sentiment analysis model analyzes the text content of each target sample text, and before obtaining the sentiment analysis result corresponding to each target sample text, for each target sample text, determine whether the text length of the target sample text is greater than a preset length threshold;

[0220] And, the device may also include:

[0221] A preprocessing module 306 is used for performing a preprocessing operation on each target sample text to update the target sample text when the judging module 304 judges that the text length of the target sample text is greater than a preset length threshold;

[0222] The specific manner in which the preprocessing module 306 performs preprocessing operations on the target sample text includes:

[0223] According to the text element information corresponding to each text structure in the target sample text, at least one target text structure satisfying the preprocessing condition is determined from all the text structures of the target sample text, wherein the text elements contained in each target text structure include at least one essential element and at least one non-essential element;

[0224] For each non-essential element of each target text structure of the target sample text, determine whether the influence of the non-essential element on the text information of the target text structure is less than a preset influence degree; when it is determined that the influence of the non-essential element on the text information of the target text structure is less than the preset influence degree, remove the non-essential element, wherein the text information includes text semantics and / or text sentiment.

[0225] It can be seen that implementation Figure 4 The described device can remove non-essential elements when the text length of the sample text is long and the impact of the non-essential elements on the text information is low, thereby reducing the occurrence of necessary elements being lost due to non-essential elements occupying too much space, which is beneficial to improving the accuracy of the sentiment analysis model on the sentiment analysis of the sample text, and can also improve the efficiency of the sentiment analysis model in analyzing the sentiment of the sample text.

[0226] Embodiment 4

[0227] See also Figure 5 , Figure 5 FIG. 1 is a schematic diagram of a structure of another device for constructing a text sentiment analysis model disclosed in an embodiment of the present invention. Figure 5 As shown, the device for constructing the text sentiment analysis model may include:

[0228] A memory 401 storing executable program codes;

[0229] a processor 402 coupled to the memory 401;

[0230] The processor 402 calls the executable program code stored in the memory 401 to execute the steps in the method for constructing a text sentiment analysis model described in the first embodiment of the present invention or the second embodiment of the present invention.

[0231] Embodiment 5

[0232] An embodiment of the present invention discloses a computer storage medium, which stores computer instructions. When the computer instructions are called, they are used to execute the steps in the method for constructing a text sentiment analysis model described in Embodiment 1 or Embodiment 2 of the present invention.

[0233] Embodiment 6

[0234] An embodiment of the present invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute the steps in the method for constructing a text sentiment analysis model described in Example 1 or Example 2.

[0235] The device embodiments described above are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.

[0236] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution can be essentially or partly contributed to the prior art in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.

[0237] Finally, it should be noted that the method and device for constructing a text sentiment analysis model disclosed in the embodiment of the present invention disclose only the preferred embodiments of the present invention, which are only used to illustrate the technical scheme of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical schemes described in the aforementioned embodiments can still be modified, or some of the technical features therein can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical schemes from the spirit and scope of the technical schemes of the embodiments of the present invention.

Claims

1. A method for constructing a text sentiment analysis model. It is characterized in that The method comprises: Determine a number of initial sample texts with annotation information; Inserting a template text matching the initial sample text at a preset position of each of the initial sample texts to obtain a plurality of target sample texts for model training, wherein the template text includes a target character for representing an unknown emotion; Input each of the target sample texts into the sentiment analysis model to be trained, so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain a sentiment analysis result corresponding to each of the target sample texts, wherein the sentiment analysis result corresponding to each of the target sample texts includes a prediction result of a target character in the target sample text, and the prediction result is a sentiment prediction result of the corresponding target sample text; According to the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts, judging whether the sentiment analysis model meets the convergence condition; When the judgment result is no, the model parameters of the sentiment analysis model are corrected, and the operation of inputting each of the target sample texts into the sentiment analysis model to be trained is re-executed so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain the sentiment analysis result corresponding to each of the target sample texts, and the operation of judging whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts is performed, until a target sentiment analysis model that meets the convergence condition is obtained, and the target sentiment analysis model is used to analyze the text sentiment of the text to be analyzed; Wherein, the method further comprises: Determine the text keywords that meet the preset confirmation conditions in each of the initial sample texts, and determine the emotion complexity corresponding to the initial sample text according to the text keywords of each of the initial sample texts; For each of the initial sample texts, an original template text that matches the emotion complexity corresponding to the initial sample text among a plurality of preset original template texts is determined as a target template text corresponding to the initial sample text, wherein the original template text includes a first-category template text and / or a second-category template text, the information to be supplemented corresponding to the first-category template text is emotion degree information, and the information to be supplemented corresponding to the second-category template text is emotion description information; According to the text keywords of each of the initial sample texts, a keyword replacement operation is performed on other text contents in the target template text corresponding to the initial sample text except the information to be supplemented, so as to obtain a template text matching the initial sample text.

2. The method for constructing a text sentiment analysis model according to claim 1, It is characterized in that The step of judging whether the sentiment analysis model satisfies a convergence condition according to sentiment analysis results corresponding to all the target sample texts and sentiment annotation results corresponding to all the initial sample texts includes: For each of the target sample texts, determining a matching degree between a sentiment analysis result corresponding to the target sample text and a sentiment annotation result corresponding to the corresponding initial sample text as a matching degree corresponding to the target sample text; Calculating the analysis accuracy of the sentiment analysis model according to the matching degrees corresponding to all the target sample texts; Determining whether the analysis accuracy is greater than or equal to a preset accuracy threshold; When the judgment result is yes, it is determined that the sentiment analysis model meets the convergence condition, and when the judgment result is no, it is determined that the sentiment analysis model does not meet the convergence condition.

3. The method for constructing a text sentiment analysis model according to claim 2, It is characterized in that The sentiment prediction result of each target sample text includes one or more sub-prediction results and probability information corresponding to each sub-prediction result; And, for each of the target sample texts, determining the matching degree between the sentiment analysis result corresponding to the target sample text and the sentiment annotation result corresponding to the corresponding initial sample text comprises: For each of the target sample texts, determining a sub-prediction result whose corresponding probability information in the emotion prediction result of the target sample text satisfies a preset probability condition as a target emotion prediction result of the target sample text; For each of the target sample texts, a matching degree between a target emotion prediction result of the target sample text and an emotion annotation result corresponding to a corresponding initial sample text is determined as the matching degree corresponding to the target sample text.

4. A method for constructing a text sentiment analysis model according to any one of claims 1 to 3, It is characterized in that The sentiment analysis model analyzes the text content of each target sample text to obtain a sentiment analysis result corresponding to each target sample text, including: The encoding structure corresponding to the sentiment analysis model performs an encoding operation on each of the target sample texts to obtain an encoding result corresponding to each of the target sample texts, wherein the encoding result corresponding to each of the target sample texts includes a text vector corresponding to the target sample text, a position vector corresponding to the target sample text, and a sentence vector corresponding to the target sample text; The vector processing structure corresponding to the sentiment analysis model analyzes the encoding result corresponding to each target sample text to obtain the sentiment analysis result corresponding to the target sample text; The encoding structure corresponding to the sentiment analysis model performs an encoding operation on each of the target sample texts to obtain an encoding result corresponding to each of the target sample texts, including: The encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in each target sample text; or, the encoding structure corresponding to the sentiment analysis model generates a text vector corresponding to the target sample text according to the mapping encoding information corresponding to each text element in the initial sample text of each target sample text and the semantic information corresponding to each text element except the target character in the template text of the target sample text, wherein the semantic information corresponding to each text element in the template text includes sub-semantic information corresponding to the text element in one or more part-of-speech dimensions corresponding to the text element; The encoding structure generates a position vector corresponding to the target sample text and a sentence vector corresponding to the target sample text according to the position information corresponding to each text element in each target sample text in the target sample text, wherein the sentence vector corresponding to each target sample text is used to represent the sentence to which each text element in the target sample text belongs in the target sample text.

5. A method for constructing a text sentiment analysis model according to any one of claims 1 to 3, It is characterized in that The step of determining a plurality of initial sample texts with annotation information includes: Get some initial texts for model training; For each of the initial texts, according to at least one preset annotation mark, a text feature corresponding to each annotation mark is extracted from the text to obtain the text content corresponding to each annotation mark; According to preset splicing characters and / or splicing sequence, a splicing operation is performed on the text contents corresponding to all the annotation marks extracted from each of the initial texts to obtain a plurality of initial sample texts with annotation information.

6. A method for constructing a text sentiment analysis model according to any one of claims 1 to 3, It is characterized in that Before inputting each of the target sample texts into the sentiment analysis model so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain a sentiment analysis result corresponding to each of the target sample texts, the method further includes: For each of the target sample texts, determining whether the text length of the target sample text is greater than a preset length threshold, and if so, performing a preprocessing operation on the target sample text to update the target sample text; The preprocessing operation on the target sample text includes: According to the text element information corresponding to each text structure in the target sample text, at least one target text structure satisfying the preprocessing condition is determined from all the text structures of the target sample text, wherein the text elements contained in each of the target text structures include at least one essential element and at least one non-essential element; For each non-essential element of each target text structure of the target sample text, determine whether the influence of the non-essential element on the text information of the target text structure is less than a preset influence degree; when it is determined that the influence of the non-essential element on the text information of the target text structure is less than the preset influence degree, remove the non-essential element, wherein the text information includes text semantics and / or text sentiment.

7. A device for constructing a text sentiment analysis model, It is characterized in that The device is used to execute the method for constructing a text sentiment analysis model according to any one of claims 1 to 6, and the device comprises: A determination module, used for determining a number of initial sample texts with annotation information; An inserting module, used for inserting a template text matching the initial sample text at a preset position of each of the initial sample texts, to obtain a plurality of target sample texts for model training, wherein the template texts include target characters for referring to unknown emotions; An input module, used for inputting each of the target sample texts into the sentiment analysis model to be trained, so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain a sentiment analysis result corresponding to each of the target sample texts, wherein the sentiment analysis result corresponding to each of the target sample texts includes a prediction result of a target character in the target sample text, and the prediction result is a sentiment prediction result of the corresponding target sample text; A judgment module, used to judge whether the sentiment analysis model meets the convergence condition according to the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts; A correction module is used to correct the model parameters of the sentiment analysis model when the judgment module determines that the sentiment analysis model does not meet the convergence condition, and trigger the input module to re-execute the operation of inputting each of the target sample texts into the sentiment analysis model to be trained so that the sentiment analysis model analyzes the text content of each of the target sample texts to obtain the sentiment analysis result corresponding to each of the target sample texts, and trigger the judgment module to execute the operation of judging whether the sentiment analysis model meets the convergence condition based on the sentiment analysis results corresponding to all the target sample texts and the sentiment annotation results corresponding to all the initial sample texts, until a target sentiment analysis model that meets the convergence condition is obtained, and the target sentiment analysis model is used to analyze the text sentiment of the text to be analyzed.

8. A device for constructing a text sentiment analysis model, It is characterized in that The device comprises: A memory storing executable program code; a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the method for constructing a text sentiment analysis model as described in any one of claims 1-6.

9. A computer storage medium, It is characterized in that The computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the method for constructing a text sentiment analysis model as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Method and system for communicating across channels simultaneously with emotion preservation

    CN101030368A

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

    CN110705300A