Chinese text classification method based on metaphor association and label constraint comparative learning

By constructing a Chinese text classification method based on metaphorical association and label constraints, quantifying Chinese character ambiguity and generating metaphorical interpretations in combination with large language models, and using context and metaphorical attention mechanisms, the problems of semantic ambiguity and metaphorical association in Chinese text classification are solved, and higher classification accuracy and semantic understanding ability are achieved.

CN120256638AActive Publication Date: 2025-07-04CHINA UNIV OF MINING & TECH

Patent Information

Application Number
CN202510738203.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-04
Publication Date
2025-07-04
Estimated Expiration
2045-06-04

AI Technical Summary

Technical Problem

Traditional Chinese text classification models are difficult to effectively capture the semantic ambiguity and metaphorical associations caused by the polyphonic and meaning of Chinese characters, resulting in a degradation in metaphor-intensive scenarios, and the large language model lacks a semantic alignment mechanism in the generation of Chinese metaphors.

Method used

A Chinese text classification method based on metaphorical association and label constraints is constructed. Chinese character ambiguity is quantified through the ambiguity recognition module, metaphorical interpretation and label definition are generated by combining the large language model, context and metaphorical attention mechanism are used to improve semantic alignment, and triple comparison learning loss function optimization model is designed.

Benefits of technology

It improves the accuracy and robustness of Chinese text classification, can effectively capture the metaphorical content and label definitions in the text, and improves the deep semantic understanding ability of Chinese text classification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120256638A_ABST
    Figure CN120256638A_ABST
Patent Text Reader

Abstract

The invention discloses a Chinese text classification method based on metaphor association and label constraint comparative learning, and belongs to the technical field of natural language processing and artificial intelligence. A classification model construction method comprises the steps that an ambiguity recognition module is constructed to quantify voice and syntactic ambiguity of characters, and high ambiguity expression is recognized; a cue word management module is constructed, metaphor interpretation and label definition description are generated through a large language model, and the text semantic understanding depth is enhanced; designing a context attention mechanism and a metaphor attention mechanism, dynamically adjusting a feature weight and realizing label definition alignment; and constructing a loss function based on triple contrast learning, enhancing relevance between metaphor content and tags, and inhibiting irrelevant literal features at the same time. The Chinese text classification method is remarkably superior to a traditional model method in tasks such as metaphor sentiment classification and poetry theme classification, and the accuracy and robustness of Chinese text classification are effectively improved.
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 artificial intelligence, and in particular relates to a Chinese text classification method based on metaphor association and label constraint contrast learning. Background Art

[0002] With the rapid development of natural language processing technology, Chinese text classification plays an important role in public opinion analysis, literary research and commercial applications. However, the language characteristics of Chinese as an ideographic writing system bring unique challenges to its deep semantic understanding. Compared with English and other phonological languages, Chinese characters carry rich cultural metaphors and context-dependent extended semantics through a structure that combines form, sound and meaning. Especially in satirical comments, classical poetry and other genres, metaphorical expressions are highly intensive and present multi-level cognitive associations. For example, "A thousand sails pass by the side of the sunken boat, and a thousand trees bloom in front of the dead tree" metaphorically compares adversity and new philosophical thoughts through natural scenes. There is often a significant cognitive gap between its literal features and real semantics. Traditional text classification models (such as TextCNN and BiLSTM) mainly rely on surface features such as word frequency and syntax to construct sparse vector representations, which are difficult to capture implicit semantic associations, and cannot effectively bridge the semantic gap between literal features and label space, resulting in a significant decrease in classification performance in metaphor-intensive scenarios. Although pre-trained language models (such as BERT and RoBERTa) have improved their semantic representation capabilities through large-scale corpus learning, they were originally designed for general contexts and do not quantify the semantic ambiguity caused by polyphones and multiple parts of speech unique to Chinese. For example, the Chinese character “长” has multiple parts of speech, such as adjective (cháng) and verb (zhǎng). Traditional methods lack a dynamic evaluation mechanism for such ambiguous features, which makes it difficult for the model to distinguish the contribution of key semantic nodes in metaphorical texts.

[0003] In recent years, Large Language Models (LLMs) have shown potential in the field of metaphor understanding. Through prompt engineering, they can generate context-related metaphor interpretations. However, existing research has mostly focused on the English context. There are two major bottlenecks in the generation of Chinese metaphors: first, the cultural specificity of the Chinese character structure makes metaphorical associations highly dependent on historical allusions and idiom knowledge, and general large language models (LLMs) (such as ChatGPT, Deepseek, etc.) are difficult to accurately capture such implicit associations; second, there is a lack of semantic alignment mechanism between label definitions and generated metaphors, which leads to a disconnect between the generated content and the classification goals. Summary of the invention

[0004] The object of the present invention is to provide a Chinese text classification method based on metaphorical association and label-constrained contrastive learning, which solves the semantic gap problem between metaphorical expressions and literal features in Chinese texts by quantifying text ambiguity and integrating metaphorical interpretations and label definitions. The steps are as follows: constructing a metaphorical association model for classifying Chinese texts; the metaphorical association model includes an input layer, a representation layer, and a classification layer;

[0005] The input layer is used to divide the Chinese text to be classified into a character sequence map the Chinese text to a metaphorical interpretation sentence ; and map the classification label to a label definition

[0006] The representation layer is used to process the character sequence metaphorical interpretation sentence and label definition into text embedding vectors metaphorical interpretation embedding vectors and label definition embedding vectors respectively; adopt a context attention mechanism to capture the context relationship between the text embedding vector and the label definition embedding vector to obtain a weighted context representation vector of the Chinese text

[0007] Adopt a metaphor attention mechanism to adjust the metaphorical interpretation under label constraints to obtain a metaphor attention representation vector; the context attention mechanism and the metaphor attention mechanism are respectively used to identify the label directivity of literal features and metaphorical features, and improve the deep semantic alignment between the text and the label; The classification layer is used to splice the weighted context representation vector of the Chinese text

[0008] and the metaphor attention representation vector, input them into a linear transformation layer, and obtain a classification prediction result; the splicing refers to the connection of parallel vectors, retaining the feature independence of both.

[0009] Furthermore, the input layer includes an ambiguity recognition module and a cue word management module; The ambiguity recognition module is used to divide the Chinese text into a character sequence

[0010]

[0011] where represents the th Chinese character in the character sequence, is the total number of characters in the Chinese text ;

[0012] The prompt word management module is used to map the Chinese text to a metaphorical interpretation sentence , and map the classification label to a label definition .

[0013] Furthermore, the mapping of the Chinese text to a metaphorical interpretation sentence , and the mapping of the classification label to a label definition are expressed as:

[0014] ,

[0015] ,

[0016] where represents generation by the large language model represents a prompt word template for generating context-based metaphorical interpretations represents a prompt word template for generating label definitions represents a predefined set of classification labels represents the number of labels is the dataset task description

[0017] Furthermore, the ambiguity recognition module is also used to calculate the ambiguity score of the Chinese text , which is expressed as follows: ;

[0018] ;

[0019] where represents the ambiguity score of the character ;

[0020] ;

[0021] where is the number of pronunciation types of the character , is the number of part-of-speech types of the character .

[0022] By introducing the quantification of the polysemy of Chinese characters and combining the phonetic complexity and part-of-speech complexity of characters, the ambiguity score of the text is calculated, further enhancing the model's ability to process polysemous texts

[0023] Furthermore, at the representation layer, a shared BERT series encoder is used to process the character sequence , metaphorical interpretation sentences and label definitions are separately processed into text embedding vectors , metaphor interpretation embedding vectors and label definition embedding vectors .

[0024] Furthermore, a context attention mechanism is adopted to capture the context relationship between the text embedding vector and the label definition embedding vector to obtain a weighted context representation vector of the Chinese text. The specific steps are as follows:

[0025] Let , be the embedding dimension, denotes the encoding embedding of the th character;

[0026] Let , where is the number of labels, denotes the encoding embedding of the th label definition;

[0027] The initial context attention distribution uses the attention weight which is expressed as:

[0028]

[0029] where, i ∈ [1, n] , j ∈ [1, m] , denotes transpose of, denotes the attention weight between the th character and the th label definition, denotes the encoding embedding of the th character;

[0030] Calculate the ambiguity adjustment factor of the character embedding , which is expressed as:

[0031]

[0032] Based on the ambiguity adjustment factor adjust the attention weight to obtain the adjusted attention weight , which is expressed as:

[0033]

[0034] Normalize the adjusted attention weights to obtain the normalized adjusted attention weights , expressed as:

[0035] ;

[0036] where represents the adjusted attention weight between the th character and the th label definition;

[0037] The weighted context representation vector of the Chinese text , expressed as: , expressed as:

[0038]

[0039] where is the matrix representation of the adjusted attention weight ;

[0040] Next, use a pooling operation to fix the size of the representation vector to obtain the weighted context representation vector of the final Chinese text :

[0041]

[0042] Furthermore, use a metaphor attention mechanism to adjust the metaphor interpretation under label constraints to obtain a metaphor attention representation vector. The specific steps are as follows:

[0043] Calculate the metaphor attention weight matrix , expressed as:

[0044] ,

[0045] where represents the metaphor attention weight matrix, represents the metaphor interpretation embedding vector, is the label definition embedding vector, represents the transpose of the label definition embedding vector ;

[0046] The embedding vector obtained after calculation by the metaphor attention mechanism, expressed as:

[0047]

[0048] Perform a pooling operation on the embedding vector as follows:

[0049]

[0050] is the final metaphor attention representation vector that integrates attention information and label definition.

[0051] Further, the weighted context representation vector of the Chinese text is concatenated with the metaphor attention representation vector and input into a linear transformation layer to obtain a classification prediction result, specifically:

[0052] Concatenate the context representation and the metaphor attention representation vector to form the final representation vector of the Chinese text, expressed as:

[0053] Z=[ R C ; R D ]

[0054] Input the representation vector into a linear transformation layer to convert it into a numerical vector of the classification label:

[0055] ,

[0056] where is the weight matrix, is the bias vector;

[0057] Then, through the Softmax function, obtain the probability distribution of the predefined classes, and finally select the label with the highest probability as the classification prediction result of the Chinese text , expressed as:

[0058] .

[0059] Further, during the process of training the metaphor association model, the loss function adopted is:

[0060]

[0061] where λ ∈ (0, 1] is the proportional adjustment hyperparameter used to balance the weights of the cross-entropy loss and the triplet contrast loss ;

[0062] The cross-entropy loss , expressed as:​

[0063] ; wherein, is the dataset for the classification task, is represented as Chinese text assign labels for the calculated probability;

[0064] ;

[0065] wherein, is the similarity distance function, i ∈ [1,n] is the th Chinese text in the dataset index, represents the th Chinese text in the training sample set context representation vector, as a negative sample, belonging to the context representation vector ; represents the th Chinese text in the training sample set metaphorical interpretation embedding vector, also known as the anchor point in the triple contrast loss, belonging to the metaphorical interpretation embedding vector ; represents the th Chinese text in the training sample set label definition representation vector, as a positive sample, belonging to the label definition representation vector ; is a margin parameter.

[0066] Beneficial effects: The present invention models and classifies Chinese text based on the large language model-based metaphor association model (L-MAM). Compared with traditional processing methods, it can more effectively utilize the advantages of the large language model to analyze the metaphorical content and label definition of Chinese text, achieve the prediction of the belonging category, thereby providing reference information for the analysis and mining of Chinese text data on the Internet, having a certain practical application value, and being able to bring certain potential economic benefits to some related text information platforms.

[0067] In the present invention, the large language model-based metaphor association model (L-MAM) is used to model and classify Chinese text. By combining the large language model and deep learning technologies, it can provide certain technical support for the practice in the fields of Chinese natural language processing, text mining, etc. It is a technical solution that integrates ambiguity quantification, dynamic attention, and label-constrained contrast learning.

[0068] (1) The ambiguity recognition module ARM in the present invention measures and quantifies the ambiguity degree of the input original text by deeply analyzing the pronunciation quantity and different parts of speech of Chinese characters;

[0069] (2) We designed a metaphor association mechanism that leverages the capabilities of the large language model (LLM) to introduce reasonable extended explanations and label definitions based on context generation to enrich text representation.

[0070] (3) Two dual attention mechanisms are designed, including the contextual attention mechanism and the metaphorical attention mechanism. The contextual attention mechanism is used to align the contextual character semantics with the label definition, and the metaphorical attention mechanism is used to align the metaphorical interpretation with the label definition, thereby improving the accuracy and rationality of the text semantic representation.

[0071] (4) We designed a “label-constrained context-metaphor contrastive learning mechanism” that can effectively bring metaphor interpretation closer to label definition while keeping a distance between metaphor interpretation and relatively irrelevant contextual character semantics. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required to be used in the embodiments are briefly introduced below.

[0073] Figure 1 It is a flow chart of the Chinese text classification method based on metaphor association and label constraint contrast learning of the present invention.

[0074] Figure 2 It is a flow chart of the prompt word management module of the present invention mapping Chinese text into metaphorical explanation sentences.

[0075] Figure 3 This is a Chinese text classification model diagram based on metaphor association and label constraint contrast learning of the present invention. DETAILED DESCRIPTION

[0076] The technical solutions in the embodiments of the present invention are described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of the present invention.

[0077] The present invention provides a Chinese text classification method based on metaphor association and label constraint contrast learning. The Chinese text classification model is used to effectively predict the category label to which a Chinese text belongs. By utilizing the capabilities of the Large Language Model (LLM), combined with potential metaphor interpretation and label definition, the effect of Chinese text classification tasks is improved. Given a Chinese text and a set of predefined classification labels , assign each text to the most appropriate category label. Let the classification function is the classification function to be learned. The classification function can effectively capture the literal and metaphorical meanings hidden in the text, as well as the deep semantics defined by the labels. The problem can be defined as:

[0078] ,

[0079] where represents the metaphorical interpretation extracted from the Chinese text , represents the label definition of the classification label set , represents the task description of the data set represents the conditional probability.

[0080] The present invention proposes a Chinese text classification method based on metaphorical association and label-constrained contrastive learning, including constructing a metaphorical association model for classifying Chinese texts; in this specific embodiment, the metaphorical association model is a large language model-based metaphorical association model (LLM-based Metaphorical Association Model, L-MAM), and the construction method is as Figure 1 shown, specifically as follows;

[0081] Step 1, Input layer design

[0082] The input layer is the basis of the large language model-based metaphorical association model (L-MAM) and is responsible for processing and encoding the input text. The input layer converts the original text input into a format suitable for subsequent layer processing. The input layer also includes an ambiguity recognition module ARM and a large language model-driven prompt management module for the ambiguity recognition module ARM to extract the ambiguity features of the text and the prompt management module to generate metaphorical interpretations and label definitions.

[0083] Step 1.1, Construct the ambiguity recognition module ARM:

[0084] A character or word may have multiple different meanings, and this phenomenon is called "ambiguity". In the context of the Chinese language and culture, ambiguity is very common in some specific literary forms, such as satirical / critical texts, classical literature, poetry, etc. In the present invention, the ambiguity of Chinese characters is quantified by considering both the phonetic changes and syntactic changes of Chinese characters. Since Chinese characters are the basic components of Chinese texts, the input Chinese text needs to be divided into a character sequence , where represents the th Chinese character in the character sequence, is the total number of characters in the text , and for each Chinese character Perform part-of-speech tagging (PoS Tagging). Then, calculate each Chinese character The number of different pronunciations and the number of different parts of speech represented by each character are calculated. The ambiguity score of , which can be used to adjust the importance weight of each character in the attention distribution, the ambiguity score It is expressed as:

[0085] ;

[0086] in, For characters The number of pronunciation types, For characters The number of parts of speech.

[0087] For example, the word “长” has two pronunciations (cháng / zhǎng) and four parts of speech (adjective, verb, adverb, noun). for

[0088] ;

[0089] In this embodiment, when the ambiguity score of a character is greater than 0.75, it is considered to have a high ambiguity potential. It is greater than 0.75, so the character “长” has a higher potential for ambiguity.

[0090] Next, define the Chinese text The ambiguity score of is the mean of all character ambiguity scores, expressed as:

[0091]

[0092] in, , the ambiguity score of the text Used for subsequent attention weight adjustment to guide the model to focus on high-ambiguity areas.

[0093] Step 1.2: Build the LLM prompt word management module

[0094] Large language models (LLMs) can be used to solve the metaphor problem that traditional text classification models only rely on surface features. The present invention uses a large language model as the prompt word management module in this application to convert the input Chinese text into It is mapped into a metaphorical explanation sentence, and the classification label is mapped to the corresponding label definition to activate the implicit semantic association and cultural connotation in the text, perform metaphorical interpretation of the input text and semantic association of the label definition, and improve the understanding of the deep semantics of Chinese text in text classification tasks, especially in texts with high information entropy and sparse literal features, so as to mine more implicit information.

[0095] Given input Chinese text , predefined classification label sets And dataset task description , the corresponding metaphorical interpretation sentence and tag definition It can be expressed as:

[0096] ,

[0097] ,

[0098] in, Represents large language model generation, It represents the prompt word template for generating context-based metaphor interpretation, as shown in Table 1. Indicates the prompt word template for generating label definitions, as shown in Table 2. and prompt templates The preset metaphor-guided sentence pattern and label explanation structure are in line with the Chinese text context.

[0099] Table 1. Large language model prompt word templates for generating metaphor interpretations

[0100]

[0101] Table 2 Large language model prompt word templates for generating label definitions

[0102]

[0103] Step 2: Presentation layer design

[0104] The representation layer is responsible for encoding various inputs into vector representations, including character sequences. , metaphorical explanation sentence and tag definition , and apply the attention mechanism to reasonably fuse the vector representation. The attention mechanism includes the context attention mechanism and the metaphor attention mechanism, so that metaphorical information, label definition information and literal features can be reasonably integrated in the text representation process, thereby improving the classification accuracy.

[0105] First, process the tokenized character sequence using the shared BERT (Bidirectional Encoder Representations from Transformers) series of encoders , the metaphor interpretation sentence and the label definition :

[0106] ,

[0107] Among them, represents the encoded embedding vector of the character sequence , also written as the text embedding vector, represents the embedding dimension, represents the metaphor interpretation sentence 's encoded embedding vector, also written as the metaphor interpretation embedding vector, represents the label definition 's encoded embedding vector, also written as the label definition embedding vector, represents the number of labels.

[0108] For example Figure 2 the example of the poem given in: "A thousand sails pass by the side of the sunken ship, and ten thousand trees thrive ahead of the withered tree." On the surface, this poem only describes a natural scene literally. A non-Chinese native speaker or a traditional Chinese text representation model may be confused by this abstract pure scene description. However, in fact, the image contrast in the Chinese text carries a profound metaphorical meaning far beyond the literal semantics: "The sunken ship" and "the withered tree" symbolize depression and failure, representing negative states or experiences. In contrast, "a thousand sails passing by" and "ten thousand trees thriving" symbolize progress, hope, and rejuvenation, embodying positive changes and new opportunities. The metaphorical interpretation of this poem is further that "the decline of the old things does not prevent the vigorous development of the new things, and all things in the world are constantly moving forward in renewal and hope."

[0109] Step 2.1, construct the context attention mechanism

[0110] Given the semantic differences between metaphorical information and literal features, the context attention mechanism is designed to capture the context relationship between the input text embedding vector and the label definition embedding vector . The context attention mechanism enables the metaphor association model to focus on the most relevant parts of the input text for each label definition.

[0111] Let , be the embedding dimension, represents the encoded embedding of the th character.

[0112] Similarly, let , where is the number of tags, represents the encoded embedding defined by the -th tag. Then the initial context attention distribution is:

[0113] ,

[0114] where, i ∈ [1, n] , j ∈ [1, m] , represents the overall context attention weight matrix, represents transpose of represents the encoded embedding of the -th character.

[0115] Next, considering that metaphorical semantics is usually irrelevant or opposite to the original semantics of literal features, the present invention proposes to use the ambiguity score of the input text to adjust the attention contribution weight of each Chinese character. This process can help the model pay more attention to those text parts with higher ambiguity:

[0116] 1) Ambiguity adjustment: For each character embedding , calculate its ambiguity adjustment factor , which is based on the ambiguity score of the character and the average ambiguity score of the Chinese text :

[0117]

[0118] If , it means that the ambiguity of this character is higher than the average level, and the metaphorical association model of the present invention should pay more attention to this character. On the contrary, if , the model should reduce its attention to this character.

[0119] 2) Adjusted attention distribution: Then, by multiplying the initial attention weight by the ambiguity adjustment factor , the attention weight defined by each tag is adjusted to obtain the adjusted attention weight , which is expressed as:

[0120]

[0121] Then, the adjusted attention weights of all characters are normalized to ensure that the adjusted attention weights The sum is 1, obtaining the dynamically adjusted attention distribution matrix :

[0122]

[0123] represents the adjusted attention weight between the th character and the definition of the th label;

[0124] After the above weight adjustment process, the matrix is multiplied by to obtain the weighted context representation of the input Chinese text :

[0125]

[0126] where is the matrix representation of the adjusted attention weight ;

[0127] Next, a pooling operation is used to fix the size of the representation vector:

[0128] ,

[0129] where is the context representation vector of the input Chinese text ;

[0130] Step 2.2, constructing the metaphor attention mechanism

[0131] Regarding the process of Chinese text understanding, the deep semantics extracted from metaphorical associations may be consistent with the literal features or may be in strong contrast to them.

[0132] Based on this, as a dual design to the context attention mechanism, the idea of the metaphor attention mechanism corresponds to the positive reinforcement phenomenon in contrastive learning. Considering the internal alignment between the metaphor essence and the label definition, the metaphor attention mechanism will be able to effectively realize metaphorical associations of literal semantics under label constraints, thus ensuring that the generated associated content is both meaningful and targeted.

[0133] However, different from the calculation process of the context attention mechanism weights, here represents the metaphor interpretation embedding vector, and the metaphor attention weight matrix is calculated as follows:

[0134] ,

[0135] where represents the metaphor attention weight matrix, Denote the metaphorical interpretation embedding vector, Define the embedding vector for the label.

[0136] The output of the metaphorical attention is:

[0137] ,

[0138] where, Denote the embedding vector obtained after calculating each label definition through the metaphorical attention mechanism.

[0139] In addition, in order to fix the size of the embedding representation vector, the following pooling operation is adopted:

[0140]

[0141] where, Is the final metaphorical attention representation vector that fuses the attention information and the label definition.

[0142] Step 3, Classification layer design

[0143] The classification layer is responsible for the final text classification task based on the rich text vector representation obtained in the previous steps.

[0144] Finally, concatenate the context representation and the metaphorical attention representation vector to form the Chinese text The final representation vector :

[0145] Z=[ R C ; R D ]

[0146] Compare context-metaphor learning:

[0147] To effectively integrate the literal and metaphorical semantics of Chinese texts, the present invention designs a "Label-constrained Contextual-metaphorical Contrastive Learning Mechanism", abbreviated as "Label-constrained Contrastive Learning Mechanism". This mechanism aims to effectively narrow the gap between metaphorical interpretations and label definitions, that is, to maximize similarity, while keeping metaphorical interpretations at a distance from the semantics of relatively unrelated contextual characters. By using the contrastive learning method, a stronger discrimination ability is established among metaphorical information, label definition information, and literal features, enabling the model to learn more valuable metaphorical associations and semantic correlations during the training process. Correspondingly, the triple contrast loss function designed by the present invention is as follows:

[0148]

[0149] where is the similarity distance function, i ∈ [1,n] is the index of the th Chinese text in the dataset , is the total number of all texts in the dataset, represents the metaphorical interpretation embedding vector of the th Chinese text in the training sample set, also known as the anchor point in the triple contrast loss (the metaphorical interpretation embedding vector without attention calculation), belonging to the metaphorical interpretation embedding vector , , represents the label definition representation vector of the th Chinese text in the training sample set, serving as the positive sample, belonging to the label definition representation vector ; ; represents the context representation vector of the th Chinese text in the training sample set, serving as the negative sample, belonging to the context representation vector ; ; is a margin parameter used to force the distance between the semantic anchor and the positive sample to be at least one interval smaller than the distance between the semantic anchor and the negative sample . If this condition is not met during the training process, the model parameters will be continuously adjusted and optimized through gradient descent.

[0150] The input of the classification layer is the final representation obtained through the metaphorical attention mechanism . The present invention applies a linear layer to convert the final text vector representation into a numerical vector of classification labels :

[0151] ,

[0152] Among them, is the weight matrix, is the bias vector.

[0153] During the classification judgment process of the model, the numerical vector of the classification label will obtain the probability distribution of the predefined categories through the Softmax function, and finally select the label with the highest probability as the classification prediction result of the input Chinese text :

[0154]

[0155] The role of the Softmax function is to map the input vector into a probability distribution, making each output value between [0,1], and the sum of all values is 1. It is often used in the output layer of multi-class classification problems.

[0156] Next is to calculate the cross-entropy loss between the predicted probability and the true label, which is more applicable to multi-class classification tasks, as it encourages the model to output confident predictions for the correct categories while penalizing incorrect predictions:

[0157] ;

[0158] Among them, is the dataset for the classification task, represents the calculated probability of assigning the label to the Chinese text .

[0159] The metaphor association model constructed by the present invention is trained as follows:

[0160] To support the validity verification of the method proposed by the present invention in the Chinese text classification task, the present invention constructs and organizes three Chinese metaphor datasets with different degrees of metaphoricity and ambiguity. At the same time, to provide character-level semantic support for the ambiguity recognition module ARM, an online Chinese dictionary is used as the basic database to obtain language attribute information such as the number of pinyins, parts of speech, and semantic item distributions of each Chinese character.

[0161] The relevant statistical information of the three Chinese metaphor datasets involved in the present invention is shown in Table 3:

[0162] Table 3 Three Chinese metaphor datasets

[0163]

[0164] 1. Weibo Sentiment Classification Dataset (WSC): This dataset contains 206,340 short Chinese Weibo texts, covering 22 daily topics, and is divided into three categories according to sentiment orientation: positive, neutral, and negative. The language form of this dataset is close to daily expressions, with a medium level of metaphor, and is suitable for testing the general sentiment classification ability of models. Among them, the training set contains 165,072 data, and the test set contains 41,268 data.

[0165] 2. Chinese Ancient Poetry Theme Classification Dataset (PTC): This dataset collects 17,103 Chinese classical poems and is divided into 21 theme categories, with high literary quality and rich metaphorical expressions, suitable for theme classification tasks in metaphorical contexts. Among them, the training set is 15,393, and the test set is 1,710. (Dataset reference: Y. Wei, L.Hu, Y. Zhu, J. Zhao, and B. Wu, “Knowledge-guided transformer for joint themeand emotion classification of chinese classical poetry,” IEEE / ACMTransactions on Audio, Speech, and Language Processing, vol. 32, pp. 4783–4794, 2024.)

[0166] 3. Chinese Ancient Poetry Semantic Matching Dataset (CPM): This dataset collects 24,498 modern paraphrased texts of Chinese ancient poems. The task objective is: given a modern text description, select the sentence with the most semantically matching from four ancient poem candidate sentences. This task examines the model's ability to understand deep semantics and metaphorical content. Among them, the training set contains 21,778, and the test set contains 2,720. (Dataset reference: W. Li, F. Qi, M. Sun, X. Yi, and J. Zhang,“Ccpm: A chinese classical poetry matching dataset,” arXiv preprint arXiv:2106.01979, 2021.)

[0167] The above three Chinese metaphor datasets cover text and semantic understanding tasks of various styles, providing sufficient support for the systematic evaluation of the generalization ability, ambiguity recognition ability, and metaphorical association ability of the method of the present invention.

[0168] Preprocess the Chinese text data in the dataset. The preprocessing refers to removing the null values or dirty data with a length less than 5 characters in the Chinese text data. Then, after shuffling the data in the dataset, 80% of the data is used as the training sample set, and the remaining 20% is used as the test sample set.

[0169] Based on the Chinese text in the training sample set and the corresponding set of class labels, optimize and train the metaphor association model using the target loss function, and evaluate the performance of the metaphor association model using the test sample set to obtain the trained metaphor association model.

[0170] Correspondingly, the final target loss function combines the standard cross-entropy loss and the triplet contrast loss, and the parameters of the metaphor association model are updated through an optimization algorithm to minimize the total loss:

[0171] ,

[0172] where λ ∈ (0, 1] is a proportional adjustment hyperparameter, whose value range is (0, 1], and the recommended range is [0.5, 0.8], which is used to balance and weights to achieve a trade-off between accurate classification and semantic contrast. It should be noted that when , the main cross-entropy loss responsible for the classification task evaluation will be completely removed, which is unreasonable in model design, so it is an open interval; and when , it means that the total loss will be completely the cross-entropy loss and the contrast loss will be completely removed. Through this design, by combining the cross-entropy loss and the triplet contrast loss, the model can distinguish different categories and effectively retain and capture the literal and metaphorical meanings in the text.

[0173] The method of the present invention is used for multi-class classification tasks of Chinese text, and is applicable to sub-tasks with metaphorical language expressions such as sentiment classification, public opinion analysis, and automatic classification of poems. The system constructed based on the method of the present invention can be embedded as a metaphor recognition module in the Chinese language intelligent processing platform into specific natural language understanding systems, including but not limited to macro application scenarios such as customer service Q&A systems, education evaluation platforms, and automatic classification of cultural works.

[0174] The above are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can still be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.

Claims

1. A Chinese text classification method, characterized in that, Construct a metaphorical association model for classifying Chinese texts; The metaphorical association model includes an input layer, a representation layer, and a classification layer; The input layer is used to divide the Chinese text to be classified into character sequences , map the Chinese text to metaphor interpretation sentences , and map the classification labels to label definitions ; The presentation layer is used to process the character sequence , the metaphor interpretation sentence and the tag definition into a text embedding vector , a metaphor interpretation embedding vector and a tag definition embedding vector ; Capture the context relationship between the text embedding vector and the label definition embedding vector to obtain the weighted context representation vector of the Chinese text ; Use the metaphor attention mechanism to adjust the metaphor interpretation under the label constraint to obtain the metaphor attention representation vector; The classification layer is used to splice the weighted context representation vector of the Chinese text and the metaphor attention representation vector, and input them into a linear transformation layer to obtain a classification prediction result.

2. The Chinese text classification method according to claim 1, characterized in that The input layer includes an ambiguity recognition module and a cue word management module; The ambiguity recognition module is used to divide the Chinese text into a character sequence , and the character sequence is expressed as: ; Among them, represents the th Chinese character in the character sequence, is the total number of characters in the Chinese text ; The prompt word management module is used to map Chinese text to metaphorical interpretation sentences , and map classification labels to label definitions .

3. The Chinese text classification method according to claim 2, wherein The above-mentioned Chinese text is mapped to a metaphorical interpretation sentence and the classification label is mapped to a label definition , which is expressed as: , , Among them, Indicates generated by the large language model, Indicates the prompt template for generating context-based metaphor interpretations, Indicates the prompt template for generating tag definitions, Indicates the predefined classification tag set, Is the number of tags, Is the dataset task description.

4. The Chinese text classification method according to claim 2, wherein The ambiguity recognition module is further configured to calculate the ambiguity score of the Chinese text as follows , which is expressed as follows: ; Among them, represents the ambiguity score of the character ; ; Among them, is the number of pronunciation types of the character , is the number of part-of-speech types of the character .

5. The Chinese text classification method according to claim 1, characterized in that At the presentation layer, a shared BERT series encoder is used to process the character sequence , metaphor interpretation sentences and label definitions into text embedding vectors , metaphor interpretation embedding vectors and label definition embedding vectors respectively.

6. The Chinese text classification method according to claim 4, characterized in that, Capture the text embedding vector using the context attention mechanism and the label definition embedding vector to obtain the weighted context representation vector of the Chinese text The specific steps are as follows: Let , be the embedding dimension, denote the encoded embedding of the -th character; Let , where is the number of labels, represents the encoded embedding defined by the -th label; The initial context attention distribution adopts attention weights which is expressed as: ; Among them, , , denotes the transpose of denotes the attention weight between the th character and the definition of the th label, denotes the encoded embedding of the th character; Calculate character embeddings for the ambiguity adjustment factor , expressed as: ; Based on the ambiguity adjustment factor Adjust the attention weights to obtain the adjusted attention weights , which is expressed as: ; Normalize the adjusted attention weights to obtain the normalized adjusted attention weights , which is expressed as: ; Among them, represents the adjustment attention weight between the th character and the th tag definition; Weighted context representation vector of Chinese text which is expressed as : ; Among them, is the matrix representation for adjusting the attention weights ; Next, a pooling operation is used to fix the size of the representation vector to obtain the final Chinese text of the weighted context representation vector : 。 7. The Chinese text classification method according to claim 6, characterized in that Adopt a metaphorical attention mechanism to adjust the metaphorical interpretation under label constraints to obtain a metaphorical attention representation vector. The specific steps are as follows: Calculate the metaphor attention weight matrix , which is expressed as: , Among them, represents the metaphor attention weight matrix, represents the metaphor interpretation embedding vector, is the embedding vector defined for the label, represents the transpose of the label definition embedding vector ; The embedding vector obtained after calculating through the metaphor attention mechanism , is expressed as: ; Perform pooling operation on the embedded vector as follows: ; It is the final metaphor attention representation vector that integrates attention information and label definition.

8. The Chinese text classification method according to claim 7, wherein Concatenate the weighted context representation vector of the Chinese text with the metaphor attention representation vector and input it into a linear transformation layer to obtain a classification prediction result, specifically: The context representation vector and the metaphor attention representation vector are concatenated to form the Chinese text The final representation vector , which is expressed as: ; The representation vector is input into the linear transformation layer and converted into a numerical vector of classification labels : , Among them, is the weight matrix, is the bias vector; Then, through the Softmax function, the probability distribution of predefined categories is obtained, and finally the label with the highest probability is selected As the Chinese text The classification prediction result is expressed as: 。 9. The Chinese text classification method according to claim 1, characterized in that, During the process of training the metaphorical association model, the loss function adopted is: ; Among them, is a proportional adjustment hyperparameter used to balance the cross-entropy loss and the triple contrast loss weights; Cross-entropy loss , expressed as: ; Among them, is the dataset for the classification task, represented as Chinese text assigned labels of the calculated probability; ; Among them, is the similarity distance function, is the index of the th Chinese text in the dataset , represents the th Chinese text in the training sample set 's context representation vector, which is used as a negative sample and belongs to the context representation vector ; represents the th Chinese text in the training sample set 's metaphorical interpretation embedding vector, which is also called the anchor point in the triple contrast loss and belongs to the metaphorical interpretation embedding vector ; represents the th Chinese text in the training sample set 's label definition representation vector, which is used as a positive sample and belongs to the label definition representation vector , is the margin parameter.

Citation Information

Patent Citations

  • Emotion classification model construction method based on metaphor recognition

    CN114942991A

  • Method for constructing sentiment classification model based on metaphor identification

    US20230289528A1

Cited By

  • Campus safety analysis early warning method and system fused with multi-modal reasoning capability

    CN120599772A

  • Product classification identification method and system based on AI technology

    CN120873855A

  • Product classification recognition method and system based on AI technology

    CN120873855B

  • Text classification method based on large model

    CN121256048A