Text classification method and device

By combining the target text and the annotated text to form a prompt text and selecting the matching annotated text category based on the semantic relationship of the characters, the problem of insufficient text classification accuracy in the existing technology is solved and higher classification accuracy is achieved.

CN117009503BActive Publication Date: 2025-09-05TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211111155.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-13
Publication Date
2025-09-05
Estimated Expiration
2042-09-13

AI Technical Summary

Technical Problem

Existing text classification methods rely on the semantics of the text itself for classification, resulting in insufficient classification accuracy.

Method used

By obtaining the target text and multiple annotated texts, combining them into a prompt text, and predicting the answer items based on the semantic relationship between characters, the target annotated text that matches the semantics of the target text is selected and its category is determined.

Benefits of technology

The accuracy of text classification is improved. By converting the text classification task into a semantic understanding task, the difficulty of classification is reduced, and classification is performed by combining the semantics of the annotated text with the semantics of the text to be classified.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117009503B_ABST
    Figure CN117009503B_ABST
Patent Text Reader

Abstract

The present application discloses a text classification method and device, belonging to the field of computer technology. The method includes: obtaining a target text to be classified and multiple annotated texts, each annotated text indicating a category, the annotated text including multiple descriptive words, and the multiple descriptive words being used to describe the category indicated by the annotated text; forming a prompt text with the target text, the multiple annotated texts, and the answer items to be predicted; predicting the answer in the answer items in the multiple annotated texts based on the semantic relationship between the characters in the prompt text, and obtaining a target annotated text that matches the semantics of the target text; and determining the category indicated by the target annotated text as the category to which the target text belongs. Annotated text that matches the semantics of the target text is selected from the multiple annotated texts, the semantics of the annotated text being equivalent to the semantics of the category, and classification is performed in combination with the semantics of the text to be classified and the semantics of various categories, which is conducive to improving the accuracy of text classification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a text classification method and device. Background Art

[0002] With the development of Internet technology, there are more and more texts on the Internet. In order to effectively manage these massive texts, the texts can be classified.

[0003] Related text classification methods extract semantic features corresponding to text and classify it based on these features to determine the category to which the text belongs. However, because this method relies solely on the semantics of the text itself for classification, the accuracy of text classification is not high enough. Summary of the Invention

[0004] The present application provides a method and apparatus for text classification, which can improve the accuracy of text classification. The technical solution is as follows:

[0005] In one aspect, a text classification method is provided, comprising:

[0006] Acquire a target text to be classified and a plurality of annotated texts, each annotated text indicating a category, the annotated text including a plurality of descriptive words, the plurality of descriptive words being used to describe the category indicated by the annotated text;

[0007] Combining the target text, the multiple annotated texts and the answer items to be predicted into a prompt text;

[0008] Based on the semantic relationship between the characters in the prompt text, predict the answer in the answer item from the multiple annotated texts to obtain a target annotated text that semantically matches the target text;

[0009] The category indicated by the target annotated text is determined as the category to which the target text belongs.

[0010] Optionally, extracting a character feature of each character in the prompt text includes:

[0011] Extracting semantic features corresponding to each character in the prompt text;

[0012] Extracting position features corresponding to each character in the prompt text;

[0013] The semantic feature and the position feature corresponding to each character are fused to obtain the text feature of each character.

[0014] Optionally, obtaining the target text to be classified includes any of the following:

[0015] Obtain comment text or barrage text for any multimedia data;

[0016] Get the title text corresponding to any multimedia data;

[0017] Get subtitle text from any multimedia data.

[0018] Optionally, the semantic detection model includes a feature extraction network, a feature processing network, and a probability prediction network. Calling the semantic detection model to determine the prediction probabilities of the multiple annotated texts based on the semantic relationship between characters in the prompt text includes:

[0019] Calling the feature extraction network to extract character features of each character in the prompt text;

[0020] calling the feature processing network to predict the character features of the answer item based on the character features of a plurality of characters in the prompt text and the similarities between the plurality of characters;

[0021] The probability prediction network is called to decode the character features of the answer items to obtain the predicted probabilities of the multiple annotated texts.

[0022] Optionally, calling the feature processing network to predict the character features of the answer item based on the character features of a plurality of characters in the prompt text and the similarity between the plurality of characters includes:

[0023] Calling the feature processing network to obtain query features, key features, and value features corresponding to the character features of each character, wherein the query features of the multiple characters constitute a query matrix, the key features of the multiple characters constitute a key matrix, and the value features of the multiple characters constitute a value matrix;

[0024] Normalizing the query matrix, the product of the transpose of the key matrix and the scaling factor to obtain a similarity matrix, wherein the similarity matrix includes similarities between the plurality of characters;

[0025] Multiplying the similarity matrix by the value matrix to obtain encoded character features of the plurality of characters;

[0026] The character features of the answer item are determined from the encoded character features of the plurality of characters.

[0027] Optionally, the feature extraction network includes a first extraction layer, a second extraction layer, and a fusion layer, and calling the feature extraction network to extract character features of each character in the prompt text includes:

[0028] Calling the first extraction layer to extract semantic features corresponding to each character in the prompt text;

[0029] Calling the second extraction layer to extract position features corresponding to each character in the prompt text;

[0030] The fusion layer is called to fuse the semantic feature and the position feature corresponding to each character to obtain the character feature corresponding to each character.

[0031] Optionally, the feature extraction network includes a first extraction layer, a second extraction layer, and a fusion layer, and calling the feature extraction network to extract sample character features of each sample character in the sample prompt text includes:

[0032] Calling the first extraction layer to extract sample semantic features corresponding to each character in the sample prompt text;

[0033] Calling the second extraction layer to extract the sample position feature corresponding to each character in the sample prompt text;

[0034] The fusion layer is called to fuse the sample semantic features and the sample position features corresponding to each character to obtain the sample character features of each sample character.

[0035] In another aspect, a text classification device is provided, comprising:

[0036] An acquisition module, configured to acquire a target text to be classified and a plurality of annotated texts, each annotated text indicating a category, the annotated text including a plurality of descriptive words, the plurality of descriptive words being used to describe the category indicated by the annotated text;

[0037] a combining module, configured to combine the target text, the plurality of annotated texts, and the answer items to be predicted into a prompt text;

[0038] A prediction module, configured to predict an answer in the answer item from the plurality of annotated texts based on semantic relationships between characters in the prompt text, and obtain a target annotated text that semantically matches the target text;

[0039] A determination module is configured to determine the category indicated by the target annotated text as the category to which the target text belongs.

[0040] Optionally, the combined module includes:

[0041] a template acquisition unit, configured to acquire a prompt template, wherein the prompt template includes a matching item to be filled, a plurality of candidate items to be filled, and the answer item to be predicted, wherein the matching item is used to fill the text to be classified, and the candidate item is used to fill the text that semantically matches the text to be classified;

[0042] A filling unit is used to fill the target text into the matching item and fill the multiple annotated texts into the candidate items in the prompt template to obtain the prompt text.

[0043] Optionally, the prompt template further includes a candidate item identifier corresponding to each candidate item; and the prediction module is configured to:

[0044] Based on the semantic relationship between the characters in the prompt text, predict the answer in the answer item from the candidate item identifiers corresponding to the multiple candidate items to obtain a target candidate item identifier;

[0045] The annotation text filled in the candidate item indicated by the target candidate item identifier is determined as the target annotation text.

[0046] Optionally, the combination module is used to:

[0047] The target text, the multiple annotated texts, the answer items and prompt words form the prompt text, and the prompt word is used to prompt to select the target annotated text that matches the semantics of the target text from the multiple annotated texts as the answer in the answer item.

[0048] Optionally, the prediction module is used to:

[0049] Extracting character features of each character in the prompt text;

[0050] Predicting the character features of the answer item based on the character features of multiple characters in the prompt text and the similarity between the multiple characters; decoding the character features of the answer item to obtain prediction probabilities of the multiple annotated texts, wherein the prediction probabilities of the annotated texts represent the probabilities that the semantics of the annotated texts match the semantics of the target text;

[0051] The annotated text with the highest predicted probability is determined as the answer to obtain the target annotated text.

[0052] Optionally, the prediction module is used to:

[0053] Obtaining a query feature, a key feature, and a value feature corresponding to the character feature of each character, wherein the query features of the multiple characters constitute a query matrix, the key features of the multiple characters constitute a key matrix, and the value features of the multiple characters constitute a value matrix;

[0054] Normalizing the query matrix, the product of the transpose of the key matrix and the scaling factor to obtain a similarity matrix, wherein the similarity matrix includes similarities between the plurality of characters;

[0055] Multiplying the similarity matrix by the value matrix to obtain encoded character features of the plurality of characters;

[0056] The character features of the answer item are determined from the encoded character features of the plurality of characters.

[0057] Optionally, the prediction module is used to:

[0058] Performing feature transformation on the character features of the answer item to obtain reference features, wherein the reference features include feature values ​​of multiple dimensions, each dimension corresponding to a labeled text;

[0059] The feature value of each dimension in the reference feature is normalized to obtain the prediction probability corresponding to the annotated text corresponding to each dimension.

[0060] Optionally, the acquisition module is used to:

[0061] Obtaining the target text to be classified, and determining a task type to which a classification task corresponding to the target text belongs, wherein the task type includes at least one of a text quality grading task, a text emotion recognition task, a sensitive text recognition task, or an advertising text recognition task;

[0062] Determine multiple categories corresponding to the task type, each task type corresponds to multiple categories, and the categories corresponding to different task types are not completely the same;

[0063] Obtain the annotation text corresponding to each category of the multiple categories.

[0064] Optionally, the prediction module is used to:

[0065] Invoking a semantic detection model to determine prediction probabilities of the plurality of annotated texts based on semantic relationships between characters in the prompt text, wherein the prediction probabilities of the annotated texts represent probabilities that the semantics of the annotated texts match the semantics of the target text;

[0066] Among the multiple annotated texts, the annotated text with the highest prediction probability is determined as the answer to obtain the target annotated text.

[0067] Optionally, the device further comprises:

[0068] The acquisition module is further configured to acquire a first sample text, a plurality of sample annotated texts, and a true category of the first sample text, wherein each sample annotated text indicates a category, and the sample annotated text includes a plurality of sample description words, wherein the plurality of sample description words are used to describe the category indicated by the sample annotated text;

[0069] The combining module is further configured to combine the first sample text, the plurality of sample annotated texts, and the answer items to be predicted into a sample prompt text;

[0070] The prediction module is further configured to call the semantic detection model to determine a first sample probability of the plurality of sample annotated texts based on the semantic relationship between characters in the sample prompt text, wherein the first sample probability of the sample annotated text represents a probability that the semantics of the sample annotated text predicted by the semantic detection model matches the semantics of the first sample text;

[0071] The first training module is used to train the semantic detection model based on the first sample probability of the sample annotated text of the real category, so as to increase the first sample probability of the sample annotated text of the real category obtained based on the trained semantic detection model.

[0072] Optionally, the semantic detection model includes a feature extraction network, a feature processing network, and a probability prediction network, and the prediction module is used to:

[0073] Calling the feature extraction network to extract sample character features of each sample character in the sample prompt text;

[0074] calling the feature processing network to predict the sample character features of the answer item based on the sample character features of a plurality of sample characters in the sample prompt text and the similarities between the plurality of sample characters;

[0075] The probability prediction network is called to decode the sample character features of the answer item to obtain the first sample probabilities of the multiple sample annotated texts.

[0076] Optionally, the prediction module is used to:

[0077] Calling the feature processing network to obtain a sample query feature, a sample key feature, and a sample value feature corresponding to the sample character feature of each sample character, wherein the sample query features of the multiple sample characters constitute a sample query matrix, the sample key features of the multiple sample characters constitute a sample key matrix, and the sample value features of the multiple sample characters constitute a sample value matrix;

[0078] Normalizing the product of the transpose of the sample query matrix and the sample key matrix and a scaling factor to obtain a sample similarity matrix, wherein the sample similarity matrix includes similarities between the plurality of sample characters;

[0079] Multiplying the sample similarity matrix by the sample value matrix to obtain encoded sample character features of the plurality of sample characters;

[0080] The sample character feature of the answer item is determined from the encoded sample character features of the plurality of sample characters.

[0081] Optionally, the device further comprises:

[0082] The acquisition module is further configured to acquire a second sample text and delete a target character at a target position in the second sample text, where the target position is any position in the second sample text;

[0083] The prediction module is further configured to call the semantic detection model to determine, based on the semantic relationship between characters in the second sample text, a second sample probability of each character in the character set, wherein the second sample probability of each character represents a probability that the character predicted by the semantic detection model belongs to the character at the target position, and the character set includes the target character;

[0084] The second training module is used to train the semantic detection model based on the second sample probability of the target character, so as to increase the second sample probability of the target character obtained based on the trained semantic detection model.

[0085] Optionally, the device further comprises:

[0086] The acquisition module is further configured to acquire a third sample text, a fourth sample text, a first true probability, and a second true probability, wherein the first true probability represents a probability that the fourth sample text is the next sentence of the third sample text, and the second true probability represents a probability that the fourth sample text is not the next sentence of the third sample text;

[0087] The prediction module is further configured to call the semantic detection model to determine a third sample probability and a fourth sample probability based on the semantic relationship between characters in the third sample text and the fourth sample text, wherein the third sample probability represents a probability that the fourth sample text predicted by the semantic detection model is the next sentence of the third sample text, and the fourth sample probability represents a probability that the fourth sample text predicted by the semantic detection model is not the next sentence of the third sample text;

[0088] The third training module is used to train the semantic detection model based on the third sample probability, the fourth sample probability, the first true probability and the second true probability, so that the similarity between the third sample probability obtained based on the trained semantic detection model and the first true probability is increased, and the similarity between the fourth sample probability obtained and the second true probability is increased.

[0089] On the other hand, a computer device is provided, comprising a processor and a memory, wherein the memory stores at least one computer program, and the at least one computer program is loaded and executed by the processor to implement the operations performed by the text classification method described in the above aspects.

[0090] On the other hand, a computer-readable storage medium is provided, in which at least one computer program is stored. The at least one computer program is loaded and executed by a processor to implement the operations performed by the text classification method described in the above aspects.

[0091] On the other hand, a computer program product is provided, including a computer program, wherein the computer program is loaded and executed by a processor to implement the operations performed by the text classification method as described in the above aspects.

[0092] The solution provided by the embodiment of the present application combines the target text with various categories of annotated text and the answer item to be predicted when classifying the target text to obtain a prompt text, and selects a target annotated text that matches the semantics of the target text based on the semantic relationship between the characters in the prompt text. The category indicated by the target annotated text is the category to which the target text belongs, thereby converting the text classification task into a semantic understanding task, which is equivalent to selecting an annotated text that matches the semantics of the target text from multiple annotated texts based on the semantics of the target text and the semantics of the annotated text, thus reducing the difficulty of text classification. And because the semantics of the annotated text is equivalent to the semantics of the category, this solution can combine the semantics of the text to be classified and the semantics of various categories to classify the text to be classified, which is conducive to improving the accuracy of text classification. BRIEF DESCRIPTION OF THE DRAWINGS

[0093] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0094] Figure 1 This is a schematic diagram of an implementation environment provided by an embodiment of the present application;

[0095] Figure 2 This is a flowchart of a text classification method provided by an embodiment of the present application;

[0096] Figure 3 This is a flowchart of another text classification method provided by an embodiment of the present application;

[0097] Figure 4 This is a flowchart of generating prompt text provided by an embodiment of the present application;

[0098] Figure 5 This is a flowchart of another text classification method provided by an embodiment of the present application;

[0099] Figure 6 This is a structural diagram of a semantic detection model provided in an embodiment of the present application;

[0100] Figure 7 This is a flowchart of another text classification method provided by an embodiment of the present application;

[0101] Figure 8 This is a flowchart of a method for training a semantic detection model provided in an embodiment of the present application;

[0102] Figure 9 This is a flowchart of another method for training a semantic detection model provided in an embodiment of the present application;

[0103] Figure 10 This is a flowchart of another method for training a semantic detection model provided in an embodiment of the present application;

[0104] Figure 11 This is a flowchart of another text classification method provided by an embodiment of the present application;

[0105] Figure 12 This is a structural diagram of a text classification device provided in an embodiment of the present application;

[0106] Figure 13 is a structural diagram of another text classification device provided in an embodiment of the present application;

[0107] Figure 14 This is a schematic diagram of the structure of a terminal provided in an embodiment of the present application;

[0108] Figure 15 This is a structural diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION

[0109] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0110] It is understood that the terms "first," "second," and the like used herein may be used to describe various concepts, but unless otherwise specified, these concepts are not limited by these terms. These terms are used solely to distinguish one concept from another. For example, a first sample text may be referred to as a second sample text, and similarly, a second sample text may be referred to as a first sample text, without departing from the scope of this application.

[0111] Here, "at least one" means one or more than one. For example, at least one text can be one text, two texts, three texts, or any other integer greater than or equal to one. "Multiple" means two or more than two. For example, "multiple" can be two texts, three texts, or any other integer greater than or equal to two. "Each" means each of at least one. For example, "each text" means each text in the multiple texts. If the multiple texts are three texts, "each text" means each of the three texts.

[0112] It is understandable that in the implementation of this application, related data such as user information is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0113] Artificial Intelligence (AI) refers to the theories, methods, techniques, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, to perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that seeks to understand the essence of intelligence and produce new intelligent machines that can respond in a manner similar to human intelligence. AI also involves studying the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.

[0114] Artificial intelligence (AI) technology is a comprehensive discipline encompassing a wide range of fields, encompassing both hardware and software technologies. Foundational AI technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, speech processing, natural language processing, as well as machine learning / deep learning, autonomous driving, and smart transportation.

[0115] Machine learning (ML) is a multidisciplinary field that encompasses probability theory, statistics, approximation theory, convex analysis, and algorithmic complexity theory. It specifically studies how computers can simulate or implement human learning behaviors to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is at the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications span all areas of AI. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and learning through demonstration.

[0116] Natural language processing (NLP) is a key area of ​​research in computer science and artificial intelligence. It studies the theories and methods that enable effective communication between humans and computers using natural language. Natural language processing (NLP) integrates linguistics, computer science, and mathematics. Therefore, research in this field involves natural language—the language we use in everyday life—and is closely linked to the study of linguistics. Natural language processing technologies typically include text processing, semantic understanding, machine translation, robotic question answering, and knowledge graphs.

[0117] The following describes the text classification method provided in the embodiment of the present application based on artificial intelligence technology and natural language processing technology.

[0118] Before describing the embodiments of the present application, the following concepts are explained:

[0119] (1) Prompt: A machine learning method that converts natural language understanding tasks into language modeling tasks by inserting, modifying, and mapping labels to text.

[0120] (2) Template: The format used to process text when using the prompt method. By filling the template with the text to be processed and the position markers of the answer items, the prompt text can be constructed.

[0121] (3) Answer Word: also known as candidate items, which are multiple candidate items for the output generated by the model for the prompt text. They usually come from a subset of the entire vocabulary and have a mapping relationship with the categories of the classification task.

[0122] (4) Transformer: A deep neural network model based on a multi-layer self-attention mechanism.

[0123] (5) BERT (Bidirectional Encoder Representations from Transformers): A pre-training method for the Transformer model that performs unsupervised learning by masking words and predicting sentence relationships.

[0124] The text classification method provided in the embodiment of the present application can be used in a computer device. Optionally, the computer device is a terminal or a server. Optionally, the server is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Optionally, the terminal is a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to this.

[0125] In one possible implementation, the computer program involved in the embodiments of the present application can be deployed and executed on a computer device, or on multiple computer devices located at one location, or on multiple computer devices distributed at multiple locations and interconnected through a communication network. Multiple computer devices distributed at multiple locations and interconnected through a communication network can constitute a blockchain system.

[0126] Figure 1 This is a schematic diagram of an implementation environment provided by an embodiment of the present application, see Figure 1 , the implementation environment includes: a terminal 101 and a server 102. The terminal 101 and the server 102 are connected via a wireless or wired network. Optionally, the server 102 is used to train a semantic detection model, which is used to detect the semantics of the text. The server 102 sends the trained semantic detection model to the terminal 101, and the terminal 101 can call the semantic detection model to predict the answer in the answer item in multiple annotated texts based on the semantic relationship between the characters in the prompt text, and obtain a target annotated text that matches the semantics of the target text, wherein the prompt text is obtained by combining the target text, multiple annotated texts, and the answer item to be predicted.

[0127] In one possible implementation, terminal 101 runs an application client provided by the server. Server 102 stores a trained semantic detection model in the application client, which has the function of classifying text. Terminal 101, based on the application client, invokes the semantic detection model and, based on the semantic relationships between characters in the prompt text, predicts the answer in the answer item from multiple annotated texts, obtains a target annotated text that semantically matches the target text, and determines the category corresponding to the target annotated text as the category to which the target text belongs.

[0128] It should be noted that Figure 1In the example, the server 102 trains the semantic detection model and sends it to the terminal 101. In another embodiment, the server can also call the semantic detection model to predict the answer in the answer item among multiple annotated texts based on the semantic relationship between the characters in the prompt text, obtain the target annotated text that matches the semantics of the target text, and then send the category corresponding to the target annotated text to the terminal 101. The terminal 101 can then determine the category as the category to which the target text belongs.

[0129] The text classification method provided in the embodiments of the present application can be applied to any scenario of text classification.

[0130] For example, the embodiment of the present application is applied to the scenario of verbal abuse classification task. The categories to which the text belongs can be divided into level 0 verbal abuse, level 1 verbal abuse, level 2 verbal abuse and level 3 verbal abuse. The annotated text for level 0 verbal abuse is "normal expression of opinions", the annotated text for level 1 verbal abuse is "slightly derogatory to others", the annotated text for level 2 verbal abuse is "hurtful, negative emotions", and the annotated text for level 3 verbal abuse is "provoking conflict, strongly derogatory to others". For the target text to be classified, the method provided by the embodiment of the present application is used to determine the annotated text that matches the semantics of the target text from multiple annotated texts. For example, if the annotated text that matches the target text is "hurtful, negative emotions", then the target text belongs to level 2 verbal abuse.

[0131] For another example, the embodiment of the present application is applied to the scenario of text sentiment classification task. The category to which the text belongs can be divided into level 0 emotion, level 1 emotion, level 2 emotion and level 3 emotion, with positive emotion having a lower level and negative emotion having a higher level. The annotated text of level 0 emotion is "positive, affirmative, active, healthy, friendly, praise, blessing", the annotated text of level 1 emotion is "no emotional tendency, stick to the facts", the annotated text of level 2 emotion is "negative, negation, gloomy, pessimistic, complaining, extreme, uncomfortable", and the annotated text of level 3 emotion is "extreme, angry, depressed". For the target text to be classified, the method provided by the embodiment of the present application is used to determine the annotated text that matches the semantics of the target text among multiple annotated texts. For example, if the annotated text that matches the target text is "no emotional tendency, stick to the facts", then the target text belongs to level 1 emotion.

[0132] For another example, the embodiment of the present application is applied to the scenario of text advertisement recognition tasks. The categories to which the text belongs can be divided into level 0 advertisements, level 1 advertisements and level 2 advertisements. The greater the possibility that the text belongs to an advertisement, the higher the level. The annotated text of level 0 advertisements is "normal speech", the annotated text of level 1 advertisements is "promotion, digital number, contact information", and the annotated text of level 2 advertisements is "advertisement, recommendation, search, contains links, digital numbers, contact information". For the target text to be classified, the method provided by the embodiment of the present application is used to determine the annotated text that matches the semantics of the target text from multiple annotated texts. For example, if the annotated text that matches the target text is "normal speech", then the target text belongs to level 0 advertisement.

[0133] In addition, the method provided in the embodiment of the present application can also be applied to security audits and identification of low-quality labels on content publishing platforms, such as inappropriate speech identification, quality grading, and low-quality hydrology identification.

[0134] Figure 2 This is a flowchart of a text classification method provided by an embodiment of the present application. The embodiment of the present application is executed by a computer device. Figure 2 , the method comprising:

[0135] 201. A computer device obtains a target text to be classified and a plurality of annotated texts.

[0136] The computer device obtains target text to be classified. The target text may be text obtained in the content publishing request when the computer device receives the content publishing request, or may be text sent to the computer device by other devices.

[0137] A computer device obtains multiple annotation texts, each annotation text indicates a category. An annotation text includes multiple descriptive words, which are used to describe the category indicated by the annotation text and serve to annotate or explain the category. Therefore, the semantics of the annotation text can reflect the semantics of the category indicated by the annotation text to a certain extent.

[0138] 202. The computer device combines the target text, multiple annotated texts, and the answer items to be predicted into a prompt text.

[0139] The computer device obtains an answer item to be predicted, where the answer in the answer item must match the semantics of the target text. The computer device combines the target text, multiple annotated texts, and the answer item to be predicted to obtain a prompt text. The prompt text can indicate that a target annotated text that semantically matches the target text is predicted as the answer among the multiple annotated texts.

[0140] It can be understood that the prompt text is equivalent to a multiple-choice question, the target text in the prompt text is the question stem, the multiple annotated texts in the prompt text are options, and the answer item to be predicted is the answer to the multiple-choice question.

[0141] In one possible implementation, a computer device combines a target text, multiple annotated texts, an answer item, and a prompt word to form a prompt text, where the prompt word is used to prompt that a target annotated text that semantically matches the target text be selected from multiple annotated texts as the answer in the answer item.

[0142] Since the prompt word is used to prompt the selection of an answer in an answer item from multiple annotated texts, the semantics of the combined prompt text is to select the target annotated text that matches the semantics of the target text as the answer in the answer item from the multiple annotated texts. With the assistance of the prompt word, the computer device can more easily understand the semantics of the prompt text and execute the operation of selecting the target annotated text from multiple annotated texts, which is conducive to improving the accuracy of subsequent predictions of the answer items.

[0143] 203. The computer device predicts the answer in the answer item from among the multiple annotated texts based on the semantic relationship between the characters in the prompt text, and obtains a target annotated text that matches the semantics of the target text.

[0144] After receiving the prompt text, the computer device determines the semantic relationship between the characters in the prompt text. Since the prompt text is equivalent to a multiple-choice question, it indicates that among multiple annotated texts, a target annotated text that semantically matches the target text is predicted as the answer. Therefore, based on the semantic relationship between the characters in the prompt text, a target annotated text that semantically matches the target text can be selected from the multiple annotated texts. This target annotated text is the answer in the predicted answer item. The semantics of the target annotated text match the semantics of the target text. Matching here means that the semantics of the target annotated text are closest to the semantics of the target text, or that the semantics of the target annotated text can describe, annotate, or explain the semantics of the target text.

[0145] 204. The computer device determines the category indicated by the target annotated text as the category to which the target text belongs.

[0146] Since the semantics of the annotated text is equivalent to the semantics of the category, and the semantics of the target annotated text matches the semantics of the target text, that is, the semantics of the category corresponding to the target annotated text matches the semantics of the target text, the category corresponding to the target annotated text is also the category to which the target text belongs.

[0147] The method provided in the embodiment of the present application combines the target text with various categories of annotated text and the answer item to be predicted when classifying the target text to obtain a prompt text, and selects a target annotated text that matches the semantics of the target text based on the semantic relationship between the characters in the prompt text. The category indicated by the target annotated text is the category to which the target text belongs, thereby converting the text classification task into a semantic understanding task, which is equivalent to selecting an annotated text that matches the semantics of the target text from multiple annotated texts based on the semantics of the target text and the semantics of the annotated text, thus reducing the difficulty of text classification. And because the semantics of the annotated text is equivalent to the semantics of the category, this solution can combine the semantics of the text to be classified and the semantics of various categories to classify the text to be classified, which is conducive to improving the accuracy of text classification.

[0148] In the above Figure 2 Based on the embodiment shown, the computer device fills the target text and the marked text into the prompt template to obtain the prompt text. The specific process is shown in the following Figure 3 The embodiment shown.

[0149] Figure 3 This is a flowchart of a text classification method provided by an embodiment of the present application. The embodiment of the present application is executed by a computer device. Figure 3 , the method comprising:

[0150] 301. A computer device obtains a target text to be classified and multiple annotated texts.

[0151] The target text can be any type of text obtained in any scenario. In one possible implementation, the computer device obtains comment text or barrage text for any multimedia data. For example, on a video playback platform, obtain comment text or barrage text for a video. On a content publishing platform, obtain comment text for an article. In another possible implementation, the computer device obtains the title text corresponding to any multimedia data. For example, on a short video publishing platform, obtain the title text corresponding to a published video. On a content publishing platform, obtain the title text corresponding to a published article. In another possible implementation, the computer device obtains subtitle text in any multimedia data. For example, on a short video publishing platform, obtain the subtitle text in a published video.

[0152] In one possible implementation, a computer device obtains a target text to be classified and a plurality of annotated texts, including the following steps (1) to (3):

[0153] (1) The computer device obtains the target text to be classified and determines the task type of the classification task corresponding to the target text, wherein the task type includes at least one of a text quality grading task, a text emotion recognition task, a sensitive text recognition task, or an advertising text recognition task.

[0154] The classification task includes at least one task type, such as a text quality grading task, a text emotion recognition task, a sensitive text recognition task, or an advertising text recognition task. The computer device determines the task type of the current classification task. For example, if the current classification task is a text emotion recognition task, the emotion expressed by the target text needs to be recognized. For another example, if the current classification task is an advertising text recognition task, the computer device determines whether the target text is an advertising text.

[0155] (2) The computer device determines multiple categories corresponding to the task type. Each task type corresponds to multiple categories, and the categories corresponding to different task types are not exactly the same.

[0156] For example, if the task type is sensitive text identification, and the sensitive text is text containing insults, then the corresponding categories for this task type include Level 0 insults, Level 1 insults, Level 2 insults, and Level 3 insults, with the higher the level, the more severe the insults. Among them, the text labeled as "normal expression of opinion" for Level 0 insults, "mildly derogatory" for Level 1 insults, "hurtful, negative emotions" for Level 2 insults, and "provoking a fight, strongly derogatory" for Level 3 insults.

[0157] For example, if the task type is text sentiment recognition, the corresponding categories include level 0 sentiment, level 1 sentiment, level 2 sentiment, and level 3 sentiment. Positive sentiment has a lower level, while negative sentiment has a higher level. Level 0 sentiment is labeled as "positive, affirmative, active, healthy, friendly, praise, blessing," level 1 sentiment is labeled as "neutral, stick to the facts," level 2 sentiment is labeled as "negative, negation, gloomy, pessimistic, complaining, extreme, uncomfortable," and level 3 sentiment is labeled as "extreme, angry, depressed."

[0158] For example, if the task type is advertising text recognition, the corresponding categories include Level 0, Level 1, and Level 2. The more likely the text is an advertisement, the higher the level. Level 0 ads are labeled "normal speech," Level 1 ads are labeled "promotion, number, contact information," and Level 2 ads are labeled "advertisement, recommendation, search, contains links, number, contact information."

[0159] (3) The computer device obtains the annotation text corresponding to each category in the multiple categories.

[0160] Optionally, the annotated text of each category is obtained through manual annotation. Optionally, the computer device calls a summary generation model to process at least one material text to obtain a summary corresponding to each material text. The computer device determines the obtained multiple summaries as annotation words. For each category, the computer device determines the annotation words used to annotate each category based on the selection operation performed among the multiple annotation words, and then the multiple annotation words corresponding to the category constitute the annotated text of the category. Optionally, the length of the annotated text of each category is not greater than the target length. For example, if the target length is 30 characters, the annotated text of each category is not more than 30 characters.

[0161] Optionally, after determining the annotated text for a category, the computer device obtains multiple annotated words in the annotated text, determines a synonym for at least one annotated word, and adds the synonym for the at least one annotated word to the annotated text for the category, thereby obtaining updated annotated text. In another possible implementation, the computer device determines an explanatory phrase for at least one annotated word, the explanatory phrase being used to explain the annotated word, and adds the explanatory phrase for the at least one word to the annotated text for the category, thereby obtaining updated annotated text.

[0162] In an embodiment of the present application, different classification tasks corresponding to different texts to be classified may belong to different task types, and different task types may correspond to different categories. Each category corresponds to its own annotated text. Therefore, in the process of classifying the text, it is only necessary to determine the annotated text corresponding to the multiple categories to which the text to be classified is to be classified. Therefore, this method is applicable to classification tasks belonging to any task type, which improves the universality of the text classification method.

[0163] 302. The computer device obtains a prompt template.

[0164] The computer device obtains a prompt template, which includes a matching item to be filled, multiple candidate items to be filled, and an answer item to be predicted. The matching item is used to fill in the text to be classified, and the candidate item is used to fill in the text that is semantically matched with the text to be classified. Optionally, the answer item of the prompt template is filled with a first reference character, and the first reference character is used to indicate that the position of the first reference character is the position of the answer item. The first reference character serves as a position marker. For example, the first reference character is a special symbol "&" or the character "MASK", etc., which is not limited in this embodiment of the present application. Optionally, the prompt template also includes a prompt word, which is used to prompt the user to select an answer item that semantically matches the matching item from multiple candidate items.

[0165] For example, the prompt template is: T = [Text to be classified]? a. (Option 1). b. (Option 2). c. (Option 3). d. (Option 4). ...The answer is {MASK}. T represents the prompt text, "[Text to be classified]" represents the matching option, "(Option 1)" represents the first candidate, "(Option 2)" represents the second candidate, "(Option 3)" represents the third candidate, "(Option 4)" represents the fourth candidate, and "{MASK}" represents the answer.

[0166] In an embodiment of the present application, by creating a unified prompt template, in each classification task, the current text to be classified and the multiple annotated texts corresponding to the current classification task can be directly filled into the corresponding positions of the prompt template. This can avoid the need to manually combine prompt texts in each classification task, saving manpower and time, and is conducive to improving the convenience and efficiency of the text classification method.

[0167] 303. The computer device fills the target text into the matching item in the prompt template and fills the multiple annotation texts into the candidate items respectively to obtain the prompt text.

[0168] After obtaining the target text, multiple annotated texts, and a prompt template, the computer device populates the target text into the matching item and the multiple annotated texts into the candidate items, thereby generating the prompt text. For different classification tasks, for example, the same target text corresponds to different categories, and therefore the annotated texts for each category are different. Therefore, the annotated texts of different categories can be populated into the candidate items to form different prompt texts. The following example uses the target text "You are such a bad person" and the first reference character "&" in the answer item as an example to illustrate the process of forming prompt texts for different classification tasks.

[0169] For example, if the task type is a sensitive text recognition task, and the sensitive text refers to abusive text, then the multiple categories corresponding to this task type include level 0 abuse, level 1 abuse, level 2 abuse, and level 3 abuse. Among them, the annotated text for level 0 abuse is "normal expression of opinion", the annotated text for level 1 abuse is "slightly derogatory of others", the annotated text for level 2 abuse is "hurtful, negative emotions", and the annotated text for level 3 abuse is "provoking conflict, strongly derogatory of others". After the computer device fills the target text and the multiple annotated texts into the prompt template, the resulting prompt text is "You speak so rudely? a. Normal expression of opinion. b. Slightly derogatory of others. c. Hurtful, negative emotions. d. Provoking conflict, strongly derogatory of others. The answer is &".

[0170] For example, if the task type is text emotion recognition, the multiple categories corresponding to this task type include level 0 emotion, level 1 emotion, level 2 emotion, and level 3 emotion. The text annotation for level 0 emotion is "positive, affirmative, active, healthy, friendly, praise, blessing," the text annotation for level 1 emotion is "neutral, stick to the facts," the text annotation for level 2 emotion is "negative, negation, gloomy, pessimistic, complaining, extreme, uncomfortable," and the text annotation for level 3 emotion is "extreme, angry, depressed." After the computer device fills the prompt template with the target text and the multiple annotated texts, the resulting prompt text is "You speak so rudely? a. Positive, affirmative, active, healthy, friendly, praise, blessing. b. Neutral, stick to the facts. c. Negative, negation, gloomy, pessimistic, complaining, extreme, uncomfortable. d. Extreme, angry, depressed. The answer is &."

[0171] For example, if the task type is an advertising text recognition task, the various categories corresponding to this task type include level 0 advertising, level 1 advertising, and level 2 advertising. The annotated text for level 0 advertising is "normal speech," the annotated text for level 1 advertising is "promotion, digital number, contact information," and the annotated text for level 2 advertising is "advertisement, recommendation, search, contains links, digital number, contact information." After the computer device fills the target text and the multiple annotated texts into the prompt template, the resulting prompt text is "You speak so rudely? a. Normal speech. b. Promotion, digital number, contact information. c. Advertising, recommendation, search, contains links, digital number, contact information. The answer is &."

[0172] In the embodiment of the present application, the target text, the plurality of annotated texts, and the answer item to be predicted are combined to obtain the prompt text by executing the above steps 302 and 303. In another embodiment, the target text, the plurality of annotated texts, and the answer item to be predicted can also be concatenated to obtain the prompt text.

[0173] Figure 4 This is a flowchart of generating prompt text provided by an embodiment of the present application, such as Figure 4 As shown, the computer device obtains the target text 401 and the prompt template 402, fills the target text 401 and multiple annotated texts into the prompt template 402, and obtains the prompt text 403.

[0174] 304. The computer device predicts the answer in the answer item from among the multiple annotated texts based on the semantic relationship between the characters in the prompt text, and obtains a target annotated text that matches the semantics of the target text.

[0175] The prompt text is equivalent to a multiple-choice question. The matching item in the prompt text (i.e., the target text) is the question stem, the multiple candidate items in the prompt text (i.e., the multiple annotated texts) are the options, and the answer item to be predicted in the prompt text is the answer to the multiple-choice question. After obtaining the prompt text, the computer device determines the semantic relationship between the characters in the prompt text. Based on this semantic relationship, the computer device predicts the answer in the answer item from the multiple annotated texts to obtain the target annotated text. This is equivalent to selecting the target annotated text from the multiple annotated texts that semantically matches the target text.

[0176] For example, in the scenario of the sensitive text recognition task mentioned above, the target text is "You speak so rudely" and the answer is "Slightly belittling others". This means that the annotated text "Slightly belittling others" is the target annotated text, and the semantics of the annotated text "Slightly belittling others" matches the semantics of the target text "You speak so rudely".

[0177] In another possible implementation, the prompt template also includes a candidate identifier corresponding to each candidate item, and the candidate identifier is used to indicate the candidate item, such as "a", "b", "c" and "d" in the above prompt template. Based on the semantic relationship between the characters in the prompt text, the computer device predicts the answer in the answer item from the candidate identifiers corresponding to the multiple candidate items, and obtains the target candidate identifier. The computer device determines the annotated text filled in the candidate item indicated by the target candidate identifier as the target annotated text. For example, in the scenario of the above-mentioned sensitive text recognition task, the target text is "You speak so rudely", the answer is "b", and the annotated text filled in the candidate item indicated by "b" is "Slightly derogatory to others". The annotated text "Slightly derogatory to others" is the target annotated text, and the semantics of the annotated text "Slightly derogatory to others" matches the semantics of the target text "You speak so rudely".

[0178] In an embodiment of the present application, a candidate item identifier corresponding to each candidate item is added to the prompt template, so that the answer to the answer item is predicted by the candidate item identifier, rather than the annotated text in the candidate item. Therefore, the prediction result will not be affected by the length of the annotated text. Even if the length of the annotated text is long, the corresponding candidate item identifier can be accurately predicted. Using the candidate item identifier to indirectly indicate the predicted annotated text can avoid the problem of a long prediction process due to the length of the annotated text being too long, and can also avoid the problem of low accuracy due to the accumulation of errors in the prediction process due to the length of the annotated text being too long. Therefore, the method of predicting candidate item identifiers can improve the efficiency and accuracy of the prediction.

[0179] 305. The computer device determines the category indicated by the target annotated text as the category to which the target text belongs.

[0180] Since the semantics of the annotated text is equivalent to the semantics of the category, and the semantics of the target annotated text matches the semantics of the target text, that is, the semantics of the category indicated by the target annotated text matches the semantics of the target text, the category indicated by the target annotated text is also the category to which the target text belongs.

[0181] The method provided in the embodiment of the present application combines the target text with various categories of annotated text and the answer item to be predicted when classifying the target text to obtain a prompt text, and selects a target annotated text that matches the semantics of the target text based on the semantic relationship between the characters in the prompt text. The category indicated by the target annotated text is the category to which the target text belongs, thereby converting the text classification task into a semantic understanding task, which is equivalent to selecting an annotated text that matches the semantics of the target text from multiple annotated texts based on the semantics of the target text and the semantics of the annotated text, thus reducing the difficulty of text classification. And because the semantics of the annotated text is equivalent to the semantics of the category, this solution can combine the semantics of the text to be classified and the semantics of various categories to classify the text to be classified, which is conducive to improving the accuracy of text classification.

[0182] Based on the above embodiment, the computer device predicts the character features of the answer item, decodes the character features of the answer item to obtain the prediction probability of multiple annotated texts. The specific process is as follows Figure 5 The embodiment shown.

[0183] Figure 5 This is a flowchart of a text classification method provided by an embodiment of the present application. The embodiment of the present application is executed by a computer device. Figure 5 , the method comprising:

[0184] 501. A computer device obtains a target text to be classified and a plurality of annotated texts.

[0185] The process of step 501 is the same as that of step 301 above, and will not be repeated here.

[0186] 502. The computer device combines the target text, the multiple annotated texts, and the answer items to be predicted into a prompt text.

[0187] The process of step 502 is the same as the process of steps 302 to 303 above, and will not be repeated here.

[0188] 503. The computer device extracts character features of each character in the prompt text.

[0189] After the computer device obtains the prompt text, it performs feature extraction on the prompt text to obtain character features of each character in the prompt text.

[0190] In one possible implementation, the computer device extracts a semantic feature corresponding to each character in the prompt text, extracts a position feature corresponding to each character in the prompt text, and fuses the semantic feature and position feature corresponding to each character to obtain a character feature for each character. For each character, the semantic feature and position feature corresponding to the character are fused, for example, by adding them together, to obtain a fused feature corresponding to the character.

[0191] Optionally, the semantic feature corresponding to each character is a word embedding vector. Optionally, the semantic feature corresponding to the character includes semantic feature values ​​of multiple dimensions, for example, the dimension of the semantic feature is 768. The dimension of the semantic feature is the dimension with the highest accuracy obtained through multiple experiments.

[0192] Optionally, the computer device uses the following formula (1) and formula (2) to extract the position features corresponding to the characters.

[0193]

[0194]

[0195] Among them, the position feature corresponding to the character includes position feature values ​​of multiple dimensions. The position feature has the same dimension as the semantic feature mentioned above, and d represents the dimension of the position feature. pos is the position number of the character in the prompt text. pos is an integer. The pos of multiple characters are numbered starting from 0 according to the arrangement order in the prompt text. For example, if a character is the first character in the prompt text, the pos of the character is equal to 0. i is the position number of the position feature value in the position feature. i is an integer. The i of multiple position feature values ​​is numbered starting from 0 according to the arrangement order in the position feature. For example, if a position feature value is the first feature value in the prompt text, the i of the position feature value is equal to 0.

[0196] Among them, when the position feature value i is an even number, the above formula (1) is used to calculate the position feature value, and PE(pos,2i) represents the position feature value when i is an even number. When the position feature value i is an odd number, the above formula (2) is used to calculate the position feature value, and PE(pos,2i+1) represents the position feature value when i is an odd number. After calculating the position feature values ​​of a character in multiple dimensions, the position feature values ​​of the multiple dimensions are spliced ​​in the order of arrangement to obtain the position feature corresponding to the character.

[0197] 504. The computer device predicts character features of the answer item based on the character features of multiple characters in the prompt text and the similarity between the multiple characters.

[0198] After obtaining the character features of each character in the prompt text, the computer device predicts the character features of the answer item based on the character features of multiple characters and the similarities between the multiple characters.

[0199] In an embodiment of the present application, taking into account the association relationship between the characters in the prompt text, for a certain annotated text, the higher the similarity between the characters in the annotated text and the characters in the target text, the greater the possibility that the semantics of the annotated text matches the semantics of the target text, that is, the greater the possibility that the annotated text belongs to the answer to the answer item. Therefore, when predicting the character features of the answer item, the computer device takes into account the character features of the characters in the prompt text and the similarity between the characters, thereby predicting more accurate character features of the answer item, which is conducive to improving the accuracy of the predicted answer item.

[0200] In one possible implementation, a computer device obtains query features, key features, and value features corresponding to the character features of each character. The query features of multiple characters form a query matrix, the key features of multiple characters form a key matrix, and the value features of multiple characters form a value matrix. The computer device normalizes the product of the transpose of the query matrix and the key matrix and a scaling factor to obtain a similarity matrix, which includes similarities between the multiple characters. The computer device multiplies the similarity matrix with the value matrix to obtain encoded character features of the multiple characters, and determines the character features of the answer item from the encoded character features of the multiple characters.

[0201] The computer device performs different spatial transformations on the character features and can obtain corresponding query features, key features and value features. Among them, the query features, key features and value features belong to different feature spaces respectively, and the query features can determine the degree of matching between the key features and the value features. Optionally, the computer device obtains a parameter matrix, which is used to perform spatial transformation on the text features. The computer device multiplies the text features with the parameter matrix to obtain a semantic matrix, and obtains query features, key features and value features based on the semantic matrix. For example, the parameter matrix is ​​a 3-dimensional parameter matrix, and the semantic matrix obtained by multiplying the text features and the parameter matrix is ​​a 3-dimensional semantic matrix. The computer device uses each dimension of the semantic matrix as a query feature, a key feature and a value feature.

[0202] The computer device obtains a scaling factor, which represents a normalized scaling factor. In an embodiment of the present application, the computer device determines the product of the transpose of the query matrix and the key matrix, and the product can represent the correlation between the query matrix and the key matrix. The computer device uses the scaling factor as a normalization parameter to normalize the product to obtain a normalized feature, which characterizes the correlation between the query matrix and the key matrix. The computer device can use the normalized feature as the weight of the value matrix, so the computer device determines the product between the normalized feature and the value matrix as the encoded character feature.

[0203] For example, the computer device uses the following formula (3) to determine the encoded character features.

[0204]

[0205] Among them, Attention(Q,K,V) represents the encoded character features, Q represents the query matrix, K represents the key matrix, and V represents the value matrix. represents the scaling factor, the d k is the dimension of character features. Softmax(·) represents the normalization function, and T represents transposition.

[0206] In an embodiment of the present application, the computer device adopts the above-mentioned self-attention encoding mechanism to perform self-attention encoding on the characters in the prompt text, so that the character features obtained by encoding take into account the influence of other character features on the character features, thereby extracting deeper character features and increasing the amount of information contained in the character features. Therefore, the subsequent prediction of the character features of the answer item based on the character features can improve the accuracy of the predicted character features.

[0207] 505. The computer device decodes the character features of the answer item to obtain predicted probabilities of multiple annotated texts.

[0208] The predicted probability of the annotated text represents the probability that the semantics of the annotated text matches the semantics of the target text.

[0209] In one possible implementation, a computer device performs feature transformation on the character features of the answer item to obtain a reference feature. The reference feature includes feature values ​​in multiple dimensions, each dimension corresponding to an annotated text. The computer device normalizes the feature values ​​in each dimension of the reference feature to obtain a predicted probability corresponding to the annotated text corresponding to each dimension.

[0210] In an embodiment of the present application, the character features of the answer item are transformed according to the dimension of the annotated text to obtain the feature value on the dimension corresponding to each annotated text. The feature value can represent the degree of semantic matching between the annotated text corresponding to the dimension and the prompt text. Therefore, the feature value of each dimension is normalized to obtain the prediction probability corresponding to the annotated text corresponding to each dimension, which provides a simple and fast decoding method and is conducive to improving decoding efficiency.

[0211] Optionally, after obtaining the character features of the answer item, the computer device uses the following formula (4) to decode the character features of the answer item to obtain the predicted probabilities of the multiple annotated texts.

[0212] q(y|x)=softmax(w T *Transformer(x)+b)| y ; Formula (4)

[0213] Where w and b are decoding parameters, Transformer(·) represents the function used to extract the character features of the answer item, x represents the target text, Transformer(x) represents the character features of the answer item, softmax(·) represents the normalization function, q(y|x) represents the predicted probability, y represents the annotated text, and T represents transpose.

[0214] 506. The computer device determines the annotated text with the highest prediction probability among the multiple annotated texts as the answer to obtain the target annotated text.

[0215] For example, the predicted answer is the predicted probability of the candidate identifier, which is also the predicted probability of the annotated text in the candidate indicated by the candidate identifier. The candidate identifiers are a, b, c, and d. The predicted probabilities are q(y=a|x)=0.5, q(y=b|x)=0.2, q(y=c|x)=0.2, and q(y=d|x)=0.1, respectively. The predicted answer is a, and the semantics of the annotated text in the candidate indicated by a match the semantics of the target text.

[0216] 507. The computer device determines the category corresponding to the target annotated text as the category to which the target text belongs.

[0217] Since the semantics of the annotated text is equivalent to the semantics of the category, and the semantics of the target annotated text matches the semantics of the target text, that is, the semantics of the category corresponding to the target annotated text matches the semantics of the target text, the category corresponding to the target annotated text is also the category to which the target text belongs.

[0218] In one possible implementation, each candidate item is associated with a candidate item identifier. The answer predicted by the computer device is the predicted probability of the candidate item identifier. The predicted probability of the candidate item identifier is also the predicted probability of the annotated text in the candidate item indicated by the candidate item identifier. In addition, the computer device stores a mapping relationship between the candidate item identifier and the category. The annotated text in the candidate item indicated by the candidate item identifier is the annotated text of the category mapped by the candidate item identifier.

[0219] Therefore, after obtaining the predicted probability of each candidate item identifier, the computer device determines the category mapped to the candidate item identifier with the largest predicted probability as the category to which the target text belongs.

[0220] For example, in the sensitive text recognition task described above, the multiple categories include Level 0, Level 1, Level 2, and Level 3 verbal abuse. The target text is "You speak so rudely," and the prompt text is "You speak so rudely? a. Expressing a normal opinion. b. Mildly demeaning others. c. Hurtful, expressing negative emotions. d. Provoking conflict, strongly demeaning others. The answer is &." Level 0 verbal abuse is mapped to a, Level 1 verbal abuse is mapped to b, Level 2 verbal abuse is mapped to c, and Level 3 verbal abuse is mapped to d. The candidate with the highest predicted probability is labeled b, and the category mapped to b is Level 1 verbal abuse. Therefore, we can determine that the target text "You speak so rudely" belongs to the Level 1 verbal abuse category.

[0221] The method provided in the embodiment of the present application combines the target text with various categories of annotated text and the answer item to be predicted when classifying the target text to obtain a prompt text, and selects a target annotated text that matches the semantics of the target text based on the semantic relationship between the characters in the prompt text. The category indicated by the target annotated text is the category to which the target text belongs, thereby converting the text classification task into a semantic understanding task, which is equivalent to selecting an annotated text that matches the semantics of the target text from multiple annotated texts based on the semantics of the target text and the semantics of the annotated text, thus reducing the difficulty of text classification. And because the semantics of the annotated text is equivalent to the semantics of the category, this solution can combine the semantics of the text to be classified and the semantics of various categories to classify the text to be classified, which is conducive to improving the accuracy of text classification.

[0222] On the basis of the above embodiment, the computer device also stores a semantic detection model, which is used to determine the semantics of the text. The computer device calls the semantic detection model and determines the prediction probability of multiple annotated texts based on the semantic relationship between the characters in the prompt text. That is, the above steps 203, 304 or 503-505 are performed based on the semantic detection model. Optionally, the model structure of the semantic detection model is Transformer. The training process of the semantic detection model is described below. Figure 8 The embodiment shown.

[0223] In one possible implementation, the semantic detection model includes a feature extraction network, a feature processing network and a probability prediction network. The feature extraction network is connected to the feature processing network, and the feature processing network is connected to the probability prediction network. The output of the feature extraction network is the input of the feature processing network, and the output of the feature processing network is the input of the probability prediction network. The feature extraction network is used to extract character features of each character in the text, the feature processing network is used to encode character features, and the probability prediction network is used to predict probabilities based on character features.

[0224] Figure 6 This is a structural diagram of a semantic detection model provided in an embodiment of the present application. Figure 6 As shown, the semantic detection model includes a feature extraction network 601, a feature processing network 602 and a probability prediction network 603.

[0225] Optionally, the feature extraction network 601 includes a first extraction layer, a second extraction layer, and a fusion layer. The first extraction layer is used to extract semantic features of each character in the text, the second extraction layer is used to extract positional features of each character in the text, and the fusion layer is used to fuse the features extracted by the first extraction layer with the features extracted by the second extraction layer 602.

[0226] The first extraction layer is connected to the fusion layer, the second extraction layer is connected to the fusion layer, and the output of the first extraction layer and the output of the second extraction layer are input to the fusion layer. The fusion layer is connected to the feature processing network 602, and the output of the fusion layer is input to the feature processing network 602.

[0227] Alternatively, as Figure 6 As shown, the feature processing network 602 includes N groups of network structures, where N is a positive integer. The N groups of network structures are connected in sequence, and each group of network structures includes a self-attention encoding layer, a first normalization layer, a feedforward operation layer, and a second normalization layer. For example, N is 12. The number of at least one group of network structures in the feature processing network 602 is the number with the highest accuracy obtained through multiple experiments.

[0228] The input to the self-attention encoding layer is the query features, key features, and value features corresponding to the text features output by the fusion layer or the previous network structure. The input to the first normalization layer is the output of the self-attention encoding layer and the text features output by the fusion layer or the previous network structure. The input to the feedforward operation layer is the output of the first normalization layer, and the input to the second normalization layer is the output of the feedforward operation layer and the output of the first normalization layer.

[0229] The following Figure 7The illustrated embodiment details the process of calling the semantic detection model to obtain the predicted probabilities of multiple annotated texts.

[0230] Figure 7 This is a flowchart of a text classification method provided by an embodiment of the present application. The embodiment of the present application is executed by a computer device. Figure 7 , the method comprising:

[0231] 701. A computer device obtains a target text to be classified and multiple annotated texts.

[0232] The process of step 701 is the same as that of step 301 above, and will not be repeated here.

[0233] 702. The computer device combines the target text, the multiple annotated texts, and the answer items to be predicted into a prompt text.

[0234] The process of step 702 is the same as the process of steps 302 to 303 above, and will not be repeated here.

[0235] 703. The computer device calls a feature extraction network to extract character features of each character in the prompt text.

[0236] The computer device inputs the prompt text into the feature extraction network of the semantic detection model to obtain the character features of each character in the prompt text. The model structure of the semantic detection model is as described above. Figure 6 shown.

[0237] In one possible implementation, the feature extraction network includes a first extraction layer, a second extraction layer, and a fusion layer. The computer device calls the first extraction layer to extract the semantic features corresponding to each character in the prompt text; calls the second extraction layer to extract the position features corresponding to each character in the prompt text; and calls the fusion layer to fuse the semantic features and position features corresponding to each character to obtain the character features of each character. Optionally, the second extraction layer is represented by the above formulas (1) and (2).

[0238] Among them, the computer device inputs the prompt text into the first extraction layer of the feature extraction network to obtain the semantic features corresponding to each character, inputs the prompt text into the second extraction layer to obtain the position features corresponding to each character, and inputs the semantic features and position features corresponding to each character into the fusion layer to obtain the character features of each character.

[0239] 704. The computer device calls a feature processing network to predict character features of the answer item based on the character features of multiple characters in the prompt text and the similarity between the multiple characters.

[0240] The computer device inputs the character features of multiple characters into the feature processing network in the semantic detection model to obtain the character features of the predicted answer item.

[0241] In one possible implementation, a computer device calls a feature processing network to obtain query features, key features, and value features corresponding to the character features of each character, wherein the query features of multiple characters constitute a query matrix, the key features of multiple characters constitute a key matrix, and the value features of multiple characters constitute a value matrix; the product of the transpose of the query matrix and the key matrix and a scaling factor is normalized to obtain a similarity matrix, wherein the similarity matrix includes similarities between multiple characters; the similarity matrix is ​​multiplied by the value matrix to obtain encoded character features of the multiple characters; and the character features of the answer item are determined among the encoded character features of the multiple characters.

[0242] Optionally, the feature processing network includes a self-attention encoding layer, a first normalization layer, a feedforward operation layer and a second normalization layer. The network structure of the feature processing network is as described above. Figure 6 Optionally, the self-attention encoding layer is represented by the above formula (3), and the feedforward operation layer is a fully connected layer.

[0243] 705. The computer device calls the probability prediction network to decode the character features of the answer item to obtain the prediction probabilities of the multiple annotated texts.

[0244] The computer device inputs the character features of the answer item into the probability prediction network in the semantic detection model to obtain the prediction probability of the multiple annotated texts. The prediction probability of the annotated text represents the probability that the semantics of the annotated text matches the semantics of the target text.

[0245] In one possible implementation, a computer device calls a probability prediction network to perform feature transformation on the character features of the answer item to obtain a reference feature. The reference feature includes feature values ​​of multiple dimensions, where each dimension corresponds to an annotated text. The feature value of each dimension in the reference feature is normalized to obtain the predicted probability corresponding to the annotated text corresponding to each dimension.

[0246] In an embodiment of the present application, by executing the above steps 703 to 705, the semantic detection model is called, and the prediction probability of multiple annotated texts is determined based on the semantic relationship between the characters in the prompt text. Therefore, the semantic detection model is used as a tool to automatically predict the prediction probability of the annotated text, which is beneficial to improving processing efficiency and saving processing resources of computer equipment.

[0247] 706. The computer device determines the annotated text with the highest prediction probability among the multiple annotated texts as the answer to obtain the target annotated text.

[0248] The process of step 706 is the same as that of step 506 above, and will not be repeated here.

[0249] 707. The computer device determines the category corresponding to the target annotated text as the category to which the target text belongs.

[0250] Since the semantics of the annotated text is equivalent to the semantics of the category, and the semantics of the target annotated text matches the semantics of the target text, that is, the semantics of the category corresponding to the target annotated text matches the semantics of the target text, the category corresponding to the target annotated text is also the category to which the target text belongs.

[0251] The method provided in the embodiment of the present application combines the target text with various categories of annotated text and the answer item to be predicted when classifying the target text to obtain a prompt text, and selects a target annotated text that matches the semantics of the target text based on the semantic relationship between the characters in the prompt text. The category indicated by the target annotated text is the category to which the target text belongs, thereby converting the text classification task into a semantic understanding task, which is equivalent to selecting an annotated text that matches the semantics of the target text from multiple annotated texts based on the semantics of the target text and the semantics of the annotated text, thus reducing the difficulty of text classification. And because the semantics of the annotated text is equivalent to the semantics of the category, this solution can combine the semantics of the text to be classified and the semantics of various categories to classify the text to be classified, which is conducive to improving the accuracy of text classification.

[0252] Figure 8 This is a flowchart of a method for training a semantic detection model provided in an embodiment of the present application. The embodiment of the present application is executed by a computer device. Figure 8 , the method comprising:

[0253] 801. A computer device obtains a first sample text, multiple sample annotated texts, and a true category of the first sample text.

[0254] The process of the computer device acquiring the first sample text and the sample annotated texts of various categories is similar to the process of acquiring the target text and the annotated texts of various categories in step 301 above, and will not be repeated here.

[0255] Each sample annotated text indicates a category, and the sample annotated text includes multiple sample description words, each of which is used to describe the category indicated by the sample annotated text. The true category of the first sample text refers to the true category to which the first sample text belongs, and the true category can be a category determined by manual judgment of the first sample text. The multiple categories include the true category.

[0256] It should be noted that if the task type of the classification task is different, the multiple categories to be classified are not exactly the same. The task type of the classification task in the embodiment of the present application can be the same as or different from the task type of the classification task in the above embodiment. Therefore, the multiple categories in the embodiment of the present application can be the same as or different from the multiple categories in the above embodiment. In other words, the multiple categories determined during the model training process can be the same as or different from the multiple categories determined during the model use process.

[0257] 802. The computer device combines the first sample text, multiple sample annotation texts, and answer items to be predicted into a sample prompt text.

[0258] The process of step 802 is similar to the process of combining the target text, multiple annotated texts and the answer item to be predicted in the above step, and will not be repeated here.

[0259] 803. The computer device calls the feature extraction network in the semantic detection model to extract the sample character features of each sample character in the sample prompt text.

[0260] In one possible implementation, the feature extraction network includes a first extraction layer, a second extraction layer, and a fusion layer. The computer device invokes the feature extraction network to extract sample character features for each sample character in the sample prompt text, including: invoking the first extraction layer to extract sample semantic features corresponding to each sample character in the sample prompt text, invoking the second extraction layer to extract sample position features corresponding to each sample character in the sample prompt text, and invoking the fusion layer to fuse the sample semantic features and sample position features corresponding to each sample character to obtain sample character features for each sample character.

[0261] The process of step 803 is the same as that of step 703 above, and will not be repeated here.

[0262] 804. The computer device calls a feature processing network in the semantic detection model to predict the sample character features of the answer item based on the sample character features of multiple sample characters in the sample prompt text and the similarity between the multiple sample characters.

[0263] In an embodiment of the present application, taking into account the association relationship between the characters in the sample prompt text, for a certain sample annotated text, the higher the similarity between the characters in the sample annotated text and the characters in the first sample text, the greater the possibility that the semantics of the sample annotated text matches the semantics of the first sample text, that is, the greater the possibility that the sample annotated text belongs to the answer to the answer item. Therefore, the computer device learns the sample character features of the sample characters in the sample prompt text and the similarity between the sample characters through the feature processing network, and learns the ability to use the sample character features and the similarity between the sample characters to predict the sample character features of the answer item, thereby improving the accuracy of the feature processing network in predicting the answer item.

[0264] In one possible implementation, a computer device calls a feature processing network to obtain sample query features, sample key features, and sample value features corresponding to the sample character features of each sample character, wherein the sample query features of multiple sample characters constitute a sample query matrix, the sample key features of multiple sample characters constitute a sample key matrix, and the sample value features of multiple sample characters constitute a sample value matrix; the transpose of the sample query matrix and the sample key matrix are normalized by multiplying them by a scaling factor to obtain a sample similarity matrix, wherein the sample similarity matrix includes similarities between multiple sample characters; the sample similarity matrix is ​​multiplied by the sample value matrix to obtain encoded sample character features of the multiple sample characters; and the sample character features of the answer item are determined from the encoded sample character features of the multiple sample characters.

[0265] In an embodiment of the present application, a computer device adopts a self-attention encoding mechanism to design a feature processing network, and uses the feature processing network to perform self-attention encoding on sample characters in the sample prompt text, so that the encoded sample character features take into account the influence of other sample character features on the sample character features, so that the feature processing network can extract deeper character features, increase the amount of information contained in the character features extracted by the feature processing network, and thus improve the accuracy of the character features predicted by the feature processing network.

[0266] The process of step 804 is the same as that of step 704 above, and will not be repeated here.

[0267] 805. The computer device calls the probability prediction network in the semantic detection model to decode the sample character features of the answer item to obtain the first sample probability of the multiple sample annotated texts.

[0268] The first sample probability of the sample annotated text represents the probability that the semantics of the sample annotated text predicted by the semantic detection model matches the semantics of the first sample text.

[0269] In one possible implementation, a computer device calls a probability prediction network to perform feature transformation on the sample character features of the answer item to obtain a sample reference feature. The sample reference feature includes sample feature values ​​of multiple dimensions, where each dimension corresponds to a sample annotation text. The sample feature value of each dimension in the sample reference feature is normalized to obtain a first sample probability corresponding to the sample annotation text corresponding to each dimension.

[0270] The process of step 805 is the same as that of step 705 above, and will not be repeated here.

[0271] By executing the above steps 803 to 805 , the semantic detection model is called to determine the first sample probability of the plurality of sample annotation texts based on the semantic relationship between the characters in the sample prompt texts.

[0272] 806. The computer device trains a semantic detection model based on the first sample probability of the sample annotated text of the real category, so as to increase the first sample probability of the sample annotated text of the real category obtained based on the trained semantic detection model.

[0273] Since the true category is the true category to which the first sample text belongs, the greater the first sample probability of the sample annotated text of the true category predicted by the semantic detection model, the higher the accuracy of the semantic detection model. Therefore, the computer device trains the semantic detection model based on the first sample probability of the sample annotated text of the true category to increase the first sample probability of the sample annotated text of the true category obtained based on the trained semantic detection model, thereby improving the accuracy of the semantic detection model.

[0274] In one possible implementation, the computer device determines a first loss parameter based on a first sample probability of the sample labeled text of the real category, where the first loss parameter is negatively correlated with the first sample probability. The computer device trains the semantic detection model based on the first loss parameter to reduce the first loss parameter obtained based on the trained semantic detection model.

[0275] Optionally, the computer device uses the following formula (5) to determine the first loss parameter.

[0276] L1=-log(q(y|x)); Formula (5)

[0277] Among them, y represents the sample annotated text of the true category, x represents the first sample text, q(y|x) represents the first sample probability of the sample annotated text of the true category, and L1 represents the first loss parameter.

[0278] Taking the sensitive text recognition task as an example, the various categories corresponding to this task type include Level 0 insults, Level 1 insults, Level 2 insults, and Level 3 insults. In related technologies, a text classification model is trained so that the text classification model determines which of the following categories the text to be classified belongs to by detecting the semantics of the text to be classified: Level 0 insults, Level 1 insults, Level 2 insults, or Level 3 insults. However, since this method only enables the text classification model to understand the semantics of the text to be classified during training, but does not consider the semantics of the four categories of Level 0 insults, Level 1 insults, Level 2 insults, and Level 3 insults, the text classification model's understanding of the classification task itself is completely dependent on the training data. When the definitions of multiple categories in the text classification task are complex or the distinctions between different categories are vague, the text classification model has difficulty making accurate predictions.

[0279] In the method provided in the embodiment of the present application, the annotated text of each category is explicitly combined with the text to be classified. The semantic detection model classifies the text to be classified by determining the semantics of the prompt text obtained by the combination. This allows the semantic detection model to combine the semantics of the text to be classified with the semantics of the annotated text of each category for processing, thereby making more accurate predictions. Furthermore, by combining the text with the answer item to be predicted, the semantic detection model selects the annotated text that matches the semantics of the text to be classified by predicting the answer item, thereby converting the classification task into a natural language understanding task. This facilitates the semantic detection model to classify the text by understanding the semantics of the text, thereby improving the performance of the text classification task.

[0280] In the above Figure 8 Based on the embodiment shown, the semantic detection model trained by the computer device can be a pre-trained semantic detection model. Pre-training the semantic detection model is beneficial to improving the effect of the training model in subsequent classification tasks. There are two ways of pre-training, see the following for details. Figure 9 The embodiment shown and Figure 10 In the illustrated embodiment, the computer device pre-trains the semantic detection model using at least one of the two pre-training methods. Optionally, the pre-training technology used is BERT.

[0281] Figure 9 This is a flowchart of a method for training a semantic detection model provided in an embodiment of the present application. The embodiment of the present application is executed by a computer device. Figure 9 , the method comprising:

[0282] 901. A computer device obtains a second sample text and deletes a target character at a target position in the second sample text. The target position may be any position in the second sample text.

[0283] The computer device obtains a second sample text, which can be any type of text. The computer device deletes the target character at the target position in the second sample text, or replaces the target character at the target position with a second reference character. The target position can be a pre-set position or a randomly determined position, and the embodiments of the present application are not limited to this.

[0284] 902. The computer device calls a semantic detection model to determine a second sample probability of each character in the character set based on the semantic relationship between characters in the second sample text.

[0285] The computer device inputs the second sample text after deleting the target character into the semantic detection model to obtain a second sample probability for each character in a character set, the character set including multiple characters, the character set including at least the target character. The second sample probability of a character represents the probability predicted by the semantic detection model that the character belongs to the character at the target position.

[0286] 903. The computer device trains a semantic detection model based on the second sample probability of the target character, so as to increase the second sample probability of the target character obtained based on the trained semantic detection model.

[0287] Since the target character is the real character at the target position, the greater the second sample probability of the target character predicted by the semantic detection model, the higher the accuracy of the semantic detection model. Therefore, the computer device trains the semantic detection model based on the second sample probability of the target character to increase the second sample probability of the target character obtained based on the trained semantic detection model, thereby improving the accuracy of the semantic detection model.

[0288] In one possible implementation, the computer device determines a second loss parameter based on the second sample probability of the target character, where the second loss parameter is negatively correlated with the second sample probability. The computer device trains the semantic detection model based on the second loss parameter to reduce the second loss parameter obtained based on the trained semantic detection model.

[0289] Optionally, the computer device uses the following formula (6) to determine the second loss parameter.

[0290] L2=-logq(m); Formula (6)

[0291] Where m represents the target character, q(m) represents the second sample probability of the target character, and L2 represents the second loss parameter.

[0292] The semantic detection model trained in the embodiment of the present application is a masked language model (MLM), which masks some characters in the text and inputs the text with masked characters into the semantic detection model, so that the semantic detection model predicts the masked characters by understanding the semantics of the context in the text, thereby improving the ability of the semantic detection model to understand semantics.

[0293] Figure 10 This is a flowchart of a method for training a semantic detection model provided in an embodiment of the present application. The embodiment of the present application is executed by a computer device. Figure 10 , the method comprising:

[0294] 1001. A computer device obtains a third sample text, a fourth sample text, a first true probability, and a second true probability.

[0295] The first true probability represents the probability that the fourth sample text is the next sentence of the third sample text, and the second true probability represents the probability that the fourth sample text is not the next sentence of the third sample text.

[0296] For example, if the fourth sample text is the next sentence of the third sample text, the first true probability is 1 and the second true probability is 0. For another example, if the fourth sample text is not the next sentence of the third sample text, the first true probability is 0 and the second true probability is 1.

[0297] 1002. The computer device calls a semantic detection model to determine a third sample probability and a fourth sample probability based on a semantic relationship between characters in the third sample text and the fourth sample text.

[0298] The computer device inputs the third sample text and the fourth sample text into the semantic detection model to obtain a third sample probability and a fourth sample probability. The third sample probability represents the probability that the fourth sample text predicted by the semantic detection model is the next sentence of the third sample text, and the fourth sample probability represents the probability that the fourth sample text predicted by the semantic detection model is not the next sentence of the third sample text.

[0299] 1003. The computer device trains a semantic detection model based on the third sample probability, the fourth sample probability, the first true probability, and the second true probability, so that the similarity between the third sample probability obtained based on the trained semantic detection model and the first true probability increases, and the similarity between the fourth sample probability obtained and the second true probability increases.

[0300] Since the first true probability is the true probability that the fourth sample text is the next sentence of the third sample text, the second true probability is the true probability that the fourth sample text is not the next sentence of the third sample text, and the third sample probability and the fourth sample probability are the probabilities predicted by the semantic detection model, the greater the similarity between the third sample probability predicted by the semantic detection model and the first true probability, and the greater the similarity between the predicted fourth sample probability and the second true probability, the higher the accuracy of the semantic detection model. Therefore, the computer device trains the semantic detection model based on the third sample probability, the fourth sample probability, the first true probability and the second true probability, so that the similarity between the third sample probability obtained based on the trained semantic detection model and the first true probability increases, and the similarity between the fourth sample probability obtained and the second true probability increases, thereby improving the accuracy of the semantic detection model.

[0301] In one possible implementation, the computer device determines a third loss parameter based on the third sample probability, the fourth sample probability, the first true probability, and the second true probability. The third loss parameter is negatively correlated with the first similarity and the second similarity, where the first similarity refers to the similarity between the third sample probability and the first true probability, and the second similarity refers to the similarity between the fourth sample probability and the second true probability. The computer device trains the semantic detection model based on the third loss parameter to reduce the third loss parameter obtained based on the trained semantic detection model.

[0302] Optionally, the computer device uses the following formula (7) to determine the third loss parameter.

[0303]

[0304] in, Represents an event set, which includes two events: one is that the fourth sample text is the next sentence of the third sample text, and the other is that the fourth sample text is not the next sentence of the third sample text. n represents an event set In the event, p(n) represents the true probability of event n, and q(n) represents the sample probability of event n predicted by the semantic detection model. L3 represents the third loss parameter.

[0305] The semantic detection model trained in the embodiment of the present application belongs to a Next Sentence Prediction (NSP) model, which is used to perform binary classification tasks. Two texts are input into the semantic detection model, so that the semantic detection model can predict whether one of the texts belongs to the next sentence of the other text by understanding the semantics of the two texts, thereby improving the ability of the semantic detection model to understand semantics.

[0306] Figure 11This is a flowchart of another text classification method provided by an embodiment of the present application. Figure 11 As shown, the method includes the following steps:

[0307] 1101. Construct prompt text.

[0308] A computer device obtains a text to be classified and annotated texts of multiple categories, fills the text to be classified and the annotated texts of multiple categories into a prompt template, and obtains a prompt text. The prompt text can indicate that among the multiple annotated texts, an annotated text that matches the semantics of the text to be classified is selected, thereby semanticizing the classification task so that the semantic detection model can learn the semantics of the text to be classified and the semantics of multiple annotated texts at the same time by detecting the semantics of the prompt text.

[0309] In the technical solution proposed in the embodiment of the present application, an optional prompt template is used to introduce multiple categories of annotation text in the semanticization process, thereby avoiding a large amount of manual design in the template construction process and avoiding the problem of difficulty in describing multiple categories. Among them, the optional prompt template is as follows:

[0310] T = [text to be classified]? a. (Option 1). b. (Option 2). c. (Option 3). ...The answer is {MASK}

[0311] The mapping relationship between candidate identifiers and categories is: category 1 is mapped to a, category 2 is mapped to b, category 3 is mapped to c, category 4 is mapped to d, and so on.

[0312] The candidate items in the embodiment of the present application correspond to candidate item identifiers, which are lowercase letters a, b, c, etc. The method requires the semantic detection model to read each annotated text represented by the candidate item identifiers a, b, c in the text T, and then output the corresponding letters as the answers to the multiple-choice questions through the semantic detection model.

[0313] For different classification tasks, different categories of annotated text can be added to the candidate items, eliminating the need to design separate templates and candidate items for each classification task. For example, using the sentence "You are such a bad person" as the to-be-classified text, the following examples show the resulting prompt texts obtained by filling in the prompt template with options for different classification tasks.

[0314] Sensitive text recognition task: Are you really speaking harshly? a. Expressing a normal opinion. b. Mildly derogatory. c. Hurtful and negative. d. Provoking a fight and strongly derogatory. The answer is &.

[0315] Text sentiment recognition task: Are you speaking harshly? a. Positive, affirmative, positive, healthy, friendly, praising, blessing. b. Neutral, sticking to the facts. c. Negative, negative, gloomy, pessimistic, complaining, extreme, uncomfortable. d. Extreme, angry, depressed. The answer is &.

[0316] Ad text recognition task: Are you speaking rudely? a. Normal speech. b. Promotion, number, contact information. c. Advertisement, recommendation, search, contains links, number, contact information. The answer is &.

[0317] 1102. Call the semantic detection model for processing.

[0318] The embodiment of the present application uses a semantic detection model to process the prompt text and obtain the predicted probabilities of multiple annotated texts. Among them, the model structure adopted by the embodiment of the present application is Transformer, and the specific processing process is as follows.

[0319] (1) Feature extraction. The semantic detection model extracts the text features corresponding to the prompt text. The semantic detection model extracts the semantic features corresponding to each character in the prompt text and extracts the positional features corresponding to each character in the prompt text (positional encoding). The semantic features and positional features corresponding to each character are then added together to obtain the character features corresponding to the character.

[0320] (2) Feature encoding. The semantic detection model encodes the character features to obtain the encoded character features. In the embodiment of the present application, the character features are encoded by using N-step serial self-attention encoding. According to the comparison of experimental performance, the encoding effect is best when N is 12. The similarity between the query feature and the key feature corresponding to the character feature is calculated by multiple trainable attention heads (Head), and the value feature corresponding to the character feature is weighted based on the similarity to obtain the encoded character feature. In addition, in addition to self-attention encoding, the encoded text features can also be normalized (Add&Norm) and feed-forwarded (Feed Forward). Among them, normalization is to add the output of the self-attention encoding to the input and then perform normalization, and the feed-forward operation is completed by a trainable fully connected neural network.

[0321] After N steps of self-attention encoding, the text features corresponding to the prompt text become high-level character features with the same dimensions as the input character features, which are also called encoded character features. From these encoded character features, the character features corresponding to the answer items in the prompt text are obtained.

[0322] (3) Feature decoding: After obtaining the character features corresponding to the answer item, the character features corresponding to the answer item are input into a fully connected neural network layer to obtain the predicted probabilities of multiple annotated texts.

[0323] 1103. Is it the training phase?

[0324] If the current phase is the training phase of the semantic detection model, then the following step 1104 is executed. If the current phase is not the training phase of the semantic detection model but the usage phase of the semantic detection model, then the following step 1105 is executed.

[0325] 1104. Update the model parameters of the semantic detection model.

[0326] To enable the semantic detection model to jointly understand the semantics of the text to be classified and the semantics of the annotated texts of various categories, it is necessary to fine-tune the semantic detection model and update its model parameters. After obtaining the predicted probabilities of multiple annotated texts, the cross-entropy between the predicted probabilities and the true probabilities of the annotated texts of the actual categories of the text to be classified is determined as the loss parameter to be optimized. Based on this loss parameter, the model parameters of the semantic detection model are updated using gradient descent.

[0327] It should be noted that this semantic detection model is a pre-trained semantic detection model. Before using it for classification tasks, it is unsupervisedly pre-trained on a large-scale corpus. Determining the model parameters from this large corpus helps improve the performance of subsequent classification tasks.

[0328] The pre-training technology used is BERT, and the pre-training objectives include a masked language model and a subsequent sentence prediction model. The masked language model masks some characters in a text and then feeds the masked text into a semantic detection model. This allows the semantic detection model to predict the masked characters by understanding the contextual semantics of the text, thereby improving the semantic detection model's ability to understand semantics. The subsequent sentence prediction model feeds two texts into the semantic detection model, allowing the semantic detection model to understand the semantics of the two texts and predict whether one text belongs to the next sentence of the other text, thereby improving the semantic detection model's ability to understand semantics.

[0329] 1105. Determine the category indicated by the annotated text as the category to which the text to be classified belongs.

[0330] In step 1102, the predicted probabilities of the multiple annotated texts are obtained, wherein the predicted probabilities of the multiple annotated texts are represented by the predicted probabilities of the multiple candidate item identifiers, and the computer device determines the candidate item identifier with the highest predicted probability.

[0331] Based on the mapping relationship between candidate identifiers and categories defined in step 1101 above, the categories corresponding to candidate identifiers a, b, c, and d can be determined. For example, in the scenario of sensitive text recognition tasks, the multiple categories include level 0 abuse, level 1 abuse, level 2 abuse, and level 3 abuse. Level 0 abuse is mapped to a, level 1 abuse is mapped to b, level 2 abuse is mapped to c, and level 3 abuse is mapped to d. For the text to be classified as "You speak so rudely", the candidate identifier with the highest predicted probability is b, so the text to be classified as "You speak so rudely" is classified as level 1 abuse.

[0332] The embodiments of the present application use a prompt template with options to semantically transform the classification task into a multiple-choice question, effectively solving the following problems: 1. For classification tasks, the answer in the answer item is the candidate identifier, which is lowercase characters {a, b, c, d...}. This avoids the problem of manually designing candidates for each category of annotated text, saving labor costs and trial-and-error costs. 2. Filling the category annotated text into the candidate items of the prompt template enables the semantic detection model to detect the semantics of the annotated text in the form of natural language based on pre-trained model parameters, avoiding the problem that the semantic detection model has difficulty understanding complex categories.

[0333] In order to demonstrate the effect achieved by the method provided in the embodiments of the present application, experiments were conducted in 9 different classification tasks using the methods of related technologies and the methods provided in the embodiments of the present application. The experimental results are shown in Table 1 below, where the experimental results are represented by two performance indicators, namely, accuracy and the macro-average F-1 value of multiple categories (Macro-F1).

[0334] Table 1

[0335]

[0336] As can be seen from Table 1, the method provided in the embodiment of the present application exceeds or is equivalent to the effects of the relevant technologies in 9 classification tasks and two performance indicators, and has achieved an improvement of more than 1 percentage point in classification tasks such as insult classification, vulgarity recognition, typo recognition, and propaganda recognition, which is a significant improvement and verifies the effectiveness of the method provided in the embodiment of the present application.

[0337] Figure 12 This is a structural diagram of a text classification device provided in an embodiment of the present application. Figure 12 , the device comprises:

[0338] An acquisition module 1201 is configured to acquire a target text to be classified and a plurality of annotated texts, each of which indicates a category and includes a plurality of descriptive words used to describe the category indicated by the annotated text;

[0339] A combining module 1202 is configured to combine the target text, the plurality of annotated texts, and the answer items to be predicted into a prompt text;

[0340] Prediction module 1203, configured to predict the answer in the answer item from the plurality of annotated texts based on the semantic relationship between the characters in the prompt text, and obtain a target annotated text that semantically matches the target text;

[0341] The determination module 1204 is configured to determine the category indicated by the target annotated text as the category to which the target text belongs.

[0342] The text classification device provided in the embodiment of the present application combines the target text with various categories of annotated text and the answer item to be predicted when classifying the target text to obtain a prompt text, and selects a target annotated text that matches the semantics of the target text based on the semantic relationship between the characters in the prompt text. The category indicated by the target annotated text is the category to which the target text belongs, thereby converting the text classification task into a semantic understanding task, which is equivalent to selecting an annotated text that matches the semantics of the target text from multiple annotated texts based on the semantics of the target text and the semantics of the annotated text, thus reducing the difficulty of text classification. And because the semantics of the annotated text is equivalent to the semantics of the category, this solution can combine the semantics of the text to be classified and the semantics of various categories to classify the text to be classified, which is conducive to improving the accuracy of text classification.

[0343] Alternatively, see Figure 13 The combined module 1202 includes:

[0344] The template acquisition unit 1212 is used to acquire a prompt template, wherein the prompt template includes a matching item to be filled, multiple candidate items to be filled, and the answer item to be predicted, wherein the matching item is used to fill the text to be classified, and the candidate item is used to fill the text that semantically matches the text to be classified;

[0345] The filling unit 1222 is configured to fill the target text into the matching item and fill the multiple annotated texts into the candidate items in the prompt template to obtain the prompt text.

[0346] Alternatively, see Figure 13 The prompt template also includes a candidate item identifier corresponding to each candidate item; the prediction module 1203 is used to:

[0347] Based on the semantic relationship between the characters in the prompt text, predict the answer in the answer item from the candidate item identifiers corresponding to the multiple candidate items to obtain a target candidate item identifier;

[0348] The annotation text filled in the candidate item indicated by the target candidate item identifier is determined as the target annotation text.

[0349] Alternatively, see Figure 13 The combined module 1202 is used to:

[0350] The target text, the multiple annotated texts, the answer item and a prompt word constitute the prompt text, and the prompt word is used to prompt that a target annotated text that matches the semantics of the target text be selected from the multiple annotated texts as the answer in the answer item.

[0351] Alternatively, see Figure 13 The prediction module 1203 is used to:

[0352] Extracting character features of each character in the prompt text;

[0353] Predicting the character features of the answer item based on the character features of multiple characters in the prompt text and the similarity between the multiple characters; decoding the character features of the answer item to obtain the predicted probabilities of the multiple annotated texts, wherein the predicted probabilities of the annotated texts represent the probabilities that the semantics of the annotated texts match the semantics of the target text;

[0354] The annotated text with the highest predicted probability is determined as the answer to obtain the target annotated text.

[0355] Alternatively, see Figure 13 The prediction module 1203 is used to:

[0356] Obtaining query features, key features, and value features corresponding to the character features of each character, wherein the query features of the multiple characters constitute a query matrix, the key features of the multiple characters constitute a key matrix, and the value features of the multiple characters constitute a value matrix;

[0357] Normalizing the query matrix, the product of the transpose of the key matrix and the scaling factor to obtain a similarity matrix, the similarity matrix including similarities between the plurality of characters;

[0358] Multiplying the similarity matrix by the value matrix to obtain encoded character features of the multiple characters;

[0359] The character feature of the answer item is determined from the encoded character features of the plurality of characters.

[0360] Alternatively, see Figure 13 The prediction module 1203 is used to:

[0361] Performing feature transformation on the character features of the answer item to obtain a reference feature, where the reference feature includes feature values ​​of multiple dimensions, each dimension corresponding to a labeled text;

[0362] The feature value of each dimension in the reference feature is normalized to obtain the prediction probability corresponding to the annotated text corresponding to each dimension.

[0363] Alternatively, see Figure 13 The acquisition module 1201 is used to:

[0364] Obtaining the target text to be classified, and determining a task type to which a classification task corresponding to the target text belongs, the task type including at least one of a text quality grading task, a text sentiment recognition task, a sensitive text recognition task, or an advertising text recognition task;

[0365] Determine the multiple categories corresponding to the task type. Each task type corresponds to multiple categories, and the categories corresponding to different task types are not exactly the same.

[0366] Get the label text corresponding to each category in the multiple categories.

[0367] Alternatively, see Figure 13 The prediction module 1203 is used to:

[0368] Invoking a semantic detection model to determine, based on semantic relationships between characters in the prompt text, prediction probabilities of the multiple annotated texts, wherein the prediction probabilities of the annotated texts represent probabilities that the semantics of the annotated texts match the semantics of the target text;

[0369] Among the multiple annotated texts, the annotated text with the highest prediction probability is determined as the answer to obtain the target annotated text.

[0370] Alternatively, see Figure 13 , the device further comprises:

[0371] The acquisition module 1201 is further configured to acquire a first sample text, a plurality of sample annotated texts, and a true category of the first sample text, wherein each sample annotated text indicates a category, and the sample annotated text includes a plurality of sample description words, wherein the plurality of sample description words are used to describe the category indicated by the sample annotated text;

[0372] The combining module 1202 is further configured to combine the first sample text, the plurality of sample annotated texts, and the answer items to be predicted into a sample prompt text;

[0373] The prediction module 1203 is further configured to call the semantic detection model to determine a first sample probability of the plurality of sample annotated texts based on the semantic relationship between characters in the sample prompt text, where the first sample probability of the sample annotated text represents a probability that the semantics of the sample annotated text predicted by the semantic detection model matches the semantics of the first sample text;

[0374] The first training module 1205 is used to train the semantic detection model based on the first sample probability of the sample annotated text of the real category, so as to increase the first sample probability of the sample annotated text of the real category obtained based on the trained semantic detection model.

[0375] Alternatively, see Figure 13 The semantic detection model includes a feature extraction network, a feature processing network and a probability prediction network. The prediction module 1203 is used to:

[0376] Calling the feature extraction network to extract sample character features of each sample character in the sample prompt text;

[0377] calling the feature processing network to predict the sample character features of the answer item based on the sample character features of the plurality of sample characters in the sample prompt text and the similarities between the plurality of sample characters;

[0378] The probability prediction network is called to decode the sample character features of the answer item to obtain the first sample probability of the multiple sample annotated texts.

[0379] Alternatively, see Figure 13 The prediction module 1203 is used to:

[0380] Calling the feature processing network to obtain a sample query feature, a sample key feature, and a sample value feature corresponding to the sample character feature of each sample character, wherein the sample query features of the multiple sample characters constitute a sample query matrix, the sample key features of the multiple sample characters constitute a sample key matrix, and the sample value features of the multiple sample characters constitute a sample value matrix;

[0381] Normalizing the product of the transpose of the sample query matrix and the sample key matrix and the scaling factor to obtain a sample similarity matrix, wherein the sample similarity matrix includes similarities between the plurality of sample characters;

[0382] Multiplying the sample similarity matrix by the sample value matrix to obtain encoded sample character features of the plurality of sample characters;

[0383] The sample character feature of the answer item is determined from the encoded sample character features of the plurality of sample characters.

[0384] Alternatively, see Figure 13 , the device further comprises:

[0385] The acquisition module 1201 is further configured to acquire a second sample text and delete a target character at a target position in the second sample text, where the target position is any position in the second sample text;

[0386] The prediction module 1203 is further configured to call the semantic detection model to determine, based on the semantic relationship between characters in the second sample text, a second sample probability of each character in the character set, where the second sample probability of the character represents a probability predicted by the semantic detection model that the character belongs to the character at the target position, and the character set includes the target character;

[0387] The second training module 1206 is configured to train the semantic detection model based on the second sample probability of the target character, so as to increase the second sample probability of the target character obtained based on the trained semantic detection model.

[0388] Alternatively, see Figure 13 , the device further comprises:

[0389] The acquisition module 1201 is further configured to acquire a third sample text, a fourth sample text, a first true probability, and a second true probability, wherein the first true probability indicates a probability that the fourth sample text is the next sentence of the third sample text, and the second true probability indicates a probability that the fourth sample text is not the next sentence of the third sample text;

[0390] The prediction module 1203 is further configured to call the semantic detection model to determine, based on the semantic relationship between characters in the third sample text and the fourth sample text, a third sample probability and a fourth sample probability, wherein the third sample probability represents a probability that the fourth sample text predicted by the semantic detection model is the next sentence of the third sample text, and the fourth sample probability represents a probability that the fourth sample text predicted by the semantic detection model is not the next sentence of the third sample text;

[0391] The third training module 1207 is used to train the semantic detection model based on the third sample probability, the fourth sample probability, the first true probability and the second true probability, so that the similarity between the third sample probability obtained based on the trained semantic detection model and the first true probability increases, and the similarity between the fourth sample probability obtained and the second true probability increases.

[0392] It should be noted that the text classification device provided in the above embodiment is merely an example of the division of the functional modules described above. In actual applications, the above functions can be assigned to different functional modules as needed. In other words, the internal structure of the computer device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the text classification device provided in the above embodiment and the text classification method embodiment are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0393] An embodiment of the present application also provides a computer device, which includes a processor and a memory, wherein the memory stores at least one computer program, and the at least one computer program is loaded and executed by the processor to implement the operations performed in the text classification method of the above embodiment.

[0394] Optionally, the computer device is provided as a terminal. Figure 14 A schematic structural diagram of a terminal 1400 provided by an exemplary embodiment of the present application is shown.

[0395] The terminal 1400 includes a processor 1401 and a memory 1402 .

[0396] The processor 1401 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 1401 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), or PLA (Programmable Logic Array). The processor 1401 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 1401 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1401 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0397] Memory 1402 may include one or more computer-readable storage media, which may be non-transitory. Memory 1402 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in memory 1402 is used to store at least one computer program, which is used by processor 1401 to implement the text classification method provided in the method embodiment of the present application.

[0398] In some embodiments, terminal 1400 may optionally include a peripheral device interface 1403 and at least one peripheral device. Processor 1401, memory 1402, and peripheral device interface 1403 may be connected via a bus or signal lines. Each peripheral device may be connected to peripheral device interface 1403 via a bus, signal lines, or circuit boards. Optionally, the peripheral device includes at least one of a radio frequency circuit 1404 and a display screen 1405.

[0399] The peripheral device interface 1403 can be used to connect at least one I / O (Input / Output)-related peripheral device to the processor 1401 and the memory 1402. In some embodiments, the processor 1401, the memory 1402, and the peripheral device interface 1403 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1401, the memory 1402, and the peripheral device interface 1403 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.

[0400] RF circuit 1404 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. RF circuit 1404 communicates with communication networks and other communication devices via electromagnetic signals. RF circuit 1404 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, RF circuit 1404 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. RF circuit 1404 can communicate with other devices via at least one wireless communication protocol. Such wireless communication protocols include, but are not limited to, metropolitan area networks, various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks, and / or WiFi (Wireless Fidelity) networks. In some embodiments, RF circuit 1404 may also include circuits related to NFC (Near Field Communication), which is not limited in this application.

[0401] The display screen 1405 is used to display a UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 1405 is a touch screen display, the display screen 1405 also has the ability to collect touch signals on the surface or above the surface of the display screen 1405. The touch signal can be input as a control signal to the processor 1401 for processing. At this time, the display screen 1405 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, there can be one display screen 1405, which is set on the front panel of the terminal 1400; in other embodiments, there can be at least two display screens 1405, which are respectively set on different surfaces of the terminal 1400 or in a folding design; in other embodiments, the display screen 1405 can be a flexible display screen, which is set on the curved surface or folding surface of the terminal 1400. Even more, the display screen 1405 can be set to a non-rectangular irregular shape, that is, a special-shaped screen.

[0402] Those skilled in the art will understand that Figure 14 The structure shown in the figure does not constitute a limitation on the terminal 1400, and the terminal 1400 may include more or fewer components than shown in the figure, or combine certain components, or adopt a different component arrangement.

[0403] Optionally, the computer device is provided as a server. Figure 15 This is a schematic diagram of the structure of a server provided in an embodiment of the present application. The server 1500 may have relatively large differences due to different configurations or performances, and may include one or more processors (Central Processing Units, CPU) 1501 and one or more memories 1502, wherein the memory 1502 stores at least one computer program, and the at least one computer program is loaded and executed by the processor 1501 to implement the methods provided in the above-mentioned various method embodiments. Of course, the server may also have components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output. The server may also include other components for implementing device functions, which will not be described in detail here.

[0404] An embodiment of the present application further provides a computer-readable storage medium, which stores at least one computer program. The at least one computer program is loaded and executed by a processor to implement the operations performed by the text classification method of the above embodiment.

[0405] An embodiment of the present application further provides a computer program product, including a computer program, which is loaded and executed by a processor to implement the operations performed by the text classification method of the above embodiment.

[0406] Those skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, which may be a read-only memory, a disk, or an optical disk, etc.

[0407] The above description is merely an optional embodiment of the embodiments of the present application and is not intended to limit the embodiments of the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the embodiments of the present application shall be included in the scope of protection of the present application.

Claims

1. A text classification method, characterized in that: The method comprises: Obtain a second sample text, and delete a target character at a target position in the second sample text, where the target position is any position in the second sample text; Invoking a semantic detection model to determine, based on semantic relationships between characters in the second sample text, a second sample probability for each character in a character set, wherein the second sample probability of each character represents a probability predicted by the semantic detection model that the character belongs to the character at the target position, and the character set includes the target character; Based on the second sample probability of the target character, training the semantic detection model so as to increase the second sample probability of the target character obtained based on the trained semantic detection model; Acquire a target text to be classified and a plurality of annotated texts, each annotated text indicating a category, the annotated text including a plurality of descriptive words, the plurality of descriptive words being used to describe the category indicated by the annotated text; Combining the target text, the multiple annotated texts and the answer items to be predicted into a prompt text; Calling the semantic detection model to predict the answer in the answer item from the plurality of annotated texts based on the semantic relationship between the characters in the prompt text, and obtaining a target annotated text that semantically matches the target text; The category indicated by the target annotated text is determined as the category to which the target text belongs.

2. The method according to claim 1, characterized in that The step of combining the target text, the plurality of annotated texts, and the answer items to be predicted into a prompt text includes: Obtaining a prompt template, the prompt template including a matching item to be filled, multiple candidate items to be filled, and the answer item to be predicted, wherein the matching item is used to fill the text to be classified, and the candidate item is used to fill the text that semantically matches the text to be classified; In the prompt template, the target text is filled into the matching item, and the multiple annotated texts are filled into the candidate items respectively to obtain the prompt text.

3. The method according to claim 2, characterized in that The prompt template further includes a candidate item identifier corresponding to each candidate item; and the step of predicting the answer in the answer item from the plurality of annotated texts based on the semantic relationship between characters in the prompt text to obtain a target annotated text that semantically matches the target text includes: Based on the semantic relationship between the characters in the prompt text, predict the answer in the answer item from the candidate item identifiers corresponding to the multiple candidate items to obtain a target candidate item identifier; The annotation text filled in the candidate item indicated by the target candidate item identifier is determined as the target annotation text.

4. The method according to claim 1, wherein The step of combining the target text, the plurality of annotated texts, and the answer items to be predicted into a prompt text includes: The target text, the multiple annotated texts, the answer items and prompt words form the prompt text, and the prompt word is used to prompt to select the target annotated text that matches the semantics of the target text from the multiple annotated texts as the answer in the answer item.

5. The method according to claim 1, wherein The calling of the semantic detection model to predict the answer in the answer item from the plurality of annotated texts based on the semantic relationship between characters in the prompt text, and obtaining a target annotated text that semantically matches the target text, includes: Calling the semantic detection model to extract character features of each character in the prompt text; Calling the semantic detection model to predict the character features of the answer item based on the character features of multiple characters in the prompt text and the similarity between the multiple characters; Calling the semantic detection model to decode the character features of the answer item to obtain prediction probabilities of the multiple annotated texts, wherein the prediction probabilities of the annotated texts represent probabilities that the semantics of the annotated texts match the semantics of the target text; The annotated text with the highest predicted probability is determined as the answer to obtain the target annotated text.

6. The method according to claim 5, characterized in that The calling of the semantic detection model to predict the character features of the answer item based on the character features of a plurality of characters in the prompt text and the similarity between the plurality of characters includes: Call the semantic detection model and perform the following operations: Obtaining a query feature, a key feature, and a value feature corresponding to the character feature of each character, wherein the query features of the multiple characters constitute a query matrix, the key features of the multiple characters constitute a key matrix, and the value features of the multiple characters constitute a value matrix; Normalizing the query matrix, the product of the transpose of the key matrix and the scaling factor to obtain a similarity matrix, wherein the similarity matrix includes similarities between the plurality of characters; Multiplying the similarity matrix by the value matrix to obtain encoded character features of the plurality of characters; The character features of the answer item are determined from the encoded character features of the plurality of characters.

7. The method according to claim 5, characterized in that The calling of the semantic detection model to decode the character features of the answer item to obtain the predicted probabilities of the multiple annotated texts includes: Calling the semantic detection model to perform feature transformation on the character features of the answer item to obtain reference features, where the reference features include feature values ​​of multiple dimensions, each dimension corresponding to an annotated text; The semantic detection model is called to normalize the feature value of each dimension in the reference feature to obtain the prediction probability corresponding to the annotated text corresponding to each dimension.

8. The method according to claim 1, characterized in that The step of obtaining the target text to be classified and the plurality of annotated texts includes: Obtaining the target text to be classified, and determining a task type to which a classification task corresponding to the target text belongs, wherein the task type includes at least one of a text quality grading task, a text emotion recognition task, a sensitive text recognition task, or an advertising text recognition task; Determine multiple categories corresponding to the task type, each task type corresponds to multiple categories, and the categories corresponding to different task types are not completely the same; Obtain the annotation text corresponding to each category of the multiple categories.

9. The method according to any one of claims 1 to 8, characterized in that The calling of the semantic detection model to predict the answer in the answer item from the plurality of annotated texts based on the semantic relationship between characters in the prompt text, and obtaining a target annotated text that semantically matches the target text, includes: Calling the semantic detection model to determine prediction probabilities of the plurality of annotated texts based on semantic relationships between characters in the prompt text, wherein the prediction probabilities of the annotated texts represent probabilities that the semantics of the annotated texts match the semantics of the target text; Among the multiple annotated texts, the annotated text with the highest prediction probability is determined as the answer to obtain the target annotated text.

10. The method according to claim 1, characterized in that The training process of the semantic detection model further includes: Obtaining a first sample text, a plurality of sample annotated texts, and a true category of the first sample text, wherein each sample annotated text indicates a category, the sample annotated texts including a plurality of sample description words, and the plurality of sample description words are used to describe the category indicated by the sample annotated text; Combining the first sample text, the plurality of sample annotated texts and the answer items to be predicted into a sample prompt text; Calling the semantic detection model to determine a first sample probability of the plurality of sample annotated texts based on the semantic relationship between characters in the sample prompt text, wherein the first sample probability of the sample annotated text represents a probability that the semantics of the sample annotated text predicted by the semantic detection model matches the semantics of the first sample text; Based on the first sample probability of the sample annotated text of the real category, the semantic detection model is trained to increase the first sample probability of the sample annotated text of the real category obtained based on the trained semantic detection model.

11. The method according to claim 10, characterized in that The semantic detection model includes a feature extraction network, a feature processing network, and a probability prediction network. Calling the semantic detection model to determine the first sample probability of the plurality of sample annotation texts based on the semantic relationship between characters in the sample prompt text includes: Calling the feature extraction network to extract sample character features of each sample character in the sample prompt text; calling the feature processing network to predict the sample character features of the answer item based on the sample character features of a plurality of sample characters in the sample prompt text and the similarities between the plurality of sample characters; The probability prediction network is called to decode the sample character features of the answer item to obtain the first sample probabilities of the multiple sample annotated texts.

12. The method according to claim 11, characterized in that The calling of the feature processing network to predict the sample character features of the answer item based on the sample character features of a plurality of sample characters in the sample prompt text and the similarity between the plurality of sample characters includes: Calling the feature processing network to obtain a sample query feature, a sample key feature, and a sample value feature corresponding to the sample character feature of each sample character, wherein the sample query features of the multiple sample characters constitute a sample query matrix, the sample key features of the multiple sample characters constitute a sample key matrix, and the sample value features of the multiple sample characters constitute a sample value matrix; Normalizing the product of the transpose of the sample query matrix and the sample key matrix and a scaling factor to obtain a sample similarity matrix, wherein the sample similarity matrix includes similarities between the plurality of sample characters; Multiplying the sample similarity matrix by the sample value matrix to obtain encoded sample character features of the plurality of sample characters; The sample character feature of the answer item is determined from the encoded sample character features of the plurality of sample characters.

13. The method according to claim 1, wherein The training process of the semantic detection model further includes: Obtaining a third sample text, a fourth sample text, a first true probability, and a second true probability, wherein the first true probability represents a probability that the fourth sample text is the next sentence of the third sample text, and the second true probability represents a probability that the fourth sample text is not the next sentence of the third sample text; calling the semantic detection model to determine, based on the semantic relationship between characters in the third sample text and the fourth sample text, a third sample probability and a fourth sample probability, wherein the third sample probability represents a probability that the fourth sample text predicted by the semantic detection model is the next sentence of the third sample text, and the fourth sample probability represents a probability that the fourth sample text predicted by the semantic detection model is not the next sentence of the third sample text; Based on the third sample probability, the fourth sample probability, the first true probability and the second true probability, the semantic detection model is trained so that the similarity between the third sample probability obtained based on the trained semantic detection model and the first true probability increases, and the similarity between the fourth sample probability obtained and the second true probability increases.

14. A text classification device, characterized in that: The device comprises: an acquisition module, configured to acquire a second sample text and delete a target character at a target position in the second sample text, where the target position is any position in the second sample text; a prediction module, configured to call a semantic detection model to determine, based on the semantic relationship between characters in the second sample text, a second sample probability of each character in a character set, wherein the second sample probability of each character represents a probability that the character predicted by the semantic detection model belongs to the character at the target position, and the character set includes the target character; A second training module is configured to train the semantic detection model based on the second sample probability of the target character, so as to increase the second sample probability of the target character obtained based on the trained semantic detection model; The acquisition module is further configured to acquire a target text to be classified and a plurality of annotated texts, each annotated text indicating a category, the annotated text including a plurality of descriptive words, the plurality of descriptive words being used to describe the category indicated by the annotated text; a combination module, configured to call the semantic detection model, and combine the target text, the plurality of annotated texts, and an answer item to be predicted into a prompt text, wherein the answer in the answer item has not yet been determined, and the answer in the answer item matches the semantics of the target text; The prediction module is further configured to predict an answer in the answer item from the plurality of annotated texts based on the semantic relationship between characters in the prompt text, and obtain a target annotated text that semantically matches the target text; A determination module is configured to determine the category indicated by the target annotated text as the category to which the target text belongs.

15. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores at least one computer program, and the at least one computer program is loaded and executed by the processor to implement the operations performed by the text classification method according to any one of claims 1 to 13.

16. A computer-readable storage medium, characterized in that The computer-readable storage medium stores at least one computer program, which is loaded and executed by a processor to implement the operations performed by the text classification method according to any one of claims 1 to 13.

17. A computer program product, characterized in that The method comprises a computer program, wherein the computer program is loaded and executed by a processor to implement the operations performed by the text classification method according to any one of claims 1 to 13.

Citation Information

Patent Citations

  • Text classification method, related equipment and readable storage medium

    CN111460149A