Text classification method and device, computer equipment and storage medium

By using knowledge graphs for coarse classification and text classification models with text writing guidance for fine classification in text classification, the problems of limited black network language recognition range and long training cycle in the existing technology are solved, and efficient and accurate text classification is achieved.

CN120670592APending Publication Date: 2025-09-19TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410310027.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-14
Publication Date
2025-09-19

AI Technical Summary

Technical Problem

In the existing technology, the keyword matching method has a limited scope of recognition of black network language, and the traditional classification model training cycle is long, resulting in low text classification accuracy and low efficiency.

Method used

Use the preset knowledge graph to roughly classify the initial text, filter out the target text, and guide the text classification model to perform fine classification through prompt text writing to improve classification accuracy and efficiency.

Benefits of technology

Through the preliminary screening of the knowledge graph and the precise classification of the text classification model, the accuracy and efficiency of text classification are improved, and the latest black network language can be identified in a timely manner.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120670592A_ABST
    Figure CN120670592A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a text classification method and device, computer equipment and a storage medium. Comprising the following steps: obtaining an initial text, and carrying out text matching on the initial text through an entity and an entity relationship in a preset knowledge graph to obtain a target text; writing a prompt text based on the target text to obtain the prompt text corresponding to the target text; inputting the target text and the prompt text into a trained text classification model, and outputting a classification result corresponding to the target text; wherein the trained text classification model is obtained by training according to model loss generated by a target sample text and a sample label, the target sample text is a text obtained by matching an initial sample text with a preset knowledge graph, and the sample label is determined by a sample prompt text obtained by performing prompt text writing according to the target sample text; and determining a text type corresponding to the initial text according to a classification result. And the efficiency and accuracy of performing text classification on the initial text are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of text processing technology, and in particular to a text classification method, apparatus, computer equipment, and storage medium. Background Art

[0002] With the development of internet technology, many new online languages ​​have emerged, allowing users to understand these languages ​​to determine the specific meaning of what is being expressed. However, some illicit industries have also created some "black" online languages, which can convey negative information. Commonly known as "slang," these can mislead users into understanding negative information and affect social security.

[0003] To identify jargon in certain scenarios, related technologies have employed keyword matching to identify jargon in text. Traditional classification models can also be used to identify jargon in text. However, keyword matching is limited in the scope of jargon that can be identified in text, and traditional classification models require manually labeled training samples and have a long training cycle, making it impossible for traditional classification models to timely classify the latest jargon.

[0004] Therefore, there are problems in the related art of low accuracy and low efficiency in text classification. Summary of the Invention

[0005] The embodiments of the present application provide a text classification method, apparatus, computer device, and storage medium, which can improve the accuracy and efficiency of text classification.

[0006] According to one aspect of the present application, a text classification method is provided, comprising:

[0007] Obtain the initial text, perform text matching on the initial text using the entities and entity relationships in the preset knowledge graph to obtain the target text;

[0008] Write prompt text based on target text to obtain prompt text corresponding to the target text;

[0009] Input the target text and prompt text into the trained text classification model and output the classification result corresponding to the target text;

[0010] The trained text classification model is obtained by training the model loss generated based on the target sample text and the sample label. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph. The sample label is determined by the sample prompt text written based on the target sample text.

[0011] The text type corresponding to the initial text is determined based on the classification results.

[0012] According to one aspect of the present application, a text classification device is provided, comprising:

[0013] The text acquisition module is used to obtain the initial text and perform text matching on the initial text through the entities and entity relationships in the preset knowledge graph to obtain the target text;

[0014] A text writing module is used to write a prompt text based on the target text to obtain a prompt text corresponding to the target text;

[0015] The text classification module is used to input the target text and prompt text into the trained text classification model and output the classification result corresponding to the target text;

[0016] The trained text classification model is obtained by training the model loss generated based on the target sample text and the sample label. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph. The sample label is determined by the sample prompt text written based on the target sample text.

[0017] The type determination module is used to determine the text type corresponding to the initial text according to the classification result.

[0018] In some embodiments, the text acquisition module includes an assignment submodule, a matching submodule, a first determination submodule, and a second determination submodule;

[0019] The word segmentation submodule is used to perform word segmentation processing on the initial text to obtain at least one word segmentation text;

[0020] A matching submodule, configured to match at least one segmented text with an entity in the knowledge graph to obtain a first matching entity;

[0021] A first determination submodule is configured to determine a second matching entity based on the first matching entity and the entity relationship in the knowledge graph;

[0022] The second determining submodule is configured to determine the first matching entity and the second matching entity as target text.

[0023] In some embodiments, the matching submodule is configured to:

[0024] Obtain the segmentation text vector corresponding to each segmentation text in at least one segmentation text;

[0025] Determine the similarity between the word segmentation text vector and the entity vector of any entity in the knowledge graph;

[0026] The entity corresponding to the entity vector with the highest similarity to the word segmentation text vector is determined as the first matching entity.

[0027] In some embodiments, the text writing module includes a third determination submodule and a text writing submodule;

[0028] A third determination submodule is configured to determine at least one label corresponding to the target text based on the knowledge graph;

[0029] The text writing submodule is used to write prompt text for the target text according to at least one tag, and obtain the prompt text corresponding to the target text under each tag.

[0030] In some embodiments, the text writing submodule is used to:

[0031] Determine the corresponding prompt text template under each label;

[0032] Prompt text is written for the target text based on the prompt text template to obtain the prompt text corresponding to the target text under each label.

[0033] In some implementations, the text classification module is configured to:

[0034] Determine the amount of data corresponding to the target text;

[0035] A trained text classification model with a corresponding model complexity is determined based on the amount of data, and the target text and prompt text are input into the trained text classification model to output the classification results.

[0036] In some implementations, the text classification module is configured to:

[0037] Determine whether the data volume corresponding to the target text is greater than the preset data volume;

[0038] When the data volume of the target text is greater than the preset data volume, determining the application scenario corresponding to the target text based on the label corresponding to the target text;

[0039] Determine a trained text classification model related to the application scenario, input the target text and prompt text into the trained text classification model, and output the classification result.

[0040] In some embodiments, the type determination module includes a label determination submodule and a type determination submodule;

[0041] The label determination submodule is used to determine the classification label corresponding to the target text based on the classification results;

[0042] The type determination submodule is used to determine the text type corresponding to the initial text according to the classification label.

[0043] In some embodiments, the type determination submodule is configured to:

[0044] When the classification label includes multiple different classification labels, multiple related text types are determined according to the classification labels;

[0045] Determine the number of classification labels corresponding to each relevant text type, and determine the level corresponding to each relevant text type based on the number;

[0046] The related text type with the highest rank is determined as the text type corresponding to the initial text, and other related text types other than the related text type with the highest rank and the rank corresponding to each other related text type are displayed.

[0047] In some embodiments, the text classification apparatus further includes a training module for:

[0048] Obtain sample text, perform text matching on the initial sample text using entities and entity relationships in the preset knowledge graph to obtain the target sample text;

[0049] Writing prompt text for the target sample text to obtain a sample prompt text corresponding to the target sample text;

[0050] Determine the sample label corresponding to the target sample text based on the sample prompt text;

[0051] Input the sample prompt text and target sample text into the basic text classification model and output the sample classification results;

[0052] Determine the model loss between the sample classification results and the sample labels;

[0053] The basic text classification model is iteratively trained according to the model loss to obtain the trained text classification model.

[0054] According to one aspect of the present application, a computer-readable storage medium is provided. The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for loading by a processor to execute the text classification method provided in an embodiment of the present application.

[0055] According to one aspect of the present application, a computer device includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor. When the processor executes the computer program, the text classification method provided in an embodiment of the present application is implemented.

[0056] According to one aspect of the present application, a computer program product includes a computer program or instructions, and when the computer program or instructions are executed by a processor, the text classification method provided in the embodiment of the present application is implemented.

[0057] In an embodiment of the present application, an initial text is obtained, and text matching is performed on the initial text through entities and entity relationships in a preset knowledge graph to obtain a target text; a prompt text is written based on the target text to obtain a prompt text corresponding to the target text; the target text and the prompt text are input into a trained text classification model, and a classification result corresponding to the target text is output; wherein the trained text classification model is trained based on a model loss generated according to target sample text and sample labels, the target sample text is a text obtained by matching the initial sample text with a preset knowledge graph, and the sample label is determined by a sample prompt text obtained by writing a prompt text based on the target sample text; and the text type corresponding to the initial text is determined based on the classification result. In an embodiment of the present application, in the training stage, the initial sample text is matched with a preset knowledge graph to achieve coarse classification of the initial sample text, so that the target sample text used to train the basic classification model can be quickly found, thereby improving the training efficiency of the subsequent basic text classification model, and then the target sample text is written with a prompt text to obtain a sample prompt text, and finally the basic text classification model is trained with the target sample text and the sample prompt text. The training tasks of the basic text classification model can be flexibly configured through the prompt text, thereby guiding the training of the basic text classification model, achieving fine classification training of the target sample text, and finally obtaining the trained text classification model; in the application stage, the preset knowledge graph is used for coarse classification, which can filter out texts that are not related to the knowledge graph and determine the target text corresponding to the text related to the knowledge graph, and then the trained text classification model is used to perform fine classification on the target text to obtain a classification result, and the text type of the initial text is determined based on the classification result, thereby improving the efficiency and accuracy of text classification of the initial text.

[0058] Other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present application. The purposes and other advantages of the present application can be achieved and obtained through the structures particularly pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] 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 present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0060] Figure 1 This is a system architecture diagram of the text classification method provided in the embodiment of the present application;

[0061] Figure 2 This is a schematic diagram of a text classification scenario provided by an embodiment of the present application;

[0062] Figure 3 Schematic diagram of the text classification method provided in the embodiment of the present application;

[0063] Figure 4 is a flow chart of step 210 provided in an embodiment of the present application;

[0064] Figure 5 This is a schematic diagram of entity relationships in the knowledge graph provided in the embodiment of the present application;

[0065] Figure 6 This is a flowchart of determining the text type provided by an embodiment of the present application;

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

[0067] Figure 8 This is another schematic diagram of a text classification scenario provided by an embodiment of the present application;

[0068] Figure 9 is a structural diagram of a text classification device provided in an embodiment of the present application;

[0069] Figure 10 is a schematic diagram of the structure of a computer device provided in an embodiment of the present application;

[0070] Figure 11 This is another structural diagram of the computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0071] In order to enable those skilled in the art to better understand the solutions of this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making any creative efforts shall fall within the scope of protection of this application.

[0072] It is understandable that in the specific implementation of this application, when the above embodiments of this application are applied to specific products or technologies, the user's permission or consent must be obtained, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards.

[0073] It should be noted that some processes described in the specification, claims, and figures above include multiple steps that appear in a specific order. However, it should be understood that these steps may be executed in a different order than the order in which they appear herein or in parallel. The step numbers are used solely to distinguish between the different steps and do not themselves represent any order of execution. Furthermore, terms such as "first," "second," or "target" are used herein to distinguish similar objects and are not necessarily used to describe a specific order or precedence.

[0074] Before further explaining the embodiments of the present disclosure in detail, the nouns and terms involved in the embodiments of the present disclosure are explained. The nouns and terms involved in the embodiments of the present disclosure are subject to the following interpretations:

[0075] Knowledge Graph (KG) is a structured knowledge base, which is essentially a directed graph with labels. Each node in the graph represents an entity, and each edge represents a relationship, which is represented by a standard triple (s, r, o), where s and o are the head entity and the tail entity respectively, and r is the relationship between s and o. Knowledge graphs are widely used in many scenarios, such as semantic search, intelligent question and answer, and decision support. However, although the creation and maintenance of knowledge graphs cost a lot of money, even the largest knowledge graphs face problems such as data sparsity and data missing. Therefore, in order to make the knowledge graph more complete and accurate, it must be continuously expanded and improved so that the knowledge graph model can be continuously constructed. It should be pointed out that the initial text in the embodiment of the present application can be queried for the corresponding entity in the pre-set knowledge graph.

[0076] The basic form of a triple mainly includes entity 1, relationship, entity 2, concept, attribute, attribute value, etc. Entities are the most basic elements in the knowledge graph, and different entities have different relationships. Concepts mainly refer to sets, categories, object types, and types of things, such as people and geography; attributes mainly refer to the properties, characteristics, features, characteristics, and parameters that an object may have, such as nationality and birthday; attribute values ​​mainly refer to the values ​​of specified attributes of an object, such as China, 1988-09-08, etc. Each entity (the extension of a concept) can be identified by a globally unique ID, each attribute-value pair (AVP) can be used to characterize the intrinsic characteristics of an entity, and relationships can be used to connect two entities and characterize the relationship between them.

[0077] Prompt Engineering is a key concept in natural language processing. It refers to the text or sentence fragments used to trigger and guide AI language models to produce specific outputs. A prompt can be a word, a phrase, a question, or a complete sentence, and can be used to guide the model to generate a specific answer, text, summary, or other output.

[0078] A pre-training model, also known as a cornerstone model or a large model, refers to a deep neural network (DNN) with large parameters. It is trained on massive amounts of unlabeled data. Leveraging the function approximation capabilities of large-parameter DNNs, the pretrained machine learning (PTM) extracts common features from the data. Through techniques such as fine tuning, efficient parameter fine tuning (PEFT), and prompt-tuning, it is then adapted for downstream tasks. Therefore, pre-trained models can achieve ideal results in few-shot or zero-shot scenarios. Based on the data modality processed, PTMs can be categorized into language models (ELMO, BERT, GPT), vision models (swin-transformer, ViT, V-MOE), speech models (VALL-E), and multimodal models (ViBERT, CLIP, Flamingo, Gato). Multimodal models are those that represent features from two or more data modalities. Pre-trained models are important tools for outputting artificial intelligence generated content (AIGC) and can also serve as a universal interface for connecting multiple task-specific models.

[0079] First, some technical problems existing in related technologies are described.

[0080] With the development of internet technology, many new online languages ​​have emerged, allowing users to understand these languages ​​to determine the specific meaning of what is being expressed. However, some illicit industries have also created some "black" online languages, which can convey negative information. Commonly known as "slang," these can mislead users into understanding negative information and affect social security.

[0081] To identify jargon in certain scenarios, related technologies have employed keyword matching to identify jargon in text. Traditional classification models can also be used to identify jargon in text. However, keyword matching is limited in the scope of jargon that can be identified in text, and traditional classification models require manually labeled training samples and have a long training cycle, making it impossible for traditional classification models to timely classify the latest jargon.

[0082] It is understandable that information spreads and diffuses very quickly on the Internet, so there will be some black network language on the Internet. These black network languages ​​only rely on the above-mentioned related technical means to be screened and classified, and there are problems with low text classification accuracy and low efficiency.

[0083] Therefore, in the embodiment of the present application, a scheme is proposed for preliminary screening and filtering of the initial text based on the knowledge graph, and then prompt text is written for the screened target text, and the written prompt text is input into the text classification model for classification, thereby obtaining the classification result. By performing rough classification of the text through the knowledge graph, most of the text that is irrelevant to the entities in the knowledge graph can be filtered out, and then the target text after rough classification is input into the text classification model for classification, and the text type corresponding to the initial text is determined based on the classification result. This improves the accuracy and efficiency of text classification.

[0084] The text classification model can be a large model that can be applied to a variety of business scenarios. It can also be a traditional model, such as a deep learning network model.

[0085] See also Figure 1 , Figure 1 1 is a diagram of the system architecture used in the text classification method provided in the embodiment of the present application, which includes a terminal 140, the Internet 130, a gateway 120, a server 110, and the like.

[0086] Terminal 140 includes, but is not limited to, mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, and the like. Embodiments of the present application can be applied to various scenarios, including, but not limited to, cloud technology and artificial intelligence. Furthermore, it can be a single device or a combination of multiple devices. For example, multiple desktop computers connected via a local area network, sharing a common display, and working collaboratively, collectively constitute a terminal 140. Terminal 140 can communicate with Internet 130 via wired or wireless means to exchange data.

[0087] Server 110 refers to a computer system that provides certain services to terminal 140. Compared to ordinary terminal 140, server 110 has higher requirements in terms of stability, security, and performance. Server 110 can be a standalone physical server, 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, and big data and artificial intelligence platforms.

[0088] Gateway 120, also known as a gateway or protocol converter, implements network interconnection at the transport layer and is a computer system or device that performs a conversion function. It acts as a translator between two systems using different communication protocols, data formats, languages, or even completely different architectures. Gateways can also provide filtering and security functions. Messages sent from terminal 140 to server 110 are sent through gateway 120 to the corresponding server 110. Messages sent from server 110 to terminal 140 are also sent through gateway 120 to the corresponding terminal 140.

[0089] The text classification method in the embodiments of the present application can be applied in a variety of scenarios, such as scenarios where some self-media articles need to be reviewed and classified before being published on the Internet. Another example is scenarios where comments and messages in some online comment areas need to be screened. Another example is scenarios where some reports and forms need to be classified.

[0090] Please also refer to Figure 2 , Figure 2 This is a schematic diagram of a text classification scenario provided in an embodiment of the present application.

[0091] The initial text may be text corresponding to a variety of scenarios, for example, the initial text may be text in a variety of content such as online articles, advertising pages, push information, web images, web videos, news, reports, and forms.

[0092] After obtaining the initial text, the initial text may be preprocessed, such as performing word segmentation on the initial text, thereby obtaining at least one word segmentation text. The word segmentation text may be understood as entities obtained based on the initial text.

[0093] For example, taking an article as an example, which includes the content corresponding to the title and the content corresponding to the body, the content corresponding to the title and the content corresponding to the body can be segmented to obtain multiple segmented texts. These segmented texts can be used as texts that need to be filtered through a preset knowledge graph.

[0094] The segmented text is then matched with the entities in the knowledge graph to obtain matched entities, which are then identified as target texts. Entities in the knowledge graph can be understood as texts, such as related words or short sentences, and their smallest component, a triple, can be understood as a unit in the form of "entity-entity relationship-another entity." Knowledge graphs can be generated by setting preset entities and entity relationships, such as collecting some black Internet language, and then determining entities related to the black Internet language. The relationships between these entities are then obtained, and the preset knowledge graph is ultimately constructed based on the entities and entity relationships.

[0095] It can be understood that the knowledge graph is used to filter the segmented text in the initial text, and can determine whether the segmented text matches the entity in the knowledge graph. If some segmented texts do not match the entity in the knowledge graph, these segmented texts are filtered out.

[0096] At the same time, other segmented texts that match the knowledge graph are determined, and then the target texts corresponding to these segmented texts are determined. For example, the target text can be the first matching entity matched by the segmented text in the knowledge graph. These first matching entities are also text and are the same as these segmented texts. The target entity can also include the second matching entities matched in the knowledge graph. These second matching entities are also text and are similar to these segmented texts.

[0097] Then, prompt text is written for the target text to generate the corresponding prompt text. This prompt text is then input into a text classification model for classification, resulting in a classification result. The text classification model can be a large model that can be applied to a variety of scenarios and possesses strong text recognition capabilities. It is capable of natural language processing (NLP), a key area in computer science and artificial intelligence. It studies various theories and methods that enable effective communication between humans and computers using natural language. Natural language processing involves natural language, the language we use everyday, and is closely related to linguistics research; it also involves computer science and mathematics. Pre-trained models, a key technology for model training in the field of artificial intelligence, are derived from large language models (LLMs) in the NLP field. After fine-tuning, LLMs can be widely applied to downstream tasks. Natural language processing technologies generally include text processing, semantic understanding, machine translation, robotic question answering, and knowledge graphs.

[0098] The text classification model is a pre-trained model. It accepts prompt text and target text as input. The prompt text guides the model's classification tasks, such as guiding it to categorize the target text according to a specific classification direction. The text classification model then continues to classify the target text, effectively performing a fine-grained screening process, enabling more specific classification of the target text.

[0099] Finally, the text type corresponding to the initial text can be determined based on the classification results of the text classification model. For example, if the classification result is that the target text is black network language, then the text type corresponding to the initial text is determined to be a text with black network language, thus achieving the classification of the initial text.

[0100] That is to say, in this application, the preset knowledge graph is used to perform a preliminary match on the initial text, the initial text is roughly classified to obtain the target text, and then the prompt text for writing the target text is input into the pre-trained text classification model for accurate classification, and the text type of the initial text is determined based on the classification results. In this way, the preset knowledge graph is used for rough classification, and then the text classification model is used for fine classification to determine the text type of the initial text, thereby improving the efficiency and accuracy of text classification of the initial text.

[0101] For a more detailed understanding of the text classification method provided in the embodiments of this application, please refer to Figure 3 , Figure 3 The following is a flow chart of a text classification method provided in an embodiment of the present application. The text classification method can be applied to terminal devices such as mobile phones, computers, and tablet computers, or computer devices such as servers. The text classification method can improve the accuracy and efficiency of text classification. The text classification method may include the following steps:

[0102] Step 210: Obtain the initial text, perform text matching on the initial text using entities and entity relationships in a preset knowledge graph, and obtain the target text;

[0103] Step 220: Write a prompt text based on the target text to obtain a prompt text corresponding to the target text;

[0104] Step 230: Input the target text and the prompt text into the trained text classification model, and output the classification result corresponding to the target text;

[0105] The trained text classification model is obtained by training the model loss generated based on the target sample text and the sample label. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph. The sample label is determined by the sample prompt text written based on the target sample text.

[0106] Step 240: Determine the text type corresponding to the initial text based on the classification result.

[0107] Steps 210 to 240 will be described in detail below.

[0108] In step 210, an initial text is obtained, and text matching is performed on the initial text through entities and entity relationships in a preset knowledge graph to obtain a target text.

[0109] The initial text can be any of a specific word, short sentence, long sentence, or long article. The initial text in the corresponding text content can be obtained according to the actual task requirements. For example, if you need to filter and classify online comments, you can obtain various comment texts from the comment area and then extract these comment texts as the initial text. For another example, if you need to classify some online articles, you can determine the text content in the online articles as the initial text. For another example, if you need to filter and classify the subtitles in a video, you can determine the subtitles in the video as the initial text. In other words, the initial text can be obtained according to the actual text classification requirements.

[0110] After obtaining the initial text, the preset knowledge graph can be used to perform preliminary text classification on the initial text to obtain the target text.

[0111] Please also refer to Figure 4 , Figure 4 This is a flow chart of step 210 provided in an embodiment of the present application. In some embodiments, text matching is performed on the initial text using entities and entity relationships in a preset knowledge graph to obtain the target text, including:

[0112] Step 301: Perform word segmentation processing on the initial text to obtain at least one word segmentation text;

[0113] Step 302: Match at least one segmented text with an entity in the knowledge graph to obtain a first matching entity;

[0114] Step 303: Determine a second matching entity based on the first matching entity and the entity relationship in the knowledge graph;

[0115] Step 304: Determine the first matching entity and the second matching entity as target text.

[0116] Steps 301 to 304 will be described in detail below.

[0117] In step 301, the initial text is segmented to obtain at least one segmented text.

[0118] The initial text may be segmented using semantic segmentation to obtain at least one segmented text. For example, the semantics of each sentence in the initial text may be determined, and then the sentence may be segmented based on the semantics to obtain at least one segmented text. For example, the corresponding nouns, verbs, etc. may be selected based on the semantics to obtain the segmented text.

[0119] For example, to further improve the efficiency of word segmentation for the initial text, the initial text can be input into a pre-trained text segmentation model, which can then be used to segment the entire initial text, thereby generating at least one segmented text. Specifically, the language corresponding to the initial text can be first determined, and then the text segmentation model that best suits the initial text can be determined based on the language. Finally, the initial text can be input into the text segmentation model to output at least one segmented text.

[0120] It is understandable that other text segmentation methods can also be used to perform word segmentation processing on the initial text, and the above examples do not limit this application.

[0121] In step 302, at least one segmented text is matched with an entity in the knowledge graph to obtain a first matching entity.

[0122] Among them, keyword matching can be used to match the segmented text with the entities in the knowledge graph. For example, a segmented text is matched with all entities in the knowledge graph. When an entity that is the same as the segmented text is matched, the entity is determined as the first matching entity.

[0123] For example, the semantics of the segmented text can be used to infer the corresponding application scenario. For example, if the segmented text contains words such as "pet," "cat," "cat grass," and "purchase link," the semantic text can be used to determine that the scenario is likely a cat product sales scenario. Based on the application scenario, all entities corresponding to that scenario are circled in the knowledge graph. Finally, the segmented text is matched with all entities in that scenario to identify the first matching entity.

[0124] In some implementations, the first matching entity can be obtained by obtaining a segmentation text vector corresponding to the segmentation text and then matching the segmentation text vector with the entity vector of the entity in the knowledge graph.

[0125] The step of matching at least one segmented text with an entity in the knowledge graph to obtain a first matching entity includes:

[0126] (1.1) Obtaining the segmentation text vector corresponding to each segmentation text in at least one segmentation text;

[0127] (1.2) Determine the similarity between the word segmentation text vector and the entity vector of any entity in the knowledge graph;

[0128] (1.3) The entity corresponding to the entity vector with the highest similarity to the word segmentation text vector is determined as the first matching entity.

[0129] Specifically, a preset encoding method can be used to encode each segmented text, thereby obtaining a segmented text vector corresponding to each segmented text. It should be noted that the segmented text vectors corresponding to all segmented texts can be understood as being in the same spatial dimension. This ensures the reliability of subsequent matching between the segmented text vectors and entities in the knowledge graph, and ensures that the similarity obtained from the matching is reliable.

[0130] The similarity between the word segmentation text vector and the entity vector of any entity in the knowledge graph is then matched to obtain the similarity between the two. The knowledge graph contains not only entities but also their corresponding entity vectors. These entity vectors are also obtained by encoding the entities using a preset encoding method. Therefore, the spatial dimensions corresponding to these entity vectors are consistent with the spatial dimensions corresponding to the target text, thus ensuring the reliability of the matching between the word segmentation text vector and the entity vector.

[0131] When performing similarity matching between the word segmentation text vector and the entity vector of any entity in the knowledge graph, the cosine distance between the word segmentation text vector and the entity vector of any entity in the knowledge graph can be obtained, and then the similarity between the word segmentation text vector and the entity vector of any entity in the knowledge graph can be determined based on the cosine distance.

[0132] For example, when the cosine distance between the word segmentation text vector and the entity vector of any entity in the knowledge graph is within a preset cosine distance range, the associated similarity value can be determined based on the cosine distance range, and finally the similarity value is determined as the similarity between the word segmentation text vector and the entity vector.

[0133] After obtaining the similarity between the word segmentation text vector and the entity vector, the entity corresponding to the entity vector with the highest similarity to the word segmentation text vector can be determined as the first matching entity. For example, if the similarity between the entity vector and the word segmentation text vector of entity 1 is 91%, the similarity between the entity vector and the word segmentation text vector of entity 2 is 95%, and the similarity between the entity vector and the word segmentation text vector of entity 3 is 99.9%, then entity 3 is determined as the first matching entity.

[0134] For example, the segmented text is "cat", the text corresponding to entity 2 is "carnivore", and the text corresponding to entity 3 is also "cat". Then, based on the similarity, it can be determined that entity 3 and the segmented text are closest, and entity 3 is determined as the first matching entity.

[0135] It is also possible to determine that the entity corresponding to the entity vector whose similarity to the word segmentation text vector is greater than a preset similarity threshold is determined as the first matching entity. For example, the similarity between the entity vector and the word segmentation text vector of entity 1 is 91%, the similarity between the entity vector and the word segmentation text vector of entity 2 is 95%, the similarity between the entity vector and the word segmentation text vector of entity 3 is 99.9%, and the similarity between the entity vector and the word segmentation text vector of entity 4 is 85%, while the preset similarity threshold is 90%. Then entity 1, entity 2, and entity 3 are determined as the first matching entity.

[0136] For example, the word segmentation text is "cat", the text corresponding to entity 2 is "carnivore", the text corresponding to entity 3 is also "cat", and the text corresponding to entity 4 is "animal". Then, through vector matching, it can be determined that the similarity between entity 2 and entity 3 and the word segmentation text is greater than the preset similarity threshold, and entity 2 and entity 3 are determined as the first matching entities.

[0137] It should be noted that the first matching entity can be a text that is exactly the same as the segmented text. It can also be a text that is highly similar to the segmented text. By retaining text that is highly similar to the segmented text, it is ensured that the segmented text is not directly filtered out. Instead, the corresponding first matching entity is used to represent the segmented text. Subsequently, the text classification model is used to perform text classification, thereby ensuring the generalization of some segmented texts during text classification and ensuring the universality of some segmented texts in the text classification process. By achieving the generalization of some segmented texts, the text that is highly similar to these segmented texts is retained as the first matching entity, which is more conducive to the subsequent accurate determination of the type corresponding to the initial text.

[0138] In step 303, a second matching entity is determined based on the first matching entity and the entity relationship in the knowledge graph.

[0139] It is understandable that the first matching entity can be an entity that is relatively relevant to the segmented text, and the second matching entity related to the first matching entity can also be determined through entity relationships. For example, the entities in the knowledge graph have entity relationships, and there are strong correlations and weak correlations between entities. The embodiment of the present application can introduce the concept of distance measurement. If there are fewer edges connecting two entities in the knowledge graph, it means that the distance between the two entities is closer. Since the edges between entities in the knowledge graph represent the relationship between entities, the fewer edges connecting two entities in the knowledge graph also means that the correlation between the two entities is stronger. The second matching entity that is strongly related to the first matching entity can be determined through the entity relationship in the knowledge graph. For example, the entity within a preset number of edges from the first matching entity is determined as the second matching entity through the entity relationship.

[0140] In step 304 , the first matching entity and the second matching entity are determined as target texts.

[0141] Finally, the first matching entity and the second matching entity can be determined as target texts, wherein the first matching entity contains the same text as the segmented text or the text closest to the segmented text, and the second matching entity can be understood as containing diffused generalized text.

[0142] Please also refer to 5. Figure 5 This is a schematic diagram of entity relationships in the knowledge graph provided by the embodiments of this application. Among them, Black Network Language 1, Black Network Language 2, Black Network Language 3, and Black Network Language 4 can be the first matching entity. Based on the entity relationships, it can be determined that Black Network Language 1 and Black Network Language 2 belong to Black Product 1, Black Network Language 3 and Black Network Language 4 belong to Black Product 2, and Black Product 1 and Black Product 2 are both related to Black Industry 1.

[0143] Then, it can be determined that the second matching entities corresponding to the first matching entities Black Network Language 1 and Black Network Language 2 are Black Product 1 and Black Industry 1. And the second matching entities corresponding to the first matching entities Black Network Language 3 and Black Network Language 4 are Black Product 2 and Black Industry 1.

[0144] It can be seen from steps 301 to 304 that determining the first matching entity and the second matching entity as the target text can, on the one hand, ensure the accuracy of the target text determined based on the segmented text, and on the other hand, realize the diffusion and generalization of the target text, which can increase the diversity of the target text. Subsequently, the target text is input into the trained text classification model to determine the corresponding classification result, and then the text type corresponding to the initial text is determined based on the classification result. This can ensure that the determined text type is more accurate.

[0145] Since the initial text is roughly classified using the knowledge graph, a large amount of text that is irrelevant to the entities in the knowledge graph is filtered out. Therefore, the amount of data of the target text obtained by matching the initial text and the knowledge graph is smaller than the amount of data of the initial text. In this way, when the trained text classification model is used to classify the target text, the amount of data processed by the text classification model will be smaller, and the text classification model will classify the target text faster, thereby improving the efficiency of text classification.

[0146] In step 220 , a prompt text is written based on the target text to obtain a prompt text corresponding to the target text.

[0147] Among them, the prompt text can be understood as the text determined based on the prompt engineering, specifically the prompt text is written based on the target text, so as to obtain the prompt text corresponding to the target text. Prompt Engineering is an important concept in the field of natural language processing, which refers to the text or sentence fragments used to trigger and guide the artificial intelligence language model to generate specific outputs. Prompt can be a word, a phrase, a question or a complete sentence, which can be used to guide the model to generate specific answers, text, summaries or other outputs.

[0148] In some implementations, writing a prompt text based on the target text to obtain a prompt text corresponding to the target text includes:

[0149] (1.1) Determine at least one tag corresponding to the target text based on the knowledge graph;

[0150] (1.2) Writing a prompt text for the target text according to at least one tag to obtain a prompt text corresponding to the target text under each tag.

[0151] Among them, the target text is determined based on the knowledge graph. The target text has corresponding relevant labels in the knowledge graph. The labels can be understood as specific application scenarios, uses, functional effects, etc. For example, if the target text is "link", its corresponding labels can be "shopping link" and "pass parameters".

[0152] Therefore, for the target text, a corresponding number of tags can be determined based on the knowledge graph, and then prompt text can be written for the target text based on at least one tag. For example, different tags correspond to different scenarios, so the written prompt text is also different. For example, when the tag is "shopping link", the corresponding scenario of this tag is online shopping, while when the tag is "passing parameters", the corresponding scenario of this tag is computer control.

[0153] In some implementations, prompt text is written for the target text according to at least one tag to obtain prompt text corresponding to the target text under each tag, including:

[0154] (1.2.1) Determine the corresponding prompt text template under each label;

[0155] (1.2.2) Writing prompt text for the target text based on the prompt text template to obtain the prompt text corresponding to the target text under each label.

[0156] For different tags, each tag has a corresponding prompt text template. The prompt text template can be understood as a general template corresponding to the prompt text writing process. The prompt text can be written and generated according to the actual target text in combination with the prompt text template.

[0157] For example, the prompt text template 1 is:

[0158] Your task is to determine whether the following samples contain vulgar content? Please answer with "yes" or "no" and do not answer anything else.

[0159] Sample: XXXXXXX.

[0160] Prompt text template 2 is:

[0161] Please identify the following samples as black internet language and mark the samples that belong to black internet language.

[0162] Sample: XXXXXXX.

[0163] If the prompt text template corresponding to a target text is determined to be prompt text template 1 based on the label, the target text can be used as the content corresponding to the "sample" in prompt text template 1 to obtain the prompt text. If the prompt text template corresponding to a target text is determined to be prompt text template 2 based on the label, the target text can be used as the content corresponding to the "sample" in prompt text template 2 to obtain the prompt text.

[0164] In some embodiments, during the process of writing prompt text, the prompt text may include target text, and the target text may be identified by a text classification model by setting an identifier, such as setting a delimiter or line break to emphasize the target text.

[0165] As can be seen from the above, using a prompt text template to write a prompt text for a target text can improve the efficiency of writing a prompt text.

[0166] In some embodiments, the prompt text for the target text can also be generated by manually inputting the prompt text corresponding to the target text based on the target text. For example, a prompt text corresponding to the target text can be written based on human experience, and then the prompt text can be used to classify the target text.

[0167] Among them, the prompt text can flexibly and accurately guide the classification task corresponding to the trained text classification model, so that when the text classification model classifies the target text, it can achieve accurate text classification according to the classification task, thereby improving the accuracy of text classification.

[0168] In step 230 , the target text and the prompt text are input into the trained text classification model, and the classification result corresponding to the target text is output.

[0169] After obtaining the prompt text, the prompt text can be used to guide the text classification model to perform the corresponding classification task. For example, it can be understood that the prompt text corresponds to a task, and the text classification model can perform the task. After inputting the prompt text and the target text into the text classification model, the text classification model can determine the corresponding classification task based on the prompt text, and then classify the target text to obtain the classification result corresponding to the target text.

[0170] For example, the prompt text is: Your task is to determine whether the following samples contain vulgar content? Please answer with "yes" or "no" and do not answer anything else.

[0171] The target text is: XX codeword 1, XX codeword 2.

[0172] The prompt text and target text are input into the text classification model. The text classification model can perform the classification task based on the prompt text, and then determine the classification result corresponding to the target text. For example, the classification result corresponding to the target text: XX codeword 1 is "yes", and the classification result corresponding to the target text: XX codeword 1 is "yes".

[0173] In some embodiments, the target text and the prompt text are input into a trained text classification model, and the classification result corresponding to the target text is output, including:

[0174] (1.1) Determine the amount of data corresponding to the target text;

[0175] (1.2) Determine a trained text classification model with a corresponding model complexity based on the amount of data, input the target text and prompt text into the trained text classification model, and output the classification results.

[0176] It is understandable that in order to improve the utilization rate of computing resources of computer equipment, a text classification model with corresponding model complexity can be selected from the database to classify the target text. Among them, the higher the model complexity, the more computing power and storage resources the model requires, and the lower the model complexity, the lower the computing power and storage resources the model requires.

[0177] Therefore, the data volume corresponding to the target text can be determined, and then a trained text classification model with a corresponding model complexity can be determined based on the data volume. For example, multiple data volume ranges can be preset, and each data volume range corresponds to a trained text classification model with a model complexity. When the data volume of the target text falls within a certain data volume range, a trained text classification model with a model complexity corresponding to that data volume range can be determined.

[0178] It should be noted that the higher the model complexity, the stronger its parallel ability to classify the target text, and it can classify multiple target texts at the same time. However, its model parameters are more and the model data volume is larger, and more computing power and storage resources are required when loading. Therefore, you can select a trained text classification model with a corresponding model complexity based on the actual data volume of the target text, and input the target text and prompt text into the trained text classification model to output the classification results. This can improve the utilization of the computing power and storage resources of the computer equipment, thereby improving the efficiency of text classification.

[0179] In some embodiments, the target text and the prompt text are input into a trained text classification model, and the classification result corresponding to the target text is output, including:

[0180] (2.1) Determine whether the data volume corresponding to the target text is greater than the preset data volume;

[0181] (2.2) When the data volume of the target text is greater than the preset data volume, determining the application scenario corresponding to the target text based on the label corresponding to the target text;

[0182] (2.3) Determine a trained text classification model related to the application scenario, input the target text and prompt text into the trained text classification model, and output the classification results.

[0183] Among them, before determining the trained text classification model corresponding to the target text, it can be determined whether the data volume corresponding to the target text is greater than the preset data volume. When the data volume corresponding to the target text is greater than the preset data volume, if a text classification model based on a large model is used to perform text classification, the computing power resources of the computer equipment required at this time are very high, which may cause the computer equipment to be unable to perform other tasks.

[0184] In an embodiment of the present application, in order to solve this technical problem, it is conceived that the target text for an application scenario can be processed using a text classification model specially trained for the application scenario. The text classification model specially trained for this scenario is only applicable to a limited number of application scenarios. The text classification model is trained based on a traditional deep neural network model. Its characteristics are that compared with large models, the text classification model has fewer model parameters and lower model complexity. When the text classification model is loaded and run by a computer device, the computer device needs to consume fewer computing power resources and storage resources.

[0185] Therefore, when the target text data volume is greater than the preset data volume, the application scenario corresponding to the target text is determined based on the label corresponding to the target text. The label corresponding to the target text can be determined based on the knowledge graph. For example, when the application scenario corresponding to the label is "online shopping scenario", a trained text classification model suitable for the "online shopping scenario" can be obtained. Then, the target text and prompt text are input into the trained text classification model to output the classification result. This can improve the utilization of the computing power and storage resources of the computer equipment, thereby improving the efficiency of text classification.

[0186] Among them, the trained text classification model is obtained by training based on the model loss generated according to the target sample text and sample labels. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph, and the sample label is determined by the sample prompt text obtained by writing the prompt text based on the target sample text.

[0187] In some embodiments, the training process of the trained text classification model includes:

[0188] (3.1) Obtain sample text, perform text matching on the initial sample text using entities and entity relationships in the preset knowledge graph to obtain the target sample text;

[0189] (3.2) Writing prompt text for the target sample text to obtain a sample prompt text corresponding to the target sample text;

[0190] (3.3) Determine the sample label corresponding to the target sample text based on the sample prompt text;

[0191] (3.4) Input the sample prompt text and target sample text into the basic text classification model and output the sample classification results;

[0192] (3.5) Determine the model loss between the sample classification results and the sample labels;

[0193] (3.6) The basic text classification model is iteratively trained according to the model loss to obtain the trained text classification model.

[0194] For example, the initial sample text can be obtained based on actual scenario requirements. If you need to train a text classification model that can classify online comments, then the initial sample text can be text obtained from the comment sections of various applications, web page comment sections, etc.

[0195] Then, the initial sample text is matched with the entities and entity relationships in the preset knowledge graph to obtain the target sample text. For example, the first vector corresponding to the initial sample text is obtained, and then the first vector is matched with the entity vector of the entity in the knowledge graph, so that the matched entity is determined as the target sample text.

[0196] The initial sample text is matched with the preset knowledge graph to achieve rough classification of the initial sample text, so that the target sample text for training the basic classification model can be quickly found, thereby improving the training efficiency of the subsequent basic text classification model.

[0197] Then, the target sample text is written with a prompt text to obtain a sample prompt text. The target sample text can be written with a prompt text template. For example, multiple prompt text templates can be pre-set, and then the target sample text is written with at least one prompt text template to obtain a sample prompt text.

[0198] Then, the sample label corresponding to the sample text is set according to the sample prompt text. For example, the sample prompt text is: Please confirm whether the text XXXX is black network language. Please answer yes or no. If the target sample text is black network language, the sample label of the sample text can be set as black network language according to the sample prompt text.

[0199] Then the sample prompt text and target sample text are input into the basic text classification model for training, and the model loss corresponding to the basic text classification model is determined based on the output results of the basic text classification model and the sample labels. Then, some parameters of the basic text classification model are adjusted based on the model loss, thereby realizing the iteration of the basic text classification model. Then, the iterated basic text classification model is trained with the target sample text and sample prompt text until the sample classification results of the basic text classification model meet the preset conditions, and the trained text classification model is obtained.

[0200] Among them, the prompt text can be used to flexibly configure the training tasks of the basic text classification model, thereby guiding the training of the basic text classification model to achieve detailed classification of the target sample text, so as to improve the accuracy of the detailed classification of the target sample text, and finally obtain the trained text classification model.

[0201] For example, the basic text classification model is continuously iteratively trained in the above manner. After the target sample text and sample prompt text are input into the iterated basic text classification model, the basic text classification model outputs the corresponding sample classification result. If the loss value corresponding to the sample classification result and the sample label is greater than the preset loss value, it means that the basic text classification model needs to continue training. By changing the model parameters of the basic text classification model, the iteration of the basic text classification model is achieved, and then the next set of target sample text and sample prompt text are input into the iterated basic text classification model. If the output sample classification result is consistent with the sample label, it means that the basic text classification model is now able to perform accurate text classification. At this time, the training of the text classification model is stopped to obtain the trained text classification model.

[0202] For another example, in the process of iterating the basic text classification model, a certain number of iterations can be set. When the number of iterations of the basic text classification model reaches the preset number of iterations, it is considered that the basic text classification model has been trained and the trained text classification model is obtained.

[0203] In some embodiments, when the text classification model is a model applicable to a certain scenario, the following method can be used to train the model: obtain the initial sample text corresponding to the application scenario, and then perform text matching on the initial sample text through the entities and entity relationships in the preset knowledge graph to obtain the target sample text, and then perform prompt text writing on the target sample text to obtain the sample prompt text, and determine the sample label corresponding to the target sample text based on the sample prompt text, and then train the text classification model with the sample prompt text and the target sample text to obtain the sample classification result corresponding to the target sample text, determine the model loss corresponding to the basic text classification model based on the sample classification result and the sample label, and then iteratively train the basic text classification model according to the model loss to obtain a trained text classification model applicable to the application scenario.

[0204] In step 240 , the text type corresponding to the initial text is determined based on the classification result.

[0205] It is understandable that for each target text, each target text corresponds to a classification result, and it is necessary to comprehensively judge the text type corresponding to the initial text based on these classification results, so as to improve the accuracy of determining the text type of the initial text.

[0206] In some implementations, determining the text type corresponding to the initial text based on the classification result includes:

[0207] (1.1) Determine the classification label corresponding to the target text based on the classification results;

[0208] (1.2) Determine the text type corresponding to the initial text based on the classification label.

[0209] For each target text, a corresponding classification label can be determined based on its corresponding classification result. For example, if the classification result of target text 1 is deceptive online language, then the classification label of target text 1 can be set as deceptive; if the classification result of target text 2 is vulgar online language, then the classification label of target text 2 can be set as vulgar.

[0210] The text type corresponding to the initial text is then determined based on the classification label. If all target texts have the same classification label, the text type corresponding to that classification label is determined as the text type corresponding to the initial text. For example, if the text type corresponding to the classification label is vulgar, the text type corresponding to the initial text can be determined to be vulgar.

[0211] If among all target texts, different target texts correspond to different classification labels, then the levels of different related text types can be determined based on the related text types corresponding to different classification labels, and the related text type with the highest level can be determined as the text type corresponding to the initial text.

[0212] For details, please refer to Figure 6 , Figure 6 The flowchart of determining the text type provided by the embodiment of the present application is shown in FIG. The text type corresponding to the initial text is determined based on the classification label, including:

[0213] Step 401: When the classification label includes multiple different classification labels, multiple related text types are determined according to the classification labels;

[0214] Step 402: Determine the number of classification labels corresponding to each relevant text type, and determine the level corresponding to each relevant text type based on the number;

[0215] Step 403: Determine the highest-ranked related text type as the text type corresponding to the initial text, and display other related text types other than the highest-ranked related text type and the corresponding level of each other related text type.

[0216] Steps 401 to 403 are described in detail below.

[0217] In step 401 , when the classification label includes multiple different classification labels, multiple related text types are determined according to the classification labels.

[0218] For example, among multiple classification labels, some of them correspond to vulgarity, so the text type corresponding to this classification label can be determined to be vulgar text type. Some of them correspond to cyberattack, so the text type corresponding to this classification label can be determined to be cyberattack text type. Some of them correspond to deception, so the text type corresponding to this classification label can be determined to be deception text type.

[0219] In step 402, the number of classification labels corresponding to each relevant text type is determined, and the level corresponding to each relevant text type is determined based on the number.

[0220] The rank of each text type can be calculated by dividing the number of categorized labels for each relevant text type by the sum of all categorized labels. For example, if the number of categorized labels for vulgar text is 70, the number of categorized labels for cyberattack is 10, and the number of categorized labels for deceptive text is 20, then the rank for vulgar text is 0.7, the rank for cyberattack is 0.1, and the rank for deceptive is 0.2.

[0221] In step 403 , the highest-ranked related text type is determined as the text type corresponding to the initial text, and other related text types other than the highest-ranked related text type and the corresponding grades of each other related text type are displayed.

[0222] For example, the vulgar text type corresponds to a level of 0.7, the cyber attack type corresponds to a level of 0.1, and the deception type corresponds to a level of 0.2. Therefore, the vulgar text type can be determined as the text type corresponding to the initial text. However, in order to more clearly understand the possible text types of the initial text, the interface can also display other related text types besides the highest-ranked related text type and the corresponding level of each other related text type. For example, the cyber attack type corresponds to a level of 0.1, and the deception type corresponds to a level of 0.2.

[0223] It can be seen from steps 401 to 403 that when there are multiple classification labels and different classification labels correspond to different related text types, the highest-level related text type can be determined as the text type of the initial text, which can ensure the accuracy of the determined text type.

[0224] It can be seen from steps 210 to 240 that in an embodiment of the present application, by obtaining an initial text, text matching is performed on the initial text through entities and entity relationships in a preset knowledge graph to obtain a target text; prompt text is written based on the target text to obtain a prompt text corresponding to the target text; the target text and the prompt text are input into a trained text classification model, and a classification result corresponding to the target text is output; wherein the trained text classification model is trained based on a model loss generated according to target sample text and sample labels, the target sample text is a text obtained by matching the initial sample text with a preset knowledge graph, and the sample label is determined by a sample prompt text obtained by writing a prompt text based on the target sample text; and the text type corresponding to the initial text is determined based on the classification result. In an embodiment of the present application, in the training stage, the initial sample text is matched with a preset knowledge graph to achieve coarse classification of the initial sample text, so that the target sample text used to train the basic classification model can be quickly found, thereby improving the training efficiency of the subsequent basic text classification model, and then the target sample text is written with a prompt text to obtain a sample prompt text, and finally the basic text classification model is trained with the target sample text and the sample prompt text. The training tasks of the basic text classification model can be flexibly configured through the prompt text, thereby guiding the training of the basic text classification model, achieving fine classification training of the target sample text, and finally obtaining the trained text classification model; in the application stage, the preset knowledge graph is used for coarse classification, which can filter out texts that are not related to the knowledge graph and determine the target text corresponding to the text related to the knowledge graph, and then the trained text classification model is used to perform fine classification on the target text to obtain a classification result, and the text type of the initial text is determined based on the classification result, thereby improving the efficiency and accuracy of text classification of the initial text.

[0225] Please also refer to Figure 7 , Figure 7 This is another flowchart of the text classification method provided by the embodiment of the present application. The text classification method may include the following steps:

[0226] Step 501: Obtain an initial text, perform word segmentation processing on the initial text, and obtain at least one word segmentation text.

[0227] In the embodiment of the present application, the text classification of the online comment text in the online comment area is taken as an example, wherein the initial text can be the text obtained from the online comment area. Then, the initial text is segmented to obtain at least one segmented text.

[0228] Step 502: Match at least one segmented text with an entity in the knowledge graph to obtain a first matching entity.

[0229] Specifically, the segmentation text vector corresponding to each segmentation text in at least one segmentation text can be obtained; the similarity between the segmentation text vector and the entity vector of any entity in the knowledge graph can be determined; and the entity corresponding to the entity vector with the highest similarity to the segmentation text vector can be determined as the first matching entity.

[0230] The first matching entity may be the same text as the segmented text, or may be the text most similar to the segmented text.

[0231] Step 503: Determine a second matching entity based on the first matching entity and the entity relationship in the knowledge graph.

[0232] like Figure 5 As shown, black network language 1, black network language 2, black network language 3, and black network language 4 can be the first matching entities. According to the entity relationship, it can be determined that black network language 1 and black network language 2 belong to black product 1, black network language 3 and black network language 4 belong to black product 2, and black product 1 and black product 2 are both associated with black industry 1.

[0233] Then, it can be determined that the second matching entities corresponding to the first matching entities Black Network Language 1 and Black Network Language 2 are Black Product 1 and Black Industry 1. And the second matching entities corresponding to the first matching entities Black Network Language 3 and Black Network Language 4 are Black Product 2 and Black Industry 1.

[0234] Step 504: Determine the first matching entity and the second matching entity as target text.

[0235] Determining the first matching entity and the second matching entity as the target text can, on the one hand, ensure the accuracy of the target text determined based on the segmented text, and on the other hand, realize the diffusion and generalization of the target text, which can increase the diversity of the target text. Subsequently, the target text is input into the trained text classification model to determine the corresponding classification result, and then the text type corresponding to the initial text is determined based on the classification result. This can ensure that the determined text type is more accurate.

[0236] Step 505: Determine at least one tag corresponding to the target text based on the knowledge graph.

[0237] Among them, the target text is determined based on the knowledge graph. The target text has corresponding relevant labels in the knowledge graph. The labels can be understood as specific application scenarios, uses, functional effects, etc. For example, if the target text is "Black Product 1", its corresponding labels can be "Commodity" and "Black Industry".

[0238] Step 506: Compose prompt text for the target text according to at least one tag, and obtain prompt text corresponding to the target text under each tag.

[0239] Specifically, the prompt text template corresponding to each tag may be determined, and then prompt text may be written for the target text based on the prompt text template to obtain the prompt text corresponding to the target text under each tag.

[0240] For example, the prompt text template 1 is:

[0241] Your task is to determine whether the following samples contain vulgar content? Please answer with "yes" or "no" and do not answer anything else.

[0242] Sample: XXXXXXX.

[0243] Then the target text can be used as the corresponding content of the "sample" in the prompt text template 1 to obtain the prompt text.

[0244] Step 507: Determine the data volume corresponding to the target text, determine the trained text classification model of the corresponding model complexity based on the data volume, input the target text and the prompt text into the trained text classification model, and output the classification result.

[0245] It is understandable that in order to improve the utilization rate of computing resources of computer equipment, a text classification model with corresponding model complexity can be selected from the database to classify the target text. Among them, the higher the model complexity, the more computing power and storage resources the model requires, and the lower the model complexity, the lower the computing power and storage resources the model requires.

[0246] Therefore, the data volume corresponding to the target text can be determined, and then a trained text classification model with a corresponding model complexity can be determined based on the data volume. For example, multiple data volume ranges can be preset, and each data volume range corresponds to a trained text classification model with a model complexity. When the data volume of the target text falls within a certain data volume range, a trained text classification model with a model complexity corresponding to that data volume range can be determined. The target text and prompt text are input into the trained text classification model, and the classification result is output.

[0247] Step 508: Determine the classification label corresponding to the target text according to the classification result.

[0248] For each target text, a corresponding classification label can be determined based on its corresponding classification result. For example, if the classification result of target text 1 is deceptive online language, then the classification label of target text 1 can be set as deceptive; if the classification result of target text 2 is vulgar online language, then the classification label of target text 2 can be set as vulgar.

[0249] Step 509: Determine the text type corresponding to the initial text according to the classification label.

[0250] If the classification labels of all target texts are the same, the text type corresponding to the classification label is determined as the text type corresponding to the initial text. For example, if the relevant text type corresponding to the classification label is vulgar, the text type corresponding to the initial text can be determined as vulgar.

[0251] If among all target texts, different target texts correspond to different classification labels, then the levels of different related text types can be determined based on the related text types corresponding to different classification labels, and the related text type with the highest level can be determined as the text type corresponding to the initial text.

[0252] From the above, it can be seen that in actual application scenarios, the text types corresponding to different texts can be determined through the above method, thereby realizing the classification of black network language on the Internet.

[0253] In an embodiment of the present application, an initial text can be obtained and segmented to obtain at least one segmented text. The at least one segmented text is matched with an entity in a knowledge graph to obtain a first matching entity. A second matching entity is determined based on the relationship between the first matching entity and the entity in the knowledge graph. The first matching entity and the second matching entity are determined as target texts. At least one label corresponding to the target text is determined based on the knowledge graph. Prompt text is written for the target text based on at least one label to obtain prompt text corresponding to the target text under each label. The amount of data corresponding to the target text is determined, and a trained text classification model of a corresponding model complexity is determined based on the amount of data, and the target text and the prompt text are input into the trained text classification model to output a classification result. The classification label corresponding to the target text is determined based on the classification result. The text type corresponding to the initial text is determined based on the classification label.

[0254] In this way, using the preset knowledge graph for coarse classification can filter out texts that are not related to the knowledge graph and determine the target text corresponding to the text related to the knowledge graph. Then, the trained text classification model is used to perform fine classification on the target text to obtain the classification result, and the text type of the initial text is determined based on the classification result, thereby improving the efficiency and accuracy of text classification of the initial text.

[0255] See also Figure 8 , Figure 8 This is another scenario diagram of text classification provided by an embodiment of the present application.

[0256] Among them, taking the text classification of black network language as an example, the knowledge graph can be constructed based on the identified black network language, where the text extraction layer can perform entity recognition on the text in the network, determine multiple entities, and also perform relationship extraction on the entity relationships between entities.

[0257] The entity extraction layer can construct entity links corresponding to entities, perform entity discovery on new entities, and reason about entity relationships between new entities and existing entities in the knowledge graph. It can also predict entity links, such as predicting the link relationship between one entity and another.

[0258] The operation interaction layer can perform daily operations on the knowledge graph, such as text classification, text filtering, etc. It can also correct some erroneous entity classifications in the knowledge graph.

[0259] The business application layer can be applied in specific business scenarios. It can understand the basic input text, and can also reason and associate the text to determine some entities similar to the text.

[0260] The data entry of the knowledge graph can be real-time. When a new black network language appears on the network, it can be entered into the knowledge graph in a timely manner. During the entry process, the entity relationship between the black network language and the existing entity can be determined, and then the black network language can be entered into the knowledge graph based on the entity relationship.

[0261] In this text classification scenario, there is also a prompt text management platform, which can manage multiple prompt text templates and can also receive newly input prompt text templates.

[0262] Obtain the initial sample text, which is the training sample. After the initial sample text is filtered through the knowledge graph, the filtered target sample text is obtained, and then the target sample text is input into the prompt text management platform. The prompt text management platform can write the target sample text to write the sample prompt text corresponding to the target sample text, and then input the sample prompt text and the target sample text into the basic text classification model.

[0263] The basic text classification model can classify the target sample text based on the task guidance of the sample prompt text, thereby obtaining the sample classification result. The sample text corresponds to a preset sample label. During the data verification process, the sample classification label and the corresponding sample classification result can be compared to obtain the data verification result. If the sample classification label and the corresponding sample classification result do not match, the data verification result will fail. At this time, it is necessary to continue training the basic text classification model. For example, other target sample texts can be written through the prompt text management platform to obtain sample prompt texts, and then the basic text classification model can continue to be trained with the sample prompt texts.

[0264] If the sample classification label and the corresponding sample classification result match, the data verification result passes. At this time, the basic text classification model training is completed, and the text classification model can be applied online, thereby realizing the text classification of the initial text in the above embodiment through the preset knowledge graph and the trained text classification model.

[0265] See also Figure 9 , Figure 9 FIG2 is a schematic diagram of the structure of a text classification device provided in an embodiment of the present application. The text classification device can be used to execute the text classification method in the above embodiment.

[0266] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.

[0267] like Figure 9 As shown, the text classification device 600 includes:

[0268] The text acquisition module 610 is used to acquire the initial text and perform text matching on the initial text using entities and entity relationships in a preset knowledge graph to obtain the target text;

[0269] A text writing module 620 is used to write a prompt text based on the target text to obtain a prompt text corresponding to the target text;

[0270] The text classification module 630 is used to input the target text and the prompt text into the trained text classification model and output the classification result corresponding to the target text;

[0271] The trained text classification model is obtained by training the model loss generated based on the target sample text and the sample label. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph. The sample label is determined by the sample prompt text written based on the target sample text.

[0272] The type determination module 640 is configured to determine the text type corresponding to the initial text according to the classification result.

[0273] In some embodiments, the text acquisition module 610 includes an assignment submodule, a matching submodule, a first determination submodule, and a second determination submodule;

[0274] The word segmentation submodule is used to perform word segmentation processing on the initial text to obtain at least one word segmentation text;

[0275] A matching submodule, configured to match at least one segmented text with an entity in the knowledge graph to obtain a first matching entity;

[0276] A first determination submodule is configured to determine a second matching entity based on the first matching entity and the entity relationship in the knowledge graph;

[0277] The second determining submodule is configured to determine the first matching entity and the second matching entity as target text.

[0278] In some embodiments, the matching submodule is configured to:

[0279] Obtain the segmentation text vector corresponding to each segmentation text in at least one segmentation text;

[0280] Determine the similarity between the word segmentation text vector and the entity vector of any entity in the knowledge graph;

[0281] The entity corresponding to the entity vector with the highest similarity to the word segmentation text vector is determined as the first matching entity.

[0282] In some embodiments, the text writing module 620 includes a third determination submodule and a text writing submodule;

[0283] A third determination submodule is configured to determine at least one label corresponding to the target text based on the knowledge graph;

[0284] The text writing submodule is used to write prompt text for the target text according to at least one tag, and obtain the prompt text corresponding to the target text under each tag.

[0285] In some embodiments, the text writing submodule is used to:

[0286] Determine the corresponding prompt text template under each label;

[0287] Prompt text is written for the target text based on the prompt text template to obtain the prompt text corresponding to the target text under each label.

[0288] In some implementations, the text classification module 630 is configured to:

[0289] Determine the amount of data corresponding to the target text;

[0290] A trained text classification model with a corresponding model complexity is determined based on the amount of data, and the target text and prompt text are input into the trained text classification model to output the classification results.

[0291] In some implementations, the text classification module 630 is configured to:

[0292] Determine whether the data volume corresponding to the target text is greater than the preset data volume;

[0293] When the data volume of the target text is greater than the preset data volume, determining the application scenario corresponding to the target text based on the label corresponding to the target text;

[0294] Determine a trained text classification model related to the application scenario, input the target text and prompt text into the trained text classification model, and output the classification result.

[0295] In some embodiments, the type determination module 640 includes a label determination submodule and a type determination submodule;

[0296] The label determination submodule is used to determine the classification label corresponding to the target text based on the classification results;

[0297] The type determination submodule is used to determine the text type corresponding to the initial text according to the classification label.

[0298] In some embodiments, the type determination submodule is configured to:

[0299] When the classification label includes multiple different classification labels, multiple related text types are determined according to the classification labels;

[0300] Determine the number of classification labels corresponding to each relevant text type, and determine the level corresponding to each relevant text type based on the number;

[0301] The related text type with the highest rank is determined as the text type corresponding to the initial text, and other related text types other than the related text type with the highest rank and the rank corresponding to each other related text type are displayed.

[0302] In some embodiments, the text classification apparatus further includes a training module for:

[0303] Obtain sample text, perform text matching on the initial sample text using entities and entity relationships in the preset knowledge graph to obtain the target sample text;

[0304] Writing prompt text for the target sample text to obtain a sample prompt text corresponding to the target sample text;

[0305] Determine the sample label corresponding to the target sample text based on the sample prompt text;

[0306] Input the sample prompt text and target sample text into the basic text classification model and output the sample classification results;

[0307] Determine the model loss between the sample classification results and the sample labels;

[0308] The basic text classification model is iteratively trained according to the model loss to obtain the trained text classification model.

[0309] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of the text classification method above, and will not be repeated here.

[0310] In an embodiment of the present application, a text acquisition module 610 is used to obtain an initial text, and perform text matching on the initial text through entities and entity relationships in a preset knowledge graph to obtain a target text; a text writing module 620 is used to write a prompt text based on the target text to obtain a prompt text corresponding to the target text; a text classification module 630 is used to input the target text and the prompt text into a trained text classification model, and output a classification result corresponding to the target text; wherein the trained text classification model is trained based on a model loss generated according to target sample text and sample labels, the target sample text is the text obtained by matching the initial sample text with the preset knowledge graph, and the sample label is determined by the sample prompt text obtained by writing the prompt text based on the target sample text; a type determination module 640 is used to determine the text type corresponding to the initial text based on the classification result. In an embodiment of the present application, in the training stage, the initial sample text is matched with a preset knowledge graph to achieve coarse classification of the initial sample text, so that the target sample text used to train the basic classification model can be quickly found, thereby improving the training efficiency of the subsequent basic text classification model, and then the target sample text is written with a prompt text to obtain a sample prompt text, and finally the basic text classification model is trained with the target sample text and the sample prompt text. The training tasks of the basic text classification model can be flexibly configured through the prompt text, thereby guiding the training of the basic text classification model to achieve fine classification of the target sample text, and finally obtain the trained text classification model; in the application stage, the preset knowledge graph is used for coarse classification, which can filter out texts that are not related to the knowledge graph and determine the target text corresponding to the text related to the knowledge graph, and then the trained text classification model is used to perform fine classification on the target text to obtain a classification result, and the text type of the initial text is determined according to the classification result, thereby improving the efficiency and accuracy of text classification of the initial text.

[0311] The embodiment of the present application also provides a computer device, which may be a server, such as Figure 10 As shown, it shows a schematic diagram of the structure of the server involved in the embodiment of the present application, specifically:

[0312] The server may include one or more processing core processors 701, one or more computer-readable storage media memories 702, a power supply 703, an input unit 704 and other components. Those skilled in the art will appreciate that Figure 10 The server structure shown in the figure does not constitute a limitation on the server, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0313] Processor 701 is the server's control center, connecting various components of the server using various interfaces and circuits. By running or executing software programs and / or modules stored in memory 702 and accessing data stored in memory 702, it performs various server functions and processes data, thereby providing overall control of the server. Optionally, processor 701 may include one or more processing cores; preferably, processor 701 may integrate an application processor and a modem processor, with the application processor primarily processing the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 701.

[0314] The memory 702 can be used to store software programs and modules. The processor 701 executes various functional applications and data processing by running the software programs and modules stored in the memory 702. The memory 702 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the server, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory 702 may also include a memory controller to provide the processor 701 with access to the memory 702.

[0315] The computer device also includes a power supply 703 for supplying power to various components. Optionally, the power supply 703 can be logically connected to the processor 701 via a power management system, thereby enabling the power management system to manage charging, discharging, and power consumption. The power supply 703 can also include one or more DC or AC power supplies, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and other arbitrary components.

[0316] The computer device may further include an input unit 704, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0317] Although not shown, the computer device may further include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 701 in the computer device will load the executable files corresponding to one or more application processes into the memory 702 according to the following instructions, and the processor 701 will run the application stored in the memory 702, thereby implementing the various method steps provided in the above embodiments, as follows:

[0318] Obtain the initial text, perform text matching on the initial text using the entities and entity relationships in the preset knowledge graph to obtain the target text;

[0319] Write prompt text based on target text to obtain prompt text corresponding to the target text;

[0320] Input the target text and prompt text into the trained text classification model and output the classification result corresponding to the target text;

[0321] The trained text classification model is obtained by training the model loss generated based on the target sample text and the sample label. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph. The sample label is determined by the sample prompt text written based on the target sample text.

[0322] The text type corresponding to the initial text is determined based on the classification results.

[0323] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of the text classification method above, and will not be repeated here.

[0324] In an embodiment of the present application, a computer device obtains an initial text, performs text matching on the initial text through entities and entity relationships in a preset knowledge graph, and obtains a target text; writes a prompt text based on the target text to obtain a prompt text corresponding to the target text; inputs the target text and the prompt text into a trained text classification model, and outputs a classification result corresponding to the target text; wherein the trained text classification model is trained based on a model loss generated according to target sample text and sample labels, the target sample text is a text obtained by matching the initial sample text with a preset knowledge graph, and the sample label is determined by a sample prompt text obtained by writing a prompt text based on the target sample text; and the text type corresponding to the initial text is determined based on the classification result. In an embodiment of the present application, in the training stage, the initial sample text is matched with a preset knowledge graph to achieve coarse classification of the initial sample text, so that the target sample text used to train the basic classification model can be quickly found, thereby improving the training efficiency of the subsequent basic text classification model, and then the target sample text is written with a prompt text to obtain a sample prompt text, and finally the basic text classification model is trained with the target sample text and the sample prompt text. The training tasks of the basic text classification model can be flexibly configured through the prompt text, thereby guiding the training of the basic text classification model to achieve fine classification of the target sample text, and finally obtain the trained text classification model; in the application stage, the preset knowledge graph is used for coarse classification, which can filter out texts that are not related to the knowledge graph and determine the target text corresponding to the text related to the knowledge graph, and then the trained text classification model is used to perform fine classification on the target text to obtain a classification result, and the text type of the initial text is determined according to the classification result, thereby improving the efficiency and accuracy of text classification of the initial text.

[0325] The embodiment of the present application also provides a computer device, which may be a terminal, such as Figure 11 As shown, it shows a schematic diagram of the structure of the terminal involved in the embodiment of the present application, specifically:

[0326] The computer device may include components such as a radio frequency (RF) circuit 801, a memory 802 including one or more computer-readable storage media, an input unit 803, a display unit 804, a sensor 805, an audio circuit 806, a wireless fidelity (WiFi) module 807, a processor 808 including one or more processing cores, and a power supply 809. It will be understood by those skilled in the art that Figure 11 The terminal structure shown in the figure does not constitute a limitation on the terminal, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0327] The RF circuit 801 can be used to receive and send signals during information transmission or calls. Specifically, after receiving downlink information from the base station, it is handed over to one or more processors 808 for processing; in addition, uplink data is sent to the base station. Generally, the RF circuit 801 includes but is not limited to an antenna, at least one amplifier, a tuner, one or more oscillators, a Subscriber Identity Module (SIM) card, a transceiver, a coupler, a low-noise amplifier (LNA), a duplexer, etc. In addition, the RF circuit 801 can also communicate with the network and other devices via wireless communication. Wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.

[0328] The memory 802 can be used to store software programs and modules. The processor 808 executes various functional applications and information retrieval by running the software programs and modules stored in the memory 802. The memory 802 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, at least one application required for a function (such as a sound playback function, an image playback function, etc.); the data storage area may store data created according to the use of the terminal (such as audio data, a phone book, etc.). In addition, the memory 802 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory 802 may also include a memory controller to provide the processor 808 and the input unit 803 with access to the memory 802.

[0329] The input unit 803 can be used to receive input digital or character information, as well as generate keyboard, mouse, joystick, optical, or trackball signal input related to object settings and function control. Specifically, in one embodiment, the input unit 803 may include a touch-sensitive surface and other input devices. A touch-sensitive surface, also known as a touch display or touchpad, can detect touch operations performed by an object on or near it (for example, operations performed by an object using a finger, stylus, or any other suitable object or accessory on or near the touch-sensitive surface) and drive corresponding connected devices according to a pre-set program. Optionally, the touch-sensitive surface may include a touch detection device and a touch controller. The touch detection device detects the touch position of the object and detects signals generated by the touch operation, transmitting the signals to the touch controller. The touch controller receives the touch information from the touch detection device, converts it into touch point coordinates, and then sends it to the processor 808. The touch controller can also receive and execute commands from the processor 808. Furthermore, touch-sensitive surfaces can be implemented using various types, including resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch-sensitive surface, the input unit 803 may also include other input devices. Specifically, other input devices may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.

[0330] The display unit 804 can be used to display information input by the object or information provided to the object and various graphic object interfaces of the terminal, which can be composed of graphics, text, icons, videos and any combination thereof. The display unit 804 may include a display panel. Optionally, the display panel can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc. Further, the touch-sensitive surface can cover the display panel. When the touch-sensitive surface detects a touch operation on or near it, it is transmitted to the processor 808 to determine the type of touch event. The processor 808 then provides corresponding visual output on the display panel according to the type of touch event. Although in Figure 11 In the embodiment, the touch-sensitive surface and the display panel are used as two independent components to realize input and output functions, but in some embodiments, the touch-sensitive surface and the display panel can be integrated to realize input and output functions.

[0331] The terminal may also include at least one sensor 805, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel according to the brightness of the ambient light, and the proximity sensor may turn off the display panel and / or backlight when the terminal is moved to the ear. As a type of motion sensor, the gravity acceleration sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors that can be configured in the terminal, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be described here.

[0332] Audio circuit 806, speakers, and microphones provide an audio interface between the device and the terminal. Audio circuit 806 converts received audio data into electrical signals and transmits them to the speaker, which then converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuit 806 and converted into audio data. The audio data is then processed by processor 808 and transmitted via RF circuit 801 to, for example, another terminal. Alternatively, the audio data can be stored in memory 802 for further processing. Audio circuit 806 may also include an earphone jack to allow communication between an external headset and the terminal.

[0333] WiFi is a short-range wireless transmission technology. The terminal can help the object to send and receive emails, browse the web and access streaming media through the WiFi module 807. It provides wireless broadband Internet access for the object. Figure 11 The WiFi module 807 is shown, but it is understandable that it is not an essential component of the terminal and can be omitted as needed without changing the essence of the invention.

[0334] Processor 808 is the terminal's control center, connecting all components of the phone using various interfaces and circuits. By running or executing software programs and / or modules stored in memory 802 and accessing data stored in memory 802, it executes various terminal functions and processes data, thereby providing overall monitoring of the phone. Optionally, processor 808 may include one or more processing cores; preferably, processor 808 may integrate an application processor and a modem processor. The application processor primarily handles the operating system, object interfaces, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 808.

[0335] The terminal also includes a power supply 809 (e.g., a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 808 via a power management system, thereby enabling the power management system to manage charging, discharging, and power consumption. The power supply 809 can also include one or more DC or AC power supplies, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and other arbitrary components.

[0336] Although not shown, the terminal may also include a camera, a Bluetooth module, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 808 in the terminal will load the executable files corresponding to the processes of one or more applications into the memory 802 according to the following instructions, and the processor 808 will run the applications stored in the memory 802 to implement various functions:

[0337] Obtain the initial text, perform text matching on the initial text using the entities and entity relationships in the preset knowledge graph to obtain the target text;

[0338] Write prompt text based on target text to obtain prompt text corresponding to the target text;

[0339] Input the target text and prompt text into the trained text classification model and output the classification result corresponding to the target text;

[0340] The trained text classification model is obtained by training the model loss generated based on the target sample text and the sample label. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph. The sample label is determined by the sample prompt text written based on the target sample text.

[0341] The text type corresponding to the initial text is determined based on the classification results.

[0342] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of the text classification method above, and will not be repeated here.

[0343] In an embodiment of the present application, a computer device obtains an initial text, performs text matching on the initial text through entities and entity relationships in a preset knowledge graph, and obtains a target text; writes a prompt text based on the target text to obtain a prompt text corresponding to the target text; inputs the target text and the prompt text into a trained text classification model, and outputs a classification result corresponding to the target text; wherein the trained text classification model is trained based on a model loss generated according to target sample text and sample labels, the target sample text is a text obtained by matching the initial sample text with a preset knowledge graph, and the sample label is determined by a sample prompt text obtained by writing a prompt text based on the target sample text; and the text type corresponding to the initial text is determined based on the classification result. In an embodiment of the present application, in the training stage, the initial sample text is matched with a preset knowledge graph to achieve coarse classification of the initial sample text, so that the target sample text used to train the basic classification model can be quickly found, thereby improving the training efficiency of the subsequent basic text classification model, and then the target sample text is written with a prompt text to obtain a sample prompt text, and finally the basic text classification model is trained with the target sample text and the sample prompt text. The training tasks of the basic text classification model can be flexibly configured through the prompt text, thereby guiding the training of the basic text classification model to achieve fine classification of the target sample text, and finally obtain the trained text classification model; in the application stage, the preset knowledge graph is used for coarse classification, which can filter out texts that are not related to the knowledge graph and determine the target text corresponding to the text related to the knowledge graph, and then the trained text classification model is used to perform fine classification on the target text to obtain a classification result, and the text type of the initial text is determined according to the classification result, thereby improving the efficiency and accuracy of text classification of the initial text.

[0344] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be accomplished by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0345] To this end, an embodiment of the present application provides a computer-readable storage medium storing a plurality of instructions that can be loaded by a processor to execute the steps of any of the text classification methods provided in the embodiments of the present application. For example, the instructions can execute the following steps:

[0346] Obtain the initial text, perform text matching on the initial text using the entities and entity relationships in the preset knowledge graph to obtain the target text;

[0347] Write prompt text based on target text to obtain prompt text corresponding to the target text;

[0348] Input the target text and prompt text into the trained text classification model and output the classification result corresponding to the target text;

[0349] The trained text classification model is obtained by training the model loss generated based on the target sample text and the sample label. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph. The sample label is determined by the sample prompt text written based on the target sample text.

[0350] The text type corresponding to the initial text is determined based on the classification results.

[0351] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of the text classification method above, and will not be repeated here.

[0352] According to one aspect of the present application, a computer program product or computer program is provided. The computer program product or computer program includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the text classification method provided in the various optional implementations provided in the above embodiments.

[0353] The specific implementation of the above operations can be found in the previous embodiments and will not be repeated here.

[0354] The computer-readable storage medium may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0355] Since the instructions stored in the computer-readable storage medium can execute the steps in any text classification method provided in the embodiments of the present application, the beneficial effects that can be achieved by any text classification method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0356] The above is a detailed introduction to a text classification method, device, computer equipment and storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A text classification method, characterized in that: include: Obtaining an initial text, performing text matching on the initial text using entities and entity relationships in a preset knowledge graph to obtain a target text; Writing a prompt text based on the target text to obtain a prompt text corresponding to the target text; Inputting the target text and the prompt text into the trained text classification model, and outputting the classification result corresponding to the target text; The trained text classification model is obtained by training based on the model loss generated by the target sample text and the sample label. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph. The sample label is determined by the sample prompt text obtained by writing the prompt text based on the target sample text. The text type corresponding to the initial text is determined according to the classification result.

2. The text classification method according to claim 1, characterized in that The initial text is matched with entities and entity relationships in a preset knowledge graph to obtain a target text, including: Performing word segmentation processing on the initial text to obtain at least one word segmentation text; Matching the at least one segmented text with an entity in the knowledge graph to obtain a first matching entity; Determine a second matching entity based on the first matching entity and the entity relationship in the knowledge graph; The first matching entity and the second matching entity are determined as target texts.

3. The text classification method according to claim 2, characterized in that The step of matching the at least one segmented text with an entity in the knowledge graph to obtain a first matching entity includes: Obtaining a segmentation text vector corresponding to each segmentation text in the at least one segmentation text; Determine the similarity between the word segmentation text vector and the entity vector of any entity in the knowledge graph; The entity corresponding to the entity vector having the highest similarity to the word segmentation text vector is determined as the first matching entity.

4. The text classification method according to claim 1, characterized in that The step of writing a prompt text based on the target text to obtain a prompt text corresponding to the target text includes: Determine at least one label corresponding to the target text according to the knowledge graph; Prompt text is written for the target text according to the at least one tag to obtain prompt text corresponding to the target text under each tag.

5. The text classification method according to claim 4, characterized in that Writing a prompt text for the target text according to the at least one tag to obtain a prompt text corresponding to the target text under each tag includes: Determine the prompt text template corresponding to each of the tags; Prompt text is written for the target text based on the prompt text template to obtain prompt text corresponding to the target text under each label.

6. The text classification method according to claim 1, characterized in that The step of inputting the target text and the prompt text into a trained text classification model and outputting a classification result corresponding to the target text includes: Determining the data volume corresponding to the target text; A trained text classification model of corresponding model complexity is determined according to the data volume, and the target text and the prompt text are input into the trained text classification model to output a classification result.

7. The text classification method according to claim 1, characterized in that The step of inputting the target text and the prompt text into a trained text classification model and outputting a classification result corresponding to the target text includes: Determining whether the data volume corresponding to the target text is greater than a preset data volume; When the data volume of the target text is greater than a preset data volume, determining an application scenario corresponding to the target text based on a label corresponding to the target text; A trained text classification model related to the application scenario is determined, and the target text and the prompt text are input into the trained text classification model, and a classification result is output.

8. The text classification method according to claim 1, characterized in that Determining the text type corresponding to the initial text according to the classification result includes: Determining a classification label corresponding to the target text according to the classification result; The text type corresponding to the initial text is determined according to the classification label.

9. The text classification method according to claim 8, characterized in that: Determining the text type corresponding to the initial text according to the classification label includes: When the classification label includes a plurality of different classification labels, determining a plurality of related text types according to the classification labels; Determining the number of the classification labels corresponding to each of the relevant text types, and determining the level corresponding to each of the relevant text types based on the number; The related text type with the highest rank is determined as the text type corresponding to the initial text, and the other related text types except the related text type with the highest rank and the ranks corresponding to each of the other related text types are displayed.

10. The text classification method according to claim 1, characterized in that: The training process of the trained text classification model includes: Obtain sample text, and perform text matching on the initial sample text using entities and entity relationships in a preset knowledge graph to obtain a target sample text; Writing a prompt text for the target sample text to obtain a sample prompt text corresponding to the target sample text; Determining a sample label corresponding to the target sample text based on the sample prompt text; Inputting the sample prompt text and the target sample text into a basic text classification model, and outputting a sample classification result; Determining a model loss between the sample classification result and the sample label; The basic text classification model is iteratively trained according to the model loss to obtain a trained text classification model.

11. A text classification device, characterized in that: include: A text acquisition module is used to acquire an initial text and perform text matching on the initial text using entities and entity relationships in a preset knowledge graph to obtain a target text; A text writing module, configured to write a prompt text based on the target text to obtain a prompt text corresponding to the target text; A text classification module, configured to input the target text and the prompt text into a trained text classification model and output a classification result corresponding to the target text; The trained text classification model is obtained by training based on the model loss generated by the target sample text and the sample label. The target sample text is the text obtained by matching the initial sample text with the preset knowledge graph. The sample label is determined by the sample prompt text obtained by writing the prompt text based on the target sample text. A type determination module is used to determine the text type corresponding to the initial text according to the classification result.

12. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the text classification method according to any one of claims 1 to 10.

13. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the text classification method according to any one of claims 1 to 10 is implemented.

14. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the text classification method according to any one of claims 1 to 10 is implemented.