A text classification method, device, system and medium
By integrating knowledge data and training samples of prompt templates and using prompt learning models for text classification, the problem of insufficient text classification accuracy in traditional methods is solved, and more efficient and accurate text classification effects are achieved.
Patent Information
- Application Number
- CN202310683287.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-09
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2043-06-09
AI Technical Summary
Traditional text classification methods lack accuracy in the financial industry, especially when dealing with long texts with complex intent, which makes accurate classification difficult, affecting the effectiveness of intelligent customer service and content push.
The training samples of fused knowledge data and prompt templates are used to train the prompt learning model, and the masked text is used to transform the text classification task, predict the target masked text and perform text type mapping to improve the classification accuracy.
By enriching the contextual information of the text and using flexible prompt templates, the accuracy of text classification is enhanced, the dependence on manual annotation is reduced, and the training efficiency and classification effect are improved.
Smart Images

Figure CN116662547B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of financial technology, and in particular to a text classification method, device, system and medium. Background Art
[0002] The financial industry, owing to its inherent adaptability to specific scenarios and abundant data, has already embraced artificial intelligence (AI) technology. Text classification, a key subfield of AI, is widely used in various financial scenarios. For example, in intelligent customer service scenarios within banks, text classification can identify user intent and push relevant questions or answers to users. In content push scenarios within banking software, news content can be identified and classified for personalized content push.
[0003] Traditional classification methods primarily use machine learning to extract information such as the subject, intent, and keywords from a text, and then classify this information. This approach is fast but inaccurate. Long texts with complex intent are difficult to distinguish, reducing the accuracy of text classification results and, in turn, hindering the effectiveness of text classification in scenarios such as intelligent customer service and content push. Summary of the Invention
[0004] In view of the above-mentioned deficiencies in the prior art, the purpose of the present invention is to provide a text classification method, device, system and medium that can be applied to financial technology or other related fields, aiming to improve the accuracy of text classification.
[0005] The technical solutions of the present invention are as follows:
[0006] A text classification method, comprising:
[0007] Collecting original text data, and constructing a training sample that integrates knowledge data and a prompt template based on the original text data, wherein the training sample includes masked text;
[0008] Inputting the training sample into a pre-built prompt learning model for training until the model converges, and the prompt learning model predicts the mask text;
[0009] Inputting a prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict the target mask text in the prompt template to be recognized;
[0010] Text type mapping is performed according to the target mask text to determine the target text type of the text to be recognized.
[0011] In one embodiment, the collecting of original text data and constructing a training sample that integrates knowledge data and a prompt template based on the original text data, wherein the training sample includes masked text, include:
[0012] Collecting original text data, performing knowledge extraction on the original text data, and classifying and annotating the knowledge extraction results to obtain training text;
[0013] Obtaining a preset prompt template, and generating a prompt training template containing masked text according to the original text data and the prompt template;
[0014] The training text and the prompt training template are added one by one to construct the training sample.
[0015] In one embodiment, the collecting of original text data, performing knowledge extraction on the original text data, and classifying and labeling the original text data according to the knowledge extraction results to obtain training text includes:
[0016] Collecting original text data and extracting knowledge entities and / or entity relationships from the original text data;
[0017] Matching the knowledge entities and / or entity relationships with a knowledge dictionary of a preset text type;
[0018] The original text data is classified and annotated according to the matching results to obtain training text.
[0019] In one embodiment, classifying and labeling the original text data according to the matching results to obtain training text specifically includes:
[0020] The preset text type corresponding to the knowledge dictionary that is successfully matched is marked as 1, and the preset text type corresponding to the knowledge dictionary that is unsuccessfully matched is marked as 0.
[0021] In one embodiment, the obtaining of the preset prompt template and generating a prompt training template containing masked text according to the original text data and the prompt template include:
[0022] Obtaining a preset prompt template, wherein the prompt template includes a mask position;
[0023] The original text data is spliced with the prompt template, and the prompt training template is generated after the mask text is filled in the mask position according to the text type annotation of the original text data.
[0024] In one embodiment, inputting the prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict the target mask text in the prompt template to be recognized includes:
[0025] Acquire a text to be recognized, and generate a prompt template to be recognized according to the text to be recognized and the prompt template, wherein the prompt template to be recognized includes a target mask position;
[0026] The prompt template to be recognized is input into the prompt learning model to predict the target mask text at the target mask position.
[0027] In one embodiment, performing text type mapping according to the target mask text to determine the target text type of the text to be recognized includes:
[0028] Matching the target mask text with a preset mask prompt dictionary to determine a target mask prompt dictionary that matches the target mask text;
[0029] According to the mapping relationship between the mask prompt dictionary and the preset text type, the target text type corresponding to the target mask prompt dictionary is determined.
[0030] A text classification device, comprising:
[0031] A sample construction module is used to collect original text data and construct a training sample that integrates knowledge data and prompt templates based on the original text data, wherein the training sample includes masked text;
[0032] A model training module, configured to input the training samples into a pre-built prompt learning model for training until the model converges, wherein the prompt learning model predicts the masked text;
[0033] A mask prediction module is used to input a prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict the target mask text in the prompt template to be recognized;
[0034] The mapping classification module is used to perform text type mapping according to the target mask text to determine the target text type of the text to be recognized.
[0035] A text classification system, the system comprising at least one processor; and
[0036] a memory communicatively connected to the at least one processor; wherein,
[0037] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the above-mentioned text classification method.
[0038] A non-volatile computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are executed by one or more processors, the one or more processors can execute the above-mentioned text classification method.
[0039] Beneficial effects: The present invention discloses a text classification method, device, system and medium. Compared with the existing technology, the embodiments of the present invention complete the text classification task by performing prompt learning training through training samples that integrate knowledge data and prompt templates, which can enrich the contextual information of the text, enhance the text classification effect, and effectively improve the accuracy of text classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0041] Figure 1 A flow chart of a text classification method provided by an embodiment of the present invention;
[0042] Figure 2 Flowchart of step S100 in the text classification method provided by an embodiment of the present invention;
[0043] Figure 3 Flowchart of step S101 in the text classification method provided in an embodiment of the present invention;
[0044] Figure 4 Flowchart of step S102 in the text classification method provided in an embodiment of the present invention;
[0045] Figure 5 Flowchart of step S300 in the text classification method provided by an embodiment of the present invention;
[0046] Figure 6 Flowchart of step S400 in the text classification method provided by an embodiment of the present invention;
[0047] Figure 7 A schematic diagram of the functional modules of a text classification device provided by an embodiment of the present invention;
[0048] Figure 8 A schematic diagram of the hardware structure of a text classification system provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0049] To make the objectives, technical solutions, and effects of the present invention more clear and distinct, the present invention is further described in detail below. It should be understood that the specific embodiments described herein are merely for the purpose of explaining the present invention and are not intended to limit the present invention. The embodiments of the present invention are described below with reference to the accompanying drawings.
[0050] The financial industry, owing to its inherent adaptability to specific scenarios and abundant data, has already embraced artificial intelligence (AI) technology. Text classification, a key subfield of AI, is widely used in various financial scenarios. For example, in intelligent customer service scenarios within banks, text classification can identify user intent and push relevant questions or answers to users. In content push scenarios within banking software, news content can be identified and classified for personalized content push.
[0051] Traditional classification methods primarily use machine learning to extract information such as the subject, intent, and keywords from a text, and then classify this information. This approach is fast but inaccurate. Long texts with complex intent are difficult to distinguish, reducing the accuracy of text classification results and, in turn, hindering the effectiveness of text classification in scenarios such as intelligent customer service and content push.
[0052] In order to solve the above problems, the present invention proposes a text classification method, see Figure 1 , Figure 1 A flowchart of an embodiment of the text classification method provided by the present invention. The text classification method provided in this embodiment is applied to a system consisting of a terminal device, a network and a server, wherein the network is a medium for providing a communication link between the terminal device and the server, which may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.; the operating system on the terminal device may include a handheld device operating system (iPhone operating system, iOS system), Android system or other operating systems, and the terminal device is connected to the server through the network to achieve interaction, thereby performing operations such as receiving or sending data, etc., and specifically can be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, portable computers and desktop servers, etc. As Figure 1 As shown, the method specifically includes the following steps:
[0053] S100 , collecting original text data, and constructing a training sample that integrates knowledge data and a prompt template based on the original text data, wherein the training sample includes a masked text.
[0054] In this embodiment, raw text data can be collected from a designated text database or from historical data in an application scenario, such as historical communication data from a customer service system. By collecting raw text data and constructing samples, training samples that integrate knowledge data and prompt templates are generated for subsequent model training. By adding rich knowledge data and flexible prompt templates to the training samples, the text classification effect is enhanced.
[0055] Among them, the constructed training samples contain masked text, that is, words in one or more positions in each training sample are masked. The masked text can convert the downstream text classification task into a mask prediction task in the pre-training stage. It is suitable for text classification scenarios with high annotation costs and fewer annotated samples, reducing annotation work and improving training efficiency.
[0056] In one embodiment, Figure 2 As shown, step S100 includes:
[0057] S101, collecting original text data, performing knowledge extraction on the original text data, and classifying and annotating the knowledge extraction results to obtain training text;
[0058] S102: Obtain a preset prompt template, and generate a prompt training template containing masked text according to the original text data and the prompt template;
[0059] S103: Add the training text and the prompt training template one by one to construct the training sample.
[0060] In this embodiment, the constructed training sample consists of two parts, one part is the training text, and the other part is the prompt training template. In the training text, in order to enrich the contextual information of the text and increase the classification effect of long text, more knowledge information is added. Specifically, knowledge extraction is performed on the original text data, and the training text is obtained after classification and annotation based on the relationship between the knowledge extraction result and the classification label. In the prompt training template, based on the preset prompt template, namely the prompt template, the original text data is substituted into the prompt template to generate a prompt training template containing mask text, wherein the prompt template can be manually generated or automatically generated, and the number and type of prompt templates are diverse, thereby enriching the position and description content of the mask text in the prompt training template, thereby improving the effect of subsequent mask prediction.
[0061] After obtaining the knowledge-based training text and the flexible and diverse prompt training templates respectively, the two are added one-to-one, that is, the training text and prompt training template belonging to the same original text data are added together to construct a training sample with knowledge and masked text, thereby achieving accurate and efficient text prediction training.
[0062] In one embodiment, Figure 3 As shown, step S101 includes:
[0063] S1011. Collect original text data and extract knowledge entities and / or entity relationships from the original text data;
[0064] S1012, matching the knowledge entities and / or entity relationships with a knowledge dictionary of a preset text type;
[0065] S1013: Classify and annotate the original text data according to the matching results to obtain training text.
[0066] In this embodiment, the training text requires categorized annotation of the original text data. For example, the actual classification result for "How should a product manager conduct business acceptance before project launch?" is the question-and-answer category; the actual labeling result for "Why is it so hot in Shenzhen today?" is the chat category. During annotation, knowledge entities and / or entity relationships from the original text data can be extracted and categorized and annotated. For example, 'product manager,' 'launch,' and 'acceptance' are extracted and labeled as 1 in the question-and-answer category, and 0 in other categories. 'Shenzhen' and 'weather' are extracted and labeled as 1 in the chat category, and 0 in other categories. This incorporates the original annotation information for model training. Due to the large volume of data, to improve annotation efficiency, knowledge dictionaries for each predefined text type can be constructed in advance. The extracted entities and / or entity relationships are then matched against each knowledge dictionary. Based on the matching results, the original text data is automatically categorized and annotated to produce the training text. Specifically, when an entity or entity relationship falls into a knowledge dictionary, the text type corresponding to that knowledge dictionary is labeled as 1, while other predefined microblog types not included in the knowledge dictionary are labeled as 0, thereby achieving efficient dictionary matching and annotation.
[0067] In one embodiment, Figure 4 As shown, step S102 includes:
[0068] S1021: Obtain a preset prompt template, where the prompt template includes a mask position;
[0069] S1022: Splicing the original text data with the prompt template, and filling the mask text in the mask position according to the text type annotation of the original text data to generate the prompt training template.
[0070] In this embodiment, when generating prompt training templates, different types of prompt templates are obtained. These prompt templates contain mask positions. The mask positions can be different in different prompt templates, increasing template diversity and improving model training effectiveness. The collected original text data is spliced with the prompt templates, and the mask positions are filled with mask text based on the text type annotation of the original text data to generate the prompt training template.
[0071] Taking the two prompt templates "This is a __ problem" and "This problem is related to __" as examples, after combining the above two original text data, we can get four prompt training templates: "How should product managers conduct business acceptance before the project goes into production? This is a __ problem", "How should product managers conduct business acceptance before the project goes into production? This problem is related to __", "Why is Shenzhen so hot today? This is a __ problem", and "Why is Shenzhen so hot today? This problem is related to __".
[0072] For the texts in the mask positions in the four prompt training templates, the corresponding descriptive words, i.e., mask texts, are filled in based on their text type annotations. For example, a corresponding mask prompt dictionary is pre-created for each preset text type, which includes several words, and when filling in the mask text, the words are randomly filled in the corresponding dictionary. For example, in the above embodiment, any one of the words {project, profession, business, management} can be filled in the mask positions of the first two templates, and any one of the words {weather, climate, region, season} can be filled in the mask positions of the last two templates. Thus, a prompt training template with mask text is generated by combining flexible and diverse prompt templates with original text data, and the downstream text classification task is converted into a prediction task for the mask text in the template, which is more suitable for training scenarios with fewer annotations and reduces the annotation workload.
[0073] S200: Input the training sample into a pre-built prompt learning model for training until the model converges, and the prompt learning model predicts the mask text.
[0074] In this embodiment, the constructed training samples are input into a pre-built prompt learning model for training. Specifically, the model can adopt a 6-layer transformer infrastructure, that is, a 6-layer Encoder block, a hidden layer dimension of 512, and the number of attention heads is 8. The text vector of the training text and the text vector of the prompt training template are added as the Embedding layer input, and the overall context vector is obtained through the Encoder module. Finally, the fully connected layer is mapped, and the model is optimized using the loss function until the model converges. The prompt learning model for predicting the masked text at the mask position in the input text can be obtained.
[0075] S300: Inputting a prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict and obtain a target mask text in the prompt template to be recognized.
[0076] In this embodiment, when performing text classification on the text to be recognized, a prompt template to be recognized is also constructed based on the prompt template and the text to be recognized, and the prompt template is input into the converged prompt learning model to perform text prediction at the mask position, thereby obtaining the target mask text in the prompt template to be recognized.
[0077] In one embodiment, Figure 5 As shown, step S300 includes:
[0078] S301, obtaining a text to be recognized, and generating a prompt template to be recognized according to the text to be recognized and the prompt template, wherein the prompt template to be recognized includes a target mask position;
[0079] S302: Input the prompt template to be recognized into the prompt learning model to predict the target mask text at the target mask position.
[0080] In this embodiment, the acquired text to be recognized is first compared with the preset prompt template to generate a prompt template to be recognized. Based on the mask setting in the prompt template, the target mask position is included in the prompt template to be recognized. For example, if the text to be recognized is "How is the weather in Shenzhen today?", the prompt template can generate "How is the weather in Shenzhen today? This is a __ problem" and "How is the weather in Shenzhen today? This problem is related to __". The blank position is the target mask position. This is input into the prompt learning model to obtain the target mask text at the target mask position predicted by the model, such as "weather" or "climate". The predicted target mask text is used as the accurate basis for text classification.
[0081] S400: Perform text type mapping according to the target mask text to determine the target text type of the text to be recognized.
[0082] In this embodiment, the predicted target mask text is mapped to a preset text type, and the target text type of the text to be recognized is determined by the text type into which the target mask text falls. Prompt learning training is performed using training samples that integrate knowledge data and prompt templates, transforming the original task into predicting words in the mask position. This mapping relationship between the mask text and the actual annotations completes the text classification task, enriching the text's contextual information, enhancing the text classification effect, and effectively improving the accuracy of text classification.
[0083] In one embodiment, Figure 6 As shown, step S400 includes:
[0084] S401, matching the target mask text with a preset mask prompt dictionary to determine a target mask prompt dictionary that matches the target mask text;
[0085] S402: Determine a target text type corresponding to the target mask prompt dictionary according to a mapping relationship between the mask prompt dictionary and a preset text type.
[0086] In this embodiment, several mask prompt dictionaries are pre-set, and each mask prompt dictionary maps a preset text type. For example, a mask prompt dictionary {project, profession, business, management} is preset for the question and answer category, and a mask prompt dictionary {weather, climate, region, season} is preset for the chat category. The length of each mask prompt dictionary can be set arbitrarily and the words therein can be updated as needed to adapt to changes in text classification needs.
[0087] When performing text classification based on the predicted target mask text, it is first matched against various mask prompt dictionaries to determine the target mask prompt dictionary that matches it. This means determining which dictionary the currently predicted target mask text falls into. Then, based on the mapping relationship between each mask prompt dictionary and the preset text type, the target text type corresponding to the target mask prompt dictionary can be determined. For example, for the text to be recognized, "What's the weather like in Shenzhen today?", after constructing a prompt template and predicting the mask text, the predicted text is "weather" or "climate." The dictionary that the predicted text falls into corresponds to the chat category, so the text to be recognized can be classified into the chat category. This allows the text classification task to be converted to mask prediction through a flexible prompt template, followed by label mapping. This not only enhances the text classification effect, but also reduces the requirement for manual annotation, thereby reducing training costs.
[0088] Another embodiment of the present invention provides a text classification device, such as Figure 7 As shown, the device 1 includes:
[0089] A sample construction module 11 is used to collect original text data and construct a training sample that integrates knowledge data and prompt templates based on the original text data, wherein the training sample includes masked text;
[0090] A model training module 12 is configured to input the training samples into a pre-built prompt learning model for training until the model converges, and the prompt learning model predicts the masked text;
[0091] The mask prediction module 13 is used to input the prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict the target mask text in the prompt template to be recognized;
[0092] The mapping and classification module 14 is configured to perform text type mapping according to the target mask text to determine the target text type of the text to be recognized.
[0093] The module referred to in the present invention refers to a series of computer program instruction segments that can perform specific functions. It is more suitable for describing the execution process of text classification than a program. For the specific implementation of each module, please refer to the corresponding method embodiment above, which will not be repeated here.
[0094] In one embodiment, the sample construction module 11 includes:
[0095] A knowledge extraction unit is used to collect original text data, extract knowledge from the original text data, and classify and annotate the knowledge extraction results to obtain training text;
[0096] A template generating unit, configured to obtain a preset prompt template and generate a prompt training template containing masked text according to the original text data and the prompt template;
[0097] The sample construction unit is used to construct the training sample by adding the training text and the prompt training template in a one-to-one correspondence.
[0098] In one embodiment, the knowledge extraction unit includes:
[0099] An extraction unit, configured to collect original text data and extract knowledge entities and / or entity relationships from the original text data;
[0100] a matching unit, configured to match the knowledge entity and / or entity relationship with a knowledge dictionary of a preset text type;
[0101] The labeling unit is used to classify and label the original text data according to the matching results to obtain training text.
[0102] In one embodiment, the marking unit is specifically configured to:
[0103] The preset text type corresponding to the knowledge dictionary that is successfully matched is marked as 1, and the preset text type corresponding to the knowledge dictionary that is unsuccessfully matched is marked as 0.
[0104] In one embodiment, the template generating unit includes:
[0105] A template acquisition unit, configured to acquire a preset prompt template, wherein the prompt template includes a mask position;
[0106] The filling generation unit is used to splice the original text data with the prompt template, and generate the prompt training template after filling the mask text in the mask position according to the text type annotation of the original text data.
[0107] In one embodiment, the mask prediction module 13 includes:
[0108] a generating unit, configured to obtain a text to be recognized, and generate a prompt template to be recognized according to the text to be recognized and the prompt template, wherein the prompt template to be recognized includes a target mask position;
[0109] The prediction unit is used to input the prompt template to be recognized into the prompt learning model to predict the target mask text at the target mask position.
[0110] In one embodiment, the mapping classification module 14 includes:
[0111] a dictionary matching unit, configured to match the target mask text with a preset mask prompt dictionary to determine a target mask prompt dictionary that matches the target mask text;
[0112] The classification mapping unit is configured to determine the target text type corresponding to the target mask prompt dictionary according to the mapping relationship between the mask prompt dictionary and the preset text type.
[0113] Another embodiment of the present invention provides a text classification system, such as Figure 8 As shown, the system 10 includes:
[0114] One or more processors 110 and memory 120, Figure 8 In the description, a processor 110 is used as an example. The processor 110 and the memory 120 may be connected via a bus or other means. Figure 8 The bus connection is taken as an example.
[0115] The processor 110 is used to implement various control logics of the system 10. It can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination of these components. In addition, the processor 110 can also be any traditional processor, microprocessor, or state machine. The processor 110 can also be implemented as a combination of computing devices, for example, a combination of a DSP and a microprocessor, multiple microprocessors, one or more microprocessors combined with a DSP, and / or any other such configuration.
[0116] Memory 120, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions corresponding to the text classification method in the embodiments of the present invention. Processor 110 executes the non-volatile software programs, instructions, and modules stored in memory 120 to execute various functional applications and data processing of system 10, thereby implementing the text classification method in the above-mentioned method embodiments.
[0117] Memory 120 may include a program storage area and a data storage area. The program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created based on the use of system 10, etc. In addition, memory 120 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 120 may optionally include memory remotely located relative to processor 110, and such remote memory may be connected to system 10 via a network. Examples of such networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0118] One or more units are stored in the memory 120, and when executed by one or more processors 110, implement the following steps:
[0119] Collecting original text data, and constructing a training sample that integrates knowledge data and a prompt template based on the original text data, wherein the training sample includes masked text;
[0120] Inputting the training sample into a pre-built prompt learning model for training until the model converges, and the prompt learning model predicts the mask text;
[0121] Inputting a prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict the target mask text in the prompt template to be recognized;
[0122] Text type mapping is performed according to the target mask text to determine the target text type of the text to be recognized.
[0123] In one embodiment, the collecting of original text data and constructing a training sample that integrates knowledge data and a prompt template based on the original text data, wherein the training sample includes masked text, include:
[0124] Collecting original text data, performing knowledge extraction on the original text data, and classifying and annotating the knowledge extraction results to obtain training text;
[0125] Obtaining a preset prompt template, and generating a prompt training template containing masked text according to the original text data and the prompt template;
[0126] The training text and the prompt training template are added one by one to construct the training sample.
[0127] In one embodiment, the collecting of original text data, performing knowledge extraction on the original text data, and classifying and labeling the original text data according to the knowledge extraction results to obtain training text includes:
[0128] Collecting original text data and extracting knowledge entities and / or entity relationships from the original text data;
[0129] Matching the knowledge entities and / or entity relationships with a knowledge dictionary of a preset text type;
[0130] The original text data is classified and annotated according to the matching results to obtain training text.
[0131] In one embodiment, classifying and labeling the original text data according to the matching results to obtain training text specifically includes:
[0132] The preset text type corresponding to the knowledge dictionary that is successfully matched is marked as 1, and the preset text type corresponding to the knowledge dictionary that is unsuccessfully matched is marked as 0.
[0133] In one embodiment, the obtaining of the preset prompt template and generating a prompt training template containing masked text according to the original text data and the prompt template include:
[0134] Obtaining a preset prompt template, wherein the prompt template includes a mask position;
[0135] The original text data is spliced with the prompt template, and the prompt training template is generated after the mask text is filled in the mask position according to the text type annotation of the original text data.
[0136] In one embodiment, inputting the prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict the target mask text in the prompt template to be recognized includes:
[0137] Acquire a text to be recognized, and generate a prompt template to be recognized according to the text to be recognized and the prompt template, wherein the prompt template to be recognized includes a target mask position;
[0138] The prompt template to be recognized is input into the prompt learning model to predict the target mask text at the target mask position.
[0139] In one embodiment, performing text type mapping according to the target mask text to determine the target text type of the text to be recognized includes:
[0140] Matching the target mask text with a preset mask prompt dictionary to determine a target mask prompt dictionary that matches the target mask text;
[0141] According to the mapping relationship between the mask prompt dictionary and the preset text type, the target text type corresponding to the target mask prompt dictionary is determined.
[0142] An embodiment of the present invention provides a non-volatile computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, which are executed by one or more processors, for example, to execute the above-described Figure 1 Method steps S100 to S400.
[0143] As examples, non-volatile storage media can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) as external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM, (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The disclosed memory components or memories of the operating environment described herein are intended to include one or more of these and / or any other suitable types of memory.
[0144] In summary, the present invention discloses a text classification method, device, system, and medium. The method collects original text data, constructs a training sample that integrates knowledge data and a prompt template based on the original text data, and the training sample includes masked text; the training sample is input into a pre-built prompt learning model for training until the model converges, and the prompt learning model predicts the masked text; the prompt template to be recognized constructed based on the text to be recognized is input into the prompt learning model to predict the target masked text in the prompt template to be recognized; and text type mapping is performed based on the target masked text to determine the target text type of the text to be recognized. By performing prompt learning training on training samples that integrate knowledge data and prompt templates to complete the text classification task, the contextual information of the text can be enriched, the text classification effect can be enhanced, and the accuracy of text classification can be effectively improved.
[0145] Of course, those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing related hardware (such as a processor, controller, etc.) through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes in the above-described method embodiments. The storage medium can be a memory, a magnetic disk, a floppy disk, a flash memory, an optical storage device, etc.
[0146] It should be understood that the application of the present invention is not limited to the above examples. For those skilled in the art, improvements or changes can be made based on the above description. All these improvements and changes should fall within the scope of protection of the claims attached to the present invention.
Claims
1. A text classification method, characterized in that: include: Collecting original text data, and constructing a training sample that integrates knowledge data and a prompt template based on the original text data, wherein the training sample includes masked text; Inputting the training sample into a pre-built prompt learning model for training until the model converges, and the prompt learning model predicts the mask text; Inputting a prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict the target mask text in the prompt template to be recognized; Performing text type mapping according to the target mask text to determine the target text type of the text to be recognized; The collecting of original text data and constructing a training sample that integrates knowledge data and a prompt template based on the original text data, wherein the training sample includes masked text, include: Collecting original text data, performing knowledge extraction on the original text data, and classifying and annotating the knowledge extraction results to obtain training text; Obtaining a preset prompt template, and generating a prompt training template containing masked text according to the original text data and the prompt template; The training text and the prompt training template are added one by one to construct the training sample; The collecting of original text data, performing knowledge extraction on the original text data, and classifying and labeling the original text data according to the knowledge extraction results to obtain training text includes: Collecting original text data, and extracting knowledge entities and / or entity relationships from the original text data; Matching the knowledge entities and / or entity relationships with a knowledge dictionary of a preset text type; The original text data is classified and annotated according to the matching results to obtain training text.
2. The text classification method according to claim 1, characterized in that The step of classifying and labeling the original text data according to the matching results to obtain the training text specifically includes: The preset text type corresponding to the knowledge dictionary that is successfully matched is marked as 1, and the preset text type corresponding to the knowledge dictionary that is unsuccessfully matched is marked as 0.
3. The text classification method according to claim 1, characterized in that The step of obtaining a preset prompt template and generating a prompt training template containing masked text according to the original text data and the prompt template includes: Obtaining a preset prompt template, wherein the prompt template includes a mask position; The original text data is spliced with the prompt template, and the prompt training template is generated after the mask text is filled in the mask position according to the text type annotation of the original text data.
4. The text classification method according to claim 1, characterized in that The step of inputting a prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict a target mask text in the prompt template to be recognized includes: Acquire a text to be recognized, and generate a prompt template to be recognized according to the text to be recognized and the prompt template, wherein the prompt template to be recognized includes a target mask position; The prompt template to be recognized is input into the prompt learning model to predict the target mask text at the target mask position.
5. The text classification method according to claim 1, characterized in that The performing text type mapping according to the target mask text to determine the target text type of the text to be recognized includes: Matching the target mask text with a preset mask prompt dictionary to determine a target mask prompt dictionary that matches the target mask text; According to the mapping relationship between the mask prompt dictionary and the preset text type, the target text type corresponding to the target mask prompt dictionary is determined.
6. A text classification device, characterized in that: include: A sample construction module is used to collect original text data and construct a training sample that integrates knowledge data and prompt templates based on the original text data, wherein the training sample includes masked text; A model training module, configured to input the training samples into a pre-built prompt learning model for training until the model converges, wherein the prompt learning model predicts the masked text; A mask prediction module is used to input a prompt template to be recognized constructed based on the text to be recognized into the prompt learning model to predict the target mask text in the prompt template to be recognized; A mapping classification module, configured to perform text type mapping according to the target mask text and determine the target text type of the text to be recognized; The sample building block includes: A knowledge extraction unit is used to collect original text data, extract knowledge from the original text data, and classify and annotate the knowledge extraction results to obtain training text; A template generating unit, configured to obtain a preset prompt template and generate a prompt training template containing masked text according to the original text data and the prompt template; A sample construction unit, configured to construct the training sample by adding the training text and the prompt training template in a one-to-one correspondence; The knowledge extraction unit includes: An extraction unit, configured to collect original text data and extract knowledge entities and / or entity relationships from the original text data; a matching unit, configured to match the knowledge entity and / or entity relationship with a knowledge dictionary of a preset text type; The labeling unit is used to classify and label the original text data according to the matching results to obtain training text.
7. A text classification system, characterized in that The system includes at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the text classification method according to any one of claims 1 to 5.
8. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores computer-executable instructions, which, when executed by one or more processors, enable the one or more processors to execute the text classification method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Relationship extraction method, system and equipment and storage medium
CN114969372A
Knowledge prompt fused legal text small sample named entity recognition method
CN115062104A