Text classification method and device, electronic equipment and storage medium

By combining a large language model with a hierarchical knowledge graph, the candidate label set is obtained step by step and task instructions are generated, which solves the problem of unstable output of large language models in text hierarchical classification. It achieves high-precision and reliable text hierarchical classification, adapts to changes in the label system and supports cold start and long-tail category scenarios.

CN121579689APending Publication Date: 2026-02-27IFLYTEK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511801548.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-02
Publication Date
2026-02-27

AI Technical Summary

Technical Problem

In existing technologies, large language models produce unstable and unreliable outputs in text hierarchical classification, potentially generating logically invalid paths, leading to unstable and unreliable classification results.

Method used

By combining the semantic understanding capabilities and hierarchical structure knowledge of large-scale language models, a hierarchical knowledge graph is used to obtain a set of candidate labels level by level. Task instructions are constructed and label generation prompts are generated to guide the model to perform semantic matching and selection in a limited set of candidate labels, ensuring that each level of classification conforms to the hierarchical structure relationship.

Benefits of technology

It achieves stability, reliability, and flexibility in text hierarchical classification, can dynamically adapt to changes in the label system, and improves the logical correctness and consistency of classification results, especially in text classification support in cold start and long-tail category scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121579689A_ABST
    Figure CN121579689A_ABST
Patent Text Reader

Abstract

The invention provides a text classification method and device, electronic equipment and a storage medium, and the method comprises the steps: obtaining a candidate label set corresponding to a current classification hierarchy in a hierarchy knowledge graph corresponding to the current classification hierarchy according to a hierarchy label of a to-be-classified text at a previous classification hierarchy; generating a task instruction corresponding to the current classification hierarchy according to the candidate label set; according to the task instruction and the to-be-classified text, obtaining a tag generation prompt word corresponding to the current classification level; and inputting the tag generation cue word into a large language model to obtain a hierarchical tag of the to-be-classified text at the current classification hierarchy. According to the method, the powerful semantic understanding ability of the large language model and the hierarchical knowledge constraint of the hierarchical knowledge graph are utilized to eliminate the situation that the output of the large language model does not exist or is disordered, it is ensured that each hierarchical classification conforms to the hierarchical structure relation, and the logic correctness and consistency of the output classification paths are ensured.
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 in particular to a text classification method, apparatus, electronic device, and storage medium. Background Technology

[0002] In numerous digital application scenarios, such as e-commerce product category management, news content organization, intelligent routing of enterprise work orders, and document archiving, it is necessary to allocate unstructured text into a predefined, hierarchical tagging system. Therefore, developing a high-precision, highly automated hierarchical classification technology is a crucial issue that the industry urgently needs to address.

[0003] In existing technologies, large language models are directly instructed to generate corresponding hierarchical classification path strings based on the input text in a single inference. However, this approach can lead to the large language model outputting a path that does not exist in the predefined label system or concatenating a logically invalid path, resulting in unstable and unreliable classification results. Summary of the Invention

[0004] This invention provides a text classification method, apparatus, electronic device, and storage medium to address the shortcomings of unstable and unreliable classification results in the prior art.

[0005] This invention provides a text classification method, comprising: Based on the hierarchical label of the text to be classified in the previous classification level, obtain the candidate label set corresponding to the current classification level in the hierarchical knowledge graph corresponding to the current classification level; Based on the candidate label set, generate the task instruction corresponding to the current classification level; Based on the task instructions and the text to be classified, obtain the tag generation prompt words corresponding to the current classification level; The generated prompt words are input into a large language model to obtain the hierarchical label of the text to be classified at the current classification level.

[0006] According to a text classification method provided by the present invention, the step of inputting the tag-generated prompt words into a large language model to obtain the hierarchical tag of the text to be classified at the current classification level includes: Based on the large language model, the task instructions are applied to predict the labels of the text to be classified, and a set of word prediction probabilities is obtained. Based on the logic processor, the predicted probability value of the first word in the word prediction probability set is modified to the target value to obtain an updated word prediction probability set; the first word does not match any word corresponding to any candidate level label in the candidate label set, and does not match any word corresponding to any preset level label. Based on the large language model, a second word is determined in the updated word prediction probability set, and the hierarchical label of the text to be classified in the current classification level is obtained according to the hierarchical label corresponding to the second word; the second word is the word with the largest predicted probability value in the updated word prediction probability set.

[0007] According to a text classification method provided by the present invention, obtaining the level label of the text to be classified at the current classification level based on the level label corresponding to the second word element includes: If the hierarchical label corresponding to the second word element is not in the candidate label set, then determine whether the hierarchical label corresponding to the second word element is the preset hierarchical label; If the hierarchical label corresponding to the second word element is the preset hierarchical label, then the label update prompt word is input into the large language model to obtain the hierarchical label of the text to be classified in the current classification level; The label update prompt is used to guide the large language model to generate new hierarchical labels for the text to be classified, and to determine the new hierarchical labels as the hierarchical labels of the text to be classified in the current classification level.

[0008] According to a text classification method provided by the present invention, the method further includes: If the level label of the text to be classified in the current classification level is the new level label, then the level label of the text to be classified in the current classification level and the text to be classified are stored in the target database. When an update to the target database is detected, if the update result indicates that the review status of the hierarchical tag of the text to be classified in the current classification level is approved, then the hierarchical tag of the text to be classified in the current classification level is added as a new node and updated to the hierarchical knowledge graph corresponding to the current classification level to obtain the hierarchical knowledge graph corresponding to the next classification level.

[0009] According to a text classification method provided by the present invention, the step of obtaining a set of candidate tags corresponding to the current classification level in the hierarchical knowledge graph corresponding to the current classification level based on the hierarchical tags of the text to be classified in the previous classification level includes: In the hierarchical knowledge graph corresponding to the current classification level, obtain the index information of the first node corresponding to the hierarchical label of the text to be classified in the previous classification level; Based on the index information, obtain the child nodes of the first node; The candidate label set is constructed based on the hierarchical labels corresponding to each child node.

[0010] According to a text classification method provided by the present invention, the step of obtaining the tag generation prompt word corresponding to the current classification level based on the task instruction and the text to be classified includes: Obtain the task description information corresponding to the text to be classified, as well as the text classification instance; The task instruction, the text information of the text to be classified, the task description information, and the text classification instance are updated to the prompt word template to obtain the tag generation prompt word.

[0011] According to a text classification method provided by the present invention, the method further includes: In the hierarchical knowledge graph corresponding to the current classification level, obtain the node type of the second node corresponding to the hierarchical label of the text to be classified in the current classification level; If the node type is a leaf node, then the hierarchical labels of the text to be classified at each classification level are summarized to obtain the multi-level classification labels of the text to be classified.

[0012] The present invention also provides a text classification device, comprising: The first acquisition unit is used to acquire the candidate tag set corresponding to the current classification level in the hierarchical knowledge graph corresponding to the current classification level based on the hierarchical tag of the text to be classified in the previous classification level. The generation unit is used to generate task instructions corresponding to the current classification level based on the candidate label set; The second acquisition unit is used to acquire the tag generation prompt words corresponding to the current classification level according to the task instruction and the text to be classified; The tag generation unit is used to input the tag generation prompts into a large language model to obtain the hierarchical tags of the text to be classified at the current classification level.

[0013] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement any of the text classification methods described above.

[0014] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the text classification method as described above.

[0015] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements any of the text classification methods described above.

[0016] The text classification method, apparatus, electronic device, and storage medium provided by this invention dynamically acquire candidate label sets level by level in a hierarchical knowledge graph based on the hierarchical labels of the previous classification level, thereby dynamically constructing task instructions corresponding to the current classification level. This constrains the classification process of the text to be classified within a predefined hierarchical structure framework. Furthermore, it generates label generation prompts using task instructions and the text to be classified, thereby guiding a large language model to perform semantic matching and selection within a limited set of candidate labels to predict hierarchical labels level by level. This fully utilizes the powerful semantic understanding capabilities of the large language model and the hierarchical knowledge constraints of the hierarchical knowledge graph to eliminate non-existent or distorted output paths from the large language model, ensuring that each classification level conforms to the hierarchical structure relationship. This guarantees the logical correctness and consistency of the output classification path, effectively supporting text classification in cold-start and long-tail category scenarios, and significantly improving the stability, reliability, and flexibility of hierarchical text classification. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0018] Figure 1 This is one of the flowcharts illustrating the text classification method provided by this invention.

[0019] Figure 2 This is the second flowchart of the text classification method provided by the present invention.

[0020] Figure 3 This is the third flowchart of the text classification method provided by the present invention.

[0021] Figure 4 This is the fourth flowchart of the text classification method provided by the present invention.

[0022] Figure 5 This is a schematic diagram of the structure of the text classification device provided by the present invention.

[0023] Figure 6 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation

[0024] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0025] In numerous digital application scenarios, such as e-commerce product category management, news content organization, intelligent routing of enterprise work orders, and document archiving, it is necessary to allocate unstructured text into a predefined, hierarchical tagging system. For example, the text for a product, "Apple iPhone 15 Pro Max," needs to be accurately categorized according to the hierarchical relationship into the path "Electronics > Mobile Communications > Smartphones." The accuracy and efficiency of this classification task directly affect user experience, retrieval efficiency, and the level of automation in business processes. Therefore, with the explosive growth of data volume and the increasing complexity of tagging systems, developing a high-precision, highly automated, and rapidly adaptable hierarchical classification technology is crucial.

[0026] Currently, the mainstream technical solutions for solving the hierarchical label classification problem include: The flat classification scheme ignores the hierarchical relationship between labels, flattens the hierarchical structure, and treats each complete path from the root node to the leaf node or each leaf node itself as an independent and mutually exclusive category. Then, a standard multi-class classification model is used for training and prediction.

[0027] The local classifier scheme trains one or more independent classifiers for each layer in the hierarchical structure. The classification process is top-down: first, the root node's classifier selects one from all first-level subcategories; then, the selected child node's classifier selects from its next-level subcategories, and so on recursively until a leaf node is reached.

[0028] The global classifier scheme designs a single, end-to-end complex model to predict the entire hierarchical path at once, aiming to output a complete classification result from root to leaf in a single inference. The model's performance is highly dependent on supervised data.

[0029] However, the above solution has the following significant drawbacks in practical applications: Flat classification schemes lose structural information between labels, causing the model to be unable to utilize the logical relationships between parent-child and sibling nodes. When the number of categories is huge, the classification performance will drop sharply and it will be difficult to scale. Local classifier schemes have serious error propagation problems. That is, once the top-level classifier makes a mistake, the error will be irreversibly propagated to the classification of all subsequent levels, resulting in an incorrect final result and greatly limiting the upper limit of the overall classification accuracy. Global classifier schemes have complex model design and high training costs. In scenarios with deep layers, many branches, and sparse samples of some bottom-level labels, the model has difficulty learning fully and its generalization ability is limited.

[0030] In recent years, with the continuous iteration of large-scale language models, their ability to understand textual knowledge has been continuously improved, fully meeting the needs of many vertical applications. Furthermore, they possess unique advantages over supervised fine-tuning of smaller models in addressing long-tail problems. In response, some technologies leverage the powerful zero-shot or few-shot capabilities of large-scale language models, directly instructing them to generate the corresponding hierarchical classification path string from the input text in a single inference.

[0031] In the process of hierarchical classification path reasoning, since the generation of large language models is probabilistic and lacks hierarchical consistency guarantee, it may output a path that does not exist in the predefined label system at all. For example, it may classify "mobile phone" as a sub-label of "clothing", or it may concatenate a logically invalid path, which leads to unstable and unreliable classification results.

[0032] In response, this application provides a text classification method that effectively combines the powerful semantic understanding capabilities of a large language model with rigid hierarchical structure knowledge to overcome problems such as error propagation, inconsistent output, and loss of structural information in existing schemes. This method ensures both the logical correctness of the output classification results and the full utilization of the model's reasoning capabilities, while also dynamically adapting to changes in the label system. This effectively guarantees the high accuracy and robustness of hierarchical classification.

[0033] It should be noted that the subject executing the method provided in this application can be an electronic device, a component in an electronic device, an integrated circuit, or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. For example, a mobile electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, wearable device, super mobile personal computer, netbook, or personal digital assistant, etc., while a non-mobile electronic device can be a server, network attached storage, personal computer, or self-service machine, etc. This invention does not impose specific limitations.

[0034] Furthermore, the method provided in this application can be applied to various text classification scenarios, including but not limited to e-commerce, medical, and document archiving text classification scenarios involving multi-level tags.

[0035] Figure 1 This is one of the flowcharts illustrating the text classification method provided by this invention, such as... Figure 1 As shown, the method includes steps 110, 120, 130 and 140.

[0036] Step 110: Based on the hierarchical label of the text to be classified in the previous classification level, obtain the candidate label set corresponding to the current classification level in the hierarchical knowledge graph corresponding to the current classification level.

[0037] The text to be classified here refers to natural language text content that requires hierarchical classification. Specific forms of the text to be classified include, but are not limited to, product titles and descriptions in e-commerce scenarios, article titles and summaries in news and information scenarios, electronic medical record chief complaint texts in medical scenarios, and case descriptions in legal documents. For example, the text to be classified could be "Product Title: Apple iPhone 15 Pro Max 256GB Space Black 5G Full Netcom Titanium Metal Body". The text to be classified can be obtained through various methods such as direct user input, file import, speech transcription, and optical character recognition; this embodiment does not impose specific limitations on these methods. The length of the text to be classified can vary, ranging from short phrases to paragraphs containing multiple sentences. Its carrier format includes, but is not limited to, strings, text files, and text fields in structured data.

[0038] The hierarchical label of the previous level refers to the classification result of the previous level that has been determined during hierarchical classification. For example, in a three-level classification system, when currently in the second-level classification stage, the hierarchical label of the previous level is the determined first-level category. In particular, when the current classification level is the first level of the entire classification system, that is, in the initial classification, the hierarchical label of the previous level can be an empty identifier or a root node identifier. At this time, the candidate label set corresponding to the current classification level is the complete set of first-level categories in the pre-constructed hierarchical knowledge graph.

[0039] The current classification level refers to the hierarchical position where a classification decision is currently being executed during the hierarchical classification process; the hierarchical knowledge graph is a data structure used to represent predefined hierarchical labels and their parent-child relationships. The construction methods of this hierarchical knowledge graph include, but are not limited to, constructing all predefined hierarchical labels as a prefix tree (hereinafter also referred to as a Trie) structure, where each node corresponds to a hierarchical label, and its node attributes store a unique identifier for the hierarchical label, the label name text, an index pointing to the parent node, and index information pointing to all direct child nodes; or, constructing all predefined hierarchical labels as a Directed Acyclic Graph (DAG) structure to support multiple inheritance relationships of labels.

[0040] This hierarchical knowledge graph is pre-stored in the memory of the executing entity so that it can be quickly queried in milliseconds during subsequent text classification to obtain the list of valid child nodes for any node.

[0041] Optionally, in order to fundamentally avoid generating invalid or logically flawed classification paths, when classifying text at each classification level, the hierarchical knowledge graph corresponding to that classification level can be used to transform traditional flat classification or freely generated classification into hierarchical classification based on hierarchical knowledge constraints, providing a structured candidate space for subsequent text classification, thereby ensuring the stability and reliability of the classification results.

[0042] Specifically, for the current classification level, the hierarchical knowledge graph corresponding to the current classification level is first obtained. This hierarchical knowledge graph can be constructed through a static predefined method, or it can be updated and expanded through a dynamic configuration interface. For example, after the hierarchical tags of the previous classification level are completed, the hierarchical knowledge graph corresponding to the previous classification level is updated based on the hierarchical tags of the previous classification level; or it can be dynamically updated by the user, etc. This embodiment does not specifically limit this approach.

[0043] Then, the nodes corresponding to the hierarchical labels of the previous level in the hierarchical knowledge graph of the current category level are analyzed, all direct child nodes of the node are queried, and the set of label name texts of all direct child nodes of the node is used as the candidate label set corresponding to the current category level.

[0044] For example, when the hierarchical label of the previous level is "electronic products", the "electronic products" node is located in the hierarchical knowledge graph, and the list of names of its direct child nodes is obtained as ['mobile communication', 'computer office', 'photography and videography', ...]. This list constitutes the candidate label set for the current level. This candidate label set limits the range of labels that can be selected under the current classification level, ensuring that the classification path always proceeds within the predefined hierarchical structure framework.

[0045] The query for all direct child nodes of a given node can be obtained by querying the connection edges between nodes in the hierarchical knowledge graph, or by querying the index information maintained by that node.

[0046] Step 120: Generate the task instruction corresponding to the current classification level based on the candidate label set.

[0047] Optionally, after obtaining the candidate label set corresponding to the current classification level, the instructions can be dynamically updated based on the candidate label set corresponding to the current classification level. This converts the structured candidate label set into task instructions that clearly define the classification task requirements of the current classification level and the selection range of the corresponding classification labels. This transforms the hierarchical knowledge constraints of the hierarchical knowledge graph into semantic constraints that the model can understand, providing a standardized task description component for subsequent prompt word generation.

[0048] The methods for generating task instructions here include, but are not limited to, filling the candidate tag set into a specified position in the template based on a predefined instruction template to form a structured natural language instruction; or, converting the candidate tag set into a command statement in a specific format based on a rule engine.

[0049] The task instruction should include at least a descriptive text for the current category task and an explicit enumeration of the candidate tag set. For example, if the candidate tag set corresponding to the current category level is ['Mobile Communication', 'Computer Office', 'Photography and Videography', ...], the corresponding generated task instruction could be "Please select the category that best matches the product description from the following candidate categories of 'Electronic Products': ['Mobile Communication', 'Computer Office', 'Photography and Videography', ...]".

[0050] Step 130: Based on the task instruction and the text to be classified, obtain the tag generation prompt words corresponding to the current classification level.

[0051] The label generation prompts here refer to the complete prompt text input into the large language model, which is used to guide the large language model to output the classification label for the current level.

[0052] Optionally, after obtaining the task instructions corresponding to the current classification level, the label generation prompt words corresponding to the current classification level can be generated based on the combination of the task instructions and the text to be classified. In this way, by organically combining the task instructions and the text to be classified, a complete input for a large language model is formed, thereby ensuring that the large language model can simultaneously obtain the classification target text and selection range constraint information, providing sufficient contextual basis and next step instructions for the model output, and guiding it to make more correct step-by-step decisions.

[0053] The tag generation prompts here include at least the task instructions and the text information of the text to be classified. Furthermore, to ensure that large language models can accurately understand the task requirements, the tag generation prompts may optionally include task description information for a clearer task definition, and may also include auxiliary information such as one or more text classification instances to help large language models better understand the output format and hierarchical logic. It should be noted that this auxiliary information can be flexibly configured according to actual application needs, and this embodiment does not impose specific limitations on it.

[0054] Step 140: Input the tag generation prompt words into a large language model to obtain the hierarchical tag of the text to be classified at the current classification level.

[0055] Optionally, after obtaining the tag generation prompts, these prompts can be input into a large-scale language model for text classification. The large-scale language model then analyzes the text to be classified based on the prompts, obtaining the hierarchical label for the text at the current classification level. In this process, by inputting the tag generation prompts into the large-scale language model, the powerful zero-shot or few-shot semantic understanding capabilities of the model are fully utilized. This allows for guided decision-making on the hierarchical labels of the text to be classified through the hierarchical knowledge constraints of the knowledge graph, without requiring fine-tuning for a specific tag system. This significantly reduces the dependence on labeled training data during classification and effectively improves the stability and reliability of the classification results.

[0056] The Large Language Model (LLM) mentioned here, also known as a large model or large language model, refers to a natural language processing model with a large number of parameters and which uses a large-scale corpus for self-supervised learning during pre-training, such as the Spark Cognitive Large Model.

[0057] It should be noted that after performing the hierarchical label prediction for the current category level, the hierarchical labels of the current category level can be used as input for the next category level to obtain a new set of candidate labels. Based on this new set of candidate labels, the task instructions corresponding to the current category level are updated, thereby updating the task instructions for the current category level and obtaining the label generation prompt for the next category level. For example, the label generation prompt for the next category level can be updated to "...Current path: 'Electronic Products'. Please select the most suitable one from the following subcategories of 'Electronic Products': ['Mobile Communication', 'Computer Office', 'Photography and Videography', ...]”; and based on the tags corresponding to the next classification level, prompt words are generated to guide the large language model to perform text classification at the next classification level for the text to be classified. This process is repeated iteratively until the iteration termination condition is met. If the iteration termination condition is met, the level tags of all the obtained classification levels are combined to form a complete hierarchical classification path. In this way, the hierarchical classification is deepened layer by layer through the iteration mechanism, so that the classification at each level is based on the deterministic result of the previous level and the structured candidate tag set of the current level, making the classification process have a clear logical chain. The iteration termination condition here may include the level tag of the current level being a leaf node in the hierarchical knowledge graph, that is, the node has no direct child nodes, or the set of child nodes of the node is empty.

[0058] It should be noted that, in the text classification process, the method provided in this embodiment effectively combines the powerful semantic understanding capabilities of large language models with rigid hierarchical structure knowledge. This transforms the hierarchical classification task from a one-time, uncontrolled generation into a multi-step, guided decision-making process strictly constrained by hierarchical knowledge. This not only overcomes the problems of error propagation, inconsistent output, and loss of structural information in existing solutions, but also achieves a high-precision, highly robust hierarchical classification technology that ensures the logical correctness of the output results, fully utilizes the model's reasoning capabilities for unsupervised text classification, and can dynamically adapt to changes in the label system. Furthermore, it has significant advantages over traditional methods in zero-shot generalization and recall improvement for long-tail categories. Specifically, for cold starts, LLM has already learned rich world knowledge and language patterns during the pre-training stage. Even without having seen training samples for a certain label, it can make reasonable classifications in the candidate label set based on the semantic matching between the label name and the input text. In the cold start scenario (i.e., no training samples after a new category is added), by directly adding the new label to the candidate set corresponding to the knowledge graph, the model can immediately predict it without additional training. For long-tail categories, by leveraging the semantic similarity between the label name and the text description, combined with the hierarchical candidate set constraint, the range of candidate classifications is significantly narrowed, thereby reducing the impact of the sample sparsity problem of long-tail categories on the selection of large language models. As long as the label name has some semantic information, LLM can make accurate selection by judging the semantic similarity with the input text, thus improving the accuracy and recall of LLM on long-tail labels.

[0059] The method provided in this embodiment dynamically acquires a candidate label set level by level in a hierarchical knowledge graph based on the hierarchical labels of the previous classification level, thereby dynamically constructing the task instructions corresponding to the current classification level. This constrains the classification process of the text to be classified within a predefined hierarchical structure framework. Furthermore, it generates label generation prompts using the task instructions and the text to be classified, thereby guiding a large language model to perform semantic matching and selection within a limited set of candidate labels to predict hierarchical labels level by level. This fully utilizes the powerful semantic understanding capabilities of the large language model and the hierarchical knowledge constraints of the hierarchical knowledge graph to eliminate non-existent or incorrect output paths from the large language model, ensuring that each classification level conforms to the hierarchical structure relationship. This guarantees the logical correctness and consistency of the output classification path, effectively supporting text classification in cold start and long-tail category scenarios, and significantly improving the stability, reliability, and flexibility of hierarchical text classification.

[0060] Figure 2 This is the second flowchart illustrating the text classification method provided by this invention. For example... Figure 2 As shown, in some embodiments, step 140 specifically includes: Step 141: Based on the large language model, apply the task instructions to predict the labels of the text to be classified, and obtain a set of word prediction probabilities. Step 142: Based on the logic processor, modify the predicted probability value of the first word in the word prediction probability set to the target value to obtain an updated word prediction probability set; the first word does not match any word corresponding to any candidate level label in the candidate label set, and does not match any word corresponding to any preset level label. Step 143: Based on the large language model, determine the second word element in the updated word element prediction probability set, and obtain the level label of the text to be classified in the current classification level according to the level label corresponding to the second word element; the second word element is the word element with the largest predicted probability value in the updated word element prediction probability set.

[0061] Optionally, in order to further reduce the randomness of the decoding results of large language models, decoding constraints can be introduced during the classification process of large language models. The output space of large language models is strictly limited to a given set of logically correct candidate labels, which achieves a stronger hard constraint than pure semantic guidance. This fundamentally eliminates the possibility of large language models generating illegal labels, so as to make the output results more consistent.

[0062] Specifically, the complete tag generation prompt words constructed for the current classification level can be input into a large language model. The large language model can then apply task instructions to predict the tags of the text to be classified, obtain the probability that the next word element (also called token) corresponding to the text to be classified belongs to each word element in the vocabulary, and obtain the word element prediction probability set.

[0063] Before the large language model outputs the hierarchical label for the current classification level, a logic processor, such as a Logits processor, is applied to obtain the candidate label set corresponding to the current classification level from the hierarchical knowledge graph. The probability values ​​of words that match the candidate hierarchical labels in the candidate label set are retained, as are the words that match the preset hierarchical labels. The probability values ​​of other words are modified to target values, which are extremely small probability values ​​or negative infinity scores. The purpose of this is to forcibly block the output possibility of the first word, forcing the large language model to select only from the given, logically correct hierarchical label set.

[0064] The target value here can be set in ways including but not limited to: setting it to a fixed constant, such as -10^9 or negative infinity. The preset hierarchical label here refers to a predefined special marker that is different from all candidate hierarchical labels in the candidate label set, such as a label named "Other," "Unknown," or "New Label." This is used to trigger specific processing logic, such as serving as a rejection exit point. For example, when a large language model is classifying text, if it deems all candidate hierarchical labels covered by the current classification hierarchical label set unsuitable, it can actively output this marker to indicate that the current knowledge graph has coverage gaps, triggering a pause in the guided classification process and switching to a new classification process to create a more suitable new hierarchical label.

[0065] When the large language model outputs the hierarchical label for the current classification level, it can specifically understand the text to be classified and select the word with the highest predicted probability value from the set of predicted probabilities of words that have been subject to forced constraints as the second word. Based on the hierarchical label corresponding to the second word, the hierarchical label of the text to be classified in the current classification level is determined. Specifically, if the hierarchical label corresponding to the second word is in the candidate label set, then the range of hierarchical labels covered by the candidate label set corresponding to the current classification level is considered appropriate, and the hierarchical label corresponding to the second word can be directly used as the hierarchical label of the text to be classified in the current classification level. If the hierarchical label corresponding to the second word is not in the candidate label set, but is a preset hierarchical label, then the range of hierarchical labels covered by the candidate label set corresponding to the current classification level is considered inappropriate. In this case, the guided classification process can be paused, and a new classification process can be switched to create a more suitable new hierarchical label as the hierarchical label of the current classification level.

[0066] The text classification method provided in this invention introduces a logic processor to dynamically modify the word prediction probability set output by a large language model. This hard-constrains the model's output space from the complete vocabulary to the candidate label set and the preset label set at the current level, achieving probabilistic hard control over the model generation process. This effectively overcomes the technical defects of large language models in hierarchical classification tasks, such as illegal outputs and deviations from the predefined label system. It significantly improves the structural consistency, logical correctness, and output reliability of the classification results. At the same time, this constraint mechanism takes effect in real time during the model inference stage, without requiring retraining or fine-tuning of the model, thus maintaining the flexibility and cold-start capability of the classification.

[0067] In some embodiments, step 143 specifically includes: If the hierarchical label corresponding to the second word element is not in the candidate label set, then determine whether the hierarchical label corresponding to the second word element is the preset hierarchical label; If the hierarchical label corresponding to the second word element is the preset hierarchical label, then the label update prompt word is input into the large language model to obtain the hierarchical label of the text to be classified in the current classification level; The label update prompt is used to guide the large language model to generate new hierarchical labels for the text to be classified, and to determine the new hierarchical labels as the hierarchical labels of the text to be classified in the current classification level. The new hierarchical labels are different from the candidate hierarchical labels in the candidate label set and the preset hierarchical labels.

[0068] Optionally, when existing technologies need to handle a new concept that cannot be covered by the existing labeling system, LLM will either force it into an old category that does not match well or generate a new category. However, this process is unsupervised and uncontrollable, which leads to problems such as large language models being unable to actively discover new labels and being unable to adapt to dynamically changing knowledge systems in hierarchical text classification tasks. In this regard, this embodiment proposes a text classification technology with new label discovery and self-evolution capabilities during the label generation process. This enables large language models to actively identify labels not covered by the hierarchical knowledge graph and generate appropriate new labels based on contextual semantics, thereby realizing the dynamic expansion and self-evolution of the knowledge system.

[0069] Specifically, in step 142, the logic processor has masked illegal words in the word prediction probability set, and the decoding layer selects the second word with the highest predicted probability value from the updated probability set. According to the aforementioned hard constraint mechanism, the hierarchical label corresponding to the second word must belong to a candidate hierarchical label in the candidate label set, or a preset hierarchical label. Therefore, when executing step 143, the hierarchical label corresponding to the second word can be compared one by one with all candidate hierarchical labels in the candidate label set; if no match is found, the hierarchical label corresponding to the second word is further compared with the preset hierarchical label. If the comparison is successful, the hierarchical label corresponding to the second word is determined to be the preset hierarchical label; if the comparison fails, it indicates an anomaly in the classification process, which can trigger an error handling mechanism or a backtracking mechanism.

[0070] If the comparison is successful, the system switches from controlled decoding mode to free new label generation mode. In this mode, a label update prompt word is obtained and sent to the large language model to guide it in generating a more suitable new hierarchical label for the text to be classified based on the context. During this process, the decoding output of the large language model is no longer constrained by the candidate label set, but generates hierarchical labels corresponding to new morphemes based on the contextual semantic relationships in the complete vocabulary, thereby generating a more suitable new hierarchical label for the text to be classified.

[0071] The label update prompts here refer to the prompt text used to guide large language models into free generation mode, generating new hierarchical labels for the text to be classified based on contextual information. The generation process of these label update prompts may include extracting the core semantic information of the text to be classified, the contextual information of the current classification path, and the triggering reasons for the preset hierarchical labels, and integrating the above information into the new label generation template.

[0072] After generating new hierarchical tags for the text to be classified, the generated new hierarchical tags can be directly designated as the hierarchical tags of the text to be classified in the current classification level. Alternatively, the generated new hierarchical tags can be manually or automatically verified. Only after passing the verification can the generated new hierarchical tags be designated as the hierarchical tags of the text to be classified in the current classification level, thereby improving the accuracy of the classification. For automatic verification, this could involve semantic matching verification between the new hierarchical tags and the text to be classified to ensure that the new hierarchical tags are relevant to the text content of the text to be classified, or logical verification between the new hierarchical tags and the current classification path to check whether the new hierarchical tags belong to a sub-path of the current classification path, to ensure the rationality of the new tags in the hierarchical structure. This embodiment does not specifically limit this approach.

[0073] The method provided in this embodiment introduces a preset hierarchical label as a rejection exit and triggers a new label generation mechanism when the model outputs the label. It has the ability to identify knowledge blind spots, freely generate new labels, and evolve autonomously. It effectively solves the technical problems of traditional classification systems being rigid in handling uncovered concepts and unable to adapt to rapid business development. It achieves efficient, robust, and self-evolving text classification, significantly improving the flexibility, scalability, and intelligence of classification.

[0074] In some embodiments, after step 130 is performed, the method further includes: If the level label of the text to be classified in the current classification level is the new level label, then the level label of the text to be classified in the current classification level and the text to be classified are stored in the target database. When an update to the target database is detected, if the update result indicates that the review status of the hierarchical tag of the text to be classified in the current classification level is approved, then the hierarchical tag of the text to be classified in the current classification level is added as a new node and updated to the hierarchical knowledge graph corresponding to the current classification level to obtain the hierarchical knowledge graph corresponding to the next classification level.

[0075] Optionally, in view of the problem that hierarchical knowledge graphs in the prior art are static and rigid and cannot evolve autonomously to adapt to new concepts, this embodiment provides a text classification method that supports human-computer collaborative review and dynamic expansion of knowledge graphs. By storing new hierarchical tags generated by a large language model into the target database and introducing a manual review mechanism, it realizes the closed-loop update, dynamic expansion and self-evolution capabilities of the knowledge graph.

[0076] Specifically, if it is determined that the hierarchical labels of the current classification level output by the large language model are entirely new hierarchical labels generated autonomously by the large language model, that is, different from the candidate hierarchical labels in the candidate label set and the preset hierarchical labels, then the hierarchical labels of the current classification level and the text to be classified are stored in the target database. This serves as a basis for domain experts or operations personnel to retrospectively review the generation of the labels, facilitating their periodic review of the rationality of the current classification level. The review results are then updated to the target database in real time. The target database here refers to a storage system used to temporarily store new hierarchical labels to be reviewed and their associated information. Specifically, the target database may contain new hierarchical labels, the original text of the text to be classified corresponding to the new hierarchical labels, the current classification path (i.e., the sequence of upper-level hierarchical labels), generation timestamps, review status, review results, etc. The review results here include, but are not limited to, approval, rejection, or label modification; this embodiment does not specifically limit these.

[0077] When an update to the target database is detected, if the update result indicates that the review status of the current category level's hierarchical tag is approved, then the current category level's hierarchical tag is added as a new node to the hierarchical knowledge graph corresponding to the current category level. Specifically, in the hierarchical knowledge graph, the parent node corresponding to the generation of the new hierarchical tag (i.e., the node corresponding to the hierarchical tag of the previous category level) is located; a new child node is created under this parent node, and an edge relationship is established between the parent node and the new child node, thus obtaining the hierarchical knowledge graph corresponding to the next category level. This completes the dynamic update and expansion of the knowledge base. Through this closed-loop process, not only can existing tags be processed, but the knowledge base can also learn and evolve on its own, dynamically expanding its knowledge boundaries and perfectly adapting to business development.

[0078] The method provided in this embodiment constructs a closed-loop knowledge management system that combines intelligence and reliability by temporarily storing new tags generated by a large language model in the target database and introducing a manual review mechanism. It realizes the dynamic expansion and self-evolution of hierarchical knowledge graphs, effectively solving the technical defects of static and rigid knowledge graphs in the prior art, which cannot adapt to the emergence of new concepts. It achieves efficient, robust and self-evolving text classification, significantly improving the scalability, flexibility and long-term adaptability of classification, and effectively ensuring the quality of tags.

[0079] In some embodiments, step 110 specifically includes: In the hierarchical knowledge graph corresponding to the current classification level, obtain the index information of the first node corresponding to the hierarchical label of the text to be classified in the previous classification level; Based on the index information, obtain the child nodes of the first node; The candidate label set is constructed based on the hierarchical labels corresponding to each child node.

[0080] Optionally, during the construction of the candidate label set, the node corresponding to the hierarchical label of the previous category level can be located in the hierarchical knowledge graph corresponding to the current category level as the first node, and the index information that can guide all its child nodes can be loaded from the attribute information of the first node. Based on the index information, all direct child nodes of the first node are obtained in the hierarchical knowledge graph corresponding to the current category level, that is, the next-level nodes directly connected to the first node through parent-child relationship edges, thus obtaining each child node corresponding to the first node. Then, the hierarchical labels corresponding to all child nodes of the first node are summarized to obtain the candidate label set.

[0081] The method provided in this embodiment introduces index information for hierarchical tag querying and candidate tag set construction, which can reduce the candidate tag set construction time from milliseconds to microseconds, greatly optimizing user experience and throughput.

[0082] In some embodiments, step 130 specifically includes: Obtain the task description information corresponding to the text to be classified, as well as the text classification instance; The task instruction, the text information of the text to be classified, the task description information, and the text classification instance are updated to the prompt word template to obtain the tag generation prompt word.

[0083] Optionally, in view of the problems in the prior art such as simple construction of label generation prompt words, single information elements, insufficient understanding of classification tasks by large language models, and unstable output quality, this embodiment provides a multi-element fusion label generation prompt word construction method, which improves the understanding depth and output accuracy of large language models for classification tasks by enriching the semantic connotation and contextual information of the prompt words.

[0084] Specifically, when constructing tag generation prompts, in addition to obtaining the task instructions and text information of the text to be classified corresponding to the current classification level, it is also possible to obtain the task description information corresponding to the text to be classified, as well as the text classification instance.

[0085] The task description information here refers to the overall description of the classification task for the text to be classified. It is used to clarify the overall classification goal to the large language model. For example, the task description information could be: "You are a professional product classification expert. Your task is to assign the given product titles and descriptions to the most appropriate category levels. Please classify step by step." The form of this task description information can be natural language paragraphs, bulleted lists, key-value pair descriptions, etc., and this embodiment does not specifically limit it. A text classification instance refers to a representative example that has been classified, used to help the large language model quickly understand the task pattern and output specifications through a context learning mechanism. The content of a text classification instance includes at least: example text, such as text of the same type as the text to be classified, and example classification path, that is, the complete hierarchical label sequence corresponding to the example text.

[0086] After obtaining the task instructions corresponding to the current classification level, the text information of the text to be classified, the task description information, and the text classification instances, the task instructions corresponding to the current classification level, the text information of the text to be classified, the task description information, and the text classification instances can be filled into the prompt word template according to their respective placeholders in the prompt word template to obtain the tag generation prompt words. That is, the tag generation prompt words need to include not only the text information of the text to be classified and the task instructions corresponding to the current classification level, but also the task description information and text classification instances as requirements for controlling the classification of large language models. In this way, when the large language model polishes the text to be classified, it can execute the text classification task according to the macro task background and quality standards provided by the task description information, the task execution paradigm provided by the text classification instances, and the hierarchical knowledge constraints provided by the task instructions corresponding to the current classification level. This significantly improves the depth of understanding and execution accuracy of the large language model for hierarchical classification tasks.

[0087] In some embodiments, after step 130 is performed, the method further includes: In the hierarchical knowledge graph corresponding to the current classification level, obtain the node type of the second node corresponding to the hierarchical label of the text to be classified in the current classification level; If the node type is a leaf node, then the hierarchical labels of the text to be classified at each classification level are summarized to obtain the multi-level classification labels of the text to be classified.

[0088] Optionally, after executing step 130, the pointer of the current node is moved to the newly selected child node, that is, the node corresponding to the level label of the current classification level (also called the second node), based on the level label of the current classification level. This is done to locate the position of the second node in the hierarchical knowledge graph and obtain its node type based on its position. The node type of the second node is then used to determine whether the classification termination condition has been met, that is, whether the node type of the second node is a leaf node (i.e., no child nodes). If the node type of the second node is a leaf node, the iterative classification process terminates, and the level labels of the text to be classified in each classification level are summarized to obtain the multi-level classification labels of the text to be classified, thereby obtaining the complete hierarchical path of the text to be classified.

[0089] If the second node is a non-leaf node, the iterative classification process continues, and steps 110 and 140 are executed iteratively until the classification termination condition is met.

[0090] The method provided in this embodiment introduces a node type determination mechanism and a multi-level label aggregation mechanism, which provides clear termination conditions and standardized result output capabilities for the hierarchical classification process, ensuring the rationality of classification depth and avoiding the problems of over-classification or under-classification.

[0091] The method provided in this embodiment will be described in detail below with specific examples.

[0092] Figure 3 This is the third flowchart of the text classification method provided by the present invention. Figure 4 This is the fourth flowchart illustrating the text classification method provided by this invention. Figure 3 and Figure 4 As shown, this text classification method can be divided into the following stages: Initialize the construction of the hierarchical knowledge graph. At this stage, all predefined hierarchical labels can be constructed as a prefix tree (hereinafter also referred to as a Trie) structure, where each node corresponds to a hierarchical label, and its node attributes store the unique identifier of the hierarchical label, the label name text, the index information pointing to the parent node, and the index information pointing to all direct child nodes, etc.; or, all predefined hierarchical labels can be constructed as a directed acyclic graph (DAG) structure to support multiple inheritance relationships of labels.

[0093] Prompt template construction and initialization; at this stage, the prompt template can be initialized to include at least task description information placeholders, dynamic task instruction placeholders, text information placeholders, and text category instance placeholders; The process involves step-by-step guided decoding and reasoning. At this stage, based on the hierarchical labels of the text to be classified at the previous classification level, a set of candidate labels corresponding to the current classification level is obtained from the hierarchical knowledge graph. A corresponding task instruction is generated based on this set, and the generated task instruction, the text content of the text to be classified, the task description information, and the text classification instance are updated to the prompt word template to obtain the label generation prompt words corresponding to the current classification level. The complete label generation prompt words constructed for the current classification level are input into a large language model. The large language model then applies the task instructions to predict the labels of the text to be classified, obtaining the probability that the next word element corresponding to the text belongs to each word element in the vocabulary. Before the large language model outputs the hierarchical labels for the current classification level, a Logits processor is applied to obtain the set of candidate labels corresponding to the current classification level from the hierarchical knowledge graph. The probability values ​​of words in the word element prediction probability set that match the word elements corresponding to the candidate hierarchical labels in the candidate label set are retained, as are the word elements that match the word elements corresponding to the preset hierarchical labels. The probability values ​​of other word elements are modified... Instead of a fixed value (such as negative infinity), the large language model is forced to choose only from a given, logically correct set of hierarchical labels. The large language model, through its understanding of the text to be classified, selects the word with the highest predicted probability from the set of predicted probabilities, which has been forcibly modified. If this word is in the selected candidate label set, its corresponding hierarchical label is added to the current classification path as the hierarchical label for the current classification level. If the word corresponds to a preset hierarchical label, such as "other," then all hierarchical labels in the candidate label set are determined. If none of these methods are suitable, the system switches to free generation mode and sends label update prompts to the LLM to guide the large language model to generate new hierarchical labels for the text to be classified. These labels are then added to the current classification path as hierarchical labels for the current classification level. Subsequently, based on the hierarchical labels of the current classification level, the system iteratively updates the label generation prompts for the next classification level to iterate the text classification for the next classification level. The iteration process terminates when the node to which the hierarchical label of the current classification level belongs is a leaf node in the hierarchical knowledge graph, and the final, valid, and complete hierarchical path is output.

[0094] The knowledge graph is dynamically expanded. At this stage, if it is discovered that the current classification level's hierarchical label is a new hierarchical label freely generated by the LLM model for the text to be classified, then the current classification level's hierarchical label and the text to be classified are stored in the target database. This serves as a basis for domain experts or operations personnel to retrospectively generate the label, facilitating their periodic review of the rationality of the current classification level's hierarchical label. The review results are then updated to the target database in real time. When the review status of the current classification level's hierarchical label is confirmed as approved, the current classification level's hierarchical label is added as a new node to the corresponding hierarchical knowledge graph, thus completing the dynamic updating and expansion of the knowledge base.

[0095] The text classification device provided by the present invention is described below. The text classification device described below and the text classification method described above can be referred to in correspondence.

[0096] Figure 5 This is a schematic diagram of the structure of the text classification device provided by the present invention; as shown below. Figure 5 As shown, the device includes: The first acquisition unit 510 is used to acquire the candidate tag set corresponding to the current classification level in the hierarchical knowledge graph corresponding to the current classification level based on the hierarchical tag of the text to be classified in the previous classification level. The generation unit 520 is used to generate a task instruction corresponding to the current classification level based on the candidate label set; The second acquisition unit 530 is used to acquire the tag corresponding to the current classification level and generate prompt words according to the task instruction and the text to be classified; The tag generation unit 540 is used to input the tag generation prompt words into a large language model to obtain the hierarchical tag of the text to be classified at the current classification level.

[0097] The device provided in this embodiment dynamically acquires a set of candidate labels level by level in a hierarchical knowledge graph based on the hierarchical labels of the previous classification level, thereby dynamically constructing the task instructions corresponding to the current classification level. This constrains the classification process of the text to be classified within a predefined hierarchical structure framework. Furthermore, it generates label generation prompts using the task instructions and the text to be classified, thereby guiding a large language model to perform semantic matching and selection within a limited set of candidate labels to predict hierarchical labels level by level. This fully utilizes the powerful semantic understanding capabilities of the large language model and the hierarchical knowledge constraints of the hierarchical knowledge graph to eliminate non-existent or incorrect output paths from the large language model, ensuring that each classification level conforms to the hierarchical structure relationship. This guarantees the logical correctness and consistency of the output classification path, effectively supporting text classification in cold start and long-tail category scenarios, and significantly improving the stability, reliability, and flexibility of hierarchical text classification.

[0098] In some embodiments, the label generation unit is specifically used for: Based on the large language model, the task instructions are applied to predict the labels of the text to be classified, and a set of word prediction probabilities is obtained. Based on the logic processor, in the word prediction probability set, the prediction probability value of the first word is modified to the target value to obtain an updated word prediction probability set; the first word is a word that does not match the word corresponding to each candidate level label in the candidate label set and the word corresponding to the preset level label. Based on the large language model, in the updated set of predicted probabilities of word elements, the word element with the largest predicted probability value is found to obtain the second word element, and the hierarchical label of the text to be classified in the current classification level is obtained according to the hierarchical label corresponding to the second word element.

[0099] In some embodiments, the label generation unit is further configured to: If the hierarchical label corresponding to the second word element is not in the candidate label set, then determine whether the hierarchical label corresponding to the second word element is the preset hierarchical label; If the hierarchical label corresponding to the second word element is the preset hierarchical label, then the label update prompt word is input into the large language model to obtain the hierarchical label of the text to be classified in the current classification level; The label update prompt is used to guide the large language model to generate a new hierarchical label for the text to be classified as the hierarchical label of the text to be classified in the current classification level. The new hierarchical label is different from the candidate hierarchical labels in the candidate label set and the preset hierarchical label.

[0100] In some embodiments, the apparatus further includes a knowledge graph updating unit, configured to: If the level label of the text to be classified in the current classification level is different from the candidate level label and the preset level label in the candidate label set, then the level label of the text to be classified in the current classification level and the text to be classified are stored in the target database. When an update to the target database is detected, if the update result indicates that the review status of the hierarchical tag of the text to be classified in the current classification level is approved, then the hierarchical tag of the text to be classified in the current classification level is updated as a new node to the hierarchical knowledge graph corresponding to the current classification level, thereby obtaining the hierarchical knowledge graph corresponding to the next classification level.

[0101] In some embodiments, the first acquisition unit is specifically used for: In the hierarchical knowledge graph corresponding to the current classification level, obtain the index information of the first node corresponding to the hierarchical label of the text to be classified in the previous classification level; Based on the index information, obtain the child nodes of the first node; The candidate label set is constructed based on the hierarchical labels corresponding to each child node.

[0102] In some embodiments, the second acquisition unit is specifically used for: Obtain the task description information corresponding to the text to be classified, as well as the text classification instance; The task instruction, the text information of the text to be classified, the task description information, and the text classification instance are updated to the prompt word template to obtain the tag generation prompt word.

[0103] In some embodiments, the apparatus further includes a summarizing unit, specifically used for: In the hierarchical knowledge graph corresponding to the current classification level, obtain the node type of the second node corresponding to the hierarchical label of the text to be classified in the current classification level; If the node type is a leaf node, then the hierarchical labels of the text to be classified at each classification level are summarized to obtain the multi-level classification labels of the text to be classified.

[0104] The apparatus provided by the present invention is used to execute the above-described method embodiments. For specific processes and details, please refer to the above embodiments, which will not be repeated here.

[0105] Figure 6 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 6 As shown, the electronic device may include a processor 610, a communications interface 620, a memory 630, and a communication bus 640, wherein the processor 610, communications interface 620, and memory 630 communicate with each other via the communication bus 640. The processor 610 can call logical instructions in the memory 630 to execute a text classification method. This method includes: obtaining a set of candidate labels corresponding to the current classification level in the hierarchical knowledge graph corresponding to the current classification level based on the hierarchical labels of the text to be classified in the previous classification level; generating a task instruction corresponding to the current classification level based on the candidate label set; obtaining label generation prompts corresponding to the current classification level based on the task instruction and the text to be classified; and inputting the label generation prompts into a large language model to obtain the hierarchical label of the text to be classified at the current classification level.

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

[0107] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer is able to execute the text classification method provided by the above methods. The method includes: obtaining a set of candidate tags corresponding to the current classification level in the hierarchical knowledge graph corresponding to the current classification level based on the hierarchical tags of the text to be classified in the previous classification level; generating a task instruction corresponding to the current classification level based on the candidate tag set; obtaining tag generation prompts corresponding to the current classification level based on the task instruction and the text to be classified; and inputting the tag generation prompts into a large language model to obtain the hierarchical tags of the text to be classified in the current classification level.

[0108] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the text classification method provided by the above methods. The method includes: obtaining a set of candidate tags corresponding to the current classification level in a hierarchical knowledge graph corresponding to the current classification level based on the hierarchical tags of the text to be classified at the previous classification level; generating a task instruction corresponding to the current classification level based on the candidate tag set; obtaining tag generation prompts corresponding to the current classification level based on the task instruction and the text to be classified; and inputting the tag generation prompts into a large language model to obtain the hierarchical tags of the text to be classified at the current classification level.

[0109] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. 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 the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0110] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0111] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method of text classification, characterized by, The method comprises the following steps: According to the hierarchical label of the text to be classified at the previous classification level, in the hierarchical knowledge graph corresponding to the current classification level, a candidate label set corresponding to the current classification level is obtained; According to the candidate label set, a task instruction corresponding to the current classification level is generated; According to the task instruction and the text to be classified, a label generation prompt word corresponding to the current classification level is obtained; The label generation prompt word is input into a large language model to obtain the hierarchical label of the text to be classified at the current classification level.

2. The text classification method of claim 1, wherein, The method comprises the following steps: Based on the large language model, the task instruction is applied to the text to be classified to perform label prediction to obtain a token prediction probability set; Based on the logic processor, the prediction probability value of a first token in the token prediction probability set is modified to a target value to obtain an updated token prediction probability set; the first token does not match the tokens corresponding to all candidate hierarchical labels in the candidate label set, and does not match the token corresponding to the preset hierarchical label; Based on the large language model, a second token is determined in the updated token prediction probability set, and a hierarchical label corresponding to the second token is obtained to obtain the hierarchical label of the text to be classified at the current classification level; the second token is the token with the maximum prediction probability value in the updated token prediction probability set.

3. The text classification method of claim 2, wherein, The method comprises the following steps: If the hierarchical label corresponding to the second token is not in the candidate label set, it is determined whether the hierarchical label corresponding to the second token is the preset hierarchical label; If the hierarchical label corresponding to the second token is the preset hierarchical label, a label update prompt word is input into the large language model to obtain the hierarchical label of the text to be classified at the current classification level; The label update prompt word is used to guide the large language model to generate a new hierarchical label for the text to be classified, and determine the new hierarchical label as the hierarchical label of the text to be classified at the current classification level.

4. The text classification method of claim 3, wherein, The method further comprises the following steps: If the hierarchical label of the text to be classified at the current classification level is the new hierarchical label, the hierarchical label of the text to be classified at the current classification level and the text to be classified are stored in a target database; When it is detected that the target database is updated, if it is learned according to the update result that the audit state of the hierarchical label of the text to be classified at the current classification level is passed, the hierarchical label of the text to be classified at the current classification level is updated as a new node in the hierarchical knowledge graph corresponding to the current classification level to obtain a hierarchical knowledge graph corresponding to the next classification level.

5. The text classification method according to any one of claims 1-4, characterized in that, The method comprises the following steps: In the hierarchical knowledge graph corresponding to the current classification level, index information of a first node corresponding to a hierarchical label of the last classification level of the text to be classified is obtained; According to the index information, the sub-nodes of the first node are obtained; According to the hierarchical labels corresponding to each of the sub-nodes, the candidate label set is constructed.

6. The text classification method according to any one of claims 1 to 4, characterized in that, The method further comprises: In the hierarchical knowledge graph corresponding to the current classification level, the node type of a second node corresponding to a hierarchical label of the current classification level of the text to be classified is obtained; If the node type is a leaf node, the hierarchical labels of the text to be classified at each classification level are summarized to obtain a multi-level classification label of the text to be classified.

7. The text classification method according to any one of claims 1 to 4, characterized in that, The method further comprises: A first obtaining unit is configured to obtain, according to a hierarchical label of the last classification level of the text to be classified, a candidate label set corresponding to the current classification level in a hierarchical knowledge graph corresponding to the current classification level; A generating unit is configured to generate a task instruction corresponding to the current classification level according to the candidate label set; 8. A text classification apparatus characterized by comprising: A second obtaining unit is configured to obtain a label generation prompt word corresponding to the current classification level according to the task instruction and the text to be classified; A label generating unit is configured to input the label generation prompt word into a large language model to obtain a hierarchical label of the text to be classified at the current classification level. The processor executes the computer program to implement the text classification method according to any one of claims 1 to 7. The computer program is executed by the processor to implement the text classification method according to any one of claims 1 to 7. ​ 9. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, ​ 10.A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, ​