Translation model training method and device, text translation method and device, equipment and medium

By using cascaded encoding sub-models and decoding sub-models in the translation model, and performing residual connections at the input and output positions of the layer normalization layer, combined with the Pre-LN and Post-LN structures, the poor training stability of the Post-LN model is solved problems and improved the quality of text translation.

CN118780340APending Publication Date: 2024-10-15TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310367742.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-04-03
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

The Transformer model based on Post-LN has poor stability during the training process, especially when the number of model layers is large, it is easy to collapse, resulting in poor text translation quality.

Method used

Using cascaded encoding sub-models and decoding sub-models, each sub-model contains a layer normalization layer and a sub-network layer, and the residual connection is performed through the input position and output position of the layer normalization layer, combining the structures of Pre-LN and Post-LN, Ensure stable propagation of gradient signals.

Benefits of technology

It improves the stability and generalization ability of the translation model, ensures the successful training convergence of the model in extremely deep scenarios, and improves the quality of text translation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118780340A_ABST
    Figure CN118780340A_ABST
Patent Text Reader

Abstract

The invention discloses a translation model training method, a text translation method and device, equipment and a medium, and belongs to the technical field of computers. The method comprises the following steps: acquiring a sample text; inputting the sample text into n coding sub-models, and sequentially performing feature extraction through each coding sub-model in the n coding sub-models to obtain coding features output by the n coding sub-models; the coding features are input into m decoding sub-models, feature extraction is sequentially carried out through each decoding sub-model in the m decoding sub-models, and decoding features output by the m decoding sub-models are obtained; predicting a sample translation result of the sample text according to the decoding features; and updating model parameters of the translation model according to the error between the real translation result of the sample text and the sample translation result. According to the method, the translation model can be successfully trained and converged even if the number of layers is deepened, and the stability of the model is improved. Therefore, the performance of the translation model can be improved, and the text translation quality is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a translation model training method, a text translation method, a device, a equipment and a medium. Background Art

[0002] Machine translation can enable communication between people without being restricted by language, thereby promoting economic and cultural exchanges among countries and regions and facilitating the mutual dissemination of various knowledge.

[0003] In related technologies, a Transformer model is usually used to perform text translation tasks. The Transformer model usually consists of an encoder and a decoder, where both the encoder and the decoder have a multi-layer (usually 6-layer) structure. According to the different positions of the LayerNorm layer in each layer, the implementation of each layer in the encoder and decoder of the Transformer model can be divided into two categories, namely, pre-layer normalization (Pre-LayerNorm, Pre-LN) and post-layer normalization (Post-LayerNorm, Post-LN).

[0004] The Transformer model based on Post-LN often has better effects and generalization. However, compared with the Transformer model based on Pre-LN, the Transformer model based on Post-LN has poor training stability and is prone to crash during the training process when the model has a large number of layers. This limits the performance of the translation model and leads to poor quality of text translation. Summary of the invention

[0005] This application provides a translation model training method, text translation method, device, equipment and medium, which can improve the quality of text translation. The technical solution is as follows:

[0006] According to one aspect of the present application, a training method for a translation model is provided, wherein the translation model comprises n cascaded encoding sub-models and m cascaded decoding sub-models, each of the encoding sub-models and each of the decoding sub-models comprises a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3, and the method comprises:

[0007] Get sample text;

[0008] Input the sample text into the n encoding sub-models, perform feature extraction in turn through each of the n encoding sub-models, and obtain encoding features output by the n encoding sub-models; wherein each of the encoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer;

[0009] Input the encoded features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection;

[0010] Predicting a sample translation result of the sample text according to the decoding feature;

[0011] The model parameters of the translation model are updated according to the error between the real translation result of the sample text and the sample translation result.

[0012] According to another aspect of the present application, a text translation method based on a translation model is provided, wherein the translation model comprises n cascaded encoding sub-models and m cascaded decoding sub-models, each of the encoding sub-models and each of the decoding sub-models comprises a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3, and the method comprises:

[0013] Get the text to be translated;

[0014] Input the text to be translated into the n encoding sub-models, and perform feature extraction in turn through each of the n encoding sub-models to obtain encoding features output by the n encoding sub-models; wherein each of the encoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction result of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer;

[0015] Input the encoded features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection;

[0016] A predicted translation result of the text to be translated is predicted according to the decoding feature.

[0017] According to another aspect of the present application, a training device for a translation model is provided, wherein the translation model comprises n cascaded encoding sub-models and m cascaded decoding sub-models, each of the encoding sub-models and each of the decoding sub-models comprises a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3, and the device comprises:

[0018] An acquisition module is used to acquire sample text;

[0019] An input-output module, used for inputting the sample text into the n encoding sub-models, performing feature extraction in turn through each of the n encoding sub-models, and obtaining encoding features output by the n encoding sub-models; wherein each of the encoding sub-models is used for performing feature extraction in turn through the layer normalization layer and the sub-network layer, and processing the feature extraction results of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer;

[0020] The input-output module is further used to input the encoding features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection;

[0021] A prediction module, used for predicting a sample translation result of the sample text according to the decoding feature;

[0022] The training module is used to update the model parameters of the translation model according to the error between the real translation result of the sample text and the sample translation result.

[0023] In an optional design, the translation model includes k cascaded encoding models, each of the encoding models includes at least two cascaded encoding sub-models among the n encoding sub-models, and k is a positive integer greater than or equal to 2; the input-output module is used to:

[0024] Inputting the sample text into a first encoding model, and extracting features in turn through each encoding sub-model in the first encoding model to obtain output features of the first encoding model;

[0025] Input the output feature of the i-th coding model into the i+1-th coding model, and extract features in turn through each of the coding sub-models in the i+1-th coding model to obtain the output feature of the i+1-th coding model, where i is a positive integer and i+1 is not greater than k;

[0026] The translation model includes k cascaded decoding models, each of which includes at least three cascaded decoding sub-models among the m decoding sub-models; the input-output module is used to:

[0027] Inputting the output features of the kth encoding model into the first decoding model, and extracting features in turn through each of the decoding sub-models in the first decoding model to obtain the output features of the first decoding model;

[0028] The output features of the kth encoding model and the output features of the jth decoding model are input into the j+1th decoding model, and feature extraction is performed in turn through each decoding sub-model in the j+1th decoding model to obtain the output features of the j+1th decoding model, where j is a positive integer and j+1 is not greater than k.

[0029] In an optional design, each of the encoding models includes a cascaded first encoding sub-model and a second encoding sub-model, the sub-network layer of the first encoding sub-model is a multi-head self-attention network, and the sub-network layer of the second encoding sub-model is a feed-forward fully connected network; the input-output module is used to:

[0030] Inputting the output feature of the i-th coding model into the first coding sub-model of the i+1-th coding model;

[0031] Performing feature extraction sequentially through the layer normalization layer and the multi-head self-attention network of the first encoding sub-model;

[0032] The output features of the i-th encoding model and the output features of the layer normalization layer of the first encoding sub-model are added to the output features of the multi-head self-attention network of the first encoding sub-model through the residual connection to obtain the output features of the first encoding sub-model;

[0033] Inputting the output features of the first encoding sub-model into the second encoding sub-model of the (i+1)th encoding model;

[0034] Performing feature extraction sequentially through the layer normalization layer and the feed-forward fully connected network of the second encoding sub-model;

[0035] The output features of the first encoding sub-model and the output features of the layer normalization layer of the second encoding sub-model are added to the output features of the feedforward fully connected network of the second encoding sub-model through the residual connection to obtain the output features of the i+1th encoding model.

[0036] In an optional design, the input-output module is used to:

[0037] Determine a first product of an output feature of the i-th coding model and a first weight; and determine a second product of an output feature of the layer normalization layer of the first coding sub-model and a second weight;

[0038] Adding the first product and the second product to the output features of the multi-head self-attention network of the first encoding sub-model through the residual connection;

[0039] Determine a third product of an output feature of the first encoding sub-model and a third weight; and determine a fourth product of an output feature of the layer normalization layer of the second encoding sub-model and a fourth weight;

[0040] The third product and the fourth product are added to the output features of the feedforward fully connected network of the second encoding sub-model through the residual connection.

[0041] In an optional design, the training module is used to:

[0042] At least one of the first weight, the second weight, the third weight and the fourth weight is optimized according to an error between a real translation result of the sample text and the sample translation result.

[0043] In an optional design, the input-output module is used to:

[0044] The decoding features output by the m decoding sub-models are normalized to obtain normalized decoding features.

[0045] In an optional design, each of the decoding models includes a cascaded first decoding sub-model, a second decoding sub-model and a third decoding sub-model, the sub-network layer of the first decoding sub-model is a first multi-head self-attention network, the sub-network layer of the second decoding sub-model is a second multi-head self-attention network, and the sub-network layer of the third encoding sub-model is a feed-forward fully connected network; the input-output module is used to:

[0046] Inputting the output feature of the j-th decoding model into the first decoding sub-model of the j+1-th decoding model;

[0047] Performing feature extraction sequentially through the layer normalization layer and the first multi-head self-attention network of the first decoding sub-model;

[0048] The output features of the j-th decoding model and the output features of the layer normalization layer of the first decoding sub-model are added to the output features of the first multi-head self-attention network of the first decoding sub-model through the residual connection to obtain the output features of the first decoding sub-model;

[0049] Inputting the output features of the k-th encoding model and the output features of the first decoding sub-model into the second decoding sub-model of the j+1-th decoding model;

[0050] Performing feature extraction sequentially through the layer normalization layer and the second multi-head self-attention network of the second decoding sub-model;

[0051] The output features of the first decoding sub-model and the output features of the layer normalization layer of the second decoding sub-model are added to the output features of the second multi-head self-attention network of the second decoding sub-model through the residual connection to obtain the output features of the second decoding sub-model;

[0052] Inputting the output features of the second decoding sub-model into the third decoding sub-model of the j+1th decoding model;

[0053] Performing feature extraction sequentially through the layer normalization layer and the feed-forward fully connected network of the third decoding sub-model;

[0054] The output features of the second decoding sub-model and the output features of the layer normalization layer of the third decoding sub-model are added to the output features of the feedforward fully connected network of the third decoding sub-model through the residual connection to obtain the output features of the j+1th decoding model.

[0055] In an optional design, the training module is used to:

[0056] When the number of training iterations of the translation model is not greater than a first number threshold, setting the number of model parameters updated by the translation model in each iteration to not exceed a number threshold;

[0057] In a case where the number of training iterations of the translation model is not less than a second number threshold, the number threshold is canceled, and the second number threshold is greater than the first number threshold.

[0058] According to another aspect of the present application, a text translation device based on a translation model is provided, wherein the translation model includes cascaded n encoding sub-models and cascaded m decoding sub-models, each of the encoding sub-models and each of the decoding sub-models includes a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3, and the device includes:

[0059] The acquisition module is used to obtain the text to be translated;

[0060] An input-output module, used for inputting the text to be translated into the n encoding sub-models, and performing feature extraction in turn through each of the n encoding sub-models to obtain encoding features output by the n encoding sub-models; wherein each of the encoding sub-models is used for performing feature extraction in turn through the layer normalization layer and the sub-network layer, and processing the feature extraction results of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer;

[0061] The input-output module is further used to input the encoding features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection;

[0062] A prediction module is used to predict a predicted translation result of the text to be translated according to the decoding feature.

[0063] According to another aspect of the present application, a computer device is provided, comprising a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the training method of the translation model or the text translation method based on the translation model as described above.

[0064] According to another aspect of the present application, a computer-readable storage medium is provided, wherein at least one instruction, at least one program, a code set or an instruction set is stored in the computer-readable storage medium, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by a processor to implement the training method of the translation model or the text translation method based on the translation model as described above.

[0065] According to another aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program including computer instructions, the computer instructions being 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 the training method of the translation model or the text translation method based on the translation model provided in various optional implementations of the above aspects.

[0066] The beneficial effects of the technical solution provided by this application include at least:

[0067] The translation model is constructed by using the encoding sub-model and the decoding sub-model. Since the layer normalization layer in each sub-model is before the sub-network layer, and the input position and output position of the layer normalization layer in the sub-model have residual connections, the residual connection of Post-LN is introduced on the basis of Pre-LN. The residual connection provides a channel for the stable propagation of gradient signals, ensuring that as the number of layers of the translation model increases, the translation model can also be successfully trained and converged, thereby improving the stability of the model. In addition, the Pre-LN-like structure in the translation model can also ensure that the translation model has better effects and generalization. Therefore, the performance of the translation model can be improved, thereby improving the quality of text translation. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] 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.

[0069] Figure 1 is a structural diagram of a Transformer model provided by an exemplary embodiment of the present application;

[0070] Figure 2 It is a structural diagram of post-layer normalization and pre-layer normalization provided by an exemplary embodiment of the present application;

[0071] Figure 3 is a structural block diagram of a computer system provided by an exemplary embodiment of the present application;

[0072] Figure 4 is a schematic diagram of the structure of a translation model provided by an exemplary embodiment of the present application;

[0073] Figure 5 is a flowchart of a method for training a translation model provided by an exemplary embodiment of the present application;

[0074] Figure 6 is a flowchart of a method for training a translation model provided by an exemplary embodiment of the present application;

[0075] Figure 7 is a schematic diagram of the structure of a coding model provided by an exemplary embodiment of the present application;

[0076] Figure 8 is a schematic diagram of the structure of a decoding model provided by an exemplary embodiment of the present application;

[0077] Fig. 9 is a flowchart of a text translation method based on a translation model provided by an exemplary embodiment of the present application;

[0078] Fig.10 is a schematic diagram of a text translation process provided by an exemplary embodiment of the present application;

[0079] Fig.11 is a schematic diagram of a chat interface provided by an exemplary embodiment of the present application;

[0080] Fig.12 is a structural schematic diagram of a training device for a translation model provided by an exemplary embodiment of the present application;

[0081] Fig.13 is a structural diagram of a text translation device based on a translation model provided by an exemplary embodiment of the present application;

[0082] Fig.14 It is a structural diagram of a computer device provided by an exemplary embodiment of the present application.

[0083] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application. DETAILED DESCRIPTION

[0084] 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.

[0085] First, the nouns involved in the embodiments of the present application are introduced:

[0086] Transformer model: A translation model based on the encoder-decoder architecture proposed in 2017.

[0087] Pre-layer normalization (Pre-LN): also known as pre-normalization (Pre-Norm), refers to a variant of the Transformer model.

[0088] Post-layer Normalization (Post-LN): Also known as Post-Norm, it refers to a variant of the Transformer model.

[0089] Residual connection: A structure used by the Transformer model to stabilize model training, which divides the model into two branches: the main branch and the identity branch.

[0090] Bilingual Evaluation Understudy (BLEU): A method to measure the similarity between texts, often used to evaluate the quality of translations.

[0091] Artificial Intelligence (AI): It is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines, so that machines have the functions of perception, reasoning and decision-making.

[0092] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0093] Machine Learning (ML): It is a multi-disciplinary interdisciplinary subject, involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and teaching learning.

[0094] Machine translation can make communication between people unrestricted by language, thereby promoting economic and cultural exchanges among countries and regions, and facilitating the mutual dissemination of various knowledge. In related technologies, the Transformer model is usually used to perform text translation tasks. The traditional Transformer model usually consists of an encoder and a decoder, where both the encoder and the decoder have a complex multi-layer (usually 6-layer) structure.

[0095] For example, Figure 1 is a schematic diagram of the structure of a Transformer model provided by an exemplary embodiment of the present application. Figure 1 As shown, the Transformer model includes an encoder 101 and a decoder 102. The encoder 101 and the decoder 102 are N-layer structures (which can be regarded as a cascade structure of N models). The structure of each layer of the encoder 101 is consistent, the structure of each layer of the decoder 102 is consistent, and the structure of each layer in the encoder 101 is similar to that of the decoder 102.

[0096] Each layer of the encoder 101 generally includes a multi-head self-attention module (also referred to as a multi-head self-attention network), namely Figure 1 The "multi-head attention" on the left side of the figure. And a feedforward fully connected module (also called feedforward network (FFN), feedforward fully connected network), that is, Figure 1 The "feed-forward fully connected" on the left side of the figure.

[0097] Each layer of the decoder 102 generally includes a mask multi-head self-attention module (Mask Multi-Head Self-Attention Module, also known as a mask multi-head self-attention network, which can be regarded as a multi-head self-attention module), that is, Figure 1 A cross encoder and decoder self-attention module (also called a cross self-attention module, a cross self-attention network, which can be regarded as a multi-head self-attention module), that is, Figure 1 The "multi-head attention" in the middle right. And a feed-forward fully connected module, i.e. Figure 1 The "Feed-Forward Full Connection" on the upper right side of the figure.

[0098] The multi-head self-attention module of encoder 101 is used to obtain the weight relationship of each word in the input text compared with other words in the input text. The feedforward fully connected module of encoder 101 is used to perform nonlinear transformation on the input features. The masked multi-head self-attention module of decoder 102 is similar to the multi-head self-attention module of encoder 101, except that it is also used to prevent decoder 102 from obtaining the translation results corresponding to the words after the word in the input text when generating the translation result of a word in the input text (in training, it will be Figure 1 The cross self-attention module of decoder 102 has a similar function to the multi-head self-attention module of encoder 101, except that the input it receives is composed of the output information of the previous module in decoder 102 and the output information of the last layer in encoder 101. The feedforward fully connected module of decoder 102 has a similar function to the feedforward fully connected module of encoder 101.

[0099] In addition, continue to refer to Figure 1 Each of the above modules (multi-head self-attention module, feed-forward fully connected module) in the encoder 101 and decoder 102 of the Transformer model requires a residual connection and layer normalization (LayerNorm) layer (i.e. Figure 1 Residual & Normalization (Add&Norm) in . Among them, the residual connection can be regarded as a structure that makes the output of a module of the model serve as the input of a non-adjacent module, which is used to reduce the complexity of the model and prevent the gradient from disappearing. The layer normalization layer is used to normalize the input information, such as normalization. The above residual connection and layer normalization layer structures are used to stabilize the training of the model.

[0100] According to the different positions of the layer normalization (LayerNorm) layer in each layer of the encoder and decoder of the Transformer model, the implementation of each layer in the encoder and decoder of the Transformer model can be divided into two categories, namely, pre-layer normalization (Pre-LayerNorm, Pre-LN) and post-layer normalization (Post-LayerNorm, Post-LN).

[0101] For example, Figure 2 FIG. 1 is a schematic diagram of a structure of a post-layer normalization and a pre-layer normalization provided by an exemplary embodiment of the present application. Figure 2 As shown in (a), in the encoder 201 of the Transformer model based on Post-LN, the layer normalization layers corresponding to the self-attention module and the feed-forward fully connected module are both set after the module. Figure 2As shown in (b), in the encoder 202 of the Transformer model based on Pre-LN, the layer normalization layers corresponding to the self-attention module and the feedforward fully connected module are both set before the module. In addition, there are also differences in the positions of the residual connections in encoder 201 and encoder 202 (the arc arrows in the figure). It should be noted that the difference in the structure of the decoder of the Transformer model under Pre-LN and Post-LN can be referred to. Figure 2 The reason is that the decoder of the Transformer model can be regarded as adding a "layer normalization and multi-head self-attention module" structure on the basis of the encoder, which will not be elaborated in the embodiments of the present application.

[0102] In order to obtain better translation results, it is usually necessary to provide more high-quality data during model training, or to increase the number of model parameters, such as increasing the number of layers of the encoder and decoder of the Transformer model. However, deepening the number of layers often means unstable training, because the gradient signal needs to propagate through a longer path. Transformer models based on Post-LN often have better effects and generalization, but compared with Transformer models based on Pre-LN, Transformer models based on Post-LN have poor training stability and are prone to crash during training when the number of model layers is large. The Transformer model based on Pre-LN itself has very good stability and can be stably trained under various layer settings. However, compared with the Transformer model based on Pre-LN and the Transformer model based on Post-LN, the Transformer model based on Pre-LN shows poor effects and insufficient generalization. Continue to refer to Figure 1 It can be seen that the traditional Transformer model is based on the Post-LN structure, so it has the problem of poor training stability, which will limit the performance of the translation model and lead to poor quality of text translation.

[0103] The embodiment of the present application provides a translation model that integrates Pre-LN and Post-LN, which can be stably trained in extremely deep layer (1000 layers) scenarios and has comparable effects to the Transformer model based on Post-LN. The translation model provided by the embodiment of the present application significantly alleviates the training stability problem of Post-LN and provides a suitable solution for the model structure in extremely deep layer scenarios. The translation model provided by the embodiment of the present application has at least the following advantages:

[0104] (1) The Pre-LN and Post-LN forms are combined. The residual connection of Pre-LN provides a channel for stable transmission of gradient signals, ensuring that the translation model can be successfully trained and converged as the number of layers increases, thereby improving the stability of the model.

[0105] (2) The residual connection of Post-LN ensures the complexity of the internal transformation of the translation model, and has a comparable effect to Post-LN in machine translation.

[0106] Figure 3 The computer system 300 includes a terminal 310 and a server 320 .

[0107] Terminal 310 is installed and runs an application 311 (client) that supports text translation, and application 311 can provide the function of translating text in a certain language into one or more other languages. Exemplarily, application 311 can specifically be any one of an instant messaging client, a social client, a medical client, a financial client, a short video client, a video-on-demand client, a music client, a takeaway client, an online shopping client, a knowledge client, and a tool client. When terminal 310 calls up application 311 to run, the user interface of application 311 is displayed on the screen of terminal 310. Terminal 310 is a terminal used by user 312, and a user account of user 312 is logged in to application 311. Terminal 310 can refer to one of multiple terminals. Optionally, the device type of terminal 310 includes at least one of a smart phone, a tablet computer, an e-book reader, an MP3 player, an MP4 player, a laptop portable computer, and a desktop computer.

[0108] The terminal 310 is connected to the server 320 via a wireless network or a wired network.

[0109] The server 320 includes at least one of a single server, multiple servers, a cloud computing platform, and a virtualization center. The server 320 is used to provide background services for the application 311 supporting text translation. Optionally, the server 320 undertakes the main computing work, and the terminal 310 undertakes the secondary computing work; or, the server 320 undertakes the secondary computing work, and the terminal 310 undertakes the main computing work; or, the server 320 and the terminal 310 adopt a distributed computing architecture for collaborative computing.

[0110] In an illustrative example, the server 320 includes a processor 321, a user account database 322, a translation module 323, and a user-oriented input / output interface (I / O interface) 324. The processor 321 is used to load instructions stored in the server 320 and process data in the user account database 322 and the translation module 323; the user account database 322 is used to store data of user accounts used by the terminal 310 and other terminals, such as the user account's avatar, the user account's nickname, the group to which the user account belongs, etc.; the translation module 323 is used to translate the acquired text; and the user-oriented I / O interface 324 is used to establish communication and exchange data with the terminal 310 through a wireless network or a wired network.

[0111] In some embodiments, the method provided in the embodiment of the present application is applied to the application 311. In this case, the translation model provided in the embodiment of the present application is integrated in the application 311, and the application 311 can independently perform the steps in the embodiment of the present application. In some embodiments, the method provided in the embodiment of the present application is applied to the server 320. In this case, the translation model provided in the embodiment of the present application is integrated in the server 320, and the server 320 can independently perform the steps in the embodiment of the present application. Exemplarily, the server 320 can obtain the text sent to it by the application 311, translate the obtained text, and then feedback the translation result of the text to the application 311.

[0112] Figure 4 Schematic diagram of the structure of a translation model provided by an exemplary embodiment of the present application. Figure 4 As shown, the translation model 401 includes a cascaded encoder 402 and a decoder 403. The encoder 402 includes k cascaded encoding models, and the decoder 403 includes k cascaded decoding models, each encoding model has the same structure, each decoding model has the same structure, and k is a positive integer greater than or equal to 2. The encoding model includes at least two cascaded encoding sub-models 404, and the decoding model includes at least three cascaded decoding sub-models 405. Optionally, the encoding model includes two cascaded encoding sub-models 404, and the decoding model includes three cascaded decoding sub-models 405.

[0113] Both the encoding sub-model 404 and the decoding sub-model 405 include a cascaded layer normalization layer and a sub-network layer, the layer normalization layer is before the sub-network layer, and the sub-network layer is one of a feed-forward fully connected network and a multi-head self-attention network. Optionally, in the encoder 402, the sub-network layer in the first encoding sub-model 404 of the encoding model is a multi-head self-attention network, and the sub-network layer in the second encoding sub-model 404 is a feed-forward fully connected network. In the decoder 402, the sub-network layer in the first decoding sub-model 405 of the decoding model is a masked multi-head self-attention network, the sub-network layer in the second decoding sub-model 405 is a cross self-attention network, and the sub-network layer in the third decoding sub-model 405 is a feed-forward fully connected network. In addition, the input position and output position of the layer normalization layer in the encoding sub-model 404 and the decoding sub-model 405 both have residual connections. By way of example, continue to refer to Figure 4 , the residual connection in the encoding sub-model 404 can add the input of the encoding sub-model 404 (the input of the layer normalization layer) and the output of the layer normalization layer to the output of the sub-network layer, and the result of the addition is the input of the next encoding sub-model 404. For the residual connection in the decoding sub-model 405, reference can be made to the introduction of the residual connection in the encoding sub-model 404, which will not be repeated here. The position setting of the layer normalization layer in the encoding sub-model 404 and the decoding sub-model 405 is similar to Pre-LN, and the residual connection set on this basis is similar to Post-LN, thereby realizing the combination of the forms of Pre-LN and Post-LN.

[0114] In the training phase, the computer device obtains a sample text and inputs the sample text into the translation model 401, thereby predicting a sample translation result of the sample text, and then training the translation model 401 based on the error between the real translation result of the sample text and the sample translation result. In the application phase, the computer device obtains a text to be translated and inputs the text to be translated into the translation model 401, thereby predicting a predicted translation result of the text to be translated, and realizing the translation of the text to be translated.

[0115] The translation model is constructed by using the encoding sub-model and the decoding sub-model. Since the layer normalization layer in each sub-model is before the sub-network layer, and the input position and output position of the layer normalization layer in the sub-model have residual connections, the residual connection of Post-LN is introduced on the basis of Pre-LN. The residual connection provides a channel for the stable propagation of gradient signals, ensuring that as the number of layers of the translation model increases (i.e., k increases), the translation model can also be successfully trained and converged, thereby improving the stability of the model. In addition, the Pre-LN-like structure in the translation model can also ensure that the translation model has better effects and generalization. Therefore, the performance of the translation model can be improved, thereby improving the quality of text translation.

[0116] Figure 5FIG. 1 is a flow chart of a method for training a translation model provided by an exemplary embodiment of the present application. The method can be used in a computer device or a client on a computer device. Figure 5 As shown, the method includes:

[0117] Step 502: Obtain sample text.

[0118] The sample text is used to train the translation model. Optionally, the computer device also obtains the real translation result corresponding to the sample text. The sample text includes one or more texts, and the real translation result includes one or more texts. The language corresponding to the sample text is different from the language corresponding to the real translation result, and the real translation result is the text of the sample text in the translated language. For example, the sample text is "How is the weather today" in Chinese, and the real translation result is "What's the weather like today" in English.

[0119] Optionally, the translation model is used to translate text in one or more first languages ​​into text in one or more second languages, the language corresponding to the sample text belongs to the one or more first languages, and the language corresponding to the actual translation result belongs to the one or more second languages.

[0120] Optionally, the computer device obtains the sample text and the real translation result through local storage, the computer device obtains the sample text and the real translation result through other computer devices, the computer device obtains the sample text and the real translation result uploaded by the user, and / or the computer device obtains the sample text and the real translation result through a public database.

[0121] Step 504: input the sample text into the n encoding sub-models of the translation model, perform feature extraction in turn through each of the n encoding sub-models, and obtain encoding features output by the n encoding sub-models.

[0122] The translation model includes n cascaded encoding sub-models, each encoding sub-model includes a cascaded layer normalization layer and a sub-network layer, and n is a positive integer greater than or equal to 2. Optionally, the sub-network layer is one of a feedforward fully connected network and a multi-head self-attention network. The n encoding sub-models include at least one feedforward fully connected network and one multi-head self-attention network. The sub-network layers in two adjacent encoding sub-models are the same or different. The layer normalization layer is used to normalize the input information, such as normalization. The multi-head self-attention network is used to calculate the weight relationship between each word in the input feature and other words in the input feature. The feedforward fully connected network is used to perform nonlinear transformation on the input features.

[0123] In the process of feature extraction through n encoding sub-models, each encoding sub-model is used to extract features through the layer normalization layer and the sub-network layer in turn, and the feature extraction results of the encoding sub-model are processed through the residual connection at the input position and the output position of the layer normalization layer. The residual connection can be regarded as a structure that makes the output features of a module of the translation model serve as the input features of a subsequent non-adjacent module, which is used to reduce the complexity of the model and prevent the gradient from disappearing.

[0124] Optionally, the translation model includes an encoder, the encoder includes k encoding models, the k encoding models are composed of the cascaded n encoding sub-models, each encoding model includes at least two cascaded encoding sub-models, and k is a positive integer. For example, each encoding model includes two cascaded encoding sub-models, each encoding model has the same structure, the sub-network layer of the first encoding sub-model of each encoding model is a multi-head self-attention network, and the sub-network layer of the second encoding sub-model of each encoding model is a feed-forward fully connected network.

[0125] Step 506: Input the encoded features into the m decoding sub-models of the translation model, and extract features through each of the m decoding sub-models in turn to obtain decoding features output by the m decoding sub-models.

[0126] The translation model includes m cascaded decoding sub-models, each decoding sub-model includes a cascaded layer normalization layer and a sub-network layer, and m is a positive integer greater than or equal to 3. Optionally, the sub-network layer is one of a feedforward fully connected network and a multi-head self-attention network, and the multi-head self-attention network can also be one of a masked multi-head self-attention network and a cross self-attention network. The m decoding sub-models include at least one feedforward fully connected network, a masked multi-head self-attention network and a cross self-attention network. The sub-network layers in two adjacent decoding sub-models are the same or different. The masked multi-head self-attention network has a similar function to the multi-head self-attention network, except that it is also used to generate the translation result of a word in the input feature, and the translation result corresponding to the word after the word in the input feature cannot be obtained. For example, when the translation model is predicted, the real translation result of the sample text will be input into the m decoding sub-models, and the m decoding sub-models will obtain the real translation result of the y-1th word when extracting the features of the yth word in the sample text, and y is a positive integer. If the feature of the first word is extracted, the input information is used to indicate the start of feature extraction, for example, the information is "0". The cross self-attention network has a similar function to the multi-head self-attention network, except that the input features it receives are composed of the output features and encoding features of the previous module in the translation model.

[0127] In the process of feature extraction through m decoding sub-models, each decoding sub-model is used to extract features through the layer normalization layer and the sub-network layer in turn, and the feature extraction results of the decoding sub-model are processed through the residual connection at the input position and the output position of the layer normalization layer. The residual connection can be regarded as a structure that makes the output features of a module of the translation model serve as the input features of a subsequent non-adjacent module, which is used to reduce the complexity of the model and prevent the gradient from disappearing.

[0128] Optionally, the translation model includes a decoder, which is cascaded with the encoder and is located after the encoder. The decoder includes k decoding models, which are composed of m decoding sub-models of the cascade, each decoding model includes at least three cascaded decoding sub-models, and k is a positive integer. For example, each decoding model includes three cascaded decoding sub-models, and the structure of each decoding model is the same. The sub-network layer of the first decoding sub-model of each decoding model is a masked multi-head self-attention network, the sub-network layer of the second decoding sub-model of each decoding model is a cross self-attention network, and the sub-network layer of the third decoding sub-model of each decoding model is a feedforward fully connected network.

[0129] Step 508: predicting a sample translation result of the sample text according to the decoding features.

[0130] The computer device can predict the sample translation result of the sample text according to the decoding features through the translation model. Optionally, the translation model also includes a cascaded linear (Linear) layer and a normalized (Softmax) layer (also called a normalized exponential function layer), and the Linear layer and the Softmax layer are cascaded. The Linear layer is used to perform a linear transformation on the input features, and the Softmax layer is used to process the input features through a normalized exponential function. After obtaining the decoding features, the computer device inputs the decoding features into the Linear layer, and processes them through the Linear layer and the Softmax layer in turn, and then outputs the translation words predicted by the translation model for each current word in the sample text, as well as the probability (Probabilities) of each translation word. The translation word is determined by the translation model in its vocabulary based on the decoding features, and the probability of the translation word is used to reflect the possibility that the translation word is a true translation word. By using vocabulary tables of different languages, the sample text can be translated into the translation result of the language corresponding to the vocabulary table.

[0131] Step 510: Update the model parameters of the translation model according to the error between the real translation result of the sample text and the sample translation result.

[0132] Updating the model parameters of the translation model is to train the translation model. Optionally, the computer device constructs an error loss function based on the error between the real translation result of the sample text and the sample translation result, and reduces the error loss through reverse gradient propagation to update the model parameters of the translation model. When the accuracy of the translation model meets the conditions, the training of the translation model is completed.

[0133] In summary, the method provided in this embodiment constructs a translation model by using an encoding sub-model and a decoding sub-model. Since the layer normalization layer in each sub-model is before the sub-network layer, and the input position and output position of the layer normalization layer in the sub-model have residual connections, the residual connection of Post-LN is introduced on the basis of Pre-LN. The residual connection provides a channel for stably propagating gradient signals, ensuring that as the number of layers of the translation model increases, the translation model can also be successfully trained and converged, thereby improving the stability of the model. In addition, a structure similar to Pre-LN in the translation model can also ensure that the translation model has better effects and generalization. Therefore, the performance of the translation model can be improved, thereby improving the quality of text translation.

[0134] Figure 6 FIG. 1 is a flow chart of a method for training a translation model provided by an exemplary embodiment of the present application. The method can be used in a computer device or a client on a computer device. Figure 6 As shown, the method includes:

[0135] Step 602: Obtain sample text.

[0136] The sample text is used to train the translation model. Optionally, the computer device also obtains a real translation result corresponding to the sample text. The sample text includes one or more texts, and the real translation result includes one or more texts. The language corresponding to the sample text is different from the language corresponding to the real translation result, and the real translation result is the text of the sample text in the translated language.

[0137] Step 604: Input the sample text into the first encoding model of the translation model, and extract features through each encoding sub-model in the first encoding model in turn to obtain output features of the first encoding model.

[0138] The translation model includes n cascaded encoding sub-models, each of which includes a cascaded layer normalization layer and a sub-network layer. Figure 4 , the input position and output position of the layer normalization layer of each encoding sub-model have residual connections, and n is a positive integer greater than or equal to 2. Optionally, the sub-network layer is one of a feed-forward fully connected network and a multi-head self-attention network. The sub-network layers in two adjacent encoding sub-models are the same or different.

[0139] The translation model includes k cascaded encoding models. Optionally, the k encoding models constitute an encoder in the translation model. Each encoding model includes at least two cascaded encoding sub-models among n encoding sub-models, and k is a positive integer greater than or equal to 2. Optionally, each encoding model includes two cascaded encoding sub-models, and each encoding model has the same structure, and the sub-network layer of the first encoding sub-model of each encoding model is a multi-head self-attention network, and the sub-network layer of the second encoding sub-model of each encoding model is a feed-forward fully connected network.

[0140] In the process of feature extraction through the coding model, each coding sub-model of the coding model is used to extract features through the layer normalization layer and the sub-network layer in sequence, and the feature extraction results of the coding sub-model are processed through the residual connection of the input position and the output position of the layer normalization layer. The process of feature extraction through the first coding model can refer to the following description of the process of feature extraction through the i+1th coding model, and the embodiments of the present application are not repeated here.

[0141] Optionally, before inputting the sample text into the first encoding model, the computer device performs feature embedding processing on the sample text to obtain an embedding vector. And determine the positional encoding of each word in the sample text, where the positional encoding is used to reflect the position of each word in the sample text. The computer device adds the embedding vector to the positional encoding and inputs it into the first encoding model of the translation model to perform the subsequent feature extraction process. The above process can be referred to Figure 1 .

[0142] Step 606: Input the output features of the i-th coding model into the i+1-th coding model, and extract features in turn through each coding sub-model in the i+1-th coding model to obtain the output features of the i+1-th coding model.

[0143] Wherein, i is a positive integer and i+1 is not greater than k. Optionally, each encoding model includes a cascaded first encoding sub-model and a second encoding sub-model, and the second encoding sub-model is after the first encoding sub-model. The sub-network layer of the first encoding sub-model is a multi-head self-attention network, and the sub-network layer of the second encoding sub-model is a feed-forward fully connected network.

[0144] In the process of sequentially extracting features through each coding sub-model in the i+1th coding model, the computer device inputs the output features of the ith coding model into the first coding sub-model of the i+1th coding model, sequentially extracts features through the layer normalization layer and the multi-head self-attention network of the first coding sub-model, and adds the output features of the ith coding model and the output features of the layer normalization layer of the first coding sub-model to the output features of the multi-head self-attention network of the first coding sub-model through residual connection, thereby obtaining the output features of the first coding sub-model.

[0145] The computer device then inputs the output features of the first coding sub-model into the second coding sub-model of the i+1th coding model, extracts features through the layer normalization layer and the feedforward fully connected network of the second coding sub-model in sequence, and adds the output features of the first coding sub-model and the output features of the layer normalization layer of the second coding sub-model to the output features of the feedforward fully connected network of the second coding sub-model through residual connection, thereby obtaining the output features of the second coding sub-model, i.e., the output features of the i+1th coding model.

[0146] Optionally, in the process of adding features through residual connection, the computer device determines a first product of an output feature of the i-th encoding model and a first weight, and determines a second product of an output feature of a layer normalization layer of the first encoding sub-model and a second weight, and then adds the first product and the second product to an output feature of a multi-head self-attention network of the first encoding sub-model through a residual connection. Also, the computer device determines a third product of an output feature of the first encoding sub-model and a third weight, and determines a fourth product of an output feature of a layer normalization layer of the second encoding sub-model and a fourth weight, and adds the third product and the fourth product to an output feature of a feedforward fully connected network of the second encoding sub-model through a residual connection.

[0147] The computer device can extract features through all coding models in turn by executing this step in a loop, and the output of the last coding model is the coding feature.

[0148] For example, the process of adding the output features through the residual connection of the encoding sub-model can be expressed as follows:

[0149] x l+1 =F(LN(x l ))+α po LN(x l )+α pe x l ;

[0150] Where l is a positive integer. l+1 represents the output feature of the l+1th encoding sub-model of the encoding model, x lRepresents the output features of the lth encoding sub-model of the encoding model. LN(x l ) represents the layer normalization of x through the layer of the l+1th encoding sub-model l The output features of the layer normalization layer obtained by feature extraction, F(LN(x l )) represents the output features of the sub-network layer obtained by extracting the output features of the layer normalization layer through the sub-network layer of the l+1th encoding sub-model, α po is LN(x l ) corresponding to the weight, α pe For x l The corresponding weight.

[0151] For example, Figure 7 is a schematic diagram of the structure of a coding model provided by an exemplary embodiment of the present application. Figure 7 As shown, the encoding model 701 includes a cascaded first encoding sub-model 702 and a second encoding sub-model 703. The first encoding sub-model 702 includes a cascaded layer normalization layer and a multi-head self-attention network, and the second encoding sub-model 703 includes a cascaded layer normalization layer and a feed-forward fully connected network. The input of the encoding model 701 is the input of the layer normalization layer of the first encoding sub-model 702, and the output of the encoding model 701 is the output of the feed-forward fully connected network of the second encoding sub-model 703 after residual connection. Optionally, when the output features of the layer normalization layer of the first encoding sub-model 702 are input into the multi-head self-attention network, the computer device will multiply the output features with the matrix respectively to obtain the query (Query, Q) vector, the key (Key, K) vector and the value (Value, V) vector, and input them into the multi-head self-attention network.

[0152] Step 608: Input the output features of the kth encoding model into the first decoding model of the translation model, and extract features in turn through each decoding sub-model in the first decoding model to obtain the output features of the first decoding model.

[0153] The translation model includes m cascaded decoding sub-models, each of which includes a cascaded layer normalization layer and a sub-network layer. Figure 4 , the input position and output position of the layer normalization layer of each decoding sub-model have residual connections, and m is a positive integer greater than or equal to 3. Optionally, the sub-network layer is one of a feed-forward fully connected network, a masked multi-head self-attention network, and a cross self-attention network. The sub-network layers in two adjacent decoding sub-models are the same or different.

[0154] The translation model includes k cascaded decoding models. Optionally, the k decoding models constitute a decoder in the translation model. Each decoding model includes at least three decoding sub-models cascaded in m decoding sub-models, and k is a positive integer greater than or equal to 2. Optionally, each decoding model includes three cascaded decoding sub-models, and the structure of each decoding model is the same. The sub-network layer of the first decoding sub-model of each decoding model is a masked multi-head self-attention network, the sub-network layer of the second decoding sub-model of each decoding model is a cross self-attention network, and the sub-network layer of the third decoding sub-model of each decoding model is a feedforward fully connected network.

[0155] In the process of feature extraction through the decoding model, each decoding sub-model of the decoding model is used to extract features through the layer normalization layer and the sub-network layer in sequence, and the feature extraction results of the decoding sub-model are processed through the residual connection. The process of feature extraction through the first decoding model can refer to the following description of the process of feature extraction through the j+1th decoding model, and the embodiments of the present application are not repeated here.

[0156] Optionally, in the process of the translation model predicting the translation result, the encoding features output by the last encoding model in the encoder will be input into each decoding model in the decoder respectively, and each decoding model will perform feature extraction on the encoding features.

[0157] Optionally, during the training process, the computer device will also input the real translation result corresponding to the sample text into the first encoding model. Optionally, before inputting the real translation result into the first decoding model, the computer device will perform feature embedding (Embedding) processing on the real translation result to obtain an embedding vector. And determine the positional encoding (Positional Encoding) of each word in the real translation result, and the positional encoding is used to reflect the position of each word in the real translation result in the real translation result. The computer device adds the embedding vector to the positional encoding and inputs it into the first decoding model of the translation model to perform the subsequent feature extraction process.

[0158] Optionally, during the model training process, when the decoding model extracts the feature vector of the yth word in the sample text, the computer device will input the actual translation result corresponding to the y-1th word into the first decoding model. If y-1=0, the computer device will input information to the first decoding model to indicate the start of feature extraction. For example, if the information is "0", this process can be called shifted right. During the model application process, it is only necessary to input information indicating the start of feature extraction into the first decoding model. The above process can be referred to. Figure 1 .

[0159] Step 610: Input the output features of the kth encoding model and the output features of the jth decoding model into the j+1th decoding model, and extract features in turn through each decoding sub-model in the j+1th decoding model to obtain the output features of the j+1th decoding model.

[0160] Wherein, j is a positive integer and j+1 is not greater than k. Optionally, each decoding model includes a cascaded first decoding sub-model, a second decoding sub-model and a third decoding sub-model, the second decoding sub-model is after the first decoding sub-model, and the third decoding sub-model is after the second decoding sub-model. The sub-network layer of the first decoding sub-model is a first multi-head self-attention network, the sub-network layer of the second decoding sub-model is a second multi-head self-attention network, and the sub-network layer of the third encoding sub-model is a feed-forward fully connected network.

[0161] In the process of sequentially extracting features through each decoding sub-model in the j+1th decoding model, the computer device inputs the output features of the jth decoding model into the first decoding sub-model of the j+1th decoding model, sequentially extracts features through the layer normalization layer and the first multi-head self-attention network of the first decoding sub-model, and adds the output features of the jth decoding model and the output features of the layer normalization layer of the first decoding sub-model to the output features of the first multi-head self-attention network of the first decoding sub-model through a residual connection to obtain the output features of the first decoding sub-model. Optionally, the first multi-head self-attention network is a masked multi-head self-attention network.

[0162] The computer device then inputs the output features of the k-th encoding model and the output features of the first decoding sub-model into the second decoding sub-model of the j+1-th decoding model, extracts features through the layer normalization layer and the second multi-head self-attention network of the second decoding sub-model in sequence, and adds the output features of the first decoding sub-model and the output features of the layer normalization layer of the second decoding sub-model to the output features of the second multi-head self-attention network of the second decoding sub-model through a residual connection to obtain the output features of the second decoding sub-model. Optionally, the second multi-head self-attention network is a cross self-attention network.

[0163] The computer device then inputs the output features of the second decoding sub-model into the third decoding sub-model of the j+1th decoding model, extracts features through the layer normalization layer and the feedforward fully connected network of the third decoding sub-model in sequence, and adds the output features of the second decoding sub-model and the output features of the layer normalization layer of the third decoding sub-model to the output features of the feedforward fully connected network of the third decoding sub-model through residual connections to obtain the output features of the j+1th decoding model.

[0164] Optionally, when adding features through residual connection, the added features may be weighted. For example, weights are set for the input features of the layer normalization layer and the output features of the layer normalization layer of the decoding sub-model. The specific implementation process can refer to the process of adding output features through residual connection in the above step 606, and the embodiment of the present application will not be described in detail here.

[0165] The computer device can extract features through all decoding models in turn by executing this step in a loop, and the output of the last decoding model is the decoding feature.

[0166] For example, Figure 8 Schematic diagram of a decoding model provided by an exemplary embodiment of the present application. Figure 8 As shown, the decoding model 801 includes a cascaded first decoding sub-model 802, a second decoding sub-model 803, and a third decoding sub-model 804. The first decoding sub-model 802 includes a cascaded layer normalization layer and a masked multi-head self-attention network, the second decoding sub-model 803 includes a cascaded layer normalization layer and a cross self-attention network, and the third decoding sub-model 804 includes a cascaded layer normalization layer and a feed-forward fully connected network. Figure 8 There are two cases for the input directly below the decoding model 801. When the decoding model 801 is the first one, the input below can refer to the introduction to the right shift (shifted right) in the previous article; when the decoding model 801 is not the first one, the input below is the output feature of the previous decoding model. The input on the left side of the decoding model 801 is the output feature of the last encoding model, but only the Q vector and K vector in the output feature are input, and the V vector is determined according to the output feature of the normalization layer of the previous layer. The output of the decoding model 801 is the output of the feedforward fully connected network of the third decoding sub-model 804 after the residual connection. Optionally, by Figure 7 Structural replacement in Figure 1 The encoder in Figure 8 Structural replacement in Figure 1 The decoder in can obtain the structure of a translation model provided in an embodiment of the present application.

[0167] Optionally, after the last decoding model completes feature extraction, the computer device normalizes the decoding features output by the decoder (i.e., the decoding features output by the m decoding sub-models) to obtain normalized decoding features, and then uses the normalized decoding features to predict subsequent translation results. Optionally, the decoding features output by the decoder can be normalized by cascading a normalization layer after the decoder.

[0168] Step 612: predicting a sample translation result of the sample text according to the decoding features.

[0169] The computer device can predict the sample translation result of the sample text according to the decoding features through the translation model. Optionally, the translation model determines the most likely word in the vocabulary of the translation model according to the decoding features, thereby obtaining the translation result. By using vocabulary of different languages, the sample text can be translated into the translation result of the language corresponding to the vocabulary.

[0170] Step 614: Update the model parameters of the translation model according to the error between the real translation result of the sample text and the sample translation result.

[0171] Updating the model parameters of the translation model is to train the translation model. Optionally, the computer device constructs an error loss function according to the error between the real translation result of the sample text and the sample translation result, and reduces the error loss by reverse gradient propagation, thereby updating the model parameters of the translation model.

[0172] Optionally, during the model training process, the computer device will also optimize at least one of the first weight, the second weight, the third weight and the fourth weight according to the error between the actual translation result of the sample text and the sample translation result.

[0173] Optionally, when the number of training iterations of the translation model is not greater than the first number threshold, the model parameter amount updated by the translation model in each iteration is set not to exceed the number threshold. When the number of training iterations of the translation model is not less than the second number threshold, the number threshold is canceled, and the second number threshold is greater than the first number threshold. That is, in the early stage of training, the parameter update amount of the model is set, and in the later stage of training, the parameter update amount of the model may not be restricted.

[0174] In summary, the method provided in this embodiment constructs a translation model by using an encoding sub-model and a decoding sub-model. Since the layer normalization layer in each sub-model is before the sub-network layer, and the input position and output position of the layer normalization layer in the sub-model have residual connections, the residual connection of Post-LN is introduced on the basis of Pre-LN. The residual connection provides a channel for stably propagating gradient signals, ensuring that as the number of layers of the translation model increases (i.e., k increases), the translation model can also be successfully trained and converged, thereby improving the stability of the model. In addition, a structure similar to Pre-LN in the translation model can also ensure that the translation model has better effects and generalization. Therefore, the performance of the translation model can be improved, thereby improving the quality of text translation.

[0175] The method provided in this embodiment also performs feature extraction through each encoding sub-model in the k encoding models and each decoding sub-model in the k decoding models to obtain extracted decoding features, thereby providing a method for accurately extracting decoding features.

[0176] The method provided in this embodiment also adds the output features of the sub-network of the encoding sub-model, the input features of the layer normalization layer, and the output features of the layer normalization layer through the residual connection in the encoding sub-model, thereby performing subsequent feature extraction. Combining the structure of Post-LN and Pre-LN not only ensures the stability of the translation model training, but also ensures that the translation model has better effect and generalization.

[0177] The method provided in this embodiment also achieves more accurate feature extraction and improved model training stability by setting weights for the added features when adding the features in the residual connection.

[0178] The method provided in this embodiment can also achieve more accurate weight setting and improve model performance by optimizing the weights used when adding features through residual connections according to errors during the training process.

[0179] The method provided in this embodiment also ensures the normalization of the features of the final output by normalizing the features output by the last sub-model, thereby ensuring the accuracy of the model prediction.

[0180] The method provided in this embodiment also adds the output features of the sub-network of the decoding sub-model, the input features of the layer normalization layer, and the output features of the layer normalization layer through the residual connection in the decoding sub-model, thereby performing subsequent feature extraction. Combining the structure of Post-LN and Pre-LN not only ensures the stability of the translation model training, but also ensures that the translation model has better effect and generalization.

[0181] The method provided in this embodiment also limits the parameter update amount in the early stage of model training, and does not limit the parameter update amount in the later stage of training, thereby ensuring the stability of model training and ensuring more complete learning of the model, thereby improving the performance release of the model.

[0182] Fig. 9 FIG. 1 is a flowchart of a text translation method based on a translation model provided by an exemplary embodiment of the present application. The method can be used in a computer device or a client on a computer device. Fig. 9 As shown, the method includes:

[0183] Step 902: Obtain the text to be translated.

[0184] The translation model is used to translate text in one or more first languages ​​into text in one or more second languages. The language corresponding to the text to be translated belongs to the one or more first languages, and the predicted translation result predicted by the translation model based on the text to be translated belongs to the one or more second languages.

[0185] Optionally, the computer device obtains the text to be translated through local storage, the computer device obtains the text to be translated through other computer devices, or the computer device obtains the text to be translated uploaded by a user.

[0186] Step 904: input the text to be translated into the n encoding sub-models of the translation model, perform feature extraction in turn through each of the n encoding sub-models, and obtain encoding features output by the n encoding sub-models.

[0187] The translation model includes n cascaded encoding sub-models, each encoding sub-model includes a cascaded layer normalization layer and a sub-network layer, and n is a positive integer greater than or equal to 2. Each encoding sub-model is used to extract features through the layer normalization layer and the sub-network layer in sequence, and to process the feature extraction result of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer.

[0188] Step 906: Input the encoded features into the m decoding sub-models of the translation model, and extract features through each of the m decoding sub-models in turn to obtain decoding features output by the m decoding sub-models.

[0189] The translation model includes m cascaded decoding sub-models, each decoding sub-model includes a cascaded layer normalization layer and a sub-network layer, and m is a positive integer greater than or equal to 3. Each decoding sub-model is used to extract features through the layer normalization layer and the sub-network layer in sequence, and process the feature extraction results of the decoding sub-model through the residual connection.

[0190] Step 908: predicting a translation result of the text to be translated according to the decoding features.

[0191] The process of predicting the translation result of the translation text by the computer device through the translation model can refer to the relevant content in the above-mentioned translation model training method embodiment, and the embodiment of the present application will not be described in detail here.

[0192] In summary, the method provided in this embodiment constructs a translation model by using an encoding sub-model and a decoding sub-model. Since the layer normalization layer in each sub-model is before the sub-network layer, and the input position and output position of the layer normalization layer in the sub-model have residual connections, the residual connection of Post-LN is introduced on the basis of Pre-LN. The residual connection provides a channel for stably propagating gradient signals, ensuring that as the number of layers of the translation model increases, the translation model can also be successfully trained and converged, thereby improving the stability of the model. In addition, a structure similar to Pre-LN in the translation model can also ensure that the translation model has better effects and generalization. Therefore, the performance of the translation model can be improved, thereby improving the quality of text translation.

[0193] In a specific example, the method provided by the embodiment of the present application can be used for various translation scenarios such as chat, friend circle, picture text, etc. in instant messaging clients. For example, when a user is talking to a friend or checking the news, the translation function implemented by the method provided by the embodiment of the present application can be used by long pressing the text to translate the current language into the language set by the user. At the same time, the language direction can also be specified for translation through the applet.

[0194] For example, Fig.10 FIG. 1 is a schematic diagram of a text translation process provided by an exemplary embodiment of the present application. Fig.10 As shown, user 1001 triggers the translation function for the text in the user interface through the user interface of the instant messaging client. The client sends a translation request to the language detection and translation request distribution module 1002 of the server, and the request includes the text to be translated and may also include the language to be translated. Module 1002 detects the language of the text to be translated, obtains the language to be translated, and then calls the translation model 1003 to translate the text to be translated and obtain the translation result. The translation result is then fed back to user 1001, and the user's instant messaging client can display the translation result.

[0195] For example, Fig.11 is a schematic diagram of a chat interface provided by an exemplary embodiment of the present application. Fig.11 As shown, the instant messaging client displays a user interface 1101, and the user interface 1101 displays a chat message 1102. Optionally, the user can trigger the translation of the chat message 1102 by performing an interactive operation on the displayed chat message 1102. After the client obtains the translation result 1103 of the chat message 1102, the translation result 1103 can be displayed on the user interface 1101.

[0196] Exemplarily, the overall process of translation in the embodiment of the present application is to first divide the received sentence into individual sentences, and then perform word segmentation on each individual sentence, such as "I love China", which is divided into "I / love / China". Then the segmented words are sent to the translation model, and the translation model outputs the corresponding translation. After that, the computer device performs simple post-processing on the punctuation marks, spaces, etc. of the translation, and then returns the translation.

[0197] The translation model provided in the embodiment of the present application integrates the structure of Pre-LN and Post-LN to combine the advantages of both, increase the training stability of the translation model and improve the effect. Continuing with reference to 2, the structural difference between Pre-LN and Post-LN mainly lies in the different positions of the layer normalization layer and the residual connection. By combining the two structures, the translation model provided in the embodiment of the present application is obtained, for example Figure 7 and Figure 8The structure of each sub-model can be simplified as Figure 4 The structure in .

[0198] The model in the embodiment of the present application is trained with bilingual data (such as English-Chinese) of a pair of languages ​​(or multiple languages) to obtain a translation model. The translation model is then deployed to an online service, which receives online translation calls, performs model derivation, and returns the translation.

[0199] In addition, the hardware environment support for the use of the translation model integrating Pre-LN and Post-LN in the embodiment of the present application is relatively simple, and training and deployment can be carried out in a common server environment. For details, please refer to Table 1, which shows the software and hardware environment involved in implementing the translation model.

[0200] Table 1

[0201] operating system Memory Locale Linux >16G Python / C++

[0202] The translation model provided in the embodiment of the present application can take into account both training stability and effect. Compared with Post-LN, it can stably train extremely deep (1000-layer) models. Compared with Pre-LN, it has improved effect and is comparable to the effect of Post-LN. It is an effective solution for training deep translation models.

[0203] In addition, the translation model provided in the embodiment of the present application can obtain the stability of Pre-LN while retaining the structure of Post-LN, without limiting the amount of updates to the model during training, and can release the potential of the model. This method does not make much change to the model structure, and can be combined with other solutions to improve the model effect (such as increasing local attention, knowledge distillation, etc.) to further improve the model effect.

[0204] The benefits of the translation model provided in the embodiment of the present application are as follows (Table 2 lists the "BLEU" index, which is a standard method for machine translation evaluation, and the higher the value, the better the effect):

[0205] Table 2

[0206] Model 200th floor 100th floor Pre-LN 30.5 31.0 Post-LN fail fail DeepNet 31.1(+0.6) 32.1(+1.1) Translation model for this application 31.5(+1.0) 32.3(+1.3)

[0207] It should be noted that the model provided in the embodiment of the present application is not only suitable for machine translation scenarios. Currently, the Transformer model is the mainstream model in the field of natural language processing. The model provided in the embodiment of the present application can be used in large language models (LLM, Large Language Model), sentiment analysis, machine summarization, etc.

[0208] It should be noted that the sequence of the method steps provided in the embodiments of the present application can be appropriately adjusted, and the steps can be increased or decreased accordingly according to the circumstances. Any technician familiar with the technical field can easily think of the changed methods within the technical scope disclosed in the present application, and they should be included in the protection scope of the present application, so they will not be repeated here.

[0209] It should be noted that, in the case where the sample text and the text to be translated in this application involve relevant data of the user, this application can display a prompt interface, pop-up window or output voice prompt information before collecting the relevant data of the user and during the process of collecting the relevant data of the user. The prompt interface, pop-up window or voice prompt information is used to prompt the user that its relevant data is currently being collected, so that this application only starts to execute the relevant steps of obtaining the relevant data of the user after obtaining the confirmation operation issued by the user to the prompt interface or pop-up window, otherwise (that is, when the confirmation operation issued by the user to the prompt interface or pop-up window is not obtained), the relevant steps of obtaining the relevant data of the user are terminated, that is, the relevant data of the user is not obtained. In other words, all user-related data collected by this application are collected with the consent and authorization of the user, and the collection, use and processing of relevant user data need to comply with the relevant laws, regulations and standards of relevant countries and regions.

[0210] Fig.12 1 is a structural diagram of a training device for a translation model provided by an exemplary embodiment of the present application. The translation model includes n cascaded encoding sub-models and m cascaded decoding sub-models, each encoding sub-model and each decoding sub-model includes a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3. Fig.12 As shown, the device comprises:

[0211] An acquisition module 1201 is used to acquire a sample text;

[0212] The input-output module 1202 is used to input the sample text into the n encoding sub-models, and perform feature extraction in turn through each of the n encoding sub-models to obtain encoding features output by the n encoding sub-models; wherein each encoding sub-model is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer;

[0213] The input-output module 1202 is further used to input the encoding features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection;

[0214] A prediction module 1203, configured to predict a sample translation result of the sample text according to the decoding feature;

[0215] The training module 1204 is used to update the model parameters of the translation model according to the error between the real translation result of the sample text and the sample translation result.

[0216] In an optional design, the translation model includes k cascaded encoding models, each of the encoding models includes at least two cascaded encoding sub-models among the n encoding sub-models, and k is a positive integer greater than or equal to 2; the input-output module 1202 is used to:

[0217] Inputting the sample text into a first encoding model, and extracting features in turn through each encoding sub-model in the first encoding model to obtain output features of the first encoding model;

[0218] Input the output feature of the i-th coding model into the i+1-th coding model, and extract features in turn through each of the coding sub-models in the i+1-th coding model to obtain the output feature of the i+1-th coding model, where i is a positive integer and i+1 is not greater than k;

[0219] The translation model includes k cascaded decoding models, each of which includes at least three cascaded decoding sub-models among the m decoding sub-models; the input-output module 1202 is used to:

[0220] Inputting the output features of the kth encoding model into the first decoding model, and extracting features in turn through each of the decoding sub-models in the first decoding model to obtain the output features of the first decoding model;

[0221] The output features of the kth encoding model and the output features of the jth decoding model are input into the j+1th decoding model, and feature extraction is performed in turn through each decoding sub-model in the j+1th decoding model to obtain the output features of the j+1th decoding model, where j is a positive integer and j+1 is not greater than k.

[0222] In an optional design, each of the encoding models includes a cascaded first encoding sub-model and a second encoding sub-model, the sub-network layer of the first encoding sub-model is a multi-head self-attention network, and the sub-network layer of the second encoding sub-model is a feed-forward fully connected network; the input-output module 1202 is used to:

[0223] Inputting the output feature of the i-th coding model into the first coding sub-model of the i+1-th coding model;

[0224] Performing feature extraction sequentially through the layer normalization layer and the multi-head self-attention network of the first encoding sub-model;

[0225] The output features of the i-th encoding model and the output features of the layer normalization layer of the first encoding sub-model are added to the output features of the multi-head self-attention network of the first encoding sub-model through the residual connection to obtain the output features of the first encoding sub-model;

[0226] Inputting the output features of the first encoding sub-model into the second encoding sub-model of the (i+1)th encoding model;

[0227] Performing feature extraction sequentially through the layer normalization layer and the feed-forward fully connected network of the second encoding sub-model;

[0228] The output features of the first encoding sub-model and the output features of the layer normalization layer of the second encoding sub-model are added to the output features of the feedforward fully connected network of the second encoding sub-model through the residual connection to obtain the output features of the i+1th encoding model.

[0229] In an optional design, the input-output module 1202 is used to:

[0230] Determine a first product of an output feature of the i-th coding model and a first weight; and determine a second product of an output feature of the layer normalization layer of the first coding sub-model and a second weight;

[0231] Adding the first product and the second product to the output features of the multi-head self-attention network of the first encoding sub-model through the residual connection;

[0232] Determine a third product of an output feature of the first encoding sub-model and a third weight; and determine a fourth product of an output feature of the layer normalization layer of the second encoding sub-model and a fourth weight;

[0233] The third product and the fourth product are added to the output features of the feedforward fully connected network of the second encoding sub-model through the residual connection.

[0234] In an optional design, the training module 1204 is used to:

[0235] At least one of the first weight, the second weight, the third weight and the fourth weight is optimized according to an error between a real translation result of the sample text and the sample translation result.

[0236] In an optional design, the input-output module 1202 is used to:

[0237] The decoding features output by the m decoding sub-models are normalized to obtain normalized decoding features.

[0238] In an optional design, each of the decoding models includes a cascaded first decoding sub-model, a second decoding sub-model and a third decoding sub-model, the sub-network layer of the first decoding sub-model is a first multi-head self-attention network, the sub-network layer of the second decoding sub-model is a second multi-head self-attention network, and the sub-network layer of the third encoding sub-model is a feed-forward fully connected network; the input-output module 1202 is used to:

[0239] Inputting the output feature of the j-th decoding model into the first decoding sub-model of the j+1-th decoding model;

[0240] Performing feature extraction sequentially through the layer normalization layer and the first multi-head self-attention network of the first decoding sub-model;

[0241] The output features of the j-th decoding model and the output features of the layer normalization layer of the first decoding sub-model are added to the output features of the first multi-head self-attention network of the first decoding sub-model through the residual connection to obtain the output features of the first decoding sub-model;

[0242] Inputting the output features of the k-th encoding model and the output features of the first decoding sub-model into the second decoding sub-model of the j+1-th decoding model;

[0243] Performing feature extraction sequentially through the layer normalization layer and the second multi-head self-attention network of the second decoding sub-model;

[0244] The output features of the first decoding sub-model and the output features of the layer normalization layer of the second decoding sub-model are added to the output features of the second multi-head self-attention network of the second decoding sub-model through the residual connection to obtain the output features of the second decoding sub-model;

[0245] Inputting the output features of the second decoding sub-model into the third decoding sub-model of the j+1th decoding model;

[0246] Performing feature extraction sequentially through the layer normalization layer and the feed-forward fully connected network of the third decoding sub-model;

[0247] The output features of the second decoding sub-model and the output features of the layer normalization layer of the third decoding sub-model are added to the output features of the feedforward fully connected network of the third decoding sub-model through the residual connection to obtain the output features of the j+1th decoding model.

[0248] In an optional design, the training module 1204 is used to:

[0249] When the number of training iterations of the translation model is not greater than a first number threshold, setting the number of model parameters updated by the translation model in each iteration to not exceed a number threshold;

[0250] In a case where the number of training iterations of the translation model is not less than a second number threshold, the number threshold is canceled, and the second number threshold is greater than the first number threshold.

[0251] Fig.13 1 is a structural diagram of a text translation device based on a translation model provided by an exemplary embodiment of the present application. The translation model includes n cascaded encoding sub-models and m cascaded decoding sub-models, each encoding sub-model and each decoding sub-model includes a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3. Fig.13 As shown, the device comprises:

[0252] An acquisition module 1301 is used to acquire a text to be translated;

[0253] The input-output module 1302 is used to input the text to be translated into the n encoding sub-models, and perform feature extraction in turn through each of the n encoding sub-models to obtain encoding features output by the n encoding sub-models; wherein each of the encoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer;

[0254] The input-output module 1302 is further used to input the encoding features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection;

[0255] The prediction module 1303 is used to predict the predicted translation result of the text to be translated according to the decoding feature.

[0256] It should be noted that the training device for the translation model provided in the above embodiment is only illustrated by the division of the above functional modules. 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 training device for the translation model provided in the above embodiment and the training method embodiment of the translation model belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0257] Similarly, the text translation device based on the translation model provided in the above embodiment is only illustrated by the division of the above functional modules. In actual application, 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 text translation device based on the translation model provided in the above embodiment and the text translation method embodiment based on the translation model belong to the same concept. The specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0258] An embodiment of the present application also provides a computer device, which includes: a processor and a memory, wherein at least one instruction, at least one program, a code set or an instruction set is stored in the memory, and the at least one instruction, at least one program, a code set or an instruction set is loaded and executed by the processor to implement the training method of the translation model or the text translation method based on the translation model provided in the above-mentioned method embodiments.

[0259] Optionally, the computer device is a server. Fig.14 It is a structural diagram of a computer device provided by an exemplary embodiment of the present application.

[0260] The computer device 1400 includes a central processing unit (CPU) 1401, a system memory 1404 including a random access memory (RAM) 1402 and a read-only memory (ROM) 1403, and a system bus 1405 connecting the system memory 1404 and the central processing unit 1401. The computer device 1400 also includes a basic input / output system (I / O system) 1406 for facilitating information transmission between various components in the computer device, and a large-capacity storage device 1407 for storing an operating system 1413, application programs 1414, and other program modules 1415.

[0261] The basic input / output system 1406 includes a display 1408 for displaying information and an input device 1409 such as a mouse and a keyboard for user inputting information. The display 1408 and the input device 1409 are connected to the central processing unit 1401 through an input / output controller 1410 connected to the system bus 1405. The basic input / output system 1406 may also include an input / output controller 1410 for receiving and processing inputs from a plurality of other devices such as a keyboard, a mouse, or an electronic stylus. Similarly, the input / output controller 1410 also provides output to a display screen, a printer, or other types of output devices.

[0262] The mass storage device 1407 is connected to the central processing unit 1401 through a mass storage controller (not shown) connected to the system bus 1405. The mass storage device 1407 and its associated computer-readable storage medium provide non-volatile storage for the computer device 1400. That is, the mass storage device 1407 may include a computer-readable storage medium (not shown) such as a hard disk or a compact disc read-only memory (CD-ROM) drive.

[0263] Without loss of generality, the computer-readable storage medium may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer-readable storage instructions, data structures, program modules or other data. Computer storage media include RAM, ROM, Erasable Programmable Read Only Memory (EPROM), Electronically Erasable Programmable Read-Only Memory (EEPROM), flash memory or other solid-state storage devices, CD-ROM, Digital Versatile Disc (DVD) or other optical storage, cassettes, tapes, disk storage or other magnetic storage devices. Of course, those skilled in the art will know that the computer storage medium is not limited to the above. The above-mentioned system memory 1404 and mass storage device 1407 can be collectively referred to as memory.

[0264] The memory stores one or more programs, and the one or more programs are configured to be executed by one or more central processing units 1401. The one or more programs contain instructions for implementing the above-mentioned method embodiments. The central processing unit 1401 executes the one or more programs to implement the methods provided by the above-mentioned various method embodiments.

[0265] According to various embodiments of the present application, the computer device 1400 can also be connected to a remote computer device on a network through a network such as the Internet. That is, the computer device 1400 can be connected to a network 1412 through a network interface unit 1411 connected to the system bus 1405, or the network interface unit 1411 can be used to connect to other types of networks or remote computer device systems (not shown).

[0266] The memory also includes one or more programs, which are stored in the memory and include steps executed by a computer device in the method provided in the embodiment of the present application.

[0267] A computer-readable storage medium is also provided in an embodiment of the present application. The computer-readable storage medium stores at least one instruction, at least one program, code set or instruction set. When the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor of a computer device, the training method of the translation model or the text translation method based on the translation model provided in the above-mentioned method embodiments is implemented.

[0268] The present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the training method of the translation model or the text translation method based on the translation model provided in the above-mentioned method embodiments.

[0269] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned readable storage medium may be a read-only memory, a disk or an optical disk, etc.

[0270] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent switching, 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 translation model, characterized in that: The translation model includes cascaded n encoding sub-models and cascaded m decoding sub-models, each of the encoding sub-models and each of the decoding sub-models includes a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3, and the method includes: Get sample text; Input the sample text into the n encoding sub-models, perform feature extraction in turn through each of the n encoding sub-models, and obtain encoding features output by the n encoding sub-models; wherein each of the encoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer; Input the encoded features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection; Predicting a sample translation result of the sample text according to the decoding feature; The model parameters of the translation model are updated according to the error between the real translation result of the sample text and the sample translation result.

2. The method according to claim 1, characterized in that The translation model includes k cascaded encoding models, each of the encoding models includes at least two cascaded encoding sub-models among the n encoding sub-models, and k is a positive integer greater than or equal to 2; the sample text is input into the n encoding sub-models, and feature extraction is performed in sequence through each of the n encoding sub-models to obtain encoding features output by the n encoding sub-models, including: Inputting the sample text into a first encoding model, and extracting features in turn through each encoding sub-model in the first encoding model to obtain output features of the first encoding model; Input the output feature of the i-th coding model into the i+1-th coding model, and extract features in turn through each of the coding sub-models in the i+1-th coding model to obtain the output feature of the i+1-th coding model, where i is a positive integer and i+1 is not greater than k; The translation model includes k cascaded decoding models, each of the decoding models includes at least three cascaded decoding sub-models among the m decoding sub-models; the encoding features are input into the m decoding sub-models, and features are extracted in sequence through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models, including: Inputting the output features of the kth encoding model into the first decoding model, and extracting features in turn through each of the decoding sub-models in the first decoding model to obtain the output features of the first decoding model; The output features of the kth encoding model and the output features of the jth decoding model are input into the j+1th decoding model, and feature extraction is performed in turn through each decoding sub-model in the j+1th decoding model to obtain the output features of the j+1th decoding model, where j is a positive integer and j+1 is not greater than k.

3. The method according to claim 2, characterized in that Each of the encoding models includes a cascaded first encoding sub-model and a second encoding sub-model, the sub-network layer of the first encoding sub-model is a multi-head self-attention network, and the sub-network layer of the second encoding sub-model is a feed-forward fully connected network; The step of inputting the output feature of the i-th coding model into the i+1-th coding model, and extracting features in sequence through each of the coding sub-models in the i+1-th coding model to obtain the output feature of the i+1-th coding model comprises: Inputting the output feature of the i-th coding model into the first coding sub-model of the i+1-th coding model; Performing feature extraction sequentially through the layer normalization layer and the multi-head self-attention network of the first encoding sub-model; The output features of the i-th encoding model and the output features of the layer normalization layer of the first encoding sub-model are added to the output features of the multi-head self-attention network of the first encoding sub-model through the residual connection to obtain the output features of the first encoding sub-model; Inputting the output features of the first encoding sub-model into the second encoding sub-model of the (i+1)th encoding model; Performing feature extraction sequentially through the layer normalization layer and the feed-forward fully connected network of the second encoding sub-model; The output features of the first encoding sub-model and the output features of the layer normalization layer of the second encoding sub-model are added to the output features of the feedforward fully connected network of the second encoding sub-model through the residual connection to obtain the output features of the i+1th encoding model.

4. The method according to claim 3, characterized in that The step of adding the output features of the i-th encoding model and the output features of the layer normalization layer of the first encoding sub-model to the output features of the multi-head self-attention network of the first encoding sub-model through the residual connection to obtain the output features of the first encoding sub-model includes: Determine a first product of an output feature of the i-th coding model and a first weight; and determine a second product of an output feature of the layer normalization layer of the first coding sub-model and a second weight; Adding the first product and the second product to the output features of the multi-head self-attention network of the first encoding sub-model through the residual connection; The step of adding the output features of the first coding sub-model and the output features of the layer normalization layer of the second coding sub-model to the output features of the feedforward fully connected network of the second coding sub-model through the residual connection to obtain the output features of the (i+1)th coding model comprises: Determine a third product of an output feature of the first encoding sub-model and a third weight; and determine a fourth product of an output feature of the layer normalization layer of the second encoding sub-model and a fourth weight; The third product and the fourth product are added to the output features of the feedforward fully connected network of the second encoding sub-model through the residual connection.

5. The method according to claim 4, characterized in that The method further comprises: At least one of the first weight, the second weight, the third weight and the fourth weight is optimized according to an error between a real translation result of the sample text and the sample translation result.

6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: The decoding features output by the m decoding sub-models are normalized to obtain normalized decoding features.

7. The method according to any one of claims 2 to 5, characterized in that: Each of the decoding models includes a cascaded first decoding sub-model, a second decoding sub-model and a third decoding sub-model, the sub-network layer of the first decoding sub-model is a first multi-head self-attention network, the sub-network layer of the second decoding sub-model is a second multi-head self-attention network, and the sub-network layer of the third encoding sub-model is a feed-forward fully connected network; The step of inputting the output features of the kth encoding model and the output features of the jth decoding model into the j+1th decoding model, and extracting features in sequence through each of the decoding sub-models in the j+1th decoding model to obtain the output features of the j+1th decoding model comprises: Inputting the output feature of the j-th decoding model into the first decoding sub-model of the j+1-th decoding model; Performing feature extraction sequentially through the layer normalization layer and the first multi-head self-attention network of the first decoding sub-model; The output features of the j-th decoding model and the output features of the layer normalization layer of the first decoding sub-model are added to the output features of the first multi-head self-attention network of the first decoding sub-model through the residual connection to obtain the output features of the first decoding sub-model; Inputting the output features of the k-th encoding model and the output features of the first decoding sub-model into the second decoding sub-model of the j+1-th decoding model; Performing feature extraction sequentially through the layer normalization layer and the second multi-head self-attention network of the second decoding sub-model; The output features of the first decoding sub-model and the output features of the layer normalization layer of the second decoding sub-model are added to the output features of the second multi-head self-attention network of the second decoding sub-model through the residual connection to obtain the output features of the second decoding sub-model; Inputting the output features of the second decoding sub-model into the third decoding sub-model of the j+1th decoding model; Performing feature extraction sequentially through the layer normalization layer and the feed-forward fully connected network of the third decoding sub-model; The output features of the second decoding sub-model and the output features of the layer normalization layer of the third decoding sub-model are added to the output features of the feedforward fully connected network of the third decoding sub-model through the residual connection to obtain the output features of the j+1th decoding model.

8. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: When the number of training iterations of the translation model is not greater than a first number threshold, setting the number of model parameters updated by the translation model in each iteration to not exceed a number threshold; In a case where the number of training iterations of the translation model is not less than a second number threshold, the number threshold is canceled, and the second number threshold is greater than the first number threshold.

9. A text translation method based on a translation model, characterized in that: The translation model includes cascaded n encoding sub-models and cascaded m decoding sub-models, each of the encoding sub-models and each of the decoding sub-models includes a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3, and the method includes: Get the text to be translated; Input the text to be translated into the n encoding sub-models, and perform feature extraction in turn through each of the n encoding sub-models to obtain encoding features output by the n encoding sub-models; wherein each of the encoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction result of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer; Input the encoded features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection; A predicted translation result of the text to be translated is predicted according to the decoding feature.

10. A translation model training device, characterized in that: The translation model includes cascaded n encoding sub-models and cascaded m decoding sub-models, each of the encoding sub-models and each of the decoding sub-models includes a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3, and the device includes: An acquisition module is used to acquire sample text; An input-output module, used for inputting the sample text into the n encoding sub-models, performing feature extraction in turn through each of the n encoding sub-models, and obtaining encoding features output by the n encoding sub-models; wherein each of the encoding sub-models is used for performing feature extraction in turn through the layer normalization layer and the sub-network layer, and processing the feature extraction results of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer; The input-output module is further used to input the encoding features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection; A prediction module, used for predicting a sample translation result of the sample text according to the decoding feature; The training module is used to update the model parameters of the translation model according to the error between the real translation result of the sample text and the sample translation result.

11. The device according to claim 10, characterized in that The translation model includes k cascaded encoding models, each of the encoding models includes at least two cascaded encoding sub-models among the n encoding sub-models, and k is a positive integer greater than or equal to 2; the input-output module is used to: Inputting the sample text into a first encoding model, and extracting features in turn through each encoding sub-model in the first encoding model to obtain output features of the first encoding model; Input the output feature of the i-th coding model into the i+1-th coding model, and extract features in turn through each of the coding sub-models in the i+1-th coding model to obtain the output feature of the i+1-th coding model, where i is a positive integer and i+1 is not greater than k; The translation model includes k cascaded decoding models, each of which includes at least three cascaded decoding sub-models among the m decoding sub-models; the input-output module is used to: Inputting the output features of the kth encoding model into the first decoding model, and extracting features in turn through each of the decoding sub-models in the first decoding model to obtain the output features of the first decoding model; The output features of the kth encoding model and the output features of the jth decoding model are input into the j+1th decoding model, and feature extraction is performed in turn through each decoding sub-model in the j+1th decoding model to obtain the output features of the j+1th decoding model, where j is a positive integer and j+1 is not greater than k.

12. A text translation device based on a translation model, characterized in that: The translation model includes cascaded n encoding sub-models and cascaded m decoding sub-models, each of the encoding sub-models and each of the decoding sub-models includes a cascaded layer normalization layer and a sub-network layer, n is a positive integer greater than or equal to 2, and m is a positive integer greater than or equal to 3, and the device includes: The acquisition module is used to obtain the text to be translated; An input-output module, used for inputting the text to be translated into the n encoding sub-models, and performing feature extraction in turn through each of the n encoding sub-models to obtain encoding features output by the n encoding sub-models; wherein each of the encoding sub-models is used for performing feature extraction in turn through the layer normalization layer and the sub-network layer, and processing the feature extraction results of the encoding sub-model through the residual connection of the input position and the output position of the layer normalization layer; The input-output module is further used to input the encoding features into the m decoding sub-models, and perform feature extraction in turn through each of the m decoding sub-models to obtain decoding features output by the m decoding sub-models; wherein each of the decoding sub-models is used to perform feature extraction in turn through the layer normalization layer and the sub-network layer, and process the feature extraction results of the decoding sub-model through the residual connection; A prediction module is used to predict a predicted translation result of the text to be translated according to the decoding feature.

13. A computer device, characterized in that: The computer device includes a processor and a memory, wherein at least one program is stored in the memory, and the at least one program is loaded and executed by the processor to implement the training method of the translation model as described in any one of claims 1 to 8, or the text translation method based on the translation model as described in claim 9.

14. A computer-readable storage medium, characterized in that: The readable storage medium stores at least one program, and the at least one program is loaded and executed by the processor to implement the training method of the translation model as described in any one of claims 1 to 8, or the text translation method based on the translation model as described in claim 9.

15. A computer program product, characterized in that The computer program product includes computer instructions, which 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 the training method of the translation model according to any one of claims 1 to 8, or the text translation method based on the translation model according to claim 9.