Knowledge distillation method, apparatus, apparatus and media

By using the supervised training of training original text and standard translation text in the student translation model, the problem that the student translation model cannot obtain performance equivalent to that of the teacher model is solved, and the effective transfer of knowledge and the improvement of translation performance are achieved.

CN118690759APending Publication Date: 2024-09-24BEIJING YOUZHUJU NETWORK TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410825002.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-25
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

It is difficult for the student translation model to achieve translation performance equivalent to that of the teacher model during the knowledge distillation process, mainly due to its limited capabilities, which results in the inability to effectively transfer the knowledge of the teacher model.

Method used

By obtaining the training original text and the standard translation text, inputting the teacher translation model and the student translation model respectively, the teacher distribution and the student distribution are generated, and the student model is iteratively trained according to the standard translation distribution, and the teacher distribution and the standard translation distribution are used for supervised training. Progressively transfer knowledge from teacher models.

Benefits of technology

The knowledge of the teacher translation model is effectively transferred to the student translation model, so that the student model obtains translation performance equivalent to that of the teacher model and improves the translation quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690759A
    Figure CN118690759A
Patent Text Reader

Abstract

The invention provides a knowledge distillation method and device, equipment and a medium. The method comprises the steps of obtaining a training original text and a standard translation text corresponding to the training original text; respectively inputting the training original text into a teacher translation model and a student translation model to obtain teacher distribution output by the teacher translation model and student distribution output by the student translation model; obtaining standard translation distribution according to the standard translation text and the training original text; and performing iterative training on the student translation model according to the teacher distribution, the student distribution and the standard translation distribution to obtain a target machine translation model. According to the method, knowledge of the teacher translation model can be effectively transferred to the student translation model, so that the student translation model can obtain translation performance equivalent to that of the teacher translation model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a knowledge distillation method, apparatus, device and medium. Background Art

[0002] Knowledge Distillation (KD) is a model compression method that can transfer knowledge from the teacher model to the student model, so that the student model can reduce the complexity of the model while maintaining performance. It is widely used in the fields of computer vision and natural language processing. For example, knowledge distillation can be applied to machine translation, an important branch of natural speech processing.

[0003] However, since the capabilities of the student translation model are usually limited, the knowledge of the teacher translation model often cannot be effectively transferred to the student translation model, making the student translation model unable to have translation performance comparable to that of the teacher translation model. Summary of the invention

[0004] The embodiments of the present application provide a knowledge distillation method, apparatus, device and medium, which can effectively transfer the knowledge of a teacher translation model to a student translation model, so that the student translation model can obtain translation performance comparable to that of the teacher model.

[0005] In a first aspect, an embodiment of the present application provides a knowledge distillation method, comprising:

[0006] Obtaining a training original text and a standard translation text corresponding to the training original text;

[0007] Inputting the training original text into a teacher translation model and a student translation model respectively, obtaining a teacher distribution output by the teacher translation model and a student distribution output by the student translation model;

[0008] Obtaining a standard translation distribution according to the standard translation text and the training original text;

[0009] According to the teacher distribution, the student distribution and the standard translation distribution, the student translation model is iteratively trained to obtain a target machine translation model.

[0010] In a second aspect, an embodiment of the present application provides a knowledge distillation device, comprising:

[0011] A sample acquisition module, used to acquire a training original text and a standard translation text corresponding to the training original text;

[0012] A first processing module is used to input the training original text into a teacher model and a student translation model respectively, to obtain a teacher distribution output by the teacher model and a student distribution output by the student translation model;

[0013] A second processing module, configured to obtain a standard translation distribution according to the standard translation text and the training original text;

[0014] The knowledge distillation module is used to iteratively train the student translation model according to the teacher distribution, the student distribution and the standard translation distribution to obtain a target machine translation model.

[0015] In a third aspect, an embodiment of the present application provides an electronic device, including:

[0016] A processor and a memory, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute the knowledge distillation method as described in the embodiment of the first aspect.

[0017] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium for storing a computer program, wherein the computer program enables a computer to execute the knowledge distillation method as described in the embodiment of the first aspect.

[0018] In a fifth aspect, an embodiment of the present application provides a computer program product comprising program instructions. When the program instructions are executed on an electronic device, the electronic device executes the knowledge distillation method as described in the embodiment of the first aspect.

[0019] The technical solution disclosed in the embodiment of the present application is to input the acquired training original text into the teacher translation model and the student translation model respectively to obtain the teacher distribution output by the teacher translation model and the student distribution output by the student translation model, and obtain the standard translation distribution according to the acquired standard translation text and the training original text, and then iteratively train the student translation model according to the teacher distribution, the student distribution and the standard translation distribution to obtain the target machine translation model. The present application supervises the training process of the student translation model by utilizing the teacher distribution output by the teacher translation model and the standard translation distribution corresponding to the standard translation text, so that the knowledge of the teacher translation model can be effectively transferred to the student translation model, so that the student translation model can obtain translation performance equivalent to that of the teacher model. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] 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 ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0021] Figure 1 A schematic diagram of a knowledge distillation scenario provided for an embodiment of the present application;

[0022] Figure 2 A flow chart of a knowledge distillation method provided in an embodiment of the present application;

[0023] Figure 3 A flowchart of a student translation model for training provided in an embodiment of the present application;

[0024] Figure 4 A schematic block diagram of a knowledge distillation device provided in an embodiment of the present application;

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

[0026] 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. According to the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0027] It should be noted that the terms "first", "second", etc. in the specification and claims 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 server that includes 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.

[0028] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or scheme described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or schemes. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0029] In the description of the embodiments of the present application, unless otherwise specified, "a plurality of" refers to two or more than two, that is, at least two. "At least one" refers to one or more than one.

[0030] In related technologies, knowledge distillation can be applied to machine translation in the field of natural language processing, because it can transfer knowledge from the teacher model to the student translation model, so that the student translation model can reduce model complexity while maintaining performance. However, since the capabilities of the student translation model are usually limited, the knowledge of the teacher translation model is often not effectively transferred to the student translation model, so that the student translation model cannot have the same translation performance as the teacher translation model.

[0031] In order to solve the above technical problems, the present application provides a knowledge distillation method, apparatus, device and medium, which can effectively transfer the knowledge of the teacher translation model to the student translation model, so that the student translation model can obtain translation performance comparable to that of the teacher model.

[0032] The technical solution of the present application is described in detail below through some embodiments. The embodiments described below can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.

[0033] Figure 1 A schematic diagram of a knowledge distillation scenario provided for an embodiment of the present application. Figure 2 A flow chart of a knowledge distillation method provided for an embodiment of the present application. The embodiment of the present application can be applied to the knowledge learning scenario of the machine translation model. The knowledge distillation method can be performed by a knowledge distillation device, which can be composed of hardware and / or software and can be integrated into an electronic device. In the present application, the electronic device can be a server, a laptop computer, a personal desktop computer, a computer device, etc., and there is no restriction on the type of electronic device.

[0034] like Figure 2 As shown, the method may include the following steps:

[0035] S101, obtaining a training original text and a standard translation text corresponding to the training original text.

[0036] In some optional embodiments, the original training text and the standard translation text corresponding to the original training text may be manually edited, or any other acquisition method may be used, such as acquiring the original training text and the standard translation text corresponding to the original training text from open source training corpus, etc. This application does not impose any specific restrictions on this.

[0037] In the present application, the number of training original texts and standard translation texts can be multiple, that is, the present application can obtain a training sample set. Moreover, each set of training original texts and standard translation texts in the training sample can be understood as a parallel corpus.

[0038] Exemplarily, the above parallel corpus can be as follows:

[0039] Original text 1: I like spring; Standard translation text 1: I like spring;

[0040] Original text 2: This is a cat; Standard translation text 2: This is a cat.

[0041] Considering each training original text and standard translation text in the training sample set, the training process of the student translation model is the same. For example, in each training process, a training original text is input to the student translation model and the teacher translation model. When the training of the training original text is completed, the next training original text is input and training begins again. Therefore, in order to facilitate the description of the technical solution of the present application, the present application will take a training original text as an example to illustrate the training process of the student translation model in the following embodiments.

[0042] S102, inputting the original training text into the teacher translation model and the student translation model respectively, obtaining the teacher distribution output by the teacher translation model and the student distribution output by the student translation model.

[0043] In this application, the teacher translation model is a machine translation model that has been trained in advance, and the student translation model is a machine translation model to be trained. The machine translation model to be trained can be understood as an initial machine translation model or an untrained student model.

[0044] The teacher translation model is in prediction mode, which freezes the model parameters of the teacher translation model so that the model parameters of the teacher translation model will not be modified during the training of the student translation model. The student translation model is in training mode, that is, during the training of the student translation model, the model parameters in the student translation model can be modified.

[0045] Furthermore, the capacity and scale of the teacher translation model are greater than those of the student translation model.

[0046] As an optional implementation, the teacher translation model and the student translation model in this application can be selected as large language models. It should be understood that the above-mentioned large language model (Large Language Model 1, LLM) is a deep learning model trained based on a large amount of training data, which can be proficient in language processing tasks, such as translation tasks, text generation, etc.

[0047] In addition, the teacher translation model and the student translation model in this application can realize language translation of any language pair, such as Chinese to English, English to German, German to French, etc.

[0048] In some optional embodiments, the present application can use the acquired training original text as input data and input it into Figure 1 The teacher translation model and student translation model shown are used to enable the teacher translation model and the student translation model to respectively segment the original training text to obtain word sequences, and then process the word sequences to obtain the teacher distribution output by the teacher translation model and the student distribution output by the student translation model.

[0049] In some optional embodiments, the teacher translation model and the student translation model perform word segmentation processing on the training original text, which can be implemented by a preset word segmentation method, wherein the preset word segmentation method can be, but is not limited to, a Byte Pair Encoder (BPE) algorithm, etc. The BPE algorithm is a data compression algorithm used to implement variable-length subwords in a fixed-size vocabulary, and the specific implementation process is to split the word into single characters, and then replace the pair of characters with the highest frequency with another character in turn, and repeat this operation until the number of words in the vocabulary reaches a preset value or the frequency of the next highest-frequency byte pair is 1.

[0050] In this application, the teacher distribution can be selected as the first candidate word probability distribution, and the student distribution can be selected as the second candidate word probability distribution. The first candidate word probability distribution contains the knowledge of the teacher translation model, and the second candidate word probability distribution contains the knowledge of the student translation model.

[0051] In addition, each of the above candidate word probability distributions will correspond to a translation candidate word.

[0052] Each candidate word for translation can be represented as a token. That is, a token corresponds to a probability distribution of the size of a word list. It should be understood that the above token can also represent the location of a candidate word for translation.

[0053] In addition, during the training process of the student translation model, the present application can obtain a translation word segmentation sequence based on the standard translation text, and then generate n word probability distributions based on the size n of the translation word segmentation sequence. Among them, each word segmentation in the translation word segmentation sequence corresponds to a word probability distribution. Because the position corresponding to each word segmentation is unique and fixed, it can be determined that each position in the translation word segmentation sequence corresponds to a word probability distribution. That is, each word segmentation in the translation word segmentation sequence and the word probability distribution corresponding to the position where each word segmentation is located are the same.

[0054] It should be understood that the above-mentioned probability distribution of a word represents the model's prediction of all possibilities of selecting a target translation word segment at a position. The model includes a student translation model and a teacher translation model.

[0055] For example, assuming that the original training text is "I like spring", the original word segmentation sequence of the original training text is [I like spring], and the translated word segmentation sequence corresponding to the original word segmentation sequence [I like spring] is [I like spring], where "I" is the word segmentation at the first position, "like" is the word segmentation at the second position, and "spring" is the word segmentation at the third position. Then, based on these three positions, it can be determined that the teacher translation model and the student translation model will generate three candidate word probability distributions respectively. Among them, each of the above three positions will correspond to a candidate word probability distribution.

[0056] Then, when the vocabulary is [I like spring], the vocabulary size is determined to be 6. At this time, based on the vocabulary size of 6, the probability distribution of the first candidate word in the first position output by the teacher translation model (i.e., teacher distribution) can be {0.1, 0.2, 0.1, 0.4, 0.1, 0.1}, the probability distribution of the first candidate word in the second position output by the teacher translation model can be {0.1, 0.2, 0.1, 0.2, 0.3, 0.1}, and the probability distribution of the first candidate word in the third position output by the teacher translation model can be {0.2, 0.1, 0.2 , 0.1, 0.1, 0.4}; similarly, the probability distribution of the second candidate word at the first position output by the student translation model (i.e., student distribution) can be {0.4, 0.2, 0.1, 0.1, 0.1, 0.1}, the probability distribution of the second candidate word at the second position output by the student translation model can be {0.1, 0.3, 0.1, 0.1, 0.2, 0.2}, and the probability distribution of the second candidate word at the third position output by the student translation model can be {0.2, 0.1, 0.4, 0.1, 0.1, 0.1}.

[0057] S103, obtaining a standard translation distribution according to the standard translation text and the training original text.

[0058] In some optional embodiments, the standard translation text may be segmented to obtain a translation word sequence, and the training original text may be segmented to obtain an original word sequence. Then, a target word list is obtained based on the translation word sequence and the original word sequence. Furthermore, the translation word sequence is one-hot encoded based on the target word list to obtain a standard translation distribution.

[0059] It should be understood that one-hot encoding is an effective encoding that uses an N-bit state register to encode N states, each state corresponds to an independent register bit, and at any time, only one valid bit

[0060] Exemplarily, assuming that the training original text is "I like spring" and the standard translation text is "I like spring", then the preset word segmentation method can be used to segment "I like spring" to obtain the original word segmentation sequence [I like spring], and the preset word segmentation method can be used to segment "I like spring" to obtain the translation word segmentation sequence: [I like spring]. Because the size of the original word segmentation sequence is 3, and the size of the translation word segmentation sequence is 3, the size of the target word list is calculated to be 3+3=6 according to the size of the original word segmentation sequence and the size of the translation word segmentation sequence. That is, N in the N-bit state register is equal to 6. And the target word list is specifically [I like spring I like spring]. Then, according to the size of the target word list 6, the word segmentation at each position in the translation word segmentation sequence is uniquely encoded to obtain the standard translation distribution corresponding to each position. Specifically, the standard translation distribution corresponding to the first position in the translation word segmentation sequence is {0,0,0,1,0,0}, the standard translation distribution corresponding to the second position in the translation word segmentation sequence is {0,0,0,0,1,0}, and the standard translation distribution corresponding to the third position in the translation word segmentation sequence is {0,0,0,0,0,1}.

[0061] It should be noted that the execution order of the above-mentioned steps S102 and S103 can be to execute step S102 first and then step S103; or to execute step S103 first and then step S102; or to execute step S102 and step S103 at the same time, and this application does not impose any restrictions on this.

[0062] S104, iteratively training the student translation model according to the teacher distribution, the student distribution and the standard translation distribution to obtain a target machine translation model.

[0063] In some optional embodiments, a target distribution can be first calculated based on the teacher distribution and the standard translation distribution corresponding to each position. Among them, the target distribution can be understood as the probability distribution of the third candidate word. Then, the error between the target distribution corresponding to each position and the student distribution is determined. And, it is determined whether the error between the target distribution corresponding to each position and the student distribution is greater than the preset error. If the error between the target distribution corresponding to any position and the student distribution is less than or equal to the preset error, it means that these positions are easy to learn or easy to distill (that is, the word segmentation at these positions is easy to learn or easy to distill). If the error between the target distribution corresponding to any position and the student distribution is greater than the preset error, it means that the position is difficult to distill or difficult to learn for the student translation model (that is, the word segmentation at these positions is difficult to learn or difficult to distill). At this time, these difficult-to-learn positions are screened out. Afterwards, the target distribution corresponding to the screened difficult-to-learn position is exposed to the student translation model, so that the student translation model learns the word segmentation at the above-mentioned difficult-to-learn position based on the exposed target distribution exposure, so as to help the student translation model learn the word segmentation at the difficult-to-learn position, so that the student translation model can obtain the knowledge of the teacher translation model, thereby having a translation ability equivalent to the teacher translation model.

[0064] In this application, the preset error can be set according to the model translation accuracy, and no limitation is imposed on it here.

[0065] For example, assuming that the target vocabulary is [I like spring I like spring], and the translation word sequence corresponding to the standard translation text is [I like spring], it can be determined that the word corresponding to the first position is "I", when the target distribution corresponding to "I" is {0.05, 0.1, 0.05, 0.7, 0.05, 0.05}, and the student distribution corresponding to "I" is {0.4, 0.2, 0.1, 0.1, 0.1, 0.1}, then it can be determined that the word with the maximum probability in the target distribution corresponding to "I" is "I", and the word with the maximum probability in the student distribution corresponding to "I" is "I", then the error value calculated according to the target distribution and student distribution corresponding to "I" is greater than the preset error. Then, it can be determined that the student translation model has not yet achieved good translation performance, that is, it is determined that the word segmentation "I" located at the first position is difficult for the student translation model to learn. At this time, the target distribution corresponding to the word segmentation "I" located at the first position is exposed to the student translation model, so that the student translation model can learn the word segmentation "I" located at the first position that is difficult to learn based on the target distribution corresponding to the word segmentation "I" located at the first position.

[0066] In some optional embodiments, after obtaining the trained student translation model, the present application may use the student translation model as a target machine translation model. Furthermore, the target machine translation model may be deployed on any device to perform machine translation operations.

[0067] The technical solution disclosed in the embodiment of the present application is to input the acquired training original text into the teacher translation model and the student translation model respectively to obtain the teacher distribution output by the teacher translation model and the student distribution output by the student translation model, and obtain the standard translation distribution according to the acquired standard translation text and the training original text, and then iteratively train the student translation model according to the teacher distribution, the student distribution and the standard translation distribution to obtain the target machine translation model. The present application supervises the training process of the student translation model by utilizing the teacher distribution output by the teacher translation model and the standard translation distribution corresponding to the standard translation text, so that the knowledge of the teacher translation model can be effectively transferred to the student translation model, so that the student translation model can obtain translation performance equivalent to that of the teacher model.

[0068] Combine the following Figure 3 , further explains the knowledge distillation method provided in the embodiment of the present application. Figure 3 As shown, Figure 2 The step S104 shown may also include the following steps S104-1 to S104-2:

[0069] S104-1, obtain the target distribution according to the teacher distribution and the standard translation distribution.

[0070] In some optional embodiments, the average value of the teacher distribution and the standard translation distribution corresponding to each of the n positions may be calculated according to the size n of the translation word segmentation sequence, and the average value may be used as the target distribution corresponding to each position.

[0071] As an optional implementation method, the target distribution corresponding to each position can be calculated by the following formula (1):

[0072]

[0073] in, is the target distribution corresponding to the i-th position, is the teacher distribution corresponding to the i-th position, is the standard translation distribution corresponding to the i-th position, where i is greater than or equal to 1, and i is less than or equal to the translation word sequence size n.

[0074] S104-2, iteratively train the student translation model according to the target distribution and the student distribution to obtain the target machine translation model.

[0075] In some optional embodiments, iteratively training the student translation model to obtain a target machine translation model may include the following steps:

[0076] Step 1: Get the first loss value based on the error between the target distribution and the student distribution.

[0077] In some optional embodiments, the error between the target distribution and the student distribution corresponding to each position can be calculated, and the error can be used as the first loss value.

[0078] As an optional implementation method, the error (first loss value) between the target distribution and the student distribution corresponding to each position can be calculated by the following formula (2):

[0079]

[0080] in, is the first loss value between the target distribution and the student distribution corresponding to the i-th position, KL is the relative entropy, also known as KL divergence, is the student distribution corresponding to the i-th position, is the target distribution corresponding to the i-th position.

[0081] For example, assuming that a target word list is [I like singing I like singing], and the translation word sequence corresponding to the standard translation text is [I like singing], then when determining the first loss value corresponding to "like" at the second position, the above formula (2) is specifically: in, is the first loss value between the target distribution and the student distribution corresponding to the “like” at the second position, that is, is the first loss value corresponding to the second position, is the student distribution corresponding to the second position, is the target distribution corresponding to the second position.

[0082] Step 2: Select target segmented words and non-target segmented words from the translation segmented word sequence corresponding to the standard translation text according to the first loss value and the preset threshold.

[0083] The preset threshold can be set according to the model translation accuracy, and there is no restriction on it here.

[0084] Furthermore, the target segmentation can be understood as the segmentation that is difficult to learn or difficult to distill, and the non-target segmentation can be understood as the segmentation that is easy to learn or easy to distill.

[0085] In some optional embodiments, the first loss value corresponding to each position can be compared with a preset threshold value to determine which positions of the segmentation words are more difficult to learn and which positions of the segmentation words are easier to learn. If the first loss value corresponding to any position is greater than the preset threshold value, it means that the segmentation word at that position is difficult to learn. At this time, according to the position of the difficult-to-learn segmentation word, the same position is determined from the translation segmentation sequence corresponding to the standard translation text, and the segmentation word at the same position is determined as the target segmentation word. If the first loss value corresponding to any position is less than or equal to the preset threshold value, it means that the segmentation word at that position is easy to learn. At this time, according to the position of the easy-to-learn segmentation word, the same position is determined from the translation segmentation sequence corresponding to the standard translation text, and the segmentation word at the same position is determined as a non-target segmentation word.

[0086] That is, the present application selects target segmentations and non-target segmentations from a translation segmentation sequence corresponding to a standard translation text, including: if a first loss value between a target distribution and a student distribution corresponding to a segmentation at any position is greater than a preset threshold, then a first target position is determined from the translation segmentation sequence corresponding to the standard translation text according to the position, and the segmentation at the first target position is determined as a target segmentation; if a first loss value between a target distribution and a student distribution corresponding to a segmentation at any position is less than or equal to a preset threshold, then a second target position is determined from the translation segmentation sequence corresponding to the standard translation text according to the position, and the segmentation at the second target position is determined as a non-target segmentation.

[0087] Step 3: Determine the proxy distribution corresponding to the target word segmentation and the proxy distribution corresponding to the non-target word segmentation.

[0088] Considering that the target distribution integrates the teacher distribution and the standard translation distribution, in order to help the student translation model learn the above-mentioned difficult-to-learn target segmentations, the present application may expose the target distribution corresponding to the target segmentations to the student translation model so that the student translation model can continue to learn the difficult-to-learn target segmentations based on the exposed target distribution.

[0089] In some optional embodiments, exposing the target distribution corresponding to the target segmentation to the student translation model can be done by determining the proxy distribution corresponding to the target segmentation and the proxy distribution corresponding to the non-target segmentation, thereby training the student translation model according to the target distribution and the proxy distribution corresponding to the target segmentation, and the target distribution and the proxy distribution corresponding to the non-target segmentation, so that the student translation model can learn the above-mentioned difficult-to-learn target segmentation.

[0090] In some optional embodiments, the proxy distribution corresponding to the target word segmentation may be determined according to the target distribution and the student distribution corresponding to the target word segmentation.

[0091] As an optional implementation method, the above-mentioned determination of the proxy distribution corresponding to the target word segmentation can be implemented by the following formula (3):

[0092]

[0093] in, is the proxy distribution corresponding to the target word at the j-th position, that is, the proxy distribution corresponding to the j-th position, is the student distribution corresponding to the jth position, is the target distribution corresponding to the jth position. In this application, j is greater than or equal to 1 and less than or equal to the size of the translated word sequence n.

[0094] It should be understood that That is, the student distribution corresponding to the target word at the jth position, That is, the target distribution corresponding to the target word at the jth position.

[0095] In some optional embodiments, when the present application determines the proxy distribution corresponding to the non-target segmentation, since the non-target segmentation is an easy-to-learn segmentation, the student distribution corresponding to the non-target segmentation can be determined as the proxy distribution corresponding to the non-target segmentation.

[0096] As an optional implementation method, the proxy distribution corresponding to the non-target segmentation word can be determined by the following formula (4):

[0097]

[0098] in, is the proxy distribution corresponding to the non-target word at the k-th position, that is, the proxy distribution corresponding to the k-th position, is the student distribution corresponding to the kth position, where k is different from j, i.e. k≠j, and k is greater than or equal to 1 and less than or equal to the size of the translation word sequence n.

[0099] Step 4: According to the target distribution and proxy distribution corresponding to the target word segmentation, and the target distribution and proxy distribution corresponding to the non-target word segmentation, the student translation model is iteratively trained to obtain the target machine translation model.

[0100] In some optional embodiments, the student translation model is iteratively trained according to the target distribution and proxy distribution corresponding to the target segmentation, and the target distribution and proxy distribution corresponding to the non-target segmentation, which can be achieved by the following steps:

[0101] Step A1, obtain the second loss value according to the error between the target distribution and the proxy distribution corresponding to the target word segmentation.

[0102] In some optional embodiments, the error (i.e., the second loss value) between the target distribution and the proxy distribution corresponding to the target word segmentation can be determined by the following formula (5):

[0103]

[0104] in, is the second loss value between the target distribution and the proxy distribution corresponding to the target word at the j-th position, that is, the second loss value corresponding to the j-th position, KL is the KL divergence, is the proxy distribution corresponding to the jth position, is the target distribution corresponding to the jth position.

[0105] In this application,

[0106] Step A2: Obtain a third loss value based on the error between the target distribution and the proxy distribution corresponding to the non-target word segmentation.

[0107] In some optional embodiments, the error (i.e., the third loss value) between the target distribution and the proxy distribution corresponding to the non-target word segmentation can be determined by the following formula (6):

[0108]

[0109] in, is the third loss value between the target distribution and the proxy distribution corresponding to the non-target word at the k-th position, that is, the third loss value corresponding to the k-th position, KL is the KL divergence, is the proxy distribution corresponding to the kth position, is the target distribution corresponding to the kth position.

[0110] In this application, and Therefore, the above formula (6) can be transformed into formula (7):

[0111]

[0112] Based on the above formula (7), it can be known that the third loss value between the target distribution and the proxy distribution corresponding to the non-target segmentation is the same as the first loss value between the target distribution and the student distribution corresponding to the kth position determined by the above formula (2).

[0113] It should be noted that the execution order of the above-mentioned steps A1 and A2 can be to execute step A1 first and then step A2; or to execute step A2 first and then step A1; or to execute step A1 and step A2 at the same time, and this application does not impose any restrictions on this.

[0114] Step A3, iteratively training the student translation model according to the second loss value and the third loss value to obtain a target machine translation model.

[0115] In some optional embodiments, the student translation model may be iteratively trained according to the second loss value corresponding to the target word at the jth position and the third loss value corresponding to the non-target word at the kth position, specifically, the second loss value and the third loss value are added to obtain a sum value, and the sum value is then used as the total loss value of the student translation model. Then, the student translation model is iteratively trained according to the total loss value to obtain the target machine translation model.

[0116] In this application, the total loss value of the student translation model is determined as shown in the following formula (8):

[0117]

[0118] Among them, L is the total loss value of the student translation model, n is the size of the translation word sequence, and L kl' is the first loss value, is the third loss value corresponding to the k-th position, and the segmentation at the k-th position is an easy-to-learn segmentation. is the second loss value corresponding to the jth position, and the word at the jth position is a difficult word to learn. Where k∈R, R is the set of positions of easy-to-learn words in the translation word sequence. j∈M, M is the set of positions of difficult-to-learn words in the translation word sequence. The sum of the set R and the set M is equal to the size n of the translation word sequence.

[0119] In the present application, the student translation model is iteratively trained according to the total loss value by reversely training the student translation model according to the total loss value, such as adjusting the model parameters in the student translation model, and repeating steps 1 to 4 until the student translation model converges or reaches a preset number of iterations to obtain the target machine translation model.

[0120] Among them, the convergence of the student translation model can mean that the total loss value is less than a preset value.

[0121] Furthermore, the above preset value and the preset number of iterations can be flexibly set according to the translation performance of the student translation model. For example, if you want to obtain a target machine translation model with higher accuracy, you can set the preset value to be smaller or the preset number of iterations to be larger. On the contrary, you can set the preset value to be relatively larger or the preset number of iterations to be relatively smaller, and this application does not impose any restrictions on this.

[0122] The technical solution disclosed in the embodiment of the present application is to input the acquired training original text into the teacher translation model and the student translation model respectively to obtain the teacher distribution output by the teacher translation model and the student distribution output by the student translation model, and obtain the standard translation distribution according to the acquired standard translation text and the training original text, and then iteratively train the student translation model according to the teacher distribution, the student distribution and the standard translation distribution to obtain the target machine translation model. The present application supervises the training process of the student translation model by utilizing the teacher distribution output by the teacher translation model and the standard translation distribution corresponding to the standard translation text, so that the knowledge of the teacher translation model can be effectively transferred to the student translation model, so that the student translation model can obtain translation performance equivalent to that of the teacher model.

[0123] Please refer to the attached Figure 4 , a knowledge distillation device proposed in the embodiment of the present application is described. Figure 4 As shown, the knowledge distillation device 400 includes: a sample acquisition module 410 , a first processing module 420 , a second processing module 430 and a knowledge distillation module 440 .

[0124] The sample acquisition module 410 is used to acquire the training original text and the standard translation text corresponding to the training original text;

[0125] A first processing module 420 is used to input the training original text into the teacher model and the student translation model respectively, to obtain the teacher distribution output by the teacher model and the student distribution output by the student translation model;

[0126] The second processing module 430 is used to obtain a standard translation distribution according to the standard translation text and the training original text;

[0127] The knowledge distillation module 440 is used to iteratively train the student translation model according to the teacher distribution, the student distribution and the standard translation distribution to obtain a target machine translation model.

[0128] In an optional implementation of the embodiment of the present application, the knowledge distillation module 440 includes:

[0129] A distribution determination unit, configured to obtain a target distribution according to the teacher distribution and the standard translation distribution;

[0130] A training unit is used to iteratively train the student translation model according to the target distribution and the student distribution to obtain a target machine translation model.

[0131] In an optional implementation of the embodiment of the present application, the training unit is specifically configured to:

[0132] Obtaining a first loss value according to an error between the target distribution and the student distribution;

[0133] According to the first loss value and a preset threshold, selecting a target segmentation word and a non-target segmentation word from a translation segmentation sequence corresponding to a standard translation text;

[0134] Determine the proxy distribution corresponding to the target segmentation word and the proxy distribution corresponding to the non-target segmentation word;

[0135] According to the target distribution and proxy distribution corresponding to the target word segmentation, and the target distribution and proxy distribution corresponding to the non-target word segmentation, the student translation model is iteratively trained to obtain a target machine translation model.

[0136] In an optional implementation of the embodiment of the present application, the training unit is further configured to:

[0137] If the first loss value between the target distribution and the student distribution corresponding to a segmentation at any position is greater than the preset threshold, a first target position is determined from the translation segmentation sequence corresponding to the standard translation text according to the position, and the segmentation at the first target position is determined as the target segmentation;

[0138] If the first loss value between the target distribution and the student distribution corresponding to a segmentation at any position is less than or equal to the preset threshold, a second target position is determined from the translated segmentation sequence corresponding to the standard translated text according to the position, and the segmentation at the second target position is determined as a non-target segmentation.

[0139] In an optional implementation of the embodiment of the present application, the training unit is further configured to:

[0140] According to the target distribution and the student distribution corresponding to the target participle, the agent distribution corresponding to the target participle is determined.

[0141] In an optional implementation of the embodiment of the present application, the training unit is further configured to:

[0142] The student distribution corresponding to the non-target segmentation is determined as the proxy distribution corresponding to the non-target segmentation.

[0143] In an optional implementation of the embodiment of the present application, the training unit is further configured to:

[0144] Obtaining a second loss value according to an error between a target distribution and a proxy distribution corresponding to the target word segmentation;

[0145] Obtaining a third loss value according to an error between the target distribution and the proxy distribution corresponding to the non-target word segmentation;

[0146] The student translation model is iteratively trained according to the second loss value and the third loss value to obtain a target machine translation model.

[0147] In an optional implementation of the embodiment of the present application, the training unit is further configured to:

[0148] Taking the sum of the second loss value and the third loss value as the total loss value of the student translation model;

[0149] The student translation model is iteratively trained according to the total loss value of the student translation model.

[0150] In an optional implementation of the embodiment of the present application, the second processing module 430 is specifically configured to:

[0151] Performing word segmentation processing on the standard translation text to obtain a translation word segmentation sequence, and performing word segmentation processing on the training original text to obtain an original word segmentation sequence;

[0152] Obtaining a target vocabulary according to the translation word segmentation sequence and the original word segmentation sequence;

[0153] According to the target vocabulary, the translation word sequence is one-hot encoded to obtain a standard translation distribution.

[0154] In an optional implementation of the embodiment of the present application, both the teacher model and the student translation model are large language models.

[0155] It should be understood that the device embodiment and the aforementioned method embodiment may correspond to each other, and similar descriptions may refer to the method embodiment. To avoid repetition, they will not be described here. Specifically, Figure 4 The apparatus 400 shown may perform Figure 2 The corresponding method embodiments, and the aforementioned and other operations and / or functions of each module in the device 400 are respectively to implement Figure 2 For the sake of brevity, the corresponding processes in each method are not repeated here.

[0156] The above describes the device 400 of the embodiment of the present application from the perspective of the functional module in conjunction with the accompanying drawings. It should be understood that the functional module can be implemented in hardware form, can be implemented by instructions in software form, and can also be implemented by a combination of hardware and software modules. Specifically, the steps of the first aspect method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit and / or software form instructions in the processor, and the steps of the first aspect method disclosed in conjunction with the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or a combination of hardware and software modules in the decoding processor to perform. Optionally, the software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory, and completes the steps in the above-mentioned first aspect method embodiment in conjunction with its hardware.

[0157] Figure 5 A schematic block diagram of an electronic device provided in an embodiment of the present application. Figure 5 As shown, the electronic device 500 may include:

[0158] The memory 510 and the processor 520, the memory 510 is used to store the computer program and transmit the program code to the processor 520. In other words, the processor 520 can call and run the computer program from the memory 510 to implement the knowledge distillation method of the first aspect of the embodiment of the present application.

[0159] For example, the processor 520 may be used to execute the above-mentioned knowledge distillation method according to the instructions in the computer program.

[0160] In some embodiments of the present application, the processor 520 may include but is not limited to:

[0161] General-purpose processor, digital signal processor (DSP), application-specific integrated circuit (ASIC), field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, etc.

[0162] In some embodiments of the present application, the memory 510 includes but is not limited to:

[0163] Volatile memory and / or non-volatile memory. Among them, the non-volatile memory can be read-only memory (ROM), programmable ROM (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM) or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM bus random access memory (DR RAM).

[0164] In some embodiments of the present application, the computer program may be divided into one or more modules, which are stored in the memory 510 and executed by the processor 520 to complete the knowledge distillation device provided by the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program in the electronic device.

[0165] like Figure 5 As shown, the electronic device 500 may further include:

[0166] The transceiver 530 may be connected to the processor 520 or the memory 510 .

[0167] The processor 520 may control the transceiver 530 to communicate with other devices, specifically, to send information or data to other devices, or to receive information or data sent by other devices. The transceiver 530 may include a transmitter and a receiver. The transceiver 530 may further include an antenna, and the number of antennas may be one or more.

[0168] It should be understood that the various components in the electronic device are connected via a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus and a status signal bus.

[0169] The present application also provides a computer storage medium on which a computer program is stored. When the computer program is executed by a computer, the computer is enabled to perform the knowledge distillation method of the first method embodiment described above.

[0170] An embodiment of the present application also provides a computer program product comprising program instructions. When the program instructions are executed on an electronic device, the electronic device executes the knowledge distillation method of the first aspect method embodiment.

[0171] When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integration. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a digital video disc (digital video disc, DVD)), or a semiconductor medium (e.g., a solid state drive (solid state disk, SSD)), etc.

[0172] Those of ordinary skill in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0173] In the several embodiments provided in the present application, it should be understood that the disclosed systems, 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 module is only a logical function division. There may be other division methods in actual implementation, such as multiple modules 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 modules, which can be electrical, mechanical or other forms.

[0174] The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. For example, each functional module in each embodiment of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0175] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.

[0176] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A knowledge distillation method, characterized in that: include: Obtaining a training original text and a standard translation text corresponding to the training original text; Inputting the training original text into a teacher translation model and a student translation model respectively, obtaining a teacher distribution output by the teacher translation model and a student distribution output by the student translation model; Obtaining a standard translation distribution according to the standard translation text and the training original text; According to the teacher distribution, the student distribution and the standard translation distribution, the student translation model is iteratively trained to obtain a target machine translation model.

2. The method according to claim 1, characterized in that The iterative training of the student translation model according to the teacher distribution, the student distribution and the standard translation distribution to obtain a target machine translation model includes: Obtaining a target distribution according to the teacher distribution and the standard translation distribution; The student translation model is iteratively trained according to the target distribution and the student distribution to obtain a target machine translation model.

3. The method according to claim 2, characterized in that The iterative training of the student translation model according to the target distribution and the student distribution to obtain a target machine translation model includes: Obtaining a first loss value according to an error between the target distribution and the student distribution; According to the first loss value and a preset threshold, selecting a target segmentation word and a non-target segmentation word from a translation segmentation sequence corresponding to a standard translation text; Determine the proxy distribution corresponding to the target segmentation word and the proxy distribution corresponding to the non-target segmentation word; According to the target distribution and proxy distribution corresponding to the target word segmentation, and the target distribution and proxy distribution corresponding to the non-target word segmentation, the student translation model is iteratively trained to obtain a target machine translation model.

4. The method according to claim 3, characterized in that The step of selecting target segmented words and non-target segmented words from a translation segmented word sequence corresponding to a standard translation text according to the first loss value and a preset threshold value includes: If the first loss value between the target distribution and the student distribution corresponding to a segmentation at any position is greater than the preset threshold, a first target position is determined from the translation segmentation sequence corresponding to the standard translation text according to the position, and the segmentation at the first target position is determined as the target segmentation; If the first loss value between the target distribution and the student distribution corresponding to a segmentation at any position is less than or equal to the preset threshold, a second target position is determined from the translated segmentation sequence corresponding to the standard translated text according to the position, and the segmentation at the second target position is determined as a non-target segmentation.

5. The method according to claim 3, characterized in that: The determining the proxy distribution corresponding to the target word segmentation includes: According to the target distribution and the student distribution corresponding to the target participle, the agent distribution corresponding to the target participle is determined.

6. The method according to claim 3, characterized in that The determining the proxy distribution corresponding to the non-target word segmentation includes: The student distribution corresponding to the non-target segmentation is determined as the proxy distribution corresponding to the non-target segmentation.

7. The method according to claim 3, characterized in that The method of iteratively training the student translation model according to the target distribution and proxy distribution corresponding to the target word segmentation and the target distribution and proxy distribution corresponding to the non-target word segmentation to obtain a target machine translation model includes: Obtaining a second loss value according to an error between a target distribution and a proxy distribution corresponding to the target word segmentation; Obtaining a third loss value according to an error between the target distribution and the proxy distribution corresponding to the non-target word segmentation; The student translation model is iteratively trained according to the second loss value and the third loss value to obtain a target machine translation model.

8. The method according to claim 7, characterized in that The iterative training of the student translation model according to the second loss value and the third loss value comprises: Taking the sum of the second loss value and the third loss value as the total loss value of the student translation model; The student translation model is iteratively trained according to the total loss value of the student translation model.

9. The method according to claim 1, characterized in that: The step of obtaining a standard translation distribution based on the standard translation text and the training original text includes: Performing word segmentation processing on the standard translation text to obtain a translation word segmentation sequence, and performing word segmentation processing on the training original text to obtain an original word segmentation sequence; Obtaining a target vocabulary according to the translation word segmentation sequence and the original word segmentation sequence; According to the target vocabulary, the translation word sequence is one-hot encoded to obtain a standard translation distribution.

10. The method according to claim 1, characterized in that The teacher model and the student translation model are both large language models.

11. A knowledge distillation device, characterized in that: include: A sample acquisition module, used to acquire a training original text and a standard translation text corresponding to the training original text; A first processing module is used to input the training original text into a teacher model and a student translation model respectively, to obtain a teacher distribution output by the teacher model and a student distribution output by the student translation model; A second processing module, configured to obtain a standard translation distribution according to the standard translation text and the training original text; The knowledge distillation module is used to iteratively train the student translation model according to the teacher distribution, the student distribution and the standard translation distribution to obtain a target machine translation model.

12. An electronic device, characterized in that: include: A processor and a memory, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute the knowledge distillation method as described in any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein the computer program enables a computer to execute the knowledge distillation method as described in any one of claims 1 to 10.

14. A computer program product comprising program instructions, characterized in that When the program instructions are executed on an electronic device, the electronic device executes the knowledge distillation method as described in any one of claims 1 to 10.