Model training method and device, electronic equipment and computer readable storage medium
By automatically generating and adjusting training samples, the problem of training difficulty for large language models is solved, and the model's processing and generalization capabilities in question-answering tasks are improved.
Patent Information
- Application Number
- CN202411709553.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2044-11-26
AI Technical Summary
When large language models are used to handle natural language tasks, the training difficulty increases because some function tools have limited question-and-answer data.
By acquiring question-and-answer data related to the function tools, questions and instructions are generated. Training samples are automatically generated using the first target model, and the second target model is trained based on these samples. This includes generating diverse questions and instructions, adjusting the order of the function toolset, simulating user dialogue scenarios, and enhancing the diversity and quality of the training samples.
It reduces the training difficulty of large language models and improves the model's ability to handle question-answering tasks, especially in question-answering tasks in the target professional domain, thereby improving the model's generalization ability and usability.
Smart Images

Figure CN119578490B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of neural network model technology, specifically to a model training method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] Large Language Model (LLM) refers to a deep learning model trained on a large amount of text data that can handle a variety of natural language tasks, such as text classification, question answering, and dialogue.
[0003] Large language models can invoke various function tools when processing natural language tasks. Before invoking these function tools, the large language model needs to be trained using question-and-answer sessions related to the function tools.
[0004] However, some functional tools have limited question-and-answer data, making it difficult to train large language models. Summary of the Invention
[0005] This application provides a model training method, apparatus, electronic device, and computer-readable storage medium, which can reduce the training difficulty of large language models.
[0006] In a first aspect, embodiments of this application provide a model training method, the method comprising:
[0007] Acquire question and answer data related to the function tool. The question and answer data includes questions generated and instructions for calling the function tool, based on the function description of the function tool and the parameter description of the input parameters required to call the function tool, through the first target model.
[0008] Based on the above question-and-answer data and the function toolset to which the above function tools belong, training samples for the second target model are generated;
[0009] Based on the above training samples, the second target model is trained to obtain the trained target model.
[0010] Secondly, embodiments of this application also provide a model training apparatus, the apparatus comprising:
[0011] The acquisition module is used to acquire question and answer data related to the function tool. The question and answer data includes questions generated by the first target model based on the function description of the function tool and the parameter description of the input parameters required to call the function tool, as well as the instructions to call the function tool.
[0012] The generation module is used to generate training samples for the second target model based on the question-and-answer data and the function toolset containing the above-mentioned functions;
[0013] The training module is used to train the second target model based on the training samples mentioned above, so as to obtain the trained target model.
[0014] Thirdly, embodiments of this application also provide an electronic device, including a memory storing multiple instructions; the processor loads instructions from the memory to execute any of the model training methods provided in embodiments of this application.
[0015] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to execute any of the model training methods provided in embodiments of this application.
[0016] In this embodiment, question-and-answer data related to the function tool is acquired. This data includes questions and instructions for calling the function tool generated by a first target model based on the function tool's functional description and parameter description of the input parameters required to call the function tool. Based on the question-and-answer data and the function tool set to which the function tool belongs, training samples for a second target model are generated. The second target model is then trained based on these training samples to obtain a trained target model. This process enables the automatic generation of question-and-answer data related to the function tool from the first target model, based on the function tool's functional description and parameter description, and the generation of training samples for the second target model. This allows the second target model to be trained based on the training samples, reducing the training difficulty of the second target model. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a schematic flowchart of one embodiment of the model training method provided in this application;
[0019] Figure 2 This is a schematic diagram of another embodiment of the model training method provided in this application;
[0020] Figure 3 This is a schematic diagram of the confusion matrix provided in an embodiment of this application;
[0021] Figure 4 This is a schematic diagram of the model evaluation method provided in the embodiments of this application;
[0022] Figure 5 This is a schematic diagram of the structure of the model training device provided in the embodiments of this application;
[0023] Figure 6 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0024] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0025] Before providing a detailed explanation of the embodiments of this application, some terms involved in the embodiments of this application will be explained.
[0026] In the description of the embodiments of this application, the terms "first," "second," etc., may be used herein to describe various concepts, but unless specifically stated otherwise, these concepts are not limited by these terms. These terms are used only to distinguish one concept from another. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices. "A plurality of" refers to two or more.
[0027] This application provides a model training method, apparatus, electronic device, and computer-readable storage medium. Specifically, the model training method of this application can be executed by an electronic device, which can be a terminal or a server, etc.
[0028] The terminal can be a smartphone, tablet, laptop, touch screen, game console, personal computer (PC), personal digital assistant (PDA), or other terminal device. The terminal can also include a client, which can be a game application client, a browser client with a game program, or an instant messaging client, etc.
[0029] A server can be a standalone physical server, a server cluster or distributed system consisting 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 communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
[0030] The following is a detailed description in conjunction with the accompanying drawings. It should be noted that the order of description of the following embodiments is not intended to limit the preferred order of the embodiments. Although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be performed in a different order than that shown in the drawings.
[0031] In this embodiment, a terminal is used as an example for illustration. This embodiment provides a model training method, such as... Figure 1 As shown, the specific process of this model training method can be as follows:
[0032] 101. Obtain question and answer data related to the function tool. The question and answer data includes questions generated based on the function tool's functional description and the parameter description of the input parameters required to call the function tool, through the first target model, and the instructions for calling the function tool.
[0033] The function tools can include function tools in the general domain and / or function tools in the target professional domain.
[0034] The target professional field refers to a specific knowledge category, which can be set according to the actual situation. For example, the target professional field can be the medical field or the automotive field. This embodiment does not limit it.
[0035] A function tool refers to a tool that encapsulates code that performs certain functions, and it may include at least one such tool. The type of code that performs certain functions can be set according to the actual situation. For example, the code that performs certain functions may be a function, an interface, a model, or a workflow, etc., and this embodiment does not limit this. The functions implemented can be set as needed. For example, when the target professional field is the medical field, the function tool may implement a drug query function or a medical record query function, and this embodiment does not limit this either.
[0036] The first target model can refer to a trained neural network model. For example, the first target model can refer to a Large Language Model (LLM), which can handle natural language tasks, including question answering tasks. The specific type of the large language model can be determined according to the actual situation. For example, the first target model can be Azure-OpenAI-GPT-3.5 or Microsoft Azure-GPT-4.0. This application embodiment does not limit this.
[0037] The function description of a function tool refers to information that describes the function tool's functionality. For example, if the function tool's function is to query the weather, the function description could be: "This function is used to query the weather in a specific location."
[0038] When calling a function tool, you need to input some parameters. The description of these parameters is called the parameter description. When the function tool performs different functions, the parameters required to call it will also be different, and so will the parameter description. For example, if the function tool's function is to query the weather, the required parameters are location and time, and the parameter description would be: "Required parameters representing location and time." Another example is a function tool that queries salaries, where the required parameter is name, and the parameter description would be: "Required parameters representing name."
[0039] In some embodiments, acquiring question-and-answer data related to function tools includes:
[0040] Get the function description of the tool and the parameter description of the input parameters required to call the tool;
[0041] Based on the functional and parameter descriptions, questions are generated using the first target model.
[0042] Based on the problem, the first target model generates the corresponding instructions.
[0043] For example, the function tool implements a salary query function, and the generated question can be "How much is Zhang San's salary?", and the corresponding command can be "salary_search(name='Zhang San')".
[0044] In this embodiment, the function description of the function tool and the parameter description of the input parameters required to call the function tool are obtained. Based on the function description and parameter description, a question is generated through the first target model. Based on the question, the corresponding instruction is generated through the first target model, thereby realizing the automatic generation of questions and corresponding instructions, and improving the generation efficiency of questions and corresponding instructions.
[0045] In some embodiments, acquiring question-and-answer data related to function tools includes:
[0046] Get the function description of the tool and the parameter description of the input parameters required to call the tool;
[0047] Based on the functional and parameter descriptions, the instructions for calling the function tool in the second target model are generated using the first target model.
[0048] The first target model is used to predict the problem that needs to be input into the second target model to trigger the generation instruction.
[0049] The second target model can be either an untrained neural network model or a trained neural network model. When the second target model is a trained neural network model, it can refer to a Large Language Model (LLM), which can handle natural language tasks, including question-answering tasks. In this case, the second target model and the first target model can be the same model or different models.
[0050] In this embodiment, the first target model generates instructions for calling the function tool of the second target model based on the functional description and parameter description. The first target model predicts the questions that need to be input into the second target model to trigger the generation of instructions. This achieves the goal of generating instructions first and then generating questions, which not only improves the efficiency of question and instruction generation, but also makes the quality of questions and instructions less dependent on the capabilities of the first target model. It also makes the generated questions and instructions more diverse, structurally complete, and stable, further enhancing the ability of the trained target model to handle question-answering tasks in the target professional domain.
[0051] For example, if the function tool implements a salary query function, the generated command could be "salary_search(name='Zhang San')", and the question that triggers the generation of this command could be "How much is Zhang San's salary?".
[0052] In some embodiments, the terminal can generate instructions based on the function information of the function tool. The function information includes the tool name, function description, parameter name, parameter description, parameter type, and parameter requirement of the function tool.
[0053] In some embodiments, based on the functional description and parameter description, instructions for calling the function tool in the second target model are generated using the first target model, including:
[0054] Based on the first target model, the target parameters required for the function calling tool are generated according to the function description and parameter description.
[0055] By assembling the target parameters and the tool name of the function tool, the instruction to call the function tool is obtained.
[0056] The target parameter required to call the function tool refers to the specific value of the parameter that needs to be entered. For example, if the function tool's function is a weather query function, the parameters required to call the function tool are parameters representing the location and time, and the target parameters required to call the function tool are Wuhan and tomorrow.
[0057] After obtaining the target parameters, the terminal can assemble the target parameters and the tool name of the function tool to obtain the instruction to call the function tool.
[0058] For example, if the function tool is for salary lookup, the target parameter is "Zhang San", the tool name is salary_search, and the command to call the function tool can be "salary_search(name='Zhang San')".
[0059] Understandably, when calling a function tool requires multiple input parameters, and each required input parameter corresponds to multiple target parameters, the terminal can first generate each target parameter through the first target model, then combine the target parameters to obtain the combined parameters, and then assemble the combined parameters and the tool name of the function tool to obtain the instruction to call the function tool.
[0060] For example, the parameters required to call a function tool include parameters representing time and parameters representing location. Target parameters generated for the time parameters include tomorrow and the day after tomorrow, and target parameters generated for the location parameters include Wuhan and Shenzhen. Combining tomorrow and Wuhan yields a combined parameter, combining tomorrow and Shenzhen yields a combined parameter, combining the day after tomorrow and Shenzhen yields a combined parameter, and combining the day after tomorrow and Wuhan yields a combined parameter, resulting in a total of four combined parameters. These four combined parameters are then combined with the tool name to obtain four commands for calling the function tool.
[0061] Alternatively, when calling a function tool requires multiple input parameters, and each required input parameter corresponds to multiple target parameters, the terminal can directly generate combined parameters through the first target model. These combined parameters include at least two target parameters. For example, if the input parameters for calling a function tool include parameters representing time and location, the terminal can directly generate the target parameter "Wuhan" and the target parameter "tomorrow," thus obtaining the combined parameters.
[0062] Optionally, when one of the target parameters affects the generation of other target parameters, the combined parameters can be generated directly through the first target model.
[0063] Optionally, when generating the target parameters required for the function calling tool based on the function description and parameter description using the first target model, a parameter generation prompt template can also be input into the first target model so that the target parameters required for the function calling tool can be generated using the first target model based on the function description, parameter description, and parameter generation prompt template.
[0064] Optionally, if generating target parameters requires samples or generation rules, the samples or generation rules can be stored in the parameter description. In this case, the parameter description includes not only a description of the required input parameters, but also samples or generation rules, so that the first target model can refer to the samples or generation rules and generate target parameters according to the functional description and parameter description.
[0065] In some embodiments, before predicting the problem that needs to be input into the second target model to trigger the generation instruction using the first target model, the method further includes:
[0066] Perform quality checks on the instructions to obtain the quality check results;
[0067] Determine the instructions corresponding to the quality inspection results that meet the preset quality conditions.
[0068] Using the first objective model, predict the problems that need to be input into the second objective model to trigger generation instructions, including:
[0069] Based on the target instruction, the information that needs to be input into the second target model to trigger the generation of the target instruction is predicted. The target instruction refers to the instruction corresponding to the quality inspection result that meets the preset quality conditions.
[0070] The process of performing quality checks on instructions and obtaining the quality check results can be as follows:
[0071] The quality of the instruction is checked based on at least one of the following: the instruction's structure, the tool name in the instruction, the parameters in the instruction, and the type of the parameters in the instruction, and the quality check result of the instruction is obtained.
[0072] For example, when performing quality checks on instructions based on their structure, we can analyze whether the instruction includes a tool name and parameters. If the instruction includes both, it indicates that the quality check result is the first quality check result. The first quality check result indicates a quality check result that meets preset quality conditions.
[0073] For example, when performing quality checks on an instruction based on the parameters in the instruction, it is possible to analyze whether the parameters in the instruction are mandatory and whether they are required input parameters. If the parameters in the instruction are required input parameters, the quality check result of the instruction is the first quality check result. If the parameters in the instruction are not required input parameters, the quality check result of the instruction is the second quality check result, which is a quality check result that does not meet the preset quality conditions.
[0074] Understandably, when performing quality checks on an instruction based on its composition structure, the tool name within the instruction, the parameters within the instruction, and the types of the parameters within the instruction, the quality check result of the instruction can be determined based on the results of various sub-quality checks.
[0075] For example, based on the composition structure of the instruction, a quality check is performed on the instruction, and the resulting sub-quality check result is the first quality check result. Based on the parameters in the instruction, a quality check is performed on the instruction, and the resulting sub-quality check result is the second quality check result. Based on the first quality check result and the second quality check result, the quality check result of the instruction is determined.
[0076] It is understandable that when the sub-quality inspection result includes the second quality inspection result, the quality inspection result of the instruction can be determined as the second quality inspection result.
[0077] In some embodiments, the question can be a short sentence or a long sentence. For example, when the function tool is a weather query function, the question can be "Wuhan, weather tomorrow" (short sentence), or "I want to ask about the weather in Wuhan tomorrow" (long sentence).
[0078] In some embodiments, the problem includes target parameters. When the problem includes all target parameters, it can be called a complete problem; when the problem includes some target parameters, it can be called a non-complete problem. The problem in this embodiment can be a complete problem and / or a non-complete problem.
[0079] For example, the parameters required to call a function tool include a parameter representing the location and a parameter representing the time. A complete question could be "What will the weather be like in Wuhan tomorrow?" In this case, the complete question includes the target parameter "Wuhan" representing the location and the target parameter "tomorrow" representing the time. An incomplete question could be "What will the weather be like tomorrow?" In this case, the incomplete question only includes the target parameter "tomorrow" representing the time and lacks the target parameter "Wuhan" representing the location.
[0080] In the embodiments of this application, when the question includes a complete question and an incomplete question, the complete question includes all the target parameters required to call the function tool, and the incomplete question includes some of the target parameters required to call the function tool. This can make the generated questions more diverse, so that after the second target model is trained according to the question and instructions, the ability of the trained target model to call the function tool to handle question answering tasks can be further improved.
[0081] In some embodiments, this embodiment further includes:
[0082] Based on the incomplete problem, a supplementary problem is generated using the first target model. The supplementary problem is used to prompt the input of the target parameters that are missing in the incomplete problem.
[0083] Using the first target model, supplementary information is generated based on the supplementary question. The supplementary information includes the missing target parameters. The supplementary question and supplementary information are used to generate training samples.
[0084] This can involve generating complete and incomplete problems based on instructions. Alternatively, a complete problem can be generated based on instructions, and then an incomplete problem can be generated based on the target parameters.
[0085] After obtaining the incomplete question, a supplementary question is generated based on the incomplete question, and supplementary information is generated based on the supplementary question.
[0086] For example, an incomplete question might be "I want to check my salary for January." Since the incomplete question lacks the target parameter representing the name, the generated supplementary question could be "Are you checking for January of this year? Also, could you provide the name you are checking?" Based on the supplementary question, the generated supplementary information could be something like "It's for January 2023, and the name is Zhang San."
[0087] In this embodiment, a supplementary question is generated based on an incomplete question using a first target model. The supplementary question is used to prompt the input of the target parameters missing in the incomplete question. Supplementary information is generated based on the supplementary question using the first target model. The supplementary information includes the missing target parameters, simulating the scenario when the user actually asks a question. This makes the question-and-answer data also include the supplementary question and the supplementary information, so that training samples can be generated based on the supplementary question and the supplementary information.
[0088] In some embodiments, this embodiment further includes:
[0089] According to the instructions, the function tool is invoked to obtain the parameter values corresponding to the problem;
[0090] Based on the parameter values, the answers to the questions are generated, and the parameter values and answers are used to generate training samples.
[0091] For example, if the question is "What is Zhang San's salary in January 2023?", the command is "salary_search(name='Zhang San')". Based on the command, the function tool is called, and the corresponding parameter values are "{'emp_no':'123456','name':'Zhang San','time':'2023 / 01,'salary':'xxxx'}". The answer to the question is "Hello, we found that Zhang San's salary in January 2023 is xxxx".
[0092] In this embodiment of the application, a function tool is called according to the instruction to obtain the parameter value corresponding to the question, and the answer corresponding to the question is generated based on the parameter value, so that the question and answer data also includes the parameter value and the answer, so that training samples can be generated based on the parameter value and the answer.
[0093] In some embodiments, predicting the problem that needs to be input into a second target model to trigger the generation instruction using a first target model includes:
[0094] Retrieve the set character information;
[0095] Based on the instructions and role information, the first target model predicts the questions that need to be input into the second target model to trigger the generation of instructions.
[0096] Role information refers to information describing a user's identity. Different role information indicates different users. For example, role information could indicate the identity of a human resources person or the identity of a regular employee.
[0097] For example, if the function tool is for querying salaries, and the role information indicates the identity of the personnel, then the predicted question to be input into the second target model to trigger the generation instruction could be "I need to query Zhang San's salary". If the role information indicates the identity of an ordinary employee, then the predicted question to be input into the second target model to trigger the generation instruction could be "I want to know how much Zhang San earns per month".
[0098] Since different users may input different questions for the same instruction, in this embodiment, the first target model predicts the questions that need to be input into the second target model to trigger the generation of instructions based on the instructions and role information. This makes the generated questions more diverse and further improves the ability of the trained target model to call function tools to process question-and-answer tasks based on the instructions and questions.
[0099] In some embodiments, after predicting the problem that needs to be input into the second target model to trigger the generation instruction using the first target model, the method further includes:
[0100] The problem is augmented to obtain the augmented problem.
[0101] In this process, the enhanced problem and instructions are used together to generate training samples for the second target model. The type of enhancement processing can be set according to the actual situation. For example, enhancement processing includes at least one of replacement processing, rewriting processing, simplification processing, and error correction processing. This embodiment does not limit the specific type of enhancement processing.
[0102] Replacement processing refers to replacing non-critical content in the question; the replaced content does not affect the generation of instructions. Rewriting processing refers to changing the syntax and question format without altering the key content. Simplification processing refers to reducing the question to a shorter sentence. Error correction processing refers to adding typos to the question.
[0103] In this embodiment of the application, after the problem is obtained, the problem is enhanced to diversify the problems used to generate data samples.
[0104] 102. Based on the question-and-answer data and the function toolset where the function tools are located, generate training samples for the second target model.
[0105] The terminal can assemble instructions, questions, and function toolsets to obtain training samples. In these training samples, questions serve as data, instructions as labels, and function toolsets as system prompts.
[0106] In some embodiments, training samples for the second target model are generated based on the question-answering data and the function toolset to which the function tools belong, including:
[0107] Based on partial question-and-answer data and function tools, training samples for the second target model are generated;
[0108] The order of the function tools in the function toolset is adjusted to obtain the adjusted function toolset;
[0109] Training samples for the second target model are generated based on additional question-and-answer data and the adjusted function toolkit.
[0110] For example, a function tool set includes function tool c1, function tool c2, and function tool c3. Function tool c1 is the first function tool in the function tool set, function tool c2 is the second function tool in the function tool set, and function tool c3 is the third function tool in the function tool set. After adjusting the order of the function tools in the function tool set, function tool c1 becomes the second function tool in the adjusted function tool set, function tool c3 becomes the first function tool in the adjusted function tool set, and function tool c2 becomes the third function tool in the adjusted function tool set.
[0111] In this embodiment, training samples for the second target model are generated based on a portion of the question-and-answer data and the function toolset. The order of the function tools in the function toolset is adjusted to obtain an adjusted function toolset. Training samples for the second target model are generated based on another portion of the question-and-answer data and the adjusted function toolset. This ensures that the order of the function tools in the function toolset is different in different training samples, preventing the trained target model from overfitting to the order of the function tools in the function toolset and improving the generalization ability of the trained target model in the target professional domain.
[0112] In some embodiments, when the question-answering data also includes supplementary questions and supplementary information, training samples for the second target model are generated based on the question-answering data and the function toolset to which the function tools reside, including:
[0113] The instructions, complete questions, and function toolsets are assembled to obtain training samples;
[0114] Training samples are generated based on incomplete and supplementary questions;
[0115] Training samples are generated based on incomplete questions, supplementary questions, supplementary information, instructions, and function toolsets.
[0116] In the training samples obtained by assembling instructions, complete questions, and function toolsets, the complete questions serve as the data in the training samples, and the instructions serve as the labels in the training samples. These training samples are used to train the second target model's ability to call function tools.
[0117] In the training samples generated from incomplete and supplementary questions, the incomplete questions serve as the data in the training samples, and the supplementary questions serve as the labels for the training samples. This training sample is used to train the follow-up questioning ability of the second objective model.
[0118] In the training samples generated from incomplete questions, supplementary questions, supplementary information, instructions, and function toolsets, incomplete questions, supplementary questions, and supplementary information are used as data, and instructions are used as labels. This data sample is used to train the second objective model's ability to call function tools to handle question-answering tasks.
[0119] It is understandable that the training samples generated based on incomplete questions and supplementary questions, as well as the training samples generated based on incomplete questions, supplementary questions, supplementary information, instructions, and function tools, belong to the multi-turn dialogue type.
[0120] In this embodiment, instructions, complete questions, and function toolsets are assembled to obtain training samples. Training samples are generated based on incomplete questions and supplementary questions. Training samples are generated based on incomplete questions, supplementary questions, supplementary information, instructions, and function toolsets. This enables the generation of training samples based on multi-turn dialogues. After training the second target model based on the training samples, the trained target model has the ability to ask follow-up questions. This allows the trained target model to better understand the user's intent, improves the usability of the trained target model, and further enhances the ability of the trained target model to call function tools to handle question-and-answer tasks.
[0121] In some embodiments, when the question-and-answer data also includes parameter values and answers, training samples for the second target model are generated based on the question-and-answer data and the function toolset to which the function tools reside, including:
[0122] Generate training samples from the toolkit of instructions, questions, and functions;
[0123] Training samples are generated based on parameter values and answers;
[0124] Training samples are generated based on instructions, questions, parameter values, answers, and function toolsets.
[0125] In the training samples generated based on parameter values and answers, the parameter values serve as data and the answers as labels. These training samples are used to train the second-objective model's ability to summarize the parameter values returned by the function tools into answers. Similarly, in the training samples generated based on instructions, questions, parameter values, answers, and the function tool set, the instructions, questions, and parameter values serve as data, and the answers as labels. These training samples are also used to train the second-objective model's ability to summarize the parameter values returned by the function tools into answers.
[0126] In this embodiment, training samples are generated from instructions, questions, and function toolsets; training samples are generated based on parameter values and answers; training samples are generated based on instructions, questions, parameter values, answers, and function toolsets, so that after training the second target model based on the training samples, the ability of the trained target model to summarize parameter values into answers can be improved, making it easier for users to understand the answers.
[0127] It is understandable that the training samples generated based on parameter values and answers, as well as the training samples generated based on instructions, questions, parameter values, and answers, belong to the multi-turn dialogue type.
[0128] Understandably, when the question-and-answer data also includes supplementary questions and information, training samples can be generated based on incomplete questions, supplementary questions, supplementary information, instructions, function tools, parameter values, and answers. In these training samples, the incomplete questions, supplementary questions, supplementary information, instructions, and parameter values serve as data, and the answers as labels. This training sample is used to train the second-objective model's ability to summarize the parameter values returned by the function tools into answers. The type of training sample generated based on incomplete questions, supplementary questions, supplementary information, instructions, parameter values, and answers belongs to the multi-turn dialogue type.
[0129] In some embodiments, training samples for the second target model are generated based on the question-answering data and the function toolset to which the function tools belong, including:
[0130] A training sample is obtained by assembling a single instruction, the corresponding problem, and a set of function tools.
[0131] The training samples are obtained by combining the two instructions, the corresponding problems and function toolsets for the two instructions respectively.
[0132] The two instructions can be any two instructions generated. Optionally, the order of the questions corresponding to the two instructions in the training samples is determined based on the order of the two instructions in the training samples. For example, the instruction to call function tool c1 is instruction d1, and the question that triggers the generation of instruction d1 is q1. The instruction to call function tool c2 is instruction d2, and the question that triggers the generation of instruction d2 is q2. In the training samples generated based on instruction d1, question q1, instruction d2, and question q2, the order of instruction d1 precedes the order of instruction d2, and the order of question q1 precedes the order of question q2.
[0133] It is understandable that assembling the training samples obtained by combining the two instructions and the problem and function toolkits corresponding to the two instructions respectively results in a parallel type of training samples.
[0134] In this application, a training sample is obtained by assembling a single instruction, the corresponding problem, and the function tool set. Similarly, a training sample is obtained by assembling two instructions, the corresponding problems, and the function tool sets. This allows a training sample to contain two instructions, enabling the parallel invocation of two function tools and improving the usability of the target model after training.
[0135] In some embodiments, the training sample type includes at least two of the following: single-tool type, multi-tool type, parallel type, and multi-turn dialogue type. The single-tool type refers to a type in which the function tool set includes only one function tool. The multi-tool type refers to a type in which the function tool set includes at least two function tools. The parallel type refers to a type in which the training sample includes two instructions and two questions that trigger the generation of the two instructions. The multi-turn dialogue type refers to a type in which the training sample contains multi-turn dialogue information, wherein the multi-turn dialogue information is used to ask follow-up questions based on the parameters required to call the function tool to obtain all the parameters required for the input.
[0136] In this embodiment of the application, the training samples include at least two types, which increases the diversity of training samples and further enhances the ability of the trained target model to handle question-answering tasks.
[0137] In some embodiments, the order of training samples of various types in the training set is shuffled, which improves the training of the second target model based on the training samples to prevent overfitting and improves the generalization ability of the trained target model.
[0138] In some embodiments, the second target model can also be trained based on training samples of an irrelevant type, which are training samples generated based on question-and-answer data unrelated to function tool calls.
[0139] In some embodiments, when the function tool is a function tool for the target professional domain, before generating the second target model training samples based on the question-answering data and the function tool set to which the function tool belongs, the method further includes:
[0140] Obtain model description information for each candidate large language model;
[0141] Based on the target professional field and model introduction information, the second target model is determined from various candidate large language models.
[0142] The model description information includes at least one of the following: basic information about the model, the characteristics of the model, and the model's logs.
[0143] The terminal can determine the matching degree between each candidate large language model and the target professional field based on the model introduction information and the requirements of the target professional field. Then, the candidate large language model with the highest matching degree is determined as the second target model. Alternatively, the terminal can predict the matching degree between the candidate large language model and the target professional field based on the model introduction information and the requirements of the target professional field, recommend each candidate large language model to the user according to the matching degree, and then, in response to the user's selection operation of the candidate large language model, determine the candidate large language model corresponding to the selection operation as the second target model.
[0144] In this regard, the matching degree between each candidate large language model and the target professional field can be determined according to the characteristics of the model and the requirements of the target professional field. For example, if the target professional field is hotel customer service, the questions in this field are usually in the form of text. In this case, the matching degree of the candidate large language model that is good at handling text-based questions is greater than that of the candidate large language model that is good at handling image-based questions. As another example, if the target professional field is law, the questions in this field are usually longer. In this case, the matching degree of the candidate large language model that is good at handling long questions is greater than that of the candidate large language model that is good at handling short questions.
[0145] In this embodiment of the application, model description information of each candidate large language model is obtained. Based on the target professional field and model description information, a second target model is determined from each candidate large language model. This allows the training of the second target model to be completed more quickly, further improving the efficiency of obtaining the trained target model.
[0146] In some embodiments, before generating training samples for the second target model based on the question-answering data and the function toolset to which the function tools reside, the method further includes:
[0147] Display the various candidate large language models;
[0148] In response to the selection operation of each candidate large language model, the candidate large language model corresponding to the selection operation is determined as the second target model.
[0149] In this embodiment, various candidate large language models are displayed. In response to a selection operation on each candidate large language model, the candidate large language model corresponding to the selection operation is determined as the second target model, allowing the user to select the second target model themselves, thus improving the user experience.
[0150] In some embodiments, when the function tool is a function tool in the target professional field, acquiring question-and-answer data related to the function tool includes:
[0151] Display the data generation interface;
[0152] In response to input operations on the data generation interface, obtain the name of the target professional field;
[0153] Using the first target model, question-and-answer data related to the function tools of the target professional field is generated based on the name of the target professional field.
[0154] In this embodiment, a data generation interface is displayed. In response to input operations on the data generation interface, the name of the target professional field is obtained. Based on the name of the target professional field, question and answer data related to the function tools of the target professional field is generated through the first target model. This allows users to select the target professional field according to their needs, thereby making the trained target model adept at handling question and answer tasks in the professional field required by the user, and enabling users to customize the model.
[0155] It is understandable that when a user manually selects a second target model, they can choose to generate question-and-answer data before selecting the second target model, or they can choose to generate question-and-answer data at the same time as selecting the second target model. This embodiment does not limit this.
[0156] Optionally, users can also provide function tools in the target professional field to make the trained target model more in line with the user's needs.
[0157] 103. Based on the training samples, train the second target model to obtain the trained target model.
[0158] Specifically, when the function tool is a general-domain function tool, the trained target model is a model that is good at calling the function tool to handle question-answering tasks in the general domain; when the function tool is a function tool in the target professional domain, the trained target model is a model that is good at calling the function tool to handle question-answering tasks in the target professional domain.
[0159] Specifically, the terminal can input the questions and function toolset from the training samples into the second target model for prediction processing to obtain prediction instructions. Based on the prediction instructions and the instructions in the training samples, a loss function value is determined. If the loss function value meets the preset loss condition, the second target model is determined as the trained target model. If the loss function value does not meet the preset loss condition, the weights of the second target model are updated according to the loss function value, and the process returns to the step of inputting the questions and function toolset from the training samples into the second target model for prediction processing. The preset loss condition is used to indicate that the loss function value has converged.
[0160] Understandably, the loss function value determined based on the prediction instruction and the instructions in the training samples is called the first loss function value. When the training samples include incomplete questions and supplementary questions, the incomplete questions are input into the second target model for prediction processing to obtain the predicted supplementary questions. The second loss function value is determined based on the predicted supplementary questions and the supplementary questions. When the training samples include parameter values and answers, the parameter values are input into the second target model for prediction processing to obtain the predicted answers. The third loss function value is determined based on the answers and the predicted answers. At this point, the loss function value of the second target model can be determined based on the first, second, and third loss function values. If the loss function value meets the preset loss condition, the second target model is determined as the post-trained target model. If the loss function value does not meet the preset loss condition, the weights of the second target model are updated according to the loss function value, and the process returns to the step of inputting the training samples into the second target model for prediction processing.
[0161] In some embodiments, the second target model is trained based on training samples to obtain the trained target model, including:
[0162] Obtain real question and answer data;
[0163] Generate real training samples based on real question-and-answer data;
[0164] The second target model is trained based on the training samples and the real training samples to obtain the trained target model.
[0165] In this embodiment, the question-and-answer data generated by the first target model can be referred to as simulated question-and-answer data. Real question-and-answer data includes questions manually entered by the user and the corresponding instructions for those questions.
[0166] In this embodiment, real question-and-answer data is obtained, real training samples are generated based on the real question-and-answer data, and the second target model is trained based on the training samples and real training samples to obtain the trained target model. This realizes the training of the second target model based on simulated question-and-answer data and real question-and-answer data, and further improves the ability of the trained target model to call function tools to process question-and-answer tasks.
[0167] In some embodiments, when the function tools include general domain function tools and target domain general function tools, the trained target model not only excels at handling question-answering tasks in the target domain, but also retains its ability to handle question-answering tasks in the general domain.
[0168] In some embodiments, the second target model is trained based on training samples to obtain the trained target model, including:
[0169] Set up an adapter for the second target model;
[0170] The training samples are input into the second target model for prediction processing to obtain the loss function value;
[0171] If the loss function value does not meet the preset loss condition, the weights of the adapter are updated based on the loss function value, and the process returns to the step of inputting the training samples into the second target model for prediction processing to obtain the loss function value.
[0172] If the loss function value meets the preset loss condition, the weights of the adapter and the weights of the network layers in the second target model are fused to obtain the trained target model.
[0173] The adapter for the second target model can be defined as adding a new network layer in a position parallel to at least one network layer in the second target model. The weights of the new network layer are obtained by multiplying two low-rank matrices. The size of the weights of the new network layer is the same as the size of the weights of the at least one network layer. If the size of the weights of the at least one network layer is m*n, splitting the m*n matrix yields two matrices, m*r and r*n. Therefore, the sizes of the two matrices for the newly added network layer are m*r and r*n, respectively. If the weights of the at least one network layer are updated directly, the number of parameters to be updated is m*n. However, if the weights of the additional network layer are updated, the number of parameters to be updated is m*r + r*n, where m*r + r*n is less than m*n.
[0174] Therefore, in this embodiment, an adapter for the second target model is set up, and training samples are input into the second target model for prediction processing to obtain a loss function value. If the loss function value does not meet the preset loss condition, the weights of the adapter are updated based on the loss function value, and the process returns to the step of inputting training samples into the second target model for prediction processing to obtain a loss function value. If the loss function value meets the preset loss condition, the weights of the adapter and the weights of at least one network layer in the second target model are fused to obtain the trained target model, thereby reducing the number of parameters that need to be updated and further improving the training efficiency of the second target model.
[0175] For example, when training the second target model based on training samples and real training samples, the training process of the second target model in this embodiment can be as follows: Figure 2 As shown.
[0176] In some embodiments, this embodiment further includes:
[0177] Get the preset number of updates;
[0178] Get the adapter's weight after the preset number of updates;
[0179] The weights of the adapter and the weights of the network layers in the second target model are fused to obtain the trained target model, which includes:
[0180] The weights after being updated a preset number of times will be merged to obtain the adapter weights;
[0181] The weights of the adapter and the weights of the network layers in the second target model are fused to obtain the trained target model.
[0182] The preset update count, also known as breakpoints, refers to certain numbers of updates made by the adapter. Since the training count of the model can be set before training, the preset update count can be determined based on the training count. For example, the preset update count could be the 1st / 3rd, 2nd / 3rd, and last training count, but this embodiment does not impose any limitations on this.
[0183] For example, if the training iterations are 30, and the adapter weights are updated 30 times when the loss function value meets the preset loss condition (the preset update times are the 10th, 20th, and 30th), the adapter weights after the 10th, 20th, and 30th updates are fused to obtain the adapter weights. Then, the adapter weights are fused with the weights of at least one network layer in the second target model to obtain the trained target model. At this point, the adapter weights fused with the weights of at least one network layer in the second target model are not the last updated adapter weights, but rather the weights fused with the adapter weights after the preset update times.
[0184] It is understandable that the terminal can record the weight of the adapter after a preset number of updates, and then obtain the weight of the adapter after a preset number of updates when the loss function value meets the preset loss condition.
[0185] As training time increases, the ability of the second target model to handle general domain question-answering tasks decreases. In this embodiment, a preset number of updates is obtained, and the weights of the adapter after the preset number of updates are obtained. The weights after the preset number of updates are fused to obtain the adapter weights. The adapter weights are then fused with the weights of the network layers in the second target model to obtain the trained target model for the target professional domain. This not only improves the ability of the trained target model to handle question-answering tasks in the target professional domain, but also maintains its ability to handle general domain question-answering tasks, preventing the trained target model from overfitting to the training samples and improving its generalization ability.
[0186] In some embodiments, after obtaining the trained target model, the ability of the trained target model to handle question-answering tasks in the target professional domain can be evaluated.
[0187] Specifically, the process of evaluating the trained target model can be as follows:
[0188] Obtain a test set that includes at least one test sample;
[0189] Based on the evaluation samples, assess the ability of the trained target model to handle question-answering tasks in the target professional domain.
[0190] The evaluation samples in the evaluation set can be manually generated samples, or the process of generating the evaluation samples can refer to the process of generating the training samples. This embodiment will not be described in detail here.
[0191] The evaluation samples include question-and-answer data related to the functions in the function toolset, as well as the function toolset itself. The question-and-answer data includes questions and instructions. For ease of description, the questions in the training samples are referred to as the first question, the instructions in the training samples as the first instruction, the questions in the evaluation samples as the second question, the instructions in the evaluation samples as the second instruction, and the predicted instructions mentioned above as the first predicted instruction. Then, based on the evaluation samples, the ability of the trained target model to handle question-and-answer tasks in the target professional domain is evaluated, including:
[0192] The second question and the function tool set are input into the trained target model for processing, generating a second prediction instruction that calls the function tools in the function tool set;
[0193] Based on the function tools invoked by the second prediction instruction and the function tools invoked by the second instruction, evaluate the ability of the trained target model to invoke the function tools in the function toolset set to handle question-answering tasks.
[0194] Specifically, after inputting the second question and the set of function tools into the trained target model, the trained target model can predict which function tool in the function tools will provide the answer to the question, and then generate a second prediction instruction to call that function tool.
[0195] For example, the function toolkit includes function tool c1, function tool c2, and function tool c3. It is predicted that the answer to the question will be obtained through function tool c2, and a second prediction instruction will be generated to call function tool c2.
[0196] The second prediction instruction includes a tool name, and the second instruction also includes a tool name. The function tool called by the second prediction instruction refers to the function tool corresponding to the tool name in the second prediction instruction. The function tool called by the second instruction is equivalent to a label. Based on the label, it is determined whether the function tool called by the second prediction instruction is correct.
[0197] For the same problem, if the function tool called by the second prediction instruction is the same as the function tool called by the second instruction, it indicates that the target training model's call to the function tool after training is accurate. If the function tool called by the second prediction instruction is different from the function tool called by the second instruction, it indicates that the target training model's call to the function tool after training is incorrect, and other function tools in the function tool set are interfering with the call to the function tool.
[0198] For example, the evaluation sample includes a question q1 and an instruction d1. Instruction d1 is an instruction to call function tool c3. The function tool set includes function tool c1, function tool c2, and function tool c3. The question q1 and the function tool set are input into the trained target model for processing to obtain the second prediction instruction d11. If the second prediction instruction d11 is a prediction instruction to call function tool c3, it indicates that the call to function tool c3 is accurate. If the second prediction instruction d11 is a prediction instruction to call function tool c2, it indicates that the call to function tool c3 is incorrect, and function tool c2 interferes with the call to function tool c3.
[0199] After receiving the second prediction instruction, the terminal can count the number of correct calls and the number of incorrect calls for each function tool according to the function tools called by the second prediction instruction and the function tools called by the second instruction. Finally, based on the statistical results of each function tool, the terminal can evaluate the ability of the trained target model to call the function tools in the function tool set to handle question answering tasks.
[0200] In this embodiment, based on the function tools invoked by the second prediction instruction and the function tools invoked by the second instruction, the ability of the trained target model to call function tools in the function tool set to handle question-answering tasks is evaluated. This simplifies the evaluation task of the trained target model's ability to handle question-answering tasks into a function tool classification task, enabling the trained target model to obtain its calling capabilities on each function tool. This refines the granularity of evaluating the trained target model's ability to handle question-answering tasks and improves the accuracy of the evaluation.
[0201] In some embodiments, the ability of the trained target model to call function tools in the function tool set to handle question-answering tasks is evaluated based on the function tools invoked according to the second prediction instruction and the function tools invoked by the second instruction, including:
[0202] Based on the function tools invoked by the second prediction instruction and the function tools invoked by the second instruction, the influence coefficient between the function tools is determined. The influence coefficient is used to indicate the degree of mutual influence between the function tools.
[0203] Based on the impact coefficient, we evaluate the ability of the target model after training to call functions in the function toolkit to handle question-answering tasks.
[0204] In this embodiment, when the function tool called by the second prediction instruction is different from the function tool called by the second instruction, it can be determined that the function tool called by the second prediction instruction is interfering with the function tool called by the second instruction. This allows us to obtain the degree of mutual influence between the various function tools, so that the training samples can be adjusted according to the degree of mutual influence between the various function tools. Based on the training samples, the target model after training can be fine-tuned. Therefore, the evaluation method of this embodiment can provide guidance for the fine-tuning of the target model after training, and improve the efficiency of obtaining the final target model.
[0205] In some embodiments, the ability of the trained target model to call function tools in the function tool set to handle question-answering tasks is evaluated based on the function tools invoked according to the second prediction instruction and the function tools invoked by the second instruction, including:
[0206] Based on the function tools called by the second prediction instruction and the function tools called by the second instruction, a confusion matrix is constructed. The column data in the confusion matrix indicates the function tools called by the second instruction, and the row data in the confusion matrix indicates the function tools called by the second prediction instruction.
[0207] Based on the confusion matrix, we evaluate the ability of the trained target model to call functions from the function toolkit to handle question-answering tasks.
[0208] The confusion matrix, also known as the error matrix, is used to show the classification results of the target model on the function tool after training.
[0209] For example, a confusion matrix can be like this: Figure 3 As shown, from Figure 3 As can be seen, there are 11 evaluation samples for function tool c1. Among the second prediction instructions generated based on the problems in the 11 evaluation samples, the function tool in 8 of the second prediction instructions is function tool c1, indicating that the 8 second prediction instructions are accurate and the call to function tool c1 is accurate. The function tool in 3 of the second prediction instructions is function tool c3, indicating that the call to function tool c1 was misidentified as a call to function tool c3, indicating that there was an error in the call to function tool c3.
[0210] In this embodiment, a confusion matrix is constructed based on the function tools called by the second prediction instruction and the function tools called by the second instruction. The column data in the confusion matrix indicates the function tools called by the second instruction, and the row data in the confusion matrix indicates the function tools called by the second prediction instruction. Based on the confusion matrix, the ability of the trained target model to call the function tools in the function tool set to handle question-answering tasks is evaluated. This allows not only a direct view of the classification results of the trained target model on the function tools, but also a comprehensive evaluation of the trained target model.
[0211] In some embodiments, based on the confusion matrix, the ability of the trained target model to invoke functions from a set of functions to handle question-answering tasks is evaluated, including:
[0212] Based on the row data in the confusion matrix, the influence coefficients between the function tools are determined. The influence coefficients are used to indicate the degree of mutual influence between the function tools.
[0213] Based on the impact coefficient, we evaluate the ability of the target model after training to call functions in the function toolkit to handle question-answering tasks.
[0214] The type of influence coefficient can be set according to the actual situation. For example, the influence coefficient can be at least one of True Positive (TP), True Negative (TN), False Positive (FP), and False Negative (FN). This application embodiment does not limit this.
[0215] True positives represent the number of evaluation samples that predict a function tool as that function tool. True negatives represent the number of evaluation samples that predict other function tools as other function tools. False positives represent the number of evaluation samples that predict other function tools as that function tool, which can represent the interference that function tool causes to other function tools. False negatives represent the number of evaluation samples that predict a function tool as other function tools, which can represent the interference that other function tools cause to that function tool.
[0216] In this embodiment, the influence coefficients between functional tools are determined based on the row data in the confusion matrix. The influence coefficients are used to indicate the degree of mutual influence between functional tools. Based on the influence coefficients, the ability of the trained target model to call functional tools in the functional tool set to handle question-answering tasks is evaluated. This allows the training samples to be adjusted according to the degree of mutual influence between the various functional tools. Based on the training samples, the trained target model can be further fine-tuned. Therefore, the evaluation method of this embodiment can provide guidance for the fine-tuning of the trained target model and improve the efficiency of obtaining the final target model.
[0217] In some embodiments, the ability of the trained target model to invoke functions from a set of functions to handle question-answering tasks is evaluated based on an impact coefficient, including:
[0218] Based on the influence coefficient, the call capability indicator parameters for each function tool are determined. The call capability indicator parameters include at least one of accuracy, precision, recall, F1 score, specificity, and area under the ROC curve.
[0219] Based on the call capability indicator parameter for each function tool, the ability of the trained target model to call each function tool is determined.
[0220] For example, based on the influence coefficient of function tool c1, determine the calling capability indicator parameter of function tool c1; based on the calling capability indicator parameter of function tool c1, determine the ability of the target model to call function tool c1 after training; based on the influence coefficient of function tool c2, determine the calling capability indicator parameter of function tool c2; based on the calling capability indicator parameter of function tool c2, determine the ability of the target model to call function tool c2 after training.
[0221] In the embodiments of this application, based on the influence coefficient, the calling capability indicator parameter for each function tool is determined. The calling capability indicator parameter includes at least one of accuracy, precision, recall, F1 score, specificity, and area under the ROC curve. Based on the calling capability indicator parameter for each function tool, the ability of the trained target model to call the function tool is determined, thereby obtaining the performance capability of the trained target model on each function tool.
[0222] In some embodiments, the ability of the trained target model to invoke functions from a set of functions to handle question-answering tasks is evaluated based on an impact coefficient, including:
[0223] Based on the influence coefficient, determine the overall evaluation coefficient of the target model after training for each function tool;
[0224] Based on the overall evaluation coefficient, the ability of the target model after training to call functions in the function toolkit to handle question-answering tasks is evaluated.
[0225] The process of determining the overall evaluation coefficients of the trained target model for each function tool based on the influence coefficient can be described as follows:
[0226] Based on the impact coefficient, the invocation capability indicator parameters for each function tool are determined. The invocation capability indicator parameters include at least one of precision and recall.
[0227] The call capability indicator parameters are weighted to obtain the overall evaluation coefficient of the target model for each function tool after training; or the call capability indicator parameters are averaged to obtain the overall evaluation coefficient of the target model for each function tool after training.
[0228] For example, when the invocation capability indicator parameter is precision, the overall evaluation coefficient can be weighted precision or average precision; when the invocation capability indicator parameter is recall, the overall evaluation coefficient can be weighted recall.
[0229] The weighted precision rate can be calculated using the following formula:
[0230]
[0231] p_i represents the accuracy of the i-th function tool, Number_i represents the number of evaluation samples associated with the i-th function tool, and Total represents the total number of evaluation samples in the evaluation set.
[0232] Average precision can be calculated using the following formula:
[0233]
[0234] Here, p_i represents the accuracy of the i-th function tool, and N represents the number of function tools in the function tool set.
[0235] In this embodiment, the overall evaluation coefficient of the trained target model for each function tool is determined based on the influence coefficient. Based on the overall evaluation coefficient, the ability of the trained target model to call the function tools in the function tool set to handle question-answering tasks is evaluated. This realizes the evaluation of the trained target model based on the overall evaluation coefficient, thereby further improving the accuracy of the evaluation of the trained target model.
[0236] In some embodiments, after receiving the second prediction instruction, the method further includes:
[0237] The correctness of the second prediction instruction is analyzed based on the target dimension, and the analysis results are obtained. The target dimension includes at least one of the following: the structure of the second prediction instruction, the parameters in the second prediction instruction, and the applicable scenarios of the second prediction instruction.
[0238] Based on the function tools invoked by the second prediction instruction and the function tools invoked by the second instruction, evaluate the ability of the trained target model to invoke the function tools in the function toolset set to handle question-answering tasks, including:
[0239] Based on the function tools invoked by the second prediction instruction, the function tools invoked by the second instruction, and the analysis results, evaluate the ability of the trained target model to invoke the function tools in the function toolset to handle question-answering tasks.
[0240] When the target dimension is the structure of the second prediction instruction, the process of analyzing the correctness of the second prediction instruction based on its structure and obtaining the analysis results can be as follows:
[0241] Determine whether the second prediction instruction includes a tool name and parameters;
[0242] If the second prediction instruction includes a tool name and parameters, it indicates that the structure of the second prediction instruction is correct, and the analysis result will be determined as the correct result.
[0243] When the target dimension is a parameter in the second prediction instruction, the process of analyzing the correctness of the second prediction instruction based on its parameters and obtaining the analysis results can be as follows:
[0244] The analysis results are obtained by examining whether the parameters in the second prediction instruction are missing, whether there are unnecessary parameters, whether the parameter types are incorrect, and whether the parameters match.
[0245] When the target dimension is the applicable scenario of the second prediction instruction, the process of analyzing the correctness of the second prediction instruction based on the applicable scenario and obtaining the analysis results can be as follows:
[0246] Determine the applicable scenario for the second prediction instruction, which indicates whether or not a function tool needs to be called.
[0247] Based on the applicable scenarios of the second prediction instruction, the correctness of the second prediction instruction is analyzed, and the analysis results are obtained.
[0248] In the case where the second prediction instruction is applicable in a scenario that requires calling a function tool, it may misidentify that a function tool should not be called as one should be called.
[0249] In this embodiment, the correctness of the second prediction instruction is analyzed based on the target dimension to obtain the analysis results. The target dimension includes at least one of the following: the structure of the second prediction instruction, the parameters in the second prediction instruction, and the applicable scenarios of the second prediction instruction. Based on the function tools called by the second prediction instruction, the function tools called by the instruction, and the analysis results, the ability of the trained target model to call the function tools in the function tool set to handle question-answering tasks is evaluated, thereby realizing the evaluation of the trained target model from multiple dimensions and further improving the accuracy of the evaluation of the trained target model.
[0250] In some embodiments, when the question-answering data includes real question-answering data and simulated question-answering data, the terminal can generate evaluation samples based on the real and simulated question-answering data. Based on the evaluation samples, the number of correct prediction instructions obtained through the trained target model and the number of correct prediction instructions obtained through the second target model are determined. Based on the number of correct prediction instructions, the accuracy of the trained target model and the accuracy of the second target model are obtained. The accuracy of the trained target model indicates its ability to handle question-answering tasks, and the accuracy of the second target model indicates its ability to handle question-answering tasks. This allows for a comparison of the ability of the trained target model and the second target model to handle question-answering tasks. For example, ... Figure 4 As shown.
[0251] As can be seen from the above, in this embodiment, question-and-answer data related to the function tool is obtained. This data includes questions and instructions for calling the function tool generated by the first target model based on the function description and parameter description of the input parameters required to call the function tool. Based on the question-and-answer data and the function tool set to which the function tool belongs, training samples for the second target model are generated. Based on the training samples, the second target model is trained to obtain the trained target model. This achieves the automatic generation of question-and-answer data related to the function tool from the first target model based on the function description and parameter description, and the generation of training samples for the second target model. This allows the second target model to be trained based on the training samples, reducing the training difficulty of the second target model.
[0252] To better implement the above methods, this application also provides a model training device, which can be integrated into an electronic device, such as a computer device, which can be a terminal, server, or other such device.
[0253] The terminal can be a mobile phone, tablet computer, smart Bluetooth device, laptop computer, personal computer, etc.; the server can be a single server or a server cluster composed of multiple servers.
[0254] For example, in this embodiment, the method of this application embodiment will be described in detail by taking the model training device specifically integrated into the terminal as an example. This embodiment provides a model training device, such as... Figure 5 As shown, the model training device may include:
[0255] The acquisition module 501 is used to acquire question and answer data related to the function tool. The question and answer data includes questions generated and instructions for calling the function tool, based on the function description of the function tool and the parameter description of the input parameters required to call the function tool, through the first target model.
[0256] The generation module 502 is used to generate training samples for the second target model based on the question-and-answer data and the function toolset where the function tools are located.
[0257] Training module 503 is used to train the second target model based on training samples to obtain the trained target model.
[0258] In some embodiments, the training module 503 is specifically used to perform:
[0259] Set up an adapter for the second target model;
[0260] The training samples are input into the second target model for prediction processing to obtain the loss function value;
[0261] If the loss function value does not meet the preset loss condition, the weights of the adapter are updated based on the loss function value, and the process returns to the step of inputting the training samples into the second target model for prediction processing to obtain the loss function value.
[0262] If the loss function value meets the preset loss condition, the weights of the adapter and the weights of the network layers in the second target model are fused to obtain the trained target model.
[0263] In some embodiments, the training module 503 is specifically used to perform:
[0264] Get the preset number of updates;
[0265] Get the adapter's weight after the preset number of updates;
[0266] The weights after being updated a preset number of times will be merged to obtain the adapter weights;
[0267] The weights of the adapter and the weights of the network layers in the second target model are fused to obtain the trained target model.
[0268] In some embodiments, the function tool is a function tool for a specific professional field, and the acquisition module 501 is also used to perform:
[0269] Obtain model description information for each candidate large language model;
[0270] Based on the target professional field and model introduction information, the second target model is determined from various candidate large language models.
[0271] In some embodiments, the generation module 502 is specifically used to perform:
[0272] Based on partial question-and-answer data and function tools, training samples for the second target model are generated;
[0273] The order of the function tools in the function toolset is adjusted to obtain the adjusted function toolset;
[0274] Training samples for the second target model are generated based on additional question-and-answer data and the adjusted function toolkit.
[0275] In some embodiments, the training samples include at least two of the following types: single-tool type, multi-tool type, parallel type, and multi-turn dialogue type;
[0276] A single-tool type refers to a type where the function toolkit contains only one function tool.
[0277] Multi-tool type refers to a type of function toolkit that includes at least two function tools;
[0278] Parallel type refers to a training sample that includes two instructions and two questions that trigger the generation of the two instructions.
[0279] Multi-turn dialogue type refers to training samples containing multi-turn dialogue information, where multi-turn dialogue information is used to ask follow-up questions based on the parameters required for the function tool to obtain all the required input parameters.
[0280] In some embodiments, the acquisition module 501 is specifically used to perform:
[0281] Get the function description of the tool and the parameter description of the input parameters required to call the tool;
[0282] Based on the functional and parameter descriptions, the instructions for calling the function tool in the second target model are generated using the first target model.
[0283] The first target model is used to predict the problem that needs to be input into the second target model to trigger the generation instruction.
[0284] In practice, each of the above modules can be implemented as an independent entity or can be combined arbitrarily to be implemented as the same or several entities. For the specific implementation methods and corresponding beneficial effects of each of the above modules, please refer to the previous method embodiments, which will not be repeated here.
[0285] Accordingly, this application also provides an electronic device, which can be a terminal, such as a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer (PC), personal digital assistant (PDA), or other terminal device. Figure 6 As shown, Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device 600 includes a processor 601 with one or more processing cores, a memory 602 with one or more computer-readable storage media, and a computer program stored on the memory 602 and executable on the processor. The processor 601 and the memory 602 are electrically connected. Those skilled in the art will understand that the electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0286] The processor 601 is the control center of the electronic device 600. It connects various parts of the electronic device 600 through various interfaces and lines. By running or loading software programs and / or modules stored in the memory 602, and calling data stored in the memory 602, it performs various functions of the electronic device 600 and processes data, thereby monitoring the electronic device 600 as a whole.
[0287] In this embodiment, the processor 601 in the electronic device 600 loads the instructions corresponding to the processes of one or more applications into the memory 602 according to the following steps, and the processor 601 runs the applications stored in the memory 602 to achieve various functions, such as:
[0288] Acquire question and answer data related to the function tool. The question and answer data includes questions generated and instructions for calling the function tool, based on the function description of the function tool and the parameter description of the input parameters required to call the function tool, through the first target model.
[0289] Based on the question-and-answer data and the function toolset where the function tools are located, training samples for the second target model are generated;
[0290] Based on the training samples, the second target model is trained to obtain the trained target model.
[0291] For details on the specific implementation methods and corresponding beneficial effects of each of the above operations, please refer to the detailed description of the model training method above, which will not be repeated here.
[0292] Optional, such as Figure 6 As shown, the electronic device 600 also includes: a touch display screen 603, a radio frequency circuit 604, an audio circuit 605, an input unit 606, and a power supply 607. The processor 601 is electrically connected to the touch display screen 603, the radio frequency circuit 604, the audio circuit 605, the input unit 606, and the power supply 607. Those skilled in the art will understand that... Figure 6 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0293] The touch display screen 603 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 603 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the electronic device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar technologies. The touch panel can be used to collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 601. It can also receive and execute commands from the processor 601. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 601 to determine the type of touch event. Subsequently, the processor 601 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 603 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 603 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 603 can also be used as part of the input unit 606 to achieve input functions.
[0294] The radio frequency circuit 604 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other electronic devices, and to transmit and receive signals with network devices or other electronic devices.
[0295] Audio circuit 605 can be used to provide an audio interface between a user and an electronic device via a speaker and a microphone. Audio circuit 605 can convert received audio data into electrical signals and transmit them to the speaker, where the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuit 605, converted back into audio data, and then processed by processor 601 before being transmitted via radio frequency circuit 604 to, for example, another electronic device, or output to memory 602 for further processing. Audio circuit 605 may also include an earphone jack to provide communication between peripheral headphones and electronic devices.
[0296] The input unit 606 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.
[0297] Power supply 607 is used to supply power to various components of electronic device 600. Optionally, power supply 607 can be logically connected to processor 601 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 607 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0298] although Figure 6 As not shown in the diagram, the electronic device 600 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.
[0299] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0300] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0301] Therefore, embodiments of this application provide a computer-readable storage medium storing multiple computer programs that can be loaded by a processor to execute any of the model training methods provided in embodiments of this application. For example, the computer program can perform the following steps:
[0302] Acquire question and answer data related to the function tool. The question and answer data includes questions generated and instructions for calling the function tool, based on the function description of the function tool and the parameter description of the input parameters required to call the function tool, through the first target model.
[0303] Based on the question-and-answer data and the function toolset where the function tools are located, training samples for the second target model are generated;
[0304] Based on the training samples, the second target model is trained to obtain the trained target model.
[0305] For details on the specific implementation methods and corresponding beneficial effects of each of the above operations, please refer to the detailed description of the model training method above, which will not be repeated here.
[0306] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0307] Since the computer program stored in the computer-readable storage medium can execute any of the model training methods provided in the embodiments of this application, it can achieve the beneficial effects that any of the model training methods provided in the embodiments of this application can achieve, as detailed in the preceding embodiments, and will not be repeated here.
[0308] The foregoing has provided a detailed description of a model training method, apparatus, electronic device, and computer-readable storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A model training method, characterized in that, The method includes: Acquire question and answer data related to the function tool, the question and answer data including questions generated by the first target model based on the function description of the function tool and the parameter description of the input parameters required to call the function tool, and instructions for calling the function tool; Based on the question-and-answer data and the function tool set to which the function tool belongs, training samples for the second target model are generated; Based on the training samples, the second target model is trained to obtain the trained target model; This includes acquiring question-and-answer data related to function tools, including: Obtain the function description of the function tool and the parameter description of the input parameters required to call the function tool; Based on the first target model and the function description and parameter description, an instruction for the second target model to call the function tool is generated. The first target model is used to predict the problem that needs to be input into the second target model to trigger the generation of the instruction.
2. The model training method as described in claim 1, characterized in that, The step of training the second target model based on the training samples to obtain the trained target model includes: Configure the adapter for the second target model; The training samples are input into the second target model for prediction processing to obtain the loss function value; If the loss function value does not meet the preset loss condition, the weights of the adapter are updated based on the loss function value, and the process returns to the step of inputting the training samples into the second target model for prediction processing to obtain the loss function value. If the loss function value satisfies the preset loss condition, the weights of the adapter and the weights of the network layers in the second target model are fused to obtain the trained target model.
3. The model training method as described in claim 2, characterized in that, The method further includes: Get the preset number of updates; Obtain the weight of the adapter after the preset number of updates; The weights of the adapter and the weights of the network layers in the second target model are fused to obtain the trained target model, including: The weights updated after the preset number of updates are merged to obtain the weights of the adapter; The weights of the adapter and the weights of the network layers in the second target model are fused to obtain the trained target model.
4. The model training method as described in claim 1, characterized in that, The function tool is a function tool for the target professional field. Before generating training samples for the second target model based on the question-and-answer data and the function tool set to which the function tool belongs, the method further includes: Obtain model description information for each candidate large language model; Based on the target professional field and the model description information, a second target model is determined from each of the candidate large language models.
5. The model training method as described in claim 1, characterized in that, The step of generating training samples for the second target model based on the question-and-answer data and the function toolset to which the function tools belong includes: Based on a portion of the question-and-answer data and the function toolkit, training samples for the second target model are generated; The order of the function tools in the function toolset is adjusted to obtain the adjusted function toolset; Training samples for the second target model are generated based on the question-and-answer data described in the other part and the adjusted function toolkit.
6. The model training method as described in claim 1, characterized in that, The training samples include at least two of the following types: single-tool type, multi-tool type, parallel type, and multi-turn dialogue type. The single tool type refers to a type in which the function tool set includes only one function tool; The term "multi-tool type" refers to a type in which the function toolkit includes at least two function tools. The parallel type refers to the type in which the training sample includes two instructions and two questions that trigger the generation of the two instructions. The multi-turn dialogue type refers to the training samples containing multi-turn dialogue information, wherein the multi-turn dialogue information is used to ask follow-up questions based on the parameters required to call the function tool to obtain all the required input parameters.
7. A model training device, characterized in that, The device includes: The acquisition module is used to acquire question and answer data related to the function tool. The question and answer data includes questions generated by the first target model based on the function description of the function tool and the parameter description of the input parameters required to call the function tool, as well as the instructions to call the function tool. The generation module is used to generate training samples for the second target model based on the question-and-answer data and the function toolset to which the function tools belong; The training module is used to train the second target model based on the training samples to obtain the trained target model; The acquisition module is used to perform: Obtain the function description of the function tool and the parameter description of the input parameters required to call the function tool; Based on the first target model and the function description and parameter description, an instruction for the second target model to call the function tool is generated. The first target model is used to predict the problem that needs to be input into the second target model to trigger the generation of the instruction.
8. An electronic device, characterized in that, The system includes a processor and a memory, the memory storing multiple instructions; the processor loads instructions from the memory to execute the model training method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions adapted for loading by a processor to execute the model training method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Training sample generation method, model training method, knowledge question and answer method and equipment
CN117575008A
Financial field intelligent question and answer method based on tool enhancement
CN118227766A
Large language model black box tracing method and system and storage medium
CN118394883A