Text translation method, device, electronic device and storage medium
By using machine translation models to classify and optimize the parameters of source language text, the problems of low accuracy and efficiency in offline machine translation are solved, achieving efficient and accurate text translation.
Patent Information
- Application Number
- CN202111577763.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-22
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2041-12-22
AI Technical Summary
In offline machine translation scenarios with limited hardware resources, existing machine translation models suffer from low translation accuracy and low efficiency due to the reduction in parameters.
By using machine translation models to classify source language texts, and then translating using translation parameters corresponding to semantic, structural, and translation difficulty categories, the computational load is reduced, while translation accuracy and efficiency are improved.
It achieves high-precision translation under limited hardware resources, while reducing training costs and computational load, and adapting to the hardware resource requirements of different terminals.
Smart Images

Figure CN114254662B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a text translation method, device, electronic device and storage medium. Background Art
[0002] Machine translation is the process of using computers to convert one natural language (source language) into another natural language (target language). Currently, source language texts are mostly translated through machine translation models.
[0003] For offline machine translation (local translation) scenarios with limited hardware resources, the scale of the machine translation model is often compressed by reducing the parameters of the machine translation model so that the compressed machine translation model can be suitable for limited hardware resources. However, the translation accuracy of the compressed machine translation model is low. Summary of the invention
[0004] The present invention provides a text translation method, device, electronic device and storage medium, which are used to solve the defect of low accuracy of off-line machine translation in the prior art.
[0005] The present invention provides a text translation method, comprising:
[0006] Identify the source language text;
[0007] Based on a machine translation model, the source language text is identified in a category, and the source language text is translated based on translation parameters corresponding to the identified category to obtain a target language text;
[0008] The machine translation model is trained based on sample source language texts of various categories and sample target language texts of the sample source language texts.
[0009] According to a text translation method provided by the present invention, the method includes: identifying the category of the source language text based on a machine translation model, and translating the source language text based on translation parameters corresponding to the identified category to obtain a target language text, including:
[0010] Based on the text category classification parameters in the machine translation model, performing semantic category recognition and / or structural category recognition on the source language text to obtain the semantic category and / or structural category of the source language text;
[0011] Based on the difficulty classification parameters corresponding to the semantic category and / or structural category in the machine translation model, identifying the translation difficulty of the source language text to obtain the translation difficulty category of the source language text;
[0012] The source language text is translated based on the translation parameters corresponding to the translation difficulty category in the machine translation model to obtain the target language text.
[0013] According to a text translation method provided by the present invention, based on the text category classification parameters in the machine translation model, the source language text is subjected to semantic category recognition and structural category recognition to obtain the semantic category and structural category of the source language text, including:
[0014] Based on the context encoding parameters in the machine translation model, context encoding is performed on the source language text to obtain text features of the source language text;
[0015] Based on the text category classification parameters in the machine translation model, semantic category recognition and structural category recognition are performed on the text features to obtain the semantic category and structural category of the source language text.
[0016] According to a text translation method provided by the present invention, the source language text is translated based on the translation parameters corresponding to the translation difficulty category in the machine translation model to obtain the target language text, including:
[0017] encoding the source language text based on the translation parameters corresponding to the translation difficulty category to obtain encoding features of the source language text;
[0018] The encoded features are decoded based on the universal decoding parameters in the machine translation model to obtain the target language text.
[0019] According to a text translation method provided by the present invention, the machine translation model is trained based on the following steps:
[0020] Determining an initial model of the machine translation model, and obtaining a predicted probability and a predicted translation result of the sample source language text belonging to each translation difficulty category based on the initial model;
[0021] Based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the initial model is iterated on parameters to obtain the machine translation model.
[0022] According to a text translation method provided by the present invention, the determining of the initial model of the machine translation model comprises:
[0023] Determining an original model of the initial model, and obtaining a predicted category of the sample source language text based on the original model;
[0024] Based on the difference between the predicted category and the semantic category label and / or the structural category label of the sample source language text, the original model is iterated on parameters to obtain the initial model.
[0025] According to a text translation method provided by the present invention, based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the initial model is iterated to obtain the machine translation model, including:
[0026] The general parameters in the initial model are frozen, and based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the translation parameters corresponding to each translation difficulty category in the initial model are iterated to obtain the machine translation model, wherein the general parameters are parameters other than the translation parameters corresponding to each translation difficulty category in the initial model.
[0027] The present invention also provides a text translation device, comprising:
[0028] A determination unit, used to determine the source language text;
[0029] A translation unit, configured to perform category recognition on the source language text based on a machine translation model, and translate the source language text based on translation parameters corresponding to the recognized category to obtain a target language text;
[0030] The machine translation model is trained based on sample source language texts of various categories and sample target language texts of the sample source language texts.
[0031] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any of the above-mentioned text translation methods are implemented.
[0032] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned text translation methods are implemented.
[0033] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the steps of any one of the above-mentioned text translation methods are implemented.
[0034] The text translation method, device, electronic device and storage medium provided by the present invention perform category identification on the source language text based on a machine translation model, and translate the source language text based on translation parameters corresponding to the identified categories to obtain a target language text. Compared with the scheme in which the machine translation model in the traditional method translates the source language text based on a large number of translation parameters, the embodiment of the present invention uses the translation parameters corresponding to the identified source language text categories to translate the source language text, which can not only ensure the translation accuracy, but also avoid the problem of low translation efficiency caused by calculation based on a large number of translation parameters in the traditional method. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the technical solutions in the present invention or 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 some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0036] Figure 1 It is a flowchart of the text translation method provided by the present invention;
[0037] Figure 2 is a flowchart of an implementation of step 120 in the text translation method provided by the present invention;
[0038] Figure 3 is a flowchart of an implementation method of step 121 in the text translation method provided by the present invention;
[0039] Figure 4 is a flowchart of an implementation of step 122 in the text translation method provided by the present invention;
[0040] Figure 5 It is a flow chart of a machine translation model training method in the text translation method provided by the present invention;
[0041] Figure 6 is a flowchart of an implementation of step 510 in the text translation method provided by the present invention;
[0042] Figure 7 It is a flowchart of another text translation method provided by the present invention;
[0043] Figure 8 It is a structural schematic diagram of the text translation device provided by the present invention;
[0044] Fig. 9 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0046] Machine translation includes online machine translation (cloud translation) and offline machine translation (local translation). Since online machine translation has abundant cloud resources, it can use a large-scale machine translation model to translate the source language text to achieve better translation results. However, online machine translation relies on a smooth network for data transmission, which will increase deployment and operating costs.
[0047] In order to reduce deployment and operating costs, offline machine translation that does not rely on the network for data transmission is often used to translate the source language text. However, offline machine translation hardware resources are limited and cannot embed large-scale machine translation models. At present, traditional methods mostly prune the machine translation model, that is, reduce the parameters of the model to reduce the scale of the machine translation model, but the translation effect of the pruned machine translation is poor.
[0048] In addition, since the machine translation model of offline machine translation is deployed on the terminal, and the hardware resources of different terminals are different, that is, different terminals have different requirements on the scale of the machine translation model, when the machine translation model is deployed on the terminal, it is necessary to train machine translation models of corresponding scales according to different terminals, and the training cost is relatively high.
[0049] To this end, the present invention provides a text translation method. Figure 1 It is a flowchart of the text translation method provided by the present invention, such as Figure 1 As shown, the method comprises the following steps:
[0050] Step 110: Determine the source language text.
[0051] Specifically, the source language text is the text to be translated, the language used in the source language text is the source language, the language used in the text after translation is the target language, and the corresponding translation result is the target language text. The source language text here can be directly input by the user, or can be obtained by voice transcription of the collected audio, or can be obtained by collecting images through image acquisition devices such as scanners, mobile phones, cameras, and performing OCR (Optical Character Recognition) on the images, and the embodiments of the present invention do not specifically limit this.
[0052] Step 120: Based on the machine translation model, the source language text is identified in categories, and the source language text is translated based on translation parameters corresponding to the identified categories to obtain the target language text; the machine translation model is trained based on sample source language texts of each category and sample target language texts of the sample source language texts.
[0053] Specifically, the categories corresponding to the source language text may include the semantic category of the source language text, the structural category of the source language text, the translation difficulty category of the source language text, etc. Among them, the semantic category of the source language text is used to characterize the category of the source language text from the semantic level, which can be determined according to the semantic information of the source language text. For example, the field category of the source language text can be determined according to the semantic information of the source language text, and the field category is used as the semantic category. The structural category of the source language text is used to characterize the category of the source language text from the structural level, which can be determined according to the sentence structure in the source language text. For example, the source language text can be determined to belong to a long sentence text or a short sentence text according to the sentence structure of the source language text, and it is used as the corresponding structural category. The translation difficulty category of the source language text is used to characterize the category of the source language text from the level of translation difficulty, which can be determined according to the segmentation, sentence, length, etc. of the source language text. For example, if the source language text contains more rare segmentations, the sentence structure is complex, and the length is long, it means that the translation difficulty of the source language text is greater.
[0054] The translation parameters refer to the model parameters used by the machine translation model when translating text. It is understandable that the machine translation model can be constructed based on an encoder and a decoder, and the corresponding translation parameters can be encoding parameters of the encoder, decoding parameters of the decoder, or encoding parameters of the encoder and decoding parameters of the decoder, which are not specifically limited in the embodiments of the present invention.
[0055] In addition, texts of the same category have commonalities in semantics or structure, so when the same category of text is translated using a machine translation model, the required translation parameters are basically the same. Therefore, after determining the category of the source language text, the source language text can be translated according to the translation parameters corresponding to the category of the source language text to obtain the target language text. Among them, the machine translation model contains translation parameters of multiple categories, so after obtaining the category of the source language text, the source language text can be translated using the translation parameters of the corresponding category.
[0056] When the machine translation model translates the source language text, the translation parameters of the corresponding category of the source language text have a much greater impact on the translation effect than the translation parameters of other categories, and the impact of the translation parameters of other categories on the translation effect can even be ignored. Therefore, compared with the solution in which the machine translation model in the traditional method translates the source language text based on the translation parameters of the corresponding category and the translation parameters of other categories, the embodiment of the present invention can not only ensure the translation accuracy, but also avoid the problem of low calculation efficiency caused by the need to calculate based on a large number of translation parameters in the traditional method, which in turn leads to low translation efficiency.
[0057] In addition, when translating the source language text, the embodiment of the present invention adopts the translation parameters of the corresponding category for translation, that is, the amount of running memory required for translation is small, that is, the scale of hardware resources required for the operation of the machine translation model is small, and then the machine translation model can be deployed on different terminals without the need to train the corresponding machine translation model according to the hardware resource scale of different terminals, thereby reducing the training cost of the model.
[0058] Before executing step 120, a machine translation model can be obtained through training. Specifically, the machine translation model can be trained through the following steps: first, sample source language texts of various categories are collected, and sample target language texts of the sample source language texts are determined on this basis; then, an initial model is trained based on the sample source language texts of various categories and the sample target language texts of the sample source language texts, so as to obtain a machine translation model.
[0059] The text translation method provided by the embodiment of the present invention performs category identification on the source language text based on a machine translation model, and translates the source language text based on translation parameters corresponding to the identified categories to obtain a target language text. Compared with the solution in which the machine translation model in the traditional method translates the source language text based on a large number of translation parameters, the embodiment of the present invention uses the translation parameters corresponding to the identified source language text categories to translate the source language text, which can not only ensure the translation accuracy, but also avoid the problem of low translation efficiency caused by calculation based on a large number of translation parameters in the traditional method.
[0060] Based on the above embodiments, Figure 2 1 is a flow chart of an implementation of step 120 in the text translation method provided by the present invention, and step 120 includes:
[0061] Step 121: Based on the text category classification parameters in the machine translation model, semantic category recognition and / or structural category recognition are performed on the source language text to obtain the semantic category and / or structural category of the source language text;
[0062] Step 122: Based on the difficulty classification parameters corresponding to the semantic categories and / or structural categories in the machine translation model, the source language text is identified for translation difficulty to obtain a translation difficulty category of the source language text;
[0063] Step 123: Based on the translation parameters corresponding to the translation difficulty categories in the machine translation model, the source language text is translated to obtain the target language text.
[0064] Specifically, the semantic category of the source language text is used to characterize the category of the source language text from a semantic level, which can be based on the text category classification parameters of the machine translation model to perform semantic recognition and determination on the source language text. For example, based on the text category classification parameters, the source language text can be semantically recognized to determine the field category to which the source language text belongs, and the field category can be used as the semantic category. It is understandable that the semantic information corresponding to texts of different field categories is different, and thus the translation parameters corresponding to texts of different field categories are different.
[0065] The structural category of the source language text is used to characterize the category of the source language text from a structural level, and it can identify the structure of the source language text based on the classification parameters of the machine translation model. For example, based on the classification parameters, the sentence structure of the source language text can be identified to determine whether the source language text belongs to a long sentence text or a short sentence text, and use it as the corresponding structural category. It can be understood that compared with short sentence text, long sentence text has more corresponding word segmentation and semantic information, so the number of translation parameters corresponding to long sentence text is more than the number of translation parameters corresponding to short sentence text.
[0066] After determining the semantic category and / or structural category of the source language text, the source language text is identified for translation difficulty based on the difficulty classification parameters corresponding to the semantic category and / or structural category in the machine translation model to obtain the translation difficulty category of the source language text. The translation difficulty category is used to characterize the category of the source language text from the perspective of the difficulty of translating the source language text. For example, if the source language text contains many uncommon participles, complex sentence structures, and a long text, it indicates that the translation difficulty of the source language text is relatively high, and the number of corresponding translation parameters required is relatively large; conversely, if the translation difficulty of the source language text is relatively low, the number of corresponding translation parameters required is relatively small.
[0067] After determining the translation difficulty category of the source language text, the source language text is translated based on the translation parameters corresponding to the translation difficulty category in the machine translation model to obtain the target language text.
[0068] It can be seen that the embodiment of the present invention firstly performs a coarse-grained recognition on the semantic category and / or structural category of the source language text, determines the category classification corresponding to the source language text, and then determines the coarse-grained translation parameters corresponding to the source language text based on the category classification. Then, a fine-grained recognition is performed on the translation difficulty category of the source language text, determines the translation difficulty category corresponding to the source language text, and then the coarse-grained translation parameters can be screened from the above-mentioned coarse-grained translation parameters based on the translation difficulty category to obtain fine-grained translation parameters.
[0069] For example, the machine translation model may correspond to multiple categories of candidate translation parameter groups, each of which includes multiple candidate translation parameters. After determining the semantic category and / or structural category of the source language text, a candidate translation parameter group of a corresponding category may be determined from the multiple candidate parameter translation groups, and then part or all of the candidate translation parameters may be selected from the candidate translation parameter group as corresponding translation parameters based on the translation difficulty category.
[0070] It can be seen that the embodiments of the present invention perform semantic category recognition and / or structural category recognition on the source language text based on the text category classification parameters in the machine translation model, and perform translation difficulty recognition on the source language text based on the difficulty classification parameters corresponding to the semantic categories and / or structural categories, thereby being able to accurately determine the translation parameters corresponding to the source language text, and then being able to translate the source language text based on the translation parameters corresponding to different categories, which not only ensures the translation accuracy, but also avoids the problem of low translation efficiency caused by calculation based on a large number of translation parameters in traditional methods.
[0071] Based on any of the above embodiments, Figure 3 is a flow chart of an implementation of step 121 in the text translation method provided by the present invention, such as Figure 3 As shown, step 121 includes:
[0072] Step 1211: Based on the context encoding parameters in the machine translation model, context encoding is performed on the source language text to obtain text features of the source language text;
[0073] Step 1212: Based on the text category classification parameters in the machine translation model, semantic category recognition and structural category recognition are performed on the text features to obtain the semantic category and structural category of the source language text.
[0074] Specifically, when context encoding the source language text based on the context encoding parameters in the machine translation model, the context information and syntactic structure information of the source language text can be combined to obtain the text features of the source language text, and the text features can be used to characterize the semantic information and structural information of the source language text. Optionally, when context encoding the source language text, the source language text can be context encoded based on the attention mechanism, focusing on the features with higher importance in the source language text, and then accurately obtaining the text features used to characterize the semantic information and structural information of the source language text, avoiding the influence of features with lower importance on subsequent semantic category recognition and structural category recognition.
[0075] After obtaining the text features of the source language text, since the text features are used to represent the semantic information and structural information of the source language text, semantic category recognition can be performed based on the semantic information in the text features to obtain the semantic category of the source language text, and structural category recognition can be performed based on the structural information in the text features to obtain the structural category of the source language text.
[0076] It can be seen that the embodiment of the present invention performs context encoding on the source language text based on the context encoding parameters in the machine translation model, so as to obtain text features for characterizing the semantic information and structural information of the source language text, and then can perform semantic category recognition and structural category recognition on the text features based on the text category classification parameters in the machine translation model, and accurately obtain the semantic category and structural category of the source language text.
[0077] Based on any of the above embodiments, Figure 4 is a flowchart of an implementation of step 122 in the text translation method provided by the present invention, such as Figure 4 As shown, step 122 includes:
[0078] Step 1221: Encode the source language text based on the translation parameters corresponding to the translation difficulty category to obtain encoding features of the source language text;
[0079] Step 1222: Based on the universal decoding parameters in the machine translation model, the encoded features are decoded to obtain the target language text.
[0080] Specifically, the machine translation model may correspond to multiple categories of candidate translation parameter groups, each candidate translation parameter group may correspond to a different semantic category, may correspond to a different structural category, or may correspond to a different text category, wherein the text category is a category determined based on the semantic category and the structural category. For example, if the semantic category is domain A and the structural category is long sentence text, then the corresponding text category may be the long sentence text category under domain A; or if the semantic category is domain A and the structural category is short sentence text, then the corresponding text category may be the short sentence text category under domain A.
[0081] It can be seen that the corresponding translation parameter group can be determined based on the semantic category, the corresponding translation parameter group can be determined based on the structural category, and the corresponding translation parameter group can also be determined based on the text category obtained by the semantic category and the structural category. The embodiment of the present invention does not specifically limit this. At the same time, each candidate translation parameter group is also divided into a plurality of groups, each group includes a number of translation parameters, and each group corresponds to a translation difficulty category. For example, the greater the translation difficulty, the more translation parameters are included in the corresponding group; the smaller the translation difficulty, the fewer translation parameters are included in the corresponding group. Therefore, after determining the corresponding translation parameter group based on the semantic category and / or the structural category, based on the translation difficulty category of the source language text, the corresponding translation parameters can be finely screened out from the corresponding candidate translation parameter group and used as the translation parameters of the machine translation model.
[0082] After determining the translation parameters of the machine translation model corresponding to the source language text, the source language text can be encoded based on the translation parameters to obtain the encoding features of the source language text. There are many ways to encode the source language text, such as extracting context features from the word vectors of each word segment in the input text through a long short-term memory network, or extracting text features by combining a self-attention mechanism with a FNN (Feedforward Neural Network).
[0083] After obtaining the encoding features of the source language text, the encoding features are decoded based on the universal decoding parameters in the machine translation model to obtain the target language text.
[0084] It can be seen that the embodiment of the present invention reduces the number of translation parameters for encoding the source language text based on the translation parameters corresponding to the translation difficulty categories, so that the encoding features of the source language text can be quickly and accurately obtained, and then when the encoding features are decoded based on the general encoding parameters, the target language text can be quickly and accurately obtained, thereby improving the efficiency and accuracy of machine translation.
[0085] Based on any of the above embodiments, Figure 5 is a flow chart of a machine translation model training method in a text translation method provided by the present invention, such as Figure 5 As shown in the figure, the machine translation model is trained based on the following steps:
[0086] Step 510: determining an initial model of the machine translation model, and obtaining the predicted probability and predicted translation result of the sample source language text belonging to each translation difficulty category based on the initial model;
[0087] Step 520: Based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the initial model is iterated to obtain a machine translation model.
[0088] Specifically, the initial model of the machine translation model can be understood as a pre-trained model, which can be used for semantic category recognition and / or structural category recognition. It can be obtained through supervised training based on sample source language text and category labels of the sample source language text. The category labels are used to characterize the semantic categories and / or structural categories of the sample source language text.
[0089] Therefore, after determining the initial model, the sample source language text can be input into the initial model, and the initial model can identify the semantic category and / or structural category of the sample source language text to obtain the predicted probability that the sample source language text belongs to each semantic category and / or structural category, and determine the candidate translation parameter group corresponding to the sample source language text based on the predicted probability of belonging to each semantic category and / or structural category, and then screen each parameter in the candidate translation parameter group based on the translation difficulty category of the sample source language text, and further determine the translation parameters corresponding to the sample source language text, so that the sample source language text can be translated based on the translation parameters corresponding to the sample source language text to obtain the predicted translation result of the sample source language text. Optionally, the semantic category and / or structural category corresponding to the maximum predicted probability can be used as the category of the sample source language text, and the candidate translation parameter group corresponding to the sample source language text is determined based on the category, and then the candidate parameters are screened from the candidate translation parameter group based on the predicted probability that the sample source language text belongs to each translation difficulty category. For example, a threshold (such as 0.5) may be set, and when the probability that the sample source language text belongs to each translation difficulty category is greater than the threshold, the corresponding translation difficulty category is used as the translation difficulty category of the sample source language text, and the sample source language text is translated based on the translation parameters corresponding to the translation difficulty category of the sample source language text to obtain a predicted translation result of the sample source language text.
[0090] It should be noted that in the process of training the initial model, the phenomenon of model collapse may occur, that is, the difference between the predicted probabilities of the sample source language text belonging to each translation difficulty category is small. At this time, if the translation difficulty category of the sample source language text is determined based on the threshold, the sample source language text may correspond to multiple translation difficulty categories, and the corresponding translation parameters are also a combination of translation parameters of multiple categories. In this case, the number of translation parameters for translating the sample source language text will increase, thereby increasing the computational complexity of the machine translation model, and further affecting the translation efficiency of the machine translation model.
[0091] In this regard, in the process of training the initial model, in addition to iterating the parameters of the initial model based on the difference between the predicted translation results and the sample target language text, the parameters of the initial model are also iterated based on the distribution of the predicted probability of the sample source language text belonging to each translation difficulty category, so as to avoid model collapse, so that the trained machine translation model can accurately identify the translation difficulty category of the source language text, and then accurately determine the translation parameters based on the identified translation difficulty category, so as to reduce the amount of calculation in the translation process and improve the translation efficiency of the model.
[0092] The distribution of the predicted probabilities that the sample source language text belongs to each translation difficulty category can be characterized by the mean and / or variance of the predicted probabilities that the sample source language text belongs to each translation difficulty category, and the loss function of the machine translation model can include a first loss function and a second loss function, wherein the first loss function can be determined based on the difference between the predicted translation result and the sample target language text, and the second loss function can be determined based on the mean and / or variance of the predicted probabilities that the sample source language text belongs to each translation difficulty category;
[0093] Optionally, when the second loss function is determined based on the mean and variance of the predicted probability that the sample source language text belongs to each translation difficulty category, the corresponding loss function L of the machine translation model can be calculated using the following formula:
[0094] L=L1+L2
[0095] L2=α*L a +β*L b
[0096]
[0097]
[0098] Among them, L1 represents the first loss function, L2 represents the second loss function, and L a represents the mean of the predicted probabilities that the sample source language text belongs to each translation difficulty category, L b represents the variance of the predicted probability that the sample source language text belongs to each translation difficulty category, α and β represent L a and L b The weight can be set according to the actual situation, n represents the number of categories, P i (x j ) represents the predicted probability that the sample source language text belongs to each translation difficulty category.
[0099] It can be seen that the embodiment of the present invention iterates the parameters of the initial model based on the difference between the predicted translation result and the sample target language text, as well as the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, thereby avoiding the model collapse phenomenon, so that the trained machine translation model can accurately identify the translation difficulty category of the source language text, and then accurately determine the translation parameters based on the identified category, so as to reduce the amount of calculation in the translation process and improve the translation efficiency of the model.
[0100] Based on any of the above embodiments, Figure 6 is a flowchart of an implementation of step 510 in the text translation method provided by the present invention, such as Figure 6 As shown, in step 510, determining the initial model of the machine translation model includes:
[0101] Step 511: determining an original model of the initial model, and obtaining a predicted category of the sample source language text based on the original model;
[0102] Step 512: Based on the difference between the predicted category and the semantic category label and / or structural category label of the sample source language text, perform parameter iteration on the original model to obtain an initial model.
[0103] Specifically, the initial model of the machine translation model may be obtained through supervised training based on sample source language texts and semantic category labels and / or structural category labels of the sample source language texts.
[0104] After the original model is determined, the sample source language text can be input into the original model to obtain the predicted category of the sample source language text output by the original model. Based on the difference between the predicted category and the semantic category label and / or structural category label of the sample source language text, the original model is iterated on parameters, and the obtained initial model has the ability to accurately perform semantic category recognition and / or structural category recognition on the sample source language text.
[0105] It can be seen that the embodiment of the present invention iterates the parameters of the original model based on the difference between the predicted category and the semantic category label and / or structural category label of the sample source language text, so that the obtained initial model can accurately perform semantic category recognition and / or structural category recognition on the sample source language text.
[0106] Based on any of the above embodiments, step 520 includes:
[0107] The universal parameters in the initial model are frozen, and based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the translation parameters corresponding to each translation difficulty category in the initial model are iterated to obtain a machine translation model. The universal parameters are parameters other than the translation parameters corresponding to each translation difficulty category in the initial model.
[0108] Specifically, since the initial model already has the ability to perform semantic category recognition and / or structural category recognition on the sample source language text, the general parameters of the initial model can be frozen at this time so that the initial model can perform semantic category recognition and / or structural category recognition on the sample source language text.
[0109] After freezing the common parameters in the initial model, based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the translation parameters corresponding to each translation difficulty category in the initial model are iterated, so that the initial model can optimize the translation parameters corresponding to the sample source language texts of different translation difficulty categories, so that the finally trained machine translation model not only has the ability to perform semantic category recognition and / or structural category recognition on the source language text, but also can accurately recognize the translation difficulty category of the source language text, and then translate the source language text based on the translation parameters corresponding to the recognized translation difficulty category, and then obtain the target language text.
[0110] It can be seen that after freezing the common parameters in the initial model, the embodiment of the present invention performs parameter iteration on the translation parameters corresponding to each translation difficulty category in the initial model based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, so that the trained machine translation model not only has the ability to perform semantic category recognition and / or structural category recognition on the source language text, but also can accurately identify the translation difficulty category of the source language text, and then translate the source language text based on the translation parameters corresponding to the identified translation difficulty category, and then obtain the target language text.
[0111] Based on any of the above embodiments, the present invention also provides a text translation method, which mainly translates the source language text through a machine translation model. The machine translation model can be constructed based on FNN, including a feature extraction layer, a text classification layer, a feature encoding layer and a feature decoding layer. Figure 7 It is a flowchart of another text translation method provided by the present invention, such as Figure 7 As shown, the method includes:
[0112] The source language text is input into the feature extraction layer, which encodes the context of the source language text based on the attention mechanism to obtain the text features of the source language text. Then, the text features of the source language text are input into the text classification layer, which performs semantic category recognition and structural category recognition on the source language text.
[0113] Then, the text features of the source language text are input into the difficulty classification layer, and the difficulty classification layer identifies the translation difficulty of the source language text based on the difficulty classification parameters corresponding to the semantic categories and structural categories identified by the text classification layer, and obtains the translation difficulty category of the source language text.
[0114] Next, the text features are input into the feature encoding layer, and the feature encoding layer performs feature encoding on the text features based on the translation parameters corresponding to the translation difficulty categories identified by the difficulty classification layer, and obtains the encoding features of the source language text. Next, the encoding features are input into the feature decoding layer, and the encoding features are decoded by the feature decoding layer to obtain the target language text. Among them, the embodiment of the present invention can first determine the candidate translation parameter group of the corresponding category from multiple candidate translation parameter groups based on the semantic category and the structural category, and then determine part or all of the parameters from the candidate translation parameter group as translation parameters based on the translation difficulty category. For example, assuming that there are 8 groups of candidate translation parameter groups, the prediction probability that the source language text belongs to each semantic category and structural category can be determined, and then the candidate translation parameter group corresponding to the maximum prediction probability is used as the candidate translation parameter group of the source language text, and then the translation parameters are determined from the candidate translation parameter group based on the translation difficulty category of the source language text.
[0115] Optionally, when determining the translation parameters corresponding to the source language text, the calculation formula FFN(x)=w2*f(w1*x+b1)+b2 can be used, where w1 and w2 represent the translation parameters after matrix grouping. It can be seen from the formula that the larger the matrix dimensions of w1 and w2, the larger the translation calculation amount. In order to reduce the translation calculation amount, the corresponding grouping translation parameters are determined from multiple groups based on the semantic categories and structural categories corresponding to the source language text, and then the grouping parameters are further screened based on the translation difficulty category of the source language text to obtain the translation parameters corresponding to the source language text, thereby reducing the parameters required for the source language text during translation, that is, reducing the matrix dimensions of w1 and w2, thereby reducing the calculation amount of text translation.
[0116] Among them, the machine translation model is trained based on the following steps:
[0117] The original model of the machine translation model is determined, and the sample source language text is input into the original model to obtain the predicted category of the sample source language text; based on the difference between the predicted category and the semantic category label and structural category label of the sample source language text, the parameters of the original model are iterated to obtain the initial model of the machine translation model. The initial model has the ability to perform semantic category recognition and structural category recognition on the sample source language text.
[0118] Then, the parameters except the translation parameters corresponding to each translation difficulty category in the initial model are frozen, and the sample source language text is input into the initial model to obtain the predicted probability that the sample source language text belongs to each translation difficulty category and the predicted translation result of the sample source language text. Based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the translation parameters corresponding to each translation difficulty category in the initial model are iterated to obtain a machine translation model. Among them, the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category can be determined based on the mean and variance of the predicted probability that the sample source language text belongs to each translation difficulty category.
[0119] The text translation device provided by the present invention is described below. The text translation device described below and the text translation method described above can be referred to each other.
[0120] Based on any of the above embodiments, Figure 8 is a schematic diagram of the structure of the text translation device provided by the present invention, such as Figure 8 As shown, the device comprises:
[0121] A determination unit 810, configured to determine a source language text;
[0122] A translation unit 820 is used to identify the category of the source language text based on a machine translation model, and translate the source language text based on translation parameters corresponding to the identified category to obtain a target language text;
[0123] The machine translation model is trained based on sample source language texts of various categories and sample target language texts of the sample source language texts.
[0124] Based on any of the above embodiments, the translation unit 820 includes:
[0125] A text category classification unit, configured to perform semantic category recognition and / or structural category recognition on the source language text based on the text category classification parameters in the machine translation model, so as to obtain the semantic category and / or structural category of the source language text;
[0126] A difficulty classification unit, configured to identify the translation difficulty of the source language text based on the difficulty classification parameters corresponding to the semantic category and / or structural category in the machine translation model, and obtain the translation difficulty category of the source language text;
[0127] The translation subunit is used to translate the source language text based on the translation parameters corresponding to the translation difficulty category in the machine translation model to obtain the target language text.
[0128] Based on any of the above embodiments, the classification unit includes:
[0129] A context encoding unit, configured to perform context encoding on the source language text based on context encoding parameters in the machine translation model to obtain text features of the source language text;
[0130] The recognition unit is used to perform semantic category recognition and structural category recognition on the text features based on the text category classification parameters in the machine translation model to obtain the semantic category and structural category of the source language text.
[0131] Based on any of the above embodiments, the translation subunit comprises:
[0132] A text encoding unit, configured to encode the source language text based on the translation parameters corresponding to the translation difficulty category to obtain encoding features of the source language text;
[0133] A decoding unit is used to decode the encoding feature based on the universal decoding parameters in the machine translation model to obtain the target language text.
[0134] Based on any of the above embodiments, the device further includes:
[0135] An acquisition unit, configured to determine an initial model of the machine translation model, and acquire, based on the initial model, a predicted probability that the sample source language text belongs to each translation difficulty category and a predicted translation result;
[0136] The first training unit is used to iterate the parameters of the initial model based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, so as to obtain the machine translation model.
[0137] Based on any of the above embodiments, the acquisition unit includes:
[0138] An original model determination unit, used to determine an original model of the initial model, and obtain a predicted category of the sample source language text based on the original model;
[0139] The second training unit is used to perform parameter iteration on the original model based on the difference between the predicted category and the semantic category label and / or the structural category label of the sample source language text to obtain the initial model.
[0140] Based on any of the foregoing embodiments, the first training unit is used to:
[0141] The general parameters in the initial model are frozen, and based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the translation parameters corresponding to each translation difficulty category in the initial model are iterated to obtain the machine translation model, wherein the general parameters are parameters other than the translation parameters corresponding to each translation difficulty category in the initial model.
[0142] Fig. 9 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Fig. 9 As shown, the electronic device may include: a processor 910, a memory 920, a communications interface 930 and a communications bus 940, wherein the processor 910, the memory 920 and the communications interface 930 communicate with each other through the communications bus 940. The processor 910 may call the logic instructions in the memory 920 to execute the text translation method, which includes: determining a source language text; based on a machine translation model, performing category recognition on the source language text, and translating the source language text based on the translation parameters corresponding to the recognized category to obtain a target language text; the machine translation model is trained based on sample source language texts of various categories and sample target language texts of the sample source language texts.
[0143] In addition, the logic instructions in the above-mentioned memory 920 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0144] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the text translation method provided by the above methods, and the method includes: determining a source language text; based on a machine translation model, performing category recognition on the source language text, and translating the source language text based on translation parameters corresponding to the recognized category to obtain a target language text; the machine translation model is trained based on sample source language texts of each category and sample target language texts of the sample source language texts.
[0145] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the above-mentioned text translation methods, the methods comprising: determining a source language text; based on a machine translation model, performing category recognition on the source language text, and translating the source language text based on translation parameters corresponding to the recognized categories to obtain a target language text; the machine translation model is trained based on sample source language texts of each category and sample target language texts of the sample source language texts.
[0146] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0147] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0148] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A text translation method, characterized in that: include: Identify the source language text; Based on a machine translation model, the source language text is identified in a category, and the source language text is translated based on a translation parameter corresponding to the identified category to obtain a target language text; The machine translation model is trained based on sample source language texts of various categories and sample target language texts of the sample source language texts; The method of identifying the category of the source language text based on the machine translation model and translating the source language text based on the translation parameters corresponding to the identified category to obtain the target language text includes: Based on the text category classification parameters in the machine translation model, performing semantic category recognition and / or structural category recognition on the source language text to obtain the semantic category and / or structural category of the source language text; Based on the difficulty classification parameters corresponding to the semantic category and / or structural category in the machine translation model, identifying the translation difficulty of the source language text to obtain the translation difficulty category of the source language text; The source language text is translated based on the translation parameters corresponding to the translation difficulty category in the machine translation model to obtain the target language text.
2. The text translation method according to claim 1, characterized in that: The step of performing semantic category recognition and structural category recognition on the source language text based on the text category classification parameters in the machine translation model to obtain the semantic category and structural category of the source language text includes: Based on the context encoding parameters in the machine translation model, context encoding is performed on the source language text to obtain text features of the source language text; Based on the text category classification parameters in the machine translation model, semantic category recognition and structural category recognition are performed on the text features to obtain the semantic category and structural category of the source language text.
3. The text translation method according to claim 1, characterized in that: The step of translating the source language text based on the translation parameters corresponding to the translation difficulty category in the machine translation model to obtain the target language text includes: encoding the source language text based on the translation parameters corresponding to the translation difficulty category to obtain encoding features of the source language text; The encoded features are decoded based on the universal decoding parameters in the machine translation model to obtain the target language text.
4. The text translation method according to any one of claims 1 to 3, characterized in that: The machine translation model is trained based on the following steps: Determining an initial model of the machine translation model, and obtaining a predicted probability and a predicted translation result of the sample source language text belonging to each translation difficulty category based on the initial model; Based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the initial model is iterated on parameters to obtain the machine translation model.
5. The text translation method according to claim 4, characterized in that: Determining the initial model of the machine translation model includes: Determining an original model of the initial model, and obtaining a predicted category of the sample source language text based on the original model; Based on the difference between the predicted category and the semantic category label and / or the structural category label of the sample source language text, the original model is iterated on parameters to obtain the initial model.
6. The text translation method according to claim 4, characterized in that: The method of performing parameter iteration on the initial model based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, to obtain the machine translation model, comprises: The general parameters in the initial model are frozen, and based on the difference between the predicted translation result and the sample target language text, and the distribution of the predicted probability that the sample source language text belongs to each translation difficulty category, the translation parameters corresponding to each translation difficulty category in the initial model are iterated to obtain the machine translation model, wherein the general parameters are parameters other than the translation parameters corresponding to each translation difficulty category in the initial model.
7. A text translation device, characterized in that: include: A determination unit, used to determine the source language text; A translation unit, configured to perform category recognition on the source language text based on a machine translation model, and translate the source language text based on translation parameters corresponding to the recognized category to obtain a target language text; The machine translation model is trained based on sample source language texts of various categories and sample target language texts of the sample source language texts; The method of identifying the category of the source language text based on the machine translation model and translating the source language text based on the translation parameters corresponding to the identified category to obtain the target language text includes: Based on the text category classification parameters in the machine translation model, performing semantic category recognition and / or structural category recognition on the source language text to obtain the semantic category and / or structural category of the source language text; Based on the difficulty classification parameters corresponding to the semantic category and / or structural category in the machine translation model, identifying the translation difficulty of the source language text to obtain the translation difficulty category of the source language text; The source language text is translated based on the translation parameters corresponding to the translation difficulty category in the machine translation model to obtain the target language text.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the text translation method according to any one of claims 1 to 6 are implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the text translation method according to any one of claims 1 to 6 are implemented.
