Data processing method and related equipment

By dynamically adjusting all parameters and fine-tuning some parameters during model training, according to the preset ratio or convergence speed, the balance problem between computing resource consumption and performance in model fine-tuning is solved, and efficient model fine-tuning is achieved.

CN120688568APending Publication Date: 2025-09-23MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510566758.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-28
Publication Date
2025-09-23

AI Technical Summary

Technical Problem

During the model fine-tuning process, how to balance the relationship between computing resource consumption and model performance? In the existing technology, full parameter fine-tuning consumes large computing resources but has good performance, while partial parameter fine-tuning has poor performance.

Method used

During the model training process, based on the preset ratio and the loss or convergence speed of the training batch, the full parameter and partial parameter fine-tuning methods are dynamically adjusted to determine whether the first i training batches are fine-tuned for all parameters and the next Ni training batches are fine-tuned for partial parameters, or whether the full parameter fine-tuning is performed when the convergence speed is greater than a threshold, and then switched to partial parameter fine-tuning when the subsequent convergence speed is less than the threshold.

Benefits of technology

While ensuring model performance, it reduces computing resource consumption, improves fine-tuning efficiency, and achieves a balance between computing resources and model performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120688568A_ABST
    Figure CN120688568A_ABST
Patent Text Reader

Abstract

The invention discloses a data processing method and related equipment. The method comprises the following steps: for N training batches of a model, determining the first i training batches and the last N-i training batches in the N training batches based on a preset proportion and the N; based on the loss corresponding to the first i training batches, performing all-parameter fine tuning on the model to obtain a first model; or in the fine tuning process based on the N training batches of the model, if the convergence rate corresponding to the jth training batch is greater than the preset threshold value, performing full-parameter fine tuning on the model based on the loss corresponding to the jth training batch, and determining the convergence rate corresponding to the (j + 1) th training batch, obtaining a first model until it is determined that the convergence speed corresponding to the (i + 1) th training batch is smaller than a preset threshold value; and for the last N-i training batches in the N training batches of the model, based on the loss corresponding to the last N-i training batches, partial parameter fine tuning is performed on the first model, and i is greater than or equal to 1 and less than N.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a data processing method and related equipment. Background Art

[0002] When fine-tuning a model, currently used techniques include fine-tuning all or some parameters. Full parameter fine-tuning allows the model to quickly adapt to new tasks and capture key task characteristics. The fine-tuned model performs well, but consumes significant computational resources. Partial parameter fine-tuning, on the other hand, reduces the number of parameters used and computing resource consumption, but results in poorer performance.

[0003] Therefore, when fine-tuning the model, how to balance the relationship between computing resource consumption and model performance is an urgent problem to be solved. Summary of the Invention

[0004] This application provides a data processing method and related equipment that can well balance the relationship between computing resource consumption and model performance.

[0005] In a first aspect, the present application provides a data processing method, the method comprising:

[0006] For the N training batches of the model, based on the preset ratio and N, determine the first i training batches and the last Ni training batches in the N training batches; based on the losses corresponding to the first i training batches, fine-tune all parameters of the model to obtain the first model;

[0007] Alternatively, in the process of fine-tuning based on N training batches of the model, if the convergence rate corresponding to the j-th training batch is greater than a preset threshold, all parameters of the model are fine-tuned based on the loss corresponding to the j-th training batch, and the convergence rate corresponding to the j+1-th training batch is determined, until it is determined that the convergence rate corresponding to the i+1-th training batch is less than the preset threshold, thereby obtaining a first model;

[0008] For the last Ni training batches among the N training batches of the model, fine-tune some parameters of the first model based on the losses corresponding to the last Ni training batches, 1≤i<N.

[0009] In a second aspect, the present application provides another data processing method, applied to an electronic device, the method comprising:

[0010] Obtaining a first instruction, wherein the first instruction includes a first query statement;

[0011] Through the second model, based on the task type corresponding to the first instruction, a structured query language corresponding to the first query statement is generated, wherein the second model is obtained based on the data processing method of the first aspect.

[0012] In a third aspect, the present application provides an electronic device comprising: a processor and a memory, the processor being connected to the memory, the memory being used to store computer programs, and the processor being used to execute the computer programs stored in the memory, so that the electronic device executes the methods of the first and second aspects.

[0013] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the method of the first aspect and the second aspect is performed.

[0014] In a fifth aspect, the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, performs the methods of the first and second aspects.

[0015] The implementation of this application has the following beneficial effects:

[0016] First, a training data set for the model is obtained, including N training batches; then, based on a preset ratio and N, the first i training batches and the last Ni training batches of the N training batches are determined; then, based on the losses corresponding to the first i training batches, all parameters of the model are fine-tuned to obtain a first model; or, in the process of fine-tuning based on the N training batches of the model, if the convergence speed corresponding to the j-th training batch is greater than a preset threshold, then based on the loss corresponding to the j-th training batch, all parameters of the model are fine-tuned, and the convergence speed corresponding to the j+1-th training batch is determined, until it is determined that the convergence speed corresponding to the i+1-th training batch is less than the preset threshold, to obtain the first model; then, for the last Ni training batches of the N training batches of the model, some parameters of the first model are fine-tuned based on the losses corresponding to the last Ni training batches, 1≤i<N. That is to say, in the process of model fine-tuning, generally speaking, the faster the model parameters change in the previous training step, the larger the loss change (decline) is, and the slower the model parameters change in the later training step, the smaller the loss change (decline) is, and then gradually converge. Therefore, in an embodiment of the present application, it can be considered to determine the first i training batches and the last Ni training batches in the N training batches based on the preset ratio and N, and then use full parameter fine-tuning in the first part of the steps, that is, corresponding to the first i training batches, so that the model can learn the instructions as quickly as possible to improve the performance (stability) of the model, and then use partial parameter fine-tuning for the first model after full parameter fine-tuning in the last part of the steps, that is, corresponding to the last Ni training batches, so as to save computing resource consumption of the electronic device while being as close as possible to the effect of full parameter fine-tuning. Alternatively, in the process of fine-tuning the model based on N training batches, it can also be determined based on the convergence speed corresponding to the training batches whether to adopt full parameter fine-tuning or partial parameter fine-tuning for the model, that is, whether the convergence speed corresponding to the training batch is greater than a preset threshold is determined. If it is greater, the model is fine-tuned based on the loss corresponding to the training batch, and the convergence speed corresponding to the next training batch is calculated, until it is determined that the convergence speed corresponding to a training batch is less than the preset threshold, and the first model is obtained, and then full parameter fine-tuning is no longer adopted. The training batch with a convergence speed less than the preset threshold is assumed to be the i+1th training batch, which means that the convergence speeds corresponding to the first i training batches of the N training batches are all greater than the preset threshold, and full parameter fine-tuning is adopted for the model, so that the model can learn the instructions as quickly as possible, and then partial parameter fine-tuning is adopted for the next Ni training batches to fine-tune the first model, so as to save computing resource consumption of electronic equipment while achieving the effect of adopting full parameter fine-tuning as close as possible.Therefore, the above method makes the performance of the model more stable than using partial parameter fine-tuning, consumes less computing resources of the electronic device than using full parameter fine-tuning, and makes the electronic device more efficient when fine-tuning the model, thus achieving a good balance between the computing resource consumption of the electronic device and the model performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0018] Figure 1 A schematic diagram of the structure of a Transformer model provided in an embodiment of the present application;

[0019] Figure 2 A flowchart of a data processing method provided in an embodiment of the present application;

[0020] Figure 3 A schematic diagram of the structure of a model provided in an embodiment of the present application;

[0021] Figure 4 A schematic diagram of fine-tuning some parameters of a model provided in an embodiment of the present application;

[0022] Figure 5 A flowchart of another data processing method provided in an embodiment of the present application;

[0023] Figure 6 A schematic diagram of a data processing scenario provided in an embodiment of the present application;

[0024] Figure 7 A schematic diagram of a data processing system provided in an embodiment of the present application;

[0025] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0027] The terms "first," "second," "third," and "fourth," etc., in the specification, claims, and drawings of this application are used to distinguish between different objects, not to describe a particular order. In addition, the terms "including," "having," and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or elements is not limited to the listed steps or elements, but may optionally include steps or elements not listed, or may optionally include other steps or elements inherent to the process, method, product, or apparatus.

[0028] References herein to "embodiments" mean that a particular feature, result, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0029] First, the relevant terms and related technologies involved in the embodiments of this application are explained:

[0030] (1) Schema: In the database field, it refers to the definition of the organization and structure of the data in the database. It may include the name of the table in the database (such as English name, Chinese name, etc.), table description, field name, Chinese interpretation of the field name, field type, remarks, etc. It can be added, deleted, and modified according to the actual business scenario. This application does not list them one by one here.

[0031] (2) External data: refers to relevant business data organized in a specific business scenario. For example, each table can correspond to different business data. After obtaining the table, the business data corresponding to the table can be obtained.

[0032] The following example illustrates the table structure information and plug-in data, as follows:

[0033] Context Start

[0034] The generated table names and table fields are all from the following tables:

[0035] Table name: XXXXXXX

[0036] Chinese name of the table: XXXXX

[0037] Table description: XXXXXX

[0038] Field: Field 1 [Chinese meaning of field 1], Field 2 [Chinese meaning of field 2];

[0039] Cheat data: XXXXX;

[0040] Please note that the current date is XXXX

[0041] End of context

[0042] (3) Chain of Thought (CoT): This refers to the process of breaking down a logically complex problem into a complete thought process through a series of logically related thoughts. In the field of artificial intelligence, CoT is used to break down complex problems into simpler ones through a series of internal reasoning processes, guiding the model to improve its reasoning ability for complex problems through detailed reasoning steps.

[0043] For example, let's provide a prompt word Prompt as input:

[0044] You are an SQL analysis expert. Based on the provided table structure information, please reason and analyze the thought process from SQL query requirements to SQL statements step by step. Analyze the specific filtering conditions, required aggregation functions, and whether grouping and sorting are required for the SQL query requirements. Be careful not to omit SQL restrictions. Your answer should be within 300 words.

[0045] The structural information of the table includes: {table_shcema};

[0046] Table name: xxxxxxxx

[0047] Chinese name of the table: xxxxxxxx

[0048] Table Description: xxxxxxxx

[0049] Field: xxxxxxxx

[0050] Cheats knowledge: XXXXX;

[0051] Please note that the current date is XXXX

[0052] Query statement: Count the number of new male users in June

[0053] SQL statement: select count(distinct user_id) from dwd.dwd_ip_user_info_dfwhere gend er_cd='M'and substr(reg_date,1,6)='202406'

[0054] Assume that the output of the model is:

[0055] According to user query requirements, the number of users needs to be queried. The specific filtering conditions are new users added in June and male users. No specific year is specified, and the default is June 2024. The registration date field should be used for new users, so it is expressed as substr(reg_date,1,6) = '202406'; male users need to be judged based on the gender field gender_cd, and male is expressed as gender_cd = 'M'. The user number should be counted using the user's unique code and duplicates need to be removed, so it is expressed as count(distinctuser_id).

[0056] It should be noted that the above explanations (1)-(3) are only randomly compiled examples for the purpose of facilitating understanding and are not intended to be limiting. Any other extensions and expansions based on these explanations fall within the scope of protection of this application.

[0057] (4) Token: Also known as word unit, it is the basic unit of model input and output. It can be understood as the smallest unit in natural language processing, or the smallest unit in the input sequence or output sequence of natural language processing. These units can be words, numbers, symbols or punctuation marks, etc., and this application does not limit them.

[0058] (5) Epoch: A round or training cycle refers to the process in which the entire training dataset is completely processed by the model. In other words, the model has learned all the samples in the training dataset once. This is called an epoch. An epoch usually contains multiple steps or batches, and there is a one-to-one correspondence between multiple steps and multiple batches.

[0059] (6) Batch Size: Batch size refers to the number of training samples that are fed into the model at one time during training. Generally, the model is not fed all training samples at once, but trained in batches. The number of training samples in each batch is the batch size.

[0060] (7) Training Batch: Corresponding to the Batch Size above, it represents the training samples input into the model each time during the training process. Each training batch can then be used for forward propagation, loss calculation, backpropagation, and parameter updates. Generally speaking, an epoch usually contains multiple training batches. In this case, these multiple batches can be represented by Batchs, which refers to the number of training batches of the model in an epoch.

[0061] (8) Step: This refers to the operation of updating the model parameters in an epoch. In layman's terms, each time a batch is trained, a step is completed. Generally speaking, an epoch usually contains multiple steps, which can be represented by Steps, which refers to the number of steps in model training in an epoch.

[0062] (9) Iteration: It refers to the operation of a step in the training process. Generally speaking, one epoch usually requires multiple iterations of the model. In this case, multiple iterations can be represented by iterations, which refers to the number of times the model is iteratively trained in one epoch. One iteration generally includes the process of forward propagation, loss calculation, backpropagation, and parameter update in one step. Therefore, in general, step and iteration can be considered to have the same meaning, and this application does not distinguish between the two.

[0063] For the sake of understanding, the parameters in (5) to (9) above are explained below with reference to specific examples.

[0064] Suppose there is a training dataset with 1500 training examples. Training all 1500 training examples once is one epoch. Because the data size is large (1500 training examples may not be considered large in practice; this is just an example assumption), we want to divide it into multiple training batches and train them in batches. Assuming each batch requires 100 examples, with a batch size of 100, we need to train 15 batches to fully train this data, with a batch size of 15. Each time a batch is trained, it completes a step, so the number of steps and iterations is also 15. This example illustrates training 1500 training examples once (one epoch). However, in general, we will need to train multiple times, meaning multiple epochs. For example, suppose we need to train for three epochs, which is equivalent to training the 1500 training examples three times. Then, the total number of steps and iterations will change with the change of epoch, and both will become 45. However, the batch size will still be 15, because the batch size is viewed from the perspective of each epoch and has nothing to do with the specific size of the epoch.

[0065] (10) NL2SQL (Natural Language to SQL): This is a technology that converts natural language queries into Structured Query Language (SQL). Through the NL2SQL principle, we can convert natural language queries entered by users into SQL statements that the database can understand and execute, thereby realizing the interaction between natural language and database. For example, a query expressed in natural language, such as "Find all customers who purchased in 2023", can be converted into an SQL query statement that can be executed by the database system, such as "SELECT * FROM customers WHERE purchase_date BETWEEN '2023-01-01' AND '2023-12-31'".

[0066] (11) Softmax: Also known as the normalization function, it is commonly used in machine learning and deep learning models, especially in the output layer of classification tasks. It is used to convert the original output of the model (usually logical values ​​​​logits) into a probability form. It can also be understood as converting each element of the model output into a probability distribution.

[0067] (12) Transformer model: It is one of the most important architectures in the field of deep learning in recent years, and has performed particularly well in natural language processing (NLP) tasks. It is a neural network based on the self-attention mechanism. For details, see Figure 1 , Figure 1 A schematic diagram of the structure of a Transformer model provided in an embodiment of the present application:

[0068] like Figure 1 As shown, the model includes an encoder and a decoder, and the Encoder and Decoder layers may include an M1 layer. This application does not limit the specific value of M1. This application uses one as an example for explanation. For the encoder, the input is word-embedded and positional encoding is added to obtain a first input vector; the input vector is then processed by a multi-head attention mechanism to obtain a first output vector after attention processing; the first input vector and the first output vector after attention processing are then residually connected and added, and then layer normalization is performed, and then input into the feed-forward neural network for processing to obtain the output of the encoder, which is a hidden state sequence.

[0069] Then for the decoder, its task is to convert the hidden state sequence output by the encoder into a target sequence. First, the target sequence will be shifted right by one bit as the input of the decoder, and then the input will be embedded and positional encoding will be added to obtain the second input vector; then the second input vector will be processed by the masked multi-head attention mechanism to obtain the second output vector after attention processing; then the second input vector and the second output vector will be residually connected and added, and then layer normalized to obtain the third output vector; then the third output vector and the hidden state sequence output by the encoder will be multi-headed to obtain the fourth output vector, where the query comes from the output of the previous layer of the decoder, and the key and value come from the output of the encoder to help the decoder refer to the relevant information of the input sequence when generating the target sequence; then the fourth output vector and the third output vector will be residually connected and added, and then layer normalized to obtain the fifth output vector; then the fifth output vector is input into the feed-forward neural network (Feed-forward neural network). NeuralNetwork) to obtain the sixth output vector; the sixth output vector and the fifth output vector are then residually connected Add and layer normalization Norm processing is performed to obtain the seventh output vector; the seventh output vector is then input into the linear layer Linear for linear processing, and then normalized Softmax processing is performed to obtain the output of the decoder, which is a probability distribution corresponding to the input, and then the target sequence of the model output can be obtained based on the probability distribution.

[0070] At present, many variants and extended models have been derived from the Transformer model. For example, the encoder part of the Transformer is used to learn contextual information through bidirectional self-attention, focusing on natural language understanding tasks. In this case, the model can be understood as an encoder-only structure; the decoder part of the Transformer is used to generate text through autoregression, focusing on natural language generation tasks. In this case, the model can be understood as a decoder-only structure.

[0071] (13) Model fine-tuning: This refers to the process of making local adjustments and optimizations based on a pre-trained model for a specific task or field. It improves the applicability and completeness of the model in a specific task or industry by using specialized datasets or methods. Currently, model fine-tuning is categorized according to different classification criteria. In the embodiments of this application, it can be summarized into two methods: full parameter fine-tuning and partial parameter fine-tuning, which will be explained in detail below.

[0072] (14) Instruction Tuning: refers to the use of data in the form of natural language to fine-tune the parameters of the pre-trained model so that it has the ability to follow instructions. It is also called supervised fine-tuning, and this application does not make any distinction between them. In addition, the full parameter fine-tuning and partial parameter fine-tuning mentioned above can both be instruction fine-tuning, which can be respectively called full parameter instruction fine-tuning and partial parameter instruction fine-tuning. The following embodiments will also mainly explain the model fine-tuning method of the embodiments of this application in the form of instruction fine-tuning.

[0073] (15) Full Parameter Fine-Tuning: This is a type of model fine-tuning, which refers to the training and optimization of all parameters (weights) of the model during the training process. Full parameter fine-tuning can be used for various tasks, especially when the task is highly specific. By adjusting all model parameters, the model can better adapt to the needs of the specific task, which can help the model adapt from beginning to end. This is better than partial parameter fine-tuning. However, fine-tuning all model parameters requires a lot of computing resources and has high computational overhead, especially on large-scale pre-trained models (such as GPT and BERT). If the training dataset is small, because the model may overfit the training data, fine-tuning all model parameters may lead to overfitting and fail to generalize well to unseen data.

[0074] (16) Partial Fine-Tuning: This is a type of model fine-tuning that only trains and optimizes certain layers or some parameters of the model, while the parameters (weights) of other layers remain unchanged. Doing so can significantly reduce the amount of computation and computational overhead during training, and significantly improve training efficiency; and the parameters (weights) of other layers remain unchanged, which can effectively avoid overfitting when the amount of data is small or the training time is insufficient; and if the new task is similar to the original task, partial parameter fine-tuning can fully utilize the features of other layers of the model and quickly adapt to the new task requirements. However, if the new task is very different from the original task, fine-tuning only some parameters may not be able to fully adapt to the characteristics of the new task; and because some parameters are not optimized, the final model performance may not be as good as full parameter fine-tuning. For example, the following mainly introduces several types of partial parameter fine-tuning:

[0075] 1) Freezing Layers: This refers to updating parameters of only some layers during fine-tuning, without updating the parameters of certain layers. For example, when the first few layers of a pre-trained model (usually the feature extraction layers) have learned valid representations, these layers can be frozen, and only the last few layers can be fine-tuned. This can reduce training time and computing resource consumption, avoid overfitting, and improve training efficiency.

[0076] 2) Layer-wise fine-tuning: This refers to updating the weights of certain layers in the model layer by layer, for example, starting from the bottom layer (feature extraction layer) and gradually expanding to the top layer (decision-making layer). This approach usually gradually unfreezes the layers of the model, fine-tuning specific layers at each stage. It can optimize at a more detailed level and ensure that the model gradually adapts to the new task.

[0077] 3) Low-Rank Adaptation (LoRA): It is a technology for fine-tuning large models. It updates the parameters of the pre-trained model by introducing low-rank matrices. For example, low-rank matrices are usually introduced for certain weight matrices (such as the weight matrix in the Transformer model), and then only the parameters of the low-rank matrix are trained, rather than the entire weight matrix. This significantly reduces the amount of parameters that need to be trained while maintaining model performance, thereby reducing the demand for computing resources and improving training efficiency. It should be noted that LoRA fine-tuning has also derived a variety of variants, and all variants generated based on it also belong to the LoRA fine-tuning mentioned herein in this application.

[0078] (17) Query: Also known as query description. In this application, query description and query statement have the same meaning and there is no need to distinguish them.

[0079] (18) Structured Query Language (SQL): is a database query and programming language used to access data and query, update, and manage relational database systems. In this application, Structured Query Language and SQL query statements have the same meaning and are not differentiated.

[0080] As can be seen from the above background, the current techniques used for fine-tuning models mainly include fine-tuning all parameters or fine-tuning some parameters. Full parameter fine-tuning enables the model to quickly adapt to new tasks and capture key task characteristics. The fine-tuned model performs well, but consumes a lot of computing resources. Partial parameter fine-tuning, on the other hand, reduces the number of parameters used in the fine-tuning process and reduces computing resource consumption, but the performance of the fine-tuned model is poor.

[0081] Because in the process of model fine-tuning, generally speaking, the faster the model parameters change in the previous training step, the larger the loss change (decline) is, and the slower the model parameters change in the later training step, the smaller the loss change (decline) is, and then gradually converge. Therefore, in order to overcome the defects of the prior art, in an embodiment of the present application, it can be considered to determine the first i training batches and the last Ni training batches in the N training batches based on a preset ratio and N, and then use full parameter fine-tuning in the first part of the steps, i.e., corresponding to the first i training batches, so that the model can learn the instructions as quickly as possible to improve the performance (stability) of the model, and then use partial parameter fine-tuning for the first model after full parameter fine-tuning in the latter part of the steps, i.e., corresponding to the last Ni training batches, so as to save computing resource consumption of the electronic device while being as close as possible to the effect of full parameter fine-tuning. Alternatively, in the process of fine-tuning the model based on N training batches, it can also be determined based on the convergence speed corresponding to the training batches whether to adopt full parameter fine-tuning or partial parameter fine-tuning for the model, that is, whether the convergence speed corresponding to the training batch is greater than a preset threshold is determined. If it is greater, the model is fine-tuned based on the loss corresponding to the training batch, and the convergence speed corresponding to the next training batch is calculated, until it is determined that the convergence speed corresponding to a training batch is less than the preset threshold, and the first model is obtained, and then full parameter fine-tuning is no longer adopted. The training batch with a convergence speed less than the preset threshold is assumed to be the i+1th training batch, which means that the convergence speeds corresponding to the first i training batches of the N training batches are all greater than the preset threshold, and full parameter fine-tuning is adopted for the model, so that the model can learn the instructions as quickly as possible, and then partial parameter fine-tuning is adopted for the next Ni training batches to fine-tune the first model, so as to save computing resource consumption of electronic equipment while achieving the effect of adopting full parameter fine-tuning as close as possible. In comparison, the method of the present application makes the performance of the model more stable than the method of fine-tuning all partial parameters, consumes less computing resources of the electronic device than the method of fine-tuning all full parameters, and makes the electronic device more efficient when fine-tuning the model, thus achieving a good balance between the computing resource consumption of the electronic device and the model performance.

[0082] The present application is explained below with reference to specific embodiments, as follows:

[0083] It should be noted that, in combination with the elaboration of the above content, the following embodiments of the present application mainly take the decoder architecture (i.e., decoder-only structure) in the Transformer model as the model, all parameter fine-tuning and partial parameter fine-tuning as instruction fine-tuning, and partial parameter fine-tuning as LoRA fine-tuning as an example to explain the model fine-tuning in the embodiments of the present application, as follows:

[0084] First of all, it is necessary to introduce how to construct a training data set. Since the embodiments of the present application are mainly illustrated in the form of instruction fine-tuning for both full parameter fine-tuning and partial parameter fine-tuning, the training data set is also constructed in the form of instructions (also referred to as an instruction data set at this time), that is, the training data set includes multiple training samples, and these multiple training samples can be divided into multiple training batches; and these multiple training samples can include training samples of at least one task type, that is, multiple training samples can be training samples of the same task type, or they can be training samples under multiple task types, thereby realizing model fine-tuning learning of multiple tasks, and in this case, these multiple training samples can be shuffled and then divided into multiple training batches, so that it can be ensured that the training samples in each training batch include training samples of at least one task type.

[0085] Furthermore, due to different application scenarios, the training samples in the constructed instruction data set will also be different, and the embodiment of the present application is mainly explained by taking the training sample as text data as an example. The following mainly takes the NL2SQL scenario as an example to construct the instruction data set in this scenario, and the task type can include multiple task types. The embodiment of the present application is mainly explained by including the first task type and the second task type as an example, wherein the first task type is used to generate a structured query language corresponding to the query statement, and the second task type is used to generate a structured query language and a thought chain corresponding to the query statement, wherein the thought chain is used to characterize the analysis process of generating a structured query language corresponding to the query statement. The following introduces the construction methods of the training samples of the first task type and the training samples of the second task type, specifically:

[0086] (1) Training samples of the first task type: These samples are mainly constructed based on part or all of the instruction template corresponding to the first task type, the structure information of the obtained table, the plug-in data corresponding to the table, the query statement, etc. In this case, the real SQL statement corresponding to the query statement in the training sample is used as the real label. An example of a training sample of the first task type is given below for illustration, as follows:

[0087]

[0088] For this example, assume the output of the model is:

[0089] output: select count(distinct contra_no) from dsst.gdl_acct_contra_detwhere dt="20241007" and if_in_collection="Y".

[0090] It can be seen that the SQL statement corresponding to the query statement Query is generated, and the model can be fine-tuned based on the output of the model and the true label. The specific fine-tuning method is not elaborated here, and please refer to the specific explanation below.

[0091] (2) Training samples of the second task type: mainly constructed based on part or all of the instruction template corresponding to the second task type, the structural information of the obtained table, the plug-in data corresponding to the table, the query statement, the corresponding preset thinking chain, etc. At this time, the real SQL statement and the preset thinking chain corresponding to the query statement in the training sample are used as real labels. It should be noted that the thinking chain in the training sample under the second task type is generated by the pre-training model based on the instruction data constructed according to the query statement and the structural information of the table. Please refer to the above-mentioned example of the thinking chain for details, which will not be repeated here. An example of a training sample of the first task type is given below for illustration, as follows:

[0092]

[0093]

[0094] For this example, assume the output of the model is:

[0095] Output: Based on the user query requirements, we first need to identify users with a login date of XXXX and a login channel number of XXXXX. This is achieved through a subquery using the fields login_date and login_chan_no, and only considers users with a successful login status, represented by login_status = 'SUCCESS'. Secondly, we count the number of users whose expiration date is before XXXX. This is achieved in the main query using the field ovdue_dt <= 'xxx'. To associate logged-in users with expired user information, we use an inner join to connect the two tables. Based on the matching of unique_id and union_id, we ensure that the target user group is counted. Finally, we use count(distinct union_id) to count the number of users after deduplication, ensuring that each user is counted only once. The generated sql is: select count(union_id) from finance_mart.fac_m_loan_ovdue awhere ovdue_dt<='xx'inner join(select distinct unique_id from dwd.dwd_ip_user_login_det_di where login_dat e='xx'and login_chan_no='xxx'and login_status='SUCCESS')b on a.union_id=b.unique_id.

[0096] It can be seen that what is generated is the SQL statement corresponding to the query statement and the thinking chain for generating the SQL statement. Then, the model can be fine-tuned based on the output of the model and the true label. The specific fine-tuning method is not elaborated here. Please refer to the specific explanation below.

[0097] It should also be noted that the above training sample examples are only provided for ease of understanding and are not limiting. They can be adjusted according to specific usage requirements and the content can be adjusted according to different scenarios. They will not be explained one by one here.

[0098] Furthermore, after constructing the training dataset, the training dataset can be divided into multiple training batches, which will not be described here. The model can then be fine-tuned based on the multiple training batches, as follows:

[0099] See Figure 2 , Figure 2 This is a flow chart of a data processing method provided in an embodiment of the present application. The method is applied to an electronic device, and the embodiment of the method includes but is not limited to steps S201-S204:

[0100] S201. For N training batches of the model, based on a preset ratio and N, determine the first i training batches and the last Ni training batches in the N training batches.

[0101] S202: Based on the losses corresponding to the first i training batches, fine-tune all parameters of the model to obtain a first model.

[0102] In an embodiment of the present application, a training data set can be constructed in advance, which will not be described in detail here; then, the model can be fine-tuned for one or more epochs based on the training data set, wherein, for each epoch, N can be determined based on the total number of training samples in the training data set and the batch size Batch Size; then, all training samples in the training data set can be divided based on N to obtain N training batches, where the number of training samples in each training batch is BatchSize. Of course, optionally, all training samples in the training data set can be randomly shuffled before being divided, which is not limited in this application.

[0103] In an embodiment of the present application, a preset ratio can be obtained in advance, and the preset ratio is used to represent the proportion of training batches used for full parameter fine-tuning or partial parameter fine-tuning of the model in N training batches; then, based on the preset ratio and N, the first i training batches and the last Ni training batches can be determined, that is, the value of i can be determined, where 1≤i<N. For example, if the preset ratio is used to represent the proportion of N training batches used for full parameter fine-tuning of the model, assuming it is 20%, then i can be obtained by N*20%, that is, the first N*20% training batches and the last NN*20% training batches are determined; similarly, if the preset ratio is used to represent the proportion of N training batches used for partial parameter fine-tuning of the model, assuming it is 80%, then i can be obtained by N*(1-80%), that is, the first N*(1-80%) training batches and the last NN*(1-80%) training batches are determined. In this case, the convergence rates corresponding to the first i training batches, determined based on the preset ratio, are generally higher than the preset threshold, while the convergence rate corresponding to the i+1th training batch is generally lower than the preset threshold. Therefore, after determining i, all model parameters can be fine-tuned based on the losses corresponding to each of the first i training batches in the N training batches, yielding the first model. It should be noted that the method for determining the losses corresponding to each training batch is not discussed here; details are provided below.

[0104] S203. During fine-tuning based on N training batches of the model, if the convergence speed corresponding to the j-th training batch is greater than a preset threshold, fine-tune all parameters of the model based on the loss corresponding to the j-th training batch, and determine the convergence speed corresponding to the j+1-th training batch, until it is determined that the convergence speed corresponding to the i+1-th training batch is less than the preset threshold, thereby obtaining a first model.

[0105] In an embodiment of the present application, in addition to obtaining the first model according to the above steps S201-S202, the relationship between the convergence speed corresponding to the jth training batch and the preset threshold value can be determined during fine-tuning based on N training batches of the model. If the convergence speed corresponding to the jth training batch is greater than the preset threshold value, the model is fine-tuned in all parameters based on the loss corresponding to the jth training batch, and the convergence speed corresponding to the next training batch, i.e., the j+1th training batch, is determined, until it is determined that the convergence speed corresponding to the i+1th training batch is less than the preset threshold value, and the first model is obtained, i.e., at this time, the convergence speed corresponding to the i-th training batch is greater than the preset threshold value, and the convergence speed corresponding to the i+1th training batch is less than the preset threshold value, where j>1. For the first training batch among the N training batches, the model can be fine-tuned in all parameters directly based on the loss corresponding to the first training batch.

[0106] Before determining the relationship between the convergence speed corresponding to the jth training batch and the preset threshold, the loss corresponding to the jzth training batch and the loss corresponding to the jth training batch can also be obtained, where the jth training batch is one of the N training batches, j ≥ z + 1, z ≥ 1. Then, based on the loss corresponding to the jzth training batch and the loss corresponding to the jth training batch, the convergence speed corresponding to the jth training batch is determined, where the convergence speed corresponding to the jth training batch is used to characterize the magnitude of the loss change from the jzth training batch to the jth training batch.

[0107] Exemplarily, based on the loss corresponding to the jz-th training batch and the loss corresponding to the j-th training batch, the loss difference corresponding to the j-th training batch is determined, wherein the loss difference can be the absolute value of the difference between the loss corresponding to the jz-th training batch and the loss corresponding to the j-th training batch; then, based on the loss difference corresponding to the j-th training batch and z, the convergence speed corresponding to the j-th training batch is determined, for example, the convergence speed corresponding to the j-th training batch is the ratio of the loss difference corresponding to the j-th training batch and z.

[0108] Then, the relationship between the convergence speed corresponding to the j-th training batch and the preset threshold is determined. If the convergence speed corresponding to the j-th training batch is greater than the preset threshold, all parameters of the model are fine-tuned based on the loss corresponding to the j-th training batch, and the convergence speed corresponding to the j+1-th training batch is determined, until the convergence speed corresponding to the i-th training batch is greater than the preset threshold and the convergence speed corresponding to the i+1-th training batch is less than the threshold, or in other words, until it is determined for the first time that the convergence speed corresponding to the i+1-th training batch is less than the preset threshold, the first model is obtained. That is to say, if the convergence rate corresponding to the j-th training batch is greater than the preset threshold, the model is fine-tuned for all parameters based on the loss corresponding to the j-th training batch, and then the convergence rate corresponding to the j+1-th training batch is determined until the convergence rate is less than the preset threshold. The first model is obtained, and the training batch when the convergence rate is less than the preset threshold (that is, the first convergence rate is less than the preset threshold) is determined as the i+1-th training batch, and the previous training batch of the training batch when the convergence rate is less than the preset threshold at this time is determined as the i-th training batch, that is, the corresponding values ​​of i and i+1 are determined.

[0109] Of course, there is a special case, that is, the first training batch among N training batches, then there is no 1-z training batches. At this time, the model can be fine-tuned for the first time according to the full parameter fine-tuning based on the loss corresponding to the first training batch; then for subsequent training batches with j>1, the corresponding convergence speed can be judged according to the method of the above embodiment. If the convergence speed is greater than the preset threshold, the model is still fine-tuned in all parameters until the convergence speed is less than the preset threshold, that is, the i+1th training batch is determined, and then the first model can be obtained after the full parameter fine-tuning of the model through the loss corresponding to the first i training batches.

[0110] S204: For the last Ni training batches among the N training batches of the model, fine-tune some parameters of the first model based on the losses corresponding to the last Ni training batches.

[0111] After obtaining the first model based on steps S201-S202 above, the first model can be partially fine-tuned based on the loss corresponding to each of the last N training batches. This process continues until all training samples in the N training batches have been fully processed by the model, completing one epoch. Similarly, model fine-tuning can be performed for multiple epochs based on actual needs. This application only uses one epoch as an example for illustration and is not intended to be limiting. Furthermore, the specific principles of partial parameter fine-tuning are not elaborated here; please refer to the following text for details.

[0112] Similarly, after obtaining the second model based on the method of the above step S203, for the i+1th training batch and subsequent training batches in the N training batches, that is, the last Ni training batches in the N training batches, there is no need to judge the convergence speed corresponding to each training batch. Instead, the first model can be fine-tuned directly by fine-tuning some parameters corresponding to the Ni training batches.

[0113] For example, for N training batches, first, based on the training samples corresponding to the first training batch, determine the loss corresponding to the first training batch; then, based on the loss corresponding to the first training batch, perform the first fine-tuning of the model according to full parameter fine-tuning. Then, based on the training samples corresponding to the second training batch, determine the loss corresponding to the second training batch; then, based on the loss corresponding to the first training batch and the loss corresponding to the second training batch, determine the convergence rate corresponding to the second training batch; assuming that the convergence rate corresponding to the second training batch is greater than a preset threshold, then, based on the loss corresponding to the second training batch, perform the second fine-tuning of the model according to full parameter fine-tuning. Then, by the same token, determine the convergence rate corresponding to the third training batch. Assuming that the convergence rate corresponding to the third training batch is less than the preset threshold, since the convergence rates corresponding to the training batches before the third training batch are all greater than the preset threshold, that is, the convergence rate corresponding to the third training batch is the first to be greater than the preset threshold, then it can be determined that i=2, i+1=3, indicating that the first model is obtained after fine-tuning the model based on the second training batch. Then, starting from the third training batch among the N training batches, that is, the last N-2 training batches among the N training batches, it is necessary to fine-tune the first model directly according to some parameters. There is no need to determine the convergence rate of the last N-2 training batches, nor is there any need to judge the relationship between the convergence rate and the preset threshold.

[0114] It should be noted that currently, either all parameters fine-tuning is used to fine-tune the model, or all parameters fine-tuning is used to fine-tune the model. Both full parameter fine-tuning and partial parameter fine-tuning have their own advantages and disadvantages, which will not be elaborated here. Therefore, in an embodiment of the present application, the preset ratio can be used to determine whether the first i training batches of N training batches adopt full parameter fine-tuning and the next Ni training batches adopt partial parameter fine-tuning. In other words, full parameter fine-tuning is adopted in the first training batch, and then the convergence rate corresponding to each subsequent training batch is determined. The convergence rate represents the change in loss from the previous z steps to the current step. The convergence rate is then compared with a preset threshold. If it is greater than the preset threshold, it means that the loss change is still large, and full parameter fine-tuning can be continued. If it is less than the preset threshold, it means that the loss change is beginning to decrease. In this case, partial parameter fine-tuning can be adopted for the training batch determined to be less than the preset threshold and the remaining training batches thereafter. This is because in the process of model fine-tuning, generally, the model parameters change faster in the earlier steps, and the corresponding loss change (decrease) is larger, while the model parameters change slower in the later steps, and the corresponding loss change (decrease) is smaller, and then gradually converges. Therefore, you can consider using full parameter fine-tuning in the first step to allow the model to learn the instructions as quickly as possible to improve the model's performance (stability). Then, in the second step, use partial parameter fine-tuning on the first model after full parameter fine-tuning to achieve the effect as close as possible to full parameter fine-tuning while saving computing resource consumption. This method makes the model performance more stable than using partial parameter fine-tuning, consumes less computing resources, and is more efficient than using full parameter fine-tuning. It strikes a good balance between computing resource consumption and model performance.

[0115] Furthermore, the following will explain in detail how to determine the loss corresponding to each training batch. The principle is as follows:

[0116] Since N training batches can include training samples of multiple task types, each divided training batch can include training samples of at least one task type among these multiple task types. That is to say, each training sample corresponds to a task type, and the task types corresponding to any two training samples can be the same or different, which will not be repeated here.

[0117] Therefore, for each training batch, we can first determine the prediction probability corresponding to each training sample under each task type in each training batch, that is, we can input each training sample into the model and output the prediction probability corresponding to each training sample under each task type in each training batch. It should be noted that the model of this application mainly takes the decoder-only structure obtained by extending the decoder in the Transformer model as an example, and the number of decoder layers can be M2. This application mainly uses 1 as an example for explanation, so combined with Figure 1 The decoder architecture shown in the embodiment is used to explain the model of this application to determine the prediction probability corresponding to each training sample. Taking one of the training samples as an example, specifically:

[0118] See Figure 3 , Figure 3 This is a schematic diagram of the structure of a model provided in the embodiment of this application. Figure 3 As shown, for each training sample, each training sample is used as the input of the model; then each training sample is word embedded and positional encoding is added to obtain the first feature corresponding to the training sample; then the first feature corresponding to the training sample is processed by the masked multi-head attention mechanism to obtain the second feature corresponding to the training sample; then the first and second features corresponding to the training sample are residually connected and added and then layer normalized to obtain the third feature corresponding to the training sample; then the third feature of the training sample is input to the feed-forward neural network for processing to obtain the fourth feature corresponding to the training sample; then the third and fourth features corresponding to the training sample are residually connected and added and then layer normalized to obtain the fifth feature corresponding to the training sample; then the fifth feature is input to the linear layer for linear processing, and then normalized Softmax processing is performed to obtain the predicted probability corresponding to the training sample, which is generally the probability distribution corresponding to the training sample, and then the final output sequence can be determined based on the predicted probability. Specifically:

[0119] If it is a discriminant classification problem, such as binary classification, multi-classification, etc., then the predicted probability obtained by normalized Softmax processing here can be understood as the predicted probability of the training sample under each classification category, that is, a probability distribution. If it belongs to the classification category, the probability is 1, otherwise it is 0. The corresponding label is the true probability of the training sample under each classification category, and then the classification category with the largest probability in the probability distribution corresponding to the training sample can be determined as the output sequence corresponding to the training sample.

[0120] For generative problems, such as the NL2SQL described above, SQL statements must be generated. Because generative problems are autoregressive, unlike discriminants, which can directly obtain a complete output sequence from a probability distribution obtained through Linear or Softmax processing, they do not output SQL statements all at once. Instead, they gradually predict and generate elements in the output sequence until the complete output sequence, i.e., the SQL statement, is obtained. Specifically:

[0121] For the first element of the output sequence / the first element of the SQL statement (or called word unit, token, which have the same meaning in this application and are not distinguished), that is, at the first time step, based on the fifth feature of the training sample, the probability distribution corresponding to the first element is obtained through Linear and Softmax processing. At this time, the probability distribution represents the probability of the first element under each preset element in the vocabulary, and then the first element can be determined based on the probability distribution corresponding to the first element, such as taking the preset element with the largest probability in the probability distribution as the first element; then, based on the fifth feature of the training sample and the obtained first element, the probability distribution corresponding to the second time step in the output sequence is obtained through Linear and Softmax processing, and then the output of the second time step, that is, the second element of the output sequence, is obtained in the same way. Subsequently, the output of the third time step, the output of the fourth time step, ..., the output of the nth time step, which is the end mark, can be obtained. <end>, which will not be described in detail here. All elements in the output sequence corresponding to the training sample can then be obtained, that is, the complete output sequence is obtained. In short, the fifth feature corresponding to the training sample is input into the fully connected layer of the model (i.e., corresponding to the above-mentioned Linear and Softmax processing). The preset element with the highest probability in the output vocabulary is then used as the first element of the SQL statement. The second element is then predicted based on the first element. The third element is then predicted based on the first and second elements, and so on until the generation is complete. That is, given the first Y elements, to predict the Y+1th element, all elements after the Y+1th element must be masked. It can be seen that the predicted probability corresponding to the training sample obtained by the above-mentioned normalized Softmax processing can now be understood as including the probability distribution corresponding to each element in the output sequence corresponding to the training sample, and the probability distribution corresponding to each element can be understood as the probability under each preset element in the vocabulary. Similarly, the predicted probability corresponding to each training sample under each task type in each training batch can be obtained. This will not be described in detail here.

[0122] Furthermore, based on the predicted probability corresponding to each training sample under each task type in each training batch, the weight corresponding to each task type can be determined, wherein the weight is used to characterize the difficulty of each task type. For example, if the weight is larger, it means that the task type is more difficult, and thus the loss can be prevented from decreasing rapidly, allowing the model to pay more attention to this task type; similarly, the smaller the weight, the simpler the task type, and thus the loss can be reduced rapidly, allowing the model to pay less attention to this task type. For example:

[0123] First, based on the predicted probability corresponding to each training sample under each task type in each training batch, the average probability corresponding to each task type in each training batch is determined. For example, the predicted probability corresponding to each training sample under each task type in each training batch is summed to obtain the first probability corresponding to each task type in each training batch.

[0124] Then, based on the first probability corresponding to each task type in each training batch and the number of training samples under each task type in each training batch, the average probability corresponding to each task type in each training batch is obtained. For example, it can be the ratio of the two. In this case, the value range of the average probability is 0 to 1. For example, the average probability corresponding to the i-th task type in the k-th training batch can be obtained by the following formula (1):

[0125]

[0126] Among them, P ki represents the average probability corresponding to the i-th task type in the k-th training batch, M ki represents the number of training samples corresponding to the i-th task type in the k-th training batch, P kij It represents the predicted probability corresponding to the jth training sample under the i-th task type in the k-th training batch.

[0127] Then, based on the average probability corresponding to each task type in each training batch, the adjustment factor corresponding to each task type in each training batch is determined, wherein the adjustment factor is negatively correlated with the average probability. There are many ways to determine the adjustment factor corresponding to each task type in each training batch by the average probability corresponding to each task type in each training batch and satisfy the negative correlation between the adjustment factor and the average probability, which are not limited in this application. For example, the adjustment factor corresponding to the i-th task type in the k-th training batch can be obtained by the following formula (2):

[0128] γ ki =g×(1-P ki ) (2)

[0129] Alternatively, the adjustment factor corresponding to the i-th task type in the k-th training batch can also be obtained by the following formula (3):

[0130]

[0131] Among them, the kth training batch is any one of the N training batches, γ ki represents the adjustment factor corresponding to the i-th task type in the k-th training batch, g represents the first preset parameter, e() is the exponential function, P ki represents the average probability corresponding to the i-th task type in the k-th training batch.

[0132] Then, based on the average probability and adjustment factor corresponding to each task type in each training batch, the weight corresponding to each task type in each training batch can be determined, wherein the weight is negatively correlated with the average probability and positively correlated with the adjustment factor. There are many ways to construct the weight corresponding to each task type and satisfy the relationship that the weight is negatively correlated with the average probability and positively correlated with the adjustment factor through the average probability and adjustment factor corresponding to each task type, which is not limited by this application. For example, the weight corresponding to the i-th task type in the k-th training batch can be obtained by the following formula (4):

[0133]

[0134] Alternatively, the weight corresponding to the i-th task type in the k-th training batch can be obtained by the following formula (5):

[0135]

[0136] Among them, W ki represents the weight corresponding to the i-th task type in the k-th training batch, γ ki represents the adjustment factor corresponding to the i-th task type in the k-th training batch, P ki represents the average probability corresponding to the i-th task type in the k-th training batch.

[0137] It can be seen that if the first probability corresponding to each task type in each training batch is larger, the corresponding average probability will be larger. If it tends to 1, it means that the training samples corresponding to the task type in the training batch belong to simple tasks and are easy to fit. In this case, the adjustment factor can be appropriately reduced, and the weight corresponding to the task type can be reduced, so that the model pays less attention to the training samples of this task type; and when the value of the average probability is smaller, such as it tends to 0, it means that the training samples corresponding to the task type in the training batch belong to difficult tasks and are not easy to fit. In this way, the adjustment factor can be appropriately increased, and the weight corresponding to the task type can be increased, so that the model pays more attention to the training samples of this task type. This dynamic adjustment method allows the model to dynamically pay attention to difficult and easy tasks, that is, to increase attention to difficult tasks and reduce the consumption of simple tasks, thereby ensuring the efficiency and accuracy of model learning.

[0138] It should be noted that this application does not limit the specific method of determining the weight corresponding to each task type in each training batch. As long as the weight is negatively correlated with the average probability and positively correlated with the adjustment factor, it is within the scope of protection of this application.

[0139] Furthermore, the loss corresponding to each training batch can be determined based on the weight corresponding to each task type in each training batch and the predicted probability corresponding to each training sample under each task type in each training batch. For example, the loss corresponding to the kth training batch can be obtained by the following formula (6):

[0140]

[0141] Among them, Loss k represents the loss corresponding to the kth training batch, H k Indicates the number of task types corresponding to the kth training batch, M ki represents the number of training samples corresponding to the i-th task type in the k-th training batch, γ ki represents the adjustment factor corresponding to the i-th task type in the k-th training batch, P kij represents the predicted probability corresponding to the jth training sample under the i-th task type in the k-th training batch, W ki represents the weight corresponding to the i-th task type in the k-th training batch.

[0142] It can be seen that the greater the predicted probability corresponding to the training samples under each task type in each training batch, the greater the first probability corresponding to each task type in each training batch, and correspondingly, the greater the second probability. Among them, the closer the value of the second probability is to 1, the more it means that the training samples corresponding to the task type in the training batch belong to simple tasks and are easy to fit, so the adjustment factor can be appropriately reduced; and when the value of the second probability is closer to 0, the more it means that the training samples corresponding to the task type in the training batch belong to difficult tasks and are not easy to fit, so the adjustment factor can be appropriately increased. This dynamic adjustment method allows the model to dynamically focus on difficult and easy tasks, that is, to increase attention to difficult tasks and reduce the consumption of simple tasks, thereby ensuring the efficiency and accuracy of model learning.

[0143] Furthermore, after determining the loss corresponding to the training batch, the model can be fine-tuned in all parameters or in part based on the loss corresponding to the training batch, that is, based on the loss corresponding to each training batch in the first i training batches among the N training batches, the model is fine-tuned in all parameters to obtain a first model, and the full parameter fine-tuning is not described here; then, based on the loss corresponding to each training batch in the last Ni training batches among the N training batches, the first model is fine-tuned in part. It should be noted that, whether it is full parameter fine-tuning or partial parameter fine-tuning, the fine-tuning based on the current training batch is performed on the model fine-tuned based on the previous training batch. The following mainly takes the LoR A fine-tuning in the partial parameter fine-tuning as an example to illustrate the example of partial parameter fine-tuning of the model of this application (i.e., the Decoder-only structure), and takes any training batch such as the i-th training batch as an example, as follows:

[0144] See Figure 4 , Figure 4 This is a schematic diagram of fine-tuning some parameters of a model provided in an embodiment of the present application. Figure 4 As shown, Figure 3 Taking the model structure shown as an example, the model structure is not elaborated here; some parameter fine-tuning of this application is mainly for the fine-tuning of the initial model weights in each linear layer Linear in the Masked Multi-head Attention in the Decoder-only model, namely Wq0 (indicating the model weight corresponding to the query q), Wk0 (indicating the model weight corresponding to the key k), and Wv0 (indicating the model weight corresponding to the value v). The parameters of other layers remain unchanged.

[0145] like Figure 4 As shown, assuming that the rank corresponding to the input vector x (i.e., corresponding to the first feature mentioned above) is dm (indicating the input or output dimension of the model, which can also be represented by the number of columns here), taking Wq0 as an example, the dimension corresponding to Wq0 is dm×dq (where dq represents the dimension of the query q. Generally speaking, dq=dm, which is not distinguished here), a branch corresponding to Wq0 is established, that is, Wq0 is split, and the matrix A and matrix B corresponding to Wq0 can be obtained, where matrix A can be initialized using a Gaussian distribution, and matrix B is initialized to zero. At this time, the rank of matrix A is dr (indicating the number of columns of matrix A).

[0146] Alternatively, when determining the matrix A and the matrix B, the gradient matrix (assuming it is G) corresponding to the i-th training batch can also be determined based on the loss corresponding to the i-th training batch; then, based on the gradient matrix, the matrix A and the matrix B are initialized. Specifically, the gradient matrix is ​​subjected to singular value decomposition. The specific decomposition principle refers to formula (3):

[0147] G=USV T (3)

[0148] Among them, G represents the gradient matrix, U represents the left singular matrix, V T Represents the transpose of the right singular matrix, and S represents a diagonal matrix. Furthermore, matrix A can be initialized based on the first dr columns (i.e., columns 1 to dr) of the left singular matrix, and matrix B can be initialized based on columns d(r+1) to dr1 of the left singular matrix, where dr1-d(r+1)=dr. In this case, the dimension of matrix A is dm×dr, and the dimension of matrix B is dr×dq, and dr is much smaller than the minimum of dm and dq, that is, dr is low rank.

[0149] Then, fine-tune based on Wq0, matrix A, and matrix B to obtain the updated weight matrix (denoted as Wq) corresponding to Wq0. In this case, Wq = Wq0 + BA. During fine-tuning, Wq0 remains unchanged, and only the parameters in matrix A and matrix B need to be trained. After obtaining the updated Wq, the forward propagation process based on the next training batch is based on the updated model weight Wq of the previous training batch. That is, it needs to be multiplied by the input training x corresponding to the training batch to obtain the corresponding h = Wq0*x + BA*x, and then self-attention processing is performed.

[0150] It can be seen that if full parameter fine-tuning is used, the amount of fine-tuning parameters is dm×dm; if partial parameter fine-tuning is used, the amount of fine-tuning parameters is only dm×dr+dr×dq, and dr is much smaller than the minimum value of dm and dq, that is, dr is low-rank, so the amount of training parameters is greatly reduced and the efficiency of model training is accelerated.

[0151] It should be noted that Figure 4 This description uses Wq0 fine-tuning as an example. The principles for fine-tuning Wk0 and Wv0 are similar to those for Wq0 and will not be elaborated on here. Furthermore, the above description uses LoRA fine-tuning as an example, but is not intended to be limiting. Other methods for fine-tuning parameters can also be used, and will not be detailed here.

[0152] It can be seen that in the embodiment of the present application, N training batches for the model are first obtained; then, the preset ratio set above can be used to determine whether the first i training batches in the N training batches adopt full parameter fine-tuning and the next Ni training batches adopt partial parameter fine-tuning; in other words, full parameter fine-tuning is adopted for the first training batch, and then for each subsequent training batch, the convergence rate corresponding to each training batch is determined, and the convergence rate represents the change in loss from the previous z steps to the current step. The convergence rate is then compared with a preset threshold. If it is greater than the preset threshold, it means that the loss change is still large, and full parameter fine-tuning can continue to be adopted. If it is less than the preset threshold, it means that the loss change is beginning to decrease, and partial parameter fine-tuning is adopted for the training batch less than the preset threshold and subsequent training batches. This is because in the process of model fine-tuning, generally, the model parameters change faster in the earlier steps, and the corresponding loss change (decrease) is larger, while the model parameters change slower in the later steps, and the corresponding loss change (decrease) is smaller, and then gradually converges. Therefore, you can consider using full parameter fine-tuning in the first step to allow the model to learn the instructions as quickly as possible to improve the performance (stability) of the model. Then, in the second step, use partial parameter fine-tuning on the first model after full parameter fine-tuning to achieve the effect as close as possible to full parameter fine-tuning while saving computing resource consumption. That is, this method makes the performance of the model more stable than using partial parameter fine-tuning, and consumes less computing resources and is more efficient than using full parameter fine-tuning. It strikes a good balance between computing resource consumption and model performance.

[0153] In addition, when calculating the loss corresponding to each training batch, since the training data set may include training samples of multiple task types, the adjustment factor corresponding to each task type in each training batch is determined by the predicted probability corresponding to the training samples under each task type in each training batch. Specifically, the larger the predicted probability, the simpler the training samples corresponding to the task type in the training batch are, and they are easy to fit. In this case, the adjustment factor can be appropriately reduced; and the smaller the predicted probability, the difficult the training samples corresponding to the task type in the training batch are, and they are not easy to fit. In this case, the adjustment factor can be appropriately increased. This dynamic adjustment method allows the model to dynamically focus on difficult and easy tasks, that is, to increase attention to difficult tasks and reduce the consumption of simple tasks, thereby ensuring the efficiency and accuracy of model learning.

[0154] Furthermore, after fine-tuning the model according to the above embodiment until the model converges, application reasoning can be performed based on the trained model, i.e., the second model. Figure 5 , Figure 5 A flow chart of another data processing method provided in an embodiment of the present application; the method is applied to an electronic device, and the method includes but is not limited to steps S501-S502:

[0155] S501: Obtain a first instruction, where the first instruction includes a first query statement;

[0156] S502: Generate a structured query language corresponding to the first query statement through the second model based on the task type corresponding to the first instruction.

[0157] The second model is obtained based on the data processing method embodiment provided above, that is, based on the losses corresponding to the last Ni training batches in the above N training batches, a model is obtained by fine-tuning some parameters of the first model. The specific principles are not described here. It should be noted that the electronic device can also perform the above Figure 2 The corresponding steps in the embodiment will not be repeated here.

[0158] The present application is described below with reference to the accompanying drawings. Figure 5 The scenario corresponding to the embodiment is the NL2SQL scenario. For details, see Figure 6 , Figure 6 A schematic diagram of a data processing scenario provided by an embodiment of the present application. The schematic diagram of the scenario includes a user device and an electronic device, wherein the electronic device is deployed with the fine-tuned model in the embodiment of the present application, namely the second model, and the electronic device can be a terminal device or a server. Figure 6 The electronic device is used as an example for explanation. Then, the user can enter the generation interface for the NL2SQL scenario on the user device. Then, the user can enter the first instruction (i.e., input sequence) in the generation interface of the user device. Assume that the first instruction is as follows:

[0159] Input: You are a text-to-SQL generator. Your main goal is to assist users in converting input text into correct SQL statements as much as possible.

[0160] Context Start

[0161] The generated table names and table fields are all from the following tables:

[0162] Table name: dsst.gdl_acct_contra_det

[0163] Chinese name of the table: User Contract Details Table

[0164] Table Description:XXXXXX

[0165] Field: XXXXXXXX;

[0166] Cheat data: XXXXX;

[0167] Please note that the current date is 20241008

[0168] End of context

[0169] Q: Please help me check the number of contracts signed yesterday.

[0170] answer:

[0171] The user device can then send a first instruction to the electronic device; accordingly, the electronic device can receive the first instruction input by the user from the user device, wherein the first instruction includes a first query statement; then the electronic device generates a structured query language corresponding to the first query statement based on the task type corresponding to the first instruction through the second model.

[0172] As can be seen from the above example, the first query statement included in the first instruction at this time is "Help me find out the number of contracts yesterday", and the task type is the above-mentioned first task type, that is, "Based on the structural information of the table, generate a structured query language corresponding to the query statement"; in addition, the first instruction can also include other content, such as the structural information of the table, plug-in data, etc., which will not be repeated here; then the electronic device uses the second model to generate an output result (that is, an output sequence) corresponding to the first instruction based on the task type corresponding to the first instruction, that is, generates a structured query language corresponding to the first query statement, that is: output:select count(distinct contra_no)from dsst.gdl_acct_contra_det where dt="20241007"; accordingly, the user device receives and displays the output result corresponding to the first instruction.

[0173] It should be noted that since the second model is obtained by fine-tuning the model according to the above-mentioned data processing method of the present application, the performance of the model is more stable than that of fine-tuning all partial parameters, and the computing resource consumption of the electronic device is less than that of fine-tuning all full parameters. In addition, since the training data includes training samples of multiple task types, it belongs to multi-task learning, which can realize knowledge sharing between tasks and make the model more likely to learn common features that are useful for multiple tasks, which helps to improve the generalization ability of the model. It can also play a regularization role, avoid overfitting the model to a single task, and improve the robustness of the model. Furthermore, based on a hybrid method of multi-task learning, full parameter fine-tuning and partial parameter fine-tuning, the model is fine-tuned to obtain the second model, and then the second model is used to generate the SQL statement corresponding to the query statement, which can improve the accuracy of the second model generation.

[0174] It should be noted that this application includes but is not limited to the above-mentioned scenarios. As long as some scenarios are processed using the fine-tuned model of this application in the process of performing natural language processing tasks, they are all within the scope of protection of this application.

[0175] The following is an explanation of the system architecture involved in this application with reference to the accompanying drawings:

[0176] The above-mentioned electronic devices can be terminal devices, such as smart phones, tablet computers, laptops, desktop computers, smart TVs, desktop computers, smart watches, smart cars and other smart terminals, which are not limited in this application. The model to be fine-tuned can be deployed on the terminal device. Then, after the terminal device obtains the training data set, which includes N training batches, the electronic device determines the first i training batches and the last Ni training batches in the N training batches of the model based on the preset ratio and N; then the electronic device fine-tunes all parameters of the model based on the losses corresponding to the first i training batches to obtain a first model; or, in the process of fine-tuning based on the N training batches of the model, if the convergence speed corresponding to the j-th training batch is greater than the preset threshold, then based on the loss corresponding to the j-th training batch, all parameters of the model are fine-tuned, and the convergence speed corresponding to the j+1-th training batch is determined, until it is determined that the convergence speed corresponding to the i+1-th training batch is less than the preset threshold, to obtain the first model; then the electronic device fine-tunes some parameters of the first model based on the losses corresponding to the last Ni training batches in the N training batches of the model, 1≤i<N, and the principle is not repeated here.

[0177] Furthermore, the trained model in the above embodiment, i.e., the above second model, can be deployed on the terminal device. Then, after obtaining the input sequence, the electronic device generates an output sequence corresponding to the input sequence based on the input sequence by deploying the locally trained model. This will not be described in detail here. The input sequence and the output sequence can be in the form of text, audio, video, image, etc., and the input sequence can be in the form of an instruction, which is not limited in this application. For example, the electronic device obtains a first instruction input by the user, and the first instruction includes a first query statement; then, the electronic device generates a structured query language corresponding to the first query statement based on the task type corresponding to the first instruction through the second model.

[0178] Of course, the electronic device can also be a server. Figure 7 , Figure 7 A schematic diagram of a data processing system provided in an embodiment of the present application.

[0179] Figure 7 The system shown includes electronic devices and user devices; the electronic device can be a server, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, as well as basic cloud computing services such as big data and artificial intelligence platforms, which are not specifically limited in this application; the user device can be a smart phone, tablet computer, laptop computer, desktop computer, smart TV, desktop computer, smart watch, smart car and other smart terminals, but is not limited to these.

[0180] In which, the model to be fine-tuned is deployed on a server, and the user can send N training batches to the electronic device through the user device, and then the electronic device determines the first i training batches and the last Ni training batches in the N training batches of the model based on the preset ratio and N; then the electronic device fine-tunes all parameters of the model based on the losses corresponding to the first i training batches to obtain a first model; or, in the process of fine-tuning based on the N training batches of the model, if the convergence speed corresponding to the j-th training batch is greater than a preset threshold, then based on the loss corresponding to the j-th training batch, all parameters of the model are fine-tuned, and the convergence speed corresponding to the j+1-th training batch is determined, until it is determined that the convergence speed corresponding to the i+1-th training batch is less than the preset threshold, to obtain the first model; then the electronic device fine-tunes some parameters of the first model based on the losses corresponding to the last Ni training batches in the N training batches of the model, 1≤i<N, and the principle is not repeated here.

[0181] Furthermore, the trained model, i.e., the second model, is deployed on a server. A user can interact with a user device, and the user device then obtains an input sequence. The user device then sends the input sequence to the electronic device, and the electronic device then generates an output sequence corresponding to the input sequence using the trained model. For example, a user inputs a first instruction through the user device, and the electronic device then receives the first instruction from the user device, the first instruction including a first query statement. The electronic device then uses the second model to generate a structured query language corresponding to the first query statement based on the task type corresponding to the first instruction.

[0182] It should be noted that the principles of the steps executed by the electronic device in this embodiment can refer to the corresponding explanations of the above embodiments, which will not be repeated here, and the steps executed by the electronic device in the above embodiments can also be executed accordingly, which will not be repeated here.

[0183] See Figure 8 , Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 8 As shown, electronic device 800 includes a transceiver 801, a processor 802, and a memory 803. These are connected via a bus 804. The memory 803 is used to store computer programs and data, and can transmit the data stored in the memory 803 to the processor 802.

[0184] The processor 802 is configured to read the computer program in the memory 803 and perform the following operations:

[0185] Control transceiver 801 to obtain N training batches;

[0186] For N training batches of the model, based on a preset ratio and N, determine the first i training batches and the last Ni training batches in the N training batches; based on the losses corresponding to the first i training batches, fine-tune all parameters of the model to obtain a first model;

[0187] Alternatively, in the process of fine-tuning based on N training batches of the model, if the convergence rate corresponding to the j-th training batch is greater than a preset threshold, all parameters of the model are fine-tuned based on the loss corresponding to the j-th training batch, and the convergence rate corresponding to the j+1-th training batch is determined, until it is determined that the convergence rate corresponding to the i+1-th training batch is less than the preset threshold, thereby obtaining a first model;

[0188] For the last Ni training batches among the N training batches of the model, fine-tune some parameters of the first model based on the losses corresponding to the last Ni training batches, 1≤i<N.

[0189] Alternatively, the control transceiver 801 obtains a first instruction, wherein the first instruction includes a first query statement; through a second model, based on the task type corresponding to the first instruction, a structured query language corresponding to the first query statement is generated, wherein the second model is obtained by training through an embodiment of the above-mentioned data processing method.

[0190] In one embodiment of the present application, the processor 802 is specifically configured to perform the following steps:

[0191] Based on the loss corresponding to the jz-th training batch and the loss corresponding to the j-th training batch, determine the convergence rate corresponding to the j-th training batch, where the convergence rate corresponding to the j-th training batch is used to characterize the magnitude of the loss change from the jz-th training batch to the j-th training batch, and the j-th training batch is one of the N training batches, j ≥ z + 1, z ≥ 1.

[0192] In one embodiment of the present application, in determining the convergence rate corresponding to the jth training batch based on the loss corresponding to the jzth training batch and the loss corresponding to the jth training batch, the processor 802 is specifically configured to perform the following steps:

[0193] Based on the loss corresponding to the jzth training batch and the loss corresponding to the jth training batch, determine the loss difference corresponding to the jth training batch;

[0194] Based on the loss difference and z corresponding to the j-th training batch, determine the convergence rate corresponding to the j-th training batch.

[0195] In one embodiment of the present application, N training batches include training samples of multiple task types, and each training batch includes training samples of at least one task type among the multiple task types. The processor 802 is specifically configured to perform the following steps:

[0196] For each training batch, based on each training sample under each task type in the training batch, determine the prediction probability corresponding to each training sample under each task type;

[0197] Based on the predicted probability of each training sample under each task type, determine the adjustment factor corresponding to each task type;

[0198] Based on the adjustment factor corresponding to each task type and the predicted probability corresponding to each training sample under each task type, the loss corresponding to the training batch is determined.

[0199] In one embodiment of the present application, in determining the weight corresponding to each task type based on the predicted probability corresponding to each training sample under each task type, the processor 802 is specifically configured to perform the following steps:

[0200] Based on the predicted probability of each training sample under each task type, determine the average probability corresponding to each task type;

[0201] Based on the average probability corresponding to each task type, determine the adjustment factor corresponding to each task type, where the adjustment factor is negatively correlated with the average probability;

[0202] Based on the average probability and adjustment factor corresponding to each task type, the weight corresponding to each task type is determined, where the weight is negatively correlated with the average probability and positively correlated with the adjustment factor.

[0203] In one embodiment of the present application, the training samples of the first task type include the structural information of the table and the query statement, and the first task type is used to generate a structured query language corresponding to the query statement based on the structural information of the table; the training samples of the second task type include the structural information of the table, the query statement and the preset thinking chain, and the second task type is used to generate a structured query language corresponding to the query statement based on the structural information of the table and the preset thinking chain.

[0204] In one embodiment of the present application, the processor 802 is specifically configured to perform the following steps:

[0205] Obtaining a first instruction, where the first instruction includes a first query statement;

[0206] Through the second model, based on the task type corresponding to the first instruction, a structured query language corresponding to the first query statement is generated, wherein the second model is a model obtained by fine-tuning some parameters of the first model based on the losses corresponding to the last Ni training batches.

[0207] In a specific implementation, the transceiver 801 and the processor 802 described in the embodiment of the present invention may also execute other implementations described in the method embodiment provided in the embodiment of the present invention, which will not be described in detail here.

[0208] It should be understood that the electronic devices in this application can be terminal devices or servers, wherein the terminal devices can be smart terminals such as smart phones, tablet computers, laptops, desktop computers, smart TVs, desktop computers, smart watches, smart cars, etc., but are not limited to these; servers can be independent physical servers, or server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and basic cloud computing services such as big data and artificial intelligence platforms. This application does not make specific limitations. The above-mentioned electronic devices are only examples, not exhaustive, and include but are not limited to the above-mentioned electronic devices.

[0209] It should be understood that an embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. The computer program is executed by a processor to implement part or all of the steps of any data processing method or content generation method described in the above method embodiments.

[0210] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute part or all of the steps of any data processing method or content generation method described in the above method embodiments.

[0211] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all optional embodiments, and the actions and modules involved are not necessarily required by this application.

[0212] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0213] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.

[0214] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0215] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or in the form of software program modules.

[0216] If the integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes a number of instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0217] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program. The program can be stored in a computer-readable memory, and the memory can include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0218] The above is a detailed introduction to the embodiments of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of ​​the present application. At the same time, for those skilled in the art, based on the ideas of the present application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.< / end>

Claims

1. A data processing method, characterized in that: Applied to electronic equipment, the method includes: For N training batches of the model, determine the first i training batches and the last Ni training batches of the N training batches based on a preset ratio and N; fine-tune all parameters of the model based on the losses corresponding to the first i training batches to obtain a first model; Alternatively, in the process of fine-tuning based on N training batches of the model, if the convergence rate corresponding to the j-th training batch is greater than a preset threshold, then based on the loss corresponding to the j-th training batch, all parameters of the model are fine-tuned, and the convergence rate corresponding to the j+1-th training batch is determined, until it is determined that the convergence rate corresponding to the i+1-th training batch is less than the preset threshold, thereby obtaining a first model; For the last Ni training batches among the N training batches of the model, fine-tune some parameters of the first model based on the losses corresponding to the last Ni training batches, 1≤i<N.

2. The method according to claim 1, characterized in that The method further comprises: Based on the loss corresponding to the jz-th training batch and the loss corresponding to the j-th training batch, determine the convergence rate corresponding to the j-th training batch, wherein the convergence rate corresponding to the j-th training batch is used to characterize the magnitude of the loss change from the jz-th training batch to the j-th training batch, j≥z+1, z≥1.

3. The method according to claim 2, characterized in that The determining, based on the loss corresponding to the jz-th training batch and the loss corresponding to the j-th training batch, a convergence rate corresponding to the j-th training batch, includes: Determine the loss difference corresponding to the jth training batch based on the loss corresponding to the jzth training batch and the loss corresponding to the jth training batch; Determine a convergence rate corresponding to the jth training batch based on the loss difference corresponding to the jth training batch and z.

4. The method according to any one of claims 1 to 3, characterized in that The N training batches include training samples of multiple task types, and each training batch includes training samples of at least one task type among the multiple task types; the method further includes: For each training batch, based on each training sample under each task type in the training batch, determine the prediction probability corresponding to each training sample under each task type; Determining a weight corresponding to each task type based on the predicted probability corresponding to each training sample under each task type, wherein the weight is used to represent the difficulty of each task type; Based on the weight corresponding to each task type and the predicted probability corresponding to each training sample under each task type, the loss corresponding to the training batch is determined.

5. The method according to claim 4, characterized in that The determining, based on the predicted probability corresponding to each training sample under each task type, a weight corresponding to each task type includes: Determining an average probability corresponding to each task type based on the predicted probability corresponding to each training sample under each task type; Determining an adjustment factor corresponding to each task type based on the average probability corresponding to each task type, wherein the adjustment factor is negatively correlated with the average probability; Based on the average probability corresponding to each task type and the adjustment factor, a weight corresponding to each task type is determined, wherein the weight is negatively correlated with the average probability and positively correlated with the adjustment factor.

6. The method according to claim 4 or 5, characterized in that The multiple task types include a first task type and a second task type; The training sample of the first task type includes table structure information and query statements, and the first task type is used to generate a structured query language corresponding to the query statement based on the table structure information; The training samples of the second task type include table structure information, query statements and preset thought chains. The second task type is used to generate a structured query language corresponding to the query statement based on the table structure information and the preset thought chain.

7. The method according to claim 6, characterized in that The method further comprises: Obtaining a first instruction, where the first instruction includes a first query statement; A structured query language corresponding to the first query statement is generated through a second model based on the task type corresponding to the first instruction, wherein the second model is a model obtained by fine-tuning some parameters of the first model based on the losses corresponding to the last Ni training batches.

8. An electronic device, characterized in that: include: A processor and a memory, the processor is connected to the memory, the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device performs the method according to any one of claims 1 to 7.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method according to any one of claims 1 to 7.

10. A computer program product, characterized in that The computer program product comprises a non-transitory computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is performed.