Model training method, electronic device, readable storage medium and program product

By using differentiated scoring of the model's multi-round response process and optimizing the training dataset, the problem of insufficient accuracy and generalization ability of base model tool calls in existing technologies is solved, thereby improving the task execution success rate.

CN123159451APending Publication Date: 2026-11-24SHANGHAI GLORY SMART TECH DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611490734.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-23
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing model training methods struggle to improve the accuracy and generalization ability of base models in tool calls, resulting in low task execution success rates.

Method used

By acquiring model response information from multiple rounds, differentiated scoring rules are designed to score each round of response. Simulated user input is generated by combining preset system prompts, and model parameters are optimized. The training dataset is optimized using supervised fine-tuning training and tool recall interfaces, and the context length is reduced to improve training efficiency.

Benefits of technology

It enables refined evaluation of the model's multi-round response process, improves the accuracy and generalization ability of the model's tool calls, and increases the success rate of task execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123159451A_ABST
    Figure CN123159451A_ABST
Patent Text Reader

Abstract

This application relates to the field of deep learning technology and discloses a model training method, an electronic device, a readable storage medium, and a program product. In this method, the electronic device can acquire a first result generated by the model to be trained, wherein the first result includes N model response information corresponding to N rounds of responses. Then, for the i-th round response in the N rounds of responses: based on the expected response information of the i-th round response, the model response information of the i-th round response is scored according to the scoring rules corresponding to the response type of the i-th round response, obtaining the round reward score of the i-th round response. Furthermore, different response types correspond to different scoring rules for the model response information. Afterwards, based on the round reward scores of the N rounds of responses, the reward score of the first result is obtained, and based on the reward score of the first result, the parameters of the model to be trained are adjusted. In this way, the multi-round interaction capability of the model can be optimized, improving the model's task execution success rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of deep learning technology, and in particular to a model training method, electronic device, readable storage medium, and program product. Background Technology

[0002] With the rapid development of artificial intelligence and mobile computing technologies, electronic devices are now able to execute various user commands in natural language through built-in agents, such as opening applications, sending messages, and adjusting system settings, thus achieving a leap in intelligent functionality from passive response to proactive service. To achieve accurate and reliable automated task execution, the agent's base model (i.e., the basic large language model) needs to be post-trained to enable it to accurately interpret intent and invoke tools.

[0003] However, existing model training methods struggle to improve the accuracy and generalization ability of base models in tool calls, thus failing to increase the model's task execution success rate. Summary of the Invention

[0004] To address the technical problem of low task execution success rate of models, embodiments of this application provide a model training method, an electronic device, a readable storage medium, and a program product. The following describes this application from multiple aspects, and the implementation methods and beneficial effects of these aspects can be referenced interchangeably.

[0005] In a first aspect, embodiments of this application provide a model training method, the method comprising: obtaining a first result generated by a model to be trained, wherein the first result includes N model response information corresponding to N rounds of responses, where N is an integer greater than 1; for the i-th round of responses in the N rounds of responses: based on the expected response information of the i-th round of responses, scoring the model response information of the i-th round of responses according to the scoring rules corresponding to the response type of the i-th round of responses, to obtain a round reward score for the i-th round of responses, wherein i is a positive integer less than or equal to N, and different response types correspond to different scoring rules for the model response information; obtaining a reward score for the first result based on the round reward scores of the N rounds of responses; and adjusting the parameters of the model to be trained based on the reward score of the first result.

[0006] It is understandable that the reward score of the first result described above can characterize the accuracy and / or quality of the tool invocation in the model's multi-round responses. Furthermore, it is understood that the training sample data typically includes the model's expected response information; the training process described above does not require the model's response information to be completely consistent with the expected response information, and can also improve the model's generalization ability.

[0007] The model training method provided in this application enables refined evaluation of the multi-round response process of the model, categorized by round. Different scoring rules are set for different response types, making the round reward score of each response more consistent with the characteristics of the response type, thereby improving the reliability and accuracy of the round reward score. Furthermore, the reward score obtained based on the round response type of multi-round responses can characterize the quality of the entire interaction trajectory. Using this reward score to update model parameters allows parameter adjustments to take into account both the local optimization of each round response and the global optimization of the entire interaction trajectory, thus optimizing the model's multi-round interaction capabilities and improving the model's task execution success rate.

[0008] In one possible implementation of the first aspect above, the user input information corresponding to each round of response in the N rounds of response in the first sample data is concatenated with the first system prompt information and then sequentially input into the model to be trained to obtain the first result, wherein: the first sample data also includes the expected response information of each round of response in the N rounds of response.

[0009] In one possible implementation of the first aspect described above, the method further includes: concatenating user input information from the first round of sample dialogue in the first sample data with first system prompt information, and inputting the concatenation into a model to be trained to obtain a first intermediate result, wherein the first intermediate result includes at least one round of model response information corresponding to the first round of sample dialogue; calling a first model to generate simulated user input information in the first round of simulated dialogue based on preset system prompt information, user input information from the first round of sample dialogue, and the first intermediate result, wherein the first model has user language simulation capabilities; concatenating the simulated user input information from the first round of simulated dialogue with first system prompt information, and inputting the concatenation into a model to be trained to obtain a second intermediate result, wherein the second intermediate result includes at least one round of model response information corresponding to the first round of simulated dialogue; and obtaining a first result based on at least one round of model response information corresponding to the first round of sample dialogue and at least one round of model response information corresponding to the first round of simulated dialogue, wherein the first sample data further includes expected response information for each round of response in the N rounds of response.

[0010] It is understandable that in practical applications, user input information is quite diverse. If only user input information from sample data is used, the training effect on the model will be limited. In this embodiment of the application, by calling the first model to obtain generalized simulated user input information, dynamic dialogue can be achieved. It can also avoid the problem of dialogue disconnect caused by the dialogue still following the first sample data when the model response information of the model to be trained is incorrect.

[0011] For example, the historical context may include user input information from the first round of sample dialogue, model response information from the first round of response, and model response information from the second round of response. If the first model determines that the tool call failed or the task was not completed based on the historical context, it can output simulated user input information that matches the context, such as "Please try again".

[0012] This also gives the model to be trained the opportunity to correct its behavior in subsequent response rounds, so that the reward score of the first result can reflect the corrective ability of the model to be trained, and the reward score obtained is richer, which is conducive to training the model's multi-turn dialogue ability.

[0013] In one possible implementation of the first aspect above, the preset system prompt information includes: role setting information, task information, input description information, behavioral constraint information, and output format information, wherein: the role setting information is used to define the identity positioning and personality stance of the first model in the interaction; the task information is used to indicate the task execution goal of the first model; the input description information is used to explain the currently available context data structure to the first model; the behavioral constraint information is used to set the behavioral boundaries and operation rules of the first model; and the output format information is used to specify the structured information output by the first model.

[0014] It is understandable that the preset system prompts can be designed according to the training objectives to instruct the behavior of the first model, that is, to instruct the first model to output generalized simulated user input information that conforms to the historical context.

[0015] In one possible implementation of the first aspect above, the user input information in the first round of sample dialogue includes a first task instruction, which includes a first task to be performed and at least one triggering condition for performing the first task; the simulated user input information in the first round of simulated dialogue includes a second task instruction or at least one triggering condition for performing the first task, which includes a second task to be performed and at least one triggering condition for performing the second task.

[0016] In other words, user input in the first round of sample dialogue can instruct the model to perform a trigger-execution task (a complex task). Simulated user input can instruct the model to perform a new trigger-execution task, or, if the triggering condition in the first task instruction in the user input in the first round of sample dialogue is unclear, simulated user input can include the clarified triggering condition.

[0017] In one possible implementation of the first aspect above, the model to be trained is a model obtained by supervising and fine-tuning the second model using the first training dataset. The first training dataset includes second sample data, which includes second system prompt information, user input information corresponding to each round of response in the N rounds of response in the first sample data, and expected response information for each round of response in the N rounds of response. The second system prompt information includes information about the target calling tool and information about the random tool in the N rounds of response.

[0018] The second model mentioned above can be a model with a certain semantic understanding capability, such as a pre-trained large language model. During supervised fine-tuning training, the second model can perform intent recognition based on user task instructions, identifying the task the user wants the model to perform. In this way, the second model can be transferred to specific scenarios; for example, the model can learn to perform corresponding complex tasks (such as triggering execution tasks) and generate responses based on user task instructions.

[0019] In this embodiment of the application, by adding only the information of the target calling tool and the information of the random tool for N rounds of response to the second system prompt information, the length of the context can be reduced and the efficiency of supervised fine-tuning training can be improved.

[0020] In one possible implementation of the first aspect above, the model to be trained is a model obtained by supervising and fine-tuning a second model using a second training dataset. The second training dataset includes N third sample data. The j-th third sample data among the N third sample data includes third system prompt information, expected response information of the first j-th round responses in the first sample data, and user input information corresponding to the first j-th round responses. The third system prompt information includes information on candidate calling tools for the j-th round response. The information on candidate calling tools for the j-th round response is obtained through the calling tool recall interface based on the user input information corresponding to the first j-th round responses.

[0021] For each third sample data point, the Last Round training method can be used to train the model and optimize the model response information in the last response round of the model output.

[0022] It's understandable that calling the tool recall interface can yield semantically similar tools, and the ability to construct interference tools is relatively strong, which can train the model to distinguish similar tools (easily confused tools). The third system prompt word in each third sample data only includes information about the candidate calling tool, which can also reduce the length of the context and improve the efficiency of supervised fine-tuning training.

[0023] In one possible implementation of the first aspect above, the model response information corresponding to the i-th round response is of a non-tool call type: the expected response information includes an expected response type label and expected response sub-information, and the model response information includes a predicted response type label and predicted response sub-information; based on the expected response information of the i-th round response, the model response information of the i-th round response is scored according to the scoring rules corresponding to the response type of the i-th round response to obtain the round reward score of the i-th round response, including: if the model response type label of the i-th round response is inconsistent with the expected response type label, the round reward score of the i-th round response is determined to be a first score; if the predicted response type label of the i-th round response is consistent with the expected response type label, a first sub-reward score corresponding to the predicted response type label is determined, and a second sub-reward score is determined based on the similarity between the predicted response sub-information and the expected response sub-information of the i-th round response; the first sub-reward score and the second sub-reward score are weighted and fused to obtain the round reward score of the i-th round response.

[0024] In one possible implementation of the first aspect above, the model response information corresponding to the i-th round response is of the tool invocation type: the expected response information includes the expected response type label and the expected tool invocation information, the expected tool invocation information includes the expected tool name, exact match expected parameters, and text expected parameters; the model response information includes the predicted response type label and the predicted tool invocation information, the predicted tool invocation information includes the predicted tool name, exact match predicted parameters, and text predicted parameters; based on the expected response information of the i-th round response, the model response information of the i-th round response is scored according to the scoring rules corresponding to the response type of the i-th round response to obtain the round reward score of the i-th round response, which also includes: If the predicted response type label and the expected response type label of the i-th round response are inconsistent, the round reward score of the i-th round response is determined as the first score; if the predicted response type label and the expected response type label of the i-th round response are consistent, a third sub-reward score is determined based on the consistency between the expected tool name and the predicted tool name, and / or a fourth sub-reward score is determined based on the consistency between the exact match class prediction parameters and the exact match class expected parameters, and / or a fifth sub-reward score is determined based on the similarity between the text class prediction parameters and the text class expected parameters; the third sub-reward score and / or the fourth sub-reward score and / or the fifth sub-reward score are weighted and fused to obtain the round reward score of the i-th round response.

[0025] It is understandable that the response type label determines the task execution direction of the corresponding response round. When the predicted response type label is inconsistent with the expected response type label, it means that the model to be trained has performed an incorrect action. At this time, the specific content of the model response information in this response round cannot change the nature of the task error. Therefore, the round reward score of this response round can be directly set to 0 to inhibit the model to be trained from learning the incorrect decision path.

[0026] In this embodiment, by designing corresponding scoring rules for different response types, differentiated scoring can be achieved, making the round reward score of each response more closely aligned with its business importance. For example, for response information that is not a tool call type, it can include natural language content. When scoring, the semantic similarity between the natural language content and the natural language content in the expected response information of the corresponding response round in the sample data can be calculated. They do not need to be completely identical, which can also improve the generalization of the model's response information.

[0027] In one possible implementation of the first aspect above, the reward score of the first result obtained based on the round reward score of N round responses includes: determining the weight of each round response based on the response type and context length of each round response in the N round responses; and performing weighted fusion based on the round reward score and weight of each round response in the N round responses to obtain the reward score of the first result.

[0028] In this way, the reward score of the first result can characterize the accuracy of tool calls and / or the quality of response in the model's multi-round responses.

[0029] In one possible implementation of the first aspect above, the response types include tool call type, follow-up question type, rejection type and summary type; the weight of the summary type response is lower than the weight of the other types of responses, and the weight of the non-summary type response in round x is lower than the weight of the non-summary type response in round x+1.

[0030] It's understandable that summary responses typically consist of a summary text of the entire interaction process. This summary text has relatively low business importance, so its weight can be set lower than other response types. Furthermore, later responses in the interaction process have longer historical contexts and are more difficult for the model to respond to; therefore, their weight can be set higher. This allows the reward score for the first result to better reflect the business focus.

[0031] In one possible implementation of the first aspect described above, the trained target model is used as a base model for an intelligent assistant in an electronic device, which includes at least a voice assistant, a text assistant, and a multimodal assistant.

[0032] It is understandable that, once deployed, the base model can be used to identify intents, invoke tools, and execute tasks based on user input information or instructions, providing intelligent agents with underlying decision-making and generation capabilities.

[0033] Secondly, embodiments of this application provide a model training method, which includes: obtaining a first result generated by a model to be trained; adjusting the parameters of the model to be trained based on the first result; wherein the first result includes N model response information corresponding to N rounds of responses, where N is an integer greater than 1; the model response information of the k-th round of responses in the N rounds of responses is obtained by: calling a first model, generating simulated user input information corresponding to the k-th round of responses based on preset system prompt information, user input information corresponding to the first k-1 rounds of responses in the first sample data, and model response information of the first k-1 rounds of responses, wherein the first model has user language simulation function, and k is an integer greater than 1 and less than or equal to N; concatenating the simulated user input information corresponding to the k-th round of responses with the first system prompt information, and inputting it into the model to be trained to obtain the model response information of the k-th round of responses.

[0034] In this embodiment of the application, by calling the first model to obtain generalized simulated user input information, dynamic dialogue can be realized. It can also avoid the problem of dialogue disconnect caused by the dialogue still following the first sample data when the model response information of the model to be trained is incorrect.

[0035] In one possible implementation of the second aspect above, the above-mentioned invocation of the first model, based on the preset system prompt information, the user input information corresponding to the first k-1 rounds of responses in the first sample data, and the model response information of the first k-1 rounds of responses, generates simulated user input information corresponding to the k-th round of responses, including: invoking the first model, determining that the task corresponding to the k-1 round has not been completed based on the preset system prompt information, the user input information corresponding to the first k-1 rounds of responses in the first sample data, and the model response information of the first k-1 rounds of responses; and generating simulated user input information corresponding to the k-th round of responses through the first model.

[0036] It is understandable that when the first model generates simulated user input, the preset system prompts can instruct the first model's behavior. For example, they can instruct the first model to combine historical context to generate simulated user input for the next round of dialogue, thus ensuring that the simulated user input is not disconnected from previous dialogues. Furthermore, the preset system prompts can also instruct the first model to determine, based on historical context, whether the task corresponding to the (k-1)th round response was successfully executed.

[0037] In one possible implementation of the second aspect above, the preset system prompt information includes: role setting information, task information, input description information, behavioral constraint information, and output format information, wherein: the role setting information is used to define the identity positioning and personality stance of the first model in the interaction; the task information is used to indicate the task execution goal of the first model; the input description information is used to explain the currently available context data structure to the first model; the behavioral constraint information is used to set the behavioral boundaries and operating rules of the first model; and the output format information is used to specify the structured information output by the first model.

[0038] In one possible implementation of the second aspect above, the model to be trained is a model obtained by supervising and fine-tuning the second model using the first training dataset. The first training dataset includes second sample data, which includes second system prompt information, user input information corresponding to each round of response in the N rounds of response in the first sample data, and expected response information for each round of response in the N rounds of response. The second system prompt information includes information about the target calling tool and information about the random tool in the N rounds of response.

[0039] In one possible implementation of the second aspect above, the model to be trained is a model obtained by supervising and fine-tuning the second model using the second training dataset, and the second training dataset includes N third sample data; the i-th third sample data among the N third sample data includes third system prompt information, expected response information of the first i rounds of response in the first sample data, and user input information corresponding to the first i rounds of response, wherein: the third system prompt information includes information on candidate calling tools for the i-th round of response, and the information on candidate calling tools for the i-th round of response is obtained through the calling tool recall interface based on the user input information corresponding to the first i rounds of response, where i is a positive integer less than or equal to N.

[0040] Thirdly, embodiments of this application provide a model training method, which includes: acquiring multiple dialogue samples containing multi-turn interactions, each dialogue sample including multiple expected response information of multi-turn responses and user input information corresponding to each round of response; splitting each dialogue sample into multiple sub-samples corresponding to the multi-turn responses, wherein the sub-sample obtained by splitting each dialogue sample and corresponding to the m-th round of response in the multi-turn responses includes: expected response information of the first m rounds of response in the multi-turn responses and user input information corresponding to the first m rounds of response, where m is a positive integer; obtaining multiple training sample data corresponding to each dialogue sample based on the multiple sub-samples corresponding to each dialogue sample and the third system prompt information corresponding to each sub-sample, wherein the third system prompt information includes information on candidate calling tools for the corresponding sub-sample, and the information on candidate calling tools is obtained through a calling tool recall interface based on the user input information in the corresponding sub-sample; constructing a second training dataset based on the training sample data corresponding to the multiple dialogue samples; and using the second training dataset to perform supervised fine-tuning of the second model to obtain the model to be trained.

[0041] Thus, by adding candidate tool information for corresponding subsamples only to the third system prompts, the length of the context can be reduced, improving the efficiency of supervised fine-tuning training. In this embodiment, when designing sample data, if the sample data needs to call easily confused tools or if the candidate tool information in the third system prompts needs to be dynamically refreshed during training, this method can be used to construct the training dataset.

[0042] Fourthly, embodiments of this application provide an electronic device, including: at least one processor; the at least one memory; the at least one memory storing at least one program, which, when executed by the at least one processor, causes the electronic device to perform the first aspect and any possible implementation of the model training method mentioned in the first aspect, or causes the electronic device to perform the second aspect and any possible implementation of the model training method mentioned in the second aspect, or causes the electronic device to perform the model training method mentioned in the third aspect.

[0043] Fifthly, embodiments of this application provide a computer-readable storage medium storing instructions that, when executed on an electronic device, cause the electronic device to perform the first aspect and any possible implementation of the model training method mentioned above, or cause the electronic device to perform the second aspect and any possible implementation of the model training method mentioned above, or cause the electronic device to perform the model training method mentioned in the third aspect.

[0044] In a sixth aspect, embodiments of this application provide a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by an electronic device, they enable the implementation of the model training method mentioned in the first aspect and any possible implementation of the first aspect, or enable the implementation of the model training method mentioned in the second aspect and any possible implementation of the second aspect, or enable the implementation of the model training method mentioned in the third aspect. Attached Figure Description

[0045] Figure 1 According to some embodiments of this application, a schematic diagram of an application scenario of an intelligent agent is shown;

[0046] Figure 2 According to some embodiments of this application, a schematic diagram of the interface of a smart assistant is shown;

[0047] Figure 3 A schematic diagram of a model training method is shown according to some embodiments of this application;

[0048] Figure 4 According to some embodiments of this application, a schematic diagram of the process for determining the reward score of a first result generated by a model to be trained is shown.

[0049] Figure 5 According to some embodiments of this application, a schematic diagram of another model training method is shown;

[0050] Figure 6 According to some embodiments of this application, a schematic diagram of the design logic for a preset system prompt message is shown;

[0051] Figure 7 According to some embodiments of this application, a schematic diagram of a model training system is shown;

[0052] Figure 8 According to some embodiments of this application, an architecture diagram of a reinforcement learning trajectory sampling engine is shown;

[0053] Figure 9 According to some embodiments of this application, a schematic diagram of an interactive trajectory sampling process is shown;

[0054] Figure 10 According to some embodiments of this application, a schematic diagram of yet another model training method is shown;

[0055] Figure 11 According to some embodiments of this application, a schematic diagram of the structure of an electronic device is shown. Detailed Implementation

[0056] The illustrative embodiments of this application include, but are not limited to, a model training method, an electronic device, a readable storage medium, and a program product. The model training method of this application is described below with reference to specific embodiments.

[0057] Let's combine the following... Figure 1 This paper introduces an application scenario for intelligent agents. The example used is a mobile phone as the electronic device and an intelligent assistant on the phone.

[0058] refer to Figure 1 In some embodiments, the first interface 11 of the smart assistant of mobile phone 10 may include interactive elements such as an input box 111, a keyboard switching button 112, and a new conversation button 113. Users can long-press the input box 111 to input commands.

[0059] If the user enters the first command 114, such as "Help me turn on Do Not Disturb mode," the smart assistant can semantically understand the first command 114, determine that the user wants to turn on Do Not Disturb mode on the phone 10, and accomplish this task by calling the tool that executes Do Not Disturb mode. After the task is successfully executed, the smart assistant can generate a reply 115, such as "Okay, you can also tell me 'Set Do Not Disturb from 9 am to 12 pm on Mondays.'"

[0060] If the user inputs the second command 116, such as "Turn on Do Not Disturb mode for me every day at 1 PM," the smart assistant performs semantic understanding of the command 116 and determines that the user wants the phone to automatically turn on Do Not Disturb mode at 1 PM every day. However, it will be difficult to successfully invoke the correct tool, thus failing to execute the task. Afterward, the smart assistant can generate a reply 117, such as "This is beyond our current capabilities; try rephrasing it."

[0061] It can be seen that the smartphone's intelligent assistant can only successfully execute some of the tasks instructed by the user, resulting in a relatively low task execution success rate. This is understandable, as existing model training methods only train for general application scenarios, resulting in models with only basic tool invocation capabilities. This makes it difficult to improve the accuracy and generalization ability of tool invocation, thus hindering the improvement of task execution success rates. For example, it can only successfully complete simple execution tasks with relatively simple tool invocation logic, while struggling with more complex tasks involving nested tool invocations or trigger-based execution tasks.

[0062] To address this technical problem, this application provides a model training method. In this method, an electronic device acquires a first result generated by the model to be trained. This first result includes N model response information corresponding to N rounds of responses, where N is an integer greater than 1. Then, for the i-th round response among these N rounds: based on the expected response information of the i-th round response, the model response information of the i-th round response is scored according to the scoring rules corresponding to the response type of the i-th round response, resulting in a round reward score for the i-th round response. Here, i is a positive integer less than or equal to N, and the scoring rules for the corresponding model response information differ depending on the response type. Afterwards, based on the round reward scores of these N rounds of responses, a reward score for the first result is obtained. Based on the reward score of the first result, the parameters of the model to be trained are adjusted.

[0063] It can be understood that the above N rounds of response can correspond to one training sample data, that is, it can belong to one interaction trajectory of the model. Here, the interaction trajectory refers to the complete state-action series in the entire process from user input to the end of the interaction in a single interaction between the user and the model. Furthermore, the more complex the task indicated by the user input, the more rounds of response the model may have, and the longer the interaction trajectory may be.

[0064] For example, response types can include tool-calling types and non-tool-calling types. The round reward score of the model response information for tool-calling types can characterize the model's tool-calling accuracy, while the model response information for non-tool-calling types can characterize the model's response quality. Thus, the reward score of the first result described above can characterize the tool-calling accuracy and / or response quality of the model's multi-round responses. Furthermore, it can be understood that the training sample data typically includes the model's expected response information; the training process described above does not require the model's response information to be completely consistent with the expected response information, and can also improve the model's generalization ability.

[0065] The model training method provided in this application enables refined evaluation of the multi-round response process of the model, categorized by round. Different scoring rules are set for different response types, making the round reward score of each response more consistent with the characteristics of the response type, thereby improving the reliability and accuracy of the round reward score. Furthermore, the reward score obtained based on the round response type of multi-round responses can characterize the quality of the entire interaction trajectory. Using this reward score to update model parameters allows parameter adjustments to consider both the local optimization of each round response and the global optimization of the entire interaction trajectory, thus optimizing the model's multi-round interaction capabilities and improving the model's task execution success rate.

[0066] The model obtained by the model training method in the embodiments of this application can be used as a base model for intelligent agents (such as intelligent assistants of mobile phones). After deployment, the base model can be used to perform intent recognition, tool invocation and task execution based on user input information or instructions, providing the intelligent agent with underlying decision-making and generation capabilities.

[0067] For example, refer to Figure 2 In some embodiments, after the model obtained by the model training method of this application is deployed on the mobile phone 10, the second interface 21 of the smart assistant of the mobile phone 10 may include prompt information in addition to interactive elements such as input box 111, keyboard switch button 112 and new chat button 113, to prompt the user on the automated tasks that the smart assistant can perform.

[0068] Specifically, the second interface 21 may include a first prompt message 211, a second prompt message 212, and a third prompt message 213. The first prompt message 211 may include the text "Automatically turn on silent mode and automatically turn on Do Not Disturb for meetings at 10:00 every day". The second prompt message 212 may include the text "Automatically turn on power saving mode and adjust screen brightness to 20 when the phone battery is below 20%". The third prompt message 213 may include the text "Automatically play music when Bluetooth is connected to headphones".

[0069] Furthermore, the aforementioned prompts can also serve as quick input information for the user. For example, when the mobile phone 10 detects a user's click on the first prompt 211, it can use the first prompt 211 as user input information, and the smart assistant can execute the task indicated by the first prompt 211.

[0070] The interaction trajectory mentioned earlier will be introduced below.

[0071] In some embodiments, the interaction trajectory may include at least one round of dialogue and at least one tool invocation result. A round of dialogue may include model response information from multiple rounds of responses.

[0072] As can be understood, a single turn of dialogue refers to one conversation between the user and the model, including a user input (such as a user task instruction) and at least one round of model response information. For example, the model response information may include information about the model's thought process or the model's reply text. A single turn of dialogue may, for example, include one user input and two model response messages.

[0073] It is also understandable that the clarity of the user's input or the complexity of the task being instructed can determine the length of the interaction trajectory.

[0074] Specifically, when the user input is clear and explicit or indicates a simple task, the model can directly identify the user's intent, determine the task to be performed and the tool to be invoked, and then execute the tool invocation to complete the corresponding task.

[0075] It's understandable that simple tasks can be execution-based tasks, which the model can complete by calling execution-based tools. Execution-based tools could include things like turning Bluetooth on / off, opening / closing apps, toggling ringtone modes, setting alarms, and enabling location services. Complex tasks, on the other hand, can be trigger-based execution tasks, involving more complex nested tool calls. The model can complete these tasks by calling both trigger-based and execution-based tools. Trigger-based tools could be fence tools used to monitor changes in the phone's status, such as time fences, geofences, app opening / closing fences, battery level fences, and lock screen status fences.

[0076] For example, in the above scenario, the interaction trajectory may include a round of dialogue and a tool call result, whereby the round of dialogue may include user input information and model response information from two rounds of responses.

[0077] Taking the first interaction trajectory (denoted as trajectory1) as an example, the user input information in the first round of dialogue (denoted as user11) could be "Please turn on Do Not Disturb mode for me at 1 PM every day." The model response information in the first round of response (denoted as assistant11) can include the model's thought process information, which can include thought text information and tool call instructions. The thought text information could be, for example, "The user wants to create an automated task to turn on Do Not Disturb mode at 1 PM every day. The trigger condition is: 1 PM every day, and the action is: Turn on Do Not Disturb mode." The tool call instruction can instruct the invocation of the time-fence tool and the execution class tool for turning on Do Not Disturb mode. The tool call result (denoted as tool1) can indicate that the tool call was successful. The model response information in the second round of response (denoted as assistant11p) can include the model's reply text generated based on the tool call result and context information, which could be "Task created successfully, automatically turning on Do Not Disturb mode at 1 PM every day."

[0078] When user input is ambiguous or indicates a complex task, the model can determine the need for the user to provide additional information or confirm the information by recognizing the user's intent. After receiving the user's response, the model can then execute the tool call to complete the corresponding task, or conclude that the corresponding task cannot be executed.

[0079] For example, in this case, the interaction trajectory may include multiple rounds of dialogue and at least one tool call result, with each round of dialogue including model response information of at least one round of response.

[0080] Taking the second interactive trajectory (denoted as trajectory2) as an example, the user input information in the first round of dialogue (denoted as user21) could be "Help me turn on eye protection mode and turn off airplane mode when I enter Xuanwu Lake Park." The model response information in the first round of response (denoted as assistant21) could include the model's thought process information, which could include thought text information and tool call instructions. The thought text information could be, for example, "The user wants to create an automated task to turn on eye protection mode and turn off airplane mode when entering Xuanwu Lake Park. The latitude and longitude of Xuanwu Lake Park needs to be obtained first." The tool call instruction could instruct the invocation of an address fence tool, for example, this address fence tool can be used to obtain the latitude and longitude of Xuanwu Lake Park. The tool call result in the first round of dialogue (denoted as tool21) could indicate that the tool call was successful and include three relevant locations. The model response information in the second round of response (denoted as assistant21p) could include the model's reply text generated based on the tool call result and context information, which could be, "Three locations related to Xuanwu Lake Park have been found for the user. Which one should you choose?"

[0081] Next, in the second round of dialogue, the user input (denoted as user22) could be "Select the Xuanwu Lake Park in Xuanwu District." The model's response in the third round (denoted as assistant22) could include the model's thought process information, which could include thought text information and tool invocation instructions. The thought text information could be, for example, "The user wants to create an automated task to turn on eye protection mode and turn off airplane mode when entering Xuanwu Lake Park in Xuanwu District." The tool invocation instructions could specify the execution tools for turning on eye protection mode and turning off airplane mode. The tool invocation result in the second round (denoted as tool22) could indicate that the tool invocation was successful. The model's response in the fourth round (denoted as assistant22p) could include the model's reply text generated based on the tool invocation result and context information, which could be, "Task created successfully. When you enter Xuanwu Lake Park in Xuanwu District, automatically turn on eye protection mode and turn off airplane mode."

[0082] For example, in this scenario, the interaction trajectory could also include a round of dialogue, which could include model response information for a round of responses. Taking the third interaction trajectory (denoted as trajectory3) as an example, the user input information (denoted as user3) in the first round of dialogue could be "Turn on Bluetooth for me while I'm exercising." The expected response information in the first round of interaction (denoted as assistant3) could include the model's thought process information and reply text information. The thought process information could be, for example, "The user wants to create an automated task to automatically turn on Bluetooth when they exercise. However, the description of 'exercise' as a trigger condition is too vague, and the system cannot recognize and translate it into a specific trigger mechanism, therefore the task cannot be created." The reply text information could be, for example, "Sorry, the system currently cannot use 'exercise' as a trigger condition; the automated task triggering failed."

[0083] It is understood that the interaction trajectories listed above are merely examples and do not constitute a limitation of this application. In actual interaction processes, there are more complex interaction trajectories, which are not listed here. For example, the third interaction trajectory mentioned above may also include a second round of dialogue, such as the user inputting more semantically clear information to instruct the model to turn on Bluetooth for the user while exercising.

[0084] The model training method provided in this application allows for the design of sample data using possible interaction trajectories and the construction of a target training dataset, which is then used for model training. The possible interaction trajectories can be obtained based on collected historical interaction data. Furthermore, in each sample data point of the target training dataset (e.g., the first sample data), the tool invocation result indicates a successful tool invocation, thereby improving the quality of the target training dataset.

[0085] The following is combined with Figure 3 This application introduces a model training method provided by an embodiment. The method can be executed by an electronic device, such as a desktop computer, laptop computer, or server.

[0086] refer to Figure 3 The method includes:

[0087] S101, Obtain the first result generated by the model to be trained, wherein the first result includes N model response information corresponding to N rounds of response, where N is an integer greater than 1.

[0088] In some embodiments, the electronic device can acquire a first result generated by the model to be trained, wherein the first result may include N model response information corresponding to N rounds of response, where N is an integer greater than 1.

[0089] It can be understood that N model response information can be the information output by the model to be trained after responding to at least one user input information N times. The at least one user input information can come from a sample data or correspond to a sample data.

[0090] In some embodiments, the electronic device can concatenate the user input information corresponding to each round of responses in the N rounds of responses in the first sample data with the first system prompt information, and then input the concatenation into the model to be trained to obtain a first result. The first sample data also includes the expected response information for each round of responses in the N rounds. The first system prompt information can also be referred to as a first system prompt word.

[0091] It is understood that the first sample data may also include first system prompt information, which can be used to define the task role of the model to be trained, the information of candidate calling tools, and output format constraints. Furthermore, the information of candidate calling tools in the first system prompt information is dynamically updated during the interaction.

[0092] The first system prompt message mentioned above could be something like: "You are the task agent, responsible for interpreting user needs and calling appropriate tools to complete the task. You can create automated tasks driven by trigger conditions, query device status, and initiate skill services. The following are the tools that can be selected from your tools list."

[0093] Trigger-type tools: Named Time Trigger Tool, described as XXXXX, parameters include trigger start condition (XXXX), trigger end condition (XXXX), trigger type (XXXX). If the start or end condition is missing, the user needs to be prompted.

[0094] Execution tools (Actions): Named "Device Control Tool," described as XXXXX, with parameters including operation type (XXXX) and query target (XXXX).

[0095] After receiving user input, the electronic device can, based on the user input and the Triggers and Actions in the first system prompt, recall relevant candidate tools through a tool recall interface and update the first system prompt with the information of these candidate tools. The recalled candidate tools may, for example, include 10 trigger-type tools and 10 execution-type tools. Furthermore, the recalled trigger-type tools and execution-type tools exhibit high semantic similarity.

[0096] It should be noted that the above-mentioned first system prompt information is only an example and does not constitute a limitation on the first system prompt information. In practical applications, the first system prompt information can be designed according to actual needs, and this application does not impose specific limitations.

[0097] For example, the first sample data may include the first system prompt information and the aforementioned trajectory1, specifically including two rounds of responses. In trajectory1, assistant11 is the expected response information of the first round, and assistant11p is the expected response information of the second round. The electronic device can concatenate user11 with the first system prompt information and input it into the model to be trained to obtain the first result, which includes the model response information of the first round and the model response information of the second round.

[0098] In other embodiments, the electronic device can concatenate the user input information from the first round of sample dialogue in the first sample data with the first system prompt information, and then input the concatenation into the model to be trained to obtain a first intermediate result. The first intermediate result may include at least one round of model response information corresponding to the first sample dialogue.

[0099] Then, the electronic device can invoke the first model to generate simulated user input information for the first round of simulated dialogue, based on preset system prompts, user input information from the first round of sample dialogue, and the first intermediate result. The first model can be, for example, a large language model (LLM), a Deepseek series model, etc.

[0100] Then, the electronic device can concatenate the simulated user input information from the first round of simulated dialogue with the first system prompt information and input it into the model to be trained to obtain a second intermediate result, wherein the second intermediate result includes at least one round of model response information corresponding to the first round of simulated dialogue.

[0101] Subsequently, the electronic device can obtain a first result based on at least one round of model response information corresponding to the first round of sample dialogue and at least one round of model response information corresponding to the first round of simulated dialogue. The first sample data also includes the expected response information of each round of response in the N rounds of response.

[0102] For example, the first sample data may include the first system prompt information and the trajectory2 mentioned above, specifically including two rounds of sample dialogue. In trajectory2, user21 is the user input information of the first round of sample dialogue, user22 is the user input information of the second round of sample dialogue, assistant21 is the expected response information of the first round response corresponding to the first round of sample dialogue, assistant21p is the expected response information of the second round response corresponding to the first round of sample dialogue, assistant22 is the expected response information of the third round response corresponding to the second round of sample dialogue, and assistant22p is the expected response information of the fourth round response corresponding to the second round of sample dialogue.

[0103] The electronic device can concatenate user21 with the first system prompt and input it into the model to be trained to obtain a first intermediate result, which includes the model response information for the first and second rounds of responses. Then, the electronic device can call the first model to generate simulated user input information for the first round of simulated dialogue. The first round of simulated dialogue can correspond to the second round of sample dialogue. The electronic device concatenates the simulated user input information with the first system prompt and inputs it into the model to be trained to obtain a second intermediate result, which can include the model response information for the third and fourth rounds of responses. Thus, the first result includes model response information for all four rounds of responses.

[0104] It is understandable that in practical applications, user input information is quite diverse. If only user input information from sample data is used, the training effect on the model will be limited. In this embodiment of the application, by calling the first model to obtain generalized simulated user input information, dynamic dialogue can be achieved. It can also avoid the problem of dialogue disconnect caused by the dialogue still following the first sample data when the model response information of the model to be trained is incorrect.

[0105] For example, if the first model determines that the tool call failed or the task was not completed based on the historical context (i.e., the user input information of the first round of sample dialogue, the model response information of the first round of response and the model response information of the second round of response), it can output simulated user input information that matches the context, such as "Please try again".

[0106] This also gives the model to be trained the opportunity to correct its behavior in subsequent response rounds, so that the reward score of the first result can reflect the corrective ability of the model to be trained, and the reward score obtained is richer, which is conducive to training the model's multi-turn dialogue ability.

[0107] In some embodiments, user input information in the first round of sample dialogue may include a first task instruction, which may include a first task to be performed and at least one triggering condition for performing the first task. Simulated user input information in the first round of simulated dialogue may include a second task instruction or at least one triggering condition for performing the first task, whereby the second task instruction may include a second task to be performed and at least one triggering condition for performing the second task.

[0108] In other words, user input in the first round of sample dialogue can instruct the model to perform a trigger-execution task. Simulated user input can instruct the model to perform a new trigger-execution task, or, if the trigger condition in the first task instruction in the user input in the first round of sample dialogue is unclear, simulated user input can include the clarified trigger condition.

[0109] For example, user input in the first round of sample dialogue might instruct the model to "turn on Bluetooth for me while I'm working out," but the trigger condition "while working out" is rather vague, preventing the system from successfully executing the task. Simulated user input could include a clarified trigger condition like "when I arrive at XXX gym."

[0110] It is understandable that the aforementioned preset system prompts can be designed according to the training objectives to instruct the behavior of the first model, that is, to instruct the first model to output generalized, historically context-compliant simulated user input information. Details will be provided later and will not be elaborated upon here.

[0111] S102, For the i-th round response in N rounds of responses: Based on the expected response information of the i-th round response, score the model response information of the i-th round response according to the scoring rules corresponding to the response type of the i-th round response to obtain the round reward score of the i-th round response, where i is a positive integer less than or equal to N, and the scoring rules for the corresponding model response information are different for different response types.

[0112] In some embodiments, after the electronic device obtains the first result, for the i-th round response in N rounds of responses: the electronic device can score the model response information of the i-th round response based on the expected response information of the i-th round response and according to the scoring rules corresponding to the response type of the i-th round response, to obtain the round reward score of the i-th round response, where i is a positive integer less than or equal to N, and the scoring rules for the corresponding model response information are different for different response types.

[0113] It is understandable that during the reinforcement learning training phase, the reward function of the model's output response information can affect the model's training performance. If the reward function is poorly designed, the reward score may fail to accurately represent the quality of the response information of the model being trained, resulting in reward hacking.

[0114] For example, electronic devices can score the first result using a reward model. If the reward function is poorly designed, the model may assume that longer response times in a single response round equate to higher quality. However, longer response times do not necessarily equate to the highest quality. This can negatively impact the model's optimization performance.

[0115] In this embodiment, by designing corresponding scoring rules for different response types, differentiated scoring can be achieved, making the round reward score of each response more closely aligned with its business importance. For example, for response information that is not a tool call type, it can include natural language content. When scoring, the semantic similarity between the natural language content and the natural language content in the expected response information of the corresponding response round in the sample data can be calculated. They do not need to be completely identical, which can also improve the generalization of the model's response information.

[0116] In some embodiments, when the model response information corresponding to the i-th round response is of a non-tool call type: the expected response information may include an expected response type label and expected response sub-information, and the model response information may include a predicted response type label and predicted response sub-information.

[0117] For example, the expected response information for the i-th round of response could include "reasoning_content": "All tasks have been completed." <summary> Summarize all execution results for the user< / summary> The reply content reads: "Task created successfully. Do Not Disturb mode will automatically activate at 1 PM every day." The expected response type tag is "Summary". <summary>< / summary> The expected response sub-information may include the tag content "summarize all execution results for the user" and the reply content "task created successfully, do not disturb mode will be automatically activated at 1 pm every day."

[0118] The model response information for the i-th round of response may include "reasoning_content": "All tasks have been completed". <summary> Summarize all execution results for the user< / summary> The content states: "A scheduled task has been successfully created for you to activate Do Not Disturb mode at 1 PM every day." The predicted response type tag is a summary type tag. <summary>< / summary> The predicted response sub-information may include the tag content "summarize all execution results for the user" and the reply content "a scheduled task has been successfully created for you, which will be activated in Do Not Disturb mode at 1 p.m. every day."

[0119] In this embodiment, the electronic device can determine the round reward score of the i-th round response as a first score if the predicted response type label and the expected response type label of the i-th round response are inconsistent. For example, the first score can be 0.

[0120] It is understandable that the response type label determines the task execution direction of the corresponding response round. When the predicted response type label is inconsistent with the expected response type label, it means that the model to be trained has performed an incorrect action. At this time, the specific content of the model response information in this response round cannot change the nature of the task error. Therefore, the round reward score of this response round can be directly set to 0 to inhibit the model to be trained from learning the incorrect decision path.

[0121] If the predicted response type label of the i-th round response matches the expected response type label, the electronic device can determine the first sub-reward score corresponding to the predicted response type label. Furthermore, based on the similarity between the predicted response sub-information and the expected response sub-information of the i-th round response, the electronic device can determine the second sub-reward score. Then, the electronic device can weightedly fuse the first and second sub-reward scores to obtain the round reward score for the i-th round response.

[0122] Based on the above example, the electronic device can determine the first sub-reward score as the second score when both the predicted response type label and the expected response type label in the i-th round of response are summary type labels. For example, the second score could be 1, representing a full score. The similarity between the predicted response sub-information and the expected response sub-information can include the first semantic similarity between the label content in the expected response sub-information and the label content in the model response sub-information, and the second semantic similarity between the response content in the expected response sub-information and the response content in the model response sub-information. For example, a first similarity score can be determined based on the first semantic similarity, and a second similarity score can be determined based on the second semantic similarity. Then, the first similarity score and the second similarity score are weighted and fused to obtain the second sub-reward score, for example, the second sub-reward score could be 0.8. The weights of the first similarity score and the second similarity score can be equal.

[0123] The electronic device can then weight and fuse the first sub-reward score and the second sub-reward score to obtain the round reward score for the i-th round response. The weight of the first sub-reward score can be equal to the weight of the second sub-reward score, or the weight of the first sub-reward score can be higher than the weight of the second sub-reward score.

[0124] Thus, the round reward score can represent both the direction of task execution and the quality of the model's response information.

[0125] In some embodiments, when the model response information corresponding to the i-th round response is of the tool invocation type: the expected response information may include an expected response type label and expected tool invocation information, which may include the expected tool name, exact match expected parameters, and text expected parameters. The model response information may also include a predicted response type label and predicted tool invocation information, which may include the predicted tool name, exact match predicted parameters, and text predicted parameters.

[0126] For example, in the expected response information of the i-th round of response, the expected response type label can be the tool call label "tool_calls", and the expected tool call information can be the tool call instruction. For example, the tool call instruction can include the expected tool name: "Query Alarm Clock", the exact match type expected parameter: "Query type is XXXX", and the text type parameter: "Query value is XXXXX".

[0127] It is understandable that the parameter values ​​in the expected parameters of the exact matching class can be fixed enumerations, exact values, etc., and the corresponding predicted parameters need to be completely consistent with the expected parameters. The parameter values ​​in the expected parameters of the text class are natural language descriptions (such as user query statements), and only the language similarity between the corresponding predicted parameters and the expected parameters needs to be greater than the similarity threshold.

[0128] In this embodiment, the electronic device can determine the round reward score for the i-th round response as a first score if the predicted response type label and the expected response type label are inconsistent. For example, the first score can be 0. That is, if the response round requires the model to execute a tool call, but the model does not actually execute the tool call, resulting in a task execution error, the round reward score for that response round can be directly set to 0 to suppress the learning of erroneous decision paths by the model to be trained.

[0129] The electronic device can determine a third sub-reward score based on the consistency between the predicted response type label and the expected response type label in the i-th round response, and / or, based on the consistency between the expected tool name and the predicted tool name, determine a fourth sub-reward score based on the consistency between the exact match class prediction parameters and the exact match class expected parameters, and / or, based on the similarity between the text class prediction parameters and the text class expected parameters. Then, the electronic device can perform a weighted fusion of the third sub-reward score and / or the fourth sub-reward score and / or the fifth sub-reward score to obtain the round reward score for the i-th round response.

[0130] Based on the above example, the electronic device can compare whether the expected tool name and the predicted tool name are completely consistent. If the predicted tool name is "Query Alarm Clock", then the third sub-reward score can be determined to be the second score. For example, the second score can be 1, which means full marks.

[0131] Electronic devices can also compare whether the predicted parameters of the exact matching class are completely consistent with the expected parameters of the exact matching class. If the predicted parameters of the exact matching class are "query type is XXXX", the fourth sub-reward score can be determined to be the second score. For example, the second score can be 1, which means full score.

[0132] Electronic devices can also calculate the similarity between text-based predicted parameters and text-based expected parameters. Specifically, they can calculate the similarity between the text-based predicted parameters and "the query value is XXXXX", and calculate the corresponding fifth sub-reward score based on the similarity. For example, if the similarity is high, the fifth sub-reward score can be 0.9, indicating a high score; if the similarity is low, the fifth sub-reward score can be 0.3, indicating a low score.

[0133] Then, the electronic device can weight and fuse the third, fourth, and fifth sub-reward scores to obtain the round reward score for the i-th round response. The weight of the third sub-reward score is, for example, 30%, the weight of the fourth sub-reward score is, for example, 35%, and the weight of the fifth sub-reward score is, for example, 35%.

[0134] As can be understood, in the example above, this round of response invoked one tool. For cases where multiple tools are invoked in a single round of response, the reward score for each tool can be calculated separately according to the process in the example above, and then the average reward score for each tool can be taken to obtain the round reward score.

[0135] It should be noted that when calculating the reward score for a tool, the weights of the sub-reward scores corresponding to each type of parameter of the tool can be pre-designed based on the number and types of parameters in the tool, and this application does not impose specific limitations on this. For example, for the tool "Search Contacts", the weight of the sub-reward score corresponding to the text-based prediction parameter "Contact Person" can be 40%, the weight of the sub-reward score corresponding to the text-based prediction parameter "Contact Person Name" can be 30%, and the weight of the sub-reward score corresponding to the text-based prediction parameter "Contact Person Pinyin" can be 30%.

[0136] S103, based on the round reward scores of N rounds of response, obtain the reward score of the first result.

[0137] In some embodiments, the electronic device may obtain a reward score for the first result based on the round reward score of the N rounds of responses.

[0138] For example, electronic devices can perform weighted fusion based on the round reward scores of N rounds of responses to obtain the reward score of the first result.

[0139] In some embodiments, the electronic device can determine the weight of each round of response based on the response type and context length of each round of response in N rounds of response. Then, the electronic device can perform weighted fusion based on the round reward score and weight of each round of response in N rounds of response to obtain the reward score of the first result.

[0140] For example, if N is 4, the response type of the first round is tool invocation, the response type of the second round is follow-up questioning, the response type of the third round is tool invocation, and the response type of the fourth round is summary, then the electronic device can determine the first weight of the first round response as 20%, the second weight of the second round response as 30%, the third weight of the third round response as 40%, and the weight of the fourth round response as 10%. Then, the electronic device can obtain the reward score of the first result through weighted fusion.

[0141] In some embodiments, the response types described above may include tool invocation type, follow-up question type, rejection type, and summary type. The weight of a summary type response is lower than the weight of other response types, and the weight of a non-summary type response in round x is lower than the weight of a non-summary type response in round x+1.

[0142] It's understandable that summary responses typically consist of a summary text of the entire interaction process. This summary text has relatively low business importance, so its weight can be set lower than other response types. Furthermore, later responses in the interaction process have longer historical contexts and are more difficult for the model to respond to; therefore, their weight can be set higher. This allows the reward score for the first result to better reflect the business focus.

[0143] S104, based on the reward score of the first result, adjust the parameters of the model to be trained.

[0144] In some embodiments, after the electronic device obtains the reward score of the first result, it can adjust the parameters of the model to be trained based on the reward score of the first result.

[0145] It is understood that the above process belongs to reinforcement learning training of the model to be trained. In the embodiments of this application, the parameters of the model to be trained are adjusted by the reward score of the first result, so that the gradient update signal of reinforcement learning can be accurately focused on key decision rounds such as tool invocation, effectively suppressing noise interference from non-key rounds (such as summary response rounds), thereby improving the accuracy and generalization of the model in complex tasks (such as nested tool invocation tasks).

[0146] It can also be understood that when the preset training termination conditions are met, the electronic device can stop training and obtain the trained target model. In some embodiments, the trained target model can be used as the base model of an intelligent assistant in the electronic device, which may include at least a voice assistant, a text assistant, or a multimodal assistant.

[0147] The preset training termination conditions may include, for example, the model's tool call accuracy reaching a preset threshold (e.g., 95%), the reward score converging, or the number of training steps reaching a preset upper limit. These preset training termination conditions can be set according to actual needs, and this application does not impose specific limitations on them.

[0148] In some embodiments, the model to be trained is a model obtained by supervising and fine-tuning the second model using a first training dataset. The first training dataset may include second sample data, which may include second system prompts, user input information corresponding to each round of response in the N rounds of response in the first sample data, and expected response information for each round of response in the N rounds of response. The second system prompts may include information about the target calling tool and information about the random tool in the N rounds of response.

[0149] It is understandable that the first training dataset can be designed and constructed using the interaction trajectories mentioned above. Furthermore, each sample in the first training dataset includes tool call results, and these results all indicate that the tool call was successful, thereby improving the quality of the first training dataset.

[0150] As mentioned earlier, the candidate tool invocation information in the system prompts is dynamically refreshed through tool recall during the interaction. For complex tasks, if tool recall is not introduced during the supervised fine-tuning training phase, all tool information needs to be added to the second system prompt, resulting in a longer context and affecting the supervised fine-tuning training effect.

[0151] The second model mentioned above can be a model with a certain semantic understanding capability, such as a pre-trained large language model. During supervised fine-tuning training, the second model can perform intent recognition based on user task instructions, identifying the task the user wants the model to perform. In this way, the second model can be transferred to specific scenarios; for example, the model can learn to perform corresponding complex tasks (such as triggering execution tasks) and generate responses based on user task instructions.

[0152] In this embodiment of the application, by adding only the information of the target calling tool and the information of the random tool for N rounds of response to the second system prompt information, the length of the context can be reduced and the efficiency of supervised fine-tuning training can be improved.

[0153] In some embodiments, the model to be trained is a model obtained by supervised fine-tuning training of a second model using a second training dataset, and the second training dataset may include N third sample data. The j-th third sample data among the N third sample data may include third system prompt information, expected response information of the first j rounds of responses in the first sample data, and user input information corresponding to the first j rounds of responses, wherein: the third system prompt information may include information on candidate calling tools for the j-th round of responses, and the information on candidate calling tools for the j-th round of responses is obtained through a calling tool recall interface based on the user input information corresponding to the first j rounds of responses.

[0154] For each third sample data point, the Last Round training method can be used to train the model and optimize the model response information in the last response round of the model output.

[0155] It's understandable that calling the tool recall interface can yield semantically similar tools, and the ability to construct distractor tools is quite strong, enabling the model to distinguish between similar tools (easily confused tools). Furthermore, by splitting the first sample data, which includes N rounds of responses, into N third sample data, with each third sample data's third system prompt word containing only information about the candidate calling tool, the length of the context can be reduced, improving the efficiency of supervised fine-tuning training. Details will be discussed later and will not be elaborated upon here.

[0156] It should be noted that the above-mentioned second system prompts and third system prompts can be designed according to actual needs, and this application does not impose any specific limitations on them.

[0157] In this embodiment of the application, after supervising the fine-tuning training of the second model using the first training dataset or the second training dataset, a model to be trained is obtained. Then, by performing reinforcement learning training on the model to be trained, the success rate of the model's task execution and the generalization ability can be improved.

[0158] The following is combined with Figure 4 This describes the process of determining the reward score for the first result generated by the model to be trained. (Reference) Figure 4 The process includes:

[0159] S201, based on the first result and the first sample data, parse the structured fields of each round of response in the N rounds of response.

[0160] As mentioned earlier, the first result includes the model response information for each round of responses in the N rounds, and the first sample data includes the expected response information for each round of responses in the N rounds. Both the model response information and the expected response information are structured fields.

[0161] In some embodiments, after the electronic device obtains the first result to be generated during training, it can parse the structured fields of each round of response in the N rounds of responses based on the first result and the first sample data. For example, the structured fields may include response type labels, label content, and response content.

[0162] After parsing, the electronic device can compare the model response information and the expected response information for each round of responses. Specifically, for the i-th round of responses in N rounds, the electronic device can execute S202 to S208 as follows.

[0163] S202, Determine if the response type tags are consistent.

[0164] In some embodiments, the electronic device can determine whether the response type labels are consistent. That is, it can determine whether the predicted response type label in the model response information is consistent with the expected response type label in the expected response information. If they are inconsistent, step S203 can be executed; if they are consistent, step S204 can be executed.

[0165] S203, determine the round reward score of the i-th round response as the first score.

[0166] In some embodiments, if the predicted response type label and the expected response type label are inconsistent, the electronic device may determine that the round reward score for the i-th round response is a first score. For example, the first score may be 0.

[0167] S204, Determine if the response type is a tool call type.

[0168] As mentioned above, in this embodiment, different scoring rules are designed for different response types, which can achieve differentiated scoring and make the round reward score of each response more closely match its business importance. For example, the scoring rules for model response information of tool call type are different from those for model response information of non-tool call type.

[0169] In some embodiments, if the predicted response type label matches the expected response type label, the electronic device may continue to determine whether the response type is a tool invocation type. If the response type is not a tool invocation type, step S205 may be executed; if the response type is a tool invocation type, step S207 may be executed.

[0170] S205, determine the first sub-reward score corresponding to the predicted response type label of the i-th round response and the second sub-reward score corresponding to the predicted response sub-information.

[0171] In some embodiments, when the response type is not a tool invocation type, the electronic device can determine the first sub-reward score corresponding to the predicted response type label of the i-th round response and the second sub-reward score corresponding to the predicted response information. For details, please refer to the relevant description in S102 above, which will not be repeated here.

[0172] S206, the first sub-reward score and the second sub-reward score are weighted and merged to obtain the round reward score of the i-th round response.

[0173] In some embodiments, after the electronic device determines the first sub-reward score and the second sub-reward score, it can perform a weighted fusion of the first sub-reward score and the second sub-reward score to obtain the round reward score for the i-th round response. For details, please refer to the relevant description in S102 above, which will not be repeated here.

[0174] S207, determine the third sub-reward score corresponding to the prediction tool name of the i-th round response, and / or, determine the fourth sub-reward score corresponding to the exact match prediction parameter, and / or, determine the fifth sub-reward score corresponding to the text prediction parameter.

[0175] In some embodiments, when the response type is a tool invocation type, the electronic device can determine the third sub-reward score corresponding to the prediction tool name of the i-th round response, and / or determine the fourth sub-reward score corresponding to the exact match prediction parameter, and / or determine the fifth sub-reward score corresponding to the text prediction parameter. For details, please refer to the relevant description in S102 above, which will not be repeated here.

[0176] S208, the third sub-reward score and / or the fourth sub-reward score and / or the fifth sub-reward score are weighted and merged to obtain the round reward score of the i-th round response.

[0177] In some embodiments, after the electronic device determines the third sub-reward score and / or the fourth sub-reward score and / or the fifth sub-reward score, it can perform weighted fusion to obtain the round reward score of the i-th round response. For details, please refer to the relevant description in S102 above, which will not be repeated here.

[0178] S209: Weight and merge the round reward scores of each response in the N rounds of responses to obtain the reward score of the first result.

[0179] In some embodiments, after the electronic device determines the round reward score of each response in N rounds of responses, it can obtain the reward score of the first result through weighted fusion. The weight of the round reward score of each response can be determined based on its response type and context length. For details, please refer to the relevant description in S103 above, which will not be repeated here.

[0180] In this embodiment, different scoring rules are set for different response types, making the round reward score of each response more consistent with the characteristics of the response type, thereby improving the reliability and accuracy of the round reward score. Furthermore, the reward score obtained by weighted fusion of the round reward types of N rounds of responses can characterize the quality of the entire interaction trajectory.

[0181] In this embodiment, the model to be trained can also be a model obtained by supervising and fine-tuning a second model using a first training dataset or a second training dataset. For details, please refer to the relevant descriptions above; they will not be repeated here.

[0182] The following is combined with Figure 5 This application introduces another model training method. The subject of this method can be an electronic device, such as a desktop computer, laptop computer, or server.

[0183] In this method, the electronic device can acquire the first result generated by the model to be trained, and adjust the parameters of the model to be trained based on the first result. The first result may include N model response information corresponding to N rounds of response, where N is an integer greater than 1.

[0184] For example, electronic devices can use a reward model to score the first result, obtain a reward score for the first result, and then adjust the parameters of the model to be trained based on the reward score of the first result.

[0185] In some embodiments, the process of generating the model response information of the k-th round response in the N-th round response of the first result generated by the model to be trained can refer to... Figure 5 The process includes:

[0186] S301, call the first model, and generate simulated user input information corresponding to the k-th round response based on the preset system prompt information, the user input information corresponding to the first k-1 rounds of response in the first sample data and the model response information of the first k-1 rounds of response. The first model has user language simulation function, and k is an integer greater than 1 and less than or equal to N.

[0187] In some embodiments, the electronic device may invoke a first model to generate simulated user input information corresponding to the k-th round response based on preset system prompts, user input information corresponding to the first k-1 rounds of responses in the first sample data, and model response information of the first k-1 rounds of responses. The first model has user language simulation function, and k is an integer greater than 1 and less than or equal to N.

[0188] For example, after obtaining at least one round of model response information from the first round of sample dialogue in the corresponding first sample data, the electronic device can invoke the first model to generate simulated user input information for the next round of dialogue.

[0189] It can be understood that the first sample data is a sample data in the target training dataset. The first sample data may include at least one round of sample dialogue. One round of sample dialogue may include user input information and expected response information for at least one round of responses. That is to say, the first sample data is the standard answer information (Ground Truthmessage) of the model response.

[0190] In some embodiments, the electronic device invokes the first model and, based on preset system prompts, user input information corresponding to the first k-1 rounds of responses in the first sample data, and model response information of the first k-1 rounds of responses, determines that the task corresponding to the (k-1)th round has not been completed. Then, simulated user input information corresponding to the kth round of responses is generated using the first model.

[0191] It can also be understood that when the first model generates simulated user input information, the preset system prompts can instruct the behavior of the first model. For example, it can instruct the first model to combine the historical context to generate simulated user input information for the next round of dialogue, so that the simulated user input information will not be disconnected from the previous dialogue.

[0192] For example, the preset system prompts can instruct the first model to determine, based on the historical context, whether the task corresponding to the (k-1)th round response has been completed. If the first model determines that the task corresponding to the (k-1)th round response has not been completed, then the first model can generate simulated user input information corresponding to the kth round response.

[0193] In some embodiments, the aforementioned preset system prompt information may include role setting information, task information, input description information, behavioral constraint information, and output format information. The role setting information can be used to define the identity and personality stance of the first model in the interaction; the task information can be used to indicate the task execution goal of the first model; the input description information can be used to explain the currently available context data structure to the first model; the behavioral constraint information can be used to set the behavioral boundaries and operating rules of the first model; and the output format information can be used to specify the structured information output by the first model.

[0194] refer to Figure 6 The design logic of the preset system prompt information may include: role setting information 61 is used to instruct the first model to play the role of a human user, not artificial intelligence (AI) and to maintain personality consistency.

[0195] The input description information 62 may include a task description 621, a standard tool invocation command 622, a prediction tool invocation command 623, and a historical dialogue 624, used to introduce the current input information to the first model. Specifically, the task description 621 may be obtained from the user input information of the first response round in the corresponding sample data during the current task execution of the first model. The standard tool invocation command 622 may come from the expected response information of the previous response round in the corresponding sample data during the current task execution of the first model. The prediction tool invocation command 623 may come from the model response information of the previous response round. The historical dialogue 624 may include the user input information and model response information of the historical response rounds in the first sample data.

[0196] For example, in the process of generating simulated user input information corresponding to the k-th round response in the first sample data, the task description 621 can be obtained from the user input information corresponding to the 1-th round response in the first sample data, the standard tool invocation instruction 622 can come from the expected response information of the (k-1)-th round response in the first sample data, the prediction tool invocation instruction 623 can come from the model response information of the (k-1)-th round response, and the historical dialogue 624 can include the user input information and the model response information of the previous (k-1)-th round responses in the first sample data.

[0197] Behavioral constraint information 63 can be used to instruct the first model to maintain the role (human user), knowledge background, allow occasional errors in output content, be goal-oriented, and remain tolerant.

[0198] For example, behavioral constraint information 63 could be: Maintain Role: Play the role of a human user. You are not AI. Maintain a consistent persona throughout the chat; Knowledge Background: Demonstrate the user's knowledge level during role-playing. If the user is unfamiliar with the task, they might not notice incorrect statements. Ask questions to show your current level of understanding and areas of confusion; Occasional Mistakes: Real users might misspell words, provide incorrect dates, give inaccurate information, or ask unclear questions. Simulate this behavior to make the interaction more natural; Goal Orientation: Keep the chat focused on your goal. Avoid small talk or going off-topic. If the conversation starts to veer off-topic, steer the conversation back to the main objective; Be Forgiving: In cases of unforeseen circumstances, such as tool execution permissions or hardware limitations preventing successful tool calls, consider that the AI ​​has done its best, and the failure to call the tool is not a problem with the AI's output instructions. A lower but non-zero score can be given.

[0199] Task information 64 can be used to indicate the tasks that the first model needs to perform, such as comparing standard tool call instructions with prediction tool call instructions, checking whether the format and parameters of prediction tool call instructions conform to the specifications, and evaluating the completion rate of tool calls.

[0200] Output format information 65 can specify the structured information output by the first model. For example, it can specify that the simulated user input information output by the first model includes structured information (JSON object) and response text. The structured information can contain task execution result fields (e.g., execution completed label) and score fields. The score field is for reference only and does not participate in the subsequent calculation of reward scores.

[0201] It should be noted that the aforementioned preset system prompts can be designed according to actual needs, and the preset system prompts may include less information or include other information. This application does not make any specific limitations in this regard.

[0202] S302, after concatenating the simulated user input information corresponding to the k-th round response with the first system prompt information, input it into the model to be trained to obtain the model response information of the k-th round response.

[0203] In some embodiments, after the electronic device obtains the simulated user input information corresponding to the k-th round response, it can concatenate the simulated user input information with the first system prompt information and input it into the model to be trained to obtain the model response information of the k-th round response.

[0204] As mentioned earlier, the first system prompt information can be used to define the task role of the model to be trained, information on candidate calling tools, and output format constraints.

[0205] In this embodiment of the application, by calling the first model to obtain generalized simulated user input information, dynamic dialogue can be realized. It can also avoid the problem of dialogue disconnect caused by the dialogue still following the first sample data when the model response information of the model to be trained is incorrect.

[0206] The following is combined with Figure 7 and Figure 8 This application introduces a model training system provided by an embodiment.

[0207] In some embodiments, the model training system 70 may include a reinforcement learning trajectory sampling engine 71, a reward module 72, and a policy training module 73.

[0208] Among them, the reinforcement learning trajectory sampling engine 71 can be used to sample the output of the model to be trained. For example, the first result mentioned above.

[0209] The reward module 72 can be used to calculate the reward score of the output result of the model to be trained. For example, the reward score of the first result mentioned above.

[0210] The policy training module 73 can be used to adjust the parameters of the model to be trained based on the reward score of the output result. It can be understood that, in the reinforcement learning phase, the model to be trained can be called the policy network, and updating the parameters of the model to be trained is equivalent to updating the parameters of the policy network.

[0211] In some embodiments, a preset reinforcement learning algorithm may be run on the policy training module 73 to calculate the policy gradient. The reinforcement learning algorithm may be, for example, a group relative policy optimization (GRPO) algorithm, a proximal policy optimization (PPO) algorithm, etc.

[0212] During the reinforcement learning training process of the model to be trained, the model training system 70 can sample interaction trajectories through the reinforcement learning trajectory sampling engine 71, and then input the sampled interaction trajectories into the reward module 72 to calculate the reward score. The reward score output by the reward module 72 and the sampled interaction data (such as the first result mentioned above) are input into the policy training module 73 to update the parameters of the policy network in the reinforcement learning trajectory sampling engine 71.

[0213] Figure 8 The architecture diagram of the reinforcement learning trajectory sampling engine 71 is shown.

[0214] refer to Figure 8 The reinforcement learning trajectory sampling engine 71 may include an agent core 81, a large model inference engine (LLM Backend) 82, a tool system 83, and an external interaction environment 84.

[0215] The agent core 81, as the main controller of the sampling engine, is responsible for driving the start, stop and flow of the entire interaction loop (Rollout Loop), coordinating the execution of tasks by each sub-module in a predetermined sequence until a single trajectory reaches the termination state (task success, failure or reaching the maximum number of rounds).

[0216] The agent core 81 can include a state machine engine 811 and a data processor 812, and also stores memory and context (Agent Data). Memory and context, as the data hub during the sampling process, can store the dialogue history of the current trajectory, tool definitions, and execution results (observations) from the environment feedback in real time, providing a complete context state for the next round of decision-making by the policy network. The state machine engine 811 can manage the lifecycle states of the sampling process (such as pending, generating, and executing states), control the legal transitions between states, and ensure that the interaction process strictly follows the sequential logic of "generation → execution → backfilling". The data processor 812 can concatenate the dynamic context of the current response round (real-time recalled tool information, historical memory, and user input information) with system prompts (such as the first system prompts mentioned in this application) into data conforming to the model input format, preparing standardized input tensors for the forward inference of the policy network.

[0217] The large model inference engine 82 serves as the runtime environment for the model to be trained. It can load the weight parameters of the current policy network and perform forward inference, outputting the model response information for the current response round. The large model inference engine 82 includes a service manager 821, which manages the load balancing and resource scheduling of underlying inference service instances (such as vLLM / SGLang), allocates inference engine instances to sampling tasks, and ensures inference efficiency and stability in high-concurrency sampling scenarios.

[0218] The tool execution system 83 can receive and parse the model response information of the policy network, complete the actual tool invocation operation, and return the execution result. The tool execution system 83 may include a parser 831, a concurrent executor 832, and a registered toolset 833. The parser 831 can be used to parse the model response information to obtain the tool invocation instruction. The concurrent executor 832 can be used to execute the tool invocation task based on the tool invocation instruction; for example, it can schedule and distribute multiple tool invocation tasks in parallel. The registered toolset 833 stores a large amount of tool information, which may include tool names, function descriptions, parameter structures, etc., for multiple tools.

[0219] The external interaction environment 84 may include an interaction module 841, which may run a first model (with user language simulation capabilities). The agent core 81 can instruct the first model to generate and obtain simulated user input information by calling the application programming interface (API) of the first model.

[0220] based on Figure 8 The architecture diagram shown below, combined with... Figure 9 This document describes an interactive trajectory sampling process in one embodiment of this application. (Reference) Figure 9 The process includes:

[0221] S401, Run the model to be trained and obtain sample data.

[0222] In some embodiments, during model training, the agent core 81 can run the model to be trained and acquire sample data. This sample data can be any sample data from the target training dataset mentioned above, such as the first sample data.

[0223] S402, Initialize the index of the current dialogue round in the sample data.

[0224] In some embodiments, the agent core 81 can initialize the index of the current dialogue turn in the sample data.

[0225] It is understandable that the sample data can include multiple dialogue rounds (i.e., multi-turn dialogue samples), where each dialogue round can include one user input and at least one expected response; that is, the sample data includes standard interaction trajectories. For a given sample data set, the agent core 81 can initialize the index of the current dialogue round before controlling the model to be trained to generate the model response, so that the index points to the first dialogue round.

[0226] S403, enter standby mode, encoding system prompt message.

[0227] In some embodiments, the agent core 81 can first switch the current state to a standby state through the state machine engine 811 and encode the system prompt information. Taking the first sample data as an example, the agent core 81 can encode the first system prompt information in the first sample data into a vector representation (embedding) that can be processed by the model to be processed through the data processor 812.

[0228] S404: Obtain user input information for the current dialogue round, enter the generation state, and control the model to generate a response.

[0229] In some embodiments, the agent core 81 can acquire user input information for the current dialogue round, then switch the current state to the generation state through the state machine engine 811, and drive the model to be trained to generate a response. Taking the first sample data as an example, if the current dialogue round is the first round, the agent core 81 can acquire user input information from the first round sample dialogue in the first sample data, and drive the model to be trained to generate model response information based on the user input information.

[0230] Specifically, the agent core 81 can encode the user input information into a vector representation that the model to be processed can process through the data processor 812, and concatenate the encoded user input information with the system prompt information and send it to the large model inference engine 82. The large model inference engine 82 can generate the model response information corresponding to the current dialogue round.

[0231] S405: Obtain model response information and determine if a tool call command exists.

[0232] In some embodiments, the agent core 81 can obtain model response information and determine whether a tool invocation instruction exists. If it exists, S406 is executed; otherwise, S407 is executed.

[0233] S406 executes a tool call based on the tool call instruction.

[0234] In some embodiments, if the agent core 81 has a tool invocation instruction, it can send the model response information to the tool execution system 83. The tool execution system 83 can then execute the tool invocation based on the tool invocation instruction.

[0235] S407, determine if the number of dialogue rounds has reached the upper limit.

[0236] In some embodiments, the agent core 81 may determine whether the number of dialogue rounds has reached the upper limit if the model response information contains a tool call instruction, or after the tool call has been executed. If not, S408 is executed; if so, S416 is executed.

[0237] Taking the first sample data as an example, if the first sample data includes two dialogue rounds, and the current dialogue round is the first dialogue round, then the agent core 81 can determine that the number of dialogue rounds has not reached the upper limit and can execute S408. If the first sample data includes one dialogue round, then the agent core 81 can determine that the number of dialogue rounds has reached the upper limit and can execute S416.

[0238] S408 calls the API of the first model.

[0239] In some embodiments, if the agent core 81 determines that the number of dialogue turns has not reached the upper limit, it may call the API of the first model running on the interaction module 841 in the external interaction environment 84. The input parameters for calling this API may include preset system prompts and historical context. For details regarding the preset system prompts and historical context, please refer to the previous description of S301; they will not be repeated here.

[0240] S409, Determine if the API's return result contains a value.

[0241] In some embodiments, after the first model generates the output result, it can return the result to the agent core 81 via API, or the API can also return the result if the model call fails.

[0242] After receiving the API's return result, the intelligent agent core 81 can determine whether the API's return result contains a value, i.e., whether the output result of the first model exists. If a value exists, S410 can be executed; if no value exists, S413 can be executed.

[0243] S410 parses the JSON object in the returned result. If the parsing is successful, it performs field parsing on the parsed result to obtain the field parsing result.

[0244] In some embodiments, the agent core 81 can parse the JSON object (i.e. the output of the first model) in the returned result. If the parsing is successful, the parsing result is parsed to obtain the field parsing result.

[0245] By parsing the JSON object, it can be confirmed whether the output of the first model is valid and structured data that can be read by the program. By parsing the fields in the parsed result, the field values ​​required in subsequent processes can be determined.

[0246] In this embodiment, the output of the first model may include simulated user input information and task execution result labels. The task execution result labels are determined based on the model response information and historical context of the previous round of response of the model to be trained, and can characterize whether the task in the previous round of response of the model to be trained was successfully executed.

[0247] S411, determine whether the tool's task execution was successful based on the field parsing results.

[0248] In some embodiments, the agent core 81 can determine whether the tool call task was successfully executed based on the field parsing result after obtaining it. If the execution is successful, S412 can be executed; if the execution fails, S414 can be executed.

[0249] For example, the field parsing result may include a task execution result label. If the task execution result label is "done", then the agent core 81 can determine that the tool call task in the previous response round was executed successfully.

[0250] S412, determine whether the sample data includes the next dialogue round.

[0251] In some embodiments, after determining that the tool call task of the previous response round was successfully executed, the agent core 81 can determine whether the sample data includes the next dialogue round. If yes, then execute S413; otherwise, execute S416.

[0252] It is understandable that sampling the current interaction trajectory can end if the sample data does not include the next dialogue turn. Afterwards, the next sample data from the target training dataset can be used to sample the interaction trajectory.

[0253] If the tool call task in the previous response round is executed successfully, the output of the first model may not include simulated user input information. Therefore, if the sample data includes the next dialogue round, the agent core 81 can execute S413.

[0254] S413, Obtain user input information for the next dialogue round from the sample data.

[0255] In some embodiments, the agent core 81 can acquire user input information for the next dialogue round from the sample data. This can improve the completeness of the current interaction trajectory sampling.

[0256] Afterwards, the agent core 81 can update the index of the current dialogue turn and repeat the process from S404 to S412.

[0257] S414, determine whether simulated user input information is included based on the field parsing results.

[0258] In some embodiments, the agent core 81 can determine whether simulated user input information is included based on the field parsing result after determining that the tool call task in the previous response round failed. If yes, then S415 is executed; otherwise, S413 is executed.

[0259] It is understandable that if the field parsing result does not include simulated user input information, then the user input information for the next dialogue round in the sample data can be obtained. Thus, if the sample data does not include the next dialogue round, the agent core 81 cannot obtain the user input information, and can therefore end the sampling of the current interaction trajectory; if the sample data includes the next dialogue round, the agent core 81 can obtain the user input information, then update the index of the current dialogue round, and repeat the process from S404 to S412.

[0260] This can improve the integrity of the current interaction trajectory sampling.

[0261] S415, simulate user input information as user input for the next dialogue round.

[0262] In some embodiments, if the field parsing result includes simulated user input, the agent core 81 can use the simulated user input as the user input for the next dialogue round. Afterwards, the index of the current dialogue round can be updated, and the process described in S404 to S412 can be repeated.

[0263] S416, End the current interaction process.

[0264] It is understandable that ending the current interaction process means ending the sampling of the current interaction trajectory.

[0265] Taking the first sample data as an example, after sampling the current interaction trajectory, a first result is generated. The reinforcement learning trajectory sampling engine 71 can send the first result to the reward module 72 to calculate the reward score corresponding to the first result. The reward module 72 can input the reward score corresponding to the first result and the first result into the policy training module 73 to update the parameters of the policy network in the reinforcement learning trajectory sampling engine 71. Afterwards, the reinforcement learning trajectory sampling engine 71 can obtain the next sample data in the target training dataset and sample the interaction trajectory.

[0266] In this embodiment of the application, by calling the first model to obtain generalized simulated user input information, dynamic dialogue can be achieved, which is beneficial for training the model's multi-turn dialogue capability.

[0267] The following is combined with Figure 10 This application introduces another model training method. The method can be implemented using an electronic device, such as a desktop computer or laptop computer.

[0268] refer to Figure 10 The method includes:

[0269] S501, acquire multiple dialogue samples containing multiple rounds of interaction, each dialogue sample including multiple expected response information for multiple rounds of response and user input information corresponding to each round of response.

[0270] In some embodiments, an electronic device may acquire multiple dialogue samples containing multi-turn interactions, each dialogue sample including multiple expected response information for multi-turn responses and user input information corresponding to each turn response.

[0271] For example, a dialogue sample could be trajectory1 as described in the previous example. trajectory1 includes user input information user11, model response information assistant11 for the first round of response, and model response information assistant11p for the second round of response. Each model response information in trajectory1 is used as the expected response information in the dialogue sample.

[0272] S502, each dialogue sample is split into multiple sub-samples corresponding to the multi-turn responses. The sub-samples corresponding to the m-th round response in the multi-turn response obtained from the splitting of each dialogue sample include: the expected response information of the first m rounds of the multi-turn response and the user input information corresponding to the first m rounds of the multi-turn response, where m is a positive integer.

[0273] In some embodiments, the electronic device may split each dialogue sample into multiple sub-samples corresponding to the multi-turn responses, wherein the sub-samples obtained by splitting each dialogue sample and corresponding to the m-th round response in the multi-turn response include: the expected response information of the first m round responses in the multi-turn response and the user input information corresponding to the first m round responses, where m is a positive integer.

[0274] Based on the above example, the electronic device can split trajectory1 into two sub-samples and use each model response information in trajectory1 as the expected response information in the corresponding sub-sample. The first sub-sample may include user input information user11 and model response information assistant11 of the first round of response. The second sub-sample may include user input information user11, model response information assistant11 of the first round of response, and model response information assistant11p of the second round of response.

[0275] S503, based on multiple sub-samples corresponding to each dialogue sample and the third system prompt information corresponding to each sub-sample, multiple training sample data corresponding to each dialogue sample are obtained. The third system prompt information includes the information of the candidate calling tool for the corresponding sub-sample. The information of the candidate calling tool is obtained by calling the tool recall interface based on the user input information in the corresponding sub-sample.

[0276] In some embodiments, the electronic device can obtain multiple training sample data corresponding to each dialogue sample based on multiple sub-samples corresponding to each dialogue sample and third system prompt information corresponding to each sub-sample. The third system prompt information includes information on candidate calling tools for the corresponding sub-sample. The information on candidate calling tools is obtained through a tool recall interface based on user input information in the corresponding sub-sample.

[0277] Based on the above example, for the first subsample, the electronic device can obtain a training sample data corresponding to the first subsample and its corresponding third system prompt information. The candidate tool information in the third system prompt information is obtained based on the user input information user11 through the tool recall interface. As mentioned earlier, if the user input information user11 is "Please turn on Do Not Disturb mode for me at 1 PM every day," then the candidate tool information can include information about the time-fence tool and information about the execution tool for turning on Do Not Disturb mode.

[0278] It is understandable that by calling the tool recall interface, semantically similar tools can be obtained. The ability to construct interference tools is relatively strong, and the model can be trained to distinguish similar tools (easily confused tools).

[0279] It is also understandable that for complex tasks, such as trigger-based tasks in mobile scenarios, nested tool calls may be involved, requiring the invocation of a large number of tools (e.g., 100+). Filling all tool information into the system prompts would reduce model training efficiency and distract the model from user instructions and key decisions, thus decreasing the accuracy of tool calls. In this embodiment, the third system prompt for each sample data only includes information on candidate tools, resulting in a shorter context and improved efficiency for supervised fine-tuning training.

[0280] S504, construct a second training dataset based on the training sample data corresponding to multiple dialogue samples.

[0281] In some embodiments, the electronic device may construct a second training dataset based on training sample data corresponding to multiple dialogue samples.

[0282] S505, using the second training dataset to perform supervised fine-tuning of the second model, resulting in the model to be trained.

[0283] In some embodiments, after the electronic device constructs the second training dataset, it can use the second training dataset to perform supervised fine-tuning of the second model to obtain the model to be trained. Specifically, for each sample data point, Lastround training can be used to optimize the model response information of the last response round output by the second model.

[0284] In this embodiment of the application, when designing sample data, if it is necessary to call easily confused tools in the sample data or to dynamically refresh the information of candidate tools in the prompt information of the third system during the training process, the second training dataset can be constructed using the above-described methods S501 to S504.

[0285] In other embodiments, after executing S501, the electronic device can obtain training sample data corresponding to each dialogue sample based on each dialogue sample and the corresponding second system prompt information. The second system prompt information includes information about the target invocation tool and the random tool for the corresponding dialogue sample. Then, based on the multiple training sample data corresponding to multiple dialogue samples, a first training dataset is constructed. Subsequently, the second model is fine-tuned under supervised supervision using the first training dataset to obtain the model to be trained.

[0286] Thus, by adding only the target tool information and random tool information of the corresponding dialogue sample to the second system prompt information, the length of the context can be reduced, and the efficiency of supervised fine-tuning training can be improved. In this embodiment, when designing sample data, if a tool with high discriminative power needs to be called in the sample data, this method can be used to construct the first training dataset to avoid the dataset being too large and affecting the model training efficiency.

[0287] In this embodiment of the application, after obtaining the model to be trained, reinforcement learning training can be performed on the model to obtain the target model. The reinforcement learning training process can be referred to the preceding description. Figure 3 , Figure 5 or Figure 9 The description will not be repeated here.

[0288] This target model can serve as a foundational model for intelligent agents (such as intelligent assistants on mobile phones). Once deployed, it can be used to perform intent recognition, tool invocation, and task execution based on user input information or instructions, providing intelligent agents with underlying decision-making and generation capabilities.

[0289] This application provides a computer-readable storage medium storing instructions that, when executed on an electronic device, cause the electronic device to perform the model training method mentioned in any embodiment of this application.

[0290] This application provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by an electronic device, the model training method mentioned in any embodiment of this application is implemented.

[0291] This application also provides an electronic device that may include at least one processor and at least one memory. The at least one memory stores at least one program, which, when executed by the at least one processor, causes the electronic device to perform any of the model training methods mentioned in this application.

[0292] For example, Figure 11 According to some embodiments of this application, a schematic diagram of the structure of an electronic device is shown.

[0293] like Figure 11 As shown, the electronic device 100 may include a processor 110, a memory 120, a communication interface 130, and a bus 140.

[0294] Processor 110 may include one or more processing units, such as a central processing unit (CPU), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a microcontroller unit (MCU), a video codec, a digital signal processor (DSP), a baseband processor, a neural network processing unit (NPU), a field-programmable gate array (FPGA), etc. In some embodiments, different processing units may be independent devices or integrated into one or more processors.

[0295] In some embodiments, the processor 110 may be used to execute one or more programs to implement the model training method provided in the embodiments of this application.

[0296] The memory 120 may include one or more memories for storing data or program code. For example, in some embodiments, the memory 120 may be used to store data such as a target training dataset, a first training dataset, a second training dataset, etc.

[0297] In some embodiments, the memory 120 may include a hard disk drive, a solid-state drive, flash memory, an optical disk, or a magneto-optical disk. In some embodiments, the memory 120 may include removable or non-removable or fixed media. In some embodiments, the memory 120 may be internal or external to the electronic device 100.

[0298] The communication interface 130 is used to enable communication between the electronic device 100 and other devices (such as test equipment and input / output devices). In some embodiments, the communication interface 130 may include a wireless communication interface and a wired communication interface.

[0299] In some embodiments, the wireless communication interface can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module can be one or more devices integrating at least one communication processing module.

[0300] Wired communication interfaces may include Ethernet interfaces (such as fiber optic interfaces, RJ-45 interfaces, etc.), universal serial bus (USB), power line carrier communication (PLC) interfaces, high definition multimedia interface (HDMI) interfaces, digital audio interfaces, and other wired communication interfaces, which are used to provide wired communication solutions for electronic devices 100.

[0301] Bus 140 is used to connect processor 110, memory 120, communication interface 130 and other possible modules or circuits.

[0302] It should be understood that Figure 11 The structure of the electronic device 100 described is only an example. In other embodiments, the electronic device 100 may include more or fewer modules, which is not limited here.

[0303] It is understood that, as used herein, the term “module” may refer to or include, or be part of, an application-specific integrated circuit (ASIC), electronic circuitry, a processor (shared, dedicated, or grouped) and / or memory that executes one or more software or firmware programs, combinational logic circuitry, and / or other suitable hardware components that provide the described functionality.

[0304] The embodiments disclosed in this application can be implemented in hardware, software, firmware, or a combination of these implementation methods. Embodiments of this application can be implemented as computer programs or program code executable on a programmable system, the programmable system including at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device.

[0305] Program code can be applied to input instructions to execute the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, the processing system includes any system having a processor such as, for example, a digital signal processor, a microcontroller, an application-specific integrated circuit, or a microprocessor.

[0306] The program code can be implemented using a high-level procedural language or an object-oriented programming language to communicate with the processing system. Assembly language or machine language can also be used when needed. In fact, the mechanisms described in this application are not limited to any particular programming language. In either case, the language can be a compiled language or an interpreted language.

[0307] In some cases, the embodiments disclosed in this application can also be implemented as instructions carried or stored thereon on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which can be read and executed by one or more processors. For example, the instructions can be distributed via a network or via other computer-readable media. Therefore, machine-readable media can include any mechanism for storing or transmitting information in a machine-readable (e.g., computer-readable) form, including but not limited to floppy disks, optical disks, optical discs, magneto-optical disks, read-only memory (ROM), random access memory (RAM), electrically programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic cards or optical cards, flash memory, or tangible machine-readable storage for transmitting information (e.g., carrier waves, infrared signals, digital signals, etc.) using the Internet in the form of electrical, optical, acoustic, or other propagation signals. Therefore, machine-readable media includes any type of machine-readable medium suitable for storing or transmitting electronic instructions or information in a machine-readable (e.g., computer-readable) form.

[0308] In the accompanying drawings, some structural or methodological features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be necessary. Rather, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. Furthermore, the inclusion of structural or methodological features in a particular figure does not imply that such features are required in all embodiments, and in some embodiments, these features may be omitted or may be combined with other features.

[0309] It should be noted that all units / modules mentioned in the device embodiments of this application are logical units / modules. Physically, a logical unit / module can be a physical unit / module, a part of a physical unit / module, or a combination of multiple physical units / modules. The physical implementation of these logical units / modules themselves is not the most important factor; the combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed in this application. Furthermore, to highlight the innovative aspects of this application, the above-described device embodiments of this application have not introduced units / modules that are not closely related to solving the technical problems proposed in this application. This does not mean that the above-described device embodiments do not contain other units / modules.

[0310] It should be noted that in the specification of this application, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0311] Although this application has been illustrated and described with reference to certain embodiments thereof, those skilled in the art will understand that various changes in form and detail may be made thereto without departing from the scope of this application.

Claims

1. A model training method, characterized in that, The method includes: Obtain the first result generated by the model to be trained, wherein the first result includes N model response information corresponding to N rounds of response, where N is an integer greater than 1; For the i-th round response in N rounds of responses: Based on the expected response information of the i-th round response, the model response information of the i-th round response is scored according to the scoring rules corresponding to the response type of the i-th round response to obtain the round reward score of the i-th round response, where i is a positive integer less than or equal to N, and the scoring rules for the corresponding model response information are different for different response types. The reward score for the first result is obtained based on the round reward scores of the N rounds of responses; Based on the reward score of the first result, the parameters of the model to be trained are adjusted.

2. The model training method according to claim 1, characterized in that, The method further includes: After concatenating the user input information corresponding to each round of response in the first sample data with the first system prompt information, the concatenation is then input into the model to be trained to obtain the first result, wherein: The first sample data also includes the expected response information for each round of responses in the N rounds of responses.

3. The model training method according to claim 1, characterized in that, The method further includes: After concatenating the user input information from the first round of sample dialogue in the first sample data with the first system prompt information, the concatenation is input into the model to be trained to obtain a first intermediate result, wherein the first intermediate result includes at least one round of model response information corresponding to the first round of sample dialogue; The first model is invoked to generate simulated user input information in the first round of simulated dialogue based on preset system prompts, user input information in the first round of sample dialogue, and the first intermediate result. The first model has user language simulation function. The simulated user input information from the first round of simulated dialogue is concatenated with the first system prompt information and then input into the model to be trained to obtain a second intermediate result. The second intermediate result includes at least one round of model response information corresponding to the first round of simulated dialogue. Based on at least one round of model response information corresponding to the first round of sample dialogue and at least one round of model response information corresponding to the first round of simulated dialogue, the first result is obtained, wherein: The first sample data also includes the expected response information for each round of responses in the N rounds of responses.

4. The model training method according to claim 3, characterized in that, The preset system prompts include: role setting information, task information, input description information, behavioral constraint information, and output format information, wherein: The role setting information is used to define the identity and personality stance of the first model in the interaction; The task information is used to indicate the task execution target of the first model; The input description information is used to explain the currently available context data structure to the first model; The behavioral constraint information is used to set the behavioral boundaries and operational criteria of the first model; The output format information is used to specify the structured information output by the first model.

5. The model training method according to claim 4, characterized in that, The user input information in the first round of sample dialogue includes a first task instruction, which includes a first task to be performed and at least one triggering condition for performing the first task. The simulated user input information in the first round of simulated dialogue includes a second task instruction or at least one triggering condition for executing the first task. The second task instruction includes a second task to be executed and at least one triggering condition for executing the second task.

6. The model training method according to claim 2 or 3, characterized in that, The model to be trained is a model obtained by supervising and fine-tuning a second model using a first training dataset. The first training dataset includes second sample data, which includes second system prompts, user input information corresponding to each of the N rounds of responses in the first sample data, and expected response information for each of the N rounds of responses. The second system prompt information includes information about the target calling tool and the random tool in the N rounds of response.

7. The model training method according to claim 2 or 3, characterized in that, The model to be trained is a model obtained by supervising and fine-tuning a second model using a second training dataset, and the second training dataset includes N third sample data. The j-th third sample data among the N third sample data includes third system prompt information, expected response information of the first j rounds of responses in the first sample data, and user input information corresponding to the first j rounds of responses, wherein: The third system prompt information includes information on candidate calling tools for the j-th round of responses, and the information on candidate calling tools for the j-th round of responses is obtained through the calling tool recall interface based on the user input information corresponding to the previous j-th rounds of responses.

8. The model training method according to claim 1, characterized in that, For the case where the model response information corresponding to the i-th round response is not of the tool call type: the expected response information includes the expected response type label and the expected response sub-information, and the model response information includes the predicted response type label and the predicted response sub-information; Based on the expected response information of the i-th round response, the model response information of the i-th round response is scored according to the scoring rules corresponding to the response type of the i-th round response to obtain the round reward score of the i-th round response, including: If the model response type label of the i-th round response is inconsistent with the expected response type label, the round reward score of the i-th round response is determined to be the first score; If the predicted response type label of the i-th round response is consistent with the expected response type label, a first sub-reward score corresponding to the predicted response type label is determined, and a second sub-reward score is determined based on the similarity between the predicted response sub-information and the expected response sub-information of the i-th round response. The first sub-reward score and the second sub-reward score are weighted and fused to obtain the round reward score of the i-th round response.

9. The model training method according to claim 1, characterized in that, For the case where the model response information corresponding to the i-th round response is of the tool invocation type: the expected response information includes the expected response type label and the expected tool invocation information, the expected tool invocation information includes the expected tool name, the expected parameters for exact matching and the expected parameters for text, the model response information includes the predicted response type label and the predicted tool invocation information, the predicted tool invocation information includes the predicted tool name, the predicted parameters for exact matching and the predicted parameters for text; The step of scoring the model response information of the i-th round response according to the scoring rules corresponding to the response type of the i-th round response, based on the expected response information of the i-th round response, to obtain the round reward score of the i-th round response, also includes: If the predicted response type label and the expected response type label of the i-th round response are inconsistent, the round reward score of the i-th round response is determined to be the first score; If the predicted response type label of the i-th round response is consistent with the expected response type label, a third sub-reward score is determined based on the consistency between the expected tool name and the predicted tool name, and / or a fourth sub-reward score is determined based on the consistency between the exact match class prediction parameter and the exact match class expected parameter, and / or a fifth sub-reward score is determined based on the similarity between the text class prediction parameter and the text class expected parameter. The third sub-reward score and / or the fourth sub-reward score and / or the fifth sub-reward score are weighted and fused to obtain the round reward score of the i-th round response.

10. The model training method according to claim 1, characterized in that, The reward score for the first result is obtained based on the round reward scores of the N rounds of responses, including: The weight of each round of response is determined based on the response type and context length of each round of response in the N rounds of response; The reward score of the first result is obtained by weighted fusion of the round reward score and weight of each response in the N rounds of responses.

11. The model training method according to claim 10, characterized in that, The response types include tool invocation type, follow-up question type, rejection type, and summary type; The weight of the summary type response is lower than the weight of other types of responses, and the weight of the non-summary type response in round x is lower than the weight of the non-summary type response in round x+1.

12. The model training method according to claim 10, characterized in that, The trained target model is used as the base model for intelligent assistants in electronic devices, which include at least voice assistants, text assistants, and multimodal assistants.

13. An electronic device, characterized in that, include: At least one processor; at least one memory; The at least one memory stores at least one program, which, when executed by the at least one processor, causes the electronic device to perform the model training method according to any one of claims 1 to 12.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed on an electronic device, cause the electronic device to perform the model training method of any one of claims 1 to 12.

15. A computer program product, characterized in that, The computer program product includes a computer program or instructions that, when executed by an electronic device, cause the model training method of any one of claims 1 to 12 to be implemented.