A domain adaptation method based on hint learning
Through the method based on prompt learning, the probability calculation problem of converting the target domain classification task into label words is solved by using Bert model and template prompts, which solves the shortcomings of shallow learning methods in cross-domain feature representation learning, and realizes the The semantic feature structure maintenance and class discernibility improve the accuracy and practicality of domain adaptive tasks.
Patent Information
- Application Number
- CN202210555187.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-19
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2042-05-19
AI Technical Summary
The existing field adaptive methods based on shallow learning are not effective in cross-domain feature representation learning, and deep learning methods require a large amount of training data, making it difficult to effectively apply in real-world application scenarios.
Using a prompt-based learning method, using Bert model and template prompts to embed input sentences, converting target domain classification tasks into label words through pre-training language models, reducing dependence on source domain data, and improving cross-domain adaptability accuracy.
The semantic feature structure maintenance and class discernibility improvement among different fields is achieved, the dependence on a large number of source domain data is reduced, and the accuracy and practicality of domain adaptive tasks are improved.
Smart Images

Figure CN114817550B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the research field of transfer learning, and in particular to a domain adaptation method based on prompt learning. Background Art
[0002] Traditional machine learning assumes that training data and test data are independent and identically distributed, but in real application scenarios, data in different fields are different but similar to each other. In order to solve this problem, research on domain adaptation has received widespread attention in recent years. Its main idea is to adapt the model trained on the labeled source domain to the unlabeled target domain, aiming to extract global feature representations of the source domain and the target domain in the same feature space, so as to reduce the distribution differences between different domains. In terms of the technology used, domain adaptation methods can be mainly divided into shallow learning methods and deep learning methods.
[0003] Domain adaptation methods based on shallow learning are mostly based on statistical models, which can achieve good performance in terms of accuracy and stability. However, existing methods based on shallow learning still have poor results in cross-domain feature representation learning, which affects the performance results of domain adaptation.
[0004] In recent years, deep learning methods have been widely used in the field of domain adaptation due to their excellent feature learning capabilities and their ability to map the feature representations of the source domain and the target domain into the same new feature space. However, existing deep neural networks require a large amount of labeled or unlabeled training data to optimize the network and model, and it is often very difficult to obtain a large amount of training data in real application scenarios. Summary of the invention
[0005] The purpose of the present invention is to overcome the defects of the prior art and provide a domain adaptation method based on prompt learning. The input sentence is embedded using template prompts. Through the pre-trained language model, the target domain classification task can be converted into a probability calculation problem of label words, so as to perform more accurate classification for the domain adaptation classification task.
[0006] The object of the present invention is achieved by: a domain adaptation method based on prompt learning, comprising the following steps:
[0007] 1) Select the Bert model, use the pre-trained language model as the backbone, and set the template and label words in the prompt learning method;
[0008] 2) Construct the required prompt learning model, use the prompt learning data loading function to load and process the data for the data set, and then perform the domain adaptation task;
[0009] 3) Randomly select a small number of source domain data samples for training, then embed the sentences of the target domain into the same template, perform masked language modeling through the pre-trained language model, and classify and predict the input target domain sentences.
[0010] Furthermore, the step 1) specifically includes:
[0011] Step 1.1) Select the pre-trained language model Bert as the backbone;
[0012] Step 1.2) Template setting: The template is used to modify the original input. Different templates are manually set according to the content of different data sets. The original input is modified and encapsulated. For each instance x, the template is first used to map x to the prompt input x. prompt =T(x);
[0013] Step 1.3) Setting of label words: Project the original label into a set of label words. There is an injective mapping function Y→V, it connects the class set and the tag word set, and maps a set of tag words that are close to their meanings based on the original label.
[0014] Furthermore, the step 2) specifically includes:
[0015] Step 2.1) construct a prompt learning model, call the prompt learning classification function in the openprompt third-party library, the prompt learning classification function includes three parameters, namely, the pre-trained language model, the template, and the label word, and assign the three variables obtained in step 1) to them respectively, so as to obtain the prompt model;
[0016] Step 2.2) Load and process the data sets in the source domain and the target domain, and call the prompt data loading function in the openprompt third-party library. The prompt data loading function includes four parameters, namely, the data set, the word segmenter, the template, and the word segmentation packaging class. The values to be assigned to the word segmenter and the word segmentation packaging class are obtained by calling the function to load the pre-trained language model, and then the processed training and test data sets are obtained to perform the domain adaptation task.
[0017] Further, the step 3) includes:
[0018] Step 3.1) After training on a small amount of source domain data, when the target domain sentence is embedded into the template, it will be classified into the category with label y, where y∈Y and the label word set is V y = {v1, v2, ..., v n},V y is a subset of the entire vocabulary V, that is, V y ∈V, and V yis mapped to the category with label y; in the pre-trained language model, V y Each word in is filled into [MASK], and its probability is expressed as P([MASK]=v∈V y |X p ); Therefore, the target domain classification task is converted into the probability calculation problem of label words, and its calculation formula is shown in (1):
[0019] P(y∈Y|X p )=P([MASK]=v∈V y |X p ) (1)
[0020] Step 3.2) Find V y After calculating the probability of each label word in the target domain, the predicted probability of each label word in the target domain is mapped to a specific category label. The average of the predicted scores is used as the basis for the final category classification. The predicted label As shown in (2):
[0021]
[0022] Step 3.3) In the target domain sentence, if V1 = {computer}'s calculated prediction probability is greater than If V2 = {recreation}, then the sentence in the target domain is finally predicted to be classified as Computer.
[0023] The present invention adopts the above technical solution, and compared with the prior art, the beneficial effects are as follows: (1) the present invention uses a prompt learning method, which does not require a large amount of source domain data for training, and can solve the distortion of semantic feature structures in the source domain and the target domain and the loss of category discriminability, making the method more practical;
[0024] (2) The present invention uses template prompts to embed input sentences. By pre-training the language model, the target domain classification task can be converted into a probability calculation problem of label words. The predicted probability of each label word in the target domain is mapped to a specific category label, and the average value of the predicted probability is used as the basis for the final category classification, so that it can be more conveniently and flexibly applied to domain adaptation problems.
[0025] (3) The present invention designs a method of applying prompt learning to domain adaptation, using different prompt parts to improve the accuracy of different domain adaptation tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 The overall framework diagram of the present invention. DETAILED DESCRIPTION
[0027] like Figure 1 A domain adaptation method based on prompt learning is shown, comprising the following steps:
[0028] 1) Select the Bert model, use the pre-trained language model as the backbone, and set the template and label words in the prompt learning method;
[0029] Step 1.1) Select the pre-trained language model Bert as the backbone; Bert uses the masked language model method to train the semantic understanding ability of words. In the domain-adaptive single-sentence classification task, the Bert model input is rewritten as a single sentence and the sentence start label [CLS] is retained. The model predicts the output feature of the sentence start label [CLS] as the classification label, and calculates the cross entropy between the classification label and the true label as shown in (3).
[0030] H(p,q)=-∑ x p(x)logq(x) (3)
[0031] Take it as the optimization target and perform fine-tuning training on the task data;
[0032] Step 1.2) Template setting: The template is used to modify the original input. Different templates are manually set according to the content of different data sets. The original input is modified and encapsulated. For each instance x, the template is first used to map x to the prompt input x. prompt = T(x); For example, for a binary sentiment classification task, we set the template T(·) = “·It was [MASK]” and map x to x prompt = “x It was [MASK]”; Templates have always been one of the important factors affecting the effectiveness of prompt learning methods. Different templates have different effects on domain adaptation tasks.
[0033] Step 1.3) Setting of label words: Project the original label into a set of label words. There is an injective mapping function Y→V, it connects the class set and the label word set, and maps a set of label words that are close to the original label in meaning. For example, if the original label is "negative" or "positive", then the mapped set of label words can be: "bad", "good, wonderful, great".
[0034] 2) Construct the required prompt learning model (PromptModel), use the prompt learning data loading function (PromptDataLoader) to load and process the data set, and then perform our domain adaptation task;
[0035] Step 2.1) Construct a prompt learning model (PromptModel), call the prompt learning classification (PromptForClassification) function in the openprompt third-party library, the prompt learning classification function includes three parameters, namely the pre-trained language model (plm), template (template), and label word (verbalizer), assign the three variables obtained in step 1) respectively, so as to obtain the prompt model;
[0036] Step 2.2) Given a source domain D with a small amount of labeled data s and a target domain D with unlabeled data t ,in and and are the i-th instance in the source domain and the j-th instance in the target domain, respectively. represents the label of the i-th instance in the source domain, N s and N t Represent the number of instances in the source domain and the target domain respectively; load and process the datasets in the source domain and the target domain, call the prompt data loading (PromptDataLoader) function in the openprompt third-party library, the prompt data loading function includes four parameters, namely dataset, tokenizer, template, tokenizer_wrapper_class, where the values assigned to the tokenizer and tokenizer_wrapper_class are obtained by calling the load_plm function to load the pre-trained language model, and then obtain the processed training and test datasets to perform domain adaptation tasks.
[0037] 3) Randomly select a small number of source domain data samples for training, then embed the sentences in the target domain into the same template, perform masked language modeling through the pre-trained language model, and classify and predict the input target domain sentences;
[0038] Step 3.1) After training on a small amount of source domain data, when the target domain sentence is embedded into the template, it will be classified into the category with label y, where y∈Y and the label word set is V y = {v1, v2, ..., v n},V y is a subset of the entire vocabulary V, that is, V y ∈V, and V y is mapped to the category with label y; in the pre-trained language model, V yEach word in is filled into [MASK], and its probability is expressed as P([MASK]=v∈V y |X p ); Therefore, the target domain classification task is converted into the probability calculation problem of label words, and its calculation formula is shown in (4):
[0039] P(y∈Y|X p )=P([MASK]=v∈V y |X p ) (4)
[0040] Step 3.2) Find V y After calculating the probability of each label word in the target domain, the predicted probability of each label word in the target domain is mapped to a specific category label. The average of the predicted scores is used as the basis for the final category classification. The predicted label As shown in (5):
[0041]
[0042] Step 3.3) In the target domain sentence, if V1 = {computer}'s calculated prediction probability is greater than If V2 = {recreation}, then the sentence in the target domain is finally predicted to be classified as Computer.
[0043] The present invention can be further illustrated by the following experiments:
[0044] In order to test the effectiveness of the present invention, prediction results are achieved on 20 Newsgroups and Reuters-21578 datasets, respectively. The 20 Newsgroups dataset contains four main categories, namely Comp, Rec, Sci and Talk. The largest category Comp is regarded as a positive class, and one of the other three categories is selected as a negative class, so there are a total of three cross-domain tasks; the Reuters-21578 dataset mainly includes three categories: organization, person and place, so we can set three cross-domain tasks, such as "organization→person", "organization→place" and "person→place".
[0045] In order to demonstrate the performance of the test results, convolutional neural network (CNN), BERT, and autoencoder were selected for comparison in the six cross-domain tasks in the two data sets. The test results of the data sets are shown in Table 1. It can be seen from Table 1 that the accuracy indicators of the results of the six cross-domain tasks in the two data sets are better than those of other methods.
[0046] Table 1 Accuracy of experimental results
[0047]
[0048] The present invention provides a domain adaptation method based on prompt learning, which uses template prompts to embed input sentences. Through pre-training language models, the target domain classification task can be converted into a probability calculation problem of label words, and the predicted probability of each label word in the target domain is mapped to a specific category label. The average value of the predicted probability is used as the basis for the final category classification, so that it can be more conveniently and flexibly applied to domain adaptation problems.
[0049] The present invention is not limited to the above-mentioned embodiments. On the basis of the technical solution disclosed in the present invention, technicians in this field can make some substitutions and deformations to some technical features therein according to the disclosed technical content without creative labor, and these substitutions and deformations are all within the protection scope of the present invention.
Claims
1. A domain adaptation method based on prompt learning, characterized in that: The following steps are involved: 1) Select the Bert model, use the pre-trained language model as the backbone, and set the template and label words in the prompt learning method; 2) Construct the required prompt learning model, use the prompt learning data loading function to load and process the data for the data set, and then perform the domain adaptation task; The step 2) specifically includes: Step 2.1) Construct a prompt learning model, call the prompt learning classification function in the openprompt third-party library, the prompt learning classification function includes three parameters, namely, the pre-trained language model, the template, and the label word, and assign the three variables obtained in step 1) to them respectively, so as to obtain the prompt model; Step 2.2) Load and process the data sets in the source domain and the target domain, call the prompt data loading function in the openprompt third-party library, the prompt data loading function includes four parameters, namely, the data set, the word segmenter, the template, and the word segmentation packaging class. The values to be assigned to the word segmenter and the word segmentation packaging class are obtained by calling the function to load the pre-trained language model, and then the processed training and test data sets are obtained to perform the domain adaptation task; 3) Randomly select a small number of source domain data samples for training, then embed the sentences in the target domain into the same template, perform masked language modeling through the pre-trained language model, and classify and predict the input target domain sentences; The step 3) includes: Step 3.1) After training on a small amount of source domain data, when the target domain sentence is embedded into the template, it will be classified into the category with label y, where y∈Y and the label word set is V y = {v1, v2, ..., v n },V y is a subset of the entire vocabulary V, that is, V y ∈V, and V y is mapped to the category with label y; in the pre-trained language model, V y Each word in is filled into [MASK], and its probability is expressed as P([MASK]=v∈V y |X p ); Therefore, the target domain classification task is converted into the probability calculation problem of label words, and its calculation formula is shown in (1): P(y∈Y|X p )=P([MASK]=v∈V y |X p ) (1) Step 3.2) Find V y After calculating the probability of each label word in the target domain, the predicted probability of each label word in the target domain is mapped to a specific category label. The average of the predicted scores is used as the basis for the final category classification. The predicted label As shown in (2): Step 3.3) In the target domain sentence, if V1 = {computer}'s calculated prediction probability is greater than If V2 = {recreation}, then the sentence in the target domain is finally predicted to be classified as Computer.
2. A domain adaptation method based on prompt learning according to claim 1, characterized in that: The step 1) specifically includes: Step 1.1) Select the pre-trained language model Bert as the backbone; Step 1.2) Template setting: The template is used to modify the original input. Different templates are manually set according to the content of different data sets. The original input is modified and encapsulated. For each instance x, the template is first used to map x to the prompt input x. prompt =T(x); Step 1.3) Setting of label words: Project the original label into a set of label words. There is an injective mapping function Y→V, it connects the class set and the tag word set, and maps a set of tag words that are close to their meanings based on the original label.
