Text prediction model training method and device, electronic equipment and storage medium

By using semi-supervised adversarial distillation in the training method of text prediction model, the student model is adaptively trained using the generated sample labels and reasons of the teacher model, the data acquisition problem in large-scale language model deployment is solved and the prediction accuracy of the model is improved.

CN119646513APending Publication Date: 2025-03-18PING AN TECH (SHENZHEN) CO LTD

Patent Information

Application Number
CN202411786098.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

Existing large language models show strong capabilities in the field of natural language processing, but due to their huge scale, there are challenges in deployment in practical applications. Both fine-tuning and distillation methods require a large amount of manual labeling and unlabeled data, which is difficult to obtain, limiting the accuracy of the model.

Method used

A training method for text prediction model is proposed. By obtaining the comprehensive sample information of the text to be predicted, inputting it into multiple teacher models for text prediction, obtaining the generated sample labels and reasons, and adaptive training of the student model based on these results, reducing the data volume requirement and improving the accuracy of model prediction.

Benefits of technology

Through the semi-supervised anti-distillation method, the data volume requirement during the training process is reduced, the prediction accuracy of the model is improved, and it is suitable for model deployment in practical applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119646513A_ABST
    Figure CN119646513A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a text prediction model training method and device, electronic equipment and a storage medium, and belongs to the technical field of text processing. The method comprises the steps of obtaining comprehensive sample information of a to-be-predicted text; inputting the comprehensive sample information into a plurality of teacher models for text prediction to obtain a first sample result; the first sample result comprises a generated sample label obtained through prediction according to the comprehensive sample information and a corresponding generated sample reason; performing adaptive training on an original student model according to the first sample result and the comprehensive sample information to obtain a first student model; and according to the first sample result, allocating a weight to each teacher model, and according to the weights, performing adaptive training on the first student model to obtain a trained text prediction model. The embodiment of the invention is beneficial to reducing the data volume required to be used in the training process and improving the prediction accuracy of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of text processing technology, and in particular to a training method and device for a text prediction model, an electronic device, and a storage medium. Background Art

[0002] At present, general large-scale language models have made important breakthroughs in the field of natural language processing and have demonstrated powerful capabilities in various tasks, such as text generation, question-answering systems, machine translation, text classification, and text summarization. However, due to its large size, it is still challenging to deploy it in practical applications. In order to overcome these deployment challenges, practitioners usually choose to deploy smaller domain-specific models, such as insurance intelligent customer service. These domain-specific models are usually trained using fine-tuning or distillation, but both methods have some problems. Among them, the fine-tuning method requires a large amount of manual labels and unlabeled data, and the difficulty of obtaining data affects the prediction accuracy of the method. The distillation method also relies on a large amount of unlabeled data, which limits the accuracy of the model. Summary of the invention

[0003] The main purpose of the embodiments of the present application is to propose a training method and device, an electronic device and a storage medium for a text prediction model, aiming to improve the prediction accuracy of the model.

[0004] To achieve the above object, a first aspect of an embodiment of the present application proposes a training method for a text prediction model, the method comprising:

[0005] Obtaining comprehensive sample information of the text to be predicted;

[0006] Input the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label predicted according to the comprehensive sample information and a corresponding generated sample reason; the generated sample reason is used to explain the corresponding relationship between the generated sample label and the comprehensive sample information;

[0007] According to the first sample result and the comprehensive sample information, adaptively training the original student model to obtain a first student model;

[0008] According to the first sample result, a weight is assigned to each teacher model, and the first student model is adaptively trained according to the weight to obtain a trained text prediction model.

[0009] The embodiment of the present application adds reason labels in the semi-supervised adversarial distillation of the teacher model and the student model, which is beneficial to reducing the amount of data required during the training process and improving the prediction accuracy of the model.

[0010] In some embodiments, the step of inputting the comprehensive sample information into a plurality of teacher models for text prediction to obtain a first sample result includes:

[0011] Establishing a prompt template; wherein the prompt template includes: a triple consisting of sample data, a sample label and a sample reason; the sample reason is used to explain the corresponding relationship between the sample data and the sample label;

[0012] The comprehensive sample information is input into a plurality of teacher models, and text prediction is performed according to the prompt template to obtain a first sample result.

[0013] In some embodiments, performing adaptive training on the original student model according to the first sample result and the comprehensive sample information to obtain the first student model includes:

[0014] Input the comprehensive sample information into the original student model to obtain a predicted sample label and a predicted sample reason; the predicted sample reason is the corresponding relationship between the predicted comprehensive sample information and the predicted sample label;

[0015] Determine a first loss function according to the predicted sample label and the generated sample label; and determine a second loss function according to the predicted sample label and the true sample label;

[0016] Determining a third loss function according to the predicted sample reason and the generated sample reason;

[0017] According to the first loss function, the second loss function and the third loss function, a loss value is determined, and the parameters of the original student model are updated according to the loss value, and the updated original student model is determined as the first student model.

[0018] In some embodiments, assigning a weight to each teacher model according to the first sample result, and adaptively training the first student model according to the weight to obtain a trained text prediction model includes:

[0019] Assigning a weight to each teacher model according to the prediction accuracy of each teacher model in the first sample result;

[0020] According to the teacher model and the weight, updating the parameters of the first student model, and determining the updated first student model as a text prediction model;

[0021] Alternatively, a loss function of the first student model is established based on the teacher model and the weight, and the parameters of the first student model are updated according to the loss function, and the updated first student model is determined as the text prediction model.

[0022] In some embodiments, inputting the comprehensive sample information into the original student model to obtain a predicted sample label and a predicted sample reason includes:

[0023] Inputting the first prefix and the comprehensive sample information into the original student model to obtain a predicted sample label;

[0024] Alternatively, the second prefix and the comprehensive sample information are input into the original student model to obtain the reason for the predicted sample; the first prefix and the second prefix are the meanings represented by the data output by the original student model.

[0025] In some embodiments, adaptive training is performed on the original student model, including:

[0026] Establishing an objective function to be optimized according to the distance between the prediction result of the original student model and the first sample result;

[0027] The objective function is processed based on a min-max framework to perform adaptive training on the original student model.

[0028] To achieve the above object, a second aspect of an embodiment of the present application proposes a text prediction method, comprising:

[0029] Obtaining comprehensive information of the text to be predicted;

[0030] The comprehensive information is input into a text prediction model trained by the above-mentioned text prediction model training method to obtain a predicted text result.

[0031] To achieve the above-mentioned purpose, a third aspect of an embodiment of the present application proposes a training device for a text prediction model, the device comprising:

[0032] The first module is used to obtain comprehensive sample information of the text to be predicted;

[0033] The second module is used to input the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label predicted according to the comprehensive sample information and a corresponding generated sample reason; the generated sample reason is used to explain the corresponding relationship between the generated sample label and the comprehensive sample information;

[0034] A third module is used to perform adaptive training on the original student model according to the first sample result and the comprehensive sample information to obtain a first student model;

[0035] The fourth module is used to assign weights to each teacher model according to the first sample results, and to adaptively train the first student model according to the weights to obtain a trained text prediction model.

[0036] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the method described in the first aspect or the second aspect when executing the computer program.

[0037] To achieve the above objectives, the fifth aspect of an embodiment of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the method described in the first aspect or the second aspect.

[0038] The training method and device, electronic device and storage medium of the text prediction model proposed in the present application include: obtaining comprehensive sample information of the text to be predicted; inputting the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label and a corresponding generated sample reason predicted according to the comprehensive sample information; the generated sample reason is used to explain the corresponding relationship between the generated sample label and the comprehensive sample information; according to the first sample result and the comprehensive sample information, the original student model is adaptively trained to obtain a first student model; according to the first sample result, a weight is assigned to each teacher model, and the first student model is adaptively trained according to the weight to obtain a trained text prediction model. The embodiment of the present application is conducive to reducing the amount of data required in the training process and improving the prediction accuracy of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 is a flowchart of a method for training a text prediction model provided in an embodiment of the present application;

[0040] Figure 2 is a flowchart of a text prediction process provided by an embodiment of the present application;

[0041] Figure 3 is a flowchart of another prediction model training process provided in an embodiment of the present application;

[0042] Figure 4 is an example diagram of the counteracting distillation process provided by an embodiment of the present application;

[0043] Figure 5 It is a structural schematic diagram of a training device for a text prediction model provided in an embodiment of the present application;

[0044] Figure 6 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0045] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0046] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0047] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0048] First, some nouns involved in this application are analyzed:

[0049] Artificial intelligence (AI) is a new technical science that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence. AI is a branch of computer science that attempts to understand the essence of intelligence and produce a new type of intelligent machine that can respond in a similar way to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing and expert systems. AI can simulate the information process of human consciousness and thinking. AI is also a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0050] Knowledge distillation is a model compression and transfer learning technology that draws on the idea of ​​the teacher-student network to "distill" the knowledge of a complex and large teacher model into a simple student model. The teacher model is usually a pre-trained, high-performance model with rich knowledge and strong expression capabilities. The student model is relatively small and simple in structure. The distillation process is as follows:

[0051] Training the teacher model: Generally, a high-precision teacher model is trained on a large-scale data set using conventional training methods, such as back propagation and optimization algorithms. Knowledge extraction: The knowledge of the teacher model includes two aspects: one is the output probability distribution, which reflects the confidence of the model in predicting different categories and contains rich information about the relationship between categories; the other is the intermediate layer features, which reflects the model's ability to abstract and extract data during the training process. Training the student model: By defining a suitable loss function, the output of the student model is made closer to the teacher model. The loss function generally contains two parts: one is the distillation loss (soft target loss), which makes the output probability distribution of the student model match the soft target probability distribution of the teacher model. The KL divergence is usually used to measure the difference between the two; the other is the original training loss of the student model (hard target loss), that is, the cross entropy loss of the student model on the true label. These two parts of the loss are added according to a certain weight and trained as the total loss of the student model.

[0052] Knowledge distillation can significantly reduce the complexity of the model, reduce computing resource consumption, and improve the reasoning speed, while retaining the accuracy of the teacher model to a certain extent. It can be widely used in the field of computer vision, such as image classification, target detection and other tasks; in the field of natural language processing, it also has a good effect on the compression and optimization of language models, and is also used in fields such as speech recognition.

[0053] Adversarial Learning is a technology widely used in the fields of machine learning and deep learning. It is mainly based on the adversarial idea in game theory. The most typical one is the structure of Generative Adversarial Networks (GAN). GAN consists of two parts: the generator and the discriminator. The task of the generator is to generate data that is as close to the distribution of real data as possible, such as generating realistic images and texts. The task of the discriminator is to distinguish whether the input data comes from real data or data generated by the generator. These two parts compete and optimize each other during the training process. Adversarial learning can learn the potential distribution of data and generate highly realistic data. At the same time, it can enhance the robustness and generalization ability of the model, and enable the model to better cope with various complex situations through adversarial training.

[0054] Adversarial Knowledge Distillation is an innovative technology that combines adversarial learning with knowledge distillation. In traditional knowledge distillation, the main focus is to transfer the knowledge of the teacher model to the student model. Adversarial knowledge distillation introduces an adversarial mechanism on this basis. Its core idea is to use adversarial training to allow the student model to enhance its robustness and ability to understand data while learning the knowledge of the teacher model. It generally consists of three main parts, namely the teacher model, the student model, and the discriminator. The teacher model, like the traditional knowledge distillation, is a provider of knowledge with strong performance and rich knowledge. The student model is a receiver of knowledge, and its goal is to learn the knowledge of the teacher model and narrow the gap with the teacher model as much as possible. The discriminator is used to distinguish the output of the student model from the teacher model. Its existence introduces an adversarial element to the learning of the student model. This technology is conducive to improving the performance of the student model: through adversarial training, the student model can better capture the knowledge details in the teacher model, thereby improving the performance of the model. Compared with traditional knowledge distillation, adversarial knowledge distillation can make the student model have better performance in indicators such as accuracy and recall. Enhance model robustness: The introduction of the adversarial mechanism helps the student model enhance its robustness to data changes and noise. The student model learns to cope with the challenges of the discriminator in adversarial training, which enables it to function more stably when faced with complex and changeable real data. Promote knowledge transfer: Adversarial knowledge distillation creates more favorable conditions for the transfer of knowledge from the teacher model to the student model. The discriminator helps to screen and transfer more valuable knowledge to a certain extent, so that the student model can absorb and utilize the knowledge of the teacher model more effectively.

[0055] At present, general large language models (LLMs) have made important breakthroughs in the field of natural language processing and have demonstrated powerful capabilities in various tasks, such as text generation, question-answering systems, machine translation, text classification, and text summarization. However, due to their large size, deployment in practical applications is still challenging. To overcome these deployment challenges, practitioners often choose to deploy smaller domain-specific models, such as insurance smart customer service. These domain-specific models are usually trained using fine-tuning or distillation, but both methods have some problems.

[0056] The fine-tuning method uses manually annotated data of downstream tasks to update a pre-trained smaller model (such as a BERT model or a T5 model). Although the fine-tuning method can achieve high performance, it requires expensive manual labels. Another method, the distillation method, uses the labels generated by the larger model to train the student model. This method can achieve comparable performance on a smaller model as a larger model, but requires a large amount of unlabeled data. Both manual labels and a large amount of unlabeled data are difficult to obtain in practice.

[0057] To address these issues, adversarial knowledge distillation of large language models becomes necessary. Adversarial knowledge distillation transfers knowledge from a larger, more powerful teacher model to a smaller student model suitable for practical applications. This approach can learn with limited labeled data because the larger teacher model can generate training datasets with pseudo labels. However, traditional knowledge distillation methods have many limitations:

[0058] (1) It relies on a large amount of unlabeled data to create a training dataset to enable the student model to achieve comparable results to the teacher model.

[0059] (2) If the quality of a single teacher model is poor, its predictions may mislead students. To this end, the industry has proposed some Multi-Teacher Knowledge Distillation (MKD) methods, which basically assign fixed weights to the prediction results from multiple teachers. However, fixed weights cannot distinguish between high-quality teachers and low-quality teachers.

[0060] (3) The goal of distillation optimization is to make the predicted values ​​of the student model at all sample points in the neighborhood consistent with the fixed true labels. However, doing so will lead to over-correction of the model smoothness, limiting the accuracy and robustness of the small model.

[0061] Based on this, the embodiments of the present application provide a training method and device for a text prediction model, an electronic device and a storage medium, aiming to improve the prediction accuracy of the model.

[0062] The training method and device of the text prediction model, the electronic device and the storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the training method of the text prediction model in the embodiments of the present application is described.

[0063] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0064] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0065] The training method of the text prediction model provided in the embodiment of the present application relates to the field of text processing technology. The training method of the text prediction model provided in the embodiment of the present application can be applied to a terminal, can also be applied to a server side, and can also be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application of the training method of the text prediction model, etc., but is not limited to the above forms.

[0066] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0067] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to user identity or characteristics such as user information, user text information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of these data will comply with relevant laws, regulations, and standards. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.

[0068] Figure 1 is an optional flowchart of the text prediction model training method provided in the embodiment of the present application, Figure 1The method may include but is not limited to steps S100 to S400.

[0069] Step S100, obtaining comprehensive sample information of the text to be predicted;

[0070] Step S200, inputting the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label predicted according to the comprehensive sample information and a corresponding generated sample reason; the generated sample reason is used to explain the corresponding relationship between the generated sample label and the comprehensive sample information;

[0071] Step S300, performing adaptive training on the original student model according to the first sample result and the comprehensive sample information to obtain a first student model;

[0072] Step S400, assigning weights to each teacher model according to the first sample result, and adaptively training the first student model according to the weights to obtain a trained text prediction model.

[0073] The comprehensive sample information of the embodiment of the present application can be questions raised by users or related questions in related fields. For example, the text prediction model proposed in the present application can be an intelligent customer service system, which can be used in finance, education, retail and other industries to answer questions raised by customers; the text prediction model of the present application can also be an intelligent office system or an information retrieval and recommendation system. Of course, the training method in the embodiment of the present application can also be used in scenarios such as data reasoning, audio prediction, and image recognition. The present application does not limit the specific application fields and application scenarios of the training method.

[0074] It should be noted that, refer to Figure 2 As shown, the embodiment of the present application uses a multi-teacher model to perform text prediction and adds reasons to the model output, where the reasons are a reasonable explanation from the comprehensive sample information to the generated sample label, so that the model predicts a more accurate generated sample label and improves the prediction accuracy of the model. Figure 3 As shown, the reason for generating the sample is input into the original student model together with the input comprehensive sample information, and the original student model is adaptively trained to perform the first knowledge transfer to obtain the first student model. In addition, the embodiment of the present application assigns weights to the multiple teacher models according to the prediction accuracy of the multiple teacher models, and performs a second knowledge transfer on the first student model according to the assigned weights to obtain a text prediction model. The embodiment of the present application improves the prediction accuracy of the model through multi-teacher semi-supervised adversarial knowledge distillation.

[0075] The image processing method provided by the embodiment of the present application includes: obtaining comprehensive sample information of the text to be predicted; inputting the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label and a corresponding generated sample reason predicted according to the comprehensive sample information; the generated sample reason is used to explain the correspondence between the generated sample label and the comprehensive sample information; according to the first sample result and the comprehensive sample information, the original student model is adaptively trained to obtain a first student model; according to the first sample result, weights are assigned to each teacher model, and the first student model is adaptively trained according to the weights to obtain a trained text prediction model. The embodiment of the present application adds reason labels in the semi-supervised adversarial distillation of the teacher model and the student model, which is conducive to reducing the amount of data required in the training process and improving the prediction accuracy of the model.

[0076] In some embodiments, the comprehensive sample information is input into multiple teacher models for text prediction to obtain a first sample result; including:

[0077] Establishing a prompt template; wherein the prompt template includes: a triple consisting of sample data, sample labels and sample reasons; the sample reasons are used to explain the corresponding relationship between the sample data and the sample labels;

[0078] The comprehensive sample information is input into multiple teacher models, and text prediction is performed according to the prompt template to obtain the first sample result.

[0079] The embodiment of the present application improves the model so that the teacher model generates predicted labels and corresponding reasons, thereby improving the prediction accuracy of the text prediction model.

[0080] In some embodiments, adaptive training is performed on the original student model according to the first sample result and the comprehensive sample information to obtain the first student model, including:

[0081] Input the comprehensive sample information into the original student model to obtain the predicted sample label and the predicted sample reason; the predicted sample reason is the corresponding relationship between the predicted comprehensive sample information and the predicted sample label;

[0082] Determine a first loss function based on the predicted sample label and the generated sample label; and determine a second loss function based on the predicted sample label and the true sample label;

[0083] Determine the third loss function according to the predicted sample reason and the generated sample reason;

[0084] According to the first loss function, the second loss function and the third loss function, a loss value is determined, and the parameters of the original student model are updated according to the loss value, and the updated original student model is determined as the first student model.

[0085] The original student model in the embodiment of the present application is not only trained with predicted sample labels and true sample labels as supervision, but also trained with predicted sample reasons as supervision. By adding reasons, the original student model can predict the intermediate reasoning process and thus better predict the result label.

[0086] In some embodiments, according to the first sample result, a weight is assigned to each teacher model, and the first student model is adaptively trained according to the weight to obtain a trained text prediction model, including:

[0087] Assign a weight to each teacher model based on its prediction accuracy in the first sample results;

[0088] According to the teacher model and the weight, the parameters of the first student model are updated, and the updated first student model is determined as the text prediction model;

[0089] Alternatively, a loss function of the first student model is established based on the teacher model and the weights, and the parameters of the first student model are updated according to the loss function, and the updated first student model is determined as the text prediction model.

[0090] The embodiment of the present application adjusts the parameters of the student model by the weights assigned to the teacher model. Specifically, the parameters of the student model can be adjusted directly according to the weights, and the loss function corresponding to the student model can also be adjusted according to the weights, thereby adjusting the parameters of the student model.

[0091] In some embodiments, the comprehensive sample information is input into the original student model to obtain the predicted sample label and the predicted sample reason, including:

[0092] Input the first prefix and comprehensive sample information into the original student model to obtain the predicted sample label;

[0093] Alternatively, the second prefix and the comprehensive sample information are input into the original student model to obtain the reason for the predicted sample; the first prefix and the second prefix are the meanings represented by the data output by the original student model.

[0094] The embodiment of the present application adjusts the output of the student model by adding a specific prefix before the input of the student model to meet the output diversity. In some embodiments, the first prefix can be [label] and the second prefix can be [reason].

[0095] In some embodiments, adaptive training is performed on the original student model, including:

[0096] According to the distance between the prediction result of the original student model and the result of the first sample, the objective function to be optimized is established;

[0097] The objective function is processed based on the min-max framework to perform adaptive training on the original student model.

[0098] The training method of the text prediction model provided in the embodiment of the present application includes: obtaining comprehensive sample information of the text to be predicted; inputting the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label and a corresponding generated sample reason predicted according to the comprehensive sample information; the generated sample reason is used to explain the correspondence between the generated sample label and the comprehensive sample information; according to the first sample result and the comprehensive sample information, the original student model is adaptively trained to obtain a first student model; according to the first sample result, a weight is assigned to each teacher model, and the first student model is adaptively trained according to the weight to obtain a trained text prediction model. The embodiment of the present application adds reason labels in the semi-supervised adversarial distillation of the teacher model and the student model, which is conducive to reducing the amount of data required in the training process and improving the prediction accuracy of the model.

[0099] The image processing method provided by the present application is described below with a specific embodiment:

[0100] Describe the data involved in this embodiment and define the data set where x i Represents input, y i Represents the corresponding manual annotation output, N is the number of data, and K is the number of teacher models. n∈N represents the nth data, and k∈K represents the kth teacher model.

[0101] Overall process reference Figure 2 As shown in the figure, after data cleaning, K teacher models are selected first, and the student model S' is obtained by using the semi-supervised adversarial distillation method; then the weight distribution module is added to perform the second-level multi-teacher model distillation to obtain the final student model S", which is the text prediction model.

[0102] Among them, regarding semi-supervised adversarial distillation, the definition of reason is to provide a natural language explanation to support the model's predicted label, and one of the behavioral characteristics of the large language model is the ability to generate such reasons to support its prediction. Specifically, the chain of thoughts (CoT) prompt is used to induce and extract the reasons why the large language model gives the corresponding answer to each question. Figure 4 As shown in , for the teacher model k, given an unlabeled data x in the dataset D i ∈D, design a prompt template p to clarify how to solve the task. Each prompt is composed of input Corresponding label and sample reasons The triplet The reason Explains why Classified as Specifically, for each x i ∈D, and x i Put it in the prompt k Then use it as input to let the large language model generate reasons and labels. k The data, labels and reasons are given in the example, and LLM can imitate the triples to give Reasons and tags

[0103] Assume that the student model is f, and generally only manual labels are used to train the student model and generate tags As supervision, the specific objective function is as follows:

[0104]

[0105] Among them l k is the cross entropy loss between the prediction and the target of f, where both the manual labels and the generated labels are unified into In this semi-supervised adversarial distillation, the extracted reasons As additional supervision, Add directly to the output of the student model f In this way, the student model f is trained to perform multi-task problems. It not only needs to predict the output but also needs to generate corresponding reasons based on the input. The objective function is modified as shown in formula (2) and formula (3):

[0106]

[0107]

[0108] in is the loss function based on the predicted label in formula (1). This enables the model to learn the intermediate reasoning steps to generate predictions, and thus can guide the model to better predict the outcome label. The above objective function is only for one teacher model, and all teacher model losses are The total target loss can be obtained by adding Refer to formula (4):

[0109]

[0110] In order to distinguish tasks, a specific prefix needs to be added before the input of the data set. [Label] means only output [Reason] represents only output When making inference predictions on new questions in the test set, just prefix the input with [label].

[0111] Regarding the two-level multi-teacher distillation of this embodiment, after completing the first knowledge transfer using semi-supervised adversarial distillation, the trained student model S' is obtained. However, in the previous step, the labels generated by each teacher model are indiscriminately added to the training set, so simply treating each teacher model as equally important cannot reveal the different importance of teachers to specific examples. To bridge this gap, this embodiment proposes to assign sample reliability to the labels generated by each teacher with the help of true labels, and the teacher with higher reliability has a greater weight. Assume that for the i-th input x i , the kth teacher model for x i The answer is In order to effectively aggregate the prediction distributions of multiple teacher models, the teacher generates labels by calculating and the true label y i The cross entropy loss between them is assigned different weights reflecting the confidence of their samples, as shown in formula (5):

[0112]

[0113] in represents the sum of the cross entropy losses between the generated labels and the true labels of all inputs by the k-th teacher model. The smaller l is, the larger w is. The overall prediction of the teacher model is as follows and aggregated with the calculated weights, as shown in formula (6):

[0114]

[0115] Teachers whose predictions are closer to the true labels will be assigned larger weights. Because it has enough confidence to make accurate judgments to provide correct guidance. As above, because this knowledge transfer only involves using the labels of the teacher model, a specific prefix [label] is added to the input of the dataset to guide the model output The student model after the second knowledge transfer is S". When making inference predictions on new questions in the test set, only the [label] prefix is ​​added before the input.

[0116] Regarding the adaptive training goal in this embodiment, the above-mentioned two-stage distillation method uses hard labels, and its optimization objective function is essentially to make the predicted values ​​of the student model at all sample points in the specified area consistent with the manual labels. However, doing so will introduce the problem of over-correction of the smoothness of the model. This over-correction problem leads to a serious trade-off between accuracy and robustness of the trained model. Therefore, based on traditional adversarial distillation, this application proposes an adaptive training goal, that is, to find the optimal matching points for the distillation training process in an adaptive manner. As shown in formula (1), the general maximization alignment goal can be formally defined as formula (7):

[0117]

[0118] T(·) and S(·) represent the teacher and student models respectively, and the model can be parameterized as θ T and θ S For a given input x, the output of the student model S(x) is trained to match T(x) generated by the teacher model. D(·, ·) is the distance function, which is the cross entropy in this case.

[0119] The adaptive training objective uses a min-max based framework to approximate the above optimization objective, as shown in formula (8):

[0120]

[0121] This approach significantly alleviates the overcorrection problem by making the student model's predictions at all points within a neighborhood of a sample point consistent with the distribution of the teacher model's predictions within that neighborhood. In addition, in max inner optimization, the matching points we look for represent the points with the largest difference between the student and teacher model predictions. These points are not necessarily highly adversarial, so unlike existing adversarial training and adversarial robust distillation methods, this method allows the use of a larger search radius for max inner optimization. A larger search radius means that the alignment constraints between the student and teacher models are stronger, and increasing the search radius can significantly improve the robust performance of the student model.

[0122] The embodiment of the present application is based on semi-supervised adversarial distillation. First, compared with traditional fine-tuning and distillation, it reduces the number of training instances by more than 50% on average; second, it is superior to LLM in training small models for specific tasks, greatly reducing the computational cost required for model deployment.

[0123] The embodiment of the present application is based on two-level multi-teacher distillation. On the basis of the first knowledge distillation using the same weight teacher model, each teacher model is given a confidence weight, which is calculated based on the similarity between its prediction and the basic fact label of the reliability identification of each training sample. Therefore, under the guidance of the label, the present application effectively integrates different knowledge from multiple teachers and improves the efficiency of knowledge transfer and utilization.

[0124] The embodiment of the present application is based on an adaptive training objective, which effectively alleviates the overcorrection problem and allows a larger search radius to be used to find the optimal point. Compared with existing methods, the adaptive objective can significantly improve the accuracy and robustness of the student model.

[0125] The training method of the text prediction model provided in the embodiment of the present application includes: obtaining comprehensive sample information of the text to be predicted; inputting the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label and a corresponding generated sample reason predicted according to the comprehensive sample information; the generated sample reason is used to explain the correspondence between the generated sample label and the comprehensive sample information; according to the first sample result and the comprehensive sample information, the original student model is adaptively trained to obtain a first student model; according to the first sample result, a weight is assigned to each teacher model, and the first student model is adaptively trained according to the weight to obtain a trained text prediction model. The embodiment of the present application adds reason labels in the semi-supervised adversarial distillation of the teacher model and the student model, which is conducive to reducing the amount of data required in the training process and improving the prediction accuracy of the model.

[0126] The present application also provides a text prediction method, including:

[0127] Obtaining comprehensive information of the text to be predicted;

[0128] The comprehensive information is input into the text prediction model trained by the above-mentioned text prediction model training method to obtain a predicted text result.

[0129] It can be understood that the beneficial effects of the above text prediction method embodiment are the same as the beneficial effects of the text prediction model training method in the embodiment of the present application.

[0130] See also Figure 5 The present application also provides a text prediction model training device, which can implement the above text prediction model training method, and the device includes:

[0131] The first module is used to obtain comprehensive sample information of the text to be predicted;

[0132] The second module is used to input the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label predicted according to the comprehensive sample information and a corresponding generated sample reason; the generated sample reason is used to explain the corresponding relationship between the generated sample label and the comprehensive sample information;

[0133] The third module is used to perform adaptive training on the original student model according to the first sample result and the comprehensive sample information to obtain a first student model;

[0134] The fourth module is used to assign weights to each teacher model according to the first sample result, and to adaptively train the first student model according to the weights to obtain a trained text prediction model.

[0135] In some embodiments, the second module is further used to: establish a prompt template; wherein the prompt template includes: a triple consisting of sample data, sample labels and sample reasons; the sample reasons are used to explain the corresponding relationship between the sample data and the sample labels;

[0136] The comprehensive sample information is input into multiple teacher models, and text prediction is performed according to the prompt template to obtain the first sample result.

[0137] In some embodiments, the third module is further used to: input the comprehensive sample information into the original student model to obtain a predicted sample label and a predicted sample reason; the predicted sample reason is the corresponding relationship between the predicted comprehensive sample information and the predicted sample label;

[0138] Determine a first loss function based on the predicted sample label and the generated sample label; and determine a second loss function based on the predicted sample label and the true sample label;

[0139] Determine the third loss function according to the predicted sample reason and the generated sample reason;

[0140] According to the first loss function, the second loss function and the third loss function, a loss value is determined, and the parameters of the original student model are updated according to the loss value, and the updated original student model is determined as the first student model.

[0141] In some embodiments, the fourth module is further used to: assign a weight to each teacher model according to the prediction accuracy of each teacher model in the first sample result;

[0142] According to the teacher model and the weight, the parameters of the first student model are updated, and the updated first student model is determined as the text prediction model;

[0143] Alternatively, a loss function of the first student model is established based on the teacher model and the weights, and the parameters of the first student model are updated according to the loss function, and the updated first student model is determined as the text prediction model.

[0144] In some embodiments, the third module is further used to: input the first prefix and the comprehensive sample information into the original student model to obtain a predicted sample label;

[0145] Alternatively, the second prefix and the comprehensive sample information are input into the original student model to obtain the reason for the predicted sample; the first prefix and the second prefix are the meanings represented by the data output by the original student model.

[0146] Some embodiments further include a fifth module, which is used to: establish an objective function to be optimized according to the distance between the prediction result of the original student model and the first sample result;

[0147] The objective function is processed based on the min-max framework to perform adaptive training on the original student model.

[0148] The training device of the text prediction model provided in the embodiment of the present application includes: a first module for obtaining comprehensive sample information of the text to be predicted; a second module for inputting the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label and a corresponding generated sample reason predicted according to the comprehensive sample information; the generated sample reason is used to explain the correspondence between the generated sample label and the comprehensive sample information; a third module is used to adaptively train the original student model according to the first sample result and the comprehensive sample information to obtain a first student model; a fourth module is used to assign weights to each teacher model according to the first sample result, and adaptively train the first student model according to the weights to obtain a trained text prediction model. The embodiment of the present application adds reason labels in the semi-supervised adversarial distillation of the teacher model and the student model, which is conducive to reducing the amount of data required in the training process and improving the prediction accuracy of the model.

[0149] The specific implementation of the text prediction model training device is basically the same as the specific implementation of the text prediction model training method described above, and will not be repeated here.

[0150] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned text prediction model training method or text prediction method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0151] See also Figure 6 , Figure 6 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0152] The processor 901 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0153] The memory 902 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 902 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 902, and the processor 901 calls and executes the training method or text prediction method of the text prediction model of the embodiment of the present application;

[0154] Input / output interface 903, used to implement information input and output;

[0155] Communication interface 904, used to realize communication interaction between the device and other devices, which can be realized by wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);

[0156] A bus 905 that transmits information between various components of the device (e.g., the processor 901, the memory 902, the input / output interface 903, and the communication interface 904);

[0157] The processor 901 , the memory 902 , the input / output interface 903 and the communication interface 904 are connected to each other in communication within the device via a bus 905 .

[0158] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the text prediction model training method or text prediction method of the embodiment of the present application.

[0159] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0160] The training method of a text prediction model, the training device of a text prediction model, the electronic device and the storage medium provided in the embodiments of the present application include: obtaining comprehensive sample information of a text to be predicted;

[0161] Input the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label predicted according to the comprehensive sample information and a corresponding generated sample reason; the generated sample reason is used to explain the corresponding relationship between the generated sample label and the comprehensive sample information;

[0162] According to the first sample result and the comprehensive sample information, adaptively training the original student model to obtain a first student model;

[0163] According to the first sample result, a weight is assigned to each teacher model, and the first student model is adaptively trained according to the weight to obtain a trained text prediction model.

[0164] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0165] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0166] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0167] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0168] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0169] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0170] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, 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, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

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

[0172] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0173] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. 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, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0174] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A training method for a text prediction model, characterized in that: The method comprises: Obtain comprehensive sample information of the text to be predicted; Input the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label predicted according to the comprehensive sample information and a corresponding generated sample reason; the generated sample reason is used to explain the corresponding relationship between the generated sample label and the comprehensive sample information; According to the first sample result and the comprehensive sample information, adaptively training the original student model to obtain a first student model; According to the first sample result, a weight is assigned to each of the teacher models, and the first student model is adaptively trained according to the weight to obtain a trained text prediction model.

2. The method according to claim 1, characterized in that The step of inputting the comprehensive sample information into a plurality of teacher models for text prediction to obtain a first sample result includes: Establishing a prompt template; wherein the prompt template includes: a triple consisting of sample data, a sample label and a sample reason; the sample reason is used to explain the corresponding relationship between the sample data and the sample label; The comprehensive sample information is input into the plurality of teacher models, and text prediction is performed according to the prompt template to obtain the first sample result.

3. The method according to claim 1, characterized in that The method of adaptively training the original student model according to the first sample result and the comprehensive sample information to obtain the first student model comprises: Input the comprehensive sample information into the original student model to obtain a predicted sample label and a predicted sample reason; the predicted sample reason is the corresponding relationship between the predicted comprehensive sample information and the predicted sample label; Determine a first loss function according to the predicted sample label and the generated sample label, and determine a second loss function according to the predicted sample label and the true sample label; Determining a third loss function according to the predicted sample reason and the generated sample reason; According to the first loss function, the second loss function and the third loss function, a loss value is determined, and the parameters of the original student model are updated according to the loss value, and the updated original student model is determined as the first student model.

4. The method according to claim 1, characterized in that: The step of assigning a weight to each teacher model according to the first sample result, and adaptively training the first student model according to the weight to obtain a trained text prediction model includes: Assigning a weight to each of the teacher models according to the prediction accuracy of each of the teacher models in the first sample results; According to the teacher model and the weight, updating the parameters of the first student model, and determining the updated first student model as a text prediction model; Alternatively, a loss function of the first student model is established based on the teacher model and the weight, and the parameters of the first student model are updated according to the loss function, and the updated first student model is determined as the text prediction model.

5. The method according to claim 3, characterized in that: The step of inputting the comprehensive sample information into the original student model to obtain a predicted sample label and a predicted sample reason includes: Inputting the first prefix and the comprehensive sample information into the original student model to obtain a predicted sample label; Alternatively, the second prefix and the comprehensive sample information are input into the original student model to obtain the reason for the predicted sample; the first prefix and the second prefix are the meanings represented by the data output by the original student model.

6. The method according to any one of claims 1 to 5, characterized in that: The adaptive training of the original student model comprises: Establishing an objective function to be optimized according to the distance between the prediction result of the original student model and the first sample result; The objective function is processed based on a min-max framework to perform adaptive training on the original student model.

7. A text prediction method, characterized in that: include: Obtaining comprehensive information of the text to be predicted; The comprehensive information is input into a text prediction model trained by the text prediction model training method according to any one of claims 1 to 6 to obtain a predicted text result.

8. A training device for a text prediction model, characterized in that: The device comprises: The first module is used to obtain comprehensive sample information of the text to be predicted; The second module is used to input the comprehensive sample information into multiple teacher models for text prediction to obtain a first sample result; the first sample result includes a generated sample label predicted according to the comprehensive sample information and a corresponding generated sample reason; the generated sample reason is used to explain the corresponding relationship between the generated sample label and the comprehensive sample information; A third module is used to perform adaptive training on the original student model according to the first sample result and the comprehensive sample information to obtain a first student model; The fourth module is used to assign weights to each of the teacher models according to the first sample results, and to adaptively train the first student model according to the weights to obtain a trained text prediction model.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Small sample text classification method based on semi-supervised teacher-student model

    CN117150021A

  • Text classification model training method and device, medium and electronic equipment

    CN117786107A

  • Text processing model training method, text processing method and question and answer processing method and device

    CN118627543A

Cited By

  • Server side privacy protection data generation method and system

    CN120579200A