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

CN118606447BActive Publication Date: 2026-10-30BEIJING CHUANGSI YUANDA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

较多的迭代次数和训练时间将会增加大语言模型在训练过程中的数据传输量,且会拖慢硬件处理速度

Benefits of technology

[0057]本申请实施例的技术方案中,在嵌入层后面添加嵌入归一化层,上述嵌入归一化层用于对嵌入层输出的第一嵌入表示中的行向量进行模长归一化。上述模长归一化可以将第一嵌入表示中不同行向量的模长归一化为相同的预设值。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606447B_ABST
    Figure CN118606447B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a model training method, a text generation method, an apparatus, a device and a medium, wherein the model training method comprises: obtaining an input matrix corresponding to a word piece of text data; performing first mapping processing on the input matrix by an embedding layer to obtain a first embedding representation; performing module length normalization on row vectors in the first embedding representation by an embedding normalization layer to normalize the module lengths of different row vectors in the first embedding representation; performing module length adjustment on the second embedding representation by a module length adjustment layer to obtain a third embedding representation; processing the third embedding representation by a processing layer to output text information of a large language model corresponding to the text data obtained this time; and determining loss information according to the text information. The embodiments of the present application can improve the training sufficiency and overall training effect of the parameters of the large language model, can reduce the data transmission amount of the large language model in the training process, and can improve the hardware processing speed corresponding to the large language model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates 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 Technology

[0002] As is well known, large language models are one of the feasible paths to general artificial intelligence. A large language model is a neural network-based natural language processing technique that can understand and generate human language, and can be used to handle text generation tasks such as summarization, machine translation, literary creation, and intelligent dialogue. A large language model typically includes an embedding layer and a processing layer. After tokens are input into the large language model, the embedding layer performs embedding processing on the tokens to obtain their corresponding embedding representations. The processing layer specifically includes a transformer layer, etc., used to determine the text information based on the embedding representations.

[0003] The training of a large language model specifically includes pre-training and fine-tuning. Pre-training is used to learn general language knowledge and representations; fine-tuning is used to refine the model for text generation tasks to adapt it to different downstream applications. These text generation tasks can include summarization, machine translation, literary creation, and intelligent dialogue.

[0004] Current large language models generally employ residual connections and pre-normalization. Residual connections directly add the embedding representations from the embedding layer to the outputs of one or more processing layers; pre-normalization performs normalization before the residual connections.

[0005] While the residual connections and pre-normalization methods described above can prevent gradient explosion or vanishing problems to some extent, directly inserting the embedded representations into the processing layer can easily affect the sufficiency of parameter training in large language models, thus impacting the overall training performance. Furthermore, related techniques require a significant number of iterations and training time to bring large language models to convergence. This increased iteration count and training time raises the amount of data transmission during training and slows down hardware processing speed. Summary of the Invention

[0006] This application provides a model training method that can improve the sufficiency of parameter training and the overall training effect of a large language model, reduce the amount of data transmission during the training process of the large language model, and thus improve the hardware processing speed of the large language model.

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

[0008] To address the aforementioned problems, this application discloses a model training method for training 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 method includes:

[0009] Obtain the input matrix corresponding to the word units of the text data, and input 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 vectors in the first embedding representation represent the feature vectors corresponding to the words in the input matrix.

[0011] The embedding normalization layer normalizes the magnitude of the row vectors in the first embedding representation to obtain the second embedding representation; the magnitude normalization is used to normalize the magnitudes of different row vectors in the first embedding representation to the same preset value.

[0012] The module length adjustment layer adjusts the module length of the second embedded representation to obtain the third embedded representation;

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

[0014] Based on the text information, the loss information is determined.

[0015] This application also discloses a text generation method applied to a large language model, the large language model comprising: an embedding layer, an embedding normalization layer, a modulus adjustment layer, and a processing layer; the method comprising:

[0016] After training the large language model, the embedding normalization layer is used to normalize the magnitude of the row vectors in the first embedding weight matrix to obtain the second embedding weight matrix. The magnitude normalization is used to normalize the magnitudes of different row vectors in the first embedding weight matrix to the same preset value.

[0017] The second embedding weight matrix is ​​adjusted using the magnitude weight vector of the magnitude adjustment layer to obtain the third embedding weight matrix; one element of the magnitude weight vector is used to adjust the magnitude of a row vector in the second embedding weight matrix.

[0018] Obtain the input matrix corresponding to the words in the text to be processed;

[0019] The input matrix is ​​mapped using the third embedding weight matrix to obtain the embedding representation;

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

[0021] This application also discloses a model training apparatus for training a large language model, the large language model including: an embedding layer, an embedding normalization layer, a module length adjustment layer, and a processing layer; the apparatus includes:

[0022] The acquisition module is used to acquire the input matrix corresponding to the word units of the text data and input the input matrix into the large language model;

[0023] The 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 vectors in the first embedding representation represent the feature vectors corresponding to the words in the input matrix.

[0024] The module for normalizing the modulus length is used to normalize the modulus length of the row vectors in the first embedded representation using the embedding normalization layer to obtain the second embedded representation; the modulus length normalization is used to normalize the modulus lengths of different row vectors in the first embedded representation to the same preset value.

[0025] A module for adjusting the module length of the second embedded representation to obtain a third embedded representation;

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

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

[0028] This application also discloses a text generation apparatus applied to a large language model, the large language model comprising: an embedding layer, an embedding normalization layer, a modulus adjustment layer, and a processing layer; the apparatus comprising:

[0029] The module for normalizing the magnitude is used to normalize the magnitude of the row vectors in the first embedding weight matrix of the embedding layer after the training of the large language model is completed, so as to obtain the second embedding weight matrix. The module for normalizing the magnitude of different row vectors in the first embedding weight matrix is ​​used to normalize the magnitude of the row vectors to the same preset value.

[0030] The module for adjusting the modulus length is used to adjust the modulus length of the second embedded weight matrix using the modulus length weight vector of the modulus length adjustment layer to obtain the third embedded weight matrix; one element of the modulus length weight vector is used to adjust the modulus length of a row vector in the second embedded weight matrix.

[0031] The acquisition module is used to acquire the input matrix corresponding to the words in the text to be processed;

[0032] The mapping module is used to map the input matrix using the third embedding weight matrix to obtain the embedding representation;

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

[0034] Optionally, the training specifically includes: pre-training, wherein 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;

[0035] The loss determination module specifically includes:

[0036] The first loss determination module is used to determine the first cross-entropy loss information based on the conditional probability corresponding to the predicted information of the i-th word and the actual information of the i-th word in the text data; the conditional probability is the probability of the predicted information of the i-th word appearing under the condition of the first i-1 words in the text data.

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

[0038] The loss determination module specifically includes:

[0039] The second loss determination module is used to determine the second cross-entropy loss information or mean squared error loss information based on 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] The first matching module is used to match the token identifiers in the input matrix with the indexes of rows in the embedded weight matrix to obtain the first target row corresponding to the token identifiers in the input matrix;

[0042] The first determining module is used to determine the embedding representation corresponding to the input matrix based on the first target row.

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

[0044] The second mapping module is used to perform a second mapping process on the input matrix according to the modulus weight vector corresponding to the modulus adjustment layer to obtain the modulus coefficient vector.

[0045] An adjustment module is used to adjust the modulus of the second embedded representation according to the modulus coefficient vector to obtain a third embedded representation; an element of the modulus coefficient vector is used to adjust the modulus of 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] The second matching module is used to match the token identifiers in the input matrix with the indices of the elements in the modulus weight vector to obtain the first target element corresponding to the token identifier in the input matrix.

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

[0049] Optionally, the adjustment module specifically includes:

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

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

[0052] Optionally, the device may further include:

[0053] The parameter update module is used to update the parameters of the large language model based on the loss information.

[0054] This application also discloses an electronic device, including: a processor; and a memory storing executable code thereon, which, when executed, causes the processor to perform the method described in this application.

[0055] This application also discloses a machine-readable medium storing executable code thereon, which, when executed, causes a processor to perform the method described in this application.

[0056] The embodiments of this application have the following advantages:

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

[0058] In the embedding representation, the row vectors are specifically feature vectors of lexical units, capable of representing lexical features. This embodiment of the application normalizes the magnitudes of different row vectors in the first embedding representation to the same preset value based on magnitude normalization, which can improve the balance between the importance of the lexical features represented by different row vectors. By improving the balance between the importance of the lexical features represented by different row vectors, this embodiment of the application can improve the accuracy of the processing results of the large language model, thereby improving the sufficiency of parameter training and the overall training effect of the large language model.

[0059] After normalizing the magnitude of the row vectors in the first embedding representation, in order not to limit the expressive power of the row vectors, the magnitude adjustment layer of this embodiment adjusts the magnitude of the second embedding representation. This magnitude adjustment makes this embodiment more conducive to adjusting the angles between feature vectors of different words, allowing for more thorough training of the angles between feature vectors of different words; therefore, this embodiment can further improve the sufficiency of parameter training and the overall training effect of the large language model.

[0060] This application embodiment improves the sufficiency of parameter training and overall training effect of large language models, and achieves convergence of large language models while reducing the number of iterations and training time. Because it reduces the number of iterations and training time, this application embodiment can reduce the amount of data transmitted during the training process of large language models, thereby improving the hardware processing speed corresponding to large language models. Attached Figure Description

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

[0062] Figure 2 This is a schematic diagram of the converter layer in a large language model according to an embodiment of this application;

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

[0064] Figure 4 This is a schematic diagram of the reparameterization of the embedding weight matrix according to an embodiment of this application;

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

[0066] Figure 6 This is a flowchart illustrating the steps of a text generation method according to an embodiment of this application;

[0067] Figure 7 This is a schematic diagram of the structure of a model training device according to an embodiment of this application;

[0068] Figure 8 This is a schematic diagram of the structure of a text generation apparatus according to an embodiment of this application;

[0069] Figure 9 This is a schematic diagram of the structure of an apparatus provided in one embodiment of this application. Detailed Implementation

[0070] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0071] The large language model in this application is an artificial intelligence model designed to understand and generate human language. Trained on large amounts of training data, the large language model can perform a wide range of tasks, including the text generation task described in this application. Large language models are typically based on deep learning architectures, such as transformer structures. This application does not limit the specific type of large language model; for example, the type of large language model may include GPT (Generative Pre-Trained Transformer) models and GLM (Generative Language Model), etc.

[0072] For example, the GPT model is a large-scale natural language generation model based on a Transformer architecture. It is pre-trained using massive amounts of training data (text data) and can generate high-quality natural language text, including articles, dialogues, and summaries. The core of the GPT model is its transformer structure, which employs an attention mechanism, enabling the GPT model to consider all positions in the input sequence simultaneously, thus better capturing long-distance dependencies. After pre-training, the GPT model can be fine-tuned to adapt to various downstream text generation tasks. During the pre-training phase, the GPT model uses an autoregressive language model training method, generating only one output at each time step, with subsequent time steps generating the next output based on the previous input and output.

[0073] The principle behind training autoregressive language models is as follows: given the preceding i words, predict the probability distribution of the (i+1)th word, where i can be a positive integer. In this way, large language models can generate semantically coherent text. During training, autoregressive language models use maximum likelihood estimation to learn the dependencies between words. Specifically, large language models update their parameters by maximizing the likelihood probability of the real text, thus making the generated new text more similar to the real text.

[0074] Text generation refers to the use of computer programs or algorithms to capture the syntax, semantics, structure, and style of text based on given input or contextual information, and then using this knowledge to generate new text content. This new text content possesses a reasonable grammatical structure, semantic accuracy, and contextual coherence, meeting the requirements of a specific task. The generated text can be a piece of 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 summarization, machine translation, literary creation, and intelligent dialogue.

[0075] The large language model in this application embodiment may include an embedding layer and a processing layer. The embedding layer is used to embed the input matrix corresponding to the lexical units of the input sequence to obtain an embedded representation. During the training phase, the input sequence may be text data used for training. During the inference phase (text generation phase), the input sequence may be the text to be processed.

[0076] Processing layers can include transformer layers. Large language models typically include multiple transformer layers. A transformer layer can employ a transformer architecture, specifically incorporating multi-head self-attention mechanisms and feedforward neural networks. Multiple transformer layers are used to perform multi-level representation learning on the embedding representations, thereby better capturing complex semantics and textual structures.

[0077] Other processing layers can be connected after the transformer layer. Examples of other processing layers may include: normalization layers, linear transformation layers, and normalization layers.

[0078] Reference Figure 1 The diagram shows a structural schematic of a large language model according to an embodiment of this application, specifically including: an embedding layer 101, N converter layers 102 (from converter layer 1 to converter layer N), a normalization 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 lexical units of the input sequence to obtain the embedding representation. The embedding representation is a semantic vector that can represent the semantic information of lexical units and can serve as the basis for large language models to understand the context, nuances, and subtle meanings of words and phrases.

[0080] N transformer layers 102 are used for multi-level representation learning of the embedded representations, thereby better capturing complex semantics and text structures. The output of 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, to some extent, overcome the gradient explosion problem caused by excessively large or small parameter values ​​in a large language model. The parameter values ​​of a large language model can refer to the numerical values ​​of the parameters corresponding to the network layers of the large language model. Embedding layer 101, N transformer layers 102 (from transformer layer 1 to transformer layer N), normalization layer 103, linear transformation layer 104, and 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 or new text. Specifically, the linear transformation layer 104 performs a linear transformation on the second output, mapping 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. The vocabulary is used to store words that a large language model can recognize.

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

[0084] A token can be the smallest indivisible semantic unit. For example, "waterfall" can be broken down into two tokens: water and fall. Additionally, punctuation marks are also broken down into tokens because they affect the semantic understanding of the entire text. For instance, "I don't know." can be broken down into five tokens: "I", "don", "'t", "know", and ".".

[0085] Current large language models generally employ residual connections and pre-normalization. (See reference...) Figure 2 The diagram illustrates the structure of a converter layer in a large language model according to an embodiment of this application. Specifically, the converter layer includes an attention processing module 201 and a multilayer perceptron module 202.

[0086] The attention processing module 201 performs attention processing on the input. In the case of converter layer 1, the input can be an embedded representation. Attention processing can include self-attention processing and cross-attention processing. Taking self-attention processing as an example, the attention processing module performs attention calculations between each position in the input sequence and other positions. Taking cross-attention processing as an example, the attention processing module performs attention calculations between each position in the input sequence and a position in the output sequence.

[0087] The multilayer perceptron module 202 is used to perform nonlinear transformations and mappings on the input to capture higher-level features.

[0088] Figure 2 In This indicates a residual connection. When the converter layer is converter layer 1, the residual connection directly adds the embedded representation of the embedding layer output to the output of converter layer 1. Pre-normalization can refer to normalization performed before the residual connection. Specifically, the attention processing module 201 normalizes its own input before performing attention processing. Figure 2 (Not shown in the image), the multilayer perceptron module 202 also normalizes its own input before performing the nonlinear transformation and mapping of the embedded representation. Figure 2 (Not shown in the image). The normalization in the attention processing module 201 and the normalization in the multilayer perceptron module 202 are examples of pre-normalization.

[0089] In practical applications, the aforementioned residual connections and pre-normalization methods can, to some extent, prevent gradient explosion or vanishing problems in the model. However, directly inserting the embedded representation into processing layers such as transformer layers can easily affect the training performance of large language models.

[0090] To address the technical problem that embedding representations directly entering processing layers such as the converter layer negatively impact the training performance of large language models, embodiments of this application provide a model training method. This method is used to train a large language model, which specifically includes: an embedding layer, an embedding normalization layer, a module length adjustment layer, and a processing layer; the method specifically includes:

[0091] Obtain the input matrix corresponding to the word units of the text data, and input 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 vectors in the first embedding representation represent the feature vectors corresponding to the words in the input matrix.

[0093] The embedding normalization layer normalizes the magnitude of the row vectors in the first embedding representation to obtain the second embedding representation; the magnitude normalization is used to normalize the magnitudes of different row vectors in the first embedding representation to the same preset value.

[0094] The module length adjustment layer adjusts the module length of the second embedded representation to obtain the third embedded representation;

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

[0096] Based on the text information, the loss information is determined.

[0097] In this embodiment, an embedding normalization layer is added after the embedding layer. This embedding normalization layer is used to normalize the magnitude of the row vectors in the first embedding representation output by the embedding layer. The magnitude normalization can normalize the magnitudes of different row vectors in the first embedding representation to the same preset value, such as 1.

[0098] In the embedding representation, the row vectors are specifically feature vectors of lexical units, representing lexical features. In traditional techniques, the magnitudes of the row vectors vary, leading to different lexical units having varying importance in model training. For example, row vectors with larger magnitudes have a greater advantage in attention processing, causing the corresponding lexical units to receive more attention; this can affect the accuracy of the attention processing results of large language models, and consequently, the training effect of the large language model. However, this embodiment of the application normalizes the magnitudes of different row vectors in the first embedding representation to the same preset value based on magnitude normalization, which can improve the balance between the importance of the lexical features represented by different row vectors. By improving the balance between the importance of the lexical features represented by different row vectors, this embodiment of the application can improve the accuracy of the processing results, thereby improving the training effect of large language models.

[0099] After normalizing the magnitude of the row vectors in the first embedded representation, in order not to limit the expressive power of the row vectors, the magnitude adjustment layer of this application embodiment adjusts the magnitude of the second embedded representation to obtain the third embedded representation.

[0100] Optionally, the modulus adjustment layer can adjust the modulus of the second embedding representation based on the modulus coefficient vector. Since one element in the modulus coefficient vector is used to adjust the modulus of a row vector in the second embedding representation, and one element in the modulus coefficient vector originates from a weight parameter in the modulus weight vector, during model training, a weight parameter is used to adjust the modulus information of a row vector (a feature vector of a word), which increases the difficulty of modulus adjustment. With the increased difficulty of modulus adjustment, the embodiments of this application are more conducive to the angle adjustment between feature vectors of different words, allowing for more thorough training of the angles between feature vectors of different words; therefore, the embodiments of this application can further improve the training effect of large language models.

[0101] This application's embodiments utilize reparameterization technology to... Figure 1 The structure of the large language model shown has been improved. The principle of reparameterization is as follows: first, a first set of structures (generally used for training) is constructed, and the parameters of the first set of structures are equivalently converted into another set of parameters (generally used for inference), thereby converting the first set of structures into the second set of structures.

[0102] Specifically, in the embodiments of this 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 inference stage of the large language model, for example, in the text generation method of the embodiments of this application.

[0103] Reference Figure 3 The diagram shows a structural schematic of a large language model according to an embodiment of this application, specifically including: an embedding layer 301, an embedding normalization layer 302, a modulus adjustment layer 303, N converter layers 304 from converter layer 1 to converter layer N, a normalization 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 the 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 embodiments of this application.

[0105] Figure 3 and Figure 1 The structural differences lie in the differences between the embedded layer 301, the embedded normalization layer 302, and the modulus adjustment layer 303 and the embedded layer 101. Figure 3 and Figure 1 The difference lies in the stage of use. Figure 3 It is applied during the training phase, while Figure 1 It is applied to the reasoning stage (i.e., the text generation stage).

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

[0107] In practical applications, assume 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 (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, which can have the size of n rows and c columns. In practical applications, n represents the size of the vocabulary, the number of lexical units it contains. Examples of n include 4096 or 10000. c represents the dimension of the embedding vector, that is, how many dimensions each lexical unit 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. Typically, c < 0. <n。

[0109] The embedding layer performs a first mapping process on the input matrix, resulting in a first embedding representation with dimensions [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 an s-row, c-column matrix, where b can be used as the depth dimension of the first embedding representation.

[0110] In this embodiment, an embedding normalization layer is used to normalize the magnitude of the row vectors in the first embedding representation. Magnitude normalization changes the magnitude of each row vector, but does not change the size of the embedding representation; therefore, the size of the second embedding representation remains [b, s, c].

[0111] The modulus weight vector in this embodiment can be an n-row, 1-column vector. This embodiment utilizes the modulus weight vector corresponding to the modulus adjustment layer to perform a second mapping process on the input matrix, resulting in a modulus coefficient vector with dimensions of s rows and 1 column.

[0112] In this embodiment of the application, the above-mentioned modulus coefficient vector is used to adjust the modulus of the second embedding representation, and the size of the third embedding representation can be [b, s, c].

[0113] refer to Figure 4This diagram illustrates a reparameterization of the embedding weight matrix according to an embodiment of this application. After training the large language model, the row vectors in the first embedding weight matrix of the embedding layer are first normalized using an embedding normalization layer to obtain a second embedding weight matrix. Then, the second embedding weight matrix is ​​adjusted using the magnitude weight vectors of the magnitude adjustment layer 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 is shown. It is used in the inference stage of the large language model to generate the target generated text.

[0114] Method Example 1

[0115] refer to Figure 5 The diagram illustrates a step-by-step flowchart of a model training method according to an embodiment of this application. This method is used to train a large language model, which specifically includes: an embedding layer, an embedding normalization layer, a modulus adjustment layer, and a processing layer. The method specifically includes the following steps:

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

[0117] Step 502, Embedding layer: Perform a first mapping process on the above input matrix to obtain a first embedding representation; the row vectors in the first embedding representation represent the feature vectors corresponding to the words in the input matrix.

[0118] Step 503: Embedding normalization layer, normalize the magnitude of the row vectors in the first embedding representation to obtain the second embedding representation; the magnitude normalization is used to normalize the magnitudes of different row vectors in the first embedding representation to the same preset value.

[0119] Step 504: Modulus adjustment layer, adjust the modulus of the second embedded representation to obtain the third embedded representation;

[0120] Step 505: Processing layer, the third embedding representation is processed to obtain the text information of the large language model.

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

[0122] Figure 5 The first embodiment of the method illustrates updating the parameters of the large language model during its training. The parameters of the large language model can include parameters corresponding to the embedding layer, the modulus adjustment layer, and the processing layer. Specifically, the parameters for the embedding layer include the embedding weight matrix. The parameters for the modulus adjustment layer specifically include the modulus weight vector.

[0123] The training process of a large language model can include forward propagation and backward propagation.

[0124] The forward propagation process calculates the final text information sequentially from the embedding layer to the processing layer, based on the parameters of the large language model. This text information is then used to determine the loss information.

[0125] Backpropagation, based on loss information, sequentially calculates and updates the parameters of a large language model, proceeding from the processing layer to the embedding layer. Large language models typically employ a neural network structure, and their parameters can include neural network weights and other parameters. During backpropagation, the gradient information of the large language model's parameters can be determined and used to update these parameters. For example, backpropagation can follow the chain rule in calculus, sequentially calculating and storing the gradient information of the large language model's parameters from the processing layer to the embedding layer.

[0126] In step 501, the training of the large language model may include pre-training or fine-tuning. During the pre-training phase, a single piece of text data may include N lexical units. These N lexical units can correspond to one or more sentences. The pre-training text data may originate from one or more of the following pre-defined corpora: books, online articles, text data from social media platforms, scientific literature, dialogue data, dialogue texts from films and television dramas, and public datasets, etc.

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

[0128] In a practical implementation, a piece of text data can be segmented 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 (sentences) 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 the size of the input matrix is ​​[b, s], the embedding layer can perform mapping processing on the input matrix. The size of the first embedding representation obtained by the embedding layer can be [b, s, c]. 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 process of performing the first mapping process on the input matrix using the embedding layer specifically includes: matching the token identifiers in the input matrix with the row indices in the embedding weight matrix to obtain the first target row corresponding to the token identifiers in the input matrix; and determining the embedding representation corresponding to the input matrix based on the first target row.

[0131] The embedding weight matrix has an n-row, c-column size, with each row having an index, which can be a token identifier. Therefore, by matching the token identifiers in the input matrix with the row indices in the embedding weight matrix, the first target row corresponding to the token identifiers in the input matrix can be obtained. s token identifiers in the input matrix can correspond to s first target rows. 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 embedding representation are normalized to obtain the second embedding representation; the normalization is used to normalize the magnitudes of different row vectors in the first embedding representation to the same preset value.

[0133] The magnitude of a planar vector is the square root of the sum of the squares of its elements. In the embodiments of this application, the feature vector of a word can be a planar vector.

[0134] In practical applications, normalization techniques can be used to normalize the magnitude of the row vectors in the first embedded representation. Specific normalization techniques include L1 norm normalization and L2 norm normalization.

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

[0136] Modulus 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 remains [b,s,c].

[0137] In step 504, the modulus adjustment layer adjusts the modulus of the second embedding representation. This modulus adjustment makes the angle adjustment between feature vectors of different lexical units more favorable in this embodiment, allowing for more thorough training of the angles between feature vectors of different lexical units. Therefore, this embodiment can further improve the sufficiency of parameter training and the overall training effect of the large language model.

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

[0139] The modulus weight vector in this embodiment can be an n-row, 1-column vector. This embodiment utilizes the modulus weight vector corresponding to the modulus adjustment layer to perform a second mapping process on the input matrix, resulting in a modulus coefficient vector with dimensions of s rows and 1 column.

[0140] The modulus weight vector is a column vector. The second mapping process of the input matrix using the modulus weight vector corresponding to the modulus adjustment layer includes: matching the word identifiers in the input matrix with the indices of the elements in the modulus weight vector to obtain the first target element corresponding to the word identifiers in the input matrix; and determining the modulus coefficient vector corresponding to the input matrix based on the first target element.

[0141] In this embodiment, the above-mentioned modulus coefficient vector can be used to adjust the modulus of the second embedding representation, and the size of the third embedding representation can be [b, s, c].

[0142] The process of adjusting the modulus of the second embedded representation using the modulus coefficient vector specifically includes: expanding the modulus coefficient vector into a modulus coefficient matrix using an automatic broadcasting mechanism; the size of the modulus coefficient matrix being the same as the size of the second embedded representation; and performing a dot product operation between the second embedded representation and the modulus coefficient matrix to obtain the third embedded representation.

[0143] Automatic broadcasting refers to the process of automatically expanding data to meet computational requirements during array operations.

[0144] The array operation corresponding to the modulus adjustment in this embodiment is specifically: the array operation corresponding to the second embedding representation and the modulus coefficient vector.

[0145] Taking the b dimension of [b,s,c] as the depth dimension, the second embedding representation can be viewed as an s x c matrix. To perform operations on the s x c matrix and the s x 1 column modulus coefficient vector, the training framework will automatically broadcast and copy the elements of each row of the modulus coefficient vector c times to obtain the s x c matrix.

[0146] The dot product operation is used for matrix multiplication. Assume matrices A and B are matrices of the same dimension, meaning the number of rows in A equals the number of rows in B, and the number of columns in A equals the number of columns in B. During the operation, corresponding elements of matrices A and B are multiplied. If both A and B are s x c matrices, their dot product will also result in an s x c matrix. Therefore, the third embedding can be an s x c matrix.

[0147] In step 505, the processing layer may include: Figure 3 The diagram shows N converter layers (304, 305, 306, and 307), including converter layer 1 to converter layer N. The processing layer can process the third embedding representation to obtain text information. The large language model can output the text information.

[0148] During the pre-training phase, the text information can be the predicted information of the i-th word, where i can be a positive integer not greater than N. During the fine-tuning training phase, the text information can be the predicted values ​​of the output sequence. Taking intelligent dialogue tasks as an example, the text information can be the predicted values ​​of the answers.

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

[0150] In the pre-training phase, 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 actual information of the i-th word in the text data; the conditional probability is specifically the probability of the predicted information of the i-th word appearing under the condition of the first i-1 words in the text data.

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

[0153]

[0154] Where L1 represents the first cross-entropy loss information, w i Let P(w) represent the i-th word in the text data. i |w1, w2, ..., w i-1 ) represents the probability of the predicted information of the i-th word given the first i-1 words in the text data. The conditional probability is 1 if the predicted information of the i-th word is the same as the actual information of the i-th word in the text data; or, the conditional probability is 0 if the predicted information of the i-th word is different from the actual information of the i-th word in the text data.

[0155] During the fine-tuning training phase, the text data includes: the input sequence and the label values ​​of the output sequence; the text information includes: the 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 squared error loss information based on the predicted value and the label value.

[0156] Specifically, the second cross-entropy loss information can be determined based on 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 the predicted value occurring under the condition of the input sequence.

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

[0158]

[0159] Where L2 represents the second cross-entropy loss information, x i Let y represent the i-th word in the text data. j Let P(y) represent the predicted value corresponding to the j-th text data. j |x1, x2, ..., x s Let represent the probability of the predicted value corresponding to the j-th text data given the input sequence of the j-th text data. Specifically, the second conditional probability is 1 if the predicted value corresponding to the j-th text data is the same as the label value corresponding to the j-th text data; or, the second conditional probability is 0 if the predicted value corresponding to the j-th text data is different from the label value corresponding to the j-th text data.

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

[0161]

[0162] Where L3 represents the mean squared error loss information, R j Let y represent the i-th word in the text data. j Let P(y) represent the predicted value corresponding to the j-th text data. j |x1, x2, ..., x s ) represents the tag value corresponding to the j-th text data.

[0163] It is understood that the aforementioned first cross-entropy loss information, second cross-entropy loss information, and mean squared error loss information are merely examples of loss information for the large language model in this application embodiment, and should not be construed as limitations on loss information in this application embodiment. In fact, those skilled in the art can determine the required types of loss information based on the task characteristics, data characteristics, and design goals of the large language model, and this application embodiment does not limit the specific types of loss information.

[0164] Based on the above-mentioned loss information, the parameters of the network layer, such as the magnitude weight vector, can be updated to obtain the target parameter values ​​of the magnitude weight vector and other parameters.

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

[0166] When using gradient descent, batch gradient descent, stochastic gradient descent, or mini-batch gradient descent can be employed. In specific implementations, iterative training can be performed based on multiple batches. The convergence condition for the above iteration can be: the loss information meets the preset conditions. The preset conditions 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 squared error loss information shown in formula (3) is 0. In other words, the iteration can end when the loss information meets the preset conditions; in this case, the target parameter values ​​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 training sufficiency of word units.

[0167] In summary, the model training method of this application adds an embedding normalization layer after the embedding layer. This embedding normalization layer is used to normalize the magnitude of the row vectors in the first embedding representation output by the embedding layer. This magnitude normalization can normalize the magnitudes of different row vectors in the first embedding representation to the same preset value.

[0168] In the embedding representation, the row vectors are specifically feature vectors of lexical units, capable of representing lexical features. This embodiment of the application normalizes the magnitudes of different row vectors in the first embedding representation to the same preset value based on magnitude normalization, which can improve the balance between the importance of the lexical features represented by different row vectors. By improving the balance between the importance of the lexical features represented by different row vectors, this embodiment of the application can improve the accuracy of the processing results of the large language model, thereby improving the sufficiency of parameter training and the overall training effect of the large language model.

[0169] After normalizing the magnitude of the row vectors in the first embedding representation, in order not to limit the expressive power of the row vectors, the magnitude adjustment layer of this embodiment adjusts the magnitude of the second embedding representation. This magnitude adjustment makes this embodiment more conducive to adjusting the angles between feature vectors of different words, allowing for more thorough training of the angles between feature vectors of different words; therefore, this embodiment can further improve the sufficiency of parameter training and the overall training effect of the large language model.

[0170] This application embodiment improves the sufficiency of parameter training and overall training effect of large language models, and achieves convergence of large language models while reducing the number of iterations and training time. Because it reduces the number of iterations and training time, this application embodiment can reduce the amount of data transmitted during the training process of large language models, thereby improving the hardware processing speed corresponding to large language models.

[0171] Method Example 2

[0172] refer to Figure 6 This diagram illustrates a step-by-step flowchart of a text generation method according to an embodiment of this application. The method is applied to a large language model, which includes an embedding layer, an embedding normalization layer, a modulus adjustment layer, and a processing layer. The method specifically includes the following steps:

[0173] Step 601: After completing the training of the large language model, the embedding normalization layer is used to normalize the magnitude of the row vectors in the first embedding weight matrix of the embedding layer to obtain the second embedding weight matrix; the above magnitude normalization is used to normalize the magnitude of different row vectors in the first embedding weight matrix to the same preset value.

[0174] Step 602: Using the modulus weight vector of the modulus adjustment layer, the modulus of the second embedding weight matrix is ​​adjusted to obtain the third embedding weight matrix; one element of the modulus weight vector is used to adjust the modulus of a row vector in the second embedding weight matrix.

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

[0176] Step 604: Using the third embedding weight matrix described above, the input matrix is ​​mapped to obtain the embedding representation;

[0177] Step 605: Using the above processing layer, 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 target generated text corresponding to the text to be processed by utilizing a large language model that has been trained. Figure 6 The illustrated method embodiment two can be applied to scenarios such as summary generation, machine translation, literary creation, and intelligent dialogue. For example, in a summary generation scenario, the target generated text can be the summary text corresponding to the text to be processed. Similarly, in a machine translation scenario, the target generated text can be the translated text corresponding to the text to be processed. In a literary creation scenario, such as essay writing, the target generated text can be the essay text corresponding to the text to be processed. Or, in an intelligent dialogue scenario, the target generated text can be the answer text or reply text corresponding to the text to be processed.

[0179] In step 601, training the large language model improves the training effect. For the large language model that has been trained, the first embedding weight matrix corresponding to its embedding layer is an n x c matrix, where the rows correspond to the lexical units.

[0180] In this embodiment, an embedding normalization layer can be used to normalize the magnitude of the row vectors in the first embedding weight matrix of the embedding layer to obtain a second embedding weight matrix. The magnitude normalization is used to normalize the magnitudes of different row vectors in the first embedding weight matrix to the same preset value, and an example of the preset value is 1.

[0181] Among them, normalization techniques such as L2 norm normalization can be used to normalize the magnitude 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 its modulus adjustment layer is an n-row, 1-column vector.

[0183] Before using a 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 mentioned above. The resulting third embedding weight matrix can then be used as... Figure 1 The embedding weight matrix corresponding to the embedding layer of the large language model is shown. The third embedding weight matrix has a size of n rows and c columns.

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

[0185] In step 603, the text to be processed can be segmented into tokens, and the input matrix corresponding to the tokens of the text to be processed can be obtained.

[0186] In step 604, the input matrix can be mapped using the aforementioned third embedding weight matrix to obtain an embedding representation. Specifically, the token identifiers in the input matrix can be matched with the row indices in the third embedding weight matrix to obtain the second target rows corresponding to the token identifiers in the input matrix. Each of the s token identifiers in the input matrix can correspond to one of the s second target rows.

[0187] Assuming the input matrix has dimensions [b, s], then Figure 1 The embedding layer shown can map the input matrix, and the resulting embedding representation can have a size of [b, s, c].

[0188] In step 605, the processing layer may include: Figure 1 The diagram shows N converter layers 102, 103, 104, and 105, including converter layer 1 to converter layer N. The processing layer can process the embedded representation to obtain the target generated text.

[0189] As mentioned earlier, the normalization layer 105 normalizes the probability distribution output by the linear transformation layer 104 to obtain target probability values ​​between [0,1]. The target probability value can be the probability that each word in the vocabulary becomes a target word. A single inference by the large language model yields a target word, which can be the word with the highest target probability value during the inference process, or one of the X largest candidate words with the highest target probability values, where X can be a positive integer such as 3. During text generation, the large language model can perform multiple inferences until it encounters a word that serves as a termination element. The target words obtained from these multiple inferences are then combined to obtain the target generated text.

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

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

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

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

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

[0195] The acquisition module 701 is used to acquire the input matrix corresponding to the word units of the text data and input the input matrix into the large language model.

[0196] The 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 vectors in the first embedding representation represent the feature vectors corresponding to the words in the input matrix.

[0197] The modulus normalization module 703 is used to normalize the modulus of the row vectors in the first embedded representation using the embedding normalization layer to obtain the second embedded representation; the modulus normalization is used to normalize the modulus of different row vectors in the first embedded representation to the same preset value.

[0198] The module length adjustment module 704 is used to adjust the module length of the second embedded representation to obtain the third embedded representation;

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

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

[0201] Optionally, the training specifically includes: pre-training, wherein 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;

[0202] The loss determination module 706 specifically includes:

[0203] The first loss determination module is used to determine the first cross-entropy loss information based on the conditional probability corresponding to the predicted information of the i-th word and the actual information of the i-th word in the text data; the conditional probability is the probability of the predicted information of the i-th word appearing under the condition of the first i-1 words in the text data.

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

[0205] The loss determination module 706 specifically includes:

[0206] The second loss determination module is used to determine the second cross-entropy loss information or mean squared error loss information based on 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] The first matching module is used to match the token identifiers in the input matrix with the indexes of rows in the embedded weight matrix to obtain the first target row corresponding to the token identifiers in the input matrix;

[0209] The first determining module is used to determine the embedding representation corresponding to the input matrix based on the first target row.

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

[0211] The second mapping module is used to perform a second mapping process on the input matrix according to the modulus weight vector corresponding to the modulus adjustment layer to obtain the modulus coefficient vector.

[0212] An adjustment module is used to adjust the modulus of the second embedded representation according to the modulus coefficient vector to obtain a third embedded representation; an element of the modulus coefficient vector is used to adjust the modulus of 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] The second matching module is used to match the token identifiers in the input matrix with the indices of the elements in the modulus weight vector to obtain the first target element corresponding to the token identifier in the input matrix.

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

[0216] Optionally, the adjustment module specifically includes:

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

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

[0219] Optionally, the device may further include:

[0220] The parameter update module is used to update the parameters of the large language model based on the loss information.

[0221] In summary, the model training apparatus of this application adds an embedding normalization layer after the embedding layer. This embedding normalization layer is used to normalize the magnitude of the row vectors in the first embedding representation output by the embedding layer. This magnitude normalization can normalize the magnitudes of different row vectors in the first embedding representation to the same preset value.

[0222] In the embedding representation, the row vectors are specifically feature vectors of lexical units, capable of representing lexical features. This embodiment of the application normalizes the magnitudes of different row vectors in the first embedding representation to the same preset value based on magnitude normalization, which can improve the balance between the importance of the lexical features represented by different row vectors. By improving the balance between the importance of the lexical features represented by different row vectors, this embodiment of the application can improve the accuracy of the processing results of the large language model, thereby improving the sufficiency of parameter training and the overall training effect of the large language model.

[0223] After normalizing the magnitude of the row vectors in the first embedding representation, in order not to limit the expressive power of the row vectors, the magnitude adjustment layer of this embodiment adjusts the magnitude of the second embedding representation. This magnitude adjustment makes this embodiment more conducive to adjusting the angles between feature vectors of different words, allowing for more thorough training of the angles between feature vectors of different words; therefore, this embodiment can further improve the sufficiency of parameter training and the overall training effect of the large language model.

[0224] This application embodiment improves the sufficiency of parameter training and overall training effect of large language models, and achieves convergence of large language models while reducing the number of iterations and training time. Because it reduces the number of iterations and training time, this application embodiment can reduce the amount of data transmitted during the training process of large language models, thereby improving the hardware processing speed corresponding to large language models.

[0225] Reference Figure 8 The diagram shows a structural schematic of a text generation device according to an embodiment of this application. The device is applied to a large language model, which includes an embedding layer, an embedding normalization layer, a module length adjustment layer, and a processing layer. Specifically, the device includes a module length normalization module 801, a module length adjustment module 802, an acquisition module 803, a mapping module 804, and a text generation module 805.

[0226] The module 801 is used to normalize the module length of the row vectors in the first embedding weight matrix of the embedding layer after the training of the large language model is completed, so as to obtain the second embedding weight matrix. The module length normalization is used to normalize the module lengths of different row vectors in the first embedding weight matrix to the same preset value.

[0227] The modulus adjustment module 802 is used to adjust the modulus of the second embedded weight matrix using the modulus weight vector of the modulus adjustment layer to obtain the third embedded weight matrix; one element of the modulus weight vector is used to adjust the modulus of a row vector in the second embedded weight matrix.

[0228] The acquisition module 803 is used to acquire the input matrix corresponding to the word units of the text to be processed;

[0229] The mapping module 804 is used to map the input matrix using the third embedding weight matrix to obtain an embedding 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 apparatus of this application improves the accuracy and other performance of the large language model by enhancing its training effect. Therefore, the text generation apparatus of this application can improve the accuracy of the target generated text.

[0232] This application also provides a non-volatile readable storage medium storing one or more modules (programs). When these modules are applied to a device, they enable the device to execute the instructions for the method steps in this application.

[0233] This application provides one or more machine-readable media storing instructions that, when executed by one or more processors, cause an electronic device to perform one or more of the methods described in the above embodiments. In this application, the electronic device includes various types of devices such as terminal devices and servers (clusters).

[0234] The embodiments of this disclosure can be implemented as an apparatus configured as desired using any suitable hardware, firmware, software, or any combination thereof, including electronic devices such as terminal devices and servers (clusters). Figure 9 An exemplary apparatus 1100 that can be used to implement the various embodiments described in this application is shown.

[0235] In one embodiment, Figure 9 An exemplary device 1100 is shown, which includes one or more processors 1102, a control module (chipset) 1104 coupled to at least one of the processors 1102, a memory 1106 coupled to the control module 1104, an NVM (non-volatile memory) / 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. Here, NVM refers to memory that stores information that can persist for a long time after the power is turned off, making it less prone to loss.

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

[0237] In some embodiments, apparatus 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 that are combined with the one or more computer-readable media and configured to execute the instructions 1114 to implement the module and thus perform the actions described in this disclosure.

[0238] In one embodiment, the control module 1104 may include any suitable interface controller to provide any suitable interface to at least one of the processors 1102 and / or any suitable device or component communicating 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] Memory 1106 may be used, for example, to load and store data and / or instructions 1114 for device 1100. In one embodiment, memory 1106 may include any suitable volatile memory, such as suitable DRAM (Dynamic Random Access Memory). In some embodiments, memory 1106 may include double data rate type quad synchronous dynamic random access memory.

[0241] In 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 (one or more) input / output devices 1110.

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

[0243] The non-volatile memory / storage device 1108 may include storage resources that are physically part of a device on which the device 1100 is mounted, or that are accessible by the device but do not necessarily have to be part of the device. For example, the non-volatile memory / storage device 1108 may be accessed via a network via one or more input / output devices 1110.

[0244] One or more input / output devices 1110 may provide an interface for device 1100 to communicate with any other suitable device. Input / output devices 1110 may include communication components, audio components, sensor components, etc. Network interface 1112 may provide an interface for device 1100 to communicate via one or more networks. Device 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, such as accessing wireless networks based on communication standards, such as WiFi (Wireless Fidelity), 2G (2-Generation wireless telephone technology), 3G (3-Generation wireless telephone technology), 4G (4-Generation wireless telephone technology), 5G (5-Generation wireless telephone technology), etc., or combinations thereof.

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

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

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

[0248] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.

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

[0250] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, create means for implementing the functions specified in one or more blocks of the flowchart illustrations and / or one or more blocks of the block diagrams.

[0251] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more blocks of a block diagram.

[0252] These computer program instructions may also be loaded onto a computer or other programmable data processing terminal equipment to cause a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable terminal equipment, provide steps for implementing the functions specified in one or more flowcharts and / or one or more blocks of a block diagram.

[0253] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.

[0254] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0255] The above provides a detailed description of a model training method and apparatus, a text generation method and apparatus, an electronic device, and a machine-readable medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A model training method, characterized in that, The method is used to train a large language model, which includes: an embedding layer, an embedding normalization layer, a module length adjustment layer, and a processing layer; the method includes: Obtain the input matrix corresponding to the word units of the text data, and input 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 vectors in the first embedding representation represent the feature vectors corresponding to the words in the input matrix. The embedding normalization layer normalizes the magnitude of the row vectors in the first embedding representation to obtain the second embedding representation; the magnitude normalization is used to normalize the magnitudes of different row vectors in the first embedding representation to the same preset value. The module length adjustment layer adjusts the module length of the second embedded representation to obtain the third embedded representation; The processing layer processes the third embedding representation to output the text information of the large language model corresponding to the text data obtained this time. Based on the text information, the loss information is determined.

2. The method according to claim 1, characterized in that, The training includes: pre-training; 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; The step of determining the loss information based on the text information includes: The first cross-entropy loss information is determined based on the conditional probability corresponding to the predicted information of the i-th word and the actual information of the i-th word in the text data; the conditional probability is the probability of the predicted information of the i-th word appearing 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, and the text data includes: the input sequence and the label values ​​of the output sequence; the text information includes: the predicted values ​​of the output sequence; The step of determining the loss information based on the text information includes: Based on the predicted value and the label value, determine the second cross-entropy loss information or the mean squared error loss information.

4. The method according to claim 1, characterized in that, The embedding layer corresponds to an embedding weight matrix. The embedding layer performs a first mapping process on the input matrix, including: The token identifiers in the input matrix are matched with the row indices in the embedding weight matrix to obtain the first target row corresponding to the token identifiers in the input matrix; Based on the first target row, determine the embedding representation corresponding to the input matrix.

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

6. The method according to claim 5, characterized in that, The modulus weight vector is a column vector. The modulus adjustment layer performs a second mapping process on the input matrix based on its corresponding modulus weight vector, including: The token identifiers in the input matrix are matched with the indices of elements in the modulus weight vector to obtain the first target element corresponding to the token identifier in the input matrix; Based on the first target element, determine the modulus coefficient vector corresponding to the input matrix.

7. The method according to claim 5, characterized in that, The step of adjusting the modulus of the second embedded representation based on the modulus coefficient vector includes: Using an automatic broadcasting mechanism, the modulus coefficient vector is expanded into a modulus coefficient matrix; the size of the modulus coefficient matrix is ​​the same as the size of the second embedded representation. The second embedding representation is multiplied by the modulus coefficient matrix to obtain the third embedding representation.

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

9. A text generation method, characterized in that, The method is applied to a large language model, which includes: an embedding layer, an embedding normalization layer, a module length adjustment layer, and a processing layer; the method includes: After training the large language model, the embedding normalization layer is used to normalize the magnitude of the row vectors in the first embedding weight matrix to obtain the second embedding weight matrix. The magnitude normalization is used to normalize the magnitudes of different row vectors in the first embedding weight matrix to the same preset value. The second embedding weight matrix is ​​adjusted using the magnitude weight vector of the magnitude adjustment layer to obtain the third embedding weight matrix; one element of the magnitude weight vector is used to adjust the magnitude of a row vector in the second embedding weight matrix. Obtain the input matrix corresponding to the words in the text to be processed; The input matrix is ​​mapped using the third embedding weight matrix to obtain the embedding representation; The processing layer is used to process the embedded representation to obtain the target generated text output by the large language model.

10. A model training device, characterized in that, The apparatus is used to train a large language model, the large language model comprising: an embedding layer, an embedding normalization layer, a module length adjustment layer, and a processing layer; the apparatus comprises: The acquisition module is used to acquire the input matrix corresponding to the word units of the text data and input the input matrix into the large language model; The 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 vectors in the first embedding representation represent the feature vectors corresponding to the words in the input matrix. The module for normalizing the modulus length is used to normalize the modulus length of the row vectors in the first embedded representation using the embedding normalization layer to obtain the second embedded representation; the modulus length normalization is used to normalize the modulus lengths of different row vectors in the first embedded representation to the same preset value. A mold length adjustment module is used to adjust the mold length of the second embedded representation according to the mold length adjustment layer to obtain a third embedded representation; The output determination module is used to process the third embedding representation using the processing layer to obtain the text information of the large language model; The loss determination module is used to determine loss information based on the text information.

11. A text generation device, characterized in that, The device is applied to a large language model, which includes: an embedding layer, an embedding normalization layer, a module length adjustment layer, and a processing layer; the device includes: The module for normalizing the magnitude is used to normalize the magnitude of the row vectors in the first embedding weight matrix of the embedding layer after the training of the large language model is completed, so as to obtain the second embedding weight matrix. The module for normalizing the magnitude of different row vectors in the first embedding weight matrix is ​​used to normalize the magnitude of the row vectors to the same preset value. The module for adjusting the modulus length is used to adjust the modulus length of the second embedded weight matrix using the modulus length weight vector of the modulus length adjustment layer to obtain the third embedded weight matrix; one element of the modulus length weight vector is used to adjust the modulus length of a row vector in the second embedded weight matrix. The acquisition module is used to acquire the input matrix corresponding to the words in the text to be processed; The mapping module is used to map the input matrix using the third embedding weight matrix to obtain the embedding representation; The text generation module is used to process the embedded representation using the processing layer to obtain the target generated text output by the large language model.

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

13. A machine-readable medium having executable code stored thereon, which, when executed, causes a processor to perform the method as described in any one of claims 1-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