Model training method, device, electronic device and storage medium
By cleaning and training corpus pairs, the translation accuracy of the network model is improved, the over-translation problem during translation is solved, and more efficient translation result coverage and accuracy are achieved.
Patent Information
- Application Number
- CN202110592495.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-28
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-05-28
AI Technical Summary
Existing network models are prone to over-translation problems during translation, resulting in low translation accuracy and inability to effectively cover all characters in the source text.
By obtaining and cleaning corpus pairs, training samples to build models and target translation models, using the two-way translation process to improve model accuracy, including identifying and removing garbled characters, abnormal corpus and semantically missing texts, and evaluating model accuracy through test texts to adjust the training process .
It reduces the probability of mis-translation or over-translation of the model, improves the accuracy and training effect of translation, and ensures the integrity and accuracy of the translation results.
Smart Images

Figure CN113204979B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a model training method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of artificial intelligence, the application of network models is becoming increasingly widespread. During translation, network models can be used to translate source text in a source language into target text in a target language. However, network models can suffer from over-translation, resulting in repeated appearance of incorrect character strings in the translated target text. Given the limited length of target text, this can easily lead to the target text being filled with incorrect character strings, failing to cover all characters in the source text and resulting in poor translation accuracy.
[0003] For example, assuming that the source text in English is "A's remote control, the mouse always has an offset of about 150px, which makes operation very difficult";
[0004] Translate the above source text into English target text. The correct translation result should be "A's remote control, the mouse always has a displacement of about 150px, the operation is very difficult";
[0005] If there is an over-translation problem, the translation result may be "A remote control, the mouse always has a bit of a bit of a bit of a bit of a bit of a bit of a bit of a bit of a bit of a bit".
[0006] In related technologies, in order to solve the above-mentioned over-translation problem, the source text is usually input into a network model to obtain multiple candidate texts translated by the network model, and the coverage rate of each candidate text for each character in the source text is determined. Based on the above coverage rate, each candidate text is scored, and the candidate text with the highest score is used as the final translation result.
[0007] In the above solution, due to the defects of the network model itself, even the candidate results with the highest scores may have over-translation problems, resulting in low accuracy of the final translation results. Summary of the Invention
[0008] The purpose of the embodiments of the present application is to provide a model training method, device, electronic device, and storage medium to improve the accuracy of model translation. The specific technical solutions are as follows:
[0009] In a first aspect, an embodiment of the present application provides a model training method, the method comprising:
[0010] Obtaining a first corpus pair, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text;
[0011] Using the first corpus to construct a model for training samples, wherein the sample construction model is used to: translate the text in the target language into the text in the source language;
[0012] Obtaining a second target text in the target language, and translating the second target text using the sample-based model to obtain a second source text;
[0013] A target translation model is trained using a second corpus pair, wherein the second corpus pair includes: the second source text and a second target text, and the target translation model is used to translate the text in the source language into the text in the target language.
[0014] In one embodiment of the present application, the training of the target translation model using the second corpus includes:
[0015] The target translation model is trained using the first corpus pair and the second corpus pair.
[0016] In one embodiment of the present application, obtaining the first corpus pair includes:
[0017] Obtaining a candidate corpus pair including the first source text and the first target text;
[0018] The candidate corpus pair is cleaned to obtain a first corpus pair.
[0019] In one embodiment of the present application, cleaning the candidate corpus pair to obtain the first corpus pair includes:
[0020] Identifying a garbled corpus pair containing garbled characters in the candidate corpus pairs, removing the garbled corpus pair from the candidate corpus pairs, and obtaining a first corpus pair; and / or
[0021] An abnormal corpus pair whose length ratio is less than a first preset ratio or greater than a second preset ratio is searched for in the candidate corpus pairs, and the abnormal corpus pair is removed from the candidate corpus pairs to obtain a first corpus pair, wherein the first ratio is: a ratio of the length of the first source text to the length of the first target text, and the second preset ratio is greater than the first preset ratio.
[0022] In one embodiment of the present application, obtaining the second target text in the target language includes:
[0023] obtaining candidate texts in the target language;
[0024] The candidate text is cleaned to obtain a second target text.
[0025] In one embodiment of the present application, the step of cleaning the candidate text to obtain the second target text includes:
[0026] Searching for texts in the candidate texts whose lengths are within a preset length range as the second target texts; and / or
[0027] Searching for incomplete texts in the candidate texts that do not end with a preset ending identifier, removing the incomplete texts from the candidate texts to obtain a second target text; and / or
[0028] The semantic information of each candidate text is identified, semantically missing texts in the candidate texts are determined based on the identified semantic information, and the semantically missing texts are removed from the candidate texts to obtain a second target text.
[0029] In one embodiment of the present application, after the step of training the target translation model using the second corpus, the method further includes:
[0030] obtaining a test text in the source language;
[0031] Inputting the test text into the trained target translation model, and translating the test text using the target translation model to obtain a model output text;
[0032] Whether the translation result of the target translation model is accurate is determined based on the model output text. If the translation result of the target translation model is inaccurate, the process returns to the step of constructing a model for the training sample using the first corpus.
[0033] In one embodiment of the present application, judging whether the translation result of the target translation model is accurate based on the model output text includes:
[0034] Calculating an accuracy index of the target translation model based on the model output text, wherein the accuracy index includes: a Bleu index and / or a perplexity;
[0035] The accuracy index is used to determine whether the translation result of the target translation model is accurate.
[0036] In a second aspect, an embodiment of the present application provides a model training device, the device comprising:
[0037] A first corpus pair obtaining module, configured to obtain a first corpus pair, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text;
[0038] A first model training module is configured to construct a model for training samples using the first corpus, wherein the sample-based model is configured to translate the target language text into the source language text;
[0039] a target text obtaining module, configured to obtain a second target text in the target language, and translate the second target text using the sample-built model to obtain a second source text;
[0040] The second model training module is used to train a target translation model using a second corpus pair, wherein the second corpus pair includes: the second source text and a second target text, and the target translation model is used to translate the text in the source language into the text in the target language.
[0041] In one embodiment of the present application, the second model training module is specifically used to:
[0042] The target translation model is trained using the first corpus pair and the second corpus pair.
[0043] In one embodiment of the present application, the first corpus pair obtaining module includes:
[0044] a candidate corpus pair obtaining unit, configured to obtain a candidate corpus pair comprising the first source text and the first target text;
[0045] The first corpus pair obtaining unit is configured to clean the candidate corpus pair to obtain a first corpus pair.
[0046] In one embodiment of the present application, the first corpus pair obtaining unit is specifically configured to:
[0047] Identifying a garbled corpus pair containing garbled characters in the candidate corpus pairs, removing the garbled corpus pair from the candidate corpus pairs, and obtaining a first corpus pair; and / or
[0048] An abnormal corpus pair whose length ratio is less than a first preset ratio or greater than a second preset ratio is searched for in the candidate corpus pairs, and the abnormal corpus pair is removed from the candidate corpus pairs to obtain a first corpus pair, wherein the first ratio is: a ratio of the length of the first source text to the length of the first target text, and the second preset ratio is greater than the first preset ratio.
[0049] In one embodiment of the present application, the target text obtaining module includes:
[0050] a candidate text obtaining unit, configured to obtain candidate texts in the target language;
[0051] The target text obtaining unit is used to clean the candidate text to obtain a second target text.
[0052] In one embodiment of the present application, the target text obtaining unit is specifically configured to:
[0053] Searching for texts in the candidate texts whose lengths are within a preset length range as the second target texts; and / or
[0054] Searching for incomplete texts in the candidate texts that do not end with a preset ending identifier, removing the incomplete texts from the candidate texts to obtain a second target text; and / or
[0055] The semantic information of each candidate text is identified, semantically missing texts in the candidate texts are determined based on the identified semantic information, and the semantically missing texts are removed from the candidate texts to obtain a second target text.
[0056] In one embodiment of the present application, the device further comprises:
[0057] a test text obtaining module, configured to obtain a test text in the source language after training the target translation model using the second corpus;
[0058] An output text obtaining module, configured to input the test text into a trained target translation model, and translate the test text using the target translation model to obtain a model output text;
[0059] The third model training module is used to determine whether the translation result of the target translation model is accurate based on the model output text, and trigger the first model training module when the translation result of the target translation model is inaccurate.
[0060] In one embodiment of the present application, the third model training module is specifically used to:
[0061] Calculating an accuracy index of the target translation model based on the model output text, wherein the accuracy index includes: a Bleu index and / or a perplexity;
[0062] The accuracy index is used to determine whether the translation result of the target translation model is accurate. If the translation result of the target translation model is inaccurate, the first model training module is triggered.
[0063] In a third aspect, an embodiment of the present application 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 via the communication bus;
[0064] Memory for storing computer programs;
[0065] The processor is configured to implement any of the method steps described in the first aspect when executing a program stored in the memory.
[0066] In a fourth aspect, an embodiment of the present application 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, any of the method steps described in the first aspect is implemented.
[0067] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described model training methods.
[0068] Beneficial effects of the embodiments of the present application:
[0069] In the model training scheme provided by the embodiment of the present application, a first corpus pair can be obtained, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text; a model is constructed by training samples using the first corpus pair, wherein the sample construction model is used to: translate the text in the target language into the text in the source language; a second target text in the target language is obtained, and the second target text is translated using the sample construction model to obtain a second source text; a target translation model is trained using the second corpus pair, wherein the second corpus pair includes: a second source text and a second target text, and the target translation model is used to: translate the text in the source language into the text in the target language. Since the second target text is a monolingual corpus, it is easy to obtain a large amount of second target text, and then use the sample construction model obtained by training to obtain a second source text corresponding to the second target text, thereby obtaining a large amount of second corpus pairs including the second source text and the second target text, and then use the above-mentioned large amount of second corpus pairs as samples to train the target translation model, which can improve the training effect of the model. It can be seen that the application of the scheme provided by the embodiment of the present application can reduce the probability of mistranslation or overtranslation of the trained model and improve the accuracy of the model translation. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0071] Figure 1 Schematic flowchart of a model training method provided by an embodiment of the present application;
[0072] Figure 2 Schematic flowchart of another model training method provided by an embodiment of the present application;
[0073] Figure 3 Schematic flowchart of yet another model training method provided by an embodiment of the present application;
[0074] Figure 4 Schematic structural diagram of a model training device provided by an embodiment of the present application;
[0075] Figure 5 Schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0076] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art based on the present application belong to the scope protected by the present application.
[0077] To improve the accuracy of model training, embodiments of the present application provide a model training method, device, electronic device, and storage medium, which will be introduced in detail below.
[0078] See Figure 1 , Figure 1 Schematic flowchart of a model training method provided by an embodiment of the present application. This method can be applied to electronic devices such as desktop computers, laptop computers, and tablet computers. The above model training method may include the following steps S101 - S104:
[0079] S101, obtain a first corpus pair.
[0080] Among them, the first corpus pair includes: the first source text in the source language, and the first target text in the target language corresponding to the first source text.
[0081] The above source language may be Chinese, English, French, Spanish, Portuguese, etc. The above first source text is: the text expressed in the above source language. For example, assuming the above source language is Chinese, the first source text may be "Before my bed a pool of light"; assuming the above source language is French, the first source text may be "Secoucher ".
[0082] The target language is a language different from the source language, and can be Chinese, English, Japanese, Russian, Korean, etc. The first target text is a text that uses the target language to express the first source text. It can be understood that the first target text can be a text obtained by translating the first source text into the target language; similarly, the first source text can be a text obtained by translating the first target text into the source language. For example, assuming that the source text is "How are you?" and the target language is English, the first target text can be "How do you do"; assuming that the source text is "Be careful on the way" and the target language is Korean, the first target text can be
[0083] In one embodiment of the present application, when obtaining the first corpus pair, the first corpus pair can be crawled from an open corpus pair platform.
[0084] In addition, a first source text may be obtained from an open text platform, and the first source text may be translated into a first target text in a target language, thereby obtaining a first corpus pair;
[0085] Alternatively, a first target text is obtained from an open text platform, and the first target text is translated into a first source text in a source language, thereby obtaining a first corpus pair.
[0086] Alternatively, the first corpus pair can be obtained from source-target language bilingual translation platforms for novels, journals, news, and other sources. For example, if the source language is English and the target language is Chinese, the first corpus can be obtained from bilingual Chinese-English novels.
[0087] S102: Build a model for training samples using the first corpus.
[0088] The sample model is used to translate text in a target language into text in a source language. This model is a language translation model, such as a Seq2Seq translation model based on the TensorFlow framework or an NMT translation model based on the Apache MXNet framework.
[0089] Specifically, when training the above-mentioned sample construction model, the first corpus pair can be used as a sample, and the first target text in the first corpus pair can be input into the sample construction model to be trained to obtain the output result, and then the loss of the output result relative to the first source text is calculated. The loss is used to adjust the parameters of the above-mentioned sample construction model to achieve one-time training of the model.
[0090] In one embodiment of the present application, after the number of training times for the sample construction model reaches a preset number threshold, the model training is considered complete, and a trained sample construction model is obtained. The number threshold may be 100,000 times, 200,000 times, 5,000,000 times, etc.
[0091] In addition, when the loss of the output result of the above-mentioned sample construction model relative to the first source text is lower than a preset loss threshold, the model accuracy is considered to have met the requirements, and the model training is considered to be completed, and the trained sample construction model is obtained.
[0092] S103: Obtain a second target text in the target language, and translate the second target text using the sample-based model to obtain a second source text.
[0093] Specifically, a text in the target language can be obtained as the second target text. Since the second target text is a monolingual corpus, it is easier to obtain than a bilingual corpus, making it easier to obtain a large number of second target texts. For each second target text, the sample construction model trained in S102 can be used to translate the second target text, and the source language text corresponding to the second target text output by the model can be obtained as the second source text. The second target text and the second source text output by the sample construction model can subsequently be used as samples to train the target translation model to be trained.
[0094] In one embodiment of the present application, when obtaining the second target text, the second target text can be obtained from an open corpus platform such as novels, journals, magazines, news, etc. in the target language, and the embodiment of the present application is not limited to this.
[0095] S104: Using the second corpus to train the target translation model.
[0096] The second corpus pair includes a second source text and a second target text. Since the second source text in the second corpus pair is a text obtained by translating the second target text, there is a corresponding relationship between the second source text and the second target text.
[0097] The target translation model is used to translate text from a source language into a target language. It is also a language translation model, such as a Seq2Seq translation model based on the TensorFlow framework or an NMT translation model based on the Apache MXNet framework.
[0098] Specifically, when training the above-mentioned target translation model, the second corpus pair can be used as a sample, and the second source text in the second corpus pair can be input into the target translation model to be trained to obtain an output result. Then, the loss of the output result relative to the second target text corresponding to the above-mentioned second source text is calculated, and the parameters of the above-mentioned target translation model are adjusted using the loss to achieve one-time training of the model.
[0099] In one embodiment of the present application, after the target translation model is trained a certain number of times, the model training is considered complete, and the trained target translation model is obtained. The above-mentioned number of times threshold can be 50,000 times, 100,000 times, 2,000,000 times, etc.
[0100] In addition, when the loss of the output result of the above-mentioned target translation model relative to the second target text is lower than a preset loss threshold, the model accuracy is considered to have met the requirements, and the model training is considered to be completed, and the trained target translation model is obtained.
[0101] In one embodiment of the present application, when training a target translation model, the target translation model may be trained using a first corpus pair and a second corpus pair.
[0102] Specifically, the first and second corpus pairs can be mixed to produce a mixed corpus pair, which includes: a first source text and a first target text corresponding to the first source text, and a second source text and a second target text corresponding to the second source text. It should be noted that the correspondence between the first source text and the first target text in the mixed corpus pair remains unchanged, and similarly, the correspondence between the second source text and the second target text remains unchanged.
[0103] In this way, when training the target translation model, the mixed corpus pair can be used as a sample, and the first source text and the second source text in the mixed corpus pair can be input into the target translation model to be trained to obtain the output result. Then, the loss of the output result relative to the target text corresponding to the above-mentioned input source text is calculated, and the parameters of the above-mentioned target translation model are adjusted using this loss to achieve one-time training of the model.
[0104] In this way, the number of training samples used is greater, and since the first corpus pair is a directly obtained, paired corpus, the accuracy of the first corpus pair is usually higher, so the accuracy of the target translation model trained based on the above first and second corpus pairs is also higher.
[0105] In the model training scheme provided by the above embodiment, a first corpus pair can be obtained, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text; a model is constructed using training samples from the first corpus pair, wherein the sample-constructed model is used to translate the text in the target language into the text in the source language; a second target text in the target language is obtained, and the sample-constructed model is used to translate the second target text to obtain a second source text; and a target translation model is trained using a second corpus pair, wherein the second corpus pair includes: a second source text and a second target text, and the target translation model is used to translate the text in the source language into the text in the target language. Because the second target text is a monolingual corpus and is widely available, it is easy to obtain a large number of second target texts. Then, the training samples are used to construct a model to obtain a second source text corresponding to the second target text, thereby obtaining a large number of second corpus pairs including the second source text and the second target text. The target translation model is then trained using the large number of second corpus pairs as samples, which can improve the training effect of the model. Therefore, it can be seen that the application of the scheme provided by the above embodiment can reduce the probability of mistranslation or overtranslation in the trained model and improve the accuracy of the model translation.
[0106] In one embodiment of the present application, when obtaining the first corpus pair in S101 above, a candidate corpus pair including a first source text and a first target text may be obtained; and the candidate corpus pair may be cleaned to obtain the first corpus pair.
[0107] Specifically, an initial corpus pair including a first source text and a first target text can be first obtained as a candidate corpus pair, and then the candidate corpus pair is cleaned to obtain the cleaned candidate corpus pair as the first corpus pair ultimately used for model training.
[0108] In one embodiment of the present application, when cleaning candidate corpus pairs, one or more of the following cleaning methods may be used, which are described below:
[0109] Method 1: Identify the garbled corpus pairs containing garbled characters in the candidate corpus pairs, remove the garbled corpus pairs from the candidate corpus pairs, and obtain the first corpus pair.
[0110] The garbled characters may be pre-set characters that affect text expression, such as #, &, *, @, etc.
[0111] Specifically, for each candidate corpus pair, each character in the candidate corpus pair can be detected to determine whether there is garbled code in the candidate corpus pair. If so, the corpus pair is treated as a garbled code corpus pair, and finally the identified garbled code corpus pair is removed from each candidate corpus pair.
[0112] Method 2: Search for abnormal corpus pairs whose length ratio is less than a first preset ratio or greater than a second preset ratio in the candidate corpus pairs, remove the abnormal corpus pairs from the candidate corpus pairs, and obtain the first corpus pair.
[0113] The first ratio is the ratio of the length of the first source text to the length of the first target text, and the second preset ratio is greater than the first preset ratio. The first preset ratio can be 0.3, 0.5, 0.2, etc., and the second preset ratio can be 2, 3, 4, etc., which are not limited in this embodiment of the present application.
[0114] The length of each text can be understood as the number of characters in the text.
[0115] Specifically, for each candidate corpus pair, the number of characters in the first source text in the corpus pair may be obtained as a first length, and the number of characters in the first target text in the corpus pair may be obtained as a second length, and then a ratio of the first length to the second length may be calculated;
[0116] It can be determined whether the ratio is less than a first preset ratio. If so, it indicates that the length of the first source text is much smaller than the length of the first target text, which further indicates that the content expressed in the first source text and the content expressed in the first target text may be different and not completely corresponding. Therefore, the corpus pair can be regarded as an abnormal corpus pair.
[0117] In addition, it is also possible to determine whether the above ratio is greater than a second preset ratio. If so, it means that the length of the first source text is much greater than the length of the first target text, which further indicates that the content expressed in the first source text and the content expressed in the first target text may not be the same, and the two are not completely corresponding. Therefore, this corpus pair can be regarded as an abnormal corpus pair.
[0118] Finally, the abnormal corpus pair found can be removed from the candidate corpus pairs to obtain the first corpus pair.
[0119] In addition, the ratio of the length of the first target text to the length of the first source text can also be calculated, and the ratio can be used to determine whether the candidate corpus pair is an abnormal corpus pair. The determination method is similar to the above method 2 and will not be repeated here.
[0120] In one embodiment of the present application, an abnormal corpus pair among the candidate corpus pairs may be searched for a length difference greater than a preset difference, and the abnormal corpus pair may be removed from the candidate corpus pairs to obtain a first corpus pair. The length difference may be the absolute value of the difference between the length of the first source text and the length of the first target text. The preset difference may be 5, 8, 10, etc., and is not limited to this in the present embodiment.
[0121] In addition to the above cleaning method, a corpus pair in which the length of the first source text is within a first preset length range and the length of the first target text is within a second preset length range may be searched from the candidate corpus pairs as the first corpus pair.
[0122] Among them, the above-mentioned first preset length range can be 15-25, 20-30, 5-18, etc., and the second preset length range can be 5-25, 3-28, 4-17, etc. The above-mentioned first preset length range and the second preset length range can be equal or different, and the embodiment of the present application is not limited to this. Specifically, the above-mentioned first preset length range and the second preset length range can be determined according to the scale of the model to be trained, the application scenario, etc.
[0123] In the above scheme, the cleaned corpus pair can be used as the first corpus pair, so that the accuracy of the obtained first corpus pair is higher, and the accuracy of the sample construction model obtained by training is also higher, which can further improve the accuracy of the target translation model obtained by subsequent training.
[0124] In one embodiment of the present application, in the above S103 , when obtaining the second target text, candidate texts in the target language may be obtained; and the candidate texts may be cleaned to obtain the second target text.
[0125] Specifically, we can first obtain an initial text expressed in the target language as a candidate text, and then perform corpus cleaning on the candidate text to obtain the cleaned candidate text as the second target text for the final model training.
[0126] In one embodiment of the present application, when cleaning candidate texts, one or more of the following cleaning methods may be used, which are described below:
[0127] Method three: search for texts in the candidate texts whose length is within a preset length range and use them as the second target texts.
[0128] Among them, the above-mentioned preset length range can be 10-25, 2-30, 3-18, etc., and the embodiments of the present application are not limited to this.
[0129] Specifically, the number of characters in each candidate text can be determined as the length of the candidate text, and whether the length is within a preset length range can be judged. If so, the candidate text is used as the second target text, otherwise the candidate text is not used as the second target text.
[0130] Method 4: searching for incomplete texts in the candidate texts that do not end with a preset end identifier, removing the incomplete texts from the candidate texts, and obtaining a second target text.
[0131] The above-mentioned ending identifier can be ".", "!", "?", ".", etc.
[0132] Specifically, in a complete text, the characters at the end are usually the end identifiers. If the characters at the end of the text are not the above end identifiers, the text can be considered incomplete. In view of this, for each candidate text, it can be determined whether the ending characters of the candidate text are the above end identifiers. If not, the text can be determined as incomplete. Then, when cleaning the candidate text, the found incomplete text can be removed from the candidate text to obtain the second target text.
[0133] Method five is to identify the semantic information of each candidate text, determine the semantically missing texts in the candidate texts based on the identified semantic information, remove the semantically missing texts from the candidate texts, and obtain a second target text.
[0134] Specifically, for each candidate text, the text's speech information can be obtained. Based on the semantic information, it can be determined whether the candidate text is semantically missing, such as missing a subject or object. If so, the text can be determined as a semantically missing text. In this way, when performing corpus cleaning, the semantically missing text can be removed from the candidate text to obtain the second target text.
[0135] Here, a semantic extraction algorithm may be used to extract semantic information of each candidate text, and then based on the extracted information, it is determined whether each candidate text is a semantically missing text.
[0136] In addition to the above cleaning methods, when cleaning the candidate text, garbled texts containing garbled characters may be identified in the candidate texts, and the garbled texts may be removed from the candidate texts to obtain a second target text.
[0137] In the above solution, the cleaned candidate text can be used as the second target text, so that the obtained second target text has higher accuracy, thereby improving the accuracy of the target translation model obtained by subsequent training.
[0138] See also Figure 2 , Figure 2 A flow chart of another model training method provided in an embodiment of the present application is shown as follows: Figure 2 As shown, after the step S104 of training the target translation model using the second corpus, the model training method may further include the following steps S105-S107:
[0139] S105: Obtain a test text in the source language.
[0140] The test text is a text expressed in the source language.
[0141] In one embodiment of the present application, the above-mentioned test text can be a text in the source language obtained from an open corpus platform, or it can be a text selected from the first source text in the first corpus pair, or it can be a text selected from the second source text, etc. The embodiment of the present application is not limited to this.
[0142] S106: Input the test text into the trained target translation model, and use the target translation model to translate the test text to obtain a model output text.
[0143] Specifically, the test text may be input into a trained target translation model, and the model may be used to translate the test text in the source language into a text in the target language to obtain a model output text.
[0144] S107, judging whether the translation result of the target translation model is accurate according to the model output text. If the translation result of the target translation model is inaccurate, return to S102 and construct a model for the training sample using the first corpus.
[0145] Specifically, based on the model output text output by the model in S106 above, it can be determined whether the translation result obtained by the target translation model when translating the input text is accurate. If it is determined to be inaccurate, it indicates that the accuracy of the model is low and further training of the model is required. In this case, in order to improve the accuracy of the model, the process can return to step S102 above and first train the sample construction model again to improve the accuracy of the sample construction model. When the accuracy of the sample construction model is improved, the accuracy of the second source text obtained by translating the second target text by the sample construction model will also be higher. Therefore, when the target translation model is subsequently trained using a second corpus pair including the second target text and the second source text, the accuracy of the trained target translation model can be improved because the accuracy of the training sample used has been improved.
[0146] In one embodiment of the present application, when determining whether the translation result of the target translation model is accurate in the above step S107, the accuracy index of the target translation model can be calculated based on the model output text; and the accuracy index can be used to determine whether the translation result of the target translation model is accurate.
[0147] The accuracy indicators include: Bleu indicator and / or perplexity.
[0148] In one implementation, when the accuracy metric includes a Bleu metric, a translation reference text corresponding to the test text can be obtained. The translation reference text is a text expressed in the target language and corresponding to the test text. After obtaining the model output text, the similarity between the model output text and the translation reference text can be calculated, and the Bleu metric can be determined based on the similarity. When the Bleu metric reaches a preset first threshold, the translation result of the target translation model can be considered accurate; otherwise, the translation result of the target translation model is considered inaccurate.
[0149] In one implementation, when the accuracy metric includes perplexity, each model output text of the target translation model may be obtained, and the perplexity may be calculated based on the confidence level corresponding to each model output text. When the perplexity is below a preset second threshold, the translation result of the target translation model may be considered accurate; otherwise, the translation result of the target translation model may be considered inaccurate.
[0150] In another implementation, mathematical statistics of the Bleu index and perplexity may be calculated, and whether the translation result of the target translation model is accurate may be determined based on the mathematical statistics.
[0151] The above-mentioned mathematical statistical values may be ratios, products, means, etc.
[0152] For example, assuming that the above mathematical statistical value is a ratio, the ratio of the Bleu index to the perplexity can be calculated. When the above ratio reaches a preset third threshold, the translation result of the target translation model can be considered accurate; otherwise, the translation result of the target translation model is considered inaccurate.
[0153] See also Figure 3 , Figure 3 A flow chart of another model training method provided in an embodiment of the present application includes the following steps S301-S308:
[0154] S301: Obtain a candidate corpus pair including a first source text and a first target text, and clean the candidate corpus pair to obtain a first corpus pair.
[0155] S302: Build a model for training samples using the first corpus.
[0156] S303: Obtain candidate texts in the target language, clean the candidate texts, and obtain a second target text.
[0157] S304: translating a second target text using the sample-based model to obtain a second source text.
[0158] S305: Train a target translation model using the first corpus pair and the second corpus pair.
[0159] The second corpus pair includes: a second source text and a second target text.
[0160] S306: Obtain a test text in the source language.
[0161] S307: Input the test text into the trained target translation model, and use the target translation model to translate the test text to obtain a model output text.
[0162] S308: Determine whether the translation result of the target translation model is accurate based on the model output text. If the translation result of the target translation model is inaccurate, return to S302 to construct a model for the training sample using the first corpus.
[0163] In the model training scheme provided by the above embodiment, a first corpus pair can be obtained, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text; a model is constructed using training samples from the first corpus pair, wherein the sample-constructed model is used to translate the text in the target language into the text in the source language; a second target text in the target language is obtained, and the sample-constructed model is used to translate the second target text to obtain a second source text; and a target translation model is trained using a second corpus pair, wherein the second corpus pair includes: a second source text and a second target text, and the target translation model is used to translate the text in the source language into the text in the target language. Because the second target text is a monolingual corpus and is widely available, it is easy to obtain a large number of second target texts. Then, the training samples are used to construct a model to obtain a second source text corresponding to the second target text, thereby obtaining a large number of second corpus pairs including the second source text and the second target text. The target translation model is then trained using the large number of second corpus pairs as samples, which can improve the training effect of the model. Therefore, it can be seen that the application of the scheme provided by the above embodiment can reduce the probability of mistranslation or overtranslation in the trained model and improve the accuracy of the model translation.
[0164] See also Figure 4 , Figure 4 A schematic diagram of the structure of a model training device provided in an embodiment of the present application, the device comprising:
[0165] A first corpus pair obtaining module 401 is configured to obtain a first corpus pair, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text;
[0166] A first model training module 402 is configured to construct a model for training samples using the first corpus, wherein the sample-based model is used to translate the text in the target language into the text in the source language;
[0167] A target text obtaining module 403 is configured to obtain a second target text in the target language, and translate the second target text using the sample-based model to obtain a second source text;
[0168] The second model training module 404 is configured to train a target translation model using a second corpus pair, wherein the second corpus pair includes the second source text and a second target text, and the target translation model is configured to translate the text in the source language into the text in the target language.
[0169] In one embodiment of the present application, the second model training module 404 is specifically configured to:
[0170] The target translation model is trained using the first corpus pair and the second corpus pair.
[0171] In one embodiment of the present application, the first corpus pair obtaining module 401 includes:
[0172] a candidate corpus pair obtaining unit, configured to obtain a candidate corpus pair comprising the first source text and the first target text;
[0173] The first corpus pair obtaining unit is configured to clean the candidate corpus pair to obtain a first corpus pair.
[0174] In one embodiment of the present application, the first corpus pair obtaining unit is specifically configured to:
[0175] Identifying a garbled corpus pair containing garbled characters in the candidate corpus pairs, removing the garbled corpus pair from the candidate corpus pairs, and obtaining a first corpus pair; and / or
[0176] An abnormal corpus pair whose length ratio is less than a first preset ratio or greater than a second preset ratio is searched for in the candidate corpus pairs, and the abnormal corpus pair is removed from the candidate corpus pairs to obtain a first corpus pair, wherein the first ratio is: a ratio of the length of the first source text to the length of the first target text, and the second preset ratio is greater than the first preset ratio.
[0177] In one embodiment of the present application, the target text obtaining module 403 includes:
[0178] a candidate text obtaining unit, configured to obtain candidate texts in the target language;
[0179] The target text obtaining unit is used to clean the candidate text to obtain a second target text.
[0180] In one embodiment of the present application, the target text obtaining unit is specifically configured to:
[0181] Searching for texts in the candidate texts whose lengths are within a preset length range as the second target texts; and / or
[0182] Searching for incomplete texts in the candidate texts that do not end with a preset ending identifier, removing the incomplete texts from the candidate texts to obtain a second target text; and / or
[0183] The semantic information of each candidate text is identified, semantically missing texts in the candidate texts are determined based on the identified semantic information, and the semantically missing texts are removed from the candidate texts to obtain a second target text.
[0184] In one embodiment of the present application, the device further comprises:
[0185] a test text obtaining module, configured to obtain a test text in the source language after training the target translation model using the second corpus;
[0186] An output text obtaining module, configured to input the test text into a trained target translation model, and translate the test text using the target translation model to obtain a model output text;
[0187] The third model training module is used to determine whether the translation result of the target translation model is accurate based on the model output text, and trigger the first model training module when the translation result of the target translation model is inaccurate.
[0188] In one embodiment of the present application, the third model training module is specifically used to:
[0189] Calculating an accuracy index of the target translation model based on the model output text, wherein the accuracy index includes: a Bleu index and / or a perplexity;
[0190] The accuracy index is used to determine whether the translation result of the target translation model is accurate. If the translation result of the target translation model is inaccurate, the first model training module is triggered.
[0191] In the model training scheme provided by the above embodiment, a first corpus pair can be obtained, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text; a model is constructed using training samples from the first corpus pair, wherein the sample-constructed model is used to translate the text in the target language into the text in the source language; a second target text in the target language is obtained, and the sample-constructed model is used to translate the second target text to obtain a second source text; and a target translation model is trained using a second corpus pair, wherein the second corpus pair includes: a second source text and a second target text, and the target translation model is used to translate the text in the source language into the text in the target language. Because the second target text is a monolingual corpus and is widely available, it is easy to obtain a large number of second target texts. Then, the training samples are used to construct a model to obtain a second source text corresponding to the second target text, thereby obtaining a large number of second corpus pairs including the second source text and the second target text. The target translation model is then trained using the large number of second corpus pairs as samples, which can improve the training effect of the model. Therefore, it can be seen that the application of the scheme provided by the above embodiment can reduce the probability of mistranslation or overtranslation in the trained model and improve the accuracy of the model translation.
[0192] The present application also provides an electronic device, such as Figure 5 As shown, it includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.
[0193] Memory 503, used for storing computer programs;
[0194] The processor 501 is used to implement the above-mentioned model training method steps when executing the program stored in the memory 503.
[0195] The communication bus mentioned in the electronic device mentioned above may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.
[0196] The communication interface is used for communication between the above electronic device and other devices.
[0197] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.
[0198] 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, and discrete hardware components.
[0199] In another embodiment provided in the present application, a computer-readable storage medium is also provided, which stores a computer program. When the computer program is executed by a processor, the steps of any of the above-mentioned model training methods are implemented.
[0200] In another embodiment provided in the present application, a computer program product comprising instructions is also provided, which, when executed on a computer, enables the computer to execute any one of the model training methods in the above embodiments.
[0201] In the model training scheme provided by the above embodiment, a first corpus pair can be obtained, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text; a model is constructed using training samples from the first corpus pair, wherein the sample-constructed model is used to translate the text in the target language into the text in the source language; a second target text in the target language is obtained, and the sample-constructed model is used to translate the second target text to obtain a second source text; and a target translation model is trained using a second corpus pair, wherein the second corpus pair includes: a second source text and a second target text, and the target translation model is used to translate the text in the source language into the text in the target language. Because the second target text is a monolingual corpus and is widely available, it is easy to obtain a large number of second target texts. Then, the training samples are used to construct a model to obtain a second source text corresponding to the second target text, thereby obtaining a large number of second corpus pairs including the second source text and the second target text. The target translation model is then trained using the large number of second corpus pairs as samples, which can improve the training effect of the model. Therefore, it can be seen that the application of the scheme provided by the above embodiment can reduce the probability of mistranslation or overtranslation in the trained model and improve the accuracy of the model translation.
[0202] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable 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, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. 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 integrations. 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 drive (SSD)).
[0203] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
[0204] Each embodiment in this specification is described in a related manner. Similar portions between the various embodiments can be referenced to each other. Each embodiment focuses on the differences from other embodiments. In particular, since the apparatus embodiments, electronic device embodiments, computer-readable storage medium embodiments, and computer program product embodiments are generally similar to the method embodiments, their descriptions are relatively simple. For related portions, reference can be made to the descriptions of the method embodiments.
[0205] The above description is only a preferred embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application are included in the scope of protection of the present application.
Claims
1. A model training method, characterized in that: The method comprises: Obtaining a first corpus pair, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text; Using the first corpus to construct a model for training samples, wherein the sample construction model is used to: translate the text in the target language into the text in the source language; Obtaining a second target text in the target language, and translating the second target text using the sample-built model to obtain a second source text; The target translation model is trained using a second corpus pair, wherein the second corpus pair includes: the second source text and the second target text, and the target translation model is used to translate the text in the source language into the text in the target language; wherein, The obtaining of the first corpus pair comprises: Obtaining a candidate corpus pair including the first source text and the first target text; An abnormal corpus pair whose length ratio is less than a first preset ratio or greater than a second preset ratio in the candidate corpus pairs is searched, the abnormal corpus pair is removed from the candidate corpus pairs, the candidate corpus pairs are cleaned, and a first corpus pair is obtained, wherein the length ratio is: the ratio of the length of the first source text to the length of the first target text, and the second preset ratio is greater than the first preset ratio.
2. The method according to claim 1, characterized in that The using the second corpus to train the target translation model includes: The target translation model is trained using the first corpus pair and the second corpus pair.
3. The method according to claim 1, characterized in that The method further comprises: A garbled corpus pair containing garbled characters is identified in the candidate corpus pairs, and the garbled corpus pair is removed from the candidate corpus pairs to obtain a first corpus pair.
4. The method according to claim 1, characterized in that: The step of obtaining the second target text in the target language comprises: obtaining candidate text in the target language; The candidate text is cleaned to obtain a second target text.
5. The method according to claim 4, characterized in that The step of cleaning the candidate text to obtain a second target text includes: Searching for texts in the candidate texts whose lengths are within a preset length range as second target texts; and / or Searching for incomplete texts in the candidate texts that do not end with a preset ending identifier, removing the incomplete texts from the candidate texts, and obtaining a second target text; and / or The semantic information of each candidate text is identified, and semantically missing texts with semantic missing in the candidate texts are determined according to the identified semantic information, and the semantically missing texts are removed from the candidate texts to obtain a second target text.
6. The method according to any one of claims 1 to 5, characterized in that After the step of training the target translation model using the second corpus, the method further includes: obtaining a test text in the source language; Inputting the test text into the trained target translation model, and translating the test text using the target translation model to obtain a model output text; Whether the translation result of the target translation model is accurate is determined according to the model output text. If the translation result of the target translation model is inaccurate, the step of constructing a model for training samples using the first corpus is returned to.
7. The method according to claim 6, characterized in that The step of judging whether the translation result of the target translation model is accurate according to the model output text includes: Calculating the accuracy index of the target translation model according to the model output text, wherein the accuracy index includes: Bleu index and / or perplexity; The accuracy index is used to determine whether the translation result of the target translation model is accurate.
8. A model training device, characterized in that: The device comprises: A first corpus pair obtaining module, configured to obtain a first corpus pair, wherein the first corpus pair includes: a first source text in a source language, and a first target text in a target language corresponding to the first source text; A first model training module is used to construct a model for training samples using the first corpus, wherein the sample construction model is used to: translate the text in the target language into the text in the source language; A target text obtaining module, used to obtain a second target text in the target language, and translate the second target text using the sample construction model to obtain a second source text; A second model training module, used for training a target translation model using a second corpus pair, wherein the second corpus pair includes: the second source text and a second target text, and the target translation model is used for translating the text in the source language into the text in the target language; The first corpus pair obtaining module includes: A candidate corpus pair obtaining unit, configured to obtain a candidate corpus pair including the first source text and the first target text; The first corpus pair obtaining unit is used to search for an abnormal corpus pair whose length ratio is less than a first preset ratio or greater than a second preset ratio in the candidate corpus pair, remove the abnormal corpus pair from the candidate corpus pair, complete the cleaning of the candidate corpus pair, and obtain a first corpus pair, wherein the length ratio is: the ratio of the length of the first source text to the length of the first target text, and the second preset ratio is greater than the first preset ratio.
9. The device according to claim 8, characterized in that The second model training module is specifically used for: The target translation model is trained using the first corpus pair and the second corpus pair.
10. The device according to claim 8, characterized in that The first corpus pair obtaining unit is further used for: A garbled corpus pair containing garbled characters is identified in the candidate corpus pairs, and the garbled corpus pair is removed from the candidate corpus pairs to obtain a first corpus pair.
11. The device according to claim 8, characterized in that The target text acquisition module comprises: A candidate text obtaining unit, used to obtain candidate texts in the target language; The target text obtaining unit is used to clean the candidate text to obtain a second target text.
12. The device according to claim 11, characterized in that The target text obtaining unit is specifically used for: Searching for texts in the candidate texts whose lengths are within a preset length range as second target texts; and / or Searching for incomplete texts in the candidate texts that do not end with a preset ending identifier, removing the incomplete texts from the candidate texts, and obtaining a second target text; and / or The semantic information of each candidate text is identified, and semantically missing texts with semantic missing in the candidate texts are determined according to the identified semantic information, and the semantically missing texts are removed from the candidate texts to obtain a second target text.
13. The device according to any one of claims 8 to 12, characterized in that The device also includes: A test text obtaining module, used to obtain a test text in the source language after training the target translation model with the second corpus; An output text obtaining module, used for inputting the test text into the trained target translation model, translating the test text using the target translation model, and obtaining a model output text; The third model training module is used to determine whether the translation result of the target translation model is accurate according to the model output text, and trigger the first model training module when the translation result of the target translation model is inaccurate.
14. The device according to claim 13, characterized in that The third model training module is specifically used for: Calculating the accuracy index of the target translation model according to the model output text, wherein the accuracy index includes: Bleu index and / or perplexity; The accuracy index is used to determine whether the translation result of the target translation model is accurate. If the translation result of the target translation model is inaccurate, the first model training module is triggered.
15. 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; A processor, for implementing the method steps described in any one of claims 1 to 7 when executing a program stored in a memory.
16. 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 method steps described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Translation model obtaining method and device, equipment and storage medium
CN111008533A
Machine translation method and device, electronic equipment and readable storage medium
CN112329482A
