Emotion detection method combining metaphor recognition and syntactic structure

By combining the emotion detection method of metaphor recognition and syntactic structure, the problem of insufficient emotion recognition accuracy in dealing with metaphorical and complex syntactic structures in the prior art is solved, and more efficient and accurate emotion analysis is achieved.

CN119557412APending Publication Date: 2025-03-04BEIJING INST OF TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411415929.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2025-03-04

AI Technical Summary

Technical Problem

When existing emotion detection methods deal with metaphorical expression and complex syntactic structures, the recognition accuracy of emotion intensity indicators is insufficient, making it difficult to accurately capture implicit emotional information.

Method used

Combining the emotion detection method of metaphor recognition and syntactic structure, the text is marked in a coarse and fine grain size through the natural language processing library, emotional keywords are extracted, and feature extraction and metaphor detection are used to perform feature extraction and metaphor detection, and finally emotional classification evaluation is performed through the emotion detection model.

Benefits of technology

It improves the accuracy of identifying emotions expressed by metaphor, reduces the introduction of irrelevant information, ensures the efficiency and accuracy of emotion analysis, and enhances the robustness of emotion detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119557412A_ABST
    Figure CN119557412A_ABST
Patent Text Reader

Abstract

The invention relates to an emotion detection method combining metaphor recognition and a syntactic structure, and belongs to the technical field of natural language processing and emotion analysis. The implementation method comprises the following steps: 1, tagging part-of-speech coarseness of a to-be-analyzed text by utilizing a natural language processing library; extracting and identifying a labeled result to obtain an emotion keyword; 2, performing fine-grained marking on the emotion keywords, and performing serial number marking on positions of the emotion keywords; 3, obtaining a feature vector, a segment vector and a mask vector; 4, screening to obtain a target word of the metaphor; 5, constructing a node relationship of the dependency tree; meanwhile, sorting and splicing are carried out, and then clauses are obtained; 6, performing emotion classification evaluation; the evaluation is used in emotional natural language text data processing; compared with the prior art, the method has the advantages that through cooperative work of the metaphor recognition model and the emotion detection model, the recognition precision of the expression emotion of the metaphor is improved, introduction of irrelevant information is effectively reduced, and high efficiency of emotion analysis is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to an emotion detection method combining metaphor recognition and syntactic structure, and belongs to the technical field of natural language processing and sentiment analysis. Background Art

[0002] With the rapid development of natural language processing (NLP) and sentiment computing technologies, emotion detection has been widely used in many fields, such as social media analysis, intelligent customer service, and satisfaction evaluation. Although current emotion detection technology performs well in processing explicit emotion recognition data, it is still insufficient when dealing with complex language phenomena, especially metaphorical expressions and complex syntactic structures. Metaphor is a common rhetorical device that conveys complex and subtle emotions through figurative expressions. It is often hidden under the surface language, which increases the difficulty of emotion detection.

[0003] At present, some emotion detection methods use bag-of-words models or simple machine learning classifiers, and mainly rely on sentiment dictionaries to extract sentiment polarity. Although such methods perform well when processing texts with clear literal meanings, they are difficult to accurately process complex emotional expressions. Specifically, many methods have obvious deficiencies in combining metaphor recognition. Metaphors, as a common phenomenon in daily language, can convey potential emotional intentions. Most existing methods focus on the extraction of surface sentiment words and fail to effectively identify and process the emotional expressions implied in metaphors. As a result, these methods often fail to judge the true emotional tendency of sentences containing metaphors, resulting in deviations in emotion detection results. On the other hand, the importance of syntactic structure in emotional expression is often overlooked. Many emotion detection methods focus on the extraction of sentiment words without fully considering the grammatical relationship between words. Syntactic structure can reveal the dependency relationship between words and affect the transmission and change of emotions. However, ignoring syntactic structure may cause the method to be biased when processing complex sentences, especially when emotional expression depends on sentence structure or grammatical information, resulting in a lack of depth in understanding complex emotional expressions, which in turn affects the accuracy and robustness of emotion detection.

[0004] Although metaphor recognition technology has made great progress in recent years, the combination of metaphor and sentiment analysis is still in its early stages. Current emotion detection systems have limitations when facing metaphorical expressions and complex syntactic structures. Future research should focus on combining metaphor recognition with syntactic analysis to further improve the ability to recognize implicit emotional information. Summary of the invention

[0005] The purpose of the present invention is to solve the technical problem that the existing emotion detection methods have insufficient recognition accuracy of emotion intensity indicators when dealing with metaphorical expressions and complex syntactic structures, and to propose an emotion detection method that combines metaphor recognition with syntactic structure.

[0006] The objective of the present invention is achieved through the following technical solutions:

[0007] Step 1: Use the natural language processing library to perform coarse-grained annotation of the part of speech of the text to be analyzed; further extract and identify the annotated results to obtain sentiment keywords;

[0008] Step 2: Perform fine-grained annotation of emotional keywords and mark the positions of emotional keywords with serial numbers;

[0009] Step 3: Extract features from the text to be analyzed and obtain feature vectors, segment vectors, and mask vectors;

[0010] Step 3.1: Construct a dictionary for metaphor detection model training using the method shown in formula (1);

[0011] (text,word,pos,fgpos,index)(1)

[0012] Among them, text is the text, word is the target word, pos is the coarse-grained part of speech, fgpos is the fine-grained part of speech, and index is the position index of the target word in the text.

[0013] Step 3.2: Use the pre-trained tokenizer to decompose the text in the dictionary and the target word into text tokens text tokens and target word tag target tokens ;

[0014] Step 3.3: Update the position number of the target word after segmentation in a stack manner to obtain targetpos;

[0015] Step 3.4: Extract local context fragments from the text to be analyzed using the method shown in formula (2);

[0016] local start =min(i|text tokens [i]′,′),

[0017] local end =min(i|text tokens [i] = ', '),

[0018] for i≤target pos , for i>target pos (2)

[0019] Among them, local start is the starting position of the local context fragment, local end The end position of the local context fragment.

[0020] Step 3.5: Mark the text tokens and target word tag target tokens The concatenation encoding is performed in the manner shown in formula (3) to form a feature vector;

[0021]

[0022] in, Indicates series connection, f Vocabulary (·) indicates that the tokens are converted into corresponding IDs according to the vocabulary of the RoBERTa pre-trained model, [CLS] indicates the start token of the RoBERTa pre-trained model, and [SEP] indicates the boundary and end tokens of the RoBERTa pre-trained model.

[0023] Step 3.6: Form a segment vector and a mask vector according to the feature vector in the manner shown in formula (4);

[0024]

[0025] input mask =[1]*len(input ias ) (4)

[0026] Among them, i represents the segment vector segment ias The index in Indicates input ias The index of the first [SEP] in Indicates input ids The index of the last [SEP] in .

[0027] Step 3.7: Fill the feature vector, segment vector and mask vector with markers as shown in formula (5) to keep the sequence lengths of the three vectors fixed;

[0028]

[0029] Among them, seqlength max Indicates the maximum length of the input sequence, and [PAD] indicates the padding tag of the RoBERTa pre-training model.

[0030] Step 4: Screening target words to obtain metaphors;

[0031] Step 4.1: Use the fully connected layer of the metaphor detection model to classify the feature vector, segment vector and mask vector in the manner shown in formula (6) to obtain the probability value of the metaphor;

[0032] logits=f classifier (f encoder(input ids , segment ids , input mask )) (6)

[0033] Among them, f encoder (·) represents the encoder, f classifier (·) indicates a linear classification layer, and [·;·] indicates a concatenation operation. Logits are processed using binary classification to obtain logits = [logit0, logit1], where logit0 is the score of category 0 (non-metaphor), and logit1 is the score of category 1 (metaphor).

[0034] Step 4.2: Obtain metaphor using the method shown in formula (7);

[0035]

[0036] Step 4.3: Use metaphors to filter target words to obtain metaphorical target words;

[0037] Step 5: Use the natural language processing library to parse the text to be analyzed, generate a dependency tree, and construct the node relationship of the dependency tree in the manner shown in formula (8); at the same time, use the method shown in formula (9) to sort and splice, and then obtain clauses;

[0038] C=w t ∪Head(w t )∪{Children(w t )}(8)

[0039] Among them, Head(Wt) represents the dependency head of the target word, {Children(w t )} represents the dependent word set of the target word;

[0040] Clause=f join (Sort(C, key=i)) (9)

[0041] Among them, i represents the index of each word in the sentence, and f join (·) means connecting words with spaces.

[0042] Step 6: Concatenate the clause and the text to be analyzed and input them into the emotion detection model to perform emotion classification evaluation in the manner shown in formula (10); the evaluation is used in emotional natural language text data processing.

[0043]

[0044] Among them, f Vocabulary(·) indicates that the token is converted into the corresponding ID according to the vocabulary of the BERT pre-trained model, f encoder (·) represents the BERT encoder, f classifier (·) denotes a linear classification layer.

[0045] Compared with the prior art, the method of the present invention has the following advantages:

[0046] 1. The recognition accuracy of metaphorically expressed emotions is improved through the collaborative work of the metaphor recognition model and the emotion detection model.

[0047] 2. The metaphor detection mechanism based on probability threshold is adopted to effectively reduce the introduction of irrelevant information, thus ensuring the efficiency of sentiment analysis.

[0048] 3. Extract the contextual substructure of metaphorical words so that the model can more accurately capture the role of metaphor in semantics, thereby improving the accuracy of sentiment analysis. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 It is a schematic diagram of the process of the present invention;

[0050] Figure 2 FIG. 4 is a diagram showing a visualization of a dependency tree in this embodiment. DETAILED DESCRIPTION

[0051] In order to better illustrate the purpose and advantages of the present invention, the invention is further described below in conjunction with the accompanying drawings and examples. It should be noted that the implementation of the present invention is not limited to the following embodiments, and any form of modification or change made to the present invention will fall within the protection scope of the present invention.

[0052] Example

[0053] Take a sample from the “Stanford Sentiment Treebank-5Class” sentiment classification dataset as an example—truth: 4, text: “It further declares its director, Zhang Yang of Shower, as a boldly experimental. contemporary stylist with a bright future.”

[0054] like Figure 1 As shown, the emotion detection method combining metaphor recognition and syntactic structure of the present invention is specifically implemented in the following steps:

[0055] Step 1: Use the natural language processing library to perform coarse-grained annotation of the part of speech of the text to be analyzed; further extract and identify the annotated results to obtain sentiment keywords;

[0056] In the embodiment, the natural language processing library spacy is used to perform coarse-grained annotation of the parts of speech of the text in the sample, and then the annotated adjectives are extracted and identified to obtain the sentiment keywords:

[0057] "experimental", "contemporary", "bright".

[0058] Step 2: Perform fine-grained annotation of emotional keywords and mark the positions of emotional keywords with serial numbers;

[0059] In the embodiment, the sentiment keywords are further annotated, and spacy is used to annotate the fine-grained parts of speech and the position numbers of the words to obtain that the fine-grained parts of speech of the three sentiment keywords are all "JJ", and the position subscripts are 14, 16, and 20 respectively.

[0060] Step 3: Extract features from the text to be analyzed and obtain feature vectors, segment vectors, and mask vectors;

[0061] Step 3.1: Construct a dictionary for metaphor detection model training using the method shown in formula (1);

[0062] (text,word,poS,fgpos,index)(1)

[0063] Among them, text is the text, word is the target word, pos is the coarse-grained part of speech, fgpos is the fine-grained part of speech, and index is the position index of the target word in the text;

[0064] In the embodiment, taking "experimental" as an example, its dictionary is (text: "It further declares its director, Zhang Yang of Shower, as a boldly experimental, contemporary stylist with a bright future.", word: "experimental", pos: "ADJ", fgpos: "JJ", index: 14).

[0065] Step 3.2: Use the pre-trained tokenizer to decompose the text in the dictionary and the target word into text tokens text tokens and target word tag target tokens ;

[0066] In the embodiment, taking "experimental" as an example, text tokens for [′It′, 'ower', 'ist', ], taking "experimental" as an example, its corresponding target tokens for

[0067] Step 3.3: Update the position number of the target word after segmentation in a stack manner to obtain targetpos;

[0068] In the embodiment, taking "experimental" as an example, its targetpos is updated to 15.

[0069] Step 3.4: Extract local context fragments from the text to be analyzed using the method shown in formula (2);

[0070] local start =min(i|text tokens [i]′,′),

[0071] local end =min(i|text tokens [i] = ', '),

[0072] for i≤target pos , for i>target pos (2)

[0073] Among them, local start is the starting position of the local context fragment, local end The end position of the local context fragment.

[0074] In the embodiment, taking "experimental" as an example, it corresponds to local start is 11, which corresponds to local end is 16.

[0075] Step 3.5: Mark the text tokens and target word tag target tokens The concatenation encoding is performed in the manner shown in formula (3) to form a feature vector;

[0076]

[0077] in, Indicates series connection, f Vocabulary(·) indicates that the tokens are converted into corresponding IDs according to the vocabulary of the RoBERTa pre-trained model, [CLS] indicates the start token of the RoBERTa pre-trained model, and [SEP] indicates the boundary and end tokens of the RoBERTa pre-trained model.

[0078] Step 3.6: Form a segment vector and a mask vector according to the feature vector in the manner shown in formula (4);

[0079]

[0080] Among them, i represents the segment vector segment ids The index in Indicates input ids The index of the first [SEP] in Indicates input ids The index of the last [SEP] in .

[0081] Step 3.7: Fill the feature vector, segment vector and mask vector with markers as shown in formula (5) to keep the sequence lengths of the three vectors fixed;

[0082]

[0083] Among them, seqlength max Indicates the maximum length of the input sequence, and [PAD] indicates the padding tag of the RoBERTa pre-training model.

[0084] In the embodiment, the feature vector, segment vector and mask vector are shown in Table 1;

[0085] Table 1 Feature vector, segment vector and mask vector feature representation

[0086]

[0087] Step 4: Screening target words to obtain metaphors;

[0088] Step 4.1: Use the fully connected layer of the metaphor detection model to classify the feature vector, segment vector and mask vector in the manner shown in formula (6) to obtain the probability value of the metaphor;

[0089] logits=f classifier (f encoder (input ids ,segment ids ,input mask )) (6)

[0090] Among them, f encoder (·) represents the encoder, f classifier(·) indicates a linear classification layer, and [·;·] indicates a concatenation operation. Logits are processed using binary classification to obtain logits = [logit0, logit1], where logit0 is the score of category 0 (non-metaphor), and logit1 is the score of category 1 (metaphor).

[0091] In the embodiment, the logits of the three words "experimental", "contemporary", and "bright" are obtained as follows:

[0092] [0.9640868306159973,0.035913147032260895],

[0093] [0.9859012961387634,0.014098766259849072],

[0094] [0.01960579864680767, 0.9803942441940308].

[0095] Step 4.2: Obtain metaphor using the method shown in formula (7);

[0096]

[0097] Step 4.3: Use metaphors to filter target words to obtain metaphorical target words;

[0098] In the embodiment, the target words are screened to obtain the metaphorical target word "bright".

[0099] Step 5: Use the natural language processing library to parse the text to be analyzed, generate a dependency tree, and construct the node relationship of the dependency tree in the manner shown in formula (8); at the same time, use the method shown in formula (9) to sort and splice, and then obtain clauses;

[0100] C=w t ∪Head(w t )∪{Children(w t )} (8)

[0101] Among them, Head(Wt) represents the dependency head of the target word, {Children(w t )} represents the dependent word set of the target word;

[0102] Clause=f join (Sort(C, key=i)) (9)

[0103] Among them, i represents the index of each word in the sentence, and f join(·) means connecting words with spaces.

[0104] In the embodiment, a dependency tree is generated such as Figure 2 As shown in the figure, the target word "bright" extracted from the dependency tree has an empty head and "future" at the tail. Several words are sorted according to their indexes in the sentence and concatenated to obtain their substructure "bright future".

[0105] Step 6: Concatenate the clause and the text to be analyzed and input them into the emotion detection model to perform emotion classification evaluation in the manner shown in formula (10); the evaluation is used in emotional natural language text data processing.

[0106]

[0107] Among them, f Vocabulary (·) indicates that the token is converted into the corresponding ID according to the vocabulary of the BERT pre-trained model, f encoder (·) represents the BERT encoder, f classifier (·) denotes a linear classification layer.

[0108] In the embodiment, the original sentence text and the substructure are concatenated to obtain [CLS]It further declares its director, Zhang Yang of Shower, as a boldly experimental, contemporary stylist with a bright future.[SEP]bright future[SEP], which is then converted into a corresponding ID, encoded using BERT, and input into the linear classification layer for sentiment classification evaluation.

[0109] To further verify the effectiveness of the method of the present invention, this example uses the "Stanford SentimentTreebank-5Class" sentiment analysis dataset for experimental comparison. There are 8544 samples in the training set and 2210 samples in the validation set. The experimental data comparison is shown in Table 2.

[0110] Table 2 Dataset comparison experimental results

[0111]

[0112] As can be seen from Table 2, the proposed method has achieved better results in the emotion classification task than the BERT model, especially in the three evaluation indicators of Precision, F1 and Accuracy. Among them, the proposed method has improved Precision by 3.68%, Accuracy by 1.88%, and F1 by 2.61% compared with the BERT model, which proves the effectiveness of the proposed method in emotion classification.

[0113] The specific description above further illustrates the purpose, technical solutions and beneficial effects of the invention in detail. It should be understood that the above is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for emotion detection combining metaphor recognition and syntactic structure, characterized in that: The following steps are included: Step 1: Use the natural language processing library to perform coarse-grained annotation of the part of speech of the text to be analyzed; further extract and identify the annotated results to obtain sentiment keywords; Step 2: Perform fine-grained annotation of emotional keywords and mark the positions of emotional keywords with serial numbers; Step 3: Extract features from the text to be analyzed and obtain feature vectors, segment vectors, and mask vectors; Step 3.1: Construct a dictionary for metaphor detection model training using the method shown in formula (1); (text,word,pos,fgpos,index) (1) Among them, text is the text, word is the target word, pos is the coarse-grained part of speech, fgpos is the fine-grained part of speech, and index is the position index of the target word in the text; Step 3.2: Use the pre-trained tokenizer to decompose the text in the dictionary and the target word into text tokens text tokens and target word tag target tokens ; Step 3.3: Update the position number of the target word after segmentation in a stack manner to get target pos ; Step 3.4: Extract local context fragments from the text to be analyzed using the method shown in formula (2); local start =min(i|text tokens [i]=′,′), local end =min(i|text tokens [i]=′,′), for i≤target pos ,for i>target pos (2) Among them, local start is the starting position of the local context fragment, local end is the end position of the local context fragment; Step 3.5: Mark the text tokens and target word tag target tokens The concatenation encoding is performed in the manner shown in formula (3) to form a feature vector; T=[CLS]⊕text tokens ⊕[SEP]⊕pos⊕[SEP]⊕fgpos⊕[SEP]⊕target tokens ⊕[SEP]input ids =f Vocabulary (T) (3) Among them, ⊕ represents series connection, f Vocabulary (·) indicates that the token is converted into the corresponding ID according to the vocabulary of the RoBERTa pre-trained model, [CLS] indicates the start token of the RoBERTa pre-trained model, and [SEP] indicates the boundary and end token of the RoBERTa pre-trained model; Step 3.6: Form a segment vector and a mask vector according to the feature vector in the manner shown in formula (4); input mask =[1]*len(input ids ) (4) Among them, i represents the segment vector segment ids The index in Indicates input ids The index of the first [SEP] in Indicates input ids The index of the last [SEP] in ; Step 3.7: Fill the feature vector, segment vector and mask vector with markers as shown in formula (5) to keep the sequence lengths of the three vectors fixed; input ids =input ids ⊕f Vocabulary ([PAD]*(seqlength max -len(input ids ))) segment ids =segment ids ⊕[0]*(seqlength max -len(segment ids )) input mask =input mask ⊕[0]*(seqlength max -len(input mask )) (5) Among them, seqlength max Indicates the maximum length of the input sequence, and [PAD] indicates the padding marker of the RoBERTa pre-training model; Step 4: Screening target words to obtain metaphors; Step 5: Use the natural language processing library to parse the text to be analyzed, generate a dependency tree, and construct the node relationship of the dependency tree in the manner shown in formula (8); at the same time, use the method shown in formula (9) to sort and splice, and then obtain clauses; C=w t ∪Head(w t )∪{Children(w t )} (8) Among them, Head(w t ) represents the dependency head of the target word, {Children(w t )} represents the dependent word set of the target word; Clause=f join (Sort(C,key=i)) (9) Among them, i represents the index of each word in the sentence, and f join (·) means connecting words with spaces; Step 6: splice the clause and the text to be analyzed and input them into the emotion detection model to perform emotion classification evaluation in the manner shown in formula (10); the evaluation is used in emotional natural language text data processing; input ids =f Vocabulary ([CLS]⊕text⊕[SEP]⊕Clause1⊕…⊕Clause n ⊕[SEP]) logits=f classifier (f encoder (input ids )) (10) Among them, f Vocabulary (·) indicates that the token is converted into the corresponding ID according to the vocabulary of the BERT pre-trained model, f encoder (·) represents the BERT encoder, f classifier (·) denotes a linear classification layer.

2. The emotion detection method combining metaphor recognition and syntactic structure as claimed in claim 1, characterized in that: Step 4 is implemented as follows: Step 4.1: Use the fully connected layer of the metaphor detection model to classify the feature vector, segment vector and mask vector in the manner shown in formula (6) to obtain the probability value of the metaphor; logits=f classifier (f encoder (input ids ,segment ids ,input mask )) (6) Among them, f encoder (·) represents the encoder, f classifier (·) indicates a linear classification layer, [·;`] indicates a concatenation operation; logits are processed using binary classification to obtain logits = [logit0, logit1], where logit0 is the score of category 0 (non-metaphor), and logit1 is the score of category 1 (metaphor); Step 4.2: Obtain metaphor using the method shown in formula (7); Step 4.3: Use metaphors to filter target words and obtain metaphorical target words.

Citation Information

Cited By

  • Text emotion multi-dimensional analysis method and system oriented to complex context

    CN122088520A