Translation model training and translating method and device
1. A method for training a translation model, comprising:
acquiring first training data, wherein the first training data comprises a plurality of first training texts, forward texts of the first training texts and translation labeling results of the first training texts;
constructing a neural network model comprising a memory module, an encoding module and a decoding module, wherein the memory module is used for outputting an updated memory vector and a second encoding vector which is used for being input into the decoding module according to a current memory vector and a first encoding vector obtained by the encoding module;
and training the neural network model by using the plurality of first training texts, the foreword texts of the plurality of first training texts and the translation labeling results of the plurality of first training texts to obtain a translation model.
2. The method of claim 1, wherein the encoding module deriving a first code vector comprises:
respectively outputting an encoding vector corresponding to the initiator, an encoding vector corresponding to the first training text and an encoding vector corresponding to the preceding text according to the input initiator, the first training text and the preceding text of the first training text;
the code vector corresponding to the start symbol is taken as the first code vector.
3. The method of claim 1, wherein the training the neural network model using the plurality of first training texts, the text of the predecessor of the plurality of first training texts, and the translation labeling results of the plurality of first training texts comprises:
for each first training text, taking the first training text and a preceding text of the first training text as the input of the coding module to obtain a first coding vector output by the coding module, a coding vector corresponding to the first training text and a coding vector corresponding to the preceding text;
taking the current memory vector and the first encoding vector as the input of the memory module to obtain an updated memory vector and a second encoding vector output by the memory module;
taking the second encoding vector, the encoding vector corresponding to the first training text and the encoding vector corresponding to the preceding text as the input of the decoding module to obtain a translation output result which is output by the decoding module and corresponds to the first training text;
and calculating a loss function value by using the translation marking result and the translation output result of the first training text, and adjusting the parameters of the neural network model according to the calculated loss function value until the neural network model converges to obtain the translation model.
4. The method of claim 1, wherein the constructing a neural network model comprising a memory module, an encoding module, and a decoding module comprises:
acquiring second training data, wherein the second training data comprises a plurality of second training texts;
pre-training the target model by using a plurality of second training texts to obtain parameters of a target coding module and parameters of a target decoding module in the pre-trained target model;
the method comprises the steps of constructing a neural network model comprising a memory module, an encoding module and a decoding module, initializing parameters of the encoding module in the neural network model by using the parameters of the target encoding module, and initializing parameters of the decoding module in the neural network model by using the parameters of the target decoding module.
5. A method of translation, comprising:
acquiring a chapter to be translated, and determining a text to be translated in the chapter to be translated and a text in the front of the text to be translated;
for each text to be translated, inputting the text to be translated and the preceding text of the text to be translated into a translation model, and obtaining a translation output result of the text to be translated according to an output result of the translation model;
outputting a result according to the translation of each text to be translated to obtain a translation result of the chapter to be translated;
wherein the translation model is pre-trained according to the method of any one of claims 1-4.
6. The method of claim 5, wherein the inputting the text to be translated and the preceding text of the text to be translated into the translation model comprises, for each text to be translated:
for each text to be translated, an initiator, the text to be translated and a preceding text of the text to be translated are input into a translation model.
7. A training apparatus for translation models, comprising:
the device comprises a first obtaining unit, a second obtaining unit and a judging unit, wherein the first obtaining unit is used for obtaining first training data, and the first training data comprises a plurality of first training texts, previous texts of the first training texts and translation marking results of the first training texts;
the device comprises a construction unit, a decoding module and a memory module, wherein the construction unit is used for constructing a neural network model comprising the memory module, the encoding module and the decoding module, and the memory module is used for outputting an updated memory vector and a second encoding vector which is used for being input into the decoding module according to a current memory vector and a first encoding vector obtained by the encoding module;
and the training unit is used for training the neural network model by using the plurality of first training texts, the foreword texts of the plurality of first training texts and the translation marking results of the plurality of first training texts to obtain a translation model.
8. The apparatus according to claim 7, wherein the encoding module constructed by the constructing unit, when obtaining the first encoding vector, specifically performs:
respectively outputting an encoding vector corresponding to the initiator, an encoding vector corresponding to the first training text and an encoding vector corresponding to the preceding text according to the input initiator, the first training text and the preceding text of the first training text;
the code vector corresponding to the start symbol is taken as the first code vector.
9. The apparatus according to claim 7, wherein the training unit, when training the neural network model using the plurality of first training texts, the text preambles of the plurality of first training texts, and the translation tagging results of the plurality of first training texts, obtains the translation model, specifically performs:
for each first training text, taking the first training text and a preceding text of the first training text as the input of the coding module to obtain a first coding vector output by the coding module, a coding vector corresponding to the first training text and a coding vector corresponding to the preceding text;
taking the current memory vector and the first encoding vector as the input of the memory module to obtain an updated memory vector and a second encoding vector output by the memory module;
taking the second encoding vector, the encoding vector corresponding to the first training text and the encoding vector corresponding to the preceding text as the input of the decoding module to obtain a translation output result which is output by the decoding module and corresponds to the first training text;
and calculating a loss function value by using the translation marking result and the translation output result of the first training text, and adjusting the parameters of the neural network model according to the calculated loss function value until the neural network model converges to obtain the translation model.
10. The apparatus according to claim 7, wherein the constructing unit, when constructing the neural network model comprising the memory module, the encoding module and the decoding module, specifically performs:
acquiring second training data, wherein the second training data comprises a plurality of second training texts;
pre-training the target model by using a plurality of second training texts to obtain parameters of a target coding module and parameters of a target decoding module in the pre-trained target model;
the method comprises the steps of constructing a neural network model comprising a memory module, an encoding module and a decoding module, initializing parameters of the encoding module in the neural network model by using the parameters of the target encoding module, and initializing parameters of the decoding module in the neural network model by using the parameters of the target decoding module.
11. A translation device, comprising:
the second acquisition unit is used for acquiring the chapter to be translated and determining the text to be translated in the chapter to be translated and the text in the front of the text to be translated;
the translation unit is used for inputting the text to be translated and the previous text of the text to be translated into a translation model aiming at each text to be translated, and obtaining a translation output result of the text to be translated according to the output result of the translation model;
the processing unit is used for outputting a result according to the translation of each text to be translated to obtain a translation result of the chapter to be translated;
wherein the translation model is pre-trained according to the apparatus of any one of claims 7-10.
12. The apparatus according to claim 11, wherein the translating unit, when inputting, for each text to be translated, the text to be translated and a preceding text of the text to be translated into the translation model, specifically performs:
for each text to be translated, an initiator, the text to be translated and a preceding text of the text to be translated are input into a translation model.
13. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
14. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of any one of claims 1-6.
15. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-6.
Background
In machine translation, sentences are generally input into a translation system for translation, and then a translation produced by the translation system is obtained. In a real translation scenario, sentences are not independent of each other, but have a context relationship. Translations produced by a translation system that are only sentence-level may be perfect at the single-sentence level, but the results of sentence-by-sentence translation are not necessarily optimal from the overall context level of the sentence.
Disclosure of Invention
According to a first aspect of the present disclosure, there is provided a method for training a translation model, including: acquiring first training data, wherein the first training data comprises a plurality of first training texts, forward texts of the first training texts and translation labeling results of the first training texts; constructing a neural network model comprising a memory module, an encoding module and a decoding module, wherein the memory module is used for outputting an updated memory vector and a second encoding vector which is used for being input into the decoding module according to a current memory vector and a first encoding vector obtained by the encoding module; and training the neural network model by using the plurality of first training texts, the foreword texts of the plurality of first training texts and the translation labeling results of the plurality of first training texts to obtain a translation model.
According to a second aspect of the present disclosure, there is provided a translation method including: acquiring a chapter to be translated, and determining a text to be translated in the chapter to be translated and a text in the front of the text to be translated; for each text to be translated, inputting the text to be translated and the preceding text of the text to be translated into a translation model, and obtaining a translation output result of the text to be translated according to an output result of the translation model; and outputting a result according to the translation of each text to be translated to obtain a translation result of the chapter to be translated.
According to a third aspect of the present disclosure, there is provided a training apparatus for a translation model, including: the device comprises a first obtaining unit, a second obtaining unit and a judging unit, wherein the first obtaining unit is used for obtaining first training data, and the first training data comprises a plurality of first training texts, previous texts of the first training texts and translation marking results of the first training texts; the device comprises a construction unit, a decoding module and a memory module, wherein the construction unit is used for constructing a neural network model comprising the memory module, the encoding module and the decoding module, and the memory module is used for outputting an updated memory vector and a second encoding vector which is used for being input into the decoding module according to a current memory vector and a first encoding vector obtained by the encoding module; and the training unit is used for training the neural network model by using the plurality of first training texts, the foreword texts of the plurality of first training texts and the translation marking results of the plurality of first training texts to obtain a translation model.
According to a fourth aspect of the present disclosure, there is provided a translation apparatus including: the second acquisition unit is used for acquiring the chapter to be translated and determining the text to be translated in the chapter to be translated and the text in the front of the text to be translated; the translation unit is used for inputting the text to be translated and the previous text of the text to be translated into a translation model aiming at each text to be translated, and obtaining a translation output result of the text to be translated according to the output result of the translation model; and the processing unit is used for outputting a result according to the translation of each text to be translated to obtain a translation result of the chapter to be translated.
According to a fifth aspect of the present disclosure, there is provided an electronic device comprising: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method as described above.
According to a sixth aspect of the present disclosure, there is provided a non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method as described above.
According to a seventh aspect of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements the method as described above.
According to the technical scheme, when the preceding text of the first training text is used for training the neural network model, the memory module in the neural network model dynamically updates the memory vector in which the preceding information is stored, so that the purpose that the neural network model translates the next first training text by using the updated memory vector is achieved, the translation model obtained by training can be combined with the two kinds of preceding information, namely the continuously updated memory vector and the directly input preceding text, so that the maximum utilization of the preceding information during translation is ensured, and the accuracy of the translation result obtained by the translation model is improved.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
FIG. 1 is a schematic diagram according to a first embodiment of the present disclosure;
FIG. 2 is a schematic diagram according to a second embodiment of the present disclosure;
FIG. 3 is a schematic diagram according to a third embodiment of the present disclosure;
FIG. 4 is a schematic diagram according to a fourth embodiment of the present disclosure;
FIG. 5 is a schematic diagram according to a fifth embodiment of the present disclosure;
FIG. 6 is a schematic diagram according to a sixth embodiment of the present disclosure;
FIG. 7 is a block diagram of an electronic device for implementing a method for training and translating a translation model according to an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram according to a first embodiment of the present disclosure. As shown in fig. 1, the training method of the translation model in this embodiment may specifically include the following steps:
s101, obtaining first training data, wherein the first training data comprises a plurality of first training texts, forward texts of the first training texts and translation labeling results of the first training texts;
s102, constructing a neural network model comprising a memory module, an encoding module and a decoding module, wherein the memory module is used for outputting an updated memory vector and a second encoding vector which is used for being input into the decoding module according to a current memory vector and a first encoding vector obtained by the encoding module;
s103, training the neural network model by using the plurality of first training texts, the foreword texts of the plurality of first training texts and the translation labeling results of the plurality of first training texts to obtain a translation model.
In the training method of the translation model of this embodiment, a neural network model including a memory module is constructed, so that the neural network model translates a first training text in combination with a memory vector dynamically updated by the memory module, and because the input of the coding module further includes a previous text of the first training text, the memory module can continuously update the memory vector according to the previous information, thereby achieving the purpose of translating a next first training text by using the updated memory vector by the neural network model, so that the translation model obtained by training can translate a current text in combination with the updated memory vector and the previous two previous information of the directly input text, thereby ensuring that the previous information is maximally utilized during translation, and improving the accuracy of a translation result obtained by the translation model.
In this embodiment, when S101 is executed to obtain first training data, different texts obtained from the same chapter may be used as a plurality of first training texts, where each first training text is a text to be translated in a training process; the text in the front of each first training text, specifically, the whole text or a part of text in the chapters before the first training text, in this embodiment, a plurality of consecutive texts before the first training text may be used as the text in the front of the first training text; the translation marking results of the plurality of first training texts are marked in advance, and the translation marking results of the first training texts are correct translation results of the first training texts.
In this embodiment, the first training text and the translation labeling result respectively correspond to different languages, that is, the first training data obtained by performing S101 in this embodiment is a chapter-level parallel corpus.
In addition, when the first training data is obtained in S101, the embodiment may also obtain a plurality of first training texts from different chapters; in order to ensure the training accuracy of the neural network model, a plurality of first training texts belonging to the same chapter are required to complete one training process of the neural network model, and then a translation model is obtained through a plurality of training processes.
In this embodiment, after the first training data including the plurality of first training texts, the text of the previous paragraphs of the plurality of first training texts, and the translation labeling result of the plurality of first training texts is obtained in S101, S102 is performed to construct a neural network model including a memory module, an encoding module, and a decoding module.
In the embodiment, the neural network model constructed by step S102 is implemented, where the encoding module is an encoder based on a Transformer structure, and the encoding module is configured to output an encoding vector corresponding to the first training text and an encoding vector corresponding to the preceding text according to the input first training text and the preceding text of the first training text, respectively; in this embodiment, the encoding vector corresponding to the text is specifically a vector sequence formed by encoding results of word segmentation results in the text.
When obtaining the first coding vector according to the first training text and the text in the foregoing of the first training text, the coding module in this embodiment may splice the coding vector corresponding to the first training text and the coding vector corresponding to the text in the foregoing, and use the spliced result as the first coding vector; the average value of the code vectors can be calculated according to the code vector corresponding to the first training text and the code vector corresponding to the preceding text, and the calculation result is used as the first code vector.
However, when the result of splicing the text code vectors is used as the first code vector, the first code vector is redundant; when the average value of the code vectors of the text is used as the first code vector, there is a problem that the first code vector loses text information.
Therefore, in order to avoid the problems of redundancy and text information loss of the first encoding vector and improve the accuracy of the obtained first encoding vector, the encoding module in this embodiment may adopt an optional implementation manner when obtaining the first encoding vector: respectively outputting an encoding vector corresponding to the initiator, an encoding vector corresponding to the first training text and an encoding vector corresponding to the preceding text of the first training text according to the input initiator, the first training text and the preceding text of the first training text; the code vector corresponding to the start symbol is taken as the first code vector.
In this embodiment, the start character used as the input of the encoding module is a special character indicating the start of input; the encoding module obtains the encoding vector corresponding to the start symbol according to the first training text and the text, and the encoding vector corresponding to the start symbol includes text information of the inputted text, so that the encoding vector corresponding to the start symbol is inputted to the memory module as the first encoding vector.
In this embodiment, the start symbol, the previous text (including different texts in the previous text) and the first training text may be separated by a separator, so that a translation output result corresponding to the first training text is determined in the output result of the decoding module according to the used separator.
In the embodiment, executing the Neural Network model constructed in S102, the memory module may be implemented based on a Recurrent Neural Network (RNN), and the memory module is configured to output the updated memory vector and a second encoding vector for inputting to the decoding module according to the current memory vector and the first encoding vector obtained by the encoding module; the memory module uses the current memory vector to translate the current first training text, and outputs the updated memory vector to translate the next first training text.
That is to say, the memory module in this embodiment updates the currently used memory vector according to the currently input first training text and the preamble text of the first training text, and continuously stores the preamble information by updating the memory vector, so as to achieve the purpose of sufficiently utilizing the preamble information to perform translation, thereby improving the translation accuracy of the first training text.
It is understood that, in the present embodiment, when the first training text is translated, the memory vector used may be a preset vector, and the preset vector may be a zero vector.
In the embodiment of the neural network model constructed by step S102, the decoding module is a decoder based on the transform result, and the decoding module is configured to output a translation output result corresponding to the first training text according to the second decoding vector output by the memory module and the encoding vector corresponding to the first training text and the encoding vector corresponding to the preceding text output by the encoding module.
In this embodiment, after the step S102 of constructing the neural network model including the memory module, the encoding module and the decoding module is performed, the step S103 of training the neural network model by using the plurality of first training texts, the forward texts of the plurality of first training texts, and the translation labeling results of the plurality of first training texts is performed to obtain the translation model.
After the translation model obtained by performing the training in S103 in this embodiment is obtained, the text to be translated in the chapter to be translated and the corresponding preceding text are sequentially used as the input of the translation model, and the translation result of each text to be translated output by the translation model is obtained, so that the translation result of the chapter to be translated is obtained.
Specifically, when executing S103 to train the neural network model by using the translation labeling result of the multiple first training texts, the text preambles of the multiple first training texts, and the multiple first training texts, to obtain the translation model, the present embodiment may adopt an optional implementation manner as follows: for each first training text, taking the first training text and a preceding text of the first training text as the input of a coding module to obtain a first coding vector output by the coding module, a coding vector corresponding to the first training text and a coding vector corresponding to the preceding text; taking the current memory vector and the first encoding vector as the input of a memory module to obtain an updated memory vector and a second encoding vector which are output by the memory module, wherein the output updated memory vector is used for the translation of the next first training text; taking the second encoding vector, the encoding vector corresponding to the first training text and the encoding vector corresponding to the preceding text as the input of a decoding module to obtain a translation output result which is output by the decoding module and corresponds to the first training text; and calculating a loss function value by using the translation marking result and the translation output result of the first training text, and adjusting the parameters of the neural network model according to the calculated loss function value until the neural network model converges to obtain the translation model.
According to the method, when the preceding text of the first training text is used for training the neural network model, the memory module in the neural network model dynamically updates the memory vector in which the preceding information is stored, so that the purpose that the neural network model translates the next first training text by using the updated memory vector is achieved, the translation model obtained by training can be combined with the two kinds of preceding information, namely the continuously updated memory vector and the directly input preceding text, so that the maximum utilization of the preceding information during translation is ensured, and the accuracy of the translation result obtained by the translation model is improved.
Fig. 2 is a schematic diagram according to a second embodiment of the present disclosure. As shown in fig. 2, when performing S102 "building a neural network model including a memory module, an encoding module, and a decoding module", the embodiment may specifically include the following steps:
s201, obtaining second training data, wherein the second training data comprises a plurality of second training texts;
s202, pre-training the target model by using a plurality of second training texts to obtain parameters of a target coding module and parameters of a target decoding module in the pre-trained target model;
s203, constructing a neural network model comprising a memory module, an encoding module and a decoding module, initializing parameters of the encoding module in the neural network model by using the parameters of the target encoding module, and initializing parameters of the decoding module in the neural network model by using the parameters of the target decoding module.
The number of the first training data may affect the translation effect of the translation model, and because the chapter-level parallel corpora are relatively rare, the embodiment adopts a pre-training mode, and the target model is pre-trained by using the chapter-level monolingual corpora first, and then the parameters in the pre-trained target model are initialized, so that the translation effect of the translation model is improved under the condition that the chapter-level parallel corpora are relatively few.
In this embodiment, when the step S201 is executed to obtain the second training data, different texts in the same chapter can be used as a plurality of second training texts, that is, the second training data obtained by the step S201 is a chapter-level monolingual corpus.
The target model in the embodiment comprises a target coding module and a target decoding module, and the target model can be an mBART model; in the embodiment, when S202 is executed, the target model may be pre-trained by using a plurality of second training texts through an existing pre-training manner, for example, after the second training texts are masked, the target model is trained by using the result of the masking processing and the second training texts.
In this embodiment, after the pre-training of the target model is completed in S202, parameters of the target encoding module and parameters of the target decoding module in the pre-trained target model may be obtained, and then when the neural network model including the memory module, the encoding module and the decoding module is constructed in S203, the parameters of the encoding module and the decoding module in the neural network model are initialized using the obtained parameters, respectively.
Fig. 3 is a schematic diagram according to a third embodiment of the present disclosure. As shown in fig. 3, the translation method of this embodiment may specifically include the following steps:
s301, acquiring a chapter to be translated, and determining a text to be translated in the chapter to be translated and a text in the front of the text to be translated;
s302, aiming at each text to be translated, inputting the text to be translated and the preceding text of the text to be translated into a translation model, and obtaining a translation output result of the text to be translated according to an output result of the translation model;
s303, outputting a result according to the translation of each text to be translated to obtain a translation result of the chapter to be translated.
According to the translation method, the to-be-translated chapters are translated through the translation model obtained through pre-training, and the translation model can be used for translating the to-be-translated text by combining the continuously updated memory vector and the input fore information, so that the fore information is utilized to the maximum extent, and the accuracy of the obtained translation result is improved.
In this embodiment, when the S301 is executed to obtain the chapters to be translated, the document input by the user may be used as the chapters to be translated, or the document obtained from the network may be used as the chapters to be translated.
In this embodiment, when the S301 is executed to determine the text to be translated in the chapter to be translated, all sentences in the chapter to be translated may be taken as the text to be translated by taking the sentences as units; in the embodiment, when the S301 is executed to determine the preceding text of the text to be translated, a preset number of texts in the chapter to be translated before the text to be translated may be used as the preceding text, for example, 3 texts before the text to be translated are used as the preceding text of the text to be translated.
In this embodiment, when executing S302 to input, for each text to be translated, the text to be translated and the previous text of the text to be translated into a translation model, an optional implementation manner that can be adopted is as follows: inputting the initial symbol, the text to be translated and the preceding text of the text to be translated into the translation model, wherein the input initial symbol is used for a coding module in the translation model to obtain a first coding vector to be input into the memory module.
In this embodiment, when the S303 is executed to obtain the translation result of the chapter to be translated according to the translation output result of each text to be translated, the translation output results of the texts to be translated may be sequentially spliced according to the sequence of the texts to be translated in the chapter to be translated, so that the splicing result of the translation output results is used as the translation result of the chapter to be translated.
Fig. 4 is a schematic diagram according to a fourth embodiment of the present disclosure. FIG. 4 shows a translation flow diagram of the present embodiment: inputting the initial symbol, the text to be translated and the text in the front of the text to be translated into a decoding module to obtain a first encoding vector corresponding to the initial symbol, an encoding vector corresponding to the text to be translated and an encoding vector corresponding to the text in the front which are output by the decoding module; inputting the current memory vector and the first encoding vector into a memory module to obtain an updated memory vector output by the memory module and a second encoding vector used for inputting into a decoding module; and inputting the second decoding vector, the coding vector corresponding to the text to be translated and the coding vector corresponding to the text in the front as coding information into a decoding module to obtain a translation output result which is output by the decoding module and corresponds to the text to be translated.
Fig. 5 is a schematic diagram according to a fifth embodiment of the present disclosure. As shown in fig. 5, the training apparatus 500 for translation models according to the present embodiment includes:
the first obtaining unit 501 is configured to obtain first training data, where the first training data includes a plurality of first training texts, previous texts of the plurality of first training texts, and translation labeling results of the plurality of first training texts;
the building unit 502 is configured to build a neural network model including a memory module, an encoding module, and a decoding module, where the memory module is configured to output an updated memory vector and a second encoding vector for inputting to the decoding module according to a current memory vector and a first encoding vector obtained by the encoding module;
the training unit 503 is configured to train the neural network model using the multiple first training texts, the previous texts of the multiple first training texts, and the translation labeling results of the multiple first training texts, so as to obtain a translation model.
When acquiring the first training data, the first acquiring unit 501 may use different texts acquired from the same chapter as a plurality of first training texts, where each first training text is a text to be translated in a training process; the text in the front of each first training text is specifically the whole text or part of the text in the chapters before the first training text; the translation marking results of the plurality of first training texts are marked in advance, and the translation marking results of the first training texts are correct translation results of the first training texts.
In this embodiment, the first training text and the translation labeling result respectively correspond to different languages, that is, the first training data acquired by the first acquiring unit 501 is a chapter-level parallel corpus.
In addition, when the first obtaining unit 501 obtains the first training data, it may also obtain a plurality of first training texts from different chapters; in order to ensure the training accuracy of the neural network model, a plurality of first training texts belonging to the same chapter are required to complete one training process of the neural network model, and then a translation model is obtained through a plurality of training processes.
In this embodiment, after the first obtaining unit 501 obtains the first training data including the plurality of first training texts, the text of the preamble of the plurality of first training texts, and the translation labeling result of the plurality of first training texts, the constructing unit 502 constructs the neural network model including the memory module, the encoding module, and the decoding module.
In the neural network model constructed by the construction unit 502, the coding module is an encoder based on a transform structure, and the coding module is configured to output a coding vector corresponding to the first training text and a coding vector corresponding to the preceding text according to the input first training text and the preceding text of the first training text, respectively; in this embodiment, the encoding vector corresponding to the text is specifically a vector sequence formed by encoding results of word segmentation results in the text.
When obtaining the first coding vector according to the first training text and the text in the front of the first training text, the coding module in the construction unit 502 may splice the coding vector corresponding to the first training text and the coding vector corresponding to the text in the front, and use the spliced result as the first coding vector; the average value of the code vectors can be calculated according to the code vector corresponding to the first training text and the code vector corresponding to the preceding text, and the calculation result is used as the first code vector.
In order to avoid the problems of redundancy and text information loss of the first encoding vector and improve the accuracy of the obtained first encoding vector, when the encoding module in the constructing unit 502 obtains the first encoding vector, the optional implementation manner that can be adopted is as follows: respectively outputting an encoding vector corresponding to the initiator, an encoding vector corresponding to the first training text and an encoding vector corresponding to the preceding text of the first training text according to the input initiator, the first training text and the preceding text of the first training text; the code vector corresponding to the start symbol is taken as the first code vector.
In this embodiment, the start character used as the input of the encoding module is a special character indicating the start of input; the encoding module obtains the encoding vector corresponding to the start symbol according to the first training text and the text, and the encoding vector corresponding to the start symbol includes text information of the inputted text, so that the encoding vector corresponding to the start symbol is inputted to the memory module as the first encoding vector.
In this embodiment, the start symbol, the previous text (including different texts in the previous text) and the first training text may be separated by a separator, so that a translation output result corresponding to the first training text is determined in the output result of the decoding module according to the used separator.
In the Neural Network model constructed by the construction unit 502, a memory module may be implemented based on a Recurrent Neural Network (RNN), and the memory module is configured to output an updated memory vector and a second encoding vector for inputting to a decoding module according to a current memory vector and a first encoding vector obtained by an encoding module; the memory module uses the current memory vector to translate the current first training text, and outputs the updated memory vector to translate the next first training text.
That is to say, the memory module constructed by the construction unit 502 updates the currently used memory vector according to the currently input first training text and the preamble text of the first training text, so that the memory vector is continuously stored with the preamble information by updating the memory vector, thereby achieving the purpose of sufficiently utilizing the preamble information for translation, and improving the translation accuracy of the first training text.
It is understood that, in the present embodiment, when the first training text is translated, the memory vector used may be a preset vector, and the preset vector may be a zero vector.
In the neural network model constructed by the construction unit 502, the decoding module is a decoder based on the transform result, and the decoding module is configured to output a translation output result corresponding to the first training text according to the second decoding vector output by the memory module and the encoding vector corresponding to the first training text and the encoding vector corresponding to the preceding text output by the encoding module.
When the building unit 502 builds the neural network model including the memory module, the encoding module and the decoding module, the following method may also be adopted: acquiring second training data, wherein the acquired second training data comprises a plurality of second training texts; pre-training the target model by using a plurality of second training texts to obtain parameters of a target coding module and parameters of a target decoding module in the pre-trained target model; the method comprises the steps of constructing a neural network model comprising a memory module, an encoding module and a decoding module, initializing parameters of the encoding module in the neural network model by using parameters of a target encoding module, and initializing parameters of the decoding module in the neural network model by using parameters of the target decoding module.
When the building unit 502 obtains the second training data, different texts in the same chapter can be used as a plurality of second training texts, that is, the second training data obtained by the building unit 502 is a chapter-level monolingual corpus.
The target model in the embodiment comprises a target coding module and a target decoding module, and the target model can be an mBART model; the building unit 502 may pre-train the target model by using a plurality of second training texts through an existing pre-training manner, for example, after performing masking processing on the second training texts, the target model is trained by using a result of the masking processing and the second training texts.
In this embodiment, after the building unit 502 builds the neural network model including the memory module, the encoding module and the decoding module, the training unit 503 trains the neural network model using the plurality of first training texts, the translation labeling results of the preceding texts of the plurality of first training texts and the plurality of first training texts, so as to obtain the translation model.
After the obtained translation model is trained by the training unit 503 and the chapters to be translated are obtained, the texts to be translated in the chapters to be translated and the corresponding preceding texts thereof are sequentially used as the input of the translation model, and the translation results of the chapters to be translated can be obtained after the translation output results corresponding to each text to be translated and output by the translation model are obtained.
Specifically, when the training unit 503 trains the neural network model using the translation labeling result of the plurality of first training texts, the forward texts of the plurality of first training texts, and the plurality of first training texts to obtain the translation model, an optional implementation manner that can be adopted is as follows: for each first training text, taking the first training text and a preceding text of the first training text as the input of a coding module to obtain a first coding vector output by the coding module, a coding vector corresponding to the first training text and a coding vector corresponding to the preceding text; taking the current memory vector and the first encoding vector as the input of a memory module to obtain an updated memory vector and a second encoding vector output by the memory module; taking the second encoding vector, the encoding vector corresponding to the first training text and the encoding vector corresponding to the preceding text as the input of a decoding module to obtain a translation output result which is output by the decoding module and corresponds to the first training text; and calculating a loss function value by using the translation marking result and the translation output result of the first training text, and adjusting the parameters of the neural network model according to the calculated loss function value until the neural network model converges to obtain the translation model.
Fig. 6 is a schematic diagram according to a sixth embodiment of the present disclosure. As shown in fig. 6, the translation apparatus 600 of the present embodiment includes:
the second obtaining unit 601 is configured to obtain chapters to be translated, and determine texts to be translated in the chapters to be translated and preceding texts of the texts to be translated;
the translation unit 602 is configured to, for each text to be translated, input the text to be translated and a preceding text of the text to be translated into a translation model, and obtain a translation output result of the text to be translated according to an output result of the translation model;
the processing unit 603 is configured to output a result according to the translation of each text to be translated, so as to obtain a translation result of the chapter to be translated.
The second obtaining unit 601 may use a document input by a user as a chapter to be translated when obtaining the chapter to be translated, or use a document obtained from a network as the chapter to be translated.
When the second obtaining unit 601 determines the text to be translated in the chapter to be translated, all sentences in the chapter to be translated can be used as the text to be translated by taking the sentences as units; the second obtaining unit 601 may use a preset number of texts in the chapter to be translated before the text to be translated as the preceding text when determining the preceding text of the text to be translated.
When the translation unit 602 inputs, for each text to be translated, the text to be translated and the preceding text of the text to be translated into the translation model, the optional implementation manners that can be adopted are as follows: inputting the initial symbol, the text to be translated and the preceding text of the text to be translated into the translation model, wherein the input initial symbol is used for a coding module in the translation model to obtain a first coding vector to be input into the memory module.
When the processing unit 603 obtains the translation result of the chapter to be translated according to the translation output result of each text to be translated, the processing unit 603 may sequentially splice the translation output results of the texts to be translated according to the sequence of the texts to be translated in the chapter to be translated, so as to use the spliced result of the translation output results as the translation result of the chapter to be translated.
The present disclosure also provides an electronic device, a readable storage medium, and a computer program product according to embodiments of the present disclosure.
Fig. 7 is a block diagram of an electronic device for training and translating a translation model according to an embodiment of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 7, the device 700 comprises a computing unit 701, which may perform various suitable actions and processes according to a computer program stored in a Read Only Memory (ROM)702 or a computer program loaded from a storage unit 708 into a Random Access Memory (RAM) 703. In the RAM703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM702, and the RAM703 are connected to each other by a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
Various components in the device 700 are connected to the I/O interface 705, including: an input unit 706 such as a keyboard, a mouse, or the like; an output unit 707 such as various types of displays, speakers, and the like; a storage unit 708 such as a magnetic disk, optical disk, or the like; and a communication unit 709 such as a network card, modem, wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
Computing unit 701 may be a variety of general purpose and/or special purpose processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and so forth. The calculation unit 701 performs the respective methods and processes described above, such as the training and translation method of the translation model. For example, in some embodiments, the training and translation methods of the translation model may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as storage unit 708.
In some embodiments, part or all of a computer program may be loaded onto and/or installed onto device 700 via ROM702 and/or communications unit 709. When loaded into RAM703 and executed by the computing unit 701, may perform one or more steps of the training and translation methods of the translation model described above. Alternatively, in other embodiments, the computing unit 701 may be configured by any other suitable means (e.g., by means of firmware) to perform the training and translation method of the translation model.
Various implementations of the systems and techniques described here can be realized in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The Server can be a cloud Server, also called a cloud computing Server or a cloud host, and is a host product in a cloud computing service system, so as to solve the defects of high management difficulty and weak service expansibility in the traditional physical host and VPS service ("Virtual Private Server", or simply "VPS"). The server may also be a server of a distributed system, or a server incorporating a blockchain.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel or sequentially or in different orders, and are not limited herein as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.
- 上一篇:石墨接头机器人自动装卡簧、装栓机
- 下一篇:文本翻译方法、装置、电子设备及存储介质