A language model training method and device
By selecting target parallel corpus pairs from multiple parallel corpus pairs in language model training, and using the standard language corpus in the pre-training stage to learn grammatical and semantic knowledge, the accuracy problem caused by the lack of parallel corpus pairs in the existing technology is solved. Efficient translation between standard languages and dialects is achieved.
Patent Information
- Application Number
- CN202111061230.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-10
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-09-10
AI Technical Summary
It is difficult to train an accurate language model between standard language and dialects with existing technology, mainly due to the lack of sufficient parallel corpus pairs, resulting in poor model training results.
By selecting target parallel corpus pairs from multiple parallel corpus pairs, the standard language corpus is used as the input corpus of the pre-training model, and the dialect corpus is used as the target corpus for fine-tuning training. The standard language corpus in the pre-training stage is used to learn grammar and semantic knowledge. Reduce reliance on parallel corpus pairs.
It is possible to use a small amount of parallel corpus to train a language model with accurate translation capabilities, improving the accuracy of translation between standard languages and dialects.
Smart Images

Figure CN113836948B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of translation technology, and in particular to a method and device for training a language model. Background Art
[0002] With the rapid development of machine learning, language models are increasingly being used. Language models can be deployed in a variety of electronic devices to facilitate users to quickly translate between different languages in different usage scenarios.
[0003] At present, there is an increasing demand for translating standard languages (such as Mandarin) into dialects or vice versa. For translation between standard languages and dialects, if a more accurate language model needs to be trained, a large number of parallel corpus pairs are required, each of which consists of a standard language corpus and a corresponding dialect corpus. In the actual model training process, it is impossible to train a more accurate language model because a large number of parallel corpus pairs including dialect corpus cannot be obtained. Summary of the invention
[0004] In view of the above problems, the present invention is proposed to provide a method and device for training a language model that overcomes the above problems or at least partially solves the above problems.
[0005] A first aspect of the present invention provides a method for training a language model, the method comprising:
[0006] Selecting a target parallel corpus pair from a plurality of parallel corpus pairs; the parallel corpus pair includes a standard language corpus and a corresponding dialect corpus;
[0007] The first corpus is used as the input corpus of the pre-training model, and the second corpus is used as the target corpus of the pre-training model to fine-tune the pre-training model; the pre-training model is obtained by pre-training the original language model with the plurality of standard language corpora acquired in advance; the first corpus is the standard language corpus or the dialect corpus in the target parallel corpus pair, and the second corpus is another corresponding corpus;
[0008] When a preset fine-tuning end condition is met, the pre-trained model is used as the target language model.
[0009] A second aspect of the present invention provides a language model training device, the device comprising:
[0010] A selection module, used for selecting a target parallel corpus pair from a plurality of parallel corpus pairs; the parallel corpus pair includes a standard language corpus and a corresponding dialect corpus;
[0011] A first training module is used to use the first corpus as the input corpus of the pre-training model and the second corpus as the target corpus of the pre-training model to fine-tune the pre-training model; the pre-training model is obtained by pre-training the original language model with the plurality of standard language corpora acquired in advance; the first corpus is the standard language corpus or the dialect corpus in the target parallel corpus pair, and the second corpus is another corresponding corpus;
[0012] The end module is used to use the pre-trained model as the target language model when a preset fine-tuning end condition is met.
[0013] In summary, the training method of the language model provided by the embodiment of the present invention first selects a target parallel corpus pair from a plurality of parallel corpus pairs, then uses the first corpus in the target parallel corpus pair as the input corpus of the pre-training model, and the second corpus as the target corpus of the pre-training model, and fine-tunes the pre-training model. When the preset fine-tuning end condition is met, the pre-training model is used as the target language model. Since the grammatical and semantic knowledge of the standard language and the dialect are the same, the language model can be trained using a large amount of standard language corpus in the pre-training stage to learn the grammatical and semantic knowledge of the standard language and the dialect. In the fine-tuning training stage, since the model has already learned the grammatical and semantic knowledge of the standard language and the dialect, a small amount of parallel corpus pairs can be used to train a language model with accurate translation capabilities.
[0014] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0016] Figure 1 is a flow chart of the steps of a language model training method provided by an embodiment of the present invention;
[0017] Figure 2 It is a block diagram of a language model training device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0018] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present invention and to enable the scope of the present invention to be fully communicated to those skilled in the art.
[0019] Reference Figure 1 , shows a flow chart of the steps of a language model training method provided by an embodiment of the present invention, the method may include:
[0020] Step 101: Select a target parallel corpus pair from multiple parallel corpus pairs.
[0021] Each parallel corpus pair consists of an original text and a corresponding translation, which can be used for training and testing a language model. In this embodiment, the original text in the parallel corpus pair can be a standard language corpus, and the translation can be a dialect corpus obtained by translating the standard language corpus. Alternatively, the dialect corpus can be defined as the original text, and the standard language corpus is a translation obtained by translating the dialect corpus. Exemplarily, the standard language corpus is Mandarin, and the dialect corpus is the Cantonese dialect corresponding to Mandarin. For example, the standard language corpus in the parallel corpus pair is "What is a money market fund", and the corresponding Cantonese dialect corpus is "What is a money market fund".
[0022] In this embodiment, the training method of the language model can be executed by electronic devices such as computers and servers. Before training, the electronic device can first obtain a certain number of parallel corpus pairs, each parallel corpus pair including a standard language corpus and a corresponding dialect corpus. During the training process, the electronic device can randomly select a parallel corpus pair from multiple parallel corpus pairs as a target parallel corpus pair, or select one of the multiple parallel corpus pairs in sequence as the target parallel corpus pair according to the storage order of the multiple parallel corpus pairs in the electronic device. The specific process of obtaining multiple parallel corpus pairs and selecting a target parallel corpus pair from multiple parallel corpus pairs can be set according to demand, and this embodiment does not limit this.
[0023] It should be noted that the standard language corpus in the parallel corpus pair may also be other standard language corpora, such as English, Korean or Japanese, and the dialect corpus corresponding to the standard language corpus may be any dialect corpus corresponding to the standard language corpus.
[0024] Step 102: Use the first corpus as the input corpus of the pre-training model, use the second corpus as the target corpus of the pre-training model, and perform fine-tuning training on the pre-training model.
[0025] Step 103: When the preset fine-tuning end condition is met, the pre-trained model is used as the target language model.
[0026] The pre-trained model is obtained by pre-training the original language model with multiple standard language corpora acquired in advance; the first corpus is the standard language corpus or dialect corpus in the target parallel corpus pair, and the second corpus is another corresponding corpus.
[0027] In this embodiment, the pre-trained model can be a language model obtained by pre-training the original language model using multiple standard language corpora. The original language model can select any natural language processing model (Natural Language Processing Model, NLPM), for example, the original language model can be a neural network language model (Neural Network Language Model, NNLM). Among them, the pre-trained model can be a pre-trained model directly downloaded from the Internet and trained with standard language corpora, or it can be a pre-trained model obtained by pre-training the original language model with standard language corpora after obtaining a large amount of standard language corpora. The method for obtaining the pre-trained model may include but is not limited to the above examples.
[0028] In one embodiment, the first corpus may be a standard language corpus in the target parallel corpus pair, and the second corpus is a dialect corpus in the target parallel corpus pair. The input corpus is used to input the pre-training model to obtain the output result output by the pre-training model, and the target corpus is used to compare with the output result, and the model parameters of the pre-training model are adjusted according to the comparison result to complete the fine-tuning training of the pre-training model. In combination with the above example, when the parallel corpus pair as described above is selected as the target parallel corpus pair, the standard language corpus (i.e., the first corpus) "What is a money market fund" can be used as the input corpus of the pre-training model, and the dialect corpus (i.e., the second corpus) "What is a money market fund" can be used as the target corpus of the pre-training model. In the process of fine-tuning the pre-training model, the input corpus can be input as an input character sequence into the pre-training model to obtain the predicted character sequence output by the pre-training model. According to the difference between the predicted character sequence and the target corpus, the model parameters of the pre-training model are adjusted to complete a fine-tuning training of the pre-training model. Repeat step 101 and step 102, that is, repeatedly select a target parallel corpus pair from multiple parallel corpus pairs, use the first corpus in the target parallel corpus pair as the input corpus of the pre-trained model, and the second corpus as the target corpus of the pre-trained model, fine-tune the pre-trained model, and determine that the training is completed when the preset fine-tuning end condition is met, then stop executing step 101 and step 102, and use the pre-trained model as the target language model. For each selected target parallel corpus pair, the first corpus is a standard language corpus, and the second corpus is a dialect corpus, or the first corpus is a dialect corpus, and the second corpus is a standard language corpus.
[0029] Among them, the fine-tuning end condition can be set according to actual needs. Exemplarily, the fine-tuning end condition can be a preset accuracy rate. The electronic device can pre-acquire multiple test corpus pairs, and the test corpus pairs are the same as the parallel corpus pairs, having a standard language corpus and a corresponding dialect corpus. After repeating steps 101 and 102 for a preset number of times, a target test corpus pair can be selected from multiple test corpus pairs, and the first corpus in the target test corpus pair is input as an input character sequence into the pre-training model to obtain an output character sequence output by the pre-training model, and the translation accuracy of the pre-training model is calculated based on the difference between the output character sequence and the second corpus in the target test corpus pair. When the translation accuracy of the pre-training model for the first corpus in the test corpus pair reaches the preset accuracy rate, it is determined that the fine-tuning end condition is reached, the fine-tuning training can be ended, and the pre-training model can be used as the target language model.
[0030] In one embodiment, the fine-tuning end condition may be a preset number of training times. In combination with the above example, when the fine-tuning end condition is the number of training times, the electronic device loops through step 101 to step 102, and each loop is executed once, and the number of training times is increased by 1. When the number of training times reaches the preset number of training times, it is determined that the training is completed, and the pre-trained model is used as the target language model. The specific value of the number of training times can be set as required.
[0031] It should be noted that the specific process of fine-tuning training can be set according to the specific type of the original language model, and this embodiment does not limit this. If the first corpus in the training process is the standard language corpus in the target parallel corpus pair, and the second corpus is the dialect corpus in the target parallel corpus pair, then in the use of the target language model, the source language input to the target language model should be the standard language, and the target language model can translate the source language into the corresponding target language, which is the dialect corresponding to the second corpus. On the contrary, if the first corpus in the training process is the dialect corpus in the target parallel corpus pair, and the second corpus is the standard language corpus in the target parallel corpus pair, then in the use of the target language model, the source language input to the target language model should be the dialect, and the target language model can translate the source language into the target language, which is the standard language.
[0032] In the standard language and the corresponding dialect, the grammar and semantic knowledge of the standard language and the dialect are the same. In the pre-training stage, a large amount of standard language corpus is used to train the original language model to obtain a pre-trained model, which can enable the pre-trained model to learn the grammar and semantic knowledge of the standard language and the dialect. In the fine-tuning training stage, since the pre-trained model has learned the grammar and semantic knowledge of the standard language and the dialect, it can be fine-tuned through a small amount of parallel corpus pairs, so that the pre-trained model can quickly learn the corresponding relationship between the standard language and the dialect, so as to obtain a more accurate target language model.
[0033] In combination with the above example, in the process of using the first corpus as the input corpus of the pre-training model and the second corpus as the target corpus of the pre-training model, the standard language corpus in the target parallel corpus pair can be used as the input corpus, and the dialect corpus in the target parallel corpus pair can be used as the target corpus. Since a large amount of standard language corpus is used to train the original language model in the pre-training stage, the original language model can learn the grammatical and semantic knowledge of the standard language. Therefore, in the fine-tuning training stage, when the standard language corpus is used as the input corpus, the pre-training model can learn the correspondence between the standard language and the dialect based on the grammatical and semantic knowledge that has been learned, so that a more accurate target language model can be trained, so that the target language model can achieve accurate translation from the standard language to the dialect.
[0034] In summary, the training method of the language model provided by the embodiment of the present invention first selects a target parallel corpus pair from a plurality of parallel corpus pairs, then uses the first corpus in the target parallel corpus pair as the input corpus of the pre-training model, and the second corpus as the target corpus of the pre-training model, and fine-tunes the pre-training model. When the preset fine-tuning end condition is met, the pre-training model is used as the target language model. Since the grammatical and semantic knowledge of the standard language and the dialect are the same, the language model can be trained using a large amount of standard language corpus in the pre-training stage to learn the grammatical and semantic knowledge of the standard language and the dialect. In the fine-tuning training stage, since the model has already learned the grammatical and semantic knowledge of the standard language and the dialect, a small amount of parallel corpus pairs can be used to train a language model with accurate translation capabilities.
[0035] Optionally, the original language model is a decoder in a sequence-to-sequence model; the sequence-to-sequence model consists of an encoder and a decoder.
[0036] In one embodiment, the original language model may be a decoder in a sequence-to-sequence model, for example, the sequence-to-sequence model may be a transformer model composed of an encoder and a decoder. In this case, the original language model may be a decoder in a transformer model. Alternatively, the original language model may be a language model composed of a decoder such as a Generative Pre-Training (GPT) model and a GPT-2 model.
[0037] In practical applications, when the pre-trained model is trained by the encoder in the sequence-to-sequence model, the trained target language model has a relatively simple structure, occupies less storage space, and is easy to deploy in different electronic devices.
[0038] Optionally, when the original language model is a decoder in a sequence-to-sequence model, step 102 may be implemented as follows:
[0039] Step 1021: taking the input corpus as a fixed character sequence and adding a separator character at one end of the fixed character sequence to obtain an input character sequence;
[0040] Step 1022: input the input character sequence into the pre-trained model to obtain an output character sequence; the output character sequence includes the input character sequence and the predicted characters predicted by the pre-trained model; the separator character divides the output character sequence into a fixed character sequence and a predicted character sequence composed of the predicted characters;
[0041] Step 1023, determining a target character from the target corpus; the position of the target character in the target corpus is the same as the position of the predicted character in the predicted character sequence;
[0042] Step 1024, determining a target mapping vector corresponding to the target character from the mapping vector list; the mapping vector list is generated by the pre-trained model in the process of predicting the predicted character;
[0043] Step 1025: Adjust the model parameters of the pre-trained model according to the difference between the target mapping vector and the reference vector;
[0044] Step 1026: Use the output character sequence as a new input character sequence and repeat the process of adjusting the model parameters of the pre-trained model until the pre-trained model outputs an end character.
[0045] In this embodiment, when the pre-trained model is composed of a decoder, in the fine-tuning training stage, the input corpus can first be used as a fixed character sequence, and then a separator character is added at one end of the fixed character sequence to obtain the input character sequence of the pre-trained model. Combined with the above example, when the first corpus is the standard language corpus "What is a money market fund" in the target parallel corpus pair, "What is a money market fund" can be used as a fixed character sequence, and a separator character is added at the end of "What is a money market fund", then the input character sequence is "What is a money market fund <del>". The separator character can be a reserved character among all characters corresponding to the pre-trained model. <del>.
[0046] Among them, in the process of inputting the input character sequence into the pre-trained model, first, according to the character encoding list corresponding to the pre-trained model, the input character sequence is mapped to the input encoding sequence. The character encoding list is set according to the characters in the standard language. For example, if there are 10,000 different characters in the standard language, the 10,000 characters in the standard language can be encoded respectively to obtain the character encoding corresponding to each character, and the 10,000 character encodings and the character encodings of the reserved characters constitute the character encoding list. After obtaining the input character sequence, the character encoding corresponding to each character in the input character sequence can be found from the character encoding list, and the input encoding sequence (also referred to as a semantic encoding sequence) is composed of the character encoding corresponding to each character in the input character sequence. The input encoding sequence is input into the pre-trained model to realize the input of the input character sequence. After the input encoding sequence is input into the pre-trained model, the output encoding sequence output by the pre-trained model can be obtained, and the output encoding sequence includes the character encoding corresponding to each character in the output character sequence. Further, according to each character encoding in the output encoding sequence, the character corresponding to each character encoding in the output encoding sequence is found from the character encoding list to form the output character sequence.
[0047] Combined with the above example, after getting the input character sequence "What is a money market fund <del>"After that, you can look up "What is a money market fund" from the character encoding list <del>"The character codes corresponding to each character in the output code sequence are composed of the character codes corresponding to each character in turn, and the input code sequence is input into the pre-trained model to obtain the output code sequence output by the pre-trained model. Then, the character corresponding to each character code in the output code sequence is searched from the character code list, and the output character sequence is composed of the characters found. "What is a money market fund <del>"What". In the output character sequence, the delimiter character <del>The output character sequence is divided into a fixed character sequence "What is a money market fund" and a predicted character sequence "乜". The character "乜" in the predicted character sequence is the predicted character obtained by the pre-trained model based on the fixed character sequence "What is a money market fund".
[0048] It should be noted that when the pre-trained model outputs a predicted character, it first outputs a list of mapping vectors corresponding to the predicted character, and then selects the largest mapping vector from the list of mapping vectors to determine that the character corresponding to the largest mapping vector is the predicted character. Each mapping vector in the list of mapping vectors corresponds to a character code in the character code list, that is, it corresponds to a character. Combining the above example, in the process of outputting the predicted character "乜", the pre-trained model first outputs the list of mapping vectors corresponding to the predicted character "乜", then determines the largest mapping vector from the list of mapping vectors, and determines that the character "乜" corresponding to the largest mapping vector in the character list is the predicted character.
[0049] In this embodiment, after obtaining the output character sequence output by the pre-trained model, the target character located at the same position can be determined from the target corpus according to the position of the predicted character in the predicted character sequence. Combining the above example, the predicted character "乜" is the first predicted character output after the first input to the pre-trained model, and the predicted character "乜" is located at the first position in the predicted character sequence. At this time, it can be determined that the character "乜" located at the first position in the target corpus "乜嘢係货币市场性基金" is the target character. Further, the electronic device can determine the target mapping vector corresponding to the target character "乜" from the list of mapping vectors corresponding to the predicted character. After the pre-trained model outputs the first predicted character "乜", the target mapping vector corresponding to the target character "乜" can be determined from the list of mapping vectors corresponding to the first predicted character "乜". The target mapping vector represents the magnitude of the predicted probability that the first character in the predicted character sequence is "乜". At the same time, the character "乜" is the first character in the target corpus, that is, the actual probability of the target character "乜" is 1. The actual probability can be used as a reference vector, and the electronic device can calculate the difference between the predicted probability and the actual probability through a penalty function, calculate the difference between the actually predicted predicted character of the pre-trained model and the target character, and adjust the model parameters of the pre-trained model through backpropagation to achieve one training of the pre-trained model.
[0050] After completing one training, the output character sequence output for the first time can be used as a new input character sequence, and the above process can be repeated. Combining the above example, the output character sequence "What is a money market fund <del>Taking "what" as the new input character sequence and inputting it into the pre-trained model, the output character sequence output by the pre-trained model for the second time is obtained. At this time, the output character sequence includes the input character sequence "What is a money market fund" <del>The characters "乜" and the predicted character "嘢". At this time, the delimiter divides the output character sequence into the fixed character sequence "什么是货币市场性基金" and the predicted character sequence "乜嘢". The predicted character sequence includes the first predicted character and the second predicted character. The electronic device can determine, according to the position of the second predicted character "嘢" in the predicted character sequence, that the character "嘢" in the second position in the target corpus is the target character. Then, determine the mapping vector corresponding to the target character "嘢" in the mapping vector list of the predicted character "嘢" as the target mapping vector. Finally, adjust the model parameters of the pre-trained model according to the difference between the reference vector and the target mapping vector to complete the second training of the pre-trained model.
[0051] After completing the second training, the second output character sequence "什么是货币市场性基金" can be <del>"What is money market fund" is used as a new input character sequence and input into the pre-trained model to obtain the output character sequence of the third output of the pre-trained model. <del>Similarly, the delimiter divides the output character sequence for the third time into a fixed character sequence "What is a money market fund" and a predicted character sequence "What is", where the predicted character sequence includes the first predicted character "What", the second predicted character "is", and the third predicted character "is", and the third predicted character "is" is the predicted character in the current output character sequence. Then, the electronic device can determine the third character "is" as the target character from the target corpus according to the position of the third predicted character "is" in the predicted character sequence. Then, the target mapping vector corresponding to the target character "is" is determined from the list of mapping vectors of the predicted character "is". According to the difference between the target mapping vector and the reference vector, the third adjustment of the model parameters of the pre-trained model is realized. Combining the above example, it can be seen that the predicted character and the target character may be the same or different each time. Steps 1021 to 1025 are repeatedly executed until the pre-trained model outputs an end character, and the training of the pre-trained model is completed through a parallel corpus.
[0052] In this embodiment, when the target language model is trained by a decoder, during the use of the target language model, first, the source language to be translated can be obtained, and then the source language to be translated is used as a fixed character sequence, and a delimiter is added at one end of the fixed character sequence to obtain an input character sequence. The input character sequence is input into the target language model to obtain an output character sequence output by the target language model; the output character sequence includes the input character sequence and predicted characters. Similarly, the delimiter in the output character sequence divides the output character sequence into a fixed character sequence and a predicted character sequence composed of predicted characters. The output character sequence is used as a new input character sequence, and the above steps are repeatedly executed. When the target language model outputs an end character, the predicted character sequence between the end character and the delimiter is used as the target language obtained by translation.
[0053] Optionally, before step 101, the method may further include:
[0054] Select a target standard language corpus from multiple pre-obtained standard language corpora;
[0055] Use the target standard language corpus as the input corpus and the target corpus of the original language model to pre-train the original language model. The steps of selecting the target standard language corpus and pre-training are repeatedly executed. When the preset pre-training end condition is reached, the original language model is used as the pre-trained model.
[0056] In one embodiment, a plurality of standard language corpora may be acquired in advance, and then the original language model may be pre-trained using the plurality of standard language corpora to obtain a pre-trained model. Exemplarily, first, a standard language corpus may be randomly selected from the plurality of standard language corpora acquired in advance as the target standard language corpus, and then the target standard language corpus may be simultaneously used as the input corpus and the target corpus of the original language model. The input corpus is input into the original language model to obtain an output character sequence output by the original language model, and the model parameters of the original language model are adjusted according to the difference between the output character sequence and the target corpus, thereby completing a pre-training of the original language model. Repeat the steps of selecting the target standard language corpus and pre-training until the preset pre-training end condition is reached. The pre-training end condition may refer to the fine-tuning end condition described above, and this implementation does not limit the specific setting of the pre-training end condition.
[0057] In another embodiment, when the original language model is a decoder in a sequence-to-sequence model, the pre-training process of the original language model can refer to steps 1021 to 1025. The difference between the pre-training process and the fine-tuning training process is that the pre-training process uses the standard language corpus as the input corpus and target corpus of the original language model, and the fine-tuning training process uses the first corpus in the parallel corpus pair as the input corpus of the pre-training model, and the second corpus as the target corpus of the pre-training model.
[0058] Figure 2 is a block diagram of a language model training device provided by an embodiment of the present invention, such as Figure 2 As shown, the device 200 may include:
[0059] A selection module 201 is used to select a target parallel corpus pair from a plurality of parallel corpus pairs; the parallel corpus pair includes a standard language corpus and a corresponding dialect corpus;
[0060] The first training module 202 is used to use the first corpus as the input corpus of the pre-training model and the second corpus as the target corpus of the pre-training model to fine-tune the pre-training model; the pre-training model is obtained by pre-training the original language model with a plurality of pre-acquired standard language corpora; the first corpus is the standard language corpus or the dialect corpus in the target parallel corpus pair, and the second corpus is another corresponding corpus;
[0061] The end module 203 is used to use the pre-trained model as the target language model when a preset fine-tuning end condition is met.
[0062] Optionally, the original language model is a decoder in a sequence-to-sequence model; the sequence-to-sequence model consists of an encoder and a decoder.
[0063] Optionally, the first training module 202 includes:
[0064] An adding unit is used to take the input corpus as a fixed character sequence and add a separator character at one end of the fixed character sequence to obtain an input character sequence;
[0065] An input unit is used to input an input character sequence into a pre-trained model to obtain an output character sequence; the output character sequence includes the input character sequence and predicted characters predicted by the pre-trained model; a separator character divides the output character sequence into a fixed character sequence and a predicted character sequence composed of predicted characters;
[0066] A first determining unit is used to determine a target character from a target corpus; the position of the target character in the target corpus is the same as the position of the predicted character in the predicted character sequence;
[0067] A second determination unit is used to determine a target mapping vector corresponding to a target character from a mapping vector list; the mapping vector list is generated by a pre-trained model in a process of predicting a predicted character;
[0068] An adjustment unit, configured to adjust a model parameter of the pre-trained model according to a difference between a target mapping vector and a reference vector;
[0069] The repeating unit is used to use the output character sequence as a new input character sequence and repeat the process of adjusting the model parameters of the pre-trained model until the pre-trained model outputs an end character.
[0070] Optionally, the first training module is specifically configured to use the standard language corpus in the target parallel corpus pair as the input corpus, and use the dialect corpus in the target parallel corpus pair as the target corpus.
[0071] Optionally, it also includes: a second training module, which is used to select a target standard language corpus from a plurality of standard language corpora acquired in advance; use the target standard language corpus as the input corpus and target corpus of the original language model, pre-train the original language model, and use the original language model as the pre-training model when a preset pre-training end condition is met.
[0072] In summary, the training device for the language model provided by the embodiment of the present invention first selects a target parallel corpus pair from a plurality of parallel corpus pairs, then uses the first corpus in the target parallel corpus pair as the input corpus of the pre-training model, and the second corpus as the target corpus of the pre-training model, and fine-tunes the pre-training model. When the preset fine-tuning end condition is met, the pre-training model is used as the target language model. Since the grammatical and semantic knowledge of the standard language and the dialect are the same, the language model can be trained with a large amount of standard language corpus in the pre-training stage to learn the grammatical and semantic knowledge of the standard language and the dialect. In the fine-tuning training stage, since the model has already learned the grammatical and semantic knowledge of the standard language and the dialect, a small amount of parallel corpus pairs can be used to train a language model with accurate translation capabilities.
[0073] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0074] It is easy for a person skilled in the art to think that any combination of the above embodiments is feasible, so any combination of the above embodiments is an implementation scheme of the present invention. However, due to space limitations, this specification will not describe them in detail here.
[0075] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0076] Similarly, it should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the intention that the claimed invention requires more features than those expressly recited in each claim. Rather, as reflected in the claims, inventive aspects lie in less than all of the features of the individual embodiments previously disclosed. Therefore, the claims that follow the detailed description are hereby expressly incorporated into the detailed description, with each claim itself serving as a separate embodiment of the present invention.
[0077] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0078] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims, any one of the claimed embodiments may be used in any combination.
[0079] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.< / del> < / del> < / del> < / del> < / del> < / del> < / del> < / del> < / del> < / del>
Claims
1. A method for training a language model, characterized in that: include: Selecting a target parallel corpus pair from multiple parallel corpus pairs; The parallel corpus pair includes a standard language corpus and a corresponding dialect corpus; Using the first corpus as the input corpus of the pre-training model and the second corpus as the target corpus of the pre-training model, and performing fine-tuning training on the pre-training model; The pre-trained model is obtained by pre-training an original language model with a plurality of the standard language corpora acquired in advance; the first corpus is a standard language corpus or a dialect corpus in the target parallel corpus pair, and the second corpus is another corresponding corpus; When a preset fine-tuning end condition is met, using the pre-trained model as a target language model; Wherein, the fine-tuning training of the pre-trained model includes: Taking the input corpus as a fixed character sequence and adding a separator character at one end of the fixed character sequence to obtain an input character sequence; The input character sequence is input into the pre-trained model to obtain an output character sequence; the output character sequence includes the input character sequence and the predicted characters predicted by the pre-trained model; the separator character divides the output character sequence into the fixed character sequence and the predicted character sequence composed of the predicted characters; Determining a target character from the target corpus; the position of the target character in the target corpus is the same as the position of the predicted character in the predicted character sequence; Determine a target mapping vector corresponding to the target character from a mapping vector list; the mapping vector list is generated by the pre-trained model in the process of predicting the predicted character; Adjusting model parameters of the pre-trained model according to the difference between the target mapping vector and the reference vector; The output character sequence is used as a new input character sequence, and the process of adjusting the model parameters of the pre-trained model is repeated until the pre-trained model outputs an end character.
2. The method according to claim 1, characterized in that The original language model is a decoder in a sequence-to-sequence model; the sequence-to-sequence model consists of an encoder and the decoder.
3. The method according to claim 1, characterized in that: The method of using the first corpus as the input corpus of the pre-training model and the second corpus as the target corpus of the pre-training model includes: The standard language corpus in the target parallel corpus pair is used as the input corpus, and the dialect corpus in the target parallel corpus pair is used as the target corpus.
4. The method according to any one of claims 1 to 3, characterized in that: Before selecting a target parallel corpus pair from a plurality of parallel corpus pairs, the method further includes: Selecting a target standard language corpus from a plurality of the standard language corpora acquired in advance; Using the target standard language corpus as the input corpus and target corpus of the original language model, pre-training the original language model, When a preset pre-training end condition is met, the original language model is used as the pre-training model.
5. A language model training device, characterized in that: include: A selection module, used for selecting a target parallel corpus pair from multiple parallel corpus pairs; The parallel corpus pair includes a standard language corpus and a corresponding dialect corpus; A first training module is used to use the first corpus as the input corpus of the pre-training model and the second corpus as the target corpus of the pre-training model to perform fine-tuning training on the pre-training model; The pre-trained model is obtained by pre-training an original language model with a plurality of the standard language corpora acquired in advance; the first corpus is a standard language corpus or a dialect corpus in the target parallel corpus pair, and the second corpus is another corresponding corpus; An end module, used to use the pre-trained model as a target language model when a preset fine-tuning end condition is met; Wherein, the first training module includes: an adding unit, configured to take the input corpus as a fixed character sequence and add a separator character at one end of the fixed character sequence to obtain an input character sequence; An input unit, used for inputting the input character sequence into the pre-trained model to obtain an output character sequence; the output character sequence includes the input character sequence and the predicted characters predicted by the pre-trained model; the separator character divides the output character sequence into the fixed character sequence and the predicted character sequence composed of the predicted characters; A first determining unit is used to determine a target character from the target corpus; the position of the target character in the target corpus is the same as the position of the predicted character in the predicted character sequence; A second determining unit is used to determine a target mapping vector corresponding to the target character from a mapping vector list; the mapping vector list is generated by the pre-trained model in the process of predicting the predicted character; An adjustment unit, configured to adjust a model parameter of the pre-trained model according to a difference between the target mapping vector and the reference vector; A repeating unit is used to use the output character sequence as a new input character sequence and repeat the process of adjusting the model parameters of the pre-trained model until the pre-trained model outputs an end character.
6. The device according to claim 5, characterized in that The original language model is a decoder in a sequence-to-sequence model; the sequence-to-sequence model consists of an encoder and the decoder.
7. The device according to claim 5, characterized in that The first training module is specifically configured to use the standard language corpus in the target parallel corpus pair as the input corpus, and use the dialect corpus in the target parallel corpus pair as the target corpus.
8. The device according to any one of claims 5 to 7, characterized in that: Also includes: The second training module is used to select a target standard language corpus from the multiple standard language corpora acquired in advance; use the target standard language corpus as the input corpus and target corpus of the original language model, pre-train the original language model, and use the original language model as the pre-training model when a preset pre-training end condition is met.
Citation Information
Patent Citations
Pre-training method and device of intelligent translation model and storage medium
CN111460838A
System for developing word-pronunciation pairs
US20020013707A1
