Model training method, device, electronic device, and storage medium
By assigning learning weights to each text element and dynamically adjusting the knowledge distillation loss, the problem of inefficiency of traditional knowledge distillation technology is solved, and more efficient model training and more accurate student model training are achieved.
Patent Information
- Application Number
- CN202210701219.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-20
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2042-06-20
AI Technical Summary
Traditional knowledge distillation technology has low efficiency in model training and is difficult to effectively improve the training efficiency of student models.
By assigning a learning weight to each text element and determining the knowledge distillation loss based on the results of the teacher model and student model, the training process of the student model is dynamically adjusted to improve training efficiency.
While consuming less computing resources, it ensures that the trained model is more accurate and significantly improves the efficiency of model training.
Smart Images

Figure CN115049074B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and specifically to a model training method, device, electronic device, and storage medium. Background Art
[0002] Knowledge distillation is a training method based on the "teacher-student model idea", which is to impart the "knowledge" in the teacher model to the student model through "distillation". Among them, the teacher model is usually a well-trained, relatively complex and large model, while the student model, as the target of the teacher model's teaching, often has a small number of parameters and a relatively simple model structure.
[0003] However, current traditional knowledge distillation techniques are inefficient in training models. Summary of the invention
[0004] The embodiments of the present application provide a model training method, device, electronic device, and storage medium, which can improve the efficiency of training models.
[0005] The present application embodiment provides a model training method, including:
[0006] Obtaining the text to be processed, where the text to be processed consists of at least one text element;
[0007] The teacher model and the student model are used to process the text to be processed respectively to obtain the teacher result and the student result;
[0008] Determine the learning weights of the student model for the text elements;
[0009] Determine the knowledge distillation loss of the student model for the text elements based on the teacher results, the student results, and the learning weights of the text elements;
[0010] Based on the knowledge distillation loss of the student model for all text elements, the student model training is guided until the student model converges to obtain a trained student model.
[0011] The present application also provides a model training device, including:
[0012] An acquisition unit, used for acquiring a text to be processed, where the text to be processed is composed of at least one text element;
[0013] A processing unit, used for processing the text to be processed by using a teacher model and a student model respectively, to obtain a teacher result and a student result;
[0014] A weight unit, used to determine the learning weight of the student model for the text element;
[0015] A loss unit, used to determine the knowledge distillation loss of the student model for the text elements based on the teacher results, the student results, and the learning weights of the text elements;
[0016] The training unit is used to guide the student model training based on the knowledge distillation loss of the student model for all text elements until the student model converges to obtain a trained student model.
[0017] In some embodiments, the training unit comprises:
[0018] Determine the subunits used to determine the weight coefficients and the cross entropy loss of the student model;
[0019] The weighted loss subunit is used to weight the knowledge distillation loss of the student model for all text elements using a weight coefficient to obtain a weighted loss;
[0020] The overall training loss subunit is used to determine the overall training loss based on the cross entropy loss and the weighted loss;
[0021] The training subunit is used to train the student model based on the overall training loss until the student model converges to obtain a trained student model.
[0022] In some embodiments, determining a subunit includes:
[0023] A coefficient submodule, used to determine a preset specific gravity coefficient and a balance parameter;
[0024] The coefficient submodule is used to take the product of the balance parameter and the preset specific gravity coefficient as the specific gravity coefficient.
[0025] In some embodiments, the coefficient submodule is used to:
[0026] Determine the preset weighting factor, the preset total number of training steps, and the current number of training steps;
[0027] The quotient of the current training step number and the preset total training step number is used as the balance parameter.
[0028] In some embodiments, the coefficient submodule is used to:
[0029] Determine a preset weighting factor, an average confidence of the student model for all text elements, and an average confidence of the teacher model for all text elements;
[0030] The quotient of the average confidence of the student model on all text elements and the average confidence of the teacher model on all text elements is taken as the balance parameter.
[0031] In some embodiments, the weight unit includes:
[0032] A confidence subunit, for determining the confidence of the teacher model on the text element and the confidence of the student model on the text element;
[0033] A first parameter subunit, used to determine a first parameter based on the confidence of the student model, the first parameter representing the mastery of the text element by the student model;
[0034] A second parameter subunit, used to determine a second parameter based on the confidence of the teacher model on the text element and the confidence of the student model on the text element, the second parameter representing the difference between the student result and the teacher result;
[0035] The weight subunit is used to determine the learning weight of the student model for the text element based on the first parameter and the second parameter.
[0036] In some embodiments, the weight subunit is used to:
[0037] Multiply the first parameter and the second parameter to obtain a mixed parameter;
[0038] Performing exponential operation based on the mixed parameter to obtain an exponential operation result;
[0039] Based on the results of exponential operation, abnormal integral processing is performed to obtain the learning weights of the student model for text elements.
[0040] An embodiment of the present application also provides an electronic device, including a memory storing multiple instructions; the processor loads instructions from the memory to execute the steps in any model training method provided in the embodiment of the present application.
[0041] An embodiment of the present application also provides a computer-readable storage medium, which stores multiple instructions, and the instructions are suitable for a processor to load to execute the steps in any model training method provided in the embodiment of the present application.
[0042] The embodiment of the present application can obtain a text to be processed, which is composed of at least one text element; use a teacher model and a student model to process the text to be processed respectively to obtain a teacher result and a student result; determine the learning weight of the student model for the text elements; based on the teacher result, the student result and the learning weight of the text elements, determine the knowledge distillation loss of the student model for the text elements; based on the knowledge distillation loss of the student model for all text elements, guide the training of the student model until the student model converges to obtain a trained student model.
[0043] In the process of knowledge distillation, this application assigns corresponding learning weights to each text element, so that the knowledge in the teacher model can be distilled based on the learning weights to guide the student model, so that each text element contributes to the model training to varying degrees, and the trained model is more accurate when the computing resources occupied by the training are small. Therefore, the training model method proposed in this solution is more efficient than the existing technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0045] Figure 1a It is a scenario schematic diagram of the model training method provided in the embodiment of the present application;
[0046] Figure 1b It is a flowchart of the model training method provided in the embodiment of the present application;
[0047] Figure 2a Schematic diagram of knowledge distillation of the model training method provided in the embodiment of the present application;
[0048] Figure 2b It is a flowchart of the model training method provided in the embodiment of the present application applied in a translation scenario;
[0049] Figure 2c Schematic diagram of knowledge distillation of an existing translation model training method and a translation model training method provided by an embodiment of the present application;
[0050] Figure 3 It is a structural schematic diagram of a model training device provided in an embodiment of the present application;
[0051] Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0053] Embodiments of the present application provide a model training method, device, electronic device, and storage medium.
[0054] The model training device can be integrated into an electronic device, which can be a terminal, a server, or other device. The terminal includes but is not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle terminals, aircraft, and other devices; the server can be a single server or a server cluster consisting of multiple servers.
[0055] In some embodiments, the model training device can also be integrated into multiple electronic devices. For example, the model training device can be integrated into multiple servers, and the model training method of the present application can be implemented by multiple servers.
[0056] In some embodiments, the server may also be implemented in the form of a terminal.
[0057] For example, refer to Figure 1a The electronic device can obtain a text to be processed, which is composed of at least one text element; use a teacher model and a student model to process the text to be processed respectively to obtain a teacher result and a student result; determine the learning weight of the student model for the text element; based on the teacher result, the student result and the learning weight of the text element, determine the knowledge distillation loss of the student model for the text element; based on the knowledge distillation loss of the student model for all text elements, guide the student model training until the student model converges to obtain a trained student model.
[0058] It should be noted that the serial numbers of the following embodiments are not intended to limit the preferred order of the embodiments.
[0059] Artificial Intelligence (AI) is a technology that uses digital computers to simulate human perception of the environment, acquire knowledge, and use knowledge. This technology can enable machines to have functions similar to human perception, reasoning, and decision-making. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, as well as machine learning / deep learning, autonomous driving, smart transportation, and other major directions.
[0060] Natural language processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language people use in daily life, so it is closely related to the study of linguistics. Natural language processing technology usually includes text processing, semantic understanding, machine, robot question answering, knowledge graph and other technologies.
[0061] Machine Learning (ML) is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, knowledge distillation, belief networks, reinforcement learning, transfer learning, inductive learning, and teaching learning.
[0062] Autonomous driving technology usually includes high-precision maps, environmental perception, behavioral decision-making, path planning, motion control and other technologies. Autonomous driving technology has broad application prospects.
[0063] With the research and advancement of artificial intelligence technology, artificial intelligence technology has been studied and applied in many fields, such as common smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned driving, automatic driving, drones, robots, smart medical care, smart customer service, Internet of Vehicles, automatic driving, smart transportation, etc. I believe that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.
[0064] In this embodiment, a model training method based on artificial intelligence and its learning is provided, such as Figure 1b As shown, the specific process of the model training method can be as follows:
[0065] 110. Obtain text to be processed, where the text to be processed consists of at least one text element.
[0066] The text to be processed is composed of at least one text element, and the text element can be of any granularity, such as a character, a word, a sentence, a phrase, a paragraph, etc.
[0067] In some embodiments, the text to be processed may be an article to be translated, and the text elements may be words.
[0068] 120. The teacher model and the student model are used to process the text to be processed respectively to obtain the teacher result and the student result.
[0069] The teacher model (Teacher) and the student model (Student) can be any neural network model, for example, convolutional neural networks (CNN), recurrent neural networks (RNN), etc.
[0070] In this embodiment, the text to be processed can be input into the teacher model to obtain the output of the teacher model, that is, the teacher result of the text to be processed; the text to be processed can be input into the student model to obtain the output of the student model, that is, the student result of the text to be processed.
[0071] In some embodiments, the teacher model is a trained neural network model for translation. After the text to be processed is translated using the teacher model, a teacher translation result of the text to be processed can be obtained; after the text to be processed is translated using the student model, a student translation result of the text to be processed can be obtained.
[0072] Since the text to be processed is composed of at least one text element, the teacher result of the text to be processed includes the teacher result of the text element. For example, the teacher translation result of the article to be translated is composed of the teacher translation results of multiple words in it. Similarly, the student result of the text to be processed includes the student result of the text element.
[0073] For example, the text to be processed is "Today's weather is sunny", and the teacher's translation result of the text is "it's sunnytoday". Since the text is composed of three words, namely "today", "weather", and "sunny", the teacher's translation result of the text includes the teacher's translation results corresponding to these three words "today", "it's", and "sunny".
[0074] 130. Determine the learning weights of the student model for text elements.
[0075] This application assigns a learning weight w to each text element j j , which is used to dynamically control the contribution of each text element j in training. The learning weight can represent the degree of mastery of the text element by the student model.
[0076] In some embodiments, the student model's ability to grasp the text element can be represented by the student model's confidence in the text element. For example, if the student model has a high confidence in translating a text element j, it means that the student model has a good grasp of the text element j. Therefore, the student model does not need to invest too much effort in learning the word j, so a lower learning weight w can be assigned to the word j. j For another example, if the student model has a low confidence in translating a text element j, it means that the student model has not yet mastered the text element j, so a higher learning weight w needs to be assigned to the word j. j , making the word j contribute more in training.
[0077] Therefore, in some embodiments, the learning weights w j =1-C j S , C j S is the confidence of the student model S in the text element j, that is, the higher the confidence of the student model S in the text element j, the smaller the learning weight.
[0078] Similarly, in some embodiments, the learning weights w j =1 / C j S , that is, the higher the confidence of the student model S in the text element j, the smaller the learning weight.
[0079] In some embodiments, the student model's ability to grasp the text element can be characterized by the difference in confidence between the teacher model and the student model for the text element. For example, if the teacher model translates a text element j with a higher confidence, and the student model's confidence in translating the text element j is almost the same as that of the teacher model, it means that the student model has already learned the teacher model's knowledge of translating the word well, so the student model has a better grasp of the word and does not need to invest more effort in learning the word j. Therefore, a lower learning weight w can be assigned to the word j. j For another example, if the teacher model translates a text element j with a higher confidence, while the student model translates text element j with a lower confidence, it means that the student model needs to continue to learn about the text element j from the teacher model, so it is necessary to assign a higher learning weight w to the word j. j , which makes the student model more beneficial in learning the word j.
[0080] Therefore, in some embodiments, the learning weights C j S is the confidence of the student model S for text element j, C j Tis the confidence of the teacher model T in the text element j, that is, the lower the confidence of the student model S in the text element j and the higher the confidence of the teacher model T in the text element j, the greater the learning weight.
[0081] In some embodiments, the learning weights w j The confidence of the student model on the text element and the confidence difference between the teacher model and the student model on the text element can be used to characterize the text element. Therefore, in some embodiments, step 130 may include the following steps:
[0082] (1) Determine the confidence C of the teacher model T for text element j j T , and the confidence C of the student model S for text element j j S .
[0083] (2) Based on the confidence of the student model S, a first parameter is determined, where the first parameter represents the degree of mastery of the student model S on the text element j.
[0084] In some embodiments, the first parameter is 1-C j S .
[0085] In some embodiments, the first parameter is 1 / C j S .
[0086] (3) Based on the confidence of the teacher model T for the text element j and the confidence of the student model S for the text element j, a second parameter is determined, and the second parameter represents the difference between the student result and the teacher result.
[0087] In some embodiments, the second parameter is
[0088] (4) Determine the learning weight of the student model for the text element based on the first parameter and the second parameter.
[0089] In some embodiments, the learning weights are calculated as follows:
[0090]
[0091] Similarly, in some embodiments, the learning weights are calculated as follows:
[0092]
[0093] Among them, γ is the inverse integral operator, and exp is the exponential operator.
[0094] Therefore, in some embodiments, step (4) of determining the learning weight of the student model for the text element according to the first parameter and the second parameter may include the following steps:
[0095] Multiply the first parameter and the second parameter to obtain a mixed parameter;
[0096] Performing exponential operation based on the mixed parameter to obtain an exponential operation result;
[0097] Based on the results of exponential operation, abnormal integral processing is performed to obtain the learning weights of the student model for text elements.
[0098] For example, the mixing parameters are For example, the mixing parameters are
[0099] In some embodiments, given a text element pair (x, y), where x = x1, x3 ... x |x| , y=y1,y2,y3…y |y| , the confidence C of the teacher model T on the text element j j T and the confidence C of the student model S for text element j j S They can be expressed as follows:
[0100] C j T =P(y j |y <j,x;θ T )
[0101] C j S =P(y j |y <j,x;θ S )
[0102] 140. Based on the teacher results, student results and the learning weights of the text elements, determine the knowledge distillation loss of the student model for the text elements.
[0103] The student model’s knowledge distillation loss L for text elements cw-kd It refers to the difference in predictions of each text element between the teacher model and the student model after learning weight addition.
[0104] The difference in predictions between the teacher model and the student model for each text element can be expressed as the KL distance (Kullback-Leibler Divergence) between the teacher model and the student model, that is, relative entropy.
[0105] For example, in some embodiments, given a text element pair (x, y), where x = x1, x3, ... x|x| , y=y1,y2,y3…y |y| , the knowledge distillation loss L of the student model for text elements cw-kd The calculation method is as follows:
[0106]
[0107] Among them, V is the preset text element library, θ S is the model parameter of the student model, θ T are the model parameters of the teacher model, and p(…|…) represents the conditional probability.
[0108] 150. Based on the knowledge distillation loss of the student model for all text elements, guide the student model training until the student model converges to obtain a trained student model.
[0109] For example, in some embodiments, step 150 may include the following steps:
[0110] (1) Determine the specific gravity coefficient α ad , and the cross entropy loss L of the student model S ce ;
[0111] (2) Using specific gravity coefficient α ad The knowledge distillation loss L for the student model for all text elements cw-kd Perform weighted processing to obtain the weighted loss α ad L cw-kd ;
[0112] (3) According to the cross entropy loss L ce and weighted loss α ad L cw-kd , determine the overall training loss L;
[0113] (4) Train the student model based on the overall training loss L until the student model converges to obtain a trained student model.
[0114] Among them, the overall training loss L can be the cross entropy loss L ce and weighted loss αL cw-kd The sum of, for example, L = L ce +α ad L cw-kd .
[0115] In some embodiments, the cross entropy loss L ce The calculation method is as follows:
[0116]
[0117] in, is the indicator function.
[0118] The weight coefficient can be used to dynamically control the knowledge distillation loss L of the student model for all text elements cw-kd The weight of the training loss L.
[0119] In some embodiments, step (1) of determining the specific gravity coefficient may include the following steps:
[0120] (1.1) Determine the preset specific gravity coefficient α and balance parameter Q;
[0121] (1.2) The product of the equilibrium parameter and the preset specific gravity coefficient is taken as the specific gravity coefficient.
[0122] Among them, the specific gravity coefficient α ad =αQ, the value of the preset specific gravity coefficient α can be set according to application requirements.
[0123] The following describes how to set the balance parameter Q:
[0124] In some embodiments, the balance parameter Q may be linearly related to the number of training steps, and step (1.1) of determining the preset weight coefficient and the balance parameter may include the following steps:
[0125] Determine the preset weighting factor, the preset total number of training steps, and the current number of training steps;
[0126] The quotient of the current training step number and the preset total training step number is used as the balance parameter.
[0127] For example, if the current step number is n and the total training step number is N, the balance coefficient can be expressed as Q=n / N.
[0128] Therefore, the specific gravity coefficient α ad =α(n / N).
[0129] For example, in some embodiments, the balance coefficient is related to the confidence of the teacher model and the student model. In each batch, the technology of the present invention averages the confidence of the student model and the confidence of the teacher model for each word to represent the confidence level of the student model and the teacher model. Therefore, step (1.1) determines the preset weight coefficient and balance parameter and includes the following steps:
[0130] Determine a preset weighting factor, an average confidence of the student model for all text elements, and an average confidence of the teacher model for all text elements;
[0131] The quotient of the average confidence of the student model on all text elements and the average confidence of the teacher model on all text elements is taken as the balance parameter.
[0132] For example, the balance coefficient can be expressed as Q = avgC j S / avgCj T , avg represents the average function.
[0133] Therefore, the specific gravity coefficient α ad =α(avgC j S / avgC j T ).
[0134] The method provided by the embodiments of the present application can be applied in various NLP fields. For example, the embodiments of the present application can be applied in the fields of language translation, synonym conversion, etc.
[0135] As can be seen from the above, the embodiment of the present application can obtain a text to be processed, which is composed of at least one text element; use a teacher model and a student model to process the text to be processed respectively, and obtain a teacher result and a student result; determine the learning weight of the student model for the text element; based on the teacher result, the student result and the learning weight of the text element, determine the knowledge distillation loss of the student model for the text element; based on the knowledge distillation loss of the student model for all text elements, guide the student model training until the student model converges to obtain a trained student model. Therefore, this solution assigns different weights to different text elements in the process of knowledge distillation, so that the student model can focus on learning knowledge from the teacher model in the process of knowledge distillation, thereby improving the efficiency of model training.
[0136] The method described in the above embodiment will be further described in detail below.
[0137] In this embodiment, the method of the embodiment of the present application will be described in detail by taking the application in the field of language translation as an example.
[0138] refer to Figure 2a , the arrow indicates the direction of knowledge distillation, the number indicates the value of the learning weight, and the teacher model Teacher distills the knowledge of each word to the student model Student according to its corresponding learning weight; this method uses weight distribution to make each word play a different role in knowledge distillation. Therefore, the technology of the present invention can make the model not only pay attention to the learning of all words, but also learn with emphasis and purpose.
[0139] The specific process is as follows Figure 2b As shown in the figure, the specific process of a word-level model training method is as follows:
[0140] 210. Obtain a text to be translated, where the text to be translated consists of at least one word.
[0141] 220. The teacher model and the student model are used to translate the text to be translated respectively to obtain the teacher translation result and the student translation result.
[0142] 230. Determine the learning weight of the student model for the words.
[0143] Based on the model confidence, this embodiment uses the confidence of the teacher model and the confidence of the student model to perform a word segmentation and distillation experiment, and proposes that important word knowledge should have the following two characteristics:
[0144] 1. The lower the student model’s confidence in a word, the more important the knowledge of that word is in the distillation process.
[0145] 2. The teacher model has a higher confidence in a word than the student model, and the knowledge transferred by the word during the knowledge distillation process is more beneficial to the student model.
[0146] Based on the above two points, the weight is calculated as follows:
[0147]
[0148] in, This means that words with low confidence in the student model will be assigned a larger weight. The greater the confidence of the teacher model, the smaller the confidence of the student model, the greater the weight. In this way, the weight assigned to each word in this embodiment comprehensively considers the mastery of the teacher model and the student model on the word knowledge.
[0149] 240. Based on the teacher's translation results, the student's translation results and the learning weights of the words, determine the knowledge distillation loss of the student model for the words.
[0150] In addition to changing the original cumulative calculation method of knowledge distillation loss, this embodiment also proposes a progressive balancing coefficient to dynamically control the proportion of knowledge distillation loss in the overall training loss. The technology of the present invention proposes two strategies in total:
[0151] Strategy 1: The balance coefficient is linearly related to the number of training steps. The current step number is n, and the total number of training steps is N. The progressive balance coefficient can be expressed as:
[0152] α ad =α·(n / N)
[0153] Strategy 2: The balance coefficient is related to the confidence of the teacher model and the student model. In each batch, the technology of the present invention averages the confidence of the student model and the confidence of the teacher model for each word to represent the confidence level of the student model and the teacher model at this training step. Further based on the two average indicators, the progressive balance coefficient is expressed as follows:
[0154] α ad =α·(avgC S / avgCT )
[0155] 250. Based on the knowledge distillation loss of the student model for all words, guide the student model training until the student model converges to obtain the translation model.
[0156] By assigning different weights to different parts of words during the knowledge distillation process, the technology of the present invention allows the student model to differentiate during the knowledge distillation process and focus on learning knowledge from the teacher model, thereby giving full play to the potential of word-level knowledge. Furthermore, the technology of the present invention can effectively avoid the negative impact of unreliable confidence in the early stage of model training by regulating the progressive balance coefficient, so that knowledge distillation can more reliably enhance the student model. Experiments on multiple languages and multiple model settings have proven the effectiveness of the technology of the present invention.
[0157] like Figure 2c As shown, the embodiment of the present application compares the currently common translation model training methods Word-KD, Seq-KD, Selective-KD and the translation model training method CW-KD proposed in the present application. Among them, Word-KD is a distillation method at word granularity, that is, the teacher model Teacher distills each word to the student model Student; Seq-KD is a distillation method at sentence granularity, that is, the teacher model Teacher distills each sentence to the student model Student; Selective-KD is a selective distillation method at word granularity, that is, the teacher model Teacher distills part of the word knowledge to the student model Student; CW-KD is a weighted distillation method at word granularity, that is, a corresponding weight is assigned to each word knowledge, and the teacher model Teacher focuses on distilling each word knowledge to the student model Student according to its weight.
[0158] For Figure 2c The training method shown in the figure is experimentally tested in this embodiment, and the experimental results are shown in Table 1 and Table 2:
[0159] Table 1
[0160]
[0161] Among them, the teacher model and student model used in this experiment are both Transformer-Base (a translation model based on encoding-decoding); the translation text library used is WMT14 En-De (an English-German translation text library) and WMT19Zh-En (a Chinese-English translation text library); the bilingual translation quality evaluation tools used are BLEU (Bilingual Evaluation Understudy) and the trained COMET (Commonsense Transformers).
[0162] According to Table 1, the confidence of the student models trained by the existing training methods Word-KD, Seq-KD, and Selective-KD are all lower than that of the CW-KD proposed in this application, regardless of whether or not a balance coefficient is used or any balance coefficient is used, and the student model after CW-KD training is closest to the teacher model.
[0163] Table 2
[0164] Model BLUE COMET Transformer-Big(Teacher) 0.2946 0.2283 Transformer-Base(Student) 0.2782 0.1395 Word-KD 0.2871 0.1953 Seq-KD 0.2886 0.1989 Selective-KD 0.2889 0.2000 CW-KD (no balance coefficient) 0.2905 0.2079 CW-KD (balance coefficient of strategy 1) 0.2909 0.2141 CW-KD (Balance coefficient of strategy 2) 0.2921 0.2228
[0165] Among them, the teacher model used in this experiment is Transformer-Big, and the student model is Transformer-Base. Both Transformer-Big and Transformer-Base are translation models based on encoding-decoding, but the model structure of Transformer-Big is more complex than that of Transformer-Base.
[0166] According to Table 2, the confidence of the student models trained by the existing training methods Word-KD, Seq-KD, and Selective-KD are all lower than that of the CW-KD proposed in this application, regardless of whether or not a balance coefficient is used or any balance coefficient is used, and the student model after CW-KD training is closest to the teacher model.
[0167] From the above, it can be seen that the embodiment of the present application comprehensively considers the mastery of each word by the teacher model and the student model, and calculates and assigns corresponding weights to each word in the knowledge distillation process, so that each word makes different contributions in the distillation process; in addition, the embodiment of the present application also proposes a balance coefficient, which controls the contribution ratio of knowledge in the distillation process as the training process changes dynamically, so that the student model gradually learns knowledge from the teacher model. Compared with traditional knowledge distillation technology, the technology of the present invention does not treat each word equally, but from a more granular perspective, and the technology of the present invention comprehensively considers the opinions of the teacher model and the student model, assigns a learning weight to each word, and maximizes the knowledge potential of each word. The embodiment of the present application also takes into account the changes in the reliability of knowledge in the knowledge distillation process. By adding a progressive balance coefficient, the proportion of knowledge distillation loss in the overall training loss can be controllably increased, reducing the negative impact of unreliable knowledge in the early stage of training.
[0168] The embodiments of the present application can be used in vehicle-mounted scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc. For example, the trained student model in the embodiments of the present application has a similar degree of mastery of translation knowledge as the teacher model, but because its network structure is simpler and has fewer network parameters, the trained student model consumes less computing resources and has higher translation efficiency, so it can be installed in vehicle-mounted equipment to provide users with vehicle-mounted translation services.
[0169] In order to better implement the above method, the embodiment of the present application also provides a model training device, which can be integrated in an electronic device, and the electronic device can be a terminal, a server, etc. Among them, the terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, a personal computer, etc.; the server can be a single server or a server cluster composed of multiple servers.
[0170] For example, in this embodiment, the method of the embodiment of the present application will be described in detail by taking the specific integration of the model training device in the terminal as an example.
[0171] For example, Figure 3 As shown, the model training device may include an acquisition unit 301, a processing unit 302, a weight unit 303, a loss unit 304, and a training unit 305, as follows:
[0172] (i) acquiring unit 301,
[0173] The acquisition unit 301 is used to acquire the text to be processed, where the text to be processed is composed of at least one text element.
[0174] (ii) Processing unit 302.
[0175] The processing unit 302 is used to use the teacher model and the student model to process the text to be processed respectively to obtain the teacher result and the student result.
[0176] (iii) Weight unit 303.
[0177] The weight unit 303 is used to determine the learning weight of the student model for the text element.
[0178] In some embodiments, the weight unit 303 includes:
[0179] A confidence subunit, for determining the confidence of the teacher model on the text element and the confidence of the student model on the text element;
[0180] A first parameter subunit, used to determine a first parameter based on the confidence of the student model, the first parameter representing the mastery of the text element by the student model;
[0181] A second parameter subunit, used to determine a second parameter based on the confidence of the teacher model on the text element and the confidence of the student model on the text element, wherein the second parameter represents the difference between the text element of the student model and the text element of the teacher model;
[0182] The weight subunit is used to determine the learning weight of the student model for the text element based on the first parameter and the second parameter.
[0183] In some embodiments, the weight subunit is used to:
[0184] Multiply the first parameter and the second parameter to obtain a mixed parameter;
[0185] Performing exponential operation based on the mixed parameter to obtain an exponential operation result;
[0186] Based on the results of exponential operation, abnormal integral processing is performed to obtain the learning weights of the student model for text elements.
[0187] (iv) Loss unit 304.
[0188] The loss unit 304 is used to determine the knowledge distillation loss of the student model for the text elements based on the teacher results, the student results and the learning weights of the text elements.
[0189] (V) Training unit 305.
[0190] The training unit 305 is used to guide the student model training based on the knowledge distillation loss of the student model for all text elements until the student model converges to obtain a trained student model.
[0191] In some embodiments, the training unit 305 includes:
[0192] Determine the subunits used to determine the weight coefficients and the cross entropy loss of the student model;
[0193] The weighted loss subunit is used to weight the knowledge distillation loss of the student model for all text elements using a weight coefficient to obtain a weighted loss;
[0194] The overall training loss subunit is used to determine the overall training loss based on the cross entropy loss and the weighted loss;
[0195] The training subunit is used to train the student model based on the overall training loss until the student model converges to obtain a trained student model.
[0196] In some embodiments, determining a subunit includes:
[0197] A coefficient submodule, used to determine a preset specific gravity coefficient and a balance parameter;
[0198] The coefficient submodule is used to take the product of the balance parameter and the preset specific gravity coefficient as the specific gravity coefficient.
[0199] In some embodiments, the coefficient submodule is used to:
[0200] Determine the preset weighting factor, the preset total number of training steps, and the current number of training steps;
[0201] The quotient of the current training step number and the preset total training step number is used as the balance parameter.
[0202] In some embodiments, the coefficient submodule is used to:
[0203] Determine a preset weighting factor, an average confidence of the student model for all text elements, and an average confidence of the teacher model for all text elements;
[0204] The quotient of the average confidence of the student model on all text elements and the average confidence of the teacher model on all text elements is taken as the balance parameter.
[0205] In specific implementation, the above units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units can refer to the previous method embodiments, which will not be repeated here.
[0206] As can be seen from the above, the model training device of this embodiment obtains the text to be processed by the acquisition unit, and the text to be processed is composed of at least one text element; the processing unit uses the teacher model and the student model to process the text to be processed respectively, and obtains the teacher result and the student result; the weight unit determines the learning weight of the student model for the text element; the loss unit determines the knowledge distillation loss of the student model for the text element based on the teacher result, the student result and the learning weight of the text element; the training unit guides the student model training based on the knowledge distillation loss of the student model for all text elements until the student model converges to obtain a trained student model.
[0207] Therefore, the embodiments of the present application can improve the efficiency of model training.
[0208] The embodiment of the present application also provides an electronic device, which can be a terminal, a server, etc. The terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, a personal computer, etc. The server can be a single server or a server cluster composed of multiple servers, etc.
[0209] In some embodiments, the model training device can also be integrated into multiple electronic devices. For example, the model training device can be integrated into multiple servers, and the model training method of the present application can be implemented by multiple servers.
[0210] In this embodiment, the electronic device of this embodiment is a terminal as an example for detailed description, for example, Figure 4 As shown, it shows a schematic diagram of the structure of the electronic device involved in the embodiment of the present application, specifically:
[0211] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, an input module 404, and a communication module 405. Those skilled in the art will appreciate that Figure 4 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0212] The processor 401 is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device. It executes various functions of the electronic device and processes data by running or executing software programs and / or modules stored in the memory 402, and calling data stored in the memory 402. In some embodiments, the processor 401 may include one or more processing cores; in some embodiments, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.
[0213] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0214] The electronic device also includes a power supply 403 for supplying power to various components. In some embodiments, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 403 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0215] The electronic device may further include an input module 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0216] The electronic device may further include a communication module 405. In some embodiments, the communication module 405 may include a wireless module. The electronic device may perform short-range wireless transmission through the wireless module of the communication module 405, thereby providing the user with wireless broadband Internet access. For example, the communication module 405 may be used to help the user send and receive emails, browse web pages, and access streaming media.
[0217] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby realizing various functions, as follows:
[0218] Obtaining the text to be processed, where the text to be processed consists of at least one text element;
[0219] The teacher model and the student model are used to process the text to be processed respectively to obtain the teacher result and the student result;
[0220] Determine the learning weights of the student model for the text elements;
[0221] Determine the knowledge distillation loss of the student model for the text elements based on the teacher results, the student results, and the learning weights of the text elements;
[0222] Based on the knowledge distillation loss of the student model for all text elements, the student model training is guided until the student model converges to obtain a trained student model.
[0223] In some embodiments, a computer program product is also proposed, including a computer program or instructions, which implement the steps in any of the above-mentioned model training methods when executed by a processor.
[0224] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0225] From the above, it can be seen that the embodiments of the present application can improve the efficiency of model training.
[0226] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0227] To this end, an embodiment of the present application provides a computer-readable storage medium, which stores multiple instructions, which can be loaded by a processor to execute the steps in any model training method provided in the embodiment of the present application. For example, the instruction can execute the following steps:
[0228] Obtaining the text to be processed, where the text to be processed consists of at least one text element;
[0229] The teacher model and the student model are used to process the text to be processed respectively to obtain the teacher result and the student result;
[0230] Determine the learning weights of the student model for the text elements;
[0231] Determine the knowledge distillation loss of the student model for the text elements based on the teacher results, the student results, and the learning weights of the text elements;
[0232] Based on the knowledge distillation loss of the student model for all text elements, the student model training is guided until the student model converges to obtain a trained student model.
[0233] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0234] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program including computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in various optional implementations of the text processing or language translation aspects provided in the above embodiments.
[0235] Since the instructions stored in the storage medium can execute the steps in any model training method provided in the embodiments of the present application, the beneficial effects that can be achieved by any model training method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0236] The above is a detailed introduction to a model training method, device, electronic device and computer-readable storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A model training method, characterized in that: include: Acquire a text to be processed, wherein the text to be processed is composed of at least one text element; The text to be processed is processed using a teacher model and a student model to obtain a teacher result and a student result respectively; Determining the learning weight of the student model for the text element; Determining the knowledge distillation loss of the student model for the text element based on the teacher result, the student result, and the learning weight of the text element; Based on the knowledge distillation loss of the student model for all the text elements, guiding the training of the student model until the student model converges to obtain a trained student model; Determining the learning weight of the student model for the text element includes: Determining the confidence of the teacher model for the text element and the confidence of the student model for the text element; Based on the confidence of the student model, determining a first parameter, wherein the first parameter represents the degree of mastery of the text element by the student model; Determining a second parameter based on the confidence of the teacher model for the text element and the confidence of the student model for the text element, wherein the second parameter characterizes the difference between the student result and the teacher result; Multiplying the first parameter and the second parameter to obtain a mixed parameter; Performing an exponential operation based on the mixing parameter to obtain an exponential operation result; An abnormal integral process is performed based on the exponential operation result to obtain the learning weight of the student model for the text element.
2. The model training method according to claim 1, characterized in that: The method of guiding the training of the student model based on the knowledge distillation loss of all the text elements of the student model until the student model converges to obtain a trained student model includes: Determining a weighting coefficient and a cross entropy loss of the student model; The weight coefficient is used to weight the knowledge distillation loss of the student model for all the text elements to obtain a weighted loss; Determining an overall training loss according to the cross entropy loss and the weighted loss; The student model is trained based on the overall training loss until the student model converges to obtain a trained student model.
3. The model training method according to claim 2, characterized in that: Determining the specific gravity coefficient comprises: Determine preset specific gravity coefficient and balance parameters; The product of the balance parameter and the preset specific gravity coefficient is used as the specific gravity coefficient.
4. The model training method according to claim 3, characterized in that: The step of determining the preset specific gravity coefficient and balance parameter comprises: Determine the preset weighting factor, the preset total number of training steps, and the current number of training steps; The quotient of the current training step number and the preset total training step number is used as a balance parameter.
5. The model training method according to claim 3, characterized in that: The step of determining the preset specific gravity coefficient and balance parameter comprises: Determining a preset weight coefficient, an average confidence of the student model for all the text elements, and an average confidence of the teacher model for all the text elements; The quotient of the average confidence of the student model for all the text elements and the average confidence of the teacher model for all the text elements is used as a balancing parameter.
6. A model training device, characterized in that: include: An acquisition unit, used for acquiring a text to be processed, wherein the text to be processed is composed of at least one text element; A processing unit, used to process the text to be processed using a teacher model and a student model respectively to obtain a teacher result and a student result; A weight unit, used to determine the learning weight of the student model for the text element; A loss unit, configured to determine a knowledge distillation loss of the student model for the text element based on the teacher result, the student result, and the learning weight of the text element; A training unit, used for guiding the training of the student model based on the knowledge distillation loss of the student model for all the text elements, until the student model converges to obtain a trained student model; The weight unit is used for: Determining the confidence of the teacher model for the text element and the confidence of the student model for the text element; Based on the confidence of the student model, determining a first parameter, wherein the first parameter represents the degree of mastery of the text element by the student model; Determining a second parameter based on the confidence of the teacher model for the text element and the confidence of the student model for the text element, wherein the second parameter characterizes the difference between the student result and the teacher result; Determining the learning weight of the student model for the text element according to the first parameter and the second parameter; Multiplying the first parameter and the second parameter to obtain a mixed parameter; Performing an exponential operation based on the mixing parameter to obtain an exponential operation result; An abnormal integral process is performed based on the exponential operation result to obtain the learning weight of the student model for the text element.
7. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps in the model training method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, which are suitable for loading by a processor to execute the steps in the model training method described in any one of claims 1 to 5.
Citation Information
Patent Citations
Model distillation method and device, storage medium and equipment
CN112465138A
Student model training method and device, computer equipment and storage medium
CN112749728A
Knowledge distillation-based sketch processing method and system
CN113360701A
