Text translation method and device, equipment and medium
By using mutual mapping learning and reverse prediction techniques of opposite speech in the training of translation model, the problem of low translation accuracy caused by insufficient training corpus is solved, and the fault tolerance and accuracy of the translation model are improved.
Patent Information
- Application Number
- CN202310716238.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-15
- Publication Date
- 2024-12-17
AI Technical Summary
When text translation is based on the translation model, when there are fewer training corpus, it is difficult to effectively train the translation model, which affects the translation accuracy.
When training the target translation model, training is carried out based on two opposite directions of the training corpus, mutual mapping learning between the translated samples and the sample to be translated is realized, and the fault tolerance of the model is enhanced through reverse prediction.
Improve the training effect of the translation model under less training corpus, and improve the accuracy and fault tolerance of text translation.
Smart Images

Figure CN119150886A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of text processing technology, and in particular to a text translation method, device, equipment and medium. Background Art
[0002] With the continuous development of artificial intelligence, more and more translation models are used for text translation. When translating text based on translation models, it is first necessary to train the translation model with training corpus. When the training corpus is small, it is difficult for the translation model to be effectively trained, thus affecting the translation accuracy. Summary of the invention
[0003] In order to overcome the problems existing in the related art, the present disclosure provides a text translation method, device, equipment and medium to solve the above technical problems.
[0004] According to a first aspect of an embodiment of the present disclosure, a text translation method is provided, the method comprising:
[0005] Get the text to be translated;
[0006] Inputting the text to be translated into a target translation model to obtain a target translated text;
[0007] The target translation model includes an encoder and a decoder, and the target translation model is trained in the following manner:
[0008] Obtaining a sample to be translated and a translation sample corresponding to the sample to be translated;
[0009] Input the sample to be translated into the encoder, and input the translation sample into the decoder to obtain first translation data, and perform first-stage training on the target translation model with the first translation data and the sample to be translated as input and the probability distribution of word segmentation in the sample to be translated as output;
[0010] The translation sample is input into the encoder, and the sample to be translated is input into the decoder to obtain second translation data, and the second translation data and the translation sample are used as input, and the probability distribution of word segmentation in the translation sample is used as output to perform second-stage training on the target translation model.
[0011] Optionally, the step of inputting the sample to be translated into the encoder and inputting the translation sample into the decoder to obtain first translation data includes:
[0012] Inputting the sample to be translated into the encoder, and inputting the translation sample into the decoder, to obtain a first predicted probability distribution of word segments in the translation sample and a word embedding matrix of the translation sample;
[0013] Determine a first product of a first predicted probability distribution of word segments in the translation sample and a word embedding matrix of the translation sample, and determine the first product as the first translation data.
[0014] Optionally, the sample to be translated corresponds to a first label, and the translated sample corresponds to a second label, the first label is used to characterize the true probability distribution of word segments in the sample to be translated, and the second label is used to characterize the true probability distribution of word segments in the translated sample, and the first translation data and the sample to be translated are used as inputs, and the probability distribution of word segments in the sample to be translated is used as output, and the target translation model is trained in the first stage, including:
[0015] Inputting the first translation data into the encoder, and inputting the sample to be translated into the decoder, to obtain a first predicted probability distribution of word segments in the sample to be translated;
[0016] Determine a first-stage loss function value according to the first predicted probability distribution of the word segmentation in the translation sample, the first predicted probability distribution of the word segmentation in the sample to be translated, the first label, and the second label;
[0017] According to the first-stage loss function value, the parameters of the target translation model are adjusted.
[0018] Optionally, the sample to be translated corresponds to a first label, and the translated sample corresponds to a second label, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translated sample, and the method further includes:
[0019] Input the translation sample into the encoder, and input the sample to be translated into the decoder, to obtain a second predicted probability distribution of word segments in the sample to be translated;
[0020] The first translation data and the sample to be translated are used as input, and the probability distribution of word segments in the sample to be translated is used as output, and the target translation model is trained in the first stage, including:
[0021] Inputting the first translation data into the encoder, and inputting the sample to be translated into the decoder, to obtain a first predicted probability distribution of word segments in the sample to be translated;
[0022] Determine a first-stage loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the sample to be translated, the first predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label;
[0023] According to the first-stage loss function value, the parameters of the target translation model are adjusted.
[0024] Optionally, determining the first-stage loss function value according to the first predicted probability distribution of the word segmentation in the to-be-translated sample, the second predicted probability distribution of the word segmentation in the to-be-translated sample, the first predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label includes:
[0025] Determine a first loss function value according to the first predicted probability distribution of the word segmentation in the translation sample and the second label, determine a second loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated and the first label, determine a third loss function value according to the second predicted probability distribution of the word segmentation in the sample to be translated and the first label, and determine a fourth loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated and the second predicted probability distribution of the word segmentation in the sample to be translated;
[0026] Determine the first stage loss function value according to the first loss function value, the second loss function value, the third loss function value and the fourth loss function value.
[0027] Optionally, the step of inputting the translation sample into the encoder and inputting the sample to be translated into the decoder to obtain second translation data comprises:
[0028] Input the translation sample into the encoder, and input the sample to be translated into the decoder, to obtain a third predicted probability distribution of word segments in the sample to be translated and a word embedding matrix of the sample to be translated;
[0029] Determine a second product of a third predicted probability distribution of word segments in the sample to be translated and a word embedding matrix of the sample to be translated, and determine the second product as the second translation data.
[0030] Optionally, the sample to be translated corresponds to a first label, and the translation sample corresponds to a second label, the first label is used to characterize the true probability distribution of word segments in the sample to be translated, and the second label is used to characterize the true probability distribution of word segments in the translation sample, and the second translation data and the translation sample are used as input, and the probability distribution of word segments in the translation sample is used as output to perform the second stage training on the target translation model, including:
[0031] Inputting the second translation data into the encoder, and inputting the translation sample into the decoder, to obtain a second predicted probability distribution of word segments in the translation sample;
[0032] Determine a second-stage loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label;
[0033] According to the second-stage loss function value, the parameters of the target translation model are adjusted.
[0034] Optionally, the sample to be translated corresponds to a first label, and the translated sample corresponds to a second label, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translated sample, and the method further includes:
[0035] Inputting the sample to be translated into the encoder, and inputting the translation sample into the decoder, to obtain a third predicted probability distribution of word segments in the translation sample;
[0036] The second translation data and the translation sample are used as input, and the probability distribution of word segments in the translation sample is used as output, and the target translation model is trained in the second stage, including:
[0037] Inputting the second translation data into the encoder, and inputting the translation sample into the decoder, to obtain a second predicted probability distribution of word segments in the translation sample;
[0038] Determine a second-stage loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the third predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label;
[0039] According to the second-stage loss function value, the parameters of the target translation model are adjusted.
[0040] Optionally, determining the second-stage loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the third predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label includes:
[0041] Determine a fifth loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated and the first label, determine a sixth loss function value according to the second predicted probability distribution of the word segmentation in the translation sample and the second label, determine a seventh loss function value according to the third predicted probability distribution of the word segmentation in the translation sample and the second label, and determine an eighth loss function value according to the second predicted probability distribution of the word segmentation in the translation sample and the third predicted probability distribution of the word segmentation in the translation sample;
[0042] Determine the second-stage loss function value based on the fifth loss function value, the sixth loss function value, the seventh loss function value and the eighth loss function value.
[0043] According to a second aspect of an embodiment of the present disclosure, a text translation device is provided, including:
[0044] A first acquisition module is configured to acquire a text to be translated;
[0045] A processing module is configured to input the text to be translated into a target translation model to obtain a target translation text;
[0046] Wherein, the target translation model includes an encoder and a decoder, and the text translation device also includes:
[0047] A second acquisition module is configured to acquire a sample to be translated and a translation sample corresponding to the sample to be translated;
[0048] A first training module is configured to input the sample to be translated into the encoder, and input the translation sample into the decoder to obtain first translation data, and perform first-stage training on the target translation model with the first translation data and the sample to be translated as input and the probability distribution of word segments in the sample to be translated as output;
[0049] The second training module is configured to input the translation sample into the encoder and the sample to be translated into the decoder to obtain second translation data, and perform second-stage training on the target translation model with the second translation data and the translation sample as input and the probability distribution of word segmentation in the translation sample as output.
[0050] Optionally, the first training module includes:
[0051] A first input unit is configured to input the sample to be translated into the encoder, and input the translation sample into the decoder, to obtain a first predicted probability distribution of word segments in the translation sample and a word embedding matrix of the translation sample;
[0052] The first determining unit is configured to determine a first product of a first predicted probability distribution of word segments in the translation sample and a word embedding matrix of the translation sample, and determine the first product as the first translation data.
[0053] Optionally, the sample to be translated corresponds to a first label, and the translated sample corresponds to a second label, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translated sample, and the first training module further includes:
[0054] A second input unit is configured to input the first translation data into the encoder, and input the sample to be translated into the decoder, to obtain a first predicted probability distribution of word segments in the sample to be translated;
[0055] A second determining unit is configured to determine a first-stage loss function value according to the first predicted probability distribution of the word segmentation in the translation sample, the first predicted probability distribution of the word segmentation in the sample to be translated, the first label, and the second label;
[0056] The first adjustment unit is configured to adjust the parameters of the target translation model according to the first stage loss function value.
[0057] Optionally, the sample to be translated corresponds to a first label, and the translation sample corresponds to a second label, the first label is used to characterize the true probability distribution of the segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the segmentation in the translation sample, and the text translation device further includes:
[0058] A third input unit is configured to input the translation sample into the encoder and the sample to be translated into the decoder to obtain a second predicted probability distribution of word segments in the sample to be translated;
[0059] Accordingly, the first training module also includes:
[0060] a fourth input unit, configured to input the first translation data into the encoder, and input the sample to be translated into the decoder, to obtain a first predicted probability distribution of word segments in the sample to be translated;
[0061] A third determining unit is configured to determine a first-stage loss function value according to the first predicted probability distribution of the segmentation in the sample to be translated, the second predicted probability distribution of the segmentation in the sample to be translated, the first predicted probability distribution of the segmentation in the translation sample, the first label, and the second label;
[0062] The second adjustment unit is configured to adjust the parameters of the target translation model according to the first stage loss function value.
[0063] Optionally, the third determining unit includes:
[0064] A first determination subunit is configured to determine a first loss function value according to the first predicted probability distribution of the word segmentation in the translation sample and the second label, determine a second loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated and the first label, determine a third loss function value according to the second predicted probability distribution of the word segmentation in the sample to be translated and the first label, and determine a fourth loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated and the second predicted probability distribution of the word segmentation in the sample to be translated;
[0065] The second determination subunit is configured to determine the first-stage loss function value based on the first loss function value, the second loss function value, the third loss function value and the fourth loss function value.
[0066] Optionally, the second training module includes:
[0067] a fifth input unit, configured to input the translation sample into the encoder, and input the sample to be translated into the decoder, to obtain a third predicted probability distribution of word segments in the sample to be translated and a word embedding matrix of the sample to be translated;
[0068] The fourth determining unit is configured to determine a second product of a third predicted probability distribution of word segments in the sample to be translated and a word embedding matrix of the sample to be translated, and determine the second product as the second translation data.
[0069] Optionally, the sample to be translated corresponds to a first label, and the translated sample corresponds to a second label, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translated sample, and the second training module includes:
[0070] a sixth input unit, configured to input the second translation data into the encoder, and input the translation sample into the decoder, to obtain a second predicted probability distribution of word segments in the translation sample;
[0071] a fifth determining unit, configured to determine a second-stage loss function value according to a third predicted probability distribution of the word segmentation in the to-be-translated sample, a second predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label;
[0072] The third adjustment unit is configured to adjust the parameters of the target translation model according to the second stage loss function value.
[0073] Optionally, the sample to be translated corresponds to a first label, and the translation sample corresponds to a second label, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translation sample, and the text translation device further includes:
[0074] a seventh input unit, configured to input the sample to be translated into the encoder, and input the translation sample into the decoder, to obtain a third predicted probability distribution of word segments in the translation sample;
[0075] Accordingly, the second training module also includes:
[0076] an eighth input unit, configured to input the second translation data into the encoder, and input the translation sample into the decoder, to obtain a second predicted probability distribution of word segments in the translation sample;
[0077] a sixth determining unit, configured to determine a second-stage loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the third predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label;
[0078] The fourth adjustment unit is configured to adjust the parameters of the target translation model according to the second stage loss function value.
[0079] Optionally, the sixth determining unit includes:
[0080] A third determination subunit is configured to determine a fifth loss function value according to a third predicted probability distribution of the word segment in the sample to be translated and the first label, determine a sixth loss function value according to a second predicted probability distribution of the word segment in the translation sample and the second label, determine a seventh loss function value according to the third predicted probability distribution of the word segment in the translation sample and the second label, and determine an eighth loss function value according to the second predicted probability distribution of the word segment in the translation sample and the third predicted probability distribution of the word segment in the translation sample;
[0081] The fourth determination subunit is configured to determine the second-stage loss function value based on the fifth loss function value, the sixth loss function value, the seventh loss function value and the eighth loss function value.
[0082] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, including:
[0083] processor;
[0084] a memory for storing processor-executable instructions;
[0085] Wherein, the processor is configured to:
[0086] Execute the steps of the text translation method provided in any one of the first aspects of the present disclosure.
[0087] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the program instructions are executed by a processor, the steps of the text translation method provided in any one of the first aspects of the present disclosure are implemented.
[0088] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0089] According to the above technical solution, when training the target translation model, on the one hand, it can be trained based on the two opposite language directions of the training corpus, so as to realize the mutual mapping learning between the translation sample and the sample to be translated, so that the target translation model can be trained with less training corpus, and the translation accuracy when the text is translated by the target translation model can be improved. On the other hand, by using the prediction result of one language direction as the input of the prediction of another language direction for reverse prediction, the fault tolerance of the target translation model can be enhanced, thereby further improving the translation accuracy.
[0090] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0091] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0092] Figure 1 is a flowchart of a text translation method according to an exemplary embodiment;
[0093] Figure 2 is a flowchart of another text translation method according to an exemplary embodiment;
[0094] Figure 3 is a flowchart of another text translation method according to an exemplary embodiment;
[0095] Figure 4 is a block diagram of a text translation device according to an exemplary embodiment;
[0096] Figure 5 is a block diagram of a device for text translation according to an exemplary embodiment;
[0097] Figure 6 The invention is a block diagram of a device for text translation according to an exemplary embodiment. DETAILED DESCRIPTION
[0098] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0099] It should be noted that all actions of acquiring signals, information or data in the present disclosure are carried out in compliance with the relevant data protection laws and policies of the country where the device is located and with the authorization given by the owner of the corresponding device.
[0100] As mentioned in the background art, when translating text based on a translation model, it is first necessary to train the translation model using a large-scale training corpus. Therefore, when the training corpus is small, it is difficult for the translation model to be effectively trained, thus affecting the translation accuracy.
[0101] In view of this, the embodiments of the present disclosure provide a text translation method, apparatus, device and medium, wherein, when training a target translation model, on the one hand, training is performed based on two opposite linguistic orientations of a training corpus to achieve mutual mapping learning between a translation sample and a sample to be translated, so that the target translation model can be trained with less training corpus, and the translation accuracy when text translation is performed by the target translation model is improved. On the other hand, by using the prediction result of one linguistic orientation as the input of another linguistic orientation prediction for reverse prediction, the fault tolerance of the target translation model can be enhanced, and the accuracy of the translation result can be further improved. Among them, the two opposite linguistic orientations include: translating the sample to be translated into the translation sample linguistic orientation and translating the translation sample into the sample to be translated linguistic orientation.
[0102] The embodiments of the present disclosure are further explained below with reference to the accompanying drawings.
[0103] Figure 1 is a flowchart of a text translation method according to an exemplary embodiment. Figure 1 As shown, the text translation method may include steps S101-S102.
[0104] In step S101, a text to be translated is obtained.
[0105] In step S102, the text to be translated is input into the target translation model to obtain the target translation text; wherein the target translation model includes an encoder and a decoder, and the target translation model is trained in the following manner:
[0106] Obtain the sample to be translated and the corresponding translation sample; input the sample to be translated into the encoder, and input the translation sample into the decoder to obtain the first translation data. Using the first translation data and the sample to be translated as the input, and the probability distribution of word segmentation in the sample to be translated as the output, perform the first-stage training on the target translation model; input the translation sample into the encoder, and input the sample to be translated into the decoder to obtain the second translation data. Using the second translation data and the translation sample as the input, and the probability distribution of word segmentation in the translation sample as the output, perform the second-stage training on the target translation model.
[0107] It should be understood that the target translation model can be a translation model in the related art, such as a Neural Machine Translation (NMT) model, a Statistical Machine Translation (SMT) model, or a Phrase-Based Translation (PBT) model, or it can also be a translation model improved from the translation model in the related art. The embodiments of the present disclosure do not impose any restrictions on this. In a possible implementation manner, in order to better process long sentences and complex text structures, the target translation model can be set as a neural machine translation model.
[0108] In addition, it should be understood that the sample to be translated and its corresponding translation sample can be set according to the actual application scenario, as long as the semantics of the sample to be translated and its corresponding translation sample are the same. The embodiments of the present disclosure also do not impose any restrictions on this.
[0109] For example, in the application scenario of translating a first language text into a second language text, the sample to be translated can be the first language text, and the corresponding translation sample can be the second language text, where the semantics of the first language text and the second language text are the same but the expressions are different. Exemplarily, the first language text can be "很高兴见到你" in Chinese, and the second language text can be "Nice to meet you" in English.
[0110] For another example, in the application scenario of translating a first font text into a second font text, the sample to be translated can be the first font text, and the corresponding translation sample can be the second font text, where the semantics of the first font text and the second font text are the same but the expressions are different. Exemplarily, the first font text can be "很高兴见到你" in simplified Chinese, and the second font text can be "很高興見到妳" in traditional Chinese.
[0111] In addition, it should be understood that the training order, number of trainings and stop conditions of the first stage training and the second stage training can also be set according to the actual situation, and the embodiments of the present disclosure do not impose any restrictions on this. In a possible implementation, the first stage training and the second stage training can be performed alternately until a preset number of iterations or a preset model accuracy is reached. For example, the sample to be translated and the corresponding translation sample can be divided into multiple batches of training samples, and the first stage training is performed with the 2k-1 batch of training samples, and the second stage training is performed with the 2k batch of training samples until the preset model accuracy is reached, where k is a natural number.
[0112] In a possible implementation, inputting a sample to be translated into an encoder, and inputting a translation sample into a decoder to obtain first translation data may include:
[0113] The sample to be translated is input into the encoder, and the translation sample is input into the decoder to obtain a first predicted probability distribution of word segments in the translation sample and a word embedding matrix of the translation sample; a first product of the first predicted probability distribution of word segments in the translation sample and the word embedding matrix of the translation sample is determined, and the first product is determined as the first translation data.
[0114] It should be understood that the word embedding matrix of the translation sample is determined by the encoder of the target translation model. Specifically, in the translation model, each word segment in the input text is usually represented as a one-hot vector form. Due to the large number of word segments in the input text, the dimension of the one-hot vector is large, which brings a series of calculation and storage problems. Therefore, the translation model will set a word embedding module, and the one-hot vector of each word segment in the input text is mapped to a low-dimensional continuous vector space and saved by the word embedding module, so as to obtain a word embedding matrix that is easy to process and occupies less storage space. Specifically, an input word embedding module (Input Embedding) can be set in the encoder, and the text input to the encoder is mapped into a low-dimensional word embedding matrix by the input word embedding module, and an output word embedding module (Output Embedding) is set in the decoder, and the text input to the decoder is mapped into a low-dimensional word embedding matrix by the output word embedding module. That is to say, the word embedding matrix of the translation sample in the embodiment of the present disclosure can be determined by the input word embedding module in the encoder.
[0115] In addition, it should be understood that the first translation data is a target translation sample predicted by the target translation model based on the sample to be translated. Specifically, since the word embedding matrix of the translation sample is used to characterize the word embedding vector of each word segment in the translation sample, and the first predicted probability distribution of the word segment in the translation sample is used to characterize the probability of each word segment in the translation sample appearing at the current position, the probability score of each word segment in the translation sample at the current position can be obtained by multiplying the word embedding matrix of the translation sample and the first predicted probability distribution of the word segment in the translation sample, and then the predicted target translation sample can be determined according to the probability score of each word segment in the translation sample at the current position.
[0116] In a possible implementation, the sample to be translated corresponds to a first label, and the translation sample corresponds to a second label, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translation sample. With the first translation data and the sample to be translated as input, and the probability distribution of the word segmentation in the sample to be translated as output, the first stage training of the target translation model may include:
[0117] The first translation data is input into the encoder, and the sample to be translated is input into the decoder to obtain the first predicted probability distribution of the word segmentation in the sample to be translated; the first stage loss function value is determined according to the first predicted probability distribution of the word segmentation in the translation sample, the first predicted probability distribution of the word segmentation in the sample to be translated, the first label and the second label; according to the first stage loss function value, the parameters of the target translation model are adjusted.
[0118] It should be understood that in the translation model training process, the difference between the predicted probability distribution and the label is generally measured based on the cross entropy loss function (CrossEntropyLoss). Therefore, in a possible implementation, the cross entropy loss function can be used to determine the first stage loss function value. Specifically, the first predicted probability distribution and the second label of the word segmentation in the translation sample can be substituted into formula (1) to obtain the loss function value L ce1 , put the first predicted probability distribution and the first label of the word segmentation in the sample to be translated into formula (2) to obtain the loss function value L ce2 , then L ce1 and L ce2 Substitute into formula (3) to obtain the first stage loss function value, where formula (1), formula (2) and formula (3) are as follows:
[0119]
[0120]
[0121] L1=L ce1 +L ce2 (3)
[0122] Among them, Y represents the second label, representing the first predicted probability distribution of word segmentation in the translation sample, representing the loss function value L ce1 , T represents the number of word segments in the translation sample, y t represents the t-th word segment of the translation sample, y<t represents the sequence composed of the first t - 1 word segments, X represents the first label, representing the first predicted probability distribution of word segmentation in the sample to be translated, representing the loss function value L ce2 , D represents the number of word segments in the sample to be translated, x d represents the d-th word segment of the sample to be translated, x<d represents the sequence composed of the first d - 1 word segments, and L1 represents the loss function value in the first stage.
[0123] In this embodiment, through the above technical solution, the first-stage training of the target translation model can be split into two sub-stages, such as Figure 2 shown in the first-stage training, where x represents the sample to be translated, y represents the translation sample, NMT represents the target translation model, representing the first predicted probability distribution of word segmentation in the translation sample, representing the target translation sample, representing the first predicted probability distribution of word segmentation in the sample to be translated. In the first sub-stage, by inputting the sample to be translated into the encoder and the translation sample into the decoder, the forward translation training from the sample to be translated to the translation sample is realized; in the second sub-stage, by inputting the target translation sample obtained from the forward translation into the encoder and the sample to be translated into the decoder, the reverse translation training from the target translation sample to the sample to be translated is realized. Thus, the mutual mapping between the translation sample and the sample to be translated can be achieved according to the forward translation training in the first sub-stage and the reverse translation training in the second sub-stage, thereby enhancing the translation accuracy of the target translation model when performing text translation; in addition, since in the reverse translation training process, the target translation sample input into the encoder is obtained by forward translation training based on the sample to be translated, there may be an error between the target translation sample and the corresponding translation sample. And since the sample to be translated is accurate during the reverse translation training based on the target translation sample and the sample to be translated, the fault tolerance of the target translation model for reverse translation can be enhanced, and the accuracy of reverse translation can be improved.
[0124] In a possible implementation, the sample to be translated corresponds to a first label, and the translation sample corresponds to a second label. The first label is used to represent the true probability distribution of word segmentation in the sample to be translated, and the second label is used to represent the true probability distribution of word segmentation in the translation sample. This text translation method may further include:
[0125] Input the translation sample into the encoder, and the sample to be translated into the decoder, to obtain a second predicted probability distribution of the word segmentation in the sample to be translated;
[0126] Accordingly, taking the first translation data and the sample to be translated as input and the probability distribution of the word segments in the sample to be translated as output, the first stage training of the target translation model may include:
[0127] The first translation data is input into the encoder, and the sample to be translated is input into the decoder to obtain a first predicted probability distribution of the word segmentation in the sample to be translated; the first-stage loss function value is determined according to the first predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the sample to be translated, the first predicted probability distribution of the word segmentation in the translation sample, the first label and the second label; and the parameters of the target translation model are adjusted according to the first-stage loss function value.
[0128] In this embodiment, through the above technical solution, the first stage training of the target translation model can be divided into three sub-stages, such as Figure 3 The first stage of training is shown in Figure 1, where x represents the sample to be translated, y represents the translation sample, and NMT represents the target translation model. represents the first predicted probability distribution of word segmentation in the translation sample, represents the target translation sample, represents the first predicted probability distribution of the word segmentation in the sample to be translated, Represents the second predicted probability distribution of the word segmentation in the sample to be translated. In the first sub-stage, the sample to be translated is input into the encoder, and the translation sample is input into the decoder, so as to realize the forward translation training from the sample to be translated to the translation sample; in the second sub-stage, the target translation sample obtained by the forward translation is input into the encoder, and the sample to be translated is input into the decoder, so as to realize the reverse translation training from the target translation sample to the sample to be translated; in the third sub-stage, the translation sample is input into the encoder, and the sample to be translated is input into the decoder, so as to realize the reverse translation training from the translation sample to the sample to be translated, and at the same time, the reverse translation training from the target translation sample to the sample to be translated and the reverse translation training from the translation sample to the sample to be translated learn from each other, so as to further realize the reverse translation training of the target translation model. Therefore, the mutual mapping between the translation sample and the sample to be translated can be achieved according to the first sub-stage, the second sub-stage and the third sub-stage, so as to enhance the translation accuracy of the target translation model when translating text; in addition, in the process of reverse translation training from the target translation sample to the sample to be translated, the target translation sample in the input encoder is obtained by forward translation training based on the sample to be translated, which may cause errors between the target translation sample and the corresponding translation sample, and in the process of reverse translation training based on the target translation sample and the sample to be translated, the sample to be translated is accurate, which can enhance the fault tolerance of the reverse translation of the target translation model and improve the accuracy of the reverse translation result; in addition, due to the translation There are differences between the sample and the target translation sample, so there may be a situation where the result obtained by performing back translation training based on the target translation sample and the sample to be translated is different from the actual result obtained by performing back translation training based on the translation sample and the sample to be translated. Therefore, the embodiment of the present disclosure reduces the gap between the result obtained by performing back translation training based on the target translation sample and the sample to be translated and the result obtained by performing back translation training based on the translation sample and the sample to be translated by allowing the back translation training from the target translation sample to the sample to be translated and the back translation training from the translation sample to the sample to be translated to learn from each other, so as to further enhance the fault tolerance of the back translation of the target translation model and improve the accuracy of the back translation result.
[0129] In a possible implementation, determining a first-stage loss function value according to a first predicted probability distribution of word segmentations in a sample to be translated, a second predicted probability distribution of word segmentations in a sample to be translated, a first predicted probability distribution of word segmentations in a translation sample, a first label, and a second label; and adjusting parameters of a target translation model according to the first-stage loss function value may include:
[0130] Determine a first loss function value based on the first predicted probability distribution and the second label of the word segmentation in the translation sample, determine a second loss function value based on the first predicted probability distribution and the first label of the word segmentation in the sample to be translated, determine a third loss function value based on the second predicted probability distribution and the first label of the word segmentation in the sample to be translated, and determine a fourth loss function value based on the first predicted probability distribution of the word segmentation in the sample to be translated and the second predicted probability distribution of the word segmentation in the sample to be translated; determine the first stage loss function value based on the first loss function value, the second loss function value, the third loss function value and the fourth loss function value.
[0131] It should be understood that the fourth loss function value is determined by the first predicted probability distribution of the word segmentation in the sample to be translated and the second predicted probability distribution of the word segmentation in the sample to be translated, and the input corresponding to the first predicted probability distribution of the word segmentation in the sample to be translated is the target translation text, and the input corresponding to the second predicted probability distribution of the word segmentation in the sample to be translated is the translation text. In order to make the text to be translated predicted by the target translation model according to the target translation text and the text to be translated predicted according to the translation text more similar, it is necessary to make the first predicted probability distribution of the word segmentation in the sample to be translated and the second predicted probability distribution of the word segmentation in the sample to be translated as close as possible. Therefore, in a possible implementation, the KL divergence (Kullback–Leibler divergence) can be used to measure the difference between the first predicted probability distribution of the word segmentation in the sample to be translated and the second predicted probability distribution of the word segmentation in the sample to be translated, that is, the fourth loss function value can be determined based on the KL divergence, that is, by substituting the first predicted probability distribution of the word segmentation in the sample to be translated and the second predicted probability distribution of the word segmentation in the sample to be translated into formula (4) to obtain the fourth loss function value:
[0132]
[0133] Among them, L kl represents the fourth loss function value, represents the first predicted probability distribution of the word segmentation in the sample to be translated, Represents the second predicted probability distribution of the word segmentation in the sample to be translated.
[0134] It should also be understood that the determination method of the first loss function value, the second loss function value, and the third loss function value can refer to the loss function value L ce1 Or the loss function value L ce2 The determination method is not described in detail in the embodiments of the present disclosure.
[0135] After obtaining the first loss function value, the second loss function value, the third loss function value and the fourth loss function value, the first loss function value, the second loss function value, the third loss function value and the fourth loss function value are added to obtain the total loss function value of the target translation model in the first stage training process, so that the parameters of the target translation model can be adjusted according to the total loss function value in the first stage training process.
[0136] In a possible implementation, inputting a translation sample into an encoder and inputting a sample to be translated into a decoder to obtain second translation data may include:
[0137] The translation sample is input into the encoder, and the sample to be translated is input into the decoder to obtain the third predicted probability distribution of the word segmentation in the sample to be translated and the word embedding matrix of the sample to be translated; the second product of the third predicted probability distribution of the word segmentation in the sample to be translated and the word embedding matrix of the sample to be translated is determined, and the second product is determined as the second translation data.
[0138] It should be understood that the word embedding matrix of the sample to be translated is determined by the encoder of the target translation model. Specifically, in the translation model, each word segment in the input text is usually represented as a one-hot vector form. Due to the large number of word segments in the input text, the dimension of the one-hot vector is large, which brings a series of calculation and storage problems. Therefore, the translation model will set a word embedding module, and the one-hot vector of each word segment in the input text is mapped to a low-dimensional continuous vector space and saved by the word embedding module, so as to obtain a word embedding matrix that is easy to process and occupies less storage space. Specifically, an input word embedding module (Input Embedding) can be set in the encoder, and the text input to the encoder is mapped into a low-dimensional word embedding matrix by the input word embedding module, and an output word embedding module (Output Embedding) is set in the decoder, and the text input to the decoder is mapped into a low-dimensional word embedding matrix by the output word embedding module. That is to say, the word embedding matrix of the sample to be translated in the embodiment of the present disclosure can be determined by the input word embedding module in the encoder.
[0139] It should also be understood that the second translation data is the target sample to be translated predicted by the target translation model based on the translation sample. Specifically, since the word embedding matrix of the sample to be translated is used to characterize the word embedding vector of each word segment in the sample to be translated, and the third predicted probability distribution of the word segment in the sample to be translated is used to characterize the probability of each word segment in the sample to be translated appearing at the current position, the probability score of each word segment in the sample to be translated at the current position can be obtained by multiplying the word embedding matrix of the sample to be translated and the third predicted probability distribution of the word segment in the sample to be translated, and then the predicted target sample to be translated can be determined according to the probability score of each word segment in the sample to be translated at the current position.
[0140] In a possible implementation, the sample to be translated corresponds to a first label, and the translation sample corresponds to a second label, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translation sample. The second translation data and the translation sample are used as input, and the probability distribution of the word segmentation in the translation sample is used as output. The second stage training of the target translation model may include:
[0141] The second translation data is input into the encoder, and the translation sample is input into the decoder to obtain a second predicted probability distribution of the word segmentation in the translation sample; a second-stage loss function value is determined according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the first label and the second label; and the parameters of the target translation model are adjusted according to the second-stage loss function value.
[0142] Among them, the method for determining the second-stage loss function value in the embodiment of the present disclosure can refer to the above-mentioned method for determining the first-stage loss function value based on the first predicted probability distribution of word segmentations in the translation sample, the first predicted probability distribution of word segmentations in the sample to be translated, the first label and the second label, and the embodiment of the present disclosure will not go into details about this.
[0143] In this embodiment, through the above technical solution, the second stage training of the target translation model can be divided into two sub-stages, such as Figure 2 The second stage training shown in Figure 1, where x represents the sample to be translated, y represents the translation sample, and NMT represents the target translation model. represents the third predicted probability distribution of the word segmentation in the sample to be translated, represents the target sample to be translated, Represents the second predicted probability distribution of word segmentation in the translation sample. In the first sub-stage, the translation sample is input into the encoder, and the sample to be translated is input into the decoder to realize the reverse translation training from the translation sample to the sample to be translated; in the second sub-stage, the target sample to be translated obtained by reverse translation is input into the encoder, and the translation sample is input into the decoder to realize the forward translation training from the target sample to be translated to the translation sample. Thus, the mutual mapping between the sample to be translated and the translation sample can be realized according to the reverse translation training of the first sub-stage and the forward translation training of the second sub-stage, so as to enhance the translation accuracy of the target translation model when translating text; in addition, since in the forward translation training process from the target sample to be translated to the translation sample, the target sample to be translated input into the encoder is obtained by reverse translation training based on the translation sample, which may cause errors between the target sample to be translated and the corresponding sample to be translated, and since the translation sample is accurate in the process of forward translation training based on the target sample to be translated and the translation sample, the fault tolerance of the forward translation of the target translation model can be enhanced, and the accuracy of the forward translation result can be improved.
[0144] In a possible implementation, the sample to be translated corresponds to a first label, and the translation sample corresponds to a second label, the first label is used to characterize the true probability distribution of the segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the segmentation in the translation sample. The text translation method may also include:
[0145] Input the sample to be translated into the encoder, and input the translated sample into the decoder to obtain a third predicted probability distribution of the word segmentation in the translated sample;
[0146] Accordingly, taking the second translation data and the translation sample as input and the probability distribution of the word segments in the translation sample as output, the second stage training of the target translation model may include:
[0147] The second translation data is input into the encoder, and the translation sample is input into the decoder to obtain the second predicted probability distribution of the word segmentation in the translation sample; the second stage loss function value is determined according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the third predicted probability distribution of the word segmentation in the translation sample, the first label and the second label; and the parameters of the target translation model are adjusted according to the second stage loss function value.
[0148] In this embodiment, through the above technical solution, the second stage training of the target translation model can be divided into three sub-stages, such as Figure 3 The second stage training shown in Figure 1, where x represents the sample to be translated, y represents the translation sample, and NMT represents the target translation model. represents the third predicted probability distribution of the word segmentation in the sample to be translated, represents the target sample to be translated, represents the second predicted probability distribution of word segmentation in the translation sample, Indicates the third predicted probability distribution of word segmentation in the translation sample. In the first sub-stage, the translation sample is input into the encoder and the sample to be translated is input into the decoder to realize the reverse translation training from the translation sample to the sample to be translated; in the second sub-stage, the target sample to be translated obtained by reverse translation is input into the encoder and the translation sample is input into the decoder to realize the forward translation training from the target sample to be translated to the translation sample; in the third sub-stage, the sample to be translated is input into the encoder and the translation sample is input into the decoder to realize the forward translation training from the sample to be translated to the translation sample, and at the same time, the forward translation training from the target sample to be translated to the translation sample and the forward translation training from the sample to be translated to the translation sample learn from each other, so as to further realize the forward translation training of the target translation model. Therefore, the mutual mapping between the translation sample and the sample to be translated can be achieved according to the first sub-stage, the second sub-stage and the third sub-stage, so as to enhance the translation accuracy of the target translation model when translating text; in addition, since the target sample to be translated in the encoder is obtained by reverse translation training based on the translation sample during the forward translation training process from the target sample to be translated to the translation sample, it may cause errors between the target sample to be translated and the corresponding sample to be translated, and since the translation sample is accurate during the forward translation training process based on the target sample to be translated and the translation sample, it is possible to enhance the fault tolerance of the forward translation of the target translation model and improve the accuracy of the forward translation result; in addition, since the target sample to be translated There are differences between the translation sample and the target sample to be translated, so there may be a situation where the result obtained by performing forward translation training based on the target sample to be translated and the translation sample is different from the actual result obtained by performing forward translation training based on the sample to be translated and the translation sample. Therefore, the embodiment of the present disclosure reduces the gap between the result obtained by performing forward translation training based on the target sample to be translated and the translation sample and the result obtained by performing forward translation training based on the sample to be translated and the translation sample by allowing the forward translation training from the target sample to be translated to the translation sample and the forward translation training from the sample to be translated to the translation sample to learn from each other, so as to further enhance the fault tolerance of the forward translation of the target translation model and improve the accuracy of the forward translation result.
[0149] In a possible implementation, determining the second-stage loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the third predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label may include:
[0150] According to the third predicted probability distribution and the first label of the word segmentation in the sample to be translated, the fifth loss function value is determined; according to the second predicted probability distribution and the second label of the word segmentation in the translation sample, the sixth loss function value is determined; according to the third predicted probability distribution and the second label of the word segmentation in the translation sample, the seventh loss function value is determined; according to the second predicted probability distribution of the word segmentation in the translation sample and the third predicted probability distribution of the word segmentation in the translation sample, the eighth loss function value is determined; according to the fifth loss function value, the sixth loss function value, the seventh loss function value and the eighth loss function value, the second stage loss function value is determined.
[0151] The fifth loss function value, the sixth loss function value, and the seventh loss function value can be determined by referring to the loss function value L ce1 Or the loss function value L ce2 The method for determining the value of the eighth loss function can refer to the method for determining the value of the fourth loss function, which will not be described in detail in the present embodiment.
[0152] After obtaining the fifth loss function value, the sixth loss function value, the seventh loss function value and the eighth loss function value, the fifth loss function value, the sixth loss function value, the seventh loss function value and the eighth loss function value are added to obtain the total loss function value of the target translation model in the second stage training process, so that the parameters of the target translation model can be adjusted according to the total loss function value in the second stage training process.
[0153] In summary, through the above-mentioned text translation method, when training the target translation model, on the one hand, it can be trained based on the two opposite language directions of the training corpus, and realize the mutual mapping learning between the translation sample and the sample to be translated, so that the target translation model can be trained with less training corpus, and the translation accuracy when the target translation model is used for text translation can be improved. On the other hand, by using the prediction result of one language direction as the input of the prediction of another language direction for reverse prediction, the fault tolerance of the target translation model can be enhanced, thereby further improving the translation accuracy.
[0154] Based on the same concept, the present disclosure also provides a text translation device. Figure 4 As shown, the text translation device 400 may include:
[0155] A first acquisition module 401 is configured to acquire a text to be translated;
[0156] The processing module 402 is configured to input the text to be translated into a target translation model to obtain a target translation text;
[0157] Wherein, the target translation model includes an encoder and a decoder, and the text translation device also includes:
[0158] A second acquisition module is configured to acquire a sample to be translated and a translation sample corresponding to the sample to be translated;
[0159] A first training module is configured to input the sample to be translated into the encoder, and input the translation sample into the decoder to obtain first translation data, and perform first-stage training on the target translation model with the first translation data and the sample to be translated as input and the probability distribution of word segments in the sample to be translated as output;
[0160] The second training module is configured to input the translation sample into the encoder and the sample to be translated into the decoder to obtain second translation data, and perform second-stage training on the target translation model with the second translation data and the translation sample as input and the probability distribution of word segmentation in the translation sample as output.
[0161] In a possible implementation, the first training module may include:
[0162] A first input unit is configured to input the sample to be translated into the encoder, and input the translation sample into the decoder, to obtain a first predicted probability distribution of word segments in the translation sample and a word embedding matrix of the translation sample;
[0163] The first determining unit is configured to determine a first product of a first predicted probability distribution of word segments in the translation sample and a word embedding matrix of the translation sample, and determine the first product as the first translation data.
[0164] In a possible implementation manner, the sample to be translated corresponds to a first label, and the translated sample corresponds to a second label, the first label is used to characterize the true probability distribution of the segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the segmentation in the translated sample, and the first training module may further include:
[0165] A second input unit is configured to input the first translation data into the encoder, and input the sample to be translated into the decoder, to obtain a first predicted probability distribution of word segments in the sample to be translated;
[0166] A second determining unit is configured to determine a first-stage loss function value according to the first predicted probability distribution of the word segmentation in the translation sample, the first predicted probability distribution of the word segmentation in the sample to be translated, the first label, and the second label;
[0167] The first adjustment unit is configured to adjust the parameters of the target translation model according to the first stage loss function value.
[0168] In a possible implementation manner, the sample to be translated corresponds to a first label, and the translation sample corresponds to a second label, the first label is used to characterize the true probability distribution of the segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the segmentation in the translation sample. The text translation device may further include:
[0169] A third input unit is configured to input the translation sample into the encoder and the sample to be translated into the decoder to obtain a second predicted probability distribution of word segments in the sample to be translated;
[0170] Accordingly, the first training module may further include:
[0171] a fourth input unit, configured to input the first translation data into the encoder, and input the sample to be translated into the decoder, to obtain a first predicted probability distribution of word segments in the sample to be translated;
[0172] A third determining unit is configured to determine a first-stage loss function value according to the first predicted probability distribution of the segmentation in the sample to be translated, the second predicted probability distribution of the segmentation in the sample to be translated, the first predicted probability distribution of the segmentation in the translation sample, the first label, and the second label;
[0173] The second adjustment unit is configured to adjust the parameters of the target translation model according to the first stage loss function value.
[0174] In a possible implementation manner, the third determining unit may include:
[0175] A first determination subunit is configured to determine a first loss function value according to the first predicted probability distribution of the word segmentation in the translation sample and the second label, determine a second loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated and the first label, determine a third loss function value according to the second predicted probability distribution of the word segmentation in the sample to be translated and the first label, and determine a fourth loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated and the second predicted probability distribution of the word segmentation in the sample to be translated;
[0176] The second determination subunit is configured to determine the first-stage loss function value based on the first loss function value, the second loss function value, the third loss function value and the fourth loss function value.
[0177] In a possible implementation, the second training module may include:
[0178] a fifth input unit, configured to input the translation sample into the encoder, and input the sample to be translated into the decoder, to obtain a third predicted probability distribution of word segments in the sample to be translated and a word embedding matrix of the sample to be translated;
[0179] The fourth determining unit is configured to determine a second product of a third predicted probability distribution of word segments in the sample to be translated and a word embedding matrix of the sample to be translated, and determine the second product as the second translation data.
[0180] In a possible implementation, the sample to be translated corresponds to a first label, and the translated sample corresponds to a second label, the first label is used to characterize the true probability distribution of the segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the segmentation in the translated sample, and the second training module may include:
[0181] a sixth input unit, configured to input the second translation data into the encoder, and input the translation sample into the decoder, to obtain a second predicted probability distribution of word segments in the translation sample;
[0182] a fifth determining unit, configured to determine a second-stage loss function value according to a third predicted probability distribution of the word segmentation in the to-be-translated sample, a second predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label;
[0183] The third adjustment unit is configured to adjust the parameters of the target translation model according to the second stage loss function value.
[0184] In a possible implementation manner, the sample to be translated corresponds to a first label, and the translation sample corresponds to a second label, the first label is used to characterize the true probability distribution of the segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the segmentation in the translation sample. The text translation device may further include:
[0185] a seventh input unit, configured to input the sample to be translated into the encoder, and input the translation sample into the decoder, to obtain a third predicted probability distribution of word segments in the translation sample;
[0186] Accordingly, the second training module may further include:
[0187] an eighth input unit, configured to input the second translation data into the encoder, and input the translation sample into the decoder, to obtain a second predicted probability distribution of word segments in the translation sample;
[0188] a sixth determining unit, configured to determine a second-stage loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the third predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label;
[0189] The fourth adjustment unit is configured to adjust the parameters of the target translation model according to the second stage loss function value.
[0190] In a possible implementation manner, the sixth determining unit may include:
[0191] A third determination subunit is configured to determine a fifth loss function value according to a third predicted probability distribution of the word segment in the sample to be translated and the first label, determine a sixth loss function value according to a second predicted probability distribution of the word segment in the translation sample and the second label, determine a seventh loss function value according to the third predicted probability distribution of the word segment in the translation sample and the second label, and determine an eighth loss function value according to the second predicted probability distribution of the word segment in the translation sample and the third predicted probability distribution of the word segment in the translation sample;
[0192] The fourth determination subunit is configured to determine the second-stage loss function value based on the fifth loss function value, the sixth loss function value, the seventh loss function value and the eighth loss function value.
[0193] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0194] The present disclosure also provides a computer-readable storage medium having computer program instructions stored thereon, and when the program instructions are executed by a processor, the steps of the text translation method provided by the present disclosure are implemented.
[0195] The present disclosure also provides an electronic device, comprising:
[0196] processor;
[0197] a memory for storing processor-executable instructions;
[0198] Wherein, the processor is configured to:
[0199] Execute the steps of the text translation method provided by the present disclosure.
[0200] Figure 55 is a block diagram of a device for text translation according to an exemplary embodiment. For example, the device 500 may be a mobile phone, a computer, a digital broadcast terminal, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0201] Reference Figure 5 , the device 500 may include one or more of the following components: a first processing component 502 , a first memory 504 , a first power supply component 506 , a multimedia component 505 , an audio component 510 , a first input / output interface 512 , a sensor component 514 , and a communication component 516 .
[0202] The first processing component 502 generally controls the overall operation of the device 500, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The first processing component 502 may include one or more first processors 520 to execute instructions to complete all or part of the steps of the above-mentioned text translation method. In addition, the first processing component 502 may include one or more modules to facilitate the interaction between the first processing component 502 and other components. For example, the first processing component 502 may include a multimedia module to facilitate the interaction between the multimedia component 505 and the first processing component 502.
[0203] The first memory 504 is configured to store various types of data to support operations on the device 500. Examples of such data include instructions for any application or method operating on the device 500, contact data, phone book data, messages, pictures, videos, etc. The first memory 504 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0204] The first power source component 506 provides power to various components of the device 500. The first power source component 506 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device 500.
[0205] The multimedia component 505 includes a screen that provides an output interface between the device 500 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 505 includes a front camera and / or a rear camera. When the device 500 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0206] The audio component 510 is configured to output and / or input audio signals. For example, the audio component 510 includes a microphone (MIC), and when the device 500 is in an operation mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the first memory 504 or sent via the communication component 516. In some embodiments, the audio component 510 also includes a speaker for outputting audio signals.
[0207] The first input / output interface 512 provides an interface between the first processing component 502 and a peripheral interface module, which may be a keyboard, a click wheel, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0208] The sensor assembly 514 includes one or more sensors for providing various aspects of status assessment for the device 500. For example, the sensor assembly 514 can detect the open / closed state of the device 500, the relative positioning of components, such as the display and keypad of the device 500, the sensor assembly 514 can also detect the position change of the device 500 or a component of the device 500, the presence or absence of user contact with the device 500, the orientation or acceleration / deceleration of the device 500, and the temperature change of the device 500. The sensor assembly 514 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 514 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 514 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0209] The communication component 516 is configured to facilitate wired or wireless communication between the device 500 and other devices. The device 500 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 516 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 516 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0210] In an exemplary embodiment, the apparatus 500 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above-mentioned text translation method.
[0211] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a first memory 504 including instructions, and the instructions can be executed by the first processor 520 of the device 500 to complete the above-mentioned text translation method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0212] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program that can be executed by a programmable device. The computer program has a code portion for executing the above-mentioned text translation method when executed by the programmable device.
[0213] Figure 6 6 is a block diagram of a device 600 for text translation according to an exemplary embodiment. For example, the device 600 may be provided as a server. Figure 6 , the apparatus 600 includes a second processing component 622, which further includes one or more processors, and a memory resource represented by a second memory 632, for storing instructions executable by the second processing component 622, such as an application. The application stored in the second memory 632 may include one or more modules, each corresponding to a set of instructions. In addition, the second processing component 622 is configured to execute instructions to perform all or part of the steps of the above-mentioned text translation method.
[0214] The device 600 may further include a second power supply component 626 configured to perform power management of the device 600, a wired or wireless network interface 650 configured to connect the device 600 to a network, and a second input / output interface 658. The device 600 may operate based on an operating system stored in the memory 632, such as Windows Server 2000. TM , Mac OSX TM , Unix TM , Linux TM , FreeBSD TM or similar.
[0215] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the present disclosure. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0216] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A text translation method, characterized in that: The method comprises: Get the text to be translated; Inputting the text to be translated into a target translation model to obtain a target translated text; The target translation model includes an encoder and a decoder, and the target translation model is trained in the following manner: Obtaining a sample to be translated and a translation sample corresponding to the sample to be translated; Input the sample to be translated into the encoder, and input the translation sample into the decoder to obtain first translation data, and perform first-stage training on the target translation model with the first translation data and the sample to be translated as input and the probability distribution of word segmentation in the sample to be translated as output; The translation sample is input into the encoder, and the sample to be translated is input into the decoder to obtain second translation data, and the second translation data and the translation sample are used as input, and the probability distribution of word segmentation in the translation sample is used as output to perform second-stage training on the target translation model.
2. The method according to claim 1, characterized in that: The step of inputting the sample to be translated into the encoder and inputting the translation sample into the decoder to obtain first translation data comprises: Inputting the sample to be translated into the encoder, and inputting the translation sample into the decoder, to obtain a first predicted probability distribution of word segments in the translation sample and a word embedding matrix of the translation sample; Determine a first product of a first predicted probability distribution of word segments in the translation sample and a word embedding matrix of the translation sample, and determine the first product as the first translation data.
3. The method according to claim 2, characterized in that The sample to be translated has a first label corresponding to it, and the translation sample has a second label corresponding to it, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translation sample, and the first translation data and the sample to be translated are used as input, and the probability distribution of the word segmentation in the sample to be translated is used as output, and the target translation model is trained in the first stage, including: Inputting the first translation data into the encoder, and inputting the sample to be translated into the decoder, to obtain a first predicted probability distribution of word segments in the sample to be translated; Determine a first-stage loss function value according to the first predicted probability distribution of the word segmentation in the translation sample, the first predicted probability distribution of the word segmentation in the sample to be translated, the first label, and the second label; According to the first-stage loss function value, the parameters of the target translation model are adjusted.
4. The method according to claim 2, characterized in that: The sample to be translated has a first label corresponding to it, and the translated sample has a second label corresponding to it, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translated sample, and the method further includes: Input the translation sample into the encoder, and input the sample to be translated into the decoder, to obtain a second predicted probability distribution of word segments in the sample to be translated; The first translation data and the sample to be translated are used as input, and the probability distribution of word segments in the sample to be translated is used as output, and the target translation model is trained in the first stage, including: Inputting the first translation data into the encoder, and inputting the sample to be translated into the decoder, to obtain a first predicted probability distribution of word segments in the sample to be translated; Determine a first-stage loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the sample to be translated, the first predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label; According to the first-stage loss function value, the parameters of the target translation model are adjusted.
5. The method according to claim 4, characterized in that The determining of the first-stage loss function value according to the first predicted probability distribution of the word segmentation in the to-be-translated sample, the second predicted probability distribution of the word segmentation in the to-be-translated sample, the first predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label includes: Determine a first loss function value according to the first predicted probability distribution of the word segmentation in the translation sample and the second label, determine a second loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated and the first label, determine a third loss function value according to the second predicted probability distribution of the word segmentation in the sample to be translated and the first label, and determine a fourth loss function value according to the first predicted probability distribution of the word segmentation in the sample to be translated and the second predicted probability distribution of the word segmentation in the sample to be translated; Determine the first stage loss function value according to the first loss function value, the second loss function value, the third loss function value and the fourth loss function value.
6. The method according to any one of claims 1 to 5, characterized in that The step of inputting the translation sample into the encoder and inputting the sample to be translated into the decoder to obtain second translation data comprises: Input the translation sample into the encoder, and input the sample to be translated into the decoder, to obtain a third predicted probability distribution of word segments in the sample to be translated and a word embedding matrix of the sample to be translated; Determine a second product of a third predicted probability distribution of word segments in the sample to be translated and a word embedding matrix of the sample to be translated, and determine the second product as the second translation data.
7. The method according to claim 6, characterized in that The sample to be translated has a first label corresponding to it, and the translation sample has a second label corresponding to it, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translation sample, and the second translation data and the translation sample are used as input, and the probability distribution of the word segmentation in the translation sample is used as output, and the target translation model is trained in the second stage, including: Inputting the second translation data into the encoder, and inputting the translation sample into the decoder, to obtain a second predicted probability distribution of word segments in the translation sample; Determine a second-stage loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label; According to the second-stage loss function value, the parameters of the target translation model are adjusted.
8. The method according to claim 6, characterized in that The sample to be translated has a first label corresponding to it, and the translated sample has a second label corresponding to it, the first label is used to characterize the true probability distribution of the word segmentation in the sample to be translated, and the second label is used to characterize the true probability distribution of the word segmentation in the translated sample, and the method further includes: Inputting the sample to be translated into the encoder, and inputting the translation sample into the decoder, to obtain a third predicted probability distribution of word segments in the translation sample; The second translation data and the translation sample are used as input, and the probability distribution of word segments in the translation sample is used as output, and the target translation model is trained in the second stage, including: Inputting the second translation data into the encoder, and inputting the translation sample into the decoder, to obtain a second predicted probability distribution of word segments in the translation sample; Determine a second-stage loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the third predicted probability distribution of the word segmentation in the translation sample, the first label, and the second label; According to the second-stage loss function value, the parameters of the target translation model are adjusted.
9. The method according to claim 8, characterized in that The determining of the second-stage loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated, the second predicted probability distribution of the word segmentation in the translation sample, the third predicted probability distribution of the word segmentation in the translation sample, the first label and the second label includes: Determine a fifth loss function value according to the third predicted probability distribution of the word segmentation in the sample to be translated and the first label, determine a sixth loss function value according to the second predicted probability distribution of the word segmentation in the translation sample and the second label, determine a seventh loss function value according to the third predicted probability distribution of the word segmentation in the translation sample and the second label, and determine an eighth loss function value according to the second predicted probability distribution of the word segmentation in the translation sample and the third predicted probability distribution of the word segmentation in the translation sample; Determine the second-stage loss function value based on the fifth loss function value, the sixth loss function value, the seventh loss function value and the eighth loss function value.
10. A text translation device, characterized in that: include: A first acquisition module is configured to acquire a text to be translated; A processing module is configured to input the text to be translated into a target translation model to obtain a target translation text; Wherein, the target translation model includes an encoder and a decoder, and the text translation device also includes: A second acquisition module is configured to acquire a sample to be translated and a translation sample corresponding to the sample to be translated; A first training module is configured to input the sample to be translated into the encoder, and input the translation sample into the decoder to obtain first translation data, and perform first-stage training on the target translation model with the first translation data and the sample to be translated as input and the probability distribution of word segments in the sample to be translated as output; The second training module is configured to input the translation sample into the encoder and the sample to be translated into the decoder to obtain second translation data, and perform second-stage training on the target translation model with the second translation data and the translation sample as input and the probability distribution of word segmentation in the translation sample as output.
11. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to: Execute the steps of the method according to any one of claims 1 to 9.
12. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the steps of the method described in any one of claims 1 to 9 are implemented.
