A method for constructing a text generation model

By splitting and extracting the activation features of the feedforward neural network layer, the target text generation model is constructed, which solves the problem of low deployment efficiency of text generation models based on hybrid expert architecture, achieves rapid deployment and efficient training of text generation models, and improves text generation. Generate efficiency.

CN118551741BActive Publication Date: 2024-10-15ZHUO SHI ZHI XING (QINGTIAN) YUAN UNIVERSE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411031316.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-10-15
Estimated Expiration
2044-07-30

AI Technical Summary

Technical Problem

The deployment efficiency of text generation models based on hybrid expert architecture is low, resulting in low text generation efficiency.

Method used

By obtaining the activation characteristics of the feedforward neural network layer, splitting neurons into multiple target neuron groups, and extracting expert target model parameters from the model parameters, a target text generation model is constructed to improve the deployment efficiency of the model.

Benefits of technology

It achieves rapid deployment and efficient training of text generation models, improving text generation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118551741B_ABST
    Figure CN118551741B_ABST
Patent Text Reader

Abstract

The present invention provides a method for constructing a text generation model, and relates to the field of artificial intelligence technology. The method comprises: obtaining model parameters corresponding to each FFN layer in a specified text generation model; obtaining activation features of neurons in the FFN layer in a transformation process, namely, a common activation matrix, an activation number vector, and an activation number list; based on the common activation matrix and the activation number vector corresponding to the FFN layer, dividing the neurons in the FFN layer into a plurality of target neuron groups according to the number of splits; for a preset number of experts, extracting target model parameters corresponding to each expert from model parameters based on a plurality of target neuron groups; and constructing a target text generation model using all activation number lists and target model parameters. The present invention utilizes the prior knowledge in the specified text generation model to quickly and reasonably configure the parameters of the target text generation model, thereby realizing the rapid deployment of the target text generation model and improving the text generation efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method for constructing a text generation model. Background Art

[0002] A text generation model is a model that can generate response text that matches the user's input text. In order to better adapt to the complex and ever-changing text generation tasks, a text generation model based on the Mixture of Experts (MoE) architecture has emerged. The MoE architecture introduces multiple experts, each of whom can focus on processing different parts or features of the input text to improve the overall expressiveness and accuracy of the text generation model.

[0003] However, when the text generation model based on the MoE architecture is deployed in various text generation scenarios, the deployment efficiency of this type of text generation model is too low, resulting in low efficiency of the entire text generation. Summary of the invention

[0004] In view of the above problems, the purpose of the present invention is to provide a method for constructing a text generation model, which can improve the deployment efficiency of the text generation model and further improve the text generation efficiency.

[0005] In order to solve the above technical problems, the present invention provides the following technical solutions:

[0006] On the one hand, a method for constructing a text generation model is provided, comprising:

[0007] Obtaining model parameters corresponding to each feedforward neural network layer in a specified text generation model, wherein the model parameters are used to transform text features input to the feedforward neural network layer;

[0008] Obtain activation features of neurons in each of the feedforward neural network layers during the transformation process, wherein the activation features include a common activation matrix, an activation number vector, and an activation number list;

[0009] Based on the common activation matrix and the activation number vector corresponding to the feedforward neural network layer, the neurons in the feedforward neural network layer are divided into a plurality of target neuron groups according to the split number;

[0010] For a preset number of experts, based on the multiple target neuron groups, extracting target model parameters corresponding to each expert from the model parameters, wherein the preset number is related to the split number;

[0011] A target text generation model is constructed using all the activation quantity lists and target model parameters corresponding to all the experts, and the target text generation model is used to generate a response text corresponding to the input text.

[0012] On the other hand, a device for constructing a text generation model is also provided, comprising:

[0013] An acquisition module, used to acquire model parameters corresponding to each feedforward neural network layer in a specified text generation model, wherein the model parameters are used to transform text features input to the feedforward neural network layer;

[0014] An activation module, used for obtaining activation features of neurons in each of the feedforward neural network layers during the transformation process, wherein the activation features include a common activation matrix, an activation number vector, and an activation number list;

[0015] A division module, for dividing the neurons in the feedforward neural network layer into a plurality of target neuron groups according to the number of splits based on the common activation matrix and the activation number vector corresponding to the feedforward neural network layer;

[0016] An extraction module, for extracting target model parameters corresponding to each expert from the model parameters based on the multiple target neuron groups for a preset number of experts, wherein the preset number is related to the split number;

[0017] A construction module is used to construct a target text generation model using all the activation quantity lists and target model parameters corresponding to all the experts, wherein the target text generation model is used to generate a response text corresponding to the input text.

[0018] On the other hand, an electronic device is also provided, comprising a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps in any method for constructing a text generation model provided by the present invention.

[0019] On the other hand, a computer-readable storage medium is also provided, wherein the computer-readable storage medium stores a plurality of instructions, wherein the instructions are suitable for loading by a processor to execute the steps in any method for constructing a text generation model provided by the present invention.

[0020] On the other hand, a computer program product is also provided, comprising a computer program / instruction, wherein when the computer program / instruction is executed by a processor, the steps in any method for constructing a text generation model provided by the present invention are implemented.

[0021] The beneficial effects brought about by the technical solution provided by the present invention include at least:

[0022] In the embodiment of the present invention, the activation features of neurons in the FFN layer in the specified text generation model are obtained, and based on the activation times vector and the common activation matrix in the activation features, the neurons in the FFN layer are split and combined into multiple target neuron groups, and then the target model parameters of the expert are extracted from the model parameters of the FFN based on the target neuron groups, and finally the target text generation model is constructed based on the target model parameters and the activation number list of the expert. By using the prior knowledge in the specified text generation model, the parameters of the target text generation model can be quickly and reasonably configured, and the model convergence can be accelerated in the subsequent training of the model, thereby realizing the rapid deployment of the target text generation model and improving the text generation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0024] Figure 1 It is a flowchart of a method for constructing a text generation model provided by an embodiment of the present invention;

[0025] Figure 2 is a schematic diagram of obtaining a first neuron group provided by an embodiment of the present invention;

[0026] Figure 3 is a schematic diagram of obtaining a first intermediate matrix provided by an embodiment of the present invention;

[0027] Figure 4 is a schematic diagram of updating a first intermediate matrix provided by an embodiment of the present invention;

[0028] Figure 5 is a schematic diagram of obtaining a second neuron group provided by an embodiment of the present invention;

[0029] Figure 6 It is a structural schematic diagram of a device for constructing a text generation model provided by an embodiment of the present invention;

[0030] Figure 7 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0031] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0032] Mixture of Experts (MoE) is an advanced neural network architecture. The MoE architecture contains multiple experts. Only some experts are activated for calculation during calculation, which can effectively reduce the amount of calculation. In order to adapt to the complex and changeable text generation tasks, a text generation model can be established based on the MoE architecture.

[0033] Since there are multiple experts and gated networks in the MoE-based text generation model, the training process is complex and time-consuming, resulting in low deployment efficiency of the entire text generation model, and thus low efficiency of text generation. Therefore, the present invention proposes a method for constructing a text generation model, which can improve the deployment efficiency of the text generation model, and thus improve the efficiency of text generation.

[0034] In this embodiment, a method for constructing a text generation model is provided, such as Figure 1 As shown, the specific process of the model parameter initialization method can be as follows:

[0035] S110, obtaining model parameters corresponding to each feedforward neural network layer in the specified text generation model.

[0036] The specified text generation model is a pre-selected text generation model, which has densely connected neural network layers. The characteristics of these layers are that each neuron in the previous layer is connected to all neurons in the next layer, forming a dense connection matrix. A feedforward neural network (FFN) is an artificial neural network composed of multiple layers of neurons, in which the neurons in each layer are fully connected to the previous layer. The specified text generation model may include multiple FFN layers.

[0037] The activation function is a key part used to introduce nonlinearity in the neural network, enabling the network to learn complex models. The FFN layer mainly uses the following activation functions: ReLU, GELU, and Swish. Introducing the GLU concept, i.e., the gating mechanism, into the above activation functions can form corresponding activation function variants with gates, which can be recorded as ReGLU, GEGLU, and SwiGLU.

[0038] The present invention can support FFN using the above 6 debiased activation functions, and the corresponding formulas are as follows:

[0039]

[0040] Among them, d is the input hidden layer dimension of FFN, h is the activation layer dimension of FFN, x is the d-dimensional input vector of FFN, W1 and W2 are FFN training parameters, W1 is dimensional matrix, W2 is dimensional matrix, V is the GLU related training parameter, which is Dimensional matrix.

[0041] For the common type of FFN, that is, the FFN layer without the GLU idea, the corresponding model parameters may include input layer transformation parameters and hidden layer transformation parameters. Among them, the input layer transformation parameters can be used to linearly transform the text features of the input layer to the hidden layer for learning the feature representation of the input data; the hidden layer transformation parameters can be used to linearly transform the text features of the hidden layer to the output layer.

[0042] For the GLU type FFN, that is, the FFN layer that introduces the GLU idea, the corresponding model parameters include not only the input layer transformation parameters and the hidden layer transformation parameters, but also the gating parameters for implementing gating control. The model parameters of the FFN layer can be used to transform the text features input to the FFN layer to better understand and generate text.

[0043] S120, obtaining activation features of neurons in each of the feedforward neural network layers during the transformation process.

[0044] The sampled text data is input into the first text generation model, and the sampled text data passes through each FFN layer, so that the FFN layer can transform the text features using the model parameters and the corresponding activation function. The activation function of the FFN layer determines whether the neuron is activated. When the FFN layer transforms the text features, the activation features of the neurons in each FFN layer can be counted. The activation features can include a common activation matrix, an activation number vector, and an activation number list.

[0045] As an implementation method, in order to obtain the activation features corresponding to the FFN layer, the sampled text data can be input into the specified text generation model so that each FFN layer in the specified text generation model performs transformation processing on the text features. For each FFN layer, the activation results corresponding to the activation function of the FFN layer each time the transformation processing is performed are counted, that is, the calculation results of max(0,xW1) or GELU(xW1) or Swish1(xW1) in the aforementioned FFN formula expression are obtained to obtain an activation statistical vector. The activation statistical vector contains the activation values ​​corresponding to each neuron in the FFN layer. For example, the dimension of the FFN layer is h, and the activation statistical vector can be recorded as S=[s1,s2,s3,...,sh].

[0046] For each FFN layer, an initial common activation matrix, an initial activation times vector, and an initial activation number list can be pre-set. The initial common activation matrix can be a matrix with all elements 0. The initial activation count vector is an h-dimensional matrix whose element values ​​are all 0, and the initial activation count list is an empty list. By using multiple activation statistical vectors corresponding to the FFN layer, the initial common activation matrix, the initial activation count vector, and the initial activation count list are updated to obtain the activation features.

[0047] Optionally, in order to obtain the activation features corresponding to the FFN layer, for each activation statistical vector of the FFN layer, the index of the element value that is not 0 in the activation statistical vector is obtained to obtain an index set. It should be noted that the activation statistical vector contains the activation value of each neuron. Usually, when a neuron is in an activated state, its activation value is not 0, that is, the activation set contains the position information of the activated neuron in the FFN layer. For example, the index set is recorded as I=[i1, i2, i3...], then the element values ​​corresponding to i1, i2 and i3 in the statistical vector are not 0.

[0048] Combine any two different indices in the index set to obtain multiple combined indices. Add 1 to the element value at each combined index in the initial common activation matrix; add 1 to the element value at each index in the index set in the initial activation count vector; and add the number of elements in the index set to the initial activation count list.

[0049] For example, if the index set is I=[2,5,7,40], then the values ​​of the elements at positions (2,5), (5,2), (2,7), (7,2), (2,40), (40,2), (5,7), (7,5), (5,40), (40,5), (7,40), (40,7) in the initial common activation matrix are added by 1 to their original values, and the values ​​of the elements at positions 2, 5, 7, and 40 in the initial activation count vector are added by 1 to their original values. There are 4 elements in the index set, so the number of neuron activations 4 is added to the initial activation count list.

[0050] Based on the above process, it can be seen that the final common activation matrix records the activation frequencies of neurons activated simultaneously in FFN during the transformation process, the activation count vector records the number of times each neuron in FFN is activated, and the activation count list records the number of neurons activated in FFN each time the text feature is transformed.

[0051] After the above processing, for each FFN layer, the activation statistical vector corresponding to the FFN layer is traversed to obtain the common activation matrix, activation number vector and activation number list corresponding to the FFN layer.

[0052] S130. Based on the common activation matrix and activation number vector corresponding to the feedforward neural network layer, the neurons in the feedforward neural network layer are divided into a plurality of target neuron groups according to the number of splits.

[0053] The number of splits is a preset value, which can be set to an integer multiple of 4, such as 4, 8, etc. The number of splits determines how many experts each FFN layer can be split into. For example, if the number of splits is 4, each FFN layer can be split into 4 experts. At the same time, a combination number can also be set, which can be set to an integer multiple of 8, such as 8, 16, etc. The combination number is used to perform redundancy processing on the split results. If the number of splits is 4 and the number of combinations is 8, each FFN layer is decomposed into 4 experts, and then 8 times redundancy is performed, eventually forming 32 experts.

[0054] Among them, one FFN can be split into several target neuron groups, each target neuron group contains several candidate lists, and the candidate list contains the number of dimensions of neurons in the h dimension of the FFN layer. It should be noted that one candidate list can correspond to one expert, that is, the number of experts can be determined based on the number of splits and the number of combinations. If the number of splits is 4 and the number of combinations is 8, each FFN layer is decomposed into 4 experts, and then 8 times redundancy is performed, finally forming 32 experts, that is, 32 candidate lists are obtained.

[0055] The common activation matrix and activation number vector corresponding to the FFN layer can be used to group the neurons in the FFN according to the number of splits to obtain the corresponding target neuron group. In some embodiments, in order to improve the diversity of experts, two different methods can be used to achieve grouping. For example, it can be combined with the common activation matrix and the activation number vector corresponding to the feedforward neural network to generate a plurality of to-be-used matrices corresponding to the feedforward neural network; for each of the to-be-used matrices, the to-be-used matrix and the split number are used to perform a first grouping process on the neurons of the feedforward neural network layer to obtain a first neuron group; for each of the to-be-used matrices, the to-be-used matrix and the split number are used to perform a second grouping process on the neurons of the feedforward neural network layer to obtain a second neuron group; the first neuron group and the second neuron group are determined as a plurality of target neuron groups.

[0056] Each FFN layer has a corresponding common activation matrix and activation times vector. Using the common activation matrix and activation times vector, multiple matrices to be used corresponding to each FFN layer can be generated. In the embodiment of the present invention, each FFN layer corresponds to 4 matrices to be used, which can be recorded as the first matrix Ai1, the second matrix Ai2, the third matrix Ai3 and the fourth matrix Ai4. The calculation method corresponding to each matrix to be used will be described in detail below.

[0057] As an implementation method, the first matrix Ai1 can be obtained based on the common activation matrix. Each element value in the common activation matrix has a corresponding index, which can generally include a row index and a column index; the position in the common activation matrix where the row index is not equal to the column index is determined as the target position; the element value at the target position is added with a preset value to obtain the matrix Ai1 to be used. Among them, the preset value is an extremely small value, which can be set according to actual needs. In an embodiment of the present invention, the preset value can be 0.00000001.

[0058] In some implementations, based on the first matrix Ai1, a second matrix Ai2 may be calculated. Specifically, the second matrix Ai2 may be calculated based on the following formula:

[0059] ;

[0060] Among them, Ai1 represents the first matrix; Ai2 represents the second matrix; Bi is the activation number vector corresponding to the FFN layer.

[0061] In some embodiments, based on the first matrix Ai1, a third matrix Ai3 can be calculated. When calculating the third matrix Ai3, the weight ω1 and the vector Co can be pre-set, where the weight ω1 can be set to 1. The vector Co is an h-dimensional vector that traverses the rows of the first matrix Ai1. Co[m] is the number of elements in the mth row of the first matrix Ai1 that are greater than the minimum value 0.0000001 divided by (h-1) 2 , represents the cumulative co-excitation coefficient of each neuron and other neurons, which is equal to the value of the number of other co-activated neurons divided by the total number. Specifically, the third matrix Ai3 can be calculated according to the following formula:

[0062] .

[0063] In some implementations, based on the first matrix Ai1, a fourth matrix Ai4 may be calculated.

[0064] .

[0065] Then, for each matrix to be used, a first method may be used to perform grouping processing on the matrix to be used, so as to obtain a first grouping result.

[0066] Optionally, in order to obtain multiple first neuron groups corresponding to each FFN layer, the first index can be added to the first specified list, the first index is the index of the largest element value in the matrix to be used, and the first index includes a first row index j and a first column index k; replace the jth row and the jth column in the matrix to be used with the first target row, and set the kth row and the kth column in the matrix to be used to the first specified value to obtain a first intermediate matrix, the first target row is generated based on the element values ​​in the jth row and the kth row of the matrix to be used; use the second column index m to update the first specified list and the first intermediate matrix until the length of the first specified list is a preset length, and then obtain the second specified list and the second intermediate matrix, the second column index m is the index corresponding to the largest element value in the jth row of the first intermediate matrix, and the preset length is calculated based on the number of splits; if the element values ​​in the second intermediate matrix are not all the first specified values, use the second intermediate matrix as the matrix to be used, and return to execute the step of adding the first index to the first specified list and subsequent steps; if the element values ​​in the second intermediate matrix are all the first specified values, use all the second specified lists as the first neuron group.

[0067] See also Figure 2 , showing a schematic diagram of obtaining the first neuron group. For each matrix to be used, the index corresponding to the maximum element value can be obtained from the matrix to be used, and the index is the first index, wherein the first index may include a first row index j and a first column index k, and then j and k in the first index are added to the first specified list.

[0068] The first target row is generated by using the element values ​​in the jth row and the kth row in the matrix to be used. As an implementation method, the jth row and the kth row in the matrix to be used may be taken as the minimum values ​​in the direction of the row index transformation to form the first target row. For example, see Figure 3 , shows a schematic diagram of obtaining the first intermediate matrix, where, Figure 3 In the figure, the j-th row and the k-th row in the matrix to be used are both set to gray. For the two element values ​​j0 and k0, if j0 is greater than k0, the smaller element value k0 is used as the 0th element value in the first target row. If j1 is less than k1, the smaller element value j1 is used as the 1st element value in the first target row. And so on, the first target row can be obtained.

[0069] The first intermediate matrix can be obtained by replacing the jth row and jth column in the matrix to be used with the first target row and setting the kth row and kth column in the matrix to be used to the first specified value. In the embodiment of the present invention, the first specified value can be set to 0.

[0070] In the j-th row of the first intermediate matrix, the index corresponding to the largest element value in the j-th row can be determined to obtain the second column index m, and then the first specified list and the first intermediate matrix are updated using the second column index m until the length of the first specified list reaches a preset length, and the second specified list and the second intermediate matrix can be obtained.

[0071] The preset length refers to the number of neurons in each expert, which can also be called the expert dimension number. The expert dimension number can be obtained by dividing the dimension number h of the FFN layer by the number of splits.

[0072] As an embodiment, obtaining the second designated list and the second intermediate matrix may include the following steps: determining the second column index m from the first intermediate matrix, and adding the second column index m to the first designated list; generating a second target row based on the element values ​​in the j-th row and the k-th row of the first intermediate matrix; replacing the j-th row and the j-th column in the first intermediate matrix with the second target row, and setting the m-th row and the m-th column in the first intermediate matrix to the first designated value to obtain a new first intermediate matrix; if the length of the first designated list is less than the preset length, returning to execute the step of determining the second column index m from the first intermediate matrix and adding the second column index m to the first designated list and subsequent steps; if the length of the first designated list is equal to the preset length, using the first designated list as the second designated list, and setting the j-th row and the j-th column of the first intermediate matrix to the first designated value to obtain the second intermediate matrix.

[0073] After determining the second column index m from the first intermediate matrix, the second column index m can be added to the specified list. Then, the second target row is generated using the element values ​​of the jth row and the kth column of the first intermediate matrix, wherein the jth row and the kth row in the matrix to be used can be taken as the minimum values ​​in the direction of the row index transformation to form the second target row. The second target row is generated in a similar manner to the first target row, and the corresponding contents mentioned above can be referred to, which will not be repeated here. The second target row is then used to replace the jth row and the jth column in the first intermediate matrix, and the mth row and the mth column are set to the first specified value to obtain a new first intermediate matrix.

[0074] For example, see Figure 4 , shows a schematic diagram of updating the first intermediate matrix, where, taking m as 1 as an example, after generating the second target row, the jth column and the jth row are replaced by the second target row, and then the 1st column and the 1st row are set to 0 to obtain a new first intermediate matrix.

[0075] After obtaining the new first intermediate matrix, it can be determined whether the length of the first designated list is less than the preset length; if the length of the first designated list is less than the preset length, it indicates that indexes can continue to be added to the first designated list, and thus, the step of determining the second column index m from the first intermediate matrix and subsequent steps can be returned with the new first intermediate matrix. If the length of the first designated list is not less than the preset length, for example, the length of the first designated list is equal to the preset length, the jth row and the jth column in the new first intermediate matrix can be set to 0 to obtain the second intermediate matrix, and the first designated list can be used as the second designated list.

[0076] When the second intermediate matrix is ​​obtained, it can be determined whether the element values ​​in the second intermediate matrix are all the first specified values, that is, whether all the elements in the second intermediate matrix are 0. If the element values ​​in the second intermediate matrix are all the first specified values, it can be considered that the matrix to be used has been traversed, and all the second specified lists obtained in the process are used as the first neuron group. If there are element values ​​in the second intermediate matrix that are not the first specified values, the second intermediate matrix can be used as the matrix to be used, and the step of adding the first index to the first specified list and subsequent steps are returned to execute.

[0077] According to the above method, for each matrix to be used in each FFN layer, a first neuron group can be obtained, and the first neuron group contains a number of split second specified lists, and the second specified list contains the number of dimensions of the grouped neurons in the h dimension. Since there are 4 matrices to be used in one FFN layer, the first grouping process is performed on each matrix to be used, and 4 first neuron groups corresponding to each FFN layer can be obtained.

[0078] In some embodiments, when performing a second grouping process on the neurons of the FFN layer using the matrix to be used and the number of splits, a preset list set, a preset dictionary, and a copy matrix can be obtained, wherein the preset list set includes the number of preset lists of splits, and the copy matrix is ​​a matrix obtained by copying the matrix to be used; a first index is obtained, wherein the first index is the index of the largest element value in the matrix to be used, and the first index includes a first row index j and a first column index k; based on the inclusion relationship between the first row index j and the first column index k and the preset dictionary respectively, at least two of the preset list set, the preset dictionary, and the matrix to be used are updated to obtain an intermediate list set, an intermediate dictionary, and a third intermediate matrix; combining the element values ​​in the jth row and the kth row in the third intermediate matrix and the copy matrix, the third intermediate matrix is ​​updated to be a fourth intermediate matrix; using the length of the intermediate list corresponding to the first list index, the length of the intermediate dictionary, and the fourth intermediate matrix, a second neuron group is obtained, wherein the first list index is the index associated with the first row index j in the intermediate dictionary.

[0079] The preset list set is a preset set containing several preset lists, and the preset list may be an initially empty list. The preset dictionary is also preset and may be used to store key-value pairs with an associated relationship. In an embodiment of the present invention, it may be used to store the associated relationship between the index in the matrix to be used and the list index in the preset list set, wherein the preset dictionary is initially empty.

[0080] First, the matrix to be used can be copied to obtain a copy matrix for subsequent use. The index of the largest element value is found from the matrix to be used, which is recorded as the first index, and the first index includes the first row index j and the first column index k. Based on the inclusion relationship between the first row index j and the first column index k and the preset dictionary, the preset dictionary and the preset list can be updated to obtain an intermediate dictionary and an intermediate list set.

[0081] It should be noted that the inclusion relationship between the first row index j and the first column index k and the preset dictionary can be the following three situations: the first row index j and the first column index k are both in the preset dictionary, the first row index j and the first column index k are not in the preset dictionary, and the first row index j or the first column index k is in the preset dictionary. The following will explain each in detail, and you can also refer to Figure 5 , showing a schematic diagram of the process of obtaining the second neuron group.

[0082] In some embodiments, if the first row index j or the first column index k is in a preset dictionary, when updating at least two of the preset dictionary, the preset list set, and the matrix to be used, the index in the preset dictionary among the first indexes can be recorded as a first-category index, and the index not in the preset dictionary can be recorded as a second-category index; the first-category list index associated with the first-category index is obtained from the preset dictionary; the second-category index is added to the preset list corresponding to the first-category list index, and the second-category index and the first-category list index are associated and written into the preset dictionary to obtain an intermediate list set and an intermediate dictionary; and the matrix to be used is used as the third intermediate matrix.

[0083] The first row index j or the first column index k is in the preset dictionary. The index in the preset dictionary can be recorded as the first category index, and the index not in the preset dictionary can be recorded as the second category index. Since the first category index is in the preset dictionary, the index associated with the first category index can be obtained from the preset dictionary and recorded as the first category list index. The second category index is then added to the preset list corresponding to the first list index, and the second category index is associated with the first list index and written into the preset dictionary to obtain an intermediate list set and an intermediate dictionary. The preset list corresponding to the first list index refers to a list in the preset list set whose index is the first list index. In this case, it is not updated to the matrix to be used, and the matrix to be used can be directly used as the third intermediate matrix.

[0084] For example, Figure 5 In the preset dictionary, if only the first row index j is in the preset dictionary, the first row index j is the first-category index. The first-category list index associated with the first row index j is taken out from the preset dictionary and recorded as index-j. Then the first column index k is added to the preset list corresponding to the first-category list index index-j, and then {k: index-j} is written into the preset dictionary.

[0085] For another example, if only the first column index k is in the preset dictionary, the first column index k is a first-class index, and the index associated with the first column index k is taken out from the preset dictionary and recorded as index-k, and this index-k is the first-class list index. The first row index j is added to the preset list corresponding to the first-class list index index-k, and then {j: index-k} is written into the preset dictionary.

[0086] In some embodiments, if the first row index j and the first column index k are both in a preset dictionary, when updating at least two of the preset dictionary, the preset list set, and the matrix to be used, the first row list index associated with the first row index j and the first column list index associated with the first column index k can be obtained from the preset dictionary; the first preset list corresponding to the first row list index and the second preset list corresponding to the first column list index are determined from the preset list set; if the sum of the lengths of the first preset list and the second preset list is not greater than the preset length, the elements in the second preset list are moved to the first preset list, and the first column list index in the preset dictionary is modified to the first row list index to obtain an intermediate list set and an intermediate dictionary; if the sum of the lengths of the first preset list and the second preset list is greater than the preset length, the matrix to be used is updated based on the first row index j and the first column index k to obtain a third intermediate matrix, and the step of obtaining the first index and subsequent steps are returned with the third intermediate matrix.

[0087] If the first row index j and the first column index k are both in the preset dictionary, the first row index j and the first column index k can find the corresponding list index from the preset dictionary. For example, the index associated with the first row index j in the preset dictionary can be recorded as the first row list index, such as index1, and the index associated with the first column index k in the preset dictionary can be recorded as the first column list index, such as index2. Then, from the preset list set, determine the first preset list corresponding to the first row list index index1, such as L-index1, and the second preset list corresponding to the first column list index index2, such as L-index2.

[0088] Calculate the sum of the lengths of the first preset list and the second preset list, that is, count the sum of the number of elements in the first preset list and the number of elements in the second preset list. If the sum of the lengths is not greater than the preset length, move the elements in the second preset list L-index2 to the first preset list L-index1, and modify the first column list index index2 of the moved elements in the preset dictionary to the first row list index index1, thereby obtaining an intermediate list set and an intermediate dictionary.

[0089] If the sum of the lengths of the first preset list and the second preset list is greater than the preset length, the update position can be determined based on the first row index j and the first column index k. For example, the update position can be the position corresponding to the jth row and the kth column in the matrix to be used, and the position corresponding to the kth row and the jth column. Then, the elements at the update position in the matrix to be used are set to the second specified value to obtain a third intermediate matrix, and then the step of obtaining the first index and subsequent steps are returned to the third intermediate matrix.

[0090] If the first row index j and the first column index k are not in the preset dictionary, when updating the preset dictionary, the preset list set and the matrix to be used, if there is a target list in the preset list set, the first row index j and the first column index k are added to the target list to obtain an intermediate list set, and the target list is an empty preset list; the target list index corresponding to the target list in the intermediate list set is obtained; the first associated index and the second associated index are written into the preset dictionary to obtain an intermediate dictionary, the first associated index includes the first row index j and the target list index, and the second associated index includes the first column index k and the target list index; if there is no target list in the preset list set, the matrix to be used is updated to a third intermediate matrix based on the first row index j and the first column index k, and the step of obtaining the first index and subsequent steps are returned.

[0091] If the first row index j and the first column index k are not in the preset dictionary, it can be determined whether there is a target list in the preset list set, and the target list refers to an empty preset list. If there is still a target list in the preset list set, the first row index j and the first column index k are added to the target list to obtain an intermediate list set.

[0092] Get the target list index corresponding to the target list from the intermediate list set, associate the first row index j with the target list index to obtain the first associated index, and associate the first column index k with the target list index to obtain the second associated index. For example, if the target list index is index-n, the first associated index is {j: index-n}, and the second associated index is {k: index-n}. Then the first associated index and the second associated index can be written into the preset dictionary to obtain the intermediate dictionary.

[0093] If the target list does not exist in the preset list set, the update position can be determined based on the first row index j and the first column index k. For example, the update position can be the position corresponding to the jth row and the kth column in the matrix to be used, and the position corresponding to the kth row and the jth column. Then, the element at the update position in the matrix to be used is set to the second specified value, and then the step of obtaining the first index and the subsequent steps are returned with the updated matrix to be used, that is, the third intermediate matrix.

[0094] After the above steps, an intermediate dictionary, an intermediate list set and a third intermediate matrix can be obtained. The intermediate list set may include multiple intermediate lists, and the intermediate list is the list obtained after the preset list is updated.

[0095] The third intermediate matrix may be updated using the element values ​​in the j-th row and the k-th row of the to-be-used matrix and the copy matrix to obtain a fourth intermediate matrix.

[0096] In some embodiments, when the third intermediate matrix is ​​updated to obtain the fourth intermediate matrix using the element values ​​in the j-th row and the k-th row of the third intermediate matrix and the copy matrix, the element value in the j-th row may be compared with the element value in the k-th row for each column in the third intermediate matrix to obtain a candidate row; if the second specified value does not exist in the candidate row, the candidate row is determined as the third target row; if the second specified value exists in the candidate row, the third column index corresponding to the second specified value is obtained; from the intermediate dictionary, the first row list index associated with the first row index j is obtained; the third column index is used as the column index, and each element in the intermediate list corresponding to the first row list index in the intermediate list set is used as the row index to obtain multiple target indexes; in the copy matrix, the second specified value in the candidate row is replaced with the minimum element value corresponding to the target index to obtain the third target row; the j-th row and the j-th column in the third intermediate matrix are replaced with the third target row, and the k-th row and the k-th column in the third intermediate matrix are set to the first specified value to obtain the fourth intermediate matrix.

[0097] For each column in the third intermediate matrix, a candidate row is obtained by taking the smaller element value in the j-th row and the k-th row, and then determining whether the candidate row contains the second specified value. If the candidate row does not contain the second specified value, the candidate row can be directly used as the third target row.

[0098] If the second specified value exists in the candidate row, the column index corresponding to the second specified value is obtained as the third column index. From the intermediate dictionary, the first row list index associated with the first row index j is obtained, and based on the first row list index, the intermediate list corresponding to the first row list index can be obtained from the intermediate list set.

[0099] Then, the third column index is used as the column index, and each element in the intermediate list is used as the row index to form multiple target indexes. In the replica matrix, the element value corresponding to each target index is determined, and the second specified value in the candidate row is replaced with the smallest element value, thereby obtaining the third target row. Finally, the third target row is used to replace the jth row and jth column in the third intermediate matrix, and the element values ​​of the kth row and kth column are set to the first specified value, that is, 0, to obtain the fourth intermediate matrix.

[0100] The second neuron group can be obtained by using the length of the intermediate list, the length of the intermediate dictionary and the fourth intermediate matrix. Optionally, if the length of the intermediate list corresponding to the first row list index j is equal to the preset length, the jth row and the jth column of the fourth intermediate matrix can be set to the first specified value, that is, 0, to obtain the fifth intermediate matrix; if the length of the intermediate list is not equal to the preset length, the fourth intermediate matrix is ​​used to return to the step of obtaining the first index and subsequent steps.

[0101] After obtaining the fifth intermediate matrix, it is possible to continue to determine whether the length of the intermediate dictionary is less than the dimension number h of FFN; if the length of the intermediate dictionary is less than h, the fifth intermediate matrix can be used to return to execute the step of obtaining the first index and subsequent steps; if the length of the intermediate dictionary is not less than h, the intermediate list set can be used as the second neuron group. The intermediate list set includes splitting several intermediate lists, each of which has a preset length, and the elements in the intermediate list are the dimensions of the neuron in the h dimension of FFN.

[0102] For a matrix to be used, one first neuron group and one second neuron group can be obtained, which can be used as two target neuron groups corresponding to the matrix to be used. Since one FFN layer corresponds to four matrices to be used, each FFN layer can obtain eight target neuron groups.

[0103] Among them, the first neuron group contains several split second specified lists, and the second neuron group contains several split intermediate lists. For the convenience of subsequent description, the second specified list and the intermediate list are recorded as candidate lists here. Then each target neuron group contains several split candidate lists. The length of each candidate list is the same as the dimension of the FFN layer, which is a preset length. The elements in the list are the dimensions corresponding to the neurons in the h dimension of FFN.

[0104] It should be noted that if the number of combinations is n times 8, steps S120 and S130 will be executed n times, wherein the corresponding sampling data is different each time, and 8 target neuron groups will be obtained each time. After n times, the number of target neuron groups of the combination will be obtained.

[0105] S140. For a preset number of experts, based on the multiple target neuron groups, extract target model parameters corresponding to each expert from the model parameters.

[0106] The preset number refers to the number of experts, and the preset number can be obtained by multiplying the number of splits and the number of combinations. For example, when the number of splits is 4 and the number of combinations is 8, the preset number is 32.

[0107] As mentioned above, for each FFN layer, multiple target neuron groups are obtained. For a preset number of experts, the target neuron groups corresponding to the FFN layer can be used to extract the target model parameters corresponding to each expert from the model parameters of the FFN layer.

[0108] Optionally, multiple target neuron groups corresponding to each feedforward neural network layer may be obtained, each of the target neuron groups including multiple candidate lists; for each expert, an extraction list may be determined from the multiple candidate lists according to the expert index, the number of splits and the number of combinations corresponding to the expert; the element value in the extraction list may be used as a row extraction index, and the first specified row corresponding to the row extraction index may be extracted from the input layer transformation parameters as the target input layer transformation parameters of the expert; the element value in the extraction list may be used as a column extraction index, and the first specified column corresponding to the column extraction index may be extracted from the hidden layer transformation parameters as the target hidden layer transformation parameters of the expert.

[0109] Each FFN layer corresponds to multiple target neuron groups, which can be recorded as a group set, and each target neuron group has its corresponding group index in the group set. Each target neuron group contains several candidate lists, the length of each candidate list is a preset length, and the element value in the candidate list represents the number of dimensions of the neuron in the h dimension.

[0110] For each expert, the extraction list that the expert needs to use can be determined based on the expert index, split number, and combination number corresponding to the expert. Specifically, the quotient of the expert index divided by the split number and the remainder of the expert index divided by the split number can be calculated. For example, let the expert index be i, the split number be s, and the combination number be z, then , the target group index can be expressed as i / s, and the extraction list index can be expressed as i%s.

[0111] Thus, the target neuron group corresponding to the target group index can be selected, and the candidate list indicated by the extraction list index can be selected from the target neuron group as the extraction list. For example, when i is 0, the target group index is 0, and the extraction list index is 0. Then the 0th candidate list in the 0th target neuron group in the group set is used as the extraction list.

[0112] As mentioned above, the model parameters of the FFN layer may include input layer transformation parameters and hidden layer transformation parameters. When extracting the target model parameters using a list, they need to be extracted from the above model parameters respectively, which will be described in detail below.

[0113] For the input layer transformation parameters of the FFN layer, the element value in the extraction list can be used as the row extraction index, and the whole row parameter corresponding to the row extraction index is extracted from the input layer transformation parameters as the first specified row, and the first specified row is the target input layer transformation parameter of the expert. Among them, the extraction list contains a preset number of element values. If the preset number is e, the input layer transformation parameter is dimensional matrix, the target input layer transformation parameters are Dimensional matrix.

[0114] For the hidden layer transformation parameters of the FFN layer, the element value in the extraction list can be used as the column extraction index, and the column extraction index extracted from the hidden layer transformation parameters corresponds to the entire column parameter as the first specified column, and the first specified column is the target hidden layer transformation parameter of the expert. If the hidden layer transformation parameter is dimensional matrix, then the target hidden layer transformation parameters are Dimensional matrix.

[0115] For the GLU type FFN layer, in addition to the above-mentioned input layer transformation parameters and hidden layer transformation parameters, the FFN layer also includes a gating parameter, which can be used to implement gating control. For the gating parameter, the element value in the extraction list can be used as the row extraction index, and the entire row parameter corresponding to the row extraction index is taken from the gating parameter as the third specified row, and the third specified row is the expert's target gating parameter. If the preset number is e, the gating parameter is dimensional matrix, the target gating parameter is Dimensional matrix.

[0116] According to the above method, for each expert, the target model parameters can be extracted from the corresponding model parameters of each FFN layer, thereby constructing each expert in the MoE architecture.

[0117] S150: construct a target text generation model using all the activation quantity lists and the target model parameters corresponding to all the experts.

[0118] In the MoE architecture, when processing text, it is necessary to select some experts from multiple experts to participate in the processing process. The specific number of experts selected to participate in the processing is determined by the expert selection rate.

[0119] The expert selection rate can be calculated using the activation number list corresponding to all FFN layers. As an implementation method, the activation number list records the number of neurons activated in the FFN during each transformation process. The sum of all numbers in the activation number list and the number of elements in the activation number list can be obtained to obtain the activation mean number. The activation rate corresponding to the FFN layer can be obtained by dividing the activation mean number by the activation layer dimension of the FFN, and then the mean of the activation rates corresponding to all FFNs is calculated to obtain the average activation rate. Then select the power of 2 closest to the average activation rate as the expert selection rate. For example, the average activation rate is 20%, 1 / 2 to the power of 3 is 12.5%, and 1 / 2 to the power of 2 is 25%. The average activation rate of 20% is closer to 25%, so 25% is the expert selection rate. If the total number of experts is 32, 8 experts need to be selected from 32 experts.

[0120] In the above process, the target model parameters corresponding to each expert have been determined, and the expert selection rate, the number of expert dimensions, and the number of experts have been calculated. The target model parameters corresponding to each expert are combined with the random linear layer and the routing strategy to form the MoE layer. The settings such as the random linear layer and the routing strategy are then modified to the MoE configuration, and the shared parameters of the non-FFN layer are copied from the specified text generation model to the MoE. After saving, the model initialization is completed.

[0121] Specifically, you can use huggingface's transformers tool to load the specified text generation model that needs to be transformed, and modify the corresponding MoE configuration with the number of experts, expert dimension, expert selection rate, random linear layer, and softmaxtop-k routing determined in the above process to randomly initialize a MoE model. Then copy the shared parameters of the non-FFN layer from the specified text generation model to the key-value pairs corresponding to the MoE, and then use the target model parameters to assign the parameters of each expert in each layer in turn. Finally, save the model to the file system to complete the initialization and obtain a model to be trained.

[0122] Then, the model to be trained is trained using sample text data to obtain the target text generation model. Since the parameters of the experts in the model to be trained are obtained based on the specified text generation model, the parameters of the experts are set more reasonably at the beginning of training, which can save training time in subsequent training, ensure rapid convergence, shorten the time required to deploy the model, and thus realize the rapid deployment of the target text generation model.

[0123] The target text generation model can generate a response text corresponding to the input text based on the input text. For example, if the input text is "Please write a New Year's greeting", the response text is the New Year's greeting generated by the target text generation model. The embodiment of the present invention can accelerate the training process and realize the rapid deployment of the target text generation model. Then, when the model needs to be used to generate text, the time consumption of the deployment model can be reduced, thereby improving the efficiency of text generation.

[0124] Of course, the embodiments of the present invention can also be used in other scenarios. For example, in the field of image processing, the image processing model of the MoE architecture can be quickly deployed. For example, in the multimodal field, the multimodal processing model of the MoE architecture can be quickly deployed.

[0125] The method provided by the embodiment of the present invention can be used to group the neurons in the FFN layer in two ways based on the activation status of each neuron in the FFN layer in the specified text generation model to obtain a target neuron group, and then use the target neuron group to extract the target model parameters corresponding to each expert from the model parameters of the FFN layer, thereby ensuring the rationality of the parameters of the experts in the target text generation model, so that the parameter range that needs to be adjusted in the subsequent model training process is relatively small, which can effectively improve the model convergence speed to obtain the target text generation model, and then realize the rapid deployment of the target text generation model.

[0126] In order to better implement the above method, the embodiment of the present invention also provides a device for constructing a text generation model, which can be integrated in an electronic device, and the electronic device can be a terminal, a server, etc. Among them, the terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a notebook computer, a personal computer, a vehicle terminal, etc.; the server can be a single server or a server cluster composed of multiple servers.

[0127] For example, in this embodiment, the method of the embodiment of the present invention is described in detail by taking the construction device of the text generation model specifically integrated in the server as an example.

[0128] For example, Figure 6 As shown, the device 200 for constructing the text generation model may include an acquisition module 210 , an activation module 220 , a division module 230 , an extraction module 240 and a construction module 250 .

[0129] An acquisition module 210 is used to acquire model parameters corresponding to each feedforward neural network layer in a specified text generation model, wherein the model parameters are used to transform text features input to the feedforward neural network layer;

[0130] An activation module 220, for obtaining activation features of neurons in each of the feedforward neural network layers during the transformation process, wherein the activation features include a common activation matrix, an activation number vector, and an activation number list;

[0131] A division module 230, for dividing the neurons in the feedforward neural network layer into a plurality of target neuron groups according to the number of splits based on the common activation matrix and the activation number vector corresponding to the feedforward neural network layer;

[0132] An extraction module 240, configured to extract target model parameters corresponding to each expert from the model parameters for a preset number of experts based on the multiple target neuron groups, wherein the preset number is related to the split number;

[0133] The construction module 250 is used to construct a target text generation model using all the activation quantity lists and target model parameters corresponding to all the experts, wherein the target text generation model is used to generate a response text corresponding to the input text.

[0134] In some embodiments, the partitioning module 230 is specifically used to:

[0135] Combining the common activation matrix corresponding to the feedforward neural network and the activation number vector, generating a plurality of to-be-used matrices corresponding to the feedforward neural network;

[0136] For each of the matrixes to be used, performing a first grouping process on the neurons of the feedforward neural network layer by using the matrix to be used and the split number to obtain a first neuron group;

[0137] For each of the matrixes to be used, performing a second grouping process on the neurons of the feedforward neural network layer by using the matrix to be used and the split number to obtain a second neuron group;

[0138] The first neuron group and the second neuron group are determined as a plurality of target neuron groups.

[0139] In some embodiments, the partitioning module 230 is specifically used to:

[0140] Adding a first index to a first specified list, where the first index is an index of a maximum element value in the matrix to be used, and the first index includes a first row index j and a first column index k;

[0141] Replacing the j-th row and the j-th column in the matrix to be used with a first target row, and setting the k-th row and the k-th column in the matrix to be used to a first specified value, to obtain a first intermediate matrix, wherein the first target row is generated based on the element values ​​in the j-th row and the k-th row of the matrix to be used;

[0142] Using the second column index m to update the first designated list and the first intermediate matrix until the length of the first designated list reaches a preset length, thereby obtaining a second designated list and a second intermediate matrix, wherein the second column index m is an index corresponding to the maximum element value in the j-th row of the first intermediate matrix, and the preset length is calculated based on the number of splits;

[0143] If not all element values ​​in the second intermediate matrix are the first specified values, use the second intermediate matrix as the matrix to be used, and return to execute the step of adding the first index to the first specified list and subsequent steps;

[0144] If the element values ​​in the second intermediate matrix are all the first specified values, all the second specified lists are used as the first neuron group.

[0145] In some embodiments, the partitioning module 230 is specifically used to:

[0146] Determine a second column index m from the first intermediate matrix, and add the second column index m to the first specified list;

[0147] Generate a second target row based on element values ​​in the j-th row and the k-th row of the first intermediate matrix;

[0148] Replacing the j-th row and the j-th column in the first intermediate matrix with the second target row, and setting the m-th row and the m-th column in the first intermediate matrix to the first specified value, to obtain a new first intermediate matrix;

[0149] If the length of the first designated list is less than the preset length, returning to execute the step of determining the second column index m from the first intermediate matrix and adding the second column index m to the first designated list and subsequent steps;

[0150] If the length of the first designated list is equal to the preset length, the first designated list is used as the second designated list, and the j-th row and the j-th column of the first intermediate matrix are set to the first designated value to obtain a second intermediate matrix.

[0151] In some embodiments, the partitioning module 230 is specifically used to:

[0152] Acquire a preset list set, a preset dictionary, and a copy matrix, wherein the preset list set includes the split preset lists, and the copy matrix is ​​a matrix obtained by copying the matrix to be used;

[0153] Obtain a first index, where the first index is an index of a maximum element value in the matrix to be used, and the first index includes a first row index j and a first column index k;

[0154] Based on the inclusion relationship between the first row index j and the first column index k and the preset dictionary, at least two of the preset list set, the preset dictionary and the matrix to be used are updated to obtain an intermediate list set, an intermediate dictionary and a third intermediate matrix;

[0155] Combining the element values ​​in the j-th row and the k-th row in the third intermediate matrix and the copy matrix, updating the third intermediate matrix to a fourth intermediate matrix;

[0156] The second neuron group is obtained using the length of the intermediate list corresponding to the first list index, the length of the intermediate dictionary and the fourth intermediate matrix, wherein the first list index is the index associated with the first row index j in the intermediate dictionary.

[0157] In some embodiments, the inclusion relationship includes that the first row index j or the first column index k is in the preset dictionary, and the partitioning module 230 is specifically configured to:

[0158] Among the first indexes, the indexes in the preset dictionary are recorded as first-category indexes, and the indexes not in the preset dictionary are recorded as second-category indexes;

[0159] Obtaining a first-category list index associated with the first-category index from the preset dictionary;

[0160] Adding the second category index to the preset list corresponding to the first category list index, and associating the second category index with the first category list index into a preset dictionary to obtain an intermediate list set and an intermediate dictionary;

[0161] The matrix to be used is used as the third intermediate matrix.

[0162] In some embodiments, the inclusion relationship includes that the first row index j and the first column index k are both in the preset dictionary, and the partitioning module 230 is specifically configured to:

[0163] Obtain, from the preset dictionary, a first row list index associated with the first row index j and a first column list index associated with the first column index k;

[0164] Determine, from the preset list set, a first preset list corresponding to the first row list index, and a second preset list corresponding to the first column list index;

[0165] If the sum of the lengths of the first preset list and the second preset list is not greater than the preset length, move the elements in the second preset list to the first preset list, and modify the first column list index in the preset dictionary to the first row list index, so as to obtain an intermediate list set and an intermediate dictionary;

[0166] If the sum of the lengths of the first preset list and the second preset list is greater than the preset length, the matrix to be used is updated based on the first row index j and the first column index k to obtain a third intermediate matrix, and the step of obtaining the first index and subsequent steps are returned with the third intermediate matrix.

[0167] In some embodiments, the inclusion relationship includes that the first row index j and the first column index k are not in the preset dictionary, and the partitioning module 230 is specifically configured to:

[0168] If a target list exists in the preset list set, the first row index j and the first column index k are added to the target list to obtain an intermediate list set, where the target list is an empty preset list;

[0169] Obtain the target list index corresponding to the target list in the intermediate list set;

[0170] Writing a first associated index and a second associated index into a preset dictionary to obtain an intermediate dictionary, wherein the first associated index includes the first row index j and the target list index, and the second associated index includes the first column index k and the target list index;

[0171] If the target list does not exist in the preset list set, the matrix to be used is updated to a third intermediate matrix based on the first row index j and the first column index k, and the process returns to execute the step of obtaining the first index and subsequent steps.

[0172] In some embodiments, the partitioning module 230 is specifically used to:

[0173] For each column in the third intermediate matrix, compare the element value of the j-th row with the element value of the k-th row to obtain a candidate row;

[0174] If the second specified value does not exist in the candidate row, determining the candidate row as a third target row;

[0175] If the second specified value exists in the candidate row, obtain the third column index corresponding to the second specified value;

[0176] From the intermediate dictionary, obtain the first row list index associated with the first row index j;

[0177] Using the third column index as a column index and each element in the intermediate list corresponding to the first row list index in the intermediate list set as a row index, a plurality of target indexes are obtained;

[0178] In the replica matrix, replacing the second specified value in the candidate row with the minimum element value corresponding to the target index to obtain a third target row;

[0179] The j-th row and the j-th column in the third intermediate matrix are replaced with the third target row, and the k-th row and the k-th column in the third intermediate matrix are set to the first specified value, so as to obtain a fourth intermediate matrix.

[0180] In some embodiments, the model parameters include input layer transformation parameters and hidden layer transformation, and the extraction module 240 is specifically used to:

[0181] Acquire multiple target neuron groups corresponding to each feedforward neural network layer, each of the target neuron groups including multiple candidate lists;

[0182] For each expert, determining an extraction list from the multiple candidate lists according to the expert index, the number of splits, and the number of combinations corresponding to the expert;

[0183] Taking the element value in the extraction list as the row extraction index, extracting the first designated row corresponding to the row extraction index from the input layer transformation parameters as the target input layer transformation parameters of the expert;

[0184] The element value in the extraction list is used as the column extraction index, and the first designated column corresponding to the column extraction index is extracted from the hidden layer transformation parameters as the target hidden layer transformation parameter of the expert.

[0185] In specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation of the above modules can be found in the previous method embodiments, which will not be repeated here.

[0186] As can be seen from the above, the device for constructing the text generation model of this embodiment can obtain the activation features of neurons in the FFN layer in the specified text generation model, split and combine the neurons in the FFN layer into multiple target neuron groups based on the activation times vector and the common activation matrix in the activation features, and then extract the expert's target model parameters from the FFN model parameters based on the target neuron groups, and finally construct the target text generation model based on the expert's target model parameters and activation number list. By using the prior knowledge in the specified text generation model, the parameters of the target text generation model can be quickly and reasonably configured, and the model convergence can be accelerated in the subsequent training of the model, thereby realizing the rapid deployment of the target text generation model and improving the text generation efficiency.

[0187] The embodiment of the present invention further provides an electronic device, which may be a terminal, a server, or the like. The terminal may be a mobile phone, a tablet computer, a smart Bluetooth device, a notebook computer, a personal computer, or the like; the server may be a single server or a server cluster composed of multiple servers, or the like.

[0188] In some embodiments, the device for constructing the text generation model may also be integrated into multiple electronic devices. For example, the device for constructing the text generation model may be integrated into multiple servers, and the method for constructing the text generation model of the present invention may be implemented by multiple servers.

[0189] In this embodiment, the electronic device of this embodiment is a server as an example for detailed description, for example, Figure 7 As shown, it shows a schematic diagram of the structure of an electronic device involved in an embodiment of the present invention, specifically:

[0190] The electronic device may include components such as a processor 310 with one or more processing cores, a memory 320 with one or more computer-readable storage media, a power supply 330, an input module 340, and a communication module 350. Those skilled in the art will appreciate that Figure 7 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0191] The processor 310 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. It executes various functions of the electronic device and processes data by running or executing software programs and / or modules stored in the memory 320, and calling data stored in the memory 320. In some embodiments, the processor 310 may include one or more processing cores; in some embodiments, the processor 310 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 310.

[0192] The memory 320 can be used to store software programs and modules. The processor 310 executes various functional applications and data processing by running the software programs and modules stored in the memory 320. The memory 320 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 320 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 320 may also include a memory controller to provide the processor 310 with access to the memory 320.

[0193] The electronic device also includes a power supply 330 for supplying power to various components. In some embodiments, the power supply 330 can be logically connected to the processor 310 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 330 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.

[0194] The electronic device may further include an input module 340, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.

[0195] The electronic device may further include a communication module 350. In some embodiments, the communication module 350 may include a wireless module. The electronic device may perform short-range wireless transmission through the wireless module of the communication module 350, thereby providing the user with wireless broadband Internet access. For example, the communication module 350 may be used to help the user send and receive , browse the web, access streaming media, etc.

[0196] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 310 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 320 according to the following instructions, and the processor 310 will run the application programs stored in the memory 320, thereby implementing the steps in the methods of the embodiments of the present invention.

[0197] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0198] As can be seen from the above, the electronic device provided by the embodiment of the present invention can obtain the activation features of neurons in the FFN layer in the specified text generation model, and based on the activation times vector and the common activation matrix in the activation features, the neurons in the FFN layer are split and combined into multiple target neuron groups, and then based on the target neuron groups, the expert's target model parameters are extracted from the FFN model parameters, and finally, based on the expert's target model parameters and activation number list, the target text generation model is constructed. By using the prior knowledge in the specified text generation model, the parameters of the target text generation model can be quickly and reasonably configured, and the model convergence can be accelerated in the subsequent training of the model, thereby realizing the rapid deployment of the target text generation model and improving the text generation efficiency.

[0199] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0200] To this end, an embodiment of the present invention provides a computer-readable storage medium, in which a plurality of instructions are stored. The instructions can be loaded by a processor to execute the steps in any method for constructing a text generation model provided in an embodiment of the present invention.

[0201] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0202] According to one aspect of the present invention, a computer program product or computer program is provided, the computer program product or computer program comprising a computer program / instruction, the computer program / instruction being stored in a computer-readable storage medium. A processor of an electronic device reads the computer program / instruction from the computer-readable storage medium, and the processor executes the computer program / instruction, so that the electronic device executes the method provided in various optional implementations of the model parameter initialization provided in the above-mentioned embodiments.

[0203] Since the instructions stored in the storage medium can execute the steps in any method for constructing a text generation model provided in the embodiments of the present invention, the beneficial effects that can be achieved by any method for constructing a text generation model provided in the embodiments of the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0204] The above is a detailed introduction to a method for constructing a text generation model provided by an embodiment of the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A method for constructing a text generation model, characterized in that: The method comprises: Obtaining model parameters corresponding to each feedforward neural network layer in a specified text generation model, wherein the model parameters are used to transform text features input to the feedforward neural network layer; Obtain activation features of neurons in each of the feedforward neural network layers during the transformation process, wherein the activation features include a common activation matrix, an activation number vector, and an activation number list; Based on the common activation matrix and the activation number vector corresponding to the feedforward neural network layer, the neurons in the feedforward neural network layer are divided into a plurality of target neuron groups according to the split number; For a preset number of experts, based on the multiple target neuron groups, extracting target model parameters corresponding to each expert from the model parameters, wherein the preset number is related to the split number; A target text generation model is constructed using all the activation quantity lists and target model parameters corresponding to all the experts, and the target text generation model is used to generate a response text corresponding to the input text.

2. The method according to claim 1, characterized in that The method of dividing the neurons in the feedforward neural network layer into a plurality of target neuron groups according to the number of splits based on the common activation matrix and the activation number vector corresponding to the feedforward neural network layer includes: Combining the common activation matrix corresponding to the feedforward neural network and the activation number vector, generating a plurality of to-be-used matrices corresponding to the feedforward neural network; For each of the matrixes to be used, performing a first grouping process on the neurons of the feedforward neural network layer by using the matrix to be used and the split number to obtain a first neuron group; For each of the matrixes to be used, performing a second grouping process on the neurons of the feedforward neural network layer by using the matrix to be used and the split number to obtain a second neuron group; The first neuron group and the second neuron group are determined as a plurality of target neuron groups.

3. The method according to claim 2, characterized in that The step of performing a first grouping process on the neurons of the feedforward neural network layer by using the matrix to be used and the split number to obtain a first neuron group includes: Adding a first index to a first specified list, where the first index is an index of a maximum element value in the matrix to be used, and the first index includes a first row index j and a first column index k; Replacing the j-th row and the j-th column in the matrix to be used with a first target row, and setting the k-th row and the k-th column in the matrix to be used to a first specified value, to obtain a first intermediate matrix, wherein the first target row is generated based on the element values ​​in the j-th row and the k-th row of the matrix to be used; Using the second column index m to update the first designated list and the first intermediate matrix until the length of the first designated list reaches a preset length, thereby obtaining a second designated list and a second intermediate matrix, wherein the second column index m is an index corresponding to the maximum element value in the j-th row of the first intermediate matrix, and the preset length is calculated based on the number of splits; If not all element values ​​in the second intermediate matrix are the first specified values, use the second intermediate matrix as the matrix to be used, and return to execute the step of adding the first index to the first specified list and subsequent steps; If the element values ​​in the second intermediate matrix are all the first specified values, all the second specified lists are used as the first neuron group.

4. The method according to claim 3, characterized in that The method of updating the first designated list and the first intermediate matrix by using the second column index m until the length of the first designated list reaches a preset length to obtain a second designated list and a second intermediate matrix comprises: Determine a second column index m from the first intermediate matrix, and add the second column index m to the first specified list; Generate a second target row based on element values ​​in the j-th row and the k-th row of the first intermediate matrix; Replacing the j-th row and the j-th column in the first intermediate matrix with the second target row, and setting the m-th row and the m-th column in the first intermediate matrix to the first specified value, to obtain a new first intermediate matrix; If the length of the first designated list is less than the preset length, returning to execute the step of determining the second column index m from the first intermediate matrix and adding the second column index m to the first designated list and subsequent steps; If the length of the first designated list is equal to the preset length, the first designated list is used as the second designated list, and the j-th row and the j-th column of the first intermediate matrix are set to the first designated value to obtain a second intermediate matrix.

5. The method according to claim 2, characterized in that: The step of performing a second grouping process on the neurons of the feedforward neural network layer by using the matrix to be used and the split number to obtain a second neuron group comprises: Acquire a preset list set, a preset dictionary, and a copy matrix, wherein the preset list set includes the split preset lists, and the copy matrix is ​​a matrix obtained by copying the matrix to be used; Obtain a first index, where the first index is an index of a maximum element value in the matrix to be used, and the first index includes a first row index j and a first column index k; Based on the inclusion relationship between the first row index j and the first column index k and the preset dictionary, at least two of the preset list set, the preset dictionary and the matrix to be used are updated to obtain an intermediate list set, an intermediate dictionary and a third intermediate matrix; Combining the element values ​​in the j-th row and the k-th row in the third intermediate matrix and the copy matrix, updating the third intermediate matrix to a fourth intermediate matrix; The second neuron group is obtained using the length of the intermediate list corresponding to the first list index, the length of the intermediate dictionary and the fourth intermediate matrix, wherein the first list index is the index associated with the first row index j in the intermediate dictionary.

6. The method according to claim 5, characterized in that The inclusion relationship includes that the first row index j or the first column index k is in the preset dictionary, and based on the inclusion relationship between the first row index j and the first column index k and the preset dictionary respectively, updating at least two of the preset list set, the preset dictionary, and the matrix to be used to obtain the intermediate list set, the intermediate dictionary, and the third intermediate matrix, including: Among the first indexes, the indexes in the preset dictionary are recorded as first-category indexes, and the indexes not in the preset dictionary are recorded as second-category indexes; Obtaining a first category list index associated with the first category index from the preset dictionary; Adding the second category index to the preset list corresponding to the first category list index, and associating the second category index with the first category list index into a preset dictionary to obtain an intermediate list set and an intermediate dictionary; The matrix to be used is used as the third intermediate matrix.

7. The method according to claim 5, characterized in that The inclusion relationship includes that the first row index j and the first column index k are both in the preset dictionary, and based on the inclusion relationship between the first row index j and the first column index k and the preset dictionary respectively, at least two of the preset list set, the preset dictionary, and the matrix to be used are updated to obtain the intermediate list set, the intermediate dictionary, and the third intermediate matrix, including: Obtain, from the preset dictionary, a first row list index associated with the first row index j and a first column list index associated with the first column index k; Determine, from the preset list set, a first preset list corresponding to the first row list index, and a second preset list corresponding to the first column list index; If the sum of the lengths of the first preset list and the second preset list is not greater than the preset length, move the elements in the second preset list to the first preset list, and modify the first column list index in the preset dictionary to the first row list index, so as to obtain an intermediate list set and an intermediate dictionary; If the sum of the lengths of the first preset list and the second preset list is greater than the preset length, the matrix to be used is updated based on the first row index j and the first column index k to obtain a third intermediate matrix, and the step of obtaining the first index and subsequent steps are returned with the third intermediate matrix.

8. The method according to claim 5, characterized in that The inclusion relationship includes that the first row index j and the first column index k are not in the preset dictionary, and based on the inclusion relationship between the first row index j and the first column index k and the preset dictionary respectively, at least two of the preset list set, the preset dictionary and the matrix to be used are updated to obtain the intermediate list set, the intermediate dictionary and the third intermediate matrix, including: If a target list exists in the preset list set, the first row index j and the first column index k are added to the target list to obtain an intermediate list set, where the target list is an empty preset list; Obtain the target list index corresponding to the target list in the intermediate list set; Writing a first associated index and a second associated index into a preset dictionary to obtain an intermediate dictionary, wherein the first associated index includes the first row index j and the target list index, and the second associated index includes the first column index k and the target list index; If the target list does not exist in the preset list set, the matrix to be used is updated to a third intermediate matrix based on the first row index j and the first column index k, and the process returns to execute the step of obtaining the first index and subsequent steps.

9. The method according to claim 5, characterized in that The combining the element values ​​in the j-th row and the k-th row in the third intermediate matrix and the copy matrix to update the third intermediate matrix to a fourth intermediate matrix includes: For each column in the third intermediate matrix, compare the element value of the j-th row with the element value of the k-th row to obtain a candidate row; If the second specified value does not exist in the candidate row, determining the candidate row as a third target row; If the second specified value exists in the candidate row, obtain the third column index corresponding to the second specified value; From the intermediate dictionary, obtain the first row list index associated with the first row index j; Using the third column index as a column index and each element in the intermediate list corresponding to the first row list index in the intermediate list set as a row index, a plurality of target indexes are obtained; In the replica matrix, replacing the second specified value in the candidate row with the minimum element value corresponding to the target index to obtain a third target row; The j-th row and the j-th column in the third intermediate matrix are replaced with the third target row, and the k-th row and the k-th column in the third intermediate matrix are set to the first specified value, so as to obtain a fourth intermediate matrix.

10. The method according to claim 1, characterized in that The model parameters include input layer transformation parameters and hidden layer transformation parameters. For a preset number of experts, based on the multiple target neuron groups, extracting target model parameters corresponding to each expert from the model parameters includes: Acquire multiple target neuron groups corresponding to each feedforward neural network layer, each of the target neuron groups including multiple candidate lists; For each expert, determining an extraction list from the multiple candidate lists according to the expert index, the number of splits, and the number of combinations corresponding to the expert; Taking the element value in the extraction list as the row extraction index, extracting the first designated row corresponding to the row extraction index from the input layer transformation parameters as the target input layer transformation parameters of the expert; The element value in the extraction list is used as the column extraction index, and the first designated column corresponding to the column extraction index is extracted from the hidden layer transformation parameters as the target hidden layer transformation parameter of the expert.