A translation model training method, text translation method, device and equipment
By identifying and preprocessing the training samples that meet the conditions, replacing the human name with its target language translation results and marking it, the problem of human name translation errors in the machine translation model is solved, and the translation accuracy is improved.
Patent Information
- Application Number
- CN202210331091.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-30
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2042-03-30
AI Technical Summary
During the training process of existing machine translation models, due to the misalignment of data between the training samples and the label, the translation results of the person name are incorrect, affecting the translation accuracy.
By identifying and preprocessing target training samples that meet the predefined conditions in the training dataset, replacing the translation results of the corresponding target language of the person name and marking them, using these preprocessed samples to train the model, reducing learning difficulty and reducing ambiguity translation results .
It improves the accuracy of the translation model for the translation of person names, improves the overall translation accuracy, and ensures that the model learns the correct translation mode of person names.
Smart Images

Figure CN114818745B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine learning technology, and in particular to a translation model training method, a text translation method, a device and equipment. Background Art
[0002] In the field of machine translation, source sentences containing people's names need to be correctly translated into the target language. For example, if the source sentence is "Hong Yugang went to school" and the target language is English, the source sentence needs to be correctly translated into "Hong Yugang goto school", that is, translated into a translation result containing the correct person's name.
[0003] In the related art, a large number of source sentences containing people's names are used as training samples, and the translation results belonging to the target language corresponding to each training sample are used as the labels of the training samples. The training samples are used to train the translation model, so that the model can learn the translation results containing people's names based on the training samples and labels.
[0004] However, in the related art, since there may be misaligned data between some training samples and labels, learning these training samples will cause the model to learn incorrect name translation results. Summary of the invention
[0005] The purpose of the embodiments of the present invention is to provide a translation model training method, device and equipment to improve the translation accuracy of the translation model; in addition, the embodiments of the present invention also provide a text translation method to improve the accuracy of text translation. The specific technical solution is as follows:
[0006] In a first aspect, an embodiment of the present invention provides a method for training a translation model, the method comprising:
[0007] Obtaining a training data set for training a translation model; wherein the training data set includes a plurality of training samples, each of which has a specified label; the specified label of each training sample is a translation result of the target language corresponding to the training sample;
[0008] Identifying each target training sample in the training data set whose designated label meets a predetermined condition; wherein any designated label meets the predetermined condition includes that the designated label contains a complete translation result of a person's name in the corresponding training sample;
[0009] Performing a specified preprocessing on each of the target training samples to obtain each first training sample; wherein the specified preprocessing is used to replace a name in any target training sample with a translation result belonging to the target language and perform a specified marking;
[0010] Using the translation model to be trained, a plurality of samples to be used are translated to obtain an output result of each sample to be used; wherein the plurality of samples to be used include the first training samples;
[0011] Determine the model loss value based on the output result corresponding to each sample to be used and the specified label it has;
[0012] Based on the model loss value, determine whether the translation model converges. If converged, the training ends and a trained translation model is obtained. Otherwise, adjust the parameters of the translation model and return to execute the step of obtaining a training data set for training the translation model.
[0013] Optionally, the identifying each target training sample in the training data set whose designated label meets a predetermined condition includes:
[0014] For each training sample in the training data set, based on a pre-built name translation dictionary, a translation result corresponding to the name in the training sample is searched as the first name translation result of the training sample; wherein the name translation dictionary is a dictionary that records names in a source language and corresponding translation results in the target language, and the source language is the language to which each training sample belongs;
[0015] The translation result corresponding to the name in the designated label of the training sample is used as the second name translation result of the training sample;
[0016] If the translation result of the first name of the training sample is the same as the translation result of the second name of the training sample, the training sample is identified as a target training sample having a designated label that meets a predetermined condition.
[0017] Optionally, performing a specified preprocessing on each target training sample to obtain each first training sample includes:
[0018] For each target training sample, the name in the target training sample is replaced with a translation result corresponding to the name in the target training sample in a name translation dictionary, to obtain intermediate data including the name translation result; wherein the name translation dictionary is a dictionary recording names in a source language and corresponding translation results in the target language, and the source language is the language to which each training sample belongs;
[0019] The name translation results contained in the intermediate data are designated and marked to obtain a first training sample.
[0020] Optionally, the multiple samples to be used further include: second training samples; wherein each second training sample is other training samples in the training data set except for each target training sample.
[0021] In a second aspect, an embodiment of the present invention provides a text translation method, the method comprising:
[0022] Determining target data to be translated; wherein the target data is data to be translated into a target language;
[0023] Performing target preprocessing on the target data to obtain preprocessed target data; wherein the target preprocessing is used to replace the names in the target data with translation results belonging to the target language and perform designated markings;
[0024] The preprocessed target data is input into a pre-trained translation model to obtain a translation result corresponding to the target data; wherein the translation model is a model trained based on the training method of the above-mentioned translation model.
[0025] In a third aspect, an embodiment of the present invention provides a training device for a translation model, the device comprising:
[0026] An acquisition module is used to acquire a training data set for training a translation model; wherein the training data set includes a plurality of training samples, each of which has a specified label; the specified label of each training sample is a translation result of the target language corresponding to the training sample;
[0027] An identification module, configured to identify each target training sample in the training data set whose designated label meets a predetermined condition; wherein any designated label meets the predetermined condition includes that the designated label contains a complete translation result of a person's name in the training sample to which it belongs;
[0028] A processing module, configured to perform a specified preprocessing on each of the target training samples to obtain each first training sample; wherein the specified preprocessing is used to replace a name in any target training sample with a translation result belonging to the target language and perform a specified marking;
[0029] A first translation module, used to use the translation model to be trained to perform translation processing on a plurality of samples to be used, and obtain an output result of each sample to be used; wherein the plurality of samples to be used include the first training samples;
[0030] A first determination module is used to determine a model loss value based on an output result corresponding to each sample to be used and a designated label;
[0031] A judgment module is used to judge whether the translation model has converged based on the model loss value. If converged, the training is terminated to obtain a trained translation model; otherwise, the parameters of the translation model are adjusted and the step of obtaining a training data set for training the translation model is returned to execute.
[0032] Optionally, the identification module is specifically used to:
[0033] For each training sample in the training data set, based on a pre-built name translation dictionary, a translation result corresponding to the name in the training sample is searched as the first name translation result of the training sample; wherein the name translation dictionary is a dictionary that records names in a source language and corresponding translation results in the target language, and the source language is the language to which each training sample belongs;
[0034] The translation result corresponding to the name in the designated label of the training sample is used as the second name translation result of the training sample;
[0035] If the translation result of the first name of the training sample is the same as the translation result of the second name of the training sample, the training sample is identified as a target training sample having a designated label that meets a predetermined condition.
[0036] Optionally, the processing module includes:
[0037] a replacement submodule, for replacing the name in each target training sample with a translation result corresponding to the name in the target training sample in a name translation dictionary, to obtain intermediate data containing the name translation result; wherein the name translation dictionary is a dictionary recording names in a source language and corresponding translation results in the target language, the source language being the language to which each training sample belongs;
[0038] The marking submodule is used to specify a mark on the name translation result contained in the intermediate data to obtain a first training sample.
[0039] Optionally, the multiple samples to be used further include: second training samples; wherein each second training sample is other training samples in the training data set except for each target training sample.
[0040] In a fourth aspect, an embodiment of the present invention provides a text translation device, the device comprising:
[0041] A second determination module is used to determine target data to be translated; wherein the target data is data to be translated into a target language;
[0042] A preprocessing module, used for performing target preprocessing on the target data to obtain preprocessed target data; wherein the target preprocessing is used to replace the names in the target data with translation results belonging to the target language and perform designated markings;
[0043] The second translation module is used to input the preprocessed target data into a pre-trained translation model to obtain a translation result corresponding to the target data; wherein the translation model is a model trained based on the training method of the above-mentioned translation model.
[0044] In a fifth aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus;
[0045] Memory, used to store computer programs;
[0046] The processor is used to implement the steps of the above-mentioned translation model training method or the above-mentioned text translation method when executing the program stored in the memory.
[0047] In a sixth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned translation model training method or the steps of the above-mentioned text translation method are implemented.
[0048] Beneficial effects of the embodiments of the present invention:
[0049] In the training method of the translation model provided by the embodiment of the present invention, when training the translation model, the first training sample in the training data set whose designated label meets the predetermined conditions and has undergone designated preprocessing is learned. Since the first training sample that has undergone designated preprocessing has a clearly specified translation result of a person's name, the first training sample is used to train the translation model to be trained, which can reduce the learning difficulty of the model and reduce the occurrence of ambiguous translation results. Therefore, a translation model with more accurate translation of person's names can be trained. It can be seen that the translation accuracy of the translation model can be improved through the training method of the translation model provided by the embodiment of the present invention.
[0050] In addition, in the text translation method provided by the embodiment of the present invention, after determining the target data to be translated, the translation model pre-trained according to the model training method provided by the embodiment of the present invention is used to translate the target data to obtain the translation result corresponding to the target data. It can be seen that since the pre-trained translation model has a high translation accuracy, the text translation method provided by the embodiment of the present invention can improve the text translation accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.
[0052] Figure 1 A flowchart of a method for training a translation model provided by an embodiment of the present invention;
[0053] Figure 2 A flowchart of a text translation method provided by an embodiment of the present invention;
[0054] Figure 3 A flowchart of a specific example of a text translation method provided in an embodiment of the present invention;
[0055] Figure 4 A schematic diagram of the structure of a translation model training device provided by an embodiment of the present invention;
[0056] Figure 5 A structural schematic diagram of a text translation device provided by an embodiment of the present invention;
[0057] Figure 6 The present invention is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0058] The technical solutions in the embodiments of the present invention will be described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0059] In the field of machine translation, especially in the scenario of machine translation of lines, source sentences and lines containing names often need to be correctly translated into the target language. For example, if the source sentence is "Hong Yugang went to school" and the target language is English, the source sentence needs to be correctly translated into "Hong Yugang go to school", that is, translated into a translation result containing the correct name. At present, sample data is usually used to train the translation model so that the model can fit autonomously, so that the model can learn to recognize names and translate correctly.
[0060] In the related art, in the process of training a translation model using sample data, a large number of source sentences containing names are used as training samples, and the target language translation results corresponding to each training sample are obtained from the dialogue translation data set as the label of the training sample, and the translation model is trained using the training samples, so that the model can learn the translation results containing names based on the training samples and the labels. The dialogue translation data set can be a data set consisting of historical dialogues and their translation results.
[0061] However, in the related art, there may be misaligned data between some training samples and labels. For example, if the training sample is "Hong Yugang went to school", its corresponding label may be "Hong go to school", that is, the name in the label is abbreviated and translated, resulting in data misalignment between the training sample and its corresponding label. Learning these training samples will cause the model to learn the wrong name translation result, that is, the translation result corresponding to the name "Hong Yugang" is "Hong".
[0062] Based on the above content, in order to improve the translation accuracy of the translation model, the embodiments of the present disclosure provide a translation model training method, a text translation method, an apparatus and a device.
[0063] Below, a translation model training method provided by an embodiment of the present invention is first introduced.
[0064] The training method of a translation model provided in an embodiment of the present invention can be applied to an electronic device. In a specific application, the electronic device can be a server or a terminal device, which is reasonable. In a practical application, the terminal device can be a laptop computer, a desktop computer, etc.
[0065] Specifically, the execution subject of the training method of the translation model may be a training device of the translation model. Exemplarily, when the training method of the translation model is applied to a terminal device, the training device of the translation model may be functional software running in the terminal device, for example, software for model training. Exemplarily, when the training method of the translation model is applied to a server, the training device of the translation model may be a computer program running in the server, and the computer program may be used to train the translation model.
[0066] The training method of a translation model provided by an embodiment of the present invention may include the following steps:
[0067] Obtaining a training data set for training a translation model; wherein the training data set includes a plurality of training samples, each of which has a specified label; the specified label of each training sample is a translation result of the target language corresponding to the training sample;
[0068] Identifying each target training sample in the training data set whose designated label meets a predetermined condition; wherein any designated label meets the predetermined condition includes that the designated label contains a complete translation result of a person's name in the corresponding training sample;
[0069] Performing a specified preprocessing on each of the target training samples to obtain each first training sample; wherein the specified preprocessing is used to replace a name in any target training sample with a translation result belonging to the target language and perform a specified marking;
[0070] Using the translation model to be trained, a plurality of samples to be used are translated to obtain an output result of each sample to be used; wherein the plurality of samples to be used include the first training samples;
[0071] Determine the model loss value based on the output result corresponding to each sample to be used and the specified label it has;
[0072] Based on the model loss value, determine whether the translation model converges. If converged, the training ends and a trained translation model is obtained. Otherwise, adjust the parameters of the translation model and return to execute the step of obtaining a training data set for training the translation model.
[0073] In the solution provided by the embodiment of the present invention, when training the translation model, the first training sample in the training data set whose designated label meets the predetermined conditions and has undergone designated preprocessing is learned. Since the first training sample that has undergone designated preprocessing has a clearly specified translation result of a person's name, the first training sample is used to train the translation model to be trained, which can reduce the learning difficulty of the model and reduce the occurrence of ambiguous translation results. Therefore, a translation model with more accurate translation of person's names can be trained. It can be seen that the translation model training method provided by the embodiment of the present invention can improve the translation accuracy of the translation model.
[0074] The following describes the training method of the translation model provided by the embodiment of the present invention in conjunction with the accompanying drawings.
[0075] like Figure 1 As shown, the training method of the translation model provided in the embodiment of the present invention may include steps S101-S106:
[0076] S101, obtaining a training data set for training a translation model; wherein the training data set includes a plurality of training samples, each of which has a designated label; the designated label of each training sample is a translation result corresponding to the target language of the training sample;
[0077] In this embodiment, the training data set can be obtained from a pre-constructed dialogue translation data set, which can be a data set pre-constructed by relevant staff and composed of historical dialogue content and its corresponding translation results. The source language dialogue in the dialogue translation data set can be used as a training sample, and the translation result of the target language corresponding to the source language dialogue in the dialogue translation data set can be used as the designated label of the training sample. Exemplarily, in the translation scenario, the source language can be any language such as Chinese, English, Japanese, etc., and the target language can also be any language such as Chinese, English, Japanese, etc. It can be understood that training the translation model based on a large number of training samples and their designated labels can enable the model to learn the translation result of the target language corresponding to the source language dialogue, so that dialogue translation can be performed.
[0078] S102, identifying each target training sample in the training data set whose designated label meets a predetermined condition; wherein any designated label meets the predetermined condition includes that the designated label contains a complete translation result of a person's name in the corresponding training sample;
[0079] It is understandable that there is a data misalignment between each training sample in the training data set and its designated label, that is, the name translation result in the designated label of each training sample is the omitted name translation result, for example: the training sample is "Hong Yugang went to school", and the designated label of the training sample is "Hong go toschool". If the model learns this type of training sample, it will lead to the model learning the wrong name translation result, that is, translating "Hong Yugang" into "Hong".
[0080] Therefore, in this embodiment, in order to enable the model to learn the correct translation result of the name, each training sample in the training data set is identified, and the training sample whose designated label meets the predetermined conditions in each training sample is identified as the target training sample. That is, the training sample corresponding to the designated label containing the complete translation result of the name in the training sample is used as the target training sample. For example: if the training sample is "Hong Yugang went to eat", and its designated label is "Hong Yugang go to eat", then the training sample is used as the target training sample. It can be understood that the model can improve the accuracy of the model's translation of names by learning the target training samples.
[0081] Optionally, in one implementation, identifying each target training sample in the training data set whose designated label meets a predetermined condition may include steps A1-A3:
[0082] A1, for each training sample in the training data set, based on a pre-built name translation dictionary, searching for a translation result corresponding to the name in the training sample as the first name translation result of the training sample; wherein the name translation dictionary is a dictionary recording names in a source language and corresponding translation results in a target language, the source language being the language to which each training sample belongs;
[0083] In this implementation, the name translation dictionary may be a dictionary pre-built by relevant technical personnel that records names in the source language and their corresponding translation results in the target language. The translation result corresponding to the name in the training sample found through the name translation dictionary is the complete translation result corresponding to the name. By using the pre-built name translation dictionary, the translation result corresponding to the name in each training sample can be found from the name translation dictionary as the first name translation result of the training sample.
[0084] A2, taking the translation result corresponding to the name in the designated label of the training sample as the second name translation result of the training sample;
[0085] That is, for each training sample, the translation result corresponding to the name in the designated label possessed by the training sample is used as the second name translation result of the training sample.
[0086] A3: If the translation result of the first name of the training sample is the same as the translation result of the second name of the training sample, the training sample is identified as a target training sample having a designated label that meets a predetermined condition.
[0087] It can be understood that, since for each training sample, the first name translation result is the complete translation result for the name in the training sample found through the name translation dictionary, and the second name translation result is the translation result for the name in the training sample in the designated label of the training sample, by comparing the first name translation result with the second name translation result, it can be known whether the designated label of the training sample meets the predetermined conditions, that is, whether the translation result for the name in the training sample in the designated label of the training sample is the complete translation result for the name in the training sample, so that each target training sample can be determined from each training sample.
[0088] S103, performing a designated preprocessing on each target training sample to obtain each first training sample; wherein the designated preprocessing is used to replace a name in any target training sample with a translation result belonging to the target language and perform a designated mark;
[0089] In this embodiment, after each target training sample is identified in step S102, a first training sample is obtained by performing a designated preprocessing on each target training sample, that is, replacing the name in each target training sample with the translation result of the target language corresponding to the name and performing designated marking. The target training sample is designatedly marked, that is, the position of the replaced name is marked, so that the model can learn that the designated marked position is the correct translation result of the name. Exemplarily, the designated marking method can be: adding specific symbols, specific numbers, etc. before and after the position of the replaced name translation result.
[0090] It can be understood that by training the model using the first training samples, the model can learn that the specified mark is the correct translation result of the name, so that the model can learn the translation pattern of the name more accurately and stably, thereby further improving the accuracy of the model translation.
[0091] Optionally, in one implementation, performing a specified preprocessing on each target training sample to obtain each first training sample may include steps B1-B2:
[0092] B1, for each target training sample, replace the name in the target training sample with the translation result corresponding to the name in the target training sample in the name translation dictionary, and obtain intermediate data containing the name translation result; wherein the name translation dictionary is: a dictionary recording the names in the source language and the corresponding translation results in the target language, and the source language is the language to which each training sample belongs;
[0093] Exemplarily, in a specific implementation, in order to replace the names in each target training sample, the names in each target training sample can be first identified, so that the location of the identified name can be replaced with the translation result corresponding to the name in the target training sample in the name translation dictionary. Exemplarily, the method of identifying the names in the target training sample can be: using a pre-built name translation dictionary, identifying whether each target training sample has a name recorded in the name translation dictionary.
[0094] For example, if the target training sample is "Hong Yugang goes to school", its designated label is "HongYugang go to school", and the translation result corresponding to "Hong Yugang" recorded in the name translation dictionary is "Hong Yugang", then "Hong Yugang" in the target training sample is replaced with "Hong Yugang", and the intermediate data obtained is "HongYugang goes to school".
[0095] B2, assigning a mark to the name translation result contained in the intermediate data to obtain a first training sample.
[0096] After replacing the name in the target training sample with the correct translation result of the name, in order to make the model correctly recognize that the translation result at the replacement is the correct translation result of the name, the intermediate data can be marked, so that the model can learn through the specified mark that the marked place is the correct translation result of the name. Exemplarily, the way to specify the mark can be to add specified start and end symbols as identifiers, for example: add "<" as the start identifier symbol, and add ">" as the end identifier symbol. Exemplarily, if the intermediate data is "Hong Yugang went to school", after the intermediate data is marked, the first training sample obtained is "<Hong Yugang> Going to school."
[0097] It can be understood that after the name translation results contained in the intermediate data are designated and marked, since the first training sample obtained contains a clearly specified name translation result, the first training sample is subsequently used to train the translation model to be trained. The model can learn that the designated mark is the correct translation result of the name, and can learn to output the name translation result at the designated mark to the correct position, thereby reducing the learning difficulty of the model and reducing the occurrence of ambiguous translation results. Therefore, using each first training sample to train the model can further improve the accuracy of the model translation.
[0098] S104, using the translation model to be trained, performing translation processing on a plurality of samples to be used, and obtaining an output result of each sample to be used; wherein the plurality of samples to be used include the first training samples.
[0099] Among them, the translation model to be trained can be a recurrent neural network model, such as: seq2seq (Sequence to Sequence) model, LSTM (long-short term memory) model, etc. Of course, the translation model to be trained can also be other types of models, such as a convolutional neural network model. It should be noted that the embodiment of the present invention does not limit the type of the translation model to be trained.
[0100] It is understandable that in order to obtain a translation model with a certain translation accuracy, it is necessary to use multiple samples to be used to train the translation model to be trained. Exemplarily, in a specific implementation, using the translation model to be trained, translating multiple samples to be used, and obtaining the output result of each sample to be used, includes: inputting each sample to be used into the translation model to be trained, and obtaining the output result corresponding to each sample to be used.
[0101] It can be understood that, since the multiple samples to be used include the first training samples, the first training samples are samples in which the names of the target training samples are replaced and the designated labels are processed, and the designated labels of the first samples are the complete translation results of the names in the samples to which they belong. Therefore, by using the first training samples to train the translation model to be trained, the translation model can learn the correct name translation pattern based on the first training samples and the designated labels of the first training samples, that is, learn that the marked part in the first training sample is the correct name translation result. Exemplarily, based on the first training sample "<Hong Yugang> Go to school", and the first training sample has the specified label "Hong Yugang go to school", we can learn "<Hong Yugang> " and the pattern corresponding to "HongYugang", so that the name can be translated accurately.
[0102] S105, determining a model loss value based on the output result corresponding to each sample to be used and the designated label it has;
[0103] The model loss value is the difference between the specified label and the output result calculated by the loss function. It should be noted that the loss function can be a cross entropy loss function, an absolute value loss function, etc. This embodiment does not limit the specific type of the loss function.
[0104] S106, based on the model loss value, determine whether the translation model has converged. If converged, the training is completed and a trained translation model is obtained. Otherwise, the parameters of the translation model are adjusted and the step of obtaining a training data set for training the translation model is returned to be executed.
[0105] It is understandable that during the training of the translation model, a loss threshold can be preset. When the model loss value is less than the threshold, the model is considered to have converged, and the training is stopped at this time to obtain a trained translation model. Otherwise, the parameters of the translation model can be adjusted based on the model loss value, and the step of obtaining a training data set for training the translation model can be returned to continue training the model using the obtained training data set until a translation model that meets the requirements is trained.
[0106] In the solution provided by the embodiment of the present invention, when training the translation model, the first training sample in the training data set whose designated label meets the predetermined conditions and has undergone designated preprocessing is learned. Since the first training sample that has undergone designated preprocessing has a clearly specified translation result of a person's name, the first training sample is used to train the translation model to be trained, which can reduce the learning difficulty of the model and reduce the occurrence of ambiguous translation results. Therefore, a translation model with more accurate translation of person's names can be trained. It can be seen that the translation model training method provided by the embodiment of the present invention can improve the translation accuracy of the translation model.
[0107] Optionally, in another embodiment of the present invention, Figure 1 On the basis of the illustrated embodiment, the multiple samples to be used in the above step S104 further include: second training samples; wherein each second training sample is other training samples in the training data set except for each target training sample.
[0108] Accordingly, in one implementation, a translation model to be trained is used to perform translation processing on multiple samples to be used to obtain an output result of each sample to be used, including: inputting a first training sample and a second training sample into the translation model to be trained respectively to obtain an output result corresponding to each training sample.
[0109] It is understandable that, in addition to the target training samples, there are other samples in the training data set whose designated labels do not meet the predetermined conditions. The other samples are used as the second training samples. The second training samples are used to train the translation model, so that the model can learn other features besides the name. That is, for the multiple training samples in the training data set, they can be divided into target training samples whose designated labels meet the predetermined conditions, and second training samples whose designated labels do not meet the predetermined conditions. For the target training samples, it is necessary to perform a designated preprocessing on them to obtain the first training samples, so that the model can learn the correct name translation mode based on the first training samples; for the second samples, they are not processed, so that the model can learn other features besides the name based on the second training samples. Therefore, in the training process of the model, the translation model can also be trained based on the second training samples, so as to train a more accurate translation model.
[0110] For example, if the training sample is "Hong Yu just went to school", and its designated label is "Hong go to eat", since the designated label of the training sample does not meet the predetermined condition, that is, the translation result of the name in the designated label of the training sample is incomplete, the training sample is the second training sample. For the second training sample, no processing is required, so that the translation model will not learn the wrong translation mode of the name from the second training sample, thereby not affecting the translation model from the first training sample to learn the correct translation mode of the name.
[0111] It can be seen that, through this solution, the model can learn the correct translation mode based on the first training sample and the second training sample. Moreover, for the second training sample, since no specified preprocessing is performed on it, the translation model will not learn the wrong translation mode of the name, which will not affect the translation model from the first training sample to learn the correct translation mode of the name. Therefore, by using the first training sample and the second training sample to train the translation model, a more accurate translation model can be trained while ensuring the accuracy of the name translation.
[0112] After the translation model is trained using the solution provided in the above embodiment, Figure 2 As shown, the embodiment of the present invention further provides a text translation method, including steps S201-S203:
[0113] S201, determining target data to be translated; wherein the target data is data to be translated into a target language;
[0114] In this embodiment, in order to perform translation using the model trained by the above-mentioned translation model training method, firstly, target data to be translated may be determined, where the target data is a source language sentence to be translated into a target language.
[0115] S202, performing target preprocessing on the target data to obtain preprocessed target data; wherein the target preprocessing is used to replace the names in the target data with translation results belonging to the target language and perform designated markings;
[0116] It is understandable that after determining the target data to be translated, in order to use the above-mentioned trained translation model to translate the target data, the target data can be converted into a format that matches the input of the translation model, that is, the target data is converted into a format that matches the first training sample used in the training process of the translation model. Therefore, in this embodiment, the target data is subjected to target preprocessing to obtain preprocessed target data. It should be noted that the target preprocessing method is similar to the specified preprocessing method in the above-mentioned step S103, and will not be repeated here. In addition, it should be noted that if it is identified that there is no human name in a certain target data, the target preprocessing process ends, and the target data is the preprocessed target data.
[0117] S203, inputting the preprocessed target data into a pre-trained translation model to obtain a translation result corresponding to the target data; wherein the translation model is a model trained based on the training method of the above-mentioned translation model.
[0118] It can be understood that since the translation model is a model trained based on the training method of the above-mentioned translation model, it has learned the correct name translation pattern. After the target data to be translated is preprocessed in step S202, the preprocessed target data can be made to conform to the name translation format learned by the translation model. By using the translation model to translate the preprocessed target data, the position of the name can be accurately located, thereby identifying that the designated mark is the correct translation result of the name, thereby obtaining a more accurate translation result.
[0119] It can be seen that, through this solution, after determining the target data to be translated, the pre-trained translation model is used according to the model training method provided in the embodiment of the present invention to translate the pre-processed target data to obtain the translation result corresponding to the target data. It can be seen that, since the pre-trained translation model has a high translation accuracy, the text translation method provided in the embodiment of the present invention can improve the text translation accuracy.
[0120] In order to better understand the content of the embodiment of the present invention, a specific example is described below.
[0121] like Figure 3 As shown, a specific example of the present invention includes a model training phase and a model reasoning phase. The model training phase corresponds to the execution phase of the training method of the translation model mentioned above, and includes the following steps:
[0122] (1) Obtaining the original data for training the translation model (corresponding to the training data set mentioned above), and obtaining a pre-built name translation dictionary. The original data may be historical data in the line translation, including a large number of source language sentences and target language sentences corresponding to each source language sentence. The name translation dictionary records a large number of names in the source language and their corresponding translation results in the target language, for example: "(Hong Yugang)", "(Li Si)", etc.
[0123] (2) Identify the data in the original data that meets the predetermined conditions (corresponding to the target training samples mentioned above), and perform specified preprocessing on the source language sentences in the data that meets the predetermined conditions, that is, replace the names with the target language and perform specified markings. The data that meets the predetermined conditions is: the source language sentence contains a name and its corresponding target language sentence contains the complete translation result of the target language of the name. For example: the source language sentence is "Hong Yugang went to school", and its corresponding target language sentence is "Hong Yugang go to school", then the source language sentence is processed as "<Hong Yugang> Going to school."
[0124] In addition, data in the original data that does not meet the predetermined conditions (corresponding to the second training sample in the above text) will not be processed. For example, if the source language sentence is "Hong Yu just went to eat", and its corresponding target language sentence is "Hong go to eat", then the data will not be processed.
[0125] (3) Using the original data processed in step (2) to train the translation model, a trained translation model is obtained, wherein each source language sentence in the original data is used as sample data, and the target language sentence corresponding to each source language sentence is used as a designated label for the source language sentence.
[0126] In addition, the translation model can be a Seq2Seq model. It is known to those skilled in the art that the Seq2Seq model is a supervised encoding and decoding model that has been widely used in the field of text generation. The Seq2Seq model includes an encoder and a decoder part, which are connected by an intermediate state vector. The encoder converts a variable-length input sequence into a fixed-length vector, and the decoder decodes the fixed-length vector into a variable-length output sequence, which can be applied to text translation.
[0127] The model inference phase, corresponding to the application phase of the text translation method above, includes the following steps:
[0128] (1) Determine the data to be translated;
[0129] (2) Using a name translation dictionary, identify whether the data to be translated contains a name. If so, replace the name in the data to be translated and assign a designated mark to obtain input data. If not, the data to be translated is the input data. For example, if the data to be translated is "Li Si went to school", the data is processed as " Going to school."
[0130] (3) Input the input data into the translation model trained in the above model training phase to obtain the translation result with the correct name. For example, if the input data is " Go to school", you will get the correct translation result of "Li Si go to school".
[0131] It can be seen that through this solution, when the source language sentence used to train the model contains a person's name and the corresponding target language sentence contains the complete translation result of the person's name, the source language sentence is processed in a specified manner, so that the model can learn the correct translation mode of the person's name, thereby improving the translation accuracy of the sentence containing the person's name, thereby improving the user experience. And when the amount of data used to train the model is small, pseudo data containing the person's name can be added for training, so that the training effect of the model is better.
[0132] Based on the above method embodiment, the present invention also provides a translation model training device, such as Figure 4 As shown, the device comprises:
[0133] The acquisition module 410 is used to acquire a training data set for training a translation model; wherein the training data set includes a plurality of training samples, each of which has a specified label; the specified label of each training sample is a translation result of the target language corresponding to the training sample;
[0134] The identification module 420 is used to identify each target training sample in the training data set whose designated label meets the predetermined condition; wherein any designated label meets the predetermined condition includes that the designated label contains the complete translation result of the name in the training sample;
[0135] The processing module 430 is used to perform a specified preprocessing on each of the target training samples to obtain each first training sample; wherein the specified preprocessing is used to replace the name of a person in any target training sample with a translation result belonging to the target language and perform a specified mark;
[0136] A first translation module 440 is used to use the translation model to be trained to perform translation processing on a plurality of samples to be used, and obtain an output result of each sample to be used; wherein the plurality of samples to be used include the first training samples;
[0137] A first determination module 450 is used to determine a model loss value based on an output result corresponding to each sample to be used and a designated label;
[0138] The judgment module 460 is used to judge whether the translation model has converged based on the model loss value. If converged, the training is completed to obtain a trained translation model. Otherwise, the parameters of the translation model are adjusted and the step of obtaining a training data set for training the translation model is returned to execute.
[0139] Optionally, the identification module is specifically used to:
[0140] For each training sample in the training data set, based on a pre-built name translation dictionary, a translation result corresponding to the name in the training sample is searched as the first name translation result of the training sample; wherein the name translation dictionary is a dictionary that records names in a source language and corresponding translation results in the target language, and the source language is the language to which each training sample belongs;
[0141] The translation result corresponding to the name in the designated label of the training sample is used as the second name translation result of the training sample;
[0142] If the translation result of the first name of the training sample is the same as the translation result of the second name of the training sample, the training sample is identified as a target training sample having a designated label that meets a predetermined condition.
[0143] Optionally, the processing module includes:
[0144] a replacement submodule, for replacing the name in each target training sample with a translation result corresponding to the name in the target training sample in a name translation dictionary, to obtain intermediate data containing the name translation result; wherein the name translation dictionary is a dictionary recording names in a source language and corresponding translation results in the target language, the source language being the language to which each training sample belongs;
[0145] The marking submodule is used to specify a mark on the name translation result contained in the intermediate data to obtain a first training sample.
[0146] Optionally, the multiple samples to be used further include: second training samples; wherein each second training sample is other training samples in the training data set except for each target training sample.
[0147] Based on the above method embodiment, the present invention also provides a text translation device, such as Figure 5 As shown, the device comprises:
[0148] The second determination module 510 is used to determine target data to be translated; wherein the target data is data to be translated into a target language;
[0149] A preprocessing module 520 is used to perform target preprocessing on the target data to obtain preprocessed target data; wherein the target preprocessing is used to replace the names in the target data with translation results belonging to the target language and to perform designated markings;
[0150] The second translation module 530 is used to input the preprocessed target data into a pre-trained translation model to obtain a translation result corresponding to the target data; wherein the translation model is a model trained based on the training method of the above-mentioned translation model.
[0151] The embodiment of the present invention further provides an electronic device, such as Figure 6 As shown, it includes a processor 601, a communication interface 602, a memory 603 and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604.
[0152] Memory 603, used for storing computer programs;
[0153] The processor 601 is used to implement the steps of the translation model training method described in any of the above embodiments, or the steps of the text translation method described in the above embodiments when executing the program stored in the memory 603.
[0154] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0155] The communication interface is used for communication between the above terminal and other devices.
[0156] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0157] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0158] In another embodiment provided by the present invention, a computer-readable storage medium is also provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of the training method of the translation model described in any of the above embodiments, or the steps of the text translation method described in the above embodiments are implemented.
[0159] In another embodiment provided by the present invention, a computer program product comprising instructions is also provided, which, when executed on a computer, enables the computer to execute the steps of the training method for the translation model described in any one of the above embodiments, or the steps of the text translation method described in the above embodiments.
[0160] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0161] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0162] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0163] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A method for training a translation model, characterized in that: The method comprises: Obtaining a training data set for training a translation model; wherein the training data set includes a plurality of training samples, each of which has a specified label; the specified label of each training sample is a translation result of the target language corresponding to the training sample; Identifying each target training sample in the training data set whose designated label meets a predetermined condition; wherein any designated label meets the predetermined condition includes that the designated label contains a complete translation result of a person's name in the corresponding training sample; Performing a specified preprocessing on each of the target training samples to obtain each first training sample; wherein the specified preprocessing is used to replace a name in any target training sample with a translation result belonging to the target language and perform a specified marking; Using the translation model to be trained, a plurality of samples to be used are translated to obtain an output result of each sample to be used; wherein the plurality of samples to be used include the first training samples; Determine the model loss value based on the output result corresponding to each sample to be used and the specified label it has; Based on the model loss value, determine whether the translation model converges; if so, the training ends and a trained translation model is obtained; otherwise, adjust the parameters of the translation model and return to the step of obtaining a training data set for training the translation model; The identifying each target training sample in the training data set whose designated label meets a predetermined condition includes: For each training sample in the training data set, based on a pre-built name translation dictionary, a translation result corresponding to the name in the training sample is searched as the first name translation result of the training sample; wherein the name translation dictionary is a dictionary that records names in a source language and corresponding translation results in the target language, and the source language is the language to which each training sample belongs; The translation result corresponding to the name in the designated label of the training sample is used as the second name translation result of the training sample; If the translation result of the first name of the training sample is the same as the translation result of the second name of the training sample, the training sample is identified as a target training sample having a designated label that meets a predetermined condition.
2. The method according to claim 1, characterized in that: The step of performing a specified preprocessing on each target training sample to obtain each first training sample includes: For each target training sample, the name in the target training sample is replaced with a translation result corresponding to the name in the target training sample in a name translation dictionary, to obtain intermediate data including the name translation result; wherein the name translation dictionary is a dictionary recording names in a source language and corresponding translation results in the target language, and the source language is the language to which each training sample belongs; The name translation results contained in the intermediate data are designated and marked to obtain a first training sample.
3. The method according to any one of claims 1 to 2, characterized in that: The plurality of samples to be used further include: second training samples; wherein each second training sample is other training samples in the training data set except for the target training samples.
4. A text translation method, characterized in that: The method comprises: Determining target data to be translated; wherein the target data is data to be translated into a target language; Performing target preprocessing on the target data to obtain preprocessed target data; wherein the target preprocessing is used to replace the names in the target data with translation results belonging to the target language and perform designated markings; The preprocessed target data is input into a pre-trained translation model to obtain a translation result corresponding to the target data; wherein the translation model is a model trained based on the method according to any one of claims 1 to 3.
5. A translation model training device, characterized in that: The device comprises: An acquisition module is used to acquire a training data set for training a translation model; wherein the training data set includes a plurality of training samples, each of which has a specified label; the specified label of each training sample is a translation result of the target language corresponding to the training sample; An identification module, configured to identify each target training sample in the training data set whose designated label meets a predetermined condition; wherein any designated label meets the predetermined condition includes that the designated label contains a complete translation result of a person's name in the training sample to which it belongs; A processing module, configured to perform a specified preprocessing on each of the target training samples to obtain each first training sample; wherein the specified preprocessing is used to replace a name in any target training sample with a translation result belonging to the target language and perform a specified marking; A first translation module, used to use the translation model to be trained to perform translation processing on a plurality of samples to be used, and obtain an output result of each sample to be used; wherein the plurality of samples to be used include the first training samples; A first determination module is used to determine a model loss value based on an output result corresponding to each sample to be used and a designated label; A judgment module, used for judging whether the translation model has converged based on the model loss value, if converged, the training is terminated to obtain a trained translation model, otherwise, adjusting the parameters of the translation model and returning to execute the step of obtaining a training data set for training the translation model; The identification module is specifically used for: For each training sample in the training data set, based on a pre-built name translation dictionary, a translation result corresponding to the name in the training sample is searched as the first name translation result of the training sample; wherein the name translation dictionary is a dictionary that records names in a source language and corresponding translation results in the target language, and the source language is the language to which each training sample belongs; The translation result corresponding to the name in the designated label of the training sample is used as the second name translation result of the training sample; If the translation result of the first name of the training sample is the same as the translation result of the second name of the training sample, the training sample is identified as a target training sample having a designated label that meets a predetermined condition.
6. The device according to claim 5, characterized in that The processing module comprises: a replacement submodule, for replacing the name in each target training sample with a translation result corresponding to the name in the target training sample in a name translation dictionary, to obtain intermediate data containing the name translation result; wherein the name translation dictionary is a dictionary recording names in a source language and corresponding translation results in the target language, the source language being the language to which each training sample belongs; The marking submodule is used to specify a mark on the name translation result contained in the intermediate data to obtain a first training sample.
7. The device according to any one of claims 5 to 6, characterized in that: The plurality of samples to be used further include: second training samples; wherein each second training sample is other training samples in the training data set except for the target training samples.
8. A text translation device, characterized in that: The device comprises: A second determination module is used to determine target data to be translated; wherein the target data is data to be translated into a target language; A preprocessing module, used for performing target preprocessing on the target data to obtain preprocessed target data; wherein the target preprocessing is used to replace the names in the target data with translation results belonging to the target language and perform designated markings; The second translation module is used to input the preprocessed target data into a pre-trained translation model to obtain a translation result corresponding to the target data; wherein the translation model is a model trained based on the method described in any one of claims 1-3.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; The processor is used to implement the steps of the translation model training method described in any one of claims 1 to 3, or the steps of the text translation method described in claim 4 when executing the program stored in the memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the training method of the translation model described in any one of claims 1 to 3, or the steps of the text translation method described in claim 4 are implemented.
