Model training method and device, text generation method and device, equipment and medium

By introducing the embedding normalization layer and the module length adjustment layer into the large language model, the problem of insufficient parameter training caused by the imbalance of embedding representation module lengths during the training process is solved, and the training effect and hardware processing speed of the model are improved.

CN118606447AActive Publication Date: 2024-09-06BEIJING CHUANGSI YUANDA TECH CO LTD

Patent Information

Application Number
CN202410674267.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-28
Publication Date
2024-09-06
Estimated Expiration
2044-05-28

AI Technical Summary

Technical Problem

During the training process of existing large language models, the embedding representation directly entering the processing layer affects the training adequacy of parameters, resulting in an increase in the number of iterations and training time, which in turn affects the hardware processing speed.

Method used

The embedding normalization layer and the module length adjustment layer are introduced into the large language model. By normalizing and adjusting the module length of the row vectors represented by the embedding, the module length balance of different row vectors is ensured, thereby improving the parameter training of the model. extent and overall training effectiveness.

Benefits of technology

Through module length normalization and adjustment, the processing result accuracy and training effect of large language models are improved, the number of iterations and training time are reduced, the amount of data transmission is reduced, and the hardware processing speed is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606447A
    Figure CN118606447A
Patent Text Reader

Abstract

The embodiment of the invention provides a model training method and device, a text generation method and device, equipment and a medium. The model training method comprises the steps that an input matrix corresponding to lexical elements of text data is obtained; the embedding layer performs first mapping processing on the input matrix to obtain a first embedding representation; the embedding normalization layer performs modulus length normalization on row vectors in the first embedding representation and normalizes modulus lengths of different row vectors in the first embedding representation; the mode length adjustment layer performs mode length adjustment on the second embedded representation to obtain a third embedded representation; the processing layer processes the third embedded representation to output text information of the large language model corresponding to the text data obtained this time; and determining loss information according to the text information. According to the embodiment of the invention, the training fullness and the overall training effect of the parameters of the large language model can be improved, the data transmission amount of the large language model in the training process can be reduced, and the hardware processing speed corresponding to the large language model can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of artificial intelligence technology, and in particular to a model training method, a text generation method, an apparatus, a device and a medium. Background Art

[0002] As we all know, the big language model is one of the feasible paths to general artificial intelligence. The big language model is a natural language processing technology based on neural networks. It can understand and generate human language and can be used to process text generation tasks such as summary generation, machine translation, literary creation, and intelligent dialogue. The big language model usually includes: an embedding layer and a processing layer. Among them, after the token is input into the big language model, the embedding layer will embed the token to obtain the embedding representation corresponding to the token. The processing layer specifically includes: a transformer layer, etc., which is used to determine the text information based on the embedding representation.

[0003] The training of large language models specifically includes: pre-training and fine-tuning training. Pre-training is used to learn general language knowledge and representation; fine-tuning training is used to fine-tune text generation tasks to adapt to different downstream applications. The above-mentioned text generation tasks may include: summary generation, machine translation, literary creation, intelligent dialogue and other text generation tasks.

[0004] The current large language models generally use residual connections and pre-normalization. Among them, residual connections add the embedded representation output by the embedding layer directly to the output of one or more processing layers; pre-normalization performs normalization before residual connections.

[0005] Although the above-mentioned residual connection and pre-normalization methods can prevent the gradient explosion or gradient vanishing problem of the model to a certain extent; however, the embedded representation directly entering the processing layer is likely to affect the degree of training adequacy of the parameters of the large language model, thereby affecting the overall training effect of the large language model. On this basis, in order for the large language model to reach the convergence conditions, the relevant technology requires a large number of iterations and training time. A large number of iterations and training time will increase the amount of data transmission of the large language model during the training process and slow down the hardware processing speed. Summary of the invention

[0006] The embodiment of the present application provides a model training method, which can improve the training adequacy and overall training effect of the parameters of a large language model, reduce the amount of data transmitted during the training process of the large language model, and thereby improve the hardware processing speed corresponding to the large language model.

[0007] Correspondingly, the embodiments of the present application also provide a text generation method, a model training device, a text generation device, an electronic device and a machine-readable medium to ensure the implementation and application of the above method.

[0008] In order to solve the above problems, the embodiment of the present application discloses a model training method, which is used to train a large language model, wherein the large language model includes: an embedding layer, an embedding normalization layer, a modulus length adjustment layer, and a processing layer; the method includes:

[0009] Obtaining an input matrix corresponding to a word unit of text data, and inputting the input matrix into the large language model;

[0010] The embedding layer performs a first mapping process on the input matrix to obtain a first embedding representation; the row vector in the first embedding representation represents a feature vector corresponding to a word in the input matrix;

[0011] The embedding normalization layer performs modulus normalization on the row vectors in the first embedding representation to obtain a second embedding representation; the modulus normalization is used to normalize the moduli of different row vectors in the first embedding representation to the same preset value;

[0012] The modulus length adjustment layer performs modulus length adjustment on the second embedded representation to obtain a third embedded representation;

[0013] The processing layer processes the third embedding representation to output text information of the large language model corresponding to the text data obtained this time;

[0014] Loss information is determined based on the text information.

[0015] The embodiment of the present application also discloses a text generation method, which is applied to a large language model, wherein the large language model includes: an embedding layer, an embedding normalization layer, a modulus length adjustment layer, and a processing layer; the method includes:

[0016] After completing the training of the large language model, using an embedding normalization layer, normalizing the modulus length of the row vectors in the first embedding weight matrix of the embedding layer to obtain a second embedding weight matrix; the modulus length normalization is used to normalize the modulus lengths of different row vectors in the first embedding weight matrix to the same preset value;

[0017] Using the modulus weight vector of the modulus adjustment layer, modulus adjustment is performed on the second embedding weight matrix to obtain a third embedding weight matrix; an element of the modulus weight vector is used to modulus adjust a row vector in the second embedding weight matrix;

[0018] Get the input matrix corresponding to the word unit of the text to be processed;

[0019] Using the third embedding weight matrix, mapping the input matrix to obtain an embedding representation;

[0020] The embedded representation is processed using the processing layer to obtain the target generated text output by the large language model.

[0021] The embodiment of the present application further discloses a model training device, which is used to train a large language model, wherein the large language model includes: an embedding layer, an embedding normalization layer, a modulus length adjustment layer, and a processing layer; the device includes:

[0022] An acquisition module, used for acquiring an input matrix corresponding to a word unit of text data, and inputting the input matrix into the large language model;

[0023] A first mapping module is used to perform a first mapping process on the input matrix using an embedding layer to obtain a first embedding representation; the row vector in the first embedding representation represents a feature vector corresponding to a word in the input matrix;

[0024] A modulus normalization module, configured to use an embedding normalization layer to perform modulus normalization on the row vectors in the first embedding representation to obtain a second embedding representation; the modulus normalization is configured to normalize the moduli of different row vectors in the first embedding representation to the same preset value;

[0025] a module length adjustment module, configured to perform module length adjustment on the second embedded representation to obtain a third embedded representation;

[0026] an output determination module, configured to process the third embedding representation using the processing layer to obtain text information of the large language model;

[0027] The loss determination module is used to determine the loss information according to the text information.

[0028] The embodiment of the present application also discloses a text generation device, which is applied to a large language model, wherein the large language model includes: an embedding layer, an embedding normalization layer, a modulus length adjustment layer, and a processing layer; the device includes:

[0029] A modulus normalization module, used for performing modulus normalization on the row vectors in the first embedding weight matrix of the embedding layer by using the embedding normalization layer after completing the training of the large language model, so as to obtain a second embedding weight matrix; the modulus normalization is used for normalizing the modulus lengths of different row vectors in the first embedding weight matrix to the same preset value;

[0030] A modulus length adjustment module, used to use the modulus length weight vector of the modulus length adjustment layer to perform modulus length adjustment on the second embedding weight matrix to obtain a third embedding weight matrix; an element of the modulus length weight vector is used to perform modulus length adjustment on a row vector in the second embedding weight matrix;

[0031] An acquisition module is used to obtain an input matrix corresponding to a word unit of a text to be processed;

[0032] A mapping module, configured to perform mapping processing on the input matrix using the third embedding weight matrix to obtain an embedding representation;

[0033] A text generation module is used to process the embedded representation using the processing layer to obtain a target generated text output by the large language model.

[0034] Optionally, the training specifically includes: pre-training, the text data includes: N word units; the text information represents: prediction information of the i-th word unit; N and i are both positive integers; i is not greater than N;

[0035] The loss determination module specifically includes:

[0036] The first loss determination module is used to determine the first cross entropy loss information according to the conditional probability corresponding to the prediction information of the i-th word and the real information of the i-th word in the text data; the conditional probability is: the probability of occurrence of the prediction information of the i-th word under the condition of the first i-1 words in the text data.

[0037] Optionally, the training specifically includes: fine-tuning training, the text data includes: input sequence, and label values ​​of output sequence; the text information includes: predicted value of output sequence;

[0038] The loss determination module specifically includes:

[0039] The second loss determination module is used to determine second cross entropy loss information or mean square error loss information according to the predicted value and the label value.

[0040] Optionally, the embedding layer corresponds to an embedding weight matrix, and the first mapping module specifically includes:

[0041] A first matching module, used for matching the word-unit identifiers in the input matrix with the indexes of the rows in the embedding weight matrix to obtain a first target row corresponding to the word-unit identifiers in the input matrix;

[0042] A first determination module is used to determine the embedding representation corresponding to the input matrix according to the first target row.

[0043] Optionally, the mold length adjustment module specifically includes:

[0044] A second mapping module, used for performing a second mapping process on the input matrix according to the modulus weight vector corresponding to the modulus adjustment layer to obtain a modulus coefficient vector;

[0045] An adjustment module is used to perform modulus adjustment on the second embedded representation according to the modulus coefficient vector to obtain a third embedded representation; an element in the modulus coefficient vector is used to perform modulus adjustment on a row vector in the second embedded representation.

[0046] Optionally, the modulus weight vector is a column vector, and the second mapping module specifically includes:

[0047] A second matching module, used for matching the word unit identifier in the input matrix with the index of the element in the modulus weight vector to obtain a first target element corresponding to the word unit identifier in the input matrix;

[0048] The second determination module is used to determine the modulus coefficient vector corresponding to the input matrix according to the first target element.

[0049] Optionally, the adjustment module specifically includes:

[0050] An expansion module, configured to expand the modulus coefficient vector into a modulus coefficient matrix by using an automatic broadcast mechanism; the size of the modulus coefficient matrix is ​​the same as the size of the second embedded representation;

[0051] A dot product module is used to perform a dot product operation on the second embedding representation and the modulus coefficient matrix to obtain a third embedding representation.

[0052] Optionally, the device may further include:

[0053] A parameter updating module is used to update the parameters of the large language model according to the loss information.

[0054] The embodiment of the present application further discloses an electronic device, including: a processor; and a memory, on which executable code is stored. When the executable code is executed, the processor executes the method described in the embodiment of the present application.

[0055] The embodiment of the present application further discloses a machine-readable medium on which executable code is stored. When the executable code is executed, a processor executes the method described in the embodiment of the present application.

[0056] The embodiments of the present application include the following advantages:

[0057] In the technical solution of the embodiment of the present application, an embedding normalization layer is added after the embedding layer, and the embedding normalization layer is used to normalize the modulus length of the row vectors in the first embedding representation output by the embedding layer. The modulus length normalization can normalize the modulus lengths of different row vectors in the first embedding representation to the same preset value.

[0058] The row vector in the embedded representation is specifically a feature vector of a word unit, which can represent the word unit features. The embodiment of the present application normalizes the modulus lengths of different row vectors in the first embedded representation to the same preset value based on modulus length normalization, which can improve the balance between the importances corresponding to the word unit features represented by different row vectors. While improving the balance between the importances corresponding to the word unit features represented by different row vectors, the embodiment of the present application can improve the accuracy of the processing results of the large language model, and thus can improve the degree of training sufficiency and overall training effect of the parameters of the large language model.

[0059] After the row vectors in the first embedding representation are normalized, in order not to limit the expressive power of the row vectors, the modulus adjustment layer of the embodiment of the present application performs modulus adjustment on the second embedding representation. The modulus adjustment can make the embodiment of the present application more conducive to the angle adjustment between the feature vectors of different word units, so that the angles between the feature vectors of different word units can be more fully trained; therefore, the embodiment of the present application can further improve the degree of training sufficiency and overall training effect of the parameters of the large language model.

[0060] The embodiment of the present application can complete the convergence of the large language model while reducing the number of iterations and training time on the basis of improving the training sufficiency of the parameters of the large language model and the overall training effect. Since the number of iterations and training time can be reduced, the embodiment of the present application can reduce the amount of data transmission of the large language model during the training process, thereby improving the hardware processing speed corresponding to the large language model. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Figure 1 It is a schematic diagram of the structure of a large language model according to an embodiment of the present application;

[0062] Figure 2 is a schematic diagram of the structure of the converter layer in a large language model of an embodiment of the present application;

[0063] Figure 3 It is a schematic diagram of the structure of a large language model according to an embodiment of the present application;

[0064] Figure 4 is a schematic diagram of re-parameterization of an embedding weight matrix according to an embodiment of the present application;

[0065] Figure 5 This is a schematic diagram of the steps of a model training method according to an embodiment of the present application;

[0066] Figure 6 It is a schematic diagram of the steps of a text generation method according to an embodiment of the present application;

[0067] Figure 7 It is a structural schematic diagram of a model training device according to an embodiment of the present application;

[0068] Figure 8 is a structural schematic diagram of a text generation device according to an embodiment of the present application;

[0069] Fig. 9 It is a schematic diagram of the structure of a device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0070] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0071] The large language model of the embodiment of the present application is an artificial intelligence model that is designed to understand and generate human language. The large language model can perform a wide range of tasks, including the text generation task of the embodiment of the present application, etc. by training on a large amount of training data. The large language model is usually based on a deep learning architecture, such as a transformer (Transformer) structure. The embodiment of the present application does not limit the specific type of the large language model. For example, the type of the large language model may include: GPT (Generative Pre-Trained Transformer) model and GLM (Generative Language Model, General Language Model) and the like.

[0072] For example, the GPT model is a large-scale natural language generation model based on the Transformer structure. It uses a large amount of training data (text data) for pre-training and can generate high-quality natural language text, including articles, conversations, summaries, etc. The core of the GPT model is the transformer structure, which uses an attention mechanism to enable the GPT model to consider all positions in the input sequence at the same time, thereby better capturing long-distance dependencies. After pre-training the GPT model, fine-tuning it can adapt to various downstream text generation tasks. In the pre-training stage, the GPT model uses the training method of the autoregressive language model to generate only one output at each time step, and the subsequent time step generates the next output based on the previous input and output.

[0073] The principle of the training method of the autoregressive language model is: given the previous i tokens, predict the probability distribution of the (i+1)th token, where i can be a positive integer. In this way, the large language model can generate text with semantic coherence. During the training process, the autoregressive language model uses maximum likelihood estimation to learn the dependencies between tokens. Specifically, the large language model updates the parameters by maximizing the likelihood probability of the real text, so that the generated new text is more similar to the real text.

[0074] The text generation task refers to the use of computer programs or algorithms to capture the grammar, semantics, structure and style of the text based on given input or context information, and use this knowledge to generate new text content. The new text content has a reasonable grammatical structure, semantic accuracy and contextual coherence, and can meet the needs of specific tasks. The generated new text can be a natural language text, an article, a sentence, a paragraph or other forms of text. Text generation can be used in various application scenarios, such as summary generation, machine translation, literary creation, intelligent dialogue, etc.

[0075] The large language model of the embodiment of the present application may include: an embedding layer and a processing layer. Among them, the embedding layer is used to embed the input matrix corresponding to the word element of the input sequence to obtain an embedded representation. In the training stage, the input sequence can be text data for training. In the reasoning stage (text generation stage), the input sequence can be a text to be processed.

[0076] The processing layer may include: a transformer layer. Large language models usually include multiple transformer layers. A transformer layer may adopt a transformer structure, specifically including: a multi-head self-attention mechanism and a feedforward neural network. Multiple transformer layers are used to perform multi-level representation learning on the embedded representation, so as to better capture complex semantics and text structures.

[0077] The transformer layer can be followed by other processing layers. Examples of other processing layers include: standardization layer, linear transformation layer, and normalization layer.

[0078] Reference Figure 1 , shows a schematic diagram of the structure of a large language model of an embodiment of the present application, specifically including: an embedding layer 101, N converter layers 102, such as converter layer 1 to converter layer N, a standardization layer 103, a linear conversion layer 104 and a normalization layer 105.

[0079] The embedding layer 101 is used to embed the input matrix corresponding to the word unit of the input sequence to obtain an embedding representation. The embedding representation is a semantic vector that can represent the semantic information of the word unit and can serve as a basis for the large language model to understand the context, nuances and subtle meanings of words and phrases.

[0080] The N transformer layers 102 are used to perform multi-level representation learning on the embedded representation to better capture complex semantics and text structures. The output of the transformer layer N can be referred to as the first output.

[0081] The normalization layer 103 is used to normalize the first output to obtain the second output. Normalization can overcome the gradient explosion problem caused by the parameter value of the large language model being too large or too small to a certain extent. The parameter value of the large language model may refer to the numerical value of the parameter corresponding to the network layer of the large language model. The embedding layer 101, the N converter layers 102 including the converter layer 1 to the converter layer N, the normalization layer 103, the linear conversion layer 104 and the normalization layer 105 are all network layers of the large language model.

[0082] The linear transformation layer 104 is used to transform the second output into a probability distribution for predicting the next word unit or new text. Specifically, the linear transformation layer 104 performs a linear transformation on the second output and maps it to a vector space of the same size as the vocabulary. The purpose of this is to predict the probability distribution of the next word unit. The vocabulary is used to store word units that can be recognized by the large language model.

[0083] The normalization layer 105 may normalize the probability distribution output by the linear transformation layer 104 to obtain a target probability value between [0, 1]. The target probability value may be the probability that each word in the vocabulary becomes a target word.

[0084] A token is the smallest semantic unit that cannot be further divided. For example, "waterfall" will be divided into two tokens: water and fall. In addition, punctuation marks will also be decomposed into tokens because they also affect the semantic understanding of the entire text. For example, "I don't know." can be decomposed into 5 tokens, which are: "I", "don", "'t", "know", and ".".

[0085] The current large language models generally use residual connections and pre-normalization. Figure 2 , shows a schematic diagram of the structure of the converter layer in a large language model of an embodiment of the present application. The converter layer specifically includes: an attention processing module 201 and a multi-layer perceptron module 202.

[0086] The attention processing module 201 is used to perform attention processing on the input. When the converter layer is converter layer 1, the input can be an embedded representation. The attention processing can include: self-attention processing and cross-attention processing. Taking self-attention processing as an example, the attention processing module is used to perform attention calculation on each position in the input sequence with other positions. Taking cross-attention processing as an example, the attention processing module is used to perform attention calculation on each position in the input sequence with the position in the output sequence.

[0087] The multi-layer perceptron module 202 is used to perform nonlinear transformation and mapping on the input to capture higher-level features.

[0088] Figure 2 In represents a residual connection. When the converter layer is converter layer 1, the residual connection directly adds the embedded representation output by the embedding layer to the output of converter layer 1. Pre-normalization may refer to normalization before the residual connection. The attention processing module 201 normalizes its input before performing attention processing ( Figure 2 ), the multi-layer perceptron module 202 also normalizes its own input before performing nonlinear transformation and mapping of the embedded representation ( Figure 2 The normalization of the attention processing module 201 and the normalization of the multi-layer perceptron module 202 are both examples of pre-normalization.

[0089] In practical applications, the above residual connection and pre-normalization methods can prevent the gradient explosion or gradient vanishing problem of the model to a certain extent. However, the embedded representation directly entering the processing layer such as the converter layer is likely to affect the training effect of the large language model.

[0090] In view of the technical problem that the embedding representation directly entering the processing layer such as the converter layer affects the training effect of the large language model, the embodiment of the present application provides a model training method, which is used to train the large language model. The above-mentioned large language model specifically includes: an embedding layer, an embedding normalization layer, a modulus length adjustment layer and a processing layer; the method specifically includes:

[0091] Obtaining an input matrix corresponding to a word unit of text data, and inputting the input matrix into the large language model;

[0092] The embedding layer performs a first mapping process on the input matrix to obtain a first embedding representation; the row vector in the first embedding representation represents a feature vector corresponding to a word in the input matrix;

[0093] The embedding normalization layer performs modulus normalization on the row vectors in the first embedding representation to obtain a second embedding representation; the modulus normalization is used to normalize the moduli of different row vectors in the first embedding representation to the same preset value;

[0094] The modulus length adjustment layer performs modulus length adjustment on the second embedded representation to obtain a third embedded representation;

[0095] The processing layer processes the third embedding representation to output text information of the large language model corresponding to the text data obtained this time;

[0096] Loss information is determined based on the text information.

[0097] In the embodiment of the present application, an embedding normalization layer is added after the embedding layer, and the embedding normalization layer is used to normalize the modulus length of the row vectors in the first embedding representation output by the embedding layer. The modulus length normalization can normalize the modulus lengths of different row vectors in the first embedding representation to the same preset value, and an example of the preset value can be 1, etc.

[0098] The row vector in the embedded representation is specifically a feature vector of a word unit, which can characterize the word unit characteristics. In traditional technology, the modulus lengths of row vectors vary, resulting in different importance of different word units to model training. For example, a row vector with a larger modulus length has a greater advantage in attention processing, which will cause the corresponding word unit to be focused on; this will affect the accuracy of the attention processing results of the large language model, and thus affect the training effect of the large language model. The embodiment of the present application normalizes the modulus lengths of different row vectors in the first embedded representation to the same preset value based on modulus length normalization, which can improve the balance between the importance corresponding to the word unit features represented by different row vectors. While improving the balance between the importance corresponding to the word unit features represented by different row vectors, the embodiment of the present application can improve the accuracy of the processing results, and thus improve the training effect of the large language model.

[0099] After the row vectors in the first embedded representation are normalized in modulus, in order not to limit the expression capability of the row vectors, the modulus adjustment layer in the embodiment of the present application performs modulus adjustment on the second embedded representation to obtain a third embedded representation.

[0100] Optionally, the modulus adjustment layer can perform modulus adjustment on the second embedding representation according to the modulus coefficient vector. Since an element in the modulus coefficient vector is used to perform modulus adjustment on a row vector in the second embedding representation, and an element in the modulus coefficient vector is derived from a weight parameter in the modulus weight vector; thus, during the model training process, a weight parameter is used to adjust the modulus information of a row vector (a feature vector of a word unit), which increases the difficulty of modulus adjustment. While increasing the difficulty of modulus adjustment, the embodiment of the present application can be more conducive to the angle adjustment between the feature vectors of different word units, so that the angles between the feature vectors of different word units can be more fully trained; therefore, the embodiment of the present application can further improve the training effect of the large language model.

[0101] The embodiment of the present application uses the re-parameterization technology to Figure 1 The structure of the large language model shown is improved. The principle of reparameterization is: first construct a first series of structures (generally used for training), and convert the parameters of the first series of structures into another set of parameters (generally used for reasoning), thereby converting the first series of structures into a second series of structures.

[0102] Specifically to the embodiment of the present application, Figure 1 The structure of the large language model shown is an example of the second series of structures, which can be used in the reasoning stage of the large language model, for example, in the text generation method of the embodiment of the present application.

[0103] Reference Figure 3 , shows a schematic diagram of the structure of a large language model of an embodiment of the present application, specifically including: an embedding layer 301, an embedding normalization layer 302, a modulus adjustment layer 303, N converter layers 304 including converter layer 1 to converter layer N, a standardization layer 305, a linear conversion layer 306 and a normalization layer 307.

[0104] Figure 3 The structure of the large language model shown is an example of a first series of structures, which can be used in the training phase of the large language model, for example, in the model training method of the embodiment of the present application.

[0105] Figure 3 and Figure 1 The difference in structure lies in the differences between the embedding layer 301 , the embedding normalization layer 302 , and the modulus length adjustment layer 303 and the embedding layer 101 . Figure 3 and Figure 1 The difference in the use phase is that Figure 3 is used in the training phase, and Figure 1 Applied to the reasoning stage (also known as the text generation stage).

[0106] For the N converter layers 304, standardization layer 305, linear conversion layer 306 and normalization layer 307, their implementation process is similar to that of the converter layer 102, standardization layer 103, linear conversion layer 104 and normalization layer 105, so they can be referenced to each other and will not be described in detail here.

[0107] In practical applications, it is assumed that the size of the input matrix is ​​[b, s], where the text data is divided into multiple batches, b represents the number of text data (number of items) contained in a batch, and s represents the sequence length of the input matrix, that is, the number of tokens contained in the input matrix.

[0108] The embedding layer can correspond to an embedding weight matrix, and the size of the embedding weight matrix can be: n rows and c columns. In practical applications, n represents the size of the vocabulary, the number of words contained in the vocabulary. Examples of n include: 4096 or 10000. c represents the dimension of the embedding vector, that is, how many dimensions each word is represented as a vector. This value can be set according to the specific requirements of the task. Examples of c include 50, 100, 200, 300, etc. Usually, c< <n。

[0109] The embedding layer performs a first mapping process on the input matrix, and the size of the obtained first embedding representation can be [b, s, c]. The row vectors in the first embedding representation can represent the feature vectors corresponding to the s words in the input matrix. The first embedding representation can be a matrix with s rows and c columns, where b can be used as the depth dimension of the first embedding representation.

[0110] The embodiment of the present application uses an embedding normalization layer to normalize the modulus of the row vectors in the first embedding representation. Modulus normalization changes the modulus of each row vector, but does not change the size of the embedding representation, so the size of the second embedding representation is still [b, s, c].

[0111] The modulus weight vector of the embodiment of the present application may be a vector of n rows and 1 column. The embodiment of the present application uses the modulus weight vector corresponding to the modulus adjustment layer to perform a second mapping process on the input matrix, and the size of the obtained modulus coefficient vector may be s rows and 1 column.

[0112] The embodiment of the present application uses the modulus coefficient vector to adjust the modulus of the second embedded representation, and the size of the obtained third embedded representation can be [b, s, c].

[0113] refer to Figure 4, shows a schematic diagram of re-parameterization of the embedding weight matrix of an embodiment of the present application, wherein, after completing the training of the large language model, the embedding normalization layer can be first used to normalize the row vectors in the first embedding weight matrix of the embedding layer to obtain a second embedding weight matrix; then, the modulus weight vector of the modulus adjustment layer is used to adjust the modulus of the second embedding weight matrix to obtain a third embedding weight matrix. The third embedding weight matrix can be used as Figure 1 The embedding weight matrix of the embedding layer of the large language model shown is used in the inference phase of the large language model to generate the target generated text.

[0114] Method Example 1

[0115] refer to Figure 5 , shows a schematic flow chart of the steps of a model training method according to an embodiment of the present application, the method is used to train a large language model, the large language model specifically includes: an embedding layer, an embedding normalization layer, a modulus length adjustment layer and a processing layer; the method specifically includes the following steps:

[0116] Step 501: Obtain an input matrix corresponding to a word unit of text data, and input the input matrix into the large language model;

[0117] Step 502: an embedding layer performs a first mapping process on the input matrix to obtain a first embedding representation; the row vector in the first embedding representation represents a feature vector corresponding to a word in the input matrix;

[0118] Step 503: embedding normalization layer, performing modulus normalization on the row vectors in the first embedding representation to obtain a second embedding representation; the modulus normalization is used to normalize the modulus of different row vectors in the first embedding representation to the same preset value;

[0119] Step 504: a modulus length adjustment layer, performing modulus length adjustment on the second embedded representation to obtain a third embedded representation;

[0120] Step 505: a processing layer processes the third embedding representation to obtain text information of the large language model;

[0121] Step 506: Determine the loss information based on the above text information.

[0122] Figure 5 In the first embodiment of the method shown, during the training process of the large language model, the parameters of the large language model are updated. The parameters of the large language model may include: parameters corresponding to the network layers such as the embedding layer, the modulus adjustment layer, and the processing layer. Among them, the parameters corresponding to the embedding layer specifically include: an embedding weight matrix. The parameters of the modulus adjustment layer specifically include: a modulus weight vector.

[0123] The training process of a large language model may include: forward propagation and back propagation.

[0124] Among them, forward propagation can calculate the text information in sequence from the embedding layer to the processing layer according to the parameters of the large language model. Among them, the text information can be used to determine the loss information.

[0125] Backward Propagation can calculate and update the parameters of the large language model in sequence according to the loss information, in the order from the processing layer to the embedding layer. The large language model usually adopts the structure of a neural network, and the parameters of the large language model may include: parameters such as the weights of the neural network. Among them, during the back propagation process, the gradient information of the parameters of the large language model can be determined, and the parameters of the large language model can be updated using the gradient information. For example, back propagation can calculate and store the gradient information of the parameters of the large language model in sequence from the processing layer to the embedding layer according to the chain rule in calculus.

[0126] In step 501, the training of the large language model may include: pre-training or fine-tuning training. In the pre-training stage, a text data may include: N word units. N word units may correspond to one or more sentences. Among them, the pre-trained text data may be derived from one or more of the following preset corpora: books, online articles, text data on social media platforms, scientific and technological literature, dialogue data, dialogue texts contained in film and television dramas, and public data sets, etc.

[0127] In the fine-tuning training phase, a piece of text data specifically includes: an input sequence and a label value of an output sequence. Taking the intelligent dialogue task as an example, the input sequence can be a question in the dialogue, and the label value of the output sequence can be the answer to the dialogue.

[0128] In a specific implementation, a text data can be divided into tokens, and the input matrix corresponding to the tokens of the text data can be obtained. The size of the input matrix can be [b, s], where b represents the number of text data (number of items) contained in a batch, and s represents the sequence length of the input matrix, that is, the number of tokens contained in the input matrix.

[0129] In step 502, assuming that the size of the input matrix is ​​[b, s], the embedding layer can perform mapping processing on the input matrix, and the size of the first embedding representation obtained by the embedding layer can be [b, s, c], and the embedding layer can pass the first embedding representation to the embedding normalization layer.

[0130] The embedding layer corresponds to an embedding weight matrix. The above-mentioned process of using the embedding layer to perform the first mapping processing on the input matrix specifically includes: matching the word element identifiers in the input matrix with the indexes of the rows in the embedding weight matrix to obtain the first target row corresponding to the word element identifiers in the input matrix; and determining the embedding representation corresponding to the input matrix according to the first target row.

[0131] The size of the embedding weight matrix is ​​n rows and c columns, and each row in the n rows corresponds to an index, which can be a word element identifier. Therefore, by matching the word element identifier in the input matrix with the index of the row in the embedding weight matrix, the first target row corresponding to the word element identifier in the input matrix can be obtained. There can be s first target rows corresponding to s word element identifiers in the input matrix. Therefore, the size of the first embedding representation obtained by the embedding layer can be [b, s, c].

[0132] In step 503, the row vectors in the first embedded representation are modulo normalized to obtain a second embedded representation; the modulo normalization is used to normalize the modulos of different row vectors in the first embedded representation to the same preset value.

[0133] The modulus of a plane vector is the square root of the sum of the squares of the vector elements. In the embodiment of the present application, the feature vector of a word unit may be a plane vector.

[0134] In practical applications, a normalization technique may be used to normalize the modulus length of the row vectors in the first embedding representation. The normalization technique specifically includes: L1 norm normalization technique or L2 norm normalization technique.

[0135] Taking L2 norm normalization technology as an example, in Euclidean space, the L2 norm of a vector can refer to the square root of the sum of the squares of the vector elements. L2 norm normalization divides each element of the vector by its L2 norm, which can scale the modulus of the vector to unit length 1.

[0136] Magnitude normalization changes the magnitude of each row vector but does not change the size of the embedding representation, so the size of the second embedding representation is still [b, s, c].

[0137] In step 504, the modulus length adjustment layer performs modulus length adjustment on the second embedding representation. The modulus length adjustment can make the embodiment of the present application more conducive to the angle adjustment between the feature vectors of different word units, so that the angles between the feature vectors of different word units can be more fully trained; therefore, the embodiment of the present application can further improve the degree of training sufficiency and overall training effect of the parameters of the large language model.

[0138] Optionally, the process of the modulus adjustment layer performing modulus adjustment on the second embedded representation specifically includes: the modulus adjustment layer performs a second mapping process on the input matrix according to its corresponding modulus weight vector to obtain a modulus coefficient vector; according to the modulus coefficient vector, performs modulus adjustment on the second embedded representation to obtain a third embedded representation; an element in the modulus coefficient vector is used to perform modulus adjustment on a row vector in the second embedded representation.

[0139] The modulus weight vector of the embodiment of the present application may be a vector of n rows and 1 column. The embodiment of the present application uses the modulus weight vector corresponding to the modulus adjustment layer to perform a second mapping process on the input matrix, and the size of the obtained modulus coefficient vector may be s rows and 1 column.

[0140] The modulus weight vector can be a column vector. The modulus weight vector corresponding to the modulus adjustment layer is used to perform a second mapping process on the input matrix, including: matching the word element identifier in the input matrix with the index of the element in the modulus weight vector to obtain the first target element corresponding to the word element identifier in the input matrix; and determining the modulus coefficient vector corresponding to the input matrix based on the first target element.

[0141] In the embodiment of the present application, the modulus coefficient vector may be used to adjust the modulus of the second embedded representation, and the size of the obtained third embedded representation may be [b, s, c].

[0142] The process of adjusting the modulus length of the second embedded representation using the modulus length coefficient vector specifically includes: using an automatic broadcast mechanism to expand the modulus length coefficient vector into a modulus length coefficient matrix; the size of the modulus length coefficient matrix is ​​the same as the size of the second embedded representation; and performing a dot multiplication operation on the second embedded representation and the modulus length coefficient matrix to obtain a third embedded representation.

[0143] Automatic Broadcasting refers to the process of automatically expanding data to meet the calculation requirements when performing array operations.

[0144] The array operation corresponding to the modulus adjustment in the embodiment of the present application is specifically: the array operation corresponding to the second embedded representation and the modulus coefficient vector.

[0145] The b dimension of [b,s,c] is used as the depth dimension, so the second embedding representation can be viewed as a matrix with s rows and c columns. If you want to operate on a matrix with s rows and c columns and a modulus coefficient vector with s rows and 1 column, the training framework will automatically broadcast and copy the elements of each row in the modulus coefficient vector c times to obtain a modulus coefficient matrix with s rows and c columns.

[0146] The dot product operation is used to multiply matrices. Assume that matrices A and B are matrices of the same dimension size, that is, the number of rows of A = the number of rows of B, and the number of columns of A = the number of columns of B. During the operation, the elements of the corresponding positions of matrices AB are multiplied. If both AB are matrices with s rows and c columns, the result of their dot product is still a matrix with s rows and c columns. Therefore, the third embedded representation can be a matrix with s rows and c columns.

[0147] In step 505, the processing layer may include: Figure 3 The N transformer layers 304, standardization layer 305, linear transformation layer 306 and normalization layer 307 are shown. The processing layer can process the third embedding representation to obtain text information. The large language model can output the text information.

[0148] In the pre-training stage, the text information can be: the prediction information of the i-th word, where i can be a positive integer not greater than N. In the fine-tuning training stage, the text information can be the predicted value of the output sequence. Taking the intelligent dialogue task as an example, the text information can be the predicted value of the answer.

[0149] In step 506, loss information may be determined based on the training phase.

[0150] Wherein, in the pre-training stage, the text data includes: N word units; the text information represents: the prediction information of the i-th word unit; N and i are both positive integers; i is not greater than N;

[0151] The process of determining the loss information based on the above text information specifically includes: determining the first cross entropy loss information based on the conditional probability corresponding to the predicted information of the i-th word and the real information of the i-th word in the text data; the conditional probability is specifically: the probability of occurrence of the predicted information of the i-th word under the condition of the first i-1 words in the text data.

[0152] Formula (1) shows an example of a calculation process of the first cross entropy loss information.

[0153]

[0154] Among them, L1 represents the first cross entropy loss information, w i represents the i-th word in the text data, P(w i |w1,w2…,w i-1 ) represents the probability of occurrence of the prediction information of the ith word under the condition of the first i-1 words in the text data. Wherein, if the prediction information of the ith word is the same as the true information of the ith word in the text data, the conditional probability is 1; or, if the prediction information of the ith word is different from the true information of the ith word in the text data, the conditional probability is 0.

[0155] In the fine-tuning training stage, the text data includes: an input sequence, and a label value of an output sequence; the text information includes: a predicted value of the output sequence; then the process of determining the loss information based on the above text information specifically includes: determining the second cross entropy loss information or the mean square error loss information based on the predicted value and the label value.

[0156] Among them, the second cross entropy loss information can be determined according to the second conditional probability corresponding to the predicted value of the output sequence and the label value of the output sequence; the second conditional probability is specifically: the probability of occurrence of the predicted value under the condition of the input sequence.

[0157] Formula (2) shows an example of a calculation process of the second cross entropy loss information.

[0158]

[0159] Among them, L2 represents the second cross entropy loss information, x i Represents the i-th word in the text data, y j represents the predicted value corresponding to the jth text data, P(y j |x1,x2...,x s ) represents the probability of occurrence of the predicted value corresponding to the jth text data under the condition of the input sequence of the jth text data. Wherein, if the predicted value corresponding to the jth text data is the same as the label value corresponding to the jth text data, the second conditional probability is 1; or, if the predicted value corresponding to the jth text data is different from the label value corresponding to the jth text data, the second conditional probability is 0.

[0160] Formula (3) shows an example of a calculation process of mean square error loss information.

[0161]

[0162] Among them, L3 represents the mean square error loss information, R j Represents the i-th word in the text data, y j represents the predicted value corresponding to the jth text data, P(y j |x1,x2...,x s ) represents the label value corresponding to the j-th text data.

[0163] It can be understood that the aforementioned first cross entropy loss information, second cross entropy loss information, and mean square error loss information are only examples of loss information of the large language model in the embodiment of the present application, and are not to be understood as limitations on loss information in the embodiment of the present application. In fact, those skilled in the art can determine the required type of loss information based on the task characteristics, data characteristics, and design goals of the large language model, and the embodiment of the present application does not limit the specific type of loss information.

[0164] In the embodiment of the present application, the parameters of the network layer such as the modulus length weight vector can be updated according to the above-mentioned loss information, and the target parameter values ​​of the parameters such as the modulus length weight vector can be obtained.

[0165] The embodiment of the present application can characterize the mapping relationship between the loss information and the parameters of the large language model through the loss function shown in any one of formulas (1) to (3). In practical applications, the partial derivatives of the parameters of the large language model can be calculated, and the partial derivatives of the obtained parameters can be written in the form of vectors. The vector corresponding to the partial derivatives can be called the gradient information corresponding to the parameters. The update amount corresponding to the parameters can be obtained based on the gradient information and the step size information.

[0166] When the gradient descent method is adopted, batch gradient descent method, stochastic gradient descent method, or small batch gradient descent method can be adopted. In a specific implementation, iterative training can be performed according to multiple batches. The convergence condition of the above iteration can be: the loss information meets the preset condition. The preset condition can be: the absolute value of the difference between the loss information and the target value is less than the difference threshold, or the number of iterations exceeds the number threshold, etc. For example, the target value of the mean square error loss information shown in formula (3) is 0. In other words, when the loss information meets the preset condition, the iteration can be terminated; in this case, the target parameter value of the large language model can be obtained. In particular, the target parameter values ​​of parameters such as the modulus weight vector can be obtained to improve the degree of training adequacy of the word unit.

[0167] In summary, the model training method of the embodiment of the present application adds an embedding normalization layer after the embedding layer, and the embedding normalization layer is used to normalize the modulus length of the row vectors in the first embedding representation output by the embedding layer. The modulus length normalization can normalize the modulus lengths of different row vectors in the first embedding representation to the same preset value.

[0168] The row vector in the embedded representation is specifically a feature vector of a word unit, which can represent the word unit features. The embodiment of the present application normalizes the modulus lengths of different row vectors in the first embedded representation to the same preset value based on modulus length normalization, which can improve the balance between the importances corresponding to the word unit features represented by different row vectors. While improving the balance between the importances corresponding to the word unit features represented by different row vectors, the embodiment of the present application can improve the accuracy of the processing results of the large language model, and thus can improve the degree of training sufficiency and overall training effect of the parameters of the large language model.

[0169] After the row vectors in the first embedding representation are normalized, in order not to limit the expressive power of the row vectors, the modulus adjustment layer of the embodiment of the present application performs modulus adjustment on the second embedding representation. The modulus adjustment can make the embodiment of the present application more conducive to the angle adjustment between the feature vectors of different word units, so that the angles between the feature vectors of different word units can be more fully trained; therefore, the embodiment of the present application can further improve the degree of training sufficiency and overall training effect of the parameters of the large language model.

[0170] The embodiment of the present application can complete the convergence of the large language model while reducing the number of iterations and training time on the basis of improving the training sufficiency of the parameters of the large language model and the overall training effect. Since the number of iterations and training time can be reduced, the embodiment of the present application can reduce the amount of data transmission of the large language model during the training process, thereby improving the hardware processing speed corresponding to the large language model.

[0171] Method Example 2

[0172] refer to Figure 6 , shows a schematic flow chart of the steps of a text generation method according to an embodiment of the present application, the method is applied to a large language model, the large language model comprises: an embedding layer, an embedding normalization layer, a modulus length adjustment layer and a processing layer; the method specifically comprises the following steps:

[0173] Step 601: After completing the training of the large language model, use an embedding normalization layer to perform modulus normalization on the row vectors in the first embedding weight matrix of the embedding layer to obtain a second embedding weight matrix; the modulus normalization is used to normalize the modulus lengths of different row vectors in the first embedding weight matrix to the same preset value;

[0174] Step 602: Use the modulus length weight vector of the modulus length adjustment layer to perform modulus length adjustment on the second embedding weight matrix to obtain a third embedding weight matrix; an element of the modulus length weight vector is used to perform modulus length adjustment on a row vector of the second embedding weight matrix;

[0175] Step 603: Obtain an input matrix corresponding to the word element of the text to be processed;

[0176] Step 604: Mapping the input matrix using the third embedding weight matrix to obtain an embedding representation;

[0177] Step 605: Use the above processing layer to process the above embedded representation to obtain the target generated text output by the above large language model.

[0178] Figure 6 The second embodiment of the method shown is used to generate a target generated text corresponding to the text to be processed by using a large language model that has completed training. Figure 6 The second embodiment of the method shown can be applied to application scenarios such as summary generation, machine translation, literary creation, and intelligent dialogue. For example, in a summary generation scenario, the target generated text may be a summary text corresponding to the text to be processed. For another example, in a machine translation scenario, the target generated text may be a translation text corresponding to the text to be processed. In a literary creation scenario, such as a composition writing scenario, the target generated text may be a composition text corresponding to the text to be processed. Alternatively, in an intelligent dialogue scenario, the target generated text may be an answer text or a reply text corresponding to the text to be processed.

[0179] In step 601, the training of the large language model improves the training effect. For the large language model that has completed the training, the first embedding weight matrix corresponding to the embedding layer included therein is a matrix with n rows and c columns, wherein the rows correspond to word units.

[0180] The embodiment of the present application can utilize an embedding normalization layer to perform modulus normalization on the row vectors in the first embedding weight matrix of the embedding layer to obtain a second embedding weight matrix; the above-mentioned modulus normalization is used to normalize the modulus of different row vectors in the first embedding weight matrix to the same preset value, and an example of the preset value may be 1.

[0181] Among them, a normalization technique such as L2 norm normalization can be used to normalize the modulus length of the row vectors in the first embedding weight matrix of the embedding layer.

[0182] In step 602, for the large language model that has completed training, the modulus weight vector of the modulus adjustment layer contained therein is a vector with n rows and 1 column.

[0183] Before using the large language model for text generation, the modulus weight vector of the modulus adjustment layer can be used to adjust the modulus of the second embedding weight matrix. The obtained third embedding weight matrix can be used as Figure 1 The embedding weight matrix corresponding to the embedding layer of the large language model shown. The size of the third embedding weight matrix is ​​n rows and c columns.

[0184] The process of adjusting the modulus length of the second embedding weight matrix using the modulus length weight vector of the modulus length adjustment layer specifically includes: using an automatic broadcast mechanism to expand the modulus length weight vector into a modulus length weight matrix; the size of the modulus length weight matrix is ​​the same as the size of the second embedding weight matrix; and performing a dot multiplication operation on the second embedding weight matrix and the weight coefficient matrix to obtain a third embedding weight matrix.

[0185] In step 603, the text to be processed may be segmented into word units, and an input matrix corresponding to the word units of the text to be processed may be obtained.

[0186] In step 604, the third embedding weight matrix may be used to map the input matrix to obtain an embedding representation. Specifically, the word-unit identifiers in the input matrix may be matched with the indexes of the rows in the third embedding weight matrix to obtain the second target rows corresponding to the word-unit identifiers in the input matrix. There may be s second target rows corresponding to s word-unit identifiers in the input matrix.

[0187] Assuming the input matrix is ​​of size [b,s], then Figure 1 The embedding layer shown can map the input matrix, and the size of the obtained embedding representation can be [b, s, c].

[0188] In step 605, the processing layer may include: Figure 1 The N transformer layers 102, such as transformer layer 1 to transformer layer N, a standardization layer 103, a linear transformation layer 104, and a normalization layer 105 are shown. The processing layer can process the embedded representation to obtain a target generated text.

[0189] As mentioned above, the normalization layer 105 can normalize the probability distribution output by the linear transformation layer 104 to obtain a target probability value between [0,1]. The target probability value can be the probability of each word in the vocabulary becoming a target word. One inference of the large language model can obtain a target word. The target word can be a word with the largest target probability value in a single inference process, or the top X candidate words with the largest target probability values, where X can be a positive integer such as 3. During the text generation process, the large language model can perform multiple inferences until a word with a termination effect is encountered. The target words obtained by multiple inferences are combined to obtain the target generated text.

[0190] The target generated text may be one or more. For example, X candidate word-units obtained by multiple inferences may be combined, and one or more target generated texts may be selected from the combined results.

[0191] In practical applications, one or more target generated texts can be output. For example, in an intelligent dialogue scenario, the client can receive the text to be processed submitted by the user, and the server can receive the text to be processed sent by the client, and use the text generation method of the embodiment of the present application to determine one or more target generated texts, and return one or more target generated texts to the client, so that the client provides the user with a reply text or answer text of the intelligent dialogue.

[0192] In summary, the text generation method of the embodiment of the present application can improve the accuracy and other performance of the large language model because the training of the large language model improves the training effect of the large language model. Therefore, the embodiment of the present application can improve the accuracy of the target generated text.

[0193] It should be noted that, for the method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the described order of actions, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.

[0194] Based on the above embodiment, this embodiment also provides a model training device, which is used to train a large language model. Figure 7 The large language model specifically includes: an embedding layer, an embedding normalization layer, a modulus length adjustment layer and a processing layer; the device specifically includes: an acquisition module 701, a first mapping module 702, a modulus length normalization module 703, a modulus length adjustment module 704, an output determination module 705 and a loss determination module 706.

[0195] The acquisition module 701 is used to acquire an input matrix corresponding to a word unit of the text data, and input the input matrix into the large language model;

[0196] A first mapping module 702 is used to perform a first mapping process on the input matrix using an embedding layer to obtain a first embedding representation; the row vector in the first embedding representation represents a feature vector corresponding to a word in the input matrix;

[0197] A modulus normalization module 703, configured to use an embedding normalization layer to perform modulus normalization on the row vectors in the first embedded representation to obtain a second embedded representation; the modulus normalization is configured to normalize the moduli of different row vectors in the first embedded representation to the same preset value;

[0198] A module length adjustment module 704, configured to perform module length adjustment on the second embedded representation to obtain a third embedded representation;

[0199] An output determination module 705 is used to process the third embedding representation using the processing layer to obtain text information of the large language model;

[0200] The loss determination module 706 is used to determine the loss information according to the text information.

[0201] Optionally, the training specifically includes: pre-training, the text data includes: N word units; the text information represents: prediction information of the i-th word unit; N and i are both positive integers; i is not greater than N;

[0202] The loss determination module 706 specifically includes:

[0203] The first loss determination module is used to determine the first cross entropy loss information according to the conditional probability corresponding to the prediction information of the i-th word and the real information of the i-th word in the text data; the conditional probability is: the probability of occurrence of the prediction information of the i-th word under the condition of the first i-1 words in the text data.

[0204] Optionally, the training specifically includes: fine-tuning training, the text data includes: input sequence, and label values ​​of output sequence; the text information includes: predicted value of output sequence;

[0205] The loss determination module 706 specifically includes:

[0206] The second loss determination module is used to determine second cross entropy loss information or mean square error loss information according to the predicted value and the label value.

[0207] Optionally, the embedding layer corresponds to an embedding weight matrix, and the first mapping module 702 specifically includes:

[0208] A first matching module, used for matching the word-unit identifiers in the input matrix with the indexes of the rows in the embedding weight matrix to obtain a first target row corresponding to the word-unit identifiers in the input matrix;

[0209] A first determination module is used to determine the embedding representation corresponding to the input matrix according to the first target row.

[0210] Optionally, the mold length adjustment module 704 specifically includes:

[0211] A second mapping module, used for performing a second mapping process on the input matrix according to the modulus weight vector corresponding to the modulus adjustment layer to obtain a modulus coefficient vector;

[0212] An adjustment module is used to perform modulus adjustment on the second embedded representation according to the modulus coefficient vector to obtain a third embedded representation; an element in the modulus coefficient vector is used to perform modulus adjustment on a row vector in the second embedded representation.

[0213] Optionally, the modulus weight vector is a column vector, and the second mapping module 704 specifically includes:

[0214] A second matching module, used for matching the word unit identifier in the input matrix with the index of the element in the modulus weight vector to obtain a first target element corresponding to the word unit identifier in the input matrix;

[0215] The second determination module is used to determine the modulus coefficient vector corresponding to the input matrix according to the first target element.

[0216] Optionally, the adjustment module specifically includes:

[0217] An expansion module, configured to expand the modulus coefficient vector into a modulus coefficient matrix by using an automatic broadcast mechanism; the size of the modulus coefficient matrix is ​​the same as the size of the second embedded representation;

[0218] A dot product module is used to perform a dot product operation on the second embedding representation and the modulus coefficient matrix to obtain a third embedding representation.

[0219] Optionally, the device may further include:

[0220] A parameter updating module is used to update the parameters of the large language model according to the loss information.

[0221] In summary, the model training device of the embodiment of the present application adds an embedding normalization layer after the embedding layer, and the embedding normalization layer is used to normalize the modulus length of the row vectors in the first embedding representation output by the embedding layer. The modulus length normalization can normalize the modulus lengths of different row vectors in the first embedding representation to the same preset value.

[0222] The row vector in the embedded representation is specifically a feature vector of a word unit, which can represent the word unit features. The embodiment of the present application normalizes the modulus lengths of different row vectors in the first embedded representation to the same preset value based on modulus length normalization, which can improve the balance between the importances corresponding to the word unit features represented by different row vectors. While improving the balance between the importances corresponding to the word unit features represented by different row vectors, the embodiment of the present application can improve the accuracy of the processing results of the large language model, and thus can improve the degree of training sufficiency and overall training effect of the parameters of the large language model.

[0223] After the row vectors in the first embedding representation are normalized, in order not to limit the expressive power of the row vectors, the modulus adjustment layer of the embodiment of the present application performs modulus adjustment on the second embedding representation. The modulus adjustment can make the embodiment of the present application more conducive to the angle adjustment between the feature vectors of different word units, so that the angles between the feature vectors of different word units can be more fully trained; therefore, the embodiment of the present application can further improve the degree of training sufficiency and overall training effect of the parameters of the large language model.

[0224] The embodiment of the present application can complete the convergence of the large language model while reducing the number of iterations and training time on the basis of improving the training sufficiency of the parameters of the large language model and the overall training effect. Since the number of iterations and training time can be reduced, the embodiment of the present application can reduce the amount of data transmission of the large language model during the training process, thereby improving the hardware processing speed corresponding to the large language model.

[0225] Reference Figure 8 , shows a structural schematic diagram of a text generation device in an embodiment of the present application, the device is applied to a large language model, the large language model includes: an embedding layer, an embedding normalization layer, a modulus adjustment layer and a processing layer; the device specifically includes: a modulus normalization module 801, a modulus adjustment module 802, an acquisition module 803, a mapping module 804 and a text generation module 805.

[0226] Among them, the modulus normalization module 801 is used to use the embedding normalization layer to perform modulus normalization on the row vectors in the first embedding weight matrix of the embedding layer after completing the training of the large language model, so as to obtain a second embedding weight matrix; the modulus normalization is used to normalize the modulus lengths of different row vectors in the first embedding weight matrix to the same preset value;

[0227] A modulus length adjustment module 802 is used to use the modulus length weight vector of the modulus length adjustment layer to perform modulus length adjustment on the second embedding weight matrix to obtain a third embedding weight matrix; an element of the modulus length weight vector is used to perform modulus length adjustment on a row vector in the second embedding weight matrix;

[0228] An acquisition module 803 is used to acquire an input matrix corresponding to a word unit of the text to be processed;

[0229] A mapping module 804 is used to map the input matrix using the third embedding weight matrix to obtain an embedded representation;

[0230] The text generation module 805 is used to process the embedded representation using the processing layer to obtain the target generated text output by the large language model.

[0231] In summary, the text generation device of the embodiment of the present application can improve the accuracy and other performance of the large language model because the training of the large language model improves the training effect of the large language model. Therefore, the embodiment of the present application can improve the accuracy of the target generated text.

[0232] The embodiment of the present application also provides a non-volatile readable storage medium, which stores one or more modules (programs). When the one or more modules are applied to a device, the device can execute instructions (instructions) of each method step in the embodiment of the present application.

[0233] The present application embodiment provides one or more machine-readable media on which instructions are stored, and when executed by one or more processors, an electronic device executes one or more of the methods described in the above embodiments. In the present application embodiment, the electronic device includes various types of devices such as terminal devices and servers (clusters).

[0234] The embodiments of the present disclosure may be implemented as a device that uses any appropriate hardware, firmware, software, or any combination thereof to perform a desired configuration, and the device may include: electronic devices such as terminal devices and servers (clusters). Fig. 9 1 shows an exemplary device 1100 that can be used to implement various embodiments described in this application.

[0235] For one embodiment, Fig. 9 An exemplary apparatus 1100 is shown, which has one or more processors 1102, a control module (chip set) 1104 coupled to at least one of the (one or more) processors 1102, a memory 1106 coupled to the control module 1104, an NVM / storage device 1108 coupled to the control module 1104, one or more input / output devices 1110 coupled to the control module 1104, and a network interface 1112 coupled to the control module 1104. Among them, NVM (non-volatile memory) means that the information stored in the memory can still exist for a long time after the power is turned off and is not easily lost.

[0236] The processor 1102 may include one or more single-core or multi-core processors, and the processor 1102 may include any combination of general-purpose processors or special-purpose processors (such as graphics processors, application processors, baseband processors, etc.). In some embodiments, the device 1100 can be used as a terminal device, server (cluster), etc. described in the embodiments of the present application.

[0237] In some embodiments, the device 1100 may include one or more computer-readable media (e.g., memory 1106 or non-volatile memory / storage device 1108) having instructions 1114 and one or more processors 1102 configured to execute the instructions 1114 in combination with the one or more computer-readable media to implement a module to perform the actions described in the present disclosure.

[0238] For one embodiment, the control module 1104 may include any suitable interface controller to provide any suitable interface to at least one of the processor(s) 1102 and / or any suitable device or component in communication with the control module 1104 .

[0239] The control module 1104 may include a memory controller module to provide an interface to the memory 1106. The memory controller module may be a hardware module, a software module, and / or a firmware module.

[0240] The memory 1106 may be used, for example, to load and store data and / or instructions 1114 for the device 1100. For one embodiment, the memory 1106 may include any suitable volatile memory, such as a suitable DRAM (Dynamic Random Access Memory). In some embodiments, the memory 1106 may include a double data rate type four synchronous dynamic random access memory.

[0241] For one embodiment, the control module 1104 may include one or more input / output controllers to provide an interface to the non-volatile memory / storage device 1108 and the input / output device(s) 1110 .

[0242] For example, non-volatile memory / storage 1108 may be used to store data and / or instructions 1114. Non-volatile memory / storage 1108 may include any suitable non-volatile memory (e.g., flash memory) and / or may include any suitable non-volatile storage device(s) (e.g., one or more hard disk drives, one or more optical disk drives, and / or one or more digital versatile optical disk drives).

[0243] The non-volatile memory / storage device 1108 may include storage resources that are physically part of the device on which the apparatus 1100 is installed, or it may be accessible to the device without being part of the device. For example, the non-volatile memory / storage device 1108 may be accessed via (one or more) input / output devices 1110 over a network.

[0244] The input / output device(s) 1110 may provide an interface for the apparatus 1100 to communicate with any other appropriate device, and the input / output device 1110 may include a communication component, an audio component, a sensor component, etc. The network interface 1112 may provide an interface for the apparatus 1100 to communicate through one or more networks, and the apparatus 1100 may wirelessly communicate with one or more components of a wireless network according to any of one or more wireless network standards and / or protocols, for example, accessing a wireless network based on a communication standard, such as WiFi (Wireless Fidelity), 2G (2nd Generation Wireless Telephone Technology), 3G (3rd Generation Wireless Telephone Technology), 4G (4th Generation Wireless Telephone Technology), 5G (5th Generation Wireless Telephone Technology), etc., or a combination thereof for wireless communication.

[0245] For one embodiment, at least one of the processor(s) 1102 may be packaged together with the logic of one or more controllers (e.g., a memory controller module) of the control module 1104. For one embodiment, at least one of the processor(s) 1102 may be packaged together with the logic of one or more controllers of the control module 1104 to form a system-in-package. For one embodiment, at least one of the processor(s) 1102 may be integrated on the same die with the logic of one or more controllers of the control module 1104. For one embodiment, at least one of the processor(s) 1102 may be integrated on the same die with the logic of one or more controllers of the control module 1104 to form a system-on-chip.

[0246] In various embodiments, the device 1100 may be, but is not limited to, a terminal device such as a server, a desktop computing device, or a mobile computing device (e.g., a laptop computing device, a handheld computing device, a tablet computer, a netbook, etc.). In various embodiments, the device 1100 may have more or fewer components and / or different architectures. For example, in some embodiments, the device 1100 includes one or more cameras, a keyboard, a liquid crystal display screen (including a touch screen display), a non-volatile memory port, multiple antennas, a graphics chip, a dedicated integrated circuit, and a speaker.

[0247] Among them, the main control chip can be used as a processor or control module in the detection device, sensor data, location information, etc. are stored in a memory or non-volatile memory / storage device, the sensor group can be used as an input / output device, and the communication interface may include a network interface.

[0248] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0249] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0250] The present application embodiment is described with reference to the flowchart and / or block diagram of the method, terminal device (system) and computer program product according to the embodiment of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, and the combination of the process and / or box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device produce a device for implementing the function specified in one process or multiple processes in the flowchart and / or one box or multiple boxes in the block diagram.

[0251] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0252] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce computer-implemented processing, so that the instructions executed on the computer or other programmable terminal device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0253] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0254] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0255] The above is a detailed introduction to a model training method and device, a text generation method and device, an electronic device and a machine-readable medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A model training method, characterized in that: The method is used to train a large language model, wherein the large language model includes: an embedding layer, an embedding normalization layer, a modulus length adjustment layer, and a processing layer; the method includes: Obtaining an input matrix corresponding to a word unit of text data, and inputting the input matrix into the large language model; The embedding layer performs a first mapping process on the input matrix to obtain a first embedding representation; the row vector in the first embedding representation represents a feature vector corresponding to a word in the input matrix; The embedding normalization layer performs modulus normalization on the row vectors in the first embedding representation to obtain a second embedding representation; the modulus normalization is used to normalize the moduli of different row vectors in the first embedding representation to the same preset value; The modulus length adjustment layer performs modulus length adjustment on the second embedded representation to obtain a third embedded representation; The processing layer processes the third embedding representation to output text information of the large language model corresponding to the text data obtained this time; Loss information is determined based on the text information.

2. The method according to claim 1, characterized in that: The training includes: pre-training, the text data includes: N words; the text information represents: prediction information of the i-th word; N and i are both positive integers; i is not greater than N; The determining of loss information according to the text information includes: The first cross entropy loss information is determined according to the conditional probability corresponding to the prediction information of the i-th word and the real information of the i-th word in the text data; the conditional probability is: the probability of occurrence of the prediction information of the i-th word under the condition of the first i-1 words in the text data.

3. The method according to claim 1, characterized in that The training includes: fine-tuning training, the text data includes: input sequence, and label values ​​of output sequence; the text information includes: predicted value of output sequence; The determining of loss information according to the text information includes: According to the predicted value and the label value, second cross entropy loss information or mean square error loss information is determined.

4. The method according to claim 1, characterized in that: The embedding layer corresponds to an embedding weight matrix, and the embedding layer performs a first mapping process on the input matrix, including: Matching the word-unit identifiers in the input matrix with the indices of the rows in the embedding weight matrix to obtain a first target row corresponding to the word-unit identifiers in the input matrix; An embedding representation corresponding to the input matrix is ​​determined according to the first target row.

5. The method according to any one of claims 1 to 4, characterized in that: The modulus length adjustment layer performs modulus length adjustment on the second embedded representation, including: The modulus adjustment layer performs a second mapping process on the input matrix according to the modulus weight vector corresponding to the layer, so as to obtain a modulus coefficient vector; According to the modulus coefficient vector, the second embedded representation is modulo-adjusted to obtain a third embedded representation; an element in the modulus coefficient vector is used to modulo-adjust a row vector in the second embedded representation.

6. The method according to claim 5, characterized in that The modulus weight vector is a column vector, and the modulus adjustment layer performs a second mapping process on the input matrix according to the modulus weight vector corresponding to itself, including: Matching the word unit identifier in the input matrix with the index of the element in the modulus weight vector to obtain a first target element corresponding to the word unit identifier in the input matrix; According to the first target element, a modulus coefficient vector corresponding to the input matrix is ​​determined.

7. The method according to claim 5, characterized in that The step of adjusting the modulus length of the second embedded representation according to the modulus length coefficient vector comprises: The modulus coefficient vector is expanded into a modulus coefficient matrix by using an automatic broadcast mechanism; the size of the modulus coefficient matrix is ​​the same as the size of the second embedded representation; A dot product operation is performed on the second embedding representation and the modulus coefficient matrix to obtain a third embedding representation.

8. The method according to any one of claims 1 to 4, 6 or 7, characterized in that: The method further comprises: According to the loss information, parameters of the large language model are updated.

9. A text generation method, characterized in that: The method is applied to a large language model, the large language model comprising: an embedding layer, an embedding normalization layer, a modulus length adjustment layer and a processing layer; the method comprises: After completing the training of the large language model, using an embedding normalization layer, normalizing the modulus length of the row vectors in the first embedding weight matrix of the embedding layer to obtain a second embedding weight matrix; the modulus length normalization is used to normalize the modulus lengths of different row vectors in the first embedding weight matrix to the same preset value; Using the modulus weight vector of the modulus adjustment layer, modulus adjustment is performed on the second embedding weight matrix to obtain a third embedding weight matrix; an element of the modulus weight vector is used to modulus adjust a row vector in the second embedding weight matrix; Get the input matrix corresponding to the word unit of the text to be processed; Using the third embedding weight matrix, mapping the input matrix to obtain an embedding representation; The embedded representation is processed using the processing layer to obtain the target generated text output by the large language model.

10. A model training device, characterized in that: The device is used to train a large language model, wherein the large language model comprises: an embedding layer, an embedding normalization layer, a modulus length adjustment layer and a processing layer; the device comprises: An acquisition module, used for acquiring an input matrix corresponding to a word unit of text data, and inputting the input matrix into the large language model; A first mapping module is used to perform a first mapping process on the input matrix using an embedding layer to obtain a first embedding representation; the row vector in the first embedding representation represents a feature vector corresponding to a word in the input matrix; A modulus normalization module, configured to use an embedding normalization layer to perform modulus normalization on the row vectors in the first embedding representation to obtain a second embedding representation; the modulus normalization is configured to normalize the moduli of different row vectors in the first embedding representation to the same preset value; a modulus length adjustment module, configured to perform modulus length adjustment on the second embedded representation according to the modulus length adjustment layer to obtain a third embedded representation; an output determination module, configured to process the third embedding representation using the processing layer to obtain text information of the large language model; The loss determination module is used to determine the loss information according to the text information.

11. A text generation device, characterized in that: The device is applied to a large language model, the large language model comprising: an embedding layer, an embedding normalization layer, a modulus length adjustment layer and a processing layer; the device comprises: A modulus normalization module, used for performing modulus normalization on the row vectors in the first embedding weight matrix of the embedding layer by using the embedding normalization layer after completing the training of the large language model, so as to obtain a second embedding weight matrix; the modulus normalization is used for normalizing the modulus lengths of different row vectors in the first embedding weight matrix to the same preset value; A modulus length adjustment module, used to use the modulus length weight vector of the modulus length adjustment layer to perform modulus length adjustment on the second embedding weight matrix to obtain a third embedding weight matrix; an element of the modulus length weight vector is used to perform modulus length adjustment on a row vector in the second embedding weight matrix; An acquisition module is used to obtain an input matrix corresponding to a word unit of a text to be processed; A mapping module, configured to perform mapping processing on the input matrix using the third embedding weight matrix to obtain an embedding representation; A text generation module is used to process the embedded representation using the processing layer to obtain a target generated text output by the large language model.

12. An electronic device, characterized in that: include: processor; and A memory having executable codes stored thereon, which, when executed, causes the processor to execute the method according to any one of claims 1 to 9.

13. A machine-readable medium having executable codes stored thereon, which, when executed, causes a processor to execute the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Word embedding method, device and equipment for model to carry out financial field task processing

    CN116738983A

  • Model training method and device, electronic equipment and storage medium

    CN117786104A

  • Method, System, and Computer Program Product for Normalizing Embeddings for Cross-Embedding Alignment

    US20230214177A1

  • Data processing method and related device

    WO2023236977A1

Cited By

  • Text generation method, electronic device, storage medium and computer program product

    CN119127038A

  • Intermediate representation generation method and device based on domestic modeling language X language

    CN119536731A