Method and device for extracting prompt context prompt

By constructing a training data set and using TF-IDF and BERTScore algorithms to screen out erroneous samples, and combining it with the LM Head component of the large model to output the vocabulary probability matrix, the problem of automated sample screening in the large model Few-shot prompt technology is solved and the accuracy is improved. and efficiency, improving the recognition accuracy.

CN118428351BActive Publication Date: 2024-09-10BEIJING HUIMEI CLOUD TECHNOLOGY CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410877470.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-02
Publication Date
2024-09-10
Estimated Expiration
2044-07-02

AI Technical Summary

Technical Problem

In the few-shot prompt technology of existing large models, the process of selecting and screening few-shot examples lacks automation, resulting in low accuracy and efficiency, reliance on manual operations, and the presence of many human factors.

Method used

By obtaining sample data containing question text data and answer text data, construct a training data set and call a large model to obtain sample prediction results, use TF-IDF and BERTScore algorithms to calculate the similarity between error samples and examples, and filter out the ones with the lowest similarity The erroneous sample data is corrected through the LM Head component of the large model to output the vocabulary probability matrix to optimize the screening process of few-shot examples.

Benefits of technology

It realizes automated screening of few-shot examples, improves the accuracy and efficiency of screening, reduces the number of erroneous samples, and improves the effect of prompts and recognition accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118428351B
    Figure CN118428351B
Patent Text Reader

Abstract

The present invention relates to a method and device for extracting prompt context prompts, the method comprising: obtaining sample data, constructing a training data set and a verification data set based on the sample data, and using an input instruction to call a large model to obtain a sample prediction result of the sample data. When the prompt dialog example list is an empty list, the input instruction is used to call the large model to predict the training sample result. And when the prompt dialog example list is a non-empty list, the splicing instruction is used to call the large model to predict the training sample result, and filter out the incorrect sample data that is not predicted correctly in the training sample result, and the splicing instruction is obtained by splicing the prompt dialog example and the input instruction. Traverse the prompt dialog example list, and call a similarity algorithm to calculate the similarity between the incorrect sample data and the prompt dialog example to obtain a prompt prompt sample, and the prompt prompt sample is the incorrect sample data with the lowest similarity.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of large model application, and in particular to a method and device for extracting prompt context hints. Background Art

[0002] The basic idea of ​​using the big model in the few-shot prompt is to provide the big model with a small amount of labeled example data. These example data are called "few-shot prompts". Their role is to provide the model with a preliminary understanding of the task and input-output mapping to guide the output of the big model and improve the effect of the recognition task.

[0003] At present, there are some problems in the application of "Few-shot" prompt technology for large models. For example, how to select better few-shot (example data) as prompt? Generally speaking, this problem is usually solved by manually screening few-shot examples, which is difficult to achieve automatic extraction. There are many human factors, which to some extent affect the accuracy and efficiency of screening few-shot examples. Summary of the invention

[0004] Based on this, it is necessary to provide a method and device for extracting prompt context hints that can automatically screen few-shot examples with high accuracy and efficiency in response to the above technical problems.

[0005] In a first aspect, the present invention provides a method for extracting a prompt context prompt, the method comprising:

[0006] Obtain sample data including multiple sets of question text data and answer text data, construct a training data set and a verification data set based on the sample data, and use input instructions to call a large model to obtain sample prediction results of the sample data;

[0007] Determining whether the prompt dialog box example list is an empty list according to the sample prediction result, and when the prompt dialog box example list is an empty list, using the input instruction to call the large model to predict the training sample result; and

[0008] When the prompt dialog example list is a non-empty list, a splicing instruction is used to call the large model to predict the training sample results, and to filter out incorrect sample data that is not predicted correctly in the training sample results, wherein the splicing instruction is obtained by splicing the prompt dialog instruction and the input instruction;

[0009] Traversing the prompt dialog example list, and calling a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example, to obtain a prompt prompt sample, wherein the prompt prompt sample is the error sample data with the lowest similarity;

[0010] Among them, in the initial state, the prompt dialog example list in the sample data is an empty list, the similarity algorithm is composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm, and the prompt dialog instruction is a few-shot context prompt dialog instruction.

[0011] Furthermore, when the example list in the prompt dialog box is a non-empty list, the large model is called using a splicing instruction to predict the training sample results, and the incorrect sample data that is not predicted correctly in the training sample results is screened out, including:

[0012] Calling the concatenated instruction consisting of the prompt instruction and the input instruction to call the large model to process the sample data in the training data set to obtain a training sample result set consisting of the training sample results;

[0013] The error sample data in the training sample result is screened out from the training sample result set, and the error sample data is added to an error array, wherein the error array contains a plurality of the error sample data.

[0014] Further, traversing the prompt dialog example list and calling a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt prompt sample includes:

[0015] Traversing the prompt dialog example list, and calling the similarity algorithm composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm to sequentially calculate the TF-IDF score and the BERTScore score between each error sample data in the error array and all prompt sample examples in the prompt dialog example list, to obtain a score value corresponding to the similarity;

[0016] The score value corresponding to the similarity is the sum of the TF-IDF score and the BERTScore score.

[0017] Further, the traversing the prompt dialog example list and calling a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt prompt sample also includes:

[0018] Obtaining the score value corresponding to the similarity between each error sample data and all prompt sample examples in the prompt dialog example list, and selecting the error sample data corresponding to the similarity with the smallest score value;

[0019] Based on the error sample data corresponding to the similarity with the smallest score value, all prompt prompt samples corresponding to the error sample data in the error array are obtained to construct a similarity score set of all prompt prompt samples.

[0020] Further, the example list of prompt dialog boxes is traversed, and a similarity algorithm is called to calculate the similarity between the error sample data and the example of prompt dialog boxes to obtain prompt samples, and then the following steps are included:

[0021] Selecting the similarity with the lowest score value from the similarity score set to determine the target error sample data with the lowest similarity score;

[0022] The target error sample data is used as the input of the large model to call the LM Head component of the large model to output the vocabulary probability matrix corresponding to the target error sample data.

[0023] Furthermore, the method further comprises:

[0024] Acquire the correct text data and authentication information corresponding to the target error sample data, and vectorize the correct text data and authentication information through a tokenizer to obtain a vector corresponding to the index position of the correct text data and authentication information;

[0025] According to the vector corresponding to the index position of the correct text data and its authentication information, the probability list of the index position is obtained from the vocabulary probability matrix of the large model, and the probabilities of all correct text data are accumulated in combination with the vocabulary probability matrix corresponding to the target error sample data to obtain the probability value of the index position.

[0026] Furthermore, the method further comprises:

[0027] Based on the probability value of the index position, the target error sample data corresponding to the index position with the lowest probability value is obtained, and the correct text data and the corresponding example text data in the prompt dialog example list are added to the sample data to correct the target error sample data.

[0028] In a second aspect, the present invention provides a device for extracting a prompt context prompt, the device comprising:

[0029] A data set construction module, used to obtain sample data including multiple sets of question text data and answer text data, and to construct a training data set and a verification data set based on the sample data, and to use input instructions to call a large model to obtain sample prediction results of the sample data;

[0030] An instruction calling module, used to determine whether the prompt dialog example list is an empty list according to the sample prediction result, and when the prompt dialog example list is an empty list, use the input instruction to call the large model to predict the training sample result; and

[0031] An instruction splicing module, used for, when the prompt dialog example list is a non-empty list, using a splicing instruction to call the large model to predict the training sample results, and screening out incorrect sample data that is not predicted correctly in the training sample results, wherein the splicing instruction is obtained by splicing the prompt dialog instruction with the input instruction;

[0032] A sample extraction module, used to traverse the prompt dialog example list and call a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt sample, wherein the prompt sample is the error sample data with the lowest similarity;

[0033] Among them, in the initial state, the prompt dialog example list in the sample data is an empty list, the similarity algorithm is composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm, and the prompt dialog instruction is a few-shot context prompt dialog instruction.

[0034] In a third aspect, the present invention further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method for extracting prompt context prompts as described in any one of the above is implemented.

[0035] In a fourth aspect, the present invention further provides a computer storage medium storing a computer program, wherein when the computer program is executed by a processor, the method for extracting prompt context hints as described in any one of the above is implemented.

[0036] The method and device for extracting prompt context prompts are obtained by obtaining sample data containing multiple groups of question text data and answer text data, constructing a training data set and a verification data set based on the sample data, and using an input instruction to call a large model to obtain a sample prediction result of the sample data. Subsequently, it is determined whether the prompt dialog example list is an empty list according to the sample prediction result, and when the prompt dialog example list is an empty list, the input instruction is used to call the large model to predict the training sample result, and when the prompt dialog example list is a non-empty list, the splicing instruction is used to call the large model to predict the training sample result, and the incorrect sample data that is not predicted correctly in the training sample result is filtered out. Finally, the prompt dialog example list is traversed, and a similarity algorithm is called to calculate the similarity between the incorrect sample data and the prompt dialog example to obtain the incorrect sample data with the lowest similarity, that is, the prompt prompt sample. When this method uses few-shot prompt optimization, it randomly selects some training sample inputs and outputs to construct few-shot examples as prompts. In order to avoid these randomly selected samples not being able to give the best prompt effect to the large model, the recognition accuracy of the rules is improved in a targeted manner, the samples with incorrect recognition are solved, and the number of incorrect samples is continuously reduced to improve the prompt effect. The automation of few-shot example screening is realized, and the screening accuracy and efficiency are high. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0038] Figure 1 A schematic diagram of a method for extracting prompt context hints provided by the present invention;

[0039] Figure 2 A schematic diagram of the Boostingprompt process of the method for extracting prompt context prompts in a specific embodiment provided by the present invention;

[0040] Figure 3 A schematic diagram of an example process of calculating bert_score of a method for extracting prompt context prompts in a specific embodiment of the present invention;

[0041] Figure 4 A schematic diagram of the max_similar_score calculation process of the method for extracting prompt context prompts in a specific embodiment provided by the present invention;

[0042] Figure 5 A flow chart of the probability of correct answer of a large model in the method of extracting prompt context hints in a specific embodiment provided by the present invention;

[0043] Figure 6 A schematic diagram of the structure of a device for extracting prompt context hints provided by the present invention;

[0044] Figure 7 This is a diagram of the internal structure of the computer device provided by the present invention. DETAILED DESCRIPTION

[0045] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0046] Combine the following Figure 1-Figure 7 The present invention describes a method and device for extracting prompt context hints.

[0047] like Figure 1 As shown, in one embodiment, a method for extracting prompt context prompts includes the following steps:

[0048] Step S110, obtaining sample data including multiple groups of question text data and answer text data, constructing a training data set and a verification data set based on the sample data, and using input instructions to call a large model to obtain sample prediction results of the sample data.

[0049] Specifically, the server obtains sample data including multiple sets of question text data and answer text data, constructs a training data set and a verification data set based on the sample data, and uses input instructions to call the large model to obtain sample prediction results of the sample data.

[0050] Step S120, judging whether the prompt dialog example list is an empty list according to the sample prediction result, and when the prompt dialog example list is an empty list, using the input instruction to call the large model to predict the training sample result.

[0051] Specifically, the server determines whether the prompt dialog example list is an empty list according to the sample prediction result obtained in step S110, and when the prompt dialog example list is an empty list, uses the input instruction to call the large model to predict the training sample result.

[0052] Step S130, when the prompt dialog example list is a non-empty list, use the splicing instruction to call the large model to predict the training sample results, and filter out the incorrect sample data that is not predicted correctly in the training sample results. The splicing instruction is obtained by splicing the prompt dialog instruction and the input instruction.

[0053] Specifically, when the prompt dialog example list is a non-empty list, the server uses a splicing instruction to call the large model to predict the training sample results, and screens out the incorrect sample data that is not predicted correctly in the training sample results. The splicing instruction is obtained by splicing the prompt dialog instruction and the input instruction. The prompt dialog instruction is a few-shot context prompt dialog instruction.

[0054] In one embodiment, the method for extracting prompt context prompts provided by the present invention, when the prompt dialog example list is a non-empty list, uses a splicing instruction to call a large model to predict training sample results, and filters out incorrect sample data that is not predicted correctly in the training sample results, specifically comprising the following steps:

[0055] Step S131, calling the concatenated instruction consisting of the prompt instruction and the input instruction to call the large model to process the sample data in the training data set to obtain a training sample result set consisting of the training sample results.

[0056] Step S132, filter out erroneous sample data in the training sample results from the training sample result set, and add the erroneous sample data to an error array, wherein the error array contains a plurality of erroneous sample data.

[0057] Step S140, traverse the prompt dialog example list, and call a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt sample, where the prompt sample is the error sample data with the lowest similarity.

[0058] Specifically, the server traverses the prompt dialog example list and calls a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt sample, which is the error sample data with the lowest similarity.

[0059] Among them, the prompt dialog example list in the sample data in the initial state is an empty list, and the similarity algorithm is composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm.

[0060] It should be noted that TF-IDF, the full name of which is Term Frequency-Inverse Document Frequency, is a statistical method commonly used in information retrieval and text mining to evaluate the importance of a term to a document collection (or corpus). It combines two key concepts:

[0061] Term Frequency (TF): Term frequency, which indicates the number of times a term appears in a document. The higher the TF of a term, the more important it is in the document.

[0062] Inverse Document Frequency (IDF): Inverse document frequency measures the prevalence of a word in the entire document collection. If a word appears in many documents, its IDF value is low, indicating that it is not very unique; conversely, if a word appears in only a few documents, its IDF value is high, indicating that it is more distinctive.

[0063] BERTScore is a sentence-level similarity evaluation method based on pre-trained Transformer models (such as BERT). It evaluates the semantic similarity of two sentences by calculating the cosine similarity of two sentences in the internal embedding space of the BERT model. Compared with traditional N-gram or edit distance methods, BERTScore takes advantage of the deep learning model's advantages in natural language understanding and can better capture the semantic association at the sentence level.

[0064] In one embodiment, the method for extracting prompt context prompts provided by the present invention traverses the prompt dialog example list and calls a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain the prompt prompt sample, specifically comprising the following steps:

[0065] Step S141, traverse the prompt dialog example list, and call the similarity algorithm composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm to sequentially calculate the TF-IDF score and BERTScore score between each error sample data in the error array and all prompt sample examples in the prompt dialog example list, and obtain the score value corresponding to the similarity.

[0066] Among them, the score corresponding to the similarity is the sum of the TF-IDF score and the BERTScore score.

[0067] Step S142, obtaining the score value corresponding to the similarity between each error sample data and all prompt sample examples in the prompt dialog example list, and selecting the error sample data corresponding to the similarity with the smallest score value.

[0068] Step S143, based on the error sample data corresponding to the similarity with the smallest score value, all prompt samples corresponding to the error sample data in the error array are obtained to construct a similarity score set of all prompt samples.

[0069] In some embodiments, the method for extracting prompt context prompts provided by the present invention traverses the prompt dialog example list and calls a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt prompt sample, and then includes the following steps:

[0070] Step S210 , selecting the similarity with the lowest score value from the similarity score set to determine the target error sample data with the lowest similarity score.

[0071] Step S220: taking the target error sample data as the input of the large model, so as to call the LM Head component of the large model to output the vocabulary probability matrix corresponding to the target error sample data.

[0072] Among them, LM Head (Language Model Head) usually refers to a specific component in the architecture of a natural language processing model that is used to generate or predict text. It is usually located on top of a pre-trained language model (such as BERT, GPT, etc.) and is used to convert the hidden state of the model into a predictable output, such as a word or character sequence. The design goal of LM Head is to enable the model to understand the language and generate natural language text based on the context, and to complete various types of natural language tasks such as text classification, question answering, machine translation, etc. by generating natural language text.

[0073] In some embodiments, the method for extracting prompt context hints provided by the present invention further includes the following steps:

[0074] Step S310, obtaining the correct text data and authentication information corresponding to the target error sample data, and vectorizing the correct text data and authentication information through a tokenizer to obtain a vector corresponding to the index position of the correct text data and authentication information.

[0075] Among them, Tokenizer is a class used to vectorize text and convert text into a sequence. When computers process language and text, they cannot understand the meaning of the text. Usually, they convert a word (a single Chinese character or word) into a positive integer, turning a text into a sequence, and then vectorize the sequence. The vectorized data is sent to the model for processing.

[0076] Step S320, obtain the probability list of the index position from the vocabulary probability matrix of the large model according to the vector corresponding to the index position of the correct text data and its authentication information, and accumulate the probabilities of all correct text data in combination with the vocabulary probability matrix corresponding to the target error sample data to obtain the probability value of the index position.

[0077] Step S330, based on the probability values ​​of the index positions, obtain the target error sample data corresponding to the index position with the lowest probability value, and add the correct text data and the corresponding sample text data in the prompt dialog example list to the sample data for correcting the target error sample data.

[0078] The method for extracting prompt context prompts is to obtain sample data containing multiple sets of question text data and answer text data, construct a training data set and a verification data set based on the sample data, and use an input instruction to call a large model to obtain a sample prediction result of the sample data. Subsequently, it is determined whether the prompt dialog example list is an empty list according to the sample prediction result, and when the prompt dialog example list is an empty list, the input instruction is used to call the large model to predict the training sample result, and when the prompt dialog example list is a non-empty list, the splicing instruction is used to call the large model to predict the training sample result, and the incorrect sample data that is not predicted correctly in the training sample result is filtered out. Finally, the prompt dialog example list is traversed, and the similarity algorithm is called to calculate the similarity between the incorrect sample data and the prompt dialog example to obtain the incorrect sample data with the lowest similarity, that is, the prompt prompt sample. When this method uses few-shot prompt optimization, it randomly selects some training sample inputs and outputs to construct few-shot examples as prompts. In order to avoid these randomly selected samples not being able to give the best prompt effect to the large model, the recognition accuracy of the rules is improved in a targeted manner, the samples with incorrect recognition are solved, and the number of incorrect samples is continuously reduced to improve the prompt effect. The automation of few-shot example screening is realized, and the screening accuracy and efficiency are high.

[0079] like Figure 2 As shown, in a specific embodiment, the method for extracting prompt context prompts provided by the present invention, when using few-shot prompt optimization, randomly selects some training sample inputs and outputs to construct few-shot examples as prompt prompts, but these randomly selected samples may not give the best prompt effect to the large model. In order to specifically improve the recognition accuracy of the rules, the Boosting prompt (prompt for wrong samples) method is adopted to specifically solve the recognition errors of the samples, and continuously reduce the error to improve the prompt effect.

[0080] First, take 100 sample data as an example, and construct 70 training sets and 30 validation sets based on the 100 sample data. In the initial state, the prompt example list C of few-shot (sample) is an empty list. Generally speaking, the prompt (prompt dialog box command) and the input command (input command) are used together to call the large model, but the input command can also be used to call the large model to obtain the sample prediction results.

[0081] In this embodiment, if the prompt example list C is empty, the input instruction calls the large model to predict the training sample results. The algorithm is as follows:

[0082] Input:

[0083] question

[0084] {sample}

[0085] If the prompt example list C of few-shot is not an empty list, the prompt and input instructions are concatenated to call the large model to predict the training sample results. The algorithm is as follows:

[0086] "prompt":

[0087] #### few-shot 1 ####

[0088] Sample Question 1

[0089] Sample Answer 1

[0090] #### few-shot 1 end ####

[0091] #### few-shot 2 ####

[0092] Sample Question 2

[0093] Sample Answer 2

[0094] #### few-shot 2 end #### ...

[0096] #### few-shot n ####

[0097] Example Question

[0098] Input:

[0099] question

[0100] {sample}

[0101] Input to the large model is

[0102] #### few-shot 1 ####

[0103] Sample Question 1

[0104] Sample Answer 1

[0105] #### few-shot 1 end ####

[0106] Input:

[0107] question

[0108] {sample}

[0109] Then, the training sample results are obtained, and the list of training samples that are not predicted correctly is filtered and added to the array T_error to improve the accuracy of the error samples in a targeted manner. The algorithm is as follows:

[0110] #### few-shot 1 ####

[0111] Sample Question 1

[0112] Sample Answer 1

[0113] #### few-shot 1 end ####

[0114] #### few-shot 2 ####

[0115] Incorrect (Example) Sample Question 2 [Example: Please output the entity of the disease in the sentence above: Essential Hypertension]

[0116] Incorrect (Example) Sample Answer 2 [Correct answer: "Essential hypertension", the previous large model output is "hypertension"]

[0117] #### few-shot 2 end ####

[0118] Input:

[0119] question

[0120] {sample}

[0121] In this embodiment, in order to ensure the text diversity of the few-shot prompt sample set, the diversity of the few-shot prompts can be given to the large model with different types and angles of prompt problem scenarios. Taking medical entity recognition as an example, different types of entity examples or text styles can be used to achieve different angle prompts. The algorithm is as follows:

[0122] #### few-shot 1 ####

[0123] Example Problem 1: Example of Drug Entity Recognition

[0124] Sample Answer 1

[0125] #### few-shot 1 end ####

[0126] #### few-shot 2 ####

[0127] Incorrect (Example) Sample Question 2 Example of disease entity recognition

[0128] Incorrect (Example) Sample Answer 2

[0129] #### few-shot 2 end ####

[0130] See also Figure 3 and Figure 4 As shown, in this embodiment, in order to improve the effect of sample recognition, a similarity algorithm (TF-IDF+BERTScore) is designed to calculate the similarity value between the few-shot prompt sample set and the sample. The text similarity is calculated by taking all sample example questions of the sample set and the selected sample example questions in turn for similarity calculation. The similarity score is obtained by defining similar_score ={tfidf_score + bert_score}. The lower the similar_score, the more dissimilar the sample is to the few-shot sample set. Then, the sample representation with the lowest similar_score among all the error samples is taken, which is the sample to be extracted. Finally, the set of similar_score scores of all samples C (i.e., prompt prompt samples) corresponding to the error samples in the T_error list is obtained. Here, the lowest value of the similar_score scores of all samples C is taken as the error sample. The T_error list constructs the input of the large model through the current prompt prompt and the sample selected from the training set, and predicts all the training set samples in turn. The training set that finds the error is the T_error list. An error sample in the T_error list is the similarity score of the error sample, that is, max_similar_score.

[0131] Combination Figure 5As shown, in this embodiment, the problem of the model identifying easily wrong samples also needs to be considered. The output result of the lm_head component of the large model can represent the probability value predicted by the dictionary. It is necessary to find the probability value of the token (authentication information) of the correct answer corresponding to the lm_head index position. The token probabilities of the correct answer (the correct result of the manual annotation of the answer to the corresponding sample) are added together, and the resulting value is called "token_score". If the token_score is lower, it means that the model believes that the probability of the correct answer is lower. Then take the sample with the lowest token_score among all the wrong samples, which is the sample to be extracted. Add the original example and the correct answer to the few-shot (the initial sample data) to correct the wrong answer and improve the recognition effect of the large model on the target sample. The example algorithm is as follows:

[0132]

【#### few-shot 1 ####

[0133] Sample Question 1

[0134] Sample Answer 1

[0135] #### few-shot 1 end ####

[0136] #### few-shot 2 ####

[0137] Incorrect (Example) Sample Question 2 [Example: Please output the entity of the disease in the sentence above: Essential Hypertension]

[0138] Incorrect (Example) Sample Answer 2 [Correct answer: "Essential hypertension", the previous large model output is "hypertension"]

[0139] #### few-shot 2 end ####

[0140] Input:

[0141] question

[0142] {sample} 】

[0144] In this embodiment, the similar_score and token_score scores of the sample list with incorrect recognition can be calculated by the above formula, and the final score = similar_score + token_score. In addition, in order to improve the training performance, the samples can be selected in a greedy manner, the scores of the samples with incorrect recognition can be sorted, and the incorrect sample T[b] with the lowest score can be added to the temporary set tmp_C.

[0145] Based on the current tmp_C as prompt, the validation set data is predicted by the large model, and the accuracy of the validation set eval_acc can be obtained. For example, adding few-shot 2, which is the error sample, to the few-shot prompt, the algorithm is as follows:

[0146] #### few-shot 1 ####

[0147] Sample Question 1

[0148] Sample Answer 1

[0149] #### few-shot 1 end ####

[0150] #### few-shot 2 ####

[0151] Incorrect (Example) Sample Question 2 [Example: Please output the entity of the disease in the sentence above: Essential Hypertension]

[0152] Incorrect (Example) Sample Answer 2 [Correct answer: "Essential hypertension", the previous large model output is "hypertension"]

[0153] #### few-shot 2 end ####

[0154] Input:

[0155] question

[0156] {sample}

[0157] In this embodiment, if the accuracy of the validation set eval_acc is improved, then

[0158] #### few-shot 1 ####

[0159] Sample Question 1

[0160] Sample Answer 1

[0161] #### few-shot 1 end ####

[0162] #### few-shot 2 ####

[0163] Incorrect (Example) Sample Question 2 [Example: Please output the entity of the disease in the sentence above: Essential Hypertension]

[0164] Incorrect (Example) Sample Answer 2 [Correct answer: "Essential hypertension", the previous large model output is "hypertension"]

[0165] #### few-shot 2 end ####

[0166] Input:

[0167] question

[0168] {sample}

[0169] Here, {sample} represents the sample of the validation set. Each sample is called in turn with the results of adding few-shot 2 and without adding few-shot 2. The two results are summarized respectively, indicating that the prompt model effect is improved after adding the sample. Then the candidate sample T[b] is added to C (that is, the prompt sample). If the accuracy eval_acc of the validation set decreases compared with the previous one, the next candidate sample with the lowest score is found in a greedy way. In fact, the greedy way is to directly find the lowest score as the candidate sample and perform the steps of similarity and authentication information screening samples.

[0170] Then, find the prompt example list C of few-shot, add the candidate sample T[b] to C, and determine whether the prompt example list is empty. After several rounds of Boosting prompt iteration (i.e., the above-mentioned step of screening the extracted samples layer by layer), once the total number of tokens in the set of all few-shot samples reaches max_token_num (for example, set max_token_num to 2048), stop iterative updating. This is because too long an input sample length will affect the prediction efficiency of the large model, so limiting the number of tokens to 2048 can improve the model prediction speed.

[0171] The above method of extracting prompt context prompts specifically selects samples with incorrect recognition to construct prompts. The prompt can guide the large model to correct samples that were incorrectly recognized when no prompt was added, thereby improving the recognition accuracy of the large model. In addition, the text similarity calculation method is used to improve the diversity of prompt samples, and the hm_lead component can be used to obtain the probability value of the correct dictionary prediction. When this method uses few-shot prompt optimization, it can randomly select the input and output of some training samples to construct few-shot examples as prompt prompts, but these randomly selected samples may not give the best prompt effect to the large model. In order to improve the recognition accuracy of the rules in a targeted manner, the Boosting prompt method is used to specifically solve the samples with incorrect recognition, and continuously reduce the number of incorrectly recognized samples to improve the effect of the prompt prompt.

[0172] The following is a description of the device for extracting prompt contextual prompts provided by the present invention. The device for extracting prompt contextual prompts described below and the method for extracting prompt contextual prompts described above can be referenced to each other.

[0173] like Figure 6 As shown, in one embodiment, a device for extracting prompt context hints includes a data set construction module 610, an instruction calling module 620, an instruction splicing module 630 and a sample extraction module 640.

[0174] The data set construction module 610 is used to obtain sample data including multiple sets of question text data and answer text data, and to construct a training data set and a verification data set based on the sample data, and to use input instructions to call a large model to obtain sample prediction results of the sample data.

[0175] The instruction calling module 620 is used to determine whether the prompt dialog example list is an empty list according to the sample prediction result, and when the prompt dialog example list is an empty list, use the input instruction to call the large model to predict the training sample result. And

[0176] The instruction splicing module 630 is used to use the splicing instruction to call the large model to predict the training sample results when the prompt dialog box example list is a non-empty list, and to filter out the incorrect sample data that is not predicted correctly in the training sample results. The splicing instruction is obtained by splicing the prompt dialog box instruction and the input instruction.

[0177] The sample extraction module 640 is used to traverse the prompt dialog example list and call a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt sample, which is the error sample data with the lowest similarity.

[0178] Among them, in the initial state, the prompt dialog example list in the sample data is an empty list, the similarity algorithm is composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm, and the prompt dialog instruction is a few-shot context prompt dialog instruction.

[0179] In this embodiment, the device for extracting prompt context prompts provided by the present invention, the instruction splicing module is specifically used for:

[0180] The concatenated instruction composed of the prompt instruction and the input instruction calls the large model to process the sample data in the training data set to obtain a training sample result set composed of the training sample results.

[0181] The error sample data in the training sample result is screened out from the training sample result set, and the error sample data is added to the error array, which contains a plurality of error sample data.

[0182] In this embodiment, the device for extracting prompt context prompts provided by the present invention, the sample extraction module is specifically used for:

[0183] Traverse the prompt dialog example list, and call the similarity algorithm composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm to calculate the TF-IDF score and BERTScore score between each error sample data in the error array and all prompt sample examples in the prompt dialog example list, and obtain the score value corresponding to the similarity.

[0184] Among them, the score corresponding to the similarity is the sum of the TF-IDF score and the BERTScore score.

[0185] In this embodiment, in the apparatus for extracting prompt context prompts provided by the present invention, the sample extraction module is further used for:

[0186] Get the score value corresponding to the similarity between each error sample data and all prompt sample examples in the prompt dialog box example list, and select the error sample data corresponding to the similarity with the smallest score value.

[0187] Based on the error sample data corresponding to the similarity with the smallest score value, all prompt samples corresponding to the error sample data in the error array are obtained to construct a similarity score set of all prompt samples.

[0188] In this embodiment, the device for extracting prompt context prompts provided by the present invention further includes a sample screening module for:

[0189] The similarity with the lowest score value is selected from the similarity score set to determine the target error sample data with the lowest similarity score.

[0190] The target error sample data is used as the input of the large model to call the LM Head component of the large model to output the vocabulary probability matrix corresponding to the target error sample data.

[0191] In this embodiment, the device for extracting prompt context prompts provided by the present invention further includes a sample screening submodule for:

[0192] The correct text data and authentication information corresponding to the target error sample data are obtained, and the correct text data and authentication information are vectorized through the tokenizer to obtain the vector corresponding to the index position of the correct text data and authentication information.

[0193] According to the vector corresponding to the index position of the correct text data and its authentication information, the probability list of the index position is obtained from the vocabulary probability matrix of the large model, and the probabilities of all correct text data are accumulated in combination with the vocabulary probability matrix corresponding to the target error sample data to obtain the probability value of the index position.

[0194] In this embodiment, the device for extracting prompt context prompts provided by the present invention further includes an error sample correction module, which is used to:

[0195] Based on the probability value of the index position, the target error sample data corresponding to the index position with the lowest probability value is obtained, and the correct text data and the corresponding sample text data in the prompt dialog box example list are added to the sample data to correct the target error sample data.

[0196] Figure 7 The physical structure diagram of an electronic device is shown as an example. The electronic device may be a smart terminal, and its internal structure diagram may be as follows: Figure 7 As shown. The electronic device includes a processor, a memory and a network interface connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the method for extracting prompt context prompts is implemented.

[0197] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the scheme of the present invention, and does not constitute a limitation on the electronic device to which the scheme of the present invention is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0198] On the other hand, the present invention also provides a computer storage medium storing a computer program, which implements the above method for extracting prompt context hints when the computer program is executed by a processor.

[0199] In another aspect, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and when the processor executes the computer instructions, the method for extracting a prompt context prompt is implemented.

[0200] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related 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.

[0201] 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 (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0202] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0203] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

Claims

1. A method for extracting prompt context prompts, characterized in that: The method comprises: Obtain sample data including multiple sets of question text data and answer text data, construct a training data set and a verification data set based on the sample data, and use input instructions to call a large model to obtain sample prediction results of the sample data; Determining whether the prompt dialog box example list is an empty list according to the sample prediction result, and when the prompt dialog box example list is an empty list, using the input instruction to call the large model to predict the training sample result; and When the prompt dialog example list is a non-empty list, a splicing instruction is used to call the large model to predict the training sample results, and to filter out incorrect sample data that is not predicted correctly in the training sample results, wherein the splicing instruction is obtained by splicing the prompt dialog instruction and the input instruction; Traversing the prompt dialog example list, and calling a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example, to obtain a prompt prompt sample, wherein the prompt prompt sample is the error sample data with the lowest similarity; Among them, in the initial state, the prompt dialog example list in the sample data is an empty list, the similarity algorithm is composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm, and the prompt dialog instruction is a few-shot context prompt dialog instruction.

2. The method for extracting prompt context hints according to claim 1, characterized in that: When the example list in the prompt dialog box is a non-empty list, using a splicing instruction to call the large model to predict the training sample results, and filtering out incorrect sample data that is not predicted correctly in the training sample results, including: Calling the concatenated instruction consisting of the prompt instruction and the input instruction to call the large model to process the sample data in the training data set to obtain a training sample result set consisting of the training sample results; The error sample data in the training sample result is screened out from the training sample result set, and the error sample data is added to an error array, wherein the error array contains a plurality of the error sample data.

3. The method for extracting prompt context hints according to claim 2, characterized in that: The traversing the prompt dialog example list and calling a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt prompt sample includes: Traversing the prompt dialog example list, and calling the similarity algorithm composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm to sequentially calculate the TF-IDF score and the BERTScore score between each error sample data in the error array and all prompt sample examples in the prompt dialog example list, to obtain a score value corresponding to the similarity; The score value corresponding to the similarity is the sum of the TF-IDF score and the BERTScore score.

4. The method for extracting prompt context hints according to claim 3, characterized in that: The traversing the prompt dialog example list and calling a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt prompt sample also includes: Obtaining the score value corresponding to the similarity between each error sample data and all prompt sample examples in the prompt dialog example list, and selecting the error sample data corresponding to the similarity with the smallest score value; Based on the error sample data corresponding to the similarity with the smallest score value, all prompt prompt samples corresponding to the error sample data in the error array are obtained to construct a similarity score set of all prompt prompt samples.

5. The method for extracting prompt context hints according to claim 4, characterized in that: The step of traversing the prompt dialog example list and invoking a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt prompt sample includes: Selecting the similarity with the lowest score value from the similarity score set to determine the target error sample data with the lowest similarity score; The target error sample data is used as the input of the large model to call the LM Head component of the large model to output the vocabulary probability matrix corresponding to the target error sample data.

6. The method for extracting prompt context hints according to claim 5, characterized in that: The method further comprises: Acquire the correct text data and authentication information corresponding to the target error sample data, and vectorize the correct text data and authentication information through a tokenizer to obtain a vector corresponding to the index position of the correct text data and authentication information; According to the vector corresponding to the index position of the correct text data and its authentication information, the probability list of the index position is obtained from the vocabulary probability matrix of the large model, and the probabilities of all correct text data are accumulated in combination with the vocabulary probability matrix corresponding to the target error sample data to obtain the probability value of the index position.

7. The method for extracting prompt context hints according to claim 6, characterized in that: The method further comprises: Based on the probability value of the index position, the target error sample data corresponding to the index position with the lowest probability value is obtained, and the correct text data and the corresponding example text data in the prompt dialog example list are added to the sample data to correct the target error sample data.

8. A device for extracting prompt context, characterized in that: The device comprises: A data set construction module, used to obtain sample data including multiple sets of question text data and answer text data, and to construct a training data set and a verification data set based on the sample data, and to use input instructions to call a large model to obtain sample prediction results of the sample data; An instruction calling module, used to determine whether the prompt dialog example list is an empty list according to the sample prediction result, and when the prompt dialog example list is an empty list, use the input instruction to call the large model to predict the training sample result; and An instruction splicing module, used for, when the prompt dialog example list is a non-empty list, using a splicing instruction to call the large model to predict the training sample results, and screening out incorrect sample data that is not predicted correctly in the training sample results, wherein the splicing instruction is obtained by splicing the prompt dialog instruction with the input instruction; A sample extraction module, used to traverse the prompt dialog example list and call a similarity algorithm to calculate the similarity between the error sample data and the prompt dialog example to obtain a prompt sample, wherein the prompt sample is the error sample data with the lowest similarity; Among them, in the initial state, the prompt dialog example list in the sample data is an empty list, the similarity algorithm is composed of the TF-IDF calculation formula and the BERTScore sentence-level similarity evaluation algorithm, and the prompt dialog instruction is a few-shot context prompt dialog instruction.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Prompt-based text similarity calculation method and system

    CN115204143A

  • Text processing method and device, electronic equipment and computer readable storage medium

    CN116680379A

  • Text generation method and device, storage medium and computer equipment

    CN116975214A

  • Frozen Model Adaptation Through Soft Prompt Transfer

    US20240020546A1