Translation method and device for example-aware machine translation large language model
Through the machine translation large language model method based on example awareness, combined with low-rank adaptive LoRA fine-tuning technology, a translation model with improved example awareness is constructed, which solves the problem of insufficient example awareness in the existing technology and achieves more efficient and accurate translation. Performance and adaptability.
Patent Information
- Application Number
- CN202410933627.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-12
AI Technical Summary
Existing large language models for machine translation have deficiencies in example perception and learning. Hint-based and fine-tuning-based methods each have limitations, limiting the adaptability and depth of translation.
Adopting a machine translation large language model method based on example awareness, by constructing sentence-level and document-level awareness examples, combined with low-rank adaptive LoRA fine-tuning technology, a machine translation large language model with improved example awareness capabilities is constructed, and the translation model is optimized to improve adaptability and performance.
Effectively integrates hint-based and fine-tuning-based methods to improve the adaptability and performance of translation models in various translation scenarios, paying special attention to rare vocabulary translation, mitigating the negative impact of noise demonstrations on translation quality, providing customized solutions and significantly Improve translation efficiency and performance.
Smart Images

Figure 00000000_0000
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of machine translation, and in particular to a translation method and device for a large language model of machine translation based on example perception. Background Art
[0002] As large language model technology has made significant progress in academia and industry, and has shown impressive performance in machine translation, large language models for machine translation have gradually become a hot research topic in the field of natural language processing. By providing relevant examples for contextual learning or fine-tuning the large model through supervised learning with translation data, the large model can be adapted to translation tasks in multiple languages, demonstrating excellent translation capabilities. Therefore, it has received widespread attention from researchers in recent years.
[0003] At present, the large language model technology for machine translation includes prompt-based methods and fine-tuning-based methods to use large language models. The prompt-based large language model for machine translation activates the translation ability of the model by providing examples to the basic large language model, providing a training-free method that can be quickly deployed according to specific translation needs (such as domain-specific translation). However, this method is constrained by fixed parameters, which limits its adaptability and translation depth. In contrast, the fine-tuning-based large language model for machine translation enhances translation capabilities through supervised fine-tuning on machine translation-specific datasets, thereby improving performance through parameter updates. However, this method often ignores the contextual learning ability of the large language model, especially in some translation scenarios that require example perception. Only sentence-level translation using simple instructions will limit the translation ability of the large language model for machine translation. Summary of the invention
[0004] In order to solve the shortcomings of example perception and learning in existing machine translation, how to overcome the limitations of the large language model of machine translation based on prompts and fine-tuning, so as to achieve more efficient and more accurate machine translation, the embodiment of the present invention provides a translation method and device of a large language model of machine translation based on example perception. The technical solution is as follows:
[0005] On the one hand, a translation method of a large language model for machine translation based on example perception is provided, the method is implemented by a translation device for a large language model for machine translation, and the method includes:
[0006] S1. Obtain data to be translated.
[0007] S2. Input the data into the constructed large language model for machine translation with improved example perception capabilities.
[0008] S3. Obtain translation results based on a large language model of machine translation with improved data and example perception capabilities.
[0009] The process of building a large language model for machine translation with improved sample perception capabilities includes:
[0010] S21. Construct sentence-level perception examples and document-level perception examples.
[0011] S22. Construct example-aware training data based on the sentence-level perception examples and the document-level perception examples; and obtain a trained large language model for machine translation through low-rank adaptive LoRA fine-tuning technology based on the example-aware training data.
[0012] S23. Construction domain translation examples and document level translation examples.
[0013] S24. Based on the domain translation examples and the document-level translation examples, the trained machine translation large language model is optimized for translation, so as to obtain a constructed machine translation large language model with improved example perception capability.
[0014] Optionally, constructing sentence-level perception examples and document-level perception examples in S21 includes:
[0015] S211. Obtain the original training set.
[0016] S212. In the original training set, randomly select multiple translation pairs and use the multiple translation pairs as sentence-level perception examples.
[0017] S213: Select any translation pair in the original training set, obtain the first multiple translation pairs of the selected translation pair in the original training set, and use the obtained multiple translation pairs as document-level perception examples.
[0018] Optionally, a sentence-level perception example is shown in the following formula (1):
[0019] (1)
[0020] In the formula, Indicates Example of sentence-level perception of translation pairs, represents the number of translation pairs, The format of the example is: Indicates The source sentence of the translation pair, Indicates The target sentence of a translation pair.
[0021] Optionally, a document-level perception example is shown in the following formula (2):
[0022] (2)
[0023] In the formula, represents a document-level aware example, represents the order of sentences in the original training set, represents the number of translation pairs, The format of the representation example is, Indicated in The first sentence before Source sentence, Indicated in The first sentence before target sentence.
[0024] Optionally, in S22, example-aware training data is constructed according to the sentence-level awareness examples and the document-level awareness examples; and according to the example-aware training data, a trained large language model for machine translation is obtained by low-rank adaptive LoRA fine-tuning technology, including:
[0025] S221. Concatenate the sentence-level perception examples and the document-level perception examples with the original training data, and mix the concatenated training data through Bernoulli probability to obtain example-perception training data.
[0026] S222. Obtain a basic large language model for machine translation.
[0027] S223. Use low-rank adaptive LoRA fine-tuning technology to add adjustable parameters to the basic machine translation large language model to obtain a machine translation large language model with adjustable parameters.
[0028] S224. According to the example perception training data, a large machine translation language model with adjustable parameters is trained to obtain a trained large machine translation language model.
[0029] Optionally, the training loss of the large language model of machine translation with adjustable parameters in S223 is as shown in the following formula (3):
[0030] (3)
[0031] In the formula, represents the training loss of a large language model for machine translation with adjustable parameters, represents the cross entropy loss, Represents the target sentence The probability distribution of represents the target sentence, represents the source sentence of the translation, Indicates the instructions being translated, express A collection of translation pairs , Represents the parameters of the basic machine translation large language model Frozen during training, Indicates an adjustable parameter.
[0032] Optionally, the construction domain translation example and the document level translation example in S23 include:
[0033] S231. Obtain an original training set.
[0034] S232. According to the R-BM25 retrieval method, the translation pairs in the original training set are scored and sorted, and the translation pairs with scores exceeding a preset threshold are selected as domain translation examples.
[0035] S233. For a target sentence in a test set, obtain the translation source sentences and target sentences of the first multiple sentences of the target sentence, input the translation source sentences and target sentences of the first multiple sentences into a trained machine translation large language model, obtain translation examples generated by the machine translation large language model, and obtain document-level translation examples based on the domain translation examples and the translation examples generated by the machine translation large language model.
[0036] On the other hand, a translation device based on an example-aware machine translation large language model is provided, and the device is applied to a translation method based on an example-aware machine translation large language model, and the device includes:
[0037] The acquisition module is used to obtain the data to be translated.
[0038] The input module is used to input data into the constructed large language model for machine translation with enhanced example-awareness.
[0039] The output module is used to obtain the translation results based on the large language model of machine translation with improved data and example perception capabilities.
[0040] The process of building a large language model for machine translation with improved sample perception capabilities includes:
[0041] S21. Construct sentence-level perception examples and document-level perception examples.
[0042] S22. Construct example-aware training data based on sentence-level perception examples and document-level perception examples; based on the example-aware training data, obtain a trained large language model for machine translation through low-rank adaptive LoRA fine-tuning technology.
[0043] S23. Construction domain translation examples and document level translation examples.
[0044] S24. Based on the domain translation examples and the document-level translation examples, the trained machine translation large language model is optimized for translation, so as to obtain a constructed machine translation large language model with improved example perception capability.
[0045] Optionally, the input module is further configured to:
[0046] S211. Obtain the original training set.
[0047] S212. Randomly select multiple translation pairs from the original training set, and use the multiple translation pairs as sentence-level perception example training data.
[0048] S213: Select any translation pair in the original training set, obtain the first multiple translation pairs of the selected translation pair in the original training set, and use the obtained multiple translation pairs as document-level perception example training data.
[0049] Optionally, a sentence-level perception example is shown in the following formula (1):
[0050] (1)
[0051] In the formula, Indicates Example of sentence-level perception of translation pairs, represents the number of translation pairs, The format of the representation example is, Indicates The source sentence of the translation pair, Indicates The target sentence of a translation pair.
[0052] Optionally, a document-level perception example is shown in the following formula (2):
[0053] (2)
[0054] In the formula, represents a document-level aware example, represents the order of sentences in the original training set, represents the number of translation pairs, The format of the representation example is, Indicated in The first sentence before Source sentence, Indicated in The first sentence before target sentence.
[0055] Optionally, the input module is further configured to:
[0056] S221. Concatenate the sentence-level perception examples and the document-level perception examples with the original training data, and mix the concatenated training data through Bernoulli probability to obtain example-perception training data.
[0057] S222. Obtain a basic large language model for machine translation.
[0058] S223. Use low-rank adaptive LoRA fine-tuning technology to add adjustable parameters to the basic machine translation large language model to obtain a machine translation large language model with adjustable parameters.
[0059] S224. According to the example perception training data, a large machine translation language model with adjustable parameters is trained to obtain a trained large machine translation language model.
[0060] Optionally, the training loss of the large language model of machine translation with adjustable parameters is as shown in the following formula (3):
[0061] (3)
[0062] In the formula, represents the training loss of a large language model for machine translation with adjustable parameters, represents the cross entropy loss, Represents the target sentence The probability distribution of represents the target sentence, represents the source sentence of the translation, Indicates the instructions being translated, express A collection of translation pairs , Represents the parameters of the basic machine translation large language model Frozen during training, Indicates an adjustable parameter.
[0063] Optionally, the input module is further configured to:
[0064] S231. Obtain an original training set.
[0065] S232. According to the R-BM25 retrieval method, the translation pairs in the original training set are scored and sorted, and the translation pairs with scores exceeding a preset threshold are selected as domain translation examples.
[0066] S233. For a target sentence in a test set, obtain the translation source sentences and target sentences of the first multiple sentences of the target sentence, input the translation source sentences and target sentences of the first multiple sentences into a trained machine translation large language model, obtain translation examples generated by the machine translation large language model, and obtain document-level translation examples based on the domain translation examples and the translation examples generated by the machine translation large language model.
[0067] On the other hand, a translation device for a large language model for machine translation is provided, the translation device for a large language model for machine translation comprising: a processor; a memory, the memory storing computer-readable instructions, and when the computer-readable instructions are executed by the processor, any one of the translation methods for a large language model for machine translation based on example-perceptual enhancement is implemented.
[0068] On the other hand, a computer-readable storage medium is provided, in which at least one instruction is stored, and the at least one instruction is loaded and executed by a processor to implement any one of the above-mentioned translation methods of the large language model of machine translation based on example-aware boosting.
[0069] The beneficial effects brought about by the technical solution provided by the embodiment of the present invention include at least:
[0070] In the embodiment of the present invention, a lightweight example-aware fine-tuning method and an example screening hybrid strategy are used to effectively integrate the prompt-based and fine-tuning methods, thereby improving the adaptability and performance of the translation model in various translation scenarios. In addition, the present invention pays special attention to using examples to promote the translation of rare words, while proposing strategies to mitigate the negative impact that noise demonstrations may have on translation quality. In this way, the present invention can not only provide customized solutions for specific needs such as domain-specific translation and document-level translation, but also significantly improve translation efficiency and performance without sacrificing translation quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0072] Figure 1 It is a flow chart of a translation method of a large language model of machine translation based on example perception provided by an embodiment of the present invention;
[0073] Figure 2 It is an overall flow chart of a translation method of a large language model of machine translation based on example perception provided by an embodiment of the present invention;
[0074] Figure 3 is a flow chart of an example perception training method provided by an embodiment of the present invention;
[0075] Figure 4 is a flow chart of an example perceptual reasoning method provided by an embodiment of the present invention;
[0076] Figure 5It is a block diagram of a translation device of a large language model of machine translation based on example perception provided by an embodiment of the present invention;
[0077] Figure 6 It is a structural schematic diagram of a translation device for a large language model of machine translation provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0078] The technical solution of the present invention is described below in conjunction with the accompanying drawings.
[0079] In the embodiments of the present invention, words such as "exemplarily" and "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "example" in the present invention should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of the word "example" is intended to present the concept in a specific way. In addition, in the embodiments of the present invention, the meaning expressed by "and / or" can be both, or it can be either of the two.
[0080] In the embodiments of the present invention, "image" and "picture" can sometimes be used interchangeably. It should be noted that when the difference between them is not emphasized, the meanings they intend to express are the same. "of", "corresponding, relevant" and "corresponding" can sometimes be used interchangeably. It should be noted that when the difference between them is not emphasized, the meanings they intend to express are the same.
[0081] In the embodiments of the present invention, sometimes the subscripts such as W 1 It may be written in non-subscript form such as W1. When the difference is not emphasized, the meaning is the same.
[0082] In order to make the technical problems, technical solutions and advantages to be solved by the present invention more clear, a detailed description will be given below with reference to the accompanying drawings and specific embodiments.
[0083] The embodiment of the present invention provides a translation method of a large language model for machine translation based on example perception, which can be implemented by a translation device for a large language model for machine translation, which can be a terminal or a server. Figure 1 The flowchart of the translation method of the example-aware machine translation large language model is shown. The processing flow of the method may include the following steps:
[0084] S1. Obtain data to be translated.
[0085] S2. Input the data into the constructed large language model for machine translation with improved example perception capabilities.
[0086] S3. Obtain translation results based on a large language model of machine translation with improved data and example perception capabilities.
[0087] Among them, Figure 2 As shown, the process of constructing a large language model for machine translation with improved perception capability may include the following steps S21-S24:
[0088] S21. Construct sentence-level perception examples and document-level perception examples.
[0089] Optionally, the above step S21 may include the following steps S211-S213:
[0090] S211. Obtain the original training set.
[0091] S212. In the original training set, randomly select multiple translation pairs and use the multiple translation pairs as sentence-level perception examples.
[0092] In a feasible implementation, the original training data of the large language model for machine translation are randomly selected by taking advantage of the fact that they are all from the same field.
[0093] Specifically, in the usual contextual learning framework, the model selects Examples as perception examples To translate the target sentence, the target sentence The probability distribution of is as follows:
[0094] (1)
[0095] In the formula, Represents the target sentence The probability distribution of Indicates the length of the target sentence.
[0096] By leveraging learned knowledge and contextual information, the model is able to generate more accurate and natural translation results.
[0097] Figure 3 The specific process of example perception training is shown. For sentence-level translation, considering that the original training data are all in the same field, the present invention randomly selects A translation pair is used as a sentence-level perception example of the present invention, and the specific structure is as follows:
[0098] (2)
[0099] In the formula, Indicates Example of sentence-level perception of translation pairs, represents the number of translation pairs, The format of the representation example is, Indicates The source sentence of the translation pair, Indicates The target sentence of the translation pair, " indicates the separator between examples.
[0100] Therefore, the probability of translation is During the training process, sentence-level examples are selected from the entire training data.
[0101] S213: Select any translation pair in the original training set, obtain the first multiple translation pairs of the selected translation pair in the original training set, and use the obtained multiple translation pairs as document-level perception examples.
[0102] In a feasible implementation, document-level selection is performed by utilizing the characteristic that the original training data of the large language model of machine translation are all logical paragraphs.
[0103] Specifically, for document-level translation, considering that in the context learning process of the model, it is crucial to understand the logical relationship in the context, and the training set usually consists of continuous paragraphs rather than unrelated sentences. To this end, the present invention randomly selects the pair of parallel training data in front of it and next to it in the original training set. An example is given as a document-level perception example of the present invention, and the specific structure is as follows:
[0104] (3)
[0105] In the formula, represents a document-level aware example, represents the order of sentences in the original training set, represents the number of translation pairs, The format of the representation example is, Indicated in The first sentence before Source sentence, Indicated in The first sentence before target sentence.
[0106] Various exemplary styles of the present invention are shown in Table 1:
[0107] Table 1
[0108]
[0109] S22. Construct example-aware training data based on sentence-level perception examples and document-level perception examples; based on the example-aware training data, obtain a trained large language model for machine translation through low-rank adaptive LoRA fine-tuning technology.
[0110] In a feasible implementation, the constructed sentence-level and document-level training data are mixed, and the LoRA (Low-Rank Adaptation) method is used for fast and efficient training.
[0111] Optionally, the above step S22 may include the following steps S221-S224:
[0112] S221. Concatenate the sentence-level perception examples and the document-level perception examples with the original training data, and mix the concatenated training data through Bernoulli probability to obtain example-perception training data.
[0113] In a feasible implementation, after constructing sentence-level perception examples and document-level perception examples, considering the different application scenarios faced by the large language model of machine translation, the present invention randomly selects the example types to be used through Bernoulli distribution for mixing. This mixed use method improves the flexibility and efficiency of the model in different translation scenarios. The specific distribution is as follows:
[0114] (4)
[0115] in, To select sentence-level demonstrations during training The probability of selecting document-level demonstration The probability of .
[0116] S222. Obtain a basic large language model for machine translation.
[0117] S223. Use low-rank adaptive LoRA fine-tuning technology to add adjustable parameters to the basic machine translation large language model to obtain a machine translation large language model with adjustable parameters.
[0118] In a feasible implementation, in order to further optimize the model performance, the present invention introduces lightweight LoRA fine-tuning technology. By adding a small number of adjustable parameters to the model, the learning ability and adaptability of the model are improved while ensuring the efficiency of the model. This method can fully utilize the capabilities of the pre-trained model and effectively fine-tune it for specific tasks. Given the parameters of the basic model , the present invention adds additional adjustable parameters to the model Therefore, the training samples The training loss is:
[0119] (5)
[0120] In the formula, represents the training loss of a large translation model with adjustable parameters, represents the cross entropy loss, Represents the target sentence The probability distribution of represents the target sentence, represents the source sentence of the translation, Indicates the instructions being translated, and equivalence, Representation parameters Frozen during training.
[0121] Since the present invention uses lightweight LoRA fine-tuning, and The comparison of the parameter sizes should satisfy:
[0122] (6)
[0123] S224. According to the example perception training data, a large machine translation language model with adjustable parameters is trained to obtain a trained large machine translation language model.
[0124] S23. Construction domain translation examples and document level translation examples.
[0125] Optionally, the above step S23 may include the following steps S231-S233:
[0126] S231. Obtain an original training set.
[0127] S232. According to the R-BM25 retrieval method, the translation pairs in the original training set are scored and sorted, and the translation pairs with scores exceeding a preset threshold are selected as domain translation examples.
[0128] In a feasible implementation, Figure 4 As shown, the R-BM25 method is used to score and sort the examples, and the present invention selects several examples with the highest scores as high-quality examples used in the reasoning of the present invention as examples for reasoning.
[0129] Among them, the R-BM25 retrieval method: the present invention first uses conventional BM25 to screen examples, then extracts all word ngrams and their counts from the translated source sentences of the retrieved BM25 examples and the target sentences of the test set, let S and Q represent the sets of translated source sentence ngrams and target sentence ngrams from the BM25 retrieval examples and the test set, respectively, re-rank according to the matching degree of ngrams, and use the following formula to calculate the R-BM25 score:
[0130] (7)
[0131] (8)
[0132] In the formula, Indicates the matching rate of ngram, Indicates the number of ngrams to be calculated. represents the R-BM25 score.
[0133] Specifically, in terms of domain translation optimization, the present invention significantly improves the translation performance of the machine translation model in a specific domain by combining the R-BM25 (Best Match25) retrieval method and the incremental learning framework. By accurately selecting translation pairs with high domain similarity to the sentences to be translated as model input demonstrations, the present invention ensures that the model can access contexts and expressions that are highly relevant to the target domain. This demonstration selection method based on N-Gram (language model) matching and language similarity calculation not only deepens the model's understanding of specific domains, but also enhances the accuracy and naturalness of its translation. In this way, the model can dynamically filter out the most relevant examples from a large data set, thereby providing rich and accurate contextual information during the translation process, greatly improving the model's adaptability and performance in diverse domain translation tasks. The present invention uses retrieval-based examples for domain translation, satisfying the equation . By retrieving the scoring function and search corpus , the retrieved R-BM25 example is:
[0134] (9)
[0135] In the formula, Indicates the filtered examples, Indicates selection The examples with the highest scores.
[0136] S233. For a target sentence in a test set, obtain the translation source sentences and target sentences of the first multiple sentences of the target sentence, input the translation source sentences and target sentences of the first multiple sentences into a trained machine translation large language model, obtain translation examples generated by the machine translation large language model, and obtain document-level translation examples based on the domain translation examples and the translation examples generated by the machine translation large language model.
[0137] In a feasible implementation, examples selected by the R-BM25 method and logical pre-translation content generated by the large language model of machine translation are used as examples for reasoning.
[0138] The target sentence is each piece of data in the test set. For each piece of test data, the multiple adjacent translated training data in front of it are used as examples. Since the test set is a logical text, each sentence is related to the previous sentences, so the adjacent translated data are used as translation examples.
[0139] Specifically, in terms of document-level translation optimization, the present invention adopts an innovative online adaptation method and hybrid demonstration strategy, which effectively utilizes the contextual relationship within the document to improve translation quality. By selecting sentences adjacent to the target sentence and the translations generated by the model itself in real time as examples, and combining them with relevant field examples retrieved through R-BM25, the document-level translation optimization strategy of the present invention, by comprehensively utilizing the direct contextual information generated by the model itself and the field-related information retrieved externally, enhances the model's capture of the entire document context and learning of sentence-related knowledge, and also improves its adaptability to document style and topic. In order to further utilize the intrinsic contextual information of the same document, the present invention uses the sentences previously translated by the model itself when translating a sentence. Using K-shot document-level demonstration , No. sentence Translation of The generation method is as follows:
[0140] (10)
[0141] Furthermore, in order to ensure the translation quality with specific information (such as domain, style or theme) in document-level translation, the present invention proposes to use retrieval-based demonstration and document-level presentation Therefore, the final mixed example decoding criterion is:
[0142] (11)
[0143] in, and Represents the number of sentence-level and document-level examples respectively. For the total number of examples ,have , where Indicates splicing.
[0144] S24. According to the domain translation examples and the document-level translation examples, the trained machine translation large language model is optimized to obtain a constructed machine translation large language model with improved example perception capability.
[0145] Table 2
[0146]
[0147] Table 2 shows the COMET and d-BLEU scores of the prompt-based machine translation large language model, the fine-tuning-based machine translation large language model, the original machine translation large language model, and the example-aware improvement-based machine translation large language model of the present invention. The present invention selects the best-performing model among the fine-tuning-based machine translation large language models as the original machine translation large language model, represents the base model used by the present invention, the example-based machine translation large language model represents the effect obtained by the original machine translation large language model using the translation examples screened by the present invention, the example-aware machine translation large language model represents the effect obtained by training using the method of the present invention and using the translation examples screened by the present invention, and 7B and 13B represent the parameter amounts of the model. According to the main results of Table 2, the present invention finds that the performance of the original fine-tuning-based machine translation large language model may be impaired by examples, while the example-aware improvement-based machine translation large language model proposed by the present invention can learn from examples significantly and stably, and the results on all data sets are better than the baseline, showing the significant improvement of the context learning ability brought by the example-aware improvement-based machine translation large language model. Finally, the large language model for machine translation based on example-aware boosting can enhance example-awareness under different model sizes and surpasses the original large language model for machine translation on all datasets, demonstrating the stable superiority of the large language model for machine translation based on example-aware boosting on different model sizes.
[0148] In the embodiment of the present invention, a lightweight example-aware fine-tuning method and an example screening hybrid strategy are used to effectively integrate the prompt-based and fine-tuning methods, thereby improving the adaptability and performance of the translation model in various translation scenarios. In addition, the present invention pays special attention to using examples to promote the translation of rare words, while proposing strategies to mitigate the negative impact that noise demonstrations may have on translation quality. In this way, the present invention can not only provide customized solutions for specific needs such as domain-specific translation and document-level translation, but also significantly improve translation efficiency and performance without sacrificing translation quality.
[0149] Figure 5 The present invention is a block diagram of a translation device based on an example-aware machine translation large language model according to an exemplary embodiment, wherein the device is used for a translation method based on an example-aware machine translation large language model. Figure 5 The device includes an acquisition module 310, an input module 320 and an output module 330. Among them:
[0150] The acquisition module 310 is used to acquire data to be translated.
[0151] The input module 320 is used to input data into the constructed large language model for machine translation with improved example perception capability.
[0152] The output module 330 is used to obtain a translation result based on the machine translation large language model with improved data and example perception capabilities.
[0153] The process of constructing a large language model for machine translation with example-aware capabilities includes:
[0154] S21. Construct sentence-level perception examples and document-level perception examples.
[0155] S22. Construct example-aware training data based on sentence-level perception examples and document-level perception examples, and obtain a trained large language model for machine translation through low-rank adaptive LoRA fine-tuning technology.
[0156] S23. Construction domain translation examples and document level translation examples.
[0157] S24. Construct example-aware training data based on sentence-level perception examples and document-level perception examples; based on the example-aware training data; based on the example-aware training data, obtain a trained large language model for machine translation through low-rank adaptive LoRA fine-tuning technology.
[0158] Optionally, the input module 320 is further configured to:
[0159] S211. Obtain the original training set.
[0160] S212. In the original training set, randomly select multiple translation pairs and use the multiple translation pairs as sentence-level perception examples.
[0161] S213: Select any translation pair in the original training set, obtain the first multiple translation pairs of the selected translation pair in the original training set, and use the obtained multiple translation pairs as document-level perception examples.
[0162] Optionally, a sentence-level perception example is shown in the following formula (1):
[0163] (1)
[0164] In the formula, Indicates Example of sentence-level perception of translation pairs, represents the number of translation pairs, The format of the example is: Indicates The source sentence of the translation pair, Indicates The target sentence of a translation pair.
[0165] Optionally, a document-level perception example is shown in the following formula (2):
[0166] (2)
[0167] In the formula, represents a document-level aware example, represents the order of sentences in the original training set, represents the number of translation pairs, The format of the example is: Indicated in The first sentence before Source sentence, Indicated in The first sentence before target sentence.
[0168] Optionally, the input module 320 is further configured to:
[0169] S221. Concatenate the sentence-level perception examples and the document-level perception examples with the original training data, and mix the concatenated training data through Bernoulli probability to obtain example-perception training data.
[0170] S222. Obtain a basic large language model for machine translation.
[0171] S223. Use low-rank adaptive LoRA fine-tuning technology to add adjustable parameters to the basic machine translation large language model to obtain a machine translation large language model with adjustable parameters.
[0172] S224. According to the example perception training data, a large machine translation language model with adjustable parameters is trained to obtain a trained large machine translation language model.
[0173] Optionally, the training loss of the large language model of machine translation with adjustable parameters is as shown in the following formula (3):
[0174] (3)
[0175] In the formula, represents the training loss of a large language model for machine translation with adjustable parameters, represents the cross entropy loss, Represents the target sentence The probability distribution of represents the target sentence, represents the source sentence of the translation, Indicates the instructions being translated, express A collection of translation pairs , Represents the parameters of the basic machine translation large language model Frozen during training, Indicates an adjustable parameter.
[0176] Optionally, the input module 320 is further configured to:
[0177] S231. Obtain an original training set.
[0178] S232. According to the R-BM25 retrieval method, the translation pairs in the original training set are scored and sorted, and the translation pairs with scores exceeding a preset threshold are selected as domain translation examples.
[0179] S233. For a target sentence in a test set, obtain the translation source sentences and target sentences of the first multiple sentences of the target sentence, input the translation source sentences and target sentences of the first multiple sentences into a trained machine translation large language model, obtain translation examples generated by the machine translation large language model, and obtain document-level translation examples based on the domain translation examples and the translation examples generated by the machine translation large language model.
[0180] In the embodiment of the present invention, a lightweight example-aware fine-tuning method and an example screening hybrid strategy are used to effectively integrate the prompt-based and fine-tuning methods, thereby improving the adaptability and performance of the translation model in various translation scenarios. In addition, the present invention pays special attention to using examples to promote the translation of rare words, while proposing strategies to mitigate the negative impact that noise demonstrations may have on translation quality. In this way, the present invention can not only provide customized solutions for specific needs such as domain-specific translation and document-level translation, but also significantly improve translation efficiency and performance without sacrificing translation quality.
[0181] Figure 6 is a structural diagram of a translation device for a large language model of machine translation provided by an embodiment of the present invention, such as Figure 6 As shown, the translation device of the machine translation large language model may include the above Figure 5 The illustrated example-based perceptual machine translation large language model translation device. Optionally, the machine translation large language model translation device 410 may include a first processor 2001 .
[0182] Optionally, the translation device 410 for machine translation of a large language model may further include a memory 2002 and a transceiver 2003 .
[0183] The first processor 2001, the memory 2002 and the transceiver 2003 may be connected via a communication bus.
[0184] Combine the following Figure 6 The components of the translation device 410 of the machine translation large language model are specifically introduced as follows:
[0185] The first processor 2001 is the control center of the translation device 410 for the large language model of machine translation, and can be a processor or a general term for multiple processing elements. For example, the first processor 2001 is one or more central processing units (CPUs), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention, such as one or more microprocessors (digital signal processors, DSPs), or one or more field programmable gate arrays (field programmable gate arrays, FPGAs).
[0186] Optionally, the first processor 2001 may perform various functions of the translation device 410 for machine translating a large language model by running or executing a software program stored in the memory 2002 and calling data stored in the memory 2002 .
[0187] In a specific implementation, as an embodiment, the first processor 2001 may include one or more CPUs, such as Figure 6 CPU0 and CPU1 are shown in FIG.
[0188] In a specific implementation, as an embodiment, the translation device 410 for machine translation of a large language model may also include multiple processors, such as Figure 6 The first processor 2001 and the second processor 2004 are shown in FIG. Each of these processors may be a single-core processor (single-CPU) or a multi-core processor (multi-CPU). The processor here may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).
[0189] The memory 2002 is used to store the software program for executing the solution of the present invention, and is controlled to be executed by the first processor 2001. The specific implementation method can refer to the above method embodiment, which will not be repeated here.
[0190] Optionally, the memory 2002 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 2002 may be integrated with the first processor 2001, or may exist independently, and accessed through the interface circuit ( Figure 6 (not shown) is coupled to the first processor 2001, which is not specifically limited in this embodiment of the present invention.
[0191] The transceiver 2003 is used to communicate with a network device or a terminal device.
[0192] Optionally, the transceiver 2003 may include a receiver and a transmitter ( Figure 6 The receiver is used to implement a receiving function, and the transmitter is used to implement a sending function.
[0193] Optionally, the transceiver 2003 may be integrated with the first processor 2001, or may exist independently and be transmitted through the interface circuit ( Figure 6 (not shown) is coupled to the first processor 2001, which is not specifically limited in this embodiment of the present invention.
[0194] It should be noted that Figure 6 The structure of the translation device 410 for the large language model of machine translation shown in the figure does not constitute a limitation on the router, and the actual knowledge structure recognition device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0195] In addition, the technical effects of the translation device 410 for the large language model of machine translation can refer to the technical effects of the translation method for the large language model of machine translation based on example perception described in the above method embodiment, which will not be repeated here.
[0196] It should be understood that the first processor 2001 in the embodiment of the present invention may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0197] It should also be understood that the memory in the embodiments of the present invention may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct rambus RAM (DR RAM).
[0198] The above embodiments can be implemented in whole or in part by software, hardware (such as circuits), firmware or any other combination. When implemented by software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that contains one or more available media sets. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a tape), an optical medium (for example, a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state hard disk.
[0199] It should be understood that the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. A and B can be singular or plural. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship, but it may also indicate an "and / or" relationship. Please refer to the context for specific understanding.
[0200] In the present invention, "at least one" means one or more, and "plurality" means two or more. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can mean: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple.
[0201] It should be understood that in various embodiments of the present invention, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0202] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0203] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described equipment, devices and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0204] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the 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 device, 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 through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0205] The units described 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.
[0206] In addition, each functional unit in each embodiment of the present invention 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.
[0207] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.
[0208] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A translation method for a large language model of machine translation based on example perception, characterized in that: The method comprises: S1. Obtain data to be translated; S2. Inputting the data into a constructed large language model for machine translation with improved example perception capability; S3, obtaining a translation result according to the data and the large language model of machine translation with improved example perception capability; The process of constructing the large language model of machine translation with improved example perception capability includes: S21, construct sentence-level perception examples and document-level perception examples; S22, constructing example perception training data according to the sentence-level perception examples and the document-level perception examples; and obtaining a trained large language model for machine translation by low-rank adaptive LoRA fine-tuning technology according to the example perception training data; S23, construction domain translation examples and document level translation examples; S24, performing translation optimization on the trained machine translation large language model according to the domain translation examples and the document-level translation examples, to obtain a constructed machine translation large language model with improved example perception capability; The constructed sentence-level perception examples and document-level perception examples in S21 include: S211, obtaining the original training set; S212. Randomly select multiple translation pairs from the original training set, and use the multiple translation pairs as sentence-level perception examples; S213, selecting any translation pair in the original training set, obtaining the first multiple translation pairs of the translation pair selected in the original training set, and using the obtained multiple translation pairs as document-level perception examples; The step S22 constructs example perception training data according to the sentence-level perception examples and the document-level perception examples; and obtains a trained large language model for machine translation by low-rank adaptive LoRA fine-tuning technology according to the example perception training data, including: S221, concatenating the sentence-level perception examples and the document-level perception examples with the original training data, and mixing the concatenated training data by Bernoulli probability to obtain example-perception training data; S222. Obtain a basic large language model for machine translation; S223, using low-rank adaptive LoRA fine-tuning technology to add adjustable parameters to the basic machine translation large language model to obtain a machine translation large language model with adjustable parameters; S224, training the large machine translation language model with adjustable parameters according to the example perception training data to obtain a trained large machine translation language model; The construction domain translation examples and document level translation examples in S23 include: S231, obtaining an original training set; S232, according to the R-BM25 retrieval method, the translation pairs in the original training set are scored and sorted, and the translation pairs with scores exceeding a preset threshold are selected as domain translation examples; S233. For a target sentence in a test set, obtain the translation source sentences and target sentences of the first multiple sentences of the target sentence, input the translation source sentences and target sentences of the first multiple sentences into a trained machine translation large language model, obtain translation examples generated by the machine translation large language model, and obtain document-level translation examples based on the domain translation examples and the translation examples generated by the machine translation large language model.
2. The translation method of the example-aware machine translation large language model according to claim 1, characterized in that: The sentence-level perception example is shown in the following formula (1): (1) In the formula, Indicates Example of sentence-level perception of translation pairs, represents the number of translation pairs, The format of the example is: Indicates The source sentence of the translation pair, Indicates The target sentence of a translation pair.
3. The translation method of the example-aware machine translation large language model according to claim 1, characterized in that: The document-level perception example is shown in the following formula (2): (2) In the formula, represents a document-level aware example, represents the order of sentences in the original training set, represents the number of translation pairs, The format of the example is: Indicated in The first sentence before Source sentence, Indicated in The first sentence before target sentence.
4. The translation method of the example-aware machine translation large language model according to claim 1, characterized in that: The training loss of the large language model of machine translation with adjustable parameters in S223 is shown in the following formula (3): (3) In the formula, represents the training loss of a large language model for machine translation with adjustable parameters, represents the cross entropy loss, Represents the target sentence The probability distribution of represents the target sentence, represents the source sentence of the translation, Indicates the instructions being translated, express A collection of translation pairs , Represents the parameters of the basic machine translation large language model Frozen during training, Indicates an adjustable parameter.
5. A translation device based on an example-aware machine translation large language model, wherein the translation device based on an example-aware machine translation large language model is used to implement the translation method based on an example-aware machine translation large language model as claimed in any one of claims 1 to 4, characterized in that: The device comprises: An acquisition module is used to acquire data to be translated; An input module, used for inputting the data into a constructed large language model for machine translation with improved example perception capability; An output module, configured to obtain a translation result based on the data and a large language model of machine translation with improved example perception capability; The process of constructing the large language model of machine translation with improved example perception capability includes: S21, construct sentence-level perception examples and document-level perception examples; S22, constructing example perception training data according to the sentence-level perception examples and the document-level perception examples; and obtaining a trained large language model for machine translation by low-rank adaptive LoRA fine-tuning technology according to the example perception training data; S23, construction domain translation examples and document level translation examples; S24, optimizing the trained machine translation large language model according to the domain translation examples and the document-level translation examples to obtain a constructed machine translation large language model with improved example perception capability; The constructed sentence-level perception examples and document-level perception examples in S21 include: S211, obtaining the original training set; S212. Randomly select multiple translation pairs from the original training set, and use the multiple translation pairs as sentence-level perception examples; S213, selecting any translation pair in the original training set, obtaining the first multiple translation pairs of the translation pair selected in the original training set, and using the obtained multiple translation pairs as document-level perception examples; The step S22 constructs example perception training data according to the sentence-level perception examples and the document-level perception examples; and obtains a trained large language model for machine translation by low-rank adaptive LoRA fine-tuning technology according to the example perception training data, including: S221, concatenating the sentence-level perception examples and the document-level perception examples with the original training data, and mixing the concatenated training data by Bernoulli probability to obtain example-perception training data; S222. Obtain a basic large language model for machine translation; S223, using low-rank adaptive LoRA fine-tuning technology to add adjustable parameters to the basic machine translation large language model to obtain a machine translation large language model with adjustable parameters; S224, training the large machine translation language model with adjustable parameters according to the example perception training data to obtain a trained large machine translation language model; The construction domain translation examples and document level translation examples in S23 include: S231, obtaining an original training set; S232, according to the R-BM25 retrieval method, the translation pairs in the original training set are scored and sorted, and the translation pairs with scores exceeding a preset threshold are selected as domain translation examples; S233. For a target sentence in a test set, obtain the translation source sentences and target sentences of the first multiple sentences of the target sentence, input the translation source sentences and target sentences of the first multiple sentences into a trained machine translation large language model, obtain translation examples generated by the machine translation large language model, and obtain document-level translation examples based on the domain translation examples and the translation examples generated by the machine translation large language model.
6. A translation device for machine translation of a large language model, characterized in that: The translation device of the machine translation large language model includes: processor; A memory having computer-readable instructions stored thereon, wherein when the computer-readable instructions are executed by the processor, the method according to any one of claims 1 to 4 is implemented.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program codes, which can be called by a processor to execute the method according to any one of claims 1 to 4.
