Noun metaphor identification method based on large language model and graph neural network

Through the method based on large language model and graph neural network, the problems of shortage of data resources and insufficient semantic representation in Chinese noun metaphor recognition are solved, and higher recognition accuracy and understanding of complex contexts are achieved.

CN119646227AActive Publication Date: 2025-03-18DALIAN UNIV OF TECH

Patent Information

Application Number
CN202411861877.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-17
Publication Date
2025-03-18
Estimated Expiration
2044-12-17

AI Technical Summary

Technical Problem

The prior art faces the problems of data resource shortage, insufficient semantic representation and difficult context modeling in the recognition of Chinese noun metaphor, resulting in low recognition accuracy.

Method used

The noun metaphor recognition method based on large language model and graph neural network is adopted to generate diversified corpus through data augmentation and distillation, and deep semantic modeling is used to construct semantic graphs based on dependent syntax and PMI information. The graph convolution network is used to update node features, and finally noun metaphor classification is performed.

Benefits of technology

It significantly improves the accuracy of noun metaphor recognition, reduces the dependence on large-scale annotation data, and can more effectively capture metaphorical information in complex contexts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119646227A_ABST
    Figure CN119646227A_ABST
Patent Text Reader

Abstract

A noun metaphor recognition method based on a large language model and a graph neural network belongs to the technical field of natural language processing, is used for accurately recognizing the purpose of a noun metaphor, and is characterized in that a to-be-processed text is input into a trained preprocessing model, and the preprocessing model outputs first feature representation; constructing a semantic graph of the to-be-processed text according to the syntactic dependency relationship and the point mutual information; inputting the first feature representation and the semantic graph into the trained graph convolutional network, wherein the graph convolutional network outputs a second feature representation; the second feature representation is classified through a classifier to obtain a noun metaphor recognition result in the to-be-processed text, the metaphor recognition accuracy is remarkably improved, and the method has wide application potential.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of natural language processing, and relates to a large language model and deep learning natural language processing, and specifically to a noun metaphor recognition model based on a large language model and a graph neural network, and the training of the model. Background Art

[0002] Conceptual metaphor theory believes that metaphor is a cognitive process of understanding unknown concepts with known concepts, and its working mechanism is mapping from the source domain to the target domain of unknown concepts. Humans encounter many complex concepts that are difficult to describe in the cognitive process. At this time, they will use other known concepts to understand and construct complex unknown concepts through metaphors. For example, in the metaphor "efficiency is life", "life" is used to explain the concept of "efficiency", and the attributes of "life" such as "precious" are extended to the concept of "efficiency" through mapping. The basic expression of metaphor mapping is "X is Y", where X represents an unknown concept and Y represents a known concept. When we say "X is Y", that is, use Y to construct concept X, we are mapping the conceptual structure of Y onto X. In fact, X maps only part of the attributes of Y, not all of them. As for which part of the attributes of Y the mapping is related to, it is determined by factors such as experience, knowledge, culture, and context.

[0003] For example, the mapping included in the conceptual metaphor "the camera lens is money" is shown in Table 1. The property of money is mapped to the lens. That is, according to common sense, the precious property should be mapped to the lens to describe the value of the lens.

[0004] Table 1 Examples of noun metaphors

[0005]

[0006] Currently, there are few data resources available for metaphor identification: The data resource shortage problem faced by existing research on Chinese noun metaphor identification is mainly manifested in the small size of the data set, the difficulty of annotation, and the lack of data diversity. Since metaphors are complex in expression and depend on context and cultural background, annotating metaphor data is not only time-consuming and laborious, but also easily affected by subjective factors, making it difficult to ensure the consistency and accuracy of annotation.

[0007] Current semantic representations for metaphor recognition are insufficient: Existing models generally rely on simple feature engineering, external semantic resources (such as WordNet, FrameNet), and shallow deep learning methods, resulting in overly simplistic semantic representations and a lack of deep understanding of metaphor complexity, implicit expressions, and cross-domain mappings. These methods have difficulty effectively capturing the difference between literal and metaphorical meanings, especially when dealing with ambiguous or polysemous expressions, and have low accuracy. For noun metaphors, there is no direct connection between the source domain and the target domain, and the mapping relationship cannot be fully represented.

[0008] Current context modeling issues for metaphor recognition: Although some deep learning models (such as Bi-LSTM) attempt to capture the sequential and contextual characteristics of metaphors, these models still fall short when dealing with long-range dependencies and complex contexts. The meaning of a metaphor is often closely related to the context, requiring a deep understanding of the cross-domain mapping relationship between the source and target domains. However, existing models are insufficient in capturing this fine-grained information, especially in cross-domain mapping and multi-level semantic fusion. Summary of the invention

[0009] In order to solve the problem of accurately identifying noun metaphors, in a first aspect, a noun metaphor recognition method based on a large language model and a graph neural network according to some embodiments of the present application is used for a metaphor recognition model, the metaphor recognition model includes a preprocessing model and a graph convolution model, and the recognition method includes the following steps:

[0010] training the metaphor recognition model;

[0011] Inputting the text to be processed into the trained preprocessing model, and the preprocessing model outputs a first feature representation;

[0012] Constructing a semantic graph of the text to be processed according to syntactic dependencies and point mutual information;

[0013] Inputting the first feature representation and the semantic graph into the trained graph convolutional network, and the graph convolutional network outputs a second feature representation;

[0014] The second feature representation is classified by a classifier to obtain a noun metaphor recognition result in the text to be processed.

[0015] According to some embodiments of the present application, the noun metaphor recognition method based on a large language model and a graph neural network, wherein the training of the metaphor recognition model in the step includes:

[0016] Performing data augmentation on the first data set by using the first large language model to construct a second data set;

[0017] Performing data distillation on the second data set through a second language model to construct a third data set;

[0018] Inputting the third data set into a preprocessing model, the preprocessing model outputting a first feature representation;

[0019] Constructing a semantic graph of the third data set according to syntactic dependencies and point mutual information;

[0020] Inputting the first feature representation and the semantic graph into a graph convolutional network, and the graph convolutional network outputs a second feature representation;

[0021] The second feature representation is classified by a classifier.

[0022] According to the noun metaphor recognition method based on a large language model and a graph neural network in some embodiments of the present application, the first data set contains Chinese sentences containing noun metaphors or Chinese sentences containing non-noun metaphors, which are represented by the following formula:

[0023] Data Input ={Sentence}

[0024] In the formula, Sentence represents a Chinese sentence containing a noun metaphor or a Chinese sentence containing a non-noun metaphor;

[0025] The prompts for the first language model in the data augmentation, wherein the sentence Data containing noun metaphors Input The prompt is expressed as follows:

[0026] Sentences metaphor =Qwen(Data Input +"Generate five similar sentences containing noun metaphors")

[0027] In the formula, Sentences metaphor Represents a sentence containing a noun metaphor Data Input The expanded sentence of

[0028] The prompts for the first language model in the data augmentation, wherein the sentence Data that does not contain noun metaphors Input The prompt is expressed as follows:

[0029] Sentences non-metaphor =Qwen(Data Input +"Generate five similar sentences that do not contain noun metaphors")

[0030] In the formula, Sentences non-metaphor Represents a sentence that does not contain a noun metaphor Data Input The expanded sentence of

[0031] The second data set includes Sentences metaphor And Sentences non-metaphor ;

[0032] The prompts for the second largest language model in the data distillation, where the sentence Data containing noun metaphors Input And its augmented sentences metaphor The prompt is:

[0033] Verificationmetaphor = ChatGLM(Sentences metaphor ,"Are all of them noun metaphors?"

[0034] The prompts for the second largest language model in the data distillation, where Data Input And its augmented sentences non-metaphor The prompt is expressed as follows:

[0035] Verification non-metaphor = ChatGLM(Sentences non-metaphor ,"Are all of them not noun metaphors?"

[0036] If the answer to the prompt is yes, then the third data set is represented by the following formula:

[0037] Final data =Verification metaphor +Verification non-metaphor

[0038] If the answer to the prompt is no, then the sentence Data containing the noun metaphor Input And its augmented sentences metaphor The sentence that is not a noun metaphor is deleted from the sentence, which is represented by the following formula:

[0039] Filtered metaphor = ChatGLM(Sentences metaphor ,"Delete sentences that are not noun metaphors")

[0040] If the answer to the prompt is no, then the sentence Data that does not contain noun metaphors Input And its augmented sentences non-metaphor The sentence in which the noun metaphor is deleted is represented by the following formula:

[0041] Filtered non-metaphor = ChatGLM(Sentences non-metaphor ,"Delete the sentence that is a noun metaphor")

[0042] Then the third data set is expressed by the following formula:

[0043] Final data =Filtered metaphor +Filtered non-metaphor

[0044] In the formula, Finaldata The third dataset;

[0045] Preferably, the first large language model includes a Qwen model, the second large prediction model includes a ChatGLM model, and the preprocessing model includes an ERNIE model.

[0046] According to some embodiments of the present application, the noun metaphor recognition method based on a large language model and a graph neural network, wherein the step of inputting the third data set into a preprocessing model, and the preprocessing model outputting a first feature representation, comprises the following steps:

[0047] S310. Finalizing the third data set data The sentences in are segmented, and the words after segmentation are {w1,w2,…,wn}. Each word generates a pre-trained word embedding E(wi), which is expressed as follows:

[0048] E(w i )=Embedding(wi)

[0049] S320. Perform position encoding on the word, wherein the position encoding is represented by P(i), which is represented by the following formula:

[0050]

[0051] In the formula, i is the position information of the word, j is the dimension of the position encoding, and d is the embedding dimension;

[0052] S330. Transform the word vector H 0 (i) The weighted sum of the values ​​of each word is obtained through the attention mechanism and the context features are weighted aggregated. The output of each attention head is concatenated and mapped back to the model dimension through linear transformation to obtain the multi-head attention mechanism output MultiHead(Q, K, V);

[0053] Among them, the word vector H of each word 0 (i), is represented by the following formula:

[0054] H 0 (i) = E(w i )+P(i);

[0055] S340. The output of each layer is normalized by layer normalization, which is expressed as follows:

[0056] H L =LayerNorm(H 0 (i)+MultiHead(Q,K,V))

[0057] S350. Output the first feature representation, which is represented by the following formula:

[0058] H final =H L

[0059] In the formula, H final Represents the first feature representation.

[0060] According to some embodiments of the present application, the noun metaphor recognition method based on a large language model and a graph neural network, wherein in step S330, a multi-head attention mechanism outputs MultiHead(Q, K, V), comprising the following steps:

[0061] S331. Input word vector H 0 (i) Using different W Q , W K , W V Generate multiple Q, K, V, and perform attention calculation on each head independently to obtain Attention1, Attention2, .....Attentionh;

[0062] S332. Splice the output of each head and transform it by linear transformation W O Mapping back to the dimensions of the model is represented by the following formula:

[0063] MultiHead(Q,K,V)=Concat(Attention 1 ,Attention 2 ,…,Attention h )W O

[0064] In the formula, MultiHead(Q,K,V) means, represents the linear transformation matrix, d model represents the dimension of the model, h represents the number of heads, and d v Represents the dimensions of a single head;

[0065] The calculation of Attention in step S331 includes the following steps:

[0066] S3311. Transform the word vector H 0 (i) Enter the attention mechanism, from the word vector H 0 In (i), the query, key, and value matrices are generated through linear transformation, which are expressed as follows:

[0067] Q=H 0 (i)W Q ,K=H 0 (i)W K ,V=H 0 (i)WV

[0068] In the formula, Respectively represent the query projection matrix, key projection matrix, and value projection matrix; Represent the query matrix, key matrix, and value matrix respectively;

[0069] S3312. Calculate the similarity score Score(i,j) between the query matrix Q and the key matrix K, which is expressed by the following formula:

[0070]

[0071] In the formula, Q i represents the query vector of the i-th word, K j represents the key vector of the j-th word, the similarity score Score(i,j) represents the strength of the relationship between position i and position j, and the superscript (t) represents the calculation of the t-th head in the multi-head attention mechanism;

[0072] S3313. Integrate the scores of all positions into a matrix form, represented by the following formula:

[0073] Scores = QK T

[0074] In the formula, represents the similarity score of each position in the sentence to all other positions, and n represents the number of words;

[0075] S3314. Scale the similarity score as follows:

[0076]

[0077] S3315. Calculate the weighted sum of the value of each word, expressed by the following formula:

[0078]

[0079] In the formula, the molecule It means converting the correlation score of the i-th position to the j-th position into a positive value, and the denominator is represents the sum of all relevance scores in the i-th row for normalization;

[0080] S3316. Add the weighted sum of the values ​​of each word to a ij For the weighted value matrix V j , weighted aggregation of context features is performed, which is expressed as follows:

[0081]

[0082] In the formula, n represents the number of words.

[0083] According to some embodiments of the present application, the noun metaphor recognition method based on a large language model and a graph neural network, wherein the step of constructing a semantic graph of the third data set according to syntactic dependencies and point mutual information includes the following steps:

[0084] S410. Finalizing the third data set data The sentences in the vocabulary building include

[0085] S411. Through S = {s 1 ,s 2 ,…,s N} indicates the third data set Final data A set of sentences in , where each sentence si contains a set of words;

[0086] S412. Split each sentence si into a series of words s i ={w i1 ,w i2 ,…,w ij}, where w ij Indicates sentence s i The jth word in ;

[0087] S420. Perform a union operation on the vocabulary sets in all sentences to obtain a vocabulary table, which is represented by the following formula:

[0088]

[0089] In the formula, vocab represents the vocabulary, U represents the union operation, and w ij represents the jth word in sentence si, and N represents the number of sentences;

[0090] S430. For each word w k ∈vocab, using word frequency word_freq(w k ) represents word w k The number of occurrences in all documents, traverse all documents, and count the frequency of each word. The frequency of each word in all documents is accumulated and recorded in the word frequency dictionary word_freq, which is expressed by the following formula:

[0091]

[0092] In the formula, is an indicator function, which indicates the result of conditional judgment. In the formula, if word wk appears in sentence S i In Otherwise, 0;

[0093] S440. Define a fixed-size context window, and calculate the number of co-occurrences of word pairs by traversing the words in the sentence, including

[0094] S441. The vocabulary sequence in sentence Si is Si = {w i1 ,w i2 ,…,w ij}, where j represents the number of words, the window size is window_size, for each word w in sentence Si ij , define its context window as:

[0095] window(w ij )={w ij-k ,w ij-k+1 ,…,w ij+k}

[0096] Where k is an integer from -window_size to window_size;

[0097] S442. For each word pair (w p ,w q ) appears in the context window, by maintaining a counting dictionary word_pair_count, recording each pair of vocabulary w p and w q The number of occurrences in the corpus is expressed as follows:

[0098] word_pair_count(w p ,w q )=word_pair_count(w p ,w q )+1

[0099] Where word_pair_count() represents the counting function, wp and wq are any pair of different words in the window;

[0100] S450. Calculate the weight of the edge between two points, where any two points are represented by any two words. If there is no syntactic dependency between the two points, the PMI value is used as the weight. If there is a syntactic dependency, the PMI value plus 10 is used as the weight.

[0101] Among them, the PMI calculation is as follows:

[0102]

[0103] Where word_pair_count(wi,wj) is the number of times the word pair (wi,wj) appears in the document, and N is the number of sentences, where:

[0104]

[0105] Among them, if there is a syntactic dependency, the PMI value plus 10 is used as the weight, which is expressed by the following formula:

[0106] PMI(w i ,w j )=PMI(w i ,w j )+10,if(w i ,w j )∈special_word_pairs

[0107] Where special_word_pairs is the set of syntactic dependency relationships between words obtained by spacy after calculating the syntactic dependency relationships.

[0108] According to some embodiments of the present application, the noun metaphor recognition method based on a large language model and a graph neural network, wherein the first feature representation and the semantic graph are input into a graph convolutional network, and the graph convolutional network outputs a second feature representation, including using an update formula of a graph convolutional network GCN, updating and optimizing the first feature representation through the semantic graph to aggregate neighbor features, and outputting a second feature representation, wherein the update formula is represented by the following formula:

[0109]

[0110] In the formula, H (L) is the node feature representation of the Lth layer, initially L=0, using H(0) output by the preprocessing model; N(i) is the set of neighbor nodes of node i, each node represents a word; is the adjacency matrix of the semantic graph, including self-connections, is the degree matrix of the node; is the Laplace normalization operation of the semantic graph; W (I) is the trainable parameter of layer I; σ() is the activation function; Represents the second feature representation.

[0111] According to the noun metaphor recognition method based on a large language model and a graph neural network in some embodiments of the present application, the second feature representation is passed through a linear layer W c and the bias term b c Classify and output a scalar y pred , which indicates the probability that the sample belongs to a certain category.

[0112]

[0113] In the formula, y predis the predicted output of the model, which indicates the probability that the input sentence belongs to a noun metaphor, and sigmoid() indicates the sigmoid function;

[0114] The loss function of the metaphor recognition model training is shown in the following formula:

[0115]

[0116] Where, LOSS all Represents the total loss, γ is a hyperparameter;

[0117] in:

[0118] Loss Ernie =-(y true log(y pred )+(1-y true )log(1-y pred ))

[0119] In the formula, Loss Ernie represents the loss of the preprocessing model, y true represents the true label, y pred represents the predicted output of the model;

[0120]

[0121] Where, L GCN represents the loss of the graph convolutional network, C represents the number of categories, and the superscript (c) represents the number of the current category.

[0122] In a second aspect, an embodiment of the present application further provides an electronic device, comprising: one or more processors, a memory, and one or more programs; wherein the one or more programs are stored in the memory, and the one or more programs include instructions, which, when executed by the electronic device, enable the electronic device to execute the first aspect and any possible technical solution of the first aspect.

[0123] In a third aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a computer program. When the computer program runs on an electronic device, the electronic device executes the first aspect and any possible technical solution of the first aspect.

[0124] Beneficial effects: The method of noun metaphor recognition based on a large language model and a graph neural network (GCN) of the present invention generates a diverse corpus and verifies its effectiveness through data augmentation and distillation, thereby reducing reliance on large-scale annotated data. The graph is established using dependency syntax and pointwise mutual information (PMI), and GCN learns the grammatical structure information in the sentence to improve the accuracy of metaphor recognition. At the same time, the ERNIE model captures the cross-domain mapping relationship between nouns through deep semantic modeling, and updates node features in combination with the graph structure information of the graph convolutional network to finally complete the noun metaphor classification. Experimental results show that this method significantly improves the accuracy of metaphor recognition and has broad application potential. Specifically:

[0125] (1) Data augmentation and distillation: First, the large language model Qwen-max is used to augment the dataset to generate a diverse corpus. Then, the augmented data is distilled using the large language model ChatGLM to extract high-quality training data. This process effectively reduces the reliance on large-scale annotated data, allowing the pre-trained model to be fine-tuned efficiently even when data is scarce.

[0126] (2) Training and cross-domain mapping based on Ernie: The expanded and distilled dataset is finally input into the Ernie model for training. Ernie can efficiently process long texts and integrate global context through the parallelization characteristics of its Transformer architecture, so as to accurately identify metaphors in complex contexts. At the same time, the recognition of metaphors not only depends on the literal meaning, but also involves cross-domain mapping between the source domain and the target domain. Ernie can capture this cross-domain relationship and combine external knowledge (such as knowledge graphs) to assist in judging the semantic connection between the source domain and the target domain. In addition, metaphor understanding also involves multi-level semantic features, such as grammatical structure, emotional color, and cultural background. Ernie effectively integrates this information through deep semantic modeling, significantly improving the accuracy and robustness of metaphor recognition.

[0127] (3) Graph convolutional network based on dependency syntax and PMI modeling: The present invention extracts the dependency syntax and PMI information of the sentence as the weights between the nodes, and constructs the corresponding graphs between sentences and words respectively. Dependency syntax reflects the direct grammatical relationship between words, and PMI reflects the statistics of the association strength between two words. The nodes are represented by Ernie outputs, and these graph structures are learned using graph convolutional neural networks (GCNs) to achieve effective information fusion. Through the graph convolutional network, the model can fully mine the different levels of grammatical information in the sentence, fully understand the structure and semantic relationship of the sentence, and improve the accuracy of metaphor recognition.

[0128] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0129] Figure 1 It is a technical roadmap in the embodiment.

[0130] Figure 2 It is a noun metaphor recognition model based on a large language model and a graph convolutional network in the embodiment

[0131] Figure 3 This is a data augmentation-noun metaphor example in the embodiment.

[0132] Figure 4 This is an example of data augmentation-non-noun metaphor-non-metaphor in the embodiment.

[0133] Figure 5 This is an example of data augmentation-non-noun metaphor-verb metaphor in the embodiment. DETAILED DESCRIPTION

[0134] The following describes the embodiments of the present application in detail with reference to the accompanying drawings, examples of which are shown in the accompanying drawings. The present application provides a method and an electronic device. The method and the device are based on the same technical concept. Since the principles of solving problems by the method and the device are similar, the implementation of the device and the method can refer to each other, and the repeated parts will not be repeated.

[0135] Terminology Note:

[0136] Noun metaphor: A noun metaphor is a figure of speech in which a noun is used to represent another concept that is different from its literal meaning, thereby creating an implicit, non-literal meaning. This metaphor allows a noun to transcend its conventional, direct physical or concrete meaning and instead carry a more abstract or symbolic meaning through contextual suggestion or association.

[0137] Data augmentation: Data augmentation refers to the process of generating new data samples by transforming the original data. In the present invention, the original noun metaphor sentences or non-noun metaphor sentences are used to generate sentences with the same structure, with the purpose of expanding the training data set, enhancing the generalization ability of the model, and reducing overfitting.

[0138] Data distillation: Data distillation refers to filtering existing data to obtain valid data to improve data quality.

[0139] Word segmentation: Word segmentation is the process of dividing a continuous text sequence into the smallest language units (such as words, subwords, characters, etc.) in natural language processing, laying the foundation for subsequent text analysis and modeling.

[0140] Word embedding: Word embedding is a technique that maps words into a high-dimensional dense vector space so that semantically similar words are close to each other in the space.

[0141] ERNIE: ERNIE (Enhanced Representation through Knowledge Integration) is a knowledge-enhanced pre-trained language model proposed by Baidu. It optimizes the representation learning of language by masking Chinese word segmentation.

[0142] Graph Convolutional Network: Graph Convolutional Network is a deep learning model for processing graph data. It learns the representation of nodes or graphs by aggregating information within the node neighborhood of the graph.

[0143] Multi-head attention mechanism: The multi-head attention mechanism is an important component of the Transformer model. It splits the input attention calculation into multiple "heads", each head independently calculates and learns different attention representations, and finally merges the outputs of each head. This mechanism helps the model capture the dependencies between different aspects of the input.

[0144] Dependency Syntax Tree: A dependency syntax tree is a graph that represents the structure of a sentence, where nodes represent words and edges represent the dependencies between words. By analyzing the dependency relationships, the grammatical functions and relationships between words in a sentence can be revealed.

[0145] Feature fusion: Feature fusion refers to combining features from different sources to build a richer and more expressive input representation.

[0146] Softmax: Softmax is an activation function commonly used in classification tasks. It converts each element in a vector into a probability value between 0 and 1, and the sum of all elements is 1. Softmax is usually used in the output layer of multi-classification problems.

[0147] Binary Classification: Binary Classification refers to a classification task that divides input data into two categories, which in this invention refers to noun metaphors and non-noun metaphors.

[0148] The method of the present invention aims to effectively identify metaphorical expressions with nouns as the core in text, provide support for improving the machine's ability to understand complex semantics in natural language, and then be applied to various natural language processing tasks, including sentiment analysis, text generation, question-answering systems, and intelligent dialogue systems.

[0149] In the first embodiment, the core of the noun metaphor identification task is to distinguish whether there is a metaphorical relationship in the sentence and how to capture the non-literal semantic association between nouns through the model. Figure 1 As shown, the method for noun metaphor recognition based on a large language model and a graph neural network of the present invention is used for noun metaphor recognition, and the method mainly includes the following steps:

[0150] Build and train deep learning network models;

[0151] Use the trained model for recognition.

[0152] The input of the model is a sentence similar to "the camera lens is money", and the output of the model is a binary classification of noun metaphor or non-noun metaphor. The present invention mainly optimizes the model framework to better adapt to this specific task.

[0153] The model training method includes the following steps:

[0154] Step 1: Get input data

[0155] The input data is a Chinese sentence containing noun metaphors or non-metaphors. The data set used in the present invention comes from the CCL2018 Chinese metaphor detection task evaluation data, which contains a total of 4,394 Chinese sentences, including various types of metaphor sentences. Since the algorithm proposed in the present invention is mainly used for the recognition of noun metaphors, the model will focus on distinguishing noun metaphors from non-metaphor sentences during training and evaluation to improve the detection accuracy of noun metaphors.

[0156] Step 2: Data Augmentation

[0157] In the noun metaphor recognition task, the Qwen-max model is used to augment the data volume. Specifically, for the noun metaphor sentences in the dataset, the augmentation prompt is: "Generate a similar sentence containing a noun metaphor", such as Figure 3 For non-noun metaphor sentences in the dataset, the prompt is: "Generate a similar sentence that does not contain a noun metaphor", such as Figure 4 and Figure 5 The sentences generated during the augmentation process will be passed as training data to the subsequent model.

[0158] Step 3: Data Distillation

[0159] Specifically, the data in step 2 is input into ChatGLM, wherein for the noun metaphor sentences in the data set and the sentences augmented by the noun metaphor sentences, a prompt is used: "Are all of them metaphor sentences?", and for the non-noun metaphor sentences in the data set and the sentences augmented by the non-noun metaphor sentences, a prompt is used: "Are all of them not metaphor sentences?".

[0160] If the answer is "yes", it means that the sentences augmented for noun metaphor sentences in step 2 are all noun metaphor sentences, and the sentences augmented for non-noun metaphor sentences are all non-noun metaphor sentences, and the data goes directly to step 4. If the answer is "no", it means that there are non-noun metaphor sentences in the sentences augmented for noun metaphor sentences in step 2 and / or there are noun metaphor sentences in the sentences augmented for non-noun metaphor sentences. For non-noun metaphor sentences in the sentences augmented for noun metaphor sentences, use the prompt: "Delete the sentences that are not noun metaphors in the augmented sentences" to delete the non-noun metaphor sentences in the sentences augmented for noun metaphor sentences. For noun metaphor sentences in the sentences augmented for non-noun metaphor sentences, use the prompt: "Delete the sentences that are metaphors in the augmented sentences" to delete the noun metaphor sentences in the sentences augmented for non-noun metaphor sentences, and then go to step 4.

[0161] Step 4: ERNIE model training

[0162] Among them, in the training process of the ERNIE model, the input data obtained by data distillation is first segmented and encoded, the sentence is broken down into word or subword units, and a pre-trained word embedding is generated for each word. Next, by combining word vectors with position encoding, the model can capture the order relationship of words in the sentence. Then, through the multi-head attention mechanism, the representation of each word learns contextual information in multiple parallel attention heads to capture long-distance semantic dependencies. Through the self-attention mechanism, the model can adjust the word vector representation, especially in metaphorical sentences, ERNIE pays special attention to the semantic changes of nouns. After multi-layer attention mechanism and context learning, the model finally obtains the vector representation of the entire sentence. In order to improve the semantic understanding of nouns, especially the recognition task of noun metaphors, the model adjusts the embedding representation of nouns and outputs (first feature representation). Through the cross entropy loss function, the model optimizes the parameters for training by comparing the gap between the predicted probability value and the true label.

[0163] Step 5: Modeling a semantic graph based on dependency syntax and PMI

[0164] Among them, in the process of semantic graph modeling based on dependency syntax and PMI, the vocabulary and word frequency dictionary are first constructed by processing the distilled data set. Specifically, each sentence in the sentence set is split into words, and the entire vocabulary is obtained through a union operation. The frequency of each word is calculated by traversing all documents and counting the number of times the word appears. Next, a word pair co-occurrence graph is constructed, the number of co-occurrences of word pairs is calculated by setting a fixed-size context window, and a counting dictionary is maintained to record the co-occurrence frequency of each pair of words. On this basis, the edge weights between word pairs are calculated: if there is a syntactic dependency relationship between the two words, 10 is added to the PMI calculation result to increase its weight. Finally, the word pair co-occurrence graph and dependency information obtained help better capture the semantic associations between words and provide richer context information for the model.

[0165] Step 6: Training of graph neural network

[0166] The node feature representation (first feature representation) output by ERNIE in step 4 and the semantic graph output by step 5 are further processed through the graph convolutional network (GCN). GCN updates the features of each node through the relationship between nodes and edges in the graph structure, fusing information layer by layer to capture the structural characteristics of the graph. Finally, the model combines the output of the ERNIE classifier and the graph convolution output of GCN to provide a comprehensive feature representation (second feature representation) for the final classification decision of the node.

[0167] Step 7: Loss calculation

[0168] The final loss value of the model is a weighted combination of the losses of the ERNIE part and the graph convolutional neural network part. By weighted summing the losses of these two parts, the model can simultaneously optimize the learning of text features through the ERNIE model and the learning of graph structure information through the graph convolutional network during the training process.

[0169] In the second embodiment, specifically, the present invention is based on a large language model and a graph neural network to identify noun metaphors, including the following steps:

[0170] Step 1: Input data

[0171] The input data is a Chinese sentence containing noun metaphors or non-noun metaphors. The formula is as follows:

[0172] Data Input ={Sentence}

[0173] Here, Sentence represents a Chinese sentence containing a noun metaphor or a Chinese sentence including a non-noun metaphor (a Chinese sentence not containing a noun metaphor).

[0174] Step 2: Data Augmentation

[0175] Among them, in the noun metaphor recognition task, data augmentation not only needs to expand the amount of data, but also should consider how to generate more sentences containing metaphors and non-metaphors. The present invention adopts the Qwen-max model for data augmentation. For a sentence containing a noun metaphor, the augmentation prompt is: "[input sentence] + generate five similar sentences containing noun metaphors". For a sentence containing a non-noun metaphor, the prompt is: "[input sentence] + generate five similar sentences that do not contain noun metaphors". For sentences containing noun metaphors:

[0176] Sentences metaphor =Qwen(Data Input +"Generate five similar sentences containing noun metaphors")

[0177] Among them, Qwen means Qwen-Max, Sentences metaphor Represents a sentence containing a noun metaphor Data Input The expanded sentence of .

[0178] For sentences that do not contain noun metaphors:

[0179] Sentences non-metaphor =Qwen(Data Input +"Generate five similar sentences that do not contain noun metaphors")

[0180] Among them, Sentences non-metaphor Represents a sentence that does not contain a noun metaphor Data Input The expanded sentence of .

[0181] After augmentation, the number of data sets is shown in Table 2:

[0182] Table 2 Augmented data

[0183] category quantity Noun Metaphor 7626 Non-nominal metaphor 8829 Verb Metaphor 7654 Non-metaphorical 1175 total 16455

[0184] Step 3: Data Distillation

[0185] In this step, ChatGLM is used to verify the validity of the augmented sentences. Specifically, the data of the original sentence in step 2 and the augmented sentence generated based on the original sentence are input into ChatGLM. For the original sentence that includes noun metaphors, a prompt is used: "Are all the augmented sentences of the original sentence noun metaphors?" For the original sentence that includes non-noun metaphors, a prompt is used: "Are all the augmented sentences of the original sentence not noun metaphors?" If the answer is "yes", the data goes directly to step 4. If the answer is "no", a prompt is used: "Delete the sentences that are not noun metaphors in the augmented sentences of the original sentence", "Delete the sentences that are noun metaphors in the augmented sentences of the original sentence", remove the non-metaphor sentences in the augmented sentences of the original sentence of noun metaphor, and remove the metaphor sentences in the augmented sentences of the original sentence of non-noun metaphor before entering step 4.

[0186] Suppose the augmented sentence set is input into ChatGLM and verified using prompts, as shown below.

[0187] Verification=ChatGLM(Sentences metaphor ,"Are all of them metaphorical sentences?"

[0188] Verification=ChatGLM(Sentences non-metaphor ,"Are all of them not metaphorical sentences?")

[0189] If the answer of ChatGLM is “yes”, it means that all the augmented sentences of the original noun metaphor sentences are noun metaphor sentences, or all the original non-noun metaphor sentences are not noun metaphor sentences, then the formula is as follows:

[0190] Final data =Verification

[0191] Final data It is a combination of two Verifications.

[0192] If ChatGLM's answer is "no", it means that the augmented sentence of the original noun metaphor sentence contains non-noun metaphor sentences, and the augmented sentence of the original non-noun metaphor sentence contains noun metaphor sentences, and further screening is required. At this time, the present invention removes the non-noun metaphor sentences contained in the augmented sentences of the original noun metaphor sentences, and removes the noun metaphor sentences contained in the augmented sentences of the original non-noun metaphor sentences. The specific operation is as follows:

[0193] Filtered = ChatGLM (Verification, "Delete sentences that are not metaphors")

[0194] Filtered = ChatGLM (Verification, "Delete metaphorical sentences")

[0195] Final valid data: The final valid data formula is:

[0196] Final data =Filtered

[0197] Final data It is the combination of two Filtered. Step 4: ERNIE model training

[0198] During the training process of the ERNIE model, the data obtained after the data distillation in step 3 is first segmented and encoded. Sentences are broken down into word or subword units by word segmentation, and word embedding is performed using pre-trained word vectors. Next, by adding position encoding to each word vector, the model is able to capture the order relationship of words in the sentence. The processed word vectors then enter the multi-head attention mechanism, which learns contextual information from different subspaces through multiple parallel attention heads. Through the self-attention mechanism, the model is able to understand the relationship between each word and other words, and adjust the word vector representation in multiple iterations to capture long-distance semantic dependencies. In metaphorical sentences, ERNIE pays special attention to the semantic changes of nouns, and continuously adjusts word embeddings through contextual information to obtain more accurate semantic representations. After multiple layers of attention mechanisms and context learning, the model finally obtains a vector representation of the entire sentence.

[0199] For the input sentence Final data , first perform word segmentation and encoding. Set the word or subword unit after word segmentation to {w1,w2,…,wn}, and generate a pre-trained word embedding E(wi) for each word:

[0200] E(w i )=Embedding(wi)

[0201] Then, word embedding is combined with position encoding to capture the order information of words in the sentence. Position encoding can be represented as P(i), where i is the position information of the word:

[0202]

[0203] Among them, i is the position information of the word, j is the dimension of the position encoding, and d is the embedding dimension. Therefore, the final representation of each word is:

[0204] H 0 (i) = E(w i )+P(i)

[0205] Word vector H 0(i) Enter the multi-head attention mechanism, each attention head can learn context information in different subspaces. Next, we will explain the word vector H in detail. 0 (i) Steps to enter the attention mechanism calculation:

[0206] First, from H 0 In (i), three matrices, query, key, and value, are generated through linear transformation:

[0207] Q=H 0 (i)W Q ,K=H 0 (i)W K ,V=H 0 (i)W V

[0208] is the projection matrix. denote the query matrix, key matrix, and value matrix respectively. model represents the dimension of the model, h represents the number of heads, and d k Represents the dimensions of a single head.

[0209] In the self-attention mechanism, the goal is to calculate the attention distribution of all other words in each word pair sequence. First, the similarity score between the query Q and the key K is calculated:

[0210]

[0211] Q i K: The query vector of the i-th word. j : The key vector of the jth word. Score(i,j): Indicates the strength of the relationship between position i and position j.

[0212] Then integrate the scores of all positions into a matrix form:

[0213] Scores = QK T

[0214] in: represents the relevance score of each position in the sentence to all other positions, and n represents the number of words.

[0215] To prevent the score from being too large (which may cause the gradient to vanish or explode), the score is scaled to:

[0216]

[0217] Then calculate the weighted sum of the values ​​of each word:

[0218]

[0219] Among them, the molecule Convert the correlation score of the i-th position to the j-th position into a positive value for normalization. Calculate the sum of all relevance scores in row i for normalization.

[0220] Finally, the attention weight a ij For the weighted value matrix V j Complete the weighted aggregation of contextual features:

[0221]

[0222] Among them, for the input H 0 (i) Use different WQWKWV to generate multiple QKVs, and then perform the above attention calculation on each head independently to obtain Attention1, Attention2, .....Attentionh. Finally, concatenate the output of each head and map it back to the model dimension through linear transformation WO.

[0223] MultiHead(Q,K,V)=Concat(Attention 1 ,Attention 2 ,…,Attention h )W O

[0224] in, is the final linear transformation matrix. The output shape is (n,d model ).

[0225] Through the above self-attention mechanism, the model is able to understand the relationship between each word and other words and adjust the representation of each word based on the context information. These adjusted word representations are the new output H L .

[0226] The output of each layer is normalized by layer normalization:

[0227] H L =LayerNorm(H 0 (i)+MultiHead(Q,K,V))

[0228] Among them, H 0 is the word representation of the input. In the noun metaphor identification task, ERNIE pays special attention to the semantic changes of nouns (such as the main words in the sentence) in the context, so it gives nouns a greater weight.

[0229] The first characteristic representation H of the final ERNIE model final=H L .

[0230] The cross entropy loss function is used in ERNIE model training, which is usually used to measure the gap between the probability distribution of the model output and the true label. true is the true label (0 or 1, indicating non-nominal metaphor and nominal metaphor, respectively), y pred is the predicted output of the model (the probability value after sigmoid activation), then the cross entropy loss function can be expressed as:

[0231] Loss Ernie =-(y true log(y pred )+(1-y true )log(1-y pred ))

[0232] Step 5: Semantic graph modeling based on dependency syntax and PMI

[0233] The data set after data distillation in step 3 is processed. It is divided into sentence list and sentence content. The sentence list is a sentence for each data item. The sentence vocabulary is constructed. Assume that S = {s1, s2, ..., sN} is a sentence set, where each sentence si contains a set of words.

[0234] Each sentence si is split into a series of words si = {wi1, wi2, ..., wij}, where wij represents the jth word in sentence si.

[0235]

[0236] Among them, ∪ represents the vocabulary obtained by the union operation of the vocabulary sets in all sentences, vocab represents the vocabulary, U represents the union operation, and w ij represents the jth word in sentence si, and N represents the number of sentences.

[0237] For each word w k ∈vocab, word frequency word_freq(w k ) represents word w k The number of occurrences in all documents can be expressed as:

[0238]

[0239] in, is an indicator function, indicating that if word wk appears in sentence S i In Otherwise it is 0. Traverse all documents and count the frequency of each word. Finally, the frequency of each word in all documents will be accumulated and recorded in the word frequency dictionary word_freq.

[0240] Next, a word pair co-occurrence graph is constructed. In order to calculate the word pair co-occurrence frequency, the present invention defines a fixed-size context window (window_size) and calculates the word pair co-occurrence times by traversing the vocabulary in the sentence.

[0241] Assume that the vocabulary sequence in sentence Si is Si = {w i1 ,w i2 ,…,w ij}, the window size is window_size, the present invention will traverse the words in the sentence and build word pairs based on the context window. For each word w in the sentence Si ij , the present invention defines its context window as:

[0242] window(w ij )={w ij-k ,w ij-k+1 ,…,w ij+k}

[0243] Where k is an integer from -window_size to window_size, that is, w ij Take window_size words on each side as its context.

[0244] For each word pair (w p ,w q ) appears in the context window, the present invention needs to maintain a counting dictionary word_pair_count, recording each pair of words w p and w q The number of times a word appears in the corpus.

[0245] word_pair_count(w p ,w q )=word_pair_count(w p ,w q )+1

[0246] Where wp and wq are any pair of different words in the window, and word_pair_count() represents the counting function.

[0247] Next, the weight of the edge between two points is calculated. If there is no syntactic dependency between the two points, the PMI value is used. If there is a syntactic dependency, 10 is added to the PMI result to increase the weight. The PMI calculation is shown below.

[0248]

[0249] Among them, count(wi,wj) is the number of times the word pair (wi,wj) appears in the document.

[0250] in,

[0251] If there is a syntactic dependency between two words, the weight value is increased by 10. The formula is as follows.

[0252] PMI(w i ,w j )=PMI(w i ,w j )+10if(w i ,w j )∈special_word_pairs

[0253] special_word_pairs is a set of syntactic dependency relationships between words obtained after spacy calculates the syntactic dependency relationships.

[0254] Step 6: Training of graph convolutional neural network

[0255] This step combines the node representation of step 4 with the graph structure of step 5, aggregates neighbor features through the GCN update formula, and generates a new node representation. This update formula uses the graph information (neighbor set, degree normalization) constructed in step 5 to further update and optimize the features obtained in step 4. In simple terms, the features in step 4 are input into the graph neural network to obtain the node representation, and the graph constructed in step 5 is used for training. The node update formula is as follows

[0256]

[0257] In the formula, H (L) is the node feature representation of the Lth layer, initially L=0, using H(0) output by the preprocessing model. N(i) is the set of neighbor nodes of node i, and each node represents a word. is the adjacency matrix of the semantic graph, including self-connections (plus the identity matrix I), is the degree matrix of the node, which is calculated through the adjacency matrix. It is the Laplace normalization operation of the graph, which is used to smooth and standardize the graph structure data. (I) is a trainable parameter of layer I, which is used to perform a linear transformation on the features.

[0258] σ(·) is an activation function, RELU used in the present invention.

[0259] The process is as follows:

[0260] 1. Adjacency matrix normalization: through Performs graph smoothing.

[0261] 2. Feature transformation: using parameter matrix W (I) For node feature H (L) Perform a linear transformation.

[0262] 3. Activation function: nonlinear transformation is introduced through σ(·), and finally the node features of the L+1th layer are obtained

[0263] For feature representation Sigmod is used to perform classification through a linear layer Wc and a bias term bc, and finally outputs a scalar ypred, which indicates the probability that the sample belongs to a certain category. The cross entropy is used to calculate the loss value. The graph convolutional neural network also uses the cross entropy loss function to calculate the cross entropy loss between the model prediction value ypred and the true label ytrue LGCN:

[0264]

[0265] Step 7: Loss calculation

[0266] The final loss value is the sum of the ERNIE part and the graph convolutional neural network part:

[0267]

[0268] Where γ is a hyperparameter, a constant.

[0269] In the experimental example of the present invention, the experimental parameters and environment settings of the present invention are as follows: This experiment is trained and inferred on two NVIDIA RTX4090 servers, each equipped with 24GB video memory. max_length (128) specifies the maximum length of the input text to ensure that the length of each input sequence is consistent. batch_size (32) determines the number of samples processed during each training, affecting the training speed and memory usage. nb_epochs (60) sets the total number of training rounds to control the number of complete iterations of model training. bert_lr (1e-4) sets the learning rate of the BERT model, affecting the step size of each parameter update. m (0.7) is used to weight the contribution ratio of the outputs of different modules of the model (such as BERT and GCN). gcn_layers (2) represents the number of layers of the graph convolutional network, which determines the capture depth of the graph structure information. n_hidden (200) determines the number of hidden units in each layer, affecting the capacity of the model. dropout (0.5) is used for regularization training, randomly discarding 50% of the neurons to prevent overfitting. The experimental parameter settings are shown in Table 3.

[0270] Table 3 Experimental parameter settings

[0271] Parameter name max_length 128 batch_size 32 nb_epochs 60 bert_lr 1e-4 m 0.7 gcn_layers 2 n_hidden 200 dropout 0.5

[0272] Comparison model: Long short-term memory network + attention mechanism (LSTM+Attention): The combination of long short-term memory network (LSTM) and attention mechanism (Attention), namely LSTM+Attention, is an enhanced model based on the classic LSTM network. It combines the time series modeling capability of LSTM and the weighted characteristics of self-attention mechanism (Self-Attention), enabling the model to process sequence data more flexibly and focus on important parts of the sequence.

[0273] Capsule Network (CapsNet): A capsule is a group of neurons whose input and output vectors are used to represent the instantiation parameters of a specific entity type (i.e., the probability of occurrence of an object or conceptual entity and its related attributes). Essentially, a capsule network is a neural network designed to perform reverse graph parsing, consisting of multiple capsules. Each capsule can be viewed as a function that attempts to predict the presence of a target at a specific location and the instantiation parameters.

[0274] BERT: BERT (Bidirectional Encoder Representations from Transformers) is a pre-trained language model based on the Transformer encoder structure and improved from GPT. Unlike GPT's unidirectional language model, BERT uses bidirectional contextual information for word prediction and learns word-level and sentence-level representations through MaskedLM and NextSentencePrediction tasks. The key features of BERT include: 1) Bidirectional encoding, using MaskedLM for word prediction and contextual information. 2) Using the Transformer encoder, it has a deeper level and better parallelism. 3) Sentence-level negative sampling, learning the relationship between sentence pairs and judging whether a sentence is the next sentence.

[0275] Transformer: Transformer is based on the Attention mechanism and is divided into two parts: encoder and decoder. Each part consists of 6 stacked layers. Each layer includes a multi-head attention mechanism and a feedforward network, and uses residual connections and normalization. Sequential information is injected through position encoding, and the output predicts the next token through Softmax. Transformer uses three multi-head attention mechanisms: encoder-decoder Attention, encoder Self-Attention, and decoder Self-Attention (with Masking to prevent illegal values). The structure is highly parallel, which improves training efficiency.

[0276] Llama-3.1-70B: Llama-3.1-70B is a large-scale pre-trained language model based on the Transformer architecture launched by Meta, containing 7 billion parameters. The model uses self-attention mechanism and multi-head attention mechanism, and processes input data in parallel through multiple Transformer layers. It can effectively model long-term dependencies and support multi-task processing. Llama-3.1-70B is trained on a large-scale, multilingual text corpus. The data sources include the Internet, books, Wikipedia and other fields, ensuring that it has efficient performance and wide application capabilities in multiple natural language processing tasks such as text generation, question answering, and sentiment analysis.

[0277] GPT-4O: GPT-4O is an enhanced version based on GPT-4, continuing the basic design of Transformer architecture and autoregressive language modeling, and has powerful multi-task processing capabilities. It is trained on a large-scale and diverse corpus, covering various types of text data, supports multilingual tasks, and performs well in text generation, question answering, translation, summarization and other fields. GPT-4O may be optimized in reasoning ability, task adaptability and processing speed, and can provide customized services in specific application scenarios such as medical and legal fields, while retaining the powerful language understanding and generation capabilities of GPT-4.

[0278] Qwen2-1.5b: Qwen-2 is a large-scale pre-trained language model based on the Transformer architecture, optimized for Chinese and multi-language natural language processing tasks. It can efficiently perform tasks such as text generation, text classification, sentiment analysis, machine translation, etc., and has powerful multi-task processing capabilities. Qwen-2 is trained on massive Chinese and multi-language data sets, has deep semantic understanding and reasoning capabilities, and can handle complex language expressions and contextual information.

[0279] Evaluation indicators: The model of the present invention and the comparative experiments are analyzed through four indicators: accuracy, precision, recall and F1 value.

[0280] Accuracy: measures the overall correctness of the classification model. The calculation formula is:

[0281]

[0282] Among them, TpTp is a true positive example (TruePositive), TnTn is a true negative example (TrueNegative), FpFp is a false positive example (FalsePositive), and FnFn is a false negative example (FalseNegative).

[0283] Precision: The accuracy of the model prediction for positive samples is calculated using the formula:

[0284]

[0285] Recall: measures the model's ability to correctly predict positive samples. The formula is:

[0286]

[0287] F1 value: The harmonic mean of precision and recall is considered comprehensively. The formula is:

[0288]

[0289] For a given predicted label, the precision and recall can be quickly calculated by using the confusion matrix. The confusion matrix for a binary classification problem contains four basic results: true positives (Tp), false positives (Fp), true negatives (Tn), and false negatives (Fn). In the confusion matrix, the columns represent the true labels and the rows represent the predicted labels. The intersection of the rows and columns corresponds to these four results, as shown in Table 4.

[0290] Table 4 Character meaning of confusion matrix

[0291]

[0292] Experimental Results

[0293] Table 5 Comparative experimental results

[0294] Model Accuracy Accuracy Recall F1 score LSTM+ATT 0.8509 0.8706 0.7952 0.8312 Capsule 0.8781 0.8755 0.8582 0.8667 BERT 0.8836 0.8740 0.8740 0.8740 Transformer 0.8563 0.8959 0.7795 0.8336 Llama-3.1-70B 0.5727 0.5064 0.8208 0.6264 GPT-4O 0.4964 0.4490 0.6820 0.5415 Qwen2-1.5b 0.4945 0.4587 0.8792 0.6029 Qwen2-1.5b (finetune) 0.9073 0.9276 0.8542 0.8894 MetaGCN-ERNIE 0.9182 0.9295 0.8792 0.9036

[0295] In order to verify the noun metaphor recognition model MetaGCN-ERNIE based on large language model and graph neural network proposed in this invention, the present invention conducted experiments on public data sets and comprehensively compared the proposed method with classic neural network models, deep learning models and modern large language models. The experimental results show that the MetaGCN-ERNIE model outperforms all the above-mentioned comparison models in the metaphor recognition task. The main reasons are as follows: First, the model of the present invention generates more training data through data augmentation technology, so that the model can more fully learn the complex features and diversified expressions of metaphors during the training process. Secondly, the model constructs a semantic graph using syntactic dependencies and point mutual information (PMI). This process helps the model capture the deep grammatical and semantic connections between words, thereby more accurately identifying noun metaphors. Thirdly, the model uses the powerful ERNIE pre-training model for feature extraction, fully considering the contextual semantics of the text, especially in the understanding of long-distance dependencies, which enhances the recognition ability of metaphors. In addition, the model uses a graph convolutional network to identify sentences and words, and optimizes the representation of sentences through graph convolution operations, so that the final model can more effectively capture the potential information in metaphorical expressions. These innovative designs enable MetaGCN-ERNIE to achieve significant performance improvements when processing noun metaphors in complex contexts.

[0296] Based on the above embodiments, the embodiments of the present application further provide a computer program, which, when executed on a computer, enables the computer to execute the methods provided in the above embodiments.

[0297] Based on the above embodiments, the embodiments of the present application further provide a computer storage medium, in which a computer program is stored. When the computer program is executed by a computer, the computer executes the method provided in the above embodiments.

[0298] The storage medium may be any available medium that can be accessed by a computer. For example, but not limited to, a computer-readable medium may include RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer.

[0299] Based on the above embodiments, an embodiment of the present application further provides a chip, which is used to read a computer program stored in a memory to implement the method provided in the above embodiments.

[0300] Based on the above embodiments, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the method provided in the above embodiments is implemented.

[0301] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0302] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0303] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0304] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0305] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A noun metaphor recognition method based on a large language model and graph neural network, characterized in that: A metaphor recognition model is used, wherein the metaphor recognition model includes a preprocessing model and a graph convolution model, and the recognition method includes the following steps: training the metaphor recognition model; Inputting the text to be processed into the trained preprocessing model, and the preprocessing model outputs a first feature representation; Constructing a semantic graph of the text to be processed according to syntactic dependencies and point mutual information; Inputting the first feature representation and the semantic graph into the trained graph convolutional network, and the graph convolutional network outputs a second feature representation; The second feature representation is classified by a classifier to obtain a noun metaphor recognition result in the text to be processed.

2. According to claim 1, the noun metaphor recognition method based on a large language model and a graph neural network, It is characterized in that The step of training the metaphor recognition model includes: Performing data augmentation on the first data set by using the first large language model to construct a second data set; Performing data distillation on the second data set through a second language model to construct a third data set; Inputting the third data set into a preprocessing model, the preprocessing model outputting a first feature representation; Constructing a semantic graph of the third data set according to syntactic dependencies and point mutual information; Inputting the first feature representation and the semantic graph into a graph convolutional network, and the graph convolutional network outputs a second feature representation; The second feature representation is classified by a classifier.

3. The noun metaphor recognition method based on a large language model and a graph neural network according to claim 2 is characterized in that: The first data set includes Chinese sentences containing noun metaphors or Chinese sentences containing non-noun metaphors, which are represented by the following formula: Data Input ={Sentence} In the formula, Sentence represents a Chinese sentence containing a noun metaphor or a Chinese sentence containing a non-noun metaphor; The prompt for the first language model in the data augmentation, wherein the sentence Data containing noun metaphor Input The prompt is expressed as follows: Sentences metaphor =Qwen(Data Input +"Generate five similar sentences containing noun metaphors") In the formula, Sentences metaphor Represents a sentence containing a noun metaphor Data Input The expanded sentence of The prompts for the first language model in the data augmentation, wherein the sentence Data that does not contain noun metaphors Input The prompt is expressed as follows: Sentences non-metaphor =Qwen(Data Input +"Generate five similar sentences that do not contain noun metaphors") In the formula, Sentences non-metaphor Represents a sentence that does not contain a noun metaphor Data Input The expanded sentence of The second data set includes Sentences metaphor And Sentences non-metaphor ; The prompts for the second largest language model in the data distillation, where the sentence Data containing noun metaphors Input And its augmented sentences metaphor The prompt is: Verification metaphor = ChatGLM(Sentences metaphor ,"Are all of them noun metaphors?" The prompts for the second largest language model in the data distillation, where Data Input And its augmented sentences non-metaphor The prompt is expressed as follows: Verification non-metaphor = ChatGLM(Sentences non-metaphor ,"Are all of them not noun metaphors?" If the answer to the prompt is yes, then the third data set is represented by the following formula: Final data =Verification metaphor +Verification non-metaphor If the answer to the prompt is no, then the sentence Data containing the noun metaphor Input And its augmented sentences metaphor The sentence that is not a noun metaphor is deleted from the sentence, which is represented by the following formula: Filtered metaphor = ChatGLM(Sentences metaphor ,"Delete sentences that are not noun metaphors") If the answer to the prompt is no, then the sentence Data that does not contain noun metaphors Input And its augmented sentences non-metaphor The sentence in which the noun metaphor is deleted is represented by the following formula: Filtered non-metaphor = ChatGLM(Sentences non-metaphor ,"Delete the sentence that is a noun metaphor") Then the third data set is expressed by the following formula: Final data =Filtered metaphor +Filtered non-metaphor In the formula, Final data The third dataset; Preferably, the first large language model includes a Qwen model, the second large prediction model includes a ChatGLM model, and the preprocessing model includes an ERNIE model.

4. The noun metaphor recognition method based on a large language model and a graph neural network according to any one of claims 2-3, characterized in that: in, The step of inputting the third data set into a preprocessing model, and the preprocessing model outputting a first feature representation, comprises the following steps: S310. Finalizing the third data set data The sentences in are segmented, and the words after segmentation are {w1,w2,…,wn}. Each word generates a pre-trained word embedding E(wi), which is expressed as follows: E(w i )mEmbedding(wi) S320. Perform position encoding on the word, wherein the position encoding is represented by P(i), which is represented by the following formula: In the formula, i is the position information of the word, j is the dimension of the position encoding, and d is the embedding dimension; S330. Obtain the weighted sum of the value of each word through the attention mechanism of the word vector H0(i) and perform weighted aggregation of context features, concatenate the output of each attention head, and map it back to the dimension of the model through linear transformation to obtain the multi-head attention mechanism output MultiHead(Q, K, V); Among them, the word vector H0(i) of each word is expressed by the following formula: H0(i)=E(in i )+P(i); S340. The output of each layer is normalized by layer normalization, which is expressed as follows: H L =LayerNorm(H0(i)+MultiHead(Q,K,V)) S350. Output the first feature representation, which is represented by the following formula: H final =H L In the formula, H final Represents the first feature representation.

5. The noun metaphor recognition method based on a large language model and a graph neural network according to claim 4 is characterized in that: in, In step S330, the multi-head attention mechanism outputs MultiHead(Q, K, V), including the following steps: S331. Use different W for the input word vector H0(i) Q , W K , W V Generate multiple Q, K, V, and perform attention calculation on each head independently to obtain Attention1, Attention2, .....Attentionh; S332. Splice the output of each head and transform it by linear transformation W O Mapping back to the dimensions of the model is represented by the following formula: MultiHead(Q,K,V)=Concat(Attention1,Attention2,…,Attention h )W O In the formula, MultiHead(Q,K,V) means, represents the linear transformation matrix, d model represents the dimension of the model, h represents the number of heads, and d v Represents the dimensions of a single head; The calculation of Attention in step S331 includes the following steps: S3311. The word vector H0(i) is fed into the attention mechanism, and the query, key, and value matrices are generated from the word vector H0(i) through linear transformation, which is expressed as follows: Q=H0(i)W Q ,K=H0(i)W K ,V=H0(i)W V In the formula, Respectively represent the query projection matrix, key projection matrix, and value projection matrix; Represent the query matrix, key matrix, and value matrix respectively; S3312. Calculate the similarity score Score(i,j) between the query matrix Q and the key matrix K, which is expressed by the following formula: In the formula, Q i represents the query vector of the i-th word, K j represents the key vector of the j-th word, the similarity score Score(i,j) represents the strength of the relationship between position i and position j, and the superscript (t) represents the calculation of the t-th head in the multi-head attention mechanism; S3313. Integrate the scores of all positions into a matrix form, represented by the following formula: Scores=QK T In the formula, represents the similarity score of each position in the sentence to all other positions, and n represents the number of words; S3314. Scale the similarity score as follows: S3315. Calculate the weighted sum of the value of each word, expressed by the following formula: In the formula, the molecule It means converting the correlation score of the i-th position to the j-th position into a positive value, and the denominator is represents the sum of all relevance scores in the i-th row for normalization; S3316. Add the weighted sum of the values ​​of each word to a ij For the weighted value matrix V j , weighted aggregation of context features is performed, which is expressed as follows: In the formula, n represents the number of words.

6. The noun metaphor recognition method based on a large language model and a graph neural network according to any one of claims 2 to 5, characterized in that: in, The step of constructing a semantic graph of the third data set according to the syntactic dependency relationship and the point mutual information includes the following steps: S410. Finalizing the third data set data The sentences in the vocabulary building include S411. Through S={s1,s2,…,s N } indicates the third data set Final data A set of sentences in , where each sentence si contains a set of words; S412. Split each sentence si into a series of words s i ={w i1 ,w i2 ,…,w ij }, where w ij Indicates sentence s i The jth word in ; S420. Perform a union operation on the vocabulary sets in all sentences to obtain a vocabulary table, which is represented by the following formula: In the formula, vocab represents the vocabulary, U represents the union operation, and w ij represents the jth word in sentence si, and N represents the number of sentences; S430. For each word w k ∈vocab, using word frequency word_freq(w k ) represents word w k The number of occurrences in all documents, traverse all documents, and count the frequency of each word. The frequency of each word in all documents is accumulated and recorded in the word frequency dictionary word_freq, which is expressed by the following formula: In the formula, is an indicator function, which indicates the result of conditional judgment. In the formula, if word wk appears in sentence S i In Otherwise, 0; S440. Define a fixed-size context window, and calculate the number of co-occurrences of word pairs by traversing the words in the sentence, including S441. The vocabulary sequence in sentence Si is Si = {w i1 ,w i2 ,…,w ij }, where j represents the number of words, the window size is window_size, for each word w in sentence Si ij , define its context window as: window(w ij )={w ij-k ,w ij-k+1 ,…,w ij+k } Where k is an integer from -window_size to window_size; S442. For each word pair (w p ,w q ) appears in the context window, by maintaining a counting dictionary word_pair_count, recording each pair of vocabulary w p and w q The number of occurrences in the corpus is expressed as follows: word_pair_count(w p ,w q )=word_pair_count(w p ,w q )+1 Where word_pair_count() represents the counting function, wp and wq are any pair of different words in the window; S450. Calculate the weight of the edge between two points, where any two points are represented by any two words. If there is no syntactic dependency between the two points, the PMI value is used as the weight. If there is a syntactic dependency, the PMI value plus 10 is used as the weight. Among them, the PMI calculation is as follows: Where word_pair_count(wi,wj) is the number of times the word pair (wi,wj) appears in the document, and N is the number of sentences, where: Among them, if there is a syntactic dependency, the PMI value plus 10 is used as the weight, which is expressed by the following formula: PMI(w i ,w j )=PMI(w i ,w j )+10,if(w i ,w j )∈special_word_pairs Where special_word_pairs is the set of syntactic dependency relationships between words obtained by spacy after calculating the syntactic dependency relationships.

7. The noun metaphor recognition method based on a large language model and a graph neural network according to any one of claims 2 to 6, characterized in that: in, In the step, the first feature representation and the semantic graph are input into a graph convolutional network, and the graph convolutional network outputs a second feature representation, including using an update formula of a graph convolutional network GCN to update and optimize the first feature representation through the semantic graph to aggregate neighbor features and output a second feature representation, wherein the update formula is expressed by the following formula: In the formula, H (L) is the node feature representation of the Lth layer, initially L=0, using H(0) output by the preprocessing model; N(i) is the set of neighbor nodes of node i, each node represents a word; is the adjacency matrix of the semantic graph, including self-connections, is the degree matrix of the node; is the Laplace normalization operation of the semantic graph; W (I) is the trainable parameter of layer I; σ() is the activation function; Represents the second feature representation.

8. The noun metaphor recognition method based on a large language model and a graph neural network according to any one of claims 1 to 7, characterized in that: The second feature representation is passed through a linear layer W c and the bias term b c Classify and output a scalar y pred , which indicates the probability that the sample belongs to a certain category. In the formula, y pred is the predicted output of the model, which indicates the probability that the input sentence belongs to a noun metaphor, and sigmoid() indicates the sigmoid function; The loss function of the metaphor recognition model training is shown in the following formula: Where, LOSS all Represents the total loss, γ is a hyperparameter; in: Loss Ernie =-(and true log(y pred )+(1-and true )log(1-y pred )) In the formula, Loss Ernie represents the loss of the preprocessing model, y true represents the true label, y pred represents the predicted output of the model; In the formula, represents the loss of the graph convolutional network, C represents the number of categories, and the superscript (c) represents the number of the current category.

9. An electronic device, comprising: One or more processors, a memory, and one or more programs; wherein the one or more programs are stored in the memory, and the one or more programs include instructions, which, when executed by the electronic device, enable the electronic device to perform any method of claims 1-8.

10. A computer-readable storage medium, comprising a computer program, which enables an electronic device to execute any one of the methods of claims 1 to 8 when the computer program is executed on the electronic device.

Citation Information

Patent Citations

  • Text-oriented metaphor recognition model and method

    CN117669591A

  • Encoder, system and method for metaphor detection in natural language processing

    US20210271822A1

Cited By

  • Semantic analysis and recognition method based on artificial intelligence

    CN121257548A