Prompt word generation method and device
The method automates prompt word generation from chat room data through domain determination and template matching, addressing the inefficiencies of manual data collection and enhancing large language model training.
Patent Information
- Application Number
- CN202411253030.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2024-12-27
AI Technical Summary
Current methods for training large language models require manual collection and preparation of question and answer data, which is labor-intensive and time-consuming.
A method and device for generating prompt words using question and answer data from chat rooms, involving domain determination and template matching to automate the process, reducing labor and time costs.
Automated generation of prompt words from chat room data improves efficiency and reduces costs by standardizing and logically accurate question-answer pairs, enhancing the training of large language models.
Smart Images

Figure CN119202169A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, specifically the field of deep learning, natural language processing and large language model technology. Background Art
[0002] A large language model is a deep learning model trained with a large amount of text data that can generate natural language text or understand the meaning of language text. Large language models can handle a variety of natural language tasks, such as text classification, question answering, and dialogue, and are an important path to artificial intelligence.
[0003] Currently, when faced with specific spy scenarios, professionals are needed to collect question and answer data and create prompt words, and then use these prompt words to train a large language model. Summary of the invention
[0004] The embodiments of the present disclosure provide a prompt word generation method, apparatus, device, storage medium, and program product.
[0005] In a first aspect, an embodiment of the present disclosure proposes a prompt word generation method, including: generating question and answer pairs based on question and answer data in a chat room; determining the domain of the question in the question and answer pairs; selecting a prompt word template based on the domain of the question; matching the question and answer pairs with the prompt word template to generate prompt words.
[0006] In the second aspect, an embodiment of the present disclosure proposes a prompt word generation device, including: a question-answer pair generation module, configured to generate question-answer pairs based on question-answer data in a chat room; a domain determination module, configured to determine the domain of the question in the question-answer pair; a template selection module, configured to select a prompt word template based on the domain of the question; and a prompt word generation module, configured to match the question-answer pair with the prompt word template to generate a prompt word.
[0007] In a third aspect, an embodiment of the present disclosure proposes an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in the first aspect.
[0008] In a fourth aspect, an embodiment of the present disclosure proposes a non-transitory computer-readable storage medium storing computer instructions, where the computer instructions are used to cause a computer to execute the method described in the first aspect.
[0009] In a fifth aspect, an embodiment of the present disclosure proposes a computer program product, including a computer program, which implements the method described in the first aspect when executed by a processor.
[0010] The key or important features of the embodiments of the present disclosure are not intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Other features, purposes and advantages of the present disclosure will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings. The drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure. Among them:
[0012] Figure 1 is a flow chart of an embodiment of a prompt word generating method according to the present disclosure;
[0013] Figure 2 is a flow chart of another embodiment of the prompt word generation method according to the present disclosure;
[0014] Figure 3 is a flow chart of another embodiment of the prompt word generating method according to the present disclosure;
[0015] Figure 4 is a structural diagram of a prompt word generation method according to the present disclosure;
[0016] Figure 5 is a structural schematic diagram of an embodiment of a prompt word generating device according to the present disclosure;
[0017] Figure 6 It is a block diagram of an electronic device used to implement the feature extraction method of the embodiment of the present disclosure. DETAILED DESCRIPTION
[0018] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0019] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0020] Figure 1 A process 100 of an embodiment of a prompt word generation method according to the present disclosure is shown. The prompt word generation method comprises the following steps:
[0021] Step 101, generating question-answer pairs based on question-answer data in the chat room.
[0022] In this embodiment, the execution body of the prompt word generation method can generate question and answer pairs based on the question and answer data in the chat room.
[0023] The execution subject of the prompt word generation method is usually a server. The server can be hardware or software. When the server is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or it can be implemented as a single server. When the server is software, it can be implemented as multiple software or software modules (for example, used to provide distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0024] An online chat room is usually called a chat room. It is a kind of online forum where users can chat online. Users in the same chat room can chat in real time by broadcasting messages. Chat rooms can be built on the basis of instant messaging software, and the means of conversation can include but are not limited to: text, voice, video, etc. Usually, chat rooms are based on rooms or channels, and users in the same room or channel can broadcast and read public messages in real time.
[0025] The chat room can pre-set multiple questions, such as what is the weather like today, how do you express your anger, etc. In order to reduce the complexity of question and answer data processing, the number of users participating in the chat (such as 5 people) and the chat duration (such as 30 minutes) can be limited. After the user registers a username and password on the web page, he can log in to the chat room. The chat room can support 3v3 or 5v5 chat. After entering the chat room, the chat room can ask multiple questions, and the user can choose to answer each question once. In addition, users in the chat room can also ask and answer freely. For example, M questions appear in the chat room, and each question is answered by N users. The question and answer data obtained from the chat room may include M questions and the answers of N users corresponding to each question.
[0026] In some embodiments, the questions in the M questions are paired with the corresponding answers of the N users one by one, and M×N first question-answer pairs can be generated. Among them, a first question-answer pair can include a question and an answer. By pairing questions and answers one by one, more question-answer pairs can be generated.
[0027] In some embodiments, the questions in the M questions are combined with the corresponding answers of the N users to generate M second question-answer pairs. Among them, a second question-answer pair may include a question and N answers. By integrating different answers to the same question, it is convenient to analyze the logic of different answers.
[0028] The first question-answer pair and the second question-answer pair can be used directly as question-answer pairs to perform subsequent steps, or they can be filtered to generate question-answer pairs. For example, the first question-answer pair is matched with the preset sensitive words in the preset sensitive word library, and the first question-answer pair that matches the preset sensitive words is filtered out, so that the remaining first question-answer pairs are more standardized. At the same time, logical judgment is performed on the different answers in the second question-answer pair, and the answers with logical contradictions in the second question-answer pair are filtered out, so that the remaining second question-answer pairs are more logically accurate. Subsequently, the intersection of the first question-answer pair and the second question-answer pair is taken to obtain a question-answer pair, thereby ensuring the standardization and logical accuracy of the question-answer pair.
[0029] Step 102, determining the domain of the question in the question-answer pair.
[0030] In this embodiment, the execution entity may determine the domain of the question in the question-answer pair.
[0031] The fields may include but are not limited to: weather, emotions, finance, medical care, etc. For each question in the question-answer pair, the question may be segmented to obtain a keyword set. The keyword set is matched with the preset domain dictionary, and the field matching the keyword set is determined as the field of the question, thereby improving the accuracy of the determined field. For example, the matching degree between the keyword set and each field in the preset domain dictionary is calculated, and the field with the highest matching degree is used as the field of the question.
[0032] Step 103: Select a prompt word template based on the field of the question.
[0033] In this embodiment, the execution entity may select a prompt word template based on the field of the question.
[0034] The prompt word templates can be designed and collected by people from different business teams. Once the prompt word template is determined, it will not change for a long time. One field can correspond to one or more prompt word templates. Different fields can correspond to different prompt word templates. Therefore, after determining the field of the problem, a prompt word template can be selected from the prompt word templates corresponding to the field of the problem.
[0035] When one field corresponds to one prompt word template, the prompt word template corresponding to the field of the question can be directly selected.
[0036] When a domain corresponds to multiple prompt word templates, a prompt word template may be selected from the multiple prompt word templates corresponding to the domain of the question according to a certain strategy.
[0037] In some embodiments, the keyword set of the question is matched with multiple prompt word templates corresponding to the field of the question, and the prompt word template that matches the keyword set is selected, thereby improving the accuracy of the selected prompt word template. Among them, the prompt word template that matches the keyword set can be one or more. In the case where there are multiple prompt word templates that match the keyword set, the prompt words generated by multiple prompt word templates can also be combined. For example, the weather field can include prompt word templates for weather such as average temperature, high temperature, low temperature, whether it is a holiday (such as whether it is the Dragon Boat Festival, whether it is the Mid-Autumn Festival, whether it is the National Day), strong wind, etc. For questions about the Mid-Autumn Festival, the prompt word template for the Mid-Autumn Festival weather can be matched. For questions about the minimum temperature below zero degrees, the prompt word template for low temperature weather can be matched.
[0038] In some embodiments, the question-answer pair and multiple prompt word templates corresponding to the field of the question are respectively input into the encoder to obtain the question-answer pair word vector and multiple prompt word template word vectors; the distance between the question-answer pair word vector and the multiple prompt word template word vectors is calculated, and the prompt word template with the closest distance is selected, thereby improving the accuracy of the selected prompt word template.
[0039] Step 104, matching the question-answer pair with the prompt word template to generate a prompt word.
[0040] In this embodiment, the execution entity may match the question-answer pair with the prompt word template to generate a prompt word.
[0041] In some embodiments, the question-answer pair is matched with the prompt word template, and the value of the variable in the prompt word template can be determined from the question-answer pair; the variable in the prompt word template is replaced by the value of the variable to generate a prompt word. Taking the weather field as an example, the generated question-answer pair is "Q: What is the temperature in a certain city today? A: The temperature in a certain city today is 37 degrees." The main framework of the selected prompt word template is "Please answer the question based on the following background information, especially the numbers in it, that is, the bold part. The following is the weather conditions on xx / xx / xx, with an average temperature of xx degrees." After that, other information will be accessed according to the specific temperature conditions. Because the temperature is higher than 30 degrees, the following information is "In hot weather, you should pay attention to sun protection and heatstroke prevention, and avoid prolonged exposure to the sun." Finally, the generated prompt words are (taking today's date, September 4, 2024, as an example): "Please answer the questions based on the following background information, paying special attention to the numbers in bold. The following is the weather conditions on September 4, 2024. The average temperature is 37 degrees. It is hot weather, so you should pay attention to sun protection and heatstroke prevention, and avoid prolonged exposure to the sun."
[0042] The disclosed embodiment provides a prompt word generation method based on a chat room function, which automatically collects question and answer data and generates prompt words, thereby reducing labor costs and time costs.
[0043] Continue to refer Figure 2 , which shows a process 200 of another embodiment of the prompt word generation method according to the present disclosure. The prompt word generation method includes the following steps:
[0044] Step 201 , pair the M questions with the corresponding N users' answers one by one to generate M×N first question-answer pairs.
[0045] In this embodiment, the execution subject of the prompt word generation method can pair the questions in the M questions with the corresponding answers of the N users one by one to generate M×N first question-answer pairs.
[0046] The execution subject of the prompt word generation method is usually a server. The server can be hardware or software. When the server is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or it can be implemented as a single server. When the server is software, it can be implemented as multiple software or software modules (for example, used to provide distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0047] An online chat room is usually called a chat room. It is a kind of online forum where users can chat online. Users in the same chat room can chat in real time by broadcasting messages. Chat rooms can be built on the basis of instant messaging software, and the means of conversation can include but are not limited to: text, voice, video, etc. Usually, chat rooms are based on rooms or channels, and users in the same room or channel can broadcast and read public messages in real time.
[0048] The chat room can pre-set multiple questions, such as what is the weather like today, how do you express your anger, etc. In order to reduce the complexity of question and answer data processing, the number of users participating in the chat (such as 5 people) and the chat duration (such as 30 minutes) can be limited. After the user registers the username and password on the web page, he can log in to the chat room. The chat room can support 3v3 or 5v5 chat. After entering the chat room, the chat room can ask multiple questions, and the user can choose to answer each question once. In addition, users in the chat room can also ask and answer freely. For example, M questions appear in the chat room, and each question is answered by N users. The question and answer data obtained from the chat room may include M questions and the answers of N users corresponding to each question. By matching the questions in the M questions with the corresponding answers of N users one by one, M×N first question and answer pairs can be generated. Among them, a first question and answer pair can include a question and an answer. By matching questions and answers one by one, more question and answer pairs can be generated.
[0049] Step 202: Match the first question-answer pair with preset sensitive words in a preset sensitive word library, and filter out the first question-answer pair that matches the preset sensitive words.
[0050] In this embodiment, the execution subject may match the first question-answer pair with a preset sensitive word in a preset sensitive word library, filter out the first question-answer pair that matches the preset sensitive word, and make the remaining first question-answer pairs more standardized. For example, if the first question-answer pair matches a sensitive word such as pornography, gambling, or drugs, the first question-answer pair is deleted.
[0051] Step 203: Combine the M questions with the corresponding answers of the N users to generate M second question-answer pairs.
[0052] In this embodiment, the execution entity may combine the questions in the M questions with the corresponding answers of the N users to generate M second question-answer pairs.
[0053] The question-and-answer data obtained from the chat room may include M questions and the answers of N users corresponding to each question. The questions in the M questions are combined with the corresponding answers of the N users to generate M second question-and-answer pairs. Among them, a second question-and-answer pair may include a question and N answers. By integrating different answers to the same question, it is convenient to analyze the logic of different answers.
[0054] Step 204: perform logical judgment on different answers in the second question-answer pair, and filter out answers in the second question-answer pair that have logical contradictions.
[0055] In this embodiment, the execution subject can perform logical judgment on different answers in the second question-answer pair, filter out logically contradictory answers in the second question-answer pair, and make the remaining second question-answer pairs more logically accurate. For example, for different answers in the second question-answer pair, if there is one answer that is opposite to the other answers, the opposite answer is deleted.
[0056] Step 205: Take the intersection of the first question-answer pair and the second question-answer pair to obtain a question-answer pair.
[0057] In this embodiment, the above-mentioned execution entity can take the intersection of the first question and answer pair and the second question and answer pair to obtain the question and answer pair, thereby ensuring the standardization and logical accuracy of the question and answer pair.
[0058] Step 206, segment the question in the question-answer pair to obtain a keyword set of the question.
[0059] In this embodiment, the execution entity may perform word segmentation on the question in the question-answer pair to obtain a keyword set of the question.
[0060] Step 207 : Match the keyword set with the preset domain dictionary, and determine the domain that matches the keyword set as the domain of the question.
[0061] In this embodiment, the execution subject may match the keyword set with the preset domain dictionary, and determine the domain that matches the keyword set as the domain of the problem, thereby improving the accuracy of the determined domain. For example, the matching degree between the keyword set and each domain in the preset domain dictionary is calculated, and the domain with the highest matching degree is used as the domain of the problem.
[0062] Step 208: Select a prompt word template based on the domain of the question.
[0063] In this embodiment, the execution entity may select a prompt word template based on the field of the question.
[0064] The prompt word templates can be designed and collected by people from different business teams. Once the prompt word template is determined, it will not change for a long time. One field can correspond to one or more prompt word templates. Different fields can correspond to different prompt word templates. Therefore, after determining the field of the problem, a prompt word template can be selected from the prompt word templates corresponding to the field of the problem.
[0065] When one field corresponds to one prompt word template, the prompt word template corresponding to the field of the question can be directly selected.
[0066] When a domain corresponds to multiple prompt word templates, a prompt word template may be selected from the multiple prompt word templates corresponding to the domain of the question according to a certain strategy.
[0067] In some embodiments, the keyword set of the question is matched with multiple prompt word templates corresponding to the field of the question, and the prompt word template that matches the keyword set is selected, thereby improving the accuracy of the selected prompt word template. Among them, the prompt word template that matches the keyword set can be one or more. In the case where there are multiple prompt word templates that match the keyword set, the prompt words generated by multiple prompt word templates can also be combined. For example, the weather field can include prompt word templates for weather such as average temperature, high temperature, low temperature, whether it is a holiday (such as whether it is the Dragon Boat Festival, whether it is the Mid-Autumn Festival, whether it is the National Day), strong wind, etc. For questions about the Mid-Autumn Festival, the prompt word template for the Mid-Autumn Festival weather can be matched. For questions about the minimum temperature below zero degrees, the prompt word template for low temperature weather can be matched.
[0068] In some embodiments, the question-answer pair and multiple prompt word templates corresponding to the field of the question are respectively input into the encoder to obtain the question-answer pair word vector and multiple prompt word template word vectors; the distance between the question-answer pair word vector and the multiple prompt word template word vectors is calculated, and the prompt word template with the closest distance is selected, thereby improving the accuracy of the selected prompt word template.
[0069] Step 209, matching the question-answer pair with the prompt word template, and determining the value of the variable in the prompt word template from the question-answer pair.
[0070] In this embodiment, the execution entity may match the question-answer pair with the prompt word template, and determine the value of the variable in the prompt word template from the question-answer pair.
[0071] Step 210: replace the variable in the prompt word template with the value of the variable to generate a prompt word.
[0072] In this embodiment, the execution subject may replace the variable in the prompt word template with the value of the variable to generate the prompt word.
[0073] Taking the weather field as an example, the generated question-answer pair is "Q: What is the temperature in XX city today? A: The temperature in XX city today is 37 degrees." The main framework of the selected prompt word template is "Please answer the question based on the following background information, especially the numbers in it, that is, the bold part. The following is the weather conditions on XX / XX / XX, with an average temperature of XX degrees." After that, other information will be accessed according to the specific temperature conditions. Because the temperature is higher than 30 degrees, the following information is "In hot weather, you should pay attention to sun protection and heatstroke prevention, and avoid prolonged exposure to the sun." In the end, the generated prompt word is (taking today's date, September 4, 2024, as an example) "Please answer the question based on the following background information, especially the numbers in it, that is, the bold part. The following is the weather conditions on September 4, 2024, with an average temperature of 37 degrees. In hot weather, you should pay attention to sun protection and heatstroke prevention, and avoid prolonged exposure to the sun."
[0074] The disclosed embodiment provides a prompt word generation method based on a chat room function, which automatically collects question and answer data and generates prompt words, thereby reducing labor costs and time costs.
[0075] Further references Figure 3 , which shows a process 300 of another embodiment of the prompt word generation method according to the present disclosure. The prompt word generation method includes the following steps:
[0076] Step 301, generating question-answer pairs based on question-answer data in the chat room.
[0077] In this embodiment, the execution body of the prompt word generation method can generate question and answer pairs based on the question and answer data in the chat room.
[0078] The execution subject of the prompt word generation method is usually a server. The server can be hardware or software. When the server is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or it can be implemented as a single server. When the server is software, it can be implemented as multiple software or software modules (for example, used to provide distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0079] An online chat room is usually called a chat room. It is a kind of online forum where users can chat online. Users in the same chat room can chat in real time by broadcasting messages. Chat rooms can be built on the basis of instant messaging software, and the means of conversation can include but are not limited to: text, voice, video, etc. Usually, chat rooms are based on rooms or channels, and users in the same room or channel can broadcast and read public messages in real time.
[0080] The chat room can pre-set multiple questions, such as what is the weather like today, how do you express your anger, etc. In order to reduce the complexity of question and answer data processing, the number of users participating in the chat (such as 5 people) and the chat duration (such as 30 minutes) can be limited. After the user registers a username and password on the web page, he can log in to the chat room. The chat room can support 3v3 or 5v5 chat. After entering the chat room, the chat room can ask multiple questions, and the user can choose to answer each question once. In addition, users in the chat room can also ask and answer freely. For example, M questions appear in the chat room, and each question is answered by N users. The question and answer data obtained from the chat room may include M questions and the answers of N users corresponding to each question.
[0081] In some embodiments, the questions in the M questions are paired with the corresponding answers of the N users one by one, and M×N first question-answer pairs can be generated. Among them, a first question-answer pair can include a question and an answer. By pairing questions and answers one by one, more question-answer pairs can be generated.
[0082] In some embodiments, the questions in the M questions are combined with the corresponding answers of the N users to generate M second question-answer pairs. Among them, a second question-answer pair may include a question and N answers. By integrating different answers to the same question, it is convenient to analyze the logic of different answers.
[0083] The first question-answer pair and the second question-answer pair can be used directly as question-answer pairs to perform subsequent steps, or they can be filtered to generate question-answer pairs. For example, the first question-answer pair is matched with the preset sensitive words in the preset sensitive word library, and the first question-answer pair that matches the preset sensitive words is filtered out, so that the remaining first question-answer pairs are more standardized. At the same time, logical judgment is performed on the different answers in the second question-answer pair, and the answers with logical contradictions in the second question-answer pair are filtered out, so that the remaining second question-answer pairs are more logically accurate. Subsequently, the intersection of the first question-answer pair and the second question-answer pair is taken to obtain a question-answer pair, thereby ensuring the standardization and logical accuracy of the question-answer pair.
[0084] Step 302, determining the domain of the question in the question-answer pair.
[0085] In this embodiment, the execution entity may determine the domain of the question in the question-answer pair.
[0086] The fields may include but are not limited to: weather, emotions, finance, medical care, etc. For each question in the question-answer pair, the question may be segmented to obtain a keyword set. The keyword set is matched with the preset domain dictionary, and the field matching the keyword set is determined as the field of the question, thereby improving the accuracy of the determined field. For example, the matching degree between the keyword set and each field in the preset domain dictionary is calculated, and the field with the highest matching degree is used as the field of the question.
[0087] Step 303: Select a prompt word template based on the field of the question.
[0088] In this embodiment, the execution entity may select a prompt word template based on the field of the question.
[0089] The prompt word templates can be designed and collected by people from different business teams. Once the prompt word template is determined, it will not change for a long time. One field can correspond to one or more prompt word templates. Different fields can correspond to different prompt word templates. Therefore, after determining the field of the problem, a prompt word template can be selected from the prompt word templates corresponding to the field of the problem.
[0090] When one field corresponds to one prompt word template, the prompt word template corresponding to the field of the question can be directly selected.
[0091] When a domain corresponds to multiple prompt word templates, a prompt word template may be selected from the multiple prompt word templates corresponding to the domain of the question according to a certain strategy.
[0092] In some embodiments, the keyword set of the question is matched with multiple prompt word templates corresponding to the field of the question, and the prompt word template that matches the keyword set is selected, thereby improving the accuracy of the selected prompt word template. Among them, the prompt word template that matches the keyword set can be one or more. In the case where there are multiple prompt word templates that match the keyword set, the prompt words generated by multiple prompt word templates can also be combined. For example, the weather field can include prompt word templates for weather such as average temperature, high temperature, low temperature, whether it is a holiday (such as whether it is the Dragon Boat Festival, whether it is the Mid-Autumn Festival, whether it is the National Day), strong wind, etc. For questions about the Mid-Autumn Festival, the prompt word template for the Mid-Autumn Festival weather can be matched. For questions about the minimum temperature below zero degrees, the prompt word template for low temperature weather can be matched.
[0093] In some embodiments, the question-answer pair and multiple prompt word templates corresponding to the field of the question are respectively input into the encoder to obtain the question-answer pair word vector and multiple prompt word template word vectors; the distance between the question-answer pair word vector and the multiple prompt word template word vectors is calculated, and the prompt word template with the closest distance is selected, thereby improving the accuracy of the selected prompt word template.
[0094] Step 304, matching the question-answer pair with the prompt word template to generate a prompt word.
[0095] In this embodiment, the execution entity may match the question-answer pair with the prompt word template to generate a prompt word.
[0096] In some embodiments, the question-answer pair is matched with the prompt word template, and the value of the variable in the prompt word template can be determined from the question-answer pair; the variable in the prompt word template is replaced by the value of the variable to generate a prompt word. Taking the weather field as an example, the generated question-answer pair is "Q: What is the temperature in a certain city today? A: The temperature in a certain city today is 37 degrees." The main framework of the selected prompt word template is "Please answer the question based on the following background information, especially the numbers in it, that is, the bold part. The following is the weather conditions on xx / xx / xx, with an average temperature of xx degrees." After that, other information will be accessed according to the specific temperature conditions. Because the temperature is higher than 30 degrees, the following information is "In hot weather, you should pay attention to sun protection and heatstroke prevention, and avoid prolonged exposure to the sun." Finally, the generated prompt words are (taking today's date, September 4, 2024, as an example): "Please answer the questions based on the following background information, paying special attention to the numbers in bold. The following is the weather conditions on September 4, 2024. The average temperature is 37 degrees. It is hot weather, so you should pay attention to sun protection and heatstroke prevention, and avoid prolonged exposure to the sun."
[0097] Step 305 , taking the question in the question-answer pair corresponding to the prompt word belonging to the target domain as input, taking the prompt word as the expected output, and training to obtain a question-answer model corresponding to the target domain.
[0098] In this embodiment, the execution subject can use the question in the question-answer pair corresponding to the prompt word belonging to the target domain as input, and the prompt word as the expected output, and fine-tune the pre-trained large language model to obtain the question-answer model corresponding to the target domain. Among them, the large language model can be pre-trained on a large amount of text data, and can perform a wide range of tasks, including but not limited to question-answering, text summarization, translation, sentiment analysis, etc. Here, the large language model is fine-tuned using the prompt words belonging to the target domain to obtain the question-answer model corresponding to the target domain, so that the answer output by the question-answer model is more matched with the corresponding domain.
[0099] The disclosed embodiment provides a prompt word generation method based on the chat room function, which automatically collects question and answer data and generates prompt words, reducing labor costs and time costs. In addition, the large language model is fine-tuned using prompt words belonging to the target field to obtain a question and answer model corresponding to the target field, so that the answer output by the question and answer model is more matched with the corresponding field.
[0100] Further references Figure 4 , which shows the structure 400 of the prompt word generation method according to the present disclosure. The structure 400 of the prompt word generation method may include a chat room page 401, a chat room background 402, and a prompt word generation service 403. User 1, user 2, and user 3 enter the chat room, and the chat room page 401 is displayed on the terminals of user 1, user 2, and user 3. The question information preset by the chat room background 401 can be displayed on the chat room page 401. User 1, user 2, and user 3 can answer the question information. The question information and the answers of user 1, user 2, and user 3 can be sent to the prompt word generation service 403 as user data. The prompt word generation service 403 can automatically generate prompt words based on the user data.
[0101] Further references Figure 5 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a prompt word generating device, and the device embodiment is Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0102] like Figure 5As shown, the prompt word generating device 500 of this embodiment may include: a question-answer pair generating module 501, a domain determining module 502, a template selecting module 503 and a prompt word generating module 504. The question-answer pair generating module 501 is configured to generate a question-answer pair based on the question-answer data in the chat room; the domain determining module 502 is configured to determine the domain of the question in the question-answer pair; the template selecting module 503 is configured to select a prompt word template based on the domain of the question; and the prompt word generating module 504 is configured to match the question-answer pair with the prompt word template to generate a prompt word.
[0103] In this embodiment, the specific processing of the question-answer pair generating module 501, the domain determining module 502, the template selecting module 503 and the prompt word generating module 504 and the technical effects thereof can be referred to in detail. Figure 1 The relevant descriptions of steps 101 - 104 in the corresponding embodiment are not repeated here.
[0104] In some optional implementations of this embodiment, the question and answer data includes M questions and answers from N users corresponding to each question; and the question and answer pair generation module 501 includes: a first generation submodule, configured to pair the questions in the M questions with the corresponding answers from the N users one by one, to generate M×N first question and answer pairs.
[0105] In some optional implementations of this embodiment, the question-answer pair generation module 501 also includes: a first filtering submodule, configured to match the first question-answer pair with preset sensitive words in a preset sensitive word library, and filter out the first question-answer pair that matches the preset sensitive words.
[0106] In some optional implementations of this embodiment, the question and answer data includes M questions and answers from N users corresponding to each question; and the question and answer pair generation module 501 includes: a second generation submodule, configured to combine the questions in the M questions with the corresponding answers from the N users to generate M second question and answer pairs.
[0107] In some optional implementations of this embodiment, the question-answer pair generation module 501 also includes: a second filtering submodule, which is configured to perform logical judgment on different answers in the second question-answer pair, and filter out answers with logical contradictions in the second question-answer pair.
[0108] In some optional implementations of this embodiment, the question-answer pair generation module 501 also includes: an intersection submodule, which is configured to take the intersection of the first question-answer pair and the second question-answer pair to obtain a question-answer pair.
[0109] In some optional implementations of this embodiment, the domain determination module 502 is further configured to: segment the questions in the question-answer pair to obtain a keyword set of the question; match the keyword set with a preset domain dictionary, and determine the domain that matches the keyword set as the domain of the question.
[0110] In some optional implementations of this embodiment, the template selection module 503 is further configured to: match the keyword set of the question with multiple prompt word templates corresponding to the field of the question, and select the prompt word template that matches the keyword set.
[0111] In some optional implementations of the present embodiment, the template selection module 503 is further configured to: input the question-answer pair and multiple prompt word templates corresponding to the field of the question into the encoder respectively to obtain the question-answer pair word vector and multiple prompt word template word vectors; calculate the distance between the question-answer pair word vector and the multiple prompt word template word vectors, and select the prompt word template with the closest distance.
[0112] In some optional implementations of this embodiment, the prompt word generation module 504 is further configured to: match the question-answer pair with the prompt word template, determine the value of the variable in the prompt word template from the question-answer pair; and replace the variable in the prompt word template with the value of the variable to generate a prompt word.
[0113] In some optional implementations of this embodiment, the prompt word generating device 500 also includes: a model training module, which is configured to take the question in the question-answer pair corresponding to the prompt word belonging to the target field as input, and the prompt word as the expected output, to train a question-answer model corresponding to the target field.
[0114] In the technical solution disclosed herein, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0115] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0116] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment 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 can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0117] like Figure 6 As shown, the device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0118] A number of components in the device 600 are connected to the I / O interface 605, including: an input unit 606, such as a keyboard, a mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0119] The computing unit 601 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 601 performs the various methods and processes described above, such as feature extraction methods. For example, in some embodiments, the feature extraction method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the feature extraction method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the feature extraction method in any other appropriate manner (e.g., by means of firmware).
[0120] Various implementations 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 chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0121] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0122] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0123] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the 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 acoustic input, voice input, or tactile input).
[0124] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0125] A computer system may include a client and a server. The client and the server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises through computer programs running on respective computers and having a client-server relationship to each other. The server may be a cloud server, a server in a distributed system, or a server combined with a blockchain.
[0126] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions provided by this disclosure can be achieved, and this document does not limit this.
[0127] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for generating a prompt word, comprising: Generate question-answer pairs based on the question-answer data in the chat room; determining the domain of the question in the question-answer pair; Select a prompt word template based on the domain of the problem; The question-answer pair is matched with the prompt word template to generate a prompt word.
2. The method according to claim 1, wherein: The question-and-answer data includes M questions and N users' answers corresponding to each question; as well as The step of generating a question-answer pair based on the question-answer data comprises: The M questions are paired with the corresponding answers of the N users one by one to generate M×N first question-answer pairs.
3. The method according to claim 2, wherein: The generating a question-answer pair based on the question-answer data further includes: The first question-answer pair is matched with a preset sensitive word in a preset sensitive word library, and the first question-answer pair matching the preset sensitive word is filtered out.
4. The method according to claim 3, wherein: The question-and-answer data includes M questions and N users' answers corresponding to each question; as well as The step of generating a question-answer pair based on the question-answer data comprises: The questions in the M questions are combined with the corresponding answers of the N users to generate M second question-answer pairs.
5. The method according to claim 4, wherein: The generating a question-answer pair based on the question-answer data further includes: Perform logical judgment on different answers in the second question-answer pair, and filter out answers in the second question-answer pair that have logical contradictions.
6. The method according to claim 5, wherein: The generating a question-answer pair based on the question-answer data further includes: An intersection is taken for the first question-answer pair and the second question-answer pair to obtain the question-answer pair.
7. The method according to any one of claims 1 to 6, wherein: Determining the domain of the question in the question-answer pair includes: Segmenting the question in the question-answer pair to obtain a keyword set for the question; The keyword set is matched with a preset domain dictionary, and the domain matching the keyword set is determined as the domain of the problem.
8. The method according to claim 7, wherein: The selecting of a prompt word template based on the field of the problem includes: The keyword set of the question is matched with a plurality of prompt word templates corresponding to the field of the question, and a prompt word template matching the keyword set is selected.
9. The method according to claim 7, wherein: The selecting of a prompt word template based on the field of the problem includes: Input the question-answer pair and a plurality of prompt word templates corresponding to the field of the question into an encoder respectively to obtain a question-answer pair word vector and a plurality of prompt word template word vectors; The distance between the question-answer pair word vector and the plurality of prompt word template word vectors is calculated, and the prompt word template with the closest distance is selected.
10. The method according to any one of claims 1 to 6, wherein: The step of matching the question-answer pair with the prompt word template to generate a prompt word includes: Matching the question-answer pair with the prompt word template, and determining the value of the variable in the prompt word template from the question-answer pair; The variable in the prompt word template is replaced by the value of the variable to generate the prompt word.
11. The method according to any one of claims 1 to 6, wherein: The method further comprises: The question in the question-answer pair corresponding to the prompt word belonging to the target domain is taken as input, and the prompt word is taken as the expected output, and a question-answer model corresponding to the target domain is obtained through training.
12. A prompt word generating device, comprising: A question-answer pair generation module is configured to generate question-answer pairs based on question-answer data in the chat room; A domain determination module configured to determine the domain of the question in the question-answer pair; A template selection module is configured to select a prompt word template based on the domain of the question; The prompt word generation module is configured to match the question-answer pair with the prompt word template to generate a prompt word.
13. The device according to claim 12, wherein: The question-and-answer data includes M questions and N users' answers corresponding to each question; as well as The question-answer pair generation module comprises: The first generation submodule is configured to pair the questions in the M questions with the corresponding answers of the N users one by one to generate M×N first question-answer pairs.
14. The device according to claim 13, wherein: The question-answer pair generation module also includes: The first filtering submodule is configured to match the first question-answer pair with a preset sensitive word in a preset sensitive word library, and filter out the first question-answer pair that matches the preset sensitive word.
15. The device according to claim 14, wherein: The question-and-answer data includes M questions and N users' answers corresponding to each question; as well as The question-answer pair generation module comprises: The second generation submodule is configured to combine the questions in the M questions with the corresponding answers of the N users to generate M second question-answer pairs.
16. The device according to claim 15, wherein: The question-answer pair generation module also includes: The second filtering submodule is configured to perform logical judgment on different answers in the second question-answer pair, and filter out answers in the second question-answer pair that have logical contradictions.
17. The device according to claim 16, wherein: The question-answer pair generation module also includes: The intersection submodule is configured to take the intersection of the first question-answer pair and the second question-answer pair to obtain the question-answer pair.
18. The device according to any one of claims 12 to 17, wherein: The domain determination module is further configured to: Segmenting the question in the question-answer pair to obtain a keyword set for the question; The keyword set is matched with a preset domain dictionary, and the domain matching the keyword set is determined as the domain of the problem.
19. The device according to claim 18, wherein The template selection module is further configured to: The keyword set of the question is matched with a plurality of prompt word templates corresponding to the field of the question, and a prompt word template matching the keyword set is selected.
20. The device according to claim 18, wherein The template selection module is further configured to: Input the question-answer pair and a plurality of prompt word templates corresponding to the field of the question into an encoder respectively to obtain a question-answer pair word vector and a plurality of prompt word template word vectors; The distance between the question-answer pair word vector and the plurality of prompt word template word vectors is calculated, and the prompt word template with the closest distance is selected.
21. The device according to any one of claims 12 to 17, wherein: The prompt word generation module is further configured to: Matching the question-answer pair with the prompt word template, and determining the value of the variable in the prompt word template from the question-answer pair; The variable in the prompt word template is replaced by the value of the variable to generate the prompt word.
22. The device according to any one of claims 12 to 17, wherein: The device also includes: The model training module is configured to take the question in the question-answer pair corresponding to the prompt word belonging to the target domain as input, take the prompt word as the expected output, and train to obtain the question-answer model corresponding to the target domain.
23. 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, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 11.
24. A non-transitory computer-readable storage medium storing computer instructions, the computer instructions being used to cause the computer to execute the method of any one of claims 1-11.
25. A computer program product comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Multilanguage question and answer interface fast constituting method based on domain ontology and template logics
CN104361127A
Chinese medicine question-answering system and method based on knowledge graph
CN113569023A
Question and answer pair generation method and device, computer equipment and storage medium
CN115481223A
Method and device for generating question and answer pairs
CN116881470A
Program development assisting method based on AIGC, storage medium and equipment
CN116991990A
