A transfer learning method, device, equipment and storage medium based on adapter
By using adapters in transfer learning to adjust the Shapley value and the number of adapters, the problems of high resource consumption and knowledge forgetting in existing transfer learning methods are solved, and efficient knowledge transfer and model update are achieved.
Patent Information
- Application Number
- CN202111396195.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-23
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-11-23
AI Technical Summary
Existing transfer learning methods need to re-train the entire model when adding new knowledge to a new task, resulting in the original knowledge being forgotten and high computational resource and time costs.
The adapter-based transfer learning method is used to build an initial transfer learning model, including the fully connected network and the encoder of the transformer model, and use the Shapley value to adjust the number of adapters to reduce training overhead and achieve knowledge transfer.
It effectively reduces training overhead, avoids forgetting model knowledge, and improves the efficiency and resource utilization of transfer learning.
Smart Images

Figure CN114091452B
Abstract
Description
Technical Field
[0001] The present application belongs to the field of artificial intelligence technology, and specifically relates to an adapter-based transfer learning method, device, equipment and storage medium. Background Art
[0002] Transfer learning has been a hot topic in the field of artificial intelligence research in recent years. This field mainly focuses on how to use a model originally trained for a specific task for another task. The characteristics of pre-trained language models are very suitable for the field of transfer learning. In recent years, good results have been achieved in many NLP fields such as text classification, intelligent question answering, machine reading, and text summarization. For example, transformers and pre-trained language models such as GPT and BERT based on transformers. Pre-trained language models are trained based on massive text data. Statistically speaking, massive text data itself contains extremely rich features. Therefore, combined with a neural network model with strong fitting ability, it is possible to learn the knowledge contained in the language and use it for different tasks.
[0003] However, most of the existing pre-trained language models are based on the self-attention transformer-encoder model, which extracts certain "knowledge" from the text through a large amount of corpus training. However, the existing transfer learning methods have the following disadvantages: when a new task requires the addition of some new "knowledge", the entire model needs to be re-pretrained, which will result in: 1. The "knowledge" that has been acquired is "forgotten" by the model, which greatly reduces the model effect; 2. The cost of retraining the model every time is too high, which consumes a lot of computing resources and time costs. Summary of the invention
[0004] The purpose of the embodiments of the present application is to propose an adapter-based transfer learning method, apparatus, computer equipment and storage medium to solve the technical problems of existing transfer learning methods, such as high training cost and easy forgetting of acquired "knowledge".
[0005] In order to solve the above technical problems, the embodiment of the present application provides an adapter-based transfer learning method, which adopts the following technical solution:
[0006] An adapter-based transfer learning method, comprising:
[0007] Building an initial transfer learning model based on a preset fully connected network and an encoder of a transformer model, wherein the initial transfer learning model includes a plurality of adapters;
[0008] Obtain training samples and preprocess them to obtain word vectors corresponding to the training samples;
[0009] Pre-training the initial transfer learning model by using the word vector to obtain a pre-training result;
[0010] Calculating the Shapley value of each adapter based on the pre-training result, and arranging the Shapley value of each adapter in descending order to obtain an adapter contribution queue;
[0011] Adjusting the adapter of the initial transfer learning model through the adapter contribution queue, and iterating the adjusted initial transfer learning model to obtain a self-attention transfer learning model;
[0012] The corpus to be transferred is obtained, and the corpus to be transferred is imported into the self-attention transfer learning model to generate a knowledge transfer result.
[0013] Furthermore, the step of obtaining training samples and preprocessing the training samples to obtain word vectors corresponding to the training samples specifically includes:
[0014] Acquire training corpus, divide the training corpus into paragraphs or sentences, and obtain a training sample set, wherein the training sample set includes a plurality of training samples;
[0015] Performing word segmentation processing on the training sample to obtain sample word segmentation;
[0016] Perform vector conversion on the sample word segmentation to obtain a word vector corresponding to the sample word segmentation.
[0017] Furthermore, the step of performing vector conversion on the sample word segmentation to obtain the word vector corresponding to the sample word segmentation specifically includes:
[0018] Identify the sample segmented text and obtain the word embedding vector corresponding to the text from a preset word vector library;
[0019] Obtaining position information of the sample word segmentation, and encoding the position information to obtain a position vector;
[0020] Identify the knowledge entity of the sample word segmentation, and obtain the knowledge vector corresponding to the knowledge entity from the word vector library;
[0021] The word embedding vector, the position vector and the knowledge vector are summed to generate a word vector corresponding to the sample word segmentation.
[0022] Furthermore, the fully connected network includes a first fully connected layer and a second fully connected layer, the output of the first fully connected layer is connected to the input of the encoder, and the output of the encoder is connected to the input of the second fully connected layer, and the step of pre-training the initial transfer learning model by the word vector and obtaining the pre-training result specifically includes:
[0023] Input the word vector as an initial input vector into the first fully connected layer, and perform linear mapping in the first fully connected layer to obtain a first mapping vector;
[0024] Inputting the first mapping vector into the encoder, and performing feature encoding on the first mapping vector in the encoder to obtain a feature encoding vector;
[0025] Inputting the feature encoding vector into the second fully connected layer, and performing linear mapping in the second fully connected layer to obtain a second mapping vector;
[0026] The second mapping vector is used as a pre-training result output by the initial transfer learning model.
[0027] Furthermore, the step of calculating the Shapley value of each adapter based on the pre-training result specifically includes:
[0028] Obtaining an output vector of each of the adapters;
[0029] Calculate the cosine similarity between each of the output vectors and the pre-training result based on a preset value function;
[0030] The Shapley value of the corresponding adapter is calculated based on the cosine similarity between each of the output vectors and the pre-training result.
[0031] Furthermore, the calculation formula of the Shapley value is as follows:
[0032]
[0033] Among them, φ i (υ) is the Shapley value of the adapter, υ is the value function, N represents all possible adapter combinations, S is a subset of N, I is any adapter, υ(S) represents the contribution of the adapter combination S, and υ(S∪{I}) represents the sum of the contributions of the adapter combination S and adapter I.
[0034] Furthermore, the step of adjusting the adapter of the initial transfer learning model through the adapter contribution queue and iterating the adjusted initial transfer learning model to obtain the self-attention transfer learning model specifically includes:
[0035] Obtaining resource usage information of the initial transfer learning model during pre-training;
[0036] determining an activation quantity of an adapter based on the adapter contribution queue and the resource usage information;
[0037] Based on the activation number of the adapter, the adapter in the initial transfer learning model is adjusted, and the adjusted initial transfer learning model is iteratively trained to obtain the self-attention transfer learning model.
[0038] In order to solve the above technical problems, the embodiment of the present application further provides an adapter-based transfer learning device, which adopts the following technical solution:
[0039] An adapter-based transfer learning device, comprising:
[0040] A model building module, used to build an initial transfer learning model based on a preset fully connected network and an encoder of a transformer model, wherein the initial transfer learning model includes a plurality of adapters;
[0041] The sample acquisition module is used to obtain training samples and preprocess the training samples to obtain word vectors corresponding to the training samples;
[0042] A pre-training module, used to pre-train the initial transfer learning model through the word vector to obtain a pre-training result;
[0043] A contribution calculation module, configured to calculate the Shapley value of each of the adapters based on the pre-training result, and arrange the Shapley value of each of the adapters in descending order to obtain an adapter contribution queue;
[0044] An adaptation training module, used for adjusting the adapter of the initial transfer learning model through the adapter contribution queue, and iterating the adjusted initial transfer learning model to obtain a self-attention transfer learning model;
[0045] The knowledge transfer module is used to obtain the corpus to be transferred and import the corpus to be transferred into the self-attention transfer learning model to generate a knowledge transfer result.
[0046] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0047] A computer device includes a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the adapter-based transfer learning method as described above are implemented.
[0048] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0049] A computer-readable storage medium having computer-readable instructions stored thereon, wherein the computer-readable instructions, when executed by a processor, implement the steps of the adapter-based transfer learning method as described above.
[0050] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0051] The present application discloses a transfer learning method, device, equipment and storage medium based on an adapter, and belongs to the field of artificial intelligence technology. The present application constructs an initial transfer learning model based on an encoder of a fully connected network and a transformer model, wherein the initial transfer learning model includes several adapters, and then the initial transfer learning model is pre-trained through pre-processed training samples, and the Shapley value of each adapter is calculated based on the pre-training results, and the Shapley value of each adapter is arranged in descending order to obtain an adapter contribution queue, and the adapter of the initial transfer learning model is adjusted through the adapter contribution queue, and the adjusted initial transfer learning model is iterated to obtain a self-attention transfer learning model. When performing knowledge transfer, the knowledge transfer of different learning tasks can be realized by inputting the corpus to be transferred in different learning tasks into the self-attention transfer learning model. The present application uses adapters to carry out knowledge transfer in different learning tasks, reducing training overhead. In addition, the present application reduces the number of adapters according to the Shapley value of each adapter during the training process, further reducing the training overhead during the transfer learning process. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0053] Figure 1 An exemplary system architecture diagram is shown in which the present application can be applied;
[0054] Figure 2 A flowchart of an embodiment of an adapter-based transfer learning method according to the present application is shown;
[0055] Figure 3 A schematic diagram of the structure of an initial transfer learning model in an embodiment of an adapter-based transfer learning method according to the present application is shown;
[0056] Figure 4 A schematic structural diagram of an embodiment of an adapter-based transfer learning device according to the present application is shown;
[0057] Figure 5 A schematic structural diagram of an embodiment of a computer device according to the present application is shown. DETAILED DESCRIPTION
[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0059] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0060] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0061] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0062] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0063] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0064] It should be noted that the adapter-based transfer learning method provided in the embodiment of the present application is generally executed by a server, and accordingly, the adapter-based transfer learning device is generally set in the server.
[0065] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0066] Continue to refer Figure 2 , shows a flow chart of an embodiment of an adapter-based transfer learning method according to the present application, wherein the adapter-based transfer learning method comprises the following steps:
[0067] S201, constructing an initial transfer learning model based on a preset fully connected network and an encoder of a transformer model, wherein the initial transfer learning model includes a plurality of adapters.
[0068] Among them, the transformer model is a model based on the encoder-decoder structure. Its encoder and decoder are both composed of attention modules and feedforward neural networks. It is the first model built with pure attention. It not only has faster calculation speed, but also has achieved good results in various knowledge learning tasks. Figure 3 As shown, the transformer-encoder includes a multi-head attention layer and a feedforward neural network layer, and corresponding residual & normalization layers are provided at the output ends of the multi-head attention layer and the feedforward neural network layer to standardize the output results. A fully connected network is essentially a single switch that connects the input and output. A fully connected network has the characteristics of high throughput, high reliability, and low latency. In a specific embodiment of the present application, the fully connected network includes a first fully connected layer and a second fully connected layer.
[0069] Specifically, the server receives the model transfer learning instruction and constructs an initial transfer learning model based on a preset fully connected network and an encoder of a transformer model, wherein the initial transfer learning model includes several adapters. Figure 3 , the initial transfer learning model structure diagram is as follows Figure 3 As shown in the figure, the initial transfer learning model consists of the encoder part of the standard transformer model and multiple adapters. Each adapter consists of a first fully connected layer and a second fully connected layer. Each adapter works with a transformer-encoder layer, which is equivalent to the input of each transformer-encoder layer first passing through the first fully connected layer of the corresponding adapter for linear mapping before being transmitted to the transformer-encoder layer for encoding. Then the output of the transformer-encoder layer is used as the input of the second fully connected layer of the adapter, and then passed to the next adapter after linear mapping of the second fully connected layer. Each input to the transformer-encoder layer needs to pass through a first fully connected layer, and each output of the transformer-encoder layer needs to pass through a second fully connected layer to achieve that both the input and output can be adapted to the transformer-encoder layer, ensuring that the features of the input and output can be retained. The adapter is used to perform knowledge transfer learning in different learning tasks, reducing the training overhead.
[0070] In this embodiment, the adapter-based transfer learning method is run on the electronic device (e.g. Figure 1 The server shown in the figure) can receive the model transfer learning instruction through a wired connection or a wireless connection. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0071] In a specific embodiment of the present application, the initial transfer learning model adopts M transformer-encoder layers, and N adapters are set in the initial transfer learning model, where N ≤ M. In practical applications, by calculating the Shapley value of each adapter and arranging the Shapley values of each adapter in descending order, an adapter contribution queue is obtained. N is determined according to the adapter contribution queue and the server resource usage, that is, the activation number of the adapters in the initial transfer learning model is determined. When N < M, it is considered that no more adapters need to be set starting from the (N + 1)-th transformer-encoder layer. At this time, the dimension is saturated and no further adaptation is required, which can further reduce the training cost.
[0072] S202. Obtain training samples and preprocess the training samples to obtain word vectors corresponding to the training samples.
[0073] Specifically, after the construction of the initial transfer learning model is completed, the server obtains training corpora, divides the training corpora according to paragraphs or sentences to obtain a training sample set, where the training sample set contains several training samples, and then
[0074] preprocess the training samples. The preprocessing includes word segmentation processing and vector transformation processing to obtain word vectors corresponding to the training samples, and use the obtained word vectors to pre-train the initial transfer learning model.
[0075] S203. Pre-train the initial transfer learning model through the word vectors to obtain a pre-training result.
[0076] Specifically, the server inputs the preprocessed training samples into the initial transfer learning model, pre-trains the initial transfer learning model through the word vectors corresponding to the training samples, obtains the output result of the initial transfer learning model, and uses the output result of the initial transfer learning model as the pre-training result. The pre-training result is the predicted label corresponding to the training sample. For example, in the text part-of-speech classification scenario, the pre-training result is nouns, verbs, adjectives, etc.
[0077] In a specific embodiment of the present application, during the model pre-training process, the number of training rounds is divided into P training sub-cycles. After the end of the i-th (generally i < 0.2P) training sub-cycle, the output results of the initial transfer learning model in P rounds can be obtained respectively, and the Shapley values of N adapters are calculated respectively according to the output results.
[0078] S204. Calculate the Shapley value of each adapter based on the pre-training result, and arrange the Shapley values of each adapter in descending order to obtain an adapter contribution queue.
[0079] Specifically, the server obtains the output vector of each adapter and calculates the cosine similarity between the output vector of each adapter and the pre-training result. The obtained cosine similarity represents the contribution of the adapter to the pre-training result, and calculates the Shapley value of the adapter based on the cosine similarity. Finally, the Shapley value of each adapter is arranged in descending order to obtain the adapter contribution queue.
[0080] S205, adjusting the adapter of the initial transfer learning model through the adapter contribution queue, and iterating the adjusted initial transfer learning model to obtain a self-attention transfer learning model.
[0081] Specifically, the server obtains resource usage information of the initial transfer learning model during the pre-training process, such as running memory usage, existing usage, etc. Then, based on the adapter contribution queue and resource usage information obtained above, the number of adapter activations is determined, and based on the number of adapter activations, the adapters in the initial transfer learning model are adjusted, and the adjusted initial transfer learning model is iteratively trained to obtain a self-attention transfer learning model.
[0082] In a specific embodiment of the present application, the resource usage information is video memory. When the video memory usage has reached a certain threshold, at the beginning of the next training sub-cycle, the number of activated adapters is determined to be K, and the first K adapters in the adapter contribution queue are retained, thereby reducing resource consumption in the next training sub-cycle and further reducing training overhead.
[0083] S206, obtaining the corpus to be transferred, and importing the corpus to be transferred into the self-attention transfer learning model to generate a knowledge transfer result.
[0084] Specifically, the server obtains the corpus to be transferred, extracts the knowledge entities in the corpus to be transferred, imports the knowledge entities into the trained self-attention transfer learning model, and generates knowledge transfer results. When performing knowledge transfer, the present application can realize knowledge transfer of different learning tasks by inputting the corpus to be transferred in different learning tasks into the self-attention transfer learning model.
[0085] It should be noted that when it is necessary to handle tasks in new business scenarios, in order to achieve transfer learning, it is necessary to make local adjustments to the self-attention transfer learning model, that is, to fix Figure 3The parameters of the transformer encoding layer are adjusted, the corpus to be transferred is imported into the self-attention transfer learning model, the output of the self-attention transfer learning model is obtained, and the parameters of the fully connected layer neural network in the adapter are adjusted based on the output of the self-attention transfer learning model to obtain the adjusted self-attention transfer learning model. This avoids the problem of the previous knowledge transfer scheme that the model needs to be completely retrained when it is applied to a new business scenario, and also realizes knowledge transfer.
[0086] In the above embodiments, the present application uses adapters to transfer knowledge in different learning tasks, reducing training overhead. In addition, the present application reduces the number of adapters according to the Shapley value of each adapter during the training process, further reducing training overhead during the transfer learning process.
[0087] Furthermore, the step of obtaining training samples and preprocessing the training samples to obtain word vectors corresponding to the training samples specifically includes:
[0088] Acquire training corpus, divide the training corpus into paragraphs or sentences, and obtain a training sample set, wherein the training sample set includes a plurality of training samples;
[0089] Performing word segmentation processing on the training sample to obtain sample word segmentation;
[0090] Perform vector conversion on the sample word segmentation to obtain a word vector corresponding to the sample word segmentation.
[0091] Specifically, the server obtains training samples, identifies training corpus, and divides the training corpus according to paragraphs or sentences to obtain multiple paragraphs or sentences, and constructs a training sample set from the obtained paragraphs or sentences, wherein the training sample set includes a plurality of training samples, and the training samples are paragraphs or sentences. Each training sample in the training sample set is segmented to obtain sample segmentation, and finally the sample segmentation is vectorized to obtain the word vector corresponding to the sample segmentation.
[0092] Furthermore, the step of performing vector conversion on the sample word segmentation to obtain the word vector corresponding to the sample word segmentation specifically includes:
[0093] Identify the sample segmented text and obtain the word embedding vector corresponding to the text from a preset word vector library;
[0094] Obtaining position information of the sample word segmentation, and encoding the position information to obtain a position vector;
[0095] Identify the knowledge entity of the sample word segmentation, and obtain the knowledge vector corresponding to the knowledge entity from the word vector library;
[0096] The word embedding vector, the position vector and the knowledge vector are summed to generate a word vector corresponding to the sample word segmentation.
[0097] Specifically, the server first obtains the text of the sample word segmentation by identifying the sample word segmentation, and converts the text of the sample word segmentation into a vector through the preset word2vec word vector library to obtain the word embedding vector corresponding to the text; then obtains the position information of the sample word segmentation, where the position information represents the position of the sample word segmentation in the training sample, and performs sine and cosine encoding on the position information to obtain the position vector; then identifies the knowledge entity of the sample word segmentation through the named entity recognition technology, and converts the knowledge entity of the sample word segmentation into a vector through the preset word2vec word vector library to obtain the knowledge vector corresponding to the knowledge entity; finally, the word embedding vector, position vector and knowledge vector are summed to generate the word vector corresponding to the sample word segmentation. It should be noted that there may be a situation where a word segmentation text is the same as an entity, in which case the word embedding vector is equal to the knowledge vector. If a word segmentation is not equivalent to an entity, its knowledge vector is set to a vector with all elements being 0.
[0098] Among them, word2vec is a group of related models used to generate word vectors. These models are shallow, two-layer neural networks that are trained to reconstruct linguistic word texts. The network is represented by words and needs to guess the input words in adjacent positions. Under the word bag model assumption in word2vec, the order of words is not important. After training, the word2vec model can be used to map each word to a vector, which can be used to represent the relationship between words. The vector is the hidden layer of the neural network.
[0099] Named Entity Recognition (NER), also known as "proper name recognition", refers to the recognition of entities with specific meanings in texts, mainly including names of people, places, institutions, proper nouns, etc. Named entity recognition is an important basic tool in application fields such as information extraction, question-answering systems, syntactic analysis, machine translation, and metadata annotation for the Semantic Web. It plays an important role in the process of natural language processing technology becoming practical. Generally speaking, the task of named entity recognition is to identify three major categories (entity category, time category, and number category) and seven minor categories (names of people, institution names, place names, time, date, currency, and percentage) of named entities in the text to be processed.
[0100] In the above embodiment, the present application obtains sample word segmentations by performing word segmentation processing on the training samples, obtains word embedding vectors, position vectors and knowledge vectors respectively by performing text vector conversion, position encoding and knowledge entity vector conversion on the sample word segmentations, and obtains word vectors of the sample word segmentations by integrating the word embedding vectors, position vectors and knowledge vectors. The word vectors of the sample word segmentations are used to train the self-attention transfer learning model.
[0101] Furthermore, the fully connected network includes a first fully connected layer and a second fully connected layer, the output of the first fully connected layer is connected to the input of the encoder, and the output of the encoder is connected to the input of the second fully connected layer, and the step of pre-training the initial transfer learning model by the word vector and obtaining the pre-training result specifically includes:
[0102] Input the word vector as an initial input vector into the first fully connected layer, and perform linear mapping in the first fully connected layer to obtain a first mapping vector;
[0103] Inputting the first mapping vector into the encoder, and performing feature encoding on the first mapping vector in the encoder to obtain a feature encoding vector;
[0104] Inputting the feature encoding vector into the second fully connected layer, and performing linear mapping in the second fully connected layer to obtain a second mapping vector;
[0105] The second mapping vector is used as a pre-training result output by the initial transfer learning model.
[0106] The initial transfer learning model includes multiple adapters (N1~N n ), each adapter is constructed by a fully connected network and an encoder of a transformer model, wherein the fully connected network includes a first fully connected layer and a second fully connected layer, the output of the first fully connected layer is connected to the input of the encoder, and the output of the encoder is connected to the input of the second fully connected layer.
[0107] In a specific embodiment of the present application, during pre-training, in the first adapter N1, the word vector of the sample word segmentation is input as the initial input vector X0 to the first fully connected layer P N1 , and in the first fully connected layer P N1 Perform linear mapping to obtain the first mapping vector X N1 , the first mapping vector X N1 Input to transformer-encoder, and in transformer-encoder, the first mapping vector X N1 Perform feature encoding to obtain the feature encoding vector X T1 , the feature encoding vector XT1 Input to the second fully connected layer P N1’ At the same time, the initial input vector X0 is also input into the second fully connected layer P after passing through the residual & standard network N1’ , in the second fully connected layer P N1’ The feature encoding vector X T1 And the normalized initial input vector X0 is linearly mapped to obtain the second mapping vector X N1’ The second mapping vector X output by the first adapter N1 is N1’ The input is input into the second adapter N2, and the above process is performed in the second adapter N2 and all subsequent adapters to obtain the second mapping vector output by the last adapter, and the second mapping vector output by the last adapter is used as the pre-training result of the initial transfer learning model output. The adapter is used to adapt the input and output to the transformer-encoder to ensure that the features of the input and output can be retained. The adapter is used to perform knowledge transfer learning in different learning tasks, thereby reducing training overhead.
[0108] In the above embodiment, an adapter is constructed by using a fully connected network and an encoder of a transformer model, adaptation between the encoder input and output is achieved through the fully connected network, and the adapter is used to perform knowledge transfer in different learning tasks, thereby reducing training overhead.
[0109] Furthermore, the step of calculating the Shapley value of each adapter based on the pre-training result specifically includes:
[0110] Obtaining an output vector of each of the adapters;
[0111] Calculate the cosine similarity between each of the output vectors and the pre-training result based on a preset value function;
[0112] The Shapley value of the corresponding adapter is calculated based on the cosine similarity between each of the output vectors and the pre-training result.
[0113] Furthermore, the calculation formula of the Shapley value is as follows:
[0114]
[0115] Among them, φ i (υ) is the Shapley value of the adapter, υ is the value function, N represents all possible adapter combinations, S is a subset of N, I is any adapter, υ(S) represents the contribution of the adapter combination S, and υ(S∪{I}) represents the sum of the contributions of the adapter combination S and adapter I.
[0116] Among them, the contribution distribution of subsets in the Shapley value set reflects the contribution of each subset to the set goal, avoids egalitarianism in distribution, and is more reasonable and fair than any distribution method that only relies on resource input value, resource allocation efficiency, or a combination of the two.
[0117] Specifically, the server obtains the output vector of each adapter, that is, the second mapping vector output by the second fully connected layer in the adapter, calculates the cosine similarity between each output vector and the pre-training result based on a preset value function, and calculates the Shapley value of the corresponding adapter based on the cosine similarity between each output vector and the pre-training result.
[0118] In the above embodiment, the present application calculates the Shapley value of the corresponding adapter based on the cosine similarity between the output vector of each adapter and the pre-training result, so as to obtain the contribution of the adapter to the pre-training.
[0119] Furthermore, the step of adjusting the adapter of the initial transfer learning model through the adapter contribution queue and iterating the adjusted initial transfer learning model to obtain the self-attention transfer learning model specifically includes:
[0120] Obtaining resource usage information of the initial transfer learning model during pre-training;
[0121] determining an activation quantity of an adapter based on the adapter contribution queue and the resource usage information;
[0122] Based on the activation number of the adapter, the adapter in the initial transfer learning model is adjusted, and the adjusted initial transfer learning model is iteratively trained to obtain the self-attention transfer learning model.
[0123] Specifically, the server obtains resource usage information of the initial transfer learning model during the pre-training process, such as running memory usage, existing usage, etc., and determines the number of activations of the adapter based on the adapter contribution queue and resource usage information. Based on the number of activations of the adapter, the adapter in the initial transfer learning model is adjusted, and the adjusted initial transfer learning model is iteratively trained to obtain a self-attention transfer learning model.
[0124] It should be noted that when constructing the initial transfer learning model, an adapter is first configured for each transformer-encoder layer in the initial transfer learning model, and then the number of activated adapters is determined by calculating the adapter contribution queue and combining the resource usage information to determine the adapters that need to be retained, and the adapters of the transformer-encoder layer that no longer need to be adapted are removed. During the training process, this application reduces the number of adapters according to the Shapley value of each adapter, further reducing the training overhead during the transfer learning process.
[0125] In a specific embodiment of the present application, the initial transfer learning model can be iteratively trained by a back propagation algorithm, which is a learning algorithm suitable for multi-layer neural networks. It is based on the gradient descent method and is used for error calculation of deep learning networks. The input-output relationship of the BP network is essentially a mapping relationship: the function performed by a BP neural network with n inputs and m outputs is a continuous mapping from an n-dimensional Euclidean space to a finite field in an m-dimensional Euclidean space, and this mapping is highly nonlinear. The learning process of the BP algorithm consists of a forward propagation process and a back propagation process. In the forward propagation process, the input information passes through the input layer and the hidden layer, is processed layer by layer and transmitted to the output layer, and is transferred to the back propagation, and the partial derivatives of the objective function to each neuron weight are obtained layer by layer, forming the gradient of the objective function to the weight vector, which is used as the basis for modifying the weight.
[0126] It should be noted that there is an upper threshold for resource usage information. When resource usage has reached the upper threshold, at the beginning of the next training sub-cycle, the number of activated adapters is determined to be K. When K adapters are activated, the training resource usage does not exceed the upper threshold. The first K adapters in the adapter contribution queue are retained to reduce resource consumption in the next training sub-cycle and further reduce training overhead.
[0127] The present application discloses a transfer learning method based on an adapter, and belongs to the field of artificial intelligence technology. The present application constructs an initial transfer learning model based on an encoder of a fully connected network and a transformer model, wherein the initial transfer learning model includes several adapters, and then the initial transfer learning model is pre-trained through pre-processed training samples, and the Shapley value of each adapter is calculated based on the pre-training result, and the Shapley value of each adapter is arranged in descending order to obtain an adapter contribution queue, and the adapter of the initial transfer learning model is adjusted through the adapter contribution queue, and the adjusted initial transfer learning model is iterated to obtain a self-attention transfer learning model, and when performing knowledge transfer, the knowledge transfer of different learning tasks can be realized by inputting the corpus to be transferred in different learning tasks into the self-attention transfer learning model. The present application uses adapters to carry out knowledge transfer in different learning tasks, reducing training overhead. In addition, the present application reduces the number of adapters according to the Shapley value of each adapter during the training process, further reducing the training overhead during the transfer learning process.
[0128] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the computer-readable instructions are executed, they can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0129] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0130] Further references Figure 4 , as a response to the above Figure 2 The present application provides an embodiment of a transfer learning device based on an adapter, and the device embodiment is similar to Figure 4Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0131] like Figure 4 As shown, the adapter-based transfer learning device described in this embodiment includes:
[0132] A model construction module 401 is used to construct an initial transfer learning model based on a preset fully connected network and an encoder of a transformer model, wherein the initial transfer learning model includes a plurality of adapters;
[0133] The sample acquisition module 402 is used to acquire training samples and pre-process the training samples to obtain word vectors corresponding to the training samples;
[0134] A pre-training module 403 is used to pre-train the initial transfer learning model through the word vector to obtain a pre-training result;
[0135] A contribution calculation module 404, configured to calculate the Shapley value of each adapter based on the pre-training result, and arrange the Shapley value of each adapter in descending order to obtain an adapter contribution queue;
[0136] An adaptation training module 405 is used to adjust the adapter of the initial transfer learning model through the adapter contribution queue, and iterate the adjusted initial transfer learning model to obtain a self-attention transfer learning model;
[0137] The knowledge transfer module 406 is used to obtain the corpus to be transferred, and import the corpus to be transferred into the self-attention transfer learning model to generate a knowledge transfer result.
[0138] Furthermore, the sample acquisition module 402 specifically includes:
[0139] A corpus division unit is used to obtain training corpus, divide the training corpus according to paragraphs or sentences, and obtain a training sample set, wherein the training sample set includes a plurality of training samples;
[0140] A word segmentation processing unit, used to perform word segmentation processing on the training sample to obtain sample word segments;
[0141] A vector conversion unit is used to perform vector conversion on the sample word segmentation to obtain a word vector corresponding to the sample word segmentation.
[0142] Furthermore, the vector conversion unit specifically includes:
[0143] A first vector conversion subunit, used to identify the sample segmented text and obtain a word embedding vector corresponding to the text from a preset word vector library;
[0144] A second vector conversion subunit is used to obtain the position information of the sample word segmentation, and encode the position information to obtain a position vector;
[0145] A third vector conversion subunit is used to identify the knowledge entity of the sample word segmentation and obtain the knowledge vector corresponding to the knowledge entity from the word vector library;
[0146] The vector integration subunit is used to sum the word embedding vector, the position vector and the knowledge vector to generate a word vector corresponding to the sample word segmentation.
[0147] Further, the fully connected network includes a first fully connected layer and a second fully connected layer, the output of the first fully connected layer is connected to the input of the encoder, the output of the encoder is connected to the input of the second fully connected layer, and the pre-training module 403 specifically includes:
[0148] A first mapping unit, configured to input the word vector as an initial input vector into the first fully connected layer, and perform linear mapping in the first fully connected layer to obtain a first mapping vector;
[0149] a feature encoding unit, configured to input the first mapping vector into the encoder, and perform feature encoding on the first mapping vector in the encoder to obtain a feature encoding vector;
[0150] A second mapping unit, used for inputting the feature encoding vector into the second fully connected layer, and performing linear mapping in the second fully connected layer to obtain a second mapping vector;
[0151] A result output unit is used to use the second mapping vector as a pre-training result output by the initial transfer learning model.
[0152] Furthermore, the contribution calculation module 404 specifically includes:
[0153] An output vector acquisition unit, used to acquire an output vector of each of the adapters;
[0154] A cosine similarity calculation unit, used to calculate the cosine similarity between each of the output vectors and the pre-training result based on a preset value function;
[0155] A contribution calculation unit is used to calculate the Shapley value of the corresponding adapter based on the cosine similarity between each of the output vectors and the pre-training result.
[0156] Furthermore, the calculation formula of the Shapley value is as follows:
[0157]
[0158] Among them, φ i (υ) is the Shapley value of the adapter, υ is the value function, N represents all possible adapter combinations, S is a subset of N, I is any adapter, υ(S) represents the contribution of the adapter combination S, and υ(S∪{I}) represents the sum of the contributions of the adapter combination S and adapter I.
[0159] Furthermore, the adaptation training module 405 specifically includes:
[0160] A resource acquisition unit, used to obtain resource usage information of the initial transfer learning model during the pre-training process;
[0161] a quantity confirmation unit, configured to determine the number of adapter activations based on the adapter contribution queue and the resource usage information;
[0162] An iterative training unit is used to adjust the adapter in the initial transfer learning model based on the activation number of the adapter, and iteratively train the adjusted initial transfer learning model to obtain the self-attention transfer learning model.
[0163] The present application discloses a transfer learning device based on an adapter, and belongs to the field of artificial intelligence technology. The present application constructs an initial transfer learning model based on an encoder of a fully connected network and a transformer model, wherein the initial transfer learning model includes several adapters, and then the initial transfer learning model is pre-trained through pre-processed training samples, and the Shapley value of each adapter is calculated based on the pre-training results, and the Shapley value of each adapter is arranged in descending order to obtain an adapter contribution queue, and the adapter of the initial transfer learning model is adjusted through the adapter contribution queue, and the adjusted initial transfer learning model is iterated to obtain a self-attention transfer learning model, and when performing knowledge transfer, the knowledge transfer of different learning tasks can be realized by inputting the corpus to be transferred in different learning tasks into the self-attention transfer learning model. The present application uses adapters to carry out knowledge transfer in different learning tasks, reducing training overhead. In addition, the present application reduces the number of adapters according to the Shapley value of each adapter during the training process, further reducing the training overhead during the transfer learning process.
[0164] To solve the above technical problems, the present application also provides a computer device. Figure 5 , Figure 5 This is a basic structural block diagram of the computer device in this embodiment.
[0165] The computer device 5 includes a memory 51, a processor 52, and a network interface 53 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 5 with components 51-53, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0166] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0167] The memory 51 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 51 can be an internal storage unit of the computer device 5, such as a hard disk or memory of the computer device 5. In other embodiments, the memory 51 can also be an external storage device of the computer device 5, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. equipped on the computer device 5. Of course, the memory 51 can also include both the internal storage unit of the computer device 5 and its external storage device. In this embodiment, the memory 51 is generally used to store the operating system and various application software installed on the computer device 5, such as computer-readable instructions of the transfer learning method based on the adapter, etc. In addition, the memory 51 can also be used to temporarily store various types of data that have been output or are to be output.
[0168] The processor 52 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 52 is generally used to control the overall operation of the computer device 5. In this embodiment, the processor 52 is used to run computer-readable instructions stored in the memory 51 or process data, such as computer-readable instructions for running the adapter-based transfer learning method.
[0169] The network interface 53 may include a wireless network interface or a wired network interface. The network interface 53 is generally used to establish a communication connection between the computer device 5 and other electronic devices.
[0170] The present application discloses a device, belonging to the field of artificial intelligence technology. The present application constructs an initial transfer learning model based on an encoder of a fully connected network and a transformer model, wherein the initial transfer learning model includes several adapters, and then the initial transfer learning model is pre-trained through pre-processed training samples, and the Shapley value of each adapter is calculated based on the pre-training results, and the Shapley value of each adapter is arranged in descending order to obtain an adapter contribution queue, and the adapter of the initial transfer learning model is adjusted through the adapter contribution queue, and the adjusted initial transfer learning model is iterated to obtain a self-attention transfer learning model, and when performing knowledge transfer, the knowledge transfer of different learning tasks can be achieved by inputting the corpus to be transferred in different learning tasks into the self-attention transfer learning model. The present application uses adapters to carry out knowledge transfer in different learning tasks, reducing training overhead. In addition, the present application reduces the number of adapters according to the Shapley value of each adapter during the training process, further reducing the training overhead during the transfer learning process.
[0171] The present application also provides another embodiment, namely, providing a computer-readable storage medium, which stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the adapter-based transfer learning method as described above.
[0172] The present application discloses a storage medium, belonging to the field of artificial intelligence technology. The present application constructs an initial transfer learning model based on an encoder of a fully connected network and a transformer model, wherein the initial transfer learning model includes several adapters, and then the initial transfer learning model is pre-trained through pre-processed training samples, and the Shapley value of each adapter is calculated based on the pre-training result, and the Shapley value of each adapter is arranged in descending order to obtain an adapter contribution queue, and the adapter of the initial transfer learning model is adjusted through the adapter contribution queue, and the adjusted initial transfer learning model is iterated to obtain a self-attention transfer learning model, and when performing knowledge transfer, the knowledge transfer of different learning tasks can be realized by inputting the corpus to be transferred in different learning tasks into the self-attention transfer learning model. The present application uses adapters to carry out knowledge transfer in different learning tasks, reducing training overhead. In addition, the present application reduces the number of adapters according to the Shapley value of each adapter during the training process, further reducing the training overhead during the transfer learning process.
[0173] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0174] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. An adapter-based transfer learning method, It is characterized in that include: Building an initial transfer learning model based on a preset fully connected network and an encoder of a transformer model, wherein the initial transfer learning model includes a plurality of adapters; Obtain training samples and preprocess them to obtain word vectors corresponding to the training samples; Pre-training the initial transfer learning model through the word vector to obtain a pre-training result; Calculating the Shapley value of each adapter based on the pre-training result, and arranging the Shapley value of each adapter in descending order to obtain an adapter contribution queue; Adjusting the adapter of the initial transfer learning model through the adapter contribution queue, and iterating the adjusted initial transfer learning model to obtain a self-attention transfer learning model; The corpus to be transferred is obtained, and the corpus to be transferred is imported into the self-attention transfer learning model to generate a knowledge transfer result.
2. The adapter-based transfer learning method according to claim 1, It is characterized in that The step of obtaining training samples and preprocessing the training samples to obtain word vectors corresponding to the training samples specifically includes: Acquire training corpus, divide the training corpus into paragraphs or sentences, and obtain a training sample set, wherein the training sample set includes a plurality of training samples; Performing word segmentation processing on the training sample to obtain sample word segmentation; Perform vector conversion on the sample word segmentation to obtain a word vector corresponding to the sample word segmentation.
3. The adapter-based transfer learning method according to claim 2, It is characterized in that The step of performing vector conversion on the sample word segment to obtain the word vector corresponding to the sample word segment specifically includes: Identify the sample segmented text and obtain the word embedding vector corresponding to the text from a preset word vector library; Obtaining position information of the sample word segmentation, and encoding the position information to obtain a position vector; Identify the knowledge entity of the sample word segmentation, and obtain the knowledge vector corresponding to the knowledge entity from the word vector library; The word embedding vector, the position vector and the knowledge vector are summed to generate a word vector corresponding to the sample word segmentation.
4. The adapter-based transfer learning method according to claim 2, It is characterized in that The fully connected network includes a first fully connected layer and a second fully connected layer, the output of the first fully connected layer is connected to the input of the encoder, and the output of the encoder is connected to the input of the second fully connected layer. The step of pre-training the initial transfer learning model by using the word vector to obtain the pre-training result specifically includes: Input the word vector as an initial input vector into the first fully connected layer, and perform linear mapping in the first fully connected layer to obtain a first mapping vector; Inputting the first mapping vector into the encoder, and performing feature encoding on the first mapping vector in the encoder to obtain a feature encoding vector; Inputting the feature encoding vector into the second fully connected layer, and performing linear mapping in the second fully connected layer to obtain a second mapping vector; The second mapping vector is used as a pre-training result output by the initial transfer learning model.
5. The adapter-based transfer learning method according to claim 1, It is characterized in that The step of calculating the Shapley value of each adapter based on the pre-training result specifically includes: Obtaining an output vector of each of the adapters; Calculate the cosine similarity between each of the output vectors and the pre-training result based on a preset value function; The Shapley value of the corresponding adapter is calculated based on the cosine similarity between each of the output vectors and the pre-training result.
6. The adapter-based transfer learning method according to claim 5, It is characterized in that The calculation formula of the Shapley value is as follows: Among them, φ i (υ) is the Shapley value of the adapter, υ is the value function, N represents all possible adapter combinations, S is a subset of N, I is any adapter, υ(S) represents the contribution of the adapter combination S, and υ(S∪{I}) represents the sum of the contributions of the adapter combination S and adapter I.
7. The adapter-based transfer learning method according to claim 1, It is characterized in that The step of adjusting the adapter of the initial transfer learning model through the adapter contribution queue and iterating the adjusted initial transfer learning model to obtain the self-attention transfer learning model specifically includes: Obtaining resource usage information of the initial transfer learning model during pre-training; determining an activation quantity of an adapter based on the adapter contribution queue and the resource usage information; Based on the activation number of the adapter, the adapter in the initial transfer learning model is adjusted, and the adjusted initial transfer learning model is iteratively trained to obtain the self-attention transfer learning model.
8. A transfer learning device based on an adapter, It is characterized in that include: A model building module, used to build an initial transfer learning model based on a preset fully connected network and an encoder of a transformer model, wherein the initial transfer learning model includes a plurality of adapters; The sample acquisition module is used to obtain training samples and preprocess the training samples to obtain word vectors corresponding to the training samples; A pre-training module, used to pre-train the initial transfer learning model through the word vector to obtain a pre-training result; A contribution calculation module, configured to calculate the Shapley value of each of the adapters based on the pre-training result, and arrange the Shapley value of each of the adapters in descending order to obtain an adapter contribution queue; An adaptation training module, used for adjusting the adapter of the initial transfer learning model through the adapter contribution queue, and iterating the adjusted initial transfer learning model to obtain a self-attention transfer learning model; The knowledge transfer module is used to obtain the corpus to be transferred and import the corpus to be transferred into the self-attention transfer learning model to generate a knowledge transfer result.
9. A computer device, It is characterized in that The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the adapter-based transfer learning method as claimed in any one of claims 1 to 7 when executing the computer-readable instructions.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the adapter-based transfer learning method according to any one of claims 1 to 7 are implemented.
