Model training method and device, computer equipment and computer readable storage medium
By generating and using conversation sample pairs based on fact record text, training the dialogue generation model is solved, and the dialogue generation model cannot accurately answer objective fact problems is improved, and the dialogue accuracy and efficiency of the model are improved.
Patent Information
- Application Number
- CN202311715375.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-13
- Publication Date
- 2024-12-20
AI Technical Summary
After fine-tuning the existing dialogue generation model for specific application scenarios, it is unable to accurately answer objective factual questions, resulting in poor dialogue effect.
By obtaining fact record text and reply prompt text, enter a dialogue generation model to generate multiple rounds of conversation content that simulates human-computer communication, generate dialogue sample pairs based on these conversation contents, and train a second dialogue generation model based on these sample pairs.
The accuracy of the second dialogue generation model responds to objective factual problems is improved, the dialogue effect is improved, and the generation time of dialogue sample pairs is reduced, and the model training efficiency is improved.
Smart Images

Figure CN119166757A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a model training method, apparatus, computer equipment and computer-readable storage medium. Background Art
[0002] After fine-tuning for specific application scenarios, existing dialogue generation models are unable to provide correct answers to factual dialogue tasks. For example, for questions such as "Who is the founder of XX company?", there is an objective answer, but the dialogue generation model cannot answer it accurately, resulting in poor dialogue performance of the dialogue generation model. Summary of the invention
[0003] The embodiments of the present application provide a model training method, apparatus, computer device, and computer-readable storage medium, which can improve the accuracy of the second dialogue generation model's responses to objective fact-related questions and improve the dialogue effect of the second dialogue generation model.
[0004] A model training method provided in an embodiment of the present application includes:
[0005] Obtaining fact record text and reply prompt text, wherein the reply prompt text is used to instruct the trained first dialogue generation model to generate reply content that meets the conditions;
[0006] Inputting the fact record text and the reply prompt text into the first dialogue generation model;
[0007] Generate, by the first dialogue generation model, a multi-round dialogue content simulating human-computer communication based on the factual record text, wherein the reply text in the multi-round dialogue content includes content associated with the factual record text;
[0008] Generating multiple groups of dialogue sample pairs according to the multiple rounds of dialogue contents;
[0009] The second dialogue generation model is trained based on the multiple groups of dialogue samples to obtain a trained second dialogue generation model.
[0010] Accordingly, an embodiment of the present application also provides a model training device, including:
[0011] An acquisition unit, used to acquire a fact record text and a reply prompt text, wherein the reply prompt text is used to instruct the trained first dialogue generation model to generate reply content that meets the conditions;
[0012] A first input unit, used for inputting the fact record text and the reply prompt text into the first dialogue generation model;
[0013] A second dialogue generation unit, configured to generate, by using the first dialogue generation model, a multi-round dialogue content simulating human-computer communication based on the fact record text and the reply prompt text, wherein the reply text in the multi-round dialogue content includes content associated with the fact record text;
[0014] A sample generating unit, configured to generate multiple groups of dialogue sample pairs according to the multiple rounds of dialogue contents;
[0015] A training unit is used to train the second dialogue generation model based on the multiple groups of dialogue samples to obtain a trained second dialogue generation model.
[0016] In one embodiment, the acquisition unit includes:
[0017] A text acquisition subunit, used to acquire candidate fact record texts and historical query texts corresponding to a plurality of facts, wherein the candidate fact record text information includes fact topics;
[0018] A comparison subunit, used for comparing the historical query text with the fact subject to obtain the relevance between the fact subject and the historical query text;
[0019] The screening subunit is used to screen the fact record text from the candidate fact record texts according to the relationship between the relevance and a preset threshold.
[0020] In one embodiment, the first input unit includes:
[0021] A construction subunit, used for constructing a question text by combining the fact record text and the question text template;
[0022] The text input subunit is used to input the question text into the first dialogue generation model.
[0023] In one embodiment, the model training device further includes:
[0024] A second input unit, used for inputting the fact record text and the reply prompt text into the second dialogue generation model;
[0025] A second dialogue generation unit, configured to generate multiple rounds of dialogue content to be verified by using the second dialogue generation model;
[0026] A calculation unit, configured to take the multiple rounds of conversation contents as true values, and calculate loss values according to the multiple rounds of conversation contents and the multiple rounds of conversation contents to be verified;
[0027] A fine-tuning unit is used to fine-tune the trained dialogue generation model according to the loss value.
[0028] In one embodiment, the fine-tuning unit comprises:
[0029] A weight determination subunit, used to determine the corresponding loss weight according to the language type of each round of dialogue content to be verified;
[0030] A weighting subunit, used for performing weighted processing on the loss value according to the loss weight to obtain a weighted loss value;
[0031] A fine-tuning processing subunit is used to fine-tune the trained dialogue generation model based on the weighted loss value.
[0032] In one embodiment, the trained second dialogue generation model includes a word segmenter, and the model training device further includes:
[0033] A training text acquisition unit, used to acquire a Chinese training text, wherein the Chinese training text is marked with a start position and an end position of each word;
[0034] A word segmentation unit, used to perform word segmentation processing on the Chinese training text through a word segmenter to obtain a word segmentation processing result;
[0035] The word segmenter processing unit is used to train the word segmenter according to the word segmentation processing result and the starting position and the ending position of each word marked in the Chinese training text to obtain the trained word segmenter.
[0036] In one embodiment, the sample generation unit includes:
[0037] The recognition subunit is used to perform dialogue intention recognition on each question text in each round of dialogue content to obtain the intended text in the question text;
[0038] A similar text acquisition subunit, used to acquire a similar intention text of the intention text;
[0039] A replacement subunit, used for performing text replacement processing on the corresponding question text with the similar intention text to obtain a replaced question text;
[0040] The sample pair generating subunit is used to generate the plurality of groups of dialogue sample pairs according to the question texts and the reply texts of the plurality of rounds of dialogue contents, and the replaced question texts and the corresponding reply texts.
[0041] Correspondingly, an embodiment of the present application also provides a computer device, including a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to execute any model training method provided in the embodiment of the present application.
[0042] Correspondingly, an embodiment of the present application also provides a computer-readable storage medium, which is used to store a computer program, and the computer program is loaded by a processor to execute any model training method provided in the embodiment of the present application.
[0043] The embodiment of the present application obtains fact record text and reply prompt text, and the reply prompt text is used to indicate that the trained first dialogue generation model generates qualified reply content; the fact record text and the reply prompt text are input into the first dialogue generation model; the first dialogue generation model generates multiple rounds of dialogue content simulating human-computer communication based on the fact record text and the reply prompt text, and the reply text in the multiple rounds of dialogue content contains content associated with the fact record text; multiple groups of dialogue sample pairs are generated according to the multiple rounds of dialogue content; and the second dialogue generation model is trained based on the multiple groups of dialogue samples to obtain the trained second dialogue generation model.
[0044] The embodiment of the present application trains the second dialogue generation model by generating dialogue sample pairs based on factual record text, which can improve the accuracy of the second dialogue generation model in responding to questions about objective facts and improve the dialogue effect of the second dialogue generation model. The dialogue sample pairs are generated by the first dialogue generation model, and there is no need to manually produce dialogue sample pairs, which reduces the time for generating dialogue sample pairs and improves the training efficiency of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0046] Figure 1 is a flow chart of the model training method provided in an embodiment of the present application;
[0047] Figure 2 It is a schematic diagram of the model training device provided in the embodiment of the present application;
[0048] Figure 3 It is a schematic diagram showing the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0050] The embodiment of the present application provides a model training method, device, computer equipment and computer readable storage medium. The model training device can be integrated in a computer equipment, which can be a server or a terminal.
[0051] The terminal may include a mobile phone, a wearable smart device, a tablet computer, a laptop computer, a personal computer (PC), and a vehicle-mounted computer.
[0052] Among them, the server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, as well as big data and artificial intelligence platforms.
[0053] It should be noted that the description order of the following embodiments is not intended to limit the preferred order of the embodiments.
[0054] This embodiment will be described from the perspective of a model training device, which can be specifically integrated into a computer device, which can be a server, a terminal or other device.
[0055] A model training method provided in the embodiment of the present application is as follows: Figure 1 As shown, the specific process of the model training method can be as follows:
[0056] 101. Obtain fact record text and reply prompt text, where the reply prompt text is used to instruct the trained first dialogue generation model to generate qualified reply content.
[0057] Among them, the first dialogue generation model can be a natural language processing model based on deep learning. The first dialogue generation model can be pre-trained through a large amount of unsupervised learning data and then can be used for generated text.
[0058] The first dialogue generation model can be a generative pre-trained transformer model (GPT). Chat GPT is the application of the GPT model in dialogue tasks. Chat GPT can have dialogues with users and generate coherent and meaningful responses.
[0059] The second dialogue generation model may also be a natural language processing model based on deep learning. The model architecture of the second dialogue generation model is different from the model structure of the first dialogue generation model. The second dialogue generation model is based on the Bloomz multilingual model.
[0060] Among them, the fact recording text can be a text that records objective facts. The fact recording text may include texts corresponding to multiple knowledge categories. For example, it can record the history of different countries, the owners and development of Internet companies, relevant information about toilet water, social hot events and other objective facts.
[0061] The fact record text can be pre-configured. For example, it can be a fact record text with corresponding factual topics constructed based on textbooks, popular science books, etc. The factual topics can be used as indexes for querying the fact record text. For example, the factual topic is toilet water, and the corresponding fact record text is the development history, ingredients and functions of toilet water. The fact record text can also be created by the user. Optionally, the fact record text can also be obtained through other means.
[0062] Among them, the reply prompt text is used to guide the first dialogue generation model to generate reply content. The reply prompt text may include question text asked to the first dialogue model. For example, it may be "Please generate multiple rounds of dialogues simulating human-computer communication based on the above content." The above content is the fact record text information. Optionally, the above content may be a reserved position for filling in the fact record text.
[0063] Optionally, the reply prompt text may include a condition that limits the form of the reply content generated by the first dialogue model. For example, the reply prompt text may be “Please generate multiple rounds of dialogues simulating human-computer communication for the above content, and the latter question is a further question based on the historical dialogue, and the dialogue follows the following plan:
[0064] <Human 1> : Ask a question
[0065] <Assistant 1> : Give a rough answer
[0066] <Human 2> : More detailed questions
[0067] <Assistant 2> : Give a more detailed answer
[0068] ……”.
[0069] In another embodiment, the reply prompt text message may be:
[0070] Based on the content input above and its topic, expand it into a multi-round dialogue in Chinese.
[0071] The dialogue requires you to have a conversation with a human as a chatbot Assistant, and expressions such as "based on the above information" cannot appear in the conversation.
[0072] Human will ask Assistant multiple different questions based on the above input as a human, and the latter question is a further question based on the historical conversation.
[0073] The Assistant's answers should be as detailed as possible, providing more explanations or examples. The content of the conversation should be as consistent with human language habits as possible and more in line with human daily conversations.
[0074] The dialogue format is "<start_chat><Human 1> :XXX;<Assistant 1> :XXX;<Human 2> :XXX:<Assistant 2> :XXX<end_chat> ”, where “XXX” represents the specific dialogue questions and answers.
[0075] The conversation should follow this plan:
[0076] <Human 1> : Ask a question
[0077] <Assistant 1> : Give a rough answer
[0078] <Human 2> : More detailed questions
[0079] <Assistant 2> : Give a more detailed answer
[0080] Here is a two-turn example:
[0081] <start_chat>
[0082] <Human 1> Q: In which district of Beijing is Communication University of China located?
[0083] <Assistant 1> :Communication University of China is located in Haidian District, Beijing.
[0084] <Human 2> Q: Where is the school located exactly?
[0085] <Assistant 2> Communication University of China is located at No. 1 Zhongguancun South Street, Haidian District, Beijing. It is adjacent to many scientific research institutions and universities, with convenient transportation and close to Xitucheng Metro Station.
[0086] <end_chat>
[0087] Since the types of content that users want to know are different in different application scenarios, the corresponding fact record text can be obtained according to the content that users want to know in the application scenario, and it is not necessary to train the second dialogue generation model with all the fact record texts, thereby improving the training speed and training effect of the second dialogue generation model. That is, in one embodiment, the step of "obtaining the fact record text" may specifically include:
[0088] Obtain candidate fact record texts and historical query texts corresponding to multiple facts, wherein the candidate fact record text information includes fact topics;
[0089] Compare the historical query text with the factual subject to obtain the relevance between the factual subject and the historical query text;
[0090] According to the relationship between the relevance and a preset threshold, the fact record text is screened out from the candidate fact record texts.
[0091] The historical query text may be the text entered by the user at the client for querying the corresponding result content.
[0092] For example, candidate fact record texts corresponding to multiple facts are obtained, and the candidate fact record texts may include texts corresponding to various knowledge categories. The fact subjects and historical query texts of the candidate fact record texts are compared, and features of the fact subjects and historical query texts are extracted respectively, and the correlation between the fact subjects and the historical query texts is determined based on the extracted feature information and the distance of the feature information in the feature space.
[0093] From the candidate fact record texts, the candidate fact record texts whose relevance between the fact subject and the historical query text is greater than a preset threshold are screened out to obtain the fact record texts.
[0094] It is understandable that there are multiple candidate fact record texts and multiple query history texts, and the corresponding fact record text can be screened for each historical query text.
[0095] 102. Input the fact record text and the response prompt text into the first dialogue generation model.
[0096] For example, the fact record text and reply prompt information can be input on the client page (the page for conducting a conversation with the artificial intelligence assistant based on the first dialogue model) to input the fact record text and reply prompt text into the first dialogue generation model.
[0097] In one embodiment, fact record text and reply prompt text can be entered on the client page provided by Chat GPT for conversing with the AI assistant.
[0098] Optionally, the reply prompt text is a question text template prompt, and the reply prompt text may contain a position for filling in the fact record text, and the fact record text is filled into the reply prompt text to obtain the question text. That is, in the embodiment, the step "the reply prompt text is a question text template, and the fact record text and the reply prompt text are input into the first dialogue generation model" includes:
[0099] Construct question text from factual record text and question text template;
[0100] Input the question text into the first dialogue generation model.
[0101] For example, the location of the fact record text may be filled in according to the indication of the question text template, the fact record text and the question text template may be merged to construct the question text, and the question text may be input into the first dialogue generation model.
[0102] 103. Generate multi-round dialogue content simulating human-computer communication based on the fact record text and the reply prompt text through the first dialogue generation model, wherein the reply text in the multi-round dialogue content includes content associated with the fact record text.
[0103] The reply text in each round of dialogue may include part of the factual record text, and may also include other text content related to the factual record text.
[0104] The first dialogue generation model generates multiple rounds of dialogue content for the factual record text based on the input factual record text and the reply prompt text, wherein each round of dialogue content includes a question text for asking a question and a reply text for answering the question, the question text is a question related to the factual record text, and the reply text can be part of the text content of the factual record text.
[0105] For example, the input fact record text is as follows:
[0106] Floral water is mainly used for covering odors, sterilization, disinfection, decontamination, and fragrance. Floral water generally has a pure aroma without impurities, and it cannot produce turbidity and precipitation at a low temperature of -5℃. Because of this, floral water is loved by more and more people. It is a sanitary product for people to repel mosquitoes, relieve itching, sterilize, and remove body odor in summer. Floral water is mainly composed of ethanol, flavors, and distilled water, supplemented by a small amount of chelating agents, antioxidants, and sun-resistant water-soluble pigments. The color is preferably light lake blue, green, and yellow. The amount of flavor is generally between 2% and 5%, and the alcohol concentration is 70% to 75%. It is customary for the flavor to be based on fragrant lavender oil. Some products use oriental perfume fragrance (such as rose musk) to enhance the ability to retain fragrance, which is called floral perfume. Drug name: Floral water. Foreign name: Florida Water. Is it a prescription drug: No. Main contraindications: Do not take orally, avoid fire, and follow the doctor's advice for those with severe dermatitis and skin damage. Dosage form: Aqueous solution. Athletes should use with caution: No. Is it included in medical insurance: No. Basic information about floral water: Floral water, like perfume and cologne, belongs to the category of water-based cosmetics. According to records, someone first added a little lavender oil to medical disinfectant alcohol (with a concentration of 75%), and invented what we call "floral water". In Europe and the United States, floral water generally has a lavender scent. However, in my country, when floral water was introduced to my country, there was no lavender oil in the country, so perfumers prepared rose musk essence, which is easier to prepare, and added it to 75% alcohol to prepare floral water. Floral water prepared in this way has been popular in my country for nearly a century. The content of the multi-round dialogue generated by the first dialogue generation model is as follows:
[0107] Human: What are the main uses of toilet water?
[0108] Assistant: Floral water is mainly used to cover odors, sterilize, disinfect, remove dirt and give fragrance. Due to its pure fragrance and certain sterilization and disinfection functions, floral water can be used to repel mosquitoes, relieve itching, sterilize and remove body odor in summer. It can be said that its efficacy is very practical and is loved by many people.
[0109] Human: How is toilet water made? What are the main ingredients?
[0110] Assistant: The production of floral water is mainly based on ethanol, essence and distilled water, supplemented by a small amount of chelating agent, antioxidant and sun-resistant water-soluble pigment. Adjust the color to light lake blue, green and yellow. The amount of essence is generally between 2% and 5%, and the alcohol concentration is 70% to 75%. In the process of making floral water, the essence is usually based on fragrant lavender oil. Some products also use oriental perfume fragrance (such as rose musk) to enhance the fragrance retention ability, which is called floral perfume.
[0111] Human: What is the difference between Chinese toilet water and that in Europe and the United States?
[0112] Assistant: The main difference between Chinese floral water and European and American floral water is the fragrance. European and American floral water is usually dominated by the scent of lavender. When floral water first became popular in China, since there was no lavender oil in China, perfumers used rose musk essence, which is easier to prepare, and added it to 75% alcohol to prepare a distinctive floral water. The floral water made in this way has been popular in China for nearly a century and has become a well-known and distinctive fragrance for the Chinese people.
[0113] Human: What precautions should be taken when using toilet water?
[0114] Assistant: When using floral water, please pay attention to the following:
[0115] Floral water should not be taken orally because it contains alcohol and fragrance ingredients, which may cause physical discomfort.
[0116] Avoid contact with fire sources, because toilet water contains a high concentration of alcohol and has certain fire hazards.
[0117] For those with severe dermatitis and damaged skin, please follow the doctor's advice before use to avoid possible irritation and adverse reactions to the skin.
[0118] Please pay attention to the storage environment, avoid high temperature, humidity, and direct sunlight, so as not to affect the quality and use effect of the floral water.
[0119] 104. Generate multiple groups of dialogue sample pairs according to the contents of multiple rounds of dialogue.
[0120] Each round of dialogue content generated by the first dialogue generation model is used as a dialogue sample pair. For example, a dialogue sample pair can be "Human: What are the main uses of floral water? - Assistant: Floral water is mainly used to cover odors, sterilize, disinfect, remove dirt and add fragrance. Due to its pure fragrance and certain bactericidal and disinfecting functions, floral water can be used to repel mosquitoes, relieve itching, sterilize and remove body odor in summer. It can be said that its efficacy is very practical and is loved by many people.".
[0121] Multiple dialogue sample pairs can be obtained based on the content of multiple rounds of dialogue.
[0122] Optionally, the dialogue intent of the question text may be obtained, and a new question text with the same dialogue intent as the question text may be constructed to increase the number of dialogue sample pairs. That is, in one embodiment, the step of "generating multiple groups of dialogue sample pairs according to multiple rounds of dialogue content" may specifically include:
[0123] Perform dialogue intent recognition on the question text in each round of dialogue content to obtain the intent text in the question text;
[0124] Get similar intent texts of the intent text;
[0125] Perform text replacement processing on the corresponding question text with the similar intention text to obtain the replaced question text;
[0126] Multiple groups of dialogue sample pairs are generated based on the question text and the reply text of each round of dialogue content, as well as the replaced question text and the corresponding reply text.
[0127] For example, the conversation intent may be identified for the question text in each round of conversation content to obtain the intention text representing the conversation intent in the question text, and then similar intention text with the same intention may be obtained based on the intention text. The intention text in the question text may then be replaced with the similar intention text to obtain a new question text, i.e., the replaced question text.
[0128] For example, if the intended text is efficacy, it can be replaced with words such as effect and function; if the intended text is ingredient, it can be replaced with words such as material and composition.
[0129] The intention text can be regarded as an entity. A text matrix is established for the question text, and then the intention text is extracted from it through the global pointer model Global Pointer.
[0130] The Global Pointer model is an information extraction model that can simultaneously identify nested entities and non-nested entities. Global Pointer treats the start and end of the target segment as a whole and uses a character matrix to represent the text segment (the [i, j] position in the matrix represents the text segment from position i to position j). The model extracts entities by mapping a text sequence of length N to a matrix of shape R^(N×N).
[0131] For each round of dialogue content, the question text and the reply text are taken as a set of dialogue sample pairs, and the replaced question text corresponding to the question text and the reply text in the round of dialogue content are taken as another set of dialogue sample pairs.
[0132] The generated dialogue sample pairs include not only multiple rounds of dialogues generated by the first dialogue generation model, but also replaced dialogue sample pairs after text replacement based on similar intent, which increases the number of samples and improves the training effect and generalization of the second dialogue generation model.
[0133] 105. Train the second dialogue generation model based on the multiple groups of dialogue samples to obtain a trained second dialogue generation model.
[0134] For example, in a group of dialogue sample pairs, the reply text is the true value, which is used to measure the accuracy of the reply content of the second dialogue generation model. The question text in the dialogue sample is input into the second dialogue generation model, and the second dialogue generation model generates corresponding reply content according to the question text. The loss is calculated based on the reply content generated by the second dialogue generation model and the reply text in the dialogue sample pair, and the second dialogue generation model is trained based on the loss. When the number of training iterations reaches a preset number threshold, or the accuracy of the second dialogue generation model reaches a preset accuracy threshold, the trained second dialogue generation model is obtained.
[0135] After obtaining the trained second dialogue generation model, fine-tuning can be performed so that the model is capable of conducting dialogues with users and solving problems raised by users. That is, in one embodiment, after the step of "training the second dialogue generation model based on multiple groups of dialogue samples to obtain the trained second dialogue generation model", the model training method provided in the embodiment of the present application may also include:
[0136] Input the fact record text and the response prompt text into the second dialogue generation model;
[0137] Generate multiple rounds of dialogue content to be verified through a second dialogue generation model;
[0138] Take the multi-round conversation content as the true value, and calculate the loss value based on the multi-round conversation content and the multi-round conversation content to be verified;
[0139] Fine-tune the trained dialogue generation model based on the loss value.
[0140] For example, the fact record text and the reply prompt text can be input into the second dialogue generation model, and multiple rounds of dialogue content to be verified can be generated by the second dialogue generation model. The multiple rounds of dialogue content can be used as the true value to measure the accuracy of the dialogue content to be verified generated by the second dialogue model. The loss value can be calculated based on the multiple rounds of dialogue content and the multiple rounds of dialogue content to be verified. The trained dialogue generation model can be trained based on the loss value, and the model parameters of the trained second dialogue generation model can be adjusted to achieve fine-tuning of the trained second dialogue generation model.
[0141] In order to enable the trained second dialogue generation model to provide better dialogue services in a specific language environment (e.g., Chinese environment), a greater weight may be set for the loss corresponding to the dialogue content in the specific language, so that the trained second dialogue generation model pays more attention to the specific language and can provide better dialogue services in the specific language environment. That is, in one embodiment, the step of "fine-tuning the trained dialogue generation model according to the loss value" may specifically include:
[0142] Determine the corresponding loss weight according to the language type of each round of dialogue content to be verified;
[0143] The loss value is weighted according to the loss weight to obtain the weighted loss value;
[0144] Fine-tune the trained dialogue generation model based on the weighted loss value.
[0145] For example, the language type corresponding to the conversation content to be verified can be determined based on the number of text units in each language type in each round of conversation content to be verified, and the corresponding loss weight can be determined. The loss weight is used to weight the loss value. If it is a specified language type, the corresponding weight is larger.
[0146] The loss value is weighted according to the weight to obtain a weighted loss value; and the trained dialogue generation model is fine-tuned based on the weighted loss value.
[0147] Optionally, in the embodiment of the present application, the second dialogue generation model may be based on the Bloomz multilingual model. In order to make the second dialogue generation model have a better effect in the Chinese environment, the word segmenter and the vocabulary in the Bloomz model may be replaced, that is, the word segmenter in the second dialogue generation model is different from the Bloomz model, and then the word segmenter is trained by Chinese corpus. For example, a Chinese training text data set may be obtained, and the Chinese text training text data set includes Chinese text in and is marked with the starting position and ending position of each word therein, which is used to train the word segmenter to improve the understanding ability of the trained second dialogue generation model for Chinese text. That is, in one embodiment, after the step "the trained second dialogue generation model includes a word segmenter, and the second dialogue generation model is trained based on multiple groups of dialogue samples to obtain the trained second dialogue generation model", the image generation method provided in the embodiment of the present application may also include:
[0148] Obtaining Chinese training text, where the Chinese training text is marked with the start position and end position of each word;
[0149] Perform word segmentation processing on the Chinese training text through the word segmenter to obtain the word segmentation processing result;
[0150] The word segmenter is trained according to the word segmentation processing result and the starting position and the ending position of each word marked in the Chinese training text to obtain a trained word segmenter.
[0151] For example, if there are multiple Chinese training texts, each Chinese training sample can be input into the word segmenter for word segmentation processing. The word segmenter outputs the word segmentation processing result of the Chinese training sample. The loss value is calculated based on the error between the word segmentation processing result and the start position and the end position of each word marked in the Chinese training text. The loss value is then back-propagated to adjust the model parameters of the word segmenter until the number of iterations meets the preset number or the accuracy reaches the preset threshold, thereby obtaining a trained word segmenter.
[0152] As can be seen from the above, the embodiment of the present application obtains fact record text and reply prompt text, and the reply prompt text is used to indicate that the trained first dialogue generation model generates qualified reply content; the fact record text and the reply prompt text are input into the first dialogue generation model; based on the fact record text and the reply prompt text, the first dialogue generation model generates multiple rounds of dialogue content simulating human-computer communication, wherein the reply text in the multiple rounds of dialogue content contains content associated with the fact record text; multiple groups of dialogue sample pairs are generated according to the multiple rounds of dialogue content; and the second dialogue generation model is trained based on the multiple groups of dialogue samples to obtain the trained second dialogue generation model.
[0153] The embodiment of the present application trains the second dialogue generation model by generating dialogue sample pairs based on factual record text, which can improve the accuracy of the second dialogue generation model in responding to questions about objective facts and improve the dialogue effect of the second dialogue generation model. The dialogue sample pairs are generated by the first dialogue generation model, and there is no need to manually produce dialogue sample pairs, which reduces the time for generating dialogue sample pairs and improves the training efficiency of the model.
[0154] In order to facilitate better implementation of the model training method provided in the embodiment of the present application, a model training device is also provided in one embodiment. The meanings of the terms are the same as those in the above-mentioned model training method, and the specific implementation details can refer to the description in the method embodiment.
[0155] The model training device can be integrated into a computer device, such as Figure 2 As shown, the model training device may include: an acquisition unit 301, a first input unit 302, a first dialogue generation unit 303, a sample generation unit 304 and a training unit 305, as follows:
[0156] (1) An acquisition unit 301 is used to acquire a fact record text and a reply prompt text, where the reply prompt text is used to instruct the trained first dialogue generation model to generate reply content that meets the conditions.
[0157] In one embodiment, the acquisition unit 301 includes:
[0158] A text acquisition subunit is used to acquire candidate fact record texts and historical query texts corresponding to a plurality of facts, wherein the candidate fact record text information includes fact topics;
[0159] A comparison subunit, used to compare the historical query text with the fact subject to obtain the relevance between the fact subject and the historical query text;
[0160] The screening subunit is used to screen the fact record text from the candidate fact record texts according to the relationship between the relevance and the preset threshold.
[0161] (2) A first input unit 302, used to input the fact record text and the reply prompt text into the first dialogue generation model.
[0162] In one embodiment, the first input unit 302 includes:
[0163] A construction subunit is used to construct a question text from a fact record text and a question text template;
[0164] The text input subunit is used to input the question text into the first dialogue generation model.
[0165] (3) a first dialogue generation unit 303, configured to generate, by using a first dialogue generation model, a multi-round dialogue content simulating human-computer communication based on the fact record text and the reply prompt text, wherein the reply text in the multi-round dialogue content includes content associated with the fact record text;
[0166] (4) a sample generation unit 304, configured to generate multiple groups of dialogue sample pairs according to the contents of multiple rounds of dialogue;
[0167] In one embodiment, the sample generation unit 304 includes:
[0168] The recognition subunit is used to recognize the conversation intention of each question text in each round of conversation content, and obtain the intention text in the question text;
[0169] A similar text acquisition subunit is used to acquire similar intent texts of the intended text;
[0170] The replacement subunit is used to perform text replacement processing on the corresponding question text with the similar intention text to obtain the replaced question text;
[0171] The sample pair generation subunit is used to generate multiple groups of dialogue sample pairs based on the question text and the reply text of the multi-round dialogue content, and the replaced question text and the corresponding reply text.
[0172] (5) A training unit 305, configured to train the second dialogue generation model based on the multiple groups of dialogue samples to obtain a trained second dialogue generation model.
[0173] In one embodiment, the model training device further includes:
[0174] A second input unit, used to input the fact record text and the reply prompt text into the second dialogue generation model;
[0175] A second dialogue generation unit, used to generate multiple rounds of dialogue content to be verified through a second dialogue generation model;
[0176] A calculation unit, used to take the multi-round dialogue content as a true value, and calculate the loss value according to the multi-round dialogue content and the multi-round dialogue content to be verified;
[0177] The fine-tuning unit is used to fine-tune the trained dialogue generation model according to the loss value.
[0178] In one embodiment, the fine-tuning unit comprises:
[0179] A weight determination subunit, used to determine the corresponding loss weight according to the language type of each round of dialogue content to be verified;
[0180] The weighting subunit is used to perform weighted processing on the loss value according to the loss weight to obtain the weighted loss value;
[0181] The fine-tuning processing subunit is used to fine-tune the trained dialogue generation model based on the weighted loss value.
[0182] In one embodiment, the trained second dialogue generation model includes a word segmenter, and the model training device further includes:
[0183] A training text acquisition unit, used to acquire Chinese training text, where the Chinese training text is marked with the start position and end position of each word;
[0184] A word segmentation unit is used to perform word segmentation processing on the Chinese training text through a word segmenter to obtain a word segmentation processing result;
[0185] The word segmenter processing unit is used to train the word segmenter according to the word segmentation processing result and the starting position and the ending position of each word marked in the Chinese training text to obtain the trained word segmenter.
[0186] As can be seen from the above, the model training device of the embodiment of the present application obtains the fact record text and the reply prompt text through the acquisition unit 301, and the reply prompt text is used to indicate that the trained first dialogue generation model generates qualified reply content; the first input unit 302 inputs the fact record text and the reply prompt text into the first dialogue generation model; the first dialogue generation unit 303 generates multi-round dialogue content simulating human-computer communication based on the fact record text and the reply prompt text through the first dialogue generation model, and the reply text in the multi-round dialogue content contains content associated with the fact record text; the sample generation unit 304 generates multiple groups of dialogue sample pairs according to the multi-round dialogue content; the training unit 305 trains the second dialogue generation model based on the multiple groups of dialogue samples to obtain the trained second dialogue generation model.
[0187] The embodiment of the present application trains the second dialogue generation model by generating dialogue sample pairs based on factual record text, which can improve the accuracy of the second dialogue generation model in responding to questions about objective facts and improve the dialogue effect of the second dialogue generation model. The dialogue sample pairs are generated by the first dialogue generation model, and there is no need to manually produce dialogue sample pairs, which reduces the time for generating dialogue sample pairs and improves the training efficiency of the model.
[0188] The present application also provides a computer device, which may be a terminal or a server. Figure 3 As shown, it shows a schematic diagram of the structure of the computer device involved in the embodiment of the present application, specifically:
[0189] The computer device may include components such as a processor 1001 with one or more processing cores, a memory 1002 with one or more computer-readable storage media, a power supply 1003, and an input unit 1004. Those skilled in the art will appreciate that Figure 3 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:
[0190] The processor 1001 is the control center of the computer device. It uses various interfaces and lines to connect various parts of the entire computer device. By running or executing software programs and / or modules stored in the memory 1002 and calling data stored in the memory 1002, it executes various functions of the computer device and processes data, thereby monitoring the computer device as a whole. Optionally, the processor 1001 may include one or more processing cores; preferably, the processor 1001 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and computer programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 1001.
[0191] The memory 1002 can be used to store software programs and modules. The processor 1001 executes various functional applications and data processing by running the software programs and modules stored in the memory 1002. The memory 1002 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, a computer program required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 1002 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 1002 may also include a memory controller to provide the processor 1001 with access to the memory 1002.
[0192] The computer device also includes a power supply 1003 for supplying power to various components. Preferably, the power supply 1003 can be logically connected to the processor 1001 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 1003 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0193] The computer device may further include an input unit 1004, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0194] Although not shown, the computer device may further include a display unit, etc., which will not be described in detail herein. Specifically, in this embodiment, the processor 1001 in the computer device will load the executable files corresponding to the processes of one or more computer programs into the memory 1002 according to the following instructions, and the processor 1001 will run the computer programs stored in the memory 1002, thereby realizing various functions, as follows:
[0195] Obtaining fact record text and reply prompt text, where the reply prompt text is used to instruct the trained first dialogue generation model to generate reply content that meets the conditions;
[0196] Inputting the fact record text and the response prompt text into the first dialogue generation model;
[0197] Generate multi-round dialogue content simulating human-computer communication based on the fact record text and the reply prompt text through the first dialogue generation model, wherein the reply text in the multi-round dialogue content includes content associated with the fact record text;
[0198] Generate multiple groups of dialogue sample pairs based on the content of multiple rounds of dialogues;
[0199] The second dialogue generation model is trained based on the multiple groups of dialogue samples to obtain a trained second dialogue generation model.
[0200] The specific implementation of the above operations can be found in the previous embodiments and will not be described in detail here.
[0201] As can be seen from the above, the computer device of the embodiment of the present application can obtain fact record text and reply prompt text, the reply prompt text is used to instruct the trained first dialogue generation model to generate qualified reply content; the fact record text and the reply prompt text are input into the first dialogue generation model; the first dialogue generation model generates multi-round dialogue content simulating human-computer communication based on the fact record text and the reply prompt text, and the reply text in the multi-round dialogue content contains content related to the fact record text; multiple groups of dialogue sample pairs are generated according to the multi-round dialogue content; the second dialogue generation model is trained based on the multiple groups of dialogue samples to obtain the trained second dialogue generation model.
[0202] The embodiment of the present application trains the second dialogue generation model by generating dialogue sample pairs based on factual record text, which can improve the accuracy of the second dialogue generation model in responding to questions about objective facts and improve the dialogue effect of the second dialogue generation model. The dialogue sample pairs are generated by the first dialogue generation model, and there is no need to manually produce dialogue sample pairs, which reduces the time for generating dialogue sample pairs and improves the training efficiency of the model.
[0203] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program including computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in various optional implementations in the above-mentioned embodiments.
[0204] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be accomplished by a computer program, or by controlling related hardware through a computer program. The computer program may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0205] To this end, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. The computer program can be loaded by a processor to execute any model training method provided in the embodiment of the present application.
[0206] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0207] The computer-readable storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0208] Since the computer program stored in the computer-readable storage medium can execute any one of the model training methods provided in the embodiments of the present application, the beneficial effects that can be achieved by any one of the model training methods provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0209] The above is a detailed introduction to a model training method, device, computer equipment and computer-readable storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A model training method, characterized in that: include: Obtaining fact record text and reply prompt text, wherein the reply prompt text is used to instruct the trained first dialogue generation model to generate reply content that meets the conditions; Inputting the fact record text and the reply prompt text into the first dialogue generation model; Generate, by the first dialogue generation model, a multi-round dialogue content simulating human-computer communication based on the fact record text and the reply prompt text, wherein the reply text in the multi-round dialogue content includes content associated with the fact record text; Generating multiple groups of dialogue sample pairs according to the multiple rounds of dialogue contents; The second dialogue generation model is trained based on the multiple groups of dialogue samples to obtain a trained second dialogue generation model.
2. The method according to claim 1, characterized in that The obtaining of fact record text includes: Acquire candidate fact record texts and historical query texts corresponding to a plurality of facts, wherein the candidate fact record text information includes fact topics; Comparing the historical query text with the fact subject to obtain the relevance between the fact subject and the historical query text; According to the relationship between the relevance and a preset threshold, the fact record text is screened from the candidate fact record texts.
3. The method according to claim 1, characterized in that: The reply prompt text is a question text template, and the fact record text and the reply prompt text are input into a first dialogue generation model, including: Constructing a question text by combining the fact record text and the question text template; The question text is input into the first dialogue generation model.
4. The method according to claim 1, characterized in that After training the second dialogue generation model based on the multiple groups of dialogue samples to obtain the trained second dialogue generation model, the method further includes: Inputting the fact record text and the reply prompt text into the second dialogue generation model; Generate multiple rounds of dialogue content to be verified by using the second dialogue generation model; Taking the multiple rounds of conversation contents as true values, and calculating loss values according to the multiple rounds of conversation contents and the multiple rounds of conversation contents to be verified; The trained dialogue generation model is fine-tuned according to the loss value.
5. The method according to claim 4, characterized in that The fine-tuning of the trained dialogue generation model according to the loss value includes: Determine the corresponding loss weight according to the language type of each round of dialogue content to be verified; Performing weighted processing on the loss value according to the loss weight to obtain a weighted loss value; The trained dialogue generation model is fine-tuned based on the weighted loss value.
6. The method according to claim 1, characterized in that The trained second dialogue generation model includes a word segmenter. After the second dialogue generation model is trained based on the multiple groups of dialogue samples to obtain the trained second dialogue generation model, the method further includes: Acquire a Chinese training text, wherein the Chinese training text is marked with a start position and an end position of each word; Performing word segmentation processing on the Chinese training text by a word segmenter to obtain a word segmentation processing result; The word segmenter is trained according to the word segmentation processing result and the starting position and the ending position of each word marked in the Chinese training text to obtain the trained word segmenter.
7. The method according to any one of claims 1 to 6, characterized in that: The generating a plurality of groups of dialogue sample pairs according to the plurality of rounds of dialogue contents comprises: Performing dialogue intent recognition on each question text in each round of dialogue content to obtain the intent text in the question text; Obtaining similar intent texts of the intent text; Performing text replacement processing on the corresponding question text by using the similar intention text to obtain a replaced question text; The multiple groups of dialogue sample pairs are generated according to the question texts and the reply texts of the multiple rounds of dialogue contents, and the replaced question texts and the corresponding reply texts.
8. A model training device, characterized in that: include: An acquisition unit, used to acquire a fact record text and a reply prompt text, wherein the reply prompt text is used to instruct the trained first dialogue generation model to generate reply content that meets the conditions; A first input unit, used for inputting the fact record text and the reply prompt text into the first dialogue generation model; A second dialogue generation unit, configured to generate, through the first dialogue generation model, a multi-round dialogue content simulating human-computer communication based on the fact record text and the reply prompt text, wherein the reply text in the multi-round dialogue content includes content associated with the fact record text; A sample generating unit, configured to generate multiple groups of dialogue sample pairs according to the multiple rounds of dialogue contents; A training unit is used to train the second dialogue generation model based on the multiple groups of dialogue samples to obtain a trained second dialogue generation model.
9. A computer device, characterized in that: It comprises a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the model training method described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, which is loaded by a processor to execute the model training method described in any one of claims 1 to 7.
Citation Information
Patent Citations
Multi-round question and answer method, device and equipment
CN114547274A
Model training method, dialogue generation method, electronic equipment and related device
CN116361431A
Dialogue generation model construction method, dialogue generation method, model optimization method and electronic equipment
CN116861234A
