Text classification method and device, computer readable storage medium and terminal

By adding prompt text to the training data of the text classification model and using category tag set to correct the results, the problem of inaccurate output of text classification models in the prior art is solved, and the accuracy and user experience of text classification results are improved.

CN119202242APending Publication Date: 2024-12-27SHANGHAI XIAOI ROBOT TECH CO LTD +1
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202310764161.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-26
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

Existing text classification models often fail to output accurate results that meet expectations when applied, resulting in a degradation of user experience.

Method used

By adding prompt text to the training dataset, clarifying the target tasks of the model, and using preset loss functions for iterative training, the text classification model is optimized; using the category label set in the classification results for correction, combining string matching, word participle matching and semantics Feature similarity improves the accuracy of the results.

Benefits of technology

It improves the predictability and accuracy of text classification results, avoids inaccurate results caused by model inference errors, and enhances the accuracy of classification results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119202242A_ABST
    Figure CN119202242A_ABST
Patent Text Reader

Abstract

The invention discloses a text classification method and device, a computer readable storage medium and a terminal, and the method comprises the steps: constructing a training data set, the training data set comprises multiple pieces of text data, and each piece of text data comprises an original text, a prompt text and a category label of the original text; inputting the training data set into an initialized text classification model for iterative training by adopting a preset loss function to obtain an optimized text classification model; inputting a to-be-classified text into the optimized text classification model to obtain a text classification result; wherein the prompt text is used for indicating the training data set and a target task of the initialized text classification model. By adopting the scheme, the predictability and the accuracy of the obtained text classification result can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of text classification, and in particular to a text classification method and device, a computer-readable storage medium, and a terminal. Background Art

[0002] Text classification is one of the more common task types in text processing technology. It is widely used in various fields, such as entity recognition, spam filtering, news classification, part-of-speech tagging, etc.

[0003] In the existing related technologies, when implementing text classification, a large number of sample texts are usually annotated first to obtain sample text data and their corresponding text category labels to construct a training data set; then a supervised training method is used to input the training data set into the model to be trained to obtain a trained text classification model. In this way, the text to be classified is input into the trained optimized text classification model to achieve automatic classification of text.

[0004] However, due to the inherent characteristics of the existing model or the model training data, when the trained text classification model is applied to the text classification process, it may fail to output the expected and accurate text classification results. For example, after the text to be classified is input into the trained text classification model, the output result obtained is the text summary or keywords, which reduces the user experience. Summary of the invention

[0005] The technical problem solved by the embodiments of the present invention is how to improve the predictability and accuracy of the obtained text classification results.

[0006] To solve the above technical problems, an embodiment of the present invention provides a text classification method, comprising the following steps: constructing a training data set, wherein the training data set includes multiple text data, each text data includes an original text, a prompt text, and a category label of the original text; using a preset loss function, inputting the training data set into an initialized text classification model for iterative training to obtain an optimized text classification model; inputting the text to be classified into the optimized text classification model to obtain a text classification result; wherein the prompt text is used to indicate the target task of the training data set and the initialized text classification model.

[0007] Optionally, each piece of text data in the training data set is obtained by concatenating the original text, the prompt text and the category label of the original text.

[0008] Optionally, the prompt text includes a prompt word, and there is a many-to-one or one-to-one relationship between the prompt word and the target task.

[0009] Optionally, the loss function is expressed by the following expression:

[0010]

[0011]

[0012] Among them, L generate represents the loss function, W represents the total number of characters included in the original category label, w represents the character sequence number in the original category label, V represents the total number of characters included in the character set, v represents the character sequence number in the character set, represents the coefficient of the w-th character in the original category label, when the w-th character is the v-th character in the character set, The value of is 1, otherwise The value of p is 0, wv represents the probability that the wth character in the current predicted label is the vth character in the character set, Represents the state matrix output after the w-th character of the original category label is input into the initialized text classification model.

[0013] Optionally, the initialized text classification model is selected from: a second-generation GPT model, a third-generation GPT model, a fourth-generation GPT model, and a Bloom model.

[0014] Optionally, inputting the text to be classified into the optimized text classification model to obtain a text classification result, including: performing at least one round of iteration based on the text to be classified and the optimized text classification model to obtain the text classification result; wherein the iterative process includes: in a first round of iteration, inputting the text to be classified into the optimized text classification model to obtain the text category characters of the first round; in each subsequent round of iteration, concatenating the text to be classified and the text category characters obtained in the previous rounds, inputting the optimized text classification model to obtain the text category characters of the current round, if the text category characters of the current round are inconsistent with the preset stop characters, continuing the next round of iteration until the text category characters obtained in the current round are consistent with the stop characters; and taking the concatenation results of the text category characters obtained in the remaining rounds except the last round as the text classification result.

[0015] Optionally, after obtaining the text classification result, the method further includes: correcting the text classification result based at least on a first category label set; wherein the first category label set is a set of category labels of each original text in the training data set.

[0016] Optionally, the text classification result is corrected based on at least the first category label set, including: respectively determining the maximum number of consecutive identical characters between the text classification result and each category label in the first category label set, and recording them as the number of identical characters; if the maximum number of identical characters is greater than or equal to a first preset number, then taking the category label to which the maximum number of identical characters belongs as the corrected text classification result.

[0017] Optionally, the method also includes: if the maximum number of identical characters is less than the first preset number, correcting the text classification result based on the similarity between the semantic features of the text classification result and the semantic features of each category label in the second category label set; wherein the second category label set includes the first category label set and its corresponding extended category label set, and each category label in the first category label set is expanded to one or more category labels in the extended category label set.

[0018] Optionally, the first preset number is determined according to the total number of characters included in the text classification result, and the larger the total number of characters is, the larger the first preset number is.

[0019] The correcting of the text classification result based at least on the first category label set includes: performing word segmentation processing on the text classification result and each category label in the first category label set respectively to obtain a first word segmentation result of the text classification result and a second word segmentation result of each category label; for each second word segmentation result, determining the number of identical word segmentations between the second word segmentation result and the first word segmentation result; determining the ratio of the number of identical word segmentations to the total number of word segmentations in the first word segmentation result as the precision rate, and determining the ratio of the number of identical word segmentations to the total number of word segmentations in the second word segmentation result as the recall rate; determining the F1 score of the category label to which each second word segmentation result belongs according to the precision rate and the recall rate; if the maximum F1 score among the category labels is greater than or equal to the preset score, taking the category label to which the maximum F1 score belongs as the corrected text classification result.

[0020] Optionally, the method also includes: if the maximum F1 score is less than the preset score, correcting the text classification result based on the similarity between the semantic features of the text classification result and the semantic features of each category label in a second category label set; wherein the second category label set includes the first category label set and its corresponding extended category label set, and each category label in the first category label set is expanded to one or more category labels in the extended category label set.

[0021] Optionally, the text classification result is corrected based on the similarity between the semantic features of the text classification result and the semantic features of each category label in the second category label set, including: determining the semantic features of the text classification result, recorded as first semantic features, and determining the semantic features of each category label in the second category label set, recorded as second semantic features; respectively determining the similarity between the first semantic feature and each second semantic feature; determining, in the second category label set, the category label with the greatest similarity to the first semantic feature; and determining a corrected text classification result based on the category label with the greatest similarity.

[0022] Optionally, determining a corrected text classification result based on the category label with the greatest similarity includes: if the category label with the greatest similarity belongs to the first category label set, using the category label with the greatest similarity as the corrected text classification result; if the category label with the greatest similarity belongs to the extended category label set, using the category label corresponding to the category label with the greatest similarity in the first category label set as the corrected text classification result.

[0023] An embodiment of the present invention also provides a text classification device, including: a training data set determination module, used to construct a training data set, the training data set includes multiple text data, each text data includes an original text, a prompt text and a category label of the original text; a model training module, used to use a preset loss function to input the training data set into an initialized text classification model for iterative training to obtain an optimized text classification model; a text classification module, used to input the text to be classified into the optimized text classification model to obtain a text classification result; wherein the prompt text is used to indicate the target task of the training data set and the initialized text classification model.

[0024] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned text classification method are executed.

[0025] An embodiment of the present invention further provides a terminal, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and the processor executes the steps of the above-mentioned text classification method when running the computer program.

[0026] Compared with the prior art, the technical solution of the embodiment of the present invention has the following beneficial effects:

[0027] In practical applications, for some initialization models related to text processing, the target tasks (or functions) that can be achieved may be diverse, including but not limited to text classification, keyword extraction, text summary extraction, automatic question answering, etc. Specifically, the same initialized text processing model can be trained for keyword extraction, trained for text classification, trained for generating text summaries, and so on. Therefore, in the prior art, in the process of text classification using a trained text classification model, it may not be possible to output the expected and accurate text classification results. For example, after the text to be classified is input into a trained text classification model, the output result obtained is a summary or keyword of the text, thereby reducing the user experience.

[0028] To solve the above problems, in an embodiment of the present invention, a prompt text is added on the basis of the original text and its category label to indicate the target task of the training data set and the initialized text classification model. Thus, the model can be trained with the target task indicated by the prompt text as a guide, so that the model training process is more targeted and the training effect meets expectations, which helps to avoid errors such as extracting keywords or generating summaries for the input text to be classified in the subsequent text classification process using the optimized text classification model obtained after training, thereby improving the predictability and accuracy of the text classification results.

[0029] Furthermore, after obtaining the text classification result, the method further includes: correcting the text classification result based on at least a first category label set; wherein the first category label set is a collection of category labels of each original text in the training data set. It can be understood that the process of training the initialized text classification model using a training data set containing category labels is the process of enabling the trained model to learn the mapping relationship between text and text category. The process of using the optimized text classification model obtained after training for reasoning (the reasoning in this embodiment refers to text classification) is the process of the model determining the text category based on the learned mapping relationship.

[0030] Therefore, the inference result of the optimized text classification model (also called text classification result) is actually closely related to the category label set of the training data set used in the training process (i.e., the first category label set). Normally, the inference result of the optimized text classification model will have a high similarity with the category labels in the first category label set, and ideally will be completely consistent with one of the category labels in the first category label set. Based on the foregoing principles, in an embodiment of the present invention, a set of category labels of the training data set of the optimized text classification model (i.e., the first category label set) is used to correct the text classification result output by the optimized text classification model. Compared with the prior art that directly uses the model inference result as the final text classification result, this implementation helps to improve the accuracy of the text classification result.

[0031] Furthermore, in an embodiment of the present invention, after the text to be classified is input into the optimized text classification model and a text classification result is obtained, a text classification result correction scheme based on "string matching" is further provided, and a category label having the largest number of identical characters with the text classification result is determined in the first category label set. It can be understood that the more identical characters there are between the category label and the text classification result output by the model, the greater the possibility that the corresponding category label is a true text classification result.

[0032] From the above, compared with the prior art that directly uses the model inference result as the final text classification result, this embodiment uses the category label to which the largest number of identical characters determined after character matching with the first category label set belongs as the corrected text classification result. In this way, it is possible to avoid using inaccurate text classification results caused by model inference errors as the final text classification results, thereby improving the accuracy of the text classification results.

[0033] Furthermore, in an embodiment of the present invention, a text classification result correction scheme based on "word segmentation matching (or word matching)" is also provided. Specifically, the category label with the largest F1 score with the text classification result is determined in the first category label set. It can be understood that the larger the F1 score, the greater the possibility that the corresponding category label is a true text classification result. Compared with the prior art that directly uses the model reasoning result as the final text classification result, this implementation scheme uses the category label to which the maximum F1 score determined after word segmentation matching with the first category label set belongs as the corrected text classification result. In this way, it is possible to avoid using inaccurate text classification results caused by model reasoning errors as the final text classification results, thereby improving the accuracy of the text classification results.

[0034] Further, in an embodiment of the present invention, if the maximum number of identical characters is less than the first preset number, it means that the number of consecutive identical characters between the text classification result and each category label of the first category label set is small. Alternatively, if the maximum F1 score in each category label is less than the preset score, it means that the number of identical segmented words between the text classification result and each category label of the first category label set is small. However, since the number of consecutive identical characters or the number of identical segmented words can only represent the size of the difference at the level of language expression, in actual applications, for sentences or words with the same or similar semantics, their expressions may not be similar or even completely different (for example, the order of characters or words is inconsistent), resulting in low string matching and segmented word matching, but sentences or words with different expressions may have the same or similar meanings.

[0035] Based on the above reasons, this embodiment further provides a text classification result correction scheme based on semantic feature similarity matching for the case where the text classification result and the string matching degree or word segmentation matching degree of the category label are not high. In this way, the shortcomings of the correction scheme based on "string matching" and the correction scheme based on "word segmentation matching" can be made up to obtain accurate text classification results.

[0036] Furthermore, in an embodiment of the present invention, considering that the same semantics can have a variety of different expressions, therefore, in the process of correcting the text classification results based on "semantic feature similarity", a second category label set is used that is determined by expanding the category labels in the first category label set, that is, the second category label set includes the first category label set and its corresponding extended category label set. In this way, the total number of category labels for semantic feature matching with the text classification results can be expanded, which helps to find category labels with similar semantics, avoid correction errors caused by insufficient number of category labels, and thus improve the accuracy of the corrected text classification results. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 is a flow chart of a text classification method in an embodiment of the present invention;

[0038] Figure 2 is a structural diagram of an initialization text classification model in an embodiment of the present invention;

[0039] Figure 3 is a flow chart of another text classification method in an embodiment of the present invention;

[0040] Figure 4 yes Figure 3 Flow chart of a first specific implementation of step S31;

[0041] Figure 5 yes Figure 3 Flow chart of a second specific implementation of step S31;

[0042] Figure 6 yes Figure 4 A flowchart of a specific implementation of step S44;

[0043] Figure 7 It is a structural schematic diagram of a text classification device in an embodiment of the present invention. DETAILED DESCRIPTION

[0044] In order to make the above-mentioned objects, features and beneficial effects of the present invention more obvious and understandable, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0045] Reference Figure 1 , Figure 1 1 is a flowchart of a text classification method in an embodiment of the present invention. The method may include steps S11 to S13:

[0046] Step S11: constructing a training data set, wherein the training data set includes a plurality of text data, each of which includes an original text, a prompt text, and a category label of the original text;

[0047] Step S12: using a preset loss function, inputting the training data set into the initialized text classification model for iterative training to obtain an optimized text classification model;

[0048] Step S13: input the text to be classified into the optimized text classification model to obtain a text classification result.

[0049] The prompt text is used to indicate the training data set and the target task of the initialized text classification model.

[0050] In the specific implementation of step S11, the category label of each text data can be manually annotated to improve the accuracy of data annotation as much as possible; or, each text data can be input into an existing text classification model to obtain the category label of the input text data to improve the efficiency of annotating the category label as much as possible. Different text data can correspond to the same category label.

[0051] In some embodiments, the category labels may be category labels corresponding to text data in different fields. For example, in the field of entertainment, the category labels may be selected from: music, movies, novels, operas, sketches, games, etc. For another example, in the field of teaching, the category labels may be selected from: Chinese, English, mathematics, history, geography, biology, chemistry, sports, etc.

[0052] In other embodiments, the category labels may also be category labels corresponding to text data of different branches in the same field. For example, in the field of games, text data of different game types (or game branches) may have their own corresponding category labels, which may be selected from: fighting games, makeup (dress-up) games, intellectual games, etc. For another example, in the field of novels, text data of novels from different countries may have their own corresponding category labels, which may be selected from: Chinese novels, British novels, American novels, French novels, etc.

[0053] Furthermore, each piece of text data in the training data set is obtained by concatenating the original text, the prompt text and the category label of the original text.

[0054] In a specific implementation, for each piece of text data, the concatenation order of the original text, the prompt text, and the category label can be original text + prompt text + category label, or prompt text + original text + category label, or other appropriate concatenation order. The embodiment of the present invention does not limit the concatenation order of the three in each piece of text data, as long as it is conducive to the output of the optimized text classification model after training to meet the expected text classification results.

[0055] In a specific implementation, the prompt text may include prompt words, and there is a many-to-one or one-to-one relationship between the prompt words and the target task. For example, for the target task of "text classification", the corresponding prompt words may be selected from: "text classification", "text category", and "text label".

[0056] In the embodiment of the present invention, the use of prompt words helps to more clearly and accurately indicate the target task of the training data set and the initialized text classification model, thereby ensuring the predictability of the model training effect.

[0057] In a specific embodiment, the text data in the training data set may be expressed as follows: "Have Zhang San and Li Si ever participated in a fight? What category is described in this text? Game". The original text is "Have Zhang San and Li Si ever participated in a fight?", the prompt text is "What category is described in this text?" (where the prompt word is "category"), and the category label is "game".

[0058] In another specific embodiment, during the splicing process, the order of the original text and the prompt text can be adjusted. For example, the presentation form of the text data can also be as follows: "What is the text category of this text? Have Zhang San and Li Si participated in a fight? Game".

[0059] It should be pointed out that the names and contents contained in the above original text are only non-limiting examples. In specific implementations, the original text can be selected or set in combination with actual application scenarios.

[0060] Furthermore, the prompt words contained in the prompt text in the text data and the expression of the prompt text are not limited to the expression provided in the above embodiment. The text design and language organization can be appropriately adjusted without departing from the target task that the training model of the training data set should achieve. For example, for the target task of text classification, the corresponding prompt text can also be expressed as "What is the label of this text?" (where the prompt word is "label"), "What is the text category of this paragraph" (where the prompt word is "text category"), "What is the text category of this paragraph" (where the prompt word is "text category"), and so on.

[0061] It is understandable that in practical applications, for some initialization models related to text processing, the target tasks (or functions) that can be achieved may be diverse, including but not limited to text classification, keyword extraction, text summary extraction, automatic question answering, etc. Specifically, the same initialized text processing model can be trained for keyword extraction, trained for text classification, trained for generating text summaries, and so on. Therefore, in the prior art, in the process of text classification using a trained text classification model, it may not be possible to output the expected and accurate text classification results. For example, after the text to be classified is input into a trained text classification model, the output result obtained is a summary or keyword of the text, thereby reducing the user experience.

[0062] To solve the above problems, in an embodiment of the present invention, a prompt text is added on the basis of the original text and its category label to indicate the target task of the training data set and the initialized text classification model. Thus, the model can be trained with the target task indicated by the prompt text as a guide, so that the model training process is more targeted and the training effect meets expectations, which helps to avoid errors such as extracting keywords or generating summaries for the input text to be classified in the subsequent text classification process using the optimized text classification model obtained after training, thereby improving the predictability and accuracy of the text classification results.

[0063] In the specific implementation of step S12, a preset loss function is used to input the training data set into the initialized text classification model for iterative training to obtain an optimized text classification model.

[0064] Reference Figure 2 , Figure 2 It is a structural diagram of an initialization text classification model in an embodiment of the present invention.

[0065] The initialized text classification model can adopt a decoder-based model, including but not limited to the second-generation generative pre-trained transformation model (Generative Pre-Trained Transformer 2, referred to as GPT2), the third-generation generative pre-trained transformation model (Generative Pre-Trained Transformer 3, referred to as GPT3), the fourth-generation generative pre-trained transformation model (Generative Pre-Trained Transformer 4, referred to as GPT4), the large language model Bloom, etc.

[0066] The initialized text classification model may include a decoder transformer layer 21 and may also include a tokenizer 22 . The decoder transformer layer 21 may be arranged after the tokenizer 22 .

[0067] The tokenizer 22 includes a class for vectorizing text or converting text into a sequence (i.e., decomposing a text stream into tokens, each token being usually a subsequence of characters in the text); the decoder conversion layer 21 is used to decode the input data. For example, the vector or word sequence (or character sequence) output by the tokenizer 22 may be decoded to obtain decoded data.

[0068] After the decoder transformer layer 21, other appropriate hierarchical structures (not shown) may be included to post-process the decoded data to obtain text classification results (or text category characters).

[0069] Furthermore, the loss function is expressed by the following expression:

[0070]

[0071]

[0072] Among them, L generate represents the loss function, W represents the total number of characters included in the original category label, w represents the character sequence number in the original category label, V represents the total number of characters included in the character set, v represents the character sequence number in the character set, represents the coefficient of the w-th character in the original category label, when the w-th character is the v-th character in the character set, The value of is 1, otherwise The value of p is 0, wvrepresents the probability that the wth character in the current predicted label is the vth character in the character set, Represents the state matrix output after the w-th character of the original category label is input into the initialized text classification model.

[0073] In the specific implementation of step S13, the text to be classified is input into the optimized text classification model to obtain a text classification result.

[0074] It is understandable that, since each text data in the training data set used in the model training process is obtained by splicing the original text and the prompt text, when the optimized text classification model is used for model reasoning or application, the text to be classified is also preferably obtained by splicing the original text and the prompt text. In this way, the consistency of the data form of the model training process and the reasoning process can be maintained, and the accuracy of the text classification result can be improved.

[0075] Furthermore, the step S13 (model inference process) may specifically include: performing at least one round of iteration based on the text to be classified and the optimized text classification model to obtain the text classification result;

[0076] The iterative process includes: in a first round of iteration, the text to be classified is input into the optimized text classification model to obtain the text category characters of the first round; in each subsequent round of iteration, the text to be classified and the text category characters obtained in the previous rounds are concatenated and input into the optimized text classification model to obtain the text category characters of the current round. If the text category characters of the current round are inconsistent with the preset stop characters, the next round of iteration is continued until the text category characters obtained in the current round are consistent with the stop characters; the concatenation results of the text category characters obtained in the remaining rounds except the last round are used as the text classification results.

[0077] Combination Figure 2 ( Figure 2(Shown as (1), (2), and (3) in the figure respectively represent the first round to the third round of iterations), the decoding end symbol can be represented by SEP. During the model inference process using the optimized text classification model obtained after training, in the first round of iteration, the text to be classified (i.e., the original text + the prompt text) is input into the optimized text classification model to obtain the text category character "You" in the first round; in the second round of iteration, the concatenation result of the text to be classified and the character "You" (original text + prompt text + You) is input into the optimized text classification model to obtain the text category character "Xi" in the current round; in the third round of iteration, the concatenation result of the text to be classified and the characters "You" and "Xi" (original text + prompt text + You + Xi) is input into the optimized text classification model to obtain the text category character "SEP" in the current round, which is consistent with the preset stop character. At this time, the iteration stops, and the concatenation result of the text category characters obtained in each round except the last round ("YouXi") is used as the text classification result.

[0078] In the embodiment of the present invention, during the text classification process using the optimized text classification model, the data input in each round of iteration not only includes the text to be classified (i.e., the original text + the prompt text), but also includes the concatenation result of the text category characters obtained in the previous rounds. Thus, it is possible to provide guidance for the model inference process in the current round based on the model output results obtained in the previous rounds, reduce the probability of errors in the current round of inference, and further improve the accuracy of the output results obtained in each round of iteration.

[0079] Refer to Figure 3 , Figure 3 is a flowchart of another text classification method in the embodiment of the present invention. The another text classification method may include Figure 1 the steps S11 to S13 in the embodiment shown, and may also include step S31, where step S31 may be executed after step S13. The following describes the differences from Figure 1 are described.

[0080] In step S31, correct the text classification result at least based on the first category label set; where the first category label set is a set of category labels of each original text in the training dataset.

[0081] Specifically, the first category label set is a set of category labels of each original text included in the training dataset. As a non-limiting embodiment, the category labels of each original text included in the training dataset include the following items: music, movie, novel, opera, skit, game, then the first category label set is {music, movie, novel, opera, skit, game}.

[0082] It is understandable that the process of training the initialized text classification model using a training data set containing category labels is the process of enabling the trained model to learn the mapping relationship between text and text category. The process of using the optimized text classification model obtained after training for reasoning (the reasoning described in this embodiment refers to text classification) is the process of the model determining the text category based on the learned mapping relationship. Therefore, the reasoning result of the optimized text classification model (also referred to as the text classification result) is actually closely related to the category label set (i.e., the first category label set) of the training data set used in the training process. Normally, the reasoning result of the optimized text classification model will have a high similarity with the category labels in the first category label set, and ideally will be completely consistent with one of the category labels in the first category label set.

[0083] Based on the above principles, in an embodiment of the present invention, a set of category labels of the training data set of the optimized text classification model (i.e., the first category label set) is used to correct the text classification results output by the optimized text classification model. Compared with the prior art that directly uses the model inference results as the final text classification results, this implementation helps to improve the accuracy of the text classification results.

[0084] Reference Figure 4 , Figure 4 yes Figure 3 Flow chart of a first specific implementation of step S31 in FIG. In the first specific implementation, step S31 may specifically include steps S41 to S44.

[0085] In step S41, the number of consecutive identical characters between the text classification result and the maximum number of each category label in the first category label set is determined respectively, and recorded as the number of identical characters.

[0086] In a specific implementation, a string matching method may be used to determine the number of consecutive identical characters.

[0087] It is understandable that, for each category label in the first category label set, there may be multiple cases where the text classification result and the category label have consecutive identical characters. In this case, the number of consecutive identical characters is determined respectively, and then the maximum value is selected as the number of identical characters. It should be noted that, for the case where there is only one identical character, the value of the number of consecutive identical characters is 1.

[0088] For example, if a category label is "French novel" and the text classification result is "Chinese Novel", there are two cases of consecutive identical characters between the two, namely, "" (space) (the number of consecutive identical characters is 1) and "ovel" (the number of consecutive identical characters is 4). Therefore, for "Frenchnovel" and "Chinese Novel", the maximum number of consecutive identical characters is 4, that is, the number of identical characters is 4.

[0089] For example, if a category label is "battle game" and the text classification result is "game", there is one case where there are two consecutive identical characters between the two, namely, "game". Therefore, for "battle game" and "game", the maximum number of consecutive identical characters is 2, that is, the number of identical characters is 2.

[0090] In step S42, it is determined whether the maximum number of identical characters is greater than or equal to a first preset number.

[0091] The maximum number of identical characters specifically refers to the maximum value of the number of identical characters between the text classification result and each category label in the first category label set.

[0092] Furthermore, the first preset number is determined according to the total number of characters included in the text classification result, and the larger the total number of characters is, the larger the first preset number is. The first preset number is a positive integer.

[0093] Specifically, the first preset number may be a preset ratio of the total number of characters included in the text classification result. The preset ratio may be appropriately set according to the actual application scenario. It is understandable that the higher the accuracy requirement for the text classification result in the actual application scenario, the larger the preset ratio. In a non-limiting manner, the preset ratio may be selected as an appropriate value in the interval [2 / 3, 1].

[0094] For example, if the total number of characters included in the text classification result is 3, the first preset number can be selected from the interval [2, 3]. For another example, if the product of the total number of characters included in the text classification result and the preset ratio is not an integer, the product can be rounded down to determine the value of the first preset number.

[0095] If the judgment result of step S42 is yes, that is, the maximum number of identical characters is greater than or equal to the first preset number, step S43 is executed;

[0096] If the judgment result of step S42 is no, that is, the maximum number of identical characters is less than the first preset number, step S44 is executed.

[0097] In step S43, the category label to which the maximum number of identical characters belongs is used as the corrected text classification result.

[0098] As described above, according to the principle of the model training process, ideally, the text classification result will be completely consistent with one of the category labels in the first category label set. Based on this, in an embodiment of the present invention, after the text to be classified is input into the optimized text classification model and the text classification result is obtained, a text classification result correction scheme based on "string matching" is further provided to determine the category label with the largest number of identical characters with the text classification result in the first category label set. It can be understood that the more identical characters there are between the category label and the text classification result output by the model, the greater the possibility that the corresponding category label is a true text classification result.

[0099] From the above, compared with the prior art that directly uses the model inference result as the final text classification result, this embodiment uses the category label to which the largest number of identical characters determined after character matching with the first category label set belongs as the corrected text classification result. In this way, it is possible to avoid using inaccurate text classification results caused by model inference errors as the final text classification results, thereby improving the accuracy of the text classification results.

[0100] In step S44, the text classification result is corrected based on the similarity between the semantic feature of the text classification result and the semantic feature of each category label in the second category label set.

[0101] The second category tag set includes the first category tag set and its corresponding extended category tag set, and each category tag in the first category tag set is extended to one or more category tags in the extended category tag set.

[0102] In a specific implementation, each category tag in the first category tag set is expanded, which specifically means: without changing the semantics (or meaning) of the category tag, the expression of the category tag is appropriately adjusted or converted. For example, if the category tag is "poetry collection", it can be expanded to "poetry collection". For another example, if the category tag is "battle game", it can be expanded to "war game" or "fighting game" or "war game", etc.

[0103] It is understandable that when the maximum number of identical characters is less than the first preset number, it means that the number of consecutive identical characters between the text classification result and each category label of the first category label set is small. However, since the number of consecutive identical characters can only represent the difference in language expression, in actual applications, for sentences or words with the same or similar semantics, their expressions may be dissimilar or even completely different (for example, the order of characters or words is inconsistent), resulting in a low string matching degree, but the meanings of sentences or words with different expressions can be the same or close.

[0104] Based on the above principle, in the embodiment of the present invention, for the case where the text classification result and the string matching degree of the category label are not high, a text classification result correction scheme based on "semantic feature similarity" is further provided. In this way, the shortcomings of the correction scheme based on "string matching" can be compensated and accurate text classification results can be obtained.

[0105] Reference Figure 5 , Figure 5 yes Figure 3 Flow chart of a second specific implementation of step S31 in FIG. In the second specific implementation, step S31 may specifically include steps S51 to S57.

[0106] In step S51, word segmentation processing is performed on the text classification result and each category label in the first category label set to obtain a first word segmentation result of the text classification result and a second word segmentation result of each category label.

[0107] In step S52, for each second word segmentation result, the number of identical word segmentations between the second word segmentation result and the first word segmentation result is determined.

[0108] In step S53, the ratio of the number of identical segmentations to the total number of segmentations in the first segmentation result is determined as the precision, and the ratio of the number of identical segmentations to the total number of segmentations in the second segmentation result is determined as the recall.

[0109] In step S54, the F1 scores of the category labels to which the second word segmentation results belong are determined respectively according to the precision and the recall.

[0110] Specifically, the F1 score (F1 score) may be determined by using the following formula: F1 score=(2×recall rate×precision rate) / (recall rate+precision rate).

[0111] The F1 score can be used to characterize the degree of word matching between the text classification result and the category label in the first category label set. The larger the F1 score, the higher the word matching between the two. The F1 score takes into account both precision and recall, and can be regarded as a harmonic average of the model's precision and recall. Its maximum value is 1 and its minimum value is 0.

[0112] In step S55, it is determined whether the maximum F1 score among the class labels is greater than or equal to a preset score.

[0113] If the judgment result is yes, that is, the maximum F1 score among the category labels is greater than or equal to the preset score, step S56 is executed.

[0114] If the judgment result is no, that is, the maximum F1 score among the category labels is less than the preset score, step S57 is executed.

[0115] In step S56, the category label to which the maximum F1 score belongs is used as the corrected text classification result.

[0116] Specifically, the category label to which the maximum F1 score belongs refers to the category label in the first category label set that has the maximum F1 score between the word segmentation result of the text classification result.

[0117] In a specific implementation, the preset score can be appropriately set according to the actual application scenario. It is understandable that the higher the accuracy requirement for the text classification result, the larger the preset score can be set. In a non-limiting manner, the preset score can be selected from an appropriate value in the interval [0.6, 0.9].

[0118] As described above, according to the principle of the model training process, ideally, the text classification result will be completely consistent with one of the category labels in the first category label set. Based on this, in an embodiment of the present invention, after the text to be classified is input into the optimized text classification model and the text classification result is obtained, a text classification result correction scheme based on "word segmentation matching (or word matching)" is further provided, and the category label with the largest F1 score with the text classification result is determined in the first category label set. It can be understood that the larger the F1 score, the greater the possibility that the corresponding category label is a true text classification result.

[0119] From the above, compared with the prior art that directly uses the model inference result as the final text classification result, this embodiment uses the category label to which the maximum F1 score is determined after word segmentation matching with the first category label set as the corrected text classification result. In this way, it is possible to avoid using inaccurate text classification results caused by model inference errors as the final text classification results, thereby improving the accuracy of the text classification results.

[0120] In step S57, the text classification result is corrected based on the similarity between the semantic feature of the text classification result and the semantic feature of each category label in the second category label set.

[0121] The second category tag set includes the first category tag set and its corresponding extended category tag set, and each category tag in the first category tag set is extended to one or more category tags in the extended category tag set.

[0122] Figure 5 The text classification result correction scheme based on "word segmentation matching" provided in the embodiment shown is similar to Figure 4 The principles of the text classification result correction solutions based on "string matching" provided in the illustrated embodiments are similar, both of which are based on the matching degree at the language expression level, and determine the category label from the first category label set as the text classification result.

[0123] Similarly, when the maximum F1 score among the various category labels is less than the preset score, it means that there are fewer identical segmented words between the text classification result and the various category labels of the first category label set. However, since the number of identical segmented words can only represent the difference in the language expression level, in actual applications, for sentences or words with the same or similar semantics, their expressions may be dissimilar or even completely different (for example, the order of words is inconsistent), resulting in a very low segmented word matching degree, but the meanings of sentences or words with different expressions can be the same or close.

[0124] Based on the above principle, in the embodiment of the present invention, for the case where the text classification result and the word segmentation of the category label do not match well, a text classification result correction scheme based on "semantic feature similarity" is further provided. Thus, the deficiency of the correction scheme based on "word segmentation matching" can be made up and accurate text classification results can be obtained.

[0125] Reference Figure 6 , Figure 6 yes Figure 4 Flow chart of a specific implementation of step S44 in FIG. The step S44 may specifically include steps S61 to S64.

[0126] In step S61, the semantic feature of the text classification result is determined, recorded as the first semantic feature, and the semantic feature of each category label in the second category label set is determined, recorded as the second semantic feature.

[0127] In step S62, the similarity between the first semantic feature and each second semantic feature is determined respectively.

[0128] In a specific implementation, the method for determining the similarity between semantic features may adopt an existing conventional method, for example, a cosine similarity calculation method.

[0129] In step S63, in the second category label set, a category label having the greatest similarity with the first semantic feature is determined.

[0130] In step S64, a corrected text classification result is determined according to the category label with the greatest similarity.

[0131] Furthermore, if the category label with the greatest similarity belongs to the first category label set, the category label with the greatest similarity is used as the corrected text classification result; if the category label with the greatest similarity belongs to the extended category label set, the category label corresponding to the category label with the greatest similarity in the first category label set is used as the corrected text classification result.

[0132] Specifically, the category label corresponding to the category label with the greatest similarity (i.e., the extended category label) in the first category label set specifically refers to the extended original category label corresponding to the first category label set. For example, if the category label b' with the greatest similarity belongs to the extended category label set B', and b' is obtained by extending the category label b in the first category label set B, then b is used as the corrected text classification result.

[0133] In the embodiment of the present invention, considering that the same semantics can have a variety of different expressions, therefore, in the process of correcting the text classification results based on "semantic feature similarity", a second category label set is used that is determined by expanding the category labels in the first category label set, that is, the second category label set includes the first category label set and its corresponding extended category label set. In this way, the total number of category labels for semantic feature matching with the text classification results can be expanded, which helps to find category labels with similar semantics, avoid correction errors caused by insufficient number of category labels, and thus improve the accuracy of the corrected text classification results.

[0134] It should be pointed out that Figure 5 Step S57 in Figure 4 The content of step S44 in is consistent, so Figure 6The steps shown are also applicable to step S57.

[0135] Reference Figure 7 , Figure 7 : is a schematic diagram of the structure of a text classification device in an embodiment of the present invention. The text classification device may include:

[0136] A training data set determination module 71 is used to construct a training data set, wherein the training data set includes a plurality of text data, each of which includes an original text, a prompt text, and a category label of the original text;

[0137] A model training module 72 is used to use a preset loss function to input the training data set into the initialization text classification model for iterative training to obtain an optimized text classification model;

[0138] A text classification module 73, used for inputting the text to be classified into the optimized text classification model to obtain a text classification result;

[0139] The prompt text is used to indicate the training data set and the target task of the initialized text classification model.

[0140] For the principle, specific implementation and beneficial effects of the text classification device, please refer to the previous article and Figures 1 to 6 The related description about the text classification method shown is not repeated here.

[0141] The embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to execute the above Figures 1 to 6 The steps of the text classification method are shown. The computer-readable storage medium may include a non-volatile memory or a non-transitory memory, and may also include an optical disk, a mechanical hard disk, a solid-state hard disk, and the like.

[0142] Specifically, in the embodiment of the present invention, the processor may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0143] It should also be understood that the memory in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM) and direct rambus RAM (DR RAM).

[0144] The embodiment of the present invention further provides a terminal, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and the processor executes the above-mentioned Figures 1 to 6 The steps of the text classification method are shown. The terminal may include but is not limited to terminal devices such as mobile phones, computers, tablet computers, etc., and may also be a server, a cloud platform, etc.

[0145] It should be understood that the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article indicates that the associated objects before and after are in an "or" relationship.

[0146] The "plurality" appearing in the embodiments of the present application refers to two or more.

[0147] The first, second, etc. descriptions appearing in the embodiments of the present application are only used for illustration and distinction of the description objects. There is no order, nor do they indicate any special limitation on the number of devices in the embodiments of the present application, and cannot constitute any limitation on the embodiments of the present application.

[0148] It should be pointed out that the serial numbers of the steps in this embodiment do not limit the execution order of the steps.

[0149] Although the present invention is disclosed as above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the scope defined by the claims.

Claims

1. A text classification method, characterized in that: include: Constructing a training data set, wherein the training data set includes multiple text data, each text data includes an original text, a prompt text, and a category label of the original text; Using a preset loss function, the training data set is input into the initialized text classification model for iterative training to obtain an optimized text classification model; Inputting the text to be classified into the optimized text classification model to obtain a text classification result; The prompt text is used to indicate the training data set and the target task of the initialized text classification model.

2. The method according to claim 1, characterized in that Each piece of text data in the training data set is obtained by concatenating the original text, the prompt text and the category label of the original text.

3. The method according to claim 1 or 2, characterized in that: The prompt text includes prompt words, and there is a many-to-one or one-to-one relationship between the prompt words and the target task.

4. The method according to claim 1, characterized in that The loss function is expressed by the following expression: Among them, L generate represents the loss function, W represents the total number of characters included in the original category label, w represents the character sequence number in the original category label, V represents the total number of characters included in the character set, v represents the character sequence number in the character set, represents the coefficient of the w-th character in the original category label, when the w-th character is the v-th character in the character set, The value of is 1, otherwise The value of p is 0, wv represents the probability that the wth character in the current predicted label is the vth character in the character set, Represents the state matrix output after the w-th character of the original category label is input into the initialized text classification model.

5. The method according to claim 1, characterized in that The initialized text classification model is selected from: a second-generation GPT model, a third-generation GPT model, a fourth-generation GPT model, and a Bloom model.

6. The method according to claim 1, characterized in that Inputting the text to be classified into the optimized text classification model to obtain the text classification result includes: Perform at least one round of iteration based on the text to be classified and the optimized text classification model to obtain the text classification result; The iterative process includes: In the first round of iteration, the text to be classified is input into the optimized text classification model to obtain the first round of text category characters; In each subsequent round of iteration, the text to be classified and the text category characters obtained in the previous rounds are concatenated and input into the optimized text classification model to obtain the text category characters of the current round. If the text category characters of the current round are inconsistent with the preset stop characters, the next round of iteration is continued until the text category characters obtained in the current round are consistent with the stop characters. The concatenation results of the text category characters obtained in the remaining rounds except the last round are used as the text classification result.

7. The method according to claim 1 or 6, characterized in that: After obtaining the text classification result, the method further includes: Correcting the text classification result based on at least the first category label set; The first category label set is a set of category labels of each original text in the training data set.

8. The method according to claim 7, characterized in that The correcting the text classification result based at least on the first category label set includes: Determine the maximum number of consecutive identical characters between the text classification result and each category label in the first category label set, respectively, and record it as the number of identical characters; If the maximum number of identical characters is greater than or equal to the first preset number, the category label to which the maximum number of identical characters belongs is used as the corrected text classification result.

9. The method according to claim 8, characterized in that The method further comprises: If the maximum number of identical characters is less than the first preset number, correcting the text classification result based on the similarity between the semantic feature of the text classification result and the semantic feature of each category label in the second category label set; The second category tag set includes the first category tag set and its corresponding extended category tag set, and each category tag in the first category tag set is extended to one or more category tags in the extended category tag set.

10. The method according to claim 8 or 9, characterized in that: The first preset number is determined according to the total number of characters included in the text classification result. The larger the total number of characters is, the larger the first preset number is.

11. The method according to claim 7, characterized in that The correcting the text classification result based at least on the first category label set includes: Performing word segmentation processing on the text classification result and each category label in the first category label set respectively to obtain a first word segmentation result of the text classification result and a second word segmentation result of each category label; For each second word segmentation result, determining the number of identical word segmentations between the second word segmentation result and the first word segmentation result; Determine the ratio of the number of identical segmented words to the total number of segmented words in the first segmented word result as the precision rate, and determine the ratio of the number of identical segmented words to the total number of segmented words in the second segmented word result as the recall rate; Determining the F1 scores of the category labels to which the second word segmentation results belong according to the precision and the recall; If the maximum F1 score among the category labels is greater than or equal to the preset score, the category label to which the maximum F1 score belongs is used as the corrected text classification result.

12. The method according to claim 11, characterized in that The method further comprises: If the maximum F1 score is less than the preset score, correcting the text classification result based on the similarity between the semantic feature of the text classification result and the semantic feature of each category label in the second category label set; The second category tag set includes the first category tag set and its corresponding extended category tag set, and each category tag in the first category tag set is extended to one or more category tags in the extended category tag set.

13. The method according to claim 9 or 12, characterized in that: The correcting of the text classification result based on the similarity between the semantic feature of the text classification result and the semantic feature of each category label in the second category label set includes: Determine a semantic feature of the text classification result, recorded as a first semantic feature, and determine a semantic feature of each category label in the second category label set, recorded as a second semantic feature; respectively determining a similarity between the first semantic feature and each second semantic feature; Determine, in the second category label set, the category label with the greatest similarity to the first semantic feature; A corrected text classification result is determined according to the category label with the greatest similarity.

14. The method according to claim 13, characterized in that Determining the corrected text classification result according to the category label with the greatest similarity includes: If the category label with the greatest similarity belongs to the first category label set, taking the category label with the greatest similarity as the corrected text classification result; If the category label with the greatest similarity belongs to the extended category label set, the category label corresponding to the category label with the greatest similarity in the first category label set is used as the corrected text classification result.

15. A text classification device, characterized in that: include: A training data set determination module is used to construct a training data set, wherein the training data set includes a plurality of text data, each of which includes an original text, a prompt text, and a category label of the original text; A model training module, used to use a preset loss function to input the training data set into the initialized text classification model for iterative training to obtain an optimized text classification model; A text classification module, used for inputting the text to be classified into the optimized text classification model to obtain a text classification result; The prompt text is used to indicate the training data set and the target task of the initialized text classification model.

16. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the text classification method according to any one of claims 1 to 14 are executed.

17. A terminal comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor runs the computer program, the steps of the text classification method according to any one of claims 1 to 14 are performed.

Citation Information

Patent Citations

  • Text label extraction method and device

    CN113065312A

  • Text abstract generation method and device, electronic equipment and storage medium

    CN113642324A

  • Text classification label correction method and device, equipment and storage medium

    CN113987136A

  • Natural language processing method and device based on knowledge guidance prefix fine tuning, computing equipment, and storage medium

    CN113987209A

  • Language processing method and device and storage medium

    CN115712701A