Machine translation method, device and computer readable storage medium
By generating adversarial samples for the source language and combining word segmentation and pinyin information for training, the problem of insufficient robustness of the neural network machine translation model in processing spoken text is solved, and the translation quality of the model is improved when processing noisy input text.
Patent Information
- Application Number
- CN202010102636.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-02-19
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2040-02-19
AI Technical Summary
Existing neural network machine translation models are prone to errors such as homophony/near sound, omission/omission, inversion, etc. when processing spoken text, resulting in insufficient translation robustness.
By generating adversarial samples for the source language and combining word segmentation and pinyin information for training, perturbations are added to improve the robustness of the machine translation model and improve the encoder's modeling ability when dealing with homophonic/near-sound errors.
Improved the robustness and translation quality of the machine translation model when dealing with noisy input text, allowing the model to better handle homophony/sound-proximity errors.
Smart Images

Figure CN113283249B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of neural network technology, and more specifically, to a machine translation method, a machine translation device and a computer-readable storage medium. Background Art
[0002] Machine translation is the process of converting one natural language (source language) into another natural language (target language) using computers. With the rapid development of economic globalization and the Internet, machine translation has important practical value and plays an increasingly important role in promoting political, economic and cultural exchanges.
[0003] The commonly used machine translation model is Neural Machine Translation (NMT) based on neural network technology. Since spoken text is an informal text with characteristics such as homophony, omission, inversion, and errors, NMT is prone to errors when translating spoken text.
[0004] Therefore, the inventors believe that it is necessary to improve the machine translation model to enhance the robustness of the machine translation model. Summary of the invention
[0005] One purpose of an embodiment of the present invention is to provide a new technical solution for machine translation.
[0006] According to a first aspect of an embodiment of the present invention, a machine translation method is provided, the method comprising:
[0007] Get the sentence to be translated;
[0008] Inputting the sentence to be translated into a pre-trained machine translation model to calculate a translated target sentence;
[0009] The machine translation model is obtained in the following way:
[0010] Obtaining training samples; wherein each training sample includes a source language and a target language;
[0011] Generating adversarial samples for the source language in the training samples;
[0012] The machine translation model is obtained by training based on adversarial samples.
[0013] Optionally, obtaining a training sample includes:
[0014] obtaining the source language,
[0015] Determining word segmentation information and pinyin information of the source language;
[0016] The word segmentation information and the pinyin information are mapped respectively, the word segmentation information is mapped to the word segmentation feature vector, and the pinyin information is mapped to the pinyin feature vector; the word segmentation feature vector and the pinyin feature vector constitute the training sample.
[0017] Optionally, generating an adversarial sample for the source language in the training sample includes:
[0018] Randomly sampling the source language to determine the position of the replaced word;
[0019] Determine a candidate word set;
[0020] According to the gradient direction, a replacement word is selected from the candidate word set, and the replacement word is added to the position of the replaced word to generate the adversarial sample.
[0021] Optionally, the training sample is composed of the word segmentation feature vector and the pinyin feature vector, including:
[0022] The word segmentation feature vector and the pinyin feature vector are fused and calculated to obtain the training sample.
[0023] Optionally, the training according to the adversarial sample to obtain a machine translation model includes:
[0024] The loss function is trained according to the adversarial sample and the target language in the training sample to obtain the machine translation model.
[0025] Optionally, the loss function is the cumulative sum of a source language loss term, a word segmentation information loss term and a pinyin information loss term.
[0026] According to a second aspect of the present invention, there is also provided a machine translation device, the device comprising:
[0027] An acquisition module is used to acquire sentences to be translated;
[0028] A calculation module, used for inputting the sentence to be translated into a pre-trained machine translation model to calculate a translated target sentence;
[0029] The machine translation model is obtained by training a training module; the training module includes:
[0030] An acquisition unit, used for acquiring training samples; wherein each training sample includes a source language and a target language;
[0031] A generating unit, configured to generate adversarial samples for the source language in the training samples;
[0032] The training unit is used to perform training based on adversarial samples to obtain a machine translation model.
[0033] Optionally, the generating unit is specifically used for:
[0034] The source language is randomly sampled to determine the position of the replaced word; a candidate word set is determined; a replacement word is selected from the candidate word set according to a gradient direction, and the replacement word is added to the position of the replaced word to generate the adversarial sample.
[0035] According to a third aspect of the present invention, there is also provided a machine translation device, the device comprising:
[0036] A memory and a processor; the memory is used to store executable instructions, and the processor is used to perform operations in the machine translation method according to any one of the first aspects of the present invention under the control of the instructions.
[0037] According to a fourth aspect of the present invention, there is further provided a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the machine translation method according to any one of the first aspects of the present invention is implemented.
[0038] According to one embodiment of the present invention, by introducing pinyin information and adding disturbance information to the input of the source language and the target language, the modeling ability of the encoder in the machine translation model when dealing with homophonic / near-phonetic errors is improved, the robustness of the machine translation model is improved, and the machine translation model can better handle noisy input text.
[0039] Further features and advantages of the present invention will become apparent from the following detailed description of exemplary embodiments of the present invention with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the invention and, together with the description, serve to explain the principles of the invention.
[0041] Figure 1 is a block diagram showing a hardware configuration of an electronic device that can implement an embodiment of the present invention.
[0042] Figure 2 A schematic flow chart of a machine translation method according to an embodiment of the present invention is shown;
[0043] Figure 3 is a schematic flow chart of training a machine translation model in a machine translation method according to an embodiment of the present invention;
[0044] Figure 4 is a schematic diagram of fusing pinyin information into a source language using a machine translation method according to an embodiment of the present invention;
[0045] Figure 5 A schematic diagram of perturbation of encoder input by a machine translation method according to an embodiment of the present invention;
[0046] Figure 6 A schematic diagram of perturbation of a decoder input by a machine translation method according to an embodiment of the present invention;
[0047] Figure 7 is a schematic diagram of a machine translation method according to an embodiment of the present invention;
[0048] Figure 8 is a schematic diagram of the structure of a machine translation device according to Embodiment 1 of the present invention;
[0049] Fig. 9 FIG. 4 is a schematic diagram of the structure of a machine translation device according to Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0050] Various exemplary embodiments of the present invention will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless otherwise specifically stated.
[0051] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the invention, its application, or uses.
[0052] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.
[0053] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0054] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0055] Hereinafter, various embodiments and examples according to embodiments of the present invention are described with reference to the accompanying drawings.
[0056] <Hardware Configuration>
[0057] Figure 1 is a block diagram showing a hardware configuration of an electronic device that can implement an embodiment of the present invention.
[0058] The electronic device 1000 may be a computer, a terminal device, etc.
[0059] In one example, the electronic device 1000 may be Figure 1 As shown, the electronic device 1000 includes a processor 1100, a memory 1200, an interface device 1300, a communication device 1400, a display device 1500, an input device 1600, an output device 1700 and a camera device 1800. Although the electronic device 1000 may also include a speaker, a microphone, etc., these components are irrelevant to the present invention and are therefore omitted here.
[0060] The processor 1100 may be, for example, a central processing unit (CPU), a microprocessor (MCU), etc. The memory 1200 may include, for example, a ROM (read-only memory), a RAM (random access memory), a non-volatile memory such as a hard disk, etc. The interface device 1300 may include, for example, a USB interface, a serial interface, etc. The communication device 1400 may be capable of wired or wireless communication, for example. The display device 1500 may be, for example, a liquid crystal display screen. The input device 1600 may include, for example, a touch screen, a keyboard, etc.
[0061] Figure 1 The electronic device shown is merely illustrative and does not in any way imply any limitation on the present invention, its application or use. In the embodiments of the present invention, the memory 1200 of the electronic device 1000 is used to store instructions, which are used to control the processor 1100 to operate to perform any one of the machine translation methods provided in the embodiments of the present invention.
[0062] It should be understood by those skilled in the art that although Figure 1 Multiple devices are shown for the electronic device 1000 , but the present invention may only involve some of the devices, for example, the electronic device 1000 only involves the processor 1100 and the storage device 1200 .
[0063] A technician can design instructions according to the scheme disclosed in the present invention. How instructions control the processor to operate is well known in the art, so it will not be described in detail here.
[0064] <Method Example>
[0065] Figure 2 A schematic flow chart of a machine translation method according to an embodiment of the present invention is shown.
[0066] The machine translation method of this embodiment can be specifically performed as follows: Figure 1 The electronic device 1000 shown in FIG.
[0067] like Figure 2 As shown, in step 2100, a sentence to be translated is obtained.
[0068] Step 2200: input the sentence to be translated into a pre-trained machine translation model to calculate and obtain a translated target sentence.
[0069] In this step, the machine translation model is used to translate the sentence to be translated, and a translated target sentence is output.
[0070] Specifically, Figure 3 As shown, the machine translation model is obtained in the following way:
[0071] Step 3100: Obtain training samples; wherein each training sample includes a source language and a target language.
[0072] In this step, pinyin information is added to the source language in the training sample to deal with homophonic / similar sound problems. Specifically, the electronic device 1000 obtains the source language, determines the word segmentation information and pinyin information of the source language; maps the word segmentation information and the pinyin information respectively, maps the word segmentation information to the word segmentation feature vector, and maps the pinyin information to the pinyin feature vector; and the word segmentation feature vector and the pinyin feature vector form the training sample.
[0073] Among them, the electronic device 1000 can fuse the word segmentation feature vector and the pinyin feature vector to obtain the training sample. Optionally, the word segmentation feature vector and the pinyin feature vector can be fused and calculated in a linear weighted manner, or the word segmentation feature vector and the pinyin feature vector can be fused and calculated in a nonlinear transformation manner. This embodiment does not specifically limit this.
[0074] like Figure 4 As shown, the source language obtained is "no member of parliament voted against him", and the corresponding pinyin information is "meiyou ren he yi yuan tou piao fan dui ta". The electronic device 1000 first maps (embedding) the pinyin information, and then fuses the segmentation information and the pinyin information through a fusion method such as linear weighting or nonlinear transformation to obtain a training sample. For example, the source language can be represented as E(w)=fusion(E Word (w), avg piew (E phonetic (pi))).
[0075] Step 3200, generating adversarial samples for the source language in the training samples.
[0076] Specifically, the electronic device 1000 can randomly sample the source language to determine the position of the replaced word; determine a candidate word set; select a replacement word from the candidate word set according to the gradient direction, and add the replacement word to the position of the replaced word to generate the adversarial sample.
[0077] In practical applications, the mainstream NMT model is the encoder-decoder architecture, where attention is used to bridge the encoder and decoder. The attention score is naturally calculated between the encoder and the decoder. The processing on the encoder side is based on uniform distribution sampling. For example, if the input is a sentence of 10 words, the probability of each position being sampled is 1 / 10. N positions can be sampled according to this distribution and perturbed. However, for the decoder, the addition of perturbations to the encoder input will inevitably affect the operation of the decoder. It is not expected to use only uniform distribution for sampling here, so an improved strategy is designed, that is, by paying attention to the attention of the words perturbed by the encoder, a more effective distribution is established, and then the perturbed positions are sampled based on this distribution.
[0078] Specifically, Figure 5 As shown in , the perturbation of the encoder input mainly includes: sampling the positions of the replaced words (sample positions): random sampling based on uniform distribution or distribution based on the strength of the modulus of the gradient vector. For example Figure 5 Select the words at the 2nd and 6th positions ("any" and "against") that need to be replaced, and then you need to select the replacement words.
[0079] There are two ways to sample candidate sets of replacement words: The first way is to sample replacement words from the entire vocabulary. This method is computationally expensive to select replacement words from the entire vocabulary. For example, if the vocabulary size is 50,000 words, then 50,000 operations need to be performed at each position that needs to be replaced, and the time complexity is O(|V|), which will bring huge training costs. The second way is to obtain candidate sets of replacement words from the entire vocabulary through a language model (LM) or random sampling, that is, select n candidate words (n<<|V|) as the candidate set.
[0080] Figure 5As shown in , the scores after W1, W2, ..., Wn are probability distributions of the vocabulary, which can be regarded as word weights. In this embodiment, the electronic device 1000 will sample based on this probability distribution. Specifically, one sampling method is uniform random sampling (Random), and another sampling method is to calculate the language model based on the context (LM). No specific limitation is made here.
[0081] After obtaining the candidate set of replacement words, the electronic device 1000 selects the word closest to the gradient direction from the candidate set of replacement words (gradient-based selection): Unlike images, whose pixels are continuous, text is discontinuous. The gradient direction of the embedding vector corresponding to the sampling position of the loss function may not correspond to the words in the candidate set (or even the entire vocabulary), so it is necessary to find the word closest to the gradient direction. That is, the gradient is calculated for the word vector corresponding to the word at the sampled position, such as Figure 5 In the above example, "any" and "against" are sampled, then the gradient of the embedding vectors of these two words needs to be calculated. For example, by the formula in, Find "which" and "negation" to replace "any" and "against" respectively in the input.
[0082] The e(x) function represents the embedding vector corresponding to word x, where x refers to any element in a word set Vx. Vx can be the entire word space or the word candidate set after pruning. i ) represents word x i The corresponding embedding vector, here x i It refers specifically to the word at the i-th position. xi It represents the gradient of the loss term with respect to the embedding of the word at the ith position. sim(a,b) refers to the similarity between a and b, where a and b are both embedding vectors.
[0083] For example Figure 5 In the example, the original input to the encoder is "no member of parliament voted against him". After adding the perturbation, the input becomes "no member of parliament voted against him". It should be noted that this is an ideal result after adding perturbation. In practice, the semantics of the sentence may change slightly after adding perturbation, but this is in line with expectations and can improve the robustness of the model. At the same time, the translation quality can be improved on some datasets.
[0084] Furthermore, considering that perturbing the encoder input alone cannot fully improve the robustness of the machine translation model, the decoder input also needs to be perturbed. The specific process can be as follows: Figure 6 As shown in Figure 1, the algorithm process is basically the same as the input perturbation of the encoder. The only difference lies in the sampling of the position of the replaced word. Here, the position of the replaced word is sampled based on the distribution corresponding to the attention score of the perturbed position of the encoder.
[0085] After obtaining the adversarial sample, execute step 3300:
[0086] In step 3300, training is performed based on adversarial samples to obtain a machine translation model.
[0087] The loss function is trained according to the adversarial sample and the target language in the training sample to obtain the machine translation model. Figure 7 As shown, the left half of the figure uses the above Figure 4 , Figure 5 , Figure 6 The method described, the right half of the figure is the improvement of the loss function of this embodiment, and the loss function is composed of the accumulation of three loss items, namely, the source language loss item, the word segmentation information loss item and the pinyin information loss item. After the loss value is calculated, the parameters of the machine translation model are updated according to the loss value until the parameters converge.
[0088] The technical solution of this embodiment can input the acquired sentence to be translated into a pre-trained machine translation model to calculate the translated target sentence; wherein, the machine translation model is obtained by acquiring training samples, generating adversarial samples for the source language in the training samples, and then training according to the adversarial samples. According to the method of this embodiment, the robustness of the machine translation model can be improved. And by introducing pinyin information and adding disturbance information to the input of the source language and the target language at the same time, the modeling ability of the encoder in the machine translation model when processing homophonic / near-phonetic errors is improved, and the robustness of the machine translation model is improved, so that the machine translation model can better handle noisy input text.
[0089] <Device Example>
[0090] Figure 8 FIG. 4 is a schematic diagram of the structure of a machine translation device according to Embodiment 1 of the present invention.
[0091] according to Figure 8 As shown, the machine translation device 8000 of this embodiment may include: an acquisition module 8100 and a calculation module 8200 .
[0092] The acquisition module 8100 is used to acquire the sentence to be translated;
[0093] The calculation module 8200 is used to input the sentence to be translated into a pre-trained machine translation model to calculate the translated target sentence.
[0094] The machine translation model is obtained by training with a training module 8300. Specifically, the training module 8300 may include: an acquisition unit 8301, a generation unit 8302, and a training unit 8303. The acquisition unit 8301 is used to acquire training samples; each training sample includes a source language and a target language; the generation unit 8302 is used to generate adversarial samples for the source language in the training samples; and the training unit 8303 is used to perform training according to the adversarial samples to obtain a machine translation model.
[0095] Specifically, the acquisition unit 8301 can be used to acquire the source language, determine the word segmentation information and pinyin information of the source language; respectively map the word segmentation information and the pinyin information, map the word segmentation information to the word segmentation feature vector, and map the pinyin information to the pinyin feature vector; and form the training sample from the word segmentation feature vector and the pinyin feature vector. The acquisition unit 8301 can be specifically used to perform a fusion calculation on the word segmentation feature vector and the pinyin feature vector to obtain the training sample.
[0096] Specifically, the generating unit 8302 is specifically used to randomly sample the source language to determine the position of the replaced word; determine a candidate word set; select a replacement word from the candidate word set according to the gradient direction, and add the replacement word to the position of the replaced word to generate the adversarial sample.
[0097] Specifically, the training unit 8303 is specifically used to train the loss function according to the adversarial sample and the target language in the training sample to obtain the machine translation model. The loss function is the cumulative sum of the source language loss term, the word segmentation information loss term and the pinyin information loss term.
[0098] Fig. 9 FIG. 4 is a schematic diagram of the structure of a machine translation device according to Embodiment 2 of the present invention.
[0099] like Fig. 9 As shown, in this embodiment, the machine translation device 9000 may include a memory 9100 and a processor 9200; the memory 9100 is used to store executable instructions, and the processor 9200 is used to execute the operations in the machine translation method provided in any one of the above embodiments according to the control of the instructions.
[0100] Those skilled in the art will appreciate that the machine translation device can be implemented in various ways. For example, the machine translation device can be implemented by configuring the processor with instructions. For example, the instructions can be stored in a ROM, and when the device is started, the instructions are read from the ROM into a programmable device to implement the machine translation device. For example, the machine translation device can be solidified into a special-purpose device (such as an ASIC). The machine translation device can be divided into independent units, or they can be combined together to implement. The machine translation device can be implemented by one of the various implementations described above, or can be implemented by a combination of two or more of the various implementations described above.
[0101] <Computer Readable Storage Medium>
[0102] In this embodiment, a computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed by a processor, the machine translation method according to any embodiment of the present invention is implemented.
[0103] It is well known to those skilled in the art that with the development of electronic information technology such as large-scale integrated circuit technology and the trend of software hardware, it has become more difficult to clearly divide the boundaries between software and hardware in computer systems. Because any operation can be implemented by software or by hardware. The execution of any instruction can be completed by hardware or by software. Whether a hardware implementation or a software implementation is adopted for a certain machine function depends on non-technical factors such as price, speed, reliability, storage capacity, and change cycle. For technicians, software implementation and hardware implementation are equivalent. Technicians can choose software or hardware to implement the above solution as needed. Therefore, no restriction is made to specific software or hardware here.
[0104] The present invention may be a device, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present invention.
[0105] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0106] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0107] The computer program instructions for performing the operation of the present invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be personalized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present invention.
[0108] Various aspects of the present invention are described herein with reference to the flow charts and / or block diagrams of the methods, devices (systems) and computer program products according to embodiments of the present invention. It should be understood that each box of the flow chart and / or block diagram and the combination of each box in the flow chart and / or block diagram can be implemented by computer-readable program instructions.
[0109] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0110] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0111] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a part of a module, a program segment or an instruction, and a part of the module, a program segment or an instruction contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions. It is well known to those skilled in the art that it is equivalent to implement it by hardware, implement it by software, and implement it by combining software and hardware.
[0112] Embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the marketplace, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein. The scope of the present invention is defined by the appended claims.
Claims
1. A machine translation method, characterized in that: The method comprises: Get the sentence to be translated; Inputting the sentence to be translated into a pre-trained machine translation model to calculate a translated target sentence; The machine translation model is obtained in the following way: Obtaining training samples; wherein each training sample includes a source language and a target language; Generating adversarial samples for the source language in the training samples; Performing training according to the adversarial sample to obtain the machine translation model; The generating of adversarial samples for the source language in the training samples includes: using the source language to determine the position of the replaced word corresponding to the encoder and the attention score of the position of the replaced word; based on the attention score, determining the position of the replaced word corresponding to the decoder; based on the position of the replaced word corresponding to the decoder, constructing an adversarial sample corresponding to the decoder, wherein the adversarial sample includes the adversarial sample corresponding to the decoder in the machine translation model and the adversarial sample corresponding to the encoder in the machine translation model.
2. The method according to claim 1, characterized in that The obtaining of training samples comprises: obtaining the source language, Determining word segmentation information and pinyin information of the source language; Mapping the word segmentation information and the pinyin information respectively, mapping the word segmentation information into a word segmentation feature vector, and mapping the pinyin information into a pinyin feature vector; The training sample is composed of the word segmentation feature vector and the pinyin feature vector.
3. The method according to claim 1, characterized in that The generating the adversarial sample for the source language in the training sample comprises: Determine a candidate word set; According to the gradient direction, a replacement word is selected from the candidate word set, and the replacement word is added to the position of the replaced word corresponding to the encoder to generate an adversarial sample corresponding to the encoder.
4. The method according to claim 2, characterized in that: The training sample is composed of the word segmentation feature vector and the pinyin feature vector, including: The training sample is obtained by fusing the word segmentation feature vector and the pinyin feature vector.
5. The method according to claim 3, characterized in that: The machine translation model is obtained by training according to the adversarial sample, including: The loss function is trained according to the adversarial sample and the target language in the training sample to obtain the machine translation model.
6. The method according to claim 5, characterized in that The loss function is the cumulative sum of the source language loss term, the word segmentation information loss term and the pinyin information loss term.
7. A machine translation device, characterized in that: The device comprises: An acquisition module is used to acquire sentences to be translated; A calculation module, used for inputting the sentence to be translated into a pre-trained machine translation model to calculate a translated target sentence; The machine translation model is obtained by training a training module; the training module includes: An acquisition unit, used for acquiring training samples; wherein each training sample includes a source language and a target language; A generating unit, configured to generate adversarial samples for the source language in the training samples; A training unit, used for performing training according to the adversarial sample to obtain the machine translation model; The generation unit is also used to generate adversarial samples for the source language in the training sample through the following steps: using the source language, determining the position of the replaced word corresponding to the encoder, and the attention score of the position of the replaced word; based on the attention score, determining the position of the replaced word corresponding to the decoder; based on the position of the replaced word corresponding to the decoder, constructing an adversarial sample corresponding to the decoder, wherein the adversarial sample includes the adversarial sample corresponding to the decoder in the machine translation model, and the adversarial sample corresponding to the encoder in the machine translation model.
8. The device according to claim 7, characterized in that The generating unit is specifically used for: Determine a candidate word set; select a replacement word from the candidate word set according to the gradient direction, and add the replacement word to the position of the replaced word corresponding to the encoder to generate an adversarial sample corresponding to the encoder.
9. A machine translation device, characterized in that: The device comprises: A memory and a processor; the memory is used to store executable instructions, and the processor is used to perform operations in the machine translation method according to any one of claims 1-6 under the control of the instructions.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, which, when executed by a processor, implements the machine translation method according to any one of claims 1 to 6.
