Text translation method, device, computer equipment and readable storage medium
By introducing the representation learning and minimizing translation differences of large language models into the translation model, the problem of the excessive mechanical results of the existing translation model is solved, and a more natural and accurate translation effect is achieved.
Patent Information
- Application Number
- CN202411312372.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2044-09-20
AI Technical Summary
The existing translation models focus on the direct correspondence between vocabulary and grammatical rules in the pre-training stage, resulting in the translation results being too mechanical and lacking natural and fluent expression.
By obtaining the text to be translated, input it into the target translation model, and using a large language model to determine the target translation result from multiple candidate translation results. The target translation model is learned by the preset translation model based on the minimization of the target loss, and the target loss is The first loss and the second loss are composed of, the first loss is determined by the difference in the translation label of the preset translation model and the large language model, and the second loss is determined by the difference in the preset translation model and the sample translation label, so as to realize the translation output of the simulated large language model. Minimize the differences in characterization learning and translation.
While ensuring the accuracy of translation, it improves the fluency of text translation and makes the translation results more natural and accurate.
Smart Images

Figure CN118839705B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of translation technology, and in particular to a text translation method, apparatus, computer device and readable storage medium. Background Art
[0002] A translation model is an artificial intelligence model used to convert text in one language into text in another language. Translation models are usually trained based on a large bilingual corpus to learn how to convert sentences in the source language into sentences in the target language.
[0003] In the related technology, the translation model in the pre-training stage mainly focuses on how to accurately translate the source text into the target language. That is to say, the translation model focuses on the direct correspondence between vocabulary and grammatical rules during training, which may cause the translation results to be too mechanical and lack the natural and fluent expression in the target language. Summary of the invention
[0004] The main purpose of the embodiments of the present application is to propose a text translation method, apparatus, computer device and readable storage medium, which can improve the fluency of text translation while ensuring the accuracy of translation model translation.
[0005] To achieve the above object, a first aspect of an embodiment of the present application proposes a text translation method, the method comprising:
[0006] Get the text to be translated;
[0007] Inputting the text to be translated into a target translation model to obtain a plurality of candidate translation results for the text to be translated;
[0008] Determining a target translation result from the plurality of candidate translation results by using a large language model;
[0009] The target translation model is obtained by learning the translation performance of a preset translation model based on minimization of target loss;
[0010] The target loss is composed of a first loss and a second loss, wherein the first loss is determined by the difference between a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model for the sample text to be translated; the second loss is determined by the difference between the first predicted translation label output by the preset translation model for the sample text to be translated and a sample translation label of the sample text to be translated;
[0011] The translation performance learning includes representation learning of a simulated large language model translation output based on minimization of a first loss, and minimization learning of a translation difference between the first predicted translation label and the sample translation label based on minimization of a second loss.
[0012] Accordingly, a second aspect of an embodiment of the present application provides a text translation device, the device comprising:
[0013] The acquisition module is used to obtain the text to be translated;
[0014] An input module, used for inputting the text to be translated into a target translation model to obtain a plurality of candidate translation results for the text to be translated;
[0015] A determination module is used to determine a target translation result from the multiple candidate translation results through a large language model; wherein the target translation model is obtained by learning the translation performance of a preset translation model based on minimization of a target loss; the target loss is composed of a first loss and a second loss, the first loss is determined by the difference between a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model for the sample text to be translated; the second loss is determined by the difference between the first predicted translation label output by the preset translation model for the sample text to be translated and a sample translation label of the sample text to be translated; the translation performance learning includes representation learning of the translation output of the simulated large language model based on minimization of the first loss, and minimization learning of the translation difference between the first predicted translation label and the sample translation label based on minimization of the second loss.
[0016] In some implementations, the determining module is further configured to:
[0017] Acquire at least one context example information corresponding to the text to be translated; wherein each of the context example information includes context prompt information, context instruction information and context reply information;
[0018] Generating corresponding translation instruction information according to the multiple candidate translation results;
[0019] Acquiring a logical pattern when the context prompt information and the context instruction information are generated by the large language model, and determining translation reply information corresponding to the context prompt information and the translation instruction information with reference to the logical pattern;
[0020] Based on the translation reply information, a target translation result is determined.
[0021] In some implementations, the text translation device further includes a training module for:
[0022] Obtaining an initial sample training set, and preprocessing the initial sample training set to obtain a target sample training set;
[0023] For each sample text to be translated in the target sample training set, the sample text to be translated is input into a preset translation model and a large language model to obtain a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model;
[0024] determining a first loss of the preset translation model based on a difference between the first predicted translation label and the second predicted translation label;
[0025] Obtaining a sample translation label of the sample text to be translated, and determining a second loss of the preset translation model based on a difference between the first predicted translation label and the sample translation label;
[0026] A target loss is determined according to the first loss and the second loss, and translation performance learning based on minimization of the target loss is performed on the preset translation model to obtain a target translation model.
[0027] In some embodiments, the training module is further used to:
[0028] Obtaining a plurality of first probabilities corresponding to a plurality of first translation words included in the first predicted translation label predicted by the preset translation model for the sample text to be translated, and a plurality of second probabilities corresponding to a plurality of second translation words included in the second predicted translation label predicted by the large language model for the sample text to be translated;
[0029] For each of the first translation words, determine the second probability of the second translation word corresponding thereto, and determine the first sub-loss of the preset translation model when translating the corresponding sample text to be translated based on the difference between the first probability and the second probability;
[0030] The first loss of the preset translation model is determined by using a plurality of first sub-losses of the preset translation model when translating a corresponding sample text to be translated.
[0031] In some embodiments, the training module is further used to:
[0032] Obtaining a plurality of first translation words included in the first predicted translation label output by the preset translation model for predicting the sample text to be translated;
[0033] Determining a second sub-loss of the preset translation model when translating the corresponding sample text to be translated according to differences between the multiple first translation words and the multiple target translation words included in the sample translation tags corresponding to the sample text to be translated;
[0034] The second loss of the preset translation model is determined by using a plurality of second sub-losses of the preset translation model when translating a corresponding sample text to be translated.
[0035] In some embodiments, the training module is further used to:
[0036] Obtaining a first weight of the first loss and a second weight of the second loss; wherein the first weight is less than the second weight;
[0037] Adjusting the first loss based on the first weight to obtain a first target loss;
[0038] Adjusting the second loss based on the second weight to obtain a second target loss;
[0039] Based on the first target loss and the second target loss, a target loss of the preset translation model is determined.
[0040] In some embodiments, the training module is further used to:
[0041] Acquire multiple initial language pairs in the initial sample training set; wherein the initial language pairs include initial sample texts to be translated and corresponding initial sample translation labels;
[0042] For each of the initial language pairs, calculating the perplexity of the initial language pair;
[0043] Obtaining a preset perplexity threshold, and filtering out the initial language pairs whose perplexity is lower than the perplexity threshold, to obtain a plurality of target language pairs; wherein the target language pairs include sample texts to be translated and corresponding sample translation labels;
[0044] Based on the multiple target language pairs, a target sample training set is obtained.
[0045] To achieve the above-mentioned purpose, the third aspect of the embodiments of the present application proposes a computer device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the text translation method described in any one of the embodiments of the first aspect of the present application when executing the computer program.
[0046] To achieve the above-mentioned purpose, the fourth aspect of the embodiments of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the text translation method described in any one of the embodiments of the first aspect of the present application.
[0047] The embodiment of the present application obtains a text to be translated; inputs the text to be translated into a target translation model to obtain a plurality of candidate translation results for the text to be translated; determines a target translation result from the plurality of candidate translation results through a large language model; wherein the target translation model is obtained by learning the translation performance of a preset translation model based on minimization of a target loss; the target loss is composed of a first loss and a second loss, the first loss being determined by the difference between a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model for the sample text to be translated; the second loss being determined by the difference between the first predicted translation label output by the preset translation model for the sample text to be translated and the sample translation label of the sample text to be translated Difference determination; translation performance learning includes representation learning of the translation output of the simulated large language model based on minimization of the first loss, and minimization learning of the translation difference between the first predicted translation label and the sample translation label based on minimization of the second loss; in this way, the output of the large language model can be used as a reference to construct the first loss of the target translation model and the large language model, so that the first predicted translation label output by the translation model can tend to the expression of the large language model, so that the translation result output by the target translation model is more fluent; at the same time, the second loss is constructed by the difference between the first predicted translation label output by the translation model and the actual sample translation label of the sample text to be translated, which can improve the accuracy of the translation model in translating text. In summary, the present application can improve the fluency of text translation while ensuring the translation accuracy of the translation model. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 It is a schematic diagram of the architecture of the text translation system provided in the embodiment of the present application;
[0049] Figure 2 is a flowchart of a text translation method provided in an embodiment of the present application;
[0050] Figure 3 is a schematic diagram of example context information provided by an embodiment of the present application;
[0051] Figure 4 is a flowchart of training a preset translation model provided in an embodiment of the present application;
[0052] Figure 5 It is an overall flow chart of the text translation method provided in the embodiment of the present application;
[0053] Figure 6 is a schematic diagram of the functional modules of the text translation device provided in an embodiment of the present application;
[0054] Figure 7 It is a schematic diagram of the hardware structure of the computer device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0056] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0058] A translation model is an artificial intelligence model used to convert text in one language into text in another language. Translation models are usually trained based on a large bilingual corpus to learn how to convert sentences in the source language into sentences in the target language.
[0059] In the related technology, the translation model in the pre-training stage mainly focuses on how to accurately translate the source text into the target language. That is to say, the translation model focuses on the direct correspondence between vocabulary and grammatical rules during training, which may cause the translation results to be too mechanical and lack the natural and fluent expression in the target language.
[0060] Based on this, the embodiments of the present application provide a text translation method, apparatus, computer device and readable storage medium, which can improve the fluency of text translation while ensuring the accuracy of translation model translation.
[0061] The text translation method, apparatus, computer device, and readable storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the text translation system in the embodiments of the present application is described.
[0062] Please refer to Figure 1 In some implementations, an embodiment of the present application provides a text translation system, including a terminal 11 and a server 12 .
[0063] Exemplarily, the terminal 11 may be a smart phone, a tablet computer, a personal computer, etc. A user may input text to be translated through the terminal 11, and the terminal 11 may perform preliminary text preprocessing, such as removing HyperText Markup Language (HTML) tags, non-printing characters, etc., and send the data to the server 12 for further processing.
[0064] Furthermore, the server side 12 may be a high-performance server, a graphics processing unit (GPU) cluster, etc. The server side 12 may receive data from the terminal 11 , perform large-scale data processing and model training tasks, and feed back the target translation result or model training result to the terminal 11 .
[0065] The text translation method in the embodiments of the present application can be illustrated by the following embodiments.
[0066] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to user identity or characteristics such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first. Moreover, the collection, use, and processing of these data will comply with relevant laws, regulations, and standards. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or separate consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the user's separate permission or separate consent, the necessary user-related data for enabling the normal operation of the embodiment of the present application will be obtained.
[0067] In the embodiments of the present application, the text translation device will be described from the perspective of the text translation device, which can be integrated into a computer device. Figure 2 , Figure 2 This is a flowchart of the steps of the text translation method provided in the embodiment of the present application. In the embodiment of the present application, the text translation device is specifically integrated on a terminal or a server as an example. When the processor on the terminal or the server executes the program instructions corresponding to the text translation method, the specific process is as follows:
[0068] Step 101: Obtain the text to be translated.
[0069] In some implementations, in order to clarify the translation requirements, the text to be translated may be obtained so as to facilitate subsequent accurate translation of the text to be translated.
[0070] The text to be translated may be the original text or content that needs to be translated into another language. For example, when translating Chinese into English, the text related to Chinese is the text to be translated.
[0071] Exemplarily, the text to be translated can be obtained by manual input, file uploading, web crawling, database crawling, etc.
[0072] Specifically, the text to be translated can be a sentence, a paragraph, an article or any other form of written content, or the text to be translated can also be speech. Furthermore, the text to be translated can come from various channels, such as document content, web page content, email, comments or posts on social media, film and television scripts or subtitles, etc.
[0073] In some implementations, the language of the text to be translated may be Chinese, English, French, etc., and the language of the target translation result to be translated may also be any language, which is not limited in the embodiments of the present application.
[0074] By obtaining the text to be translated, it is possible to subsequently translate the text to be translated using a target translation model.
[0075] Step 102: input the text to be translated into the target translation model to obtain a plurality of candidate translation results for the text to be translated.
[0076] In some implementations, in order to quickly obtain the translation result of the text to be translated, the text to be translated may be input into a trained target training model to obtain a corresponding plurality of candidate translation results, so as to cover more expressions.
[0077] The target translation model may be a translation model optimized through a specific training process. The target translation model is obtained by training a preset translation model, and can express the translation fluently while having accurate translation capabilities.
[0078] The candidate translation results may be a series of possible translation outputs generated by the target translation model for a given text to be translated. The candidate translation results provide different translation options so that the best target translation result can be selected from them later.
[0079] In some implementations, only one candidate translation result may be generated, in which case the candidate translation result may be directly output as the target translation result. When there are multiple candidate translation results, the candidate translation results may be 2, 3, 5, etc., and may be specifically output according to corresponding settings.
[0080] In some embodiments, the generator interface parameters of the target translation model, that is, the interface parameters of the decoding part of the target translation model, can be adjusted to obtain multiple candidate translation results. For example, since the beam width parameter controls the number of candidate sequences retained during the decoding process, the number of candidate translation results can be increased by increasing the beam width parameter. It is understandable that the target translation model is adjusted to generate multiple candidate translation results in a manner not limited to adjusting the beam width parameter, but can also be adjusted in other ways, and the embodiments of the present application do not make specific restrictions here.
[0081] By generating multiple candidate translation results, the diversity of the final translation results can be increased, so that the highest quality candidate translation result can be finally selected as the target translation result, thereby improving the accuracy of the translation.
[0082] Step 103: determine a target translation result from multiple candidate translation results using a large language model.
[0083] The target translation model is obtained by learning the translation performance of the preset translation model based on minimization of the target loss;
[0084] The target loss is composed of a first loss and a second loss, wherein the first loss is determined by the difference between a first predicted translation label output by a preset translation model for each sample text to be translated and a second predicted translation label output by a large language model for the sample text to be translated; the second loss is determined by the difference between the first predicted translation label output by the preset translation model for the sample text to be translated and a sample translation label of the sample text to be translated;
[0085] Translation performance learning includes representation learning of a simulated large language model translation output based on minimizing a first loss, and minimizing translation difference learning between a first predicted translation label and a sample translation label based on minimizing a second loss.
[0086] In some embodiments, since the large language model has better language understanding and generation capabilities, can capture a wider range of language patterns and contextual information, and can help screen out the most natural and accurate translation results, multiple candidate translation results can be input into the large language model, and the large language model can be used to select the candidate translation result with the best performance as the target translation result.
[0087] Among them, the large language model can be a pre-trained language model with a large parameter scale, and the large language model can be pre-trained through large-scale unlabeled text data to learn language structure and patterns. In this application, the large language models used are all trained large language models, such as the ChatGPT series models.
[0088] The target translation result may be an optimal translation result determined by the large language model from a plurality of candidate translation results output by the target translation model.
[0089] The preset translation model may be a translation model that needs to be trained. After the preset translation model is trained and reaches a preset convergence condition, a target translation model may be obtained.
[0090] The target loss may be the total loss obtained by adding the first loss and the second loss. Furthermore, the target loss may be the total loss obtained by adding the first loss and the second loss after weight adjustment of the first loss and the second loss. The target loss is used to train the preset translation model. By minimizing the target loss, the target translation model can learn the natural expression of the large language model and translate the text to be translated more accurately.
[0091] Among them, the first loss can be used to measure the difference, that is, the similarity, between the probability distribution corresponding to the first predicted translation label output by the preset translation model and the probability distribution of the second predicted translation label output by the large language model, so that the preset translation model can learn the representation ability of the large language model from the probability distribution of the large language model by minimizing the first loss.
[0092] The second loss can be used to measure the difference between the probability distribution corresponding to the first predicted translation label output by the preset translation model and the actual sample translation label (true value). In this way, the preset translation model can gradually improve the accuracy of translation by minimizing the second loss.
[0093] The sample text to be translated may be a sample for training a preset translation model, and the sample text to be translated may be a source language sentence and its corresponding sample translation label.
[0094] The first predicted translation label may be a prediction result obtained by a preset translation model for the sample text to be translated.
[0095] The second predicted translation label may be a prediction result obtained by the large language model for the sample text to be translated.
[0096] The sample translation label may be the correct translation result of the sample text to be translated, that is, the correct and standard target language sentence corresponding to the source language sentence. The sample translation label may be used to verify the accuracy of the translation of the preset translation model.
[0097] In some embodiments, the preset translation model can be optimized by minimizing the first loss, so that the preset translation model can better simulate the output of the large language model, that is, the preset translation model can output a more fluent translation in the actual translation process. In addition, the preset translation model is optimized by minimizing the second loss, so that the preset translation model can generate a result that is more consistent with the standard translation. Therefore, by combining the first loss and the second loss to obtain the target loss, and adjusting the parameters of the preset translation model based on the target loss, two different types of supervisory signals can be combined to improve the quality and accuracy of the translation of the preset translation model during the translation process.
[0098] Exemplarily, by constructing context example information, the large language model can determine the target translation result from multiple candidate translation results with reference to the context example information, and at the same time, provide a chain of thought when generating the target translation result. In short, the large language model can adopt a method of context learning combined with a chain of thought, refer to the logical model of the context example information, and the way of thinking of generating the corresponding target translation result, determine the target translation result from multiple candidate translation results, and provide a chain of thought for generating the target translation result.
[0099] In some implementations, when the target translation model generates only one candidate translation result, the candidate translation result can be directly used as the target translation result without selecting it through a large language model.
[0100] The embodiment of the present application obtains a text to be translated; inputs the text to be translated into a target translation model to obtain a plurality of candidate translation results for the text to be translated; determines a target translation result from the plurality of candidate translation results through a large language model; wherein the target translation model is obtained by learning the translation performance of a preset translation model based on minimization of a target loss; the target loss is composed of a first loss and a second loss, the first loss being determined by the difference between a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model for the sample text to be translated; the second loss being determined by the difference between the first predicted translation label output by the preset translation model for the sample text to be translated and the sample translation label of the sample text to be translated Difference determination; translation performance learning includes representation learning of the translation output of the simulated large language model based on minimization of the first loss, and minimization learning of the translation difference between the first predicted translation label and the sample translation label based on minimization of the second loss; in this way, the output of the large language model can be used as a reference to construct the first loss of the target translation model and the large language model, so that the first predicted translation label output by the translation model can tend to the expression of the large language model, so that the translation result output by the target translation model is more fluent; at the same time, the second loss is constructed by the difference between the first predicted translation label output by the translation model and the actual sample translation label of the sample text to be translated, which can improve the accuracy of the translation model in translating text. In summary, the present application can improve the fluency of text translation while ensuring the translation accuracy of the translation model.
[0101] In some implementations, in order to help the large language model select a more reasonable and logical target translation result, the target translation result can be generated by combining context learning with a thinking chain to ensure the accuracy of the final result. For example, step 103 may include:
[0102] (103.1) Acquire at least one context example information corresponding to the text to be translated; wherein each context example information includes context prompt information, context instruction information and context reply information;
[0103] (103.2) generating corresponding translation instruction information according to the plurality of candidate translation results;
[0104] (103.3) obtaining the logical pattern of the context prompt information and the context instruction information when generating the context reply information through the large language model, and determining the translation reply information corresponding to the context prompt information and the translation instruction information with reference to the logical pattern;
[0105] (103.4) Determine the target translation result based on the translation response information.
[0106] The context example information may be a specific example of a task for guiding a large language model to select a target translation result.
[0107] Among them, the contextual prompt information can be the background information provided to the large language model, which helps to guide the subsequent actions of the large language model.
[0108] The context instruction information may be information that instructs the large language model to perform a specific task in a context example, such as a translation result selection instruction.
[0109] The contextual reply information may be a response generated by the large language model based on the contextual prompt information and the contextual instruction information. As part of the contextual example information, the contextual reply information may be used to show the correct answer format and content so that the large language model can learn how to generate similar answer patterns based on different instructions and gradually acquire the ability to generate similar answer patterns based on different instructions.
[0110] The translation instruction information may be a specific instruction generated based on the current multiple candidate translation results, and is used to guide the task that the large language model currently needs to perform.
[0111] The logical model may be a generation rule for the large language model to generate contextual response information after given contextual prompt information and contextual instruction information. According to the logical model, the large language model can learn how to correctly generate translation response information.
[0112] The translation response information may be a response to the translation instruction information made by the large language model based on the logical pattern learned by the context example information.
[0113] Please refer to Figure 3 , exemplarily, the context example information may include context prompt information, context instruction information and context reply information.
[0114] Exemplarily, the context prompt information may be: The following is a description of a task, please give an appropriate response to the task.
[0115] The contextual instruction information may be: Given the Chinese sentence "All roads lead to Rome.", there are three English translations below. Please select the best translation and explain the reasons for selecting this translation as the best translation:
[0116] [1]All roads lead to Rome.
[0117] [2]Every path reaches Rome.
[0118] [3]Various routes end at Rome.
[0119] Furthermore, the contextual response information may be: The first translation is the most appropriate translation because it is a well-known English idiom used to indicate that there are multiple ways to achieve a goal, which is completely consistent with the meaning of the original sentence. Therefore, the answer is option 1.
[0120] Exemplarily, the large language model can generate a reply to the current translation instruction information with reference to the context example information. Specifically, in the process of selecting the target translation result from multiple candidate translation results, the example context prompt information can be used, or a new context prompt information can be set, and this application does not make specific restrictions on this.
[0121] Furthermore, the contextual instruction information can be referred to to generate the translation instruction information of the current task. For example, if the candidate translation result is:
[0122] [1]Reading a book a hundred times, its meaning will become clear.
[0123] [2]After reading a text a hundred times, the meaning will be revealed.
[0124] [3]Read a text a hundred times and the meaning will naturally become apparent.
[0125] Then corresponding translation instruction information can be generated according to multiple candidate translation results, specifically:
[0126] Given the Chinese sentence "Read a book a hundred times and its meaning will become clear", there are three English translations below. Please choose the best translation and explain why you choose this translation as the best translation:
[0127] [1]Reading a book a hundred times, its meaning will become clear.
[0128] [2]After reading a text a hundred times, the meaning will be revealed.
[0129] [3]Read a text a hundred times and the meaning will naturally become apparent.
[0130] Furthermore, the logical pattern when generating context reply information according to the context prompt information and the context instruction information can be referred to in the context example information, and the translation reply information corresponding to the context prompt information and the translation information can be generated by referring to the logical pattern through the large language model, so that the large language model can generate a reply similar to the context reply information, and generate the differences between different candidate translation results and the reasons for selecting the optimal translation, so as to improve the accuracy of the translation.
[0131] Exemplarily, referring to the context example information, the above translation reply information may be: the third translation is aligned with the original text, the expression is more fluent, and the answer is 3.
[0132] Specifically, the In Context Learning method can enable the large language model to select more appropriate candidate translation results based on the provided context examples. By combining context learning with thought chaining, the large language model can perform reasoning before selecting the target translation result, which helps the large language model determine a more reasonable and logical target translation result.
[0133] It is understandable that the above-mentioned contextual prompts and contextual instructions are constructed as an example only, and different expressions can be used in actual applications as long as they do not deviate from the concept of this application. For example, the form of the translation reply information generated by the large language model may be different, but in the end, the target translation result will be selected from multiple candidate translation results, and the thinking chain for selecting the current target translation result will be given.
[0134] Through the above method, the large language model can not only output the target translation result, but also explain why the target translation result is determined to be the optimal solution, thereby improving the transparency and explainability of the entire selection process and improving the accuracy and naturalness of the final target translation result.
[0135] Please refer to Figure 4In some embodiments, in order to enable the target translation model to have both accurate and fluent translation capabilities, the preset translation model can be trained by combining the first loss and the second loss. The first loss can be the Kullback-Leibler divergence (KL divergence) loss that measures the similarity between the first predicted translation label output by the preset translation model and the second predicted translation label output by the large language model; the second loss can be the cross-entropy loss that measures the difference between the first predicted translation label output by the preset translation model and the sample translation label. Training the preset translation model with the target loss constructed by the first loss and the second loss can enable the preset translation model to improve the quality and naturalness of translation while maintaining accuracy. For example, the process of training the preset translation model to obtain the target translation model is as follows:
[0136] Step 201: obtain an initial sample training set, and preprocess the initial sample training set to obtain a target sample training set.
[0137] Among them, the initial sample training set is the original data set that has not been preprocessed, and the initial sample training set is the basic training data for the translation task.
[0138] The target sample training set may be a preprocessed training data set.
[0139] For example, the initial sample training set can be formed by crawling parallel corpus webpage content, obtaining from public parallel corpus libraries, purchasing from corpus companies, etc. Parallel corpus is the initial language pair used to train the preset translation model. For example, if you want to train the preset translation model from Chinese to English, a pair of parallel corpus is a Chinese sentence and an English sentence that express the same semantics.
[0140] For example, after the initial sample training set is collected, it needs to be cleaned and filtered due to its complex sources and uneven quality, and initial language pairs with poor quality need to be removed to avoid affecting the training effect of the preset translation model.
[0141] For example, the cleaning of initial language pairs can be divided into rule-based cleaning and neural network-based cleaning. Rule-based cleaning preliminarily screens the initial language pairs by formulating preset cleaning rules (such as whether it contains sensitive words, whether it is the corresponding language, whether it meets the sentence length limit, the number of garbled symbols, etc.). Neural network-based cleaning performs semantic-level screening by calculating the semantic similarity between the initial language pairs, and removes the initial language pairs with insufficient semantic similarity.
[0142] Furthermore, after the initial language pairs are cleaned, the perplexity of each initial language pair can be calculated using a large language model, and the initial language pairs with perplexity higher than a perplexity threshold can be filtered out.
[0143] Furthermore, after the initial language pair is cleaned and filtered, the initial language pair can be preprocessed. Preprocessing is divided into public preprocessing and language preprocessing. Among them, public preprocessing uses all languages, such as standardizing punctuation marks, removing non-printing characters, etc. Language preprocessing performs targeted preprocessing for different languages, such as word segmentation for Chinese and Japanese.
[0144] In some implementations, in order to ensure the quality of the target sample training set, each initial language pair may be cleaned and then evaluated to ensure the reliability of the target sample training set, thereby improving the performance of the target translation model. For example, the "preprocessing the initial sample training set to obtain the target sample training set" in step 201 may include:
[0145] (201.1) Obtain multiple initial language pairs in the initial sample training set; wherein the initial language pairs include initial sample texts to be translated and corresponding initial sample translation labels;
[0146] (201.2) For each initial language pair, calculate the perplexity of the initial language pair;
[0147] (201.3) obtaining a preset perplexity threshold, and filtering out the initial language pairs whose perplexity is lower than the perplexity threshold, to obtain a plurality of target language pairs; wherein the target language pairs include sample texts to be translated and corresponding sample translation labels;
[0148] (201.4) Based on multiple target language pairs, a target sample training set is obtained.
[0149] The initial language pair may be a language pair consisting of an initial sample text to be translated and its corresponding initial sample label to be translated. The initial language pair has not been screened, and there may be a situation where the initial sample translated text and the initial sample translation label cannot correspond.
[0150] The initial sample text to be translated may be a source language sentence that needs to be translated.
[0151] The initial sample translation label may be a reference translation corresponding to the initial sample text to be translated.
[0152] Among them, the perplexity can be an indicator for evaluating the probability of a preset translation model, and can be used to measure the uncertainty of the preset translation model when evaluating the corresponding initial language pair.
[0153] The perplexity threshold may be a preset value used as a standard for evaluating whether the perplexity meets the requirements.
[0154] Among them, the target language pair can be a higher quality language pair retained after screening, usually with lower perplexity, and will be used to train the preset translation model.
[0155] For example, the average log probability can be used to calculate the perplexity of the corresponding initial language pair. Specifically, the calculation formula of perplexity is as follows:
[0156]
[0157] in, ) is each word or character output by the large language model based on the initial sample text to be translated The probability of , n is the total number of words and characters predicted based on the initial sample text to be translated.
[0158] In some implementations, the large language model may also calculate the perplexity of the initial sentence pair in other ways, the specific ways of which are not listed here one by one.
[0159] For example, if in the initial sample training set, there is an initial language pair 1, the corresponding perplexity is 12; there is an initial language pair 2, the corresponding perplexity is 18; there is an initial language pair 3, the corresponding perplexity is 6; there is an initial language pair 4, the corresponding perplexity is 22. The perplexity threshold is 15, then it can be determined that the perplexity of the initial language pair 1 and the initial language pair 3 is lower than the perplexity threshold, indicating that when the preset translation model translates the initial language pair 1 and the initial language pair 3, the translation certainty is higher, and a higher probability estimate can be obtained during translation, which helps the preset translation model learn more accurate translation rules.
[0160] Furthermore, if the perplexity of initial language pair 2 and initial language pair 4 is higher than the perplexity threshold, it indicates that when the preset translation model predicts initial language pair 2 and initial language pair 4, the certainty of their translation is low, that is, the probability estimate given is low, which may cause the preset translation model to learn inaccurate translation rules. Therefore, initial language pair 1 and initial language pair 3 can be determined as the target language pair, and the target sample training set can be obtained based on initial language pair 1 and initial language pair 3. The above scheme is only an example, and in actual situations, the target sample training set can include a larger number of target language pairs.
[0161] By screening multiple initial language pairs in the initial sample training set through perplexity, initial language pairs that are difficult to predict or have problems with the preset translation model can be excluded, thereby improving the quality of training data and facilitating subsequent improvement of training efficiency and accuracy.
[0162] Step 202: for each sample text to be translated in the target sample training set, the sample text to be translated is input into a preset translation model and a large language model to obtain a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model.
[0163] In some embodiments, in order to improve the accuracy and quality of translation performed by a preset translation model by combining the prediction results of the preset translation model and the large language model, a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model can be obtained to facilitate subsequent calculation of the first loss of the preset translation model.
[0164] The first predicted translation tag may be a translation result output by a preset translation model for each sample text to be translated. The first predicted translation tag may be a word, a phrase or a whole sentence of the sample text to be translated, depending on the output format of the preset translation model.
[0165] The second predicted translation label may be a translation result output by the large language model for each sample text to be translated. The second predicted translation label may be a word, a phrase, or an entire sentence of the sample text to be translated, depending on the output format of the preset translation model. The output format of the second predicted translation label is the same as the output format of the first predicted translation label.
[0166] For example, when the sample text to be translated is “Hello, how are you?”, the first predicted translation tag may be “Hello, how are you?”, and the second predicted translation tag may be “Hello, how are you?”.
[0167] By presetting the first predicted translation label output by the translation model for each sample text to be translated and the second predicted translation label output by the large language model, it is possible to facilitate the subsequent calculation of the first loss and the second loss of the preset translation model, thereby efficiently and accurately training the preset translation model.
[0168] Step 203: Determine a first loss of a preset translation model based on a difference between the first predicted translation label and the second predicted translation label.
[0169] In some embodiments, in order to measure the similarity between the large language model and the preset translation model in the output probability distribution, the first loss of the preset translation model can be determined based on the difference between the first predicted translation label and the second predicted translation label, so as to guide the preset translation model to learn the expression of the large language model, thereby improving the quality of translation.
[0170] Among them, the first loss can be used to evaluate the degree of difference between the output of the preset translation model and the large language model when translating the sample text to be translated.
[0171] Exemplarily, the sample text to be translated can be translated by the preset translation model and the large language model, and the KL divergence loss can be calculated by the first probability of each first translated word output by the preset translation model and the second probability of each second translated word output by the large language model, and by the difference between the distribution of multiple first probabilities and the distribution of multiple second probabilities, and the calculated KL divergence loss can be used as the first loss of the preset translation model. In this way, the similarity between the output distributions of the large language model and the preset translation model can be measured by the first loss. The closer the two output distributions are, the smaller the first loss is, which means that the output of the preset translation model will continue to approach the expression of the large language model.
[0172] By quantifying the difference between the output of the preset translation model and the large language model and using it as one of the optimization targets in the training process, the output of the preset translation model can be made closer and closer to the output of the large language model, ultimately improving the quality and naturalness of the translation.
[0173] In some implementations, in order to improve the quality and naturalness of the translation of the preset translation model, the difference between the first predicted translation label and the second predicted translation label may be calculated to determine the first loss of the preset translation model, so that the preset translation model gradually reduces the difference between the language expression of the preset translation model and the large language model by minimizing the first loss, thereby improving the fluency of the expression. For example, step 203 may include:
[0174] (203.1) Obtaining a plurality of first probabilities corresponding to a plurality of first translation words included in a first predicted translation label output by a preset translation model predicting a sample text to be translated, and a plurality of second probabilities corresponding to a plurality of second translation words included in a second predicted translation label output by a large language model predicting a sample text to be translated;
[0175] (203.2) for each first translation word, determining a second probability of a corresponding second translation word, and determining a first sub-loss of a preset translation model when translating the corresponding sample text to be translated based on a difference between the first probability and the second probability;
[0176] (203.3) Determine a first loss of a preset translation model by using a plurality of first sub-losses of the preset translation model when translating a corresponding sample text to be translated.
[0177] The first translation vocabulary may be a translation vocabulary predicted by a preset translation model. The first predicted translation tag includes at least one first translation vocabulary.
[0178] The first probability may be the probability of the first translation word output by the preset translation model appearing at the current position.
[0179] The second translation vocabulary may be a translation vocabulary predicted by the large language model. The second predicted translation tag includes at least one second translation vocabulary.
[0180] The second probability may be a probability of the second translation word output by the large language model appearing at the current position.
[0181] The first sub-loss may be a loss value calculated from the difference between the first translated word and the corresponding second translated word.
[0182] Exemplarily, the sample text to be translated may be "Hello, how are you?". Assuming that the first predicted translation label output by the preset translation model is "How are you, how are you?", the first probabilities Q corresponding to the first translation words are obtained as follows: Q={"you": 0.3, "good": 0.3, "are": 0.1, "how": 0.5}. At each corresponding position to the first translation word, the second probabilities P corresponding to the second translation words are obtained as follows: P={"you": 0.3, "good": 0.3, "are": 0.05, "how": 0.05}. It can be understood that the first translation word is arranged in the same position as the corresponding second translation word.
[0183] Further, for each first translation word, the corresponding second translation word is determined. For example, if the first translation word and the corresponding second translation word are "you", the corresponding first sub-loss can be calculated. for:
[0184]
[0185] in, is the first probability, is the second probability.
[0186] Then the first loss of the preset translation model when translating the corresponding sample text to be translated is:
[0187]
[0188] in, is the first probability, is the second probability, and i is the number of the specific translation word.
[0189] By calculating the first loss, the preset translation model can be helped to minimize the first loss, better learn the language representation ability of the large language model, and improve the quality and naturalness of the translation of the preset translation model.
[0190] Step 204: Obtain a sample translation label of the sample text to be translated, and determine a second loss of the preset translation model based on the difference between the first predicted translation label and the sample translation label.
[0191] In some embodiments, in order to guide the preset translation model to learn the correct translation ability, the performance of the preset translation model can be optimized by measuring the difference between the first predicted translation label output by the preset translation model and the actual sample translation label, and minimizing the difference, so that the output of the preset translation model is as close to the actual translation label as possible.
[0192] Among them, the second loss can be used to evaluate the degree of difference between the preset translation model and the actual sample translation label when translating the sample to be translated text.
[0193] Exemplarily, the second loss may be a cross entropy loss. Specifically, the cross entropy loss may be calculated by the difference between each first translation word output by the preset translation model and multiple target translation words in the sample translation label. In this way, the second loss may be used to measure the degree of difference between the output of the preset translation model and the true sample translation label. The smaller the difference between the two, the smaller the second loss, which means that the output of the preset translation model is closer to the true sample translation label.
[0194] By calculating the second loss of the preset translation model, it is possible to ensure that the output of the preset translation model is as close to the true sample translation label as possible, thereby improving the accuracy of the translation.
[0195] In some embodiments, in order to enable the preset translation model to learn the correct translation ability and ensure that the first predicted translation label is as close as possible to the real sample translation label, the second loss of the preset translation model can be calculated to ensure that the preset translation model can generate a translation result that is consistent with the real sample translation label as much as possible. For example, "determining the second loss of the preset translation model based on the difference between the first predicted translation label and the sample translation label" in step 204 may include:
[0196] (204.1) Obtaining a plurality of first translation words included in a first predicted translation label output by a preset translation model predicting a sample text to be translated;
[0197] (204.2) determining a second sub-loss of the preset translation model when translating the corresponding sample text to be translated based on differences between the plurality of first translation words and the plurality of target translation words included in the sample translation tags corresponding to the sample text to be translated;
[0198] (204.3) Determine a second loss of a preset translation model by using a plurality of second sub-losses of the preset translation model when translating a corresponding sample text to be translated.
[0199] The target translation vocabulary is the translation vocabulary contained in the sample translation label corresponding to the sample text to be translated, and the target translation vocabulary is the vocabulary that the preset translation model should translate correctly.
[0200] For example, when the sample text to be translated is "The cat is on the mat.", the preset translation model predicts the first translation word that may appear in each position group and its probability distribution. For example, for the first position of the first predicted translation label (assuming it is from left to right), the preset translation model gives the following probability distribution:
[0201] “Le” (definite article in French): 0.8;
[0202] “chat” (French for “cat”): 0.1;
[0203] “est” (French for “yes”): 0.05;
[0204] “sur” (French for “in”): 0.03;
[0205] Other vocabulary: 0.02;
[0206] Furthermore, we can compare the difference between the probability distribution of the first translation order predicted by the preset translation model and the actual sample translation label. Assuming that the actual sample translation label is "Le chat est sur le mat.", then for the word "Le" at the first position, its actual translation label distribution will be a one-hot encoding, that is:
[0207] “Le”: 1; “chat”: 0; “est”: 0; “sur”: 0; other words: 0.
[0208] The second sub-loss can be determined for:
[0209]
[0210] in, One-hot encoding of the true target translation vocabulary; is the second probability, that is, the probability that the first translated word at the corresponding position obtained by translating the preset translation model is the same as the target translated word.
[0211] Continuing with the above example, the sub-loss for the first translated word is: -log0.8.
[0212] The second loss of the preset translation model when translating the corresponding sample text to be translated is for:
[0213]
[0214] Wherein, N is the number of first translation words of the first predicted translation label obtained by translating the preset translation model, One-hot encoding of the true target translation vocabulary; is the second probability, that is, the probability that the first translated word at the corresponding position obtained by translating the preset translation model is the same as the target translated word.
[0215] By calculating the cross entropy loss, we can ensure that the output of the preset translation model is as close as possible to the true sample translation label, thereby improving the accuracy of the translation.
[0216] Step 205 , determining a target loss according to the first loss and the second loss, and performing translation performance learning based on minimization of the target loss on the preset translation model to obtain a target translation model.
[0217] In some embodiments, in order to enable the preset translation model to produce more natural, fluent and accurate translation results, a target loss can be constructed by using the first loss and the second loss, and the preset translation model can be trained based on the target loss to obtain a model that can be faithful to the source text and generate high-quality translations.
[0218] In some implementations, the first loss and the second loss may be directly added to obtain a target loss, and translation performance learning based on minimization of the target loss may be performed on a preset translation model to obtain a target translation model.
[0219] In some implementations, the first loss and the second loss may be weighted and then added to obtain a target loss. Specifically, since the core requirement of the translation task is to ensure the accuracy of the translation result, the weight of the first loss may be set to be smaller than the weight of the second loss, for example, the weight of the first loss may be set to 0.3, and the weight of the second loss may be set to 0.7. The specific weights may be adjusted according to actual conditions.
[0220] Furthermore, when the training rounds of the preset translation model reach the preset training rounds, for example, when the training rounds reach 1000 times, the training of the preset translation model can be stopped to obtain the target translation model. The specific preset training rounds can be set according to the actual situation. Alternatively, when the target loss is lower than the loss threshold, for example, lower than 0.1, the training of the preset translation model can be stopped to obtain the target translation model. The loss threshold can be set according to the actual situation. Alternatively, when the model parameters no longer change, the training of the preset translation model can be stopped to obtain the target translation model.
[0221] By constructing the target loss through the first loss and the second loss, and training the preset translation model through the target loss, the preset translation model can produce more authentic and natural translation results while maintaining high translation quality.
[0222] In some implementations, in order to make the preset translation model have fluent expression ability while paying attention to the core translation requirements as much as possible, the weights of the first loss and the second loss can be adjusted so that the preset translation model can achieve better translation performance. For example, "determining the target loss according to the first loss and the second loss" in step 205 may include:
[0223] (205.1) Obtain a first weight of a first loss and a second weight of a second loss; wherein the first weight is less than the second weight;
[0224] (205.2) adjusting the first loss based on the first weight to obtain a first target loss;
[0225] (205.3) adjusting the second loss based on the second weight to obtain a second target loss;
[0226] (205.4) Determine a target loss of a preset translation model based on the first target loss and the second target loss.
[0227] In some embodiments, in order to ensure the accuracy of the translation results, the target loss of the preset translation model can be obtained by adding the adjusted first target loss and the second target loss, so that in the process of training the preset translation model, the training of the model can be focused while maintaining the fluency and accuracy of the translation.
[0228] The first weight may be a coefficient assigned to the first loss, used to adjust the relative importance of the first loss in the total target loss.
[0229] The second weight may be a coefficient assigned to the second loss, used to adjust the relative importance of the second loss in the total target loss.
[0230] The first target loss may be a value obtained by performing a first weight adjustment on the first loss, and the first target loss may be determined by multiplying the first loss by the first weight.
[0231] The second target loss may be a value obtained by performing a second weight adjustment on the second loss, and the second target loss may be determined by multiplying the second loss by the second weight.
[0232] The target loss may be the sum of the first target loss and the second target loss, and is used to guide the training of a preset translation model.
[0233] Specifically, the calculation formula of the target loss L is as follows:
[0234]
[0235] in, is the first weight, For the first loss; is the second weight, and CE is the second loss.
[0236] In some embodiments, Can always remain at 1, The value can be set according to the actual situation. For example, when When is 1, It can be 0.6. When is 0.7, It can be 0.3.
[0237] In some implementations, in some scenarios where the fluent expression of the preset translation model is more important, It can also be compared big.
[0238] By adjusting the ratio of the first weight to the second weight, a suitable balance can be found between the accuracy and naturalness of the translation, and the emphasis of the translation can be adjusted according to actual needs. For example, in some cases, accuracy may be given more attention, while in other cases, naturalness may be given more attention.
[0239] Please refer to Figure 5 In some embodiments, in combination Figure 5 The overall process of the present application is introduced. Exemplarily, a plurality of initial sentence pairs are first collected, and the initial sentence pairs are cleaned and filtered to obtain a target training set. Furthermore, the sample text to be translated can be respectively input into the preset translation model and the large language model to obtain the corresponding probability distribution, and then, based on the probability distribution between the two, the first loss is determined so that the preset translation model can minimize the first loss and gradually learn fluent expression ability from the large language model. At the same time, based on the first predicted label and the actual sample translation label, the second loss can be determined, and by minimizing the second loss, the translation output of the preset translation model gradually approaches the real translation. Based on the first loss and the second loss, a target loss can be combined, and the preset translation model can be trained by the target loss to obtain a target translation model, which has both the ability to accurately translate and the ability to fluently express the translation results.
[0240] Furthermore, based on the large language model, the large language model may refer to at least one provided context example information to screen multiple candidate translation results generated by the target translation model for the text to be translated to obtain a target translation result.
[0241] The embodiment of the present application obtains a text to be translated; inputs the text to be translated into a target translation model to obtain a plurality of candidate translation results for the text to be translated; determines a target translation result from the plurality of candidate translation results through a large language model; wherein the target translation model is obtained by learning the translation performance of a preset translation model based on minimization of a target loss; the target loss is composed of a first loss and a second loss, the first loss being determined by the difference between a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model for the sample text to be translated; the second loss being determined by the difference between the first predicted translation label output by the preset translation model for the sample text to be translated and the sample translation label of the sample text to be translated Difference determination; translation performance learning includes representation learning of the translation output of the simulated large language model based on minimization of the first loss, and minimization learning of the translation difference between the first predicted translation label and the sample translation label based on minimization of the second loss; in this way, the output of the large language model can be used as a reference to construct the first loss of the target translation model and the large language model, so that the first predicted translation label output by the translation model can tend to the expression of the large language model, so that the translation result output by the target translation model is more fluent; at the same time, the second loss is constructed by the difference between the first predicted translation label output by the translation model and the actual sample translation label of the sample text to be translated, which can improve the accuracy of the translation model in translating text. In summary, the present application can improve the fluency of text translation while ensuring the translation accuracy of the translation model.
[0242] See also Figure 6 The present application also provides a text translation device, which can implement the above text translation method. The text translation device includes:
[0243] An acquisition module 61 is used to acquire the text to be translated;
[0244] An input module 62, used to input the text to be translated into the target translation model to obtain a plurality of candidate translation results for the text to be translated;
[0245] A determination module 63 is used to determine a target translation result from multiple candidate translation results through a large language model; wherein the target translation model is obtained by learning the translation performance based on minimization of a target loss by a preset translation model; the target loss is composed of a first loss and a second loss, the first loss is determined by the difference between a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model for the sample text to be translated; the second loss is determined by the difference between the first predicted translation label output by the preset translation model for the sample text to be translated and the sample translation label of the sample text to be translated; the translation performance learning includes learning the representation of the translation output of the simulated large language model based on minimization of the first loss, and learning the minimization of the translation difference between the first predicted translation label and the sample translation label based on minimization of the second loss.
[0246] The specific implementation of the text translation device is basically the same as the specific implementation of the text translation method described above, and will not be repeated here. On the premise of meeting the requirements of the embodiment of the present application, the text translation device can also be provided with other functional modules to implement the text translation method in the above embodiment.
[0247] The embodiment of the present application also provides a computer device, the computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the above text translation method when executing the computer program. The computer device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0248] See also Figure 7 , Figure 7 The hardware structure of a computer device according to another embodiment is shown, and the computer device includes:
[0249] The processor 71 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0250] The memory 72 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 72 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 72, and the processor 71 is used to call and execute the text translation method of the embodiment of this application;
[0251] Input / output interface 73, used to implement information input and output;
[0252] Communication interface 74, used to realize communication interaction between the device and other devices, which can be realized by wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.);
[0253] A bus 75 that transmits information between the various components of the device (e.g., the processor 71, the memory 72, the input / output interface 73, and the communication interface 74);
[0254] The processor 71 , the memory 72 , the input / output interface 73 and the communication interface 74 are connected to each other in communication within the device via a bus 75 .
[0255] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned text translation method is implemented.
[0256] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0257] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0258] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0259] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0260] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0261] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0262] It should be understood that in the present application, "at least one (item)" and "several" refer to one or more, and "plurality" refers to two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0263] In the several embodiments provided in the present application, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are merely schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0264] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0265] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0266] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or 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 multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0267] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A text translation method, characterized in that: The method comprises: Get the text to be translated; Inputting the text to be translated into a target translation model to obtain a plurality of candidate translation results for the text to be translated; Determining a target translation result from the plurality of candidate translation results by using a large language model; The target translation model is obtained by learning the translation performance of a preset translation model based on minimization of target loss; The target loss is composed of a first loss and a second loss, wherein the first loss is determined by the difference between a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model for the sample text to be translated; the first loss is a KL divergence loss, which is used to measure the similarity between the output distributions of the large language model and the preset translation model; The second loss is determined by a difference between a first predicted translation label output by the preset translation model for the sample text to be translated and a sample translation label of the sample text to be translated; The translation performance learning includes representation learning of a simulated large language model translation output based on minimization of a first loss, and minimization learning of a translation difference between the first predicted translation label and the sample translation label based on minimization of a second loss.
2. The text translation method according to claim 1, characterized in that: The determining a target translation result from the plurality of candidate translation results by using a large language model includes: Acquire at least one context example information corresponding to the text to be translated; wherein each of the context example information includes context prompt information, context instruction information and context reply information; Generating corresponding translation instruction information according to the multiple candidate translation results; Acquiring a logical pattern when the context prompt information and the context instruction information are generated by the large language model, and determining translation reply information corresponding to the context prompt information and the translation instruction information with reference to the logical pattern; Based on the translation reply information, a target translation result is determined.
3. The text translation method according to claim 1, characterized in that: The target translation model is trained in the following way: Obtaining an initial sample training set, and preprocessing the initial sample training set to obtain a target sample training set; For each sample text to be translated in the target sample training set, the sample text to be translated is input into a preset translation model and a large language model to obtain a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model; determining a first loss of the preset translation model based on a difference between the first predicted translation label and the second predicted translation label; Obtaining a sample translation label of the sample text to be translated, and determining a second loss of the preset translation model based on a difference between the first predicted translation label and the sample translation label; A target loss is determined according to the first loss and the second loss, and translation performance learning based on minimization of the target loss is performed on the preset translation model to obtain a target translation model.
4. The text translation method according to claim 3, characterized in that: The determining a first loss of the preset translation model based on a difference between the first predicted translation label and the second predicted translation label includes: Obtaining a plurality of first probabilities corresponding to a plurality of first translation words included in the first predicted translation label predicted by the preset translation model for the sample text to be translated, and a plurality of second probabilities corresponding to a plurality of second translation words included in the second predicted translation label predicted by the large language model for the sample text to be translated; For each of the first translation words, determine the second probability of the second translation word corresponding thereto, and determine the first sub-loss of the preset translation model when translating the corresponding sample text to be translated based on the difference between the first probability and the second probability; The first loss of the preset translation model is determined by using a plurality of first sub-losses of the preset translation model when translating a corresponding sample text to be translated.
5. The text translation method according to claim 3, characterized in that: The determining, based on the difference between the first predicted translation label and the sample translation label, a second loss of the preset translation model comprises: Obtaining a plurality of first translation words included in the first predicted translation label output by the preset translation model for predicting the sample text to be translated; Determining a second sub-loss of the preset translation model when translating the corresponding sample text to be translated according to differences between the multiple first translation words and the multiple target translation words included in the sample translation tags corresponding to the sample text to be translated; The second loss of the preset translation model is determined by using a plurality of second sub-losses of the preset translation model when translating a corresponding sample text to be translated.
6. The text translation method according to claim 3, characterized in that: The determining the target loss according to the first loss and the second loss includes: Obtaining a first weight of the first loss and a second weight of the second loss; wherein the first weight is less than the second weight; Adjusting the first loss based on the first weight to obtain a first target loss; Adjusting the second loss based on the second weight to obtain a second target loss; Based on the first target loss and the second target loss, a target loss of the preset translation model is determined.
7. The text translation method according to claim 3, characterized in that: The preprocessing of the initial sample training set to obtain a target sample training set includes: Acquire multiple initial language pairs in the initial sample training set; wherein the initial language pairs include initial sample texts to be translated and corresponding initial sample translation labels; For each of the initial language pairs, calculating the perplexity of the initial language pair; Obtaining a preset perplexity threshold, and filtering out the initial language pairs whose perplexity is lower than the perplexity threshold, to obtain a plurality of target language pairs; wherein the target language pairs include sample texts to be translated and corresponding sample translation labels; Based on the multiple target language pairs, a target sample training set is obtained.
8. A text translation device, characterized in that: The device comprises: The acquisition module is used to obtain the text to be translated; An input module, used for inputting the text to be translated into a target translation model to obtain a plurality of candidate translation results for the text to be translated; A determination module is used to determine a target translation result from the multiple candidate translation results through a large language model; wherein the target translation model is obtained by learning translation performance based on minimization of a target loss by a preset translation model; the target loss is composed of a first loss and a second loss, the first loss is determined by the difference between a first predicted translation label output by the preset translation model for each sample text to be translated and a second predicted translation label output by the large language model for the sample text to be translated; the first loss is a KL divergence loss, and the first loss is used to measure the similarity between the output distributions of the large language model and the preset translation model; the second loss is determined by the difference between the first predicted translation label output by the preset translation model for the sample text to be translated and a sample translation label of the sample text to be translated; the translation performance learning includes representation learning of the translation output of the simulated large language model based on minimization of the first loss, and minimization learning of the translation difference between the first predicted translation label and the sample translation label based on minimization of the second loss.
9. A computer device, characterized in that: The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the text translation method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the text translation method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Translation model training method and device and device for translation model training
CN113723117A