Large language model adaptive fusion method, device and equipment
Through fine-tuning the base model and the adaptive fusion method of the gating mechanism, the nonlinear conflict and high-frequency feature loss problems of the model fusion method in the existing technology are solved, and efficient and accurate multi-vertical domain task processing is achieved.
Patent Information
- Application Number
- CN202511105806.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-08
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2045-08-08
AI Technical Summary
Existing model fusion methods such as linear averaging and task vector distillation cannot effectively resolve the nonlinear conflicts between task vectors, and have high training costs, resulting in poor performance of the fusion model on certain tasks.
By fine-tuning the base model based on multiple vertical domain datasets, calculating the task vector, and introducing a gating mechanism to dynamically adjust the fusion weight, the gating parameters are updated using Bernoulli sampling and cross-entropy loss to achieve adaptive fusion.
It improves the flexibility and accuracy of the model in multi-vertical domain scenarios, reduces training costs and time complexity, avoids linear conflicts and high-frequency feature loss, and enhances the adaptability and generalization capabilities of the model.
Smart Images

Figure CN120597991A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of large language model fusion, and in particular relates to a large language model adaptive fusion method, device and equipment. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] In recent years, large language models (LLMs) have demonstrated remarkable general capabilities in multiple fields, such as question answering, code generation, and mathematical computation. However, as the application of LLMs in specific fields continues to increase, there is a need to support tasks that incorporate both general and domain-specific knowledge. To achieve this goal, performance optimization methods based on model fusion have been proposed. Specifically, multiple task models obtained through further fine-tuning of the same base model (such as a general large model, CLIP, ResNet-IN1K, etc.) can be merged together to integrate the model capabilities of multiple fields and improve overall efficiency. However, although model fusion technology has effectively improved the multi-task capabilities of the model, existing methods still have limitations.
[0004] Currently, common model fusion methods include linear averaging (such as TIES-Merging) and task vector distillation. Linear averaging achieves fusion by taking a weighted average of model weights, but this method cannot resolve nonlinear conflicts between task vectors. Task vector distillation distills knowledge from multiple models into a single model, but this process results in the loss of high-frequency features and significantly increases training costs. Summary of the Invention
[0005] In view of this, the present invention provides a large language model adaptive fusion method, device and equipment to obtain a fusion model applicable to multiple vertical domains.
[0006] One aspect of the present invention provides a large language model adaptive fusion method, comprising the following steps: Fine-tune the base model based on multiple vertical domain data sets to obtain multiple vertical domain models; Calculate the incremental vector of the model parameters of each vertical domain model relative to the base model parameters, recorded as the task vector; A training set is obtained by sampling from the union of the plurality of vertical domain data sets; The base model is fixed and the gating parameters are trained. During the training process, for each training sample, the semantic feature vector of the input text of the training sample is extracted based on the base model, and a gating probability matrix is calculated according to the current gating parameters. The fusion weight of each task vector is calculated according to the gating probability matrix. The fusion model parameters are obtained based on the base model parameters, the task vector and the corresponding fusion weight. The fusion model parameters are assigned to the base model to obtain a new fusion model. For the new fusion model, the gating parameters are updated through model feedforward and backpropagation, and the training process is repeated until the termination condition is met.
[0007] In some embodiments, after obtaining multiple vertical domain data sets, each sample data is preprocessed. Specifically, each sample data includes input text and output text, and both the input text and the output text are segmented and converted into a numerical sequence.
[0008] In some embodiments, multiple batch training sets are sampled from the union of the multiple vertical domain data sets, each batch training set includes sample data of multiple vertical domains, and each round of training is performed based on one batch training set.
[0009] In some embodiments, during the training process, for each training sample, an intermediate semantic feature vector is extracted based on each feature extraction layer of the base model to obtain a multi-layer semantic feature vector; For each layer of semantic feature vectors, the gating probability matrix is calculated according to the current gating parameters, and the gating probability matrices corresponding to each layer are averaged to obtain the overall gating probability matrix; Calculate the fusion weight for each task vector based on the overall gating probability matrix; Based on the base model parameters, task vectors and corresponding fusion weights, the fusion model parameters of each layer are obtained.
[0010] In some embodiments, after obtaining the gating probability matrix, Bernoulli sampling is first performed on the gating probability matrix to generate a binary gating vector, and the fusion weight for each task vector is calculated based on the gating vector.
[0011] In some embodiments, the normalized fusion weight for each task vector is calculated based on the conflict factor and the gating vector between the vertical domain tasks, wherein the normalized fusion weight for the i-th vertical domain task vector is The calculation formula is:
[0012] in, is the value of the gate vector for the i-th vertical domain task, represents the conflict factor between the i-th vertical domain task and other vertical domain tasks, is a constant, and N is the number of vertical domains.
[0013] In some embodiments, the conflict factor between the i-th vertical domain task and other vertical domain tasks is The calculation formula is:
[0014] in, S ij is the similarity between the task vectors of the i-th vertical domain and the j-th vertical domain, and N is the number of vertical domains.
[0015] In some embodiments, updating the gating parameters through model feedforward and backpropagation includes: predicting the output of each training sample based on the input text and the corresponding new fusion model; calculating the cross-entropy loss between the predicted output distribution and the actual output distribution; estimating the gating gradient based on the cross-entropy loss, and updating the gating parameters based on the gating gradient.
[0016] A second aspect of the present invention provides a large language model adaptive fusion device, comprising: The vertical domain model fine-tuning module is configured to: fine-tune the base model based on multiple vertical domain data sets to obtain multiple vertical domain models; The task vector calculation module is configured to: calculate an incremental vector of the model parameters of each vertical domain model relative to the base model parameters, which is recorded as a task vector; A training data acquisition module is configured to: sample a training set from the union of the plurality of vertical domain data sets; The model training module is configured to: fix the base model and train the gating parameters; during the training process, for each training sample, extract the semantic feature vector of the task text based on the base model, calculate the gating probability matrix based on the current gating parameters; calculate the fusion weight of each task vector based on the gating probability matrix; and obtain the fusion model parameters based on the base model parameters, the task vector and the corresponding fusion weight; The gating parameter update module is configured to assign the fusion model parameters to the base model to obtain a new fusion model, update the gating parameters for the new fusion model through model feedforward and backpropagation, and repeat the training process until the termination condition is met.
[0017] A third aspect of the present invention provides an electronic device, comprising a processor and a memory, wherein the memory stores computer instructions, and when the computer instructions are executed by the processor, the electronic device executes the method described.
[0018] One or more of the above technical solutions obtain multiple vertical domain models through fine-tuning and calculate task vectors, which can accurately capture the unique characteristics and differences of each vertical domain. Through the gating mechanism, the model can dynamically adjust the fusion weight of the task vector according to the semantic features of the input text, thereby realizing adaptive prediction of different vertical domains and improving the flexibility and accuracy of the model in multi-vertical domain scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0020] Figure 1 An architectural diagram of a computer system provided by an exemplary embodiment of the present application is shown; Figure 2 A flowchart of a large language model adaptive fusion method provided by an exemplary embodiment of the present application is shown; Figure 3 A structural block diagram of a large language model adaptive fusion device provided by an exemplary embodiment of the present application is shown. DETAILED DESCRIPTION
[0021] The following describes embodiments of the present application in more detail with reference to the accompanying drawings. Although certain embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be construed as limited to the embodiments described herein. Instead, these embodiments are provided to provide a more thorough and complete understanding of the present application. It should be understood that the drawings and embodiments of the present application are for illustrative purposes only and are not intended to limit the scope of protection of the present application.
[0022] In the description of the embodiments of the present application, the term “including” and similar terms should be understood as open inclusion, that is, “including but not limited to.” The term “based on” should be understood as “at least partially based on.”
[0023] As described in the background technology, among the common model fusion methods, the linear averaging method is a relatively simple fusion strategy, which achieves fusion by taking a weighted average of the weights of different task models. The advantage of this method is that the calculation process is relatively simple and easy to implement. However, the linear averaging method has obvious limitations. It cannot effectively resolve nonlinear conflicts between task vectors. When the model weights of different tasks have directional conflicts in the vector space, simple weighted averaging may cause the weights to cancel each other out, thereby reducing the performance of the fusion model. This phenomenon is particularly common in multi-task scenarios, because the optimal weights of different tasks often point in different directions, and direct linear combinations are difficult to capture these complex relationships.
[0024] Task vector distillation takes a different approach, achieving fusion by distilling the knowledge of multiple task models into a single model. The core idea of this approach is to compress and integrate the features and knowledge of multiple models to produce a comprehensive model with better performance. However, task vector distillation faces numerous challenges in practical applications. First, the distillation process can lead to the loss of high-frequency features. High-frequency features often contain subtle but important information that is crucial for the model's performance on certain tasks. During the distillation process, due to the compression and simplification of information, these high-frequency features may be ignored or lost, affecting the accuracy of the fused model. Second, task vector distillation significantly increases the training cost. The distillation process requires additional training steps and computational resources, making the entire fusion process more complex and time-consuming. Furthermore, the information loss and increased training cost during the distillation process often result in the fused model performing worse than the individually trained models on certain tasks, limiting its widespread adoption in practical applications.
[0025] Figure 1 FIG. 1 is a block diagram of a computer system 100 according to an exemplary embodiment of the present application. The computer system 100 includes a server 110 and a terminal 120 .
[0026] Server 110 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides cloud computing services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), as well as basic cloud computing services such as big data and artificial intelligence platforms.
[0027] Terminal 120 can be an electronic device such as a mobile phone, tablet computer, vehicle-mounted terminal (vehicle computer), wearable device, PC (Personal Computer), unmanned reservation terminal, smart speaker, etc. Terminal 120 is used to collect task data from different vertical domains and construct vertical domain datasets.
[0028] The server 110 and the terminal 120 may communicate with each other via a network, such as a wired or wireless network.
[0029] Those skilled in the art will appreciate that the number of the terminals 120 may be greater or less. For example, the number of the terminals 120 may be only one, or may be dozens, hundreds, or more. The present embodiment does not limit the number or device type of the terminals 120.
[0030] Figure 2A flowchart of a large language model adaptive fusion method provided by an exemplary embodiment of the present application is shown, wherein the method is executed by a server or a terminal, which may be Figure 1 The server or terminal shown. The method specifically includes the following steps: S101: fine-tuning the base model based on multiple vertical domain data sets to obtain multiple vertical domain models; S102: Calculate the incremental vector of the model parameters of each vertical domain model relative to the base model parameters, recorded as the task vector; S103: Sampling from the union of the plurality of vertical domain data sets to obtain a training set; S104: Fixing the base model and training the gating parameters; during the training process, for each training sample, extracting the semantic feature vector of the input text of the training sample based on the base model, calculating the gating probability matrix according to the current gating parameters; calculating the fusion weight of each task vector according to the gating probability matrix; and obtaining the fusion model parameters based on the base model parameters, the task vector and the corresponding fusion weight; S105: Assign the fusion model parameters to the base model to obtain a new fusion model. For the new fusion model, update the gating parameters through model feedforward and backpropagation, and repeat steps S104 and S105 until the termination condition is met.
[0031] This method achieves efficient fusion and adaptive prediction of multiple vertical domain datasets by fine-tuning the base model and combining it with a gating mechanism. First, by fine-tuning multiple vertical domain models and calculating the task vector, it can accurately capture the unique characteristics and differences of each vertical domain, providing rich semantic information for subsequent fusion. At the same time, the introduction of the gating mechanism enables the model to dynamically adjust the fusion weights of the task vector based on the semantic features of the input text, thereby achieving adaptive prediction for different vertical domains and improving the model's flexibility and accuracy in multi-vertical domain scenarios. In addition, this method fixes the base model during training and only trains the gating parameters, greatly reducing the computational cost and time complexity of training.
[0032] In step S101, the base model M can be a general language model such as GPT, or a language model such as BERT. N}, corresponding to N different target areas, namely vertical domains. Different vertical domains include intelligent question answering, code generation, mathematical calculations, etc. in the fields of medicine, law, and finance.
[0033] In some embodiments, after acquiring multiple vertical domain datasets, each sample data item in each vertical domain dataset is preprocessed. Each sample data item includes input text and output text, representing the requirements and solutions of a task. Both the input and output texts are segmented and tokenized. Tokenization converts the text into a numerical token ID, typically a sequence of integer values, for use as input and output of the model.
[0034] Based on each preprocessed vertical domain data set, the base model M is fine-tuned to obtain multiple vertical domain models {M1, M2, ..., M N}.
[0035] In step S102, the incremental vector of the model parameters of each vertical domain model relative to the base model parameters is calculated and recorded as the task vector {Δθ1, Δθ2, ..., Δθ N}. Task vector Δθ i represents the changes in model parameters on the tasks in vertical domain i, which reflect the task-specific knowledge of vertical domain i.
[0036] In step S103, the union of the plurality of vertical domain data sets is obtained. Multiple training batches are obtained by sampling from the union of multiple vertical domain datasets. Each training batch contains sample data from multiple vertical domains. Each round of training is based on a batch of training sets. By sampling the training set from the union of multiple vertical domain datasets, the diversity of cross-domain data can be fully utilized, enhancing the generalization ability of the final fusion model. It can be understood that in the training set, the input and output text of each sample data is a pre-processed numeralized token ID.
[0037] In step S104, the base model is fixed and the gate parameters are trained. During the training process, the following steps are performed for each training sample to obtain a new fusion model. Specifically, the following steps are performed: S1041: extracting intermediate semantic feature vectors based on each feature extraction layer of the base model to obtain a multi-layer semantic feature vector; S1042: For each layer of semantic feature vectors, a gating probability matrix is calculated according to the current gating parameters, and the gating probability matrices corresponding to each layer are averaged to obtain an overall gating probability matrix; S1043: Calculating the fusion weight for each task vector according to the overall gating probability matrix; S1044: Based on the base model parameters, the task vector and the corresponding fusion weight, the fusion model parameters of each layer are obtained.
[0038] By introducing the gating mechanism, the model can dynamically adjust the fusion weight of the task vector according to the semantic features of the input text. Since the training set covers the input and output of different tasks, the model can learn the differences and similarities between tasks in different target domains, thereby achieving adaptive prediction for different vertical domains. The obtained gated probability matrix G (G∈R N ) for each column vector G i Indicates the i vertical domain tasks and current input x Through these probabilities, the vertical domain that is most relevant to the current input can be dynamically selected.
[0039] In step S1041, based on each feature extraction layer of the base model, the intermediate semantic feature vectors are extracted to obtain multi-layer semantic feature vectors. x , the multi-layer semantic feature vector is expressed as h x =Encoder( x ), h x ∈R d , d is the number of feature extraction layers of the base model.
[0040] In step S1042, the calculation formula of the gate probability matrix is: G=σ(W·h x +b), where W∈R d×N is a learnable weight matrix, b∈R N is a learnable bias vector, and σ is a Sigmoid function that maps the output value to the [0,1] interval.
[0041] In step S1043, after obtaining the gated probability matrix, the gated probability matrix is first subjected to Bernoulli sampling to generate a binary gate vector, which converts the continuous probability values in the gated probability matrix into discrete values, thereby making the relevant vertical domain clearer. Specifically, the gated probability matrix is subjected to Bernoulli sampling to generate a binary gate vector g=[g1,g2,...,g N ], that is, g i ~Bernoulli(G i ), where Bernoulli represents Bernoulli sampling. For example, if the input text is about the medical field, the gating probability of the medical task in the gating probability matrix G is higher. Through Bernoulli sampling, the g of the medical task is i More likely to be 1, g for other tasks i More likely to be 0.
[0042] It can be understood that for each layer of semantic feature vector, a gating vector is obtained. According to the correlation between the current task text and each vertical domain task reflected in the gating vector, the fusion weight corresponding to each task vector can be calculated.
[0043] In order to reduce the conflict between task vectors, in some embodiments, the degree of conflict between tasks is also considered when calculating the fusion weight. Specifically, for each vertical domain task, the similarity between the vertical domain task vector and each other vertical domain task vector is calculated. Based on the accumulated value of these similarities, the conflict factor is calculated. The conflict factor calculation formula between the i-th vertical domain task vector and other vertical domain task vectors is:
[0044] in, S ij is the similarity between task vectors. If cosine similarity is used, the formula is: , where Δ θ i and Δ θ j is the task vector, and cos represents the cosine similarity.
[0045] The normalized weight calculation formula corresponding to the task vector of the i-th vertical domain is:
[0046] Here, ε is a constant that prevents the denominator from being zero.
[0047] The conflict factor is used to quantify the degree of conflict, making the calculation of the fusion weight more accurate. It can dynamically adjust the weight distribution according to the degree of conflict between tasks, thereby better balancing the contributions of different tasks during the fusion process and avoiding performance degradation caused by conflicts between task vectors.
[0048] In step S1044, based on the base model parameters, the task vector and the corresponding fusion weight, the calculation formula for the fusion model parameters is obtained as follows:
[0049] in, represents the fusion model parameters, Represents the base model parameters.
[0050] It can be understood that after the above steps, a set of fusion model parameters is obtained for each training sample, including the fusion model parameters calculated by the semantic feature vector and the gating vector of each layer, and then multiple new fusion models can be obtained.
[0051] In step S105, multiple sets of fusion model parameters are assigned to the base model to obtain multiple new fusion models. Then, the model feedforward is executed to predict the output of each training sample based on the input text and the corresponding new fusion model; the cross entropy loss between the predicted output distribution and the actual output distribution is calculated. L The model feedforward evaluates the performance of the model through the loss function, providing gradient information for back propagation. Then, through back propagation, the gate gradient is estimated based on the cross entropy loss, and the gate parameters are updated based on the gate gradient.
[0052] Among them, the gate gradient is the gradient of the gate probability matrix. Since the gate vector g It is a discrete value obtained by Bernoulli sampling, and it is impossible to calculate the gradient directly. Therefore, a direct estimate is used to approximate the gradient, that is, the gradient of the gate probability matrix G is approximated using the gradient of the gate vector g. .
[0053] For the new fusion model, the gating parameters are updated through model feedforward and backpropagation, and steps S104 and S105 are repeated based on other batches of training sets until the termination condition is met. It is understood that the termination condition can be that the number of training samples reaches a preset upper limit or the loss function converges to a certain value.
[0054] This gated parameter update mechanism based on cross-entropy loss can effectively improve the model's adaptability to different inputs, ensure that the model is adaptable to multi-vertical domain tasks, and at the same time improve the model's generalization ability and stability.
[0055] Compared with traditional model fusion methods, the methods provided in one or more of the above embodiments have the following advantages: in terms of nonlinear conflict processing, the fusion weights are normalized through conflict perception, avoiding parameter cancellation caused by linear averaging; in terms of information retention capability, direct parameter operations and dynamic gating mechanisms are used to avoid the risk of high-frequency feature loss due to model distillation; in terms of domain adaptability, the gated probability matrix is updated through Bernoulli sampling and model training, which can achieve adaptive adaptation to the semantics of the input text; in terms of computational efficiency, since only the gating parameters are trained, the number of parameters is much smaller than the total number of model parameters, which greatly improves the computational efficiency.
[0056] Based on the above method, one or more embodiments of the present invention further provide a large language model adaptive fusion device, including: a vertical domain model fine-tuning module 201, configured to: fine-tune the base model based on multiple vertical domain data sets to obtain multiple vertical domain models; a task vector calculation module 202, configured to: calculate the incremental vector of the model parameters of each vertical domain model relative to the base model parameters, recorded as the task vector; a training data acquisition module 203, configured to: sample from the union of the multiple vertical domain data sets to obtain a training set; a model training module 204, configured to: fix the base model, The gating parameters are trained; during the training process, for each training sample, the semantic feature vector of the task text is extracted based on the base model, and the gating probability matrix is calculated according to the current gating parameters; the fusion weight of each task vector is calculated according to the gating probability matrix; the fusion model parameters are obtained based on the base model parameters, the task vector and the corresponding fusion weight; the gating parameter update module 205 is configured to: assign the fusion model parameters to the base model to obtain a new fusion model, and for the new fusion model, update the gating parameters through model feedforward and backpropagation, and repeat the training process until the termination condition is met.
[0057] The vertical domain model fine-tuning module 201 is also configured to execute: obtaining multiple vertical domain data sets, and preprocessing each sample data therein, specifically: each sample data includes input text and output text, and both the input text and the output text are segmented and converted into numerical sequences.
[0058] In the training data acquisition module 203, multiple batch training sets are sampled from the union of the multiple vertical domain data sets, each batch training set includes sample data of multiple vertical domains, and each round of training is performed based on one batch training set.
[0059] In the model training module 204, for each training sample, the intermediate semantic feature vector is extracted based on each feature extraction layer of the base model to obtain a multi-layer semantic feature vector; for each layer of semantic feature vector, the gating probability matrix is calculated according to the current gating parameters, and the gating probability matrix corresponding to each layer is averaged to obtain the overall gating probability matrix; the fusion weight for each task vector is calculated based on the overall gating probability matrix; based on the base model parameters, the task vector and the corresponding fusion weight, the fusion model parameters of each layer are obtained.
[0060] In addition, after obtaining the overall gating probability matrix, Bernoulli sampling is first performed on the gating probability matrix to generate a binary gating vector, and the fusion weight for each task vector is calculated based on the gating vector.
[0061] One or more embodiments of the present invention further provide an electronic device that can be used to implement the method in the above embodiments. The electronic device includes one or more processors, one or more memories coupled to the processors, and a communication module coupled to the processors.
[0062] The memory in the embodiment of the present invention is used to store various types of data to support Figure 2 Execution of the method shown in .
[0063] It is understood that the memory can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. The memory in the embodiment of the present invention can store the following: Figure 2 The computer programs corresponding to the steps in the method shown in . The operating system includes various system programs, such as a framework layer, a core library layer, and a driver layer, which are used to implement various basic services and handle hardware-based tasks. The application program can include various application programs.
[0064] As an example, a processor can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0065] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer readable medium, the computer program including a computer program for executing Figure 2 In such an embodiment, the computer program can be downloaded and installed from a network via the communication portion and / or installed from a removable medium. When the computer program is executed by the central processing unit, the various functions defined in the apparatus of the present application are performed.
[0066] in, Figure 2 The computer program instructions corresponding to the method shown can also be stored in a computer readable memory that can guide a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0067] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention are intended to be within the scope of protection of the present invention.
Claims
1. A large language model adaptive fusion method, characterized in that: The following steps are involved: Fine-tune the base model based on multiple vertical domain data sets to obtain multiple vertical domain models; Calculate the incremental vector of the model parameters of each vertical domain model relative to the base model parameters, recorded as the task vector; A training set is obtained by sampling from the union of the plurality of vertical domain data sets; Fixing the base model and training the gating parameters; During the training process, for each training sample, the semantic feature vector of the input text of the training sample is extracted based on the base model, and the gate probability matrix is calculated according to the current gate parameters; the fusion weight of each task vector is calculated according to the gate probability matrix; Based on the base model parameters, task vectors and corresponding fusion weights, the fusion model parameters are obtained; The fusion model parameters are assigned to the base model to obtain a new fusion model. For the new fusion model, the gating parameters are updated through model feedforward and backpropagation, and the training process is repeated until the termination condition is met.
2. The large language model adaptive fusion method according to claim 1, characterized in that: After obtaining multiple vertical domain data sets, each sample data is preprocessed. Specifically, each sample data includes input text and output text, and both the input text and the output text are segmented and converted into numerical sequences.
3. The large language model adaptive fusion method according to claim 1, characterized in that: Multiple batch training sets are sampled from the union of the multiple vertical domain data sets, each batch training set includes sample data of multiple vertical domains, and each round of training is performed based on one batch training set.
4. The large language model adaptive fusion method according to claim 1, characterized in that: During the training process, for each training sample, the intermediate semantic feature vector is extracted based on each feature extraction layer of the base model to obtain a multi-layer semantic feature vector; For each layer of semantic feature vectors, the gating probability matrix is calculated according to the current gating parameters, and the gating probability matrices corresponding to each layer are averaged to obtain the overall gating probability matrix; Calculate the fusion weight for each task vector based on the overall gating probability matrix; Based on the base model parameters, task vectors and corresponding fusion weights, the fusion model parameters of each layer are obtained.
5. The large language model adaptive fusion method according to any one of claims 1 to 4, characterized in that: After obtaining the gate probability matrix, Bernoulli sampling is first performed on the gate probability matrix to generate a binary gate vector, and the fusion weight for each task vector is calculated based on the gate vector.
6. The large language model adaptive fusion method according to claim 5, characterized in that: According to the conflict factors and gate vectors between vertical domain tasks, the normalized fusion weight for each task vector is calculated, where the normalized fusion weight for the i-th vertical domain task vector is The calculation formula is: in, is the value of the gate vector for the i-th vertical domain task, represents the conflict factor between the i-th vertical domain task and other vertical domain tasks, is a constant, and N is the number of vertical domains.
7. The large language model adaptive fusion method according to claim 6, characterized in that: The conflict factor between the i-th vertical domain task and other vertical domain tasks The calculation formula is: in, S ij is the similarity between the task vectors of the i-th vertical domain and the j-th vertical domain, and N is the number of vertical domains.
8. The large language model adaptive fusion method according to claim 1, characterized in that: Through model feedforward and backpropagation, updating the gating parameters includes: predicting the output based on the input text of each training sample and the corresponding new fusion model; calculating the cross-entropy loss between the predicted output distribution and the actual output distribution; estimating the gating gradient based on the cross-entropy loss, and updating the gating parameters based on the gating gradient.
9. A large language model adaptive fusion device, characterized in that: include: The vertical domain model fine-tuning module is configured to: fine-tune the base model based on multiple vertical domain data sets to obtain multiple vertical domain models; The task vector calculation module is configured to: calculate an incremental vector of the model parameters of each vertical domain model relative to the base model parameters, which is recorded as a task vector; A training data acquisition module is configured to: sample a training set from the union of the plurality of vertical domain data sets; The model training module is configured to: fix the base model and train the gating parameters; During the training process, for each training sample, the semantic feature vector of the task text is extracted based on the base model, and the gate probability matrix is calculated according to the current gate parameters; the fusion weight of each task vector is calculated according to the gate probability matrix; Based on the base model parameters, task vectors and corresponding fusion weights, the fusion model parameters are obtained; The gating parameter update module is configured to assign the fusion model parameters to the base model to obtain a new fusion model, update the gating parameters for the new fusion model through model feedforward and backpropagation, and repeat the training process until the termination condition is met.
10. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein computer instructions are stored in the memory. When the computer instructions are executed by the processor, the electronic device executes the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
A Multimodal Fusion Method and System for Early Detection of Rumors Based on Gating Mechanism
CN114936266A
Multi-modal feature fusion emotion recognition method based on gating cross-attention mechanism
CN117370828A
Gating vertical large model fine tuning method
CN118278450A
Semantic consistency text-level neural machine translation method based on topic fusion
CN119047492A
Multi-task processing method and system for large language model fused with LoRA
CN119416143A
Cited By
Large model fusion method and device, electronic equipment and storage medium
CN121119196A
Large language model control fine tuning method and system based on multi-task cooperative regulation and control
CN121920461A
