Prompt word template generation method and device, electronic equipment, and storage medium
By acquiring the target task dataset and initial prompt word template, and combining sample data and text descriptions to optimize the prompt word template, the problem that the output quality of large language models depends on the prompt word design is solved, and efficient and accurate prompt word template optimization is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING BAIDU NETCOM SCI & TECH CO LTD
- Filing Date
- 2024-09-11
- Publication Date
- 2026-07-24
AI Technical Summary
The output quality of Large Language Models (LLMs) is highly dependent on the design of input prompts, resulting in significant differences in accuracy, fluency, and relevance of the generated results under the same task. Existing technologies struggle to efficiently optimize prompt templates.
By acquiring the dataset and initial prompt word template for the target task, and combining sample data and text descriptions, the initial answer is determined and evaluated. Based on the evaluation results and text descriptions, the prompt word template is optimized to generate the target prompt word template.
It enables automatic optimization of prompt word templates, improving optimization efficiency and accuracy, and enhancing the quality of optimized prompt word templates.
Smart Images

Figure CN119443094B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to the fields of artificial intelligence technology such as natural language processing, large language models, and deep learning. Specifically, it relates to a method, apparatus, electronic device, and storage medium for generating prompt word templates. Background Technology
[0002] In recent years, Large Language Models (LLMs) have gained widespread attention in the field of natural language processing. Through large-scale pre-training and fine-tuning, LLMs have demonstrated excellent performance on various tasks. However, research shows that the output quality of LLMs largely depends on the design of the input prompts. Even for the same task, different input prompts can lead to significant differences in the accuracy, fluency, and relevance of the generated results. Therefore, prompt design and optimization have become the core issues of prompt engineering. Summary of the Invention
[0003] This disclosure provides a method, apparatus, electronic device, and storage medium for generating prompt word templates.
[0004] According to a first aspect of this disclosure, a method for generating a prompt word template is provided, comprising:
[0005] Obtain the first dataset and initial prompt word template corresponding to the target task, wherein the first dataset includes sample data, text descriptions corresponding to the sample data, and reference answers;
[0006] Based on the initial prompt word template, the sample data, and the corresponding text description, determine the first answer corresponding to the sample data;
[0007] Based on the reference answer and the first answer, determine the first evaluation result corresponding to the first answer;
[0008] Based on the first evaluation result and the text description, the initial prompt word template is optimized to obtain the target prompt word template.
[0009] According to a second aspect of this disclosure, an apparatus for generating prompt word templates is provided, comprising:
[0010] The acquisition module is used to acquire the first dataset and initial prompt word template corresponding to the target task, wherein the first dataset includes sample data, text descriptions corresponding to the sample data, and reference answers;
[0011] The first determining module is used to determine the first answer corresponding to the sample data based on the initial prompt word template, the sample data, and the corresponding text description;
[0012] The second determining module is used to determine the first evaluation result corresponding to the first answer based on the reference answer and the first answer;
[0013] The optimization module is used to optimize the initial prompt word template based on the first evaluation result and the text description to obtain the target prompt word template.
[0014] According to a third aspect of this disclosure, an electronic device is provided, comprising:
[0015] At least one processor; and
[0016] A memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the prompt word template generation method as described in the first aspect.
[0018] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided that stores computer instructions for causing the computer to perform a prompt word template generation method as described in the first aspect.
[0019] According to a fifth aspect of this disclosure, a computer program product is provided, including computer instructions that, when executed by a processor, implement the steps of the prompt word template generation method as described in the first aspect.
[0020] The method, apparatus, electronic device, and storage medium for generating prompt word templates provided in this disclosure have the following beneficial effects:
[0021] In this embodiment, based on the initial prompt word template, sample data, and corresponding text description, a first answer corresponding to the sample data is determined. Then, based on the reference answer corresponding to the sample data and the first answer, a first evaluation result corresponding to the first answer is determined. Finally, based on the first evaluation result and text description, the initial prompt word template is optimized to obtain the target prompt word template. Therefore, by comparing the difference between the first answer and the reference answer corresponding to the sample data under the initial prompt word template, defects in the initial prompt word template can be identified. Then, combined with the text description corresponding to the sample data, the initial prompt word template can be optimized, thereby achieving automatic optimization of the prompt word template, improving the efficiency and accuracy of prompt word template optimization, and ultimately improving the quality of the optimized target prompt word template.
[0022] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0023] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0024] Figure 1 This is a flowchart illustrating a method for generating a prompt word template according to an embodiment of the present disclosure;
[0025] Figure 2 This is a flowchart illustrating a method for generating a prompt word template according to yet another embodiment of this disclosure;
[0026] Figure 3 This is a flowchart illustrating a method for generating a prompt word template according to yet another embodiment of this disclosure;
[0027] Figure 4 This is a schematic diagram of a prompt word template generation device provided according to an embodiment of the present disclosure;
[0028] Figure 5 This is a block diagram of an electronic device used to implement the prompt word template generation method of the embodiments of this disclosure. Detailed Implementation
[0029] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0030] This disclosure relates to the fields of artificial intelligence technologies such as large language models, natural language processing, and deep learning.
[0031] Artificial Intelligence (AI) is a new technical science that studies and develops theories, methods, technologies, and application systems to simulate, extend, and expand human intelligence.
[0032] Large Language Models (LLMs), also known as large models, are deep learning models trained on massive amounts of text data. They can not only generate natural language text, but also deeply understand the meaning of text and handle various natural language tasks, such as text summarization, question answering, and translation.
[0033] Natural Language Processing (NLP) is an important field within computer science and artificial intelligence. It studies the theories and methods for enabling effective communication between humans and computers using natural language. NLP is a science that integrates linguistics, computer science, and mathematics. It does not simply study natural language in general, but rather focuses on developing computer systems, especially the software systems, that can effectively achieve natural language communication.
[0034] Deep learning learns the inherent patterns and hierarchical representations of sample data. The information gained during this learning process greatly aids in interpreting data such as text, images, and sound. The ultimate goal of deep learning is to enable machines to possess analytical and learning capabilities similar to humans, allowing them to recognize data such as text, images, and sound.
[0035] The acquisition, storage, and application of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0036] The following description, with reference to the accompanying drawings, outlines a method, apparatus, electronic device, and storage medium for generating prompt word templates according to embodiments of the present disclosure.
[0037] It should be noted that the execution subject of the prompt word template generation method in this embodiment is the prompt word template generation device. This device can be implemented by software and / or hardware. This device can be configured in an electronic device, which may include, but is not limited to, a terminal, a server, etc.
[0038] Figure 1 This is a flowchart illustrating a method for generating a prompt word template according to an embodiment of the present disclosure.
[0039] like Figure 1 As shown, the method for generating this prompt word template includes:
[0040] S101, obtain the first dataset and initial prompt word template corresponding to the target task. The first dataset includes sample data, text descriptions of the sample data, and reference answers.
[0041] The target task can be an image recognition task, an image description task, a text summarization task, etc. This disclosure does not limit it.
[0042] The initial prompt word template is a prompt word template that is generated in advance based on the target task and is yet to be further optimized.
[0043] In some embodiments, the sample data can be at least one of the following: text data, image data, and audio data. Therefore, prompt word templates corresponding to the target task can be generated for multimodal data, improving the versatility of the prompt word template generation method.
[0044] In some embodiments, the text description is textual information associated with the sample data. For example, when the target task describes an image and the sample data is an image, the corresponding text description could be a topic.
[0045] In some embodiments, the reference answer can be the answer corresponding to the sample data under the target task. For example, if the target task is image description and the sample data is an image, the corresponding reference answer can be a manually determined description of the image.
[0046] In some embodiments, the first dataset may contain one or more sample data. This disclosure does not limit this.
[0047] S102. Based on the initial prompt word template, sample data, and corresponding text description, determine the first answer corresponding to the sample data.
[0048] In some embodiments, text descriptions can be filled into preset positions in the initial prompt word template to obtain the first prompt word corresponding to the sample data. Then, the first prompt word and the sample data are input into the first large model to obtain the first answer corresponding to the sample data. Thus, the first answer corresponding to the sample data under the initial prompt word template can be obtained quickly.
[0049] The first answer can be the first answer corresponding to the sample data generated by the large model based on the first prompt word and sample data.
[0050] In some embodiments, the first major model may also be referred to as the generator.
[0051] In some embodiments, the first large model can be obtained by fine-tuning an existing large language model based on the target task.
[0052] S103. Based on the reference answer and the first answer, determine the first evaluation result corresponding to the first answer.
[0053] In some embodiments, when the target task is a preset task, a reference answer, a first answer, and a second prompt can be input into a second large model to obtain a first evaluation result. The second prompt is used to instruct the second large model to evaluate the first answer based on the reference answer. Thus, the first evaluation result corresponding to the first answer can be determined quickly and accurately based on the second large model.
[0054] The preset tasks can be those with relatively complex reference answers. For example, tasks with longer answers, such as image description tasks or text summary tasks.
[0055] It should be noted that text comparison is a relatively common task, and existing large-scale models already possess this capability and can accurately compare two texts. Therefore, existing large-scale models capable of text comparison can be directly identified as the second largest model.
[0056] In some embodiments, when the target task is not a preset task, the first answer can also be evaluated based on a simple logical evaluation function. For example, if the content of the first answer is relatively simple, such as when the target task is a classification task and the first answer and the reference answer are the probabilities of belonging to each category, then the probabilities of the first answer and the reference answer can be directly compared based on the logical function to obtain the first evaluation result.
[0057] S104. Based on the first evaluation result and text description, optimize the initial prompt word template to obtain the target prompt word template.
[0058] In some embodiments, a first evaluation result, a text description, an initial prompt word template, and a third prompt word can be input into a third model to obtain a target prompt word template. The third prompt word is used to prompt the third model to optimize the initial prompt word template based on the first evaluation result and the corresponding text description.
[0059] In some embodiments, the third major model, the second major model, and the first major model may be the same major model or different major models. This disclosure does not limit this.
[0060] In some embodiments, the target sample data indicating an error in the first evaluation result can be identified first. Then, the first evaluation result, text description, initial prompt word template, and third prompt word corresponding to the target sample data are input into the third model to obtain the target prompt word template. The third prompt word is used to prompt the third model to optimize the initial prompt word template based on the first evaluation result and the corresponding text description.
[0061] In some embodiments, if the first evaluation result contains a question distinguishing between the first answer and the reference answer, then the first evaluation result indicates an error. It should be noted that only the first evaluation result indicating an error is valuable for optimizing the initial prompt word template. Therefore, it is necessary to first determine the target sample data where the first evaluation result indicates an error, and then optimize the initial prompt word template based on the corresponding first evaluation result.
[0062] In some embodiments, target sample data indicating an error in the first evaluation result is identified. Then, when there are at least two target sample data points, the text description associated with the first evaluation result is determined based on the first evaluation result and text description corresponding to the target sample data. Subsequently, the initial prompt word template, the third prompt word, the first evaluation result, and the text description associated with the first evaluation result are input into a third large model to obtain a target prompt word template. The third prompt word is used to prompt the third large model to optimize the initial prompt word template based on the first evaluation result and the corresponding text description. Therefore, when there are multiple first evaluation results, the association between the first evaluation result and the text description is communicated to the large model, allowing the target prompt word template generated by the large model to be applicable to sample data corresponding to different text descriptions.
[0063] In this embodiment, based on the initial prompt word template, sample data, and corresponding text description, a first answer corresponding to the sample data is determined. Then, based on the reference answer corresponding to the sample data and the first answer, a first evaluation result corresponding to the first answer is determined. Finally, based on the first evaluation result and text description, the initial prompt word template is optimized to obtain the target prompt word template. Therefore, by comparing the difference between the first answer and the reference answer corresponding to the sample data under the initial prompt word template, defects in the initial prompt word template can be identified. Then, combined with the text description corresponding to the sample data, the initial prompt word template can be optimized, thereby achieving automatic optimization of the prompt word template, improving the efficiency and accuracy of prompt word template optimization, and ultimately improving the quality of the optimized target prompt word template.
[0064] Figure 2 This is a flowchart illustrating a method for generating a prompt word template according to yet another embodiment of this disclosure;
[0065] like Figure 2 As shown, the method for generating this prompt word template includes:
[0066] S201, Obtain the first dataset and initial prompt word template corresponding to the target task. The first dataset includes sample data, text descriptions corresponding to the sample data, and reference answers.
[0067] S202. Based on the initial prompt word template, sample data, and corresponding text description, determine the first answer corresponding to the sample data.
[0068] S203. Based on the reference answer and the first answer, determine the first evaluation result corresponding to the first answer.
[0069] S204. Based on the first evaluation result and text description, optimize the initial prompt word template to obtain the target prompt word template.
[0070] The specific implementation of steps S201 to S204 can be found in the detailed descriptions of other embodiments in this disclosure, and will not be repeated here.
[0071] S205. Based on the target prompt word template, sample data, and corresponding text description, determine the second answer corresponding to the sample data.
[0072] In some embodiments, text descriptions can be filled into preset positions in the target prompt word template to obtain new prompt words corresponding to the sample data. Then, the new prompt words and sample data are input into the first large model to obtain the second answer corresponding to the sample data.
[0073] The second answer can be the first answer generated by the large model based on the sample data and the new prompt words corresponding to the sample data.
[0074] S206. Based on the second answer and the reference answer, determine the second evaluation result corresponding to the second answer.
[0075] In some embodiments, a reference answer, a second answer, and a second prompt word can be input into a second large model to obtain a second evaluation result, wherein the second prompt word is used to prompt the second large model to evaluate the second answer based on the reference answer.
[0076] S207. Determine the prompt word template to be optimized from the target prompt word template and the initial prompt word template.
[0077] In some embodiments, the optimal prompt word template can be determined from the target prompt word template and the initial prompt word template, and used as the prompt word template to be optimized. Thus, the optimal prompt word template can be optimized in each iteration.
[0078] In some embodiments, a first score corresponding to an initial prompt word template and a second score corresponding to a target prompt word template can be determined. Then, the prompt word template with the highest score between the first and second scores is selected as the prompt word template to be optimized. A higher score indicates a better quality prompt word template. Therefore, based on the scores of each prompt word template, a higher-quality prompt word template can be accurately determined as the prompt word template to be optimized.
[0079] In some embodiments, a first score corresponding to the initial prompt word template can be determined based on the first evaluation result corresponding to each sample data, and a second score corresponding to the target prompt word template can be determined based on the second evaluation result corresponding to each sample data.
[0080] In some embodiments, a third score can be determined for each first answer based on the difference between the first answer and the reference answer for each sample data point. Then, a first score for the initial prompt word template can be determined based on the third score for each first answer. Thus, the first score for the initial prompt word template can be comprehensively judged based on the scores of the first answers corresponding to each sample data point under the first prompt word template, making the determined first score for the initial prompt word template more accurate.
[0081] In some embodiments, the reference answer, the first answer, and the second prompt word can be output to the second large model to obtain the first evaluation result and the first score. The second prompt word is used to prompt the second large model to evaluate the first answer based on the reference answer and output the score for the first answer. Therefore, the first score can be obtained simultaneously with the first evaluation result, improving the efficiency of optimizing the initial prompt word objective.
[0082] In some embodiments, a third score corresponding to the first answer may also be determined based on the similarity between the first answer and the reference answer.
[0083] In some embodiments, when there are multiple sample data, the mean, sum, variance, etc. of the third scores corresponding to multiple first answers can be determined as the first score corresponding to the initial prompt word template.
[0084] In some embodiments, a fourth score is determined for each second answer based on the difference between the second answer and the reference answer for each sample data point. Then, a second score for the target prompt word template is determined based on the fourth score for each second answer. Thus, the second score for the target prompt word template can be comprehensively judged based on the scores of the second answers for each sample data point under the target prompt word template, making the determined second score for the target prompt word template more accurate.
[0085] In some embodiments, the reference answer, the second answer, and the second prompt word are output to the second large model to obtain a second evaluation result and a second score. The second prompt word prompts the second large model to evaluate the second answer based on the reference answer and output the score for the second answer. Therefore, the first score can be obtained simultaneously with the first evaluation result, improving the efficiency of optimizing the initial prompt word objective.
[0086] In some embodiments, a third score corresponding to the first answer may also be determined based on the similarity between the first answer and the reference answer.
[0087] In some embodiments, when there are multiple sample data, the mean, sum, variance, etc. of the third scores corresponding to multiple first answers can be determined as the first score corresponding to the initial prompt word template.
[0088] S208. Based on the second evaluation results and text description, the prompt word template to be optimized is optimized to obtain the optimized target prompt word template.
[0089] In some embodiments, the second evaluation result, text description, prompt word template to be optimized, and a third prompt word can be input into a third model to obtain the optimized target prompt word template. The third prompt word is used to prompt the third model to optimize the prompt word template based on the second evaluation result and the corresponding text description.
[0090] In some embodiments, after determining the optimized target prompt word template, a third evaluation result corresponding to the optimized target prompt word template can also be determined. From the optimized target prompt word template and the prompt word template to be optimized, a prompt word template to be further optimized can be determined. Based on the third evaluation result and text description, the prompt word template to be further optimized is optimized. This process is iterated until a preset stopping condition is reached.
[0091] The preset stopping condition can be reaching a preset number of iterations, reaching a preset score for the score corresponding to the optimized prompt word template, or the difference between the scores corresponding to the prompt word templates after multiple consecutive iterations of optimization being less than a difference threshold.
[0092] In some embodiments, when the prompt word template to be optimized is the initial prompt word template, the first evaluation result and the second evaluation result corresponding to the sample data are merged to obtain the third evaluation result corresponding to the sample data. Then, based on the third evaluation result and the text description, the initial prompt word is optimized to obtain the optimized target prompt word template. This allows for a more comprehensive identification of the problems existing in the initial prompt word template, thereby enabling accurate optimization of the initial prompt word template and improving the quality of the optimized target prompt word template.
[0093] In this embodiment, after optimizing the initial prompt word template to obtain the target prompt word template, a second answer corresponding to the sample data can be determined based on the target prompt word template, sample data, and corresponding text description. A second evaluation result corresponding to the second answer is determined based on the second answer and a reference answer. A prompt word template to be optimized is then determined from the target prompt word template and the initial prompt word template. Finally, based on the second evaluation result and text description, the prompt word template to be optimized is further optimized to obtain the optimized target prompt word template. Therefore, the current best-quality prompt word template can be optimized based on the evaluation result corresponding to the latest prompt word template. This allows for optimization of the current best-quality prompt word template based on potential defects, further improving the accuracy of the optimized prompt word template.
[0094] Figure 3 This is a flowchart illustrating a method for generating a prompt word template according to yet another embodiment of this disclosure;
[0095] like Figure 3 As shown, the method for generating this prompt word template includes:
[0096] S301, Obtain the first dataset and initial prompt word template corresponding to the target task. The first dataset includes sample data, text descriptions corresponding to the sample data, and reference answers.
[0097] S302. Based on the initial prompt word template, sample data, and corresponding text description, determine the first answer corresponding to the sample data.
[0098] S303. Based on the reference answer and the first answer, determine the first evaluation result corresponding to the first answer.
[0099] S304, Determine that the first evaluation result indicates an erroneous target sample data.
[0100] The specific implementation of steps S301 to S304 can be found in the detailed descriptions of other embodiments in this disclosure, and will not be repeated here.
[0101] S305, when there are at least two target sample data, cluster the first evaluation results corresponding to the target sample data to determine the target evaluation result corresponding to the initial prompt word template.
[0102] It should be noted that when there are at least two target sample data points, there may be multiple target sample data points with the same, similar, or partially overlapping first evaluation results. Therefore, the first evaluation results can be clustered to obtain one or more different target evaluation results corresponding to the initial prompt word template. This can reduce the input of the third model, thereby reducing the amount of data processed by the third model and improving the optimization efficiency of the initial prompt word template.
[0103] S306, Based on the target sample data to which the first evaluation result corresponding to the target evaluation result belongs, and the text description corresponding to the target sample data, determine the text description associated with the target evaluation result.
[0104] In this embodiment of the disclosure, a correlation can be established between the target evaluation result to which the first evaluation result belongs and the text description corresponding to the same sample data. This allows the correlation between the target evaluation result and the text description to be input into the third major model.
[0105] S307. Input the initial prompt word template, the third prompt word, the target evaluation result, and the text description associated with the target evaluation result into the third language model to obtain the target prompt word template.
[0106] The third prompt word is used to prompt the third language model to optimize the initial prompt word template based on the target evaluation results and associated text descriptions.
[0107] In this embodiment, when there are at least two target sample data points indicating an error in the first evaluation result, the first evaluation results corresponding to the target sample data are clustered to determine the target evaluation result corresponding to the initial prompt word template. Then, based on the target sample data to which the first evaluation result belongs and the text description corresponding to the target sample data, the text description associated with the target evaluation result is determined. Finally, the initial prompt word template, the third prompt word, the target evaluation result, and the text description associated with the target evaluation result are input into the third language model to obtain the target prompt word template. Thus, by clustering the first evaluation results to obtain one or more different target evaluation results corresponding to the initial prompt word template, the input to the third model can be reduced, thereby reducing the amount of data processed by the third model and improving the efficiency of optimizing the initial prompt word template.
[0108] For example, if the text description is: "Image of black scabs on the back of pemphigus vesicles", the initial prompt word template would be:
[0109] "You are a health expert highly skilled in image description, responsible for providing a professional and objective description of an image titled "{title}". Please ensure your description closely relates to the image's theme, uses clean Simplified Chinese, and strictly avoids any special tags or formatting, such as '#End#', '#END#', '#CONTENT#', '#Note#', '#RESPONSE#', etc. Furthermore, your description should not be blank or contain meaningless output."
[0110] When describing images, please follow these guidelines:
[0111] *It is forbidden to elaborate on the educational significance of the images or their helpfulness to people.
[0112] * Do not rate the image quality.
[0113] *Describe the image based on its type, such as inspection documents, instruction manuals, cartoon-style science images, or images involving human body parts or organs.
[0114] *If the image contains text, please indicate the location of the text and briefly describe its content.
[0115] #OBJECTIVE OF STEP1#
[0116] Please use 2-3 keywords to concisely and accurately extract the core points of the image, including key people, disease symptoms, objects, or indicators.
[0117] Formatting requirements: "Brief description:"
[0118] #OBJECTIVE OF STEP2#
[0119] Building upon STEP 1, elaborate further on the image content, avoiding repetition of STEP 1, and summarize it in 1-2 sentences. When describing, stay focused on the image's theme; do not make disease diagnoses or offer medical advice, and avoid excessive description of potential symptoms or body parts.
[0120] Formatting requirement: "Detailed explanation:"
[0121] #STYLE#
[0122] Please use professional medical terminology, maintain precise language, and ensure that your sentences do not contain special markers or formats such as '#word#'.
[0123] #TONE#
[0124] Express it in a popular science style, using language that is easy to understand, while ensuring that the sentences are fluent and objective.
[0125] #AUDIENCE#
[0126] Targeting people without a medical background
[0127] The first answer output by the first major model could be: "Back, Rash, Scabs. Detailed explanation: This image shows a person's back with a noticeable rash and scabs. The rash is red, and the scabs are brown, covering most of the back. The rash and scabs appear dry, and in some places there are even cracks. This image may be used for medical education or diagnosis to help doctors and patients understand this skin condition. However, please note that this image cannot be used for diagnosis or treatment, as there are many types of skin diseases that require professional diagnosis and treatment by a doctor."
[0128] If the corresponding reference answer is "This image shows a person's skin lesion on their back. The lesion area is large, affecting almost the entire back skin. Redness, swelling, ulcers, and scabs are visible. The scabs are brown, flaky, and cover the skin surface," then the first evaluation result output by the second model could be "The generated description is relatively complete, but contains redundant information, and some descriptions are not completely consistent with the full-mark description."
[0129] The target prompt template can be:
[0130] "You are a health expert highly skilled in image description, responsible for providing a professional and objective description of an image titled "{title}". Please ensure your description closely relates to the image's theme, uses clean Simplified Chinese, and strictly avoids any special tags or formatting, such as '#End#', '#END#', '#CONTENT#', '#Note#', '#RESPONSE#', etc. Furthermore, your description should not be blank or contain meaningless output."
[0131] When describing images, please follow these guidelines:
[0132] *It is forbidden to elaborate on the educational significance of the images or their helpfulness to people.
[0133] * Do not rate the image quality.
[0134] *Describe the image based on its type, such as inspection documents, instruction manuals, cartoon-style science images, or images involving human body parts or organs.
[0135] *If the image contains text, please indicate the location of the text and briefly describe its content.
[0136] #OBJECTIVE OF STEP1#
[0137] Please use 2-3 keywords to concisely and precisely extract the core message of the image, including key people, disease symptoms, objects, or indicators. Ensure these keywords are closely related to the image's theme and avoid using vague or general terms.
[0138] Formatting requirements: "Brief description:"
[0139] #OBJECTIVE OF STEP2#
[0140] Building upon STEP 1, further elaborate on the image content, avoiding repetition of STEP 1, and summarize it in 1-2 sentences. When describing, stay focused on the image's theme; do not make disease diagnoses or offer medical advice, and avoid excessive description of potential symptoms or body parts. Ensure your description is specific, accurate, and highly consistent with the image content.
[0141] Formatting requirement: "Detailed explanation:"
[0142] #STYLE#
[0143] Please use professional medical terminology, maintain precise language, and ensure that your sentences do not contain special markers or formatting like '#word#'. Avoid using overly complex or obscure vocabulary; ensure your descriptions are easy to understand.
[0144] #TONE#
[0145] Express information in a popular science style, using simple and easy-to-understand language while ensuring fluent and objective sentences. Avoid using highly subjective vocabulary or expressions, and ensure that the descriptions are objective and neutral.
[0146] #AUDIENCE#
[0147] This is intended for a non-medical audience, so please use easy-to-understand language and expressions, avoiding overly technical or obscure medical terminology.
[0148] Figure 4 This is a schematic diagram of a prompt word template generation device provided according to an embodiment of the present disclosure;
[0149] like Figure 4 As shown, the device 400 for generating the prompt word template includes:
[0150] The acquisition module 401 is used to acquire the first dataset and initial prompt word template corresponding to the target task. The first dataset includes sample data, text descriptions corresponding to the sample data, and reference answers.
[0151] The first determining module 402 is used to determine the first answer corresponding to the sample data based on the initial prompt word template, sample data and corresponding text description;
[0152] The second determining module 403 is used to determine the first evaluation result corresponding to the first answer based on the reference answer and the first answer;
[0153] The optimization module 404 is used to optimize the initial prompt word template based on the first evaluation result and text description to obtain the target prompt word template.
[0154] In some embodiments of this disclosure, a processing module is further included for:
[0155] Based on the target prompt word template, sample data, and corresponding text description, determine the second answer corresponding to the sample data;
[0156] Based on the second answer and the reference answer, determine the second evaluation result corresponding to the second answer;
[0157] From the target prompt word template and the initial prompt word template, determine the prompt word template to be optimized;
[0158] Based on the second evaluation results and text description, the prompt word template to be optimized is optimized to obtain the optimized target prompt word template.
[0159] In some embodiments of this disclosure, the processing module is configured to:
[0160] Determine the first score corresponding to the initial prompt word template and the second score corresponding to the target prompt word template;
[0161] The prompt word template with the highest score in the first and second ratings will be selected as the prompt word templates to be optimized.
[0162] In some embodiments of this disclosure, the processing module is configured to:
[0163] Based on the difference between the first answer and the reference answer for each sample data, determine the third score corresponding to each first answer;
[0164] Based on the third score corresponding to each first answer, determine the first score corresponding to the initial prompt word template;
[0165] Based on the difference between the second answer and the reference answer for each sample data, determine the fourth score for each second answer;
[0166] Based on the fourth score corresponding to each second answer, determine the second score corresponding to the target prompt word template.
[0167] In some embodiments of this disclosure, the processing module is configured to:
[0168] When the prompt word template to be optimized is the initial prompt word template, the first evaluation result and the second evaluation result corresponding to the sample data are merged to obtain the third evaluation result corresponding to the sample data.
[0169] Based on the third evaluation results and text description, the initial prompt words are optimized to obtain the optimized target prompt word template.
[0170] In some embodiments of this disclosure, the first determining module 402 is configured to:
[0171] Fill the text description into the preset position in the initial prompt word template to obtain the first prompt word corresponding to the sample data;
[0172] Input the first prompt word and sample data into the first large model to obtain the first answer corresponding to the sample data.
[0173] In some embodiments of this disclosure, the second determining module 403 is configured to:
[0174] When the target task is a preset task, the reference answer, the first answer, and the second prompt are input into the second large model to obtain the first evaluation result. The second prompt is used to prompt the second large model to evaluate the first answer based on the reference answer.
[0175] In some embodiments of this disclosure, the optimization module 404 is configured to:
[0176] The first evaluation result indicates that the target sample data is incorrect;
[0177] When there are at least two target sample data, the text description associated with the first evaluation result is determined based on the first evaluation result and text description corresponding to the target sample data.
[0178] The initial prompt word template, the third prompt word, the first evaluation result, and the associated text description of the first evaluation result are input into the third major model to obtain the target prompt word template. The third prompt word is used to prompt the third major model to optimize the initial prompt word template based on the first evaluation result and the corresponding text description.
[0179] In some embodiments of this disclosure, the optimization module 404 is configured to:
[0180] The first evaluation result indicates that the target sample data is incorrect;
[0181] When there are at least two target sample data, the first evaluation results corresponding to the target sample data are clustered to determine the target evaluation result corresponding to the initial prompt word template;
[0182] Based on the target sample data to which the first evaluation result corresponding to the target evaluation result belongs, and the text description corresponding to the target sample data, determine the text description associated with the target evaluation result;
[0183] The initial prompt word template, the third prompt word, the target evaluation result, and the text description associated with the target evaluation result are input into the third language model to obtain the target prompt word template. The third prompt word is used to prompt the third language model to optimize the initial prompt word template based on the target evaluation result and the associated text description.
[0184] In some embodiments of this disclosure, the sample data is at least one of the following:
[0185] Text data, image data, and audio data.
[0186] It should be noted that the foregoing explanation of the method for generating prompt word templates also applies to the prompt word template generation device of this embodiment, and will not be repeated here.
[0187] In this embodiment, based on the initial prompt word template, sample data, and corresponding text description, a first answer corresponding to the sample data is determined. Then, based on the reference answer corresponding to the sample data and the first answer, a first evaluation result corresponding to the first answer is determined. Finally, based on the first evaluation result and text description, the initial prompt word template is optimized to obtain the target prompt word template. Therefore, by comparing the difference between the first answer and the reference answer corresponding to the sample data under the initial prompt word template, defects in the initial prompt word template can be identified. Then, combined with the text description corresponding to the sample data, the initial prompt word template can be optimized, thereby achieving automatic optimization of the prompt word template, improving the efficiency and accuracy of prompt word template optimization, and ultimately improving the quality of the optimized target prompt word template.
[0188] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0189] Figure 5 A schematic block diagram of an example electronic device 500 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0190] like Figure 5 As shown, device 500 includes a computing unit 501, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 502 or a computer program loaded from storage unit 508 into random access memory (RAM) 503. RAM 503 may also store various programs and data required for the operation of device 500. The computing unit 501, ROM 502, and RAM 503 are interconnected via bus 504. Input / output (I / O) interface 505 is also connected to bus 504.
[0191] Multiple components in device 500 are connected to I / O interface 505, including: input unit 506, such as keyboard, mouse, etc.; output unit 507, such as various types of monitors, speakers, etc.; storage unit 508, such as disk, optical disk, etc.; and communication unit 509, such as network card, modem, wireless transceiver, etc. Communication unit 509 allows device 500 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0192] The computing unit 501 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 501 performs the various methods and processes described above, such as the method for generating prompt word templates. For example, in some embodiments, the method for generating prompt word templates may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on device 500 via ROM 502 and / or communication unit 509. When the computer program is loaded into RAM 503 and executed by the computing unit 501, one or more steps of the method for generating prompt word templates described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to perform the method for generating prompt word templates by any other suitable means (e.g., by means of firmware).
[0193] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0194] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0195] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0196] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0197] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), the Internet, and blockchain networks.
[0198] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service ecosystem, addressing the shortcomings of traditional physical hosts and VPS (Virtual Private Server, or simply "VPS") services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.
[0199] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0200] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this disclosure, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified. In the description of this disclosure, the words "if" and "suppose" as used may be interpreted as "when," "when," "in response to determination," or "in the circumstances."
[0201] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A method for generating prompt word templates, wherein, include: Obtain the first dataset and initial prompt word template corresponding to the target task, wherein the first dataset includes sample data, text descriptions corresponding to the sample data, and reference answers; The text description is filled into the preset position in the initial prompt word template to obtain the first prompt word corresponding to the sample data; Input the first prompt word and the sample data into the first large model to obtain the first answer corresponding to the sample data; When the target task is a preset task, the reference answer, the first answer, and the second prompt are input into the second large model to obtain the first evaluation result corresponding to the first answer. The second prompt is used to prompt the second large model to evaluate the first answer based on the reference answer. The first evaluation result includes text describing the difference between the first answer and the reference answer. The preset task includes an image description task. The sample data includes images. The text description corresponding to the sample data includes the theme information of the image. Based on the first evaluation result and the text description, the initial prompt word template is optimized to obtain the target prompt word template; The step of optimizing the initial prompt word template based on the first evaluation result and the text description to obtain the target prompt word template includes: The first evaluation result indicates that the target sample data is incorrect; When there are at least two target sample data, the first evaluation results corresponding to the target sample data are clustered to determine the target evaluation result corresponding to the initial prompt word template; Based on the target sample data to which the first evaluation result corresponding to the target evaluation result belongs, and the text description corresponding to the target sample data, determine the text description associated with the target evaluation result; The initial prompt word template, the third prompt word, the target evaluation result, and the text description associated with the target evaluation result are input into the third language model to obtain the target prompt word template. The third prompt word is used to prompt the third language model to optimize the initial prompt word template based on the target evaluation result and the associated text description.
2. The method according to claim 1, wherein, After optimizing the initial prompt word template based on the first evaluation result and the text description to obtain the target prompt word template, the method further includes: Based on the target prompt word template, the sample data, and the corresponding text description, determine the second answer corresponding to the sample data; Based on the second answer and the reference answer, determine the second evaluation result corresponding to the second answer; From the target prompt word template and the initial prompt word template, determine the prompt word template to be optimized; Based on the second evaluation result and the text description, the prompt word template to be optimized is optimized to obtain the optimized target prompt word template.
3. The method according to claim 2, wherein, The step of determining the prompt word template to be optimized from the target prompt word template and the initial prompt word template includes: Determine the first score corresponding to the initial prompt word template and the second score corresponding to the target prompt word template; The prompt word template with the highest score between the first and second scores is determined as the prompt word template to be optimized.
4. The method according to claim 3, wherein, The determination of the first score corresponding to the initial prompt word template and the second score corresponding to the target prompt word template includes: Based on the difference between the first answer and the reference answer corresponding to each sample data, a third score is determined for each first answer; Based on the third score corresponding to each first answer, determine the first score corresponding to the initial prompt word template; Based on the difference between the second answer and the reference answer corresponding to each sample data, a fourth score is determined for each second answer; Based on the fourth score corresponding to each second answer, determine the second score corresponding to the target prompt word template.
5. The method according to claim 2, wherein, After determining the prompt word template to be optimized from the target prompt word template and the initial prompt word template, the method further includes: When the prompt word template to be optimized is the initial prompt word template, the first evaluation result and the second evaluation result corresponding to the sample data are merged to obtain the third evaluation result corresponding to the sample data; Based on the third evaluation result and the text description, the initial prompt words are optimized to obtain the optimized target prompt word template.
6. The method according to claim 1, wherein, The step of optimizing the initial prompt word template based on the first evaluation result and the text description to obtain the target prompt word template further includes: The first evaluation result indicates that the target sample data is incorrect; When there are at least two target sample data, the text description associated with the first evaluation result is determined based on the first evaluation result corresponding to the target sample data and the text description. The initial prompt word template, the third prompt word, the first evaluation result, and the text description associated with the first evaluation result are input into the third large model to obtain the target prompt word template. The third prompt word is used to prompt the third large model to optimize the initial prompt word template based on the first evaluation result and the corresponding text description.
7. An apparatus for generating prompt word templates, wherein, include: The acquisition module is used to acquire the first dataset and initial prompt word template corresponding to the target task, wherein the first dataset includes sample data, text descriptions corresponding to the sample data, and reference answers; The first determining module is used to determine the first answer corresponding to the sample data based on the initial prompt word template, the sample data, and the corresponding text description; The second determining module is used to determine the first evaluation result corresponding to the first answer based on the reference answer and the first answer; The optimization module is used to optimize the initial prompt word template based on the first evaluation result and the text description to obtain the target prompt word template. The first determining module is used for: The text description is filled into the preset position in the initial prompt word template to obtain the first prompt word corresponding to the sample data; Input the first prompt word and the sample data into the first large model to obtain the first answer corresponding to the sample data; The second determining module is used for: When the target task is a preset task, the reference answer, the first answer, and the second prompt word are input into the second large model to obtain the first evaluation result. The second prompt word is used to prompt the second large model to evaluate the first answer based on the reference answer. The first evaluation result includes text describing the difference between the first answer and the reference answer. The preset task includes an image description task. The sample data includes images. The text description corresponding to the sample data includes the theme information of the image. The optimization module is used for: The first evaluation result indicates that the target sample data is incorrect; When there are at least two target sample data, the first evaluation results corresponding to the target sample data are clustered to determine the target evaluation result corresponding to the initial prompt word template; Based on the target sample data to which the first evaluation result corresponding to the target evaluation result belongs, and the text description corresponding to the target sample data, determine the text description associated with the target evaluation result; The initial prompt word template, the third prompt word, the target evaluation result, and the text description associated with the target evaluation result are input into the third language model to obtain the target prompt word template. The third prompt word is used to prompt the third language model to optimize the initial prompt word template based on the target evaluation result and the associated text description.
8. The apparatus according to claim 7, wherein, It also includes a processing module for: Based on the target prompt word template, the sample data, and the corresponding text description, determine the second answer corresponding to the sample data; Based on the second answer and the reference answer, determine the second evaluation result corresponding to the second answer; From the target prompt word template and the initial prompt word template, determine the prompt word template to be optimized; Based on the second evaluation result and the text description, the prompt word template to be optimized is optimized to obtain the optimized target prompt word template.
9. The apparatus according to claim 8, wherein, The processing module is used for: Determine the first score corresponding to the initial prompt word template and the second score corresponding to the target prompt word template; The prompt word template with the highest score between the first and second scores is determined as the prompt word template to be optimized.
10. The apparatus according to claim 9, wherein, The processing module is used for: Based on the difference between the first answer and the reference answer corresponding to each sample data, a third score is determined for each first answer; Based on the third score corresponding to each first answer, determine the first score corresponding to the initial prompt word template; Based on the difference between the second answer and the reference answer corresponding to each sample data, a fourth score is determined for each second answer; Based on the fourth score corresponding to each second answer, determine the second score corresponding to the target prompt word template.
11. The apparatus according to claim 8, wherein, The processing module is used for: When the prompt word template to be optimized is the initial prompt word template, the first evaluation result and the second evaluation result corresponding to the sample data are merged to obtain the third evaluation result corresponding to the sample data; Based on the third evaluation result and the text description, the initial prompt words are optimized to obtain the optimized target prompt word template.
12. The apparatus according to claim 7, wherein, The optimization module is also used for: The first evaluation result indicates that the target sample data is incorrect; When there are at least two target sample data, the text description associated with the first evaluation result is determined based on the first evaluation result corresponding to the target sample data and the text description. The initial prompt word template, the third prompt word, the first evaluation result, and the text description associated with the first evaluation result are input into the third large model to obtain the target prompt word template. The third prompt word is used to prompt the third large model to optimize the initial prompt word template based on the first evaluation result and the corresponding text description.
13. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
14. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-6.
15. A computer program product comprising computer instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1-6.