A Chinese-English machine translation method based on knowledge distillation
By introducing Future decoder and knowledge distillation method modules into the neural machine translation model, interactive learning of before and after information solves the problem of exposure bias in neural machine translation, improves translation quality and reduces computational costs.
Patent Information
- Application Number
- CN202210500736.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-09
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-05-09
AI Technical Summary
The exposure bias problem caused by the teacher-forcing algorithm in existing neural machine translation technology leads to a decrease in the quality of translations generated by the model, and the mitigation method takes a long time to train, has many parameters, and has high computational costs.
The Chinese-English machine translation method based on knowledge distillation is adopted. By introducing the Future decoder decoder and the knowledge distillation method module into the translation model, the training model reversely transfers the loss of the Future decoder to the Transformer decoder, interactively learns the before and after information, and reduces the exposure bias.
It effectively alleviates the exposure bias problem, improves the fluency of the translation, avoids errors of improper matching, significantly reduces the calculation cost, and improves the decoding efficiency of the model.
Smart Images

Figure CN115034236B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of language processing, and in particular to a Chinese-English machine translation method based on knowledge distillation. Background Art
[0002] With the rapid development of deep learning technology, machine translation and natural language processing have made great progress in recent years. From the perspective of actual needs, localized human-assisted translation, real-time translation for overseas travel, cross-border e-commerce, foreign trade and other scenarios all require machine translation technology. The research on machine translation has gone through the era of machine translation based on grammatical rules and statistical methods, and has developed to the current machine translation based on deep learning (neural machine translation).
[0003] Initially, rule-based methods were the mainstream of machine translation research, but their disadvantages were high cost and difficulty in processing non-standard languages. In the early 1990s, Peter Brown and others from IBM formally proposed a statistical machine translation model. In 2013, Kalchbrenner and Blunsom proposed using neural networks for machine translation. In the following year or two, Sutskever and others proposed a neural machine translation model based on an encoder-decoder structure, marking the entry of machine translation into the era of deep learning. Neural machine translation uses encoder-decoder as the basic framework and uses deep neural networks to model the translation process. This process does not rely on manually defined features. The entire translation model can be trained in an end-to-end mode, and translation decoding becomes a process of forward calculation or inference of the neural network.
[0004] The models commonly used in existing neural machine translation technologies are recurrent neural networks, convolutional neural networks, and Transformer. The training strategies adopted by these models are all teacher-forcing. The teacher forcing algorithm will bring about the problem of exposure bias. The decoder needs the target sequence label as input during training. At this time, the sequence generated by the model is only used to calculate the error; during testing, there is no target sequence, so the output of the previous time step is used as the input of the current time step. When the model is trained with teacher forcing, the decoding results of the model are inferred from different distributions during training and prediction, so this inconsistency will lead to some deviations. This deviation will increase with the increase of sentence length, and ultimately lead to a decrease in the quality of the translation generated by the model. Although many scholars have proposed methods to alleviate the problem of exposure bias, these methods have long training time, large model parameters, and are quite expensive to calculate. Summary of the invention
[0005] The present invention provides a Chinese-English machine translation method based on knowledge distillation to solve the problem of translation deviation caused by solution exposure deviation in the prior art.
[0006] The present invention provides a Chinese-English machine translation method based on knowledge distillation, comprising the following steps:
[0007] Step 1: Obtain Chinese-English parallel corpus and preprocess each sentence in the parallel corpus;
[0008] Step 2: Set the encoder of the translation model to include: Transformer encoder encoder; the decoder to include: Transformer decoder decoder and Future decoder decoder, add a knowledge distillation module to the translation model, use the preprocessed parallel corpus obtained in step 1 as the input information of the translation model to train the translation model, and the translation model interacts with the two decoders through the knowledge distillation method;
[0009] Step 3: After the translation model training is completed, remove the Future decoder and knowledge distillation modules in the translation model;
[0010] Step 4: Use the translation model obtained in step 3 to translate between Chinese and English.
[0011] Furthermore, the mathematical description of the Transformer encoder is:
[0012]
[0013] in, is the word embedding matrix of the source language, X is the one-hot matrix of the source language sentence, and P X is the position encoding of the source sentence, LayerNorm(·) is the layer normalization function, and E t is the output of the tth encoder, E N is the output of the Transformer encoder, and N is the number of encoders stacked in the Transformer encoder.
[0014] Furthermore, the mathematical description of the Transformer decoder is:
[0015]
[0016] in, is the word embedding matrix of the target language, Y is the one-hot matrix of the target language sentence, and P Y is the positional encoding of the target sentence, D t is the output of the tth decoder, D Nis the output of the Transformer decoder, and N is the number of decoders stacked in the Transformer decoder.
[0017] Furthermore, the Future decoder decoder masks the word before the current word to be processed, and the output vector of the Future decoder decoder is sorted in the opposite order to the output vector of the Transformer decoder decoder.
[0018] Furthermore, the specific method of the translation model to interact the two decoders through knowledge distillation is as follows:
[0019] When the translation model has finished training the array sentences, it passes the loss function of the Future decoder decoder back to the Transformer decoder decoder through the knowledge distillation method.
[0020] Furthermore, the preprocessing method in step 1 is: performing word segmentation and byte pair encoding on each sentence.
[0021] Beneficial effects of the present invention:
[0022] The present invention utilizes the characteristic of knowledge distillation that can effectively realize knowledge transfer, and proposes a Chinese-English machine translation method based on knowledge distillation. The method uses two decoders to learn the connection between the current word and the previous text and the connection between the current word and the following text respectively, and uses knowledge distillation as a bridge for the interaction between the two decoders, so that the model can effectively learn the connection between the previous and next information and the current position word, increase the fluency of the translation, and avoid inappropriate collocation errors in the translation. Compared with the traditional model training method using the teacherforcing strategy, this method can enable the model to effectively learn the connection between the previous and next information and the current position word, significantly alleviating the exposure bias problem. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The features and advantages of the present invention will be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the present invention in any way. In the accompanying drawings:
[0024] Figure 1 A method architecture diagram of a specific embodiment of the present invention;
[0025] Figure 2 A comparison diagram of two decoder masking methods in a specific embodiment of the present invention;
[0026] Figure 3 is a structural diagram of a Transformer model in a specific embodiment of the present invention;
[0027] Figure 4It is a calculation graph of self-attention in a specific embodiment of the present invention. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0029] The embodiment of the present invention provides a Chinese-English machine translation method based on knowledge distillation, such as Figure 1-4 As shown, including:
[0030] Step 1: Get the Chinese and English parallel corpus from the official website of the WMT18 dataset, and then preprocess each sentence: word segmentation and byte pair encoding. The details are as follows: Download the Chinese and English news corpus from http: / / www.statmt.org / wmt14 / , use Moses to segment and convert English sentences into uppercase and lowercase, and use Standford Segmentor to segment Chinese sentences. Then use the BPE-dropout algorithm to decompose the words into subwords to reduce the vocabulary. The specific steps to obtain the subword list are: 1. Prepare the corpus and decompose it into the smallest unit, such as the 26 letters in English plus various symbols, which are used as the initial vocabulary; 2. Count the frequency of adjacent symbol pairs according to the corpus; 3. Pick out the symbol pair with the highest frequency, such as th composed of t and h, add it to the vocabulary, and merge all the adjacent symbol pairs in the training corpus, where all t and h become th; 4. Repeat 2 and 3 until the number of words in the vocabulary reaches the set amount, such as 32,000.
[0031] BPE-dropout adds a certain amount of randomness to the BPE algorithm. Specifically, each time the training data is processed and segmented, a certain probability (such as 10%) is set to prevent some fusions from passing. Therefore, even for the same word, the subwords generated by BPE-dropout are different each time. Use Google's sentence piece toolkit to implement BPE-dropout processing of words.
[0032] Step 2: Input the preprocessed corpus into the translation model for training. The encoder of the translation model is the Transformer encoder, and the decoder is the Transformer decoder and the Future decoder. The knowledge learned by the Future decoder is transferred to the Transformer decoder through the knowledge distillation technology, so that the model can effectively learn the connection between the previous and next information and the current position word. The details are as follows:
[0033] Step 2.1: Transformer encoder: Figure 3 As shown in the figure, the Transformer encoder is composed of N identical large modules (6 in this embodiment), each of which is composed of two modules, namely the multi-head self-attention module and the feedforward neural network module. The input received by the first large module is the Input Embedding, and the output of the previous large module received by the remaining large modules is used as the output of the entire encoder. Self-attention is the most important structural unit in the entire Transformer structure. Figure 4 As shown, the entire calculation process revolves around a formula:
[0034]
[0035] Among them, the three vectors K, Q, and V are obtained by multiplying the word vector with three different weight matrices during the training process. The attention function can be described as mapping a query and a set of key-value pairs to the output, where query, key, value, and output are all vectors.
[0036] The calculation process of each encoder layer is as follows:
[0037] First, calculate the input word embedding vector X = (x1,...,x n ) T and position code T = (t1,...,t n ) T Add the word embedding X = (x1+t1,...,x n +t n ) T For subsequent use;
[0038] Then input X into the multi-head self-attention layer with 8 attention heads and calculate XW i Q =Q i ,XW i K =K i ,XWi V =V i ,i=1,...,8, here
[0039] Finally, self-attention and multi-head self-attention are calculated, and residual connections and layer normalization are performed.
[0040] Step 2.2: Transformer decoder: Figure 3 As shown in the figure, the Transformer decoder end is also composed of N identical large modules (here 6) stacked together, each of which is composed of three modules, namely the multi-head self-attention module, the encoder-decoder interaction module and the feedforward neural network module.
[0041] Step 2.3: Future decoder: Future decoder is basically the same as Transformer decoder, and is also composed of a multi-head self-attention module, an encoder-decoder interaction module, and a feedforward neural network module. The only difference between the two is the masking method of the multi-head self-attention: Transformer decoder uses Figure 2 The masking method shown in (a) is to mask the word in the i-th position. Shielding; while Future decoder uses Figure 2 (b) shows the masking method. When generating the word at the i-th position, the masking matrix Shielding.
[0042] Step 2.4: Loss function: Given a sentence pair <X,Y * >, Transformer decoder calculates the probability distribution of the current position The cross entropy loss function of Transformer decoder is
[0043]
[0044] Where K is the size of the training set, I k is the length of the kth target sentence. Future decoder calculates the probability distribution of the current position Its loss function is
[0045]
[0046] In order to make the two decoders (Transformer decoder and Future decoder) interact during training and compress the model during testing, the information learned by Future decoder is passed to Transformer decoder through knowledge distillation. The loss function of knowledge distillation is:
[0047]
[0048] Where |V| is the size of the target vocabulary. The total training loss is:
[0049] L=L2+λL1+(1-λ)L3
[0050] In this embodiment, λ is set to 0.5. Different from the traditional knowledge distillation method, this embodiment trains all parameters from scratch, but keeps the Future decoder unchanged during the knowledge distillation process. Specifically, the gradient is back-propagated to the Future decoder only through L2, not through L3.
[0051] Step 3: After the translation model training is completed, the Transformer decoder has learned the knowledge from the Future decoder through knowledge distillation. In order to reduce the computing cost and improve the decoding speed in actual use, the Future decoder module and knowledge distillation module in the model are removed;
[0052] Step 4: Use the translation model obtained in step 3 to translate between Chinese and English.
[0053] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A Chinese-English machine translation method based on knowledge distillation, characterized in that: The steps include: Step 1: Obtain Chinese-English parallel corpus and preprocess each sentence in the parallel corpus; Step 2: Set the encoder of the translation model to include: Transformer encoder encoder; the decoder to include: Transformer decoder decoder and Future decoder decoder, add a knowledge distillation module to the translation model, use the preprocessed parallel corpus obtained in step 1 as the input information of the translation model to train the translation model, and the translation model interacts with the two decoders through the knowledge distillation method. Among them, the mathematical description of the Transformer encoder is: in, is the word embedding matrix of the source language, X is the one-hot matrix of the source language sentence, and P X is the position encoding of the source sentence, LayerNorm(·) is the layer normalization function, and E t is the output of the tth encoder, E N is the output of the Transformer encoder, and N is the number of encoders stacked by the Transformer encoder; The mathematical description of the Transformer decoder is: in, is the word embedding matrix of the target language, Y is the one-hot matrix of the target language sentence, and P Y is the positional encoding of the target sentence, D t is the output of the tth decoder, D N is the output of Transformer decoder, and N is the number of decoders stacked in Transformerdecoder; The specific method of the translation model to interact with the two decoders through knowledge distillation is as follows: When the translation model has finished training the array sentences, it uses the knowledge distillation method to reversely transfer the loss function of the Future decoder decoder to the Transformer decoder decoder; Step 3: After the translation model training is completed, remove the Future decoder and knowledge distillation modules in the translation model; Step 4: Use the translation model obtained in step 3 to translate between Chinese and English.
2. The Chinese-English machine translation method based on knowledge distillation as claimed in claim 1, characterized in that: The Future decoder decoder masks the word before the current word to be processed, and the output vector of the Future decoder decoder is sorted in the opposite order to the output vector of the Transformer decoder decoder.
3. The Chinese-English machine translation method based on knowledge distillation as claimed in claim 1, characterized in that: The preprocessing method in step 1 is: performing word segmentation and byte pair encoding on each sentence.
