Metaphor identification method based on anchor base double example and multi-theory semantic interaction
By constructing an anchor-based bitonal model and a multi-theory semantic interaction method, the complexity and insufficient contextual understanding of pre-trained models in metaphor detection are solved, achieving more efficient metaphor recognition and semantic analysis, and improving the performance of natural language processing tasks.
Patent Information
- Application Number
- CN202510996208.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2025-11-18
AI Technical Summary
Existing pre-trained models suffer from insufficient ability to handle complex metaphors, limited contextual understanding, and errors in generated results in metaphor detection, making it difficult to accurately identify and understand metaphorical expressions.
We adopt an anchor-based biexample and multi-theory semantic interaction approach. By constructing an anchor-based biexample paradigm with positive examples, anchor sentences, and negative examples, and combining it with the theories of choice preference violation and metaphor recognition procedure, we enhance the model's understanding of sentence semantic structure. Semantic analysis is then performed through a multi-theory semantic interaction module.
It significantly improves the model's ability to recognize metaphorical semantic structures, enabling it to more accurately capture the semantic changes of target words in different contexts, thereby improving the accuracy of metaphor detection and the performance of various natural language processing tasks.
Smart Images

Figure CN120975101A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to a metaphor recognition method based on anchor-based double instances and multi-theory semantic interaction, belonging to the technical field of Internet and artificial intelligence. BACKGROUND
[0002] As a special rhetorical way, the essence of metaphor lies in establishing a mapping relationship between two surface unrelated concepts or things, and realizing the improvement of language information transmission efficiency. From the perspective of cognitive linguistics, this rhetorical mechanism breaks the conventional semantic logic framework and completes the meaning construction through cross-concept domain meaning projection. Taking the classic expression "time is money" as an example, its semantic construction is not based on the equal judgment of literal meaning, but through the systematic migration of the value attribute of the "money" concept in the economic field to the time dimension, thus constructing the cognitive framework of "time has scarcity and quantifiable value".
[0003] Metaphorical expression not only expands the semantic tension of language, but also poses special challenges to natural language understanding systems. Metaphor recognition, as an important research topic in the field of natural language processing, aims to automatically detect and semantically analyze metaphorical expressions in text through algorithmic models. This technical capability has important research value in multiple NLP application scenarios such as sentiment analysis, machine translation, and intelligent question answering. In addition, metaphor recognition research is driving the cross-disciplinary theoretical integration and technological innovation of computational linguistics, cognitive science, and artificial intelligence.
[0004] With the development of deep learning, pre-trained models such as Bidirectional Encoder Representations from Transformers (BERT) and the Robust Optimization BERT Pretraining model (RoBERTa) have achieved remarkable results in natural language processing. In metaphor detection, these models have learned rich language features and semantic information through pre-training on large-scale text data. However, due to the limited ability of pre-trained models in understanding the pragmatic function and context of metaphors, this to some extent restricts their metaphor detection performance in complex text environments.
[0005] The advent of large language models (LLMs) presents new opportunities for metaphor detection. Some studies have combined LLMs with pre-trained models to optimize the model's ability to capture abstract semantic mappings in metaphorical expressions. However, LLMs also face some challenges in metaphor detection. First, the training of LLMs heavily relies on large-scale text data, which makes them prone to overfitting to patterns and biases in the data during training. Metaphorical expressions, however, are highly innovative and diverse, and existing annotated datasets are difficult to cover all types of metaphorical expressions. Therefore, when LLMs face novel or rare metaphors, their recognition ability may be constrained due to the lack of corresponding training samples. In addition, LLMs exhibit "hallucination" when generating results, i.e., generating content that is inconsistent with facts or logic. The understanding of metaphors usually requires the combination of context and contextual information, while LLMs may generate incorrect metaphorical explanations or judgments in this process, further affecting the accuracy of metaphor detection. Finally, the decision-making process of LLMs is usually not interpretable. The metaphor detection task requires the model to accurately distinguish between metaphorical and literal meanings and make inferences based on context. However, due to the uninterpretable nature of LLMs, researchers have difficulty determining the source of errors in metaphor detection, making it difficult for the model to continuously improve when faced with complex metaphors.
[0006] In view of the deficiencies of existing research in metaphor detection, especially the limitations in handling complex metaphors and understanding context, the present invention introduces a new metaphor recognition method based on anchor-based double examples and multi-theory semantic interaction. First, to explore the complex semantics of metaphorical sentences, the invention proposes a new anchor-based double example group construction framework, which constructs sentences with similar structures but different metaphorical properties into an anchor-based double example paradigm, to deeply excavate the semantic relationship between the subject, relationship, and object, to accurately understand the sentence semantics and determine the existence of metaphors. In addition, current models generally have difficulty accurately grasping the dynamic changes of context, therefore, the invention integrates the "Selectional Preference Violation (SPV) theory" and "Metaphor Identification Procedure (MIP) theory" which have been widely recognized and applied in the field of linguistics, and proposes a double-theory semantic interaction module. By integrating these theories into the metaphor detection model, the semantic interaction between metaphorical words and sentences is enhanced, significantly improving the understanding and recognition ability of metaphorical semantic structures. SUMMARY
[0007] To solve the problems and deficiencies in the prior art, the application provides a metaphor recognition method based on anchor-based double examples and multi-theory semantic interaction, an anchor-based double example paradigm combination structure of positive examples, anchor sentences and negative examples is constructed, the model's grasp of the semantic structure of a sentence is significantly enhanced, a comparison mechanism of positive examples and negative examples is introduced, semantic changes of a target word in different contexts are accurately captured, and richer semantic information basis is provided for metaphor detection. In addition, a double-theory semantic interaction module is designed, the extracted anchor-based double example paradigm is analyzed, whether the target word in the sentence contains a metaphor is judged, consistency between the characteristics of the target word and the overall context characteristics of the text is evaluated by using a "selection preference violation theory SPV", and on this basis, the coherence between the context characteristics of the target word and the potential use characteristics of the target word is evaluated by integrating a "metaphor identification procedure theory MIP", so that whether the target word contains a metaphor is determined.
[0008] To achieve the above object, the technical scheme of the application is as follows: a metaphor recognition method based on anchor-based double examples and multi-theory semantic interaction, the method comprising the following steps:
[0009] Step 1: Metaphor text normalization;
[0010] Step 2: Anchor-based double example group construction;
[0011] Step 3: Contextual semantic learning;
[0012] Step 4: Multi-theory semantic interaction learning;
[0013] Step 5: Model joint loss training.
[0014] As an improvement of the application, in step 1: metaphor text normalization, a data set containing metaphors is obtained by using a crawler technology and a data preprocessing technology, and is normalized to contain one sentence S and one specific target word t in each group of data. The purpose is to judge whether the target word in the sentence has special metaphorical expression.
[0015] As an improvement of the application, in step 2: anchor-based double example group construction, the combination of positive examples, anchor sentences and negative examples is constructed to enhance the model's learning ability of the metaphorical characteristics of the target word. For anchor-based double example group paradigm (S P ,S A ,S N ) construction, assuming that S1={"Fear","seized","the","prisoners"} and t={"seized"}, the positive example S P is defined as the original sentence containing the target word t, and the purpose is to provide complete semantic information of the target word in the original context. Therefore, the positive example S p =S1. The anchor sentence S A is constructed by replacing the target word t in the positive example SP The sentence generated after replacing the target word t in the anchor sentence S A with the placeholder "[Mask]". The construction of the anchor sentence aims to provide the position information of the target word in the context while removing the semantic information of the target word itself. Therefore, the anchor sentence S N corresponding to S1 is A {"Fear", "[Mask]", "the", "prisoners"}.
[0016] The negative example S N is the sentence that is most similar to the anchor sentence S A but has opposite metaphorical expression, aiming to provide a sentence that is in sharp contrast to the positive example S P in semantic information. According to the anchor sentence S A {"Fear", "[Mask]", "the", "prisoners"}, the sentence S2 = {"The", "prisoner", "[Mask]", "at", "the", "chains"} with the highest similarity but opposite metaphorical expression is found in the data set, and then the original sentence S3 = {"The", "prisoner", "tugged", "at", "the", "chains"} of S2 is obtained as the negative example S A of the anchor sentence S N In this example, the target word "seized" in the positive example S P is metaphorically expressed in the sentence, while the target word "tugged" in S N is not metaphorically expressed in the sentence. At this point, the anchor-based double example group paradigm (S P , S A , S N ) can be constructed as the input of the model.
[0017] As an improvement of the present application, step 3: context semantic learning, using the anchor-based double example paradigm obtained in step 2, three key semantic representations are constructed using the RoBERTa model: word-level semantic representation of the target word, sentence-level semantic representation of the target word, and context semantic representation of the target word. The three semantic representations capture the semantic information of the target word itself, the context information of the target word in the sentence, and the semantic information of the entire sentence, providing rich semantic features for subsequent metaphorical recognition. The implementation of this step can be divided into the following sub-steps:
[0018] Sub-step 3-1, word-level semantic representation of the target word. This semantic representation aims to eliminate contextual interference and capture the inherent semantic features of the target word. First, by performing word segmentation on the target word t, the input sequence X t is obtained. Then, the input sequence X t is input into the RoBERTa model to obtain the hidden state Ht Finally, the word-level semantic representation V t :
[0019] X t = tokenizer(t)
[0020] H t = RoBERTa(X t )
[0021]
[0022] where |H t | denotes the length of hidden states. In addition, define and where m is the length of the tokenized sequence X t . d is the hidden layer dimension of the RoBERTa model.
[0023] Sub-step 3-2, sentence-level semantic representation of the target word. It represents the complete semantic information by capturing the global semantic structure of the sentence. First, the input sequence X S is obtained by tokenizing the sentence S. Then, the sequence X S is input into the RoBERTa model to obtain the hidden state H S of the last layer. Finally, the semantic representation of the [CLS] token is extracted as the sentence-level semantic representation V S :
[0024] X S = tokenizer(S)
[0025] H s = RoBERTa(X S )
[0026]
[0027] where H denotes the hidden state corresponding to the [CLS] token. In addition, define and where n is the length of the tokenized sequence X S .
[0028] Sub-step 3-3, context semantic representation of the target word. This semantic representation is used to represent the context information of the target word in the sentence. First, locate the position k of the target word t in the sentence, then extract the semantic representation V (s,t) of t in the sentence S according to k:
[0029] k = index(Xt ,X S )
[0030]
[0031] Among them, the definition This represents the semantic meaning of the target word within its context. The function `index()` is used to find the position of `t` in `S`.
[0032] As an improvement to this invention, step 4 involves multi-theory semantic interaction learning. Utilizing the semantics of the target word learned in step 3, the interactive semantics within the sentence context are explored. This invention designs two semantic interaction modules: Selectional Preference Violation Semantic Interaction (SPV-SI) and Metaphor Identification Procedure Semantic Interaction (MIP-SI). These two modules enhance the semantic representation of the target word from different perspectives, thereby improving the model's ability to recognize metaphorical expressions. The implementation of this step can be divided into the following sub-steps:
[0033] Sub-step 4-1, selecting preferences violates semantic interaction. The core objective of the SPV-SI module is to enable semantic interaction between the target word's context and the sentence. This module achieves this by using the sentence-level semantic representation V of the target word. S The contextual semantic representation V of the target word (s,t) The components are concatenated to form a joint semantic representation V. SPV Then V SPV The input is fed into a fully connected layer (FC1) to further extract global interaction features h. SPV .
[0034] V SPV =Concat(V S V (s,t) )
[0035] h SPV =FC1(V SPV )
[0036] Here, `Concat()` represents the concatenation operation. Additionally, the definition...
[0037] Sub-step 4-2: Semantic interaction of the metaphor recognition program. The core objective of the MIP-SI module is to enable semantic interaction between the target word and its context. This module achieves this by using the word-level semantic representation V of the target word. t The contextual semantic representation V of the target word(s,t) Concatenate to form a joint semantic representation V MIP . Then V MIP is input into a fully connected layer (FC2) to further extract local interaction features h MIP .
[0038] V MIP = Concat(V (s,t) , V t )
[0039] h MIP = FC2(V MIP )
[0040] where the definition
[0041] Finally, h SPV and h MIP are concatenated to form a joint semantic representation h S , which is the final semantic representation of the sentence S. This joint semantic representation integrates the semantic interaction information between the target word and the sentence, as well as the semantic interaction information between the target word and the target word context, providing rich feature representation for subsequent recognition.
[0042] h S = Concat(h SPV , h MIP )
[0043] where
[0044] As an improvement of the invention, step 5: model joint loss training, according to the design of the previous 4 steps, the invention proposes a combined loss function, which combines Cross-Entropy Loss and Triplet Loss, aiming to optimize the classification performance of the model and the learning of the embedding space at the same time, thereby enhancing the recognition ability of the model for metaphorical expressions. The implementation of this step can be divided into the following sub-steps:
[0045] Sub-step 5-1, Cross-Entropy Loss. Cross-Entropy Loss is a widely used loss function in classification tasks, used to measure the difference between the model's predicted probability distribution and the true label distribution. In this invention, the Cross-Entropy Loss is calculated by concatenating the semantic representations of the positive example, anchor sentence and negative example.
[0046] Specifically, for the semantic representation of the positive example h P , the semantic representation of the anchor sentence h A and the semantic representation of the negative example h N , concatenate the three semantic representations to form a joint semantic representation hcomined .
[0047] h comined = Concat(h P , h A , h N )
[0048] where, Then, h comined is input into the classifier to obtain the predicted probability distribution y pred , and the cross-entropy loss
[0049]
[0050] where y true is the true label, taking values 0 or 1. y pred is the probability that the model predicts the target word to be a metaphorical expression, taking values in the range [0, 1].
[0051] Sub-step 5-2, Triplet Loss. The anchor-based pair loss function is a commonly used loss function in metric learning, which aims to pull the distance between the positive example and the anchor sample in the embedding space, while pushing the distance between the negative example and the anchor sample. The expression of anchor-based pair loss is:
[0052]
[0053] where, denotes the square of the Euclidean distance. h P , h A and h N represent the positive example, anchor sample and negative example, respectively. α is a preset hyperparameter for controlling the minimum distance interval between the positive example and the negative example. max represents the maximum value operation.
[0054] Sub-step 5-3, combined loss. In order to optimize the classification performance of the model and the learning of the embedding space at the same time, the present application combines the cross-entropy loss and the anchor-based pair loss to form a combined loss function
[0055]
[0056] where λ c and λ tri are hyperparameters for balancing the weights of cross-entropy loss and anchor-based pair loss.
[0057] By combining the loss function, the model can accurately construct the anchor-based double example group closely related to the semantic context during the training process, significantly enhance the model's grasp of the sentence semantic structure, and more accurately capture the semantic changes of the target word in different contexts, thereby providing more rich semantic information basis for metaphor detection. On this basis, the designed context semantic learning mechanism can perform multi-granularity semantic learning on the target word, and accurately evaluate the consistency between the target word features and the overall context features of the text, and the coherence between the context features of the target word and its potential use features, thereby determining whether the target word contains a metaphor, enhancing the model's metaphor recognition ability, and thereby improving the effect of various natural language processing tasks related to metaphor recognition (such as metaphor expression recognition in machine translation, metaphor viewpoint analysis in news public opinion analysis, metaphor demand analysis in intelligent customer service dialogue, metaphor semantic mining in text intelligent review, etc.), enhancing the practical value of various text analysis systems and optimizing the landing performance of intelligent language models.
[0058] An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the metaphor recognition method based on anchor-based double examples and multi-theory semantic interaction when executing the program.
[0059] A storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the metaphor recognition method based on anchor-based double examples and multi-theory semantic interaction.
[0060] Compared with the prior art, the advantages of the present application are as follows:
[0061] (1) The present application introduces a metaphor recognition method based on anchor-based double examples and multi-theory semantic interaction, which accurately constructs a semantic-related anchor-based double example group and consolidates the semantic information foundation. The model can accurately construct a semantic context closely related anchor-based double example group composed of anchor points, positive examples, and negative examples during training, which can significantly enhance the understanding of sentence semantic structure, and deeply explore the semantic relationship between the subject, relationship, and object of the sentence. At the same time, it can more accurately capture the semantic changes of the target word in different contexts, and provide rich semantic information support for metaphor detection.
[0062] (2) The present application integrates multi-granularity semantic learning and multi-theory interaction evaluation, and deepens semantic feature analysis. The context semantic learning mechanism designed by the model can perform multi-granularity semantic learning on the target word, and accurately evaluate the consistency between the target word features and the overall context features of the text, and the coherence between the context features of the target word and its potential use features, providing deep analysis basis for metaphor judgment.
[0063] (3) This invention can effectively improve the metaphor recognition capability of the model, optimize the detection effect, and significantly enhance the practical value of various natural language processing related systems: effectively avoid metaphor translation bias in machine translation tasks, ensure accurate cross-language conversion of literary and commercial texts; help intelligent customer service quickly understand users' metaphorical needs and provide targeted solutions; accurately identify hidden metaphorical viewpoints, quickly analyze and resolve news and public opinion; avoid various legal disputes caused by metaphorical expressions, etc. The improvement of metaphor recognition capability enhances the practical value of various text analysis systems and optimizes the performance of language models developed based on intelligent agents. It is not a purely theoretical innovation, but has a clear protected object attribute. Attached Figure Description
[0064] Figure 1 This is an overall model diagram of an embodiment of the present invention;
[0065] Figure 2 This is a flowchart illustrating the method processing of an embodiment of the present invention. Detailed Implementation
[0066] To enhance understanding of the present invention, the invention will be further explained below with reference to specific embodiments.
[0067] Example 1: A metaphor recognition method based on anchor-based biexamples and multi-theory semantic interaction significantly enhances the model's grasp of sentence semantic structure by constructing a biexample paradigm combination structure of positive examples, anchor sentences, and negative examples. Furthermore, by introducing a comparison mechanism between positive and negative examples, it accurately captures the semantic changes of target words in different contexts, thus providing a richer semantic information foundation for metaphor detection. In addition, a dual-theory semantic interaction module is designed to analyze the extracted anchor-based biexample paradigms to determine whether the target words in the sentence contain metaphors. The "Selection Preference Violation Theory (SPV)" is used to evaluate the consistency between target word features and the overall contextual features of the text. Based on this, the "Metaphor Recognition Procedure Theory (MIP)" is integrated to evaluate the coherence between the contextual features of the target words and their potential usage features, thereby determining whether the target words contain metaphors.
[0068] For the specific model, please refer to [link / details]. Figure 1 The detailed implementation steps are as follows:
[0069] Step 1: Metaphorical Text Normalization. First, web scraping and data preprocessing techniques are used to obtain a dataset containing metaphors. This dataset is then normalized so that each data set contains a sentence S and a specific target word t. The purpose is to determine whether the target word in the sentence possesses a special metaphorical expression.
[0070] Step 2: Anchor-based biexample construction. By constructing combinations of positive examples, anchor sentences, and negative examples, the model's ability to learn the metaphorical features of the target word is enhanced. For the anchor-based biexample paradigm (S...P ,S A ,S N ) is constructed, assuming S1 = {"Fear", "seized", "the", "prisoners"} and t = {"seized"},
[0071] then the positive example S P is defined as the original sentence containing the target word t, which aims to provide the complete semantic information of the target word in the original context. Therefore, the positive example S p = S1. The anchor sentence S A is generated by replacing the target word t in the positive example S P with a placeholder "[Mask]". The construction of the anchor sentence aims to provide the location information of the target word in the context while removing the semantic information of the target word itself. Therefore, the anchor sentence S A corresponding to S1 is S1 = {"Fear", "[Mask]", "the", "prisoners"}.
[0072] The negative example S N is the sentence that is most similar to the anchor sentence S A but expresses the opposite metaphorically, aiming to provide a sentence that is in sharp contrast to the positive example S P in semantic information. According to the anchor sentence S A = {"Fear", "[Mask]", "the", "prisoners"}, the sentence S2 = {"The", "prisoner", "[Mask]", "at", "the", "chains"} is found in the dataset that is most similar to it but expresses the opposite metaphorically, and then the original sentence S3 = {"The", "prisoner", "tugged", "at", "the", "chains"} of S2 is obtained as the negative example S A of the anchor sentence S N . In this example, the target word "seized" in the positive example S P is a metaphorical expression in the sentence, while the target word "tugged" in S N is a non-metaphorical expression in the sentence. At this point, the anchor-based double example group paradigm (S P , S A , S N ) can be constructed as the input of the model.
[0073] Step 3: Contextual semantic learning, using the anchor-based double-instance paradigm obtained in step 2, a RoBERTa model is used to construct three key semantic representations: word-level semantic representation of target word, sentence-level semantic representation of target word, and contextual semantic representation of target word. The three semantic representations capture the semantic information of the target word itself, the context information of the target word in the sentence, and the semantic information of the entire sentence, providing rich semantic features for subsequent metaphor recognition. The implementation of this step can be divided into the following sub-steps:
[0074] Sub-step 3-1, word-level semantic representation of target word. This semantic representation aims to eliminate contextual interference and capture the inherent semantic features of the target word. First, by performing tokenization on the target word t, the input sequence X t is obtained. Subsequently, the input sequence X t is input into the RoBERTa model to obtain the hidden state H t of the last layer. Finally, the mean value of the last layer hidden state is calculated to obtain the word-level semantic representation V t of the target word:
[0075] X t = tokenizer(t)
[0076] H t = RoBERTa(X t )
[0077]
[0078] where |H t | represents the length of the hidden state. In addition, define and where m is the length of the tokenized sequence X t and d is the hidden layer dimension of the RoBERTa model.
[0079] Sub-step 3-2, sentence-level semantic representation of target word. It represents the complete semantic information by capturing the global semantic structure of the sentence. First, by performing tokenization on the sentence S, the input sequence X S is obtained. Subsequently, the sequence X S is input into the RoBERTa model to obtain the hidden state H S of the last layer. Finally, the semantic representation of the [CLS] token is extracted as the sentence-level semantic representation V S of the target word:
[0080] X S = tokenizer(S)
[0081] H s = RoBERTa(XS )
[0082]
[0083] wherein, denotes the hidden state corresponding to the [CLS] token. Furthermore, define where n is the length of the tokenized sequence X S .
[0084] Sub-step 3-3, Contextual Semantic Representation of Target Word. This semantic representation is used to represent the contextual information of the target word in the sentence. First, locate the position k of the target word t in the sentence, and then extract the corresponding semantic representation V (s,t) of t in the sentence S according to k:
[0085] k = index(X t , X S )
[0086]
[0087] wherein, define denotes the contextual semantic representation of the target word. The function index() is used to find the position of t in S.
[0088] As an improvement of the present application, Step 4: Multi-theory Semantic Interaction Learning, uses the semantic representation of the target word learned in Step 3 to explore its interactive semantics in the context of the sentence. The present application designs two semantic interaction modules: Selectional Preference Violation Semantic Interaction (SPV-SI) and Metaphor Identification Procedure Semantic Interaction (MIP-SI). These two modules enhance the semantic representation of the target word from different angles, thereby improving the model's ability to recognize metaphorical expressions. The implementation of this step can be divided into the following sub-steps:
[0089] Sub-step 4-1, Selectional Preference Violation Semantic Interaction. The core goal of the SPV-SI module is to perform semantic interaction between the context of the target word and the sentence. This module concatenates the sentence-level semantic representation V S of the target word and the contextual semantic representation V (s,t) of the target word to form a joint semantic representation V SPV . Then input V SPV into the fully connected layer (FC1) to further extract global interaction features h SPV.
[0090] V SPV = Concat(V S , V (s,t) )
[0091] h SPV = FC1(V SPV )
[0092] where Concat() denotes the concatenation operation. In addition, we define
[0093] Sub-step 4-2, Metaphor Identification Program Semantic Interaction. The core goal of the MIP-SI module is to perform semantic interaction between the target word and the target word context. This module forms a joint semantic representation V t by concatenating the word-level semantic representation V (s,t) of the target word and the context semantic representation V MIP of the target word. V MIP is then input into a fully connected layer (FC2) to further extract local interaction features h MIP .
[0094] V MIP = Concat(V (s,t) , V t )
[0095] h MIP = FC2(V MIP )
[0096] where we define
[0097] Finally, h SPV and h MIP are concatenated to form a joint semantic representation h S , which is the final semantic representation of the sentence S. This joint semantic representation integrates the semantic interaction information between the context of the target word and the sentence, as well as the semantic interaction information between the target word and the target word context, providing rich feature representation for subsequent identification.
[0098] h S = Concat(h SPV , h MIP )
[0099] where
[0100] Step 5: Model Joint Loss Training. Based on the design of the previous four steps, the present invention proposes a combined loss function that integrates Cross-Entropy Loss and Triplet Loss, aiming to optimize both the classification performance of the model and the learning of the embedding space, thereby enhancing the model's ability to recognize metaphorical expressions. The implementation of this step can be divided into the following sub-steps:
[0101] Sub-step 5-1, Cross-Entropy Loss. Cross-Entropy Loss is a widely used loss function in classification tasks, used to measure the difference between the model's predicted probability distribution and the true label distribution. In this invention, the Cross-Entropy Loss is calculated by concatenating the semantic representations of the positive example, anchor sentence, and negative example.
[0102] Specifically, for the semantic representation of the positive example h P , the semantic representation of the anchor sentence h A , and the semantic representation of the negative example h N , these three semantic representations are concatenated to form a joint semantic representation h comined .
[0103] h comined =Concat(h P ,h A ,h N )
[0104] where, Subsequently, h comined is input into the classifier to obtain the predicted probability distribution y pred , and the Cross-Entropy Loss is calculated as
[0105]
[0106] where y true is the true label, taking values of 0 or 1. y pred is the probability that the model predicts the target word to be a metaphorical expression, taking values in the range [0, 1].
[0107] Sub-step 5-2, Triplet Loss. Anchor-based pair group loss function is a commonly used loss function in metric learning, aiming to pull the distance between the positive example and the anchor sample closer in the embedding space, while pushing the distance between the negative example and the anchor sample farther away. The expression of the anchor-based pair group loss is:
[0108]
[0109] where, represents the square of the Euclidean distance. h P , h A , and hN respectively represent positive samples, anchor samples and negative samples. α is a preset hyperparameter for controlling the minimum distance interval between positive and negative examples. max represents the maximum value operation.
[0110] Sub-step 5-3, combining loss. In order to optimize the classification performance of the model and the learning of the embedding space at the same time, the present application combines the cross-entropy loss and the anchor-based double-instance group loss to form a combined loss function
[0111]
[0112] wherein λ c and λ tri are hyperparameters for balancing the weights of the cross-entropy loss and the anchor-based double-instance group loss.
[0113] Through the combined loss function, the model can accurately construct anchor-based double-instance groups closely related in semantic context during the training process, significantly enhance the model's grasp of the semantic structure of the sentence, and more accurately capture the semantic changes of the target word in different contexts, thereby providing a more rich semantic information basis for metaphor detection. On this basis, the designed context semantic learning mechanism can perform multi-granularity semantic learning on the target word, and accurately evaluate the consistency between the target word features and the overall context features of the text and the coherence between the context features of the target word and its potential use features, so as to determine whether the target word contains a metaphor, enhance the metaphor recognition ability of the model, and thus improve the effect of various natural language processing tasks related to metaphor recognition (such as metaphor expression recognition in machine translation, metaphor viewpoint analysis in news public opinion analysis, metaphor demand analysis in intelligent customer service dialogue, metaphor semantic mining in text intelligent review, etc.), enhance the practical value of various text analysis systems, and optimize the landing performance of intelligent language models.
[0114] Based on the same inventive concept, the metaphor recognition method and device based on anchor-based double instances and multi-theory semantic interaction of the present application include a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is loaded into the processor, the above-mentioned method for metaphor recognition based on anchor-based double instances and multi-theory semantic interaction is implemented.
[0115] Those skilled in the art will appreciate that the embodiments described herein are intended to aid the reader in understanding the principles of the present application and should not be used to limit the scope of the present application, and that modifications to the various embodiments of the present application made by those skilled in the art after reading the present application fall within the scope defined by the claims of the present application.
Claims
1. A metaphor recognition method based on anchor-based bitonality and multi-theory semantic interaction, characterized in that, The method includes the following steps: Step 1: Metaphorical text normalization; Step 2: Constructing the anchorage double-instance group; Step 3: Contextual semantic learning; Step 4: Multi-theoretical semantic interactive learning; Step 5: Training the joint loss of the model.
2. The metaphor recognition method based on anchor-based bitonality and multi-theory semantic interaction according to claim 1, characterized in that, Step 1: Metaphorical text normalization. First, web crawling and data preprocessing techniques are used to obtain a dataset containing metaphors. The dataset is then normalized so that each data set contains a sentence S and a specific target word t. The purpose is to determine whether the target word in the sentence has a special metaphorical expression.
3. The metaphor recognition method based on anchor-based bitonality and multi-theory semantic interaction according to claim 1, characterized in that, Step 2: Anchor-based pair construction. By constructing combinations of positive examples, anchor sentences, and negative examples, the model's ability to learn the metaphorical features of the target word is enhanced. For the anchor-based pair paradigm (S... P ,S A ,S N Construct a system, assuming S1 = {"Fear", "seized", "the", "prisoners"}, t = {"seized"}, then the positive examples S P Defined as the original sentence containing the target word t, its purpose is to provide complete semantic information about the target word in the original context, therefore, positive example S p =S1, anchor sentence S A It is by passing positive example S P The sentence generated after replacing the target word 't' with the placeholder "[Mask]" is an anchor sentence designed to provide the positional information of the target word in the context while removing the semantic information of the target word itself. Therefore, the anchor sentence S1 corresponds to S1. A ={"Fear","[Mask]","the","prisoners"}, Negative Example S N Is it related to anchor sentence S? A The sentence that is most similar but has the opposite metaphorical expression is intended to provide semantic information that can be compared with the positive example S. P Sentences that create a stark contrast, based on anchor sentence S A ={"Fear","[Mask]","the","prisoners"}, find the sentence S2 = {"The","prisoner","[Mask]","at","the","chains"} with the highest similarity but opposite metaphorical meaning in the dataset, and then obtain the original sentence S3 = {"The","prisoner","tugged","at","the","chains"} as the anchor sentence S. A Negative example S N In this example, the positive example S P The target word "seized" in the sentence is used metaphorically, while S N The target word "tugged" in the sentence is a non-metaphorical expression; therefore, the anchor-based bi-example paradigm (S) can be constructed. P ,S A ,S N () is used as the input to the model.
4. The metaphor recognition method based on anchor-based bitonality and multi-theory semantic interaction according to claim 1, characterized in that, Step 3: Contextual semantic learning. Utilizing the anchor-based bi-example paradigm obtained in Step 2, three key semantic representations are constructed using the RoBERTa model: word-level semantic representation of the target word, sentence-level semantic representation of the target word, and contextual semantic representation of the target word. These three semantic representations capture the semantic information of the target word itself, the contextual information of the target word in the sentence, and the semantic information of the entire sentence, respectively, providing rich semantic features for subsequent metaphor recognition. This step is implemented in the following sub-steps: Sub-step 3-1 involves word-level semantic representation of the target word. This semantic representation aims to eliminate contextual interference and capture the inherent semantic features of the target word. First, the target word t is segmented to obtain the input sequence X. t Then, the input sequence X will be... t The input is fed into the RoBERTa model to obtain the hidden state H of the last layer. t Finally, by calculating the mean of the last hidden state, the word-level semantic representation V of the target word is obtained. t : X t =tokenizer(t) H t =RoBERTa(X t ) Among them, |H t | indicates the length of the hidden state; additionally, it defines... as well as Where m is the sequence X after word segmentation. t The length of , where d is the hidden layer dimension of the RoBERTa model. Sub-step 3-2, sentence-level semantic representation of the target word, represents the complete semantic information by capturing the global semantic structure of the sentence. First, the sentence S is segmented to obtain the input sequence X. S Then, sequence X S The input is fed into the RoBERTa model to obtain the hidden state H of the last layer. S Finally, the semantic representation of the [CLS] tag is extracted as the sentence-level semantic representation V of the target word. S : X S =tokenizer(S) H s =RoBERTa(X S ) in, This indicates the hidden state corresponding to the [CLS] flag. Additionally, it defines... Where n is the sequence X after word segmentation. S Length, Sub-step 3-3 involves the contextual semantic representation of the target word. This semantic representation is used to represent the contextual information of the target word in the sentence. First, the position k of the target word t in the sentence is located. Then, based on k, the semantic representation V of t in sentence S is extracted. (s,t) : k=index(X t ,X S ) Among them, the definition The contextual semantic representation of the target word is represented by the index() function, which is used to find the position of t in S.
5. The metaphor recognition method based on anchor-based bitonality and multi-theory semantic interaction according to claim 1, characterized in that, Step 4: Multi-theory Semantic Interaction Learning. Utilizing the semantics of the target words learned in Step 3, this step explores their interactive semantics within the sentence context. Two semantic interaction modules are designed: Selectional Preference Violation Semantic Interaction (SPV-SI) and Metaphor Identification Procedure Semantic Interaction (MIP-SI). The implementation of this step consists of the following sub-steps: Sub-step 4-1, selecting preferences violates semantic interaction. The core objective of the SPV-SI module is to enable semantic interaction between the target word's context and the sentence. This module achieves this by using the sentence-level semantic representation V of the target word. S The contextual semantic representation V of the target word (s,t) The components are concatenated to form a joint semantic representation V. SPV Then V SPV The input is fed into a fully connected layer (FC1) to further extract global interaction features h. SPV , In SPV =Concat(V S ,V (s,t) ) h SPV =FC1(V SPV ) Where Concat() represents the concatenation operation, defined as follows: Sub-step 4-2, semantic interaction of the metaphor recognition program. The core objective of the MIP-SI module is to perform semantic interaction between the target word and its context. This module achieves this by using the word-level semantic representation V of the target word. t The contextual semantic representation V of the target word (s,t) The components are concatenated to form a joint semantic representation V. MIP Then V MIP The input is fed into a fully connected layer (FC2) to further extract local interaction features h. MIP , In MIP =Concat(V (s,t) ,V t ) h MIP =FC2(V MIP ) Among them, the definition Finally, h SPV and h MIP The components are concatenated to form a joint semantic representation h. S As the final semantic representation of sentence S, this joint semantic representation integrates the semantic interaction information between the target word's context and the sentence, as well as the semantic interaction information between the target word and its context, providing rich feature representations for subsequent recognition. h S =Concat(h SPV ,h MIP ) in 6. The metaphor recognition method based on anchor-based bitonality and multi-theory semantic interaction according to claim 1, characterized in that, Step 5: Joint loss training of the model. This step is divided into the following sub-steps: Sub-step 5-1, Cross-Entropy Loss, is as follows: for the semantic representation h of the positive example... P The semantic representation of anchor sentences is h A The semantic representation h of negative examples N These three semantic representations are concatenated to form a joint semantic representation h. comined , h comined =Concat(h P ,h A ,h N ) in, Then, h comined The input is fed into the classifier to obtain the predicted probability distribution y. pred And calculate the cross-entropy loss. Among them, y true These are real labels, with values of 0 or 1, y pred It is the probability that the target word predicted by the model is a metaphorical expression, and its value ranges from [0,1]. Sub-step 5-2, Triplet Loss, the expression for the anchor-based biplex loss is: in, h represents the square of the Euclidean distance. P h A and h N These represent positive samples, anchor samples, and negative samples, respectively. α is a preset hyperparameter used to control the minimum distance interval between positive and negative samples, and max indicates the operation of taking the maximum value. Sub-step 5-3, Combining Loss: This step combines the cross-entropy loss and the anchor-based bi-instance loss to form a combined loss function. Where, λ c and λ tri It is a hyperparameter used to balance the weights of cross-entropy loss and anchor-based two-instance loss. By combining loss functions, the model can accurately construct anchor-based pairs closely related to semantic context during training, significantly enhancing the model's grasp of sentence semantic structure. It also more accurately captures the semantic changes of target words in different contexts, thus providing a richer semantic information foundation for metaphor detection. Based on this, the designed contextual semantic learning mechanism can perform multi-granular semantic learning on target words and accurately evaluate the consistency between target word features and the overall text context features, as well as the coherence between the contextual features of the target word and its potential usage features, based on multi-theoretical semantic interaction learning. This determines whether the target word contains a metaphor, enhances the model's metaphor recognition ability, and improves the performance of various metaphor-related natural language processing tasks (such as metaphor expression recognition in machine translation, metaphor viewpoint analysis in news sentiment analysis, metaphor demand analysis in intelligent customer service dialogue, and metaphor semantic mining in intelligent text review). This enhances the practical value of various text analysis systems and optimizes the implementation performance of intelligent language models.
7. 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 metaphor recognition method based on anchor-based bitonal and multi-theory semantic interaction as described in any one of claims 1 to 6.
8. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the metaphor recognition method based on anchor-based bitonal and multi-theory semantic interaction as described in any one of claims 1 to 6.