Text classification method and electronic device
Patent Information
- Application Number
- CN202611206660.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-10
- Publication Date
- 2026-10-30
AI Technical Summary
[0004]本申请的目的在于,针对上述现有技术中的不足,提供一种文本分类方法及电子设备,以解决现有技术中分类结果准确性较低的问题
[0025]根据本申请实施例的文本分类方法及电子设备,基于标签树对待分类文本进行层级定位,确定待分类文本的层级维度,得到至少一个待分类层级,然后利用基于标签树构建的标签语义索引库,针对各待分类层级进行精准的向量化检索,从全量标签中筛选出符合各待分类层级的层级约束的候选标签集合,以便后续大语言模型仅从该候选标签集合中进行分类标签预测,有效缩小了搜索范围,避免了全量搜索带来的噪声干扰。而在大语言模型预测过程中,结合待分类文本与筛选得到的候选标签集合进行逐层受限预测,输出各待分类层级对应的分类标签及置信度,进而依据各待分类层级的预测结果与置信度生成最终的分类结果。如此,本申请将复杂的全局分类转化为多层级的逐层分析,在大幅降低大语言模型推理复杂度的同时,确保标签预测严格遵循标签树的层级与约束关系,从而有效解决了现有技术中因标签冲突和推理偏差导致的分类结果不准确的问题,显著提升了分类结果的准确性。
Smart Images

Figure CN123012172A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and more specifically, to a text classification method and an electronic device. Background Technology
[0002] Text classification is one of the fundamental functions of information processing systems. In practical business applications, for text to be classified, classification is not only necessary to determine which business domain the text belongs to, but also to further identify more granular business affiliations.
[0003] Currently, traditional machine learning methods are commonly used for text classification. These methods primarily rely on a stable label system for label prediction, meaning they make an overall judgment based on all labels in the system to output the probability of the classification label corresponding to the text to be classified. However, in practical business applications, due to the diverse expressions of the text to be classified and the complex relationships such as constraints and mutual exclusions between labels, traditional machine learning methods suffer from problems such as high inference costs and conflicting label prediction results, leading to inaccurate classification results. Summary of the Invention
[0004] The purpose of this application is to provide a text classification method and electronic device to address the shortcomings of the prior art, thereby solving the problem of low accuracy in classification results in the prior art.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows: In a first aspect, embodiments of this application provide a text classification method, the method comprising: Obtain the text to be classified, and based on the text to be classified and a pre-built tag tree, determine at least one classification level corresponding to the text to be classified. The tag tree includes multiple tag knowledge nodes arranged in a hierarchical manner, and each tag knowledge node corresponds to a tag. The candidate tag set corresponding to each classification level is determined based on a pre-built tag semantic index library. The tag semantic index library is constructed based on the tag tree. The tag semantic index library includes index records corresponding to multiple tag knowledge nodes. The index records include at least the tag semantic vector corresponding to the tag knowledge node. Based on the text to be classified and the candidate label set corresponding to each classification level, a large language model is invoked to predict the classification label and confidence level corresponding to each classification level. The classification results corresponding to the text to be classified are generated and output based on the classification labels and confidence scores of each classification level.
[0006] As one possible implementation, determining at least one classification level corresponding to the text to be classified based on the text to be classified and a pre-built tag tree includes: Obtain the context information of the text to be classified; Based on the text to be classified and its context information, a standardized text to be classified is generated. Feature extraction is performed on the standardized text to be classified to generate a text vector corresponding to the standardized text to be classified. Calculate the similarity between the text vector corresponding to the standardized text to be classified and each tag knowledge node in the tag tree, and take the tag knowledge node with a similarity greater than a preset threshold as the target node; The classification level is determined based on the hierarchical information of the target node in the tag tree.
[0007] As one possible implementation, the tag tree is constructed based on the following method: The raw tag data is obtained from multiple business data sources, and the raw tag data includes multiple tags and attribute information of the multiple tags; The attribute information of each tag is standardized according to a preset mapping strategy to obtain the standardized attribute information of each tag. Multiple tag knowledge nodes are determined based on the multiple tags, and the hierarchical relationship between the tag knowledge nodes is determined based on the standardized attribute information of each tag. The tag tree is constructed based on the hierarchical relationship between the knowledge nodes of each tag.
[0008] As one possible implementation, the tag semantic index library is constructed based on the following method: Based on the data structure information of each tag knowledge node in the tag tree, generate tag knowledge text corresponding to each tag knowledge node; Encode the tag knowledge text corresponding to each tag knowledge node to generate a tag semantic vector corresponding to each tag knowledge node; Based on the data structure information of each of the tag knowledge nodes, the tag knowledge text, and the tag semantic vector, an index record corresponding to each of the tag knowledge nodes is generated, and the level of each index record is determined. According to the hierarchy of each index record, the index records corresponding to each of the aforementioned tag knowledge nodes are added to the tag semantic index library.
[0009] As one possible implementation, determining the candidate tag set corresponding to each of the classification levels based on a pre-built tag semantic index library includes: Based on the level identifier of each level to be classified, determine the candidate search range corresponding to each level to be classified in the tag semantic index library, wherein the candidate search range includes index records corresponding to multiple target tag knowledge nodes; The candidate tag set corresponding to each of the classification levels is determined from the candidate search range corresponding to each of the classification levels in the tag semantic index library.
[0010] As one possible implementation, determining the candidate search range corresponding to each of the to-be-classified levels in the tag semantic index based on the level identifier of each to-be-classified level includes: Based on the level identifier of each level to be classified, determine the parent label corresponding to each level to be classified; Based on each of the levels to be classified, the parent tags corresponding to each level to be classified, and the levels of each index record in the tag semantic index library, the candidate search range corresponding to each level to be classified in the tag semantic index library is determined.
[0011] As one possible implementation, determining the candidate tag set corresponding to each of the classification levels from the candidate search range corresponding to each of the classification levels in the tag semantic index library includes: Obtain the tag semantic vector corresponding to each target tag knowledge node from the index record corresponding to each target tag knowledge node, and calculate the vector similarity between the tag semantic vector corresponding to each target tag knowledge node and the text vector corresponding to the text to be classified. Based on the vector similarity between the semantic vector of each target tag knowledge node and the text vector of the text to be classified, the target tags corresponding to each target tag knowledge node are sorted, and a preset number of target tags are selected according to the sorting order. Add a preset number of target tags to the candidate tag set corresponding to the classification level.
[0012] As one possible implementation, the step of calling a large language model based on the text to be classified and the candidate label set corresponding to each classification level, and having the large language model predict the classification label and confidence score corresponding to each classification level, includes: Based on the text to be classified, the context information of the text to be classified, and the candidate tag set corresponding to the classification level, construct the prompt words corresponding to the classification level; The prompt word is input into the large language model, which then predicts the classification label and confidence level corresponding to the level to be classified based on the prompt word. The classification label is the classification label in the candidate label set corresponding to the level to be classified.
[0013] As one possible implementation, generating and outputting the classification result corresponding to the text to be classified based on the classification result and confidence level of each of the classification levels includes: Based on the classification labels corresponding to each of the classification levels, a classification result for the text to be classified is generated, wherein the classification result includes at least one level of classification result; The overall confidence level is determined based on the confidence level of the classification labels corresponding to each of the classification levels. Based on the comprehensive confidence level, determine the strategy for outputting the classification results; The classification result of the text to be classified is output according to the classification result output strategy.
[0014] Secondly, embodiments of this application provide a text classification device, the device comprising: The first determining module is used to obtain the text to be classified and, based on the text to be classified and a pre-constructed tag tree, determine at least one classification level corresponding to the text to be classified. The tag tree includes multiple tag knowledge nodes arranged in a hierarchical manner, and each tag knowledge node corresponds to a tag. The second determining module is used to determine the candidate tag set corresponding to each of the classification levels based on a pre-built tag semantic index library. The tag semantic index library is constructed based on the tag tree and includes index records corresponding to multiple tag knowledge nodes. The index records include at least the tag semantic vector corresponding to the tag knowledge node. The classification module is used to call the large language model according to the text to be classified and the candidate label set corresponding to each of the classification levels, and the large language model predicts the classification label and confidence level corresponding to each of the classification levels. The generation module is used to generate and output the classification results corresponding to the text to be classified based on the classification labels and confidence scores corresponding to each of the classification levels.
[0015] As one possible implementation, the first determining module is specifically used for: Obtain the context information of the text to be classified; Based on the text to be classified and its context information, a standardized text to be classified is generated. Feature extraction is performed on the standardized text to be classified to generate a text vector corresponding to the standardized text to be classified. Calculate the similarity between the text vector corresponding to the standardized text to be classified and each tag knowledge node in the tag tree, and take the tag knowledge node with a similarity greater than a preset threshold as the target node; The classification level is determined based on the hierarchical information of the target node in the tag tree.
[0016] As one possible implementation, the text classification device further includes a construction module, which is specifically used for: The raw tag data is obtained from multiple business data sources, and the raw tag data includes multiple tags and attribute information of the multiple tags; The attribute information of each tag is standardized according to a preset mapping strategy to obtain the standardized attribute information of each tag. Multiple tag knowledge nodes are determined based on the multiple tags, and the hierarchical relationship between the tag knowledge nodes is determined based on the standardized attribute information of each tag. The tag tree is constructed based on the hierarchical relationship between the knowledge nodes of each tag.
[0017] As one possible implementation, the building module is specifically used for: Based on the data structure information of each tag knowledge node in the tag tree, generate tag knowledge text corresponding to each tag knowledge node; Encode the tag knowledge text corresponding to each tag knowledge node to generate a tag semantic vector corresponding to each tag knowledge node; Based on the data structure information of each of the tag knowledge nodes, the tag knowledge text, and the tag semantic vector, an index record corresponding to each of the tag knowledge nodes is generated, and the level of each index record is determined. According to the hierarchy of each index record, the index records corresponding to each of the aforementioned tag knowledge nodes are added to the tag semantic index library.
[0018] As one possible implementation, the second determining module is specifically used for: Based on the level identifier of each level to be classified, determine the candidate search range corresponding to each level to be classified in the tag semantic index library, wherein the candidate search range includes index records corresponding to multiple target tag knowledge nodes; The candidate tag set corresponding to each of the classification levels is determined from the candidate search range corresponding to each of the classification levels in the tag semantic index library.
[0019] As one possible implementation, the second determining module is specifically used for: Based on the level identifier of each level to be classified, determine the parent label corresponding to each level to be classified; Based on each of the levels to be classified, the parent tags corresponding to each level to be classified, and the levels of each index record in the tag semantic index library, the candidate search range corresponding to each level to be classified in the tag semantic index library is determined.
[0020] As one possible implementation, the second determining module is specifically used for: Obtain the tag semantic vector corresponding to each target tag knowledge node from the index record corresponding to each target tag knowledge node, and calculate the vector similarity between the tag semantic vector corresponding to each target tag knowledge node and the text vector corresponding to the text to be classified. Based on the vector similarity between the semantic vector of each target tag knowledge node and the text vector of the text to be classified, the target tags corresponding to each target tag knowledge node are sorted, and a preset number of target tags are selected according to the sorting order. Add a preset number of target tags to the candidate tag set corresponding to the classification level.
[0021] As one possible implementation, the classification module is specifically used for: Based on the text to be classified, the context information of the text to be classified, and the candidate tag set corresponding to the classification level, construct the prompt words corresponding to the classification level; The prompt word is input into the large language model, which then predicts the classification label and confidence level corresponding to the level to be classified based on the prompt word. The classification label is the classification label in the candidate label set corresponding to the level to be classified.
[0022] As one possible implementation, the generation module is specifically used for: Based on the classification labels corresponding to each of the classification levels, a classification result for the text to be classified is generated, wherein the classification result includes at least one level of classification result; The overall confidence level is determined based on the confidence level of the classification labels corresponding to each of the classification levels. Based on the comprehensive confidence level, determine the strategy for outputting the classification results; The classification result of the text to be classified is output according to the classification result output strategy.
[0023] Thirdly, embodiments of this application provide an electronic device, including: a processor, a storage medium, and a bus. The storage medium stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the text classification method as described in any of the first aspects above.
[0024] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the text classification method as described in any of the first aspects above.
[0025] According to the text classification method and electronic device of this application, the hierarchical positioning of the text to be classified is performed based on a tag tree to determine the hierarchical dimension of the text to be classified, obtaining at least one classification level. Then, using a tag semantic index library built based on the tag tree, precise vectorized retrieval is performed for each classification level, filtering out a set of candidate tags that meet the hierarchical constraints of each classification level from the full set of tags. This allows the subsequent large language model to predict classification tags only from this set of candidate tags, effectively narrowing the search scope and avoiding noise interference from the full search. During the large language model prediction process, the text to be classified and the filtered set of candidate tags are combined for layer-by-layer constrained prediction, outputting the classification tags and confidence scores corresponding to each classification level. Finally, the final classification result is generated based on the prediction results and confidence scores of each classification level. In this way, this application transforms complex global classification into multi-level layer-by-layer analysis, significantly reducing the inference complexity of the large language model while ensuring that tag prediction strictly follows the hierarchical and constraint relationships of the tag tree. This effectively solves the problem of inaccurate classification results caused by tag conflicts and inference biases in the prior art, and significantly improves the accuracy of the classification results. Attached Figure Description
[0026] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0027] Figure 1 A flowchart illustrating a text classification method provided in an embodiment of this application is shown; Figure 2 A flowchart illustrating a tag tree construction method provided in an embodiment of this application is shown. Figure 3 A schematic diagram of a tag tree provided in an embodiment of this application is shown; Figure 4 A flowchart illustrating a method for constructing a tag semantic index library according to an embodiment of this application is shown; Figure 5 A flowchart illustrating a method for determining the classification level provided in an embodiment of this application is shown. Figure 6 A flowchart illustrating a method for determining a candidate tag set according to an embodiment of this application is shown; Figure 7 A flowchart illustrating another method for determining a candidate tag set provided in an embodiment of this application is shown; Figure 8 A schematic flowchart of a model prediction method provided in an embodiment of this application is shown; Figure 9 A flowchart illustrating a classification result generation method provided in an embodiment of this application is shown; Figure 10 This paper shows a schematic diagram of the structure of a text classification device provided in an embodiment of this application; Figure 11 A schematic diagram of the structure of an electronic device provided in an embodiment of this application is shown. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the accompanying drawings in this application are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this application. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate operations implemented according to some embodiments of this application. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical contextual relationships may be reversed or implemented simultaneously. In addition, those skilled in the art, guided by the content of this application, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts.
[0029] Furthermore, the described embodiments are merely some, not all, of the embodiments of this application. The components of the embodiments of this application described and illustrated herein can typically be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0030] It should be noted that the term "comprising" will be used in the embodiments of this application to indicate the presence of the features declared thereafter, but does not exclude the addition of other features.
[0031] Figure 1 A flowchart illustrating a text classification method provided in an embodiment of this application is shown. (Refer to...) Figure 1As shown, the method specifically includes the following steps: S101. Obtain the text to be classified, and based on the text to be classified and the pre-built label tree, determine at least one classification level corresponding to the text to be classified.
[0032] Optionally, the text to be categorized can be user input, work order content, customer service dialogue, government requests, document summaries, business descriptions, etc., with no specific format restrictions.
[0033] The tag tree includes multiple tag knowledge nodes arranged hierarchically, with each tag knowledge node corresponding to a tag.
[0034] Optionally, the text to be classified is preprocessed and encoded to obtain the text vector corresponding to the text to be classified, and the similarity between the text vector and the tag semantic vector corresponding to each tag knowledge node in the tag tree is calculated. Then, the target node is selected based on the similarity, so as to determine at least one classification level corresponding to the text to be classified according to the hierarchical information of the target node in the tag tree and the parent-child constraint relationship between each tag knowledge node in the tag tree.
[0035] S102. Determine the set of candidate tags corresponding to each classification level based on the pre-built tag semantic index library.
[0036] The tag semantic index is built based on the tag tree. The tag semantic index includes index records corresponding to multiple tag knowledge nodes, and each index record includes at least the tag semantic vector corresponding to the tag knowledge node.
[0037] Optionally, for each classification level, a search is performed in the tag semantic index based on the level identifier of the classification level. First, an effective candidate search range is determined, which includes index records of multiple target tag knowledge nodes. The tag semantic vectors corresponding to each target tag knowledge node are obtained from the index records within the candidate search range. The similarity between the text vector corresponding to the text to be classified and the tag semantic vectors corresponding to each target tag knowledge node is calculated. The similarity is then sorted to obtain multiple candidate tags, generating a candidate tag set corresponding to the classification level.
[0038] S103. Based on the text to be classified and the candidate label set corresponding to each classification level, call the large language model respectively, and use the large language model to predict the classification label and confidence level corresponding to each classification level.
[0039] Optionally, for each classification level, prompt words are constructed based on the text to be classified and the candidate label set corresponding to the classification level, and a large language model is called to predict layer by layer according to the constructed prompt words and output the classification label and confidence score corresponding to each classification level.
[0040] S104. Generate and output the classification results corresponding to the text to be classified based on the classification labels and confidence scores of each classification level.
[0041] Optionally, the prediction results output by the large language model are subjected to consistency verification. After the verification is passed, a comprehensive confidence score is calculated based on the output confidence score and other multi-dimensional business confidence signals. The final classification result output strategy is determined according to the comprehensive confidence score, and the classification result corresponding to the text to be classified is output according to the classification result output strategy.
[0042] Based on this, the text classification method according to the embodiments of this application performs hierarchical positioning of the text to be classified based on a tag tree, determines the hierarchical dimension of the text to be classified, and obtains at least one level to be classified. Then, using a tag semantic index library built based on the tag tree, precise vectorized retrieval is performed for each level to be classified, and a set of candidate tags that meet the hierarchical constraints of each level to be classified is selected from the full set of tags. This allows the subsequent large language model to predict the classification tags only from this set of candidate tags, effectively narrowing the search scope and avoiding noise interference caused by full search. During the prediction process of the large language model, the text to be classified and the selected set of candidate tags are combined to perform layer-by-layer constrained prediction, outputting the classification tags and confidence scores corresponding to each level to be classified. Finally, the final classification result is generated based on the prediction results and confidence scores of each level to be classified. In this way, this application transforms the complex global classification into a multi-level layer-by-layer analysis, which significantly reduces the inference complexity of the large language model while ensuring that the tag prediction strictly follows the hierarchical and constraint relationships of the tag tree. This effectively solves the problem of inaccurate classification results caused by tag conflicts and inference biases in the prior art, and significantly improves the accuracy of the classification results.
[0043] Figure 2 A flowchart illustrating a tag tree construction method provided in an embodiment of this application is shown. (Refer to...) Figure 2 As shown, the method specifically includes the following steps: S201. Obtain raw label data from multiple business data sources.
[0044] Optionally, business data sources include business systems, tag management platforms, database tables, Excel / CSV / JSON files, business catalog documents, or historically labeled samples. The original tag data includes multiple tags and their attribute information. The tag attribute information includes, but is not limited to, tag name, tag number, tag code, category identifier, category name, parent tag, parent category, parent category number, hierarchical path, tag description, category description, business meaning, scope of application, keywords, aliases, positive examples, negative examples, mutually exclusive conditions, channel, region, and business version.
[0045] S202. Standardize the attribute information of each tag according to the preset mapping strategy to obtain the standardized attribute information of each tag.
[0046] Optionally, since the attribute information of multiple tags is obtained from different business data sources, and the field descriptions of the same attribute information differ between different business data sources, in order to achieve unified attribute field descriptions, this application embodiment adopts a preset mapping strategy to standardize the attribute fields of each tag.
[0047] For example, a pre-defined mapping strategy refers to a standardized processing mechanism that maps and converts heterogeneous attribute fields into standardized field names by establishing unified rules to address the issue of differences in the descriptions of the same or similar attribute fields in different business data sources. This achieves a unified description of attribute information. In this embodiment, the pre-defined mapping strategy may, for example, map attribute fields such as "category number, label code, category identifier" to the field "label_id", "category name, label name" to the field "label_name", "parent label, parent category, parent class number" to the field "parent_id", and "category description, business meaning" to the field "definition", etc. This yields standardized attribute information for each label. It should be noted that these are merely examples of pre-defined mapping strategies; the mapping relationships between attribute fields can be specifically set according to actual business applications and are not specifically limited.
[0048] S203. Determine multiple tag knowledge nodes based on multiple tags, and determine the hierarchical relationship between tag knowledge nodes based on the standardized attribute information of each tag.
[0049] Optionally, the tag tree is composed of multiple tag knowledge nodes. After obtaining multiple tags, the tags can be deduplicated, and each tag obtained after deduplication can be used as a tag knowledge node.
[0050] Optionally, the standardized attribute information of each tag is parsed to determine the parent-child relationship between tags, and then the hierarchical relationship between tag knowledge nodes is determined based on the parent-child relationship between tags. For example, the standardized attribute information of a tag includes two attribute fields: `parent_id`. The parent-child relationship between tag knowledge nodes corresponding to each tag can be obtained by parsing the `parent_id` attribute field of each tag. If the standardized attribute information of a tag lacks the `parent_id` attribute field but includes a hierarchical field, such as first-level tag, second-level tag, third-level tag, or complete tag path, the parent-child relationship is determined based on the hierarchical field. Alternatively, if there is neither a parent_id attribute field nor a hierarchical field, the parent-child relationship between tags can be supplemented through manual configuration, importing from the business directory, or manual review and confirmation. For example, candidate parent relationships can be generated first based on tag name, definition, and similarity to historical samples, and then the final parent-child relationship can be determined after manual confirmation.
[0051] Furthermore, based on the established parent-child relationships between tags, a rigorous validity check is performed on these relationships. The check focuses on anomalies such as the existence of parent nodes, circular references, hierarchical jumps, and duplicate names within the same parent node. Upon successful verification, the hierarchical value and complete tag path of each tag knowledge node are generated. Specifically, based on the confirmed parent-child relationships, upward or downward traversal is performed to accurately calculate the specific hierarchical value of each tag knowledge node in the tag tree, such as level 1, level 2, etc. Then, based on the hierarchical values and parent-child pointers between tag knowledge nodes, the complete tag path of each tag knowledge node is generated from top to bottom, ultimately determining the hierarchical relationship of each tag knowledge node in the tag tree. Data that fails the verification is intercepted and stored in an anomaly list for correction.
[0052] S204. Construct a tag tree based on the hierarchical relationship between the knowledge nodes of each tag.
[0053] Optionally, a tag tree is constructed based on the specific hierarchical value of each tag knowledge node in the tag tree and the complete tag path of each tag knowledge node. Business rules are then bound to one or more corresponding tag knowledge nodes to form computable rule records. These business rules include, but are not limited to: mutual exclusion rules, scope of application rules, keyword or alias rules, required field rules, regional or channel restriction rules, rules on whether further subdivision is allowed, rules on whether multiple tags are allowed to coexist, and low-confidence fallback rules.
[0054] For example, refer to Figure 3The tag tree shown starts at the "root node" and extends downwards with multiple branches to represent the parent-child relationships between tag knowledge nodes. Specifically, the "root node" extends downwards to two main first-level tags: "Level 1 Tag A" and "Level 1 Tag B". "Level 1 Tag A" is further subdivided into "Level 2 Tag A1" and "Level 2 Tag A2". "Level 2 Tag A1" has "Level 3 Tag A1a" and "Level 3 Tag A1b", and "Level 2 Tag A2" has "Level 3 Tag A2a". Similarly, "Level 1 Tag B" has "Level 2 Tag B1", and "Level 2 Tag B1" has "Level 3 Tag B1a". Figure 3 The structure of the tag tree shown clearly demonstrates the parent-child relationship between each tag knowledge node and the level of each tag knowledge node in the tag tree. Moreover, for each tag knowledge node, the complete tag path of each tag knowledge node can be clearly known, ensuring that each leaf node, such as third-level tag A1a, third-level tag A1b, etc., can be traced back to the root node through a unique tag path.
[0055] For example, continue to refer to Figure 3 As shown, the root node, first-level label A, first-level label B, second-level label A1, second-level label A2, second-level label B1, third-level label A1a, third-level label A1b, third-level label A2a, and third-level label B1a are each a label knowledge node. Based on the standardized attribute information of each label, each label knowledge node includes, but is not limited to, the following data structure information: label_id (unique label identifier), label_name (label name), parent_id (parent label identifier), level, label_path (label path), label definition, applicable_scope, positive_examples (positive examples), negative_examples (negative examples), aliases, exclusion_rules, required_fields, allow_children (allow further subdivision), allow_multi_label (allow multi_label), and version number. In one implementation, the specific data structure of the label knowledge node is as follows: { "label_id": "L3_008", "label_name": "Third-level label name", "parent_id": "L2_003", "level": 3, "label_path": "Level 1 tag / Level 2 tag / Level 3 tag", "definition": "The business meaning and judgment criteria corresponding to this tag", "applicable_scope": "The scope of business that this tag applies to", "positive_examples": ["positive example text 1", "positive example text 2"], "negative_examples": ["negative example text 1", "negative example text 2"], "aliases": ["aliases1", "colloquial expressions1"], "exclusion_rules": ["mutually exclusive with a certain label", "must not be hit if a certain condition is met"], "required_fields": ["Item Name", "Regional Information"], "allow_children": true, "allow_multi_label": false, "version": "v1.0" } In addition, each time a new tag is added, a tag is deleted, a tag name is modified, a parent-child relationship is adjusted, a definition is modified, positive or negative examples are added or deleted, or aliases or business rules are adjusted, a version number needs to be generated or updated, and change information such as effective time, expiration time, change type, content before change, content after change, and review status needs to be recorded in order to synchronously version the tag tree.
[0056] Based on this, this application embodiment obtains raw tag data from multi-source heterogeneous business data and performs standardization processing using a preset mapping strategy to obtain standardized attribute information for each tag. This effectively solves the problem of inconsistent field descriptions from different data sources and achieves unified standardization of tag attribute information. Furthermore, by parsing the standardized attribute information of each tag, the hierarchical relationship between corresponding tag knowledge nodes is determined, and a tag tree is constructed. This provides a data foundation for the subsequent construction of a tag semantic index library and the hierarchical retrieval of candidate tag sets.
[0057] As one possible implementation, based on the constructed tag tree, a tag semantic index library can be further constructed.
[0058] Figure 4 This diagram illustrates a flowchart of a tag semantic index library construction method provided in an embodiment of this application. (Refer to...) Figure 4 As shown, the method specifically includes the following steps: S401. Based on the data structure information of each tag knowledge node in the tag tree, generate the tag knowledge text corresponding to each tag knowledge node.
[0059] Optionally, the tag knowledge text is not directly obtained by taking the data structure information of the tag knowledge node shown above, but by selecting a portion of the fields from the data structure information and combining them with business rules. This is then used for semantic retrieval based on the constructed tag semantic index library.
[0060] For example, for each tag knowledge node in the tag tree, the tag knowledge text can be obtained by concatenating the tag name (label_name), tag path (label_path), tag definition (definition), applicable scope (applicable_scope), positive examples (positive_examples), negative examples (negative_examples), and synonyms or aliases in the data structure information, combined with business rules in sequence. For example, "tag knowledge text = tag name + tag path + tag definition + applicable scope + positive examples + negative examples + synonyms or aliases + business rules".
[0061] S402. Encode the tag knowledge text corresponding to each tag knowledge node to generate the tag semantic vector corresponding to each tag knowledge node.
[0062] Optionally, a text vectorization model can be invoked to encode the labeled knowledge text, for example, to record the first... The tag knowledge text corresponding to each tag knowledge node is: The encoding operation function of the text vectorization model is Then the encoding generates the first The tag semantic vector corresponding to each tag knowledge node It can be represented as .
[0063] It is worth noting that since the tag knowledge text is a combination of tag name, tag path, tag definition, scope of application, positive examples, negative examples, synonyms or aliases and business rules, the encoded tag semantic vector can represent the business meaning, applicable boundaries and distinguishing information of the corresponding tag knowledge node.
[0064] S403. Based on the data structure information of each tag knowledge node, the tag knowledge text, and the tag semantic vector, generate the index record corresponding to each tag knowledge node, and determine the level of each index record.
[0065] Optionally, for each tag knowledge node, the tag unique identifier label_id, parent tag identifier parent_id, level, and tag path label_path are obtained from the data structure information of the tag knowledge node. These are then combined with the generated tag knowledge text label_text, tag semantic vector label_vector, rule identifier rule_ids, version number, and status to generate the corresponding index record for the tag knowledge node. That is, the index record of the tag knowledge node includes at least the tag unique identifier, parent tag identifier, level, tag path, tag knowledge text, tag semantic vector, rule identifier, version number, and status.
[0066] For example, the structure of the index record is as follows: { "label_id": "L3_008", "parent_id": "L2_003", "level": 3, "label_path": "Level 1 tag / Level 2 tag / Level 3 tag", "label_text": "T_label", "label_vector ": [0.12, -0.08, 0.35], "rule_ids": ["R_001"], "version": "v1.0", "status": "active" } S404. According to the hierarchy of each index record, add the index records corresponding to each tag knowledge node to the tag semantic index library.
[0067] Optionally, after generating the index records corresponding to each tag knowledge node, the level of the index records corresponding to each tag knowledge node is determined based on the level of each tag knowledge node in the tag tree, and the index records corresponding to each tag knowledge node are written into the tag semantic index library according to the level of each index record. The tag semantic index library can be implemented by combining vector database, approximate nearest neighbor index, inverted index and vector index.
[0068] In addition, when the tag tree undergoes a version change, the tag semantic index is also updated synchronously. For newly added tags in the tag tree, a corresponding new tag semantic vector is generated and written into the index record. If the tag definition, alias, example, or business rule is modified, a new tag knowledge text and tag semantic vector are regenerated, and a new index record is generated and written into the tag semantic index. If a tag is deleted or deactivated, the index record corresponding to the tag knowledge node is marked as invalid.
[0069] Based on this, this application's embodiments generate tag knowledge text for tag knowledge nodes based on the data structure information of the tag knowledge nodes, and encode the tag knowledge text to generate tag semantic vectors. On this basis, combined with structured information such as tag unique identifiers, levels, and paths, index records corresponding to the tag knowledge nodes are generated, and these generated index records are written into the tag semantic index library according to their levels. Thus, by constructing a tag semantic index library, data support is provided for subsequent similarity-based tag retrieval and matching to filter candidate tag sets, significantly improving the semantic understanding capability and business adaptability of the tag system.
[0070] Figure 5 A flowchart illustrating a method for determining the classification level according to an embodiment of this application is shown. (Refer to...) Figure 5 As shown, the above steps, based on the text to be classified and a pre-built tag tree, determine at least one classification level corresponding to the text to be classified, specifically including the following steps: S501. Obtain the context information of the text to be classified.
[0071] Optionally, the contextual information includes, but is not limited to, the source channel of the text to be classified, the user's region, the business time, historical conversations, work order fields, associated objects, submitting department, user profile, etc.
[0072] S502. Based on the text to be classified and its contextual information, generate standardized text to be classified.
[0073] Optionally, after obtaining the text to be classified and its context information, the text to be classified and the context information can be preprocessed. This preprocessing includes, but is not limited to, character encoding unification, removal of invalid characters, marking tags used to define structure or format, removal of repeated whitespace and noise symbols, splicing of text identified in titles, body text, supplementary descriptions, and attachments, segmentation of excessively long texts, compression of abstracts or key information, extraction of keywords, entities, time, location, organization names, product names, and event names, and normalization of misspellings, abbreviations, synonyms, and domain terms.
[0074] For example, let the text to be classified be Text_raw, the context information of the text to be classified be Context, and the preprocessing function be Normalize(). Then the generated normalized text to be classified, T_input, can be represented as T_input = Normalize(Text_raw, Context).
[0075] S503. Extract features from the standardized text to be classified and generate the text vector corresponding to the standardized text to be classified.
[0076] Optionally, after generating the standardized text to be classified, a pre-trained language model, such as a Transformer-based Bidirectional Encoder Representations from Transformers (BERT) model or a word embedding layer, can be used to convert each word in the standardized text to be classified into a corresponding word vector. Then, the word vectors are aggregated through a context encoding mechanism to generate a text vector that can accurately represent the semantics of the standardized text to be classified.
[0077] S504. Calculate the similarity between the text vector corresponding to the standardized text to be classified and each tag knowledge node in the tag tree, and take the tag knowledge node with a similarity greater than a preset threshold as the target node.
[0078] Optionally, during the construction of the tag semantic index library, tag semantic vectors corresponding to each tag knowledge node have been generated. After generating the text vector corresponding to the standardized text to be classified, the text vector corresponding to the standardized text to be classified can be matched with each tag knowledge node in the tag tree. Specifically, the similarity between the text vector corresponding to the standardized text to be classified and the tag semantic vector corresponding to each tag knowledge node is calculated. This similarity can be determined by using the cosine similarity calculation method, so as to measure the degree of closeness between the text vector corresponding to the standardized text to be classified and each tag knowledge node in the tag tree in the semantic space.
[0079] Furthermore, after calculating the similarity between the text vector corresponding to the standardized text to be classified and the tag semantic vector corresponding to each tag knowledge node, filtering is performed based on a pre-set threshold, retaining only the tag knowledge nodes with a similarity greater than the pre-set threshold as target nodes, and the target node can be one or more.
[0080] S505. Determine the classification level based on the hierarchical information of the target node in the tag tree.
[0081] Optionally, based on the structure of the tag tree, the level value of the target node in the tag tree and the complete tag path are read to determine the classification level corresponding to the text to be classified. (Continue to refer to...) Figure 3 As shown, if the target node is "Level 1 Tag A", then the corresponding classification level is Level 2. Its complete tag path includes three sub-paths: the first is Level 1 Tag A, Level 2 Tag A1, and Level 3 Tag A1a; the second is Level 1 Tag A, Level 2 Tag A1, and Level 3 Tag A1b; and the third is Level 1 Tag A, Level 2 Tag A2, and Level 3 Tag A2a. If the target node includes multiple nodes, such as Level 1 Tag A and Level 1 Tag B, refer to... Figure 3 As shown, both tags are first-level tags, and their level in the tag tree is level 2. Therefore, level 2 is the only level to be classified. However, if multiple target nodes are not at the same level, such as a target node including first-level tag A and second-level tag B1, these two target nodes are obviously not at the same level. In this case, the specific level to be classified for the text can be determined based on the similarity between the two target nodes and the parent-child constraint relationship between the tag knowledge nodes shown in the tag tree. For example, nodes with more complete tag paths and that conform to business logic (such as parent and child tags with parent-child relationships; according to the parent-child constraint relationship, tags cannot contain both parent and child at the same time, so level disambiguation is required, and the parent tag is preferred) are selected as target nodes. If tag path conflicts occur, the optimal target node can be selected by comprehensively comparing similarity and tag path weights, and the level of the optimal target node is determined as the level to be classified. Among them, the more complete the tag path and the more parent and child tags it contains, the greater the tag path weight.
[0082] Based on this, the embodiments of this application generate standardized unclassified text by standardizing the text to be classified and its context information, effectively eliminating noise interference and format differences in multi-source heterogeneous data, and significantly improving the data quality of the classified text. Furthermore, by calculating the similarity between the text vector corresponding to the standardized unclassified text and the knowledge nodes of each tag in the tag tree, the classification level of the unclassified text is determined, providing a hierarchical basis for subsequent hierarchical retrieval to determine the candidate tag set.
[0083] Figure 6 A flowchart illustrating a method for determining a candidate tag set according to an embodiment of this application is shown. (Refer to...) Figure 6 As shown, step S102 above determines the candidate tag set corresponding to each classification level based on a pre-built tag semantic index library, specifically including the following steps: S601. Based on the level identifier of each level to be classified, determine the candidate search range corresponding to each level to be classified in the tag semantic index library.
[0084] The candidate search scope includes index records corresponding to multiple target label knowledge nodes.
[0085] Optionally, based on the level identifier of each level to be classified, the parent label corresponding to each level to be classified is determined, and based on each level to be classified, the parent label corresponding to each level to be classified, and the level of each index record in the label semantic index library, the candidate search range corresponding to each level to be classified in the label semantic index library is determined.
[0086] For example, if the hierarchy identifier of the level to be classified is a first-level category, then the parent label corresponding to the level to be classified is determined as the root node. If the hierarchy identifier of the level to be classified is a second-level category, then the parent label corresponding to the level to be classified is determined as the label of the previous level, such as a first-level node. In other words, the level to be classified is the next level below the level corresponding to the parent label.
[0087] For example, let the level to be classified be L and the parent label corresponding to the level to be classified be P. Then, taking the level to be classified L and the parent label corresponding to the level to be classified P as the core constraints, and based on the level of each index record in the label semantic index library, condition filtering search is performed in the label semantic index library to select all index records that meet the requirements of parent label matching, level value matching, and are in the current effective version and active state, thereby accurately narrowing the search scope.
[0088] For example, determining the candidate search scope is essentially filtering target tag knowledge nodes that meet certain conditions. For instance, C_scope={label|label.parent_id=P and label.level=L and label.version=V_current and label.status=active}. This example specifically represents the set of all tag knowledge nodes (labels) in the tag semantic index that meet the following four conditions: the parent tag identifier (parent_id) of the tag knowledge node (label) must be equal to the parent tag P; the level of the tag knowledge node (label) must be equal to the classification level L; the version number of the tag knowledge node (label) must be the currently active version V_current; and the status of the tag knowledge node (label) must be active. Based on this, the index records corresponding to the target tag knowledge nodes in the above set C_scope are used as candidate search scopes.
[0089] S602. Determine the set of candidate tags corresponding to each classification level from the candidate search range corresponding to each classification level in the tag semantic index library.
[0090] Optionally, only target tag knowledge nodes within the aforementioned candidate search scope, i.e., only target tag knowledge nodes in the set C_scope, will participate in subsequent similarity calculation and ranking processes. In other words, each candidate tag in the candidate tag set must be retrieved within its corresponding candidate search scope, rather than being retrieved globally.
[0091] Figure 7 A flowchart illustrating another method for determining a candidate tag set provided in an embodiment of this application is shown. (Refer to...) Figure 7 As shown, step S602 above determines the candidate tag set corresponding to each classification level from the candidate search range corresponding to each classification level in the tag semantic index library, specifically including the following steps: S701. Obtain the tag semantic vector corresponding to each target tag knowledge node from the index record corresponding to each target tag knowledge node, and calculate the vector similarity between the tag semantic vector corresponding to each target tag knowledge node and the text vector corresponding to the text to be classified.
[0092] Optionally, for each target label knowledge node in the determined C_scope set, the label semantic vector corresponding to each target label knowledge node is extracted from the index record of each target label knowledge node. At the same time, the text vector corresponding to the text to be classified is obtained by encoding the text to be classified. The vector similarity calculation algorithm, such as the cosine similarity calculation method, is used to calculate the vector similarity between the text vector corresponding to the text to be classified and the label semantic vector corresponding to each target label knowledge node.
[0093] S702. Based on the vector similarity between the semantic vector of the tag corresponding to each target tag knowledge node and the text vector corresponding to the text to be classified, sort the target tags corresponding to each target tag knowledge node, and select a preset number of target tags according to the sorting order.
[0094] Optionally, based on the vector similarity Sim_text_label_i between the semantic vector of each target label knowledge node and the text vector of the text to be classified, the target labels corresponding to each target label knowledge node can be directly sorted according to the magnitude of the vector similarity Sim_text_label_i, and a preset number of target labels can be selected according to the sorting order, such as selecting the first K labels as target labels. Here, K can be a fixed value, or it can be dynamically determined according to the number of labels, business thresholds, etc., without specific restrictions.
[0095] In another possible implementation, the comprehensive recall score of the tags corresponding to each target tag knowledge node can be calculated based on the vector similarity, combined with the keyword hit score Match_keyword_i, alias hit score Match_alias_i, rule trigger score Match_rule_i, context matching score Match_context_i, and historical prior score Prior_i. Then, the comprehensive recall scores are used to sort the tags, and the top K tags are selected as target tags according to the sorting order.
[0096] For example, the comprehensive recall score Score_recall_i is calculated as follows: Score_recall_i = α×Sim_text_label_i + β×Match_keyword_i + γ×Match_alias_i + δ×Match_rule_i + ε×Match_context_i + ζ×Prior_i. Where α, β, γ, δ, ε, and ζ are configurable weights.
[0097] S703. Add a preset number of target tags to the candidate tag set corresponding to the classification level.
[0098] Optionally, the selected K target labels are used as candidate labels for the classification level and written into the candidate label set.
[0099] Based on this, the embodiments of this application precisely narrow the search scope to the set of effective nodes through hierarchical identifiers and parent tag constraints, effectively avoiding redundant calculations and interference from irrelevant tags caused by full-database retrieval. Furthermore, by calculating similarity and sorting and extracting a preset number of target tags to form a candidate tag set, the accuracy of tag recommendations is significantly improved.
[0100] Figure 8 A schematic flowchart of a model prediction method provided in an embodiment of this application is shown. (Refer to...) Figure 8 As shown, step S103 above calls the large language model based on the text to be classified and the candidate label set corresponding to each classification level. The large language model predicts the classification label and confidence level corresponding to each classification level. Specifically, it includes the following steps: S801. Based on the text to be classified, the context information of the text to be classified, and the candidate tag set corresponding to the classification level, construct the prompt words corresponding to the classification level.
[0101] Optionally, the candidate label set corresponding to the classification level, the label definition, positive and negative examples, parent label path and other information of each target label in the candidate label set, the text to be classified and the context information of the text to be classified are organized into structured prompt words, so as to input the prompt words into the large language model for restricted classification judgment.
[0102] Optionally, the constructed prompts may include at least the classification task description, the text to be classified, the parent label path, the candidate label set, the name and definition of each target label in the candidate label set, the distinction between labels, the output format requirements, the constraint that labels outside the candidate label set should not be output, and the rule that allows output of "uncertain" or "stay on the parent label" when there is insufficient information.
[0103] S802. Input the prompt words into the large language model, and the large language model will predict the classification label and confidence level corresponding to the classification level based on the prompt words.
[0104] The category label is the category label in the candidate label set corresponding to the level to be categorized.
[0105] For example, the large language model makes predictions based on cue words and inputs results in the following structured format: { "selected_label_id": "L2_003", "selected_label_name": "Example secondary label", "reason": "The text contains a description of an event that matches the definition of this tag, and no other candidate tags are matched as exclusion criteria." "evidence": ["evidence fragment 1", "evidence fragment 2"], "confidence_llm": 0.86, "continue_drill_down": true, "need_manual_review": false, "excluded_candidates": [ { "label_id": "L2_001", "reason": "The key entity required by this label is missing." } ] } Furthermore, the output format of the above large language model is parsed and verified. If the classification label predicted by the large language model is not in the candidate label set, the classification label predicted this time is marked as invalid, and a prompt and rollback for manual review are triggered.
[0106] It is worth noting that the large language model predicts classification labels one by one according to the classification level. That is, it only moves on to the next level of prediction after the current classification level is predicted. If any of the following situations occur, the large language model will stop drilling down, that is, stop moving to the next level of classification prediction. The situations that stop drilling down include, but are not limited to, the current label is a leaf label, the current label field allow_children is not, the current level has reached the maximum output level required by the business, the large language model outputs the continue_drill_down flag as not being true, the confidence of the current level is lower than the continue-drill-down threshold, the text to be classified lacks the necessary fields required for the next level of classification, there are no available sub-labels under the current label, and the business rules require that this type of text is only output to the current level, etc.
[0107] In addition, after the large language model outputs classification labels, a consistency check is performed on the output results. This check includes, but is not limited to: parent-child relationship check, hierarchical integrity check, required field check, scope of application check, confidence threshold check, and multi-round consistency check. Specifically, parent-child relationship check checks whether a second-level label is a child node of a selected first-level label, and whether a third-level label is a child node of a selected second-level label; hierarchical integrity check checks for breaks or skips in the output path; mutual exclusion rule check checks for violations of mutual exclusion rules between multiple labels; required field check checks whether the entity or field required by the current label appears in the input text; scope of application check checks whether the applicable region, business channel, and event type of the label are consistent with the context; confidence threshold check checks whether the confidence level at each level meets the output requirements; and multi-round consistency check, in optional implementations, provides secondary prompts or multiple samples for low-confidence results and compares the consistency of results across multiple rounds.
[0108] Furthermore, when a verification failure is detected, one or more of the following corrective methods can be used to rectify the issue: recalling and sorting candidate labels within the current parent scope, removing conflicting labels from the candidate label set and then re-invoking the large language model, reducing the confidence of conflicting labels, falling back to the parent label as the final output, outputting the candidate label set and marking it as requiring manual review, triggering the manual review process, and recording erroneous samples as subsequent optimization data.
[0109] Based on this, the large language model advances layer by layer in the prediction process, so that the classification prediction at each level is constrained by the classification constraints of the previous level, ensuring the consistency of the parent-child label relationship, avoiding mismatch between the first-level label and the second-level and third-level labels, and effectively improving the accuracy of classification prediction.
[0110] Figure 9 A flowchart illustrating a classification result generation method provided in an embodiment of this application is shown. (Refer to...) Figure 9 As shown, step S104 above generates and outputs the classification results corresponding to the text to be classified based on the classification results and confidence scores of each classification level. Specifically, it includes the following steps: S901. Based on the classification labels corresponding to each classification level, generate the classification results of the text to be classified.
[0111] The classification results include at least one level of classification results.
[0112] Optionally, after deduplication and verification of the classification labels corresponding to each classification level predicted by the large language model, the classification labels corresponding to each classification level are combined according to the hierarchical relationship to obtain the complete classification result.
[0113] S902. Determine the overall confidence level based on the confidence level of the classification labels corresponding to each classification level.
[0114] Optionally, the large language model outputs the confidence score of the classification label while predicting it. Based on the confidence score (Confidence_llm), it integrates confidence signals from multiple sources to calculate a comprehensive confidence score to determine the final classification result output strategy. These multiple confidence signals include, but are not limited to: comprehensive recall score (Score_recall), business rule hit strength (Rule_strength), label path consistency verification score (Path_consistency), textual evidence coverage of the label definition (Evidence_coverage), and multi-round inference result consistency (Multi_round_consistency).
[0115] For example, the overall confidence score Confidence_final is calculated as follows: Confidence_final = w1 × Confidence_llm + w2 × Score_recall + w3 × Rule_strength + w4 × Path_consistency + w5 × Evidence_coverage + w6 × Multi_round_consistency. Where w1, w2, w3, w4, w5, and w6 are configurable weights.
[0116] S903. Determine a classification result output strategy based on the comprehensive confidence level.
[0117] Optionally, the classification result output strategy is determined based on preset service thresholds including an upper threshold T_high and a lower threshold T_mid, in combination with the comprehensive confidence Confidence_final.
[0118] Exemplarily, if Confidence_final≥T_high, the classification result output strategy is determined to output a complete multi-level label path; if T_mid≤Confidence_final<T_high, the classification result output strategy is determined to output a higher-level label, accompanied by candidate labels and a manual review mark; if Confidence_final<T_mid, the classification result output strategy is determined to reject recognition or output a candidate label set, waiting for manual confirmation.
[0119] S904. Output the classification result of the to-be-classified text according to the classification result output strategy.
[0120] Optionally, after the classification result output strategy is determined, the classification result of the to-be-classified text is output correspondingly according to the classification result output strategy, for example, outputting a complete multi-level label path, or outputting a higher-level label accompanied by candidate labels and a manual review mark, or rejecting recognition or outputting a candidate label set for manual confirmation.
[0121] On this basis, the embodiments of the present application perform deduplication and verification on the prediction result of the large model, which ensures the integrity of the label hierarchy structure and the consistency of service logic, and combines multi-source confidence signals such as recall score, service rule, path consistency, text evidence coverage and multi-round reasoning consistency to avoid the limitation of single model confidence evaluation. Further, the classification result output strategy is dynamically determined in combination with preset service thresholds, which improves the classification processing efficiency while ensuring the classification quality.
[0122] Based on the same inventive concept, the embodiments of the present application further provide a text classification apparatus corresponding to the text classification method. Since the principle of the text classification apparatus in the embodiments of the present application for solving problems is similar to that of the above-mentioned text classification method in the embodiments of the present application, the implementation of the text classification apparatus may refer to the implementation of the text classification method, and repeated parts will not be described again.
[0123] Refer to Figure 10 which is a schematic structural diagram of a text classification apparatus provided in an embodiment of the present application, the text classification apparatus 1000 includes: a first determination module 1001, a second determination module 1002, and a classification module 1003, wherein: The first determining module 1001 is used to obtain the text to be classified and, based on the text to be classified and a pre-built tag tree, determine at least one classification level corresponding to the text to be classified. The tag tree includes multiple tag knowledge nodes arranged in a hierarchical manner, and each tag knowledge node corresponds to a tag. The second determining module 1002 is used to determine the candidate tag set corresponding to each classification level based on a pre-built tag semantic index library. The tag semantic index library is constructed based on a tag tree and includes index records corresponding to multiple tag knowledge nodes. The index records include at least the tag semantic vectors corresponding to the tag knowledge nodes. The classification module 1003 is used to call the large language model according to the text to be classified and the candidate label set corresponding to each classification level, and the large language model predicts the classification label and confidence level corresponding to each classification level. The generation module 1004 is used to generate and output the classification results corresponding to the text to be classified based on the classification labels and confidence scores corresponding to each classification level.
[0124] Based on this, the text classification device according to the embodiments of this application performs hierarchical positioning of the text to be classified based on a tag tree, determines the hierarchical dimension of the text to be classified, and obtains at least one level to be classified. Then, using a tag semantic index library built based on the tag tree, it performs precise vectorized retrieval for each level to be classified, and selects a set of candidate tags that meet the hierarchical constraints of each level to be classified from the full set of tags. This allows the subsequent large language model to predict the classification tags only from this set of candidate tags, effectively narrowing the search range and avoiding noise interference caused by full search. During the prediction process of the large language model, it performs layer-by-layer constrained prediction by combining the text to be classified with the selected set of candidate tags, outputting the classification tags and confidence scores corresponding to each level to be classified, and then generating the final classification result based on the prediction results and confidence scores of each level to be classified. In this way, this application transforms the complex global classification into a multi-level layer-by-layer analysis, which significantly reduces the inference complexity of the large language model while ensuring that the tag prediction strictly follows the hierarchical and constraint relationships of the tag tree. This effectively solves the problem of inaccurate classification results caused by tag conflicts and inference biases in the prior art, and significantly improves the accuracy of the classification results.
[0125] In one possible implementation, the first determining module 1001 is specifically used for: Obtain the contextual information of the text to be classified; Based on the text to be classified and its contextual information, a standardized text to be classified is generated. Feature extraction is performed on the standardized text to be classified, and text vectors corresponding to the standardized text to be classified are generated. Calculate the similarity between the text vector corresponding to the standardized text to be classified and each tag knowledge node in the tag tree, and take the tag knowledge node with similarity greater than a preset threshold as the target node; The classification level is determined based on the hierarchical information of the target node in the tag tree.
[0126] In one possible implementation, the text classification device further includes a construction module, which is specifically used for: The raw tag data is obtained from multiple business data sources. The raw tag data includes multiple tags and attribute information of the tags. The attribute information of each tag is standardized according to the preset mapping strategy to obtain the standardized attribute information of each tag; Multiple tag knowledge nodes are determined based on multiple tags, and the hierarchical relationship between tag knowledge nodes is determined based on the standardized attribute information of each tag. A tag tree is constructed based on the hierarchical relationship between the knowledge nodes of each tag.
[0127] In one possible implementation, the above-mentioned building module is specifically used for: Based on the data structure information of each tag knowledge node in the tag tree, generate tag knowledge text corresponding to each tag knowledge node; Encode the tag knowledge text corresponding to each tag knowledge node to generate a tag semantic vector corresponding to each tag knowledge node; Based on the data structure information, tag knowledge text, and tag semantic vector of each tag knowledge node, an index record corresponding to each tag knowledge node is generated, and the level of each index record is determined. According to the hierarchy of each index record, add the index records corresponding to each tag knowledge node to the tag semantic index library.
[0128] In one possible implementation, the second determining module 1002 described above is specifically used for: Based on the level identifier of each level to be classified, determine the candidate search range corresponding to each level to be classified in the tag semantic index library. The candidate search range includes the index records corresponding to multiple target tag knowledge nodes. The candidate tag set corresponding to each classification level is determined from the candidate search range corresponding to each classification level in the tag semantic index library.
[0129] In one possible implementation, the second determining module 1002 described above is specifically used for: Based on the level identifier of each level to be classified, determine the parent label corresponding to each level to be classified; Based on each classification level, its corresponding parent label, and the level of each index record in the label semantic index, determine the candidate search range for each classification level in the label semantic index.
[0130] In one possible implementation, the second determining module 1002 described above is specifically used for: Obtain the tag semantic vector corresponding to each target tag knowledge node from the index record corresponding to each target tag knowledge node, and calculate the vector similarity between the tag semantic vector corresponding to each target tag knowledge node and the text vector corresponding to the text to be classified. Based on the vector similarity between the semantic vector of each target tag knowledge node and the text vector of the text to be classified, the target tags corresponding to each target tag knowledge node are sorted, and a preset number of target tags are selected according to the sorting order. Add a preset number of target tags to the candidate tag set corresponding to the classification level.
[0131] In one possible implementation, the classification module 1003 is specifically used for: Based on the text to be classified, the context information of the text to be classified, and the candidate tag set corresponding to the classification level, construct the prompt words corresponding to the classification level; The prompt words are input into the large language model, which then predicts the classification label and confidence level corresponding to the classification level based on the prompt words. The classification label is the classification label in the candidate label set corresponding to the classification level.
[0132] In one possible implementation, the above-mentioned generation module 1004 is specifically used for: Based on the classification labels corresponding to each classification level, generate classification results for the text to be classified, including classification results for at least one level. The overall confidence level is determined based on the confidence level of the classification labels corresponding to each classification level. Based on the overall confidence level, determine the strategy for outputting classification results; Output the classification results of the text to be classified according to the classification result output strategy.
[0133] The processing flow of each module in the device and the interaction flow between each module can be referred to the relevant descriptions in the above method embodiments, and will not be detailed here.
[0134] This application also provides an electronic device 1100, such as... Figure 11The diagram shown is a structural schematic of an electronic device 1100 provided in an embodiment of this application. It includes a processor 1101 and a memory 1102, and optionally, a bus 1103. The memory 1102 stores machine-readable instructions executable by the processor 1101. When the electronic device 1100 is running, the processor 1101 and the memory 1102 communicate via the bus 1103. When the machine-readable instructions are executed by the processor 1101, they perform the steps of the text classification method described in any of the preceding claims.
[0135] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the text classification method described in any of the preceding claims.
[0136] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the method embodiments, and will not be repeated here. In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection can be through some communication interfaces; the indirect coupling or communication connection of devices or modules can be electrical, mechanical, or other forms.
[0137] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, 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 this invention. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.
[0138] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A text classification method, characterized in that, include: Obtain the text to be classified, and based on the text to be classified and a pre-built tag tree, determine at least one classification level corresponding to the text to be classified. The tag tree includes multiple tag knowledge nodes arranged in a hierarchical manner, and each tag knowledge node corresponds to a tag. The candidate tag set corresponding to each classification level is determined based on a pre-built tag semantic index library. The tag semantic index library is constructed based on the tag tree. The tag semantic index library includes index records corresponding to multiple tag knowledge nodes. The index records include at least the tag semantic vector corresponding to the tag knowledge node. Based on the text to be classified and the candidate label set corresponding to each classification level, a large language model is invoked to predict the classification label and confidence level corresponding to each classification level. The classification results corresponding to the text to be classified are generated and output based on the classification labels and confidence scores of each classification level.
2. The method according to claim 1, characterized in that, The step of determining at least one classification level corresponding to the text to be classified based on the text to be classified and a pre-constructed tag tree includes: Obtain the context information of the text to be classified; Based on the text to be classified and its context information, a standardized text to be classified is generated. Feature extraction is performed on the standardized text to be classified to generate a text vector corresponding to the standardized text to be classified. Calculate the similarity between the text vector corresponding to the standardized text to be classified and each tag knowledge node in the tag tree, and take the tag knowledge node with a similarity greater than a preset threshold as the target node; The classification level is determined based on the hierarchical information of the target node in the tag tree.
3. The method according to claim 1, characterized in that, The tag tree is constructed based on the following method: The raw tag data is obtained from multiple business data sources, and the raw tag data includes multiple tags and attribute information of the multiple tags; The attribute information of each tag is standardized according to a preset mapping strategy to obtain the standardized attribute information of each tag. Multiple tag knowledge nodes are determined based on the multiple tags, and the hierarchical relationship between the tag knowledge nodes is determined based on the standardized attribute information of each tag. The tag tree is constructed based on the hierarchical relationship between the knowledge nodes of each tag.
4. The method according to claim 1, characterized in that, The tag semantic index library is constructed based on the following method: Based on the data structure information of each tag knowledge node in the tag tree, generate tag knowledge text corresponding to each tag knowledge node; Encode the tag knowledge text corresponding to each tag knowledge node to generate a tag semantic vector corresponding to each tag knowledge node; Based on the data structure information of each of the tag knowledge nodes, the tag knowledge text, and the tag semantic vector, an index record corresponding to each of the tag knowledge nodes is generated, and the level of each index record is determined. According to the hierarchy of each index record, the index records corresponding to each of the aforementioned tag knowledge nodes are added to the tag semantic index library.
5. The method according to claim 1, characterized in that, The process of determining the candidate tag set corresponding to each classification level based on a pre-built tag semantic index library includes: Based on the level identifier of each level to be classified, determine the candidate search range corresponding to each level to be classified in the tag semantic index library, wherein the candidate search range includes index records corresponding to multiple target tag knowledge nodes; The candidate tag set corresponding to each of the classification levels is determined from the candidate search range corresponding to each of the classification levels in the tag semantic index library.
6. The method according to claim 5, characterized in that, The step of determining the candidate search range corresponding to each of the unclassified levels in the tag semantic index based on the level identifier of each unclassified level includes: Based on the level identifier of each level to be classified, determine the parent label corresponding to each level to be classified; Based on each of the levels to be classified, the parent tags corresponding to each level to be classified, and the levels of each index record in the tag semantic index library, the candidate search range corresponding to each level to be classified in the tag semantic index library is determined.
7. The method according to claim 5, characterized in that, The step of determining the candidate tag set corresponding to each of the classification levels from the candidate search range corresponding to each of the classification levels in the tag semantic index library includes: Obtain the tag semantic vector corresponding to each target tag knowledge node from the index record corresponding to each target tag knowledge node, and calculate the vector similarity between the tag semantic vector corresponding to each target tag knowledge node and the text vector corresponding to the text to be classified. Based on the vector similarity between the semantic vector of each target tag knowledge node and the text vector of the text to be classified, the target tags corresponding to each target tag knowledge node are sorted, and a preset number of target tags are selected according to the sorting order. Add a preset number of target tags to the candidate tag set corresponding to the classification level.
8. The method according to claim 1, characterized in that, The step of calling a large language model based on the text to be classified and the candidate label set corresponding to each classification level, and predicting the classification label and confidence score corresponding to each classification level by the large language model, includes: Based on the text to be classified, the context information of the text to be classified, and the candidate tag set corresponding to the classification level, construct the prompt words corresponding to the classification level; The prompt word is input into the large language model, which then predicts the classification label and confidence level corresponding to the level to be classified based on the prompt word. The classification label is the classification label in the candidate label set corresponding to the level to be classified.
9. The method according to claim 1, characterized in that, The step of generating and outputting the classification result corresponding to the text to be classified based on the classification result and confidence score corresponding to each of the classification levels includes: Based on the classification labels corresponding to each of the classification levels, a classification result for the text to be classified is generated, wherein the classification result includes at least one level of classification result; The overall confidence level is determined based on the confidence level of the classification labels corresponding to each of the classification levels. Based on the comprehensive confidence level, determine the strategy for outputting the classification results; The classification result of the text to be classified is output according to the classification result output strategy.
10. An electronic device, characterized in that, include: A processor and a memory, the memory storing machine-readable instructions executable by the processor, which, when the electronic device is running, are executed by the processor to perform the steps of the text classification method as described in any one of claims 1 to 9.
