Text classification model optimization method and text classification method and device

By performing fine-grained semantic unit division and multi-strategy data enhancement on text data, and optimizing the text classification model with preference reward function, the problem of poor text classification effect in few samples and unbalanced scenarios is solved, and higher accuracy and robustness are achieved.

CN120561301APending Publication Date: 2025-08-29WUHAN UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510646723.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-20
Publication Date
2025-08-29

AI Technical Summary

Technical Problem

The prior art has poor text classification effect in small samples, unevenness and complex semantic scenarios, making it difficult to capture deep semantic associations.

Method used

By dividing the original data set in fine-grained semantic units, supplementary text is generated using multi-strategy data augmentation method, and a preference reward function for keyword semantic scores and global semantic scores is constructed to guide the optimization of text classification model.

Benefits of technology

Improve the accuracy and robustness of text classification, and optimize the performance of the model in small samples and unbalanced scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120561301A_ABST
    Figure CN120561301A_ABST
Patent Text Reader

Abstract

The invention provides a text classification model optimization method and a text classification method and device.The method comprises the steps that each text in an original data set is divided, and semantic units of the texts at different levels are obtained; respectively enhancing the semantic units of each level by adopting different data enhancement modes, obtaining a preset number of supplementary texts for each text, and arranging the supplementary texts into an original data set to obtain an enhanced data set; constructing a preference reward function based on the keyword semantic score and the global semantic score; and on the enhanced data set, performing fine adjustment on the original text classification model by using a preference reward function to obtain an optimized text classification model. According to the method, a multi-strategy fine-grained data enhancement method is realized, a preference award function is constructed, and preference learning is introduced, so that model training is guided in the process of optimizing a text classification model, and the text classification model with higher accuracy and robustness is obtained through optimization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a text classification model optimization method, a text classification method and a device. Background Art

[0002] Text classification, a core task in natural language processing (NLP), aims to map input text to predefined category labels. It is widely used in scenarios such as sentiment analysis, news classification, legal judgment archiving, and medical text mining. Traditional methods rely on manual feature engineering and large amounts of high-quality annotated data, making it difficult to capture deep semantic connections. In practical applications, they often face challenges such as insufficient training samples, uneven data distribution, and complex semantic expressions.

[0003] Although deep learning methods achieve end-to-end learning, they still face bottlenecks in the problems of few samples, imbalanced categories, and the processing of complex semantics. Summary of the Invention

[0004] The present invention provides a text classification model optimization method, a text classification method and a device to solve the defects of the existing technology, such as poor text classification effect under small sample, imbalanced and complex semantic scenarios, and realize a text classification model optimization method to improve the accuracy and robustness of text classification.

[0005] The present invention provides a text classification model optimization method, comprising: Divide each text in the original data set to obtain semantic units of the text at different levels; Different data enhancement methods are used to enhance the semantic units at each level, respectively, to obtain a preset number of supplementary texts for each text, and the supplementary texts are sorted into the original data set to obtain an enhanced data set; Constructing a preference reward function based on a keyword semantic score and a global semantic score, wherein the keyword semantic score represents the semantic contribution of the key words of the enhanced dataset to the text category, and the global semantic score represents the semantic contribution of the complete text of each text data in the enhanced dataset to the text category; On the enhanced dataset, the preference reward function is used to fine-tune the original text classification model to obtain an optimized text classification model.

[0006] According to a text classification model optimization method provided by the present invention, the levels include vocabulary, phrases, and segments; the step of enhancing the semantic units of each level using different data enhancement methods specifically includes: When the semantic unit level is vocabulary, data augmentation is achieved by replacing synonyms and / or antonyms; When the semantic unit level is a phrase, data enhancement is achieved by sentence rewriting; When the semantic unit level is a segment, data augmentation is achieved by inserting similar text and / or deleting redundant text.

[0007] According to a text classification model optimization method provided by the present invention, before the step of constructing a preference reward function based on keyword semantic scores and global semantic scores, the method further includes: Defining a key vocabulary set of the enhanced data set, extracting the semantic contribution of each word in the keyword set to the text category through an attention mechanism, and determining the keyword semantic score based on the semantic contribution of each keyword in the keyword set; The semantic contribution of each piece of text data in the enhanced dataset to the text category is extracted through the attention mechanism, and the global semantic score is determined based on the semantic contribution of each piece of text data to the text category.

[0008] According to a text classification model optimization method provided by the present invention, the step of constructing a preference reward function based on keyword semantic scores and global semantic scores specifically includes: defining a confidence score based on a linear weighted sum of the keyword semantic score and the global semantic score; The preference reward function is constructed based on the confidence score.

[0009] According to a text classification model optimization method provided by the present invention, the step of fine-tuning the original text classification model using the preference reward function on the enhanced dataset to obtain an optimized text classification model specifically includes: The LoRA method is adopted to fine-tune the original text classification model using a preference reward function on the enhanced dataset, wherein the original text classification model is trained based on the original dataset.

[0010] The present invention also provides a text classification method, comprising: Get the text to be classified; The text to be classified is input into a classification model to obtain a text category of the text to be classified output by the classification model, wherein the classification model is trained using any of the above-mentioned text classification model optimization methods.

[0011] The present invention also provides a text classification model optimization device, comprising: A segmentation module is used to segment each text in the original data set to obtain semantic units of the text at different levels; An enhancement module is used to enhance the semantic units at each level using different data enhancement methods, obtain a preset number of supplementary texts for each text, and organize the supplementary texts into the original data set to obtain an enhanced data set; a determination module, configured to construct a preference reward function based on a keyword semantic score and a global semantic score, wherein the keyword semantic score represents the semantic contribution of the key words of the enhanced dataset to the text category, and the global semantic score represents the semantic contribution of the complete text of each text data in the enhanced dataset to the text category; The optimization module is used to fine-tune the original text classification model using the preference reward function on the enhanced dataset to obtain an optimized text classification model.

[0012] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the text classification model optimization method described above is implemented.

[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described text classification model optimization methods.

[0014] The present invention also provides a computer program product, comprising a computer program, which, when executed by a processor, implements any of the above-described text classification model optimization methods.

[0015] The text classification model optimization method, text classification method and device provided by the present invention divide the original text data into multiple semantic units of different levels and adopt different data enhancement measures for the semantic units of different levels to achieve data enhancement of the original text, thereby realizing a multi-strategy fine-grained data enhancement method. At the same time, by constructing a preference reward function, preference learning is introduced to guide model training in the process of optimizing the text classification model, strengthen the influence of higher-quality text data on the text classification model, and weaken the influence of lower-quality text data on the text classification model, thereby optimizing a text classification model with greater accuracy and robustness. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0017] Figure 1This is one of the flow charts of the text classification model optimization method provided by the present invention; Figure 2 This is the second flow chart of the text classification model optimization method provided by the present invention; Figure 3 It is a flowchart of the text classification method provided by the present invention; Figure 4 It is a structural diagram of the text classification model optimization device provided by the present invention; Figure 5 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0018] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.

[0019] The following combination Figure 1 and Figure 2 The text classification model optimization method of the present invention is introduced. Figure 1 Shown, including: Step 101: Divide each text in the original data set to obtain semantic units of the text at different levels; Collect raw text data related to the target classification task, such as news text, e-commerce reviews, academic papers, etc.

[0020] Optionally, the original text data can come from various channels such as the Internet, social media, and news reports.

[0021] Optionally, the collected data is preprocessed by, for example, data cleaning to remove noise information, such as HTML tags, special characters, etc., and necessary format conversion is performed to unify it into a text format, and the preprocessed raw text data is organized into an original data set.

[0022] The content of each data in the original data set is preprocessed text data, and the label is the text category corresponding to the text data.

[0023] On this basis, the text content of each text data in the original dataset is divided to obtain the semantic units of the text at different levels, so as to realize the division of fine-grained semantic units and provide a fine-grained semantic basis for data enhancement.

[0024] Optionally, semantic units at different levels may include any combination of at least two of words, phrases, sentences, and paragraphs.

[0025] For example, a piece of text data is divided into semantic units at two levels: words and phrases, or a piece of text data is divided into semantic units at three levels: words, phrases, and paragraphs.

[0026] In one feasible embodiment, a natural language processing tool such as NLTK, spaCy and / or Stanford CoreNLP is used to perform multi-dimensional semantic analysis on each text in the original text data, including but not limited to one or more of part-of-speech tagging, dependency parsing and named entity recognition.

[0027] Specifically, named entity recognition is used to extract entities such as names of people, organizations, and products in each text, and to identify key objects in the text; part-of-speech tagging is used to identify nouns, verbs, adjectives, and the like, and to locate core semantic vocabulary; dependency syntax analysis is used to construct grammatical dependency relationships between words, parse sentence structures, and split sentences into phrases such as subject, predicate, object, attributive, adverbial, and complement.

[0028] By performing multi-dimensional semantic analysis on each text data in the original data set in the above manner, each text is divided into semantic units at different levels, and semantic units at different levels of each text are obtained.

[0029] Taking the news article "Pineapple Company releases a new Pineapple phone with significantly improved performance" as an example, part-of-speech tagging identifies "Pineapple Company" as a noun phrase and "release" as a verb. Dependency parsing clarifies that "Pineapple Company" is the subject of "release." Named entity recognition identifies "Pineapple Company" as an organizational entity and "Pineapple Phone" as a product entity. Semantic role annotation identifies "Pineapple Company" as the agent of the action "release" and "Pineapple Phone" as the object. Semantic classification of the entire sentence is then performed as "commercial."

[0030] Finally, taking the semantic unit level as an example of words and phrases, at the word level, the example sentences are divided into pineapple company, release, new model, pineapple mobile phone, significant and improved; at the phrase level, the example sentences are divided into "pineapple company releases pineapple mobile phone" and "the performance of pineapple mobile phone is significantly improved."

[0031] Step 102: enhancing the semantic units at each level using different data enhancement methods, obtaining a preset number of supplementary texts for each text, and arranging the supplementary texts into the original data set to obtain an enhanced data set; On the basis of the above, the corresponding data enhancement method is defined in advance for the semantic units of each level, and the semantic units of each level obtained by dividing each text data in the original data set are enhanced using the data enhancement method corresponding to each level.

[0032] Taking the above news text as the text content and the semantic unit level as words and phrases as an example, at the lexical level, data enhancement is performed on the words. For example, "pineapple phone" is replaced with "banana phone" to obtain the supplementary text "Pineapple Company has released a new banana phone, and its performance has been significantly improved."

[0033] At the phrase level, the phrase "Pineapple Company releases Pineapple Mobile Phone" is rewritten to obtain the supplementary text "The new Pineapple Mobile Phone was released by Pineapple Official, and its performance has been significantly improved."

[0034] Through the above method, fine-grained data enhancement is achieved for each text in the original dataset at different levels of semantic units, thereby obtaining supplementary text with richer semantic content and more fine-grained content.

[0035] It is understandable that for a piece of text data, multiple words, phrases and / or sentences can be divided, and by using corresponding data enhancement methods at each semantic level, more supplementary texts can be obtained accordingly. However, a large number of supplementary texts will also lead to distortion of the content of the data set. Therefore, for a piece of original text data, several supplementary texts are selected from the supplementary texts corresponding to the semantic units at each level, and finally a preset number of supplementary texts are determined for a piece of text data.

[0036] Optionally, the preset number can be determined according to the amount of data in the original data set. If the amount of data is small, the preset number is correspondingly small. Preferably, 3 to 5 supplementary texts are determined for each text data in the original data set.

[0037] It should be noted that in this embodiment, the hierarchical source of the supplementary text is not limited, but efforts are made to ensure that in the final generated supplementary text, there is at least one corresponding supplementary text for each semantic level. For example, if there are three supplementary texts and the levels are divided into three different levels, one supplementary text determined at each level is selected as the final supplementary text. If there are five supplementary texts and the levels are divided into three different levels, two supplementary texts each are selected from the vocabulary and phrases, and one supplementary text determined by the sentence is selected as the final supplementary text.

[0038] Through the above method, a preset number of supplementary texts are generated for each text data in the original data. After the generated supplementary texts are assigned corresponding text category labels, they are organized in the original data set to obtain an enhanced data set.

[0039] Step 103: constructing a preference reward function based on the keyword semantic score and the global semantic score, wherein the keyword semantic score represents the semantic contribution of the key words of the enhanced dataset to the text category, and the global semantic score represents the semantic contribution of the complete text of each text data in the enhanced dataset to the text category; Furthermore, while fine-tuning the text classification model directly on the augmented dataset can achieve some optimization results, the data augmentation process inevitably introduces redundant text with low category similarity to the original text data, thus limiting the performance of the fine-tuned text classification model. For example, if the word "mobile phone" in the above example sentence is replaced with "agriculture" when obtaining supplementary text, the text category may change from business or technology to agriculture, meaning that "pineapple," a brand name, will be recognized as a fruit.

[0040] To this end, when fine-tuning the text classification model, a preference reward function based on keyword semantics and global semantics is introduced to drive the text classification model to learn the co-occurrence relationship between semantic units, so as to achieve better classification performance for the model through the Direct Preference Optimization algorithm (DPO).

[0041] Specifically, the keywords of the enhanced dataset are words with practical meaning in the text of the enhanced dataset, such as entity words and sentiment words. Optionally, the semantic unit division results at the vocabulary level can be sorted and deduplicated as the keyword set of the enhanced dataset; the global semantics of the enhanced dataset are the semantics of the complete text in the text of the enhanced dataset.

[0042] Optionally, a keyword set is determined based on the text category of the enhanced dataset, and the relevance of each keyword to the text category is calculated based on the content of each text in the enhanced dataset as the semantic score of each keyword. The keyword semantic score of the enhanced dataset is determined based on the semantic unit score of each keyword.

[0043] Optionally, the relevance of each piece of text data in the enhanced dataset to the text category is calculated based on the complete text content thereof, and the global semantic score of the enhanced dataset is determined based on the relevance of each piece of text data.

[0044] On this basis, a preference reward function is constructed based on keyword semantic scores and global semantic scores to achieve fine-grained preference modeling. The constructed preference reward function enables the model to learn the semantic relationship between features during the optimization process of the text classification model.

[0045] Taking the above news text as an example, the preference reward function aims to calculate the contribution of words such as "Pineapple Company" and "Pineapple Mobile Phone" in the text classification task, as well as the impact of the global semantics of the complete sentence on the classification. It also analyzes the co-occurrence relationship and semantic similarity relationship between semantic units such as "Pineapple Company" and "Pineapple Mobile Phone". In the design of the preference reward function, higher rewards are given to model decisions that can accurately capture this relationship and correctly classify this text into the "Technology" category.

[0046] Step 104 : fine-tune the original text classification model using the preference reward function on the enhanced dataset to obtain an optimized text classification model.

[0047] Optionally, the original text classification model may be a text classification model trained on the original data set, or may be other known text classification models that can perform classification tasks on text of this category.

[0048] Furthermore, on the enhanced dataset, the constructed preference reward function is used to fine-tune the original text classification model through a direct preference optimization algorithm to obtain an optimized text classification model.

[0049] The present invention realizes data enhancement of the original text by dividing the original text data into multiple semantic units of different levels and adopting different data enhancement measures for the semantic units of different levels, thereby realizing a multi-strategy fine-grained data enhancement method. At the same time, by constructing a preference reward function and introducing preference learning, the method guides model training in the process of optimizing the text classification model, strengthens the influence of higher-quality text data on the text classification model, and weakens the influence of lower-quality text data on the text classification model, thereby optimizing a text classification model with greater accuracy and robustness.

[0050] In the text classification model optimization method of the present invention, the levels include vocabulary, phrases, and segments; the step of enhancing the semantic units of each level using different data enhancement methods specifically includes: When the semantic unit level is vocabulary, data augmentation is achieved by replacing synonyms and / or antonyms; In this embodiment, each text in the original text dataset is divided into three semantic levels: vocabulary, phrases, and segments, and a corresponding data enhancement method is proposed for each semantic level to achieve hierarchical data enhancement.

[0051] When the semantic unit is at the vocabulary level, we use word frequency statistics and semantic importance assessment to identify high-frequency and semantically interchangeable words in the segmented vocabulary. We then use dictionaries such as WordNet to replace these words with synonyms and / or antonyms. It is important to note that when replacing antonyms, the corresponding classification labels must also be modified to ensure data accuracy and consistency.

[0052] When the semantic unit level is a phrase, data enhancement is achieved by sentence rewriting; Optionally, at the phrase level, the word order of the phrases can be adjusted according to the dependency syntactic tree, such as transcribing active sentences into passive sentences. Text retelling technology can also be used to generate phrases with different syntactic structures but semantically equivalent, thereby achieving data enhancement by rewriting the original phrases.

[0053] For example, "Xiao Ming ate the apple" can be converted to "The apple was eaten by Xiao Ming."

[0054] When the semantic unit level is a segment, data augmentation is achieved by inserting similar text and / or deleting redundant text.

[0055] It can be understood that a segment may include several sentences. For example, if the text content is a sentence, the complete text content is determined as a segment; if the text content is a complete article, the article can be divided into multiple segments according to the logic of the article, and each segment includes several complete sentences.

[0056] Optionally, at the segment level, by calculating cosine similarity or other methods, we can identify semantically relevant segments from similar texts and insert them into the current segment. Alternatively, we can delete redundant, low-frequency segments from the current segment to balance text length and semantic integrity. For example, in a mobile phone review, we can extract relevant advantages and disadvantages from other reviews and insert them into the current segment.

[0057] The supplementary text produced through the above-mentioned data augmentation method not only maintains the original semantics but also has syntactic and lexical diversity, effectively alleviating the problems of data scarcity and category imbalance.

[0058] In the text classification model optimization method of the present invention, before the step of constructing the preference reward function based on the keyword semantic score and the global semantic score, the method further includes: Defining a key vocabulary set of the enhanced data set, extracting the semantic contribution of each word in the keyword set to the text category through an attention mechanism, and determining the keyword semantic score based on the semantic contribution of each keyword in the keyword set; In order to determine the keyword semantic score, in this embodiment, the keyword semantic contribution to the classification result, that is, the contribution to the text category, is first calculated through the attention mechanism to obtain the keyword semantic score.

[0059] Specifically, the keyword set in the enhanced dataset is defined as , n Indicates the number of keywords in the augmented dataset.

[0060] The influence of each keyword on the classification result is extracted through the attention mechanism: The attention mechanism is i The attention weight of keywords, For the i Hidden representation of keywords, is the learning vector (learnable parameter) of the keyword semantic score, then the keyword semantic score can be expressed as: ; Where, is an activation function, such as sigmoid, is the attention score, which can be calculated by self-attention mechanism, cross-attention mechanism or other attention mechanisms; It represents the semantic contribution score of the keyword to the classification task, that is, the keyword semantic score.

[0061] The semantic contribution of each piece of text data in the enhanced dataset to the text category is extracted through the attention mechanism, and the global semantic score is determined based on the semantic contribution of each piece of text data to the text category.

[0062] Further, let is the vector representation of all words in each text data, The learned vector for global semantic scoring, For the i The attention weight of the text category of the word pair and its corresponding text data is is the global semantic representation vector of the data, and the global semantic score can be expressed as: ; Where, is an activation function, such as sigmoid, It represents the semantic contribution score of the overall semantics of the text data to the text category, that is, the global semantic score.

[0063] In the text classification model optimization method of the present invention, the The steps for constructing the preference reward function based on keyword semantic scoring and global semantic scoring include: defining a confidence score based on a linear weighted sum of the keyword semantic score and the global semantic score; The preference reward function is constructed based on the confidence score.

[0064] After determining the keyword semantic score and the global semantic score, a fine-grained confidence score is defined based on these two scores: ; Where, , used to control the weighted ratio of keyword semantics to global semantics.

[0065] On this basis, before constructing the preference reward function, it is also necessary to define the preference relationship. Specifically, by analyzing the semantic similarity and syntactic dependency strength between semantic units, a preference relationship graph is constructed to define the priority of feature interaction.

[0066] Then, we construct a preference reward function. Specifically, we encode the confidence score and the preference relationship as a reward signal to guide the model to learn the semantic relationship between features. We use the confidence score as a weighted term to assign different importance to the loss function to each sample. The preference reward function is constructed as follows: ; In the formula, Indicates that on sample x, and Quantifying semantic differences and fine-grained preference confidence.

[0067] In the text classification model optimization method of the present invention, the step of fine-tuning the original text classification model using the preference reward function on the enhanced dataset to obtain an optimized text classification model specifically includes: The LoRA method is adopted to fine-tune the original text classification model using a preference reward function on the enhanced dataset, wherein the original text classification model is trained based on the original dataset.

[0068] In this embodiment, the optimization of the original text classification model is carried out in two steps: the first is the optimization of the reinforcement learning strategy based on direct preference optimization (DPO), and the second is the joint optimization of the fusion supervised learning.

[0069] In a specific implementation, after constructing the preference reward function, the Direct Preference Optimization (DPO) algorithm can be used to build a reinforcement learning framework. The model is considered an intelligent agent, the state is defined as the set of semantic units of the current input text and the historical decision record, and the actions include sample selection strategy, feature learning strategy, and classification decision strategy. The Direct Preference Optimization (DPO) algorithm can be understood through the following formula and steps: Set two strategies and , the reward model selects a more preferred strategy, and the model preference can be expressed as: ; Where, is the expected return of the strategy, is the activation function, usually the Logistic function. The optimization goal of direct preference optimization is to maximize the probability of model preference, which can be expressed as: ; Where is the policy parameter, A is the preference dataset, which is the enhanced dataset in this implementation. The direct preference optimization algorithm (DPO) updates the model policy parameters by alternating between policy generation and preference feedback during training: ; Where, is the learning rate, is the gradient of the neural network.

[0070] Based on the above formula, the fine-grained confidence score and preference reward function are integrated to drive the model to adaptively adjust the strategy during training.

[0071] Using the Direct Preference Optimization (DPO) algorithm, during the interaction between the model and data samples, for example, given a text sample containing the words "pineapple company" and "pineapple phone," the model updates its parameters based on its current state (such as learned semantic features and preference relationships) and action selection strategy. If the model correctly identifies a close association between the two and makes a reasonable classification decision, it is rewarded according to the preference reward function. Otherwise, it is penalized, thereby dynamically adjusting the strategies for sample selection, feature learning, and classification decisions.

[0072] Through the above approach, DPO-based reinforcement learning optimization can be implemented for the original text classification model. In this embodiment, the original text classification model is trained based on a supervised learning strategy on the constructed original dataset. Therefore, when optimizing the original text classification model, this embodiment also optimizes the model through a joint optimization approach.

[0073] In one feasible implementation, the LoRA method is used to fine-tune the model optimized based on DPO, integrating supervised learning loss and reinforcement learning reward to construct a joint optimization objective: ; Where, Cross-entropy loss in supervised learning to ensure the model's ability to fit the labeled data; A preference reward function that incorporates fine-grained confidence scores , guiding the model to learn semantic relation preferences, and is the weight parameter (determined by tuning on the validation set). Use stochastic gradient descent (SGD) or Adam optimizer to minimize the joint loss, combining the stability of supervised learning with the flexibility of reinforcement learning.

[0074] like Figure 2 As shown, the above method realizes the joint optimization training of the original text classification model, thereby realizing the optimization of the original text classification model.

[0075] The present invention introduces a multi-level fine-grained semantic feature mining and enhancement strategy, a preference optimization modeling mechanism based on fine-grained confidence scoring, and a preference-driven reinforcement learning framework to achieve a deep understanding and adaptive optimization of text semantics, thereby improving the accuracy and robustness of text classification in small-sample, unbalanced, and complex semantic scenarios.

[0076] The text classification method provided by the present invention is described below. Figure 3 As shown, the method includes: Step 301: Obtain the text to be classified; The text to be classified is the text set that needs to complete the text classification task.

[0077] Step 302: input the text to be classified into a classification model to obtain the text category of the text to be classified output by the classification model, wherein the classification model is trained using the text classification model optimization method described above.

[0078] The text to be classified is input into the text classification model optimized by the above method. The text classification model extracts fine-grained semantic features from the input text, and the reinforcement learning control module dynamically selects features according to the strategy learned through training. The category probability distribution is output through the text classification module, and finally the category corresponding to the maximum probability value is taken as the classification result.

[0079] For example, for an e-commerce review about pineapple agricultural products, "The pineapple company has released a new pineapple phone with significantly improved performance," the model can accurately classify it as a positive category; while for a fine-grained enhanced data sample, "The pineapple company has released a new pineapple phone with significantly reduced performance," the model can accurately classify it as a negative category.

[0080] The text classification model optimization device provided by the present invention is described below. The text classification model optimization device described below and the text classification model optimization method described above can be referenced to each other.

[0081] like Figure 4As shown, the text classification model optimization device includes a division module 401, an enhancement module 402, a determination module 403 and an optimization module 404; A segmentation module 401 is used to segment each text in the original data set to obtain semantic units of the text at different levels; Collect raw text data related to the target classification task, such as news text, e-commerce reviews, academic papers, etc.

[0082] Optionally, the original text data can come from various channels such as the Internet, social media, and news reports.

[0083] Optionally, the collected data is preprocessed by, for example, data cleaning to remove noise information, such as HTML tags, special characters, etc., and necessary format conversion is performed to unify it into a text format, and the preprocessed raw text data is organized into an original data set.

[0084] The content of each data in the original data set is preprocessed text data, and the label is the text category corresponding to the text data.

[0085] On this basis, the text content of each text data in the original dataset is divided to obtain the semantic units of the text at different levels, so as to realize the division of fine-grained semantic units and provide a fine-grained semantic basis for data enhancement.

[0086] Optionally, semantic units at different levels may include any combination of at least two of words, phrases, sentences, and paragraphs.

[0087] For example, a piece of text data is divided into semantic units at two levels: words and phrases, or a piece of text data is divided into semantic units at three levels: words, phrases, and paragraphs.

[0088] In one feasible embodiment, a natural language processing tool such as NLTK, spaCy and / or Stanford CoreNLP is used to perform multi-dimensional semantic analysis on each text in the original text data, including but not limited to one or more of part-of-speech tagging, dependency parsing and named entity recognition.

[0089] Specifically, named entity recognition is used to extract entities such as names of people, organizations, and products in each text, and to identify key objects in the text; part-of-speech tagging is used to identify nouns, verbs, adjectives, and the like, and to locate core semantic vocabulary; dependency syntax analysis is used to construct grammatical dependency relationships between words, parse sentence structures, and split sentences into phrases such as subject, predicate, object, attributive, adverbial, and complement.

[0090] By performing multi-dimensional semantic analysis on each text data in the original data set in the above manner, each text is divided into semantic units at different levels, and semantic units at different levels of each text are obtained.

[0091] An enhancement module 402 is configured to enhance the semantic units at each level using different data enhancement methods, obtain a preset number of supplementary texts for each text, and organize the supplementary texts into the original data set to obtain an enhanced data set; On the basis of the above, the corresponding data enhancement method is defined in advance for the semantic units of each level, and the semantic units of each level obtained by dividing each text data in the original data set are enhanced using the data enhancement method corresponding to each level.

[0092] Taking the above news text as the text content and the semantic unit level as words and phrases as an example, at the lexical level, data enhancement is performed on the words. For example, "pineapple phone" is replaced with "banana phone" to obtain the supplementary text "Pineapple Company has released a new banana phone, and its performance has been significantly improved."

[0093] At the phrase level, the phrase "Pineapple Company releases Pineapple Mobile Phone" is rewritten to obtain the supplementary text "The new Pineapple Mobile Phone was released by Pineapple Official, and its performance has been significantly improved."

[0094] Through the above method, fine-grained data enhancement is achieved for each text in the original dataset at different levels of semantic units, thereby obtaining supplementary text with richer semantic content and more fine-grained content.

[0095] It is understandable that for a piece of text data, multiple words, phrases and / or sentences can be divided, and by using corresponding data enhancement methods at each semantic level, more supplementary texts can be obtained accordingly. However, a large number of supplementary texts will also lead to distortion of the content of the data set. Therefore, for a piece of original text data, several supplementary texts are selected from the supplementary texts corresponding to the semantic units at each level, and finally a preset number of supplementary texts are determined for a piece of text data.

[0096] Optionally, the preset number can be determined according to the amount of data in the original data set. If the amount of data is small, the preset number is correspondingly small. Preferably, 3 to 5 supplementary texts are determined for each text data in the original data set.

[0097] It should be noted that in this embodiment, the hierarchical source of the supplementary text is not limited, but efforts are made to ensure that in the final generated supplementary text, there is at least one corresponding supplementary text for each semantic level. For example, if there are three supplementary texts and the levels are divided into three different levels, one supplementary text determined at each level is selected as the final supplementary text. If there are five supplementary texts and the levels are divided into three different levels, two supplementary texts each are selected from the vocabulary and phrases, and one supplementary text determined by the sentence is selected as the final supplementary text.

[0098] Through the above method, a preset number of supplementary texts are generated for each text data in the original data. After the generated supplementary texts are assigned corresponding text category labels, they are organized in the original data set to obtain an enhanced data set.

[0099] Determining module 403, configured to construct a preference reward function based on a keyword semantic score and a global semantic score, wherein the keyword semantic score represents the semantic contribution of the key words of the enhanced dataset to the text category, and the global semantic score represents the semantic contribution of the complete text of each text data in the enhanced dataset to the text category; Furthermore, while fine-tuning the text classification model directly on the augmented dataset can achieve some optimization results, the data augmentation process inevitably introduces redundant text with low category similarity to the original text data, thus limiting the performance of the fine-tuned text classification model. For example, if the word "mobile phone" in the above example sentence is replaced with "agriculture" when obtaining supplementary text, the text category may change from business or technology to agriculture, meaning that "pineapple," a brand name, will be recognized as a fruit.

[0100] To this end, when fine-tuning the text classification model, a preference reward function based on keyword semantics and global semantics is introduced to drive the text classification model to learn the co-occurrence relationship between semantic units, so as to achieve better classification performance for the model through the Direct Preference Optimization algorithm (DPO).

[0101] Specifically, the keywords of the enhanced dataset are words with practical meaning in the text of the enhanced dataset, such as entity words and sentiment words. Optionally, the semantic unit division results at the vocabulary level can be sorted and deduplicated as the keyword set of the enhanced dataset; the global semantics of the enhanced dataset are the semantics of the complete text in the text of the enhanced dataset.

[0102] Optionally, a keyword set is determined based on the text category of the enhanced dataset, and the relevance of each keyword to the text category is calculated based on the content of each text in the enhanced dataset as the semantic score of each keyword. The keyword semantic score of the enhanced dataset is determined based on the semantic unit score of each keyword.

[0103] Optionally, the relevance of each piece of text data in the enhanced dataset to the text category is calculated based on the complete text content thereof, and the global semantic score of the enhanced dataset is determined based on the relevance of each piece of text data.

[0104] On this basis, a preference reward function is constructed based on keyword semantic scores and global semantic scores to achieve fine-grained preference modeling. The constructed preference reward function enables the model to learn the semantic relationship between features during the optimization process of the text classification model.

[0105] The optimization module 404 is configured to fine-tune the original text classification model using the preference reward function on the enhanced dataset to obtain an optimized text classification model.

[0106] Optionally, the original text classification model may be a text classification model trained on the original data set, or may be other known text classification models that can perform classification tasks on text of this category.

[0107] Furthermore, on the enhanced dataset, the constructed preference reward function is used to fine-tune the original text classification model through a direct preference optimization algorithm to obtain an optimized text classification model.

[0108] The present invention realizes data enhancement of the original text by dividing the original text data into multiple semantic units of different levels and adopting different data enhancement measures for the semantic units of different levels, thereby realizing a multi-strategy fine-grained data enhancement method. At the same time, by constructing a preference reward function and introducing preference learning, the method guides model training in the process of optimizing the text classification model, strengthens the influence of higher-quality text data on the text classification model, and weakens the influence of lower-quality text data on the text classification model, thereby optimizing a text classification model with greater accuracy and robustness.

[0109] Figure 5 An example of a physical structure diagram of an electronic device is shown below. Figure 5As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530, and a communication bus 540, wherein the processor 510, the communication interface 520, and the memory 530 communicate with each other via the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute a text classification model optimization method, which includes: dividing each text in the original data set to obtain semantic units of the text at different levels; enhancing the semantic units at each level using different data enhancement methods, obtaining a preset number of supplementary texts for each text, and arranging the supplementary texts into the original data set to obtain an enhanced data set; constructing a preference reward function based on keyword semantic scores and global semantic scores, wherein the keyword semantic scores represent the semantic contributions of the key words of the enhanced data set to the text category, and the global semantic scores represent the semantic contributions of the complete text of each text data in the enhanced data set to the text category; and fine-tuning the original text classification model on the enhanced data set using the preference reward function to obtain an optimized text classification model.

[0110] Furthermore, the logic instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0111] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the text classification model optimization method provided by the above methods, which includes: dividing each text in the original data set to obtain semantic units of the text at different levels; enhancing the semantic units at each level using different data enhancement methods, obtaining a preset number of supplementary texts for each text, and arranging the supplementary texts into the original data set to obtain an enhanced data set; constructing a preference reward function based on keyword semantic scores and global semantic scores, wherein the keyword semantic score represents the semantic contribution of the key words of the enhanced data set to the text category, and the global semantic score represents the semantic contribution of the complete text of each text data in the enhanced data set to the text category; on the enhanced data set, using the preference reward function to fine-tune the original text classification model to obtain an optimized text classification model.

[0112] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the text classification model optimization method provided by the above-mentioned methods, the method comprising: dividing each text in the original data set to obtain semantic units of the text at different levels; enhancing the semantic units at each level using different data enhancement methods, obtaining a preset number of supplementary texts for each text, and arranging the supplementary texts into the original data set to obtain an enhanced data set; constructing a preference reward function based on keyword semantic scores and global semantic scores, wherein the keyword semantic score represents the semantic contribution of the key words of the enhanced data set to the text category, and the global semantic score represents the semantic contribution of the complete text of each text data in the enhanced data set to the text category; on the enhanced data set, using the preference reward function to fine-tune the original text classification model to obtain an optimized text classification model.

[0113] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.

[0114] Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented using software plus a necessary general-purpose hardware platform, or of course, hardware. Based on this understanding, the essence of the above technical solution, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, or an optical disk, and includes a number of instructions for causing a computer device (such as a personal computer, server, or network device) to execute the methods described in each embodiment or certain portions of the embodiments.

[0115] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims

1. A text classification model optimization method, characterized in that: include: Divide each text in the original data set to obtain semantic units at different levels of the text; Different data enhancement methods are used to enhance the semantic units at each level, respectively, to obtain a preset number of supplementary texts for each text, and the supplementary texts are sorted into the original data set to obtain an enhanced data set; Constructing a preference reward function based on a keyword semantic score and a global semantic score, wherein the keyword semantic score represents the semantic contribution of the key words of the enhanced dataset to the text category, and the global semantic score represents the semantic contribution of the complete text of each text data in the enhanced dataset to the text category; On the enhanced dataset, the preference reward function is used to fine-tune the original text classification model to obtain an optimized text classification model.

2. The text classification model optimization method according to claim 1, characterized in that The levels include words, phrases, and segments; and the steps of enhancing the semantic units of each level using different data enhancement methods specifically include: When the semantic unit level is vocabulary, data augmentation is achieved by replacing synonyms and / or antonyms; When the semantic unit level is a phrase, data enhancement is achieved by sentence rewriting; When the semantic unit level is a segment, data augmentation is achieved by inserting similar text and / or deleting redundant text.

3. The text classification model optimization method according to claim 1, characterized in that: Before the step of constructing the preference reward function based on the keyword semantic score and the global semantic score, the method further includes: Defining a key vocabulary set of the enhanced data set, extracting the semantic contribution of each word in the keyword set to the text category through an attention mechanism, and determining the keyword semantic score based on the semantic contribution of each keyword in the keyword set; The semantic contribution of each piece of text data in the enhanced dataset to the text category is extracted through the attention mechanism, and the global semantic score is determined based on the semantic contribution of each piece of text data to the text category.

4. The text classification model optimization method according to claim 1, characterized in that The step of constructing a preference reward function based on keyword semantic scores and global semantic scores specifically includes: defining a confidence score based on a linear weighted sum of the keyword semantic score and the global semantic score; The preference reward function is constructed based on the confidence score.

5. The text classification model optimization method according to any one of claims 1 to 4, characterized in that: The step of fine-tuning the original text classification model using the preference reward function on the enhanced dataset to obtain an optimized text classification model specifically includes: The LoRA method is adopted to fine-tune the original text classification model using a preference reward function on the enhanced dataset, wherein the original text classification model is trained based on the original dataset.

6. A text classification method, characterized in that: include: Get the text to be classified; The text to be classified is input into a classification model to obtain a text category of the text to be classified output by the classification model, wherein the classification model is trained using the text classification model optimization method according to any one of claims 1 to 5.

7. A text classification model optimization device, characterized in that: include: A segmentation module is used to segment each text in the original data set to obtain semantic units of the text at different levels; An enhancement module is used to enhance the semantic units at each level using different data enhancement methods, obtain a preset number of supplementary texts for each text, and organize the supplementary texts into the original data set to obtain an enhanced data set; a determination module, configured to construct a preference reward function based on a keyword semantic score and a global semantic score, wherein the keyword semantic score represents the semantic contribution of the key words of the enhanced dataset to the text category, and the global semantic score represents the semantic contribution of the complete text of each text data in the enhanced dataset to the text category; The optimization module is used to fine-tune the original text classification model using the preference reward function on the enhanced dataset to obtain an optimized text classification model.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the text classification model optimization method according to any one of claims 1 to 5 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the text classification model optimization method according to any one of claims 1 to 5 is implemented.

10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the text classification model optimization method according to any one of claims 1 to 5 is implemented.

Citation Information

Cited By

  • High-efficiency fine tuning method for large language model for fine-grained text classification

    CN121413692A