Text classification method, text classification device, computer equipment and storage medium
By rewriting and filtering unlabeled text and adjusting the classification model in combination with cluster center data, the problem of long-tail distribution in text classification is solved, and classification accuracy and effectiveness of training data are improved.
Patent Information
- Application Number
- CN202310717358.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-16
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2043-06-16
AI Technical Summary
The existing technology has long tail distribution problems in text classification, resulting in uneven distribution of positive and negative categories labels, affecting classification accuracy, and insufficient validity and rationality of new sample texts generated by existing data enhancement methods.
By obtaining the initial text data, using the preset prompt template and mask prediction model to rewritten unlabeled text, filtering and expanding text with the cluster center data, adjusting the classification model parameters to ensure the balance and accuracy of the training data.
It effectively solves the problem of long-tail distribution of text data, improves the accuracy of text classification, reduces the cost of manpower labeling, and ensures the effectiveness and rationality of training data.
Smart Images

Figure CN116680400B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of financial technology, and in particular to a text classification method, a text classification device, a computer device, and a storage medium. Background Art
[0002] With the rapid development of the Internet and the advent of the big data era, text classification has become a hot research topic in the current field of natural language processing. For example, in the field of financial technology, various e-commerce platforms collect data such as user product review texts and build product recommendation models based on the collected data to recommend products to users. Currently, long-tail distribution refers to the phenomenon that the distribution of data labeling categories obtained in actual applications is uneven. For example, when obtaining product review texts, positive review texts often outnumber negative review texts, resulting in an uneven distribution of text corresponding to positive and negative category labels, which in turn affects the accuracy of the review text classification. Text classification methods in related technologies usually perform data augmentation processing on category data with a small number of labels during training to obtain training samples with a balanced distribution. For example, related technologies usually use methods such as adding content, deleting content, and rewriting content in the text content of categories with a small number of labels to generate new sample text for that category. However, while this method can improve the balance of sample distribution, it can easily generate new sample texts with contradictory content or incoherent sentences. This makes it impossible to control the validity and rationality of these new sample texts, meaning it has no effect on improving text classification accuracy. Furthermore, the classification of invalid sample texts can also affect the construction of product recommendation models. Therefore, finding a text classification method that can better address the long-tail distribution of text data and improve text classification accuracy has become a pressing technical challenge. Summary of the Invention
[0003] The main purpose of the embodiments of the present application is to propose a text classification method, a text classification device, a computer device and a storage medium, which can better solve the problem of long-tail distribution of text data and improve the accuracy of text classification.
[0004] To achieve the above objectives, a first aspect of an embodiment of the present application provides a text classification method, the method comprising:
[0005] Acquire initial text data, the initial text data including initial annotated data and unannotated text, the initial annotated data including first annotated text annotated with a first annotation category and second annotated text annotated with a second annotation category, wherein the number of texts in the first annotated text is less than the number of texts in the second annotated text;
[0006] Rewriting the unlabeled text according to a preset prompt template to obtain a rewritten text, and inputting the rewritten text into a preset mask prediction model to perform mask category prediction to obtain a mask category of the rewritten text;
[0007] If the first annotation category and the mask category are the same, determining the unannotated text as the initial expanded text;
[0008] Obtaining first cluster center data of the first annotated text and second cluster center data of the second annotated text, determining a first category distance based on the initial expanded text and the first cluster center data, and determining a second category distance based on the initial expanded text and the second cluster center data;
[0009] Performing text screening on the initial expanded text according to the first category distance and the second category distance to determine a target expanded text;
[0010] Merging the target expanded text and the first annotated text to obtain a first data set, and obtaining a second data set based on the second annotated text, wherein the number of texts in the first data set is the same as the number of texts in the second data set;
[0011] Adjusting parameters of a preset initial classification model according to the first data set and the second data set to obtain a text classification model;
[0012] The pre-acquired target text is classified according to the text classification model.
[0013] In some embodiments, screening the initial expansion text according to the first category distance and the second category distance to determine the target expansion text includes:
[0014] Performing a numerical comparison on the first category distance and the second category distance to obtain a distance comparison result;
[0015] If the distance comparison result indicates that the second category distance is greater than the first category distance, the initial expanded text is determined as the target expanded text.
[0016] In some embodiments, adjusting parameters of a preset initial classification model based on the first data set and the second data set to obtain a text classification model includes:
[0017] determining training data based on the first data set and the second data set;
[0018] Parameters of the initial classification model are adjusted according to the training data to obtain the text classification model.
[0019] In some embodiments, determining training data based on the first data set and the second data set includes:
[0020] Determining a third category distance according to the target expanded text and the first cluster center data;
[0021] determining a fourth category distance according to the first annotated text and the first cluster center data;
[0022] sorting the texts of the first data set according to the third category distance and the fourth category distance to obtain an expanded text sequence;
[0023] Performing text sampling on the expanded text sequence to obtain a first text subsequence, where the first text subsequence includes a first training text whose text category is the first labeled category;
[0024] Randomly sampling the second data set according to the number of texts in the first text subsequence to determine a second text subsequence, where the second text subsequence includes second training texts whose text category is the second labeled category;
[0025] The first training text and the second training text are merged to obtain training data.
[0026] In some embodiments, adjusting parameters of the initial classification model according to the training data to obtain the text classification model includes:
[0027] Adjusting parameters of the initial classification model according to the training data to obtain a candidate classification model;
[0028] Performing text sampling on the expanded text sequence according to the first text subsequence to determine a third text subsequence, wherein the third text subsequence includes a third training text whose text category is the first labeled category, and a category distance between the third training text and the first cluster center data is greater than or equal to a category distance between the first training text and the first cluster center data;
[0029] Randomly sampling the second data set according to the number of texts in the third text subsequence to determine a fourth text subsequence, wherein the fourth text subsequence includes a fourth training text whose text category is the second labeled category;
[0030] Merging the third training text and the fourth training text, and updating the training data according to the merging result;
[0031] The parameters of the candidate classification model are adjusted according to the updated training data to obtain the text classification model.
[0032] In some embodiments, performing text sampling on the expanded text sequence according to the first text subsequence to determine the third text subsequence includes:
[0033] Obtaining sampling cutoff data of the first text subsequence;
[0034] Text sampling is performed on the expanded text sequence according to the sampling cutoff data to determine the third text subsequence.
[0035] In some embodiments, obtaining first cluster center data of the first annotated text and second cluster center data of the second annotated text includes:
[0036] Acquire initial cluster center data and target cluster data of the initial annotated data, wherein the initial cluster center data includes first center data of the first annotated text and second center data of the second annotated text;
[0037] Performing distance calculation based on the first center data and the initial labeled data to obtain first cluster distance data;
[0038] Performing distance calculation based on the second center data and the initial labeled data to obtain second cluster distance data;
[0039] Performing a numerical comparison based on the first cluster distance data and the second cluster distance data to determine predicted cluster data of the initial labeled data according to a result of the numerical comparison;
[0040] Class loss data is determined according to the predicted cluster data and the target cluster data, and data adjustment is performed on the initial cluster center data according to the class loss data to obtain the first cluster center data and the second cluster center data.
[0041] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides a text classification device, comprising:
[0042] a text data acquisition module, configured to acquire initial text data, the initial text data including initial annotated data and unannotated text, the initial annotated data including first annotated text annotated with a first annotation category and second annotated text annotated with a second annotation category, wherein the first annotated text has less text than the second annotated text;
[0043] A mask category prediction module is used to rewrite the unlabeled text according to a preset prompt template to obtain a rewritten text, and input the rewritten text into a preset mask prediction model to perform mask category prediction to obtain the mask category of the rewritten text;
[0044] a category determination module, configured to determine the unlabeled text as initial expanded text if the first labeled category and the mask category are the same;
[0045] a cluster distance calculation module, configured to obtain first cluster center data of the first annotated text and second cluster center data of the second annotated text, determine a first category distance based on the initial expanded text and the first cluster center data, and determine a second category distance based on the initial expanded text and the second cluster center data;
[0046] a text screening module, configured to screen the initial expanded text according to the first category distance and the second category distance to determine a target expanded text;
[0047] a data set construction module, configured to merge the target expanded text and the first annotated text to obtain a first data set, and obtain a second data set based on the second annotated text, wherein the number of texts in the first data set is the same as the number of texts in the second data set;
[0048] A model building module, configured to adjust parameters of a preset initial classification model according to the first data set and the second data set to obtain a text classification model;
[0049] The text classification module is used to perform text classification on the pre-acquired target text according to the text classification model.
[0050] To achieve the above-mentioned objectives, a third aspect of the embodiments of the present application provides a computer device, including:
[0051] at least one memory;
[0052] at least one processor;
[0053] at least one computer program;
[0054] The at least one computer program is stored in the at least one memory, and the at least one processor executes the at least one computer program to implement the text classification method described in the first aspect.
[0055] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a storage medium, which is a computer-readable storage medium. The computer-readable storage medium stores a computer program, and the computer program is used to enable a computer to execute the text classification method described in the first aspect above.
[0056] The text classification method, text classification device, computer equipment and storage medium proposed in the embodiments of the present application first obtain initial text data, which includes a first annotated text annotated with a first annotated category and a second annotated text annotated with a second annotated category, and the number of texts in the first annotated text is less than the number of texts in the second annotated text. Then, the unannotated text is rewritten according to a preset prompt template to obtain a rewritten text, and the rewritten text is input into a preset mask prediction model for mask category prediction to obtain the mask category of the rewritten text. If the first annotated category and the mask category are the same, the unannotated text is determined as the initial expanded text. In order to further determine that the expanded text meets the text category to be expanded, the first cluster center data of the first annotated text and the second cluster center data of the second annotated text are obtained, and the first category distance is determined based on the initial expanded text and the first cluster center data, and the second category distance is determined based on the initial expanded text and the second cluster center data. Afterwards, the initial expanded text is subjected to text screening based on the first category distance and the second category distance to determine the target expanded text. Before model training, the target expanded text and the first annotated text are merged to obtain a first data set. A second data set is then obtained based on the second annotated text. The first data set contains the same number of texts as the second data set. The parameters of a preset initial classification model are adjusted based on the first and second data sets to obtain a text classification model. Finally, the acquired target text is classified according to the text classification model. This embodiment of the present application can better address the problem of long-tail distribution of text data and improve the accuracy of text classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 is a flowchart of the text classification method provided in an embodiment of the present application;
[0058] Figure 2 yes Figure 1 Flowchart of step S140 in FIG.
[0059] Figure 3 yes Figure 1 Flowchart of step S150 in FIG.
[0060] Figure 4 yes Figure 1 Flowchart of step S170 in FIG.
[0061] Figure 5 yes Figure 4 Flowchart of step S410 in FIG.
[0062] Figure 6 yes Figure 4 Flowchart of step S420 in FIG.
[0063] Figure 7 yes Figure 6 Flowchart of step S620 in FIG.
[0064] Figure 8 is a structural diagram of a text classification device provided in an embodiment of the present application;
[0065] Figure 9 This is a schematic diagram of the hardware structure of the computer device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0066] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0067] It should be noted that although the device schematics illustrate functional module divisions and the flowcharts illustrate logical sequences, in certain circumstances, the steps shown or described may be performed in a sequence that differs from the module divisions in the device or the sequence in the flowcharts. The terms "first," "second," and so on, in the specification, claims, and drawings, are used to distinguish similar items and are not necessarily used to describe a specific sequence or precedence.
[0068] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0069] First, let’s analyze some of the terms used in this application:
[0070] Artificial Intelligence (AI) is a new technical discipline that studies and develops theories, methods, technologies, and application systems for simulating, extending, and expanding human intelligence. A branch of computer science, AI seeks to understand the essence of intelligence and create new intelligent machines that can respond in a manner similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. AI can simulate the information processes of human consciousness and thinking. It also encompasses theories, methods, technologies, and application systems that use digital computers or digital computer-controlled machines to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results.
[0071] Hint learning: refers to a method that changes the downstream task to a text generation task by adding "hint information" to the input text without significantly changing the structure and parameters of the pre-trained language model.
[0072] Mask (MASK): refers to the use of a selected image, graphic or object to block the processed image (all or part) to control the image processing area or processing process. The specific image or object used for coverage is called a mask or template.
[0073] Token: is a computer term that means a token (temporary) in computer authentication and a tag in lexical analysis, an object that represents the right to perform certain operations.
[0074] BERT (Bidirectional Encoder Representation from Transformers): This model is designed to further enhance the generalization capabilities of word embedding models, fully describing features at the character, word, and sentence levels, and even inter-sentence relationships. It is built on the Transformer architecture. BERT includes three types of embeddings: token embedding, segment embedding, and position embedding. Token embeddings are word embeddings, with the first word being a CLS marker, which can be used for subsequent classification tasks.
[0075] With the rapid development of the internet and the advent of the big data era, text classification has become a hot research topic in the field of natural language processing. For example, in the field of financial technology, e-commerce platforms collect data such as user product reviews and build product recommendation models based on this data to recommend products to users. Currently, long-tail distribution refers to the phenomenon of uneven distribution of labeled categories in data obtained in practical applications. For example, when obtaining product reviews, positive reviews often outnumber negative reviews, resulting in an uneven distribution of text corresponding to positive and negative class labels, which in turn affects the accuracy of review text classification. Related text classification methods typically perform data augmentation on data from categories with fewer labels during training to obtain balanced training samples. For example, related techniques often use methods such as adding, deleting, or rewriting content from text in categories with fewer labels to generate new sample text for that category. However, while these methods can improve the balance of sample distribution, they are prone to generating new sample text with contradictory meanings or incoherent sentences. This makes it impossible to control the validity and rationality of the new sample text, and thus has no effect on improving text classification accuracy. Therefore, how to provide a text classification method that can better solve the problem of long-tail distribution of text data and improve the accuracy of text classification has become a technical problem that needs to be solved urgently.
[0076] Based on this, the embodiments of the present application provide a text classification method, a text classification device, a computer device and a storage medium, which can better solve the problem of long-tail distribution of text data and improve the accuracy of text classification.
[0077] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to achieve optimal results.
[0078] Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0079] The text classification method provided in the embodiment of the present application relates to the field of artificial intelligence technology. The text classification method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or can be configured as a server cluster or a distributed system composed of multiple physical servers, or can be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms; the software can be an application that implements the text classification method, etc., but is not limited to the above forms.
[0080] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, multi-processor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network personal computers (PCs), minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0081] See also Figure 1 , Figure 1 This is an optional flow chart of the text classification method provided in the embodiment of the present application. In some embodiments of the present application, Figure 1 The method may specifically include but is not limited to steps S110 to S180. Figure 1 These eight steps are introduced in detail.
[0082] Step S110, obtaining initial text data, the initial text data including initial annotated data and unannotated text, the initial annotated data including first annotated text annotated with a first annotation category and second annotated text annotated with a second annotation category, wherein the number of texts in the first annotated text is less than the number of texts in the second annotated text;
[0083] Step S120: rewriting the unlabeled text according to a preset prompt template to obtain a rewritten text, and inputting the rewritten text into a preset mask prediction model to perform mask category prediction to obtain a mask category of the rewritten text;
[0084] Step S130: If the first annotation category and the mask category are the same, the unannotated text is determined as the initial expanded text;
[0085] Step S140, obtaining first cluster center data of the first annotated text and second cluster center data of the second annotated text, determining a first category distance based on the initial expanded text and the first cluster center data, and determining a second category distance based on the initial expanded text and the second cluster center data;
[0086] Step S150, screening the initial expanded text according to the first category distance and the second category distance to determine the target expanded text;
[0087] Step S160: merging the target expanded text and the first annotated text to obtain a first data set, and obtaining a second data set based on the second annotated text, wherein the number of texts in the first data set is the same as the number of texts in the second data set;
[0088] Step S170, adjusting parameters of a preset initial classification model according to the first data set and the second data set to obtain a text classification model;
[0089] Step S180 , performing text classification on the pre-acquired target text according to the text classification model.
[0090] In steps S110 to S180 of some embodiments, first, initial text data is obtained, and the initial annotation data includes a first annotated text annotated with a first annotation category, a second annotated text annotated with a second annotation category, and unannotated text, and the number of texts in the first annotated text is less than the number of texts in the second annotated text. Then, the unannotated text is rewritten according to a preset prompt template to obtain a rewritten text, and the rewritten text is input into a preset mask prediction model for mask category prediction to obtain the mask category of the rewritten text. If the first annotated category and the mask category are the same, the unannotated text is determined as the initial expanded text. In order to further determine that the expanded text meets the text category to be expanded, the first cluster center data of the first annotated text and the second cluster center data of the second annotated text are obtained, and the first category distance is determined based on the initial expanded text and the first cluster center data, and the second category distance is determined based on the initial expanded text and the second cluster center data. Afterwards, the initial expanded text is subjected to text screening based on the first category distance and the second category distance to determine the target expanded text. Before model training, the target expanded text and the first annotated text are merged to obtain a first data set. A second data set is then obtained based on the second annotated text. The first data set contains the same number of texts as the second data set. The parameters of a preset initial classification model are adjusted based on the first and second data sets to obtain a text classification model. Finally, the acquired target text is classified according to the text classification model. This embodiment of the present application can better address the problem of long-tail distribution of text data and improve the accuracy of text classification.
[0091] In step S110 of some embodiments, the initial annotation data is used to represent the sample text that has been annotated, and the unannotated text is used to represent the sample text that has not been annotated. In practical application fields, the number of texts corresponding to the obtained annotation categories is usually prone to imbalance. For example, in the evaluation of a product, the initial annotation data is used to represent the evaluation text that has been divided into the annotation categories, and the unannotated text can be used to represent the newly uploaded evaluation text. Among them, the positive evaluations in the obtained evaluations are often more than the negative evaluations, then the evaluation texts can be divided into two types of texts, positive labels and negative labels, positive labels are used to represent positive evaluations, and negative labels are used to represent negative evaluations. Therefore, the first annotation category can be used to represent negative labels, and the second annotation category can be used to represent positive labels, then the number of texts of the first annotation text corresponding to the first annotation category is usually less than the number of texts of the second annotation text under the second annotation category.
[0092] It should be noted that when the initial annotation data includes three or more annotation categories, they are sorted from small to large according to the number of texts corresponding to the annotation categories, and the annotation category with the smallest number of texts is used as the first annotation category, and the annotation category with the largest number of texts is used as the second annotation category. The text classification method of this application is performed on the corresponding text according to the currently set annotation category, so that the number of texts corresponding to the first annotation category is the same as the number of texts corresponding to the second annotation category. Afterwards, the annotation categories that are larger than the annotation category with the smallest number of texts are iteratively processed as the new first annotation category, so that the number of texts corresponding to all annotation categories is the same.
[0093] It should be noted that the sample text can be a text file uploaded by the user to the server or terminal, a text file stored in the local disk of the server or terminal, or a text file stored in a node of the blockchain.
[0094] It should be noted that, in some embodiments, the initial text data can be obtained by writing a web crawler or script program to crawl data in a targeted manner.
[0095] In step S120 of some embodiments, in order to reduce the annotation cost of unlabeled text and improve the annotation accuracy of unlabeled text, the embodiment of the present application rewrites the unlabeled text according to the preset prompt template to obtain a rewritten text. In order to determine whether the annotation category is a positive label or a negative label, the preset prompt template constructed by the embodiment of the present application can be in the form of "[CLS][MASK] emotion: unlabeled text [SEP]". Among them, "[MASK] emotion" is used to represent the prompt information, and the rewritten text is classified according to the prompt information, and it can be predicted that the text information at [MASK] is "positive" or "negative", and the positive emotion is used to correspond to the positive label, that is, the second annotation category, and the negative emotion is used to correspond to the negative label, that is, the first annotation category.
[0096] It should be noted that the embodiment of the present application can construct a mask prediction model based on the Masked Language Model (MLM) task of the BERT model structure. Specifically, for example, in the financial technology shopping platform scenario, when the unlabeled text in the user's evaluation text of the product is "This dress is of good quality", the rewritten text after the unlabeled text is rewritten is "[CLS][MASK] Sentiment: This dress is of good quality [SEP]". Then, the rewritten text is submitted to the mask prediction model for mask category prediction to obtain the prediction score of the rewritten text under each labeled category. The mask category is the first labeled category and the second labeled category. The embodiment of the present application rewrites the unlabeled text by combining the prompt learning method to achieve the expansion of the category samples with a small number of texts corresponding to the labeled categories in the text corpus, which can effectively avoid the problem of invalid samples or changes in meaning caused by directly changing the words of the labeled samples in the related art.
[0097] It should be noted that the mask prediction model includes an embedding representation processing layer, a mask language model processing layer and a prediction processing layer. The embedding representation processing layer performs embedding representation processing on each rewritten text to obtain an embedding representation vector. Among them, before the rewritten text is passed to the embedding representation processing layer, the content in the rewritten text needs to be tokenized to achieve the classification task of the token position. Afterwards, the mask language model processing layer performs mask language model processing on the obtained embedding representation vector to obtain a mask representation vector, that is, the embodiment of the present application can make full use of the characteristics of MLM pre-training, and judge the final mapping by the native input-output deviation of the [MASK] position, thereby avoiding the possible deviation and statistical calculation consumption introduced by the three-party knowledge base. Finally, the prediction processing layer performs prediction processing on the mask representation vector to obtain the token probability score of each rewritten text under different predicted words, that is, the prediction score of predicting whether the word at [MASK] is "positive" or "negative". Finally, the token probability scores are numerically compared to determine that the labeling category corresponding to the word with the highest token probability score is the mask category.
[0098] It should be noted that after rewriting the text input mask prediction model, the embodiment of the present application can also obtain a text vector for each unlabeled text. Specifically, the text vector is obtained by averaging the token vector and the [CLS] vector of the last layer of the mask prediction model, that is, satisfying E(text) = (E(CLS) + E(token1) + ... + E(token n)) / n, where text represents the unlabeled text, n represents the number of text characters in the unlabeled text, and E(·) represents the vector.
[0099] In step S130 of some embodiments, in order to achieve the expansion of category samples with a small number of texts corresponding to the labeled category, if the first labeled category and the mask category are the same, the unlabeled text is determined as the initial expanded text; if the first labeled category and the mask category are different, the unlabeled text belongs to the labeled category with a large number of texts corresponding to the labeled category, and the unlabeled text is eliminated. The embodiment of the present application introduces prompt learning to complete the transformation of the form of the sample and use the MLM task of BERT to predict the sample category in the case of a small amount of original annotations, which can effectively utilize the pre-training task of the mask prediction model itself. Secondly, the embodiment of the present application can obtain labeled samples with higher accuracy under a small number of labeled samples, thereby ensuring the balance of training data under different categories, so as to effectively solve the problem of long-tail distribution of text data, and does not require human labeling costs.
[0100] In step S140 of some embodiments, since the expansion of the category samples corresponding to the labeled categories with a small number of texts in the embodiments of the present application is obtained through prompt learning without annotation and without the need for training, the annotation accuracy of the unlabeled text is not necessarily very high. Therefore, in order to improve the annotation accuracy of the unlabeled text, the text of the required labeled category is retained, thereby improving the accuracy of text classification. After determining the initial expanded text, the embodiments of the present application perform text screening on the initial expanded text through a clustering method to accurately determine that the labeled category is a category sample with a small number of texts.
[0101] See also Figure 2 , Figure 2 This is a flowchart of the specific method of step S140 provided in the embodiment of the present application. In some embodiments of the present application, step S140 may specifically include but is not limited to steps S210 to S250. Figure 2 These five steps are introduced in detail.
[0102] Step S210, obtaining initial cluster center data and target cluster data of initial annotated data, wherein the initial cluster center data includes first center data of the first annotated text and second center data of the second annotated text;
[0103] Step S220, performing distance calculation based on the first center data and the initial labeled data to obtain first cluster distance data;
[0104] Step S230, performing distance calculation based on the second center data and the initial labeled data to obtain second cluster distance data;
[0105] Step S240 , performing a numerical comparison based on the first cluster distance data and the second cluster distance data, to determine predicted cluster data of the initial labeled data based on the result of the numerical comparison;
[0106] Step S250 , determining category loss data based on the predicted cluster data and the target cluster data, and performing data adjustment on the initial cluster center data based on the category loss data to obtain first cluster center data and second cluster center data.
[0107] In step S210 of some embodiments, in order to improve the annotation accuracy of unannotated text and retain the text of the required annotation category, the cluster center data of each annotation category is first determined based on the initial annotation data, thereby ensuring the clustering accuracy of the initial expanded text. The initial cluster center data is used to characterize the cluster center data of each pre-given annotation category, which includes the first center data corresponding to the first annotation text and the second center data corresponding to the second annotation text. The input text can be divided into different categories according to the first center data and the second center data. The target cluster data is used to characterize the annotation category corresponding to the initial annotation data, and the target cluster data can be the first annotation category or the second annotation category.
[0108] In some embodiments, in steps S220 to S250, since clustering is to divide the category of each sample point by the closest distance between the sample point and the cluster center, assuming that each initial labeled data is a sample point, the vector corresponding to each initial labeled data is respectively calculated with the first center data and the second center data to obtain the first cluster distance data and the second cluster distance data. By performing a numerical comparison on the first cluster distance data and the second cluster distance data, the predicted cluster data of the initial labeled data is determined according to the cluster distance with the smaller numerical value. The predicted cluster data is used to characterize the labeled category predicted for the initial labeled data based on the first center data and the second center data, and the predicted cluster data can be the first labeled category or the second labeled category. The category loss data is determined based on the predicted cluster data and the target cluster data to determine whether the current first center data and the second center data can accurately classify the input sample points. Through continuous iteration and data adjustment of the initial cluster center data based on the category loss data, when there is no longer any category change in the final sample, the current first cluster center data and the second cluster center data can be determined.
[0109] It should be noted that the distance calculation method between the initial annotated data and the first and second center data can be any of the following: Euclidean distance, Manhattan distance, Chebyshev distance, etc., which are not specifically limited or detailed here. The calculation of the category loss data can be performed using the cross entropy loss function, the 0-1 loss function, etc., which are not specifically limited or detailed here.
[0110] In step S150 of some embodiments, after determining the first cluster center data and the second cluster center data, the text vector of the initial expanded text obtained in the mask prediction is respectively subjected to distance calculation with the first cluster center data and the second cluster center data. Wherein, the first category distance is used to characterize the distance between the initial expanded text and the first cluster center data, and the second category distance is used to characterize the distance between the initial expanded text and the second cluster center data. In order to accurately judge whether the initial expanded text is the text of the required annotation category, the initial expanded text is subjected to text screening according to the first category distance and the second category distance, and the target expanded text is determined. The target expanded text is a category sample of the annotation category with a smaller number of texts, i.e., the text of the first annotation category. In addition, the clustering algorithm adopted in the embodiment of the present application can be a k-means clustering algorithm, a Mean shift clustering algorithm, etc. Therefore, after the embodiment of the present application obtains the initial expanded text through prompt learning, the initial expanded text is subjected to data cleaning by combining the clustering algorithm and the distance calculation method to further delete the sample text that does not meet the required annotation category.
[0111] It should be noted that the cluster center distance calculation method can refer to the above-mentioned method for calculating the distance between the initial labeled data and the first center data and the second center data, which is not specifically limited or elaborated here.
[0112] See also Figure 3 , Figure 3 This is a flowchart of the specific method of step S150 provided in the embodiment of the present application. In some embodiments of the present application, step S150 may specifically include but is not limited to step S310 and step S320. Figure 3 These two steps are introduced in detail.
[0113] Step S310, performing a numerical comparison on the first category distance and the second category distance to obtain a distance comparison result;
[0114] In step S320 , if the distance comparison result indicates that the second category distance is greater than the first category distance, the initial expanded text is determined as the target expanded text.
[0115] In step S310 and step S320 of some embodiments, in order to further delete sample texts that do not conform to the required annotation category, a numerical comparison is performed on the first category distance and the second category distance. If the distance comparison result indicates that the second category distance is greater than the first category distance, it means that the initial expanded text belongs to the first annotation category, and the initial expanded text is used as the target expanded text. If the distance comparison result indicates that the second category distance is less than or equal to the first category distance, it means that the initial expanded text belongs to the second annotation category. Since this application is an expansion of samples of the first annotation category with a small number of text categories, the initial expanded text marked as the second annotation category is a sample text that does not conform to the required annotation category, and the initial expanded text is eliminated.
[0116] In step S160 of some embodiments, in order to improve the classification accuracy of the text classification model, after obtaining the target expanded text of a small number of categories, the target expanded text and the first annotated text are sorted and merged to obtain a first data set. A second data set is constructed based on the second annotated text, and the number of texts in the current first data set is the same as the number of texts in the second data set. The embodiment of the present application expands the number of texts in the training data by combining prompt learning with a clustering algorithm, so that the number of texts in different annotated categories is the same. And the model is trained based on the balanced training text, which effectively solves the problem of long-tail distribution of text data. For example, in the evaluation of a product, positive reviews often outnumber negative reviews. The embodiment of the present application expands the amount of data of negative reviews by combining prompt learning with a clustering algorithm, thereby effectively improving the accuracy of text classification.
[0117] In step S170 of some embodiments, in order to improve the classification efficiency and classification accuracy of the text classification model, the embodiments of the present application continuously train the model in order from easy to difficult using samples in the data set through course learning to optimize the model effect, thereby improving the classification efficiency of the text classification model.
[0118] See also Figure 4 , Figure 4 This is a flowchart of the specific method of step S170 provided in the embodiment of the present application. In some embodiments of the present application, step S170 may specifically include but is not limited to step S410 and step S420. Figure 4 These two steps are introduced in detail.
[0119] Step S410, determining training data based on the first data set and the second data set;
[0120] Step S420: Adjust the parameters of the initial classification model according to the training data to obtain a text classification model.
[0121] In steps S410 and S420 of some embodiments, in order to continuously train the model with samples in the data set in order from easy to difficult, the embodiment of the present application divides the first data set and the second data set according to the preset division rounds to divide the data into training data for multiple training rounds, and the training rounds are represented as epochs. Among them, the preset division rounds are positive integers and can be set according to actual needs and are not specifically limited here. For example, when the preset division rounds are 5, the training data of each epoch includes 20% of the text with few categories in the first data set and the same number of text with many categories in the second data set. The initial classification model is trained based on the training data, and the predicted labeled categories obtained from the training are compared with the categories already labeled in the data to adjust the parameters of the initial classification model. The embodiment of the present application uses a course learning method to continuously train the model with samples in the data set in order from easy to difficult, that is, full training of all small-category samples is achieved through multiple epochs, effectively improving the classification efficiency of the text classification model.
[0122] See also Figure 5 , Figure 5 This is a flowchart of the specific method of step S410 provided in the embodiment of the present application. In some embodiments of the present application, step S410 may specifically include but is not limited to steps S510 to S560. Figure 5 These six steps are introduced in detail.
[0123] Step S510, determining a third category distance based on the target expanded text and the first cluster center data;
[0124] Step S520, determining a fourth category distance based on the first annotated text and the first cluster center data;
[0125] Step S530, sorting the texts in the first data set according to the third category distance and the fourth category distance to obtain an expanded text sequence;
[0126] Step S540: performing text sampling on the expanded text sequence to obtain a first text subsequence, where the first text subsequence includes a first training text whose text category is a first labeled category;
[0127] Step S550, randomly sampling the second data set according to the number of texts in the first text subsequence to determine a second text subsequence, where the second text subsequence includes a second training text whose text category is a second labeled category;
[0128] Step S560: Merge the first training text and the second training text to obtain training data.
[0129] In some embodiments, in steps S510 to S560, the closer the distance between the text and the cluster center, the easier it is to classify the text, and it is recorded as a simple sample. The farther the distance between the text and the cluster center, the less likely it is to classify the text, and it is recorded as a complex sample. Specifically, a third category distance between the target expanded text and the first cluster center data is determined based on a distance calculation, and a fourth category distance between the first annotated text and the first cluster center data is determined based on a distance calculation. All text in the first dataset is sorted based on the third and fourth category distances to obtain an expanded text sequence arranged in ascending order from smallest to largest distance, wherein the text tag categories in the expanded text sequence are all first annotated categories. For example, when the preset number of division rounds is 5, the expanded text sequence is sampled based on the preset number of division rounds to obtain a first text subsequence, which includes 20% of the text in the expanded text sequence. The second dataset is randomly sampled based on the number of texts in the first text subsequence to obtain a second text subsequence with the same number of texts as the first text subsequence. Therefore, the first training text and the second training text constitute the training data for the first epoch. The embodiment of the present application sorts the expanded data based on distance, and trains the model in the order of samples from small to large distance, that is, from easy to difficult, with easy samples being simple and difficult samples being complex, which can more reasonably and effectively improve the effect of the model.
[0130] See also Figure 6 , Figure 6 This is a flowchart of the specific method of step S420 provided in the embodiment of the present application. In some embodiments of the present application, step S420 may include but is not limited to steps S610 to S650. Figure 6 These five steps are introduced in detail.
[0131] Step S610, adjusting the parameters of the initial classification model according to the training data to obtain a candidate classification model;
[0132] Step S620: performing text sampling on the expanded text sequence according to the first text subsequence to determine a third text subsequence, wherein the third text subsequence includes a third training text whose text category is the first labeled category, and a category distance between the third training text and the first cluster center data is greater than or equal to a category distance between the first training text and the first cluster center data;
[0133] Step S630: Randomly sample the second data set according to the number of texts in the third text subsequence to determine a fourth text subsequence, where the fourth text subsequence includes fourth training texts whose text category is the second labeled category.
[0134] Step S640, merging the third training text and the fourth training text, and updating the training data according to the merging result;
[0135] Step S650: Adjust the parameters of the candidate classification model according to the updated training data to obtain a text classification model.
[0136] In some embodiments, in steps S610 to S650, after the training data for the first epoch is divided and parameters of the initial classification model are adjusted to obtain candidate classification data, text sampling is performed on the expanded text sequence based on the first text subsequence. The third text subsequence thus constructed represents the 20% of text ranked after the first text subsequence, and the category distance between the third training text and the first cluster center data is greater than or equal to the category distance between the first training text and the first cluster center data. A fourth text subsequence, equal in number to the third text subsequence, is randomly sampled from the second dataset.
[0137] For example, when the preset number of division rounds is 5, training data for 5 epochs is obtained based on the first and second data sets. After adjusting the parameters of the initial classification model based on the training data of the first epoch to obtain candidate classification data, the parameters of the obtained candidate classification model are further adjusted based on the second epoch consisting of the third and fourth training texts. After continuously adjusting the model parameters, when the model parameters of the obtained 5 epochs of training data are adjusted based on the model structure adjusted by the previous training data, a text classification model with higher text classification accuracy is obtained.
[0138] It should be noted that the embodiment of the present application can also arrange the text in ascending order according to the distance between the text in the second data set and the second cluster center data. In this case, random sampling is also performed according to the course learning method to train the model based on the training data constructed based on the arranged text subsequence, thereby improving the training effect of the model.
[0139] See also Figure 7 , Figure 7 This is a flowchart of the specific method of step S620 provided in the embodiment of the present application. In some embodiments of the present application, step S620 may specifically include but is not limited to step S710 and step S720. Figure 7 These two steps are introduced in detail.
[0140] Step S710, obtaining sampling cutoff data of the first text subsequence;
[0141] Step S720 : performing text sampling on the expanded text sequence according to the sampling cutoff data to determine a third text subsequence.
[0142] In some embodiments, in steps S710 to S720, to enable training on a full set of small-category samples, when text sampling is performed on the expanded text sequence to obtain a first text subsequence, the sampling cutoff data for the first text subsequence is simultaneously recorded. This sampling cutoff data is used to characterize the text with the largest category distance in the first text subsequence. Therefore, when text sampling is performed again on the expanded text sequence, the next text corresponding to the sampling cutoff data is used as the first sampled text for the next training data, and a third text subsequence is constructed based on the number of samples.
[0143] In step S180 of some embodiments, when performing text classification, the server first obtains the target text to be classified. The server may obtain the target text from a database pre-stored with target texts or directly from the target user's terminal. When the target user requires text classification, the target text can be transmitted to the server via the target user's terminal. The server then performs text classification based on a pre-trained text classification model to determine the target text category.
[0144] It should be noted that due to the large number of texts in the era of big data, it is impossible to label each evaluation text. In order to better solve the problem of long-tail distribution of text data, embodiments of the present application can execute the text classification method of the present application on the collected initial text data to build a text classification model with better classification effect, thereby better solving the problem of long-tail distribution of text data and improving the accuracy of text classification. For example, in the scenario of a financial technology shopping platform, after purchasing a product, the target object will post a text evaluation of the product, namely the target text, for example, "This dress is really beautiful." Alternatively, in the scenario of financial technology insurance claims, after completing the claim process, the target object can also post a text evaluation of the claim product or merchant, namely the target text, for example, "The claim process for this product is relatively complicated." The target text can then be input into the trained text classification model to obtain a more accurate target text category. For example, "This dress is really beautiful" is a positive evaluation, and "The claim process for this product is relatively complicated" is a negative evaluation.
[0145] See also Figure 8 , Figure 8 Schematic diagram of the module structure of a text classification device provided in an embodiment of the present application. This device can implement the text classification method of the above embodiment and includes a text data acquisition module 810, a mask category prediction module 820, a category determination module 830, a cluster distance calculation module 840, a text screening module 850, a dataset construction module 860, a model construction module 870, and a text classification module 880.
[0146] A text data acquisition module 810 is configured to acquire initial text data, the initial text data including initial annotated data and unannotated text, the initial annotated data including first annotated text annotated with a first annotation category and second annotated text annotated with a second annotation category, wherein the first annotated text has less text than the second annotated text;
[0147] The mask category prediction module 820 is used to rewrite the unlabeled text according to the preset prompt template to obtain the rewritten text, and input the rewritten text into the preset mask prediction model to perform mask category prediction to obtain the mask category of the rewritten text;
[0148] A category determination module 830 is configured to determine the unlabeled text as the initial expanded text if the first label category and the mask category are the same;
[0149] A cluster distance calculation module 840 is configured to obtain first cluster center data of the first annotated text and second cluster center data of the second annotated text, determine a first category distance based on the initial expanded text and the first cluster center data, and determine a second category distance based on the initial expanded text and the second cluster center data;
[0150] A text screening module 850 is configured to screen the initial expanded text according to the first category distance and the second category distance to determine a target expanded text;
[0151] A data set construction module 860 is configured to merge the target expanded text and the first annotated text to obtain a first data set, and obtain a second data set based on the second annotated text, wherein the number of texts in the first data set is the same as the number of texts in the second data set;
[0152] A model building module 870 is configured to adjust parameters of a preset initial classification model according to the first data set and the second data set to obtain a text classification model;
[0153] The text classification module 880 is used to perform text classification on the pre-acquired target text according to the text classification model.
[0154] It should be noted that the text classification device of the embodiment of the present application is used to implement the text classification method of the above embodiment. The text classification device of the embodiment of the present application corresponds to the above text classification method. Please refer to the above text classification method for the specific processing process, which will not be repeated here.
[0155] The present application also provides a computer device comprising: at least one memory, at least one processor, and at least one computer program, wherein the at least one computer program is stored in the at least one memory and the at least one processor executes the at least one computer program to implement any of the text classification methods described in the above embodiments. The computer device can be any intelligent terminal, such as a tablet computer or an in-vehicle computer.
[0156] See also Figure 9 , Figure 9 The hardware structure of a computer device according to another embodiment is shown, and the computer device includes:
[0157] The processor 910 may be implemented as a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is configured to execute relevant programs to implement the technical solutions provided in the embodiments of the present application.
[0158] The memory 920 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 920 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 920 and is called by the processor 910 to execute the text classification method of the embodiments of this application.
[0159] Input / output interface 930, used to implement information input and output;
[0160] Communication interface 940, used to implement communication interaction between this device and other devices, which can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WiFi, Bluetooth, etc.);
[0161] bus 950 , which transmits information between various components of the device (e.g., processor 910 , memory 920 , input / output interface 930 , and communication interface 940 );
[0162] The processor 910 , the memory 920 , the input / output interface 930 , and the communication interface 940 are connected to each other in communication within the device via a bus 950 .
[0163] An embodiment of the present application further provides a storage medium, which is a computer-readable storage medium. The computer-readable storage medium stores a computer program, which is used to enable a computer to execute the text classification method in the above embodiment.
[0164] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0165] The text classification method, text classification device, computer equipment and storage medium provided in the embodiment of the present application rewrite the unlabeled text by combining the method of prompt learning, and can obtain a high-precision labeled sample in the case of a small amount of original annotation. According to this method, it is possible to expand the category samples with a small number of texts corresponding to the labeled categories in the text corpus, and ensure the balance of training data under different categories, thereby effectively solving the problem of long-tail distribution of text data without the consumption of human annotation costs. Secondly, since the embodiment of the present application is an expansion of the category samples with a small number of texts corresponding to the labeled categories, it is obtained by prompt learning without annotation and without training, and its annotation accuracy for unlabeled text is not necessarily very high. Then, after the embodiment of the present application obtains the initial expanded text through prompt learning, the initial expanded text is cleaned by combining the clustering algorithm and the distance calculation method, and the sample text that does not meet the required annotation category can be further deleted. In addition, the embodiment of the present application divides the samples in the order of samples from small to large distance, and trains the model from simple samples to complex samples based on the divided training data, which can reasonably and effectively improve the effect of the model. Therefore, the embodiments of the present application can better solve the problem of long-tail distribution of text data and improve the efficiency and accuracy of text classification.
[0166] The embodiments described in the embodiments of this application are intended to more clearly illustrate the technical solutions of the embodiments of this application and do not constitute a limitation on the technical solutions provided by the embodiments of this application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0167] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0168] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, i.e., they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.
[0169] Those skilled in the art will appreciate that all or some of the steps in the methods, systems, and functional modules / units in the devices disclosed above may be implemented as software, firmware, hardware, or appropriate combinations thereof.
[0170] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0171] It should be understood that in this application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0172] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the above-mentioned units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0173] The units described above as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0174] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0175] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes multiple instructions for enabling 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 of various embodiments of the present application. The aforementioned storage medium includes: various media that can store programs, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0176] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but are not intended to limit the scope of the present invention. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and essence of the present invention should be within the scope of the present invention.
Claims
1. A text classification method, characterized in that: The method comprises: Acquire initial text data, the initial text data including initial annotated data and unannotated text, the initial annotated data including first annotated text annotated with a first annotation category and second annotated text annotated with a second annotation category, wherein the number of texts in the first annotated text is less than the number of texts in the second annotated text; Rewriting the unlabeled text according to a preset prompt template to obtain a rewritten text, and inputting the rewritten text into a preset mask prediction model to perform mask category prediction to obtain a mask category of the rewritten text; If the first annotation category and the mask category are the same, determining the unannotated text as the initial expanded text; Obtaining first cluster center data of the first annotated text and second cluster center data of the second annotated text, determining a first category distance based on the initial expanded text and the first cluster center data, and determining a second category distance based on the initial expanded text and the second cluster center data; Performing text screening on the initial expanded text according to the first category distance and the second category distance to determine a target expanded text; Merging the target expanded text and the first annotated text to obtain a first data set, and obtaining a second data set based on the second annotated text, wherein the number of texts in the first data set is the same as the number of texts in the second data set; Adjusting parameters of a preset initial classification model according to the first data set and the second data set to obtain a text classification model; The pre-acquired target text is classified according to the text classification model.
2. The method according to claim 1, characterized in that The step of screening the initial expanded text according to the first category distance and the second category distance to determine the target expanded text includes: Performing a numerical comparison on the first category distance and the second category distance to obtain a distance comparison result; If the distance comparison result indicates that the second category distance is greater than the first category distance, the initial expanded text is determined as the target expanded text.
3. The method according to claim 1, characterized in that The step of adjusting parameters of a preset initial classification model according to the first data set and the second data set to obtain a text classification model includes: determining training data based on the first data set and the second data set; Parameters of the initial classification model are adjusted according to the training data to obtain the text classification model.
4. The method according to claim 3, characterized in that The determining of training data according to the first data set and the second data set includes: Determining a third category distance according to the target expanded text and the first cluster center data; determining a fourth category distance according to the first annotated text and the first cluster center data; sorting the texts of the first data set according to the third category distance and the fourth category distance to obtain an expanded text sequence; Performing text sampling on the expanded text sequence to obtain a first text subsequence, where the first text subsequence includes a first training text whose text category is the first labeled category; Randomly sampling the second data set according to the number of texts in the first text subsequence to determine a second text subsequence, where the second text subsequence includes second training texts whose text category is the second labeled category; The first training text and the second training text are merged to obtain the training data.
5. The method according to claim 4, characterized in that The step of adjusting parameters of the initial classification model according to the training data to obtain the text classification model includes: Adjusting parameters of the initial classification model according to the training data to obtain a candidate classification model; Performing text sampling on the expanded text sequence according to the first text subsequence to determine a third text subsequence, wherein the third text subsequence includes a third training text whose text category is the first labeled category, and a category distance between the third training text and the first cluster center data is greater than or equal to a category distance between the first training text and the first cluster center data; Randomly sampling the second data set according to the number of texts in the third text subsequence to determine a fourth text subsequence, wherein the fourth text subsequence includes a fourth training text whose text category is the second labeled category; Merging the third training text and the fourth training text, and updating the training data according to the merging result; The parameters of the candidate classification model are adjusted according to the updated training data to obtain the text classification model.
6. The method according to claim 5, characterized in that The performing text sampling on the expanded text sequence according to the first text subsequence to determine a third text subsequence includes: Obtaining sampling cutoff data of the first text subsequence; Text sampling is performed on the expanded text sequence according to the sampling cutoff data to determine the third text subsequence.
7. The method according to any one of claims 1 to 6, characterized in that The acquiring first cluster center data of the first annotated text and second cluster center data of the second annotated text includes: Acquire initial cluster center data and target cluster data of the initial annotated data, wherein the initial cluster center data includes first center data of the first annotated text and second center data of the second annotated text; Performing distance calculation based on the first center data and the initial labeled data to obtain first cluster distance data; Performing distance calculation based on the second center data and the initial labeled data to obtain second cluster distance data; Performing a numerical comparison based on the first cluster distance data and the second cluster distance data to determine predicted cluster data of the initial labeled data according to a result of the numerical comparison; Class loss data is determined according to the predicted cluster data and the target cluster data, and data adjustment is performed on the initial cluster center data according to the class loss data to obtain the first cluster center data and the second cluster center data.
8. A text classification device, characterized in that: The device comprises: a text data acquisition module, configured to acquire initial text data, the initial text data including initial annotated data and unannotated text, the initial annotated data including first annotated text annotated with a first annotation category and second annotated text annotated with a second annotation category, wherein the first annotated text has less text than the second annotated text; A mask category prediction module is used to rewrite the unlabeled text according to a preset prompt template to obtain a rewritten text, and input the rewritten text into a preset mask prediction model to perform mask category prediction to obtain the mask category of the rewritten text; a category determination module, configured to determine the unlabeled text as initial expanded text if the first labeled category and the mask category are the same; a cluster distance calculation module, configured to obtain first cluster center data of the first annotated text and second cluster center data of the second annotated text, determine a first category distance based on the initial expanded text and the first cluster center data, and determine a second category distance based on the initial expanded text and the second cluster center data; a text screening module, configured to screen the initial expanded text according to the first category distance and the second category distance to determine a target expanded text; a data set construction module, configured to merge the target expanded text and the first annotated text to obtain a first data set, and obtain a second data set based on the second annotated text, wherein the number of texts in the first data set is the same as the number of texts in the second data set; A model building module, configured to adjust parameters of a preset initial classification model according to the first data set and the second data set to obtain a text classification model; The text classification module is used to perform text classification on the pre-acquired target text according to the text classification model.
9. A computer device, characterized in that: include: at least one memory; at least one processor; at least one computer program; The at least one computer program is stored in the at least one memory, and the at least one processor executes the at least one computer program to implement: The method according to any one of claims 1 to 7.
10. A storage medium, wherein the storage medium is a computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is used to cause a computer to execute: The method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Text classification method, text classification device, computer equipment and storage medium
CN115640394A
Methods and apparatuses for training service model and determining text classification category
US11216620B1