A method, device and computer-readable storage medium for generating data for enhancing robustness of machine translation based on vector representation

By constructing machine translation models and vector representations, enhanced data that conforms to the actual situation of machine translation is generated, which solves the problem of uninterpretable generated data in existing technologies, improves the robustness of machine translation and makes it interpretable.

CN117094330BActive Publication Date: 2024-08-23SICHUAN LAN-BRIDGE INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310874358.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-17
Publication Date
2024-08-23
Estimated Expiration
2043-07-17

AI Technical Summary

Technical Problem

Existing technologies lack interpretability when generating robustness enhancement data for machine translation models, failing to generate data based on the model's true state and relying on human intuition.

Method used

By constructing two machine translation models, augmented data is generated using vector representation, including the processing of word vectors and sentence vectors. Words are randomly selected for replacement, and the replacement sentences are judged to meet the augmented data standards by using cosine similarity and the machine translation model, thus forming a robust augmented dataset.

Benefits of technology

It enables the generation of enhanced data based on the actual situation of the machine translation model, thereby improving the robustness of machine translation and providing interpretability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117094330B
    Figure CN117094330B
Patent Text Reader

Abstract

The present invention belongs to the technical field of machine translation, and provides a method, device and computer-readable storage medium for enhancing robustness of machine translation generated according to vector representation, comprising: traversing an original sentence x from a set Γ, adding a mask, inputting it into a BERT language model, outputting a probability value and taking the last n words with the lowest ranking; randomly selecting one of the words w i , calculate word w i The word vectors of all words in the legal word list set M' are obtained with w i The k pre-selected words with the closest Euclidean distance form the pre-selected word set M` i ; Use the pre-selected word set M` i traverse the words in the original sentence x, and replace the words to be replaced in the original sentence x respectively; calculate the cosine similarity difference between each replaced sentence x' and the original sentence x, and take the replaced sentence x` with the highest score to replace the original sentence x; determine whether the replaced sentence x` satisfies the enhanced data set #imgabs0#. If it does, compare the replaced sentence x` with the corresponding standard translation y of the replaced sentence before replacement ref Store in collection Z.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of machine translation, and in particular, relates to a method, device and computer-readable storage medium for generating machine translation robustness enhancement data based on vector representation. Background Art

[0002] For the robustness adversarial data of traditional machine translation models, the existing technology is to specify certain rules based on some artificial linguistic knowledge and the robustness-related problems of the model to construct enhanced data that we think can improve the robustness of the model. The shortcomings of this method are: it is unexplainable and cannot generate enhanced data based on the actual situation of the model, but relies on human "intuition". Summary of the invention

[0003] The object of the present invention is to provide a method for generating data for enhancing the robustness of machine translation according to vector representation, so as to solve the technical problems existing in the prior art.

[0004] In order to achieve the above object, the technical solution adopted by the present invention is as follows:

[0005] A method for enhancing robustness of machine translation data generated according to vector representation, comprising:

[0006] (1) Construct two machine translation models to output word vectors and sentence vectors: the machine translation model f_MT from src_lang to tgt_lang and the machine translation model g_MT from tgt_lang to src_lang, where src_lang represents the original text and tgt_lang represents the translated text;

[0007] (2) Traverse an original sentence x from the set Γ, x = {w1,…,w i ,…,w m}, add mask, and get Use it as input to the BERT language model M: Output probability value S(x,w i ), and take the last n words with the lowest probability value, where the value of n is determined by the length of the sentence word level, and the set Γ represents the data set used to generate enhanced data. is the maximum set of sentences to which the original text src_lang belongs;

[0008] (3) Based on the last n words in step (2), randomly select one word w i ;

[0009] (4) Calculate word w iThe word vectors of all words in the legal word list set M' are obtained with w i The k pre-selected words with the closest Euclidean distance to each other constitute the pre-selected word set Among them, the legal vocabulary set M' is the vocabulary of the bert language model M;

[0010] (5) Word replacement: Based on the original sentence x={w1,…,w i ,…,w m}, using a pre-selected word set The words in the traversal are replaced by the original sentence x = {w1,…,w i ,…,w m}, and obtain several replaced sentences x';

[0011] (6) Based on the replaced sentence x' and the original sentence x in step (5), according to the formula: Calculate the cosine similarity difference E(x,x) between each replaced sentence x' and the original sentence x ` ),in, and Represents the cosine similarity of the sentence vectors of two sentences, f(*) is the inference function of the machine translation model f_MT, and g(*) is the inference function of the machine translation model g_MT;

[0012] (7) Take E(x,x ` ) The replaced sentence x with the highest score ` Replace the original sentence x;

[0013] (8) Determine the replaced sentence x in step (7) ` Whether to meet the enhanced data set If satisfied, execute step (9); if not satisfied, execute step (11);

[0014] (9) Replace the sentence x in step (7) ` The standard translation y of the corresponding replacement sentence ref Deposit into collection Z;

[0015] (10) Repeat steps (2) to (9) until all enhanced data sets in the set Γ in step (2) are traversed, and the resulting set Z is the final robustness enhanced data;

[0016] (11) Repeat steps (3) to (7) until the replaced sentence x ` Meet the enhanced data set Then, execute steps (9) and (10).

[0017] Furthermore, the enhanced data set It is expressed as follows: in, is the maximum set of sentences belonging to the original text src_lang, is the maximum set of sentences to which the translation tgt_lang belongs, f(*) is the inference function of the machine translation model f_MT, g(*) is the inference function of the machine translation model g_MT, y=f(x), is the augmented data generated by modifying x, ``

[0018] y=f(x), S t (*,*

[0019] ) is the cosine similarity of the sentence vectors of two sentences, is the dataset prepared for generating augmented data, y ref is the standard translation of x, and α, ∈, δ, and γ are adjustable custom parameters.

[0020] Furthermore, in step (11), if the pre-selected words obtained in step (4) have been traversed, and the replaced sentence x obtained in step (7) based on the pre-selected words ` Does not meet the enhanced data set Then the replaced sentence x will not be ` Store it in the set Z, and continue to repeat steps (3)-(7) until the enhanced data set in the set Γ in step (2) is traversed.

[0021] Furthermore, the method of judging in step (8) is as follows: judging the replaced sentence x ` Whether the enhanced data set is satisfied

[0022] In order to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium having a computer program stored thereon, and the computer program is executed by a processor to implement the method of generating data for enhancing robustness of machine translation according to vector representation.

[0023] In order to achieve the above-mentioned objectives, the present invention also provides a device for generating data for enhancing the robustness of machine translation according to vector representation, comprising: a processor and a memory; the memory is used to store computer programs; the processor is connected to the memory, and is used to execute the computer program stored in the memory, so that the device for generating data for enhancing the robustness of machine translation according to vector representation executes the method for generating data for enhancing the robustness of machine translation according to vector representation.

[0024] Compared with the prior art, the present invention has the following beneficial effects:

[0025] (1) The present invention selects synonyms (pre-selected words) based on the vector representation of the word in the machine translation model, which is more in line with the actual situation encountered in machine translation.

[0026] (2) The present invention sets constraints so that the original text of the enhanced data does not change much in the original machine translation, but the translation changes greatly, which is in line with the characteristics of robust enhanced data.

[0027] (3) The technical solution provided by the present invention is explainable. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 This is a schematic diagram of the structure of Example 3 of the present invention. DETAILED DESCRIPTION

[0029] In order to enable those skilled in the art to have a clearer understanding and knowledge of the present invention, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described below are only used to explain the present invention, and are convenient for understanding. The technical solutions provided by the present invention are not limited to the technical solutions provided by the following embodiments, and the technical solutions provided by the embodiments should not limit the protection scope of the present invention.

[0030] It should be noted that the illustrations provided in the following embodiments are only used to illustrate the basic concept of the present invention in a schematic manner. Therefore, the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0031] Example 1

[0032] This embodiment provides a method for improving machine turning robustness enhancement data generated according to vector representation, the method comprising the following steps:

[0033] 1. Define the original text as src_lang and the translated text as tgt_lang. Prepare a machine translation model from src_lang to tgt_lang, defined as f_MT. Prepare a machine translation model from tgt_lang to src_lang, defined as g_MT. All word vectors and sentence vector representations in the following steps are given by the machine translation model.

[0034] 2. Traverse an original sentence x from the set Γ, x={w1,…,w i ,…,w m}, add mask, and get Use it as input to the BERT language model M: Output probability value S(x,w i ), and take the last n words with the lowest probability value, where the value of n is determined by the length of the sentence word level. Set Γ is a custom dataset, which represents the dataset used to generate enhanced data. It is the maximum set of sentences to which the original text src_lang belongs.

[0035] 3. Based on the last n words in step 2, randomly select one of the words w i .

[0036] 4. Extract the word w selected in step 3 i , calculate word w i The word vectors of all words in the legal word list set M' are obtained with w i The k pre-selected words with the closest Euclidean distance to each other constitute the pre-selected word set Among them, the legal vocabulary set M' is the vocabulary of the BERT language model M, and the above word vector is generated by the embedding layer of the BERT model M.

[0037] 5. Word replacement: Based on the original sentence x={w1,…,w i ,…,w m}, using a pre-selected word set The words in the traversal are replaced by the original sentence x = {w1,…,w i ,…,w m The word to be replaced in} i , replace the word w in the original sentence x i Replace with the pre-selected word set M ` i The pre-selected words in the text are used to obtain several replaced sentences x'. For example, the original text is "I like basketball", the word to be replaced is "like", and the pre-selected word set is {"love", "like"}, then they are replaced into two sentences, "I love basketball" and "I like basketball".

[0038] 6. Based on the replaced sentence x' and the original sentence x in step 5, according to the formula: Calculate the cosine similarity difference E(x,x) between each replaced sentence x' and the original sentence x ` ),in, and Represents the cosine similarity of the sentence vectors of two sentences, f(*) is the inference function of the machine translation model f_MT, and g(*) is the inference function of the machine translation model g_MT.

[0039] 7. Take E(x,x ` ) The replaced sentence x with the highest score ` Replace the original sentence x.

[0040] 8. Determine the replaced sentence x in step 7 ` Whether to meet the enhanced data set If satisfied, then execute step nine; wherein, the enhanced data set It is expressed as follows:

[0041] ,in, is the maximum set of sentences belonging to the original text src_lang, is the maximum set of sentences to which the translation tgt_lang belongs, f(*) is the inference function of the machine translation model f_MT, g(*) is the inference function of the machine translation model g_MT, y=f(x), is the augmented data generated by modifying x, ``

[0042] y=f(x), S t (*,*) is the cosine similarity of the sentence vectors of two sentences, is the dataset prepared for generating augmented data, y ref is the standard translation of x, α,∈,δ,γ are adjustable custom parameters, which are hyperparameters and are used to determine whether the enhanced data set is satisfied. The judgment standard is: ` Whether the enhanced data set is satisfied For example: First, determine whether the cosine similarity of the sentence vectors of the original sentence and the replaced sentence is less than ε, and use the machine translation model to obtain the machine translation of the original sentence and the replaced sentence, and then determine whether the similarity of the two translations meets the requirements of the enhanced data set. The definition interval of .

[0043] 9. Replace the sentence x in step 7 ` The standard translation y of the corresponding replacement sentence ref Deposit into collection Z;

[0044] 10. Repeat steps 2 to 9 until all enhanced data sets in set Γ in step 2 are traversed, and the resulting set Z is the final robustness enhanced data.

[0045] In step eight, if the replaced sentence x ` Does not meet the enhanced data set , then execute step 11: repeat steps 3 to 7 until the replaced sentence x ` Meet the enhanced data set Then, execute steps 9 and 10. In this step, if the pre-selected words obtained in step 4 have been traversed, and the replaced sentence x obtained in step 7 based on the pre-selected words ` Does not meet the enhanced data set Then the replaced sentence x will not be ` Store it in set Z and continue to repeat steps 3 to 7 until all the enhanced data sets in set Γ in step 2 are traversed.

[0046] Example 2

[0047] This embodiment provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the method for generating robustness enhancement data for lifting machine translation according to vector representation as described in Embodiment 1. Those skilled in the art can understand that all or part of the steps of implementing the method provided in Embodiment 1 can be completed by hardware related to the computer program, and the above-mentioned computer program can be stored in a computer-readable storage medium, and when the program is executed, the steps of the method provided in Embodiment 1 are executed; and the above-mentioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.

[0048] Example 3

[0049] like Figure 1 As shown, the present invention also provides a device for generating data for enhancing the robustness of machine translation according to vector representation, comprising: a processor and a memory; the memory is used to store computer programs; the processor is connected to the memory, and is used to execute the computer programs stored in the memory, so that the device for generating data for enhancing the robustness of machine translation according to vector representation executes the method for generating data for enhancing the robustness of machine translation according to vector representation described in Example 1.

[0050] Specifically, the memory includes: ROM, RAM, disk, USB flash drive, memory card or CD and other media that can store program code. Preferably, the processor can be a general-purpose processor, including a central processing unit, a network processor, etc.; it can also be a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.

[0051] The above is the preferred embodiment of the present invention. It should be noted that those skilled in the art can make several improvements without departing from the design principle and technical solution of the present invention, and these improvements should also be regarded as the protection scope of the present invention.

Claims

1. A method for enhancing robustness of machine translation data generated based on vector representation, characterized in that: include: (1) Construct two machine translation models to output word vectors and sentence vectors: the machine translation model f_MT from src_lang to tgt_lang and the machine translation model g_MT from tgt_lang to src_lang, where src_lang represents the original text and tgt_lang represents the translated text; (2) Traverse an original sentence x from the set Γ, x = {w1,…,w i ,…,w m }, add mask, and get Use it as input to the BERT language model M: Output probability value S(x,w i ), and take the last n words with the lowest probability value, where the value of n is determined by the length of the sentence word level, and the set Γ represents the data set used to generate enhanced data. is the maximum set of sentences belonging to the original text src_lang; (3) Based on the last n words in step (2), randomly select one word w i ; (4) Calculate word w i The word vectors of all words in the legal word list set M' are obtained with w i The k pre-selected words with the closest Euclidean distance to each other constitute the pre-selected word set Among them, the legal vocabulary set M' is the vocabulary of the bert language model M; (5) Word replacement: Based on the original sentence x={w1,…,w i ,…,w m }, using a pre-selected word set The words in the traversal are replaced by the original sentence x = {w1,…,w i ,…,w m }, and obtain several replaced sentences x'; (6) Based on the replaced sentence x' and the original sentence x in step (5), according to the formula: Calculate the cosine similarity difference E(x,x) between each replaced sentence x' and the original sentence x ` ),in, and Represents the cosine similarity of the sentence vectors of two sentences, f(*) is the inference function of the machine translation model f_MT, and g(*) is the inference function of the machine translation model g_MT; (7) Take E(x,x ` ) The replaced sentence x with the highest score ` Replace the original sentence x; (8) Determine the replaced sentence x in step (7) ` Whether to meet the enhanced data set If satisfied, execute step (9); if not satisfied, execute step (11); (9) Replace the sentence x in step (7) ` The standard translation y of the corresponding replacement sentence ref Deposit into collection Z; (10) Repeat steps (2) to (9) until all enhanced data sets in the set Γ in step (2) are traversed, and the resulting set Z is the final robustness enhanced data; (11) Repeat steps (3) to (7) until the replaced sentence x ` Meet the enhanced data set Then, execute steps (9) and (10); The enhanced data set It is expressed as follows: in, is the maximum set of sentences belonging to the original text src_lang, is the maximum set of sentences to which the translation tgt_lang belongs, f(*) is the inference function of the machine translation model f_MT, g(*) is the inference function of the machine translation model g_MT, y=f(x), is the augmented data generated by modifying x, S t (*,*) is the cosine similarity of the sentence vectors of two sentences, is the dataset prepared for generating augmented data, y ref is the standard translation of x, and α, ∈, δ, and γ are adjustable custom parameters.

2. The method for improving the robustness enhancement data of machine translation generated according to vector representation according to claim 1, characterized in that: In step (11), if the pre-selected words obtained in step (4) have been traversed, and the replaced sentence x obtained in step (7) based on the pre-selected words ` Does not meet the enhanced data set Then the replaced sentence x will not be ` Store it in the set Z, and continue to repeat steps (3)-(7) until the enhanced data set in the set Γ in step (2) is traversed.

3. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program is executed by a processor to implement the method for generating data for enhancing robustness of mechanical turnover according to vector representation as claimed in any one of claims 1 to 2.

4. A device for enhancing robustness of machine turning generated according to vector representation, comprising: Processor and memory; The memory is used to store computer programs; The processor is connected to the memory and is used to execute the computer program stored in the memory, so that the device for generating the data for enhancing the robustness of machine translation according to the vector representation executes the method for generating the data for enhancing the robustness of machine translation according to the vector representation as described in any one of claims 1 to 2.