Adapter-based large-model multi-field adaptive method and system
By introducing adapter modules and deep neural network adaptive modules into the large model, a large model multi-domain adaptive network based on adapters is solved, and the effect of cross-domain adaptive and resource conservation is achieved.
Patent Information
- Application Number
- CN202411606892.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-12
- Publication Date
- 2025-03-18
AI Technical Summary
Existing large models have limited adaptability in multiple domains, and parameter fine-tuning requires a large amount of training data and resources, limiting rapid verification and cross-domain adaptation.
By introducing an adapter module into the large model, multiple adapter-based parameter fine-tuning is carried out, and combining deep neural networks as adapter-based modules, a large-scale multi-domain adaptive network is built to achieve cross-domain adaptive.
It realizes adaptive adjustment of large models in multiple fields, reduces hardware resource usage, can meet the needs of large models in multiple fields in constrained environments, and improves cross-domain adaptability and performance.
Smart Images

Figure CN119647544A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the application field of large models, and in particular to an adapter-based large model multi-domain self-adaptive method and system. Background Art
[0002] As an emerging technology in the field of artificial intelligence, big model technology is widely used in different fields, such as finance, medicine, and education. As we all know, when applying a general big model to a specific field, a base general big model is usually selected, and the base general big model is fine-tuned to the specific field by fine-tuning parameters to obtain a domain big model. However, this method can only make the domain big model adapt to a specific field and cannot be expanded to multiple fields.
[0003] In addition, considering that parameter fine-tuning is generally done by fine-tuning the parameters of the universal large model of the base, this method of fine-tuning the parameters of the entire parameter often requires a large amount of training data, a long training time, and more training resources, which limits the rapid verification of many algorithms based on large model technology. Therefore, more and more researchers are turning to efficient parameter fine-tuning.
[0004] The efficient parameter fine-tuning method is to add an adapter module to the network structure of the large model. During fine-tuning, the base general large model is not directly trained, but the adapter is trained. The purpose of model domain fine-tuning is achieved by fine-tuning the parameters of the adapter. However, even with efficient parameter fine-tuning, it is still impossible to horizontally expand the capabilities of the large model in multiple fields. Summary of the invention
[0005] The purpose of the present invention is to provide an adapter-based large model multi-domain adaptive method and system, which can enable the large model to make domain-level adaptive adjustments for different scenarios, so as to horizontally expand the performance of the large model in multiple fields; at the same time, it can also achieve less hardware resource usage and meet the requirements for multi-domain large models in some restricted environments.
[0006] To achieve the above object, the present invention provides the following technical solutions:
[0007] An adapter-based large model multi-domain adaptive method, which is an application method involving multi-professional field expansion of a large model, comprises the following steps:
[0008] Step S1, data collection and preprocessing to obtain training data;
[0009] Step S2, selecting a universal large model of the base and a parameter fine-tuning method according to the training data, performing multiple adapter-based parameter fine-tuning on the large model to obtain multiple fine-tuned adapters;
[0010] Step S3, using a deep neural network as an adaptive module, and combining it with the base universal large model and multiple fine-tuned adapters to form an adapter-based large model multi-domain adaptive network;
[0011] Step S4, using the training data to train the adaptive modules in the large-model multi-domain adaptive network to obtain trained adaptive modules;
[0012] Step S5, according to the user input, use the large model multi-domain adaptive network to reason it and obtain the output of the corresponding field. That is: construct the specified field problem text format input data, input the input data into the large model multi-domain adaptive network, and the large model multi-domain adaptive network will adaptively select the adapter to be used according to the field category of the input data.
[0013] Preferably, in step S1, data collection and preprocessing to obtain training data are specifically:
[0014] S11: Collect general data and data in multiple specific fields, such as general data, financial data, medical data, legal data, etc.
[0015] S12: Based on the collected general data and multiple specific field data, data preprocessing is performed, mainly including: data cleaning, data normalization, data standardization, etc. After preprocessing, a sufficient amount of training data is obtained;
[0016] Preferably, in step S2, according to the training data, a universal large model of the base and an efficient parameter fine-tuning method are selected, and the large model is subjected to multiple adapter-based efficient parameter fine-tuning to obtain multiple fine-tuned adapters, specifically:
[0017] S21: Select the universal large model of the base, such as QWen-2.5-7B, LLaMa-3-8B, ChatGLM-3-6B, etc.
[0018] S22: Select an adapter-based efficient parameter fine-tuning method, such as Adapter, LoRA, Prefix-Tuning, etc.
[0019] S23: According to the selected universal large model of the base and the efficient parameter fine-tuning method based on the adapter, using the training data to perform efficient parameter fine-tuning based on the adapter on the large model to obtain a fine-tuned adapter;
[0020] S24: Repeat S22-S23 continuously, use training data from different fields to perform efficient parameter fine-tuning, and obtain multiple fine-tuned adapters.
[0021] Preferably, in step S4, the adaptive module in the large-model multi-domain adaptive network is trained using the training data to obtain a trained adaptive module, specifically:
[0022] S41: The training data is first input into the adaptive module of the large model multi-domain adaptive network, and the output of the adaptive module is the predicted mask pred , and then obtain the mask predicted by the adaptive module pred ;
[0023] S42: Mask the training data according to its domain source real , as a Label, and the mask predicted by the adaptive module pred , using the binary cross entropy as the loss function, calculating the Loss, and updating the parameters of the adaptive module in reverse;
[0024] S43: Continuously repeat S41-S42 to iteratively update the adaptive module until the adaptive module is optimal, thereby obtaining a trained adaptive module.
[0025] Preferably, in step S5, according to the user input, the large model multi-domain adaptive network is used to infer it to obtain a response output, specifically:
[0026] S51: constructing input samples according to user input;
[0027] S52: Input the input sample into the adaptive module in the large model multi-domain adaptive network to obtain a mask, which is specifically as follows:
[0028] mask=Net adaptive (x)
[0029] Among them, Net adaptive is an adaptive module, and x is the input sample;
[0030] S53: Input the input sample to other modules in the large model multi-domain adaptive network, as shown in the following formula:
[0031] out = Transformer(x) + (Net_1 adapter (x)+...+Net_n adapter (x))*mask
[0032] Among them, Transformer is the Transformer layer of the base general large model. The base general large model is theoretically composed of multiple layers of Transformer layers. Net_1 adapter For the first adapter, Net_nadapter For the nth adapter.
[0033] S54: Repeat S53 for reasoning according to the number of Transformer layers of the large model to obtain a response output adapted to the domain.
[0034] An adapter-based large-model multi-domain adaptive system, comprising:
[0035] Training data acquisition unit, used for data collection and preprocessing;
[0036] A universal large model adjustment unit for the base selects a universal large model for the base and a parameter fine-tuning method according to the training data, and performs multiple adapter-based parameter fine-tuning on the large model to obtain multiple fine-tuned adapters;
[0037] A large-model multi-domain adaptive network construction unit uses a deep neural network as an adaptive module, which is combined with the base universal large model and multiple fine-tuned adapters to form an adapter-based large-model multi-domain adaptive network;
[0038] A large-model multi-domain adaptive network training unit uses the training data to train the adaptive modules in the large-model multi-domain adaptive network to obtain trained adaptive modules;
[0039] The output unit uses the large model multi-domain adaptive network to reason based on the user input to obtain the output of the corresponding field.
[0040] A computer storage medium stores an executable program, and the executable program is executed by a processor to implement the steps of the adapter-based large model multi-domain self-adaptation method.
[0041] Compared with the prior art, the present invention has the following advantages: (1) The large-model multi-domain adaptive method proposed in the present invention can realize the adaptation of a large model in multiple fields without switching the large model, thereby improving the cross-domain adaptability of the large model; (2) The present invention enhances the adaptability of the large model by adding only a small number of parameters; (3) The present invention achieves less hardware resource usage and can meet the requirements for multi-domain large models in some restricted environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is a flow chart of a large model multi-domain adaptive method based on an adapter of the present invention;
[0043] Figure 2 It is the overall architecture diagram of the large-model multi-domain adaptive network of the present invention;
[0044] Figure 3is a schematic diagram of the parameter efficient fine-tuning method LoRA used in a specific implementation example of the present invention;
[0045] Figure 4 It is a schematic diagram of the overall process of a large-model multi-domain adaptive network in a specific implementation example of the present invention. DETAILED DESCRIPTION
[0046] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0047] like Figure 1 and Figure 2 As shown, this embodiment provides an adapter-based large model multi-domain adaptive method, which aims to enable the large model to adaptively switch adapters in different scenarios through an adaptive method to improve the professionalism and accuracy of its response, specifically including:
[0048] S1 data collection and preprocessing to obtain training data, including:
[0049] S11: Collecting general data and multiple specific field data. In this embodiment, in addition to the collected general data, three specific field data are collected, namely, financial field, medical field, and legal field data;
[0050] S12: Based on the collected general data and multiple specific domain data, data preprocessing is performed, mainly including: data cleaning, data normalization, data standardization, etc. In this embodiment, the collected general data and three specific domain data are subjected to data cleaning, word segmentation, etc., and are matched according to the ratio of "general data: financial data: medical data: legal data = 6:1:1:1". After preprocessing, a sufficient amount of training data is obtained;
[0051] S2 selects a universal large model of the base and an efficient parameter fine-tuning method according to the training data, performs multiple adapter-based efficient parameter fine-tuning on the large model, and obtains multiple fine-tuned adapters, and also includes:
[0052] S21: Select a universal large model of the base. In this embodiment, select QWen-2.5-7B-Instruct developed by Alibaba Cloud;
[0053] S22: Select an adapter-based efficient parameter fine-tuning method, such as Adapter, LoRA, Prefix-Tuning, etc. In this embodiment, LoRA is selected. The principle of LoRA is to freeze the pre-trained model weights and inject the trainable rank decomposition matrix into each weight of the Transformer layer. To put it bluntly, it actually adds a "side branch" on the right, that is, first use a Linear layer A to reduce the data from d dimensions to r (r is the rank), and then use a second Linear layer B to change the data from r back to d dimensions. Finally, add and fuse the results of the left and right parts, and combine them. Figure 3 , according to the following formula, the hidden_state output of each Transformer layer in the large model will be obtained;
[0054] h=W0x+ΔWx=(W0+ΔW)x=W0x+BAx
[0055] Among them, W0 is the weight parameter of the Transformer layer in the base general large model, ΔW represents the weight parameter of the adapter, and h is the output of the Transformer layer.
[0056] In this embodiment, the parameters of LoRA are set as: rank lora_r=8; scaling factor lora_alpha=16.
[0057] S23: According to the selected base universal large model and the adapter-based LoRA efficient parameter fine-tuning method, the base universal large model Tongyi Qianwen QWen-2.5-7B-Instruct is fine-tuned using the training data, and the number of fine-tuning training iterations is set to 20,000 times to obtain a fine-tuned adapter;
[0058] S24: Repeat S22-S23 continuously, use the training data of different fields to perform efficient parameter fine-tuning respectively, and obtain multiple fine-tuned adapters. In this embodiment, the financial field, the medical field, and the legal field are used to perform fine-tuning in the manner of efficient LoRA parameter fine-tuning to obtain three fine-tuned adapters;
[0059] S3 uses a deep neural network as an adaptive module. In this embodiment, the adaptive module uses a three-layer fully connected neural network, the base universal large model, and multiple fine-tuned adapters to form an adapter-based large model multi-domain adaptive network to obtain a large model multi-domain adaptive network;
[0060] S4 uses the training data to train the adaptive modules in the large-model multi-domain adaptive network to obtain trained adaptive modules, specifically including:
[0061] S41: The training data is first input into the adaptive module of the large model multi-domain adaptive network, and the output of the adaptive module is the predicted mask pred , and then obtain the mask predicted by the adaptive module pred ;
[0062] S42: Mask the training data according to its domain source real , as a Label, and the mask predicted by the adaptive module pred , using the binary cross entropy as the loss function, calculating the Loss, and updating the parameters of the adaptive module in reverse;
[0063] S43: Continuously repeat S41-S42, iteratively update the adaptive module, until the adaptive module is optimal or reaches a specified number of training times, thereby obtaining a trained adaptive module; in this embodiment, the number of adaptive module training iterations is set to 10,000 times;
[0064] S5 uses the large model multi-domain adaptive network to infer the user input and obtain the response output. Figure 4 , specifically including:
[0065] S51: constructing an input sample according to the user input; in this embodiment, the user input may be "Can people with high blood sugar, high blood pressure, and high blood lipids drink sugar-free cola? Will this make the three highs more serious?"
[0066] S52: Input the input sample into the adaptive module in the large model multi-domain adaptive network to obtain a mask, which is specifically as follows:
[0067] mask=Net adaptive (x)
[0068] Among them, Net adaptive is an adaptive module, and x is the input sample;
[0069] In this embodiment, since the user input is a problem related to the medical field, the three outputs of the adaptive module are: a multidimensional matrix with a value close to 0 (representing the adaptive output in the financial field), a multidimensional matrix with a value close to 1 (representing the adaptive output in the medical field), and a multidimensional matrix with a value close to 0 (representing the adaptive output in the legal field).
[0070] S53: Input the input sample to other modules in the large model multi-domain adaptive network, as shown in the following formula:
[0071] out = Transformer(x) + (Net_1 adapter(x)+...+Net_n adapter (x))*mask
[0072] Among them, Transformer is the Transformer layer of the base general large model. The large model is theoretically composed of multiple layers of Transformer layers. Net_1 adapter For the first adapter, Net_n adapter For the nth adapter.
[0073] In this embodiment, the universal large model of the base is QWen-2.5-7B-Instruct, and its Transformer layer is 28 layers; in this embodiment, there are three fields, namely finance, medical care, and law, so there are three adapters, namely Net_1 adapter 、Net_2 adapter 、Net_3 adapter .
[0074] S54: Repeat S53 to perform reasoning according to the number of Transformer layers of the large model to obtain the response output of the adaptive domain; in this embodiment, since the universal large model of the base is Tongyi Qianwen
[0075] QWen-2.5-7B-Instruct has 28 Transformer layers, so S53 is repeated 28 times in total. Finally, the large model accurately answers the medical field question: "Sugar-free cola uses synthetic or natural sweeteners, not real sugar..."
[0076] The embodiments show that the present invention can make the large model adaptive in multiple fields by adding only a small number of parameters to the large model without switching the large model, thereby improving the cross-domain adaptability of the large model and enhancing the performance of the large model.
[0077] An adapter-based large-model multi-domain adaptive system, comprising:
[0078] Training data acquisition unit, used for data collection and preprocessing;
[0079] A universal large model adjustment unit for the base selects a universal large model for the base and a parameter fine-tuning method according to the training data, and performs multiple adapter-based parameter fine-tuning on the large model to obtain multiple fine-tuned adapters;
[0080] A large-model multi-domain adaptive network construction unit uses a deep neural network as an adaptive module, which is combined with the base universal large model and multiple fine-tuned adapters to form an adapter-based large-model multi-domain adaptive network;
[0081] A large-model multi-domain adaptive network training unit uses the training data to train the adaptive modules in the large-model multi-domain adaptive network to obtain trained adaptive modules;
[0082] The output unit uses the large model multi-domain adaptive network to reason based on the user input to obtain the output of the corresponding field.
[0083] A computer storage medium stores an executable program, and the executable program is executed by a processor to implement the steps of the adapter-based large model multi-domain self-adaptation method.
[0084] This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method and core ideas of the present invention. At the same time, for those skilled in the art, according to the ideas of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention. Any non-substantial changes to the present invention using this concept shall be deemed as an infringement of the protection scope of the present invention.
Claims
1. An adapter-based large model multi-domain adaptive method, characterized in that: include: Step S1, data collection and preprocessing to obtain training data; Step S2, selecting a universal large model of the base and a parameter fine-tuning method according to the training data, performing multiple adapter-based parameter fine-tuning on the large model to obtain multiple fine-tuned adapters; Step S3, using a deep neural network as an adaptive module, and combining it with the base universal large model and multiple fine-tuned adapters to form an adapter-based large model multi-domain adaptive network; Step S4, using the training data to train the adaptive modules in the large-model multi-domain adaptive network to obtain trained adaptive modules; Step S5, based on the user input, use the large model multi-domain adaptive network to reason it and obtain the output of the corresponding field.
2. The adapter-based large model multi-domain adaptive method according to claim 1, characterized in that: The data collection and preprocessing to obtain training data specifically include: S11: Collect general data and multiple specific domain data; S12: Perform data preprocessing based on the collected general data and multiple specific field data.
3. The adapter-based large model multi-domain adaptive method according to claim 2, characterized in that: The data preprocessing includes data cleaning, data normalization and data standardization.
4. The adapter-based large model multi-domain adaptive method according to claim 1, characterized in that: The universal large models of the base in step S2 include QWen-2.5-7B, LLaMa-3-8B and ChatGLM-3-6B; the parameter fine-tuning methods include Adapter, LoRA and Prefix-Tuning.
5. The adapter-based large model multi-domain adaptive method according to claim 4, characterized in that: The parameter fine-tuning method is LoRA, the universal large model of the base is Tongyi Qianwen QWen-2.5-7B, and multiple adapter-based parameter fine-tuning of the large model specifically includes: freezing the pre-trained model weights, and injecting the trainable rank decomposition matrix into each weight of the Transformer layer of the universal large model of the base, first using a Linear layer A to reduce the data from d dimensions to r, r is the rank, and then using a second Linear layer B to change the data from r back to d dimensions, and finally adding and fusing the results of the two parts, according to the following formula, the output of each Transformer layer in the universal large model of the base is obtained; h=W0x+ΔWx Among them, W0 is the weight parameter of the Transformer layer in the base general large model, ΔW represents the weight parameter of the adapter, and h is the output of the Transformer layer.
6. The adapter-based large model multi-domain adaptive method according to claim 1, characterized in that: The step S4 specifically includes: S41: The training data is first input into the adaptive module of the large model multi-domain adaptive network, and the output of the adaptive module is the predicted mask pred , and then obtain the mask predicted by the adaptive module pred ; S42: Mask the training data according to its domain source real , as a Label, and the mask predicted by the adaptive module pred , calculate the loss Loss through the loss function, and update the parameters of the adaptive module in reverse; S43: Continuously repeat S41-S42 to iteratively update the adaptive module until the adaptive module is optimal, thereby obtaining a trained adaptive module.
7. The adapter-based large model multi-domain adaptive method according to claim 6, characterized in that: The cross entropy of binary classification is used as the loss function.
8. The adapter-based large model multi-domain adaptive method according to claim 5, characterized in that: The step S5 specifically includes: S51: constructing input samples according to user input; S52: Input the input sample into the adaptive module in the large model multi-domain adaptive network to obtain a mask, which is specifically as follows: mask=Net adaptive (x) Among them, Net adaptive is an adaptive module, and x is the input sample; S53: Input the input sample to other modules in the large model multi-domain adaptive network, as shown in the following formula: out=Transformer(x)+(Net_1 adapter (x)+...+Net_n adapter (x))*mask Among them, Transformer is the Transformer layer of the base general large model, Net_1 adapter The first adapter for the universal large model of the base, Net_n adapter For the nth adapter. S54: Repeat S53 for reasoning according to the number of Transformer layers of the base general large model to obtain the response output adapted to the domain.
9. An adapter-based large-model multi-domain adaptive system for implementing any of the methods described in claims 1-8, characterized in that: include: Training data acquisition unit, used for data collection and preprocessing; A universal large model adjustment unit for the base selects a universal large model for the base and a parameter fine-tuning method according to the training data, and performs multiple adapter-based parameter fine-tuning on the large model to obtain multiple fine-tuned adapters; A large-model multi-domain adaptive network construction unit uses a deep neural network as an adaptive module, which is combined with the base universal large model and multiple fine-tuned adapters to form an adapter-based large-model multi-domain adaptive network; A large-model multi-domain adaptive network training unit uses the training data to train the adaptive modules in the large-model multi-domain adaptive network to obtain trained adaptive modules; The output unit uses the large model multi-domain adaptive network to reason based on the user input to obtain the output of the corresponding field.
10. A computer storage medium, characterized in that: The computer storage medium stores an executable program, and the executable program is executed by a processor to implement the steps of the adapter-based large model multi-domain adaptive method described in any one of claims 1-8.
Citation Information
Cited By
Data processing method, dynamic route and data processing system
CN120278190A
Efficient fine tuning method and system for rail transit construction potential safety hazard recognition model
CN120596924A
Self-adaptive intelligent optimization and cross-domain fusion architecture of wide-field large model
CN120781107A