A prompt learning-based pseudo-label iteration domain adaptation method
By employing a pseudo-label iterative method based on prompting learning, and utilizing a pre-trained language model for masked language modeling and multiple iterations, the problem of insufficient data in cross-domain feature representation learning is solved, and efficient target domain classification is achieved.
Patent Information
- Application Number
- CN202211273240.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-18
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2042-10-18
AI Technical Summary
Existing shallow learning-based domain adaptation methods are ineffective in cross-domain feature representation learning, and deep neural networks require a large amount of training data, which is difficult to obtain in real-world applications.
A pseudo-labeling iterative method based on cue learning is adopted. By manually setting language templates and using a pre-trained language model for masked language modeling, pseudo-labels of target domain data are predicted multiple times, and the classification of the target domain is finally achieved.
It can achieve accurate target domain classification without a large amount of training data, solves the problems of semantic feature structure distortion and loss of class discriminability in the source and target domains, and improves the accuracy of domain adaptation tasks.
Smart Images

Figure CN115640829B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of transfer learning research, and particularly relates to a domain adaptation method based on pseudo-label iteration of prompt learning. BACKGROUND
[0002] Traditional machine learning assumes that training data and test data are independent and identically distributed, but in real application scenarios, data in different domains are different but similar to each other. In order to solve this problem, in recent years, the research on domain adaptation has attracted widespread attention. The 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 difference between different domains. In terms of the technology used, the domain adaptation method can be mainly divided into shallow learning method and deep learning method.
[0003] The domain adaptation method based on shallow learning is mainly based on statistical model. This kind of method can achieve good performance in accuracy and stability. However, the existing method based on shallow learning still has poor effect in cross-domain feature representation learning, thereby affecting the performance of domain adaptation.
[0004] In recent years, due to the excellent feature learning ability of deep learning method, the feature representations of the source domain and the target domain can be mapped to the same new feature space, so it has been widely used in the field of domain adaptation. However, the existing deep neural network needs 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
[0005] The purpose of the present application is to overcome the defects of the prior art and provide a domain adaptation method based on pseudo-label iteration of prompt learning. After manually setting a language template, only a small amount of source domain labeled samples are used for training, and the input sentences of the target domain are embedded into the same template, so that the pre-trained language model performs mask language modeling. Through multiple iterations, the labels of part of the data samples in the target domain are predicted, and then the labeled data are used to test the classification of all data in the target domain, so as to realize the classification prediction of the target domain, solve the distortion of semantic feature structure and the loss of class distinguishability in the source domain and the target domain, and realize more accurate classification for the domain adaptation classification task.
[0006] The purpose of the present application is achieved by a domain adaptation method based on pseudo-label iteration of prompt learning, comprising the following steps:
[0007] 1) Select the Bert model, set the template and label word in the prompt learning method as the backbone of the pre-trained language model;
[0008] 2) Construct the required prompt learning model, randomly select a small amount of source domain data samples for training, then embed the sentences without labels in the target domain into the same template, and predict the pseudo-labels of the input target domain sentences through pre-trained language model mask language modeling;
[0009] 3) Randomly select a small amount of pseudo-label target domain data for training, predict the pseudo-labels of the target domain data again through the prompt learning method, and obtain the labels of part of the data samples in the target domain through multiple iterations. Finally, a small amount of target domain data samples with labels are selected for training in the target domain label, and finally all the data in the target domain are classified and tested.
[0010] As a further limitation of the application, step 1) specifically comprises:
[0011] Step 1.1) Select the pre-trained language model Bert as the backbone;
[0012] Step 1.2) Template setting, embedding the original input into the template for prompt learning, manually setting different templates according to the content of different data sets, modifying and packaging the original input, for each instance x, first use the template to map x to the prompt input x prompt =T(x);
[0013] Step 1.3) Label word setting: project the original label into a set of label words, there is a one-to-one mapping function It connects the class set and the label word set, and according to the original label, a set of label words close to its meaning is mapped.
[0014] As a further limitation of the application, step 2) specifically comprises:
[0015] Step 2.1) Construct the prompt learning model, call the prompt learning classification function in the openprompt third-party library, which includes three parameters, pre-trained language model, template, and label word, assign the three variables obtained in step 1) to get the prompt model;
[0016] Step 2.2) After training 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, 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 into the category labeled y; in the pre-trained language model, each word in V y is filled into [MASK], and the probability is represented as P ([MASK] = v ∈ V y |X p ); the target domain classification task is converted into a probability calculation problem of the label word, and the calculation formula is shown in (1):
[0017] P (y ∈ Y |X p ) = P ([MASK] = v ∈ V y |X p ) (1)
[0018] Step 2.3) After obtaining the probability of each label word in V y , the predicted probability of each label word in the target domain is mapped to the specific category label, and the average value of the prediction score is taken as the basis of the final pseudo label, and the predicted pseudo label is shown in (2):
[0019]
[0020] As a further limitation of the application, the step 3) comprises:
[0021] Step 3.1) After obtaining the pseudo label in the target domain, a small amount of data with the pseudo label target domain is selected for training, and then the pseudo label prediction of all data in the target domain is performed again through the prompt learning method;
[0022] Step 3.2) After multiple iterations, multiple different pseudo labels of the target domain data are obtained, and a threshold k is set, and if the number of the same pseudo label of a single data in the target domain is equal to k after multiple iterations, the pseudo label is the label of the target domain data;
[0023] Step 3.3) Finally, the threshold is set to obtain the label of part of the data samples in the target domain, and then a small amount of target data samples with labels are selected for training in the target domain label, and all sentences without labels in the target domain are embedded into the prompt template, and the mask language modeling is performed through the pre-trained language model, and finally the classification test of all data in the target domain is performed.
[0024] The above technical scheme is adopted in the application, compared with the prior art, and the beneficial effects are: (1) the pseudo label iteration method based on prompt learning is used in the application, a large amount of source domain data is not needed for training, the pseudo label of the target domain is iterated, part of the labels of the target domain are predicted, and the distortion of the semantic feature structure and the loss of class distinguishability in the source domain and the target domain can be solved, so that the method has stronger practicability.
[0025] (2) This invention uses template prompts to embed the input statement. Through a pre-trained language model, the task of predicting the pseudo-label probability of the target domain can be transformed into the problem of calculating the probability of the label word. The predicted probability of each label word in the target domain is mapped to a specific category label to obtain the pseudo-label in the target domain. Then, these pseudo-labels are used to predict the label of the target domain again. Through different iterations, the label of some data in the target domain is finally determined. Then, a small number of labels in the target domain are selected to classify and predict all data in the target domain, so as to be more accurately applied to the domain adaptation problem and achieve better performance.
[0026] (3) The present invention designs a method for learning prompts and applies iterative pseudo-labels to domain adaptation, thereby improving the accuracy of different domain adaptation tasks by using different prompt templates and iteration times. Attached Figure Description
[0027] Figure 1 Overall framework diagram of the present invention. Detailed Implementation
[0028] like Figure 1 The illustrated method for domain adaptation based on prompt learning and iterative pseudo-labeling includes the following steps:
[0029] 1) Select the BERT model, use this pre-trained language model as the backbone, and set the template and tag words in the prompt learning method;
[0030] 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 input of the BERT model is rewritten into a single sentence and the sentence beginning label [CLS] is retained. The model prediction uses the output features of the sentence beginning label [CLS] as the classification label. The cross-entropy between the classification label and the real label is calculated as shown in (1).
[0031] H(p,q)=-∑ x p(x)logq(x) (1)
[0032] This is used as the optimization target, and fine-tuning is performed on the task data.
[0033] Step 1.2) Template setting: Templates are used to modify the original input. Different templates are manually set according to the content of different datasets to modify and encapsulate the original input. 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, set the template T(·) = "·It was [MASK]" and map x to xprompt = "x It was[MASK]" ; Template has always been an important factor affecting the effectiveness of prompt learning method, and different templates have different effects on domain adaptation tasks;
[0034] Step 1.3) Setting of label words: Project the original label into a set of label words, there is a single mapping function It connects the class set and the label word set, and maps a set of label words close to its meaning according to the original label; For example, if the original label is "negative", "positive", then a set of label words can be "bad", "good, wonderful, great".
[0035] 2) Construct the required prompt learning model, randomly select a small amount of source domain data samples for training, then embed the unlabeled target domain sentences into the same template, and predict the pseudo label of the input target domain sentence through the mask language modeling of the pre-trained language model;
[0036] Step 2.1) Construct prompt learning model (PromptModel), call prompt learning classification (PromptForClassification) function in openprompt third-party library, prompt learning classification function includes three parameters, pre-trained language model (plm), template (template), label word (verbalizer), assign the three variables obtained in step 1) into it, so as to get the prompt model;
[0037] Step 2.2) After training a small amount of source domain data, when the target domain sentence is embedded into the template, it will be classified into the class 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 class with label y; In the pre-trained language model, each word in V y is filled into [MASK], and its probability is represented as P([MASK]=v∈V y |X p ); Therefore, the target domain classification task is converted into a probability calculation problem of label words, and its calculation formula is shown in (2):
[0038] P(y∈Y|X p )=P([MASK]=v∈V y |X p ) (2)
[0039] Step 2.3) After obtaining the probability of each label word in the target domain, the predicted probability of each label word in the target domain is mapped to the specific category label, and the average value of the prediction score is used as the basis for the final pseudo label, and the pseudo label is predicted y As shown in (3):
[0040]
[0041] 3) A small amount of pseudo-labeled target domain data is randomly selected for training, and the pseudo label of the target domain data is predicted again through the prompt learning method. Through multiple iterations, the labels of part of the data samples in the target domain can be obtained. Finally, a small amount of labeled target domain data samples are selected for training, and finally all the data in the target domain are classified and tested;
[0042] Step 3.1) After obtaining the pseudo label of the target domain, a small amount of data with pseudo label in the target domain is selected for training, and the pseudo label of all data in the target domain is predicted again through the prompt learning method;
[0043] Step 3.2) After multiple iterations, multiple different pseudo labels of the target domain data are obtained. Then we set a threshold k. If the number of the same pseudo label of a single data in the target domain is equal to k after multiple iterations, we consider that the pseudo label is the label of the target domain data;
[0044] Step 3.3) Finally, through the setting of the threshold, the labels of part of the data samples in the target domain can be obtained, and then a small amount of labeled target domain data samples are selected for training. All unlabeled target domain sentences are embedded into the prompt template, which 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, there is a one-to-one mapping function V y is mapped to the category with label y. In the pre-trained language model, each word in V y is filled into [MASK], and its probability can be represented as Therefore, the target domain classification task can be converted into a probability calculation problem of label words, and its calculation formula is shown in (4):
[0045]
[0046] After obtaining V y After obtaining the probability of each label word in the target domain, the prediction probability of each label word in the target domain is mapped to a specific class label, and the average value of the prediction score is taken as the basis for the final class classification, and the prediction label The calculation formula is shown in (5):
[0047]
[0048] Finally, in the target domain sentence, if the calculated prediction probability of V1={computer} is greater than the calculated prediction probability of V2={recreation}, then the sentence in the target domain is finally predicted to be classified into the Computer class, wherein Computer and Recreation represent original labels, and computer and recreation represent label words.
[0049] The present application can be further illustrated by the following experiments:
[0050] In order to test the effectiveness of the present application, the prediction results are realized on the 20 newsgroup and Reuters-21578 data sets respectively, wherein the 20 newsgroup data set contains four main categories, namely Comp, Rec, Sci and Talk, the maximum category Comp is regarded as the positive class, and one of the other three categories is selected as the negative class, so there are six cross-domain tasks; the Reuters-21578 data set mainly includes three categories of organization, person and place, so three cross-domain tasks can be set, such as "organization->person", "organization->place" and "person->place".
[0051] In order to show the performance of the test results, among the nine cross-domain tasks in the two data sets, Bert, convolutional neural network (CNN), self-encoder-based domain adaptation method (SDA) and prompt learning-based domain adaptation method (Prompt) are selected as comparison, and the data set test results are shown in Table 1, and it can be known from Table 1 that the accuracy rate indicators of the results of the present application in the nine cross-domain tasks in the two data sets are better than those of other methods.
[0052] Table 1 Accuracy rate of experimental results
[0053]
[0054] The application provides a domain self-adaption method based on prompt learning and pseudo-label iteration, after a language template is manually set, only a small amount of source domain labeled samples are used for training, input sentences of the target domain are embedded into the same template, a pre-training language model is used for mask language modeling, through multiple iterations, labels of part of data samples in the target domain are predicted, then all data of the target domain are classified and tested through the label data, so that classification prediction of the target domain is realized, and the accuracy of the classification result in the target domain is improved.
[0055] The application is not limited to the above-mentioned embodiments, and on the basis of the technical solutions disclosed in the application, those skilled in the art can make some substitutions and deformations to some technical features according to the disclosed technical content without creative labor, and the substitutions and deformations are all within the protection scope of the application.
Claims
1. A domain adaptation method based on iterative pseudo-labeling using cue learning, characterized in that, Includes the following steps: 1) Select the BERT model, use this pre-trained language model as the backbone, and set the template and tag words in the prompt learning method; 2) Construct the required prompt learning model, randomly select a small number of source domain data samples for training, then embed sentences in the target domain without labels into the same template, perform masked language modeling through a pre-trained language model, and predict the pseudo-labels of the input target domain sentences. Step 2.1) Construct a prompt learning model by calling the prompt learning classification function in the openprompt third-party library. The prompt learning classification function includes three parameters: the pre-trained language model, the template, and the label word. Assign the three variables obtained in step 1) to the prompt model. Step 2.2) After training on a small amount of source domain data, when a sentence from the target domain is embedded into the template, it will be classified into the category labeled y, where y∈Y, and the set of labeled words is V. y ={v1, v2, ..., v n }, V y It is a subset of the entire vocabulary V, that is, V y ∈V, and V y It is mapped to a category labeled y; in a pre-trained language model, V y Each word in the text is filled into [MASK], and its probability is represented as P([MASK]=v∈V). y |X p The probability calculation problem of converting the target domain classification task into label words is shown in formula (1): P(y∈Y|X p )=P([MASK]=v∈V y |X p ) (1) Step 2.3) After calculating V y After calculating the probability of each tag word in the target domain, the predicted probability of each tag word is mapped to a specific category label. The average of the predicted scores is used as the basis for the final pseudo-label. As shown in (2): 3) Randomly select a small number of pseudo-labeled target domain data for training. Through the cue learning method, predict the pseudo-label of the target domain data again. Through multiple iterations, obtain the labels of some data samples in the target domain. Finally, select a small number of labeled target domain data samples from the target domain labels for training. Finally, perform classification tests on all data in the target domain. Step 3.1) After obtaining the pseudo-labels in the target domain, select a small amount of data in the target domain with pseudo-labels for training, and then use the cue learning method to predict the pseudo-labels for all data in the target domain again. Step 3.2) After multiple iterations, multiple pseudo-labels of different target domain data are obtained. Then, a threshold k is set. After multiple iterations, if the number of identical pseudo-labels of a single data in the target domain is equal to k, then the pseudo-label is the label of the target domain data. Step 3.3) Finally, by setting the threshold, we obtain the labels of some data samples in the target domain. Then, we select a small number of labeled target data samples from the target domain labels for training. We embed all unlabeled sentences in the target domain into the prompt template, perform masked language modeling through a pre-trained language model, and finally perform classification testing on all data in the target domain.
2. The domain adaptation method based on cue learning and iterative pseudo-labeling according to claim 1, characterized in that, Step 1) specifically includes: Step 1.1) Select the pre-trained language model BERT as the backbone; Step 1.2) Template setting: Embed the raw input into the template for prompt learning. Manually set different templates according to the content of different datasets, modifying and encapsulating the raw input. For each instance x, first use the template to map x to the prompt input x. prompt =T(x); Step 1.3) Setting the tag words: Projecting the original tags onto a set of tag words, there exists an injective mapping function. Y→V connects the category set and the tag word set, mapping a set of tag words with similar meanings to the original tag.