A model prompting learning method and device, electronic equipment and storage medium

By using a learnable optimizer to determine the parameter update amount of the pre-trained language model, the problem of low learning efficiency caused by traditional optimization strategies is solved, and efficient prompt learning of the pre-trained language model is achieved.

CN114860915BActive Publication Date: 2026-01-23ZHONGKE DINGFU BEIJING TECH DEV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210626295.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-02
Publication Date
2026-01-23
Estimated Expiration
2042-06-02

AI Technical Summary

Technical Problem

In existing technologies, the cue learning efficiency of pre-trained language models is low, and traditional optimization strategies require multiple cycles, resulting in low learning efficiency.

Method used

A learnable optimizer is employed to determine the parameter update amount by obtaining the current-round parameter gradient values ​​of the pre-trained language model and the current-round optimization parameters of the optimizer, and to calculate the next-round gradient value based on the output data until the learning termination condition is reached, thus avoiding traditional optimization strategies based on human experience.

Benefits of technology

It effectively accelerates the cue learning process of pre-trained language models, improves learning efficiency, and avoids the inefficiency caused by traditional optimization strategies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114860915B_ABST
    Figure CN114860915B_ABST
Patent Text Reader

Abstract

The application provides a model prompt learning method and device, electronic equipment and storage medium, which are used for improving the low efficiency of prompt learning of a pre-trained language model. The method comprises the following steps: obtaining a current round parameter gradient value of the pre-trained language model; obtaining a current round optimization parameter of a learned optimizer; determining a current round parameter update amount of the pre-trained language model by using the current round parameter gradient value and the current round optimization parameter; performing prompt learning on the pre-trained language model by using the current round parameter update amount, and calculating a next round parameter gradient value of the pre-trained language model according to output data of the pre-trained language model until a learning termination condition is reached to obtain a learned language model. The prompt learning process of the pre-trained language model is accelerated by using the learnable optimizer, the prompt learning process of the pre-trained language model is avoided to be optimized by using a traditional optimization strategy based on artificial experience, and the prompt learning efficiency of the pre-trained language model is effectively accelerated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical fields of Natural Language Processing (NLP), deep learning, and prompting learning, and more specifically, to a model prompting learning method, apparatus, electronic device, and storage medium. Background Technology

[0002] Pre-trained language models (PLMs), also known simply as pre-trained models, refer to neural network models obtained by using a large amount of text corpus as training data and performing semi-supervised machine learning on the neural network using the training data. Specific examples of pre-trained semantic models include: Bidirectional Encoder Representations from Transformer (BERT) models, RoBERTa models, SentenceBERT models, GloVe models, and Generative Pre-Training (GPT) models, etc.

[0003] Currently, most methods for learning prompts on pre-trained language models employ traditional optimization strategies such as Adam or Adagrad. For example, training a prompt matrix for a specific NLP task on a PLM using Adam or Adagrad typically requires over 100 epochs. Therefore, using traditional optimization strategies for learning prompts on pre-trained language models is inefficient. Summary of the Invention

[0004] The purpose of this application is to provide a model prompting learning method, apparatus, electronic device, and storage medium to improve the low efficiency of prompting learning for pre-trained language models.

[0005] This application provides a model prompting learning method, including: obtaining the current-round parameter gradient values ​​of a pre-trained language model; obtaining the current-round optimization parameters of the optimized generator after learning; using the current-round parameter gradient values ​​and the current-round optimization parameters to determine the current-round parameter update amount of the pre-trained language model; using the current-round parameter update amount to perform prompting learning on the pre-trained language model; and calculating the next-round parameter gradient values ​​of the pre-trained language model based on the output data of the pre-trained language model, until the learning termination condition is reached, thereby obtaining the learned language model. In the implementation of the above scheme, a learnable optimizer is used to accelerate the prompting learning process of the pre-trained language model. That is, the current-round parameter update amount of the pre-trained language model is determined based on the current-round parameter gradient values ​​of the pre-trained language model and the current-round optimization parameters of the optimizer, and the current-round parameter update amount is used to perform prompting learning on the pre-trained language model. This allows for adjustment based on the corresponding data and optimization task, providing the optimal update direction and update size for each step, thereby avoiding the use of traditional optimization strategies based on human experience to optimize the prompting learning process of the pre-trained language model, effectively accelerating the prompting learning efficiency of the pre-trained language model.

[0006] Optionally, in this embodiment, obtaining the current-round parameter gradient value of the pre-trained language model includes: obtaining sample text and sample labels; using the pre-trained language model to predict the sample text and obtain the predicted category; calculating the loss value between the sample label and the predicted category, and determining the current-round parameter gradient value based on the loss value. In the implementation of the above scheme, by calculating the loss value between the sample label and the predicted category, and determining the current-round parameter gradient value based on the loss value, the use of the current-round parameter gradient value determined by traditional optimization strategies based on human experience to optimize the prompt learning process of the pre-trained language model is avoided, effectively accelerating the prompt learning efficiency of the pre-trained language model.

[0007] Optionally, in this embodiment, the optimizer is a Long Short-Term Memory (LSTM) network. The current optimization parameters of the LSTM network include the current model parameters and the current hidden state. Determining the current parameter update amount of the pre-trained language model using the current parameter gradient and the current optimization parameters includes: obtaining the current model parameters and the current hidden state of the LSTM network; and determining the next hidden state of the LSTM network and the current parameter update amount of the pre-trained language model based on the current model parameters and the current hidden state. In the implementation of the above scheme, by determining the next hidden state of the LSTM network and the current parameter update amount of the pre-trained language model based on the current model parameters and the current hidden state, the problem of traditional optimization strategies struggling to determine the temporal parameters of the current hidden state is avoided, effectively accelerating the cue learning efficiency of the pre-trained language model.

[0008] Optionally, in this embodiment, obtaining the current-round model parameters of the LSTM network includes: obtaining the previous-round model parameters and the previous-round parameter update amount of the LSTM network; and determining the current-round model parameters based on the previous-round model parameters and the previous-round parameter update amount. In the implementation of the above scheme, by determining the current-round model parameters based on the previous-round model parameters and the previous-round parameter update amount, the traditional optimization strategy of directly determining the current-round model parameters based on the gradient and learning rate is avoided, effectively accelerating the cue learning efficiency of the pre-trained language model.

[0009] Optionally, in this embodiment, the pre-trained language model is a Transformer-type model. The process of using the current round of parameter updates to perform cue learning on the pre-trained language model includes: modifying the attention matrix in the Transformer-type model according to the current round of parameter updates to obtain a modified attention matrix; performing cue learning based on the modified attention matrix; and calculating the next round of parameter gradient values ​​for the pre-trained language model based on the output data of the pre-trained language model, until the learning termination condition is met, thus obtaining the learned language model. In the implementation of the above scheme, by modifying the attention matrix in the Transformer-type model according to the current round of parameter updates and performing cue learning based on the modified attention matrix, the problem of low learning efficiency caused by cue learning based on manually designed cue templates is avoided, effectively accelerating the cue learning efficiency of the pre-trained language model.

[0010] Optionally, in this embodiment, before obtaining the current optimization parameters of the optimizedr after learning, the method further includes: determining the total loss value of the optimizedr based on the expected output value of the pre-trained language model, and updating the optimizedr's parameters based on the total loss value. In the implementation of the above scheme, by determining the total loss value of the optimizedr based on the expected output value of the pre-trained language model and updating the optimizedr's parameters based on the total loss value, the traditional optimization strategy based on human experience is avoided from optimizing the prompt learning process of the pre-trained language model, effectively accelerating the prompt learning efficiency of the pre-trained language model.

[0011] Optionally, in this embodiment, after obtaining the learned language model, the method further includes: obtaining sample text and a prompt template, the prompt template including: input slots and answer slots; filling the input slots in the prompt template with the sample text to obtain a filled template; and using the learned language model to predict the corresponding text in the answer slots of the filled template to obtain the predicted answer text. In the implementation of the above scheme, by using the learned language model to predict the corresponding text in the answer slots of the filled template to obtain the predicted answer text, since the learned language model is obtained after optimizing the prompt learning process of the language model using L2O technology, the traditional optimization strategy based on human experience is avoided to optimize the prompt learning process of the pre-trained language model, effectively accelerating the prompt learning efficiency of the pre-trained language model.

[0012] This application also provides a model suggestion learning device, including: a parameter gradient acquisition module, used to acquire the current round parameter gradient values ​​of a pre-trained language model; an optimization parameter acquisition module, used to acquire the current round optimization parameters of the learned optimizer, and use the current round parameter gradient values ​​and the current round optimization parameters to determine the current round parameter update amount of the pre-trained language model; and a model suggestion learning module, used to perform suggestion learning on the pre-trained language model using the current round parameter update amount, and calculate the next round parameter gradient values ​​of the pre-trained language model based on the output data of the pre-trained language model, until the learning termination condition is reached, and obtain the learned language model.

[0013] Optionally, in this embodiment, the parameter gradient acquisition module includes: a text label acquisition submodule, used to acquire sample text and sample labels; a predicted category acquisition submodule, used to predict the sample text using a pre-trained language model to obtain the predicted category; and a first gradient determination submodule, used to calculate the loss value between the sample label and the predicted category, and determine the parameter gradient value for this round based on the loss value.

[0014] Optionally, in this embodiment, the optimizer is a Long Short-Term Memory (LSTM) network. The current optimization parameters of the LSTM network include: the current model parameters and the current hidden state. The optimization parameter acquisition module includes: a state parameter acquisition submodule, used to acquire the current model parameters and the current hidden state of the LSTM network; and a state update determination submodule, used to determine the next hidden state of the LSTM network and the current parameter update amount of the pre-trained language model based on the current model parameters and the current hidden state.

[0015] Optionally, in this embodiment, the pre-trained language model is a Transformer-type model; the model prompting learning module includes: an attention matrix modification submodule, used to modify the attention matrix in the Transformer-type model according to the parameter update amount in this round, obtain the modified attention matrix, and perform prompting learning based on the modified attention matrix.

[0016] Optionally, in this embodiment of the application, the model prompting learning device further includes: an optimizer parameter update module, used to determine the total loss value of the optimizer based on the expected output value of the pre-trained language model, and to perform parameter update learning on the optimizer based on the total loss value.

[0017] Optionally, in this embodiment of the application, the model prompt learning device further includes: a prompt template acquisition module, used to acquire sample text and a prompt template, the prompt template including: input slots and answer slots; a filling template acquisition module, used to fill the input slots in the prompt template with sample text to obtain a filling template; and a language model prediction module, used to predict the corresponding text of the answer slots in the filling template using the learned language model to obtain the predicted answer text.

[0018] This application also provides an electronic device, including a processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and the machine-readable instructions, when executed by the processor, perform the method described above.

[0019] This application also provides a computer-readable storage medium storing a computer program that is executed by a processor to perform the methods described above. Attached Figure Description

[0020] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 The diagram shown is a flowchart illustrating the model prompting learning method provided in an embodiment of this application.

[0022] Figure 2 The diagram shown is a schematic representation of the network structure of the Transformer class model provided in an embodiment of this application.

[0023] Figure 3The diagram shown is a schematic of the encoder and the multi-head attention network structure in the encoder of the Transformer-Block provided in the embodiments of this application;

[0024] Figure 4 The diagram shown is a schematic representation of the LSTM optimization hint learning process provided in an embodiment of this application.

[0025] Figure 5 The diagram shown is a structural schematic of the model prompting learning device provided in an embodiment of this application. Detailed Implementation

[0026] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. The components of the embodiments of this application described and shown in the accompanying drawings can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed embodiments of this application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of the embodiments of this application.

[0027] It is understood that the terms "first" and "second" in the embodiments of this application are used to distinguish similar objects. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that the terms "first" and "second" are not necessarily different.

[0028] Before introducing the model prompting learning method provided in the embodiments of this application, let's first introduce some concepts involved in the embodiments of this application:

[0029] Prompt learning, also known as prompt-based learning, is a learning paradigm in the field of NLP that uses pre-trained language models to perform prediction tasks. This paradigm mainly includes pre-training, prompting, and prediction. It can replace the traditional fine-tuning-based learning paradigm, which can include pre-training and fine-tuning.

[0030] Learning to Optimize (L2O) is a novel approach to developing and optimizing neural network training processes using machine learning. The primary goal of L2O is to reduce the tedious iterations involved in training neural network models. L2O can automatically design optimization methods based on different model training sets. These different models include, but are not limited to: different model types (e.g., using GloVe, GPT, BERT, RoBERTa, and SentenceBERT models to train the optimizer, then using the optimizer to train the desired pre-trained language model, resulting in the trained language model), and / or different numbers of models (using 3 or 5 BERT models to train the optimizer, then using the optimizer to train the desired pre-trained language model, resulting in the trained language model). This data-driven process effectively addresses common problems in the training process, representing a significant departure from traditional theory-driven optimization strategies.

[0031] It should be noted that the model prompting learning method provided in this application embodiment can be executed by an electronic device. Here, electronic device refers to a device terminal or server with the function of executing computer programs. Device terminals include, for example, smartphones, personal computers, tablets, personal digital assistants, or mobile internet devices. Servers refer to devices that provide computing services through a network. Servers include, for example, x86 servers and non-x86 servers. Non-x86 servers include, for example, mainframes, minicomputers, and UNIX servers.

[0032] The following describes the application scenarios applicable to this model-driven prompting learning method. These scenarios include, but are not limited to, the following: When using a pre-trained language model for prediction and inference in downstream NLP tasks, the model-driven prompting learning method can be used to optimize the prompting learning process of the pre-trained language model. This involves using a learnable optimizer to accelerate the prompting learning process of the pre-trained language model. The downstream NLP tasks include, but are not limited to, text classification, natural language inference, knowledge probing, information extraction, question answering, text generation, and multimodal learning, etc. For ease of understanding and explanation, this application uses text sentiment classification as the downstream NLP task for detailed explanation in its embodiments; the technical principles of other downstream NLP tasks are similar.

[0033] The prompt process described above can generally include the following three steps. For ease of understanding, the following uses a manually designed static and discrete prompt template to illustrate the prompt process in detail:

[0034] The first step is to add prompts to the pre-trained language model. This can be done by adding either a filled (human-designed) prompt template or a prompt vector (learned by the machine model from the prompt template). The filled prompt template includes filled input slots and unfilled answer slots. Specifically, an unfilled prompt template is selected, for example: [X], which in short means "This is a [Z] movie." Here, [X] represents the input slot, used to input prompt text (e.g., "I like this movie," or "I hate this movie") or a prompt vector, and [Z] represents the answer slot, used by the pre-trained language model to generate answer text or an answer vector on the fly.

[0035] The second step involves the pre-trained language model predicting the answer text or vector corresponding to the empty answer slot based on the filled cue template (Slot). Specifically, the filled cue template might be, for example, "I like this movie," or "In short, this is a [Z] movie." The pre-trained language model can predict whether the answer text corresponding to the empty answer slot is good, fantastic, or bad.

[0036] The third step is to map the answer text or answer vector corresponding to the empty answer slot to the output prediction result. In the case of a text sentiment classification task, good and fantastic answer texts can be mapped to positive sentiment categories, while bad answer texts can be mapped to negative sentiment categories.

[0037] It is understandable that the above descriptions use manually designed static and discrete prompt templates to illustrate the prompting process. However, in practice, neural network models (such as optimizers) can be used to generate dynamic and continuous prompt templates to perform the above prompting process. The following section will describe in detail how to use optimizers to generate dynamic and continuous prompt templates to perform the above prompting process.

[0038] The main idea of ​​the model prompting learning method provided in this application is to apply L2O technology to the prompting learning process of a pre-trained language model (PLM). Specifically, it uses an optimizer learned through L2O technology (which is learnable) to accelerate the prompting learning process of the PLM, thereby avoiding the use of traditional optimization strategies designed based on human experience (which are not learnable) to optimize the PLM's learning process. Specifically, the working principle of the optimizer learned through L2O technology can be expressed by the following formula: Where θ represents the weight parameters in the model, it is easy to see that θ t+1 and θ t Let f(θ) represent the weight parameters of the iterative model in round (t+1) (e.g., the number of iterations, time intervals, or periods) and round t, respectively. Let α represent the learning rate hyperparameter. t This represents the output data of the pre-trained language model during the t-th round (e.g., the tth training cycle). This represents the gradient value of the parameters in the t-th training round (e.g., the t-th iteration or cycle) of the pre-trained language model, g represents the parameter update amount of the pre-trained language model calculated by the learnable optimizer, and φ represents the weight parameters of the optimizer in L2O. Therefore, using the above model prompting learning method can effectively accelerate the prompting learning efficiency of PLM.

[0039] Please see Figure 1 The illustrated flowchart represents a model suggestion learning method provided in an embodiment of this application; the implementation of this model suggestion learning method may include:

[0040] Step S110: Obtain the gradient values ​​of the parameters of the pre-trained language model in this round.

[0041] Understandably, pre-trained language models can be Transformer-type models based on an encoder-decoder structure. Here, Transformer-type models refer to neural network models that use Transformer Blocks, including but not limited to: BERT, RoBERTa, T5, and SentenceBERT models. Since there are many types and versions of Transformer-type models (different levels and depths), for specific downstream NLP tasks (such as text classification), multiple Transformer-type models can be used to train each optimizer separately, resulting in multiple trained optimizers. Then, the optimizedr with the highest accuracy among these trained optimizers is used as the subsequent learned optimizer (the specific learning and training process of this optimizer will be described in detail below).

[0042] Step S120: Obtain the current round optimization parameters of the optimizedr after learning, and use the current round parameter gradient value and the current round optimization parameters to determine the current round parameter update amount of the pre-trained language model.

[0043] An optimizer (learnable optimizer) refers to a neural network model whose weight parameters can be updated (i.e., a learnable optimizer). This optimizer is used to optimize the training process of a pre-trained language model, specifically by outputting the update direction and step size of the pre-trained language model parameters at each step, so that the pre-trained language model can complete the training process and reach the prediction and inference stage more quickly. The optimizer can be any neural network model with a temporal structure, such as: Recurrent Neural Network (RNN), Long Short-Term Memory (LSTM) network, Bidirectional Long Short-Term Memory (Bi-LSTM) network, Gated Recurrent Unit (GRU), and Transformer-Block, etc. For ease of understanding and explanation, this application uses LSTM networks for detailed description in its embodiments. The process of determining the current parameter update amount of the LSTM is explained in detail below. The technical principles of other neural network models with temporal structures are similar.

[0044] Step S130: Use the parameter update amount of this round to perform cue learning on the pre-trained language model, and calculate the next round parameter gradient value of the pre-trained language model based on the output data of the pre-trained language model, until the learning termination condition is reached, and obtain the learned language model.

[0045] In the above implementation process, a learnable optimizer is used to accelerate the prompt learning process of the pre-trained language model. Specifically, the current parameter update amount of the pre-trained language model is determined based on the current parameter gradient value of the pre-trained language model and the current optimization parameters of the optimizer. The current parameter update amount is then used to perform prompt learning on the pre-trained language model. This optimizer can adjust according to the corresponding data and optimization task, providing the optimal update direction and update size for each step. This avoids using traditional optimization strategies based on human experience to optimize the prompt learning process of the pre-trained language model, effectively accelerating the prompt learning efficiency of the pre-trained language model.

[0046] Please see Figure 2The diagram illustrates the network structure of a Transformer-type model provided in this embodiment of the application. The pre-trained language model described above can adopt a Transformer-type model, the specific structure of which may include: an embedding layer, multiple stacked transforming blocks (Transformer-Blocks), and an output layer. The multiple stacked transforming blocks are stacked on top of each other (i.e., connected sequentially). Since the embedding layer, the multiple stacked transforming blocks, and the output layer in the diagram are also connected sequentially, the dimensions of the embedding layer and any one of the multiple stacked transforming blocks are equal. This dimension can be represented as [l, H], where l represents the horizontal length of the embedding layer and the transforming block, and H represents the vertical height of the transforming block.

[0047] The aforementioned embedding layer is primarily used to map and convert the input sample text into a matrix vector. This embedding layer is connected to the first deformation module (e.g., deformation module 1 in the diagram) among the multiple stacked deformation modules. Since Transformer-type models cannot directly process sample text, the embedding layer is needed to map and convert the sample text into a matrix vector. The specific mapping and conversion process can include: segmenting the sample text into words; adding symbolic representations to each sentence in the sample text (e.g., [CLS] and [SEP] in the diagram represent the start and end symbols of a sentence, respectively), resulting in multiple words with added symbolic representations. Finally, each word (e.g., "like") or symbolic representation (e.g., [CLS] and [SEP]) among these words with added symbolic representations is converted and mapped into a one-hot representation vector, obtaining the matrix vector corresponding to the sample text. That is, the matrix vector is composed of multiple representation vectors. Each representation vector may include a position embedding code and a word embedding vector. The position embedding code represents the position encoding of the representation vector in a sentence or text, and the word embedding vector represents the one-hot encoding of the transformation mapping for each word (e.g., like) or representation symbol (e.g., [CLS] and [SEP]).

[0048] The aforementioned stacked Transformer Blocks are the core components of the Transformer class model, and the total number of these stacked Transformer Blocks can be represented as L. Each of these stacked Transformer Blocks includes multiple encoders and multiple decoders; the encoders are connected sequentially (i.e., as shown below). Figure 2As shown in the stacked diagram, the last encoder (e.g., encoder M in the diagram) is then connected to multiple decoders (i.e., decoder 1 to decoder M in the diagram). Finally, these decoders are connected sequentially, with the last decoder (e.g., decoder M in the diagram) outputting the final result. Each encoder primarily performs multi-head attention calculations on the matrix vector (this process will be detailed below) to obtain feature vectors. In other words, Transformer-Block segments the matrix vector (also known as word vectors), and the number of segments is called "heads," hence the term multi-head attention calculation. The specific calculation process will be described in detail below.

[0049] The output layer described above is used to determine the predicted category of the sample text based on the feature vector. This output layer is connected to the last deformation module (e.g., deformation module M in the figure) among the multiple stacked deformation modules. That is, the last deformation module (Transformer-Block) is connected to the output layer.

[0050] As an optional implementation of step S110, the gradient values ​​of the current round parameters of the pre-trained language model are obtained for the first time. The process of obtaining the gradient values ​​of the current round parameters may include:

[0051] Step S111: Obtain sample text and sample labels.

[0052] The sample text and sample labels mentioned above can be obtained separately. For example, sample text can be collected manually (e.g., the sample text is "I like this movie"), and the sample labels of the sample text can be identified manually (if the sample text is "I like this movie", then the identified sample label is positive sentiment). Of course, the sample text and sample labels can also be packaged into a training dataset and obtained together. Here, we will take obtaining the training dataset together as an example.

[0053] There are many ways to implement step S111 above, including but not limited to: the first method is to receive the training dataset sent by other terminal devices and store the training dataset in a file system, database or mobile storage device; the second method is to obtain the pre-stored training dataset, specifically for example, to obtain the training dataset from a file system, database or mobile storage device; the third method is to use software such as a browser to obtain the training dataset on the Internet, or to use other applications to access the Internet to obtain the training dataset.

[0054] Step S112: Use a pre-trained language model to predict the sample text and obtain the predicted category.

[0055] Please see Figure 3 The diagram shown is a schematic of the encoder and multi-head attention network structure of the Transformer-Block provided in this application embodiment. The implementation of steps S111 to S112 is as follows: Sample text and sample labels are obtained; the sample text is mapped into a matrix vector using the embedding layer in the pre-trained language model; and the matrix vector is processed by the encoder in each transformation module of the pre-trained language model using multi-head attention, vector addition, normalization, and feedforward calculations, etc. (see [link to specific calculation process]). Figure 3 The feature vector is obtained; the output layer of the pre-trained language model is used to determine the predicted category of the sample text based on the feature vector.

[0056] The following section focuses on the calculation process of Multi-Head Attention. "Multi-Head" here means dividing each representation vector in the input matrix vector into h dimensions. If h = 1, it means no division; if h = 8, it means dividing each representation vector into 8 parts (i.e., 8 sub-vectors). Attention here actually refers to weighting and re-representing the text after dividing the multiple sub-vectors. That is, attention can be represented as an attention matrix, which can include: a query matrix (Q), a key matrix (K), and a value matrix (V); where Q and K represent the weights of the attention.

[0057] It is understandable that in the calculation process of the above multi-head attention, Q, K, and V need to be divided according to the number of heads (e.g., h). For ease of description, only two heads are used as an example to explain the overall calculation process. In practice, the number of heads can be set to any length. The calculation process of multi-head attention includes: linear projection, scaled dot-product attention, concatenation, and a second linear projection. Specifically, for example: the first query matrix Q1, the first key matrix K1, and the first numerical matrix V1 are linearly projected, and then the projected features of Q1, K1, and V1 are processed with scaled dot-product attention to obtain the first attention matrix. Similarly, the second query matrix Q2, the second key matrix K2, and the second numerical matrix V2 are linearly projected, and then the projected features of Q2, K2, and V2 are processed with scaled dot-product attention to obtain the second attention matrix. Then, the first and second attention matrices are concatenated along the h-dimensional plane to obtain the concatenated matrix. Finally, the concatenated matrix is ​​linearly projected again to obtain the output data of multi-head attention.

[0058] The calculation process of the scaled dot-product attention described above can be expressed by the formula: Where Q represents the query matrix, K represents the key matrix, and K T The transpose of the key matrix is ​​represented by , V represents the numerical matrix, Attention(Q,K,V) represents the result of scaling dot product attention, and d k Indicates the dimension of the key matrix. This represents the scaling factor. It's understandable that this is because the input includes the dimension (d) of the query matrix. q ), Dimensions of the key matrix (d) k ) and numerical matrix dimension (d v However, what needs to be calculated here is the dot product between the query matrix and all numerical matrices. Therefore, each head needs to be divided by a certain factor during the calculation process. The softmax function is then used to obtain the weight values ​​of the numerical matrix (V).

[0059] The following explanation focuses on the impact of the learning process on the encoder in the deformation module, specifically addressing one (i.e., one layer) of a stacked Transformer-Block architecture. The computation process of each deformation module can include the following sub-processes:

[0060] The first sub-process calculates Q and K in the attention matrix based on the input of the transformation module. For example, suppose the input to the i-th layer Transformer-Block is x. i The attention matrix, including Q, K, and V, can be obtained by calculating using the following formula.

[0061]

[0062] Where (h) represents the h-th head, Q, K, and V represent the query matrix, key matrix, and numerical matrix, respectively, and x i This represents the input to the i-th layer Transformer-Block. These represent the weight parameters (b) of the h-th part of the query matrix, key matrix, and numerical matrix during linear mapping, respectively. h,q b h,k b h,v These represent the bias parameters of the h-th head portion of the query matrix, key matrix, and numerical matrix during linear mapping, respectively.

[0063] The second sub-process calculates self-attention based on Q and K in the attention matrix. This is done using the formula... Calculate self-attention; where (h) represents the h-th head. Let x represent the self-attention of the i-th Transformer-Block, the softmax function represent the normalized exponential function, Q and K represent the query matrix and the key matrix, respectively, and x i d represents the input of the i-th layer Transformer-Block, and k represents the dimension of the pre-trained language model's internal computation. Generally, k > d / h.

[0064] The third sub-process modifies the numerical matrix V in the attention matrix based on self-attention, obtaining the modified matrix. The self-attention process involves updating weights, concatenating dimensions, and normalizing the data using the following formula, thereby modifying the numerical matrix V in the attention matrix and obtaining the modified matrix.

[0065]

[0066]

[0067] Where (h) represents the h-th head. V represents the numerical matrix V, u after weight update calculated based on the h-th head. i V represents the numerical matrix V resulting from the concatenation and normalization of dimensions calculated by all heads. V represents the self-attention of the i-th layer Transformer-Block. (h) Let x represent the numerical matrix corresponding to the h-th head. i W represents the input of the i-th layer Transformer-Block. c,h This represents the concatenated weight matrix or weight vector, b. c,h This represents the concatenated bias matrix or bias vector. d represents the original dimension, and LayerNorm represents the layer normalization, the specific formula of which is: The layer normalization here is mainly to avoid the gradient vanishing problem. z represents the input data, and σ z μ represents the variance or standard deviation of the input data. z This represents the expected average value of the input data. These are trainable parameters, primarily used to adjust the shape (height, width, etc.) and vertex coordinates of the function curve. `concat` is a concatenation operation in P-tuning or P-tuning V2 (including pre-concatenation, mid-concatenation, and post-concatenation). Representative matrix W c,h The transpose of .

[0068] The fourth sub-process uses the ReLU activation function to calculate the modified matrix and then normalizes it again to obtain the output of the deformed module. Specifically, it uses the ReLU activation function to calculate the modified matrix, obtaining the activated matrix; then normalizes the activated matrix again to obtain the output of the deformed module. This is achieved by using the following formula to calculate and normalize the modified matrix to obtain the output of the deformed module.

[0069]

[0070] Among them, z i This represents the activated matrix. Let represent the weight parameters of the h-th part in the first and second layer transformer blocks during linear mapping, respectively. x represents the bias parameter of the h-th part in the first and second layer transformer blocks during linear mapping, respectively. LayerNorm represents the layer normalization, with the same meaning as described above. i+1 This represents the output of the i-th layer Transformer-Block, which is the input of the (i+1)-th layer Transformer-Block.

[0071] Step S113: Calculate the loss value between the sample label and the predicted category, and determine the gradient value of the parameters in this round based on the loss value.

[0072] The implementation of step S113 above can be exemplified as follows: Since the last transformation module (Transformer-Block) is connected to the output layer, and the downstream NLP task of this pre-trained language model is text sentiment classification, the output layer can be set to a normalized exponential function (e.g., a softmax function). In this case, the output layer can determine the predicted category of the sample text based on the output of the last transformation module (Transformer-Block). Specifically, assuming there are y types of text sentiment classification tasks, the loss value between the sample label and the predicted category can be calculated using the following formula.

[0073]

[0074] Among them, Logits X This represents a list of probabilities for multiple predicted categories of the sample text (e.g., positive sentiment 0.9, negative sentiment 0.1), and the softmax function represents the normalization exponential function. This represents the first subvector in the weight parameters of the last Transformer Block (since the program starts counting from 0, this is the first one), x L x represents the output matrix vector of the last transformer block. L [0] represents the first subvector of the output matrix vector of the last layer of the Transformer-Block (since the program starts counting from 0, this is the vector corresponding to the first [CLS]). This represents the first subvector of the bias parameter in the last Transformer-Block layer (since the program starts counting from 0, this is the first one); argmax represents the predicted category with the highest probability selected from a list of probabilities for multiple predicted categories (for example, the predicted category with the highest probability between positive sentiment 0.9 and negative sentiment 0.1 is positive sentiment, which is the final predicted category). The value represents the predicted category of the final output of the pre-trained language model; CrossEntropyLoss represents the Cross Entropy Loss function, L represents the function value calculated by the Cross Entropy Loss function, and Y represents the sample label above.

[0075] Finally, the gradient values ​​of the pre-trained language model's parameters during back propagation are calculated based on the loss value. Specifically, for example, the gradient value of the pre-trained language model's parameters during back propagation is obtained by differentiating the loss value with respect to the weight parameters. This gradient value can be expressed as: In the training process of this pre-trained language model, t represents the number of training iterations (e.g., the t-th iteration) or the training period (e.g., the t-th period), and θ t f(θ) represents the weight parameters of the pre-trained language model during the t-th round (e.g., the tth time or epoch) of training. t ) represents the output data of the pre-trained language model during the tth round (e.g., the tth time or cycle) of training.

[0076] In the implementation of the above scheme, by calculating the loss value between the sample label and the predicted category, and determining the parameter gradient value of this round based on the loss value, the traditional optimization strategy based on human experience is used to determine the parameter gradient value of this round to optimize the prompt learning process of the pre-trained language model, which effectively accelerates the prompt learning efficiency of the pre-trained language model.

[0077] Please see Figure 4The illustration shows a schematic diagram of the LSTM optimization hint learning process provided in the embodiments of this application. It can be understood that the optimizer described above can be a Long Short-Term Memory (LSTM) network or a Bidirectional Long Short-Term Memory (Bi-LSTM) network. For ease of explanation and understanding, the embodiments of this application use an LSTM network as the optimizer for detailed description. The optimization parameters of the LSTM network in this round include: the model parameters and the hidden states in this round. The working principle of the LSTM network as the optimizer can be expressed by the following formula: Where θ represents the weight parameters in the model, it is easy to see that θ t+1 and θ t Let f(θ) represent the weight parameters of the iterative model in round (t+1) (e.g., the number of iterations, time intervals, or periods) and round t, respectively. Let α represent the learning rate hyperparameter. t This represents the output data of the pre-trained language model during the t-th round (e.g., the tth training cycle). φ represents the gradient value of the parameters in the tth round (e.g., the tth time or cycle) of the pre-trained language model, g represents the parameter update amount of the pre-trained language model calculated by the learnable optimizer, and φ represents the weight parameters of the optimizer in L2O.

[0078] As an optional implementation of step S120, the implementation of determining the current round parameter update amount of the pre-trained language model may include:

[0079] Step S121: Obtain the current model parameters and hidden states of the LSTM network.

[0080] An example implementation of step S121 above is as follows: directly obtain the hidden state of the current round from the LSTM network, and obtain the model parameters θ of the previous round of the LSTM network. t-1 And the parameter update amount g from the previous round t-1 Using formula θ t =θ t-1 +g t-1 The model parameters for the current round can be obtained by calculating the parameters and update amounts from the previous round; where θ t θ represents the model parameters for this round. t-1 G represents the parameters of the previous model. t-1 This represents the parameter update amount from the previous round. Similarly, the formula θ can also be used. t+1 =θ t +g t By calculating the model parameters and update amounts for the current round, the model parameters for the next round can be obtained; where θ t+1 θ represents the model parameters for the next round.t G represents the model parameters for this round. t Let represent the parameter update amount of the pre-trained language model in round t calculated by the optimizer (i.e., the parameter update amount in this round). In the implementation of the above scheme, the model parameters in this round are determined based on the model parameters and the parameter update amount in the previous round, thereby avoiding the situation in traditional optimization strategies where the model parameters in this round are directly determined based on the gradient and learning rate, effectively accelerating the prompt learning efficiency of the pre-trained language model.

[0081] Step S122: Determine the next round hidden state of the LSTM network and the parameter update amount of the pre-trained language model in this round based on the current round model parameters and the current round hidden state.

[0082] An example implementation of step S122 above is as follows: using the formula The model parameters and hidden states for this round are calculated to obtain the hidden states of the LSTM network for the next round and the parameter updates of the pre-trained language model for this round; where g t h represents the parameter update amount of the pre-trained language model in round t calculated by the optimizer (i.e., the parameter update amount in this round). t+1 Let θ represent the hidden state of the LSTM network in the (t+1)th round (i.e., the hidden state in the next round), m represent the computation process of the LSTM network, and θ represent the hidden state of the LSTM network in the (t+1)th round. t Let f(θ) represent the weight parameters of the model in the t-th iteration. t This represents the output data of the pre-trained language model during the t-th round (e.g., the tth training cycle). h represents the gradient value of the parameters in the t-th round (e.g., the tth time or epoch) of the pre-trained language model. t φ represents the hidden state parameters of the LSTM network in round t (i.e., the hidden state in this round), and φ represents the weight parameters of the optimizer (i.e., the LSTM network) in L2O.

[0083] As an optional implementation of step S130, the pre-trained language model is a Transformer-type model; the pre-trained language model is subjected to cue learning using the parameter update amount in this round, including:

[0084] Step S131: Modify the attention matrix in the Transformer class model according to the parameter update amount in this round to obtain the modified attention matrix.

[0085] The implementation of step S131 above is as follows: The basic computational operation process of the Transformer class model has been described above. Due to the above K (h) (x i ),V (h) (x iEach head in each layer of the algorithm is exactly the same size. Therefore, for ease of understanding, we will use one head in each layer as an example below. Let's assume the prompt matrix is ​​represented as P. k P q and / or P v (The initial hint matrix can be randomly initialized, and subsequent hint matrices are determined using the parameter update amount from this round), where the hint matrix P is... k Used to modify the key matrix (K) in the attention matrix, here the cue matrix P q Used to modify the query matrix (Q) in the attention matrix, and the suggestion matrix P here. v Used to modify the numerical matrix (V) in the attention matrix.

[0086] In practical application, the cue matrix can be used to modify any one matrix (Q, K, or V) in the attention matrix, any two matrices (Q and K, or K and V, or Q and V), or all three matrices (Q, K, and V). For ease of understanding and explanation, the following example only illustrates the modification of K and V in the attention matrix. The above can be achieved by randomly initializing the cue matrix P. k and P v Then, the formula K′=concat(P) can be used. k ,K); V′=concat(P v The key matrix K and the numerical matrix V in the attention matrix are modified separately to obtain the modified attention matrix K′ and V′. K′ is the key matrix in the modified attention matrix, V′ is the numerical matrix in the modified attention matrix, and concat is a concatenation operation in P-tuning or P-tuning V2 (including pre-concatenation, mid-concatenation, and post-concatenation).

[0087] In the implementation of the above scheme, the cue matrix can be obtained by random initialization at the beginning. Subsequently, the cue matrix can be determined by the parameter update amount in the current round. The attention matrix in the Transformer-type model can be modified according to the cue matrix through P-tuning or P-tuning V2. Cue learning is then performed based on the modified attention matrix. By combining the historical optimization of the algorithm, the optimal strategy is selected for each step, thereby avoiding the problem of low learning efficiency caused by cue learning based on manually designed cue templates. This effectively accelerates the cue learning efficiency of the pre-trained language model.

[0088] Step S132: Based on the modified attention matrix, perform cue learning on the Transformer-type model, and calculate the next round parameter gradient value of the pre-trained language model according to the output data of the pre-trained language model until the learning termination condition is reached, and obtain the learned language model.

[0089] The implementation of step S132 above is as follows: Calculate the modified self-attention based on Q and K′ in the attention matrix; modify the numerical matrix V′ in the modified attention matrix based on the modified self-attention to obtain the modified matrix; calculate the modified matrix using the ReLU activation function and normalize it again to obtain the output data of the final deformation module in the pre-trained language model. This can be achieved using the formula... The gradient values ​​of the parameters for the next round of the pre-trained language model are obtained by calculating the output data of the last morphing module in the pre-trained language model; where f(θ) represents the output data of the last morphing module in the pre-trained language model. This represents the gradient value of the parameters in the next round of the pre-trained language model. Since the implementation method here is similar to that of steps S111 and S112 above, it will not be described again. The above-described cue learning is performed on the pre-trained language model in a loop until the learning termination condition is met, resulting in the learned language model. The learning termination condition can be of various types, including but not limited to: learning to a preset number of rounds (e.g., learning to the 200th round), or the total loss value being less than a preset loss value (e.g., 10%), or the total accuracy being greater than a preset percentage (e.g., 80%), etc. In the implementation of the above scheme, by modifying the attention matrix in the Transformer-type model according to the parameter update amount in this round, and performing cue learning based on the modified attention matrix, the problem of low learning efficiency caused by cue learning based on manually designed cue templates is avoided, effectively accelerating the cue learning efficiency of the pre-trained language model.

[0090] The main idea of ​​the aforementioned model prompting learning method is to apply L2O technology to the prompting learning process of a pre-trained language model (PLM). Specifically, it uses an optimizer learned through L2O (which is learnable) to accelerate the prompting learning process of the PLM, thus avoiding the use of traditional optimization strategies based on human experience (which are not learnable) to optimize the PLM's learning process. In other words, a learnable optimizer accelerates the prompting learning process of the pre-trained language model. This involves determining the current parameter update amount of the pre-trained language model based on the current parameter gradient values ​​and the current optimization parameters of the optimizer, and then using this update amount to perform prompting learning on the pre-trained language model. This allows for adjustments based on the corresponding data and optimization task, providing the optimal update direction and size for each step, thereby avoiding the use of traditional optimization strategies based on human experience to optimize the prompting learning process of the pre-trained language model and effectively accelerating the prompting learning efficiency of the pre-trained language model.

[0091] As an alternative implementation of the model hint learning method, before obtaining the current optimization parameters of the optimizedr after learning, the optimizedr can also be trained (i.e., the weight parameters in the optimizedr are updated), including:

[0092] Step S210: Determine the total loss value of the optimizer based on the expected output value of the pre-trained language model.

[0093] For example, the implementation of step S210 above can be achieved using the desired formula. The expected output value of the pre-trained language model is calculated to obtain the total loss value of the optimizer; where, θ represents the weight parameters in the model. It is easy to see that θ t+1 and θ t Let f(θ) represent the weight parameters of round t+1 (e.g., the number of rounds, time periods, or cycles) and round t, respectively. Let T represent the unrolling length of the pre-trained language model, which can be understood as the total number of rounds in training the model. t This represents the output data of the pre-trained language model during the t-th round (e.g., the tth training cycle). g represents the gradient value of the parameters in the t-th round (e.g., the number of times or cycles) of training the pre-trained language model. t φ represents the parameter update amount of the pre-trained language model calculated by the learnable optimizer in the t-th round (e.g., the tth iteration or epoch) of training (i.e., the parameter update amount in this round), φ represents the weight parameters of the optimizer (i.e., the LSTM network) in L2O, m represents the calculation process of the LSTM network, and h t h represents the hidden state parameters (i.e., the hidden state in this round) of the LSTM network in round t. t+1This represents the hidden state of the LSTM network in round t+1 (i.e., the hidden state in the next round).

[0094] Step S220: Update the optimizer's parameters based on the total loss value to obtain the learned optimizer.

[0095] The specific implementation of step S220 above is as follows: The optimizer's parameters are updated and learned based on the total loss value until the learning termination condition is met (e.g., after 20 rounds of learning), thus obtaining the learned optimizer. In the implementation of the above scheme, by determining the optimizer's total loss value based on the expected output value of the pre-trained language model, and updating the optimizer's parameters based on the total loss value, the traditional optimization strategy based on human experience is avoided in optimizing the prompt learning process of the pre-trained language model, effectively accelerating the prompt learning efficiency of the pre-trained language model.

[0096] As an alternative implementation of the model prompt learning method, after obtaining the learned language model, the learned language model can also be used for prompt prediction (i.e., using prompt templates for model inference). The prompt prediction process can include:

[0097] Step S310: Obtain sample text and prompt template, the prompt template includes: input slot and answer slot.

[0098] The implementation of step S310 above is as follows: Obtain sample text, such as: "I like this movie," or "I hate this movie." Then, obtain and select an unfilled prompt template, such as: [X], in short, this is a [Z] movie. Here, [X] represents an input slot, used to input prompt text (e.g., "I like this movie," or "I hate this movie") or a prompt vector; [Z] represents an answer slot, used by the pre-trained language model to generate answer text or an answer vector on the fly.

[0099] Step S320: Fill the input slots in the prompt template with sample text to obtain the filling template.

[0100] The implementation of step S320 above is as follows: Sample text is filled into the input slots of the prompt template to obtain a filled prompt template (i.e., a filled template). For example: I like this movie; in short, it's a [Z] movie. The pre-trained language model can predict whether the answer text corresponding to the answer slot is good, fantastic, or bad.

[0101] Step S330: Use the learned language model to predict the text corresponding to the empty answer slots in the filling template to obtain the predicted answer text.

[0102] For example, the above step S330 can be implemented by using the learned language model to predict the text corresponding to the answer slots in the filling template. Then the pre-trained language model can predict that the predicted answer text corresponding to the answer slots includes: good, fantastic, or bad.

[0103] Step S340: Map the predicted answer text to the output prediction result.

[0104] For example, in a text sentiment classification task, the text for "good" and "fantastic" answers can be mapped to positive sentiment categories, while "bad" answers can be mapped to negative sentiment categories. In the implementation of this scheme, the predicted answer text is obtained by predicting the text corresponding to the empty answer slots in the template using a learned language model. Since the learned language model is obtained by optimizing the prompting learning process of the language model using L2O technology, the traditional optimization strategy based on human experience is avoided in optimizing the prompting learning process of the pre-trained language model, effectively accelerating the prompting learning efficiency of the pre-trained language model.

[0105] Please see Figure 5 The diagram shown is a structural schematic of the model prompting learning device provided in an embodiment of this application; this application provides a model prompting learning device 400, including:

[0106] The parameter gradient acquisition module 410 is used to acquire the current parameter gradient values ​​of the pre-trained language model.

[0107] The optimization parameter acquisition module 420 is used to acquire the current round optimization parameters of the optimizedr after learning, and to determine the current round parameter update amount of the pre-trained language model using the current round parameter gradient value and the current round optimization parameters.

[0108] The model prompting learning module 430 is used to perform prompting learning on the pre-trained language model using the parameter update amount of the current round, and calculate the next round parameter gradient value of the pre-trained language model based on the output data of the pre-trained language model, until the learning termination condition is reached, and obtain the learned language model.

[0109] Optionally, in this embodiment of the application, the parameter gradient acquisition module includes:

[0110] The text label retrieval submodule is used to retrieve sample text and sample labels.

[0111] The predicted category acquisition submodule is used to predict the category of sample text using a pre-trained language model.

[0112] The first gradient determination submodule is used to calculate the loss value between the sample label and the predicted category, and determine the gradient value of the parameters in this round based on the loss value.

[0113] Optionally, in this embodiment, the optimizer is a Long Short-Term Memory (LSTM) network, and the current optimization parameters of the LSTM network include: the current model parameters and the current hidden state; the optimization parameter acquisition module includes:

[0114] The state parameter acquisition submodule is used to obtain the current round model parameters and the current round hidden state of the LSTM network.

[0115] The State Update Determination Submodule is used to determine the next round hidden state of the LSTM network and the parameter update amount of the pre-trained language model in this round based on the current round model parameters and the current round hidden state.

[0116] Optionally, in this embodiment, the pre-trained language model is a Transformer-type model; the model prompting learning module includes:

[0117] The Attention Matrix Modification submodule is used to modify the attention matrix in the Transformer class model according to the parameter update amount in this round, obtain the modified attention matrix, and perform prompt learning based on the modified attention matrix.

[0118] Optionally, in embodiments of this application, the model prompting learning device further includes:

[0119] The optimizer parameter update module is used to determine the total loss value of the optimizer based on the expected output value of the pre-trained language model, and to update the optimizer parameters based on the total loss value.

[0120] Optionally, in embodiments of this application, the model prompting learning device further includes:

[0121] The prompt template acquisition module is used to acquire sample text and prompt templates. The prompt templates include: input empty slots and answer empty slots.

[0122] The fill template acquisition module is used to fill the input slots in the prompt template with sample text to obtain the fill template.

[0123] The language model prediction module is used to predict the text corresponding to the empty answer slots in the filling template using the learned language model, and obtain the predicted answer text.

[0124] It should be understood that this device corresponds to the model prompting learning method embodiment described above and is capable of performing the various steps involved in the above method embodiment. The specific functions of this device can be found in the description above, and detailed descriptions are omitted here to avoid repetition. The device includes at least one software functional module that can be stored in memory or embedded in the device's operating system (OS) in the form of software or firmware.

[0125] An electronic device provided in this application includes a processor and a memory. The memory stores machine-readable instructions that can be executed by the processor. When the machine-readable instructions are executed by the processor, the method described above is performed.

[0126] This application also provides a computer-readable storage medium storing a computer program, which is executed by a processor to perform the above-described method.

[0127] The computer-readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.

[0128] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For apparatus embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0129] It should be understood that the disclosed apparatus and methods can also be implemented in other ways, as provided in the embodiments of this application. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in the flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the accompanying drawings. For example, two consecutive blocks may actually be executed substantially in parallel, or they may sometimes be executed in reverse order, depending primarily on the functions involved.

[0130] Furthermore, the functional modules of each embodiment in this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part. In addition, in the description of this specification, the reference to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., means that the specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.

[0131] In this document, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, without necessarily requiring or implying any such actual relationship or order between these entities or operations.

[0132] The above description is only an optional implementation of the embodiments of this application, but the protection scope of the embodiments of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the embodiments of this application should be covered within the protection scope of the embodiments of this application.

Claims

1. A model prompting learning method, characterized in that, include: Obtain the gradient values ​​of the parameters of the pre-trained language model in this round; Obtain the current round optimization parameters of the optimizedr after learning, and use the gradient values ​​of the current round parameters and the current round optimization parameters to determine the current round parameter update amount of the pre-trained language model; The pre-trained language model is prompted to learn using the parameter update amount of this round, and the next round parameter gradient value of the pre-trained language model is calculated based on the output data of the pre-trained language model until the learning termination condition is reached to obtain the learned language model. The learned language model is used to predict sample text to obtain the predicted answer text. The pre-trained language model is a Transformer-type model; the step of using the current round of parameter update to perform cue learning on the pre-trained language model includes: modifying the attention matrix in the Transformer-type model according to the current round of parameter update, obtaining the modified attention matrix, and performing cue learning based on the modified attention matrix, wherein the attention matrix includes: query matrix, key matrix and numerical matrix; The optimizer is a Long Short-Term Memory (LSTM) network. The current optimization parameters of the LSTM network include the current model parameters and the current hidden state. Determining the current parameter update amount of the pre-trained language model using the current parameter values ​​and the current optimization parameters includes: obtaining the previous model parameters and the previous parameter update amount of the LSTM network; determining the current model parameters based on the previous model parameters and the previous parameter update amount; and determining the next hidden state of the LSTM network and the current parameter update amount of the pre-trained language model based on the current hidden state and the current model parameters.

2. The method according to claim 1, characterized in that, The process of obtaining the gradient values ​​of the current round parameters of the pre-trained language model includes: Obtain sample text and sample tags; The pre-trained language model is used to predict the sample text to obtain the predicted category; Calculate the loss value between the sample label and the predicted category, and determine the gradient value of the parameters for this round based on the loss value.

3. The method according to any one of claims 1-2, characterized in that, Before obtaining the current round optimization parameters of the learned optimizer, the following steps are also included: The total loss value of the optimizer is determined based on the expected output value of the pre-trained language model, and the optimizer is then used to update its parameters based on the total loss value.

4. The method according to any one of claims 1-2, characterized in that, After obtaining the learned language model, the following is also included: Obtain sample text and a prompt template, wherein the prompt template includes: an input slot and an answer slot; Fill the input slots in the prompt template with the sample text to obtain the filling template; The learned language model is used to predict the text corresponding to the empty answer slots in the filling template to obtain the predicted answer text.

5. A model prompting learning device, characterized in that, include: The parameter gradient acquisition module is used to obtain the current parameter gradient values ​​of the pre-trained language model. The optimization parameter acquisition module is used to acquire the current round optimization parameters of the learned optimizer, and use the gradient value of the current round parameters and the current round optimization parameters to determine the current round parameter update amount of the pre-trained language model; The model prompting learning module is used to perform prompting learning on the pre-trained language model using the current round of parameter update amount, and calculate the next round of parameter gradient value of the pre-trained language model based on the output data of the pre-trained language model, until the learning termination condition is reached to obtain the learned language model. The learned language model is used to predict sample text to obtain the predicted answer text. The pre-trained language model is a Transformer-type model; the step of using the current round of parameter update to perform cue learning on the pre-trained language model includes: modifying the attention matrix in the Transformer-type model according to the current round of parameter update, obtaining the modified attention matrix, and performing cue learning based on the modified attention matrix, wherein the attention matrix includes: query matrix, key matrix and numerical matrix; The optimizer is a Long Short-Term Memory (LSTM) network. The current optimization parameters of the LSTM network include the current model parameters and the current hidden state. Determining the current parameter update amount of the pre-trained language model using the current parameter values ​​and the current optimization parameters includes: obtaining the previous model parameters and the previous parameter update amount of the LSTM network; determining the current model parameters based on the previous model parameters and the previous parameter update amount; and determining the next hidden state of the LSTM network and the current parameter update amount of the pre-trained language model based on the current hidden state and the current model parameters.

6. An electronic device, characterized in that, include: A processor and a memory, the memory storing machine-readable instructions executable by the processor, which, when executed by the processor, perform the method as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Adam-based optimization method, system and terminal

    CN111931422A