Emotion triple extraction method and device
By combining semantic features and Chinese word segmentation features in the extraction model, the problem of low accuracy in extracting Chinese sentiment triples is solved, achieving more efficient Chinese sentiment triple extraction and improving the accuracy of sentiment analysis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TSINGHUA UNIVERSITY
- Filing Date
- 2022-06-30
- Publication Date
- 2026-06-23
AI Technical Summary
Existing sentiment triplet extraction models do not perform well in Chinese text sentiment analysis scenarios and fail to effectively consider the linguistic features of Chinese.
An extraction model based on fragmented text samples and Chinese word segmentation features is adopted. By combining semantic features and Chinese word segmentation features, the extraction model can better understand the structural information of Chinese text and improve the accuracy of sentiment triple extraction.
It improves the accuracy of sentiment triple extraction from Chinese text, enabling the extraction of suitable sentiment triples in specific application scenarios and enhancing the accuracy of the sentiment analysis model.
Smart Images

Figure CN115017881B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for extracting emotion triples. Background Technology
[0002] The sentiment triad can better characterize the sentiment polarity of opinion expression under different semantic environments or different evaluation objects, thus better assisting the sentiment analysis model to obtain more comprehensive and accurate sentiment analysis results.
[0003] Current research on sentiment triplet extraction models is still limited to English datasets and does not take into account the linguistic features of Chinese in the design of text features. Therefore, the performance of existing sentiment triplet extraction models is not ideal in Chinese text sentiment analysis scenarios. Summary of the Invention
[0004] This invention provides a method and apparatus for extracting sentiment triples, which addresses the shortcomings of low accuracy in extracting Chinese sentiment triples in the prior art and improves the accuracy of Chinese sentiment triple extraction.
[0005] In a first aspect, the present invention provides a method for extracting emotion triples, comprising:
[0006] Obtain the text to be evaluated;
[0007] The text to be evaluated is input into the extraction model to obtain the sentiment triples output by the extraction model;
[0008] The extraction model is trained based on fragment text samples, text combinations composed of the fragment text samples, and sentiment tags corresponding to the text combinations. The sentiment tags are predetermined based on the text combinations.
[0009] The extraction model is used to extract sentiment triples from the text to be evaluated based on the semantic features and Chinese word segmentation features of the text to be evaluated.
[0010] Optionally, the step of inputting the text to be evaluated into the extraction model to obtain the sentiment triples output by the extraction model includes:
[0011] The text to be evaluated is segmented to obtain all text segments in the text to be evaluated;
[0012] Semantic feature extraction and structural information extraction are performed on each of the text segments to obtain the text segment feature representation corresponding to each text segment;
[0013] For each text segment feature representation, segment classification is performed to obtain segment classification results, which include evaluation object features, opinion expression features, or non-emotional triplet element features;
[0014] Based on the characteristics of the evaluation object, the characteristics of the viewpoint expression, and the text to be evaluated, the context features are determined;
[0015] Based on the characteristics of the evaluation object, the characteristics of the viewpoint expression, and the context features, a combined feature representation of the text fragments is determined;
[0016] The combined feature representations of the text fragments are classified into types and sentiment polarities to obtain type classification results and sentiment polarity classification results;
[0017] Based on the type classification results and the sentiment polarity classification results, sentiment triples are obtained.
[0018] Optionally, the step of extracting semantic features and structural information for each text segment to obtain a text segment feature representation corresponding to each text segment includes:
[0019] The text to be evaluated is text-encoded to obtain the character-level semantic representation of each character in the text to be evaluated.
[0020] The text to be evaluated is segmented into Chinese words to obtain the segmentation results;
[0021] Based on the character-level semantic representation, obtain the segment semantic representation corresponding to each text segment;
[0022] Each text segment is compared with the word segmentation result to determine the number of words contained in each text segment;
[0023] Based on the semantic representation of each text segment and the number of words segmented for each text segment, the text segment feature representation of each text segment is determined.
[0024] Optionally, obtaining the segment semantic representation corresponding to each text segment based on the character-level semantic representation includes:
[0025] Aggregate the character-level semantic representations corresponding to each text segment to obtain the segment semantic representation corresponding to each text segment.
[0026] Optionally, determining the text segment feature representation of each text segment based on the segment semantic representation corresponding to each text segment and the number of word segments corresponding to each text segment includes:
[0027] The semantic representation of each text segment and the number of words segmented for each text segment are concatenated to obtain the text segment feature representation of each text segment.
[0028] Optionally, determining the context features based on the characteristics of the evaluation object, the characteristics of the opinion expression, and the text to be evaluated includes:
[0029] Obtain the text segment between the evaluation object text and the opinion expression text, wherein the evaluation object text is the text segment corresponding to the evaluation object feature, and the opinion expression text is the text segment corresponding to the opinion expression feature;
[0030] Semantic features are extracted from the spaced text segments to obtain the contextual features.
[0031] Optionally, the optimization objective of the extraction model during training is to minimize the value of the loss function;
[0032] The loss function is the sum of the cross-entropy loss for fragment classification, the cross-entropy loss for type classification, the cross-entropy loss for sentiment polarity classification, and the L2 regularization loss of the extraction model.
[0033] Secondly, the present invention also provides an emotion triplet extraction device, comprising:
[0034] The acquisition unit is used to acquire the text to be evaluated.
[0035] An extraction unit is used to input the text to be evaluated into an extraction model and obtain the sentiment triples output by the extraction model.
[0036] The extraction model is trained based on fragment text samples, text combinations composed of the fragment text samples, and sentiment tags corresponding to the text combinations. The sentiment tags are predetermined based on the text combinations.
[0037] The extraction model is used to extract sentiment triples from the text to be evaluated based on the semantic features and Chinese word segmentation features of the text to be evaluated.
[0038] Thirdly, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the emotion triple extraction method as described in the first aspect.
[0039] Fourthly, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the sentiment triple extraction method described in the first aspect.
[0040] The sentiment triple extraction method and apparatus provided by this invention extract sentiment triples through an extraction model. This model combines the semantic features of the text to be evaluated with Chinese word segmentation features. Due to the differences between Chinese and English text expression (e.g., Chinese words do not have spaces, while English is expressed in words separated by spaces), machine understanding of Chinese is more difficult than that of English. In this embodiment, the extraction model encodes the Chinese word segmentation features of the text to be evaluated to represent its structural information, improving the model's perception and processing capabilities of Chinese word segmentation features and increasing the accuracy of sentiment triple extraction from Chinese text. Furthermore, after training, the extraction model in this embodiment can extract sentiment triples that conform to specific application scenarios, improving the application accuracy of sentiment triples. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0042] Figure 1 This is one of the flowcharts illustrating the emotion triple extraction method provided in this embodiment of the invention;
[0043] Figure 2 This is a schematic diagram of the structure of the text fragment classification module provided in an embodiment of the present invention;
[0044] Figure 3 This is a schematic diagram of the structure of the text fragment combination and classification module provided in an embodiment of the present invention;
[0045] Figure 4 This is a schematic diagram of the process for obtaining text fragment feature representations provided in an embodiment of the present invention;
[0046] Figure 5 This is a schematic diagram of the process for obtaining the combined feature representation of text fragments provided in an embodiment of the present invention;
[0047] Figure 6 This is the second flowchart of the emotion ternary extraction method provided in the embodiment of the present invention;
[0048] Figure 7 This is a schematic diagram of the structure of the emotion triplet extraction device provided in an embodiment of the present invention;
[0049] Figure 8 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0050] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0051] With the development and popularization of internet technology, the internet has become an important platform for netizens to obtain information, express emotions, and share and communicate. With the participation of numerous internet users, the massive amount of online comment text contains a vast and rich amount of emotions and opinions. However, these emotions and opinions typically exist in various unstructured forms within natural language texts from different sources and fields, making comprehensive identification, acquisition, and statistical analysis difficult, and even more challenging to meet the training data requirements of existing sentiment analysis models. The sentiment knowledge base, located at the lower layer of the sentiment knowledge graph, corresponds to the data layer in the general knowledge graph structure. Its content mainly includes the evaluation object, opinion expression, and sentiment relationship in natural language comment texts, stored in the form of sentiment knowledge triples: "evaluation object, opinion expression, sentiment polarity." Compared to the traditional sentiment dictionary's binary form of "opinion expression, sentiment polarity" or "opinion expression, sentiment score," sentiment triples can better represent the sentiment polarity of opinion expression under different semantic environments or different evaluation objects, thus better assisting sentiment analysis models in obtaining more comprehensive and accurate sentiment analysis results.
[0052] In the current field of sentiment analysis research, sentiment triple extraction aims to extract the sentiment polarity between evaluation objects, opinion expressions, and their collocations in natural language text. Currently, sentiment triple extraction is mainly divided into two methods: pipelined and end-to-end. The classic model of the pipelined method is the pipeline model, while the end-to-end method is mainly divided into sequence labeling-based methods and sequence generation-based methods, depending on the implementation method. While sentiment triple extraction research has made considerable progress, due to the relatively short research history in this field, existing sentiment triple extraction models are still limited to English datasets and have not considered the linguistic features of Chinese in their text feature design. Therefore, in Chinese text sentiment analysis scenarios, the performance of existing sentiment triple extraction models is not ideal.
[0053] To address the aforementioned issues, this invention proposes an emotion triple extraction method that combines semantic features and Chinese word segmentation features. Chinese word segmentation features characterize the structural information of text fragments, enhancing the emotion triple extraction model's ability to perceive and process Chinese word segmentation features. Furthermore, based on this, a method for constructing a smart city emotion knowledge base is designed. Under the knowledge constraints of a smart city domain knowledge ontology, emotion knowledge triples are obtained through the emotion triple extraction method proposed in this invention, thereby constructing a smart city emotion expression knowledge base.
[0054] The following is combined with Figure 1 - Figure 5 This invention describes the emotion triple extraction method provided in the embodiments of the present invention.
[0055] Figure 1 This is one of the flowcharts illustrating the emotion triple extraction method provided in this embodiment of the invention, such as... Figure 1 As shown, the emotion triple extraction method provided in this embodiment of the invention includes:
[0056] Step 110: Obtain the text to be evaluated;
[0057] The text to be evaluated refers to text that contains emotional expression. For example, the text to be evaluated can be a review posted by a user on a shopping platform, social content posted on a social platform, or an article posted on a sharing platform.
[0058] Step 120: Input the text to be evaluated into the extraction model to obtain the sentiment triplet output by the extraction model;
[0059] The extraction model is trained based on fragment text samples, text combinations composed of the fragment text samples, and sentiment tags corresponding to the text combinations. The sentiment tags are predetermined based on the text combinations.
[0060] The extraction model is used to extract sentiment triples from the text to be evaluated based on the semantic features and Chinese word segmentation features of the text to be evaluated.
[0061] Specifically, the extraction model can be the TSSpan (Text-Segmentation Span-Based Model), a sentiment triple extraction model based on Chinese word segmentation features. The extraction model can combine the semantic features of the text to be evaluated and the Chinese word segmentation features to extract sentiment triples. The semantic features represent the textual meaning information of the text to be evaluated, and the Chinese word segmentation features represent the structural information of the text to be evaluated.
[0062] A text fragment sample refers to a text fragment consisting of at least one word. A text fragment sample may include text samples of evaluation objects, text samples of opinion expressions, and text samples of non-sentimental triple elements. A text combination may consist of at least one text sample of an evaluation object and at least one text sample of an opinion expression. Sentiment tags are used to distinguish the sentiment polarity corresponding to the text combination sample. Sentiment tags may include positive sentiment, neutral sentiment, and negative sentiment.
[0063] For example, in a training scenario where an extraction model is used to extract user reviews from a shopping platform, the text samples of the evaluation objects may include "quality" and "personality"; the text samples of opinion expression may include "good"; the text samples of non-sentiment triple elements may include "very"; the text combination consisting of "quality" and "good" is a positive sample, and the corresponding sentiment label can be positive sentiment; the text combination consisting of "personality" and "good" is a negative sample because it does not conform to the application scenario.
[0064] The sentiment triple extraction method provided in this invention extracts sentiment triples through an extraction model. This model combines the semantic features of the text to be evaluated with Chinese word segmentation features. Due to the differences between Chinese and English text expression (e.g., Chinese words do not have spaces, while English is expressed in words separated by spaces), machine understanding of Chinese is more difficult than that of English. In this invention, the extraction model encodes the Chinese word segmentation features of the text to be evaluated to represent its structural information, improving the model's perception and processing capabilities of Chinese word segmentation features and increasing the accuracy of sentiment triple extraction from Chinese text. Furthermore, after training, the extraction model in this invention can extract sentiment triples that conform to specific application scenarios, improving the application accuracy of sentiment triples.
[0065] The following is a further explanation of the possible implementation methods of the above steps in specific embodiments.
[0066] Optionally, step 120, which involves inputting the text to be evaluated into the extraction model to obtain the sentiment triples output by the extraction model, includes:
[0067] Step 121: Perform segmentation on the text to be evaluated to obtain all text segments in the text to be evaluated;
[0068] Exemplarily, for segmenting the text to be evaluated, a character can be selected as the first character in the text to be evaluated, and a character can be selected as the last character, and the field between the first character and the last character is used as the text segment. Obtaining all the text segments in the text to be evaluated means obtaining all the possible text segments that may appear in the text to be evaluated through all possible segmentation methods. In one embodiment, "the logistics speed is fast" can be segmented into "物", "流", "速", "度", "快", "物流", "流速", "速度", "度快", "物流速", "流速度", "速度快", "物流速度", "流速度快", and "物流速度快", a total of 16 text segments.
[0069] Optionally, in order to reduce the training cost of the model, the extraction module can limit the maximum length of the text segment (i.e., the maximum number of Chinese characters included in the text segment).
[0070] Step 122: Extract semantic features and structural information for each of the text segments, and obtain a text segment feature representation corresponding to each of the text segments;
[0071] The structural information refers to the segmentation information such as the dynamic role relationship or attributes between the various components of a Chinese word. The extraction of structural information can be achieved through syntactic analysis or Chinese word segmentation, etc.
[0072] Exemplarily, extract semantic features for each text segment to obtain the semantic features of the text segment, extract structural information for each text segment to obtain the Chinese word segmentation features of the text segment, and obtain a text segment feature representation corresponding to each of the text segments based on the semantic features and the Chinese word segmentation features.
[0073] Step 123: Classify each of the text segment feature representations to obtain a segment classification result, where the segment classification result includes evaluation object features, opinion expression features, or non-emotional triple element features;
[0074] Exemplarily, the text segment feature representation can be input into the text segment classification module to obtain the segment classification result output by the text segment classification module. Figure 2 is the structural schematic diagram of the text segment classification module provided by the embodiment of the present invention. As Figure 2 shown, S i represents the text segment feature representation, u i represents the semantic feature of the text segment, and v i represents the structural information (Chinese word segmentation feature) of the text segment; This represents the fragment classification result; the text fragment classification module includes a fully connected layer, which consists of an input layer, at least one hidden layer, and an output layer. In the text fragment classification module, the extraction model feeds the text fragment feature representation into the fully connected layer to determine the type of the fragment (evaluation object, opinion expression, or non-sentiment triple element).
[0075] Step 124: Determine contextual features based on the characteristics of the evaluation object, the characteristics of the viewpoint expression, and the text to be evaluated;
[0076] Evaluation object features refer to the feature representation of text fragments whose text fragment type is evaluation object; opinion expression features refer to the feature representation of text fragments whose text fragment type is opinion expression; non-sentiment triple element features refer to the feature representation of text fragments whose text fragment type is non-sentiment triple element.
[0077] For example, relational texts that reflect the relationship between the characteristics of the evaluation object and the characteristics of the viewpoint expression can be determined in the text to be evaluated, and contextual features can be determined based on the relational texts.
[0078] Step 125: Based on the evaluation object features, the opinion expression features, and the context features, determine the text fragment combination feature representation;
[0079] Optionally, the evaluation object features, the opinion expression features, and the context features can be added, spliced, combined, or fused to obtain a combined feature representation of the text fragment.
[0080] For example, by using steps 121-123 for "fast logistics speed", we can obtain the text set of "evaluation object": "logistics", "flow rate", "speed"; and the text set of "opinion expression": "fast". Using "logistics" as the evaluation object, we can obtain text fragment combination 1 "fast logistics". Similarly, we can also obtain text fragment combination 2 "fast flow rate" and text fragment combination 3 "fast speed".
[0081] Step 126: Perform type classification and sentiment polarity classification on the combined feature representation of the text fragments to obtain type classification results and sentiment polarity classification results;
[0082] For example, the combined feature representation of text fragments can be input into the text fragment combination classification module to obtain the fragment classification result output by the text fragment combination classification module. Figure 3 This is a structural diagram of the text fragment combination and classification module provided in an embodiment of the present invention, as shown below. Figure 3 As shown, p i This represents the feature representation of combined text fragments; Indicates the type classification result; This represents the sentiment polarity classification result. The text fragment combination classification module consists of two fully connected layers, each including an input layer, at least one hidden layer, and an output layer. In the text fragment combination classification module, the extraction model feeds the text fragment combination feature representation into the two fully connected layers to determine the type and sentiment polarity of the text fragment combination. The type classification result can include evaluative and non-evaluative combinations, and the sentiment polarity classification result can include positive sentiment, neutral sentiment, and negative sentiment.
[0083] For example, in the application scenario of extracting user shopping sentiment triplets, classifying text fragment combination 1 "fast logistics" determines the type classification result as an evaluative pairing and the sentiment polarity classification result as positive sentiment; classifying text fragment combination 2 "fast flow" determines the type classification result as a non-evaluative pairing and the sentiment polarity classification result as positive sentiment; classifying text fragment combination 3 "fast speed" determines the type classification result as a non-evaluative pairing and the sentiment polarity classification result as positive sentiment. It should be understood that text fragment combinations 2 and 3 do not conform to the application scenario and are therefore classified as non-evaluative pairings. In the case of non-evaluative text fragment combinations, sentiment polarity classification can be omitted. However, it should be understood that continuing sentiment polarity classification is chosen to avoid affecting the processing speed of the extraction model.
[0084] Step 127: Based on the type classification results and the sentiment polarity classification results, obtain the sentiment triplet.
[0085] Specifically, the text fragment combinations whose type classification results are evaluation pairings and their corresponding sentiment polarity classification results can be extracted to obtain sentiment triples.
[0086] The sentiment triple extraction method provided in this invention obtains all possible text segments in the text to be evaluated and acquires text segment feature representations that can represent the semantic and structural information of the text segments. Then, it classifies all text segment feature representations to obtain evaluation objects, opinion expressions, or non-sentiment triple elements. By combining evaluation objects and opinion expressions, it extracts both from the text to be evaluated, facilitating the extraction model's understanding of Chinese text. Furthermore, this invention adds contextual features to the combined text segment feature representations. Contextual features can express the relationship between evaluation objects and opinion expressions, thereby enriching the content of the combined text segment feature representations. This allows the extraction model to obtain more information through the combined text segment feature representations, more accurately understand Chinese text, and improve the accuracy of the extraction model in classifying the types of combined text segment feature representations and the accuracy in classifying sentiment polarity, thus improving the accuracy of sentiment triple extraction.
[0087] Optionally, Figure 4This is a schematic diagram of the process for obtaining text fragment feature representations provided in an embodiment of the present invention, such as... Figure 4 As shown, step 122, which involves extracting semantic features and structural information for each text segment to obtain a text segment feature representation corresponding to each text segment, includes:
[0088] Step 1221: Perform text encoding on the text to be evaluated to obtain the character-level semantic representation corresponding to each character in the text to be evaluated;
[0089] Optionally, the extraction model can use BERT as an encoder to learn semantic representations of words. BERT is a pre-trained language model based on Transformer networks, widely used in various natural language processing tasks due to its excellent context modeling capabilities.
[0090] In one embodiment, the text to be evaluated is "Traffic aspects still need improvement," which is input into the bert-base-chinese module to obtain each character output by the bert-base-chinese module. i The corresponding character-level semantic representation h i .
[0091] Step 1222: Perform Chinese word segmentation on the text to be evaluated to obtain the segmentation results;
[0092] Specifically, Chinese word segmentation refers to dividing a sequence of Chinese characters into individual words. Word segmentation is the process of recombinizing a continuous sequence of characters into a sequence of words according to certain rules. Word segmentation methods can include: string matching-based segmentation methods, understanding-based segmentation methods, and statistical segmentation methods, etc.
[0093] Optionally, the text to be evaluated can be input into LTP to obtain the word segmentation results output by LTP.
[0094] In one embodiment, the text to be evaluated, “Traffic aspects still need improvement”, is input into the LTP module to obtain the word segmentation results “traffic”, “aspects”, “still”, “need to” and “improve” output by the LTP module.
[0095] Step 1223: Based on the character-level semantic representation, obtain the segment semantic representation corresponding to each text segment;
[0096] For example, character-level semantic representations can be concatenated, added, pooled, or merged to obtain corresponding segment semantic representations.
[0097] Optionally, obtaining the segment semantic representation corresponding to each text segment based on the character-level semantic representation includes:
[0098] Aggregate the character-level semantic representations corresponding to each of the text segments to obtain the segment semantic representation corresponding to each of the text segments.
[0099] Specifically, aggregate the Chinese character word embedding vector representations in the text segment through a max pooling operation, so as to obtain a vector containing the semantics of the text segment.
[0100] Step 1224: Compare each of the text segments with the word segmentation result to determine the number of word segments included in each of the text segments.
[0101] Specifically, compare the text segment with the Chinese word segmentation result of the evaluation text to determine the number of Chinese word segments included in this text segment (if the text segment does not conform to Chinese word segmentation, set the number of Chinese word segments included in the text segment to 0). Exemplarily, after comparing the text segment "in terms of transportation" with the word segmentation result, it can be determined that the word segments "transportation" and "aspect" are included, that is, the number of word segments is 2.
[0102] Step 1225: Determine the text segment feature representation of each of the text segments based on the segment semantic representation corresponding to each of the text segments and the number of word segments corresponding to each of the text segments.
[0103] Specifically, map the number of Chinese word segments included in the text segment into a vector containing the text segment structure information, and an embedding matrix can be used for mapping. The embedding matrix represents the embedding dimension of the number of Chinese word segments. Combining the semantic features and structure information of the text segment, the overall feature representation of this segment is finally obtained.
[0104] Optionally, the determining the text segment feature representation of each of the text segments based on the segment semantic representation corresponding to each of the text segments and the number of word segments corresponding to each of the text segments includes:
[0105] Concatenate the segment semantic representation corresponding to each of the text segments and the number of word segments corresponding to each of the text segments to obtain the text segment feature representation of each of the text segments.
[0106] It should be understood that the embedding matrix is used to represent the number of word segments, and the embedding matrix and the segment semantic representation have at least one dimension with the same dimension. Concatenation refers to vector concatenation (concatenate), and the mathematical expression is: embedding matrix v i and segment semantic representation u i , concatenate them at the same order to obtain the text segment feature representation S i =[u i ,v i .
[0107] Take a simple example with the simplified embedding matrix v and segment semantic representation u:
[0108]
[0109]
[0110]
[0111] Where v represents the embedding matrix, u represents the semantic representation of the fragment, con represents the concatenation function, and S represents the feature representation of the text fragment.
[0112] Steps 1221 and 1222 above can be executed simultaneously or separately. When executed separately, the order of execution is not limited here.
[0113] The sentiment triple extraction method provided in this invention combines semantic features representing the semantic information of a text fragment with Chinese word segmentation features representing the structural information of the text fragment to obtain a feature representation of the text fragment. This improves the extraction model's ability to perceive and process Chinese text and increases the accuracy of sentiment triple extraction from Chinese text.
[0114] Optionally, Figure 5 This is a schematic diagram of the process for obtaining text fragment combination feature representation provided in an embodiment of the present invention, such as... Figure 5 As shown, step 124, determining the context features based on the characteristics of the evaluation object, the characteristics of the viewpoint expression, and the text to be evaluated, includes:
[0115] Step 1241: Obtain the interval text segment between the evaluation object text and the opinion expression text, wherein the evaluation object text is the text segment corresponding to the evaluation object feature, and the opinion expression text is the text segment corresponding to the opinion expression feature;
[0116] Specifically, the extraction model uses the text fragments between the evaluation object and the opinion expression as the context for the combination of text fragments, which may involve three possible scenarios:
[0117] a. When the object of evaluation comes first, and there is a textual gap between the object of evaluation and the expression of opinion;
[0118] b. When the object of evaluation is listed later, and there is a textual gap between the object of evaluation and the expression of opinion;
[0119] c. When there is no textual gap between the object of evaluation and the expression of opinion.
[0120] Step 1242: Extract semantic features from the spaced text fragments to obtain the context features.
[0121] Specifically, the word-level semantic representations (word vector representations) corresponding to the spaced text segments are subjected to max pooling to aggregate the context features. It should be understood that if there are no text gaps, context features may not be required.
[0122] Optionally, the features of the evaluation object, context features, and opinion expression features can be concatenated into a combined feature representation of the text fragment.
[0123] It should be understood that the embodiments of the present invention do not limit the splicing order of evaluation object features, context features, and opinion expression features, as long as the splicing order remains consistent during the training and application processes.
[0124] The sentiment triple extraction method provided in this invention obtains contextual features by arranging text at intervals. These contextual features are used to supplement information such as the relationship, attributes, and syntax between the evaluation object and the opinion expression, thereby improving the information richness of the text fragment combination feature representation, enhancing the extraction model's perception and processing capabilities for Chinese text, improving the classification accuracy of the extraction model for text fragment combination feature representation, and thus improving the accuracy of sentiment triple extraction from Chinese text.
[0125] Optionally, the optimization objective of the extraction model during training is to minimize the value of the loss function;
[0126] The loss function is the sum of the cross-entropy loss for fragment classification, the cross-entropy loss for type classification, the cross-entropy loss for sentiment polarity classification, and the L2 regularization loss of the extraction model.
[0127] Specifically, the training and optimization objectives of the extraction model include cross-entropy loss for text fragment classification, fragment combination classification, and fragment combination sentiment polarity classification, as well as the model's L2 regularization loss:
[0128]
[0129] Where γ represents the L2 regularization loss ‖θ‖ 2 The weights are denoted by L, which represents the overall loss function.
[0130] The cross-entropy loss L for segment classification s The definition is as follows:
[0131]
[0132] Where, N s Indicates the number of text segments. Let represent the true category probability distribution of the i-th text segment.
[0133] The cross-entropy loss for type classification is defined as follows:
[0134]
[0135] Where, N p Indicates the number of combinations of text fragments. Let represent the true category probability distribution of the i-th text segment combination.
[0136] The cross-entropy loss for sentiment polarity classification is defined as follows:
[0137]
[0138] in, Let represent the true category probability distribution of the sentiment polarity of the i-th text fragment combination.
[0139] Optionally, before obtaining the text to be evaluated, the process further includes:
[0140] Get the statement to be evaluated;
[0141] The statement to be evaluated is segmented to obtain the text to be evaluated.
[0142] Specifically, the statement to be evaluated may include multiple texts to be evaluated, which can be segmented according to punctuation marks to obtain multiple texts to be evaluated.
[0143] The following describes a sample annotation method provided by an embodiment of the present invention.
[0144] In one embodiment, the sentiment corpus is annotated to provide a data foundation for training the TSSpan model. It should be understood that the sentiment corpus is a database composed of evaluation text samples, which may include multiple text fragments.
[0145] To obtain the dataset for training the TSSpan model, this embodiment of the invention constructs a sentiment corpus for the smart consumption domain through manual annotation. The original data includes two fields: comment text ID (comment_id) and comment content (comment_text). Annotated content is stored in the comment text unit (comment_units) field. The complete data format after annotation is shown in the figure, and the final result of the annotated data is stored in JSON format. For the annotated content, this invention adopts a unit-based annotation method, where each annotation unit represents a sentiment knowledge tuple. Each sentiment knowledge tuple includes the target, opinion, sentiment polarity, and the concept node (aspect) corresponding to the ontology of the smart consumption domain. The annotation results are stored in the comment_units field as a list of annotation units. Furthermore, considering that the same text fragment may appear multiple times in a single online comment, this invention also saves the position information within the text when annotating the target and opinion.
[0146] In one embodiment, data annotation in the smart consumption field is shown below:
[0147]
[0148] Optionally, a concept classification module can be added to the extraction model. This module includes a fully connected layer. The combined feature representation of the text fragments is input into the concept classification module, which outputs the concept classification. "Aspect" represents a conceptual aspect, indicating the conceptual domain to which the text fragment belongs. By setting multi-level conceptual domains, the construction of a smart city sentiment expression knowledge base can be facilitated. For example, first-level and second-level conceptual aspects can be designed, and the smart city sentiment expression knowledge base can be constructed hierarchically based on these conceptual aspects.
[0149] The sentiment corpus provides the data foundation for training the TSSpan model. Optionally, the sentiment corpus can be updated, and the amount of data in the labeled sentiment corpus will continue to grow over time.
[0150] The experimental results provided in the embodiments of the present invention are described below.
[0151] In one embodiment, regarding model training data, this embodiment of the invention uses the sentiment corpus obtained from the above annotations and divides it into a training set, a validation set, and a test set in proportions of 80%, 10%, and 10%, respectively. During the model training phase, TSSpan generates positive and negative training samples from a given sentence in the following manner: for candidate text segments, real evaluation elements are used as positive examples, and then N samples are randomly selected.n e.g. s Irrelevant segments are used as negative samples; for candidate segment combinations, the true evaluation combinations are used as positive samples, and then N random samples are taken. n e.g. p Each erroneous segment is combined as a negative sample. Table 1 is the training parameter table provided in the embodiments of the present invention, and the training parameters are shown in Table 1:
[0152] Table 1. Training Parameter Table
[0153]
[0154] Maximum text length refers to the maximum length of the text to be evaluated, and maximum text fragment length refers to the maximum length of a text fragment. Warm-up rounds refer to the number of times the extraction model is allowed to warm up during training. Since neural networks are very unstable at the beginning of training, the initial learning rate should be set very low. Setting the number of warm-up rounds ensures that the extraction model has good convergence.
[0155] The aforementioned trained model is validated through the following steps:
[0156] (1) Evaluation indicators
[0157] This invention uses the F1 score of text fragment classification, text fragment combination feature representation type classification, and text fragment combination feature representation sentiment polarity classification to evaluate the model's performance in the sentiment triple extraction task.
[0158] For the evaluation objects or opinions extracted from the model output, they are considered correct only when their start and end positions are exactly the same as the labels; for the evaluation combinations output by the model, they are considered correct only when both the evaluation objects and opinions they contain are correct; for the sentiment polarity of the evaluation combinations output by the model, they are considered correct when both the corresponding evaluation combination classification and the sentiment polarity category classification are correct.
[0159] (2) Comparison Method
[0160] The TSSpan model proposed in this invention is an improvement on the Span-ASTE model for Chinese smart city network text scenarios. The Span-ASTE-Ch model, with its BERT encoder replaced by a Chinese BERT encoder, is used as the baseline model for experimental comparison. The Span-ASTE-Ch model uses word length encoding to encode structural information features of text fragments, while the TSSpan model encodes Chinese word segmentation as the structural information feature of the text fragment. Furthermore, to explore the training effects of different structural information feature encoding methods on Chinese datasets, this paper removes the word length encoding feature from the Span-ASTE-Ch model, constructing the Span-ASTE-Ch-no_size model; and constructs the Span-ASTE-Ch-seg model by simultaneously using Chinese word segmentation encoding and word length encoding as structural information features of text fragments.
[0161] (3) Experimental Results
[0162] The above model was trained under the same parameter mode, and the average value was taken after 10 consecutive repetitions. Table 2 is the F1 value table of the test results provided by the embodiment of the present invention. The test results are shown in Table 2:
[0163] Table 2. Test Results F1 Value Table
[0164]
[0165]
[0166] The experimental results above show that the TSSpan model proposed in this invention achieves the best results in evaluating collocation relationship extraction and evaluating collocation sentiment polarity classification. Compared with the baseline model Span-ASTE-Ch, it shows an F1 score improvement of 9.13%, 12.30%, and 10.07% in the three extraction results. Comparing the Span-ASTE-Ch and Span-ASTE-Ch-seg, and Span-ASTE-Ch-no_size and TSSpan models, the models with added Chinese word segmentation feature encoding all achieved better sentiment triplet extraction results, proving the effectiveness of the Chinese word segmentation result encoding features in the TSSpan model.
[0167] In one embodiment, Figure 6 This is the second flowchart illustrating the emotion ternary extraction method provided in this embodiment of the invention, as shown below. Figure 6As shown, the extraction model first encodes the input knowledge text to be evaluated and enumerates all possible text fragments in the comment text. For each possible text fragment, its semantic features are concatenated with the Chinese text segmentation features to obtain the overall feature representation of the text fragment. The overall feature representation of the text fragment is then fed into the text fragment classification module to predict the category of each candidate fragment. Based on the classification results of the candidate fragments, all possible combinations of evaluation objects and opinion expressions are enumerated. The overall feature representation of the fragment combination is then concatenated with the contextual semantic features to obtain the fragment combination feature representation, which is then fed into the fragment combination classification module to predict the category and sentiment polarity of each fragment combination. Finally, the model extracts sentiment triples from the comment text based on the above prediction results.
[0168] This invention proposes a sentiment triplet extraction model TSSpan based on Chinese word segmentation features. The extraction model uses Chinese word segmentation features to represent the structural information of text fragments. The extraction model proposed in this invention improves the F1 score of sentiment triplet extraction by 10.07%.
[0169] The following describes the emotional triplet extraction device provided by the present invention. The emotional triplet extraction device described below and the emotional triplet extraction method described above can be referred to in correspondence.
[0170] Figure 7 This is a schematic diagram of the structure of the emotion triplet extraction device provided in an embodiment of the present invention, as shown below. Figure 7 As shown, an embodiment of the present invention provides an emotion triple extraction device, comprising:
[0171] Acquisition unit 710 is used to acquire the text to be evaluated;
[0172] Extraction unit 720 is used to input the text to be evaluated into the extraction model and obtain the sentiment triplet output by the extraction model;
[0173] The extraction model is trained based on fragment text samples, text combinations composed of the fragment text samples, and matching labels corresponding to the text combinations. The matching labels are predetermined based on the text combinations.
[0174] The extraction model is used to extract sentiment triples from the text to be evaluated based on the semantic features and Chinese word segmentation features of the text to be evaluated.
[0175] It should be noted that the apparatus provided in this embodiment of the invention can implement all the method steps implemented in the above method embodiment and can achieve the same technical effect. Therefore, the parts and beneficial effects that are the same as those in the method embodiment will not be described in detail here.
[0176] It should be noted that the apparatus provided in this embodiment of the invention can implement all the method steps implemented in the above method embodiment and can achieve the same technical effect. Therefore, the parts and beneficial effects that are the same as those in the method embodiment will not be described in detail here.
[0177] Figure 8 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 8 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830, and a communication bus 840, wherein the processor 810, the communication interface 820, and the memory 830 communicate with each other through the communication bus 840. The processor 810 can call logical instructions in the memory 830 to execute a sentiment triple extraction method; wherein the method includes: acquiring the text to be evaluated; inputting the text to be evaluated into an extraction model to obtain the sentiment triples output by the extraction model; wherein the extraction model is trained based on fragment text samples, text combinations composed of the fragment text samples, and collocation labels corresponding to the text combinations, and the collocation labels are predetermined based on the text combinations; the extraction model is used to extract sentiment triples from the text to be evaluated based on the semantic features and Chinese word segmentation features of the text to be evaluated.
[0178] Furthermore, the logical instructions in the aforementioned memory 830 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0179] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer is able to execute the sentiment triple extraction method provided by the above methods. The method includes: acquiring a text to be evaluated; inputting the text to be evaluated into an extraction model to obtain sentiment triples output by the extraction model; wherein the extraction model is trained based on fragment text samples, text combinations composed of the fragment text samples, and collocation labels corresponding to the text combinations, and the collocation labels are predetermined based on the text combinations; the extraction model is used to extract sentiment triples from the text to be evaluated based on the semantic features and Chinese word segmentation features of the text to be evaluated.
[0180] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the sentiment triple extraction method provided by the above methods; wherein the method includes: acquiring a text to be evaluated; inputting the text to be evaluated into an extraction model to obtain sentiment triples output by the extraction model; wherein the extraction model is trained based on fragment text samples, text combinations composed of the fragment text samples, and collocation labels corresponding to the text combinations, the collocation labels being predetermined based on the text combinations; the extraction model is used to extract sentiment triples from the text to be evaluated based on the semantic features and Chinese word segmentation features of the text to be evaluated.
[0181] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0182] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0183] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for extracting emotion triples, characterized in that, include: Obtain the text to be evaluated; The text to be evaluated is input into the extraction model to obtain the sentiment triples output by the extraction model; The extraction model is trained based on fragment text samples, text combinations composed of the fragment text samples, and sentiment tags corresponding to the text combinations. The sentiment tags are predetermined based on the text combinations. The extraction model is used to extract sentiment triples from the text to be evaluated based on the semantic features and Chinese word segmentation features of the text to be evaluated. The step of inputting the text to be evaluated into the extraction model to obtain the sentiment triples output by the extraction model includes: The text to be evaluated is segmented to obtain all text segments in the text to be evaluated; Semantic feature extraction and structural information extraction are performed on each of the text segments to obtain the text segment feature representation corresponding to each text segment; For each text segment feature representation, segment classification is performed to obtain segment classification results, which include evaluation object features, opinion expression features, or non-emotional triplet element features; Based on the characteristics of the evaluation object, the characteristics of the viewpoint expression, and the text to be evaluated, the context features are determined; Based on the characteristics of the evaluation object, the characteristics of the viewpoint expression, and the context features, a combined feature representation of the text fragments is determined; The combined feature representations of the text fragments are classified into types and sentiment polarities to obtain type classification results and sentiment polarity classification results; Based on the type classification results and the sentiment polarity classification results, sentiment triples are obtained.
2. The emotional triplet extraction method according to claim 1, characterized in that, The step of extracting semantic features and structural information for each text segment to obtain a text segment feature representation corresponding to each text segment includes: The text to be evaluated is text-encoded to obtain the character-level semantic representation of each character in the text to be evaluated. The text to be evaluated is segmented into Chinese words to obtain the segmentation results; Based on the character-level semantic representation, obtain the segment semantic representation corresponding to each text segment; Each text segment is compared with the word segmentation result to determine the number of words contained in each text segment; Based on the semantic representation of each text segment and the number of words segmented for each text segment, the text segment feature representation of each text segment is determined.
3. The emotional triplet extraction method according to claim 2, characterized in that, The step of obtaining the segment semantic representation corresponding to each text segment based on the character-level semantic representation includes: Aggregate the character-level semantic representations corresponding to each text segment to obtain the segment semantic representation corresponding to each text segment.
4. The emotional triplet extraction method according to claim 2, characterized in that, The step of determining the text segment feature representation of each text segment based on the segment semantic representation and the number of word segments corresponding to each text segment includes: The semantic representation of each text segment and the number of words segmented for each text segment are concatenated to obtain the text segment feature representation of each text segment.
5. The emotional triple extraction method according to claim 1, characterized in that, The step of determining contextual features based on the characteristics of the evaluation object, the characteristics of the opinion expression, and the text to be evaluated includes: Obtain the text segment between the evaluation object text and the opinion expression text, wherein the evaluation object text is the text segment corresponding to the evaluation object feature, and the opinion expression text is the text segment corresponding to the opinion expression feature; Semantic features are extracted from the spaced text segments to obtain the contextual features.
6. The emotional triple extraction method according to claim 1, characterized in that, The optimization objective of the extraction model during training is to minimize the value of the loss function; The loss function is the sum of the cross-entropy loss for fragment classification, the cross-entropy loss for type classification, the cross-entropy loss for sentiment polarity classification, and the L2 regularization loss of the extraction model.
7. An emotion triplet extraction device, characterized in that, include: The acquisition unit is used to acquire the text to be evaluated. An extraction unit is used to input the text to be evaluated into an extraction model and obtain the sentiment triples output by the extraction model. The extraction model is trained based on fragment text samples, text combinations composed of the fragment text samples, and sentiment tags corresponding to the text combinations. The sentiment tags are predetermined based on the text combinations. The extraction model is used to extract sentiment triples from the text to be evaluated based on the semantic features and Chinese word segmentation features of the text to be evaluated. The extraction unit is specifically used for: The text to be evaluated is segmented to obtain all text segments in the text to be evaluated; Semantic feature extraction and structural information extraction are performed on each of the text segments to obtain the text segment feature representation corresponding to each text segment; For each text segment feature representation, segment classification is performed to obtain segment classification results, which include evaluation object features, opinion expression features, or non-emotional triplet element features; Based on the characteristics of the evaluation object, the characteristics of the viewpoint expression, and the text to be evaluated, the context features are determined; Based on the characteristics of the evaluation object, the characteristics of the viewpoint expression, and the context features, a combined feature representation of the text fragments is determined; The combined feature representations of the text fragments are classified into types and sentiment polarities to obtain type classification results and sentiment polarity classification results; Based on the type classification results and the sentiment polarity classification results, sentiment triples are obtained.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the sentiment triple extraction method as described in any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the sentiment triple extraction method as described in any one of claims 1 to 6.