Natural language understanding method based on feature adaptation of large language model
By introducing a feature-adaptive natural language understanding method into the large language model and using lightweight modulators to extract task features from common features, the adaptability and input length limitations of the large language model in natural language understanding tasks are solved. Achieving more efficient label prediction and data scalability.
Patent Information
- Application Number
- CN202411016848.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-07-29
AI Technical Summary
Existing large language models have adaptability issues and input length limitations when predicting specific task labels in natural language understanding tasks, resulting in the inability to fully utilize more task examples to improve performance.
A feature adaptation method based on large language models is designed. Task adaptive features are extracted from general features through lightweight task-specific modulators, and a small number of task examples are used as fixed model input prefixes, and the remaining examples are used as training data for optimization. Modulator solves the problem of input length limitation and data unexpandability.
It achieves better downstream task performance and data scalability, supports incremental annotation of examples to optimize performance, and improves the performance of natural language understanding tasks.
Smart Images

Figure CN118551204B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language understanding, and in particular to a feature-adaptive natural language understanding method based on a large language model. Background Art
[0002] With the popularization of the Internet and the rapid growth of digital information, massive amounts of text data have emerged from social media, news websites, forums, emails, blogs, etc. These data contain human thoughts, emotions, knowledge and information, and have extremely high research value. However, most of the massive text data lacks the necessary labels and classification information, which is not conducive to data analysis and application, such as in information retrieval, sentiment analysis and other fields. At the same time, manual data labeling requires a lot of time and human resources, and is often affected by subjective factors, and the quality and consistency of labels cannot be guaranteed. Therefore, automatic labeling of massive text data has become a common and important research and application problem.
[0003] The automatic labeling of massive text data requires natural language understanding methods. In addition to the traditional method that requires a large amount of labeled data for supervised training for specific tasks, the emergence of large language models provides an alternative solution that only requires a small number of task examples to complete data labeling, namely contextual learning. Contextual learning adds a small number of input-label pairs, namely task examples, as prompts to the test sample through task-specific templates, and inputs them into the large language model to complete the prediction of the test sample label. However, this method has two obvious flaws. First, the training goal of the large language model during the pre-training process is language modeling, not a specific downstream task. There is an adaptability problem in predicting downstream task labels based on the general features in the large language model. In addition, due to the input length limit of the large language model, contextual learning can only add a small number of task examples as prompts to improve the label prediction performance, and cannot use more task examples to obtain further performance improvement. Summary of the invention
[0004] In view of the above-mentioned defects, the present invention proposes a natural language understanding method based on feature adaptation of a large language model to improve the performance of the large language model in natural language understanding tasks. The present invention proposes two innovative ideas. First, on the basis of obtaining general features through a large language model, a lightweight modulator for a specific task is designed to extract task-adaptive features from general features and complete the prediction; second, the practice of inputting all task examples into the model in contextual learning is abandoned, and only a small number of examples are used as fixed model input prefixes, and the remaining examples are used as training data to optimize the modulator for specific tasks, which solves the problem that the number of examples is limited by the model input length, that is, the data is not scalable. In addition, this method is suitable for low-resource scenarios where massive data lacks annotation labels and only has a few task examples. And because of data scalability, it supports incremental annotation examples to further optimize performance, so it has good application prospects.
[0005] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0006] A feature-adaptive natural language understanding method based on a large language model, which uses a natural language understanding model to obtain test samples for specific tasks. Tags , specifically including the following steps:
[0007] Step 1: Construct a training set for a specific task, which contains multiple training samples. and the corresponding labels , randomly selected from the training set The training samples constitute the task example set , They are The Task example samples and corresponding labels, the training set excludes the task example set After the remaining The remaining sample set consists of , They are The labeled samples and corresponding labels;
[0008] Step 2: Feature extraction: The individual task examples in the sample are provided by task-specific templates. Composition hint prefix , each template Packaged labeled samples Add the same prompt prefix Then input into the large language model:
[0009] ;
[0010] in, Represents the forward propagation of the large language model, where the last hidden state of the last layer in the large language model is used as a universal feature ; Indicates the labeled sample wrapped by the template without the corresponding label, in the form of a string. is a placeholder. Indicates that in a given Under the condition of As input;
[0011] Step 3: Task-specific modulator: For the remaining sample set Each labeled sample in After extracting the common features, they are paired with the corresponding labels and then used as supervisory signals to train the modulator for a specific task. :
[0012] ;
[0013] in, represents the parameters of the modulator, Denotes the loss function of the modulator When the minimum value is obtained The value of Represents the remaining sample set The number of elements in , ;
[0014] Step 4: During inference, the modulator of the trained natural language understanding model can extract task-specific features from general features and map them to the label space: ; For test samples The universal features obtained after passing through the large language model; Indicates a given Under this condition, the probability that the possible label is y is, express Possible tags; largest The corresponding y is the test sample Final Label ;
[0015] The specific task is a sentiment classification task; the test sample and the training sample are both sentiment texts; the label is the sentiment category of the sentiment text; or,
[0016] The specific task is a subjective discrimination task; the test sample and the training sample are both evaluation texts; and the label is a subjective discrimination type of the evaluation text.
[0017] Furthermore, the modulator is a logistic regression model, a linear support vector machine or a multi-layer perceptron.
[0018] Furthermore, when the specific task is a sentiment classification task, the modulator is a logistic regression model, and the loss function of the modulator is The L2 norm loss is adopted.
[0019] Furthermore, when the specific task is a subjective discrimination task, the modulator is a linear support vector machine, and the loss function of the modulator is The L1 norm loss is adopted.
[0020] Compared with the prior art, the beneficial technical effects of the present invention are:
[0021] The present invention includes two parts: a feature extractor based on a large language model and several task examples, and a lightweight modulator for specific tasks. The large language model with several task examples can fully call on the knowledge learned in the pre-training process to obtain general features containing rich semantic information, and then complete the task extraction and label prediction on the specific task through the additionally introduced trained lightweight modulator, so as to obtain better downstream task performance; in addition, the method has data scalability, and incremental labeled data can be added to train the lightweight modulator, so as to obtain more powerful feature extraction and mapping performance of specific task features to labels, thereby further improving the performance on downstream tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is a structural diagram of the natural language understanding model of the present invention. DETAILED DESCRIPTION
[0023] A preferred embodiment of the present invention is described in detail below with reference to the accompanying drawings.
[0024] The natural language understanding task can usually be formalized as: given a sample-label pair under a specific task A collection of training and testing samples , by learning the mapping relationship between samples and labels under this specific task, correctly predict the label of the test sample .
[0025] The natural language understanding model used in the present invention is as follows Figure 1 As shown in Figure 1, it includes the following two parts: (1) a feature extractor based on a large language model and several task examples, and (2) a lightweight task-specific modulator. In addition, in this method, the training set is divided into two parts: a small set of training samples and a task example set consisting of corresponding labels. And the remaining sample set . Figure 1 middle, , Subscript , , respectively represent the task example set and the remaining sample set The number of elements of , .
[0026] (1) Feature Extractor:
[0027] In this method, the large language model is actually regarded as a feature extractor with a general context learning form, which obtains general features for subsequent use. Specifically, just like in context learning, the present invention first randomly selects some training samples as task example samples , through task-specific templates Composition hint prefix .
[0028] Take the sentiment classification task as an example:
[0029] Suppose the training sample is "This movie is powerful, easy to understand, and interesting"; the corresponding label is "positive".
[0030] The template for the sentiment classification task can be set as “review: {x}, sentiment: {y}”.
[0031] Put the training sample into the template of the sentiment classification task, and get the prompt prefix "Comment: This movie is powerful, easy to understand, and interesting, sentiment: positive". That is, the prompt prefix is a string.
[0032] Then, the present invention packages each labeled sample into a template. Add the same prompt prefix Input into the large language model.
[0033] The common features of each labeled sample can be obtained by a simple forward propagation:
[0034] ;
[0035] in, Represents the forward propagation of the large language model, where the last hidden state of the last layer in the large language model is used as a labeled sample Common features of The features obtained here are used for language modeling of a large language model, rather than a specific downstream task, the so-called universal features, so they need to be feature refined before being used in downstream tasks.
[0036] (2) Task-specific modulators:
[0037] For a specific natural language understanding task, a lightweight modulator is introduced to refine general features to adapt to specific downstream tasks and perform final predictions. Since the downstream tasks are invisible to the large language model, there is inevitably a problem of task inadaptability. In other words, the general features from the large language model are not suitable for direct use on downstream tasks. In addition to the high-cost fine-tuning training of the large language model, an effective alternative solution is to use additional lightweight modules to perform feature adaptation for downstream tasks while maintaining the parameters and versatility of the large language model. Specifically, the present invention is a residual sample set. Each labeled sample in extracts common features and pairs them with corresponding labels, which are then used as supervision signals to train a lightweight modulator:
[0038] ;
[0039] in Indicates when the loss function reaches the minimum value The value of modulator It can be a logistic regression model, linear SVM, multi-layer perceptron, etc. The specific optimization goal The sum algorithm depends on the specific choice of modulator and possibly on the specific task.
[0040] After training, the modulator can be used as a solver for a specific task. During inference, the modulator can extract task-specific features from general features and map them directly to the label space without the need for label textualization introduced in context learning:
[0041] ;
[0042] ;
[0043] For test samples Common features obtained through large language models; Indicates the test samples that do not contain the corresponding labels in the template packaging. Indicates that in a given Under the condition of As input; Indicates a given conditions, The probability that a possible label is y, express Possible tags; largest The corresponding y is the test sample Final Label .
[0044] In summary, this method achieves data scalability by splitting the labeled training set (i.e., using a fixed small portion of the data as the task example set and the remaining scalable portion for supervising the feature adaptation process) and multiple model calls. In addition, feature adaptation is achieved by refining the general features into task-specific features through trained task-specific modulators.
[0045] Embodiment 1
[0046] When the specific task is a sentiment classification task:
[0047] The training sample is: "This movie is powerful, easy to understand, and interesting", and the label is: "positive".
[0048] The test sample is: "No beauty, only clumsy jokes". The purpose of the sentiment classification task is to predict the label of the test sample: "negative".
[0049] The template for the sentiment classification task is “review: {x}, sentiment: {y}”.
[0050] The modulator for the sentiment classification task is a logistic regression model, and the loss function of the modulator is Using L2 norm loss, set the label of the training sample , the prediction value of the natural language understanding model is ,but .
[0051] Embodiment 2
[0052] When the specific task is a subjective judgment task:
[0053] The training sample is: "The script is not very good, even a talented person like xxx (actor) can't do it", and the label is: "subjective".
[0054] The test sample is: "After another drunken night, they quickly spent all their savings." The purpose of the subjective discrimination task is to predict the label of the test sample: "objective".
[0055] The template for the subjective judgment task is “evaluation: {x}, category: {y}”.
[0056] The modulator for the subjective discrimination task is a linear support vector machine, and the loss function of the modulator is L1 norm loss is used. Let the label of the training sample be , the prediction value of the natural language understanding model is ,but .
[0057] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention, and any reference numerals in the claims should not be regarded as limiting the claims involved.
[0058] In addition, it should be understood that although this specification is described in terms of implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.
Claims
1. A natural language understanding method based on feature adaptation of a large language model, It is characterized in that Use natural language understanding models to obtain test samples for specific tasks Tags , specifically including the following steps: Step 1: Construct a training set for a specific task, which contains multiple training samples. and the corresponding labels , randomly selected from the training set The training samples constitute the task example set , They are The Task example samples and corresponding labels, the training set excludes the task example set After the remaining The remaining sample set consists of , They are The labeled samples and corresponding labels; Step 2: Feature extraction: The individual task examples in the sample are provided by task-specific templates. Composition hint prefix , each template Packaged labeled samples Add the same prompt prefix Then input into the large language model: ; in, Represents the forward propagation of the large language model, where the last hidden state of the last layer in the large language model is used as a universal feature ; Indicates the labeled sample wrapped by the template without the corresponding label, in the form of a string. is a placeholder. Indicates that in a given Under the condition of As input; Step 3: Task-specific modulator: For the remaining sample set Each labeled sample in After extracting the common features, they are paired with the corresponding labels and then used as supervisory signals to train the modulator for a specific task. : ; in, represents the parameters of the modulator, Denotes the loss function of the modulator When the minimum value is obtained The value of Represents the remaining sample set The number of elements in , ; Step 4: During inference, the modulator of the trained natural language understanding model can extract task-specific features from general features and map them to the label space: ; For test samples The universal features obtained after passing through the large language model; Indicates a given Under this condition, the probability that the possible label is y is, express Possible tags; largest The corresponding y is the test sample Final Label ; The specific task is a sentiment classification task; the test sample and the training sample are both sentiment texts; the label is the sentiment category of the sentiment text; or, The specific task is a subjective discrimination task; the test sample and the training sample are both evaluation texts; the label is a subjective discrimination type of the evaluation text; The modulator is a logistic regression model, a linear support vector machine or a multi-layer perceptron.
2. The method for natural language understanding based on feature adaptation of a large language model according to claim 1, It is characterized in that When the specific task is a sentiment classification task, the modulator is a logistic regression model, and the loss function of the modulator is The L2 norm loss is adopted.
3. The feature-adaptive natural language understanding method based on a large language model according to claim 1, It is characterized in that When the specific task is a subjective discrimination task, the modulator is a linear support vector machine, and the loss function of the modulator is The L1 norm loss is adopted.
Citation Information
Patent Citations
Natural language processing method and device based on knowledge guidance prefix fine tuning, computing equipment, and storage medium
CN113987209A
Text processing model training method, text processing method and related equipment
CN116151236A
Prompt learning small sample classification method, system and equipment based on pre-training language model and medium
CN116415170A
Natural language processing machine learning frameworks trained using multi-task training routines
US20230419035A1
Systems and methods for text classification using label modular prompts
US20230419049A1
