A prompt word generation method, device, electronic device and readable storage medium
Through the multi-level model optimization prompt word generation method, the problem that the existing technology cannot adjust prompt words according to different problems is solved, and the generation of accurate prompt words that are suitable for the problem is achieved.
Patent Information
- Application Number
- CN202411635907.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-15
- Publication Date
- 2025-04-04
AI Technical Summary
The existing prompt word generation methods cannot adjust the prompt word according to different problems, resulting in the inability to provide appropriate prompt words for the problem.
By receiving the user input questions, input them into the trained first model, generate the basic prompt words, and then input them into the trained second model, optimize them based on historical dialogue information and domain knowledge, and generate the first optimization prompt words. Further, the first optimization prompt word is input into the trained third model, and optimized based on user portrait, historical input information and dialogue scenes to generate the second optimization prompt word.
Accurate prompt words can be generated based on a variety of information involving problem situations and user situations, and prompt words that are suitable for the current problem.
Smart Images

Figure CN119761359A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer technology, and in particular, relates to a prompt word generation method, device, electronic device and readable storage medium. Background Art
[0002] In order to improve the accuracy of the output of the large language model, prompt words are generally provided for the question so that the large language model can output accurate results for the question.
[0003] However, existing prompt word generation methods usually rely on manual design or simple rules, which makes it impossible to adjust the prompt words according to different questions, and thus cannot provide appropriate prompt words for the questions. Summary of the invention
[0004] The embodiments of the present application provide a prompt word generation method, device, electronic device, readable storage medium and computer program product, which can solve the problem that the prompt words cannot be adjusted according to different questions.
[0005] In a first aspect, an embodiment of the present application provides a method for generating a prompt word, comprising:
[0006] Receive user input questions;
[0007] Input the question into a trained first model to obtain basic prompt words output by the trained first model, wherein the trained first model is used to analyze the question and obtain and output the basic prompt words;
[0008] The basic prompt word is input into the trained second model to obtain the first optimized prompt word output by the trained second model, and the trained second model is used to optimize the basic prompt word according to the historical dialogue information and domain knowledge to obtain and output the first optimized prompt word.
[0009] In one embodiment, after obtaining the first optimization prompt word output by the trained second model, the method further includes:
[0010] Inputting the first optimized prompt word into a trained third model to obtain a second optimized prompt word output by the trained third model, wherein the trained third model is used to optimize the first optimized prompt word according to the user portrait, historical input information, and conversation scenario, and obtain and output the second optimized prompt word;
[0011] The format of the second optimized prompt word is the format of input data of the inference model, and the inference model is used to determine the answer according to the prompt word.
[0012] In one embodiment, the trained first model is specifically used to obtain the question type, user intent, key information, task instructions, and question and answer template from the question; and generate the basic prompt words according to the question type, user intent, key information, task instructions, and question and answer template.
[0013] In one embodiment, the trained second model is specifically used to obtain relevant questions and relevant answers from the historical dialogue information according to the question; determine the domain knowledge according to the question; determine the implicit intention of the question according to the historical dialogue information; and optimize the basic prompt words according to the relevant questions, the relevant answers, the domain knowledge, and the implicit intention to obtain the first optimized prompt words.
[0014] In one embodiment, the trained second model is specifically used to obtain relevant questions and relevant answers from the historical dialogue information according to the question; determine the implicit intention of the question according to the historical dialogue information; determine the domain knowledge, prompt word length and prompt word style according to the question; and optimize the basic prompt word according to the relevant questions, the relevant answers, the domain knowledge, the implicit intention, the prompt word length and the prompt word style to obtain the first optimized prompt word.
[0015] In one embodiment, the trained third model is specifically used to determine the user portrait based on the historical conversation information; determine the conversation scenario based on the question; determine the user's emotional information based on the historical input information; determine relevant examples based on the user portrait, the conversation scenario, the question and the emotional information; and obtain the second optimization prompt word for the first optimization prompt word based on the user portrait, the conversation scenario, the emotional information and the relevant examples.
[0016] In one embodiment, before inputting the question into the first model and obtaining the basic prompt words output by the first model, the method further includes:
[0017] Acquire first training data, second training data, and third training data, wherein the first training data includes multiple user questions and corresponding first labels, the first labels include first real prompt words, the second training data includes context information of the user questions, domain knowledge, and corresponding second labels, the second labels are second real prompt words, and the third training data includes portrait information of the user questions, scene information, the context information, and corresponding third labels, the third labels are third real prompt words;
[0018] Using the first training data, training a first model to obtain the trained first model;
[0019] Using the second training data, training a second model to obtain the trained second model;
[0020] The third model is trained using the third training data to obtain the trained third model.
[0021] In a second aspect, an embodiment of the present application provides a prompt word generating device, comprising:
[0022] A receiving module, used for receiving questions input by users;
[0023] A generating module, used for inputting the question into a trained first model, obtaining basic prompt words output by the trained first model, wherein the trained first model is used for analyzing the question, obtaining and outputting the basic prompt words;
[0024] The method is also used to input the basic prompt word into the trained second model to obtain the first optimized prompt word output by the trained second model. The trained second model is used to optimize the basic prompt word according to historical dialogue information and domain knowledge to obtain and output the first optimized prompt word.
[0025] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements a method as described in any one of the above-mentioned first aspects when executing the computer program.
[0026] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method as described in any one of the above-mentioned first aspects is implemented.
[0027] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes any one of the methods described in the first aspect.
[0028] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0029] The embodiment of the present application receives a question input by a user; inputs the question into a trained first model to obtain basic prompt words output by the trained first model, the trained first model is used to analyze the question, obtain and output basic prompt words; inputs the basic prompt words into a trained second model to obtain first optimized prompt words output by the trained second model, the trained second model is used to optimize the basic prompt words according to historical conversation information and domain knowledge, obtain and output first optimized prompt words, and can generate accurate prompt words according to a variety of information related to the problem situation and the user situation, and obtain prompt words suitable for the current problem.
[0030] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0032] Figure 1 This is a first flow chart of a method for generating prompt words provided in an embodiment of the present application;
[0033] Figure 2 This is a second flow chart of the method for generating prompt words provided in one embodiment of the present application;
[0034] Figure 3 This is a third flow chart of the prompt word generation method provided in an embodiment of the present application;
[0035] Figure 4 It is a structural schematic diagram of a prompt word generating device provided in an embodiment of the present application;
[0036] Figure 5 It is a schematic diagram of the structure of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0037] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0038] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0039] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0040] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0041] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0042] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0043] In one embodiment, Figure 1 This is a schematic diagram of the first flow chart of the prompt word generation method provided in an embodiment of the present application. Figure 1 As shown, the method comprises:
[0044] S11: Receive questions input by the user.
[0045] In the application, after the user inputs a question in natural language on the electronic device, the question input by the user is obtained. For example, the question is how is the weather today?
[0046] S12: Input the question into the trained first model to obtain the basic prompt words output by the trained first model.
[0047] The trained first model is used to analyze the question, obtain and output basic prompt words; and the inference model is used to determine the answer based on the prompt words.
[0048] In one possible implementation, the trained first model is specifically used to obtain question type, user intent, key information, task instructions, and question and answer templates from the question; and generate basic prompt words based on the question type, user intent, key information, task instructions, and question and answer templates.
[0049] In the application, the trained first model identifies the type of question and obtains the question type. The question type enables the trained first model to determine the way to understand the user's question. The question type includes factual questions, reasoning questions, and advisory questions.
[0050] For example, the question is: What is the weather like today? (Factual question). The question is: If I have to go on a business trip tomorrow, what should I prepare? (Inference question). The question is: How can I increase the traffic of my website? (Suggestive question)
[0051] The trained first model identifies the intent of the question and obtains the user's intent. The user's intent enables the trained first model to know the core information or answer that the user wants to obtain, clarify the user's purpose, and the generated prompt words enable the reasoning model to focus on the key part of the answer.
[0052] For example, the question is How can I increase my website traffic? The user intent is ways to increase website traffic.
[0053] The first model has been trained to extract key information. Key information includes specific nouns, time, place, verbs, etc. Key information enables the inference model to generate more accurate answers.
[0054] For example, the question is "What will the weather be like in Beijing tomorrow?" The key information includes "tomorrow" and "Beijing". The question is "How can I increase the number of visits to my website?" The key information includes "website" and "number of visits".
[0055] The trained first model specifies task instructions based on the question to instruct the reasoning model what to do. Task instructions include providing explanations, listing steps, giving suggestions, generating articles, etc.
[0056] For example, the question is how can I increase my website traffic? The task instructions are to provide specific steps or strategies for website optimization.
[0057] The trained first model determines the structure of the reasoning model's answer based on the question and obtains a question-and-answer template. The question-and-answer template can help the reasoning model organize language. The question-and-answer template includes segmented answers, summary first and detailed explanation, etc.
[0058] For example, the question is How can I increase my website traffic? The answer template is to first provide a few simple suggestions and then explain each suggestion in detail.
[0059] After obtaining the above data, basic prompt words are generated according to question type, user intent, key information, task instructions, and question and answer templates.
[0060] For example, the question is How can I increase my website traffic? The basic prompt words are to provide users with specific steps or strategies for website optimization and increase website traffic. When answering, first provide a few simple suggestions and then explain each suggestion in detail.
[0061] In one possible implementation, the trained first model is specifically used to obtain historical dialogue information of a question; obtain question type, user intent, key information, task instructions, and question-answering templates from the question; and generate basic prompt words based on the question type, user intent, key information, task instructions, question-answering templates, and historical dialogue information.
[0062] In the application, when the user inputs a question in a dialogue or continuous scenario, the trained first model obtains historical dialogue information based on the question. Historical dialogue information can help the inference model better understand the question and generate a coherent answer.
[0063] After obtaining the above data, basic prompt words are generated according to question type, user intent, key information, task instructions, question and answer templates, and historical dialogue information. The basic prompt words also include historical dialogue information.
[0064] S13: Input the basic prompt word into the trained second model to obtain the first optimized prompt word output by the trained second model.
[0065] The trained second model is used to optimize the basic prompt words according to the historical dialogue information and domain knowledge, and obtain and output the first optimized prompt words.
[0066] In one possible implementation, the trained second model is specifically used to obtain relevant questions and relevant answers from historical dialogue information based on the question; determine domain knowledge based on the question; determine the implicit intention of the question based on the historical dialogue information; and optimize the basic prompt words based on the relevant questions, relevant answers, domain knowledge, and implicit intention to obtain the first optimized prompt words.
[0067] In the application, the trained second model analyzes the historical conversation information according to the question type, user intent, key information, etc., obtains relevant content, and then obtains relevant questions and relevant answers. The relevant questions and relevant answers instruct the trained second model to add relevant content to the prompt words or adjust the structure and content of the prompt words, so that the generated prompt words are consistent with the previous questions and answers, and thus the answers generated by the inference model are also coherent and consistent with the overall scenario of the conversation.
[0068] The historical dialogue information includes one or more rounds of dialogue before the question.
[0069] The trained second model analyzes the historical conversation information, explores the user's implicit purpose, and obtains the user's implicit intention. The implicit intention allows the trained second model to clarify the user's hidden intention and generate prompt words that better meet the user's needs.
[0070] For example, the content related to the task instruction can be refined and optimized according to the implicit intent. The content related to the user intent or key information can also be refined and optimized according to the implicit intent.
[0071] The trained second model searches for relevant domain knowledge in the pre-built domain knowledge base based on the question. Domain knowledge can help the trained second model supplement missing professional terms or rewrite expressions in the prompt words to generate prompt words that conform to the style and logic of the target domain, thereby helping the reasoning model generate more in-depth and professional answers.
[0072] Among them, domain knowledge includes domain terminology, frequently asked questions, professional advice, etc.
[0073] After obtaining the above data, the basic prompt words are optimized according to relevant questions, relevant answers, domain knowledge, and implicit intentions to obtain the first optimized prompt words.
[0074] In one possible implementation, the trained second model is specifically used to obtain relevant questions and relevant answers from historical dialogue information based on the question; determine the implicit intention of the question based on the historical dialogue information; determine the domain knowledge, prompt word length and prompt word style based on the question; and optimize the basic prompt word based on the relevant questions, relevant answers, domain knowledge, implicit intention, prompt word length and prompt word style to obtain the first optimized prompt word.
[0075] In the application, the trained second model can determine the current dialogue scenario based on the question, understand the user's needs based on the dialogue scenario, and then determine the length and style of the prompt word. Based on the length and style, the model parameters (temperature, maximum generation length, etc.) are dynamically adjusted to adjust the length and style of the prompt word.
[0076] Or the trained second model can determine the domain to which the question belongs according to the question, determine the domain requirements according to the domain, and then determine the prompt word length and prompt word style. Based on the length and style, the parameters of the model (temperature, maximum generation length, etc.) are dynamically adjusted to adjust the length and style of the prompt word.
[0077] For example, the content of the question and answer template can be adjusted to adjust the prompt word length and style, and can be adjusted to generate a concise summary, a detailed explanation, or a step-by-step action plan. The content of the key information can be adjusted to adjust the prompt word length and style.
[0078] After obtaining the above data, the basic prompt words are optimized according to relevant questions, relevant answers, domain knowledge, implicit intentions, prompt word lengths and prompt word styles to obtain first optimized prompt words.
[0079] It can be understood that through step S13, the trained second model can better understand the user's intention based on the coherence and accuracy of the historical conversation information, and can better understand the relevant professional terms based on the professionalism of the domain knowledge related to the problem, and generate prompt words that are more in line with user needs and fields.
[0080] This embodiment receives a question input by a user; inputs the question into a trained first model to obtain basic prompt words output by the trained first model, the trained first model is used to analyze the question, obtain and output basic prompt words; inputs the basic prompt words into a trained second model to obtain first optimized prompt words output by the trained second model, the trained second model is used to optimize the basic prompt words according to historical conversation information and domain knowledge, obtain and output first optimized prompt words, and can generate accurate prompt words according to a variety of information related to the problem situation and the user situation, and obtain prompt words suitable for the current problem.
[0081] In one embodiment, Figure 2 This is a second flow chart of the method for generating prompt words provided in an embodiment of the present application. Figure 2 As shown, after step S13, the following steps are also included:
[0082] S14: Input the first optimization prompt word into the trained third model to obtain the second optimization prompt word output by the trained third model.
[0083] The trained third model is used to optimize the first optimization prompt word according to the user portrait, historical input information and dialogue scenario, and obtain and output the second optimization prompt word.
[0084] In one possible implementation, the trained third model is specifically used to determine the user portrait based on historical conversation information; determine the conversation scenario based on the question; determine the user's emotional information based on historical input information; determine relevant examples based on the user portrait, conversation scenario, question and emotional information; and obtain the second optimized prompt word for the first optimized prompt word based on the user portrait, conversation scenario, emotional information and relevant examples.
[0085] In the application, the trained third model determines the user's age, work situation, family situation, interests and hobbies, past experience, plans, budget constraints, and time preferences based on the historical conversation information of the question to obtain a user portrait.
[0086] For example, for recommended places. According to historical conversation information, the user is a backpacker, and the optimized prompt words tend to like exploring new and exotic natural attractions. According to historical conversation information, the user has a family and children, and the optimized prompt words tend to places with high safety and entertainment facilities. According to historical conversation information, the user has mentioned many times that he likes beach travel and hopes to avoid crowded places. The optimized prompt words tend to be niche beach cities to avoid peak traffic hours. According to historical conversation information, the user mentioned that he wanted to go to a certain area, and the optimized prompt words tend to be that area. According to historical conversation information, the user likes beaches and outdoor activities, and the optimized prompt words tend to be travel seasons or time arrangements.
[0087] The trained third model determines the dialogue scenario based on the question. The dialogue scenario can help the trained third model better understand the user's needs and generate prompt words that better meet the user's needs. The dialogue scenarios include work scenarios, leisure scenarios, and learning scenarios.
[0088] For example, the conversation scenario is determined to be a parent-child travel according to the question, and the optimized prompt words tend to be places suitable for parent-child travel.
[0089] The trained third model determines the user's emotional information based on the historical input information. The emotional information can assist the trained third model in refining the explanation or recommending simplification of the answer template.
[0090] The trained third model determines relevant examples based on user portraits, conversation scenarios, questions, and sentiment information. Adding relevant examples to prompt words can help the inference model better understand user needs and generate high-quality answers that better meet user expectations.
[0091] For example, if the user has a multicultural background or language skills, the relevant example is to recommend language-friendly places. If the user has children, the relevant example is to recommend places with high safety, suitable for families and children. If the user wants to travel, has a low budget and has a family, the relevant example is to recommend you to choose a beach close to you based on your budget and family needs, which has fewer tourists and is also suitable for family travel, with rich parent-child activities and safe beach areas suitable for children to play.
[0092] After obtaining the above data, the first optimized prompt word is optimized according to the user portrait, dialogue scenario, emotional information and related examples to obtain the second optimized prompt word.
[0093] The format of the second optimized prompt word is the format of the input data of the reasoning model. During the optimization process, the format of the prompt word is adjusted to the format of the input data of the reasoning model so that the reasoning model can better identify the second optimized prompt word. And the second optimized prompt word is a customized prompt word that meets the needs of the user, so that the reasoning model can better generate customized, practical and user-friendly answers.
[0094] For example, scenario description: The user is a family of three (a couple and a 5-year-old child) and plans to take a seaside trip during the National Day holiday with a budget of less than 5,000 yuan. The user likes quiet and less crowded attractions.
[0095] Question input by the user: We want to travel to the seaside during the National Day holiday. The budget should not exceed 5,000 yuan. Do you have any recommendations for something suitable for children?
[0096] First layer: The first model has been trained to extract information from the question as follows:
[0097] Question type: Suggestive question;
[0098] User intention: Want to visit a seaside attraction with few people and suitable for parent-child activities during the National Day holiday;
[0099] Key information: National Day holiday, beach, few people, family-friendly, less than 5,000 yuan;
[0100] Mission instructions: Recommend tourist destinations;
[0101] Answer template: Suggest first, then analyze.
[0102] The first trained model generates basic prompt words based on the above information: recommend seaside travel destinations suitable for families during the National Day holiday, with a budget of less than 5,000 yuan and parent-child activities, and answer with suggestions first and analysis later.
[0103] Second layer: The second model has been trained to optimize the basic prompt words:
[0104] The second model has been trained to obtain the following information:
[0105] Implicit intention: Go to less popular beaches instead of popular attractions;
[0106] Domain knowledge: tourism knowledge;
[0107] The second model has been trained to generate the first optimized prompt word: recommend niche locations suitable for family seaside travel during the National Day, avoid peak traffic periods, have a budget of less than 5,000 yuan, and provide parent-child activities suitable for 5-year-old children; answer with suggestions first and then analysis.
[0108] The third layer: The third model has been trained to optimize the first optimization prompt word
[0109] The information obtained by the trained third model is as follows:
[0110] User profile: The user prefers beaches, likes quietness, has a family and a 5-year-old child, and has a travel budget of less than 5,000 yuan;
[0111] Dialogue scenario: leisure travel;
[0112] Emotional information: joy;
[0113] Related example: Recommend a certain seaside attraction; suitable for a family of three to have a seaside vacation during the National Day holiday. There are fewer tourists here, the budget is within 5,000 yuan, and there are a variety of parent-child activities, such as a beach play area and parent-child boating projects, suitable for 5-year-old children. You can also taste the local specialty seafood and enjoy a quiet seaside vacation.
[0114] The second model has been trained to generate the second optimization prompt: Please recommend a seaside tourist spot suitable for a family of three during the National Day holiday, with a budget of less than 5,000 yuan. The location needs to have fewer tourists, be suitable for 5-year-old children, and provide parent-child activities. Answer: Suggest first, then analyze. Recommend a certain seaside attraction; there are quiet beaches, parent-child boating activities, and children's amusement facilities, which are suitable for a relaxing family vacation.
[0115] Example, user-entered question: I would like to improve my eating habits to help lose weight, but I have high blood pressure and mild diabetes, is there any recommended diet plan?
[0116] First layer: The first model has been trained to extract information from the question as follows:
[0117] Question type: Suggestive question;
[0118] User intent: Recommend a weight loss diet plan suitable for people with high blood pressure or mild diabetes;
[0119] Key information: high blood pressure, mild diabetes, weight loss, dietary regimen;
[0120] Task instructions: Recommend a healthy diet plan suitable for weight loss to the user, in line with the needs of hypertension and diabetes management;
[0121] Answer template: Based on your health status and goals, the following diet plan is recommended for you:
[0122] 1. Meal type and main components (e.g., breakfast, lunch, dinner).
[0123] 2. Description of ingredients and recommended recipes.
[0124] 3. Precautions and taboos.
[0125] The first trained model generates basic prompt words based on the above information: Recommend a weight loss diet that meets the needs of hypertension and diabetes management. Answer template: Based on your health status and goals, the following diet is recommended for you:
[0126] 1. Meal type and main components (e.g., breakfast, lunch, dinner).
[0127] 2. Description of ingredients and recommended recipes.
[0128] 3. Precautions and taboos.
[0129] Second layer: The second model has been trained to optimize the basic prompt words:
[0130] The second model has been trained to obtain the following information:
[0131] Implicit intent: To provide dietary advice that is easy to operate, healthy, and suitable for long-term adherence;
[0132] Domain knowledge: dietary knowledge;
[0133] The second model has been trained to generate the first optimization prompt: Based on the user's hypertension and diabetes, recommend a healthy diet plan that is easy to implement in the long term, low in sugar and salt, and suitable for weight loss. Prioritize natural low-processed ingredients, fiber-rich vegetables, and high-quality protein. Provide specific recipe suggestions and easy-to-use ingredient selections, avoid processed foods, answer template: Based on your health status and goals, the following diet plan is recommended for you:
[0134] 1. Meal type and main components (e.g., breakfast, lunch, dinner).
[0135] 2. Description of ingredients and recommended recipes.
[0136] 3. Precautions and taboos.
[0137] Third layer: The third model has been trained to optimize the first optimization prompt word:
[0138] The information obtained by the trained third model is as follows:
[0139] User profile: The user prefers to eat chicken, has a blood pressure value of xx and a blood sugar value of xx;
[0140] Dialogue scene: casual dining;
[0141] Related examples: Recommend chicken and fish;
[0142] The second model has been trained to generate the second optimization prompt word: Based on the requirements of hypertension and mild diabetes management, a detailed healthy diet plan is provided, which is suitable for weight loss and meets the characteristics of long-term persistence. The three meals a day are recommended to include fiber-rich vegetables and high-quality protein such as chicken, fish and beans. Low-salt, low-fat, high-fiber foods are recommended for breakfast. The plan takes into account the characteristics of health and ease of implementation, avoids complex cooking, and recommends easy-to-obtain ingredients. Answer template: Based on your health status and goals, the following diet plan is recommended for you:
[0143] 1. Meal type and main components (e.g., breakfast, lunch, dinner).
[0144] 2. Description of ingredients and recommended recipes.
[0145] 3. Precautions and taboos.
[0146] In this embodiment, the first optimized prompt word is input into the trained third model to obtain the second optimized prompt word output by the trained third model. The trained third model is used to optimize the first optimized prompt word according to the user portrait, historical input information, questions and dialogue scenarios, obtain and output the second optimized prompt word, learn the user's personalized needs, further optimize the prompt word, generate customized prompt words for the user that meet the question, and provide a basis for the reasoning model to output high-quality and expected answers.
[0147] In one embodiment, Figure 3 FIG. 1 is a third flow chart of a method for generating prompt words provided in an embodiment of the present application. Figure 3 As shown, before step S12, it also includes:
[0148] S21: Acquire first training data, second training data, and third training data.
[0149] Among them, the first training data includes multiple user questions and corresponding first labels, the first label includes a first real prompt word, the second training data includes context information, domain knowledge and corresponding second labels of user questions, the second label is a second real prompt word, and the third training data includes portrait information, scene information, context information and corresponding third labels of user questions, and the third label is a third real prompt word.
[0150] In the application, the user questions in the first training data cover a wide range of scenarios, such as shopping, travel, education, medical treatment, computers, etc.). The first label is the corresponding prompt word manually annotated, which is usually a concise framework that the model can understand.
[0151] The context of the second training data includes multi-round dialogue data and domain knowledge data. The multi-round dialogue data includes questions previously input by the user and answers output by the inference model.
[0152] The portrait information of the third training data includes the user's age, gender, interests, historical behavior and other information. The training model generates prompt words based on the user's personalized needs.
[0153] Scenario information includes different scenario features, such as work, leisure, study, etc., and the model is trained to recognize the scenario of the current conversation.
[0154] Contextual information includes the user’s emotional changes during the conversation, time, location, and other information, and the model is trained to learn the style and content of the prompt words.
[0155] S22: Train a first model using the first training data to obtain a trained first model.
[0156] S23: Train the second model using the second training data to obtain a trained second model.
[0157] S24: Train a third model using the third training data to obtain a trained third model.
[0158] In the application, the architecture of the first model, the second model, and the third model can be based on the Transformer architecture. Each model can be initialized using a pre-trained model (such as the GPT (Generative Pre-Trained Transformer) model) to ensure that each model has a strong natural language understanding capability. After initialization, fine-tuning training is performed.
[0159] Fine-tuning process:
[0160] For each model, supervised learning is used to fine-tune the prompt word generation task and gradually optimize the prompt words, with the goal of converting the input question into high-quality prompt words.
[0161] During the training of the first model, the goal is to quickly convert the user's natural language questions into a basic prompt word framework that the model can understand, ensuring that the subsequent reasoning model can handle it.
[0162] During the training of the second model, the goal is to further optimize the prompt words using the context of the question and domain-related knowledge to ensure that the prompt words are highly relevant to the domain and maintain the coherence of the conversation.
[0163] During the training of the third model, the goal is to personalize the prompt words based on the user portrait, scenario, and real-time context to ensure that the prompt words meet the user's personalized needs and the current conversation situation.
[0164] Loss function: Use the cross entropy loss function to optimize the model's prompt word generation accuracy.
[0165] Evaluation indicators: The value of the loss function, BLEU (Bilingual Evaluation Understudy), ROUGE (Recall-Oriented Understudy for Gisting Evaluation), etc. can be used to evaluate the quality of the prompt words generated by the model, and whether the generated prompt words help improve the answer effect of the inference large language model.
[0166] This embodiment trains the model through training data so that each trained model has generalization and personalization capabilities, thereby providing a basis for generating high-quality prompt words in different scenarios.
[0167] It should be understood that the order of execution of the steps in the above embodiments does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. In addition, the data collection in the above embodiments is compliant, and its use or implementation does not involve any infringement on the public interest.
[0168] Corresponding to the method described in the above embodiment, for the convenience of explanation, only the part related to the embodiment of the present application is shown.
[0169] In one embodiment, Figure 4 Schematic diagram of the structure of the prompt word generating device provided by an embodiment of the present application. Figure 4 As shown, the device comprises:
[0170] A receiving module 10, used to receive questions input by a user;
[0171] A generating module 11 is used to input a question into the trained first model and obtain basic prompt words output by the trained first model, wherein the trained first model is used to analyze the question and obtain and output basic prompt words;
[0172] It is also used to input the basic prompt words into the trained second model to obtain the first optimized prompt words output by the trained second model. The trained second model is used to optimize the basic prompt words according to historical dialogue information and domain knowledge to obtain and output the first optimized prompt words.
[0173] In one embodiment, the generating module is further used to input the first optimized prompt word into the trained third model to obtain the second optimized prompt word output by the trained third model, and the trained third model is used to optimize the first optimized prompt word according to the user portrait, historical input information, questions and dialogue scenarios, and obtain and output the second optimized prompt word;
[0174] The format of the second optimized prompt word is the format of input data of the inference model, and the inference model is used to determine the answer according to the prompt word.
[0175] Figure 5 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Figure 5 As shown, the electronic device 2 of this embodiment includes: at least one processor 20 ( Figure 5 Only one is shown in the figure), a memory 21, and a computer program 22 stored in the memory 21 and executable on the at least one processor 20, wherein the processor 20 implements the steps of any of the above-mentioned method embodiments when executing the computer program 22.
[0176] The electronic device 2 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The electronic device 2 may include, but is not limited to, a processor 20 and a memory 21. Those skilled in the art will appreciate that Figure 5 It is only an example of the electronic device 2 and does not constitute a limitation on the electronic device 2. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.
[0177] The processor 20 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0178] In some embodiments, the memory 21 may be an internal storage unit of the electronic device 2, such as a hard disk or memory of the electronic device 2. In other embodiments, the memory 21 may also be an external storage device of the electronic device 2, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 2. Further, the memory 21 may also include both an internal storage unit of the electronic device 2 and an external storage device. The memory 21 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program. The memory 21 may also be used to temporarily store data that has been output or is to be output.
[0179] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0180] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0181] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0182] An embodiment of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0183] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium can at least include: any entity or device that can carry the computer program code to the camera / terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, RandomAccess Memory), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some cases, the computer-readable medium cannot be an electric carrier signal and a telecommunication signal.
[0184] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0185] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0186] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0187] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0188] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for generating a prompt word, characterized in that: include: Receive user input questions; Input the question into a trained first model to obtain basic prompt words output by the trained first model, wherein the trained first model is used to analyze the question and obtain and output the basic prompt words; The basic prompt word is input into the trained second model to obtain the first optimized prompt word output by the trained second model, and the trained second model is used to optimize the basic prompt word according to the historical dialogue information and domain knowledge to obtain and output the first optimized prompt word.
2. The method according to claim 1, characterized in that After obtaining the first optimization prompt word output by the trained second model, the method further includes: Inputting the first optimized prompt word into a trained third model to obtain a second optimized prompt word output by the trained third model, wherein the trained third model is used to optimize the first optimized prompt word according to the user portrait, historical input information, and conversation scenario, and obtain and output the second optimized prompt word; The format of the second optimized prompt word is the format of input data of the inference model, and the inference model is used to determine the answer according to the prompt word.
3. The method according to claim 2, characterized in that: The trained first model is specifically used to obtain question type, user intent, key information, task instructions, and question-answering template from the question; The basic prompt words are generated according to the question type, the user intention, the key information, the task instruction, and the question and answer template.
4. The method according to claim 3, characterized in that: The trained second model is specifically used to obtain relevant questions and relevant answers from the historical dialogue information according to the question; and determine the domain knowledge according to the question; Determining the implicit intention of the question based on the historical conversation information; And according to the relevant questions, the relevant answers, the domain knowledge, and the implicit intention, the basic prompt words are optimized to obtain the first optimized prompt words.
5. The method according to claim 3, characterized in that: The trained second model is specifically used to obtain relevant questions and relevant answers from the historical dialogue information according to the question; and determine the implicit intention of the question according to the historical dialogue information; Determining the domain knowledge, the length of the prompt word, and the style of the prompt word according to the question; And according to the relevant questions, the relevant answers, the domain knowledge, the implicit intention, the prompt word length and the prompt word style, the basic prompt word is optimized to obtain the first optimized prompt word.
6. The method according to claim 2, characterized in that: The trained third model is specifically used to determine the user portrait according to the historical conversation information; determine the conversation scene according to the question; determine the user's emotional information according to the historical input information; determine relevant examples according to the user portrait, the conversation scene, the question and the emotional information; And according to the user portrait, the conversation scenario, the emotional information and the relevant examples, the first optimization prompt word is obtained to obtain the second optimization prompt word.
7. The method according to any one of claims 1 to 6, characterized in that: Before inputting the question into the trained first model and obtaining the basic prompt words output by the trained first model, the method further includes: Acquire first training data, second training data, and third training data, wherein the first training data includes multiple user questions and corresponding first labels, the first labels include first real prompt words, the second training data includes context information of the user questions, domain knowledge, and corresponding second labels, the second labels are second real prompt words, and the third training data includes portrait information of the user questions, scene information, the context information, and corresponding third labels, the third labels are third real prompt words; Using the first training data, training a first model to obtain the trained first model; Using the second training data, training a second model to obtain the trained second model; The third model is trained using the third training data to obtain the trained third model.
8. A prompt word generating device, characterized in that: include: A receiving module, used for receiving questions input by users; A generating module, used for inputting the question into a trained first model, obtaining basic prompt words output by the trained first model, wherein the trained first model is used for analyzing the question, obtaining and outputting the basic prompt words; The method is also used to input the basic prompt word into the trained second model to obtain the first optimized prompt word output by the trained second model. The trained second model is used to optimize the basic prompt word according to historical dialogue information and domain knowledge to obtain and output the first optimized prompt word.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Prompt word reconstruction model training and retrieval enhancement generation method, device and equipment
CN120723861A
Prompt word optimization method and device, electronic equipment, storage medium and product
CN121029941A
Conversation processing method and system based on personality characteristics, intelligent agent and electronic equipment
CN121413633A
Interaction method and device, electronic equipment and computer readable storage medium
CN121565169A
Intelligent question and answer method and device, electronic equipment and readable storage medium
CN122364407A