A language processing method, device and terminal based on automatic prompt recommendation

By obtaining and combining target prompt text to improve the downstream task accuracy of the pre-trained language model, the problem of low accuracy in processing downstream tasks is solved, and a higher processing effect is achieved.

CN114238629BActive Publication Date: 2025-08-19PENG CHENG LAB
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111429355.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-29
Publication Date
2025-08-19
Estimated Expiration
2041-11-29

AI Technical Summary

Technical Problem

The existing pre-trained language models are not very accurate when processing downstream tasks. Due to the huge amount of parameters, ordinary stand-alone hardware resources cannot support training and reasoning, resulting in poor processing results.

Method used

By obtaining the target prompt text of the pending text, combining the pre-trained language model, new input text is formed to improve accuracy, including text classification, clustering, similarity and probability calculation, the sampling method selects the target prompt text, and combines processing in the pre-trained model.

Benefits of technology

Improve the processing accuracy of the pre-trained language model in downstream tasks, and output more accurate results by guiding the pre-trained model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114238629B_ABST
    Figure CN114238629B_ABST
Patent Text Reader

Abstract

The present invention discloses a language processing method, device, and terminal based on automatic prompt recommendation. The method comprises: obtaining a text to be processed; obtaining a target prompt text corresponding to the text to be processed based on the text to be processed, wherein the target prompt text includes a sample text to be processed and a result corresponding to the sample text to be processed; combining the text to be processed and the target prompt text, inputting the result into a pre-trained language model, and obtaining a target result output by the pre-trained language model as the result corresponding to the text to be processed. The present invention can improve the accuracy of the pre-trained language model when processing downstream tasks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of natural language processing, and in particular to a language processing method, device and terminal based on automatic prompt recommendation. Background Art

[0002] In the field of natural language processing, ultra-large-scale pre-trained language models based on large-scale data training, such as GPT-3 and Penguin-α, possess powerful zero-shot and small-shot learning capabilities. However, since these models are trained on large amounts of data, while applicable to a variety of downstream tasks, they require fine-tuning to achieve higher accuracy for specific domains or types of processing tasks. Limited by the sheer number of parameters, often in the tens of billions or even hundreds of billions, these models require limited single-machine hardware resources to support the training and inference of models with such a large parameter scale. Therefore, the traditional pre-training and fine-tuning model is difficult to apply to these models, resulting in low accuracy for downstream tasks.

[0003] Therefore, the existing technology needs to be improved and enhanced. Summary of the Invention

[0004] In response to the above-mentioned defects of the prior art, the present invention provides a language processing method, device and terminal based on automatic prompt recommendation, aiming to solve the problem of low accuracy of pre-trained language models in the prior art when processing downstream tasks.

[0005] In order to solve the above technical problems, the technical solutions adopted by the present invention are as follows:

[0006] A first aspect of the present invention provides a language processing method based on automatic prompt recommendation, the method comprising:

[0007] Acquire a text to be processed, and acquire a target prompt text corresponding to the text to be processed according to the text to be processed, wherein the target prompt text includes a sample text to be processed and a result corresponding to the sample text to be processed;

[0008] The text to be processed and the target prompt text are combined and input into a pre-trained language model, and a target result output by the pre-trained language model is obtained as a result corresponding to the text to be processed.

[0009] The language processing method based on automatic prompt recommendation, wherein the step of obtaining a target prompt text corresponding to the text to be processed according to the text to be processed includes:

[0010] Determining a target language processing task type from a plurality of preset language processing task types according to the text to be processed;

[0011] determining a target prompt text library from a plurality of prompt text libraries according to the target language processing task type, wherein each of the prompt text libraries includes a plurality of prompt texts;

[0012] A prompt text is selected from the target prompt text library as the target prompt text.

[0013] The language processing method based on automatic prompt recommendation, wherein, before obtaining the target prompt text corresponding to the text to be processed according to the text to be processed, includes:

[0014] Acquire multiple sample texts to be processed and the results corresponding to each of the sample texts to be processed, and combine each sample text to be processed and the corresponding results to obtain the prompt text;

[0015] Classifying each of the sample texts to be processed, and determining the preset language processing task type corresponding to each of the sample texts to be processed;

[0016] Each prompt text is classified into the corresponding prompt text library according to the preset language processing task type corresponding to each sample text to be processed.

[0017] The language processing method based on automatic prompt recommendation, wherein the classifying of each sample text to be processed and determining the preset language processing task type corresponding to each sample text to be processed includes:

[0018] Roughly classifying each of the sample texts to be processed according to the question sentences included in each of the sample texts to be processed;

[0019] Clustering is performed on the sample texts to be processed that belong to the same category after rough classification, and each of the preset language processing task types is determined based on the data commonalities of the sample texts to be processed in each category after clustering.

[0020] The language processing method based on automatic prompt recommendation, wherein determining the target language processing task type from a plurality of preset language processing task types according to the text to be processed, includes:

[0021] Calculating the text similarity between the to-be-processed text and each of the prompt texts respectively;

[0022] Inputting the text to be processed into a pre-trained classifier, obtaining the predicted type output by the classifier and the probability corresponding to the predicted type;

[0023] The target language processing task type is determined according to the text similarity between the to-be-processed text and each of the prompt texts and the probability corresponding to the predicted type.

[0024] The language processing method based on automatic prompt recommendation, wherein the step of determining the target language processing task type based on the text similarity between the text to be processed and each of the prompt texts and the probability corresponding to the predicted type, includes:

[0025] If the text similarity between the intermediate prompt text and the text to be processed is higher than a first preset threshold, determining the preset language processing task type corresponding to the intermediate prompt text as the target language processing task type, wherein the intermediate prompt text is the prompt text with the highest text similarity to the text to be processed;

[0026] If the text similarity between the intermediate prompt text and the to-be-processed text is lower than the first preset threshold, determining whether the probability corresponding to the predicted type output by the classifier is higher than a second preset threshold; if so, determining that the predicted type is the target language processing task type;

[0027] If not, determining that the target language processing task type is other types;

[0028] The language processing method based on automatic prompt recommendation, wherein the step of selecting a prompt text from the target prompt text library as the target prompt text, includes:

[0029] Sampling the target prompt text library in at least one sampling method to obtain prompt text corresponding to each sampling method;

[0030] According to the prompt texts corresponding to each sampling method, a prompt text corresponding to one sampling method is determined as the target prompt text.

[0031] The language processing method based on automatic prompt recommendation, wherein the sampling method includes random sampling, similarity sampling, and correlation sampling; sampling in the target prompt text library using at least one sampling method to obtain the prompt text corresponding to each sampling method, includes:

[0032] When random sampling is used for sampling, randomly selecting prompt text from the target prompt text library as the prompt text corresponding to the random sampling method;

[0033] When sampling is performed using a similarity sampling method, a prompt text having the smallest edit distance with the to-be-processed text is selected from the target prompt text library as the prompt text corresponding to the similarity sampling method;

[0034] When sampling is performed using the correlation sampling method, the prompt text with the best overall perplexity after being spliced with the text to be processed is selected from the target prompt text library as the prompt text corresponding to the correlation sampling method.

[0035] The language processing method based on automatic prompt recommendation, wherein the step of determining the prompt text corresponding to one sampling method as the target prompt text from the prompt texts corresponding to each sampling method, includes:

[0036] If the edit distance between the prompt text obtained by sampling using the similarity sampling method and the text to be processed is less than a third preset threshold, the prompt text corresponding to the similarity sampling method is used as the target prompt text;

[0037] If the edit distance between the prompt text sampled by the similarity sampling method and the to-be-processed text is greater than the third preset threshold, then determining whether the perplexity of the concatenation of the prompt text sampled by the correlation sampling method and the to-be-processed text is better than the fourth preset threshold; if so, using the prompt text corresponding to the correlation sampling method as the target prompt text;

[0038] If not, the prompt text corresponding to the random sampling method is used as the target prompt text.

[0039] The language processing method based on automatic prompt recommendation, wherein the combining of the text to be processed and the target prompt text comprises:

[0040] Obtaining a target template according to the target prompt text;

[0041] The to-be-processed text and the target prompt text are combined according to the target template.

[0042] A second aspect of the present invention provides a language processing device based on automatic prompt recommendation, comprising:

[0043] A target prompt text acquisition module is used to acquire a text to be processed, and acquire a target prompt text corresponding to the text to be processed according to the text to be processed, wherein the target prompt text includes a sample text to be processed and a result corresponding to the sample text to be processed;

[0044] A combination module is used to combine the text to be processed and the target prompt text, input them into a pre-trained language model, and obtain the target result output by the pre-trained language model as the result corresponding to the text to be processed.

[0045] In a third aspect of the present invention, a terminal is provided, comprising a processor and a computer-readable storage medium communicatively connected to the processor, wherein the computer-readable storage medium is suitable for storing multiple instructions, and the processor is suitable for calling the instructions in the computer-readable storage medium to execute the steps of implementing any of the above-mentioned language processing methods based on automatic prompt recommendations.

[0046] A fourth aspect of the present invention provides a computer-readable storage medium, which stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of any of the above-mentioned language processing methods based on automatic prompt recommendation.

[0047] Compared with the prior art, the present invention provides a language processing method, device and terminal based on automatic prompt recommendation. The language processing method based on automatic prompt recommendation, after obtaining the text to be processed, determines the target prompt text corresponding to the text to be processed according to the text to be processed, combines the text to be processed and the target prompt text to form a new input text, and then inputs it into a pre-trained language model, and obtains the target result output by the pre-trained language model as the result corresponding to the text to be processed. Since the target prompt text includes the sample text to be processed and the result corresponding to the sample text to be processed, the input text obtained by combining the text to be processed and the target prompt text can guide the pre-trained language model to output better results, thereby improving the accuracy of the pre-trained language model when processing downstream tasks. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 A flowchart of an embodiment of a language processing method based on automatic prompt recommendation provided by the present invention;

[0049] Figure 2 This is an overall framework diagram of an embodiment of the language processing method based on automatic prompt recommendation provided by the present invention;

[0050] Figure 3 A schematic diagram of determining a preset language processing task type corresponding to a text to be processed in an embodiment of the language processing method based on automatic prompt recommendation provided by the present invention;

[0051] Figure 4 A schematic diagram of a target template in an embodiment of the language processing method based on automatic prompt recommendation provided by the present invention;

[0052] Figure 5 A schematic diagram of sampling target prompt text in an embodiment of the language processing method based on automatic prompt recommendation provided by the present invention;

[0053] Figure 6A structural principle diagram of an embodiment of a language processing device based on automatic prompt recommendation provided by the present invention;

[0054] Figure 7 This is a schematic diagram of the principles of an embodiment of a terminal provided by the present invention. DETAILED DESCRIPTION

[0055] In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0056] The language processing method based on automatic prompt recommendation provided by the present invention can be applied to a terminal with computing capabilities. The terminal can execute the language processing method based on automatic prompt recommendation provided by the present invention to process the text to be processed. The terminal can be but is not limited to various computers, mobile terminals, smart home appliances, wearable devices, etc.

[0057] Example 1

[0058] like Figure 1 As shown, in one embodiment of the language processing method based on automatic prompt recommendation, the steps include:

[0059] S100: Acquire a text to be processed, and acquire a target prompt text corresponding to the text to be processed according to the text to be processed, wherein the target prompt text includes a sample text to be processed and a result corresponding to the sample text to be processed.

[0060] The text to be processed is the input of the language processing task, and the purpose of the language processing task is to obtain the result corresponding to the text to be processed. For example, when the language processing task is question-answering, the text to be processed can be a question, and the purpose of the task is to generate an answer that meets the question, and the answer is the result corresponding to the text to be processed. The language processing model pre-trained based on large-scale data can perform a variety of language processing tasks, but the accuracy is not good. In the language processing method based on automatic prompt recommendation provided in this embodiment, in order to improve the accuracy of the results output by the pre-trained language processing model, Figure 2 As shown, the target prompt text corresponding to the text to be processed is first obtained, and the text to be processed and the target prompt text are combined and then input into the pre-trained language processing model.

[0061] The target prompt text includes a sample to be processed text and the result corresponding to the sample to be processed text. Specifically, in this embodiment, multiple prompt texts are prepared in advance, each prompt text includes a sample to be processed text and the result corresponding to the sample to be processed text. The sample to be processed text can be obtained based on user input in a previous language processing task, and the result corresponding to the sample to be processed text is the correct result corresponding to the sample to be processed text, which can be obtained by manual annotation or output by a language processing model based on the input sample to be processed text. One of the multiple prompt texts is selected as the target prompt text based on the to-be-processed text.

[0062] Specifically, obtaining a target prompt text corresponding to the text to be processed according to the text to be processed includes:

[0063] S110, determining a target language processing task type from a plurality of preset language processing task types according to the text to be processed;

[0064] S120, determining a target prompt text library from a plurality of prompt text libraries according to the target language processing task type, wherein each of the prompt text libraries includes a plurality of prompt texts;

[0065] S130: Select a prompt text from the target prompt text library as the target prompt text.

[0066] In this embodiment, the target prompt text corresponding to the text to be processed is determined based on the language processing task type corresponding to the text to be processed. During specific implementation, a plurality of preset language processing task types are predetermined. The preset language processing task type can be determined based on a plurality of sample texts to be processed. Specifically, a plurality of sample texts to be processed can be classified, and the preset language processing task type is determined based on the classification results. A prompt text library can be established for each preset language processing task type, and each prompt text in each prompt text library is consistent with the preset language processing task type corresponding to the prompt text library where the prompt text is located. Specifically, before obtaining the target prompt text corresponding to the text to be processed based on the text to be processed, the following steps are included:

[0067] Acquire multiple sample texts to be processed and the results corresponding to each of the sample texts to be processed, and combine each sample text to be processed and the corresponding results to obtain the prompt text;

[0068] Classifying each of the sample texts to be processed, and determining the preset language processing task type corresponding to each of the sample texts to be processed;

[0069] Each prompt text is classified into the corresponding prompt text library according to the preset language processing task type corresponding to each sample text to be processed.

[0070] The classification of each sample text to be processed and the determination of the preset language processing task type corresponding to each sample text to be processed can be achieved through mining clustering. In one possible implementation, all the sample texts to be processed can be directly clustered, and each clustered category can be used as a preset language processing task type. However, due to the large amount of data of the sample texts to be processed, in order to improve classification efficiency and accuracy, in this embodiment, rough classification is first performed before classification. Specifically, the classification of each sample text to be processed and the determination of the preset language processing task type corresponding to each sample text to be processed include:

[0071] Roughly classifying each of the sample texts to be processed according to the question sentences included in each of the sample texts to be processed;

[0072] Clustering is performed on the sample texts to be processed that belong to the same category after rough classification, and each of the preset language processing task types is determined based on the data commonalities of the sample texts to be processed in each category after clustering.

[0073] Specifically, the sample text to be processed can be roughly classified into question and answer, dialogue and other types. Specifically, it can be performed based on the questions included in the sample text to be processed. For example, when the sample text to be processed is a single question, the sample text to be processed can be classified as a question and answer type. When the sample text to be processed is a plurality of questions and statements appearing in sequence, the sample text to be processed is classified as a dialogue type, otherwise it is classified as other types.

[0074] After the sample texts to be processed are roughly classified, clustering processing is performed on the sample texts to be processed that belong to the same category. Specifically, clustering processing can be performed on the sample texts to be processed that belong to the question-answer type and other types, and no clustering operation is performed on the dialogue type. The K-means clustering algorithm can be used to cluster the sample texts to be processed that belong to the same category after rough classification. Different K values can be selected for different rough classification types. Figure 2As shown, after the clustering process is completed, a type label is assigned to each type of data based on the data commonalities of each type of data. Each type label is a preset language processing task type. In one possible implementation, a clustering operation with K of 2 can be performed for the question-and-answer type, and a clustering operation with K of 7 can be performed for other types. In this way, the question-and-answer type and other types can be subdivided into 2 subcategories and 7 subcategories, respectively. Together with the dialogue type, there are 10 types in total. Labels are assigned based on the data commonalities of the sample texts to be processed included in the 10 types to obtain the preset language processing task types. For example, the 10 preset language processing task types that can be obtained are: knowledge question-and-answer, open question-and-answer, couplets, news, novels, free generation, numerical reasoning, dialogue, poetry, and others.

[0075] After the clustering process is completed, a prompt text library is constructed for each of the preset language processing task types, and the prompt text corresponding to each sample to-be-processed text is stored in the corresponding prompt text library. Thus, after determining the target language processing task type corresponding to the to-be-processed text, the corresponding target prompt text can be selected from the prompt text library corresponding to the target language processing task type. Because the language processing task type corresponding to the target prompt text is consistent with the language processing task type corresponding to the to-be-processed text, the target prompt text can provide guidance for processing the to-be-processed text. Combining the target prompt text with the to-be-processed text and inputting it into the pre-trained language processing model can enable the pre-trained language processing model to output more accurate results.

[0076] Determining a target language processing task type from a plurality of preset language processing task types according to the text to be processed specifically comprises the following steps:

[0077] S111 , respectively calculating the text similarity between the text to be processed and each of the prompt texts.

[0078] The text similarity between the text to be processed and each of the prompt texts can be measured by the text editing distance between the text to be processed and the prompt text. The larger the editing distance, the lower the text similarity. After respectively calculating the text similarity between the text to be processed and each of the prompt texts, the prompt text with the highest text similarity to the text to be processed is determined as the intermediate prompt text. In a possible implementation, the intermediate prompt text can be directly used as the target prompt text. However, text similarity reflects the degree of similarity in terms of literal meaning. In fact, there are many cases where two texts are similar in literal meaning but have different meanings. Therefore, in this embodiment, if Figure 3As shown, a neural network is also combined to determine the target language processing task type corresponding to the text to be processed, that is, determining the target language processing task type from a plurality of preset language processing task types according to the text to be processed, further comprising the steps of:

[0079] S112: inputting the text to be processed into a pre-trained classifier, and obtaining a predicted type output by the classifier and a probability corresponding to the predicted type;

[0080] S113 : Determine the target language processing task type according to the text similarity between the to-be-processed text and each of the prompt texts and the probability corresponding to the predicted type.

[0081] The classifier uses a deep neural network model such as TextCNN, FastText, or BERT. It can be trained using multiple sets of training data, each of which includes sample text and the preset language processing task type corresponding to the sample text. This allows the pre-trained classifier to be fed with a text input, and the classifier to output the probability that the text is of each of the preset language processing task types. The classifier then selects the one with the highest probability as the predicted type. Because deep neural networks can extract semantic features, determining the target language processing task type corresponding to the text to be processed by combining text similarity and the probability corresponding to the predicted type can achieve higher accuracy.

[0082] The determining the target language processing task type according to the text similarity between the to-be-processed text and each of the prompt texts and the probability corresponding to the prediction type includes:

[0083] If the text similarity between the intermediate prompt text and the text to be processed is higher than a first preset threshold, determining the preset language processing task type corresponding to the intermediate prompt text as the target language processing task type;

[0084] If the text similarity between the intermediate prompt text and the to-be-processed text is lower than the first preset threshold, determining whether the probability corresponding to the predicted type output by the classifier is higher than a second preset threshold; if so, determining that the predicted type is the target language processing task type;

[0085] If not, it is determined that the target language processing task type is other types.

[0086] After determining the target language processing task type, the prompt text library corresponding to the target language processing task type can be used as the target prompt text library, and a prompt text is selected from the target prompt text library as the target prompt text. The selecting of a prompt text from the target prompt text library as the target prompt text includes:

[0087] Sampling the target prompt text library in at least one sampling method to obtain prompt text corresponding to each sampling method;

[0088] According to the prompt texts corresponding to each sampling method, a prompt text corresponding to one sampling method is determined as the target prompt text.

[0089] After determining the target prompt text library, any sampling method can be used to sample the target prompt text library to obtain the target prompt text. For example, similarity sampling can be performed based on the similarity between the text to be processed and the text in the target prompt text library, or correlation sampling can be performed based on the correlation between the text to be processed and the text in the target prompt text library. Multiple sampling methods can also be used to perform sampling, and the sampling results of different sampling methods are combined to finally determine the sampling result of one sampling method as the target prompt text. In this embodiment, if Figure 5 As shown, three sampling methods are used for sampling, specifically including: random sampling, similarity sampling and correlation sampling. The sampling is performed in the target prompt text library using at least one sampling method, and the prompt text corresponding to each sampling method is obtained, including:

[0090] When random sampling is used for sampling, randomly selecting prompt text from the target prompt text library as the prompt text corresponding to the random sampling method;

[0091] When sampling is performed using a similarity sampling method, a prompt text having the smallest edit distance with the to-be-processed text is selected from the target prompt text library as the prompt text corresponding to the similarity sampling method;

[0092] When sampling is performed using the correlation sampling method, the prompt text with the best overall perplexity after being spliced with the text to be processed is selected from the target prompt text library as the prompt text corresponding to the correlation sampling method.

[0093] After sampling using various sampling methods, determining which sampling method to use based on the sampling results of each sampling method. Specifically, determining the prompt text corresponding to one sampling method as the target prompt text from the prompt texts corresponding to each sampling method includes:

[0094] If the edit distance between the prompt text obtained by sampling using the similarity sampling method and the text to be processed is less than a third preset threshold, the prompt text corresponding to the similarity sampling method is used as the target prompt text;

[0095] If the edit distance between the prompt text sampled by the similarity sampling method and the to-be-processed text is greater than the third preset threshold, then determining whether the perplexity of the concatenation of the prompt text sampled by the correlation sampling method and the to-be-processed text is better than the fourth preset threshold; if so, using the prompt text corresponding to the correlation sampling method as the target prompt text;

[0096] If not, the prompt text corresponding to the random sampling method is used as the target prompt text.

[0097] Please refer again Figure 1 The language processing method based on automatic prompt recommendation provided in this embodiment further includes the following steps after determining the target prompt text:

[0098] S200: Combine the text to be processed and the target prompt text, input the result to a pre-trained language model, and obtain a target result output by the pre-trained language model as a result corresponding to the text to be processed.

[0099] Combining the text to be processed and the target prompt text may be directly splicing the text to be processed and the target prompt text. In one possible implementation, in order to achieve a better guidance effect, different templates are further set for different preset language processing task types. Combining the text to be processed and the target prompt text includes the following steps:

[0100] Obtaining a target template according to the target prompt text;

[0101] The to-be-processed text and the target prompt text are combined according to the target template.

[0102] Different templates can be set for different preset language processing task types. Each prompt text library can be recorded as: {task; Prompt; prompt text}, where task represents the preset language processing task type corresponding to the prompt text library, Prompt represents the template corresponding to the prompt text library, and prompt text represents all prompt texts in the prompt text library. Figure 4 As shown in the figure, the template consists of three parts: the text to be processed, the target prompt text and the prompt word. Figure 4The light-colored words in the target prompt text are prompt words, which are used to distinguish the sample text to be processed and the result corresponding to the sample text to be processed. When the target language processing task type is determined, the template corresponding to the target language processing task type is used as the target template. Figure 2 As shown, after the text to be processed and the target prompt text are combined according to the target template, they are input into the pre-trained language processing model for reasoning, and the pre-trained language processing model outputs a text as the result corresponding to the text to be processed.

[0103] In summary, this embodiment provides a language processing method based on automatic prompt recommendation. After obtaining the text to be processed, the target prompt text corresponding to the text to be processed is determined according to the text to be processed, the text to be processed and the target prompt text are combined to form a new input text, which is then input into the pre-trained language model, and the target result output by the pre-trained language model is obtained as the result corresponding to the text to be processed. Since the target prompt text includes the sample text to be processed and the result corresponding to the sample text to be processed, the input text obtained by combining the text to be processed and the target prompt text can guide the pre-trained language model to output better results, thereby improving the accuracy of the pre-trained language model in processing downstream tasks.

[0104] It should be understood that, although the steps in the flowcharts provided in the accompanying drawings of the present invention are shown in sequence as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps may be performed in other orders. Moreover, at least a portion of the steps in the flowcharts may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily performed at the same time, but may be performed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but may be performed in rotation or alternation with other steps or at least a portion of sub-steps or stages of other steps.

[0105] Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0106] Example 2

[0107] Based on the above embodiment, the present invention also provides a language processing device based on automatic prompt recommendation, such as Figure 6 As shown, the device includes:

[0108] A target prompt text acquisition module, the target prompt text acquisition module is used to acquire a text to be processed, and acquire a target prompt text corresponding to the text to be processed according to the text to be processed, wherein the target prompt text includes a sample text to be processed and a result corresponding to the sample text to be processed, as described in the first embodiment;

[0109] A combination module is used to combine the text to be processed and the target prompt text, input them into a pre-trained language model, and obtain the target result output by the pre-trained language model as the result corresponding to the text to be processed, as specifically described in Example 1.

[0110] Example 3

[0111] Based on the above embodiments, the present invention also provides a terminal, such as Figure 7 As shown, the terminal includes a processor 10 and a memory 20. Figure 7Only some of the components of the terminal are shown, but it should be understood that implementation of all of the shown components is not required, and more or fewer components may be implemented instead.

[0112] In some embodiments, the memory 20 may be an internal storage unit of the terminal, such as a hard disk or memory of the terminal. In other embodiments, the memory 20 may also be an external storage device of the terminal, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the terminal. Furthermore, the memory 20 may also include both an internal storage unit of the terminal and an external storage device. The memory 20 is used to store application software and various types of data installed on the terminal. The memory 20 may also be used to temporarily store data that has been output or is to be output. In one embodiment, a language processing program 30 based on automatic prompt recommendation is stored on the memory 20, and the language processing program 30 based on automatic prompt recommendation can be executed by the processor 10, thereby realizing the language processing method based on automatic prompt recommendation in the present application.

[0113] In some embodiments, the processor 10 may be a central processing unit (CPU), a microprocessor, or other chip, configured to execute program codes or process data stored in the memory 20, such as executing the language processing method based on automatic prompt recommendation.

[0114] In one embodiment, when the processor 10 executes the language processing program 30 based on automatic prompt recommendation in the memory 20, the following steps are implemented:

[0115] Acquire a text to be processed, and acquire a target prompt text corresponding to the text to be processed according to the text to be processed, wherein the target prompt text includes a sample text to be processed and a result corresponding to the sample text to be processed;

[0116] The text to be processed and the target prompt text are combined and input into a pre-trained language model, and a target result output by the pre-trained language model is obtained as a result corresponding to the text to be processed.

[0117] Wherein, obtaining the target prompt text corresponding to the text to be processed according to the text to be processed includes:

[0118] Determining a target language processing task type from a plurality of preset language processing task types according to the text to be processed;

[0119] determining a target prompt text library from a plurality of prompt text libraries according to the target language processing task type, wherein each of the prompt text libraries includes a plurality of prompt texts;

[0120] A prompt text is selected from the target prompt text library as the target prompt text.

[0121] Wherein, before obtaining the target prompt text corresponding to the text to be processed according to the text to be processed, the method includes:

[0122] Acquire multiple sample texts to be processed and the results corresponding to each of the sample texts to be processed, and combine each sample text to be processed and the corresponding results to obtain the prompt text;

[0123] Classifying each of the sample texts to be processed, and determining the preset language processing task type corresponding to each of the sample texts to be processed;

[0124] Each prompt text is classified into the corresponding prompt text library according to the preset language processing task type corresponding to each sample text to be processed.

[0125] The step of classifying each of the sample texts to be processed and determining the preset language processing task type corresponding to each of the sample texts to be processed includes:

[0126] Roughly classifying each of the sample texts to be processed according to the question sentences included in each of the sample texts to be processed;

[0127] Clustering is performed on the sample texts to be processed that belong to the same category after rough classification, and each of the preset language processing task types is determined based on the data commonalities of the sample texts to be processed in each category after clustering.

[0128] The step of determining a target language processing task type from a plurality of preset language processing task types according to the text to be processed includes:

[0129] Calculating the text similarity between the to-be-processed text and each of the prompt texts respectively;

[0130] Inputting the text to be processed into a pre-trained classifier, obtaining the predicted type output by the classifier and the probability corresponding to the predicted type;

[0131] The target language processing task type is determined according to the text similarity between the to-be-processed text and each of the prompt texts and the probability corresponding to the predicted type.

[0132] The step of determining the target language processing task type according to the text similarity between the to-be-processed text and each of the prompt texts and the probability corresponding to the prediction type includes:

[0133] If the text similarity between the intermediate prompt text and the text to be processed is higher than a first preset threshold, determining the preset language processing task type corresponding to the intermediate prompt text as the target language processing task type, wherein the intermediate prompt text is the prompt text with the highest text similarity to the text to be processed;

[0134] If the text similarity between the intermediate prompt text and the to-be-processed text is lower than the first preset threshold, determining whether the probability corresponding to the predicted type output by the classifier is higher than a second preset threshold; if so, determining that the predicted type is the target language processing task type;

[0135] If not, determining that the target language processing task type is other types;

[0136] The step of selecting a prompt text from the target prompt text library as the target prompt text includes:

[0137] Sampling the target prompt text library in at least one sampling method to obtain prompt text corresponding to each sampling method;

[0138] According to the prompt texts corresponding to each sampling method, a prompt text corresponding to one sampling method is determined as the target prompt text.

[0139] The sampling methods include random sampling, similarity sampling, and correlation sampling; sampling the target prompt text library using at least one sampling method to obtain prompt text corresponding to each sampling method includes:

[0140] When random sampling is used for sampling, randomly selecting prompt text from the target prompt text library as the prompt text corresponding to the random sampling method;

[0141] When sampling is performed using a similarity sampling method, a prompt text having the smallest edit distance with the to-be-processed text is selected from the target prompt text library as the prompt text corresponding to the similarity sampling method;

[0142] When sampling is performed using the correlation sampling method, the prompt text with the best overall perplexity after being spliced with the text to be processed is selected from the target prompt text library as the prompt text corresponding to the correlation sampling method.

[0143] The step of determining the prompt text corresponding to one sampling method as the target prompt text from the prompt texts corresponding to each sampling method includes:

[0144] If the edit distance between the prompt text obtained by sampling using the similarity sampling method and the text to be processed is less than a third preset threshold, the prompt text corresponding to the similarity sampling method is used as the target prompt text;

[0145] If the edit distance between the prompt text sampled by the similarity sampling method and the to-be-processed text is greater than the third preset threshold, then determining whether the perplexity of the concatenation of the prompt text sampled by the correlation sampling method and the to-be-processed text is better than the fourth preset threshold; if so, using the prompt text corresponding to the correlation sampling method as the target prompt text;

[0146] If not, the prompt text corresponding to the random sampling method is used as the target prompt text.

[0147] The combining of the to-be-processed text and the target prompt text includes:

[0148] Obtaining a target template according to the target prompt text;

[0149] The to-be-processed text and the target prompt text are combined according to the target template.

[0150] Example 4

[0151] The present invention also provides a computer-readable storage medium, which stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the language processing method based on automatic prompt recommendation as described above.

[0152] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims

1. A language processing method based on automatic prompt recommendation, characterized in that: The method comprises: Acquire a text to be processed, and acquire a target prompt text corresponding to the text to be processed according to the text to be processed, wherein the target prompt text includes a sample text to be processed and a result corresponding to the sample text to be processed; Combining the text to be processed and the target prompt text, inputting the results into a pre-trained language model, and obtaining a target result output by the pre-trained language model as a result corresponding to the text to be processed; The step of obtaining a target prompt text corresponding to the text to be processed according to the text to be processed includes: Determining a target language processing task type from a plurality of preset language processing task types according to the text to be processed; determining a target prompt text library from a plurality of prompt text libraries according to the target language processing task type, wherein each of the prompt text libraries includes a plurality of prompt texts; Selecting a prompt text from the target prompt text library as the target prompt text; Before obtaining the target prompt text corresponding to the text to be processed according to the text to be processed, the method includes: Acquire multiple sample texts to be processed and the results corresponding to each of the sample texts to be processed, and combine each sample text to be processed and the corresponding results to obtain the prompt text; Classifying each of the sample texts to be processed, and determining the preset language processing task type corresponding to each of the sample texts to be processed; Classifying each of the prompt texts into the corresponding prompt text library according to the preset language processing task type corresponding to each of the sample texts to be processed; The classifying each of the sample texts to be processed and determining the preset language processing task type corresponding to each of the sample texts to be processed includes: Roughly classifying each of the sample texts to be processed according to the question sentences included in each of the sample texts to be processed; performing clustering processing on the sample texts to be processed that belong to the same category after rough classification, and determining each of the preset language processing task types based on the data commonalities of the sample texts to be processed in each category after clustering; The sample texts to be processed are roughly classified into question-answer, dialogue, and other types; when the sample text to be processed is a single question, the sample text to be processed is classified as the question-answer type; when the sample text to be processed is a plurality of questions and statements appearing in sequence, the sample text to be processed is classified as the dialogue type; otherwise, the sample text to be processed is classified as other types; clustering processing is performed on the sample texts to be processed belonging to the question-answer type and the other types, and no clustering operation is performed on the dialogue type; clustering processing is performed on the sample texts to be processed that belong to the same type after rough classification using a K-means clustering algorithm, performing a clustering operation with K of 2 for the question-answer type and a clustering operation with K of 7 for the other types; Determining a target language processing task type from a plurality of preset language processing task types according to the text to be processed includes: Calculating the text similarity between the to-be-processed text and each of the prompt texts respectively; Inputting the text to be processed into a pre-trained classifier, obtaining the predicted type output by the classifier and the probability corresponding to the predicted type; Determining the target language processing task type according to the text similarity between the to-be-processed text and each of the prompt texts and the probability corresponding to the prediction type; The text similarity is measured by the text edit distance between the text to be processed and the prompt text. The larger the edit distance, the lower the text similarity. The determining the target language processing task type according to the text similarity between the to-be-processed text and each of the prompt texts and the probability corresponding to the prediction type includes: If the text similarity between the intermediate prompt text and the text to be processed is higher than a first preset threshold, determining the preset language processing task type corresponding to the intermediate prompt text as the target language processing task type, wherein the intermediate prompt text is the prompt text with the highest text similarity to the text to be processed; If the text similarity between the intermediate prompt text and the to-be-processed text is lower than the first preset threshold, determining whether the probability corresponding to the predicted type output by the classifier is higher than a second preset threshold; if so, determining that the predicted type is the target language processing task type; If not, determining that the target language processing task type is other types; The classifier is trained using multiple sets of training data, each set of training data including sample text and the preset language processing task type corresponding to the sample text.

2. The language processing method based on automatic suggestion recommendation according to claim 1, characterized in that: The step of selecting a prompt text from the target prompt text library as the target prompt text comprises: Sampling the target prompt text library in at least one sampling method to obtain prompt text corresponding to each sampling method; According to the prompt texts corresponding to each sampling method, a prompt text corresponding to one sampling method is determined as the target prompt text.

3. The language processing method based on automatic suggestion recommendation according to claim 2, characterized in that: The sampling methods include random sampling, similarity sampling and correlation sampling; The sampling in the target prompt text library using at least one sampling method to obtain prompt text corresponding to each sampling method includes: When random sampling is used for sampling, randomly selecting prompt text from the target prompt text library as the prompt text corresponding to the random sampling method; When sampling is performed using a similarity sampling method, a prompt text having the smallest edit distance with the to-be-processed text is selected from the target prompt text library as the prompt text corresponding to the similarity sampling method; When sampling is performed using the correlation sampling method, the prompt text with the best overall perplexity after being spliced with the text to be processed is selected from the target prompt text library as the prompt text corresponding to the correlation sampling method.

4. The language processing method based on automatic suggestion recommendation according to claim 2, characterized in that: The step of determining a prompt text corresponding to one sampling method from the prompt texts corresponding to each sampling method as the target prompt text includes: If the edit distance between the prompt text obtained by sampling using the similarity sampling method and the text to be processed is less than a third preset threshold, the prompt text corresponding to the similarity sampling method is used as the target prompt text; If the edit distance between the prompt text sampled by the similarity sampling method and the to-be-processed text is greater than the third preset threshold, then determining whether the perplexity of the concatenation of the prompt text sampled by the correlation sampling method and the to-be-processed text is better than the fourth preset threshold; if so, using the prompt text corresponding to the correlation sampling method as the target prompt text; If not, the prompt text corresponding to the random sampling method is used as the target prompt text.

5. The language processing method based on automatic suggestion recommendation according to claim 1, characterized in that: The combining of the to-be-processed text and the target prompt text includes: Obtaining a target template according to the target prompt text; The to-be-processed text and the target prompt text are combined according to the target template.

6. A language processing device based on automatic prompt recommendation, characterized in that: include: A target prompt text acquisition module is used to acquire a text to be processed, and acquire a target prompt text corresponding to the text to be processed according to the text to be processed, wherein the target prompt text includes a sample text to be processed and a result corresponding to the sample text to be processed; A combining module, configured to combine the text to be processed and the target prompt text, input the combined text into a pre-trained language model, and obtain a target result output by the pre-trained language model as a result corresponding to the text to be processed; The step of obtaining a target prompt text corresponding to the text to be processed according to the text to be processed includes: Determining a target language processing task type from a plurality of preset language processing task types according to the text to be processed; determining a target prompt text library from a plurality of prompt text libraries according to the target language processing task type, wherein each of the prompt text libraries includes a plurality of prompt texts; Selecting a prompt text from the target prompt text library as the target prompt text; Before obtaining the target prompt text corresponding to the text to be processed according to the text to be processed, the method includes: Acquire multiple sample texts to be processed and the results corresponding to each of the sample texts to be processed, and combine each sample text to be processed and the corresponding results to obtain the prompt text; Classifying each of the sample texts to be processed, and determining the preset language processing task type corresponding to each of the sample texts to be processed; Classifying each of the prompt texts into the corresponding prompt text library according to the preset language processing task type corresponding to each of the sample texts to be processed; The classifying each of the sample texts to be processed and determining the preset language processing task type corresponding to each of the sample texts to be processed includes: Roughly classifying each of the sample texts to be processed according to the question sentences included in each of the sample texts to be processed; performing clustering processing on the sample texts to be processed that belong to the same category after rough classification, and determining each of the preset language processing task types based on the data commonalities of the sample texts to be processed in each category after clustering; The sample texts to be processed are roughly classified into question-answer, dialogue, and other types; when the sample text to be processed is a single question, the sample text to be processed is classified as the question-answer type; when the sample text to be processed is a plurality of questions and statements appearing in sequence, the sample text to be processed is classified as the dialogue type; otherwise, the sample text to be processed is classified as other types; clustering processing is performed on the sample texts to be processed belonging to the question-answer type and the other types, and no clustering operation is performed on the dialogue type; clustering processing is performed on the sample texts to be processed that belong to the same type after rough classification using a K-means clustering algorithm, performing a clustering operation with K of 2 for the question-answer type and a clustering operation with K of 7 for the other types; Determining a target language processing task type from a plurality of preset language processing task types according to the text to be processed includes: Calculating the text similarity between the to-be-processed text and each of the prompt texts respectively; Inputting the text to be processed into a pre-trained classifier, obtaining the predicted type output by the classifier and the probability corresponding to the predicted type; Determining the target language processing task type according to the text similarity between the to-be-processed text and each of the prompt texts and the probability corresponding to the prediction type; The text similarity is measured by the text edit distance between the text to be processed and the prompt text. The larger the edit distance, the lower the text similarity. The determining the target language processing task type according to the text similarity between the to-be-processed text and each of the prompt texts and the probability corresponding to the prediction type includes: If the text similarity between the intermediate prompt text and the text to be processed is higher than a first preset threshold, determining the preset language processing task type corresponding to the intermediate prompt text as the target language processing task type, wherein the intermediate prompt text is the prompt text with the highest text similarity to the text to be processed; If the text similarity between the intermediate prompt text and the to-be-processed text is lower than the first preset threshold, determining whether the probability corresponding to the predicted type output by the classifier is higher than a second preset threshold; if so, determining that the predicted type is the target language processing task type; If not, determining that the target language processing task type is other types; The classifier is trained using multiple sets of training data, each set of training data including sample text and the preset language processing task type corresponding to the sample text.

7. A terminal, characterized in that: The terminal includes: a processor, a computer-readable storage medium communicatively connected to the processor, the computer-readable storage medium being suitable for storing a plurality of instructions, and the processor being suitable for calling the instructions in the computer-readable storage medium to execute the steps of the language processing method based on automatic prompt recommendation as described in any one of claims 1 to 5 above.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the language processing method based on automatic prompt recommendation according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Interactive output method for robot

    CN106874406A

  • Intelligent dialogue method, robot dialogue system, server and storage medium

    CN109885664A