Text classification method and device, storage medium and electronic equipment

This text classification method generates fine-grained semantic labels through clustering and contrastive learning training. It solves the problems of high model training cost and poor recognition effect of new categories in existing technologies, realizes the self-updating and optimization of the model, and improves the accuracy and adaptability of classification.

CN122489771APending Publication Date: 2026-07-31PING AN INT FINANCIAL LEASING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
PING AN INT FINANCIAL LEASING CO LTD
Filing Date
2026-06-29
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

Existing neural network text classification models require modification of the model structure and retraining when adding new categories, resulting in high computational costs and poor recognition performance for new categories.

Method used

By pre-clustering to mine the inherent semantic structure of the data, using a large language model to generate fine-grained semantic category labels, and training the model through contrastive learning, the model learns the deep correspondence between the text and the fine-grained semantic labels, thus achieving self-updating and optimization.

Benefits of technology

It reduces model maintenance costs, improves recall for new categories and overall classification accuracy, enhances model robustness and scalability, and enables it to adapt to new data distributions and categories.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122489771A_ABST
    Figure CN122489771A_ABST
Patent Text Reader

Abstract

This application relates to a text classification method, apparatus, storage medium, and electronic device, belonging to the field of natural language processing technology, and applicable to the financial and medical fields. The method includes: responding to a training instruction, converting multiple unlabeled texts into multiple initial text vectors based on a text classification model to be trained; clustering the multiple initial text vectors to obtain at least one cluster; inputting each initial text vector included in each cluster and preset semantic label constraint information into a large language model to obtain a first semantic category label for each cluster; training the text classification model to be trained based on the first semantic category labels of each cluster and the initial text vectors included in each cluster to obtain a preset text classification model; and inputting the text to be tested into the preset text classification model to obtain a text classification matching result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, and can be applied to the financial and medical fields. In particular, it relates to a text classification method, apparatus, storage medium, and electronic device. Background Technology

[0002] Currently, in the field of natural language processing, text classification tasks are generally implemented using neural network-based methods. Related neural network classification techniques typically combine a feature extraction network (backbone) with a classification head for classification. For example, the Bert For Sequence Classification model in the Transformers library uses this structure. However, this method has significant limitations: the output dimension of the classification head is fixed, meaning the number of categories the model can classify is locked during training. When new categories need to be added in a business scenario, it is often necessary to modify the model structure and retrain the entire model, resulting in high computational and time costs. Furthermore, adding new categories often yields poor results due to insufficient samples. Summary of the Invention

[0003] This invention provides a text classification method, apparatus, storage medium, and electronic device to at least solve the problems of high model training costs and poor recognition performance for newly added categories in related technologies. The technical solution of this invention is as follows: According to a first aspect of the present invention, a text classification method is provided, the method comprising: a text classification method, the method comprising: responding to a training instruction of a text classification model to be trained, invoking the text classification model to be trained, and converting multiple unlabeled texts into multiple initial text vectors; wherein, the multiple initial text vectors are clustered to obtain at least one cluster; each cluster includes at least one initial text vector; inputting each initial text vector included in each cluster and preset semantic label constraint information into a large language model to obtain a first semantic category label for each cluster; training the text classification model to be trained based on the first semantic category label of each cluster and the initial text vector included in each cluster to obtain a trained preset text classification model; the set of first semantic category label vectors of the preset text classification model includes the first semantic label vector of the first semantic category label of each cluster; inputting the text to be tested into the preset text classification model to obtain a text classification matching result.

[0004] The above scheme automatically mines the inherent semantic structure of data through pre-clustering, and generates fine-grained semantic category labels using a large language model. Then, it trains the model through contrastive learning, making the feature space learned by the model more discriminative. This solves the problems of fixed number of categories and fluctuating effects of adding new categories in traditional classification methods.

[0005] As a technical solution, the text to be tested is input into a preset text classification model to obtain a text classification matching result. This includes: using the preset text classification model to perform the following operations on the text to be tested: converting the text to be tested into a text vector; matching the text vector to be tested with each semantic category label vector in the first semantic category label vector set to find the target semantic category label vector with the highest semantic similarity to the text vector to be tested; if the target semantic similarity of the target semantic category label vector is determined to be higher than the similarity threshold, then the text classification matching result is determined based on the target semantic category label vector.

[0006] The above scheme can accurately identify the category that best matches the semantics of the text to be tested by calculating the similarity between the text vector and the label vector and setting a threshold, while filtering out results with low matching degree, thus improving the accuracy of classification.

[0007] As a technical solution, the method further includes: if the target semantic similarity of the target semantic category label vector is determined to be lower than the similarity threshold, generating and displaying the first prompt information; the first prompt information is used to indicate that the matching degree between the semantic category label vector in the semantic category label vector set and the text to be tested is low; the first prompt information includes the text vector to be tested; generating target training text conditions based on the text vector to be tested in the first prompt information; filtering out multiple new training texts associated with the text vector to be tested based on the target training text conditions; initiating a training instruction for a preset text classification model; responding to the training instruction for the preset text classification model, generating multiple new text vectors of multiple new training texts based on the preset text classification model; generating each new cluster to which each new text vector belongs and the second semantic category label corresponding to each new cluster; training and adjusting the preset text classification model based on the second semantic category label of each new cluster and the new text vectors included in each new cluster to obtain a first target text classification model; the second semantic category label vector set of the first target text classification model includes the second semantic label vector of the second semantic category label.

[0008] The above approach achieves self-updating and optimization of the model by automatically triggering incremental training when low matching degree is identified, enabling it to adapt to new data distributions and categories, and further improving the robustness and scalability of the model.

[0009] As a technical solution, a text classification model to be trained is trained based on the first semantic category label of each cluster and the initial text vectors included in each cluster to obtain a pre-trained text classification model. This includes: determining positive sample pairs by combining the initial text vectors included in each cluster with the first semantic label vectors of the first semantic category label of the cluster; determining negative sample pairs by combining the initial text vectors included in each cluster with the first semantic label vectors of the first semantic category label of other clusters; and fine-tuning the text classification model to be trained using a training sample set composed of all positive and negative sample pairs, based on a contrastive learning loss function, to obtain the pre-trained text classification model. The contrastive learning loss function is used to maximize the first semantic similarity between the initial text vectors and the first semantic label vectors in positive sample pairs, and to minimize the second semantic similarity between the initial text vectors and other first semantic label vectors in negative sample pairs.

[0010] The above scheme, by constructing positive and negative sample pairs and using a contrastive learning loss function for training, narrows the distance between samples of the same class and their labels in the vector space, while widening the distance between samples of different classes, thereby significantly improving the model's semantic discrimination ability in the feature space.

[0011] As a technical solution, the method further includes: in response to a fine classification request from the text classification model to be trained, determining the coarse-fine category mapping relationship between each original category and multiple fine category labels reclassified from each original category in the text classification model to be trained; converting the fine label text included in each fine category label into a fine label text vector included in each fine category label; training and adjusting the text classification model to be trained based on each fine category label and the multiple fine label text vectors included in each fine category label to obtain an adjusted second target text classification model; the third semantic category label vector set of the second target text classification model includes the fine category label vectors of the fine category labels.

[0012] The above approach introduces fine-grained category labels for training, enabling the model to capture more subtle semantic features and further improving the precision of classification.

[0013] As a technical solution, the method includes: using a second target text classification model to classify the input text, including: converting the input text into text embedding vectors; determining the third semantic similarity between the text embedding vectors and each sub-category label vector in the third semantic category label vector set, and determining the third semantic similarity of the association of multiple sub-label text vectors associated with each original category according to the coarse and fine category mapping relationship; determining the average similarity of the third semantic similarity of the association of multiple sub-label text vectors associated with each original category as the comprehensive semantic similarity of each original category; and determining the original category with the highest comprehensive semantic similarity as the classification result of the input text.

[0014] The above scheme determines the coarse category by calculating the average similarity of the fine categories. It utilizes the complementarity of fine-grained features, making the classification results more stable and accurate, and effectively solving the bias problem caused by the lack of training for newly added categories.

[0015] As a technical solution, the initial text vectors and preset semantic label constraint information of each cluster are input into a large language model to obtain the first semantic category label of each cluster. This includes: embedding the preset semantic label constraint information as a label generation constraint condition into a preset prompt word template to obtain the target prompt word corresponding to each cluster; wherein, the label generation constraint condition is used to constrain the semantic category label generated by the large language model to satisfy the preset semantic label constraint information; and inputting the target prompt word of each cluster and the initial text vector of each cluster into the large language model to obtain the first semantic category label of each cluster.

[0016] The preset semantic tag constraints include at least one of the following: format requirements for semantic category tags; word count or length limits for semantic category tags; keywords to be avoided in semantic category tags; and the expected level of abstraction embodied by semantic category tags.

[0017] The above solution constructs prompt words using templates, effectively integrating pre-defined semantic label constraints into each stage of label generation. This ensures that the labels output by the large language model conform to the pre-defined specifications in terms of format, length, keywords, and abstraction level, thereby improving label quality and the reliability of subsequent model training.

[0018] According to a second aspect of the present invention, a text classification apparatus is provided, the apparatus comprising: a training unit configured to, in response to a training instruction for a text classification model to be trained, convert multiple unlabeled texts into multiple initial text vectors based on the text classification model to be trained; cluster the multiple initial text vectors to obtain at least one cluster; each cluster includes at least one initial text vector; input each initial text vector included in each cluster and preset semantic label constraint information into a large language model to obtain a first semantic category label for each cluster; train the text classification model to be trained based on the first semantic category labels of each cluster and the initial text vectors included in each cluster to obtain a trained preset text classification model; the set of first semantic category label vectors of the preset text classification model includes the first semantic label vectors of the first semantic category labels of each cluster; and a classification unit configured to input test text into the preset text classification model to obtain a text classification matching result.

[0019] According to a third aspect of the present invention, a text classification system is provided, which is configured to perform a text classification method as described in the first aspect and any possible implementation thereof.

[0020] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, on which instructions are stored, such that when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is able to perform a text classification method as described in the first aspect and any possible implementation thereof.

[0021] According to a fifth aspect of the present disclosure, a computer program product is provided, the computer program product including computer instructions that, when executed on an electronic device, cause the electronic device to perform the text classification method of the first aspect and any possible implementation thereof.

[0022] The technical solution provided by the embodiments of the present invention brings at least the following beneficial effects: First, through pre-clustering and contrastive learning training, the model learns a deep correspondence between text and fine-grained semantic tags, rather than a hard mapping of fixed categories. When a new category needs to be added, only a new semantic tag vector needs to be generated and included in the matching set, without modifying the model structure or retraining, which greatly reduces maintenance costs.

[0023] Secondly, this application employs a strategy of averaging fine-grained subclass and major class similarities. During training, each major class corresponds to multiple fine-grained subclass names, and the model learns semantic similarity rather than rigid category IDs. During inference, the major class is determined by averaging the similarities of the fine-grained subclasses. This mechanism allows the model to effectively distinguish new categories based on their semantic label vectors, even if they are not included in the training. Furthermore, by increasing the number of untrained subclasses, the vector space distribution can be balanced, making neutral samples more likely to be biased towards the new category, thereby significantly improving the recall rate of new categories and the overall classification accuracy.

[0024] Finally, by using a large language model to automatically generate semantic labels, not only is the cost of manual annotation reduced, but the potential semantic structure of the data is also mined through clustering, making the training data more representative and thus improving the model's generalization ability in complex scenarios.

[0025] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0026] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.

[0027] Figure 1 This is a schematic diagram illustrating a text classification system according to an exemplary embodiment; Figure 2 This is a flowchart illustrating a text classification method according to an exemplary embodiment; Figure 3 This is a comparative schematic diagram illustrating a vector distribution according to an exemplary embodiment; Figure 4 This is a block diagram illustrating a text classification device according to an exemplary embodiment; Figure 5 This is a schematic diagram of an electronic device according to an exemplary embodiment. Detailed Implementation

[0028] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.

[0029] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.

[0030] Before providing a detailed description of the text classification method provided in the embodiments of this application, a brief introduction to the implementation environment involved in the embodiments of this application is given.

[0031] Figure 1 This is a schematic diagram of a text classification system provided in this disclosure. For example... Figure 1 As shown, the text classification system includes a client 11 and a server 12. The text classification system can be a distributed system. The client 11 and the server 12 communicate with each other via a wired network and / or a wireless network.

[0032] This system can be a standalone server cluster or a cloud-based service platform. The system includes input interfaces, output interfaces, a processor, and storage media.

[0033] Server 12 receives unlabeled text sets or test texts uploaded by user 11. After acquiring a large amount of unlabeled text, server 12 performs pre-clustering on the text vectors corresponding to the unlabeled texts, trains a pre-set model using contrastive learning, and stores the trained model on server 12. When server 12 acquires test text, it uses the trained model to perform real-time inference on the test text and returns the inference result to user 11. Through the above method, the system achieves fully automated management of the entire process from data input, model training, model deployment to online inference, providing users with an efficient, scalable, and robust text classification solution.

[0034] In some embodiments, server 12 includes or is connected to a database that stores text classification models used for performing text classification. Text classification models for different business types are stored in different databases. For example, financial text classification models are stored in a first database, while medical text classification models reside in a second database. Users of client 11 can access these databases associated with server 12.

[0035] In other embodiments, server 12 may be a single server, or it may be a server cluster consisting of multiple servers. In some embodiments, the server cluster may also be a distributed cluster. This application does not limit the specific implementation of server 12.

[0036] The text classification method provided in this application embodiment can be applied to the aforementioned... Figure 1 The text classification system in the implementation architecture shown is illustrated. For ease of understanding, the text classification method provided in this application will be described in detail below with reference to the accompanying drawings.

[0037] Figure 2 This is a flowchart illustrating a text classification method according to an exemplary embodiment, such as... Figure 2 As shown, this text classification method includes the following steps.

[0038] Step S100: In response to the training instruction of the text classification model to be trained, multiple unlabeled texts are converted into multiple initial text vectors based on the text classification model to be trained.

[0039] In this embodiment, the text classification model to be trained can be a pre-trained language model based on the Transformer architecture, such as the BERT model, the RoBERTa model, or the Qwen-Embedding model. These models have powerful text feature extraction capabilities and can map discrete text characters into points in a continuous high-dimensional vector space.

[0040] Unlabeled text refers to raw text data that has not been manually categorized, such as user comments, news articles, or customer service chat logs scraped from the internet. Training instructions can be initiated by a system administrator via a terminal device or automatically triggered by a scheduled system task. Upon receiving the instruction, the model reads a massive amount of unlabeled text stored in a database or file system and uses its internal embedding layer or encoder to convert each text into a fixed-dimensional initial text vector.

[0041] It should be understood that the dimension of the initial text vector depends on the selected model architecture, such as 768 dimensions, 1024 dimensions or other dimensions, and this embodiment does not specifically limit it.

[0042] Step S101: Cluster the multiple initial text vectors to obtain at least one cluster; a cluster includes at least one initial text vector.

[0043] After obtaining the initial text vectors, this embodiment uses a clustering algorithm to perform unsupervised clustering of these vectors. The clustering algorithm can be K-Means, DBSCAN, or hierarchical clustering, among others. Taking K-Means as an example, the system pre-sets a clustering parameter K, the value of which is usually greater than the actual number of categories required in the business scenario. For example, if the business requirement is binary classification (such as positive sentiment and negative sentiment), the clustering parameter K can be set to 4 or a larger value.

[0044] Clustering operations group similar vectors in a high-dimensional vector space together to form several clusters. Each cluster represents a set of texts with similar semantic features.

[0045] The reason for performing clustering before generating labels in this embodiment is that directly generating labels for massive amounts of unlabeled text is not only computationally expensive but also prone to semantic overlap or incomplete coverage. For example, different texts may express the same meaning; directly generating labels might result in multiple similar labels such as "happy," "joyful," and "pleasant," leading to category redundancy; or some long-tail semantics might be ignored, resulting in incomplete label coverage. By clustering, semantically similar texts are grouped together, and then this group of texts is uniformly named, which effectively uncovers the inherent semantic structure of the data, ensuring that the generated labels are both distinctive and representative.

[0046] Step S102: Input the initial text vectors and preset semantic label constraint information of each cluster into the large language model to obtain the first semantic category label of each cluster.

[0047] After clustering is completed, for each cluster, this embodiment will randomly extract several sample text vectors and restore them to the original text, which will be input into the large language model along with the preset semantic label constraint information.

[0048] Large language models can be GPT series models, LLaMA series models, or Qwen series models, etc. Preset semantic label constraint information is a key control parameter used to guide the large language model in generating standardized labels.

[0049] Specifically, the preset semantic label constraint information may include the following information.

[0050] First, there are formatting requirements for semantic category tags. For example, tags must be in the format of nouns and adjectives.

[0051] Secondly, there are character or length restrictions on semantic category tags.

[0052] For example, the length of the tag is limited to no more than 4 Chinese characters.

[0053] Third, keywords that should be avoided in semantic category tags, such as prohibiting the use of vague words like "other" or "unknown".

[0054] Fourth, the abstract hierarchy embodied by the semantic category labels is expected.

[0055] For example, the label should describe a specific emotional tendency rather than a specific event.

[0056] By setting these constraints, it can be ensured that the tags generated by the large language model conform to the business logic, avoiding the generation of overly abstract or colloquial tags.

[0057] Step S103: Based on the first semantic category label of each cluster and the initial text vector included in each cluster, train the text classification model to be trained to obtain the pre-trained text classification model.

[0058] The first semantic category label vector set of the preset text classification model includes the first semantic label vector of the first semantic category label of each cluster.

[0059] After obtaining the first semantic category label corresponding to each cluster, this embodiment uses these labels and the original text vectors to construct training samples for fine-tuning the text classification model to be trained. The training process can be carried out using a contrastive learning approach.

[0060] Specifically, text vectors within a cluster and their corresponding first semantic category label vectors are considered positive sample pairs, while text vectors within a cluster and their corresponding first semantic category label vectors from other clusters are considered negative sample pairs. By minimizing the contrastive learning loss function, the model can narrow the distance between positive sample pairs and widen the distance between negative sample pairs in the vector space. The trained model is the predefined text classification model, which not only learns the semantic features of the text but also the deep correspondence between the text and fine-grained labels.

[0061] The first semantic category label vector set refers to the vector set obtained after the first semantic category labels generated by all clusters are encoded by the model. This set constitutes the benchmark vector library for matching in the subsequent inference stage.

[0062] Step S200: Input the text to be tested into the preset text classification model to obtain the text classification matching result.

[0063] During the model application phase, when a user inputs a piece of text to be tested, the pre-defined text classification model first converts the text into a text vector, and then calculates the semantic similarity between this text vector and each label vector in the first semantic category label vector set. Semantic similarity can be calculated using methods such as cosine similarity, Euclidean distance, or dot product. Finally, the model outputs the category corresponding to the label vector with the highest similarity to the text vector, as the text classification matching result.

[0064] This embodiment utilizes the above-described scheme to mine the inherent structure of unlabeled data and combines it with a large language model to automatically generate fine-grained labels that conform to business specifications, thus achieving automated construction of training data and greatly reducing the cost of manual annotation. Simultaneously, through comparative learning training, the model learns more discriminative semantic features, enabling effective classification without retraining the model when handling new categories, significantly improving the scalability and robustness of the text classification system.

[0065] This embodiment, based on Embodiment 1, provides a detailed explanation of the matching and determination process of the text classification model during the inference phase. This process mainly involves how to accurately classify the test text using a pre-trained text classification model, and how to ensure matching accuracy through pre-defined semantic label constraints.

[0066] The above step S200, which involves inputting the text to be tested into a preset text classification model to obtain the text classification matching result, specifically includes the following processing procedures.

[0067] Step S201: Using a preset text classification model, perform the following operation on the text to be tested: convert the text to be tested into a text vector.

[0068] In this embodiment, a preset text classification model receives the test text input by the user and uses the embedding layer or encoder inside the model to map the test text into a test text vector in a high-dimensional vector space. The dimension of this vector is consistent with the dimension of the first semantic category label vector generated during the training phase to ensure that effective mathematical calculations can be performed subsequently.

[0069] It should be understood that the text vector to be tested carries the deep semantic features of the text to be tested, which is the basis for subsequent similarity calculation.

[0070] Step S202: Match the text vector to be tested with each semantic category label vector in the first semantic category label vector set to find the target semantic category label vector with the highest semantic similarity to the text vector to be tested.

[0071] After obtaining the text vector to be tested, the model calculates the semantic similarity between this vector and each label vector in the first semantic category label vector set. The semantic similarity can be calculated using cosine similarity, the reciprocal of Euclidean distance, dot product, or other measures that can characterize the distance or angle between vectors.

[0072] Taking cosine similarity (cosine_similarity(A, B)) as an example, its calculation formula is as follows.

[0073] cosine_similarity(A, B) =(A·B) / (||A|| ||B||).

[0074] Where A represents the text vector to be tested, B represents the label vector, and the cosine similarity value ranges from -1 to 1. The closer the value is to 1, the more consistent the semantic direction of the two vectors are.

[0075] The model iterates through all the label vectors in the set, calculates a series of similarity values, and selects the label vector with the highest value as the target semantic category label vector. This process is essentially finding the category center that is closest to the text to be tested in a high-dimensional semantic space.

[0076] Step S203: If the target semantic similarity of the target semantic category label vector is higher than the similarity threshold, then the text classification matching result is determined based on the target semantic category label vector.

[0077] To ensure the reliability of the classification results, this embodiment introduces a similarity threshold as a judgment criterion. The similarity threshold is a preset value, such as 0.75, 0.8, or 0.85, and the specific value can be adjusted according to the requirements of accuracy and recall in the business scenario.

[0078] If the calculated highest similarity (i.e. target semantic similarity) is higher than the threshold, it indicates that the text to be tested has a very high semantic correlation with a certain category. The model determines that the text belongs to that category and outputs the corresponding label as the classification result.

[0079] Conversely, if the target semantic similarity is below the threshold, it means that the text to be tested may not match all existing categories well. In this case, the model may not be able to give a definite classification result. In this case, the system can trigger the subsequent model self-update process or manual intervention mechanism to avoid incorrect classification output.

[0080] Furthermore, this embodiment details the impact of preset semantic label constraint information on matching accuracy. During the training phase, when generating the first semantic category label, the preset semantic label constraint information plays a crucial guiding role, and this constraint information includes at least one of the following.

[0081] The first requirement is the format requirements for semantic category tags.

[0082] For example, tags must be in the format of noun + adjective or verb-object structure. Standardized formats reduce ambiguity between tags, resulting in more clearly defined distribution boundaries for the generated tag vectors in space, thereby improving the accuracy of vector matching during the inference phase.

[0083] For example, when generating text expressing happiness, generating "extreme joy" is more in line with the standard format than generating "haha," as the former is easier to distinguish from other emotion categories in the vector space.

[0084] The second item is the word count or length limit for semantic category tags.

[0085] For example, the number of characters in the tag can be limited to between 2 and 10 Chinese characters. Too few characters (such as a single character) often cannot carry enough semantic information, resulting in a lack of discriminative power in the generated tag vector, which can easily lead to misjudgment during matching; too many characters may introduce noise information, resulting in an overly sparse vector space, which also affects the matching accuracy.

[0086] By limiting the number of characters, we can ensure that tags have rich semantic expression while maintaining conciseness, thereby optimizing the effect of vector matching.

[0087] Thirdly, keywords that should be avoided in semantic category tags.

[0088] For example, the use of vague or generalized terms such as "other," "unknown," and "mixed" as labels is prohibited. The semantic boundaries of these terms are extremely vague, and their corresponding vectors are prone to overlap with vectors of multiple categories in space, leading to confusion during matching.

[0089] By setting a keyword blacklist, low-quality tags can be effectively removed, improving the model's ability to distinguish specific categories.

[0090] The fourth item is the level of abstraction embodied by the expected semantic category label.

[0091] For example, the labels should describe specific emotional tendencies (such as anger or sadness) rather than specific events (such as smashing a cup or crying). If the labels are too specific, it will lead to an explosion in the number of categories, and the same semantic meaning will be broken down into multiple fragmented labels, making it difficult for the text to be matched with the most appropriate category; if the labels are too abstract, they will fail to capture the subtle differences in the text.

[0092] By setting an appropriate level of abstraction, large language models can be guided to generate labels with appropriate granularity, making the category distribution in the vector space more reasonable, thereby improving the robustness of matching.

[0093] This embodiment, through the aforementioned refined vector matching logic and threshold determination mechanism, combined with a multi-dimensional label constraint strategy, not only achieves automated classification of the text to be tested, but also ensures the accuracy and reliability of the classification results from the source, effectively solving the classification deviation problem caused by inconsistent label quality in the prior art.

[0094] This embodiment, based on the above embodiments, provides a detailed explanation of the training process of the text classification model. Specifically, this embodiment elaborates on how to utilize a contrastive learning algorithm to construct training samples and fine-tune the model based on unlabeled data obtained from clustering and the generated large language model labels, thereby endowing the model with powerful semantic discrimination capabilities.

[0095] Specifically, the steps of training the text classification model to obtain the pre-trained text classification model based on the first semantic category label of each cluster and the initial text vector included in each cluster include the following processing procedures.

[0096] First, the initial text vectors included in each cluster and the first semantic label vector of the first semantic category label of the cluster are identified as positive sample pairs.

[0097] In this embodiment, the construction of positive sample pairs is the core of contrastive learning training. Since clustering operations have already grouped semantically similar texts into the same cluster, text vectors within the same cluster have a natural proximity relationship in the semantic space. The first semantic category label (e.g., extreme joy) generated by the large language model for this cluster is a high-level summary of the semantics of all texts within that cluster.

[0098] Based on this, pairing text vectors within a cluster with the label vector of that cluster as positive samples means that the training process forces the model to learn the association that the text belongs to that semantic category. For example, if the texts in a cluster are "This movie is so exciting" and "The plot is very engaging," and the label for that cluster is "Exciting plot," then the model will bring these two text vectors closer to the label vector for "Exciting plot." The advantage of this approach is that it no longer relies on manually labeling data line by line, but instead uses the clustering structure to automatically uncover the potential associations between text and labels, greatly reducing data preparation costs.

[0099] Secondly, the initial text vectors included in each cluster and the first semantic label vectors of the first semantic category labels of other clusters are identified as negative sample pairs.

[0100] In contrast to positive sample pairs, negative sample pairs are used to tell the model which categories the text does not belong to. In this embodiment, for a text vector within a certain cluster, the label vectors of other clusters represent drastically different semantic directions. For example, for text within the "exciting plot" cluster mentioned above, the labels of other clusters might be "awkward acting" or "dim screen." Pairing these label vectors with the text vector as negative samples forces the model to push the text vector away from these irrelevant semantic regions in the semantic space. This embodiment employs a strategy of negative sampling between clusters, which is more discriminative than traditional random negative sampling. Because the semantic differences between different clusters are usually large, the model can more easily learn the clear boundaries between different categories, thereby accelerating convergence and improving classification accuracy.

[0101] Next, using the training sample set consisting of all positive and negative sample pairs, the text classification model to be trained is fine-tuned based on the contrastive learning loss function to obtain the preset text classification model.

[0102] In this embodiment, the design goal of the contrastive learning loss function is to maximize the first semantic similarity between the initial text vector and the first semantic label vector in the positive sample pair, and to minimize the second semantic similarity between the initial text vector and other first semantic label vectors in the negative sample pair.

[0103] Specifically, this embodiment can use the InfoNCE loss function as the contrastive learning loss function, and its mathematical expression is as follows.

[0104] L = -log( exp(sim(v_i, l_pos) / τ) / Σ_k exp(sim(v_i, l_k) / τ) ) Where v_i represents the i-th initial text vector within the cluster, l_pos represents the first semantic label vector corresponding to the cluster, l_k represents the k-th label vector including positive sample labels and all negative sample labels, sim(·,·) represents the cosine similarity function, and τ represents the temperature coefficient.

[0105] The temperature coefficient τ is a hyperparameter used to control the difficulty the model makes in distinguishing negative samples. When τ is small, the model pays more attention to those difficult-to-distinguish negative samples, thus learning more refined semantic features; when τ is large, the model's distinction of negative samples is relatively lenient. By minimizing this loss function L, the model continuously adjusts its parameters, making the distance between v_i and l_pos in the vector space get closer and closer, while the distance between v_i and l_k (k≠pos) gets farther and farther.

[0106] This embodiment achieves effective utilization of unlabeled text data through the contrastive learning strategy of positive within clusters and negative between clusters. Traditional supervised classification training usually adopts a strategy of positive for similar categories and negative for dissimilar categories, which relies on a large amount of manually labeled data to define similar and dissimilar categories.

[0107] This embodiment utilizes cluster structures automatically generated by clustering algorithms to define positive and negative samples. This not only solves the problem of training with unlabeled data but also constructs a denser supervisory signal through fine-grained cluster labels (compared to coarse-grained class labels). This training method results in a more compact and discriminative vector space distribution learned by the model. Text and labels of the same semantic category cluster together, while text and labels of different semantic categories are far apart, thus significantly improving the classification accuracy and robustness in subsequent inference stages.

[0108] This embodiment, based on the above embodiments, provides a detailed explanation of the self-updating and incremental training mechanism when the model encounters low-matching scenarios during the inference phase. In real-world business scenarios, new text categories or semantic drift may emerge over time, causing the preset text classification model to fail to accurately identify the test text. This embodiment solves this problem by constructing a closed-loop optimization process through the following steps.

[0109] Step S301: If the target semantic similarity of the target semantic category label vector is determined to be lower than the similarity threshold, generate and display the first prompt information.

[0110] The first prompt is used to indicate that the semantic category label vector in the semantic category label vector set has a low matching degree with the text to be tested; the first prompt includes the text vector to be tested.

[0111] In this embodiment, when the calculated highest similarity (i.e., the target semantic similarity) is lower than a preset similarity threshold, it indicates that the text to be tested does not match any category in the existing tag set. This situation usually means that the text to be tested belongs to a new category that has never appeared before, or that its semantic features have shifted significantly.

[0112] At this point, the system will not force an incorrect classification result, but will instead generate a preliminary warning message. This message can be an alert log, a notification email, or a pop-up notification on the front-end interface, informing the administrator or operations personnel that the current model cannot process the text. The test text vector contained in the preliminary warning message is a key data index for subsequent incremental training.

[0113] Step S302: Generate target training text conditions based on the text vector to be tested in the first prompt information.

[0114] The target training text conditions are a set of rules used to select potential training samples. Since a single test text may contain noise or randomness, directly using it for training may not be robust enough. Therefore, it is necessary to retrieve more similar samples based on the text's features. Specifically, the target training text conditions can include: other text vectors whose cosine similarity to the test text vector is within a preset range (e.g., between 0.8 and 0.95); or text data from the same source channel as the test text (e.g., the same user group, the same time period); or other texts containing the same keywords as the test text. By generating these conditions, the system can accurately locate a subset of data related to the current new category from a massive historical database.

[0115] Step S303: Based on the target training text conditions, select multiple new training texts that are associated with the text vector to be tested.

[0116] The system inputs the target training text conditions into a database or search engine, performs a retrieval operation, and thus filters out multiple new training texts. These new training texts are semantically highly relevant to the test text and represent new categories or distributions that the model has not previously learned. For example, if the test text is a description of an emerging concept about the metaverse, and the model has not previously encountered such texts, the filtered new training texts may include a large number of documents on related topics such as virtual reality and digital twins. This step ensures the scale and diversity of incremental training data and avoids the overfitting risk caused by single-sample training.

[0117] Step S304: Initiate a training instruction for the preset text classification model.

[0118] Once the data is ready, the system automatically triggers a training command. This command signifies that the model is switching from a static inference state to a dynamic learning state. It should be understood that the training command in this embodiment can be initiated automatically by the system or after manual review and confirmation, depending on the business's security requirements.

[0119] Step S305: In response to the training instruction for the preset text classification model, based on the preset text classification model, generate multiple new text vectors for multiple newly added training texts; generate each new text vector to its respective new cluster and the second semantic category label corresponding to each new cluster.

[0120] In this implementation step, the system uses an existing preset text classification model (or its encoder portion) to vectorize the selected new training texts, obtaining new text vectors. Subsequently, the system performs a clustering operation on these new text vectors, generating new clusters. Similar to the initial training phase, the system calls a large language model to generate a second semantic category label for each new cluster.

[0121] It is worth noting that the number of new clusters K' can differ from the initial number of clusters K, allowing the system to adaptively adjust the clustering parameters based on the scale and distribution density of the new data. Through this process, the model can automatically discover and define new semantic categories, such as identifying the metaverse as a new independent category and assigning it an accurate label.

[0122] Step S306: Based on the second semantic category label of each newly added cluster and the newly added text vectors included in each newly added cluster, the preset text classification model is trained and adjusted to obtain the first target text classification model; the set of second semantic category label vectors of the first target text classification model includes the second semantic label vectors of the second semantic category labels.

[0123] After obtaining the new labels and vectors, the system employs a contrastive learning strategy similar to that in Example 3 to fine-tune the preset text classification model. The difference lies in the incremental training: the model not only learns the new categories but also retains its memory of the old categories. Therefore, in addition to the newly added positive and negative samples, the training sample set can also include some samples from the old categories as replay data to prevent catastrophic forgetting. After training, the resulting model is called the first target text classification model. The label vector set of this model not only includes the original first semantic category label vectors but also expands upon the newly generated second semantic label vectors, thus achieving real-time updates to the model's knowledge base.

[0124] This embodiment, through the aforementioned closed-loop mechanism, endows the text classification system with powerful dynamic adaptability. When faced with new categories or semantic drift, the system does not require manual intervention to re-label massive amounts of data, nor does it need to retrain the model from scratch. Instead, it can automatically identify blind spots, proactively retrieve relevant samples, autonomously define new categories, and complete incremental learning. This mechanism effectively solves the problem of poor performance caused by untrained new categories in existing technologies, greatly improving the system's robustness and maintainability, enabling it to adapt to constantly changing real-world business environments.

[0125] This embodiment, building upon the previous embodiments, provides a detailed explanation of the training and inference strategies for text classification models, specifically addressing business scenarios requiring refined classification. In practical applications, coarse-grained classification often falls short of requirements. For instance, in sentiment analysis, simply distinguishing between positive and negative might be too simplistic; business stakeholders may desire to further differentiate between finer-grained emotions such as extreme joy or relaxation. This embodiment addresses this by introducing fine-grained category labels and their mapping relationships through the following training adjustment steps, thereby enhancing the model's discriminative ability.

[0126] Step S401: In response to the fine classification request of the text classification model to be trained, determine the coarse and fine category mapping relationship between each original category and the multiple fine category labels reclassified from each original category in the text classification model to be trained.

[0127] In this embodiment, the fine-grained classification request can be initiated by business personnel based on actual needs, such as specifying the original categories to be subdivided through a configuration file. The original category refers to the coarse-grained category set during the initial training of the model, such as positive emotion; the fine-grained category label refers to the more specific label obtained after semantically splitting the original category, such as splitting positive emotion into extreme joy, relaxed and happy, and satisfied. The system automatically establishes a mapping table between the original categories and the fine-grained category labels, for example: {positive emotion: [extreme joy, relaxed and happy, satisfied], negative emotion: [anger, sadness, disappointment]}. The establishment of this mapping relationship provides the foundation for the aggregation calculation in the subsequent inference stage.

[0128] Step S402: Convert the sub-label text included in each sub-category label into a sub-label text vector included in each sub-category label.

[0129] The system uses a pre-defined text classification model (or its encoder part) to convert the text description of each sub-category label into a sub-label text vector in a high-dimensional vector space. It should be understood that these sub-label text vectors are in the same semantic space as the first semantic category label vector generated in the initial training phase, so similarity calculation can be performed directly.

[0130] Step S403: Based on each subcategory label and the multiple subcategory label text vectors included in each subcategory label, the text classification model to be trained is trained and adjusted to obtain the adjusted second target text classification model; the third semantic category label vector set of the second target text classification model includes the subcategory label vectors of the subcategory labels.

[0131] During the training and adjustment phase, the system can employ a contrastive learning strategy similar to that in Example 3, using fine-tuning with subcategories and corresponding text data. Through this process, the model can learn more nuanced semantic features, ensuring that different subcategories within the same original category maintain a certain degree of clustering (belonging to the same major category) while also having clear boundaries (belonging to different subcategories) in the vector space.

[0132] During the inference phase, this embodiment uses a second target text classification model to classify the input text, specifically including the following steps.

[0133] Step S404: Convert the input text into a text embedding vector.

[0134] Step S405: Determine the third semantic similarity between the text embedding vector and each sub-category label vector in the third semantic category label vector set, and determine the third semantic similarity of the multiple sub-label text vectors associated with each original category according to the coarse and fine category mapping relationship.

[0135] Step S406: The average similarity of the third semantic similarity of the multiple fine label text vectors associated with each original category is determined as the comprehensive semantic similarity of each original category.

[0136] Step S407: The original category with the highest comprehensive semantic similarity is determined as the classification result of the input text.

[0137] The core of the above reasoning lies in the calculation of average similarity.

[0138] Combination Figure 3 The diagram showing the vector distribution comparison can intuitively illustrate its principle. Figure 3 The left side shows the vector distribution when classifying directly using coarse-grained labels. As you can see, the vector circles for two major categories (such as positive and negative) have a large overlap, and samples at this overlap (solid black dots) are easily misclassified. This is because the semantic scope of coarse-grained labels is too broad, resulting in unclear category centers and blurred boundaries in the vector space.

[0139] like Figure 3As shown, this application's embodiment employs a strategy of averaging fine-grained subclasses and major categories to determine the vector distribution. A comparison reveals that the original major category circles are further divided into multiple non-overlapping inner circles (fine categories). During inference, the system calculates the similarity between the input text and all fine category vectors, and then, based on the mapping relationship, averages the similarities of fine categories belonging to the same major category.

[0140] For example, if the similarity of the input text to extreme joy is 0.85, the similarity to relaxed and happy is 0.82, and the similarity to satisfied is 0.80, then the overall similarity of positive emotions is (0.85+0.82+0.80) / 3=0.823.

[0141] Based on the above comparison, we can see that: First, fine category labels (such as extreme joy) have a clearer semantic orientation than coarse category labels (such as positive), and can form more compact clusters in the vector space, thereby reducing the overlapping area between categories.

[0142] Second, averaging can smooth out noise biases introduced by individual subcategories. For example, if an input text happens to have a significant semantic deviation from a particular subcategorie label, averaging can reduce the impact of this randomness on the overall classification result.

[0143] Third, for newly added categories, since the distribution of new, untrained subcategories in the vector space is relatively loose, their overall score after averaging is often more competitive, thus effectively solving the problem of low recognition rate caused by the lack of training for newly added categories.

[0144] This embodiment significantly improves the accuracy and robustness of the classification system in complex scenarios without increasing the cost of manual annotation through the above mechanism.

[0145] In one implementation, the initial text vectors and preset semantic label constraint information of each cluster are input into a large language model to obtain the first semantic category label of each cluster. This includes: embedding the preset semantic label constraint information as a label generation constraint condition into a preset prompt word template to obtain the target prompt word corresponding to each cluster; wherein, the label generation constraint condition is used to constrain the semantic category label generated by the large language model to satisfy the preset semantic label constraint information; and inputting the target prompt word of each cluster and the initial text vector of each cluster into the large language model to obtain the first semantic category label of each cluster.

[0146] In this embodiment, the preset prompt word template is a pre-designed text framework used to guide the large language model to perform a specific tag generation task. The preset prompt word template may include task description fields, output format requirement fields, and constraint condition fields, etc. The process of embedding preset semantic tag constraint information into the preset prompt word template is essentially converting structured constraint information into natural language instructions that the large language model can understand.

[0147] For example, if the preset semantic label constraints include that the label should not exceed four Chinese characters and that vague words such as "other" or "unknown" are prohibited, the target prompt word could be: "Based on the following text sample, please generate a semantic category label for this set of texts. Requirements: The label should not exceed four Chinese characters, and vague words such as "other" or "unknown" are not allowed. The label should reflect the core sentiment of the text."

[0148] In this way, constraint information is explicitly passed to the large language model, enabling it to follow these constraints when generating labels.

[0149] It should be understood that the design of the preset prompt word template can be adjusted according to different business scenarios. For example, more granular constraints can be added, such as requiring the label to be a noun phrase or the label to reflect a specific emotional direction rather than an event description.

[0150] Furthermore, different clusters can share the same preset prompt word template, or different preset prompt word templates can be used according to the semantic features of the clusters. This embodiment does not make specific limitations in this regard.

[0151] After combining the constructed target prompts with the initial text vectors, the input is fed into the large language model via the application programming interface (API). Upon receiving the input, the large language model, based on its pre-trained language understanding capabilities, comprehensively analyzes the semantic features of the input text and, guided by the constraints in the target prompts, generates a first semantic category label that meets the requirements. For example, for a cluster containing a large number of texts expressing "satisfaction with the movie plot," the large language model might generate "exciting plot" as the initial semantic category label.

[0152] In some embodiments, the first semantic category label is the direct output of the large language model. Although the large language model is guided by constraints during generation, the generation process of the large language model has a certain degree of randomness. The first semantic category label directly output by the large language model may occasionally not fully meet all constraints. Therefore, according to the preset semantic label constraint information, the first semantic category label directly output by the large language model is constrained and verified, and the first semantic category label that passes the verification is determined as the first semantic category label of each cluster.

[0153] Constraint validation includes at least one of the following: checking whether the number of characters in the first semantic category tag meets the character or length limit; checking whether the first semantic category tag contains keywords that should be avoided; checking whether the format of the first semantic category tag meets the format requirements, such as checking whether the tag is a noun phrase format.

[0154] If the first semantic category label passes all constraint checks, it is directly determined as the first semantic category label of the cluster. If the first semantic category label fails a constraint check, the system will perform corresponding correction operations according to the type of constraint that failed. For example, if the label character count exceeds the limit, the label is truncated, retaining the most semantically concentrated part; if the label contains prohibited keywords, the prohibited keywords are replaced with preset alternative words; if the label format does not meet the requirements, the label is converted to a compliant format. After post-processing, the final label is the first semantic category label of the cluster, which strictly conforms to the requirements of the preset semantic label constraint information in terms of format, length, keywords, and abstraction level. To achieve the above functions, the text classification device includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, in conjunction with the algorithm steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or computer software-driven hardware depends on the specific application and design constraints of the technical solution. Skilled professionals may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0155] This disclosure also provides an embodiment such as Figure 4 The text classification device shown includes a training unit 41 and a classification unit 42. This device aims to implement the text classification method described in any of the above embodiments through a combination of hardware and software, thereby ensuring the efficiency of model training and the real-time performance of the inference phase at the hardware level.

[0156] Training unit 41 is configured to respond to training instructions for the text classification model to be trained, and based on the text classification model to be trained, convert multiple unlabeled texts into multiple initial text vectors; cluster the multiple initial text vectors to obtain at least one cluster; each cluster includes at least one initial text vector; input each initial text vector included in each cluster and the preset semantic label constraint information into the large language model to obtain the first semantic category label of each cluster; train the text classification model to be trained based on the first semantic category label of each cluster and the initial text vector included in each cluster to obtain the trained preset text classification model; the set of first semantic category label vectors of the preset text classification model includes the first semantic label vector of the first semantic category label of each cluster.

[0157] The training unit 41 is the core logic module in the device responsible for model building and optimization. In terms of hardware implementation, the training unit 41 can be carried out by specific computing circuits in the processor 30 or by a neural network processing unit (NPU). The training unit 41 can be further divided into a vector transformation module, a clustering processing module, a label generation module, and a model fine-tuning module.

[0158] The vector conversion module is responsible for calling the pre-trained embedding model to convert text into vectors.

[0159] The clustering module executes clustering algorithms such as K-Means.

[0160] The tag generation module generates tags by calling externally or internally deployed large language models through API interfaces.

[0161] The model fine-tuning module adjusts the model parameters based on the contrastive learning loss function. After training is completed, the training unit 41 stores the parameters of the generated preset text classification model (such as the weight matrix and bias terms) and the first semantic category label vector set for use in the subsequent inference stage.

[0162] It should be understood that in actual deployment, training unit 41 can also share the same set of underlying computing resources with classification unit 42, and the reuse of training and inference can be achieved through time-slice rotation or parallel computing.

[0163] Classification unit 42 is configured to input the text to be tested into a preset text classification model to obtain the text classification matching result.

[0164] The aforementioned classification unit 42 is the module responsible for actual business processing in the device, responding to users' real-time query requests. The classification unit 42 obtains the model parameters and label vector set stored in the training unit 42, performs vectorization processing on the text to be tested, and executes similarity calculation and threshold determination logic.

[0165] The processing latency of the classification unit 42 directly determines the user's service experience, so it is usually deployed on a high-performance inference chip. In terms of data flow, the classification unit 42 receives the input test text and outputs the classification matching result. If the judgment result is a low matching degree, the classification unit 42 can also generate a trigger signal to instruct the training unit 42 to start the incremental training process, thereby realizing a closed-loop interaction between the training unit 42 and the classification unit 42.

[0166] Regarding the apparatus in the above embodiments, the specific manner in which each unit module performs its operations has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0167] Figure 5 This is a schematic diagram of an electronic device provided in this application. (For example...) Figure 5 The electronic device 50 may include at least one first processor 501 and a memory 503 for storing processor-executable instructions. The first processor 501 is configured to execute the instructions in the memory 503 to implement the text classification method in the following embodiments.

[0168] In addition, electronic device 50 may also include communication bus 502, at least one communication interface 504, input device 506 and output device 505.

[0169] The first processor 501 may be a processor (central processing unit, CPU), a microprocessor unit, an ASIC, or one or more integrated circuits for controlling the execution of programs according to the present application.

[0170] The communication bus 502 may include a path for transmitting information between the aforementioned components.

[0171] Communication interface 504 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.

[0172] Input device 506 is used to receive input signals and output device 505 is used to output signals.

[0173] Memory 503 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital versatile optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. Memory may exist independently and be connected to the processing unit via a bus. Memory may also be integrated with the processing unit.

[0174] The memory 503 stores instructions for executing the scheme of this application, and the execution is controlled by the first processor 501. The first processor 501 executes the instructions stored in the memory 503 to realize the functions of the method of this application.

[0175] In a specific implementation, as one example, the first processor 501 may include one or more CPUs, for example... Figure 5 CPU0 and CPU1 in the CPU.

[0176] In a specific implementation, as one example, the electronic device 50 may include multiple processors, such as... Figure 5 The first processor 501 and the second processor 507 are described. Each of these processors can be a single-core processor or a multi-core processor. A processor here can refer to one or more devices, circuits, and / or processing cores used to process data (such as computer program instructions).

[0177] The electronic device is as follows Figure 5 The diagram includes a first processor 501 and a memory 503 for storing executable instructions of the first processor 501; wherein the first processor 501 is configured to execute the executable instructions to implement the text classification method as described in any of the possible embodiments above. And it can achieve the same technical effect, so to avoid repetition, it will not be described again here.

[0178] This application also provides a computer-readable storage medium, which, when executed by a processor of a text classification device or electronic device, enables the text classification device or electronic device to perform the text classification method as described in any of the possible embodiments above. The same technical effect can be achieved, and to avoid repetition, it will not be repeated here.

[0179] This application also provides a computer program product, including a computer program or instructions, which are executed by a processor using a text classification method as described in any of the possible implementations above. This achieves the same technical effect, and to avoid repetition, it will not be repeated here.

[0180] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0181] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A text classification method, characterized in that, The method includes: In response to the training instruction of the text classification model to be trained, the text classification model to be trained is invoked to convert multiple unlabeled texts into multiple initial text vectors; Clustering multiple initial text vectors yields at least one cluster, wherein each cluster includes at least one initial text vector; Each initial text vector and preset semantic label constraint information included in each cluster are input into the large language model to obtain the first semantic category label of each cluster. Based on the first semantic category label of each cluster and the initial text vector included in each cluster, the text classification model to be trained is trained to obtain the pre-trained text classification model. The first semantic category label vector set of the preset text classification model includes the first semantic label vector of the first semantic category label of each cluster; The text to be tested is input into the preset text classification model to obtain the text classification matching result.

2. The method according to claim 1, characterized in that, The step of inputting the text to be tested into the preset text classification model to obtain the text classification matching result includes: The following operations are performed on the text to be tested using the preset text classification model: Convert the text to be tested into a text vector; The text vector to be tested is matched with each semantic category label vector in the first semantic category label vector set to find the target semantic category label vector with the highest semantic similarity to the text vector to be tested. If the target semantic similarity of the target semantic category label vector is determined to be higher than the similarity threshold, then the text classification matching result is determined based on the target semantic category label vector.

3. The method according to claim 2, characterized in that, The method further includes: If it is determined that the target semantic similarity of the target semantic category tag vector is lower than the similarity threshold, a first prompt message is generated and displayed; the first prompt message is used to indicate that the matching degree between the semantic category tag vector in the semantic category tag vector set and the text to be tested is low; the first prompt message includes the text vector to be tested; Based on the text vector to be tested in the first prompt information, generate target training text conditions; Based on the target training text conditions, multiple new training texts associated with the test text vector are selected; Initiate a training instruction for the preset text classification model; In response to the training instruction for the preset text classification model, multiple new text vectors of the multiple newly added training texts are generated based on the preset text classification model. Generate the new cluster to which each new text vector belongs and the second semantic category label corresponding to each new cluster; Based on the second semantic category labels of each newly added cluster and the newly added text vectors included in each newly added cluster, the preset text classification model is trained and adjusted to obtain the first target text classification model. The second semantic category label vector set of the first target text classification model includes the second semantic label vector of the second semantic category label.

4. The method according to claim 1, characterized in that, The text classification model to be trained is trained based on the first semantic category labels of each cluster and the initial text vectors included in each cluster, to obtain the trained preset text classification model, including: Each initial text vector included in the cluster and the first semantic label vector of the first semantic category label of the cluster are determined as positive sample pairs; The initial text vectors included in the cluster are used as negative sample pairs with the first semantic label vectors of the first semantic category labels of other clusters. Using a training sample set consisting of all positive and negative sample pairs, the text classification model to be trained is fine-tuned based on a contrastive learning loss function to obtain the preset text classification model. The contrastive learning loss function is used to maximize the first semantic similarity between the initial text vector and the first semantic label vector in the positive sample pair, and minimize the second semantic similarity between the initial text vector and other first semantic label vectors in the negative sample pair.

5. The method according to claim 1, characterized in that, The method further includes: In response to a fine classification request for the text classification model to be trained, a coarse-fine category mapping relationship is determined between each original category in the text classification model to be trained and multiple fine category labels reclassified from each original category. Convert the text of each subcategory label into a vector of text of each subcategory label. Based on each subcategory label and the multiple subcategory label text vectors included in each subcategory label, the text classification model to be trained is trained and adjusted to obtain the adjusted second target text classification model; The third semantic category label vector set of the second target text classification model includes the fine category label vectors of the fine category labels.

6. The method according to claim 5, characterized in that, The method includes: The second target text classification model is used to classify the input text, including: converting the input text into text embedding vectors; determining the third semantic similarity between the text embedding vectors and each sub-category label vector in the third semantic category label vector set, and determining the third semantic similarity of the multiple sub-label text vectors associated with each original category according to the coarse and fine category mapping relationship; determining the average similarity of the third semantic similarity of the multiple sub-label text vectors associated with each original category as the comprehensive semantic similarity of each original category; and determining the original category with the highest comprehensive semantic similarity as the classification result of the input text.

7. The method according to claim 1, characterized in that, The process involves inputting the initial text vectors and preset semantic label constraint information of each cluster into the large language model to obtain the first semantic category label for each cluster, including: The preset semantic label constraint information is embedded as a label generation constraint condition into a preset prompt word template to obtain the target prompt word corresponding to each cluster; The label generation constraint is used to constrain the semantic category labels generated by the large language model to satisfy the preset semantic label constraint information. The target prompt word for each cluster and the initial text vector for each cluster are input into the large language model to obtain the first semantic category label for each cluster.

8. A text classification apparatus for performing the method as described in any one of claims 1 to 7, characterized in that, The device includes: The training unit is configured to respond to a training instruction for a text classification model to be trained, and based on the text classification model to be trained, convert multiple unlabeled texts into multiple initial text vectors; cluster the multiple initial text vectors to obtain at least one cluster; each cluster includes at least one initial text vector; input each initial text vector included in each cluster and preset semantic label constraint information into a large language model to obtain a first semantic category label for each cluster; train the text classification model to be trained based on the first semantic category labels of each cluster and the initial text vectors included in each cluster to obtain a trained preset text classification model; the set of first semantic category label vectors of the preset text classification model includes the first semantic label vectors of the first semantic category labels of each cluster; The classification unit is configured to input the text to be tested into the preset text classification model to obtain the text classification matching result.

9. A computer-readable storage medium, characterized in that, The system contains a computer program that, when executed by a processor, implements the text classification method as described in any one of claims 1 to 7.

10. An electronic device, characterized in that, The computer-readable storage medium as described in claim 9 is configured to perform the text classification method as described in any one of claims 1-7.