Machine translation model training method, machine translation method, device and equipment
By using gradient vectors to generate aggressive adversarial samples during the training process of the machine translation model and conducting adversarial training, the problem of insufficient robustness of the neural network machine translation model in a noisy environment is solved and the translation performance and accuracy are improved. .
Patent Information
- Application Number
- CN202111389048.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-22
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2041-11-22
AI Technical Summary
Existing neural network machine translation models are not robust enough in noisy environments, resulting in reduced translation performance. Existing adversarial sample generation methods may lead to semantic changes or logical confusion, which in turn makes the model less aggressive.
By using gradient vectors to generate adversarial samples during the training process, and conducting adversarial training based on training samples and adversarial samples, the robustness of the model is increased. The specific method includes sampling training samples, obtaining the target word vector, selecting the candidate word vector with the largest distance from the vector as replacement, generating adversarial samples, and iteratively adjusting model parameters until convergence conditions are met.
The robustness and translation performance of the machine translation model are improved, enabling more accurate translation results to be output in noisy environments.
Smart Images

Figure CN114154520B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a training method for a machine translation model, a machine translation method, a device and equipment. Background Art
[0002] With the continuous development of computer technology, machine translation models based on neural networks have shown excellent translation performance, and machine translation using machine translation models has gradually become the mainstream translation method. However, due to the fragility of neural networks, when unexpected noises such as input offsets, disturbances, and human attacks appear in actual applications and real environments, the translation performance of machine translation models will be significantly reduced. Therefore, how to improve the robustness of machine translation models in noisy environments has become an urgent problem to be solved.
[0003] In the related art, in order to improve the robustness of the machine translation model, during the training phase of the machine translation model, adversarial samples are generated for the training samples through text editing operations (such as insertion, deletion, replacement, exchange, etc.), and then the machine translation model is trained based on the generated adversarial samples.
[0004] However, text editing operations may cause changes in the semantics of a sentence, or cause confusion in the grammatical logic of the sentence, making the generated adversarial samples less aggressive, and thus making the translation performance of the machine translation model unstable under specific noise, and the translation results obtained by the machine translation model are not accurate enough. Summary of the invention
[0005] The present application provides a machine translation model training method, a machine translation method, a device and equipment, which can solve the problems in the related technology.
[0006] In a first aspect, a method for training a machine translation model is provided, the method comprising:
[0007] A training sample set is obtained, wherein the training sample set includes training samples and standard translation texts corresponding to the training samples; the training samples and the standard translation texts corresponding to the training samples are input into a machine translation model to obtain a gradient vector generated by the machine translation model during back propagation; adversarial samples are generated for the training samples based on the gradient vector and a plurality of noise words; adversarial training is performed on the machine translation model based on the training samples and the adversarial samples to obtain a target machine translation model.
[0008] In one possible implementation, generating an adversarial sample for the training sample based on the gradient vector and multiple noise words includes: sampling the training sample, obtaining a target word vector according to the sampling result, and the target word vector is the word vector that needs to be replaced; obtaining at least one candidate word vector corresponding to the target word vector from the vector space of the multiple noise words; based on the gradient vector, selecting a target candidate word vector corresponding to the target word vector from the at least one candidate word vector; and replacing the target word vector in the training sample with the target candidate word vector to obtain an adversarial sample.
[0009] In one possible implementation, selecting a target candidate word vector corresponding to the target word vector from the at least one candidate word vector based on the gradient vector includes: updating the target word vector based on the gradient vector to obtain an updated word vector; and selecting, from the at least one candidate word vector, a candidate word vector with the largest distance from the updated word vector as the target candidate word vector.
[0010] In a possible implementation, updating the target word vector based on the gradient vector to obtain the updated word vector includes: obtaining a target gradient vector corresponding to the target word vector from the gradient vector; and updating the target word vector along the direction of the target gradient vector to obtain the updated word vector.
[0011] In a possible implementation, the adversarial training of the machine translation model based on the training sample and the adversarial sample to obtain a target machine translation model includes: obtaining a first predicted translation text output by the machine translation model according to the training sample, and obtaining a first loss function value based on the first predicted translation text and the standard translation text; obtaining a second predicted translation text output by the machine translation model according to the adversarial sample, and obtaining a second loss function value based on the second predicted translation text and the standard translation text; obtaining a target loss function value based on the first loss function value and the second loss function value; and iteratively adjusting the model parameters of the machine translation model and the adversarial sample according to the target loss function value until a convergence condition is met to obtain a target machine translation model.
[0012] In a possible implementation, obtaining a target loss function value based on the first loss function value and the second loss function value includes: obtaining a weighted sum of the first loss function value and the second loss function value, and obtaining the target loss function value according to the weighted sum.
[0013] In a possible implementation, the model parameters of the machine translation model and the adversarial sample are iteratively adjusted according to the target loss function value until a convergence condition is met to obtain a target machine translation model, including: if the target loss function value is greater than a target threshold, the model parameters of the machine translation model and the adversarial sample are iteratively adjusted according to the target loss function value until a convergence condition is met to obtain a target machine translation model; if the target loss function value is less than or equal to the target threshold and the convergence condition is met, the machine translation model under the current model parameters is used as the target machine translation model.
[0014] In a second aspect, a machine translation method is provided, the method comprising:
[0015] Obtain content to be translated; and obtain a translation result corresponding to the content to be translated through a machine translation model, wherein the machine translation model is trained according to any one of the machine translation model training methods in the first aspect above.
[0016] In a third aspect, a training device for a machine translation model is provided, the device comprising:
[0017] A first acquisition module is used to acquire a training sample set, wherein the training sample set includes training samples and standard translation texts corresponding to the training samples;
[0018] A second acquisition module is used to input the training sample and the standard translation text corresponding to the training sample into the machine translation model to obtain the gradient vector generated by the machine translation model during the back propagation process;
[0019] A generating module, configured to generate an adversarial sample for the training sample based on the gradient vector and a plurality of noise words;
[0020] A training module is used to perform adversarial training on the machine translation model based on the training sample and the adversarial sample to obtain a target machine translation model.
[0021] In one possible implementation, a generation module is used to sample the training sample, obtain a target word vector based on the sampling result, and the target word vector is the word vector that needs to be replaced; obtain at least one candidate word vector corresponding to the target word vector from the vector space of the multiple noise words; based on the gradient vector, select a target candidate word vector corresponding to the target word vector from the at least one candidate word vector; replace the target word vector in the training sample with the target candidate word vector to obtain an adversarial sample.
[0022] In one possible implementation, a generation module is used to update the target word vector based on the gradient vector to obtain an updated word vector; and from the at least one candidate word vector, select a candidate word vector with the largest distance from the updated word vector as the target candidate word vector.
[0023] In a possible implementation, a generation module is used to obtain a target gradient vector corresponding to the target word vector from the gradient vector; and update the target word vector along the direction of the target gradient vector to obtain the updated word vector.
[0024] In one possible implementation, a training module is used to obtain a first predicted translation text output by the machine translation model based on the training sample, and obtain a first loss function value based on the first predicted translation text and the standard translation text; obtain a second predicted translation text output by the machine translation model based on the adversarial sample, and obtain a second loss function value based on the second predicted translation text and the standard translation text; obtain a target loss function value based on the first loss function value and the second loss function value; and iteratively adjust the model parameters of the machine translation model and the adversarial sample according to the target loss function value until a convergence condition is met to obtain a target machine translation model.
[0025] In a possible implementation, the training module is used to obtain a weighted sum of the first loss function value and the second loss function value, and obtain a target loss function value according to the weighted sum.
[0026] In one possible implementation, the training module is used to iteratively adjust the model parameters of the machine translation model and the adversarial sample according to the target loss function value until the convergence condition is met to obtain the target machine translation model if the target loss function value is greater than the target threshold; if the target loss function value is less than or equal to the target threshold and the convergence condition is met, the machine translation model under the current model parameters is used as the target machine translation model.
[0027] In a fourth aspect, a machine translation device is provided, the device comprising:
[0028] The acquisition module is used to obtain the content to be translated;
[0029] A translation module is used to obtain a translation result corresponding to the content to be translated through a machine translation model, wherein the machine translation model is trained according to any one of the machine translation model training methods in the first aspect above.
[0030] In a fifth aspect, a computer device is also provided, comprising a processor and a memory, wherein the memory stores at least one program code, and the at least one program code is loaded and executed by the processor so that the computer device implements the training method of the machine translation model described in any one of the above items, or the machine translation method described in any one of the above items.
[0031] In the sixth aspect, a computer-readable storage medium is also provided, in which at least one program code is stored, and the at least one program code is loaded and executed by a processor so that a computer implements any of the above-mentioned training methods for machine translation models, or any of the above-mentioned machine translation methods.
[0032] In a seventh aspect, a computer program product or a computer program is also provided, wherein the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes any of the above-mentioned training methods for machine translation models, or any of the above-mentioned machine translation methods.
[0033] The technical solution provided by this application can at least bring the following beneficial effects:
[0034] The technical solution provided in the present application generates adversarial samples that are more aggressive to the machine translation model through the gradient vectors generated during the training process of the machine translation model, and conducts adversarial training on the model based on the training samples and the adversarial samples at the same time, thereby increasing the diversity of training data, improving the robustness of the machine translation model, and further improving the translation performance of the machine translation model, making the translation results obtained by the machine translation model more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the technical solutions in the embodiments of the present application, 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 application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0036] Figure 1 It is a schematic diagram of an implementation environment of a training method for a machine translation model provided in an embodiment of the present application;
[0037] Figure 2 It is a flowchart of a method for training a machine translation model provided in an embodiment of the present application;
[0038] Figure 3is a schematic diagram of a machine translation model provided in an embodiment of the present application;
[0039] Figure 4 is a flow chart of a machine translation method provided by an embodiment of the present application;
[0040] Figure 5 is a schematic diagram of a training device for a machine translation model provided in an embodiment of the present application;
[0041] Figure 6 is a schematic diagram of a machine translation device provided in an embodiment of the present application;
[0042] Figure 7 is a structural schematic diagram of a computer device provided in an embodiment of the present application;
[0043] Figure 8 It is a structural diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0045] See also Figure 1 , Figure 1 A schematic diagram of an implementation environment of a method for training a machine translation model provided in an embodiment of the present application, wherein the implementation environment includes a terminal device 101 and a server 102 for training a machine translation model, wherein the terminal device 101 and the server 102 are connected via a network, which may be a wired network or a wireless network. The terminal device 101 can provide the server 102 with training samples and standard translation texts corresponding to the training samples.
[0046] After the server 102 obtains the training samples and the standard translation texts corresponding to the training samples from the terminal device 101 through the network, the server 102 uses all the obtained training samples and the standard translation texts corresponding to the training samples as a training sample set; then, the training sample set is input into the machine translation model, and the server 102 obtains the gradient vector generated by the machine translation model during the back propagation process, and generates adversarial samples for the training samples based on the gradient vector and multiple noise words; then, the server 102 performs adversarial training on the machine translation model based on the training samples and the adversarial samples to obtain the target machine translation model. It should be noted that in the process of adversarial training, the adversarial samples are updated with the update of the gradient vector of each iteration.
[0047] After the server 102 obtains the target machine translation model through training, the target machine translation model can be further sent to the terminal device 101 to run the target machine translation model on the terminal device 101 and implement corresponding functions using the target machine translation models.
[0048] It should be noted that the above Figure 1 The implementation environment shown is only an example. In actual applications, the terminal device 101 and the server 102 can also train the machine translation model separately.
[0049] Based on the above Figure 1 In the implementation environment shown, the present application embodiment provides a method for training a machine translation model. For ease of description, the following embodiment is described with the server 102 as the execution subject. It should be understood that the execution subject of the machine translation model training method is not limited to the server 102, but can also be applied to devices with model training functions such as the terminal device 101. Figure 2 As shown, the training method of the machine translation model includes but is not limited to the following steps 201 to 204.
[0050] Step 201: Obtain a training sample set, where the training sample set includes training samples and standard translation texts corresponding to the training samples.
[0051] In an embodiment of the present application, the server obtains a training sample set to train a machine translation model using training samples in the training sample set; the training sample set includes multiple training samples and standard translation texts corresponding to each of the training samples.
[0052] In a possible implementation, the server may obtain some historical data from a relevant database, the some historical data including some texts and translation texts corresponding to the texts, and use the obtained some historical data as a training sample set. It should be understood that when the execution subject of the training method of the neural network model provided in the embodiment of the present application is a terminal device, the terminal device may initiate a request to the server to obtain historical data, and obtain some historical data from the server as a training sample set.
[0053] Optionally, the training sample includes but is not limited to at least one of the text, video or audio to be translated, and the standard label corresponding to the training sample is the standard translation text. When the training sample is the text to be translated, the standard label corresponding to the training sample is the standard translation text corresponding to the text to be translated; when the training sample is the video to be translated, it is usually used in the application scenario of image annotation, and the standard label corresponding to the training sample is the standard translation text, which is the text information corresponding to the scene presented by the video to be translated; when the training sample is the audio to be translated, the standard label corresponding to the training sample is still the standard translation text, which is the text information corresponding to the audio to be translated.
[0054] The above training samples are usually composed of a group of ordered elements, that is, the training samples can be expressed as an element sequence. Taking a training sample including i (i is a positive integer greater than 0) elements as an example, the training sample can be expressed as X = {x 1 , x 2 , x 3 , …, x i}, the length of the training sample is i, x i It represents the i-th word in the training sample, or it can also be called the i-th token; for example, if the text to be translated as the training sample is "I love my hometown", the training sample can be expressed as {I, love, home, hometown} accordingly; for another example, if the text to be translated as the training sample is "Today is Monday", the training sample can be expressed as {Today, is, Monday} accordingly.
[0055] Step 202: input the training samples and the standard translation texts corresponding to the training samples into the machine translation model, and obtain the gradient vectors generated by the machine translation model during the back propagation process.
[0056] In an embodiment of the present application, after the server obtains the training sample set, the training samples in the training sample set and the standard translation texts corresponding to the training samples are input into the machine translation model one by one, so as to train the machine translation model using the training samples in the training sample set and the standard translation texts corresponding to the training samples, so as to obtain the gradient vector generated by the machine translation model during the back propagation process in the training stage.
[0057] Optionally, the machine translation model is a pre-built network model, and the embodiment of the present application does not limit the structure of the machine translation model. For example, the machine translation model can be a recurrent neural network model (RNN), a neural machine translation model (NMT) or an encoder-decoder (Encoder-Decoder) and other structures; the embodiment of the present application does not limit the framework for constructing the machine translation model, for example, the machine translation model is constructed based on the FairSeq framework using a Transformer model.
[0058] In a possible implementation, before inputting the training samples and the standard translation texts corresponding to the training samples into the machine translation model, the method further includes: preprocessing the training samples in the training sample set, and inputting the preprocessed training samples into the machine translation model. Optionally, the preprocessing method may be: performing word segmentation processing on the training samples, for example, using the Jieba word segmenter; performing regularization processing on the punctuation marks in the training samples, for example, using the Moses decoder script tool.
[0059] For example, see Figure 3 The machine translation model includes an encoder and a decoder. The structures of the encoder and the decoder are similar or identical. Optionally, the encoder may include a multi-layer attention mechanism unit and a feedforward neural network unit, such as a self-attention mechanism unit (Self-attention) and a multi-head attention mechanism unit (Muiti-head Attention), etc.; the decoder may include a self-attention mechanism and a cross-attention mechanism (Cross-attention), etc.
[0060] In one possible implementation, Figure 3 Taking the machine translation model shown as an example, the training samples and the standard translation texts corresponding to the training samples are input into the machine translation model to obtain the gradient vectors generated by the machine translation model during the back propagation process, including: inputting the training samples in the training sample set and the standard translation texts corresponding to the training samples into the encoder and decoder of the machine translation model, obtaining the predicted translation text output by the machine translation model through forward propagation, and obtaining the loss function value corresponding to the training sample based on the comparison result between the predicted translation text corresponding to the training sample and the standard translation text; performing back propagation based on the loss function value obtained in the forward propagation to obtain the gradient vector generated during the back propagation process.
[0061] Step 203: Generate adversarial samples for the training samples based on the gradient vector and multiple noise words.
[0062] In a possible implementation, before generating adversarial samples for training samples based on gradient vectors and multiple noise words, it further includes: obtaining multiple noise words. The embodiments of the present application do not limit the manner of obtaining multiple noise words, as long as the obtained multiple noise words can generate adversarial samples for the training samples.
[0063] Optionally, the multiple noise words include multiple pairs of homophones or paronyms. Obtaining multiple noise words includes: obtaining a sentence database; performing data statistics on homophones or paronyms of multiple words included in the sentence database, and obtaining multiple noise words according to the statistical results. Exemplarily, the multiple noise words can be embodied in the form of a noise word table, and the content recorded in each row of the noise word table is: word, the corresponding homophone or paronym of the word, for example: "它、->他".
[0064] Optionally, the sentence database can adopt the STC (Speech Translation Corpus) dataset. The STC dataset is constructed based on a set of licensed speech or lecture videos, including approximately 68 hours of Mandarin data, manual records and English translations, as well as automatic records of the ASR (Automatic Speech Recognition) model, with a total of 188,317 data entries. Optionally, the data statistics on homophones or paronyms in the STC dataset can be implemented by means of the python open-source toolkit asr-evaluation.
[0065] The most common ASR noise in Chinese speech recognition is "words with the same pronunciation but different characters", such as "我与他" and "我于它". Refer to Table 1, which shows the comparison between the translation results of the machine translation model under the input of ASR noise text and the standard translation results. It can be seen from Table 1 that in the face of the input of ASR noise text, the semantic differences between the translation results of the baseline machine translation model and the standard translation text are relatively large.
[0066] Table 1
[0067]
[0068] Therefore, in order to solve the instability of translation performance caused by the above-mentioned ASR noise of "words with the same pronunciation but different characters", the multiple noise words constructed in the embodiments of the present application include multiple pairs of homophones or paronyms. The multiple noise words are used to provide candidate words for the generation of adversarial samples. During the process of generating adversarial samples, they can implicitly construct appropriate acoustic features for word vectors and尽可能 ensure that the semantics of the adversarial samples do not change.
[0069] In a possible implementation, generating adversarial samples for training samples based on gradient vectors and multiple noise words includes: sampling the training samples, obtaining a target word vector according to the sampling result, the target word vector being the word vector to be replaced; obtaining at least one candidate word vector corresponding to the target word vector from the vector space of multiple noise words; selecting a target candidate word vector corresponding to the target word vector from at least one candidate word vector based on the gradient vector, replacing the target word vector in the training sample with the target candidate word vector, and obtaining an adversarial sample. The target candidate word vector is the candidate word vector that has the greatest similarity with the target word vector and is most aggressive to the machine translation model among at least one candidate word vector.
[0070] In the embodiment of the present application, the sampling method for determining the target word vector in the training sample is not limited. Optionally, the sampling method can be random sampling, that is, the training sample is randomly sampled by setting a random seed, for example, the seed is set to 20%, and the training sample includes 10 word vectors, then 2 word vectors of the training sample are randomly selected as the target word vector.
[0071] In a possible implementation, multiple noise words are embodied in the form of a noise word list, wherein the noise word list also includes the frequency of occurrence of each pair of homophones or phonetic words in the data statistics process, that is, the word frequency. Exemplarily, the content of each row in the noise word list is recorded as: word, homophone or phonetic word corresponding to the word, word frequency, for example: "it, -> he, 9131".
[0072] Optionally, the sampling method may also be word frequency sampling, that is, sampling the training samples according to the word frequency of each word vector in the training samples in multiple noise words, for example, obtaining the word vector in the training sample whose word frequency is greater than the word frequency threshold as the target word vector. The word frequency threshold can be set based on experience or flexibly adjusted according to the application scenario.
[0073] Since multiple noise words include the correspondence between words and homonyms or phonetic words, after sampling the training samples and obtaining the target word vector according to the sampling results, the word vector corresponding to the target word vector and at least one homonym vector or phonetic word vector corresponding to the word vector can be found from the vector space of multiple noise words, and then the target candidate word vector corresponding to the target word vector can be obtained.
[0074] In one possible implementation, based on the gradient vector, a target candidate word vector corresponding to the target word vector is selected from at least one candidate word vector, including: updating the target word vector based on the gradient vector to obtain an updated word vector; and selecting, from at least one candidate word vector, a candidate word vector having the largest distance from the updated word vector as the target candidate word vector.
[0075] In the embodiment of the present application, since the gradient vector generated during the back propagation process of the machine translation model is used in the process of acquiring the target candidate word vector corresponding to the target word vector, the target candidate word vector is used as an adversarial sample generated by replacement, which not only has a high similarity with the target word vector, but also has a greater aggressiveness to the machine translation model.
[0076] In a possible implementation, updating the target word vector based on the gradient vector to obtain the updated word vector includes: obtaining a target gradient vector corresponding to the target word vector from the gradient vector; and updating the target word vector along the direction of the target gradient vector to obtain the updated word vector.
[0077] For example, X = {x 1 , x 2 , x 3 , …, x i} represents the training sample, and X′={x′ 1 , x′ 2 , x′ 3 ,…,x′ i} represents adversarial samples, x′ i represents the i-th word in the adversarial sample, or can also be called the i-th token in the adversarial sample, and G = {g 1 , g 2 , g 3 , …, g i} represents the gradient vector generated by the machine translation model based on the training sample during the propagation process. Optionally, the target candidate word vector can be selected from at least one candidate word vector by the following formula (1).
[0078] Max[Sim(e(x),e(x i )-λg i )] Formula (1)
[0079] Among them, x i is the i-th token in the training sample, e(x i ) is the vector representation of the i-th token, that is, the i-th word vector in the training sample; x is the replacement x i candidate word, e(x) is the vector representation of x, that is, any candidate word vector in at least one candidate word vector; g i is x i The corresponding gradient is the gradient vector x generated by back propagation during training. i The gradient corresponding to the position; e(x i )-λg i is the updated word vector obtained based on the gradient vector during training; Sim represents the Euclidean distance function, Sim(e(x),e(x i )-λgi ) is used to obtain e(x) and e(x i )-λg i The distance between them, λ is a hyperparameter; Max represents the maximum value function, which is used to obtain the maximum distance value, that is, the x corresponding to the maximum distance value is the target candidate word x′ i .
[0080] The hyperparameter λ can be set based on experience or flexibly adjusted according to the application scenario. For example, the hyperparameter λ=0.1.
[0081] The selection criteria for generating adversarial samples based on the above formula (1) are: from the vector space of at least one candidate word vector, select the candidate word vector with the largest distance to the updated word vector as the target candidate word vector, replace the i-th token in the training sample with the target candidate word, and the replaced training sample is the adversarial sample with the greatest offensiveness to the model.
[0082] In order to more clearly illustrate the specific performance of the above formula (1) in the training process of the machine translation model, let y = e(x), y′ = e(x i ), that is, use y as the vector representation of the candidate word and y′ as the vector representation of the i-th token in the training sample. Then the above formula (1) can be expanded into the following formula (2).
[0083] Max[Sim(e(x),e(x i )-λg i )]=Max[Sim(y,y′-λg i )] Formula (2)
[0084] Since Sim is the Euclidean distance, Sim(y,y′-λg i ) can be converted to <y-(y′-λg i ),y-(y′-λg i )>, that is, [(yy′)+λg i ] T [(yy′)+λg i ]; if t=(yy′), the above formula can also be converted to [t+λg i ] T [t+λg i ]; further expansion is t T t+2λt T g i +λ 2 g i T g i . Since λ 2 g i T g iThe tokens to be replaced are all the same, so they can be ignored when solving Max. Then the above formula (2) can be written as the following formula (3).
[0085] Max(t T t+2λt T g i ) Formula (3)
[0086] It can be seen from formula (3) that e(x) and e(x i )-λg i The distance between them is expressed as t T t and 2λt T g i Two parts. Among them, t T t represents the Euclidean distance between y and y', which shortens the distance between the real word and the candidate word, which is equivalent to implicitly constructing a suitable acoustic feature for the word; T g i =(yy′) T *g i =Sim(yy′,g i ) represents the cosine similarity in the gradient direction, so that the selected target candidate words can produce the greatest attack on the machine translation model.
[0087] Step 204: Perform adversarial training on the machine translation model based on the training samples and the adversarial samples to obtain a target machine translation model.
[0088] In one possible implementation, adversarial training is performed on a machine translation model based on training samples and adversarial samples to obtain a target machine translation model, including: obtaining a first predicted translation text output by the machine translation model according to the training samples, and obtaining a first loss function value based on the first predicted translation text and a standard translation text; obtaining a second predicted translation text output by the machine translation model according to the adversarial sample, and obtaining a second loss function value based on the second predicted translation text and the standard translation text; obtaining a target loss function value based on the first loss function value and the second loss function value; and iteratively adjusting model parameters and adversarial samples of the machine translation model according to the target loss function value until convergence conditions are met to obtain a target machine translation model.
[0089] It should be noted that in the iterative process of machine translation model training, in addition to iteratively adjusting the model parameters of the machine translation model according to the target loss function value, the adversarial samples are iteratively updated according to the gradient vectors iteratively generated by the machine translation model during the back-propagation process. In other words, adversarial sample generation and adversarial training are performed in the same process, that is, adversarial training is performed based on adversarial samples while adversarial samples are generated, so that the adversarial samples remain highly aggressive to the machine translation model during the iterative adjustment of the machine translation model.
[0090] Optionally, the method of iteratively updating adversarial samples is the same as the method of generating adversarial samples as described above, that is, sampling the training samples, and obtaining a target word vector based on the sampling results, where the target word vector is the word vector that needs to be replaced; obtaining at least one candidate word vector corresponding to the target word vector from the vector space of multiple noise words; updating the target word vector based on the gradient vector generated iteratively to obtain an updated word vector; from at least one candidate word vector, selecting the candidate word vector with the largest distance to the updated word vector as the target candidate word vector; replacing the target word vector in the training sample with the target candidate word vector to obtain an updated adversarial sample.
[0091] In an embodiment of the present application, the generated adversarial samples are input into the machine translation model for continued training. On the one hand, this increases the diversity of the training data. On the other hand, since the adversarial samples add noise disturbances, they can attack the machine translation model, enabling the machine translation model to better learn the noise characteristics and enhance the robustness of the machine translation model.
[0092] In a possible implementation, based on the first loss function value and the second loss function value, obtaining a target loss function value includes: obtaining a weighted sum of the first loss function value and the second loss function value, and obtaining the target loss function value based on the weighted sum. Based on the first loss function value output by the machine translation model according to the training sample and the second loss function value output according to the adversarial sample, the target loss function value is obtained, and the machine translation model is trained based on the target loss function value, thereby achieving adversarial between the training sample and the adversarial sample.
[0093] Optionally, training the machine translation model is a process of optimizing the target, and optionally, the target is the standard translation text corresponding to the training sample. The optimization target refers to the process of calculating the loss function based on the prediction results output by the machine translation model during the machine translation process, and adjusting the parameters in the machine translation model according to the calculation result of the loss function, so that the prediction results output by the machine translation model after parameter adjustment are as close to the optimization target as possible, that is, the calculation result of the loss function is minimized. Among them, the loss function is used to describe the gap between the model prediction value and the optimization target. The smaller the value of the loss function, the more accurate the prediction result of the model.
[0094] In one possible implementation, the model parameters and adversarial samples of the machine translation model are iteratively adjusted according to the target loss function value until the convergence condition is met to obtain the target machine translation model, including: if the target loss function value is greater than the target threshold, the model parameters and adversarial samples of the machine translation model are iteratively adjusted according to the target loss function value until the convergence condition is met to obtain the target machine translation model; if the target loss function value is less than or equal to the target threshold and the convergence condition is met, the machine translation model under the current model parameters is used as the target machine translation model.
[0095] Optionally, the target threshold may be set based on experience, or flexibly adjusted based on experience. For example, the target threshold is any value greater than or equal to 0 and less than or equal to 1.
[0096] The trained machine translation model can be implemented as a part of the application and installed in the terminal, so that the terminal outputs the translation result when receiving the content to be translated; or, the trained machine translation model is set in the background server of the application, so that the terminal with the application installed can realize the translation function with the help of the background server.
[0097] See also Figure 3 , Figure 3 A schematic diagram of a machine translation model provided in an embodiment of the present application. Figure 3 Taking the machine translation model shown as an example, the training method of the machine translation model provided in the embodiment of the present application is explained.
[0098] First, the training sample X = {x 1 , x 2 , x 3 , …, x i}The input is sent to the encoder and decoder of the machine translation model, and after forward propagation through the hidden layer (Hidden), the corresponding clean input translation loss is represented by Loss_ref. Clean input refers to the training sample that is directly input, that is, the training sample without adding noise.
[0099] Then, in the back propagation process, the gradient vector (Gradient) G = {g 1 , g 2 , g 3 , …, g i}, according to the gradient value g i According to the selection criteria of the target candidate words in formula (1), select the words that match x from the confusion set. i The target candidate word with the highest similarity and the highest offensiveness to the model is used to replace the current x i , thus obtaining the adversarial sample X′={x′1 , x′ 2 , x′ 3 ,…,x′ i}.
[0100] The generated adversarial sample X′={x′ 1 , x′ 2 , x′ 3 ,…,x′ i}The input is sent to the encoder and decoder of the machine translation model for adversarial training. After Hidden forward propagation, the corresponding translation loss of the noise input is obtained and represented by Loss_adv.
[0101] Finally, the loss value (Loss) output by the machine translation model is the weighted sum of the translation loss Loss_ref of the clean input and the translation loss Loss_adv of the noisy input. Optionally, the loss value is expressed by the following formula (4).
[0102] Loss=α*Loss_ref+β*Loss_adv formula (4)
[0103] Among them, α and β are weight coefficients, and α and β may be the same or different. Optionally, α and β may be set based on experience or flexibly adjusted based on application scenarios, for example, α=0.2, β=0.3.
[0104] The training method of the machine translation model provided in the embodiment of the present application utilizes the gradient values generated during the back propagation process of the neural network to select noise candidate words in a targeted manner, construct adversarial samples that are more aggressive to the machine translation model, and perform adversarial training on the model based on the training samples and the adversarial samples at the same time, thereby increasing the diversity of training data, thereby improving the robustness of the machine translation model, and further improving the translation performance of the machine translation model.
[0105] Since the internal parameter information of the model, such as the gradient vector, can be seen when the adversarial sample is generated, the training method of the machine translation model provided in the embodiment of the present application can be referred to as a white-box method.
[0106] Below, in order to verify the effectiveness of the training method of the machine translation model provided in the embodiment of the present application, the following two test experiments are used for illustration. In the following two test experiments, the white box method is used to represent the training method of the machine translation model provided in the embodiment of the present application.
[0107] Experiment 1
[0108] The WMT (Workshop on Machine Translation) test set data was used to test the machine translation model using the Bilingual Evaluation Understudy (BLEU) tool. As shown in Table 2, Table 2 shows the performance test results corresponding to the machine translation model, and the performance test results are the obtained BLEU values.
[0109] Table 2
[0110]
[0111] As shown in Table 2, three models were tested in Experiment 1. The first one was the Transformer model; the second one was the black-box method, which was a model trained based on the black-box adversarial sample generation method; and the third one was the white-box method provided in an embodiment of the present application, which was a model trained based on the white-box adversarial sample generation method, where λ=1.0.
[0112] The black-box method refers to adversarial samples generated without knowing the internal parameters of the machine translation model. For example, the black-box method based on random sampling: random sampling is performed from the vector space of multiple noise words, and the candidate words selected by random sampling are used to replace the words in the training data, thereby constructing adversarial samples; the black-box method based on word frequency sampling: word frequency sampling is performed from the vector space of multiple noise words, and optionally, the candidate words with the largest word frequency among the multiple noise words are used to replace the words in the training data, thereby constructing adversarial samples.
[0113] Among them, the test set includes three categories. The first category is the test samples of clean input. The second category is black box noise, that is, the noise samples generated by using the black box adversarial sample generation method for the above clean input; the third category is white box noise, that is, the noise samples generated by using the white box method provided in the embodiment of the present application for the above clean input.
[0114] It should be noted that when constructing noise test samples using the white-box method and the black-box method, the random seed is fixed to ensure that the position of the replaced noise is consistent.
[0115] As can be seen from Table 2, the white-box method provided in the embodiment of the present application not only performs better on the test set of clean input, but also has a smaller BLEU reduction value when facing two types of noise input, indicating that the model trained using the white-box method provided in the embodiment of the present application is more robust and has better translation performance when facing ASR noise input. The BLEU reduction value refers to the difference between the BLEU value obtained based on the test sample with added noise and the BLEU value obtained based on the test sample with clean input.
[0116] Experiment 2
[0117] The real-scene speech translation dataset provided in the STC speech translation data was used as the test set data, and 1,000 manually recorded Chinese words were selected as the clean input test set. The ASR records corresponding to these 1,000 manually recorded words were used as the noise input test set, and their corresponding English translations were used as the reference translations. The machine translation model was tested using BLEU, as shown in Table 3, which is the performance test result of the machine translation model. As shown in the last two columns of Table 3, a test on the removal of punctuation marks was added to the second test experiment.
[0118] Table 3
[0119]
[0120] As can be seen from Table 3, the white-box method provided in the embodiment of the present application, whether with punctuation or without punctuation, has a BLEU reduction value that is basically smaller than that of other methods when ASR noise is input. Taking punctuation removal as an example, the BLEU reduction value of the Transformer model is 5.05, the BLEU reduction values of the two black-box methods are 3.76 and 3 respectively, and the BLEU reduction value of the white-box method model is 3.45. Therefore, the model trained using the white-box adversarial sample generation method provided in the embodiment of the present application can show higher robustness and better translation performance when facing real ASR noise scene input, which further verifies the effectiveness of the white-box method provided in the embodiment of the present application.
[0121] Regarding the above Figure 3 The machine translation model shown in the embodiment of the present application also provides a machine translation method to enable the machine translation model to be applied in practice. Figure 4 , Figure 4 The flowchart of the machine translation method provided in the embodiment of the present application is shown below. For the convenience of description, the machine translation method is introduced below with the terminal device as the execution subject. It should be understood that the machine translation method can also be applied to the server in practical applications. Figure 4 As shown, the machine translation method includes but is not limited to the following steps 401 and 402.
[0122] Step 401, obtaining content to be translated.
[0123] It should be noted that the above-mentioned content to be translated can be at least one of text, video or audio to be translated, and different types of content to be translated can be applied to different application scenarios. For example, when the content to be translated is text to be translated, the text to be translated can be translated into a corresponding language; for another example, when the content to be translated is a video to be translated, the video to be translated can be translated into a text corresponding to the scene presented by the video; for another example, when the content to be translated is audio to be translated, the audio to be translated can be translated into a text corresponding to the audio, or translated into a text corresponding to a specified language.
[0124] For the text to be translated, the terminal device may provide a text input box for the user, in which the user may input the text to be translated. Accordingly, the terminal device obtains the text input by the user in the text input box as the content to be translated.
[0125] For the video and / or audio to be translated, the terminal device can provide the user with a file upload area, and the user can drag and drop the video and / or audio to be translated to the file upload area. Accordingly, when the terminal device detects that there is a file in the file upload area, it uses the file as the content to be translated. Alternatively, the terminal device can provide the user with a file upload button, and the user triggers the file upload operation by clicking the file upload button, selects the video and / or audio to be translated from the files stored in the terminal device, and uploads the selected video and / or audio to be translated, so that the terminal device obtains the content to be translated.
[0126] Step 402: Obtain the translation result corresponding to the content to be translated through a machine translation model.
[0127] After the terminal device obtains the content to be translated, the content to be translated is input into the machine translation model. The machine translation model is trained according to the training method of the machine translation model provided in the above embodiment. The specific structure of the machine translation model can be found in Figure 3 .
[0128] The encoder in the machine translation model is a recurrent neural network model, which can read the source vector sequence corresponding to the content to be translated as a fixed-length code. The decoder in the machine translation model is also a recurrent neural network model, which can decode the input sequence of the encoder to output the target sequence, that is, the vector sequence corresponding to the output label. Then, the machine translation model generates a translation result corresponding to the content to be translated based on the vector sequence output by the decoder.
[0129] In a possible implementation, after obtaining the translation result corresponding to the content to be translated through the machine translation model, the translation result may be directly displayed to the user.
[0130] The machine translation method provided in this embodiment applies a machine translation model to translate the content to be translated and determines the translation result corresponding to the content to be translated. Since the applied machine translation model is trained by the training method of the neural network model provided in the above embodiment, the machine translation model is robust against ASR noise. Therefore, it can ensure that the translation result finally output by the machine translation model is more accurate.
[0131] See also Figure 5 , the embodiment of the present application provides a training device for a machine translation model, the device comprising:
[0132] A first acquisition module 501 is used to acquire a training sample set, where the training sample set includes a training sample and a standard translation text corresponding to the training sample;
[0133] A second acquisition module 502 is used to input the training sample and the standard translation text corresponding to the training sample into the machine translation model to obtain the gradient vector generated by the machine translation model during the back propagation process;
[0134] A generating module 503, for generating adversarial samples for training samples based on the gradient vector and a plurality of noise words;
[0135] The training module 504 is used to perform adversarial training on the machine translation model based on the training samples and the adversarial samples to obtain the target machine translation model.
[0136] In one possible implementation, a generation module 503 is used to sample training samples, obtain a target word vector based on the sampling results, and obtain at least one candidate word vector corresponding to the target word vector from the vector space of multiple noise words; based on the gradient vector, select a target candidate word vector corresponding to the target word vector from at least one candidate word vector; replace the target word vector in the training sample with the target candidate word vector to obtain an adversarial sample.
[0137] In a possible implementation, the generation module 503 is used to update the target word vector based on the gradient vector to obtain an updated word vector; and select a candidate word vector with the largest distance from the updated word vector from at least one candidate word vector as the target candidate word vector.
[0138] In a possible implementation, the generation module 503 is used to obtain a target gradient vector corresponding to the target word vector from the gradient vector; and update the target word vector along the direction of the target gradient vector to obtain an updated word vector.
[0139] In one possible implementation, the training module 504 is used to obtain a first predicted translation text output by the machine translation model based on the training sample, and obtain a first loss function value based on the first predicted translation text and the standard translation text; obtain a second predicted translation text output by the machine translation model based on the adversarial sample, and obtain a second loss function value based on the second predicted translation text and the standard translation text; obtain a target loss function value based on the first loss function value and the second loss function value; iteratively adjust the model parameters and the adversarial sample of the machine translation model according to the target loss function value until the convergence condition is met to obtain the target machine translation model.
[0140] In a possible implementation, the training module 504 is used to obtain a weighted sum of the first loss function value and the second loss function value, and obtain a target loss function value according to the weighted sum.
[0141] In one possible implementation, the training module 504 is used to iteratively adjust the model parameters and adversarial samples of the machine translation model according to the target loss function value if the target loss function value is greater than the target threshold until the convergence condition is met to obtain the target machine translation model; if the target loss function value is less than or equal to the target threshold and the convergence condition is met, the machine translation model under the current model parameters is used as the target machine translation model.
[0142] The device provided in the present application generates adversarial samples that are most aggressive to the machine translation model through the gradient vectors generated during the training process of the machine translation model, and conducts adversarial training on the model based on the training samples and the adversarial samples at the same time, thereby increasing the training data, improving the robustness of the machine translation model, and further improving the translation performance of the machine translation model.
[0143] See also Figure 6 , an embodiment of the present application provides a machine translation device, the device comprising:
[0144] The acquisition module 601 is used to acquire the content to be translated;
[0145] The translation module 602 is used to obtain the translation result corresponding to the content to be translated through a machine translation model. The machine translation model is based on Figure 2 The machine translation model is trained using the training method shown.
[0146] The machine translation device provided in this embodiment applies a machine translation model to translate the content to be translated and determines the translation result corresponding to the content to be translated. Since the applied machine translation model is trained by the training method of the machine translation model provided in the above embodiment, the machine translation model is robust against ASR noise. Therefore, it can ensure that the translation result displayed by the machine translation device is more accurate.
[0147] It should be understood that the device provided in the above embodiment only uses the division of the above functional modules as an example to implement its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and their specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0148] Please refer to Figure 7 , which shows a schematic diagram of the structure of a computer device provided by an embodiment of the present application. The computer device may be a terminal, such as a smart phone, a tablet computer, a vehicle-mounted terminal, a laptop computer or a desktop computer. The terminal may also be called a user device, a portable terminal, a laptop terminal, a desktop terminal or other names.
[0149] Typically, the terminal includes: a processor 701 and a memory 702 .
[0150] The processor 701 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 701 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 701 may also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 701 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 701 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0151] The memory 702 may include one or more computer-readable storage media, which may be non-transitory. The memory 702 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 702 is used to store at least one instruction, which is used to be executed by the processor 701 to implement the training method of the machine translation model provided in the method embodiment of the present application, or the machine translation method provided in the method embodiment of the present application.
[0152] In some embodiments, the terminal may further optionally include: a peripheral device interface 703 and at least one peripheral device. The processor 701, the memory 702 and the peripheral device interface 703 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 703 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 704, a display screen 705, a camera assembly 706, an audio circuit 707, a positioning assembly 708 and a power supply 709.
[0153] The peripheral device interface 703 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 701 and the memory 702. In some embodiments, the processor 701, the memory 702, and the peripheral device interface 703 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 701, the memory 702, and the peripheral device interface 703 may be implemented on a separate chip or circuit board, which is not limited in this embodiment.
[0154] The radio frequency circuit 704 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 704 communicates with communication networks and other communication devices through electromagnetic signals. The radio frequency circuit 704 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the radio frequency circuit 704 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency circuit 704 can communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: a metropolitan area network, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a wireless fidelity (Wireless Fidelity, WiFi) network. In some embodiments, the radio frequency circuit 704 may also include circuits related to NFC (Near Field Communication, short-range wireless communication), which is not limited in this application.
[0155] The display screen 705 is used to display the UI (User Interface). The UI may include graphics, text, icons, videos and any combination thereof. When the display screen 705 is a touch display screen, the display screen 705 also has the ability to collect touch signals on the surface or above the surface of the display screen 705. The touch signal can be input to the processor 701 as a control signal for processing. At this time, the display screen 705 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 705 can be one, set on the front panel of the terminal; in other embodiments, the display screen 705 can be at least two, respectively set on different surfaces of the terminal or in a folding design; in some other embodiments, the display screen 705 can be a flexible display screen, set on the curved surface or folding surface of the terminal. Even, the display screen 705 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 705 can be made of materials such as LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode) and the like.
[0156] The camera assembly 706 is used to capture images or videos. Optionally, the camera assembly 706 includes a front camera and a rear camera. Typically, the front camera is arranged on the front panel of the terminal, and the rear camera is arranged on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 706 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.
[0157] The audio circuit 707 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 701 for processing, or input them into the radio frequency circuit 704 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the terminal. The microphone may also be an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 701 or the radio frequency circuit 704 into sound waves. The speaker may be a traditional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 707 may also include a headphone jack.
[0158] Positioning component 708 is used to locate the current geographical location of the terminal to implement navigation or LBS (Location Based Service). Positioning component 708 can be a positioning component based on the US GPS (Global Positioning System), China's Beidou system, Russia's Grenas system or the European Union's Galileo system.
[0159] The power supply 709 is used to power various components in the terminal. The power supply 709 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 709 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also be used to support fast charging technology.
[0160] In some embodiments, the terminal further includes one or more sensors 710 , including but not limited to: an acceleration sensor 711 , a gyroscope sensor 712 , a pressure sensor 713 , a fingerprint sensor 714 , an optical sensor 715 , and a proximity sensor 716 .
[0161] The acceleration sensor 711 can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established by the terminal. For example, the acceleration sensor 711 can be used to detect the components of gravity acceleration on the three coordinate axes. The processor 701 can control the display screen 705 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor 711. The acceleration sensor 711 can also be used for collecting game or user motion data.
[0162] The gyroscope sensor 712 can detect the body direction and rotation angle of the terminal, and the gyroscope sensor 712 can cooperate with the acceleration sensor 711 to collect the user's 3D actions on the terminal. The processor 701 can implement the following functions based on the data collected by the gyroscope sensor 712: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
[0163] The pressure sensor 713 can be set in the side frame of the terminal and / or the lower layer of the display screen 705. When the pressure sensor 713 is set in the side frame of the terminal, the user's holding signal of the terminal can be detected, and the processor 701 performs left and right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor 713. When the pressure sensor 713 is set in the lower layer of the display screen 705, the processor 701 controls the operability controls on the UI interface according to the user's pressure operation on the display screen 705. The operability controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.
[0164] The fingerprint sensor 714 is used to collect the user's fingerprint, and the processor 701 identifies the user's identity based on the fingerprint collected by the fingerprint sensor 714, or the fingerprint sensor 714 identifies the user's identity based on the collected fingerprint. When the user's identity is identified as a trusted identity, the processor 701 authorizes the user to perform relevant sensitive operations, which include unlocking the screen, viewing encrypted information, downloading software, paying, and changing settings. The fingerprint sensor 714 can be set on the front, back, or side of the terminal. When a physical button or manufacturer logo is set on the terminal, the fingerprint sensor 714 can be integrated with the physical button or manufacturer logo.
[0165] The optical sensor 715 is used to collect the ambient light intensity. In one embodiment, the processor 701 can control the display brightness of the display screen 705 according to the ambient light intensity collected by the optical sensor 715. Specifically, when the ambient light intensity is high, the display brightness of the display screen 705 is increased; when the ambient light intensity is low, the display brightness of the display screen 705 is reduced. In another embodiment, the processor 701 can also dynamically adjust the shooting parameters of the camera assembly 706 according to the ambient light intensity collected by the optical sensor 715.
[0166] The proximity sensor 716, also known as a distance sensor, is usually arranged on the front panel of the terminal. The proximity sensor 716 is used to collect the distance between the user and the front of the terminal. In one embodiment, when the proximity sensor 716 detects that the distance between the user and the front of the terminal is gradually decreasing, the processor 701 controls the display screen 705 to switch from the screen-on state to the screen-off state; when the proximity sensor 716 detects that the distance between the user and the front of the terminal is gradually increasing, the processor 701 controls the display screen 705 to switch from the screen-off state to the screen-on state.
[0167] Those skilled in the art will understand that Figure 7 The structure shown in the figure does not constitute a limitation on the computer device, and may include more or less components than shown in the figure, or combine some components, or adopt a different component arrangement.
[0168] Please refer to Figure 8 , Figure 8 It is a structural diagram of a server provided in an embodiment of the present application. The server 800 may have relatively large differences due to different configurations or performances, and may include one or more processors (Central Processing Units, CPU) 801 and one or more memories 802, wherein the one or more memories 802 store at least one program instruction, and the at least one program instruction is loaded and executed by the one or more processors 801 to implement the training method of the machine translation model provided by the above-mentioned various method embodiments, or the machine translation method provided by the above-mentioned various method embodiments. Of course, the server 800 may also have components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output. The server 800 may also include other components for implementing device functions, which will not be repeated here.
[0169] In an exemplary embodiment, a computer device is also provided, the computer device comprising a processor and a memory, wherein at least one program code is stored in the memory. The at least one program code is loaded and executed by one or more processors to enable the computer device to implement any of the above-mentioned training methods for machine translation models, or any of the above-mentioned machine translation methods.
[0170] In an exemplary embodiment, a computer-readable storage medium is also provided, in which at least one program code is stored, and the at least one program code is loaded and executed by a processor of a computer device to enable the computer to implement any of the above-mentioned machine translation model training methods, or any of the above-mentioned machine translation methods.
[0171] Optionally, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, etc.
[0172] In an exemplary embodiment, a computer program product or a computer program is also provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes any of the above-mentioned training methods for machine translation models, or any of the above-mentioned machine translation methods.
[0173] The terms "first", "second", "third" and "fourth" etc. in the specification and claims of the present application and the drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0174] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for training a machine translation model, characterized in that: The method comprises: Acquire a training sample set, wherein the training sample set includes training samples and standard translation texts corresponding to the training samples; Inputting the training sample and the standard translation text corresponding to the training sample into a machine translation model, and obtaining a gradient vector generated by the machine translation model during back propagation; Sampling the training sample, and obtaining a target word vector according to the sampling result, wherein the target word vector is the word vector that needs to be replaced; Acquire at least one candidate word vector corresponding to the target word vector from a vector space of a plurality of noise words, wherein the plurality of noise words include a plurality of pairs of homophones or phonetic words; Obtaining a target gradient vector corresponding to the target word vector from the gradient vector; Updating the target word vector along the direction of the target gradient vector to obtain an updated word vector; From the at least one candidate word vector, select the candidate word vector with the largest distance from the update word vector as the target candidate word vector; Replacing the target word vector in the training sample with the target candidate word vector to obtain an adversarial sample; The machine translation model is adversarially trained based on the training samples and the adversarial samples to obtain a target machine translation model.
2. The method according to claim 1, characterized in that The step of performing adversarial training on the machine translation model based on the training sample and the adversarial sample to obtain a target machine translation model includes: Obtaining a first predicted translation text output by the machine translation model according to the training sample, and obtaining a first loss function value based on the first predicted translation text and the standard translation text; Obtaining a second predicted translation text output by the machine translation model according to the adversarial sample, and obtaining a second loss function value based on the second predicted translation text and the standard translation text; Based on the first loss function value and the second loss function value, obtaining a target loss function value; The model parameters of the machine translation model and the adversarial sample are iteratively adjusted according to the target loss function value until a convergence condition is met to obtain a target machine translation model.
3. The method according to claim 2, characterized in that The acquiring a target loss function value based on the first loss function value and the second loss function value includes: Obtain a weighted sum of the first loss function value and the second loss function value, and obtain a target loss function value according to the weighted sum.
4. The method according to claim 2, characterized in that: The iterative adjustment of the model parameters of the machine translation model and the adversarial sample according to the target loss function value until a convergence condition is met to obtain a target machine translation model includes: If the target loss function value is greater than the target threshold, iteratively adjusting the model parameters of the machine translation model and the adversarial sample according to the target loss function value until a convergence condition is met to obtain a target machine translation model; If the target loss function value is less than or equal to the target threshold and the convergence condition is met, the machine translation model under the current model parameters is used as the target machine translation model.
5. A machine translation method, characterized in that: The method comprises: Get the content to be translated; The translation result corresponding to the content to be translated is obtained through a machine translation model, wherein the machine translation model is trained according to the training method for a machine translation model according to any one of claims 1 to 4.
6. A training device for a machine translation model, characterized in that: The device comprises: A first acquisition module is used to acquire a training sample set, wherein the training sample set includes training samples and standard translation texts corresponding to the training samples; A second acquisition module is used to input the training sample and the standard translation text corresponding to the training sample into the machine translation model to obtain the gradient vector generated by the machine translation model during the back propagation process; A generation module is used to sample the training sample, obtain a target word vector according to the sampling result, and the target word vector is the word vector to be replaced; obtain at least one candidate word vector corresponding to the target word vector from the vector space of multiple noise words, and the multiple noise words include multiple pairs of homophones or similar-sounding words; obtain a target gradient vector corresponding to the target word vector from the gradient vector; update the target word vector along the direction of the target gradient vector to obtain an updated word vector; select a candidate word vector with the largest distance from the updated word vector from the at least one candidate word vector as the target candidate word vector; replace the target word vector in the training sample with the target candidate word vector to obtain an adversarial sample; A training module is used to perform adversarial training on the machine translation model based on the training samples and the adversarial samples to obtain a target machine translation model.
7. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores at least one program code, and the at least one program code is loaded and executed by the processor so that the computer device implements the training method of the machine translation model as described in any one of claims 1 to 4, or the machine translation method as described in claim 5.
