Text processing method and device, electronic equipment, storage medium and program product
By introducing a hybrid expert model into the large language model for feature projection processing and optimizing the output features, the problem of difficulty and high cost in training large language models is solved, and efficient text processing performance and fine-tuning effects are achieved.
Patent Information
- Application Number
- CN202410917061.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-09-03
AI Technical Summary
The parameter size of large language models grows rapidly, making training and fine-tuning all model parameters expensive and difficult in terms of time and hardware costs.
The hybrid expert model is introduced, and feature projection processing is performed through the linear layer network and the hybrid expert model to optimize the output features, reduce the training difficulty of the model, and only fine-tune some parameters during the fine-tuning process to achieve efficient fine-tuning of parameters.
It effectively improves the text processing performance of the model, reduces the time and hardware cost of model fine-tuning, and the fine-tuning performance of the hybrid expert model even exceeds the fine-tuning of all parameters.
Smart Images

Figure CN118586433A
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence (AI) technology. Specifically, the present application relates to a text processing method, device, electronic device, storage medium and program product. Background Art
[0002] Large Language Model is an important technology in the field of artificial intelligence, which aims to enable computers to understand and generate natural language and solve the challenges of natural language processing tasks. Recently, some large language models have achieved remarkable results in natural language processing tasks.
[0003] These models use the method of pre-training and fine-tuning. First, they are pre-trained on large-scale data to obtain rich external knowledge, and then fine-tuned on instruction fine-tuning datasets to obtain powerful human instruction-following capabilities, enabling them to handle various natural language tasks according to instructions input by humans.
[0004] However, because the scale of model parameters is growing rapidly, the number of parameters of the current mainstream large language models is usually in the order of tens to hundreds of billions. Using data to train all model parameters and then fine-tuning all model parameters requires a lot of time and hardware costs, resulting in training and fine-tuning all model parameters becoming increasingly expensive and difficult. Summary of the invention
[0005] The purpose of the embodiments of the present application is to solve the technical problem of how to improve the text processing performance of a large language model.
[0006] According to one aspect of an embodiment of the present application, a text processing method is provided, the method comprising: Acquire a large language model and a target text, wherein the large language model includes a plurality of hidden layers, each hidden layer includes a linear layer network, and at least one hidden layer also includes a mixed expert model; Based on the target text, the input features of each hidden layer are obtained; For each hidden layer including the hybrid expert model, the input features of the hidden layer are subjected to a first projection process through a linear layer network to obtain a first hidden feature, the input features of the hidden layer are subjected to a second projection process through the hybrid expert model to obtain a second hidden feature, and the first hidden feature and the second hidden feature are fused to obtain an output feature of the hidden layer; Based on the output features of the last hidden layer of the large language model, the processing result of the target text is obtained.
[0007] In an optional implementation, the hybrid expert model includes at least two expert networks and a gating network, and the input feature of the hidden layer is subjected to a second projection process through the hybrid expert model to obtain a second hidden feature, including: The input features of the hidden layer are respectively subjected to second projection processing through each expert network to obtain corresponding third hidden features; Based on the input features of the hidden layer, projection processing is performed through the gating network to obtain the weights corresponding to each third hidden feature; Based on the weights corresponding to the third hidden features, the third hidden features are weightedly fused to obtain the second hidden feature.
[0008] In an optional implementation, the expert network includes a connected dimensionality reduction network and a dimensionality increase network, and based on the input features of the hidden layer, projection processing is performed through a gating network to obtain weights corresponding to each third hidden feature, including at least one of the following methods: Through the gating network, the input features of the hidden layer are projected into weights corresponding to each third hidden feature; Through the gating network, the first feature of the input feature of the hidden layer after dimension reduction processing by the dimension reduction network is projected into the weights corresponding to each third hidden feature; Through the gating network, the input features of the hidden layer are successively reduced in dimension through the dimensionality reduction network and the dimensionality increase network, and the second features after dimensionality increase are projected into the weights corresponding to each third hidden feature.
[0009] In an optional implementation, the expert network includes a connected dimensionality reduction network and a dimensionality increase network, and the input features of the hidden layer are processed by any expert network to obtain corresponding third hidden features, including: Obtain the degree of change of the first dimension corresponding to the expert network; Based on the number of expert networks included in the hybrid expert model, the variation degree of the first dimension is reduced to obtain the variation degree of the second dimension; Based on the degree of change of the second dimension, the input features of the hidden layer are sequentially processed by the dimensionality reduction network for dimensionality reduction and the dimensionality increase network for dimensionality increase, so as to obtain the corresponding third hidden features; The degree of dimension change represents the degree of dimensionality reduction and / or dimensionality increase of the feature in the expert network.
[0010] In an optional implementation, based on the number of expert networks included in the hybrid expert model, reducing the first dimension variation degree to obtain the second dimension variation degree includes: The degree of change in the first dimension is divided by the number of expert networks included in the mixed expert model to obtain the degree of change in the second dimension.
[0011] In an optional embodiment, the linear layer network includes at least one of an attention subnetwork, a feedforward model subnetwork, and a multilayer perceptron subnetwork.
[0012] In an optional implementation, the large language model is obtained by the following training method: Get the pre-trained linear layer networks; Under the condition of freezing the network parameters of each pre-trained linear layer network, training each hybrid expert model to obtain each trained hybrid expert model; Based on the pre-trained linear layer networks and the trained mixed expert models, a trained large language model is obtained.
[0013] In an optional implementation, each hybrid expert model includes a dimensionality reduction network, a dimensionality increase network, and a gating network. Before training each hybrid expert model, the following steps are further included: Initialize the parameters of the dimensionality reduction network according to the standard Gaussian distribution; Initialize the parameters of the dimension-raising network to zero; Initialize the parameters of the gating network in a predetermined manner.
[0014] In an optional implementation, each hybrid expert model is trained to obtain each trained hybrid expert model, including: Obtain multiple text training sets, each text training set corresponds to a text task; Based on each training set, each hybrid expert model is trained to obtain multiple sets of trained hybrid expert models; Based on the pre-trained linear layer networks and the trained mixed expert models, a trained large language model is obtained, including: Based on the pre-trained linear layer networks and each set of trained hybrid expert models, a large language model corresponding to a variety of text tasks is obtained.
[0015] According to another aspect of the embodiments of the present application, a text processing device is provided, the device comprising: A first acquisition module is used to acquire a large language model and a target text, wherein the large language model includes a plurality of hidden layers, each hidden layer includes a linear layer network, and at least one hidden layer also includes a hybrid expert model; The second acquisition module is used to obtain input features of each hidden layer based on the target text; A first processing module is used for, for each hidden layer including the hybrid expert model, performing a first projection process on the input features of the hidden layer through a linear layer network to obtain a first hidden feature, performing a second projection process on the input features of the hidden layer through the hybrid expert model to obtain a second hidden feature, and fusing the first hidden feature and the second hidden feature to obtain an output feature of the hidden layer; The second processing module is used to obtain the processing result of the target text based on the output features of the last hidden layer of the large language model.
[0016] In an optional implementation, the hybrid expert model includes at least two expert networks and a gating network, and the first processing module is used to perform a second projection process on the input feature of the hidden layer through the hybrid expert model to obtain the second hidden feature, specifically for: The input features of the hidden layer are respectively subjected to second projection processing through each expert network to obtain corresponding third hidden features; Based on the input features of the hidden layer, projection processing is performed through the gating network to obtain the weights corresponding to each third hidden feature; Based on the weights corresponding to the third hidden features, the third hidden features are weightedly fused to obtain the second hidden feature.
[0017] In an optional implementation, the expert network includes a connected dimensionality reduction network and a dimensionality increase network, and the first processing module is used to perform projection processing based on the input features of the hidden layer through the gating network to obtain the weights corresponding to each third hidden feature, specifically for at least one of the following methods: Through the gating network, the input features of the hidden layer are projected into weights corresponding to each third hidden feature; Through the gating network, the first feature of the input feature of the hidden layer after dimension reduction processing by the dimension reduction network is projected into the weights corresponding to each third hidden feature; Through the gating network, the input features of the hidden layer are successively reduced in dimension through the dimensionality reduction network and the dimensionality increase network, and the second features after dimensionality increase are projected into the weights corresponding to each third hidden feature.
[0018] In an optional implementation, the expert network includes a connected dimensionality reduction network and a dimensionality increase network, and the first processing module is used to process the input feature of the hidden layer through any expert network to obtain the corresponding third hidden feature, specifically for: Obtain the degree of change of the first dimension corresponding to the expert network; Based on the number of expert networks included in the hybrid expert model, the variation degree of the first dimension is reduced to obtain the variation degree of the second dimension; Based on the degree of change of the second dimension, the input features of the hidden layer are sequentially processed by the dimensionality reduction network for dimensionality reduction and the dimensionality increase network for dimensionality increase, so as to obtain the corresponding third hidden features; The degree of dimension change represents the degree of dimensionality reduction and / or dimensionality increase of the feature in the expert network.
[0019] In an optional implementation, the first processing module, when used to reduce the first dimension variation degree based on the number of expert networks included in the hybrid expert model to obtain the second dimension variation degree, is specifically used to: The degree of change in the first dimension is divided by the number of expert networks included in the mixed expert model to obtain the degree of change in the second dimension.
[0020] In an optional embodiment, the linear layer network includes at least one of an attention subnetwork, a feedforward model subnetwork, and a multilayer perceptron subnetwork.
[0021] In an optional implementation, the text processing device further includes a training module, which is used to obtain a large language model by the following training method: Get the pre-trained linear layer networks; Under the condition of freezing the network parameters of each pre-trained linear layer network, training each hybrid expert model to obtain each trained hybrid expert model; Based on the pre-trained linear layer networks and the trained mixed expert models, a trained large language model is obtained.
[0022] In an optional implementation, each hybrid expert model includes a dimensionality reduction network, a dimensionality increase network, and a gating network. Before the training module is used to perform training processing on each hybrid expert model, it is also used to: Initialize the parameters of the dimensionality reduction network according to the standard Gaussian distribution; Initialize the parameters of the dimension-raising network to zero; Initialize the parameters of the gating network in a predetermined manner.
[0023] In an optional implementation, when the training module is used to train each hybrid expert model to obtain each trained hybrid expert model, it is specifically used to: Obtain multiple text training sets, each text training set corresponds to a text task; Based on each training set, each hybrid expert model is trained to obtain multiple sets of trained hybrid expert models; When the training module is used to obtain a trained large language model based on pre-trained linear layer networks and trained hybrid expert models, it is specifically used for: Based on the pre-trained linear layer networks and each set of trained hybrid expert models, a large language model corresponding to a variety of text tasks is obtained.
[0024] According to another aspect of an embodiment of the present application, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the text processing method provided in the embodiment of the present application.
[0025] According to another aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored, wherein when the computer program is executed by a processor, the text processing method provided in the embodiment of the present application is implemented.
[0026] According to another aspect of an embodiment of the present application, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the text processing method provided by the embodiment of the present application is implemented.
[0027] The text processing method, device, electronic device, storage medium and program product provided in the embodiment of the present application obtain a large language model and a target text, wherein the large language model includes multiple hidden layers, each hidden layer includes a linear layer network, and at least one hidden layer also includes a hybrid expert model; based on the target text, the input features of each hidden layer are obtained; for each hidden layer including the hybrid expert model, the input features of the hidden layer are subjected to a first projection process through a linear layer network to obtain a first hidden feature, the input features of the hidden layer are subjected to a second projection process through a hybrid expert model to obtain a second hidden feature, the first hidden feature and the second hidden feature are fused to obtain the output feature of the hidden layer; based on the output feature of the last hidden layer of the large language model, the processing result of the target text is obtained. That is, in the embodiment of the present application, a hybrid expert model is introduced into part or all of the linear layer networks for feature projection processing to optimize the output features, which can reduce the difficulty of model training, and the fine-tuning of the hybrid expert model can reach or even exceed the model performance of the fine-tuning of all parameters, so that the use of the hybrid expert model can effectively improve the text processing performance of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in describing the embodiments of the present application.
[0029] Figure 1 A flowchart of a text processing method provided in an embodiment of the present application; Figure 2 A schematic diagram of a linear layer network corresponding to the attention network provided in an embodiment of the present application; Figure 3 A schematic diagram of a large language model fine-tuning solution provided in an embodiment of the present application; Figure 4 A schematic diagram of a processing process of a current hidden layer provided in an embodiment of the present application; Figure 5 A schematic diagram of the structure of a hybrid expert model provided in an embodiment of the present application; Figure 6 A schematic diagram of a processing process of a hidden layer including a linear layer network and a hybrid expert model provided in an embodiment of the present application; Figure 7 A flowchart of a method for training a large language model provided in an embodiment of the present application; Figure 8 A structural diagram of a text processing device provided in an embodiment of the present application; Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.
[0031] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "an" and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we call an element "connected" or "coupled" to another element, the one element can be directly connected or coupled to the other element, or it can refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used here may include wireless connection or wireless coupling. The term "and / or" used here indicates at least one of the items defined by the term, for example, "A and / or B" can be implemented as "A", or as "B", or as "A and B".
[0032] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0033] First, several terms involved in this application are introduced and explained: (1) Natural Language Processing (NLP): It can be understood as a bridge of communication between machine language and human language. It mainly studies how to enable computers to understand, process, generate and simulate human language, so as to achieve the purpose of human-computer communication.
[0034] (2) Machine Learning: Allow computers to simulate or implement human learning behaviors to acquire new knowledge or skills, and divide existing content into knowledge structures to effectively improve learning efficiency. In this way, computers can automatically learn rules and patterns from data and make predictions and decisions based on these rules and patterns.
[0035] (3) Model fine-tuning (Finetune): refers to making minor adjustments to a pretrained model to improve its accuracy and performance. In the field of machine learning, model fine-tuning can also be used to optimize the model to adapt to new data sets and tasks. Compared with training a model from scratch (Training a model from scatch), it can save a lot of computing resources and computing time, and improve computing efficiency.
[0036] (4) Full parameter fine-tuning: This can also be called fine-tuning of all parameters or full-scale fine-tuning. It means that every parameter of the pre-trained model is updated during the fine-tuning process. The characteristic is that the fine-tuning effect is usually better, but the fine-tuning cost is expensive.
[0037] (5) Parameter-Efficient Fine-Tuning (PEFT): Fine-tuning is performed by introducing a small number of trainable parameters. The feature of PEFT is low fine-tuning cost, but the fine-tuning effect is usually slightly worse than full parameter fine-tuning.
[0038] (6) Mixture of Experts (MoE): Based on a very natural voting idea, it can dynamically activate some neural networks, thereby significantly increasing the number of model parameters without increasing the amount of calculation. It has the characteristics of being able to improve the performance of the overall system, low training difficulty, and able to ensure the generalization performance of the entire system.
[0039] The embodiments of the present application provide a text processing method, device, electronic device, storage medium and program product, so that the technical solution of the embodiments of the present application can achieve the effects of improving the text processing performance of the model, reducing the time cost and hardware cost of model fine-tuning, and improving the flexibility of the model.
[0040] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present application and the technical effects produced by the technical solutions of the present application. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.
[0041] The present application provides a text processing method, such as Figure 1 As shown, the method includes: Step S101: obtaining a large language model and a target text, wherein the large language model includes a plurality of hidden layers, each hidden layer includes a linear layer network, and at least one hidden layer also includes a hybrid expert model; Step S102: Based on the target text, obtain input features of each hidden layer; Step S103: for each hidden layer including the hybrid expert model, performing a first projection process on the input features of the hidden layer through a linear layer network to obtain a first hidden feature, performing a second projection process on the input features of the hidden layer through the hybrid expert model to obtain a second hidden feature, and fusing the first hidden feature and the second hidden feature to obtain an output feature of the hidden layer; Step S104: Based on the output features of the last hidden layer of the large language model, the processing result of the target text is obtained.
[0042] In the embodiment of the present application, the target text refers to the text to be processed by the natural language processing task. Optionally, the target text includes but is not limited to text data, text converted from voice data, text extracted from image or video data, etc. The embodiment of the present application does not specifically limit the source of the target text.
[0043] It can be understood that for different natural language processing tasks, the type and content of the target text, and the corresponding predetermined processing methods may be different. For example, the text processing method provided in the embodiment of the present application can be applied to target tasks such as question answering, summary generation, translation, sentiment analysis, etc., but is not limited to this. As an example, for question answering tasks, the target text may refer to the question text, and the corresponding target task processing may refer to generating answers; for summary generation tasks, the target text may refer to the main text, and the corresponding target task processing may refer to generating summaries; for translation scenarios, the target text may refer to text or speech to be translated into other languages, and the corresponding target task processing may refer to translating the target text into other languages; for sentiment analysis tasks, the target text may refer to text or images to be analyzed, and the corresponding target task processing may refer to generating sentiment analysis results, etc.
[0044] Optionally, the target text is processed for the target task through the large language model, specifically, the data features corresponding to the target text are processed in a predetermined manner through the large language model. As an example, the target text can be vectorized to obtain text features. For example, the word2vec (word to vector) algorithm, the Bert (bidirectional encoder representation from transformers) model or the text encoding method can be used to vectorize the text to be processed, but it is not limited thereto.
[0045] In the embodiment of the present application, input features of each hidden layer are obtained based on the target text. Optionally, feature extraction can be performed on the target text to obtain input features of one or more hidden layers. Optionally, the input features of some hidden layers may also be output features of other hidden layers, which is determined by the structure of the large language model.
[0046] In the embodiment of the present application, there is no restriction on the type and model structure of the large language model. Optionally, any large language model can be used as the initial large language model, but it is not limited thereto, and other neural network models can also be used.
[0047] The large language model includes multiple hidden layers. The hidden layer refers to the neural network layer included in the large language model. Each hidden layer includes the original linear layer network. The linear layer networks corresponding to different hidden layers may be different. For large language models with different structures, the types of hidden layers and corresponding linear layer networks may be different. For example, if the large language model includes Figure 2 The attention network shown in the figure, the features of the hidden state are respectively network, Network and The network (which can be called attention subnetwork or attention sublayer) is processed to obtain Q (Query) features, K (Key) features and V (Value) features for attention calculation, then network, Network and The network can be regarded as a linear layer network (which can be used as a hidden layer). For another example, if the large language model includes a feedforward neural network (FFN), then each subnetwork (or FFN sublayer) included in the feedforward neural network can be regarded as a linear layer network (which can be used as a hidden layer). For another example, if the large language model includes a multi-layer perceptron (MLP), then each neural network layer (MLP subnetwork) used for feature extraction in the MLP can be regarded as a linear layer network (which can be used as a hidden layer), etc. The embodiment of the present application does not limit the types of hidden layers and corresponding linear layer networks.
[0048] In the embodiment of the present application, at least one hidden layer also includes a hybrid expert model connected in parallel with the linear layer network of the hidden layer. That is, the embodiment of the present application adds a hybrid expert model branch to at least one linear layer network, wherein the parameters of the added hybrid expert model branch are trainable and can be used as trainable parameters in the fine-tuning process to reduce the amount of training parameters in the fine-tuning process of the large language model, that is, the use of the hybrid expert model can realize the parameter efficient fine-tuning method (i.e., PEFT method), which has the advantages of low hardware overhead and short fine-tuning time compared with the fine-tuning of all parameters; and the use of the hybrid expert model can reduce the difficulty of model training, so that the model fine-tuning reaches or even exceeds the model performance of the fine-tuning of all parameters.
[0049] In an optional implementation, the large language model includes multiple blocks, such as transformer blocks, and the linear layer network may include at least one of an attention subnetwork, a feedforward model subnetwork, and a multilayer perceptron subnetwork, that is, a hybrid expert model (i.e., a hybrid expert model) branch is added to each Attention subnetwork, each FFN subnetwork, and each MLP subnetwork in each block, and only the hybrid expert model branch is fine-tuned to implement an efficient parameter fine-tuning method.
[0050] In an example, Figure 3 As shown in the figure, the large language model includes L network blocks, each of which includes an attention network and an FFN network. network, Network and The MoE network is introduced into the network respectively, and the MoE network is introduced into the sub-network in the FFN network. Specifically, the input of the network block is encoded into a hidden state, and then The network and the related MoE network are processed, and the processing results are fused to obtain the Q feature. The network and the related MoE network are processed, and the processing results are fused to obtain K features. The network and the related MoE network are processed, and the processing results are fused to obtain V features. Attention calculation is performed based on Q features, K features and V features. The attention calculation results and the input of the network block are added and layer normalized and input into the FFN network. In one or more subnetworks of the FFN network, the related MoE network is processed in a similar manner to obtain the output of the FFN network. The output of the FFN network and the input of the FFN network are added and layer normalized to obtain the output of the network block, and then the processing result of the corresponding target task can be obtained.
[0051] In the embodiment of the present application, the reasoning application of the linear layer network and the hybrid expert model may include: for each hidden layer including the linear layer network (i.e., not including the hybrid expert model), the input feature of the hidden layer is subjected to a first projection process through the linear layer network to obtain the output feature of the hidden layer; for each hidden layer including the parallel linear layer network and the hybrid expert model, such as Figure 4 As shown, the input features of the hidden layer can be projected through a linear layer network to obtain the first hidden feature ( ), the input features of the hidden layer are processed by the hybrid expert model for the second projection to obtain the second hidden features ( ), where the use of the hybrid expert model can achieve efficient fine-tuning of parameters, and the second hidden feature can be regarded as an optimization of the first hidden feature. By fusing the first hidden feature and the second hidden feature, the output feature of the hidden layer can be obtained ( ).
[0052] The fusion of the first hidden feature and the second hidden feature can be achieved by direct addition or weighted addition, that is:
[0053] or:
[0054] However, it is not limited to this, and other fusion methods may also be used. The specific fusion method may be related to the connection method between the linear layer network and the hybrid expert model. Those skilled in the art may set it according to actual conditions, and the embodiments of the present application are not limited here.
[0055] It should be noted that the order of the two steps in the above-mentioned reasoning application of the linear layer network and the hybrid expert model does not constitute a limitation on the order of the two steps or the number of executions, that is, the execution order of the two steps may not be in order, and the number of executions may be zero, one, or multiple times. The specific execution method may be related to the structure of the large language model. As an example, if the hidden layer that does not include the hybrid expert model and the hidden layer that includes the hybrid expert model are connected in series, the step of the hidden layer that does not include the hybrid expert model may be executed first and then the step of the hidden layer that includes the hybrid expert model, or the step of the hidden layer that includes the hybrid expert model may be executed first and then the step of the hidden layer that does not include the hybrid expert model; if the hidden layer that does not include the hybrid expert model and the hidden layer that includes the hybrid expert model are connected in parallel, the two steps may be executed simultaneously. As another example, if multiple hidden layers that do not include the hybrid expert model and multiple hidden layers that include the hybrid expert model are alternately connected, the two steps may be executed alternately multiple times. As another example, if multiple hidden layers in the large language model all introduce hybrid expert models, the steps of not including the hidden layers of the hybrid expert model may not be executed, and the steps of including the hidden layers of the hybrid expert model may be executed multiple times. Those skilled in the art may make settings based on actual conditions, and the embodiments of the present application are not limited here.
[0056] In the embodiment of the present application, the hybrid expert model includes at least two expert networks (Expert Network) and a gating network (Gating Network, which may also be called a control gate, and specifically may adopt a gating matrix). As an example, the structure of a hybrid expert model may be as follows: Figure 5 As shown ( Figure 5 In the example above, the hybrid expert model includes three expert networks. The overall output of the hybrid expert model is composed of the outputs of each expert network, and the specific proportion is determined by the gating network, namely:
[0057] in, represents the output of the mixed expert model, Indicates The output of the expert network is Indicates that the gating network is assigned to The output of the hybrid expert model is the weighted addition result of the outputs of multiple expert networks.
[0058] Then, in step S103, the input feature of the hidden layer is subjected to a second projection process through the hybrid expert model to obtain a second hidden feature, which may specifically include: Step S201: The input features of the hidden layer are respectively subjected to a second projection process through each expert network to obtain the corresponding third hidden features (i.e. ).
[0059] Step S202: Based on the input features of the hidden layer, projection processing is performed through the gating network to obtain the weights corresponding to each third hidden feature (i.e. ).
[0060] Step S203: Based on the weights corresponding to the third hidden features, perform weighted fusion on the third hidden features to obtain the second hidden feature.
[0061] That is, in the implementation of this application, multiple expert networks are introduced to simultaneously predict the input data, and the performance of the overall system is improved by combining the capabilities of multiple expert networks.
[0062] In the embodiment of the present application, the expert network can specifically use a low-rank mapping matrix, that is, the expert network can include a connected dimensionality reduction network (specifically, a dimensionality reduction projection matrix can be used, which can be referred to as a dimensionality reduction matrix) and a dimensionality increase network (specifically, a dimensionality increase projection matrix can be used, which can be referred to as a dimensionality increase matrix), and the input features of the hidden layer are respectively projected by the dimensionality reduction operation and the dimensionality increase operation of the two networks to obtain the output of the expert network Among them, the degree of dimensional change of features in the expert network (that is, the degree of dimensionality reduction and / or dimensionality increase of features in the expert network) can be expressed by rank (which can be expressed as ), The smaller the value, the higher the degree of dimensionality reduction and / or dimensionality increase.
[0063] Based on this, in the embodiment of the present application, a feasible implementation method is provided for step S202, specifically, it may include at least one of the following methods: Method 1: Through the gating network, the input features of the hidden layer are projected into the weights corresponding to each third hidden feature; That is, the weight can be at the input of each expert network Calculate on the input features of the hidden layer and concatenate the inputs of all expert networks , and based on the characteristics Dimensions , the splicing result Projected as the number of expert networks , the linear layer outputs the output of each expert network The corresponding weights .
[0064] Method 2: Through the gating network, the first feature of the hidden layer input feature processed by the dimension reduction network is projected into the weights corresponding to each third hidden feature; That is, the weights can be calculated at the output of the dimension reduction network of each expert network. (That is, the input of the dimensional network, the dimension is from Compressed to ) and concatenate the outputs of the dimension reduction networks of all expert networks , and based on the characteristics Dimensions , the splicing result Projected as the number of expert networks , the linear layer outputs the output of each expert network The corresponding weights .
[0065] Method 3: Through the gating network, the input features of the hidden layer are processed by the dimensionality reduction network and the dimensionality increase network in turn, and the second features after dimensionality reduction and dimensionality increase are projected into the weights corresponding to each third hidden feature; That is, the weights can be at the output of each expert network (That is, the output of the dimensionality-raising network, the dimension is from Expand to ) and concatenate the outputs of all expert networks , and based on the characteristics Dimensions , the splicing result Projected as the number of expert networks , the linear layer outputs the output of each expert network The corresponding weights .
[0066] In an example, considering the dimension The number of parameters is smaller than or even much smaller than the dimension , the output of each expert network can be calculated using method 2 (i.e. the third hidden feature) respectively corresponds to the weight , which can reduce the number of parameters calculated by the gating network and further reduce the fine-tuning cost.
[0067] In the embodiment of the present application, the output of each expert network is calculated as follows: (i.e. the third hidden feature) respectively corresponds to the weight For example, Figure 6 As shown, an example of a processing flow is provided (for the hidden layer including the linear layer network and the hybrid expert model). The processing methods of the second and third methods can be deduced by analogy and will not be described in detail here. Specifically, it may include: Step S5.1: is the input feature of the current hidden layer. After being processed by the pre-trained linear layer network branch, the hidden feature is obtained. , where the linear layer network can use the original linear layer of the hidden layer for projection. The specific calculation process can be expressed as:
[0068] in, Corresponding to the processing process of the linear layer network. Among them, and The dimensions of both are the same. , is the sequence length (i.e. text length), is the feature dimension (i.e. the dimension of the word vector).
[0069] Step S5.2: Input features of the current hidden layer , n expert networks after the hybrid expert model The dimension reduction network and dimension increase network in are processed, and the specific calculation process can be expressed as:
[0070] in, and Corresponding to the expert network The processing process of dimensionality reduction network and dimensionality increase network, is the rank of the expert network. Input features After dimensionality reduction projection and dimensionality increase projection, the expert network is obtained. Output .
[0071] Step S5.3: Expert Network The corresponding weight The output from the gate network Gate. The specific calculation process can be expressed as:
[0072] in Corresponding to the processing process of the gated network, the input feature Dimensions Projection as number of experts , represents the output of each expert network The importance of The activation function normalizes the weight distribution to obtain the final output probability distribution weight .
[0073] Step S5.4: The overall output of the hybrid expert model branch is a weighted combination of the outputs of each expert network. The specific calculation process can be expressed as:
[0074] Step S5.5: The output features of the hidden layer are the two outputs of the original linear layer network branch and the hybrid expert model branch. and The fusion result .
[0075] In the embodiment of the present application, an optional implementation is provided for step S201. Specifically, the input feature of the hidden layer is processed by any expert network to obtain the corresponding third hidden feature, which may include: S2011: Obtain the degree of change of the first dimension corresponding to the expert network; In an embodiment of the present application, the degree of change of the first dimension corresponding to the expert network can be determined based on the LoRA (Low-Rank Adaptation) parameter efficient fine-tuning method. Among them, the LoRA parameter efficient fine-tuning method studies the inherent low rank problem of the pre-trained model and proposes low rank fine-tuning.
[0076] Among them, LoRA has only one low-rank fine-tuning branch, and its parameter quantity is .
[0077] In the embodiment of the present application, the rank of LoRA can be Determined as the degree of change of the first dimension.
[0078] S2012: based on the number of expert networks included in the hybrid expert model, reducing the degree of change of the first dimension to obtain the degree of change of the second dimension; In the embodiment of the present application, the expert network can be reduced The rank of can be used to ensure that the number of branch parameters of the hybrid expert model and the LoRA parameter efficient fine-tuning method are the same. Specifically, the number of expert networks included in the hybrid expert model can be To reduce the variation of the first dimension , get the second dimension change degree .
[0079] Optionally, the degree of change in the first dimension may be divided by the number of expert networks included in the hybrid expert model to obtain the degree of change in the second dimension. The specific calculation process may be expressed as:
[0080] SB13: Based on the degree of change of the second dimension, the input features of the hidden layer are processed by the dimensionality reduction network and the dimensionality increase network in turn to obtain the corresponding third hidden features.
[0081] In the embodiment of the present application, for the hybrid expert model, each expert network The parameter quantity is , the total number of parameters of all expert networks is = , which is the same as the number of parameters in the LoRA parameter efficient fine-tuning method.
[0082] In one example, r can be set to 8 or 16, and the number of expert networks can be set to 2 or 4.
[0083] Then in the embodiment of the present application, based on the degree of change of the second dimension, the input features of the hidden layer are processed by the expert network to obtain the corresponding third hidden features. Due to the participation of multiple expert networks, it can be ensured that the fine-tuning effect is better than the LoRA parameter efficient fine-tuning method without increasing the number of parameters.
[0084] In addition, for step S202, the parameter quantity of the gate control network Gate that is additionally introduced due to the need for weight calculation is , where the number of parameters of the gating network is 1 / 2r of the total number of parameters of the expert network. This part of the overhead is very small and can be ignored.
[0085] As can be seen from the above introduction, the large language model includes multiple hidden layers, each hidden layer includes a corresponding linear layer network, at least one hidden layer also includes a hybrid expert model associated with the linear layer network of the hidden layer, and the hybrid expert model is a hybrid expert model. Based on this, a training method for a large language model is provided in an embodiment of the present application, such as Figure 7 As shown, the large language model is obtained through the following training method: Step S701: Obtain each pre-trained linear layer network; This step can be understood as initializing the linear layer network. Specifically, the linear layer network (such as the original linear layer) branch can be initialized using pre-trained parameters. Among them, the pre-trained parameters can directly use the parameters of the existing large language model, or can be obtained by real-time training. In the embodiment of the present application, the acquisition and initialization method of the linear layer network are not limited.
[0086] Step S702: while freezing the network parameters of each pre-trained linear layer network, training each hybrid expert model to obtain each trained hybrid expert model; This step can be understood as fine-tuning the large language model based on the hybrid expert model. Freeze the pre-trained linear layer networks, that is, keep the parameters of each linear layer network unchanged. That is, when the parameters of each pre-trained linear layer network are fixed, train each hybrid expert model to obtain each trained hybrid expert model.
[0087] Optionally, the parameters of the hybrid expert model branch may be updated using a back propagation algorithm, but is not limited thereto.
[0088] Step S703: Based on the pre-trained linear layer networks and the trained hybrid expert models, a trained large language model is obtained.
[0089] In the embodiment of the present application, the pre-trained linear layer networks and the trained hybrid expert models are integrated to obtain a trained large language model.
[0090] Optionally, the large language model in the embodiment of the present application can adopt an end-to-end training (fine-tuning) method, that is, after inferring the training samples through each hidden layer, the loss function is calculated to update the parameters of each hybrid expert model. Among them, the reasoning process may include: for the hidden layer that is not added to the hybrid expert model, the reasoning process is to input the result through the original linear layer branch output, and for the hidden layer that is added to the hybrid expert model, the input is passed through the gating network and the softmax activation function to generate each expert weight, which is used to calculate the weighted output of each expert network. Finally, the final hidden layer output is added to the original linear layer branch input. The specific implementation process can be found in the introduction above, which will not be repeated here.
[0091] In the embodiment of the present application, before performing the second training process on each hybrid expert model, the step may also include: initializing each hybrid expert model, wherein each hybrid expert model includes a dimensionality reduction network, a dimensionality increase network, and a gating network. Specifically, the step may include: Step SA: Initialize the parameters of the dimensionality reduction network according to the standard Gaussian distribution; That is, the parameters of the dimension reduction network in each expert network of each mixed expert model are initialized according to the standard Gaussian distribution.
[0092] Step SB: Initialize the parameters of the dimension-raising network to zero; That is, the parameters of the dimension-increasing network in each expert network of each mixed expert model are initialized to 0.
[0093] Step SC: Initialize the parameters of the gating network according to a predetermined method.
[0094] Among them, the predetermined method can be a random method, that is, the gated network that generates weights in each hybrid expert model randomly initializes parameters; or, the predetermined method can also be a predefined algorithm, which technical personnel in this application can set according to actual conditions, and the embodiments of the present application are not limited here.
[0095] Compared with the overall parameter fine-tuning method, the new efficient parameter fine-tuning method provided in the embodiment of the present application can reduce the hardware cost and time cost of model fine-tuning, and compared with the existing efficient parameter fine-tuning method (although the existing efficient parameter fine-tuning method claims to be able to achieve an effect close to that of the overall parameter fine-tuning method, in fact, there is still a certain distance between the existing efficient parameter fine-tuning method and the overall parameter fine-tuning method on more evaluation benchmarks), it can improve the fine-tuning performance of the model, that is, the embodiment of the present application can achieve the model performance that reaches or even exceeds that of the overall parameter fine-tuning method at the fine-tuning cost of the existing efficient parameter fine-tuning method.
[0096] In addition, the efficient model parameter fine-tuning method provided in the embodiment of the present application is pluggable because it introduces a hybrid expert model for fine-tuning, which is similar to a "model patch".
[0097] As an example, multiple sets of hybrid expert models may be trained under different fine-tuning data sets. That is, step S702 may specifically include: Step S7021: Acquire multiple text training sets, each text training set corresponds to a text task.
[0098] Step S7022: Based on each training set, each hybrid expert model is trained to obtain multiple sets of trained hybrid expert models.
[0099] Then step S703 may specifically include: obtaining trained large language models corresponding to a variety of text tasks based on the pre-trained linear layer networks and each set of trained hybrid expert models.
[0100] Different large language models can be applied to different tasks or scenarios (fine-tuned using corresponding text training sets). In the application process of large language models, different large language models can be loaded to introduce different fine-tuning data knowledge, realize rapid switching of model capabilities, and improve model flexibility, such as rapid switching between logical reasoning, code generation, and problem solving in different middle school subjects, but not limited to these.
[0101] On the other hand, multiple expert networks in the hybrid expert model can learn the knowledge of different sub-topics and sub-fields in the data separately, and then integrate the knowledge of these expert networks to predict new data. Compared with using a single network, learning multiple expert networks separately can reduce the learning difficulty of each expert network while ensuring the generalization performance of the entire system.
[0102] The efficient parameter fine-tuning method provided in the embodiments of the present application reduces the amount of trainable parameters in the fine-tuning process by introducing a lightweight neural network component (i.e., a hybrid expert model) to a pre-trained network model (i.e., a linear layer network). These modifications allow better adaptation to specific tasks while minimizing the computational overhead of adding task-specific parameters, which helps to perform fine-tuning more efficiently and effectively in NLP, making it easier to apply large language models to various business scenarios.
[0103] In addition to the above embodiments, the hybrid expert model branch may also be considered to be combined with other existing efficient parameter fine-tuning methods, such as Adapter Tuning or Prefix Tuning.
[0104] Among them, the adapter parameter efficient fine-tuning method inserts a double-layer perceptron after multiple hidden layers of the pre-trained large language model. In the embodiment of the present application, the double-layer perceptron and the hybrid expert model can be combined, and only the model parameters of this part are trained to achieve the effect of efficient parameter fine-tuning.
[0105] The efficient fine-tuning method of Prefix parameters, also known as the Prompt fine-tuning method, fine-tunes by splicing a small number of tokens of the same dimension in front of the input sequence to act as training parameters. Unlike the traditional [CLS (classification)] tag appended to the input sequence, Prefix fine-tuning adds several task-specific prefixes to guide the model in the direction of the required task. This prefix, combined with the task-specific labels in the training data, helps the model adapt to specific tasks more effectively. The advantage of Prefix fine-tuning is that it allows fine-tuning with minimal additional parameters, thereby achieving efficient adaptation. In an embodiment of the present application, the prefix can be combined with the introduction of a hybrid expert model to achieve the effect of efficient parameter fine-tuning.
[0106] It is also necessary to explain that the existing hybrid expert model is usually constructed at the overall network level, which results in the overall model being too large, increasing the time cost and hardware cost of training. The embodiment of the present application implements the hybrid expert model solution at a smaller granularity (combined with a single linear layer network), avoiding the problems of the existing hybrid expert model solution being large overall model scale and high training cost, and fully utilizing the performance of each expert model while introducing a smaller number of training parameters.
[0107] In general, the large language model provided in the embodiment of the present application introduces a hybrid expert model at a finer granularity, which can significantly reduce the overall parameter amount of the model and significantly reduce the time cost and hardware cost of model training compared to the overall parameter fine-tuning method and the existing hybrid expert model building method. Compared with the existing efficient parameter fine-tuning method, it can improve the fine-tuning performance of the model, and can also combine the outputs of different expert models to enable the model to achieve the integration of various capabilities, such as logical reasoning, code generation, solving math problems, etc., and the model is more flexible.
[0108] The text processing method provided in the embodiment of the present application can be specifically applied in a terminal device, or in a server, or can be completed by a plurality of computer devices or devices with computing capabilities in collaboration, and different computer devices or devices each complete a part of the steps of each method provided by the implementation of the present application. For example, one computer device or device can be responsible for pre-training a linear layer network, another computer device or device can be responsible for fine-tuning a large language model (training a mixed expert model), and another computer device or device can be responsible for using a large language model for text processing, etc., but is not limited thereto.
[0109] Optionally, the devices for text processing, training linear layer networks, and training hybrid expert models (i.e., fine-tuning large language models) may be the same device or different devices. Those skilled in the art may deploy them according to actual conditions, and the embodiments of the present application are not limited thereto.
[0110] Optionally, the terminal device may be a smart phone, tablet computer, laptop computer, desktop computer, smart wearable device (such as watch, glasses, etc.), smart TV, smart speaker, vehicle terminal, personal digital assistant, portable multimedia player, navigation device, etc., but is not limited thereto. The server may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0111] The present application embodiment provides a text processing device, such as Figure 8 As shown, the text processing device 80 may include: a first acquisition module 801, a second acquisition module 802, a first processing module 803 and a second processing module 804, wherein: A first acquisition module 801 is used to acquire a large language model and a target text, wherein the large language model includes a plurality of hidden layers, each hidden layer includes a linear layer network, and at least one hidden layer also includes a hybrid expert model; A second acquisition module 802 is used to obtain input features of each hidden layer based on the target text; The first processing module 803 is used for, for each hidden layer including the hybrid expert model, performing a first projection process on the input features of the hidden layer through a linear layer network to obtain a first hidden feature, performing a second projection process on the input features of the hidden layer through the hybrid expert model to obtain a second hidden feature, and fusing the first hidden feature and the second hidden feature to obtain an output feature of the hidden layer; The second processing module 804 is used to obtain the processing result of the target text based on the output features of the last hidden layer of the large language model.
[0112] In an optional implementation, the hybrid expert model includes at least two expert networks and a gating network. When the first processing module 803 is used to perform a second projection process on the input feature of the hidden layer through the hybrid expert model to obtain the second hidden feature, it is specifically used to: The input features of the hidden layer are respectively subjected to second projection processing through each expert network to obtain corresponding third hidden features; Based on the input features of the hidden layer, projection processing is performed through the gating network to obtain the weights corresponding to each third hidden feature; Based on the weights corresponding to the third hidden features, the third hidden features are weightedly fused to obtain the second hidden feature.
[0113] In an optional implementation, the expert network includes a connected dimension reduction network and a dimension increase network, and the first processing module 803 is used to perform projection processing based on the input features of the hidden layer through the gating network to obtain the weights corresponding to each third hidden feature, specifically for at least one of the following methods: Through the gating network, the input features of the hidden layer are projected into weights corresponding to each third hidden feature; Through the gating network, the first feature of the input feature of the hidden layer after dimension reduction processing by the dimension reduction network is projected into the weights corresponding to each third hidden feature; Through the gating network, the input features of the hidden layer are successively reduced in dimension through the dimensionality reduction network and the dimensionality increase network, and the second features after dimensionality increase are projected into the weights corresponding to each third hidden feature.
[0114] In an optional implementation, the expert network includes a connected dimensionality reduction network and a dimensionality increase network. When the first processing module 803 is used to process the input feature of the hidden layer through any expert network to obtain the corresponding third hidden feature, it is specifically used to: Obtain the degree of change of the first dimension corresponding to the expert network; Based on the number of expert networks included in the hybrid expert model, the variation degree of the first dimension is reduced to obtain the variation degree of the second dimension; Based on the degree of change of the second dimension, the input features of the hidden layer are sequentially processed by the dimensionality reduction network for dimensionality reduction and the dimensionality increase network for dimensionality increase, so as to obtain the corresponding third hidden features; The degree of dimension change represents the degree of dimensionality reduction and / or dimensionality increase of the feature in the expert network.
[0115] In an optional implementation, the first processing module 803, when used to reduce the first dimension variation degree based on the number of expert networks included in the hybrid expert model to obtain the second dimension variation degree, is specifically used to: The degree of change in the first dimension is divided by the number of expert networks included in the mixed expert model to obtain the degree of change in the second dimension.
[0116] In an optional embodiment, the linear layer network includes at least one of an attention subnetwork, a feedforward model subnetwork, and a multilayer perceptron subnetwork.
[0117] In an optional implementation, the text processing apparatus further includes a training module 804, which is used to obtain a large language model by the following training method: Get the pre-trained linear layer networks; Under the condition of freezing the network parameters of each pre-trained linear layer network, training each hybrid expert model to obtain each trained hybrid expert model; Based on the pre-trained linear layer networks and the trained mixed expert models, a trained large language model is obtained.
[0118] In an optional implementation, each hybrid expert model includes a dimensionality reduction network, a dimensionality increase network, and a gating network. Before being used to train each hybrid expert model, the training module 804 is further used to: Initialize the parameters of the dimensionality reduction network according to the standard Gaussian distribution; Initialize the parameters of the dimension-raising network to zero; Initialize the parameters of the gating network in a predetermined manner.
[0119] In an optional implementation, the training module 804 is used to train each hybrid expert model to obtain each trained hybrid expert model, and is specifically used to: Obtain multiple text training sets, each text training set corresponds to a text task; Based on each training set, each hybrid expert model is trained to obtain multiple sets of trained hybrid expert models; When the training module 804 is used to obtain a trained large language model based on each pre-trained linear layer network and each trained hybrid expert model, it is specifically used to: Based on the pre-trained linear layer networks and each set of trained hybrid expert models, a large language model corresponding to a variety of text tasks is obtained.
[0120] The device of the embodiments of the present application can execute the method provided by the embodiments of the present application, and the implementation principles are similar. The actions performed by each module in the device of each embodiment of the present application correspond to the steps in the method of each embodiment of the present application. For the detailed functional description of each module of the device and the beneficial effects produced, please refer to the description in the corresponding method shown in the previous text, which will not be repeated here.
[0121] An embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory, and the processor executes the above-mentioned computer program to implement the steps of each method embodiment.
[0122] In an alternative embodiment, an electronic device is provided, such as Fig. 9 As shown, Fig. 9 The electronic device 900 shown includes: a processor 901 and a memory 903. The processor 901 and the memory 903 are connected, such as through a bus 902. Optionally, the electronic device 900 may also include a transceiver 904, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 904 is not limited to one, and the structure of the electronic device 900 does not constitute a limitation on the embodiments of the present application.
[0123] The processor 901 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor 901 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0124] The bus 902 may include a path to transmit information between the above components. The bus 902 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 902 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig. 9 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0125] The memory 903 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), magnetic disk storage medium, other magnetic storage devices, or any other medium that can be used to carry or store computer programs and can be read by a computer, without limitation herein.
[0126] The memory 903 is used to store the computer program for executing the embodiment of the present application, and the execution is controlled by the processor 901. The processor 901 is used to execute the computer program stored in the memory 903 to implement the steps shown in the above method embodiment.
[0127] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps and corresponding contents of the aforementioned method embodiment can be implemented.
[0128] The embodiment of the present application also provides a computer program product, including a computer program, which can implement the steps and corresponding contents of the aforementioned method embodiment when executed by a processor.
[0129] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that shown or described in the drawings.
[0130] It should be understood that, although each operation step is indicated by arrows in the flowchart of the embodiment of the present application, the implementation order of these steps is not limited to the order indicated by the arrows. Unless clearly stated herein, in some implementation scenarios of the embodiment of the present application, the implementation steps in each flowchart can be performed in other orders according to demand. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on actual implementation scenarios. Some or all of these sub-steps or stages may be executed at the same time, and each sub-step or stage in these sub-steps or stages may also be executed at different times respectively. In different scenarios of execution time, the execution order of these sub-steps or stages may be flexibly configured according to demand, and the embodiment of the present application does not limit this.
[0131] The above are only optional implementation methods for some implementation scenarios of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the technical concept of the scheme of the present application, other similar implementation methods based on the technical ideas of the present application are also within the protection scope of the embodiments of the present application.
Claims
1. A text processing method, It is characterized in that include: Acquire a large language model and a target text, wherein the large language model includes a plurality of hidden layers, each hidden layer includes a linear layer network, and at least one hidden layer also includes a hybrid expert model; Based on the target text, obtaining input features of each hidden layer; For each hidden layer including the hybrid expert model, performing a first projection process on the input features of the hidden layer through the linear layer network to obtain a first hidden feature, performing a second projection process on the input features of the hidden layer through the hybrid expert model to obtain a second hidden feature, and fusing the first hidden feature and the second hidden feature to obtain an output feature of the hidden layer; Based on the output features of the last hidden layer of the large language model, a processing result of the target text is obtained.
2. The text processing method according to claim 1, It is characterized in that The hybrid expert model includes at least two expert networks and a gating network, and the step of performing a second projection process on the input feature of the hidden layer through the hybrid expert model to obtain a second hidden feature includes: The input features of the hidden layer are respectively subjected to second projection processing through each of the expert networks to obtain corresponding third hidden features; Based on the input features of the hidden layer, projection processing is performed through the gating network to obtain weights corresponding to each of the third hidden features; Based on the weights corresponding to the third hidden features, weighted fusion is performed on the third hidden features to obtain the second hidden feature.
3. The text processing method according to claim 2, It is characterized in that The expert network includes a connected dimension reduction network and a dimension increase network, and the input features based on the hidden layer are projected through the gating network to obtain weights corresponding to each of the third hidden features, including at least one of the following methods: Projecting the input features of the hidden layer into weights corresponding to each of the third hidden features through the gating network; Through the gating network, projecting the first feature of the input feature of the hidden layer after dimension reduction processing by the dimension reduction network into the weights corresponding to each of the third hidden features; Through the gating network, the input features of the hidden layer are projected into weights corresponding to each of the third hidden features after the second features are successively reduced in dimension and increased in dimension by the dimensionality reduction network and the dimensionality increase network.
4. The text processing method according to claim 2, It is characterized in that The expert network includes a connected dimensionality reduction network and a dimensionality increase network. The input feature of the hidden layer is processed by any of the expert networks to obtain a corresponding third hidden feature, including: Obtaining a degree of change of the first dimension corresponding to the expert network; Based on the number of the expert networks included in the hybrid expert model, reducing the first dimension change degree to obtain a second dimension change degree; Based on the variation degree of the second dimension, the input features of the hidden layer are sequentially processed by the dimensionality reduction network for dimensionality reduction and by the dimensionality increase network for dimensionality increase, so as to obtain corresponding third hidden features; The degree of dimension change represents the degree of dimensionality reduction and / or dimensionality increase of the feature in the expert network.
5. The text processing method according to claim 4, It is characterized in that The reducing the first dimension variation degree based on the number of the expert networks included in the hybrid expert model to obtain the second dimension variation degree includes: The first dimension variation degree is divided by the number of the expert networks included in the hybrid expert model to obtain the second dimension variation degree.
6. The text processing method according to claim 1, It is characterized in that The linear layer network includes at least one of an attention sub-network, a feedforward model sub-network and a multi-layer perceptron sub-network.
7. The text processing method according to any one of claims 1 to 6, It is characterized in that The large language model is obtained by the following training method: Obtaining the pre-trained linear layer networks; Under the condition of freezing the network parameters of each of the pre-trained linear layer networks, training each of the hybrid expert models to obtain each of the trained hybrid expert models; Based on the pre-trained linear layer networks and the trained hybrid expert models, the trained large language model is obtained.
8. A text processing device, It is characterized in that include: A first acquisition module is used to acquire a large language model and a target text, wherein the large language model includes a plurality of hidden layers, each hidden layer includes a linear layer network, and at least one hidden layer also includes a hybrid expert model; A second acquisition module is used to obtain input features of each hidden layer based on the target text; A first processing module is used for, for each hidden layer including the hybrid expert model, performing a first projection process on the input features of the hidden layer through the linear layer network to obtain a first hidden feature, performing a second projection process on the input features of the hidden layer through the hybrid expert model to obtain a second hidden feature, and fusing the first hidden feature and the second hidden feature to obtain an output feature of the hidden layer; The second processing module is used to obtain the processing result of the target text based on the output features of the last hidden layer of the large language model.
9. An electronic device comprising a memory, a processor and a computer program stored in the memory, It is characterized in that The processor executes the computer program to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Video understanding method and device based on double-layer hybrid expert model
CN119964043A
A video understanding method and device based on a double-layer hybrid expert model
CN119964043B
Chinese smoothness assessment method and apparatus, electronic device, and readable medium
WO2026123854A1
