A language model stable optimization method based on mixed prompt learning
By employing a hybrid cue learning approach, hard and soft cues are processed separately and interacted with each other. This approach combines deep interaction between multiple encoder and generator-decoder layers, addressing the adaptability and stability issues of pre-trained language models on specific downstream tasks and achieving higher prediction accuracy and stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XI AN JIAOTONG UNIV
- Filing Date
- 2024-04-17
- Publication Date
- 2026-07-31
AI Technical Summary
Existing pre-trained language models are not adaptable to specific downstream tasks and have high training costs. Furthermore, there are issues with the performance stability and initialization selection of hint learning, especially in scenarios with few samples where their effectiveness is limited.
We adopt a hybrid cue-based learning approach, which separates and interacts with hard and soft cues, designs corresponding sub-processes to model semantic and category information, utilizes a multi-encoder module and a generator-decoder layer for deep interaction, and combines masked language model loss and contrastive learning loss for optimization.
It improves the model's semantic understanding and class discrimination capabilities in sparse sample environments, reduces noise issues caused by random initialization prompts, and improves the accuracy and stability of prediction results.
Smart Images

Figure CN118364050B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence and natural language processing technology, and specifically relates to a method for stabilizing and optimizing a language model based on hybrid prompting learning. Background Technology
[0002] In the fields of artificial intelligence and natural language processing (NLP), pre-trained language models (PLMs) have become a cutting-edge technology in research and application. These models, such as GPT, BERT, and their subsequent variants, have learned rich language, knowledge, and logical reasoning capabilities through pre-training on large-scale text data, providing a strong foundation for various NLP tasks. Although pre-trained language models demonstrate a deep understanding and processing ability of language, they still face severe challenges such as adaptability to specific downstream tasks and high training costs. These challenges mainly stem from the large parameter scale of pre-trained language models and their dependence on large amounts of labeled data. Especially in specific data-sparse domains or low-sample scenarios, directly fine-tuning pre-trained language models is not only costly but also yields limited results. To address this issue, prompt learning has emerged as an emerging method for adapting pre-trained language models to downstream tasks. The core idea of prompt learning is to guide the model to handle specific tasks in a manner similar to that during pre-training by designing task-specific prompts (such as question templates), thereby effectively utilizing the knowledge and capabilities of the pre-trained model without significantly adjusting the model parameters. Hint learning has demonstrated superior performance across multiple domains, particularly in handling few-shot problems, where it can significantly reduce the need for labeled data and improve the model's generalization ability.
[0003] While cue learning has demonstrated promising application results, it still faces challenges related to performance stability and cue initialization. On one hand, hard cues rely heavily on carefully designed natural language templates, making their performance highly dependent on template selection and construction; different cue templates can lead to significant fluctuations in model performance. On the other hand, soft cues, by searching for optimal cues in the model's representation space, avoid directly using natural language, but their effective initialization also directly impacts model performance stability; furthermore, obtaining suitable soft cues for downstream tasks using pre-training methods incurs high computational costs. Moreover, existing research primarily focuses on single-type cues, lacking in-depth exploration of how to comprehensively utilize the advantages of both hard and soft cues, and how to design stable and efficient hybrid cue learning methods. Summary of the Invention
[0004] To overcome the shortcomings of the prior art, the present invention aims to provide a stable optimization method for language models based on hybrid cue learning. In a sparse sample environment, this method solves the stability problem faced by traditional cue learning by processing hard cues and soft cues separately and interacting with them. Based on the characteristics of different cues, corresponding sub-processes are designed to model semantic and category information, thereby improving semantic understanding and classification capabilities for different categories.
[0005] To achieve the above objectives, this invention mainly adopts the following approach: 1) In a sparse sample environment, the stability problem faced by traditional cue learning is addressed by processing hard cues and soft cues separately and allowing them to interact. Based on the characteristics of different cues, corresponding sub-processes are designed to model semantic and category information. 2) The text information processing utilizes a multi-encoder module. First, the PLM encoder encodes the hard cues and input text into semantic embedding vectors. Then, further semantic interaction processing is performed in the semantic encoder layer. Finally, a generative decoder interacts with the soft cues to enrich semantic representation and improve model performance. 3) The soft cue processing introduces a generative decoder layer to process soft cues, unlike the traditional method of directly concatenating soft cues to the input text. This layer allows soft cues to serve as query input, interacting with the output state from the semantic encoder, and achieving category information extraction and semantic enhancement through a cross-attention mechanism. 4) In the joint learning process, a dual loss function design was adopted to optimize model training, including two parts: masked language model loss and contrastive learning loss. Not only does the masked language model loss enable the model to efficiently understand semantic information, but the category-aware contrastive learning also improves the model's ability to distinguish between different categories.
[0006] The language model stabilization optimization method based on hybrid prompting learning disclosed in this invention can capture semantic and category information separately using hybrid prompts, thereby effectively solving the noise problem caused by random prompt initialization. The prediction results have high accuracy and small error, and can be applied to various language model classification scenarios, which has high practical value.
[0007] The specific technical solution adopted in this invention is as follows: A method for stabilizing and optimizing a language model based on hybrid prompting learning includes the following steps: Step 1: Through the encoding conversion process, using the task category of the classification dataset as a constraint, obtain a list of character IDs for the input text and task-specific hard cues; Step 2: Process the character ID list using a prompt-based multi-encoder to obtain a semantic information output vector; Step 3: Use the soft cue as the query input to the generator decoder, interact with the semantic information output vector, and obtain the category-aware cue through cross-attention mechanism and processing. Step 4: Process the semantic information output vector and category-aware cues separately, calculate the loss of each part, integrate them, update the model, and then train it. Step 5: Perform natural language processing using the trained model.
[0008] In one embodiment, step 1 involves obtaining input text and label information from a natural language classification dataset, and then... and task-specific hard hints The concatenation is performed, and the resulting text is encoded using a tokenizer to convert it into a list of character IDs; in, Represents a list The first in Input text, list This represents the input text in a natural language classification dataset. The number of input texts; The label is represented as , Represents a list The first in Tags, list This represents the label in a natural language classification dataset. The label element consists of 0s and 1s, representing whether the corresponding input text is a negative sample or a positive sample, respectively. A positive sample is a sample whose label or result belongs to the target category, and a negative sample is a sample whose label or result does not belong to the target category. For example, in a sentiment analysis task, samples labeled "positive" are positive samples, and samples labeled "negative" are negative samples. Task categories from a natural language classification dataset are extracted from an external hard cue library. These cue categories provide clear, context-sensitive guidance to the PLM encoder, helping it accurately focus on task-related semantic representations. For example, in sentiment analysis, the hard cue "the sentiment of the comment is [mask]" directly guides the model to focus on the sentiment polarity of the comment text, thereby improving the prediction accuracy for that specific task.
[0009] In one embodiment, the input text and task-specific hard hints The splicing process is as follows: Different input text With the same selected task-specific hard hints Perform splicing, with task-specific hard hints. Concatenate to input text Before.
[0010] In one embodiment, processing the character ID list using a prompt-based multi-encoder to obtain a semantic information output vector includes: For the character ID list, a semantic information representation vector mapped to the semantic representation space is obtained using a frozen PLM encoder. ; The semantic information representation vector Using a trainable semantic encoder layer, semantic information is represented as vectors. Projecting onto the semantic shared space yields a semantic information output vector. .
[0011] In one embodiment, the calculation using the frozen PLM encoder is specifically implemented as follows:
[0012] in Indicates a splicing operation; This indicates the input text. This indicates a task-specific hard hint; The text describes the use of a trainable semantic encoder layer to represent semantic information as vectors. Projecting onto the semantic shared space, specifically implemented as follows:
[0013] in A trainable semantic encoder layer is a layer capable of representing semantic information as vectors. The data is projected into a semantic shared space, while category-aware information backpropagated from the soft cue processing module is incorporated during training to ensure that semantically similar representation vectors are projected more consistently within the shared space.
[0014] In one embodiment, the step of using soft cues as query input to the generator decoder, interacting with the semantic information output vector, and obtaining category-aware cues through cross-attention mechanism calculation and processing includes: Initialize the length to soft prompts and semantic information output vector The data is concatenated and then fed into the generator decoder to obtain category-aware cues. And after mean pooling, the final category-aware cue is obtained. The soft prompt mentioned above Refers to the vector representation composed of adjustable parameters of the model, with an initial length of Random values are assigned. These adjustable parameters will be optimized during training so that the language model can perform category-aware learning based on soft cues.
[0015] In one embodiment, the computation process of the generator decoder is as follows:
[0016]
[0017]
[0018] Indicates a query. Represents key-value pairs. This indicates the generator decoder, which uses a cross-attention mechanism and soft cues. It serves as a query to retrieve semantic information from the output vector, thereby achieving the goal of interacting with the input and extracting context-aware information; The mean pooling process is specifically implemented as follows:
[0019] in This refers to the mean pooling operation, and the formula for calculating the mean pooling operation is:
[0020] By all vectors The resulting vector is obtained by averaging the corresponding elements, with the average value of each dimension calculated independently.
[0021] In one embodiment, the process of processing the obtained semantic information output vector and category-aware cues separately, calculating the two losses, integrating them, and then updating the model for training includes: The semantic information output vector is extracted to obtain the masked representation. We project it onto a space that can compute the masked language loss using a lexicalization function, thus obtaining the masked language model loss. ; The final category-aware cue Supervised contrastive learning is applied to extract category-aware information, resulting in contrastive learning loss. ; Combined with the masked language model loss And the contrastive learning loss Total loss The optimizer is used to minimize the total loss function during training. After each training session, the model's learnable parameters are updated, and the calculation process in steps 2 to 4 is repeated to perform the next training and output the results.
[0022] In one embodiment, the masked language model loss is specifically implemented as follows:
[0023]
[0024] in Refer to input text Tag categories, Refers to all learnable parameters. Indicates a mask marker; Refers to the mask character. Refer to the given parameters Input text and task-specific hard hints At that time, the event The conditional probability of occurrence Refer to the given parameters and mask marking representation At that time, mask mark Mapping words to tag categories The conditional probability of the same event occurring; The contrastive learning loss is specifically implemented as follows:
[0025] in Indicates the temperature coefficient. Indicates batch size, This indicates the input text after mean pooling. The representative category perception cue treats samples with the same label in the same batch as positive sample pairs and samples with different labels as negative sample pairs. The aim is to achieve instance-level intra-class compactness and inter-class separability to discover the essential differences between categories, thereby improving the classification performance of the model. The cosine similarity is calculated using the following formula:
[0026] Representing vectors and dot product, and Representing vectors and The Euclidean norm; The total loss during model training is the sum of two components: the masked language model loss and the contrastive loss. It aims to optimize the model's language understanding and category discrimination abilities, as shown in the following formula:
[0027] in This is the total loss function.
[0028] In one embodiment, the natural language processing described in this invention includes text classification, sentiment analysis, and natural language entailment.
[0029] Compared with the prior art, the beneficial effects of the present invention are: (1) This invention enhances the generation of semantic embedding vectors for hard prompts and input text, as well as further semantic interaction processing, by utilizing a multi-encoder module, including a PLM encoder and a semantic encoder layer. This deep semantic processing enhances the model's ability to understand textual information, enabling the model to more effectively understand and process complex textual information.
[0030] (3) This invention introduces a generator-decoder layer to process soft cues, allowing soft cues to be used as query inputs and interact deeply with the output state of the semantic encoder, compared to traditional methods. This interaction is achieved through a cross-attention mechanism, which not only enriches the semantic representation but also enhances the ability to extract category information, thereby significantly improving the model's performance.
[0031] (3) This invention effectively solves the stability problem in traditional cue learning by processing hard cues and soft cues separately and interacting with them in a sparse sample environment. This separate processing and interaction method enables the model to capture semantic and category information more stably, reduces the noise problem caused by random initialization of cues, thereby improving the accuracy of prediction results and reducing errors, and has high practical value. Attached Figure Description
[0032] Figure 1 This is an architecture diagram of a stable optimization method for language models based on hybrid prompting learning.
[0033] Figure 2 This refers to the text information processing process.
[0034] Figure 3 This is the soft suggestion processing procedure.
[0035] Figure 4 This is a visualization of the effectiveness of the supervised contrastive learning method in Embodiment 2 of the present invention in extracting category-aware information from category-aware cues, wherein (a) refers to the category-aware cues before training. After using the t-SNE algorithm, the dimensionality is reduced to a distribution in 2D space. (b) refers to the category-aware cue after training. After using the t-SNE algorithm, the dimensionality is reduced to a distribution in 2-dimensional space. Detailed Implementation
[0036] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings and examples.
[0037] This invention presents a language model stabilization optimization method based on hybrid cue learning, applicable to natural language processing (NLP) tasks such as text classification, sentiment analysis, and natural language entailment. The steps are the same for different NLP tasks, differing mainly in the selection of different task-specific hard cues. The task-specific hard cues are extracted from an external hard cue library using task categories from a natural language classification dataset. These cues provide clear, context-sensitive guidance to the PLM encoder, helping it accurately focus on task-related semantic representations.
[0038] In the following embodiments, text classification, sentiment analysis, and natural language entailment are used as natural language processing tasks to describe the solution of the present invention in detail.
[0039] Example 1 A stable optimization method for language models based on hybrid prompting learning, used for text classification, such as... Figure 1 As shown, the main steps include the following: Step 1: Through the encoding conversion process, using the task categories of the classification dataset as constraints, obtain a list of character IDs for the input text and task-specific hard cues.
[0040] This step can be described in detail as follows: Step 1.1: In this embodiment, the natural language classification dataset is PHEME, a dataset related to fake news detection, containing 1706 evaluation data after preprocessing. Each comment is labeled, with 0 indicating a rumor and 1 indicating a non-rumor classification. The relevant data is stored in a specific format.
[0041] Step 1.2: Using a list This represents the input text in the natural language classification dataset, where Represents a list The Middle Input text, Number of characters in the input text. List. This represents the labels in a natural language classification dataset. The label is represented as , Represents a list The first in There are 1 tags, and each tag element consists of 0s and 1s. This indicates that the input text is a positive sample. This indicates that the input text is a negative sample.
[0042] Step 1.3: Use This indicates a task-specific hard cue. Based on the task categories in the classification dataset, the task-specific hard cue extracted from an external hard cue library is "Here is a piece of claim with..." <mask>information.
[0043] Step 1.4: Input text and task-specific hard hints To concatenate the different input texts, follow these steps: With the same selected task-specific hard hints Perform splicing, with task-specific hard hints. Concatenate to input text Previously, the concatenated text was then encoded using a tokenizer and converted into a list of character IDs [0, 1398, 16, ..., 235, 326, 2].
[0044] Step 2: Process the input text and the list of character IDs for task-specific hard cues using a cue-based multi-encoder to obtain a semantic information output vector.
[0045] like Figure 2 As shown, this step can be described in detail as follows: Step 2.1: Using the obtained input text and the list of character IDs for task-specific hard hints, calculate the semantic information representation vector mapped to the semantic representation space using the frozen PLM encoder. =[3.5422e-02,5.6707e-03, -9.7407e-02, ..., 1.3143e-01, 3.3544e-02, -2.8532e-02], with a dimension size of 768.
[0046] The formula used for calculations by the PLM encoder in a frozen state is as follows:
[0047] In the formula This indicates a splicing operation.
[0048] Step 2.2: Represent the semantic information vector Using a trainable semantic encoder layer, semantic information is represented as vectors. Projecting onto the semantic sharing space, the formula is:
[0049] Obtain semantic information output vector =[-1.9191e-02, 3.8215e-02, 7.0873e-02, ...,6.2706e-02, -6.8157e-02, 7.0513e-02], with a dimension size of 768. This refers to a trainable semantic encoder layer that incorporates category-aware information backpropagated from the soft cueing processing module during training.
[0050] Step 3: The soft cue is used as the query input of the generator decoder and interacts with the semantic information output vector from the semantic encoder. After calculation and processing through the cross-attention mechanism, the category-aware cue is obtained.
[0051] like Figure 3 As shown, this step can be described in detail as follows: Step 3.1: Use This indicates a soft prompt. It is a vector representation composed of adjustable parameters of the model, with the soft cue initialization length set to [value missing]. Initialize the length using random values. soft prompts = [ 0.9743,0.0872, -0.8115,...,0.3163, -1.3616,0.4748], length The size is 10, and the dimension size is 768.
[0052] Step 3.2: Set the soft tip and semantic information output vector The data is concatenated and then input together into the generator decoder. The calculation process of the generator decoder is as follows:
[0053]
[0054]
[0055] Calculate category-aware cues = [-0.1253, 0.3260, -0.2656, ..., -0.0635, 0.4458, -0.6641], with a length of 10 and a dimension size of 768. Indicates a query. Represents key-value pairs. This indicates the generator decoder, which uses a cross-attention mechanism and soft cues. The goal is to use the input as a query to retrieve semantic information from the output vector, thereby achieving the goal of interacting with the input and extracting context-aware information.
[0056] right After applying mean pooling, the formula is as follows:
[0057] in This refers to the mean pooling operation, and the formula for calculating the mean pooling operation is:
[0058] By all vectors The resulting vector is obtained by averaging the corresponding elements, with the average value of each dimension calculated independently.
[0059] This yields more representative category-aware cues. =[-0.2253, -0.3989,0.5027,..., -0.3641, -0.0361, -0.9904, Length is 1, Dimension size is 768.]
[0060] Step 4: Process the obtained semantic information output vector and category-aware cues separately to obtain two parts of loss. Integrate them and update the model for training.
[0061] This step can be described in detail as follows: Step 4.1: Extract the semantic information output vector obtained in Step 2.2 to obtain the masked representation. A wordification function is used to represent the mask tokens. Projecting onto a space where the masked language loss can be computed, we obtain the masked language model loss, expressed as:
[0062]
[0063] The embodiment obtained = 0.7017. Wherein Refer to input text Tag categories, Refers to all learnable parameters. This indicates a mask marker. Refers to the mask character. Refer to the given parameters Input text and task-specific hard hints At that time, the event The conditional probability of occurrence Refer to the given parameters and mask marking representation At that time, mask mark Mapping words to tag categories The conditional probability of the same event occurring.
[0064] Step 4.2: Apply the representative category-aware cues obtained in Step 3.2, which are the final category-aware cues. Supervised contrastive learning is applied to extract category-aware information, resulting in the contrastive learning loss, which is expressed as:
[0065] The embodiment obtained = 1.9099. Wherein Indicates the temperature coefficient. Indicates batch size, This indicates the input text after mean pooling. The representative category perception cue treats samples with the same label in the same batch as positive sample pairs and samples with different labels as negative sample pairs. The cosine similarity is calculated using the following formula:
[0066] Representing vectors and dot product, and Representing vectors and The Euclidean norm.
[0067] Step 4.3: Combine masked language model loss And comparative loss The total loss is obtained from the two components, and the formula is as follows:
[0068] The embodiment obtained = 2.6116, train using a suitable optimizer to minimize the total loss function, train using the Adam optimizer to minimize the loss function, and set the learning rate to 0.0001.
[0069] Step 4.4: After one training session, update the model's learnable parameters, and repeat the calculation process in steps 2, 3, and 4 to perform the next training session and output the results.
[0070] Step 5: Perform natural language processing using the trained model.
[0071] The experimental results of this embodiment are as follows: The accuracy (AUC) on the test set remained stable at 0.7535, and the F1-score remained stable at 0.8243.
[0072] Example 2 A language model stabilization optimization method based on hybrid prompting learning, used for sentiment analysis, such as... Figure 1 As shown, the main steps include the following: Step 1: Through the encoding conversion process, using the task categories of the classification dataset as constraints, obtain a list of character IDs for the input text and task-specific hard cues.
[0073] Step 1.1: In this embodiment, the natural language classification dataset is SST-2, a sentiment analysis-related dataset, containing 1758 review comments after preprocessing. Each comment is labeled, with 0 indicating negative sentiment and 1 indicating positive sentiment. The relevant data is stored in a specific format.
[0074] Step 1.2: Using a list This represents the input text in the natural language classification dataset, where Represents a list The Middle Input text, Number of characters in the input text. List. This represents the labels in a natural language classification dataset. The label is represented as , Represents a list The first in There are 1 tags, and each tag element consists of 0s and 1s. This indicates that the input text is a positive sample. This indicates that the input text is a negative sample.
[0075] Step 1.3: Use This indicates a task-specific hard cue. Based on the task categories in the classification dataset, the task-specific hard cue is extracted from an external hard cue library as "Here is a piece of review with...". <mask>sentiment.
[0076] Step 1.4: Input text and task-specific hard hints The concatenation is performed, and the concatenated text is encoded using a tokenizer into a list of character IDs [0, 958, 24622, ..., 7283, 2580, 2].
[0077] Step 2: Process the input text and task-specific hard cues using a cue-based multi-encoder to obtain a semantic information output vector.
[0078] like Figure 2 As shown, this step can be described in detail as follows: Step 2.1: Using the obtained input text and the list of character IDs for task-specific hard hints, calculate the semantic information representation vector mapped to the semantic representation space using the frozen PLM encoder. = [-2.0591e-02,1.7121e-02, -5.1641e-02, ..., 9.9549e-02, 5.4954e-02, 2.3237e-02], with a dimension size of 768.
[0079] Step 2.2: Represent the semantic information vector Using a trainable semantic encoder layer, semantic information is represented as vectors. Projecting onto the semantic shared space yields a semantic information output vector. = [3.4015e-02, 5.8743e-02, -2.1755e-02, ..., -8.0490e-02, 2.5827e-02, 8.9256e-03]. The dimension size is 768.
[0080] Step 3: The soft cue is used as the query input to the generator decoder and interacts with the output vector from the semantic encoder. After being calculated and processed through a cross-attention mechanism, a category-aware cue is obtained.
[0081] like Figure 3 As shown, this step can be described in detail as follows: Step 3.1: Use This indicates a soft suggestion, and sets the initial length of the soft suggestion to [value]. Initialize the length using random values. soft prompts = [ 1.0860, 0.4789, -2.1474, ..., 0.6961, -1.2275, 1.3948], length The size is 10, and the dimension size is 768.
[0082] Step 3.2: Set the soft tip and semantic information output vector The data is concatenated and fed into the generator decoder to obtain category-aware cues. = [ 1.5020, 0.5260, -1.7999, ..., 1.6598, -1.2244, 1.1778], with a length of 10 and a dimension size of 768, after mean pooling, a more representative category-aware cue is obtained. = [0.9617, 0.7739, -0.3986, ..., 1.0846, 0.1912, 0.0022], with a length of 1 and a dimension size of 768.
[0083] Step 4: Process the obtained semantic information output vector and category-aware cues separately to obtain two parts of loss. Integrate them and update the model for training.
[0084] Step 4.1: Extract the semantic information output vector obtained in Step 2.2 to obtain the masked representation. A wordification function is used to represent the mask tokens. Projecting onto a space where the masked language loss can be computed, we obtain the masked loss. = 0.9237.
[0085] Step 4.2: Perceive the representative category hints obtained in Step 3.2 Supervised contrastive learning methods are applied to extract category-aware information, resulting in contrastive learning loss. = 2.4231.
[0086] Figure 4 (a) and (b) reflect category-aware cues Distribution before and after training, and category-aware cues after training. The degree of separation was significantly greater than before training, demonstrating the effectiveness of contrastive learning.
[0087] Step 4.3: Combine the masked language model loss and the contrastive loss to obtain the total loss. =3.3468, use a suitable optimizer to minimize the total loss function for training, use the Adam optimizer to minimize the loss function for training, and set the learning rate to 0.0001.
[0088] Step 4.4: After one training session, update the model's learnable parameters, and repeat the calculation process in steps 2, 3, and 4 to perform the next training session and output the results.
[0089] Step 5: Perform natural language processing using the trained model.
[0090] The experimental results of this embodiment are as follows: The accuracy (AUC) on the test set remained stable at 0.8349, and the F1-score remained stable at 0.8467.
[0091] Example 3 A language model stabilization optimization method based on hybrid prompting learning, used for natural language entailment, such as... Figure 1 As shown, the main steps include the following: Step 1: Through the encoding conversion process, using the task categories of the classification dataset as constraints, obtain a list of character IDs for the input text and task-specific hard cues.
[0092] Step 1.1: In this embodiment, the natural language classification dataset is QNLI, a natural language entailment relevance dataset with 2056 evaluation data after preprocessing. Each comment is labeled: 0 indicates that the statement relationship is non-entailment, and 1 indicates that the statement relationship is entailment. The relevant data is stored in a specific format.
[0093] Step 1.2: Using a list This represents the input text in the natural language classification dataset, where Represents a list The Middle Input text, Number of characters in the input text. List. This represents the labels in a natural language classification dataset. The label is represented as , Represents a list The first in There are 1 tags, and each tag element consists of 0s and 1s. This indicates that the input text is a positive sample. This indicates that the input text is a negative sample.
[0094] Step 1.3: Use This represents task-specific hard cues. By classifying the task categories in the dataset, task-specific hard cues are extracted from an external hard cue library as "Question and answer". <mask>.".
[0095] Step 1.4: Input text and task-specific hard hints The strings are concatenated, and the resulting text is encoded using a tokenizer into a list of character IDs: [0,6179,203,473,10, 23440,1258,254,4073,6,3225,116,2, 50264,1437, 16215, 19040,11,3430,64,28,3382,453,9,721,7811,19,5,1049,1980,145,5, 24720,2534,9,3430,8,5,5411, 16021,14245,108,1544,4,2]. Step 2: Process the input text and task-specific hard cues using a cue-based multi-encoder to obtain a semantic information output vector.
[0096] like Figure 2 As shown, this step can be described in detail as follows: Step 2.1: Using the obtained input text and the list of character IDs for task-specific hard hints, calculate the semantic information representation vector mapped to the semantic representation space using the frozen PLM encoder. =[-0.0808, -0.0019,-0.0862,...,0.1236,0.0764, -0.0110], with a dimension size of 768.
[0097] Step 2.2: Represent the semantic information vector Using a trainable semantic encoder layer, semantic information is represented as vectors. Projecting onto the semantic shared space yields a semantic information output vector [7.1938e-03, 5.0488e-02, -2.1862e-02, ..., 4.0330e-04, -4.1823...]. The dimension is 768.
[0098] Step 3: The soft cue is used as the query input to the generator decoder and interacts with the output vector from the semantic encoder. After being calculated and processed through a cross-attention mechanism, a category-aware cue is obtained.
[0099] like Figure 3 As shown, this step can be described in detail as follows: Step 3.1: Use This indicates a soft suggestion, and sets the initial length of the soft suggestion to [value]. Initialize the length using random values. soft tips = [ 0.9743,0.0872, -0.8115,...,0.3163, -1.3616,0.4748], length The size is 10, and the dimension size is 768.
[0100] Step 3.2: Set the soft tip and semantic information output vector The data is concatenated and fed into the generator decoder to obtain category-aware cues. = [ 1.0352e-02,3.9901e-01, -3.9259e-01,..., -2.7021e-01,2.5252e-01, -7.8307e-01], with a length of 10 and a dimension of 768, after mean pooling, a more representative category-aware cue is obtained. = [ 0.0306, -0.3158,0.1467,..., -0.3264,0.1992,-1.0794], with a length of 1 and a dimension size of 768.
[0101] Step 4: Process the obtained semantic information output vector and category-aware cues separately to obtain two parts of loss. Integrate them and update the model for training.
[0102] Step 4.1: Extract the semantic information output vector obtained in Step 2.2 to obtain the masked representation. A wordification function is used to represent the mask tokens. Projecting onto a space where the masked language loss can be computed, we obtain the masked loss. = 0.7630.
[0103] Step 4.2: Perceive the representative category hints obtained in Step 3.2 Supervised contrastive learning methods are applied to extract category-aware information, resulting in contrastive learning loss. = 1.9343.
[0104] Step 4.3: Combine the masked language model loss and the contrastive loss to obtain the total loss. =2.6973, train using a suitable optimizer to minimize the total loss function, train using the Adam optimizer to minimize the loss function, and set the learning rate to 0.0001.
[0105] Step 4.4: After one training session, update the model's learnable parameters, repeat the calculation process in steps 2, 3, and 4, and perform the next training session and output the results.
[0106] Step 5: Perform natural language processing using the trained model.
[0107] The experimental results of this embodiment are as follows: The accuracy (AUC) on the test set remained stable at 0.6307, and the F1-score remained stable at 0.6391.
[0108] The experimental results show that the language model stability optimization method based on hybrid prompting learning proposed in this invention can capture semantic and classification information separately using hybrid prompts, thus effectively solving the noise problem caused by random prompt initialization. The prediction results have high accuracy and small error, and can be applied to various language model classification scenarios, which has high practical value.
[0109] Although the illustrative specific embodiments of the present invention have been described above to enable those skilled in the art to understand the invention, it should be understood that the invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the invention as defined and determined by the appended claims, and all inventions utilizing the concept of the present invention are protected.< / mask> < / mask> < / mask>
Claims
1. A language model stable optimization method based on mixed prompt learning, characterized in that, Includes the following steps: Step 1: Through the encoding conversion process, using the task category of the classification dataset as a constraint, obtain a list of character IDs for the input text and task-specific hard clues; Step 2: Process the character ID list using a prompt-based multi-encoder to obtain a semantic information output vector; Step 3: Using the soft cue as the query input to the generator decoder, it interacts with the semantic information output vector, and after calculation and processing through a cross-attention mechanism, a category-aware cue is obtained, including: Initialize the length to soft prompts and semantic information output vector The data is concatenated and then fed into the generator decoder to obtain category-aware cues. And after mean pooling, the final category-aware cue is obtained. The soft prompt mentioned above Refers to the vector representation composed of adjustable parameters of the model, with an initial length of Get a random value; The calculation process in the generator decoder is as follows: Indicates a query. Represents key-value pairs. This indicates the generator decoder, which uses a cross-attention mechanism and soft cues. It serves as a query to retrieve semantic information from the output vector, thereby achieving the goal of interacting with the input and extracting context-aware information; The mean pooling process is specifically implemented as follows: wherein denotes the mean-pooling operation, the mean-pooling operation being calculated according to the formula: is the result vector obtained by averaging the corresponding elements of all vectors , the average in each dimension being computed independently; Step 4: Process the semantic information output vector and category-aware cues separately, calculate the loss of each part, integrate them, update the model, and then train it. Step 5: Perform natural language processing using the trained model.
2. The method of claim 1, wherein, The step 1, input text and task-specific hard prompts are spliced, and the spliced text is encoded into a character id list using a tokenizer; in, Represents a list The first in Input text, list This represents the input text in a natural language classification dataset. The number of input texts; The label is represented as , Represents a list The first in Tags, list The label represents the label in the natural language classification dataset. The label element consists of 0 and 1, which respectively indicate that the corresponding input text is a negative sample and a positive sample. Task categories from a natural language classification dataset are extracted from an external hard cue library, providing clear, context-sensitive guidance for the PLM encoder and helping it to accurately focus on task-related semantic representations.
3. The language model stabilization optimization method based on hybrid prompting learning according to claim 2, characterized in that, The input text and task-specific hard cues are concatenated, as follows: different input texts with the same selected task-specific hard cues are stitched, and the task-specific hard cues are stitched to the input texts before.
4. The method of claim 2, wherein, The step of processing the character ID list using a prompt-based multi-encoder to obtain a semantic information output vector includes: For the list of character ids, a semantic information representation vector mapped to the semantic representation space is computed using a frozen state of the PLM encoder ; The semantic information representation vector Using a trainable semantic encoder layer, semantic information is represented as vectors. Projecting onto the semantic shared space yields a semantic information output vector. .
5. The method of claim 4, wherein, The calculation using the frozen PLM encoder is specifically implemented as follows: wherein represents a concatenation operation; represents an input text, represents a task-specific hard hint; The use of trainable semantic encoder layers to represent semantic information as vectors projecting to a semantic shared space, specifically implemented as: in This refers to a trainable semantic encoder layer that incorporates category-aware information backpropagated from the soft cueing processing module during training.
6. The method for stabilizing and optimizing a language model based on hybrid prompting learning according to claim 1, characterized in that, The obtained semantic information output vector and category-aware cues are processed separately, and the losses of the two parts are calculated. After integration, the model is updated and trained, including: The semantic information output vector is extracted to obtain the masked representation. We project it onto a space that can compute the masked language loss using a lexicalization function, thus obtaining the masked language model loss. ; Final category perception prompt , the application supervises the contrast learning method to extract the category perception information, and obtains a contrast learning loss ; combining the masked language model loss and the contrastive learning loss to obtain a total loss training using an optimizer to minimize the total loss function; After each training session, the model's learnable parameters are updated, and the calculation process in steps 2 to 4 is repeated to perform the next training and output the results.
7. The method of claim 6, wherein, The masked language model loss is specifically implemented as follows: in Refer to input text Tag categories, Refers to all learnable parameters. Indicates a mask marker; Refers to the mask character. Refer to the given parameters Input text and task-specific hard hints At that time, the event The conditional probability of occurrence Refer to the given parameters and mask marking representation At that time, mask mark Mapping words to tag categories The conditional probability of the same event occurring; The contrastive learning loss is specifically implemented as follows: in Indicates the temperature coefficient. Indicates batch size, This indicates the input text after mean pooling. The representative category perception cue treats samples with the same label in the same batch as positive sample pairs and samples with different labels as negative sample pairs. The cosine similarity is calculated using the following formula: Representing vectors and dot product, and Representing vectors and The Euclidean norm; The total loss is specifically implemented as follows: wherein is the total loss function.
8. The method of claim 1, wherein, The natural language processing includes text classification, sentiment analysis, and natural language entailment.