Neural network processing method, neural network and natural language processing method
By performing multi-layer normalization processing between adjacent substructures of the neural network, the problem of gradient saturation during training of the layer normalization method is solved, the robustness of the model is enhanced and the performance is improved.
Patent Information
- Application Number
- CN202410843469.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-09-24
AI Technical Summary
Existing layer normalization methods still face problems such as gradient saturation in neural network training, which affects the stability and performance of the model.
A multi-layer normalization method is proposed. By performing normalization processing between adjacent substructures, the parameter distribution is constrained to a reasonable interval, reducing large-scale changes in parameters between substructures, thereby reducing the probability of gradient saturation.
It effectively reduces the occurrence probability of gradient saturation, enhances the robustness of the model, and appropriately reduces the hidden layer dimension or improves the model performance while maintaining the same performance.
Smart Images

Figure CN118690790A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence, and in particular to a neural network processing method, a neural network and a natural language processing method. Background Art
[0002] Layer Normalization is a common normalization method in machine learning, especially in natural language processing (NLP). For example, layer normalization is used in Transformer.
[0003] Although the existing layer normalization operation helps to improve the training stability and performance of the neural network, it still faces problems such as gradient saturation in the training of the neural network. Summary of the invention
[0004] According to a first aspect of an embodiment of the present disclosure, a neural network processing method is proposed, wherein the neural network has L stacked substructures, the L substructures have the same structure, and L is an integer not less than 2, and the method comprises: calculating the feature representation of the output of the first substructure based on the feature representation of the output of the previous layer of the first substructure; calculating the feature representation of the output of the second substructure based on the feature representation of the output of the first substructure, wherein the second substructure is adjacent to the first substructure and is located after the first substructure; normalizing the feature representation output by the first substructure and the feature representation output by the second substructure together; and performing subsequent calculations of the current reasoning of the neural network based on the result of the normalization processing.
[0005] Optionally, normalizing the feature representation of the first substructure output and the feature representation of the second substructure output includes: calculating the mean and variance for the nodes respectively contained in the feature representation of the first substructure output and the feature representation of the second substructure output; and normalizing the feature representation of the second substructure output based on the mean and the variance to obtain a normalized feature representation of the second substructure output.
[0006] Optionally, normalizing the feature representation output by the first substructure and the feature representation output by the second substructure together includes: using a multi-layer normalization layer of the second substructure to perform the normalization on the feature representation output by the first substructure and the feature representation output by the second substructure.
[0007] Optionally, the third substructure is adjacent to the second substructure and is located after the second substructure, wherein subsequent calculations of the current inference of the neural network based on the result of the normalization processing include: the third substructure calculates the feature representation of the third substructure output based on the feature representation of the normalized second substructure output; the multi-layer normalization layers of the third substructure normalize the feature representation of the normalized second substructure output and the feature representation of the third structure output together to obtain the feature representation of the normalized third substructure output; and the latter structure of the third substructure performs calculations based on the feature representation of the normalized third substructure output.
[0008] Optionally, the third substructure is adjacent to the second substructure and is located after the second substructure, and the fourth substructure is adjacent to the third substructure and is located after the third substructure, wherein subsequent calculations of the current inference of the neural network based on the result of the normalization processing include: the third substructure calculates the feature representation of the output of the third substructure based on the feature representation of the normalized second substructure output; the fourth substructure calculates the feature representation of the output of the fourth substructure based on the feature representation of the output of the third substructure, and uses the multi-layer normalization layer of the fourth substructure to normalize the feature representation of the output of the third substructure and the feature representation of the output of the fourth structure to obtain the normalized feature representation of the output of the fourth substructure; and the latter structure of the fourth substructure is calculated based on the feature representation of the normalized fourth substructure output.
[0009] Optionally, the third substructure is adjacent to the second substructure and is located after the second substructure, and the method further includes: the third substructure calculates a feature representation of the third substructure output based on the feature representation of the second substructure output, wherein normalizing the feature representation of the first substructure output and the feature representation of the second substructure output together includes: using a multi-layer normalization layer of the third substructure to normalize the feature representation of the first substructure output, the feature representation of the second substructure output, and the feature representation of the third substructure output together to obtain a normalized feature representation of the third substructure output, and performing subsequent calculations of the current inference of the neural network based on the result of the normalization processing includes: calculating a subsequent structure of the third substructure based on the feature representation of the normalized third substructure output.
[0010] Optionally, the L substructures each include N hidden layers, and normalizing the feature representation of the output of the first substructure and the feature representation of the output of the second substructure includes: using a multi-layer normalization layer followed by the nth hidden layer of the second substructure to normalize the feature representation of the output of the nth hidden layer of the first substructure and the feature representation of the output of the nth hidden layer of the second substructure together to obtain a normalized feature representation of the output of the nth hidden layer of the second substructure, wherein N is an integer not less than 2, and N≥n≥1.
[0011] Optionally, the second substructure calculates the feature representation of the output of the second substructure based on the feature representation of the output of the first substructure, including: the second substructure calculates the feature representation of the output of the first hidden layer of the second substructure based on the feature representation of the output of the first substructure, and normalizes the feature representation of the output of the first substructure and the feature representation of the output of the second substructure together, including: using the multi-layer normalization layer followed by the first hidden layer of the second substructure to normalize the feature representation of the output of the first hidden layer of the first substructure and the feature representation of the output of the first hidden layer of the second substructure together to obtain the normalized feature representation of the output of the first hidden layer of the second substructure; the second hidden layer of the second substructure calculates the feature representation of the output of the second hidden layer of the second substructure based on the normalized feature representation of the output of the first hidden layer of the second substructure; and using the multi-layer normalization layer followed by the second hidden layer of the second substructure to normalize the feature representation of the output of the second hidden layer of the first substructure and the feature representation of the output of the second hidden layer of the second substructure together to obtain the normalized feature representation of the output of the second hidden layer of the second substructure.
[0012] According to a second aspect of an embodiment of the present disclosure, a neural network processing method is proposed, wherein the neural network includes L stacked substructures, each of the substructures includes at least two or more normalization layers, and the method includes: in two adjacent substructures: the normalization layer of the latter substructure receives the intermediate feature representation output from its own non-normalization layer and receives the intermediate feature representation output from the non-normalization layer of the former substructure to generate a normalized sequence.
[0013] Optionally, the normalization layer of the latter substructure receives the intermediate feature representation from its own non-normalized layer output and the intermediate feature representation from the non-normalized layer output of the former substructure to generate a normalized sequence, including: the attention normalization layer of the latter substructure receives the intermediate feature representation from its own attention layer output and the intermediate feature representation from the attention layer output of the former substructure to generate an attention layer normalized sequence; and the feedforward normalization layer of the latter substructure receives the intermediate feature representation from its own feedforward layer output and the intermediate feature representation from the feedforward layer output of the former substructure to generate a feedforward layer normalized sequence.
[0014] Optionally, the attention normalization layer of the latter substructure receives the intermediate feature representation from its own attention layer output and the intermediate feature representation from the attention layer output of the previous substructure to generate an attention layer normalization sequence, including: the self-attention normalization layer of the latter substructure receives the intermediate feature representation from its own self-attention layer output and the intermediate feature representation from the self-attention layer output of the previous substructure to generate a self-attention layer normalization sequence; and / or the interactive attention normalization layer of the latter substructure receives the intermediate feature representation from its own interactive attention layer output and the intermediate feature representation from the interactive attention layer output of the previous substructure to generate an interactive attention layer normalization sequence.
[0015] Optionally, the normalization layer of the previous substructure receives the intermediate feature representation output by its own non-normalization layer to generate a normalized sequence.
[0016] According to a third aspect of an embodiment of the present disclosure, a neural network is proposed, comprising: L stacked substructures, wherein each of the substructures comprises one or more normalization layers, and in two adjacent substructures, the non-normalization layer of the previous substructure is also connected to the normalization layer of the next substructure.
[0017] According to a fourth aspect of an embodiment of the present disclosure, a natural language processing method is proposed, including: obtaining text input; processing using the method described in the first and / or second aspects; and generating text, an image or a video as a response based on the processing result.
[0018] According to the fifth aspect of an embodiment of the present disclosure, a terminal device is proposed, comprising: a processor; and a memory on which executable code is stored, and when the executable code is executed by the processor, the processor executes the method based on the first, second and / or fourth aspects.
[0019] According to the sixth aspect of an embodiment of the present disclosure, a non-temporary machine-readable storage medium is proposed, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor executes a method based on the first, second and / or fourth aspects.
[0020] According to a seventh aspect of an embodiment of the present disclosure, a computer program product is proposed, comprising computer program instructions, characterized in that when the computer program instructions are executed by a processor, the method based on the first, second and / or fourth aspects is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.
[0022] Figure 1 An example flow of a layer normalization operation is shown.
[0023] Figure 2 A schematic flowchart of a neural network processing method according to an embodiment of the present disclosure is shown.
[0024] Figure 3 An example of the process of normalizing adjacent layers of the present disclosure is shown.
[0025] Figure 4 An example of a multi-layer normalization process of the present disclosure is shown.
[0026] Figures 5A to 5D An example of multi-layer normalization between multiple decoders is shown.
[0027] Figure 6 An example of multi-layer normalization processing is shown in each layer of decoder1 and decoder2.
[0028] Figure 7 A schematic flowchart of a neural network processing method according to an embodiment of the present disclosure is shown.
[0029] Figure 8 An example of multi-layer normalization between multiple substructures is shown.
[0030] Fig. 9 An example of detailed operation of multi-layer normalization inside a substructure is shown.
[0031] Fig.10 A schematic flowchart of a natural language processing method according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0032] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although possible embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms without being limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art. In addition, it should be understood that the descriptions of "first", "second", "third" and "fourth" herein are intended to distinguish different objectives of the same type of object, rather than to make any suggestion as to the order or importance of these objectives.
[0033] In the field of machine learning, neural networks with features of different scales usually take longer to train because gradient descent takes more time to converge. In some cases, the introduction of features of different scales can even cause the error gradient to explode.
[0034] Layer normalization is a common normalization technique in machine learning, which is mainly used to normalize each input sample independently. It calculates the mean and variance of each sample in each layer of the network, and introduces two learnable parameters to rescale and offset the standardized output.
[0035] Layer normalization uses network nodes of the same layer as input. Figure 1 An example of a layer normalization process is shown. represents the sum of the inputs of the ith node in the lth layer, then we can first calculate the mean of all network nodes in this layer based on the following formula:
[0036]
[0037] Calculate the mean of layer l, that is, calculate the mean of all nodes in layer l (represented by l_i in the figure), and then calculate the variance based on the following formula:
[0038]
[0039] That is, the variance of the lth layer is calculated, that is, the variance of all nodes in the lth layer (represented by l_i in the figure) is calculated, and the calculated mean and variance are used to calculate the output of the normalization layer. That is, the final output is:
[0040]
[0041] Among them, f is the activation function, g is the gain parameter, and b is the bias. These parameters will not destroy the previous information and the gain parameter and bias are learnable. The normalized output obtained can then be used for the calculation of the next layer of the neural network. By standardizing the data distribution of each sample, layer normalization helps to speed up the training process and improve the stability of the model.
[0042] Layer normalization has a wide range of applications in NLP, reinforcement learning (RL), computer vision, generative models, and time series analysis. For example, in natural language processing tasks, layer normalization is widely used in various model structures. Specifically, models such as Gemini, Llama, GPT, and Kimi widely use Transformer, and layer normalization in Transformer is used to stabilize the training process and improve model performance. Layer normalization is used many times in multi-head self-attention mechanisms and feedforward neural networks. In encoders and decoders (usually using sequence-to-sequence (Seq2Seq) models) in tasks such as machine translation and text summarization, layer normalization helps the model process long sequence inputs. In addition, in sentiment analysis tasks, layer normalization can help improve the ability to capture subtle sentiment changes in text. In reinforcement learning, layer normalization can help stabilize the training process of policy networks and value networks, especially when dealing with complex environments and long time series. In computer vision tasks, layer normalization is mainly used to process small batches of data or distributed training environments. In generative models, layer normalization is used to stabilize the training process of the model and improve the quality of generated samples. Layer normalization is also widely used in time series prediction and analysis tasks. For example, in recurrent neural networks such as long short-term memory networks (LSTM) and gated recurrent units (GRU), layer normalization can be applied to each layer to improve long-term dependency problems and training stability. In the Transformer model for time series prediction, layer normalization ensures the stability of the model when processing long time series. Through its application in these different fields, layer normalization has demonstrated its important role in improving model training efficiency, stability, and performance. Although the existing layer normalization operation helps to improve the training stability and performance of the model, it still faces problems such as gradient saturation in the training of neural networks.
[0043] In view of this, the embodiment of the present disclosure proposes a multi-layer normalization method that can be applied to multiple stacked substructures (e.g., multi-layer Transformer). By performing a multi-layer normalization operation with constrained parameter distribution on adjacent substructures, the parameters between adjacent substructures can be distributed in a reasonable range, avoiding large-scale changes in parameters between adjacent substructures, thereby enhancing the robustness of the model. This method is particularly suitable for the training stage of the model and can effectively reduce the probability of gradient saturation.
[0044] The multi-layer normalization processing method of the disclosed embodiment is applicable to various neural network models having the same or different stacked substructures and having normalization layers for performing layer normalization operations in the substructures, and by using normalization between adjacent substructures, a larger amount of parameters is allowed to participate in statistics, thereby ensuring statistical validity. Therefore, while ensuring that the model performance remains unchanged, the hidden layer dimension can be appropriately reduced; or the model performance can be improved while the hidden layer dimension remains unchanged; or, more network layers can be added within the allowed range to improve the performance of the neural network. At the same time, since the consistency of the parameter distribution of adjacent substructures is guaranteed (that is, the parameters are constrained within a reasonable range), large-scale changes in parameters between adjacent substructures can be avoided, thereby reducing the probability of gradient saturation.
[0045] In one embodiment, the model to which the multi-layer normalization processing method of the present disclosure is applied can be a recurrent neural network (RNN) and its variants (e.g., LSTM, GRU). Specifically, LSTM and GRU are variants of RNN, which solve the gradient vanishing and gradient exploding problems in traditional RNN by introducing a gating mechanism. Multiple LSTM or GRU units can be stacked into a multi-layer structure, with the output of each layer serving as the input of the next layer. Layer normalization can be applied between the output and input of each time step to stabilize the training process. The above model structure is widely used in scenarios such as time series data prediction, natural language processing (such as language modeling, machine translation), etc.
[0046] In one embodiment, the model to which the multi-layer normalization processing method of the present disclosure is applied may be a graph neural network (GNN). GNN includes a graph convolution layer (GCN), which updates the representation of a node by aggregating the features of neighboring nodes. GNN generally includes multiple graph convolution layers stacked in sequence to propagate information and features layer by layer in graph structured data. Layer normalization can be applied after each layer of graph convolution to normalize node features. The above model structure is widely used in scenarios such as node classification, graph classification, and link prediction.
[0047] In one embodiment, the model to which the multi-layer normalization processing method of the present disclosure is applied can be an autoencoder. The autoencoder consists of an encoder and a decoder, the encoder compresses the input data into a low-dimensional latent space, and the decoder reconstructs the input data from the latent space. In the autoencoder, multiple encoder and decoder layers can be stacked, and layer normalization can be applied after each layer of encoder and decoder to stabilize the training process. The above model structure is widely used in scenarios such as data dimensionality reduction, feature extraction, and anomaly detection.
[0048] In one embodiment, the model to which the multi-layer normalization processing method of the present disclosure is applied can be a generative adversarial network (GAN). The generator and discriminator of GAN compete with each other, the generator attempts to generate realistic data, and the discriminator attempts to distinguish between real data and generated data. In practical applications, the generator and the discriminator may include multiple convolutional layers or fully connected layers, which can be stacked, and layer normalization is applied after each layer to normalize features and stabilize training. The above model structure is widely used in scenes such as image generation, data enhancement, and style transfer.
[0049] In one embodiment, the model to which the multi-layer normalization processing method of the present disclosure is applied can be a convolutional neural network. A convolutional network generally includes a plurality of sequentially stacked convolutional layers. The convolutional layer extracts local features by sliding the convolution kernel on the input feature map. For example, the residual network (ResNet) and the densely connected network (DenseNet) enhance the information flow by adding jump connections and dense connections. In the construction of multiple sequentially stacked convolutional layers, layer normalization can be applied after each layer of convolution to standardize the output and stabilize the training process. Residual connections or dense connections can be introduced between layers. The above model structure is widely used in scenes such as image classification, target detection, and semantic segmentation.
[0050] In one embodiment, the model to which the multi-layer normalization processing method of the present disclosure is applied can be a pre-trained language model of a Transformer variant, such as BERT (Bidirectional Encoder Representations from Transformers, bidirectional encoding representation from Transformer), GPT (Generative Pre-trained Transformer, generative pre-trained Transformer), Gemini, Llama, etc. Among them, BERT uses the encoder stack of Transformer, so that it can consider the contextual information on both sides of the word when encoding each word. Unlike traditional unidirectional language models, BERT's bidirectional encoding makes it more powerful in capturing semantic information and sentence relationships. GPT, Gemini and Llama are all unidirectional autoregressive language models, that is, when generating each word, only the contextual information in front of the word (from left to right order) is considered, and future information is not considered. GPT, Gemini and Llama use the decoder part in the Transformer architecture, and multiple decoder layers are stacked together. These pre-trained language model models capture complex language features through multi-layer Transformer encoders and / or decoders. Layer normalization is used in each substructure to normalize the output and stabilize the training. The above model structure is widely used in natural language processing tasks such as text generation, machine translation, question answering systems, etc.
[0051] In one embodiment, the model to which the multi-layer normalization processing method of the present disclosure is applied can be a hybrid model. The hybrid model can mix different types of neural networks (such as RNN, CNN, Transformer) to make full use of their respective advantages. Layer normalization can be applied between different substructures. For example, in a complex network architecture, substructures such as RNN, CNN, Transformer can be stacked together, and layer normalization is applied after each substructure. The above model structure can be applied to scenarios such as multimodal data processing, spatiotemporal series prediction, and complex system simulation.
[0052] In the following embodiments, the principles of the present invention will be explained with emphasis on using Transformer, especially the decoder part of Transformer, as an example of multiple substructures stacked in sequence. However, it should be noted that the multi-layer normalization processing method of the present invention can be used in any model of stacked substructures that require layer normalization operations as described above, and can be applied to future developed models that have stacked substructures that require layer normalization operations.
[0053] Figure 2 A schematic flow chart of a neural network processing method according to an embodiment of the present disclosure is shown. The neural network has L stacked substructures, the structures of the L substructures are the same, and L is an integer not less than 2. In one embodiment, the neural network can be a large language model, the input of the model is text, and the output is also text. In another embodiment, the neural network can be a multimodal model, the input of the model is text, and the output is an image or video or text. It should be understood that the neural network can also be used for models of other scenarios, such as any model with a stacked substructure that requires a layer normalization operation as mentioned above.
[0054] For ease of understanding, Figure 3 An example of a stacked L substructure is shown. As shown in the figure, Figure 3 The decoder L includes L stacked decoders (the decoder can be, for example, a Transformer decoder structure), and can be regarded as part of a large pre-trained language model or a multimodal data processing model. The direction of the arrows in the figure indicates the direction of data flow, that is, the input from the upper layer (for example, user input, such as text, audio, picture, video or machine code) is first sent to decoder1, and the output after calculation by decoder1 is then sent to decoder2, and the output after calculation by decoder2 is then sent to decoder3, and so on, until decoderL. The output of decoderL can be sent to the lower layer for subsequent calculations of the current reasoning of the neural network. For example, when decoderL is the last decoder substructure included in the GPT model, decoderL sends its output result to the last layer of the model (a linear layer plus a softmax layer) to convert the final hidden state into a probability distribution in the vocabulary to generate the next word.
[0055] It should be understood that although the figure shows a network structure with bottom input and top output, in the field of machine learning, the layers closer to the input are usually described as upper layers or shallow layers, and the layers closer to the output are described as lower layers or deep layers. Figure 3 Not shown, those skilled in the art will appreciate that between the input and decoder 1 may include, for example, a text mapping module for performing Tokenization processing on the aforementioned input text, and may also include, for example, a position mapping module for identifying the corresponding position of each vector obtained by the Tokenization processing.
[0056] In one embodiment, the neural network may include the L decoders shown in the figure. In another embodiment, the neural network may include more decoders, for example, at least one stacked decoder is included above decoder1, and / or at least one stacked decoder is included below decoderL. Further, since the multi-layer normalization processing in the present disclosure is performed by a substructure located at a lower layer (or a deeper layer) in an adjacent substructure, for example, the multi-layer normalization processing between decoder1 and decoder2 is performed by decoder2, decoder1 may not include a normalization layer (at least not a layer for performing multi-layer normalization processing), or include a normalization layer (but the normalization layer actually only performs conventional layer normalization processing, rather than multi-layer normalization processing, because it does not obtain the output of the previous structure). In at least one embodiment, decoder1 can be regarded as having the same structure as other decoders (decoder2~decoderN), because the main structures of decoder1~decoderN (for example, the self-attention layer, interactive attention layer, and feedforward layer, etc.) are consistent.
[0057] In addition, it should be understood that in neural networks, "layer" is a basic concept that represents a collection of computing units in the network structure. Each layer receives input from the previous layer, performs specific calculations or transformations, and then passes the results to the next layer. The reference of "layer" can be large or small, for example, Figure 3 The structure of can be described as a stack of L "layers" of decoders, in which case one layer corresponds to a substructure (the substructure is usually a well-known structure in the field of neural networks). In other examples, each decoder may also include multiple layers, such as a self-attention layer, an interactive attention layer, and a feedforward layer. For this reason, in the present disclosure, "multi-layer normalization" refers to the normalization of multiple homogeneous nodes in adjacent substructures, for example, it may be the normalization of the output nodes of two adjacent substructures, the normalization of the nodes of a corresponding layer in two adjacent substructures (for example, the normalization between the feedforward layer output of decoder1 and the feedforward layer output of decoder2), or the normalization of the nodes of each corresponding layer in the two adjacent substructures that originally need to perform layer normalization (for example, the normalization between the self-attention layer output of decoder1 and the self-attention layer output of decoder2, the normalization between the interactive attention layer output of decoder1 and the interactive attention layer output of decoder2, and the normalization between the feedforward layer output of decoder1 and the feedforward layer output of decoder2).
[0058] In step S210, the first substructure calculates the feature representation of the first substructure output based on the feature representation of the previous layer output of the first substructure. In step S220, the second substructure calculates the feature representation of the second substructure output based on the feature representation of the first substructure output, wherein the second substructure is adjacent to the first substructure and is located after the first substructure (i.e., the second substructure is located at a lower layer than the first substructure and is closer to the output).
[0059] Here, the first substructure and the second substructure may correspond to Figure 3 For any two adjacent decoders shown, the first substructure is in front (i.e., located at a higher level in the model, although the diagram is shown at the bottom), and the second substructure is in the back (i.e., located at a lower level in the model, although the diagram is shown at the top). For ease of understanding, the first substructure corresponds to decoder1 and the second substructure corresponds to decoder2 as an example for description.
[0060] In step S210, decoder1 obtains the feature representation from the output of its previous layer (for example, when decoder1 corresponds to the first stacked decoder substructure in the GPT model, decoder1 obtains the input embedding calculated from the input text) and generates the corresponding feature representation h decoder1 In one embodiment, decoder1 may not perform layer normalization, that is, the output feature representation h decoder1 is the hidden vector without normalization operation. In another embodiment, decoder1 can perform layer normalization operation, that is, perform Add&Norm (addition & layer normalization operation) required by the conventional Transformer decoder structure, and the output feature representation h decoder1 is the hidden vector after normalization. In any embodiment, h decoder1 can be considered as the output results independently calculated by decoder1. decoder1 The specific result of is only related to the input received by decoder1 and the internal calculation operation of decoder1, and has nothing to do with the output of other decoders. In addition, in the different embodiments of the present disclosure described below, the feature representation h decoder1 Here, it is assumed that decoder1 includes N layers (for example, including self-attention layers, interactive attention layers, and feedforward layers), h decoder1 It can refer to the output of any one or more layers, for example h decoder1_1 、h decoder1_2 ,…,h decoder1_N , where h decoder1_NRepresents the output of the last layer in decoder1, that is, the output of the entire decoder1 submodule, which is also the output sent to the upper layer decoder2.
[0061] In step S220, decoder 2 directly obtains the feature representation h decoder1 (In more detail, h decoder1_N ) as input and generate h decoder2 As output. Similarly, in the different embodiments of the present disclosure described below, the feature representation h decoder2 Here, decoder2 also includes N layers, h decoder2 It can refer to the output of any one or more layers, for example h decoder2_1 、h decoder2_2 ,…,h decoder2_N , where h decoder2_N Represents the output of the last layer in decoder2, that is, the output of the entire decoder2 submodule.
[0062] In step S230, the feature representation output by the first substructure and the feature representation output by the second substructure are normalized together. Here, "normalizing together" means that the feature representation output by the first substructure and the feature representation output by the second substructure are processed together in one normalization operation. At this time, the object of the normalization operation is no longer a certain substructure, or a specific layer of a certain substructure, that is, it is no longer the normalization of network nodes in the same layer, but the normalization of network nodes in two adjacent substructures (or one or more layers in two adjacent substructures). In the above example where the first substructure corresponds to decoder1 and the second substructure corresponds to decoder2, it is the normalization of h decoder1 and h decoder2 At this time, let h decoder1 and h decoder2 Each of them includes M network nodes, then step S230 is to decoder1 and h decoder2 Each includes a total of 2M network nodes, which are normalized in the same normalization operation. This operation may be referred to as a "multi-layer normalization" operation in this disclosure.
[0063] Then, in step S240, subsequent calculations of the current reasoning of the neural network are performed based on the result of the normalization processing. Here, the subsequent calculations of the current reasoning of the neural network refers to a reasoning process performed on the current input of the neural network model. After the normalization operation of step S230 is completed, subsequent calculations can be performed using the result of the normalization processing until the current reasoning is completed. The current input can be the input in the training samples sent to the model during the model training phase, or it can be the input sent during the model verification, fine-tuning or actual reasoning phase. Since the multi-layer normalization processing method disclosed in the present invention can particularly reduce the probability of gradient saturation, the neural network model should include the multi-layer normalization processing method disclosed in the present invention during the model training phase.
[0064] Therefore, the multi-layer normalization processing method disclosed in the present invention allows a larger amount of parameters to participate in statistics by using normalization between adjacent substructures, thereby ensuring statistical validity. Therefore, while ensuring that the model performance remains unchanged, the hidden layer dimension can be appropriately reduced. At the same time, since the consistency of the distribution of parameters of adjacent substructures is guaranteed (i.e., the parameters are constrained within a reasonable range), large-scale changes in parameters between adjacent substructures can be avoided, thereby reducing the probability of gradient saturation.
[0065] As before combined Figure 1 As described above, conventional layer normalization processing is to obtain the mean and variance of the network nodes of the same layer, and then adjust the numerical range of the output of the network nodes of this layer. The multi-layer normalization processing in the present disclosure is to constrain the output numerical range of more than one "layer" (as mentioned above, "layer" can refer to a substructure such as a decoder, or a more detailed layer within a substructure, such as an attention layer and / or a feedforward layer). To this end, step S230 may include: calculating the mean and variance for the nodes respectively contained in the feature representation of the output of the first substructure and the feature representation of the output of the second substructure; and normalizing the feature representation of the output of the second substructure based on the mean and the variance to obtain the normalized feature representation of the output of the second substructure.
[0066] For ease of understanding, the multi-layer normalization of the present disclosure will be described below in conjunction with a formula. Specifically, when the multi-layer normalization is implemented as a two-layer normalization, if represents the sum of the inputs of the ith node in all nodes of the lth layer and the l+1th layer (where the lth layer and the l+1th layer can refer to two adjacent substructures, or the causal layers of two adjacent substructures), then the mean can be calculated first:
[0067]
[0068] That is, calculate the mean of the two layers, layer l and layer l+1, that is, calculate the mean of all nodes in layer l and layer l+1 (represented by l_i and l+1_i in the figure), and then calculate the variance:
[0069]
[0070] That is, the variance of the two layers, layer l and layer l+1, is calculated, that is, the variance of all nodes in layer l and layer l+1 (represented by l_i and l+1_i in the figure) is calculated, and the calculated mean and variance are used to calculate the output. That is, the final output is:
[0071]
[0072] Among them, f is the activation function, g is the gain parameter, and b is the bias. These parameters will not destroy the previous information and the gain parameter and bias are learnable. Figure 4 An example of a multi-layer normalization process of the present disclosure is shown.
[0073] In different embodiments of the present disclosure, the operations of performing multi-layer normalization between various substructures may be different. Figures 5A to 5D An example of multi-layer normalization between multiple decoders is shown.
[0074] First, the ranges of the multiple layers in the multi-layer normalization can be different. For example, two layers can be normalized together, or three layers (or even more layers) can be normalized together. For example, in one embodiment, the above formula can be used and Figure 5A As shown, only two adjacent substructures are subjected to multi-layer normalization operation. In another embodiment, as Figure 5B As shown, multi-layer normalization operations may be performed on more adjacent substructures (eg, three substructures).
[0075] Specifically, in Figure 5A When the multi-layer normalization operation is performed only on two adjacent substructures, the normalization layer of the second substructure may perform the multi-layer normalization operation on the first and second substructures, so step S230 may include: using the multi-layer normalization layer of the second substructure to perform the normalization process on the feature representation output by the first substructure and the feature representation output by the second substructure. Figure 5A In the example, decoder2 can directly obtain the feature representation h after decoder1 completes all calculations. decoder1 (In more detail, h decoder1 N) as input, and replace the original normalization layer position that performs layer normalization with a multi-layer normalization layer, and perform multi-layer normalization operations on the calculation results (or intermediate calculation results) of decoder2 and the corresponding calculation results (or intermediate calculation results) at the corresponding position of decoder1 (that is, Figure 5A Herein, a normalization layer that performs a multi-layer normalization operation may be referred to as a “multi-layer normalization layer”.
[0076] In contrast, Figure 5B As shown, when performing multi-layer normalization operations on more adjacent substructures (for example, three substructures), the normalization layer of the last substructure in the adjacent substructures (for example, the third substructure, the third substructure is closer to the output than the first and second substructures) can perform multi-layer normalization operations on the first and second substructures. At this time, the third substructure is adjacent to the second substructure and is located after the second substructure. For example, decoder3 can be regarded as the third substructure. Therefore, the method also includes: the third substructure calculates the feature representation of the output of the third substructure based on the feature representation output by the second substructure. Step S230 may include: using the normalization layer of the third substructure to normalize the feature representation output by the first substructure, the feature representation output by the second substructure, and the feature representation output by the third substructure, to obtain the normalized feature representation of the output of the third substructure. Step S240 may include: the latter structure of the third substructure is calculated based on the feature representation output by the normalized third substructure. That is, in Figure 5B In the example, decoder1 completes all calculations independently based on the upper layer input and provides feature representation h to decoder2. decoder1 (In more detail, h decoder1_N ) as the input of decoder2, decoder2 also represents h according to the upper layer input feature decoder1 Complete all calculations independently and provide feature representation h to decoder2 decoder2 (In more detail, h decoder2_N ) as the input of decoder3. In other words, decoder2 is the same as decoder1. In addition to obtaining input data, its respective calculation process does not need to obtain data from other adjacent decoders. After decoder2 completes all calculations, decoder3 can directly obtain the feature representation h decoder2 (In more detail, h decoder2_N) as input, and replace the original normalization layer position that performs layer normalization with a multi-layer normalization layer, and perform multi-layer normalization operations on the calculation results (or intermediate calculation results) of decoder3 together with the corresponding calculation results (or intermediate calculation results) at the corresponding positions of decoder1 and decoder2 (that is, Figure 5B Calculation of multi-layer normalization shown).
[0077] Secondly, each substructure may perform multi-layer normalization operations with only one adjacent substructure, or may perform multi-layer normalization operations with multiple adjacent substructures. Figure 5C As shown, a substructure performs a multi-layer normalization operation only with one of its adjacent substructures. Figure 5D As shown, the substructure and its adjacent previous and next substructures are subjected to multi-layer normalization operations.
[0078] Specifically, in Figure 5C As shown in the figure, after decoder2 performs multi-layer normalization operation with decoder1, decoder2 provides the calculation result to the lower layer decoder3 as the input of decoder3, but its calculation result (or intermediate calculation result) does not participate in the subsequent multi-layer normalization operation. Instead, the subsequent decoder4 implements the multi-layer normalization operation with decoder3. Figure 5C The operation shown can be viewed as Figure 5A At this time, a fourth substructure (corresponding to Figure 5C The decoder 4 shown in the figure, and step S240 may include: the third substructure calculates the feature representation of the third substructure output based on the normalized feature representation of the second substructure output; the fourth substructure calculates the feature representation of the fourth substructure output based on the feature representation of the third substructure output, and uses the multi-layer normalization layer of the fourth substructure to normalize the feature representation of the third substructure output and the feature representation of the fourth structure output to obtain the normalized feature representation of the fourth substructure output; and the latter structure of the fourth substructure is calculated based on the feature representation of the normalized fourth substructure output.
[0079] As an alternative, Figure 5D As shown ( Figure 5D The operation shown can also be viewed as Figure 5A(a subsequent operation embodiment of the operation shown in the figure), after decoder2 performs a multi-layer normalization operation with decoder1, decoder2 provides the calculation result to decoder3 of the lower layer as the input of decoder3, and its calculation result (or intermediate calculation result) also participates in the multi-layer normalization operation of decoder3. Further, although not shown in the figure, decoder3 can also provide the calculation result to decoder4 of the lower layer as the input of decoder4 after performing a multi-layer normalization operation with decoder2, and its calculation result (or intermediate calculation result) also participates in the multi-layer normalization operation of decoder4, and so on. At this time, step S240 may include: the third substructure calculates a feature representation of the third substructure output based on the feature representation of the normalized second substructure output; the normalization layer of the third substructure normalizes the feature representation of the normalized second substructure output and the feature representation of the third structure output together to obtain a normalized feature representation of the third substructure output; and the latter structure of the third substructure is calculated based on the feature representation of the normalized third substructure output.
[0080] In addition, although not shown in the figure, Figure 5B As shown, when performing multi-layer normalization operations on more adjacent substructures (for example, three substructures), only the substructures numbered as multiples of 3 may perform multi-layer normalization operations with the first two substructures (for example, after decoder3 performs multi-layer normalization operations with decoder1 and decoder2, decoder6 directly performs multi-layer normalization operations with decoder4 and decoder5), or each substructure may perform multi-layer normalization operations when it is the lowest-level substructure of the three adjacent substructures (for example, after decoder3 performs multi-layer normalization operations with decoder1 and decoder2, decoder4 immediately performs multi-layer normalization operations with decoder2 and decoder3, and then decoder5 performs multi-layer normalization operations with decoder3 and decoder4, and so on).
[0081] As mentioned above, when performing multi-layer normalization operations on adjacent substructures, multiple normalization operations may be performed on all nodes in these substructures; or when the substructure itself includes multiple hidden layers, multi-layer normalization operations may be performed on the corresponding hidden layers of the adjacent substructures.
[0082] In one embodiment, the L substructures each include N hidden layers, and normalizing the feature representation output by the first substructure and the feature representation output by the second substructure includes: using a multi-layer normalization layer followed by the nth hidden layer of the second substructure to normalize the feature representation output by the nth hidden layer of the first substructure and the feature representation output by the nth hidden layer of the second substructure together to obtain a normalized feature representation output by the nth hidden layer of the second substructure, wherein N is an integer not less than 2, and N≥n≥1. When n is not equal to N, the calculation of the n+1th hidden layer in the second substructure is performed after the multi-layer normalization of the nth hidden layer in the second substructure and the nth hidden layer in the first substructure. In one embodiment, multi-layer normalization can be performed for each of the N hidden layers in the second substructure. At this time, step S220 includes: the second substructure calculates the feature representation of the first hidden layer output of the second substructure based on the feature representation of the first substructure output, and step S230 includes: using the normalization layer connected to the first hidden layer of the second substructure to normalize the feature representation of the first hidden layer output of the first substructure and the feature representation of the first hidden layer output of the second substructure together, to obtain the normalized feature representation of the first hidden layer output of the second substructure; the second hidden layer of the second substructure calculates the feature representation of the second hidden layer output of the second substructure based on the normalized feature representation of the first hidden layer output of the second substructure; and using the normalization layer connected to the second hidden layer of the second substructure to normalize the feature representation of the second hidden layer output of the first substructure and the feature representation of the second hidden layer output of the second substructure together, to obtain the normalized feature representation of the second hidden layer output of the second substructure. Similarly, when N=3 or above, subsequent multi-layer normalization operations for the third hidden layer and the like can also be performed.
[0083] For ease of understanding, Figure 6 An example of multi-layer normalization processing is shown in each layer of decoder1 and decoder2. Here, decoder1 and decoder2 have the same structure, and each includes a multi-layer normalization layer after various self-attention layers, interactive attention layers, and feedforward layers. When decoder1 is not the first decoder in a plurality of stacked decoder structures in a neural network, decoder1 can perform normalization operations on the decoder above it. When decoder1 corresponds to the first decoder in a plurality of stacked decoder structures in a neural network, since the upper layer of decoder1 does not have the same decoder structure, decoder1 does not need to perform multi-layer normalization operations. At this time, Figure 6Decoder1 in the example shown may include multiple layers of normalization layers, but performs normalization operations on this layer (i.e., performs conventional layer normalization operations), or may not include layers that perform normalization operations at all (because decoder2 performs multiple layers of normalization operations on the outputs of decoder1's self-attention layer, interactive attention layer, and feedforward layer).
[0084] As the lower decoder of decoder1, decoder2 needs to perform multi-layer normalization operations in combination with the outputs of each layer of decoder1. Therefore, a multi-layer normalization layer after its self-attention layer, interactive attention layer (encoder-decoder attention, i.e., encoder-decoder attention) and feedforward layer will obtain the outputs of the corresponding layers of decoder1 and decoder2 to perform multi-layer normalization operations. For those skilled in the art, it should be known that in the decoder structure of a conventional Transformer, an Add&Norm layer is included after its self-attention layer, interactive attention layer and feedforward layer. Add is used to perform the addition of the residual connection and the output of the current layer. For example, the Add&Norm layer after the self-attention layer will be residually connected to the input of the self-attention layer, and the input and output of the self-attention layer will be added, and the result after the addition will be layer normalized to ensure the stability and convergence of the model. In the present disclosure, for a substructure that does not perform multi-layer normalization operations itself but whose calculation results (or intermediate calculation results) are to be sent to the lower substructure for multi-layer normalization operations (for example, decoder1 as the top layer), an Add&Norm layer can be included after the self-attention layer, the interactive attention layer, and the feedforward layer, that is, it has the same structure as the decoder of the existing Transformer; it can also be as follows Figure 6 The example includes multiple normalization layers (but only performs normalization operations on this layer); it may also not include normalization layers (but still includes the Add layer for residual connection addition), because the output results of each layer of decoder1 will be normalized by the corresponding layer of decoder2. For substructures that need to perform multi-layer normalization operations (for example, decoder2~decoderL), multi-layer normalization layers can be used to replace the original Add&Norm layer. Although Figure 6 In order to focus on describing the principles of the present invention, the residual connections of the self-attention layer, the interactive attention layer, and the feedforward layer input and output are omitted. However, it should be understood that the neural network model using the processing method of the present invention will still perform Add (addition operation), and after performing the addition operation, a multi-layer normalization operation will be performed.
[0085] Specifically, after decoder1 obtains the content of the upper layer output (for example, the output of the encoder stack), its self-attention layer, interactive attention layer, and feedforward layer perform operations layer by layer, and the final output h of the feedforward layer is converted into decoder1_3 (actually the result of adding the residual connection of the feedforward layer output to the feedforward layer input) is fed into decoder2 as the input of decoder2's self-attention layer. The decoder2's self-attention layer then operates on this input to generate the output h decoder2_1 (Actually, it is the result of adding the residual connection of the self-attention layer output to the self-attention layer input). The multi-layer normalization layer after the self-attention layer then performs a normalization on the output h. decoder2_1 and decoder1’s self-attention layer output h decoder1_1 Perform multi-layer normalization operations to obtain the self-attention layer output h of decoder2 after multi-layer normalization decoder2_1_MLN The multi-layer normalization operation can be performed according to the above formulas (4) to (6). At this time, the self-attention layer of decoder1 corresponds to the lth layer, and the self-attention layer of decoder2 corresponds to the l+1th layer.
[0086] Subsequently, the interactive attention layer of decoder2 uses h decoder2_1_MLN As input, and get the encoder layer is the output of interactive attention to generate the output h decoder2_2 (Actually, it is the result of adding the residual connection of the interactive attention layer output to the interactive attention layer input). The multi-layer normalization layer after the interactive attention layer then performs a normalization on the output h. decoder2_2 The interactive attention layer output h of decoder1 decoder1_2 Perform multi-layer normalization operations to obtain the output h of the interactive attention layer of decoder2 after multi-layer normalization decoder2_2_MLN Similarly, the multi-layer normalization operation can be performed according to the above formulas (4) to (6). At this time, the interactive attention layer of decoder1 corresponds to layer l, and the interactive attention layer of decoder2 corresponds to layer l+1.
[0087] Similarly, the feedforward layer of decoder2 also performs operations to obtain the output h decoder2_3 , the multi-layer normalization layer after the feed-forward layer then performs a normalization on the output h decoder2_3 and the feedforward layer output h of decoder1 decoder1_3 Perform multi-layer normalization operations to obtain the multi-layer normalized decoder2 feedforward layer output h decoder2_3_MLN The output h decoder2_3_MLN It can be sent to the upper structure as the output of decoder2, for example, to decoder3 for subsequent calculation.
[0088] When it should be understood, Figure 6 The decoder stack shown is an example of a neural network model that also includes an encoder (and therefore includes an interactive attention layer that needs to obtain data from the encoder). In some models, such as the GPT model, since the model itself does not include a Transformer encoder but only includes a Transformer decoder stack, the interactive attention layer may not be included in the decoder substructure. In this case, the substructure only includes a self-attention layer (multi-head self-attention) and a feedforward layer, so it is only necessary to perform a multi-layer normalization operation after each of these two layers.
[0089] In one embodiment, the present disclosure may also be implemented as a neural network processing method. Figure 7 A schematic flow chart of a neural network processing method according to an embodiment of the present disclosure is shown. For ease of understanding, Figure 8 An example of multi-layer normalization between two substructures is shown. Figure 7 In the processing method, the neural network includes L stacked substructures, the structures of the L substructures are the same or different, and each of the substructures includes one or more normalization layers. It should be understood that when a substructure has no previous substructure, the substructure can have a conventional Add&Norm layer as described above, or omit the normalization layer.
[0090] The method comprises the following operations performed in two adjacent substructures.
[0091] In step S710, the normalized layer of the latter substructure receives the intermediate feature representation outputted by its own non-normalized layer and receives the intermediate feature representation outputted by the non-normalized layer of the former substructure. Thus, in step S720, a normalized sequence is generated.
[0092] like Figure 8 As shown, in Figure 7 In the processing method, when the substructure is the previous substructure, it provides the output of the non-normalized layer, such as the attention layer (such as the self-attention layer, the interactive attention layer) and / or the feedforward layer as the intermediate feature representation to the next substructure for multi-layer normalization processing. The intermediate feature representation indicates that the output sequence is neither the input sequence nor the output sequence of the substructure, but the sequence output by the intermediate layer (but non-normalized layer) of the substructure. When the substructure is the next substructure, it obtains the intermediate feature representation of the previous substructure to perform normalization processing together with the output of its corresponding intermediate layer.
[0093] In one embodiment, steps S710-S720 may include: the attention normalization layer of the latter substructure receives the intermediate feature representation from its own attention layer output and the intermediate feature representation from the attention layer output of the former substructure to generate an attention layer normalization sequence; and the feedforward normalization layer of the latter substructure receives the intermediate feature representation from its own feedforward layer output and the intermediate feature representation from the feedforward layer output of the former substructure to generate a feedforward layer normalization sequence.
[0094] In one embodiment, the substructure may correspond to the encoder of the Transformer. In another embodiment, the substructure may correspond to the encoder and the decoder. In another embodiment, the substructure may correspond to the decoder. When the substructure corresponds to the decoder (for example, the model is decoderonly), each decoder includes only one attention layer (i.e., multi-head self-attention) and one feedforward layer; if the model includes an encoder and a decoder, each encoder includes only one attention layer (i.e., multi-head self-attention) and one feedforward layer, and each decoder includes two attention layers (multi-head self-attention and interactive attention) and one feedforward layer; if the model includes only an encoder (for example, the model is encoderronly), each encoder includes only one attention layer (i.e., multi-head self-attention) and one feedforward layer.
[0095] For example, the model includes an encoder and a decoder structure. When the substructure is a decoder structure, the attention normalization layer of the latter substructure receives the intermediate feature representation from the output of its own attention layer and the intermediate feature representation from the output of the attention layer of the former substructure to generate an attention layer normalization sequence, including: the self-attention normalization layer of the latter substructure receives the intermediate feature representation from the output of its own self-attention layer and the intermediate feature representation from the output of the self-attention layer of the former substructure to generate a self-attention layer normalization sequence; and the interactive attention normalization layer of the latter substructure receives the intermediate feature representation from the output of its own interactive attention layer and the intermediate feature representation from the output of the interactive attention layer of the former substructure to generate an interactive attention layer normalization sequence.
[0096] For example, the model includes an encoder and a decoder structure. When the substructure is an encoder structure, the attention normalization layer of the latter substructure receives the intermediate feature representation from the output of its own attention layer and the intermediate feature representation from the output of the attention layer of the former substructure to generate an attention layer normalization sequence, including: the self-attention normalization layer of the latter substructure receives the intermediate feature representation from the output of its own self-attention layer and the intermediate feature representation from the output of the self-attention layer of the former substructure to generate a self-attention layer normalization sequence.
[0097] For example, the model only includes an encoder structure or the model only includes a decoder structure. Regardless of whether the substructure is an encoder structure or a decoder structure, the attention normalization layer of the latter substructure receives the intermediate feature representation from its own attention layer output and the intermediate feature representation from the attention layer output of the former substructure to generate an attention layer normalization sequence, including: the self-attention normalization layer of the latter substructure receives the intermediate feature representation from its own self-attention layer output and the intermediate feature representation from the self-attention layer output of the former substructure to generate a self-attention layer normalization sequence.
[0098] It can be understood that no matter whether the substructure is an encoder structure or a decoder structure or a structure including both, if the previous substructure includes a normalization layer, it will also receive the intermediate feature representation output from the non-normalized layer before its own normalization layer, for example, it receives the intermediate feature representation from the output of the multi-head self-attention layer, or receives the intermediate feature representation from the output of the feedforward layer, or receives the intermediate feature representation from the output of the interactive attention layer, so as to realize layer normalization processing in the normalization layer of the previous substructure.
[0099] Furthermore, for ease of understanding, Fig. 9 An example of detailed operation of multi-layer normalization within a substructure is shown. Figure 7 The former substructure described in the illustrated method may correspond to the substructure l in the figure, and the latter substructure corresponds to the substructure l+1 in the figure. Fig. 9 The substructure shown may correspond to the encoder structure of a Transformer, or the decoder structure of a Transformer if the model does not include the encoder structure of a Transformer.
[0100] As shown in the figure, after the attention layer output, substructure l+1 performs multi-layer normalization processing on the attention layer output of substructure l and the attention layer output of substructure l+1; then the feedforward layer is calculated, and after the feedforward layer output, the feedforward layer output of substructure l and the feedforward layer output of substructure l+1 are normalized, and the output obtained is sent to substructure l+2. When substructure l+2 is calculating, Figure 7 The previous substructure described in the method shown becomes the substructure l+1 in the figure, and the next substructure becomes the substructure l+2 in the figure. At this time, the attention layer output and feedforward layer output of substructure l+1 are also used for the calculation of the two multi-layer normalization layers of substructure l+2, and so on. Similarly, before substructure l+1 performs calculations, substructure l can also be used as the next substructure of substructure l-1 for multi-layer normalization operations.
[0101] It should be noted that in Fig. 9 In the described example, substructure l can be the first substructure, that is, the substructure that receives the mapping sequence, or substructure l can be a substructure in the middle of the neural network; substructure l+2 can be a substructure in the middle of the neural network, followed by other substructures, or substructure l+2 can also be the last substructure in the neural network, followed by, for example, a fully connected layer, an activation function layer, etc.
[0102] It can be understood that each normalization layer of substructure l, substructure l+1 and substructure l+2 also includes an Add operation to receive a sequence from a higher layer, such as input to an attention layer or input to a feedforward layer. This is a conventional operation in the art and will not be described in detail.
[0103] In one embodiment, the neural network processing method described in any embodiment of the present disclosure may be applied to part of the neural network or all of the neural network. For example, in a neural network that only includes an encoder or only includes a decoder, only part of the encoder or decoder uses the processing method described in the embodiment of the present disclosure, while the remaining part does not use the processing method described in the embodiment of the present disclosure.
[0104] For example, in a neural network including an encoder and a decoder, the processing method described in the embodiments of the present disclosure may be used only in the encoder structure or only in the decoder structure, or may be used in both the encoder and decoder structures, which does not constitute a limitation of the present disclosure.
[0105] Accordingly, the present disclosure can also be implemented as a neural network, comprising: L stacked substructures, wherein the structures of the L substructures are the same or different, each of the substructures includes one or more normalized layers, and in two adjacent substructures, the non-normalized layer of the previous substructure is also connected to the normalized layer of the next substructure. Fig. 9 It can be seen as a schematic diagram of the stacked substructure included in the neural network.
[0106] The above describes a normalization method that can be applied to multi-layer stacked structures. This method proposes a multi-layer normalization method with constrained parameter distribution for adjacent substructures, which can make the parameter distribution between layers within a reasonable range, especially avoiding the gradient saturation problem during model training, thereby enhancing the robustness of the model.
[0107] To this end, the present disclosure may also be implemented as a natural language processing method. Fig.10 A schematic flowchart of a natural language processing method according to an embodiment of the present disclosure is shown.
[0108] In step S1010, text input is obtained. In one embodiment, the dialogue system may obtain text typed by the user, and in another embodiment, the voice system may obtain voice instructions input by the user and recognize them as text for input.
[0109] Step S1020, processing is performed using the method described above. That is, the model can also perform multi-layer normalization operations during the processing.
[0110] Then, in step S1030, text, image or video is generated as a response based on the processing result.
[0111] Here, the model can be a large language model whose input is text and whose output is also text, or it can be a multimodal model whose input is text and whose output is other forms (e.g., images, videos).
[0112] Since the processing method disclosed in the present invention performs multi-layer normalization processing between adjacent layers, a larger number of parameters can be allowed to participate in statistics during model calculation, which not only ensures the statistical validity, but also appropriately reduces the hidden layer dimension while maintaining the model performance unchanged. In addition, since the parameters are constrained within a reasonable range, the consistency of the distribution of the parameters of the adjacent layers is guaranteed, thus avoiding the gradient saturation problem caused by large-scale changes in the parameters of the adjacent layers during model training.
[0113] In one embodiment, the present disclosure may also be implemented as a terminal device, including: a processor; and a memory, on which executable codes are stored, and when the executable codes are executed by the processor, the processor executes the method described above.
[0114] In one embodiment, the present disclosure may also be implemented as a non-transitory machine-readable storage medium having executable codes stored thereon. When the executable codes are executed by a processor of an electronic device, the processor is caused to execute the method described above.
[0115] In one embodiment, the present disclosure may also be implemented as a computer program product, including computer program instructions, which implement the method described above when executed by a processor.
[0116] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.
[0117] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the system and method according to multiple embodiments of the present invention. For this reason, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0118] Embodiments of the present invention have been described above, and the above description is exemplary rather than exhaustive and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A neural network processing method, wherein: The neural network has L stacked substructures, the L substructures have the same structure, L is an integer not less than 2, and the method includes: The first substructure calculates the feature representation of the output of the first substructure based on the feature representation of the output of the previous layer of the first substructure; The second substructure calculates the feature representation output by the second substructure based on the feature representation output by the first substructure, wherein the second substructure is adjacent to the first substructure and is located after the first substructure; Normalizing the feature representation output by the first substructure and the feature representation output by the second substructure; and The subsequent calculation of the current reasoning of the neural network is performed based on the result of the normalization process.
2. The method according to claim 1, wherein: Normalizing the feature representation output by the first substructure and the feature representation output by the second substructure includes: Calculating means and variances for nodes respectively included in the feature representation output by the first substructure and the feature representation output by the second substructure; and Based on the mean and the variance, the feature representation of the second substructure output is normalized to obtain a normalized feature representation of the second substructure output.
3. The method according to claim 1, wherein: Normalizing the feature representation output by the first substructure and the feature representation output by the second substructure includes: The normalization process is performed on the feature representation output by the first substructure and the feature representation output by the second substructure using the multi-layer normalization layer of the second substructure.
4. The method according to claim 3, wherein: The third substructure is adjacent to the second substructure and is located after the second substructure, wherein the subsequent calculation of the current reasoning of the neural network based on the result of the normalization process includes: The third substructure calculates the feature representation of the output of the third substructure based on the feature representation of the normalized output of the second substructure; The multi-layer normalization layer of the third substructure normalizes the normalized feature representation of the second substructure output and the feature representation of the third structure output together to obtain the normalized feature representation of the third substructure output; and The latter structure of the third substructure is calculated based on the feature representation of the normalized third substructure output.
5. The method according to claim 3, wherein: The third substructure is adjacent to the second substructure and is located behind the second substructure, and the fourth substructure is adjacent to the third substructure and is located behind the third substructure, wherein: The subsequent calculation of the current reasoning of the neural network based on the result of the normalization process includes: The third substructure calculates the feature representation of the output of the third substructure based on the feature representation of the normalized output of the second substructure; The fourth substructure calculates the feature representation output by the fourth substructure based on the feature representation output by the third substructure, Using the multi-layer normalization layer of the fourth substructure to normalize the feature representation output by the third substructure and the feature representation output by the fourth substructure, to obtain a normalized feature representation output by the fourth substructure; and The latter structure of the fourth substructure is calculated based on the feature representation of the normalized fourth substructure output.
6. The method according to claim 1, wherein: The third substructure is adjacent to the second substructure and is located behind the second substructure, and the method further includes: The third substructure calculates the feature representation output by the third substructure based on the feature representation output by the second substructure, The normalizing of the feature representation output by the first substructure and the feature representation output by the second substructure includes: Using the multi-layer normalization layer of the third substructure, normalize the feature representation output by the first substructure, the feature representation output by the second substructure, and the feature representation output by the third substructure to obtain a normalized feature representation output by the third substructure, and The subsequent calculation of the current reasoning of the neural network based on the result of the normalization process includes: The latter structure of the third substructure is calculated based on the feature representation of the normalized third substructure output.
7. The method according to claim 1, wherein: The L substructures each include N hidden layers, and normalizing the feature representation output by the first substructure and the feature representation output by the second substructure includes: The feature representation of the output of the nth hidden layer of the first substructure and the feature representation of the output of the nth hidden layer of the second substructure are normalized together using the multi-layer normalization layer following the nth hidden layer of the second substructure to obtain the normalized feature representation of the output of the nth hidden layer of the second substructure, wherein N is an integer not less than 2 and N≥n≥1.
8. The method according to claim 7, wherein: The feature representation output by the second substructure is calculated based on the feature representation output by the first substructure, and the feature representation output by the second substructure includes: The second substructure calculates the feature representation of the output of the first hidden layer of the second substructure based on the feature representation of the output of the first substructure, and Normalizing the feature representation output by the first substructure and the feature representation output by the second substructure includes: Using a multi-layer normalization layer connected to the first hidden layer of the second substructure, normalize the feature representation of the output of the first hidden layer of the first substructure and the feature representation of the output of the first hidden layer of the second substructure, to obtain a normalized feature representation of the output of the first hidden layer of the second substructure; The second hidden layer of the second substructure calculates the feature representation of the second hidden layer output of the second substructure based on the normalized feature representation of the first hidden layer output of the second substructure; and The feature representation of the output of the second hidden layer of the second substructure is normalized together with the feature representation of the output of the second hidden layer of the first substructure and the feature representation of the output of the second hidden layer of the second substructure using the multi-layer normalization layer following the second hidden layer of the second substructure to obtain the normalized feature representation of the output of the second hidden layer of the second substructure.
9. A neural network processing method, wherein: The neural network comprises L stacked substructures, each of which comprises one or more normalization layers, and the method comprises in two adjacent substructures: The normalization layer of the latter substructure receives the intermediate feature representation output from its own non-normalization layer and receives the intermediate feature representation output from the non-normalization layer of the former substructure to generate a normalized sequence.
10. The method according to claim 9, wherein: The normalized layer of the latter substructure receives the intermediate feature representation output from its own non-normalized layer and receives the intermediate feature representation output from the non-normalized layer of the former substructure to generate a normalized sequence, including: The attention normalization layer of the latter substructure receives the intermediate feature representation output from its own attention layer and the intermediate feature representation output from the attention layer of the former substructure to generate an attention layer normalization sequence; and The feedforward normalization layer of the latter substructure receives the intermediate feature representation outputted from its own feedforward layer and the intermediate feature representation outputted from the former feedforward layer of the substructure to generate a feedforward layer normalization sequence.
11. The method according to claim 10, wherein: The attention normalization layer of the latter substructure receives the intermediate feature representation output from its own attention layer and the intermediate feature representation output from the attention layer of the previous substructure to generate an attention layer normalization sequence, including: The self-attention normalization layer of the latter substructure receives the intermediate feature representation output from its own self-attention layer and the intermediate feature representation output from the self-attention layer of the former substructure to generate a self-attention layer normalization sequence; and / or The interactive attention normalization layer of the latter substructure receives the intermediate feature representation output from its own interactive attention layer and the intermediate feature representation output from the previous substructure's interactive attention layer to generate an interactive attention layer normalization sequence.
12. The method according to claim 9, further comprising: The normalization layer of the previous substructure receives the intermediate feature representation output by its own non-normalization layer to generate a normalized sequence.
13. A neural network comprising: L stacked substructures, wherein each of the substructures comprises one or more normalized layers, and in two adjacent substructures, the non-normalized layer of the former substructure is also connected to the normalized layer of the latter substructure.
14. A natural language processing method, comprising: Get text input; Treating using the method according to any one of claims 1 to 12; as well as Generate text, image or video as a response based on the processing result.
15. A terminal device, comprising: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 12 or 14. 16 . A non-transitory machine-readable storage medium having executable codes stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute a method according to any one of claims 1 to 12 or 14.
17. A computer program product comprising computer program instructions, characterized in that When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 12 or 14 is implemented.
Citation Information
Cited By
Multi-point virtual measurement method, system and device and storage medium
CN119415961A
