Prompt word generation method and text processing method
Through the optimization of hierarchical sampling and prompt word generation model, the problem of incompatibility of convergence direction and speed during prompt word design and optimization in the existing technology is solved, and the rapid and accurate prompt word generation is achieved, which improves matching and accuracy. sex.
Patent Information
- Application Number
- CN202411143879.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2044-08-20
AI Technical Summary
In the prior art, the design and optimization process of prompt words cannot be compatible with the convergence direction and convergence speed, and a large number of samples are required, resulting in high cost and low efficiency, and it is impossible to quickly generate prompt words that match specific tasks.
By responding to the prompt word generation request of the target language model, the sample set is determined and the hierarchical sampling process is performed according to the preset hierarchical sampling strategy, representative samples are generated, and the initial prompt words are generated using the prompt word generation model is used, and the intermediate prompt words and The evaluation information is optimized until a target prompt word is obtained that meets the optimization stop condition.
It realizes the rapid and accurate generation of prompt words matching specific tasks, ensuring that the prompt words converge in the correct direction, speeding up the convergence speed, and improving the matching and accuracy of prompt words.
Smart Images

Figure CN118655989B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present specification relate to the field of machine learning technology, and more particularly to a prompt word generation method and a text processing method. Background Art
[0002] With the development of computer and Internet technology, large models are applied in more and more scenarios. When the large model is used to feedback the input results of the user, the accuracy of the feedback results is more affected by the prompt words. Due to the large differences in the prompt words selected by different users, the application end effect is unstable. In order to improve stability, an effective prompt word is usually set for a specific task for the user to use. The design of the prompt word needs to be determined after repeated attempts, and the whole process is time-consuming and labor-intensive. In the prior art, in order to be able to use prompt words with better effects for result prediction in the application of large models, most of them will use models with optimization capabilities for prompt words for iterative processing, so as to generate prompt words with better effects for users to use quickly. However, this processing process is not compatible with the convergence direction and convergence speed, and requires a large number of sample drives, which is not only costly, but also inefficient, so an effective solution is urgently needed to solve the above problems. Summary of the invention
[0003] In view of this, an embodiment of this specification provides a prompt word generation method. One or more embodiments of this specification also relate to a text processing method, a prompt word generation device, a text processing device, a computing device, a computer-readable storage medium and a computer program product to solve the technical defects existing in the prior art.
[0004] According to a first aspect of an embodiment of this specification, a method for generating a prompt word is provided, comprising:
[0005] Determining a sample set in response to a prompt word generation request submitted for a target language model, performing stratified sampling processing on the sample set according to a preset stratified sampling strategy, and determining a plurality of representative samples according to the stratified sampling processing result;
[0006] Inputting the plurality of representative samples and the structured prompt information respectively corresponding to the plurality of representative samples into a prompt word generation model for processing to obtain initial prompt words respectively corresponding to the plurality of representative samples;
[0007] Extracting intermediate prompt words from the initial prompt words corresponding to the plurality of representative samples respectively, and determining evaluation information associated with the intermediate prompt words;
[0008] The intermediate prompt word is optimized according to the evaluation information until a target prompt word that meets the optimization stop condition is obtained.
[0009] According to a second aspect of an embodiment of this specification, a text processing method is provided, which is applied to a server, and includes:
[0010] Receive question text submitted by the client for the target language model;
[0011] Selecting a prompt word to be applied from a target prompt word set associated with the target language model according to the question text, wherein the prompt words included in the target prompt word set are generated by the above method;
[0012] The question text is updated based on the prompt word to be applied, and the updated question text is input into the target language model for processing to obtain an answer text;
[0013] The answer text is fed back to the client.
[0014] According to a third aspect of the embodiments of this specification, a prompt word generating device is provided, including:
[0015] A determination module is configured to determine a sample set in response to a prompt word generation request submitted for a target language model, perform stratified sampling processing on the sample set according to a preset stratified sampling strategy, and determine a plurality of representative samples according to the stratified sampling processing result;
[0016] An input module is configured to process the plurality of representative samples and the structured prompt information respectively corresponding to the plurality of representative samples into a prompt word generation model to obtain initial prompt words respectively corresponding to the plurality of representative samples;
[0017] An extraction module is configured to extract intermediate prompt words from the initial prompt words corresponding to the plurality of representative samples, and determine evaluation information associated with the intermediate prompt words;
[0018] The optimization module is configured to optimize the intermediate prompt word according to the evaluation information until a target prompt word that meets the optimization stop condition is obtained.
[0019] According to a fourth aspect of the embodiments of this specification, a text processing device is provided, which is applied to a server, including:
[0020] A text receiving module is configured to receive a question text submitted by a client for a target language model;
[0021] A prompt word selection module is configured to select prompt words to be applied from a target prompt word set associated with the target language model according to the question text, wherein the prompt words included in the target prompt word set are generated by the above method;
[0022] An updating text module is configured to update the question text based on the prompt word to be applied, and input the updated question text into the target language model for processing to obtain an answer text;
[0023] The feedback text module is configured to feed back the answer text to the client.
[0024] According to a fifth aspect of an embodiment of this specification, a computing device is provided, including:
[0025] Memory and processor;
[0026] The memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions. When the computer executable instructions are executed by the processor, the steps of the above-mentioned prompt word generation method or text processing method are implemented.
[0027] According to a sixth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores computer-executable instructions, and when the instructions are executed by a processor, the steps of the above-mentioned prompt word generation method or text processing method are implemented.
[0028] According to a seventh aspect of the embodiments of this specification, a computer program product is provided, including a computer program or instructions, which, when executed by a processor, implement the steps of the above-mentioned prompt word generation method or text processing method.
[0029] The prompt word generation method provided in this embodiment can quickly and accurately obtain prompt words matching specific tasks, and ensure that the prompt words converge in the correct direction while accelerating the convergence speed. First, a sample set can be determined in response to the prompt word generation request submitted for the target language model. In order to ensure the accuracy of subsequent prompt word generation, the sample set can be subjected to stratified sampling processing according to a preset stratified sampling strategy, so as to determine multiple representative samples according to the stratified sampling processing results; on this basis, multiple representative samples and structured prompt information corresponding to multiple representative samples can be input into the prompt word generation model for processing, so as to use the prompt word generation model to predict the initial prompt words corresponding to each representative sample; at this time, the initial prompt words obtained are only the initial recommendation results, and their accuracy may be low, so they can be further optimized. At this time, the intermediate prompt words can be extracted from the initial prompt words corresponding to the multiple representative samples, and the evaluation information associated with the intermediate prompt words can be determined; then, the intermediate prompt words can be optimized according to the evaluation information, so as to achieve convergence in the correct convergence direction based on the initial prompt words, until the target prompt words that meet the optimization stop condition are obtained, so as to ensure the matching of the target prompt words with the specific tasks, so that the prompt words can be used to feedback more accurate results to the user in the application stage. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 is a schematic diagram of a prompt word generation method provided by an embodiment of this specification;
[0031] Figure 2 is a flow chart of a prompt word generation method provided by an embodiment of this specification;
[0032] Figure 3 is a flowchart of a text processing method provided by an embodiment of this specification;
[0033] Figure 4 is a processing flow chart of a text processing method provided by an embodiment of this specification;
[0034] Figure 5 It is a structural schematic diagram of a prompt word generating device provided by an embodiment of this specification;
[0035] Figure 6 is a structural schematic diagram of a text processing device provided by an embodiment of this specification;
[0036] Figure 7 It is a structural block diagram of a computing device provided by an embodiment of this specification. DETAILED DESCRIPTION
[0037] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.
[0038] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0039] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0040] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0041] First, the terms involved in one or more embodiments of this specification are explained.
[0042] Meta-Prompt: is an advanced prompt technology, which is mainly used to improve the performance and functionality of language models when processing complex tasks. This technology guides the language model to perform task decomposition, expert model allocation, interactive supervision between models, and its own critical thinking, reasoning and verification by constructing a high-level "meta" prompt (Meta-Prompt). It is used here to analyze the input and output of task sample data and summarize the task instruction prompts, and guide the optimization of prompts based on the output effect of prompts on the verification task data set.
[0043] Prompt: plays a vital role in large language models. It is a bridge between the user and the model, guiding the model to generate expected responses or complete specific tasks by providing clear instructions or questions to the model. Prompt can be a question, a description, a task description, or even part of the conversation history.
[0044] In this specification, a prompt word generation method is provided. One or more embodiments of this specification also relate to a text processing method, a prompt word generation device, a text processing device, a computing device, a computer-readable storage medium and a computer program product, which are described in detail one by one in the following embodiments.
[0045] See also Figure 1As shown in the schematic diagram, the prompt word generation method provided in this embodiment can first determine a sample set in response to a prompt word generation request submitted to a target language model in order to quickly and accurately obtain prompt words matching a specific task and ensure that the prompt words converge in the right direction while accelerating the convergence speed. In order to ensure the accuracy of subsequent prompt word generation, the sample set can be subjected to stratified sampling processing according to a preset stratified sampling strategy, so as to determine a plurality of representative samples according to the stratified sampling processing results. On this basis, the plurality of representative samples and the structured prompt information corresponding to the plurality of representative samples can be input into the prompt word generation model for processing, so as to achieve the use of the prompt word generation model to first predict the initial prompt words corresponding to each representative sample. At this time, the initial prompt words obtained are only initial recommendation results, and their accuracy may be low, so they can be further optimized. At this time, the intermediate prompt words can be extracted from the initial prompt words corresponding to multiple representative samples, and the evaluation information associated with the intermediate prompt words can be determined; then the intermediate prompt words are optimized according to the evaluation information, so that convergence in the correct convergence direction can be achieved based on the initial prompt words, until the target prompt words that meet the optimization stop conditions are obtained, thereby ensuring the matching of the target prompt words with the specific tasks, so that the prompt words can be used to provide users with more accurate feedback results in the application stage.
[0046] See also Figure 2 , Figure 2 A flowchart of a prompt word generation method provided according to an embodiment of the present specification is shown, which specifically includes the following steps.
[0047] Step S202 : determining a sample set in response to a prompt word generation request submitted for a target language model, performing stratified sampling processing on the sample set according to a preset stratified sampling strategy, and determining a plurality of representative samples according to the stratified sampling processing result.
[0048] The prompt word generation method provided in this embodiment can be applied to the prompt word generation scenario of any type of large language model, wherein the model can be a large language model in any field, such as education scenario, financial scenario, legal scenario, image processing scenario, etc., and no matter whether the model is deployed for the first time or redeployed after optimization, there will be a problem of no applicable prompt words. On this basis, the prompt word generation method provided in this embodiment can be used for the language model that is deployed for the first time or redeployed, to accurately and efficiently generate prompt words corresponding to the specified task, so as to ensure that in the application stage, the generated target prompt words can be combined to provide users with more accurate model prediction results.
[0049] Specifically, the target language model specifically refers to the language model that needs to be optimized for prompt words in the current stage. The language model can be a language model used in scenarios such as education, finance, and law to process user input and feedback the corresponding answer. For example, in the legal scenario, the user inputs {whether event A violates the law}, and the model combines the prompt words and the user's input to feedback the result of whether event A is illegal, as well as the introduction of relevant laws. Correspondingly, the prompt word generation request specifically refers to the request triggered in the prompt word update phase when the target language model needs to be updated. The request can be automatically triggered by the system or submitted by the operation and maintenance personnel. This embodiment does not make any restrictions here. Correspondingly, the sample set specifically refers to the set of samples that the target language model needs to use in the fine-tuning phase or the training phase. In order to generate more matching prompt words for the target language model, and the prediction ability of the model is affected by the sample coverage dimension, the prompt words can be generated based on the sample set of the target language model, so as to ensure that the final prompt words match the target language model better.
[0050] Further, the stratified sampling strategy specifically refers to a strategy for stratifying the samples in the sample set and selecting representative samples. The strategy records the stratification rules and the rules for selecting representative samples, so that representative samples can be screened out for subsequent prompt word generation processing. Correspondingly, the representative sample specifically refers to the representative sample selected in each level after the sample set is stratified. It can be understood that the representative sample is a representative sample in each layer after the task category or value range category of the sample set is processed separately, which is used for the subsequent prompt word generation operation based on the representative sample. It can be understood that each level corresponds to a task category, so that the representative sample can be selected for each task category for the subsequent prompt word generation processing. In actual applications, when extracting representative samples for each task category, the number of representative samples can be set according to actual needs, and this embodiment does not make any restrictions here.
[0051] Based on this, in order to quickly and accurately obtain prompt words that match specific tasks, and to ensure that the prompt words converge in the right direction while accelerating the convergence speed, the sample set can be determined in response to the prompt word generation request submitted to the target language model. In order to ensure the accuracy of subsequent prompt word generation, the sample set can be stratified sampled according to the preset stratified sampling strategy, so as to determine multiple representative samples based on the stratified sampling processing results; so that prompt words can be generated subsequently in combination with multiple representative samples.
[0052] In practical applications, the sample set N corresponding to the target language model can contain S subtasks, each of which consists of t items (input, output). For example, the extraction task consists of the text to be extracted and the extraction result. It can be expressed as ,in, Respectively represent Of the subtasks The input and its corresponding output On this basis, subsequent stratified sampling can be performed to obtain representative samples for subsequent prompt word generation operations.
[0053] Furthermore, when performing stratified sampling, in order to ensure that the multiple representative samples obtained after sampling are representative, the samples can be stratified according to the stratification information specified in the stratified sampling strategy, and then de-resampled to screen out representative samples. In this embodiment, the specific implementation method is as follows:
[0054] Determine sample stratification information according to a preset stratified sampling strategy, and perform stratification processing on the sample set based on the sample stratification information to obtain multiple sample subsets; determine label information corresponding to candidate samples in each sample subset, and perform representative detection on each sample subset according to the label information; when it is determined according to the representative detection result that the multiple sample subsets meet the deduplication condition, perform deduplication processing on the multiple sample subsets respectively; perform sampling in the multiple sample subsets after deduplication, and determine multiple representative samples according to the sampling results.
[0055] Specifically, the sample stratification information specifically refers to the information specified when the sample set is stratified. This information records the stratification rules and is used to implement the processing of the samples contained in the sample set into multiple sample subsets. In practical applications, the sample stratification information can be constructed according to the clustering rules. By setting different clustering centers according to the characteristics of the task, it is possible to cluster the samples contained in the sample set to obtain multiple sample subsets. Correspondingly, the label information specifically refers to the sample label information corresponding to each candidate sample. For example, in the extraction task, the candidate sample is the text to be extracted, and the label information is the extraction result corresponding to the text to be extracted. Correspondingly, deduplication processing specifically refers to the need to perform deduplication operations on the samples in the sample subset when there are different finite enumerable subsets of the label information corresponding to each sample.
[0056] Based on this, after determining the sample set corresponding to the target language model, in order to select representative samples for prompt word generation, thereby ensuring that the generated prompt words better match the target language model, a stratified sampling strategy can be selected to process the sample set. In this process, the sample stratification information can be determined according to the preset stratified sampling strategy. At this time, the sample set can be stratified based on the sample stratification information, and after the sample set is divided according to different levels, multiple sample subsets are obtained; on this basis, the label information corresponding to the candidate sample in each sample subset can be determined, and at this time, each sample subset is representatively detected according to the label information; thus, it can be determined whether multiple sample subsets meet the deduplication conditions based on the representative detection results; if they meet, deduplication processing can be performed on multiple sample subsets respectively; after deduplication processing, the samples contained in the sample subset can be made more specific. Therefore, multiple representative samples can be sampled from multiple sample subsets after deduplication for subsequent use.
[0057] In actual applications, in the initial Meta-prompt construction phase, for the S subtasks contained in the sample set N, if each subtask S i In the case where the answer value range of has different finite enumeration subsets, the remaining subtasks S_dup can be obtained by removing duplicates, where S_dup i The subtask consists of t questions and answers, each question and answer t i Expressed as ( , ) and len(t)<=len(S i ), and then by sampling from the deduplicated samples, representative samples can be obtained for subsequent use.
[0058] It should be noted that, since the value domains corresponding to subtasks in scenarios such as text classification and entity extraction are enumerable, representative samples can be sampled by deduplication. For scenarios with a limited set of labels, each type of label can automatically generate corresponding template instructions for screening representative samples. This embodiment does not make any limitations here. Specifically, in view of the non-uniqueness of the answer value domain in the question-and-answer scenario, in actual sampling, based on the similarity between questions and answers between samples in the subtasks, N cluster center points can be set according to business characteristics for unsupervised classification and then sampling by category.
[0059] This embodiment takes the target language model as a large language model corresponding to the financial field as an example to illustrate the above description. Specifically, a sample set is obtained, and the sample set contains S samples. At this time, the sample set is stratified according to the stratified sampling strategy, and n sample subsets can be obtained, each sample subset corresponds to a level; then, in order to be able to select representative samples from the n sample subsets for subsequent prompt generation, the value domain corresponding to the samples contained in each sample subset can be deduplicated, thereby enhancing the representativeness of the sample. After deduplication, sampling can be performed in each deduplicated sample subset to obtain n representative samples for subsequent use.
[0060] In summary, by eliminating repeated items in the enumerable value domain, the representativeness of the sample can be improved. Based on this, sampling can obtain representative samples corresponding to each layer, thereby improving the generation accuracy of the prompt word.
[0061] Step S204: input the plurality of representative samples and the structured prompt information respectively corresponding to the plurality of representative samples into a prompt word generation model for processing, so as to obtain initial prompt words respectively corresponding to the plurality of representative samples.
[0062] Specifically, after obtaining multiple representative samples as mentioned above, in order to achieve iterative optimization of prompt words and select the prompt words that best match the target language model, the structured prompt information corresponding to each representative sample can be obtained, and the representative samples and the structured prompt information corresponding to the representative samples can be combined to construct the input of the prompt word generation model. After inputting it into the prompt word generation model, the initial prompt words corresponding to each representative sample can be obtained, and then optimization can be performed on the basis of the initial prompt words to generate target prompt words that match the target language model for use.
[0063] Among them, the structured prompt information specifically refers to the structured information constructed by combining the candidate prompt words associated with the representative samples, the scores of the candidate prompt words, the error samples and the error prediction results corresponding to the error samples. After being input into the prompt word generation model, the model can generate prompt words from both the forward and reverse dimensions, so that the generated prompt words can approach the ideal prompt words and deviate from the non-ideal prompt words, so that the subsequent optimization can accelerate the convergence. Correspondingly, the initial prompt words specifically refer to the prompt words to be optimized generated by the prompt word generation model for the representative samples.
[0064] In practical applications, the large model optimizer generated by combining Meta-prompt and stratified sampling of representative samples and error samples for prompt optimization can be expressed as , by inputting the above information into the large model optimizer , the initial prompt word corresponding to each representative sample can be obtained for subsequent iterative optimization.
[0065] Furthermore, in order to ensure that the prompt word generation model can output an initial prompt word with higher accuracy, and to achieve that the prompt word generation model can approach positive results and stay away from negative results, the construction of structured prompt information can be completed by combining information such as error samples and candidate prompt words. In this embodiment, the determination of structured prompt information corresponding to a representative sample associated with any task category in a plurality of representative samples includes:
[0066] According to the preset meta-prompt strategy, candidate prompt words are constructed for the target representative sample, and the prompt word score corresponding to the candidate prompt word is determined; the target error sample associated with the target representative sample is loaded, and the error prediction result corresponding to the target error sample and the error prompt information corresponding to the error prediction result are determined; based on the candidate prompt words, the prompt word score, the target error sample, the error prediction result and the error prompt information, structured prompt information corresponding to the target representative sample is constructed.
[0067] Specifically, the meta-prompt strategy specifically refers to the strategy corresponding to Meta-prompt. Accordingly, the candidate prompt word specifically refers to the prompt word to be optimized constructed by the meta-prompt strategy for the target representative sample. Accordingly, the prompt word score specifically refers to the evaluation score of the corresponding candidate prompt word. The higher the score, the higher the accuracy of the candidate prompt word. Correspondingly, the target error sample specifically refers to the sample corresponding to the deviation between the model output and the true result based on the candidate prompt word combined with the model input. The error prediction result is the prediction result output by the model, which deviates from the true result. Correspondingly, the error prompt information specifically refers to the prompt information that is determined to have an error problem after comparing the error prediction result with the true result.
[0068] Based on this, for any representative sample among multiple representative samples, when determining its corresponding structured prompt information, in order to enable the prompt word generation model to output more accurate prompt words for the representative sample at the current stage, candidate prompt words can be first constructed for the target representative sample according to the preset meta-prompt strategy, and the prompt word score that measures the accuracy of the candidate prompt word can be determined; after determining the information that can positively affect the prompt word generation, the target error sample associated with the target representative sample can be loaded, and the error prediction result corresponding to the target error sample and the error prompt information corresponding to the error prediction result are determined; thereby obtaining information that can reversely affect the prompt word generation, and at this time, the structured prompt information corresponding to the target representative sample can be constructed based on the candidate prompt words, the prompt word score, the target error sample, the error prediction result and the error prompt information, so that the prompt word generation model can output a more matching initial prompt word for the representative sample after inputting the information.
[0069] In practical applications, since the meta-prompt strategy corresponds to the Meta-prompt strategy, the slot filling in Meta-prompt can dynamically select the number of representative samples according to the length of the prompt word that the prompt word generation model can handle, such as 3-5 representative samples, etc. Among them, the slot contains the prompt word and its corresponding score, the new representative sample data representing the training set, the sample and prediction result of the previous round of validation set prediction error, and the error prompt information. Through the error sample and its corresponding error information, the new representative sample and the prompt word score, the prompt word optimization direction can be guided, thereby ensuring the matching between the newly generated prompt word and the representative sample.
[0070] Using the above example, after obtaining n representative samples, we can first determine the corresponding candidate prompt words and the scores of the candidate prompt words for the n=3 representative samples, and then collect the error samples corresponding to the candidate prompt words, the prediction results corresponding to the error samples, and the error reasons corresponding to the error samples. At this time, we can combine the above information to construct the structured prompt information corresponding to the n=3 representative samples, and after inputting it into the prompt word generation model, we can get the initial prompt word 1 corresponding to the n=3 representative samples. Similarly, after the above processing is applied to each representative sample, the initial prompt word corresponding to each type of subtask will be obtained in turn. Subsequently, the specified task can be optimized based on the initial prompt word, so that the target prompt word that matches the financial field and supports the use of the target language model can be obtained.
[0071] In summary, by combining positive information and reverse information to construct structured prompt information corresponding to representative samples, the prompt word generation model can output more accurate prompt words when predicting the prompt words corresponding to representative samples, thereby facilitating subsequent iterative optimization.
[0072] Step S206 , extracting intermediate prompt words from the initial prompt words corresponding to the plurality of representative samples respectively, and determining evaluation information associated with the intermediate prompt words.
[0073] Specifically, after obtaining the initial prompt words corresponding to multiple representative samples as mentioned above, in order to optimize the prompt words for use by the target language model for the specified task, intermediate prompt words can be extracted from multiple representative samples. However, the intermediate prompt words, as the output results of the prompt word generation model, may not achieve the expected results. Therefore, the evaluation information associated with the intermediate prompt words can be determined so that the intermediate prompt words can be optimized in combination with the evaluation information to achieve the optimization of the target prompt words that meet the needs.
[0074] The intermediate prompt words specifically refer to the prompt words with higher accuracy selected from the multiple prompt words generated in each round of iteration based on the initial prompt words. Correspondingly, the evaluation information specifically refers to the descriptive information that can characterize the excellence of the intermediate prompt words, which can be used to clarify the optimization direction in the prompt word optimization stage.
[0075] Furthermore, when extracting intermediate prompt words from the initial prompt words corresponding to multiple representative samples, in order to ensure that the extracted intermediate prompt words are more accurate, a verification set verification method can be used for screening. In this embodiment, the specific implementation method is as follows:
[0076] Acquire a verification set associated with the target language model; determine representative samples of at least two categories of tasks from the multiple representative samples, and determine initial prompt words corresponding to the representative samples of the at least two categories of tasks; use the verification set to evaluate the initial prompt words corresponding to the representative samples of the at least two categories of tasks, and obtain verification scores corresponding to the initial prompt words of each category of tasks; sort the verification scores, and select a set number of initial prompt words as intermediate prompt words according to the sorting results.
[0077] Specifically, the validation set refers to the sample set for accuracy verification of each initial prompt word. Correspondingly, the validation score refers to the score calculated by combining the samples in the validation set with each initial prompt word and inputting them into the target language model for processing, and then comparing the output of the model with the real result corresponding to the sample. The higher the score, the higher the accuracy of the table name prompt word.
[0078] Based on this, when using the validation set to validate each initial prompt word, you can first obtain the validation set associated with the target language model; at this time, you can use the samples contained in the validation set, combined with each initial prompt word to build the input of the target language model, input it into the target language model to obtain the prediction result, and then compare the prediction result with the actual result corresponding to the sample. For classification and extraction problems, EM (Exactly Match) is used to calculate the accuracy, and for other categories, the verification score corresponding to each initial prompt word is obtained by calculating the text distance (Edit Distance). Since the high or low verification score represents the performance of the initial prompt word on the validation set, it can be sorted according to the verification score, so that a set number of initial prompt words can be selected as intermediate prompt words according to the sorting result for subsequent use.
[0079] It should be noted that when screening the intermediate prompts, the results obtained through stratified sampling when considering multiple representative samples correspond to different task types at different levels. Therefore, when verifying, the representative samples corresponding to each type of task can be determined among multiple representative samples, and then the initial prompt words corresponding to the representative samples of this type of task can be selected, and then verified using the verification set, so as to obtain the verification score of the initial prompt words corresponding to this type of task. After the initial prompt words of any task category have completed the verification score prediction in this way, they can be used for subsequent sorting, and the intermediate prompt words can be screened out for subsequent use.
[0080] In actual applications, the number of selected intermediate prompt words can be set according to actual needs, such as selecting 2-6, and this embodiment does not make any limitation here.
[0081] Continuing with the above example, after obtaining n intermediate prompt words, the validation set corresponding to the target language model can be used to evaluate the intermediate prompt words corresponding to each type of task. After evaluation, the score corresponding to the intermediate prompt word 1 corresponding to the first type of task is determined to be S1, the score corresponding to the intermediate prompt word 2 corresponding to the second type of task is S2… The score corresponding to the intermediate prompt word n corresponding to the mth type of task is Sn. Then, the intermediate prompt words are sorted according to the scores, and top2-6 are selected as the prompt words for subsequent optimization. At this time, the selected prompt words are determined to be prompt word 1, prompt word 2,…, prompt word 5, prompt word 6.
[0082] In summary, by using the verification set verification method to score the initial prompt words associated with each type of task, it is possible to compare the excellence of each initial prompt word with each other under the same conditions, so that the initial prompt words with higher accuracy can be screened out as intermediate prompt words, so as to quickly optimize the target prompt words for subsequent use.
[0083] Furthermore, considering that the optimization operation of the intermediate prompt word needs to be completed based on its corresponding evaluation information, and the evaluation information is information describing the excellence of the intermediate prompt word, it can be combined with the performance of the initial prompt word on the validation set to ensure that the subsequent optimization direction is more accurate. In this embodiment, the specific implementation method is as follows:
[0084] Determine a plurality of verification samples corresponding to the verification set in the evaluation stage of the intermediate prompt word, and extract an erroneous verification sample associated with the intermediate prompt word from the plurality of verification samples; determine prompt word optimization information in response to the prompt word generation request, and determine historical verification information associated with the prompt word optimization information; construct evaluation information associated with the intermediate prompt word based on the erroneous verification samples, representative samples corresponding to the intermediate prompt word, and the historical verification information.
[0085] Specifically, the verification sample specifically refers to the sample used in the evaluation stage of the intermediate prompt word by the verification set. Correspondingly, the error verification sample specifically refers to the sample in which the intermediate prompt word is verified and evaluated by the verification sample set again, and the intermediate prompt word is combined with the sample to input the model, so that the output result of the model does not match the real result. It can reflect the bias of the intermediate prompt word so that it can be used as a reference for subsequent optimization. Correspondingly, the prompt word optimization information specifically refers to the information referenced when optimizing the intermediate prompt word to a specified task. For example, if the specified task is to extract entities in the financial field, the prompt word optimization information is the description information of the entity extraction in the financial field, which is used to guide the optimization direction of the intermediate prompt word. Correspondingly, the historical verification information specifically refers to the relevant information after the optimization of the intermediate prompt word in the previous optimization cycle of the current optimization cycle, which includes the prediction error samples in the samples used in the previous round of optimization cycle, as well as the error prompt information.
[0086] Based on this, when constructing evaluation information for the intermediate prompt word, in order to guide the optimization direction of the intermediate prompt word through the evaluation information, you can first determine the multiple verification samples corresponding to the evaluation stage of the intermediate prompt word in the verification set. At this time, you can extract the wrong verification samples associated with the intermediate prompt word from the multiple verification samples; on this basis, you can determine the prompt word optimization information in response to the prompt word generation request to achieve a clear optimization direction for the intermediate prompt word. Further, by determining the historical verification information associated with the prompt word optimization information; that is, based on the wrong verification samples, the representative samples corresponding to the intermediate prompt word, and the historical verification information, you can construct the evaluation information associated with the intermediate prompt word, so that you can subsequently complete the optimization of the intermediate prompt word based on the evaluation information, so that the intermediate prompt word can match the prompt word optimization information after the optimization is completed.
[0087] Following the above example, after verifying n prompt words using the validation set, prompt word 1, prompt word 2, ..., prompt word 5, prompt word 6 can be screened out. Further, in the verification stage of prompt word 1, it is recorded that prompt word 1 is combined with validation sample 1, validation sample 2 and validation sample 7 in the validation set, and the prediction result is wrong. At this time, validation sample 1, validation sample 2 and validation sample 7 can be used as the error validation sample corresponding to prompt word 1. On this basis, the representative sample 1 corresponding to prompt word 1 is combined to guide the optimization direction of the prompt word. At the same time, the validation sample with the previous round of prediction error and the existing error cause prompt in meta-prompt are used to strengthen the repair bias of prompt word 1 for the entity extraction task in the financial field, thereby constructing the evaluation information corresponding to prompt word 1; similarly, after constructing the evaluation information for prompt word 2, ..., prompt word 5, and prompt word 6, it can be realized that when the prompt word is optimized later, the prompt word can be more inclined to the entity extraction task in the financial field.
[0088] In summary, by combining multi-dimensional information to construct evaluation information, it is possible to record the optimization direction and avoidance direction of the prompt words in the evaluation information, so that the prompt words can be more inclined to the usage requirements of the target language model.
[0089] Step S208: optimizing the intermediate prompt words according to the evaluation information until a target prompt word that meets the optimization stop condition is obtained.
[0090] Specifically, after obtaining the intermediate prompt word and the evaluation information corresponding to the intermediate prompt word, the intermediate prompt word can be optimized according to the evaluation information. This process uses an iterative optimization method to continuously optimize the intermediate prompt word until a target prompt word that meets the optimization stop condition is obtained and used for subsequent use. Among them, the optimization stop condition can be the condition of the number of iterations, or the condition that the optimized prompt word is scored and the score does not change significantly for multiple iteration cycles.
[0091] In practical applications, the prompt to be generated based on the specified task is represented by P i , combined with P i The prediction generation model for the sample is expressed as , then the instruction set optimized for each round of task iteration is It is expressed as: ;in represents the representative sample used for stratification, represents the sample pairs that are predicted incorrectly on the validation set, The optimal prompt set in each iteration. The task goal is to generate the prompt instruction set before and after optimization. Find the optimal instruction This enables it to achieve the best accuracy (Acc) in the validation data set, namely:
[0092] ; ; ;in is the input of the samples in the validation set, For sample The predicted output is Indicates whether the sample prediction is equal to the actual result. For the extraction and intent recognition scenarios, the score is strictly equal. Finally, according to the verification set The accuracy of each predicted result and the actual result is used as the criterion for selecting the optimal task prompt.
[0093] Furthermore, when optimizing the intermediate prompt words, the intermediate prompt words can be combined with the evaluation information and then input into the prompt word optimization model for processing, and then the model output result can be compared with the actual result to determine the optimization information of the intermediate prompt words, so as to complete the optimization processing of the intermediate prompt words. In this embodiment, the specific implementation method is as follows:
[0094] Construct prompt word optimization information according to the evaluation information and the intermediate prompt word; input the prompt word optimization information into the prompt word optimization model for processing to obtain prompt word prediction information corresponding to the prompt word optimization information; compare the prompt word prediction information with the prompt word standard information corresponding to the prompt word optimization information, and optimize the intermediate prompt word according to the comparison result until a target prompt word that meets the optimization stop condition is obtained.
[0095] Specifically, the prompt word optimization information specifically refers to the information of the input prompt word optimization model constructed by combining the intermediate prompt words and the evaluation information, wherein the prompt word optimization model specifically refers to a large language model that can output prompt word prediction information based on the intermediate prompt words and the evaluation information. Correspondingly, the prompt word standard information specifically refers to the real information corresponding to the prompt word optimization information, and the prompt word prediction information is the prediction result output by the model.
[0096] Based on this, after obtaining the intermediate prompt words and evaluation information, the prompt word optimization information can be first constructed according to the evaluation information and the intermediate prompt words; thereafter, the prompt word optimization information can be input into the prompt word optimization model for processing, so that the prompt word optimization model can output the prompt word prediction information corresponding to the prompt word optimization information; on this basis, the prompt word prediction information can be compared with the prompt word standard information corresponding to the prompt word optimization information, so that the optimization direction of the prompt word can be determined, and therefore the intermediate prompt word can be optimized according to the comparison results until the target prompt word that meets the optimization stop condition is obtained.
[0097] In summary, by using the prompt word optimization model to optimize the intermediate prompt words according to the evaluation information, the intermediate prompt words can be made more inclined to the optimization direction, thereby obtaining the target prompt words matching the target language model, which is convenient for subsequent use by users.
[0098] Furthermore, in order to ensure that the target prompt words can be quickly and efficiently iterated to meet the requirements after being optimized, different optimization stop conditions can be set. In this embodiment, the specific implementation method is as follows:
[0099] The prompt word prediction information is compared with the prompt word standard information corresponding to the prompt word optimization information, and the intermediate prompt word is optimized according to the comparison result; the number of iterations corresponding to the optimized intermediate prompt word is determined, if the number of iterations meets a preset iteration number threshold; or, the optimized intermediate prompt word is verified, and if the comparison relationship between the verification result and the historical verification result meets the preset comparison condition, it is determined that the intermediate prompt word meets the optimization stop condition, and the optimized intermediate prompt word is used as the target prompt word.
[0100] Based on this, after obtaining the prompt word prediction information output by the model, the prompt word prediction information can be compared with the prompt word standard information corresponding to the prompt word optimization information. After the comparison is completed, the intermediate prompt word can be optimized according to the comparison result; at this time, the optimized intermediate prompt word can be tested. During the test, the number of iterations corresponding to the optimized intermediate prompt word can be determined first. If the number of iterations meets the preset iteration number threshold, it means that the iterative optimization of the intermediate prompt word has reached the threshold at this time, and the optimized intermediate prompt word can be directly used as the target prompt word.
[0101] In addition, the optimized intermediate prompt word can also be verified. If the comparison relationship between the verification result and the historical verification result meets the preset comparison condition, it means that the intermediate prompt word has not changed for multiple consecutive iteration cycles after optimization. Therefore, the optimized intermediate prompt word can be directly used as the target prompt word.
[0102] Following the above example, after obtaining the evaluation information corresponding to prompt word 1, prompt word 2, prompt word 5, prompt word 6, and prompt word 7, the evaluation information can be combined with the prompt word input into the prompt word optimization model for processing to obtain the model prediction information corresponding to each prompt word. Afterwards, the model prediction information is compared with the real information corresponding to the prompt word, and then the prompt word can be optimized according to the comparison result. The optimized prompt word will continue to be optimized when the number of iterations is not met. Until the number of iterations reaches M, the optimization of the prompt word will be stopped at this time, and then the optimized prompt word 1, prompt word 2, prompt word 5, prompt word 6, and prompt word 7 will be scored, and the optimized prompt word with the highest score will be selected as the target prompt word. In the application stage, the input features that meet the target language model can be constructed in combination with the user's input and the target prompt word, so that the model can accurately extract entities in the text of the financial field for subsequent use.
[0103] The prompt word generation method provided in this embodiment can quickly and accurately obtain prompt words matching specific tasks, and ensure that the prompt words converge in the correct direction while accelerating the convergence speed. First, a sample set can be determined in response to the prompt word generation request submitted for the target language model. In order to ensure the accuracy of subsequent prompt word generation, the sample set can be subjected to stratified sampling processing according to a preset stratified sampling strategy, so as to determine multiple representative samples according to the stratified sampling processing results; on this basis, multiple representative samples and structured prompt information corresponding to multiple representative samples can be input into the prompt word generation model for processing, so as to use the prompt word generation model to predict the initial prompt words corresponding to each representative sample; at this time, the initial prompt words obtained are only the initial recommendation results, and their accuracy may be low, so they can be further optimized. At this time, the intermediate prompt words can be extracted from the initial prompt words corresponding to the multiple representative samples, and the evaluation information associated with the intermediate prompt words can be determined; then, the intermediate prompt words can be optimized according to the evaluation information, so as to achieve convergence in the correct convergence direction based on the initial prompt words, until the target prompt words that meet the optimization stop condition are obtained, so as to ensure the matching of the target prompt words with the specific tasks, so that the prompt words can be used to feedback more accurate results to the user in the application stage.
[0104] Corresponding to the above method embodiment, this specification also provides a text processing method embodiment, Figure 3 FIG. 1 is a flowchart of a text processing method provided by an embodiment of the present specification. Figure 3 As shown, the method is applied to the server, including:
[0105] Step S302, receiving a question text submitted by the client for the target language model;
[0106] Step S304, selecting a prompt word to be applied from a target prompt word set associated with the target language model according to the question text, wherein the prompt words included in the target prompt word set are generated by the above method;
[0107] Step S306, updating the question text based on the prompt word to be applied, and inputting the updated question text into the target language model for processing to obtain an answer text;
[0108] Step S308: Feedback the answer text to the client.
[0109] Specifically, the text processing method provided in this embodiment is applied to the server. After the target prompt word is obtained through optimization by the above method and added to the prompt word set, for the question text submitted by the client, the prompt word to be applied that matches the question text can be selected from the prompt word set. By updating the question text with the prompt word to be applied, the model input feature can be obtained, and it is input into the target language model for processing, so that the answer text corresponding to the question text can be accurately generated and fed back to the client.
[0110] In summary, by adopting the above prompt word generation method to construct a prompt word set that matches the target language model, it is convenient to select prompt words that match the current user needs from the set to construct the model input during the application stage, thereby improving the accuracy of the model generating the answer text.
[0111] The following combination Figure 4 , taking the application of the text processing method provided in this specification in the entity extraction scenario as an example, the text processing method is further described. Figure 4 A flowchart of a text processing method provided by an embodiment of the present specification is shown, which specifically includes the following steps.
[0112] Step S402: determining a sample set in response to a prompt word generation request submitted for a target language model.
[0113] Step S404: determine sample stratification information according to a preset stratified sampling strategy, and perform stratification processing on the sample set based on the sample stratification information to obtain multiple sample subsets.
[0114] Step S406, determining label information corresponding to the candidate samples in each sample subset, and performing representative detection on each sample subset according to the label information.
[0115] Step S408: When it is determined according to the representative detection result that the multiple sample subsets meet the deduplication condition, deduplication processing is performed on the multiple sample subsets respectively.
[0116] Step S410 , sampling is performed in the multiple sample subsets after deduplication, and multiple representative samples are determined according to the sampling results.
[0117] Step S412: Input the plurality of representative samples and the structured prompt information respectively corresponding to the plurality of representative samples into a prompt word generation model for processing, so as to obtain initial prompt words respectively corresponding to the plurality of representative samples.
[0118] Among them, the determination of structured prompt information corresponding to representative samples associated with the same subtask after stratification includes: constructing candidate prompt words for the target representative samples according to a preset meta-prompt strategy, and determining the prompt word scores corresponding to the candidate prompt words; loading the target error samples associated with the target representative samples, and determining the error prediction results corresponding to the target error samples and the error prompt information corresponding to the error prediction results; based on the candidate prompt words, prompt word scores, target error samples, error prediction results and error prompt information, constructing the structured prompt information corresponding to the target representative samples.
[0119] Step S414, obtaining a validation set associated with the target language model.
[0120] Step S416: Use the verification set to evaluate the initial prompt words corresponding to the multiple representative samples to obtain a verification score corresponding to each initial prompt word.
[0121] Step S418: sorting the verification scores, and selecting a set number of initial prompt words as intermediate prompt words according to the sorting result.
[0122] Step S420 , determining a plurality of verification samples corresponding to the evaluation stage of the intermediate prompt word in the verification set, and extracting an erroneous verification sample associated with the intermediate prompt word from the plurality of verification samples.
[0123] Step S422: determining prompt word optimization information in response to the prompt word generation request, and determining historical verification information associated with the prompt word optimization information.
[0124] Step S424: construct evaluation information associated with the intermediate prompt word based on the error verification sample, the representative sample corresponding to the intermediate prompt word, and the historical verification information.
[0125] Step S426: construct prompt word optimization information according to the evaluation information and the intermediate prompt words.
[0126] Step S428: input the prompt word optimization information into the prompt word optimization model for processing to obtain prompt word prediction information corresponding to the prompt word optimization information.
[0127] Step S430: compare the prompt word prediction information with the prompt word standard information corresponding to the prompt word optimization information, and optimize the intermediate prompt word according to the comparison result.
[0128] Step S432, determining the number of iterations corresponding to the optimized intermediate prompt word, and if the number of iterations meets a preset iteration number threshold, using the optimized intermediate prompt word as the target prompt word.
[0129] After that, the target prompt word can be added to the target prompt word set matched by the target language model. When the question text submitted by the client for the target language model is received, the prompt word to be applied is selected from the target prompt word set associated with the target language model according to the question text, and the question text is updated based on the prompt word to be applied, and the updated question text is input into the target language model for processing, and the entity extraction result can be obtained according to the processing result, and then the entity extraction result is fed back to the client, so that the client can use the entity extraction result for subsequent processing, such as data sorting, summary generation, etc.
[0130] In summary, in order to quickly and accurately obtain prompt words that match specific tasks, and to ensure that the prompt words converge in the correct direction while accelerating the convergence speed, a sample set can be determined in response to a prompt word generation request submitted for a target language model. In order to ensure the accuracy of subsequent prompt word generation, the sample set can be subjected to stratified sampling processing according to a preset stratified sampling strategy, so as to determine multiple representative samples according to the stratified sampling processing results; on this basis, multiple representative samples and structured prompt information corresponding to multiple representative samples can be input into a prompt word generation model for processing, so as to achieve the use of the prompt word generation model to first predict the initial prompt words corresponding to each representative sample; the initial prompt words obtained at this time are only initial recommendation results, and their accuracy may be low, so they can be further optimized. At this time, the intermediate prompt words can be extracted from the initial prompt words corresponding to the multiple representative samples, and the evaluation information associated with the intermediate prompt words can be determined; then, the intermediate prompt words can be optimized according to the evaluation information, so as to achieve convergence in the correct convergence direction based on the initial prompt words, until the target prompt words that meet the optimization stop condition are obtained, so as to ensure the matching of the target prompt words with the specific tasks, so that the prompt words can be used to feedback more accurate results to the user in the application stage.
[0131] Corresponding to the above method embodiment, this specification also provides a prompt word generating device embodiment, Figure 5 FIG. 1 shows a schematic diagram of a prompt word generating device provided by an embodiment of the present specification. Figure 5 As shown, the device comprises:
[0132] The determination module 502 is configured to determine a sample set in response to a prompt word generation request submitted for a target language model, perform stratified sampling processing on the sample set according to a preset stratified sampling strategy, and determine a plurality of representative samples according to the stratified sampling processing result;
[0133] An input module 504 is configured to input the plurality of representative samples and the structured prompt information respectively corresponding to the plurality of representative samples into a prompt word generation model for processing, so as to obtain initial prompt words respectively corresponding to the plurality of representative samples;
[0134] An extraction module 506 is configured to extract intermediate prompt words from the initial prompt words corresponding to the plurality of representative samples, and determine evaluation information associated with the intermediate prompt words;
[0135] The optimization module 508 is configured to optimize the intermediate prompt word according to the evaluation information until a target prompt word that meets the optimization stop condition is obtained.
[0136] In an optional embodiment, the determining module 502 is further configured to:
[0137] Determine sample stratification information according to a preset stratified sampling strategy, and perform stratification processing on the sample set based on the sample stratification information to obtain multiple sample subsets; determine label information corresponding to candidate samples in each sample subset, and perform representative detection on each sample subset according to the label information; when it is determined according to the representative detection result that the multiple sample subsets meet the deduplication condition, perform deduplication processing on the multiple sample subsets respectively; perform sampling in the multiple sample subsets after deduplication, and determine multiple representative samples according to the sampling results.
[0138] In an optional embodiment, determining the structured prompt information corresponding to any one of the plurality of representative samples includes:
[0139] According to the preset meta-prompt strategy, candidate prompt words are constructed for the target representative sample, and the prompt word score corresponding to the candidate prompt word is determined; the target error sample associated with the target representative sample is loaded, and the error prediction result corresponding to the target error sample and the error prompt information corresponding to the error prediction result are determined; based on the candidate prompt words, the prompt word score, the target error sample, the error prediction result and the error prompt information, structured prompt information corresponding to the target representative sample is constructed.
[0140] In an optional embodiment, the extraction module 506 is further configured to:
[0141] Acquire a verification set associated with the target language model; determine representative samples of at least two categories of tasks from the multiple representative samples, and determine initial prompt words corresponding to the representative samples of the at least two categories of tasks; use the verification set to evaluate the initial prompt words corresponding to the representative samples of the at least two categories of tasks, and obtain verification scores corresponding to the initial prompt words of each category of tasks; sort the verification scores, and select a set number of initial prompt words as intermediate prompt words according to the sorting results.
[0142] In an optional embodiment, the extraction module 506 is further configured to:
[0143] Determine a plurality of verification samples corresponding to the verification set in the evaluation stage of the intermediate prompt word, and extract an erroneous verification sample associated with the intermediate prompt word from the plurality of verification samples; determine prompt word optimization information in response to the prompt word generation request, and determine historical verification information associated with the prompt word optimization information; construct evaluation information associated with the intermediate prompt word based on the erroneous verification samples, representative samples corresponding to the intermediate prompt word, and the historical verification information.
[0144] In an optional embodiment, the optimization module 508 is further configured to:
[0145] Construct prompt word optimization information according to the evaluation information and the intermediate prompt word; input the prompt word optimization information into the prompt word optimization model for processing to obtain prompt word prediction information corresponding to the prompt word optimization information; compare the prompt word prediction information with the prompt word standard information corresponding to the prompt word optimization information, and optimize the intermediate prompt word according to the comparison result until a target prompt word that meets the optimization stop condition is obtained.
[0146] In an optional embodiment, the optimization module 508 is further configured to:
[0147] The prompt word prediction information is compared with the prompt word standard information corresponding to the prompt word optimization information, and the intermediate prompt word is optimized according to the comparison result; the number of iterations corresponding to the optimized intermediate prompt word is determined, if the number of iterations meets a preset iteration number threshold; or, the optimized intermediate prompt word is verified, and if the comparison relationship between the verification result and the historical verification result meets the preset comparison condition, it is determined that the intermediate prompt word meets the optimization stop condition, and the optimized intermediate prompt word is used as the target prompt word.
[0148] The prompt word generation device provided in this embodiment can quickly and accurately obtain prompt words matching specific tasks, and ensure that the prompt words converge in the correct direction while accelerating the convergence speed. The sample set can be determined in response to the prompt word generation request submitted for the target language model. In order to ensure the accuracy of subsequent prompt word generation, the sample set can be subjected to stratified sampling processing according to the preset stratified sampling strategy, so as to determine multiple representative samples according to the stratified sampling processing results; on this basis, the multiple representative samples and the structured prompt information corresponding to the multiple representative samples can be input into the prompt word generation model for processing, so as to use the prompt word generation model to predict the initial prompt words corresponding to each representative sample; the initial prompt words obtained at this time are only the initial recommendation results, and their accuracy may be low, so they can be further optimized. At this time, the intermediate prompt words can be extracted from the initial prompt words corresponding to the multiple representative samples, and the evaluation information associated with the intermediate prompt words can be determined; then the intermediate prompt words can be optimized according to the evaluation information, so as to achieve convergence in the correct convergence direction based on the initial prompt words, until the target prompt words that meet the optimization stop condition are obtained, so as to ensure the matching of the target prompt words with the specific tasks, so that the prompt words can be used to feedback more accurate results to the user in the application stage.
[0149] The above is a schematic scheme of a prompt word generation device of this embodiment. It should be noted that the technical scheme of the prompt word generation device and the technical scheme of the prompt word generation method described above are of the same concept, and the details not described in detail in the technical scheme of the prompt word generation device can be found in the description of the technical scheme of the prompt word generation method described above.
[0150] Corresponding to the above method embodiment, this specification also provides a text processing device embodiment, Figure 6 FIG. 1 shows a schematic diagram of the structure of a text processing device provided by an embodiment of the present specification. Figure 6 As shown, the device is applied to the server, including:
[0151] A text receiving module 602 is configured to receive a question text submitted by a client for a target language model;
[0152] A prompt word selection module 604 is configured to select prompt words to be applied from a target prompt word set associated with the target language model according to the question text, wherein the prompt words included in the target prompt word set are generated by the above method;
[0153] The text updating module 606 is configured to update the question text based on the prompt word to be applied, and input the updated question text into the target language model for processing to obtain an answer text;
[0154] The feedback text module 608 is configured to feed back the answer text to the client.
[0155] The above is a schematic scheme of a text processing device of this embodiment. It should be noted that the technical scheme of the text processing device and the technical scheme of the above text processing method belong to the same concept, and the details not described in detail in the technical scheme of the text processing device can be referred to the description of the technical scheme of the above text processing method.
[0156] Figure 7 The block diagram of a computing device 700 according to an embodiment of the present specification is shown. The components of the computing device 700 include but are not limited to a memory 710 and a processor 720. The processor 720 is connected to the memory 710 via a bus 730, and the database 750 is used to store data.
[0157] The computing device 700 also includes an access device 740 that enables the computing device 700 to communicate via one or more networks 760. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 740 may include one or more of any type of network interface (e.g., a network interface card (NIC)) of wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a world-wide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, and a near field communication (NFC).
[0158] In one embodiment of the present specification, the above components of the computing device 700 and Figure 7 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 7 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0159] The computing device 700 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 700 may also be a mobile or stationary server.
[0160] The processor 720 is used to execute the following computer executable instructions, which, when executed by the processor, implement the steps of the above-mentioned prompt word generation method or text processing method.
[0161] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the above-mentioned prompt word generation method or text processing method belong to the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the above-mentioned prompt word generation method or text processing method.
[0162] An embodiment of the present specification further provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the steps of the above-mentioned prompt word generation method or text processing method.
[0163] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the above-mentioned prompt word generation method or text processing method belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the above-mentioned prompt word generation method or text processing method.
[0164] An embodiment of the present specification also provides a computer program product, including a computer program or instructions, which implement the steps of the above-mentioned prompt word generation method or text processing method when executed by a processor.
[0165] The above is a schematic scheme of a computer program product of this embodiment. It should be noted that the technical scheme of the computer program product and the technical scheme of the above-mentioned prompt word generation method or text processing method belong to the same concept, and the details not described in detail in the technical scheme of the computer program product can be referred to the description of the technical scheme of the above-mentioned prompt word generation method or text processing method.
[0166] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0167] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0168] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0169] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0170] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that technicians in the relevant technical field can understand and use this specification well.
Claims
1. A prompt word generation method, It is characterized in that include: Determining a sample set in response to a prompt word generation request submitted for a target language model, performing stratified sampling processing on the sample set according to a preset stratified sampling strategy, and determining a plurality of representative samples according to the stratified sampling processing result; Input the plurality of representative samples and the structured prompt information respectively corresponding to the plurality of representative samples into the prompt word generation model for processing, and obtain the initial prompt words respectively corresponding to the plurality of representative samples, wherein the determination of the structured prompt information corresponding to any one of the plurality of representative samples includes: constructing candidate prompt words for the target representative sample according to a preset meta-prompt strategy, and determining the prompt word score corresponding to the candidate prompt word; loading the target error sample associated with the target representative sample, and determining the error prediction result corresponding to the target error sample and the error prompt information corresponding to the error prediction result; constructing the structured prompt information corresponding to the target representative sample based on the candidate prompt words, the prompt word score, the target error sample, the error prediction result and the error prompt information; Extracting an intermediate prompt word from the initial prompt words corresponding to the multiple representative samples, determining multiple verification samples corresponding to the verification set associated with the target language model for the evaluation stage of the intermediate prompt word, and extracting an erroneous verification sample associated with the intermediate prompt word from the multiple verification samples; determining prompt word optimization information in response to the prompt word generation request, and determining historical verification information associated with the prompt word optimization information; constructing evaluation information associated with the intermediate prompt word based on the erroneous verification sample, the representative sample corresponding to the intermediate prompt word, and the historical verification information; The intermediate prompt word is optimized according to the evaluation information until a target prompt word that meets the optimization stop condition is obtained.
2. The method for generating prompt words according to claim 1, It is characterized in that The step of performing stratified sampling processing on the sample set according to a preset stratified sampling strategy and determining a plurality of representative samples according to the stratified sampling processing result includes: Determine sample stratification information according to a preset stratified sampling strategy, and perform stratification processing on the sample set based on the sample stratification information to obtain multiple sample subsets; Determine label information corresponding to the candidate samples in each sample subset, and perform representative detection on each sample subset according to the label information; When it is determined according to the representative detection result that the multiple sample subsets meet the deduplication condition, deduplication processing is performed on the multiple sample subsets respectively; Sampling is performed on multiple sample subsets after deduplication, and multiple representative samples are determined according to the sampling results.
3. The method for generating prompt words according to claim 1, It is characterized in that The step of extracting the intermediate prompt words from the initial prompt words respectively corresponding to the plurality of representative samples comprises: Obtaining a validation set associated with the target language model; Determining task representative samples of at least two types of tasks from the multiple representative samples, and determining initial prompt words corresponding to the task representative samples of the at least two types of tasks; Using the verification set, evaluating the initial prompt words corresponding to the task representative samples of the at least two types of tasks, and obtaining the verification score corresponding to the initial prompt words of each type of task; The verification scores are sorted, and a set number of initial prompt words are selected as intermediate prompt words according to the sorting result.
4. The method for generating prompt words according to claim 1, It is characterized in that The step of optimizing the intermediate prompt word according to the evaluation information until a target prompt word that satisfies the optimization stop condition is obtained includes: Constructing prompt word optimization information according to the evaluation information and the intermediate prompt word; Inputting the prompt word optimization information into a prompt word optimization model for processing to obtain prompt word prediction information corresponding to the prompt word optimization information; The prompt word prediction information is compared with the prompt word standard information corresponding to the prompt word optimization information, and the intermediate prompt word is optimized according to the comparison result until a target prompt word that meets the optimization stop condition is obtained.
5. The method for generating prompt words according to claim 4, It is characterized in that The step of comparing the prompt word prediction information with the prompt word standard information corresponding to the prompt word optimization information, and optimizing the intermediate prompt word according to the comparison result until a target prompt word that meets the optimization stop condition is obtained includes: Comparing the prompt word prediction information with the prompt word standard information corresponding to the prompt word optimization information, and optimizing the intermediate prompt word according to the comparison result; Determine the number of iterations corresponding to the optimized intermediate prompt word, if the number of iterations meets the preset iteration number threshold; or, verify the optimized intermediate prompt word, if the comparison relationship between the verification result and the historical verification result meets the preset comparison condition, determine that the intermediate prompt word meets the optimization stop condition, and use the optimized intermediate prompt word as the target prompt word.
6. A text processing method, It is characterized in that Applied to the server, including: Receive question text submitted by the client for the target language model; Selecting a prompt word to be applied from a target prompt word set associated with the target language model according to the question text, wherein the prompt words included in the target prompt word set are generated by the method according to any one of claims 1 to 5; The question text is updated based on the prompt word to be applied, and the updated question text is input into the target language model for processing to obtain an answer text; The answer text is fed back to the client.
7. A computing device, It is characterized in that include: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the method described in any one of claims 1 to 6 are implemented.
8. A computer-readable storage medium, It is characterized in that It stores computer executable instructions, which, when executed by a processor, implement the steps of the method described in any one of claims 1 to 6.
9. A computer program product, It is characterized in that The method comprises a computer program or an instruction, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 6.
