Natural language processing method and device based on language model
By introducing soft prompt parameters to fine-tune the language model, the problems of efficient, low-cost execution and accuracy in natural language processing tasks are solved, and the language model is well adapted to specific tasks or fields.
Patent Information
- Application Number
- CN202411601023.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-03-11
AI Technical Summary
The prior art is difficult to perform natural language processing tasks efficiently and at low cost, and it is difficult to ensure the accuracy of the execution of tasks, especially when the data volume is insufficient and the labeling cost is high.
By introducing soft prompt parameters, the language model can be fine-tuned to adapt to specific tasks or fields without the need to directly fine-tune the language model. The specific steps include obtaining fine-tuning sample data and soft prompt parameters, generating fine-tuning prompt data and inputting language model, and adjusting soft prompt parameters to optimize task execution.
It realizes efficient and low-cost execution of tasks in natural language processing tasks, ensures the accuracy of tasks execution, reduces the amount of parameters that need to be fine-tuned, and makes the language model better adapt to specific tasks or fields.
Smart Images

Figure CN119598964A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present application relate to the field of artificial intelligence technology, and in particular, to a natural language processing method and device based on a language model. Background Art
[0002] Natural Language Processing (NLP) is an interdisciplinary subject in the fields of computer science, artificial intelligence and linguistics, which aims to enable computers to understand, interpret and generate human natural language. The main tasks of natural language processing include but are not limited to: text classification, that is, assigning text to predefined categories, such as news categories, sentiment analysis (positive, negative, neutral, etc.); Named Entity Recognition (NER), that is, identifying entity names in text, such as names of people, places, and organizations; sentiment analysis, that is, determining the emotional state or attitude of the text, such as judging whether a comment is positive or negative; machine translation, that is, translating one natural language into another natural language; information extraction, that is, extracting key information from a large amount of text; question-answering system, that is, automatically answering users' natural language questions; dialogue system, that is, building a chatbot or virtual assistant that can communicate naturally with humans; and so on.
[0003] Nowadays, how to perform natural language processing tasks efficiently and at low cost, and ensure the accuracy of natural language processing tasks, has become a highly concerned issue. Summary of the invention
[0004] One or more embodiments of the present application provide the following technical solutions:
[0005] The present application provides a natural language processing method based on a language model, the method comprising:
[0006] Acquire fine-tuning sample data corresponding to a natural language processing task to be performed, and acquire soft prompt parameters corresponding to the natural language processing task;
[0007] Based on the fine-tuning sample data and the soft prompt parameters, fine-tuning prompt data corresponding to the natural language processing task is generated, and the fine-tuning prompt data is input into a language model, and the language model performs reasoning based on the fine-tuning prompt data to obtain a reasoning result corresponding to the fine-tuning prompt data;
[0008] Based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, the soft prompt parameters are adjusted to perform the natural language processing task based on the adjusted soft prompt parameters and the language model.
[0009] The present application also provides a natural language processing device based on a language model, the device comprising:
[0010] An acquisition module is used to acquire fine-tuning sample data corresponding to a natural language processing task to be performed, and to acquire soft prompt parameters corresponding to the natural language processing task;
[0011] An inference module, which generates fine-tuning prompt data corresponding to the natural language processing task based on the fine-tuning sample data and the soft prompt parameters, and inputs the fine-tuning prompt data into a language model, and the language model performs inference based on the fine-tuning prompt data to obtain an inference result corresponding to the fine-tuning prompt data;
[0012] An adjustment module adjusts the soft prompt parameters based on an inference result corresponding to the fine-tuning prompt data and an optimization target corresponding to the language model, so as to perform the natural language processing task based on the adjusted soft prompt parameters and the language model.
[0013] The present application also provides an electronic device, including:
[0014] processor;
[0015] a memory for storing processor-executable instructions;
[0016] The processor implements the steps of any of the above methods by running the executable instructions.
[0017] The present application also provides a computer-readable storage medium having computer instructions stored thereon, which implement the steps of any of the above methods when executed by a processor.
[0018] In the above technical scheme, when fine-tuning sample data corresponding to a natural language processing task to be executed is obtained, the soft prompt parameters corresponding to the natural language processing task can be first obtained, and then based on the fine-tuning sample data and the soft prompt parameters, the fine-tuning prompt data corresponding to the natural language processing task is generated, and the fine-tuning prompt data is input into a language model, and the language model performs reasoning based on the fine-tuning prompt data to obtain the reasoning result corresponding to the fine-tuning prompt data, and finally, based on the reasoning result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, the soft prompt parameters are adjusted to execute the natural language processing task based on the adjusted soft prompt parameters and the language model.
[0019] By adopting the above method, by introducing soft prompt parameters, it is possible to adjust the introduced soft prompt parameters to achieve the effect of fine-tuning the language model, thereby ensuring that the language model can better adapt to specific tasks or fields without directly fine-tuning the language model. This reduces the amount of parameters that need to be fine-tuned. Therefore, when the language model is applied to natural language processing, natural language processing tasks can be performed efficiently and at low cost, and the execution accuracy of natural language processing tasks can be guaranteed. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The following is a description of the accompanying drawings required for describing the exemplary embodiments, wherein:
[0021] Figure 1 It is a schematic diagram of a natural language processing system shown in an exemplary embodiment of the present application.
[0022] Figure 2 It is a flowchart of a natural language processing method based on a language model shown in an exemplary embodiment of the present application.
[0023] Figure 3 It is a schematic diagram of a natural language processing process based on a language model shown in an exemplary embodiment of the present application.
[0024] Figure 4 It is a structural schematic diagram of a device shown in an exemplary embodiment of the present application.
[0025] Figure 5 It is a block diagram of a natural language processing device based on a language model shown as an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0026] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the accompanying drawings. When the following description relates to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of the present application. On the contrary, they are only examples consistent with some aspects of one or more embodiments of the present application.
[0027] It should be noted that in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this application. In some other embodiments, the steps included in the method may be more or less than those described in this application. In addition, a single step described in this application may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this application may also be combined into a single step for description in other embodiments.
[0028] Natural Language Processing (NLP) is an interdisciplinary subject in the fields of computer science, artificial intelligence and linguistics, which aims to enable computers to understand, interpret and generate human natural language. The main tasks of natural language processing include but are not limited to: text classification, that is, assigning text to predefined categories, such as news categories, sentiment analysis (positive, negative, neutral, etc.); Named Entity Recognition (NER), that is, identifying entity names in text, such as names of people, places, and organizations; sentiment analysis, that is, determining the emotional state or attitude of the text, such as judging whether a comment is positive or negative; machine translation, that is, translating one natural language into another natural language; information extraction, that is, extracting key information from a large amount of text; question-answering system, that is, automatically answering users' natural language questions; dialogue system, that is, building a chatbot or virtual assistant that can communicate naturally with humans; and so on.
[0029] With the development of deep learning, language models (LM) have become one of the mainstream technologies in the field of natural language processing. Language models capture the complex structure of language by learning from large-scale corpora and can be transferred to a variety of downstream tasks, thus promoting the progress of natural language processing. In the field of natural language processing, downstream tasks refer to tasks that use language models for specific applications. These tasks are usually specific language understanding and generation tasks, such as text classification, named entity recognition, sentiment analysis, machine translation, information extraction, question-answering systems, dialogue systems, etc.
[0030] In the field of natural language processing, large-scale text data sets are usually called corpuses. Corpuses can contain various types of text data, such as literary works, academic papers, legal documents, news reports, daily conversations, emails, online forum posts, etc. By learning the text data in the corpus, the language model can obtain and understand the laws and patterns of natural language, thereby achieving effective processing and generation of human language.
[0031] A language model is a deep learning model trained with a large amount of text data, which can be used to generate natural language text or understand the meaning of natural language text. It is a statistical model used to estimate the probability distribution of a text sequence formed by a series of words, characters or other symbols in a given language. Language models play a core role in a variety of natural language processing tasks and are an important path to artificial intelligence. These natural language processing tasks include but are not limited to: text generation, which means that language models can be used to generate coherent text sequences, such as articles, stories, poems, etc.; machine translation, which means that language models help generate reasonable sentences in the target language; information retrieval, which means that language models help improve the effectiveness of search engines and improve the relevance of search results by better understanding the query intent; dialogue systems, which means that language models can be used to build natural language processing systems so that machines can communicate with people more naturally; and so on.
[0032] Language models usually use the Transformer architecture, that is, language models are usually deep learning models based on the Transformer architecture. Deep learning models based on the Transformer architecture are a type of neural network model that uses the Transformer architecture. This model performs well in areas such as natural language processing.
[0033] Transformer is a neural network model for sequence-to-sequence modeling. Transformer does not need to rely on recursive structures, can parallelize training and reasoning, and speed up model processing. In deep learning models based on the Transformer architecture, a multi-layer Transformer encoder is usually used to extract features from the input sequence, and a Transformer decoder is used to convert the extracted features into an output sequence, such as T5 (Text-to-Text Transfer Transformer); in addition, there are models that only contain Transformer encoders, such as BERT (Bidirectional Encoder Representations from Transformers), and models that only contain Transformer decoders, such as the Qwen model. At the same time, such models usually also use a self-attention mechanism to capture long-distance dependencies in the input sequence, and use residual connections and regularization methods to accelerate training and improve model performance.
[0034] A pre-trained language model is a language model that is pre-trained on large-scale unlabeled text data. A pre-trained language model is a general model that is not designed and optimized for specific tasks. In order to adapt the pre-trained language model to specific application scenarios and task requirements, fine-tuning is required to improve the performance of the model on specific tasks. The language model that is finally put into use is usually a model that is further fine-tuned on the basis of the pre-trained language model and is a supervised learning model based on labeled text data. Pre-training and fine-tuning are complementary processes. Pre-training enables the model to have a wide range of language understanding capabilities, while fine-tuning makes the model more professional and accurate in specific tasks.
[0035] That is, the training process of the language model can be divided into two stages: pre-training and fine-tuning. In the pre-training stage, unsupervised learning (e.g., self-supervised learning) can be used to perform pre-training on large-scale, unlabeled text data sets (e.g., online encyclopedias, online articles, books, etc.). Specifically, the missing part or the next word can be predicted based on the context, and statistical laws and language structures such as semantics and syntax can be learned. The prediction loss can be minimized through back-propagation and optimization algorithms (e.g., gradient descent method), and model parameters can be iteratively updated to gradually improve the model's ability to understand language. In the fine-tuning stage, you can select corresponding supervised learning tasks (such as text classification, named entity recognition, sentiment analysis, machine translation, information extraction, question-answering system, dialogue system, etc.) according to specific application scenarios and task requirements, and prepare task-specific text datasets, so that the pre-trained model can be used as the starting point for fine-tuning, and fine-tuning can be performed on the task-specific text dataset using supervised learning. Specifically, the task can be performed based on the text dataset, and the loss used to measure the performance of the model in processing specific tasks can be minimized through back propagation and optimization algorithms (such as gradient descent), and the model parameters can be iteratively updated to gradually improve the performance of the model on specific tasks. In practical applications, both the pre-training stage and the fine-tuning stage can flexibly select supervised learning, unsupervised learning, or semi-supervised learning according to the specific application scenarios and the type of available data; in some special cases, transfer learning, reinforcement learning, and other methods can also be selected.
[0036] It should be noted that the language comprehension ability learned by the language model in the pre-training and fine-tuning stages enables the language model to make logical inferences, knowledge inferences or solve problems by understanding, analyzing and integrating text information when faced with complex problems or tasks. This ability is usually referred to as the reasoning ability of the language model.
[0037] Language models usually perform specific tasks under the guidance of prompt text. Prompt text is an initial text or text fragment provided to the language model, which is intended to stimulate the model to produce corresponding output. Through the prompt text, you can clearly tell the language model what task you expect it to perform, such as: answering a question, simulating a conversation, writing an article, translating text, etc. At the same time, the prompt text can provide the language model with the necessary background information and context, so that the language model can understand the logic, style, theme or position that should be followed when generating content. In addition, the prompt text can also stimulate the language model to show its inherent knowledge reserves or specific language capabilities, such as: explaining complex concepts, citing regulations, imitating the writing style of a specific writer, etc.
[0038] It should be noted that a type of prompt similar to the above prompt text is usually called a hard prompt. Hard prompts refer to clear and specific instructions or questions used in natural language processing tasks. These instructions or questions are directly provided as input to the language model in order to guide the model to generate a specific type of output. In other words, hard prompts can directly tell the model what it should do or what type of response is expected. Hard prompts are usually artificially designed to guide the behavior of the model without adjusting or fine-tuning the parameters of the model itself, and they do not contain any learnable parameters themselves. Hard prompts are usually included in the input text and are in natural language form. For example, if you want the model to generate a poem, you can give a hard prompt like this: "Write a five-character quatrain about autumn."
[0039] In addition, there is another type of prompt called soft prompt. Soft prompt is a technique used in natural language processing tasks. It involves adding a series of learnable parameters to the model input, which are usually expressed as embedding vectors. These vectors can be regarded as a kind of virtual vocabulary or text inside the model. They do not directly correspond to natural language text, but are adjusted and fine-tuned by optimizing the objective function during model training. Among them, the optimization function can usually be a loss function, a cost function, a risk function, a reward function, an evaluation function, a utility function, etc. The main purpose of soft prompts is to make the pre-trained language model better adaptable to specific tasks or fields without completely fine-tuning the entire model. This makes soft prompts more flexible to adapt to different tasks or fields, and does not require artificial design of complex instructions or questions.
[0040] In the actual application scenarios of natural language processing, in order to use language models to perform specific natural language processing tasks, it is necessary to fine-tune the pre-trained language model based on the text dataset corresponding to such natural language processing tasks, so as to apply the fine-tuned language model to such natural language processing tasks, that is, the fine-tuned language model provides the corresponding natural language processing services.
[0041] In the fine-tuning stage of the language model, supervised learning is usually chosen, which requires that the text dataset used to fine-tune the pre-trained language model is labeled. In this case, in order to ensure the model effect of the fine-tuned language model, it is necessary to fine-tune the pre-trained language model on a large amount of labeled text data.
[0042] However, in practical applications, on the one hand, it is usually difficult to obtain large-scale text data that can be used for fine-tuning. On the other hand, since manual annotation is usually used to ensure the quality of labels, the annotation cost is high, which further reduces the amount of labeled text data that can be obtained. Therefore, the fine-tuning of pre-trained language models often faces the problem of insufficient data, which affects the model effect of the fine-tuned language model. In addition, even if the amount of labeled text data obtained can be guaranteed, due to the large amount of data, the efficiency of fine-tuning the pre-trained language model on these labeled text data is usually not high. When there are many types of natural language processing tasks expected to be performed by the language model, these problems will be exacerbated, that is, the natural language processing tasks cannot be performed efficiently and at low cost, and the execution accuracy of the natural language processing tasks cannot be guaranteed.
[0043] One or more embodiments of the present application provide a technical solution for natural language processing based on a language model. In the technical solution, when fine-tuning sample data corresponding to a natural language processing task to be executed is obtained, soft prompt parameters corresponding to the natural language processing task can be first obtained, and then fine-tuning prompt data corresponding to the natural language processing task is generated based on the fine-tuning sample data and the soft prompt parameters, and the fine-tuning prompt data is input into the language model, and the language model performs reasoning based on the fine-tuning prompt data to obtain a reasoning result corresponding to the fine-tuning prompt data. Finally, based on the reasoning result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, the soft prompt parameters are adjusted to execute the natural language processing task based on the adjusted soft prompt parameters and the language model.
[0044] By adopting the above method, by introducing soft prompt parameters, it is possible to adjust the introduced soft prompt parameters to achieve the effect of fine-tuning the language model, thereby ensuring that the language model can better adapt to specific tasks or fields without directly fine-tuning the language model. This reduces the amount of parameters that need to be fine-tuned. Therefore, when the language model is applied to natural language processing, natural language processing tasks can be performed efficiently and at low cost, and the execution accuracy of natural language processing tasks can be guaranteed.
[0045] Please refer to Figure 1 , Figure 1 It is a schematic diagram of a natural language processing system shown in an exemplary embodiment of the present application.
[0046] like Figure 1 As shown, the above-mentioned natural language processing system may include a server and at least one client accessing the server through any type of wired or wireless network.
[0047] Among them, the above-mentioned server can correspond to a server including an independent physical host, or it can be a server cluster composed of multiple independent physical hosts; or it can correspond to a virtual server, cloud server, etc. carried by a host cluster.
[0048] The above-mentioned client may correspond to terminal devices such as smart phones, tablet computers, laptops, desktop computers, PCs (Personal Computers), PDAs (Personal Digital Assistants), wearable devices (such as smart glasses, smart watches, etc.), smart car devices or game consoles.
[0049] Users can use the natural language processing service provided by the natural language processing system through the client; the client and the server can implement user-oriented natural language processing services through data interaction between each other.
[0050] Taking the information extraction service as an example, the client can output a corresponding user interface to the user, so that the user can perform operations such as inputting text or documents from which information needs to be extracted, selecting information extraction services, etc. in the user interface, so as to inform the natural language processing system that it needs to perform information extraction tasks for the input text or documents, and use the information extraction service provided by the natural language processing system. The client can send the text or document input by the user to the server, and the server will extract information from the text or document and output the extracted information to the user, that is, return the extracted information to the client, and the client will display the extracted information to the user through the user interface for the user to view, thereby realizing user-oriented information extraction services.
[0051] Taking the question-answering and dialogue service as an example, the client can output a corresponding user interface to the user, so that the user can perform operations such as inputting question text (which can be called Query or Question) and uploading documents or pictures used to assist in asking questions in the user interface, so as to ask questions to the natural language processing system and use the question-answering and dialogue services provided by the natural language processing system. The client can send the question text input by the user to the server, and the server will generate the corresponding answer text (which can be called Answer) for the question text, and output the answer text to the user, that is, return the answer text to the client, and the client will display the answer text to the user through the user interface for the user to view, thereby realizing user-oriented question-answering and dialogue services.
[0052] Specifically, a language model may be deployed on the server, and the natural language processing system may be based on the language model, and the language model may execute specific steps in the natural language processing task.
[0053] In addition, other functional modules can be deployed on the above server, such as data preprocessing module, soft prompt parameter selection module, soft prompt parameter pre-training module, soft prompt parameter fine-tuning module, soft prompt parameter update module, post-processing module, etc. In addition, a soft prompt parameter pool for storing different soft prompt parameters can also be deployed on the server. These modules can work together with the language model deployed on the server to jointly realize natural language processing.
[0054] Please refer to Figure 2 , Figure 2 It is a flowchart of a natural language processing method based on a language model shown in an exemplary embodiment of the present application.
[0055] In this embodiment, the above-mentioned natural language processing method based on language model can be applied to Figure 1 The server side is shown.
[0056] like Figure 2 As shown, the above-mentioned natural language processing method based on the language model may include the following steps:
[0057] Step 202: Obtain fine-tuning sample data corresponding to the natural language processing task to be performed, and obtain soft prompt parameters corresponding to the natural language processing task.
[0058] In this embodiment, in order to use the language model to perform a natural language processing task, it is necessary to fine-tune the language model based on a text data set corresponding to such a natural language processing task. That is, first, data corresponding to the natural language processing task to be performed and used for fine-tuning the language model (which may be referred to as fine-tuning sample data) may be obtained. The fine-tuning sample data may generally be data in text form.
[0059] As mentioned above, the main purpose of soft hints is to make the pre-trained language model better adapted to a specific task or domain without completely fine-tuning the entire model. Therefore, in order to efficiently and cost-effectively obtain a language model that can provide natural language processing services, soft hint parameters can be introduced, and the effect of fine-tuning the pre-trained language model can be achieved by adjusting and fine-tuning the introduced soft hint parameters, instead of directly fine-tuning the pre-trained language model itself. In this case, the soft hint parameters corresponding to the natural language processing task to be performed can be obtained.
[0060] In some embodiments, in order to facilitate unified maintenance and management of different soft prompt parameters, a soft prompt parameter pool may be set, and different soft prompt parameters may be stored in the soft prompt parameter pool. In this case, when obtaining the soft prompt parameters corresponding to the above-mentioned natural language processing task, the soft prompt parameters corresponding to the natural language processing task may be selected from the soft prompt parameter pool based on a preset soft prompt parameter selection strategy.
[0061] For example, in the above soft prompt parameter pool, soft prompt parameters can be stored in the form of Key-Value pairs. Among them, a Key can be a task type or application scenario, and a Value can be one or a group of soft prompt parameters; task types can include text classification, named entity recognition, sentiment analysis, machine translation, information extraction, question-answering system, dialogue system, etc., and application scenarios can include business, law, medical, etc. That is, a task type can correspond to one or a group of soft prompt parameters; or, an application scenario can correspond to one or a group of soft prompt parameters.
[0062] Correspondingly, the soft prompt parameter selection strategy may be to select soft prompt parameters corresponding to the task type or application scenario of the natural language processing task. In this case, the task type or application scenario of the natural language processing task to be executed may be determined first, and then the determined task type or application scenario may be used as a key to query the Value corresponding to the Key in the soft prompt parameter pool, and the soft prompt parameter represented by the queried Value may be used as the soft prompt parameter corresponding to the natural language processing task.
[0063] In practical applications, the soft prompt parameter selection strategy may also be to obtain manually selected soft prompt parameters corresponding to the natural language processing task. That is, the soft prompt parameters corresponding to the natural language processing task to be executed may also be selected manually from the soft prompt parameter pool.
[0064] It should be noted that the present application does not limit the specific content of the above-mentioned soft prompt parameter selection strategy.
[0065] In some embodiments, in order to ensure that the soft prompt parameters corresponding to the natural language processing task to be executed can be selected from the soft prompt parameter pool, and to avoid the problem that the soft prompt parameters corresponding to the natural language processing task cannot be determined due to the lack of suitable soft prompt parameters stored in the soft prompt parameter pool, one or a group of general soft prompt parameters can also be stored in the soft prompt parameter pool. In this case, for the natural language processing task for which the soft prompt parameters corresponding to it cannot be selected according to the soft prompt parameter selection strategy, the general soft prompt parameters in the soft prompt parameter pool can be used as the soft prompt parameters corresponding to the natural language processing task.
[0066] In practical applications, for a natural language processing task for which the corresponding soft prompt parameters cannot be selected according to the above soft prompt parameter selection strategy, a natural language text may be used as the initialized soft prompt parameters.
[0067] Step 204: Based on the fine-tuning sample data and the soft prompt parameters, generate fine-tuning prompt data corresponding to the natural language processing task, and input the fine-tuning prompt data into a language model, and the language model performs inference based on the fine-tuning prompt data to obtain an inference result corresponding to the fine-tuning prompt data.
[0068] In this embodiment, since the soft prompt parameters are a series of learnable parameters added to the model input, it is possible to generate prompt data (which may be referred to as fine-tuning prompt data) corresponding to the natural language processing task based on the fine-tuning sample data corresponding to the natural language processing task to be executed and the soft prompt parameters corresponding to the natural language processing task, and input the fine-tuning prompt data into the language model, and the language model performs inference based on the fine-tuning prompt data to obtain an inference result corresponding to the fine-tuning prompt data.
[0069] It should be noted that the above-mentioned language model at this time may refer to a pre-trained language model, and through this fine-tuning, the fine-tuned language model can perform the natural language processing task; or, the language model may also refer to a language model that has been fine-tuned, and through this fine-tuning, the language model is closer to the requirements of the natural language processing task and performs better on the natural language processing task.
[0070] In some embodiments, as mentioned above, the soft prompt parameters can be expressed as an embedding vector. In practical applications, the fine-tuning sample data is usually expressed as text data. In this case, the fine-tuning sample data can be first embedded to obtain an embedding vector corresponding to the fine-tuning sample data, and then the soft prompt parameters can be inserted into the embedding vector corresponding to the fine-tuning sample data. For example, the soft prompt parameters can be spliced before the embedding vector corresponding to the fine-tuning sample data to form a new vector with more dimensions, and the new vector is used as the embedding vector corresponding to the real prompt text, and input into the above-mentioned language model, so that the language model can perform reasoning based on the prompt text to obtain the corresponding reasoning result, and the reasoning result can be used as the reasoning result corresponding to the fine-tuning sample data.
[0071] In some embodiments, the soft prompt parameters may also be similar to the fine-tuning sample data, and both are expressed as text data. In this case, the soft prompt parameters and the fine-tuning sample data may be directly spliced, for example, the soft prompt parameters may be directly spliced before the fine-tuning sample data, and the spliced text data is used as the real prompt text and input into the language model, so that the language model can perform reasoning based on the prompt text to obtain the corresponding reasoning result, and the reasoning result can be used as the reasoning result corresponding to the fine-tuning sample data.
[0072] In some embodiments, prompt tuning may be used to adjust the above soft prompt parameters.
[0073] Prompt tuning is a machine learning technique used to improve the performance of language models on specific tasks. Its core idea is to guide the model to produce more accurate or more in-demand outputs by adjusting the textual prompts (i.e., prompts) input to the model without changing the parameters of the model itself, so that the model can better perform specific tasks. These textual prompts can include instructions, examples (Shots), contextual information, etc. Their purpose is to guide the model to respond in a certain way, such as generating a specific type of content, following a certain style, performing a certain task, etc.
[0074] Therefore, hint tuning is particularly suitable for large-scale language models with a large number of parameters, as fully fine-tuning these models can be very time-consuming and computationally demanding.
[0075] Hint tuning can be achieved through hard hint design, zero-shot learning, or few-shot learning.
[0076] Among them, hard prompt design refers to the manual design and writing of hard prompt text.
[0077] Zero-shot learning is asking a model to complete a task without providing any training data for that specific task. In this case, the design of hard hint text is crucial. Hard hint text usually contains a description of the task or contextual information so that the model can infer the correct behavior based on what it has learned during pre-training. For example, if the task is named entity recognition, the hard hint text may include a brief description of the task and some example sentences for the model to try to recognize the entity.
[0078] Few-shot learning refers to providing a few labeled examples as part of the hard prompt text. These examples usually contain the input and the corresponding correct output so that the model can learn the rules of the task by observing these examples. This method assumes that the model can quickly learn from a small number of examples and generalize to new, unseen data. For example, in a question-answering task, you can include a few pairs of questions and their correct answers in the hard prompt text, and then let the model answer new questions based on these examples.
[0079] In order to adjust the soft prompt parameters, small sample learning can be used as the basis. A hard prompt text can be first constructed based on the fine-tuning sample data, and the hard prompt text and the soft prompt parameters can be combined into the fine-tuning prompt data. The fine-tuning prompt data is then input into the language model. The language model performs reasoning based on the fine-tuning prompt data to obtain the reasoning result corresponding to the fine-tuning prompt data, and the objective function is optimized based on the reasoning result and the fine-tuning sample data to adjust the soft prompt parameters.
[0080] That is, when generating fine-tuning prompt data corresponding to the above-mentioned language model based on the above-mentioned fine-tuning sample data and the above-mentioned soft prompt parameters, it is possible to first generate a hard prompt text corresponding to the above-mentioned natural language processing task based on the fine-tuning sample data, and then generate fine-tuning prompt data corresponding to the natural language processing task based on the generated hard prompt text and the soft prompt parameters.
[0081] Specifically, the fine-tuning sample data may be labeled sample data, that is, the fine-tuning sample data may include sample content and sample labels. In this case, a hard prompt text may be constructed based on the sample content in the fine-tuning sample data, and the fine-tuning prompt data may be generated based on the hard prompt text and the soft prompt parameters, and then the fine-tuning prompt data may be input into the language model, and the language model may perform reasoning based on the fine-tuning prompt data to obtain a reasoning result corresponding to the fine-tuning prompt data. Subsequently, the loss may be calculated based on the loss function, the reasoning result, and the sample labels in the fine-tuning sample data, and the soft prompt parameters may be adjusted with the purpose of minimizing the loss.
[0082] In some embodiments, in order to improve the efficiency and effect of prompt tuning, the hard prompt text generated based on the fine-tuning sample data may have a unified data format. Specifically, when generating the hard prompt text corresponding to the above natural language processing task based on the fine-tuning prompt sample, the task type of the natural language processing task may be determined first, and then based on the fine-tuning sample data, the hard prompt text having a data format corresponding to the task type may be generated.
[0083] Taking the sentiment analysis task as an example, suppose there is a sentiment analysis task, the purpose of which is to let the model determine whether a text is positive or negative. If the above fine-tuning sample data is the text "The service in this restaurant is terrible", the hard prompt text "Please judge the sentiment tendency of the following comment: [input text]" can be generated according to the data format corresponding to sentiment analysis, "Please judge the sentiment tendency of the following comment: The service in this restaurant is terrible."
[0084] Taking the information extraction task as an example, suppose there is an information extraction task, the purpose of which is to let the model extract specific information from a text. If the above fine-tuning sample data is the text "Li Hua went to Beijing today", the hard prompt text "Please extract the geographic location from the following sentence: [input text]" can be generated according to the data format corresponding to sentiment analysis, "Please extract the geographic location from the following sentence: Li Hua went to Beijing today".
[0085] Step 206: Based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, the soft prompt parameters are adjusted to perform the natural language processing task based on the adjusted soft prompt parameters and the language model.
[0086] In this embodiment, when the inference result corresponding to the above-mentioned fine-tuning prompt data output by the above-mentioned language model is obtained, the soft prompt parameters corresponding to the above-mentioned natural language processing task can be adjusted based on the inference result and the optimization target corresponding to the language model. Among them, the optimization target can refer to optimizing the objective function; the objective function can be set according to actual needs and circumstances. For example, when the above-mentioned fine-tuning sample data is labeled sample data, the objective function can specifically be a loss function, and optimizing the loss function means minimizing the function value of the loss function.
[0087] It should be noted that after the adjustment of the soft prompt parameters is completed, the natural language processing task can be performed based on the adjusted soft prompt parameters and the language learning model. Specifically, similar to the process of adjusting the soft prompt parameters, a hard prompt text corresponding to the natural language processing task can be generated based on the task data corresponding to the natural language processing task and based on the task data, and then task prompt data corresponding to the natural language processing task can be generated based on the generated hard prompt text and the soft prompt parameters, and then the task prompt data can be input into the language model, and the language model can perform reasoning based on the task prompt data to obtain a reasoning result corresponding to the task prompt data.
[0088] In some embodiments, in order to avoid misoperation, during the process of adjusting the soft prompt parameters, the model parameters of the language model itself may be frozen to ensure that these model parameters are not adjusted.
[0089] In some embodiments, as described above, all soft prompt parameters can be maintained by a soft prompt parameter pool. In this case, after completing the adjustment of the above soft prompt parameters, it can be further determined whether it is necessary to update the soft prompt parameters stored in the soft prompt parameter pool to the adjusted soft prompt parameters.
[0090] Specifically, after adjusting the soft prompt parameters based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, it can be determined whether the adjusted soft prompt parameters can be used to update the soft prompt parameters originally stored in the soft prompt parameter pool. If it is determined that it can be updated, the soft prompt parameters originally stored in the soft prompt parameter pool can be updated to the adjusted soft prompt parameters based on the adjusted soft prompt parameters. In this case, the updated soft prompt parameters stored in the soft prompt parameter pool and the language model can be used to perform the natural language processing task.
[0091] In some embodiments, when determining whether the adjusted soft prompt parameters are used to update the soft prompt parameters in the soft prompt parameter pool, it can be specifically determined whether the degree of difference between the adjusted soft prompt parameters and the soft prompt parameters originally stored in the soft prompt parameter pool reaches a preset threshold. If the degree of difference reaches the threshold, it can be determined that the adjusted soft prompt parameters are used to update the soft prompt parameters in the soft prompt parameter pool.
[0092] In actual applications, in addition to determining whether the soft prompt parameter pool needs to be updated based on the degree of difference, other methods that meet actual needs may also be used to determine whether the soft prompt parameter pool needs to be updated, and this application does not impose any restrictions on this.
[0093] In some embodiments, in order to improve the adjustment efficiency and accuracy of soft prompt parameters, when creating the above-mentioned soft prompt parameter pool, the soft prompt parameters can be pre-trained first, and then the pre-trained soft prompt parameters can be stored in the soft prompt parameter pool. Subsequently, soft prompt parameters corresponding to a certain natural language processing task can be further selected from the soft prompt parameter pool, and the soft prompt parameters can be adjusted based on the fine-tuning sample data corresponding to this natural language processing task.
[0094] Specifically, when pre-training the soft prompt parameters, first, sample data corresponding to at least one natural language processing task (which may be referred to as pre-training sample data) may be obtained, and the initial soft prompt parameters corresponding to each natural language processing task may be determined. Among them, these initial soft prompt parameters may be randomly set. Then, for the initial soft prompt parameters corresponding to a natural language processing task, prompt data corresponding to the natural language processing task (which may be referred to as the first type of pre-training prompt data) may be generated based on the pre-training sample data and the initial soft prompt parameters, and the first type of pre-training prompt data may be input into the above-mentioned language model, and the language model may be inferred based on the first type of pre-training prompt data to obtain the inference result corresponding to the first type of pre-training prompt data, so that the initial soft prompt parameters corresponding to the natural language processing task may be adjusted based on the inference result corresponding to the first type of pre-training prompt data and the optimization target corresponding to the language model. After completing the adjustment of the initial soft prompt parameters corresponding to each natural language processing task, the adjusted initial soft prompt parameters may be stored in the above-mentioned soft prompt parameter pool as the soft prompt parameters corresponding to each natural language processing task.
[0095] In practical applications, the above pre-training sample data can come from a large amount of open source data.
[0096] In some embodiments, as described above, the above-mentioned soft prompt parameter pool may also store general prompt parameters. Similar to the above-mentioned content, the general prompt parameter may also be pre-trained. Specifically, the initial soft prompt parameter corresponding to the above-mentioned at least one natural language processing task may be determined. Then, based on the pre-training sample data and the initial soft prompt parameter, prompt data corresponding to these natural language processing tasks (which may be referred to as the second type of pre-training prompt data) may be generated, and the second type of pre-training prompt data may be input into the above-mentioned language model, and the language model may be inferred based on the second type of pre-training prompt data to obtain the inference result corresponding to the second type of pre-training prompt data, so that the initial soft prompt parameters corresponding to these natural language processing tasks may be adjusted based on the inference result corresponding to the second type of pre-training prompt data and the optimization target corresponding to the language model. After completing the adjustment of the initial soft prompt parameters corresponding to these natural language processing tasks, the adjusted initial soft prompt parameters may be stored in the soft prompt parameter pool as general soft prompt parameters.
[0097] In some embodiments, when the inference result output by the language model and the fine-tuning sample data, the pre-training sample data or the task data is obtained, data processing can be performed on the inference result based on a preset output processing strategy, and the processed inference result can be determined as a task execution result corresponding to the natural language processing task, so as to facilitate user viewing and analysis. For example, in a named entity recognition task, the entities output by the language model can be aggregated to obtain a result sorted in the order in which the entities appear in the input text.
[0098] In the above technical scheme, when fine-tuning sample data corresponding to a natural language processing task to be executed is obtained, the soft prompt parameters corresponding to the natural language processing task can be first obtained, and then based on the fine-tuning sample data and the soft prompt parameters, the fine-tuning prompt data corresponding to the natural language processing task is generated, and the fine-tuning prompt data is input into a language model, and the language model performs reasoning based on the fine-tuning prompt data to obtain the reasoning result corresponding to the fine-tuning prompt data, and finally, based on the reasoning result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, the soft prompt parameters are adjusted to execute the natural language processing task based on the adjusted soft prompt parameters and the language model.
[0099] By adopting the above method, by introducing soft prompt parameters, the introduced soft prompt parameters can be adjusted to achieve the effect of fine-tuning the language model, ensuring that the language model can better adapt to specific tasks or fields without directly fine-tuning the language model completely, so that the number of parameters that need to be fine-tuned can be reduced. Therefore, when the language model is applied to natural language processing, the natural language processing task can be performed efficiently and at low cost, and the execution accuracy of the natural language processing task can be guaranteed.
[0100] like Figure 3 As shown, Figure 3 It is a schematic diagram of a natural language processing process based on a language model shown in an exemplary embodiment of the present application.
[0101] like Figure 3 As shown, in the above process, first, the soft prompt parameter pre-training module can use the pre-training sample data to pre-train the initial soft prompt parameters corresponding to each natural language processing task, and store the pre-trained soft prompt parameters in the soft prompt parameter pool. Among them, the soft prompt parameters can be classified according to the task type of the natural language processing task.
[0102] Then, when fine-tuning sample data corresponding to the natural language processing task to be executed is obtained, the data preprocessing module can determine the task type of the natural language processing task, and the soft prompt parameter selection module can obtain the soft prompt parameters corresponding to the task type from the above-mentioned soft prompt parameter pool as the soft prompt parameters corresponding to the natural language processing task.
[0103] Then, based on the fine-tuning sample data and the soft prompt parameters, fine-tuning prompt data corresponding to the above-mentioned natural language processing task can be generated, and the fine-tuning prompt data can be input into the language model, and the language model can perform inference based on the fine-tuning prompt data to obtain an inference result corresponding to the fine-tuning prompt data.
[0104] Finally, the soft prompt parameter fine-tuning module can adjust the soft prompt parameter based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, and the soft prompt parameter updating module determines whether the adjusted soft prompt parameter can be used to update the soft prompt parameter in the soft prompt parameter pool, and if so, performs the update. Subsequently, the natural language processing task can be performed based on the soft prompt parameter stored in the soft prompt parameter pool and the language model.
[0105] In addition, the post-processing module may also perform data processing on the above-mentioned inference result based on a preset output processing strategy, and determine the processed inference result as the task execution result corresponding to the above-mentioned natural language processing task.
[0106] Corresponding to the aforementioned method embodiments, the present application also provides device embodiments.
[0107] Please refer to Figure 4 , Figure 4 It is a structural diagram of a device shown in an exemplary embodiment of the present application. At the hardware level, the device includes a processor 402, an internal bus 404, a network interface 406, a memory 408 and a non-volatile memory 410, and of course may also include other required hardware. One or more embodiments of the present application can be implemented based on software, such as the processor 402 reading the corresponding computer program from the non-volatile memory 410 into the memory 408 and then running it. Of course, in addition to the software implementation, one or more embodiments of the present application do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic module, but can also be hardware or logic devices.
[0108] Please refer to Figure 5 , Figure 5 It is a block diagram of a natural language processing device based on a language model shown as an exemplary embodiment of the present application.
[0109] The above-mentioned natural language processing device based on language model can be applied to Figure 4 The device shown is used to implement the technical solution of the present application. The device includes:
[0110] An acquisition module 502 acquires fine-tuning sample data corresponding to a natural language processing task to be performed, and acquires soft prompt parameters corresponding to the natural language processing task;
[0111] The reasoning module 504 generates fine-tuning prompt data corresponding to the natural language processing task based on the fine-tuning sample data and the soft prompt parameters, and inputs the fine-tuning prompt data into a language model, and the language model performs reasoning based on the fine-tuning prompt data to obtain a reasoning result corresponding to the fine-tuning prompt data;
[0112] The adjustment module 506 adjusts the soft prompt parameters based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, so as to perform the natural language processing task based on the adjusted soft prompt parameters and the language model.
[0113] In some embodiments, the generating, based on the fine-tuning sample data and the soft prompt parameter, fine-tuning prompt data corresponding to the language model includes:
[0114] Based on the fine-tuning sample data, hard prompt text corresponding to the natural language processing task is generated, and based on the hard prompt text and the soft prompt parameters, fine-tuning prompt data corresponding to the language model is generated.
[0115] In some embodiments, generating hard prompt text corresponding to the natural language processing task based on the fine-tuning sample data includes:
[0116] The task type of the natural language processing task is determined, and based on the fine-tuning sample data, a hard prompt text having a data format corresponding to the task type is generated.
[0117] In some embodiments, the obtaining of soft prompt parameters corresponding to the natural language processing task includes:
[0118] Based on a preset soft prompt parameter selection strategy, a soft prompt parameter corresponding to the natural language processing task is selected from a soft prompt parameter pool.
[0119] In some embodiments, the adjusting the soft prompt parameters based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, so as to perform the natural language processing task based on the adjusted soft prompt parameters and the language model, includes:
[0120] Based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, adjusting the soft prompt parameter, and determining whether the adjusted soft prompt parameter is used to update the soft prompt parameter in the soft prompt parameter pool;
[0121] If yes, the soft prompt parameters in the soft prompt parameter pool are updated based on the adjusted soft prompt parameters, so as to perform the natural language processing task based on the updated soft prompt parameters in the soft prompt parameter pool and the language model.
[0122] In some embodiments, determining whether the adjusted soft prompt parameter is used to update the soft prompt parameter in the soft prompt parameter pool includes:
[0123] Determining whether a difference between the adjusted soft prompt parameter and the soft prompt parameter in the soft prompt parameter pool reaches a preset threshold;
[0124] If yes, it is determined that the adjusted soft prompt parameter is used to update the soft prompt parameter in the soft prompt parameter pool.
[0125] In some embodiments, the apparatus further comprises:
[0126] A second acquisition module acquires pre-training sample data corresponding to at least one natural language processing task, and determines initial soft prompt parameters corresponding to each natural language processing task;
[0127] A second reasoning module generates first-type pre-training prompt data corresponding to each natural language processing task based on the pre-training sample data and the initial soft prompt parameters, and inputs the first-type pre-training prompt data into the language model, and the language model performs reasoning based on the first-type pre-training prompt data to obtain a reasoning result corresponding to the first-type pre-training prompt data;
[0128] a second adjustment module, adjusting initial soft prompt parameters corresponding to each natural language processing task based on the inference result corresponding to the first type of pre-trained prompt data and the optimization target corresponding to the language model;
[0129] The storage module stores the adjusted initial soft prompt parameters as soft prompt parameters corresponding to each natural language processing task in the soft prompt parameter pool.
[0130] In some embodiments:
[0131] The second acquisition module is further used to determine initial soft prompt parameters corresponding to the at least one natural language processing task;
[0132] The second reasoning module is further used to generate a second type of pre-training prompt data corresponding to the at least one natural language processing task based on the pre-training sample data and the initial soft prompt parameters, and input the second type of pre-training prompt data into the language model, so that the language model performs reasoning based on the second type of pre-training prompt data to obtain a reasoning result corresponding to the second type of pre-training prompt data;
[0133] The second adjustment module is further used to adjust the initial soft prompt parameters corresponding to the at least one natural language processing task based on the inference result corresponding to the second type of pre-trained prompt data and the optimization target corresponding to the language model;
[0134] The storage module is further configured to store the adjusted initial soft prompt parameters as general soft prompt parameters in the soft prompt parameter pool.
[0135] In some embodiments, the apparatus further comprises:
[0136] The processing module performs data processing on the inference result based on a preset output processing strategy, and determines the processed inference result as a task execution result corresponding to the natural language processing task.
[0137] For the device embodiment, it basically corresponds to the method embodiment, so the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the technical solution of the present application.
[0138] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0139] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0140] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0141] Computer-readable media include permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0142] It should be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of further restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0143] The above specific embodiments of the present application are described. Other embodiments are within the scope of the present application. In some cases, the actions or steps recorded in the present application can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the process depicted in the accompanying drawings does not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0144] The terms used in one or more embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present application. The singular forms of "a", "said" and "the" are also intended to include plural forms, unless the context clearly indicates other meanings. The term "and / or" refers to and includes any or all possible combinations of one or more associated listed items.
[0145] The description of the terms "one embodiment", "some embodiments", "example", "specific example" or "an implementation method" etc. used in one or more embodiments of the present application means that the specific features or characteristics described in conjunction with the embodiment are included in at least one embodiment of the present application. The schematic description of these terms is not necessarily for the same embodiment. Moreover, the specific features or characteristics described can be combined in a suitable manner in one or more embodiments of the present application. In addition, different embodiments and specific features or characteristics in different embodiments can be combined without contradicting each other.
[0146] It should be understood that, although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of the present application, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determination".
[0147] The above description is merely a preferred embodiment of one or more embodiments of the present application and is not intended to limit one or more embodiments of the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present application shall be included in the scope of protection of one or more embodiments of the present application.
[0148] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
Claims
1. A natural language processing method based on a language model, the method comprising: Acquire fine-tuning sample data corresponding to a natural language processing task to be performed, and acquire soft prompt parameters corresponding to the natural language processing task; Based on the fine-tuning sample data and the soft prompt parameters, fine-tuning prompt data corresponding to the natural language processing task is generated, and the fine-tuning prompt data is input into a language model, and the language model performs reasoning based on the fine-tuning prompt data to obtain a reasoning result corresponding to the fine-tuning prompt data; Based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, the soft prompt parameters are adjusted to perform the natural language processing task based on the adjusted soft prompt parameters and the language model.
2. The method according to claim 1, wherein generating fine-tuning prompt data corresponding to the language model based on the fine-tuning sample data and the soft prompt parameters comprises: Based on the fine-tuning sample data, hard prompt text corresponding to the natural language processing task is generated, and based on the hard prompt text and the soft prompt parameters, fine-tuning prompt data corresponding to the language model is generated.
3. The method according to claim 2, wherein generating hard prompt text corresponding to the natural language processing task based on the fine-tuning sample data comprises: The task type of the natural language processing task is determined, and based on the fine-tuning sample data, a hard prompt text having a data format corresponding to the task type is generated.
4. According to the method of claim 1, the obtaining of soft prompt parameters corresponding to the natural language processing task comprises: Based on a preset soft prompt parameter selection strategy, a soft prompt parameter corresponding to the natural language processing task is selected from a soft prompt parameter pool.
5. The method according to claim 4, wherein the soft prompt parameters are adjusted based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, so as to perform the natural language processing task based on the adjusted soft prompt parameters and the language model, comprising: Based on the inference result corresponding to the fine-tuning prompt data and the optimization target corresponding to the language model, adjusting the soft prompt parameter, and determining whether the adjusted soft prompt parameter is used to update the soft prompt parameter in the soft prompt parameter pool; If yes, the soft prompt parameters in the soft prompt parameter pool are updated based on the adjusted soft prompt parameters, so as to perform the natural language processing task based on the updated soft prompt parameters in the soft prompt parameter pool and the language model.
6. The method according to claim 5, wherein determining whether the adjusted soft prompt parameter is used to update the soft prompt parameter in the soft prompt parameter pool comprises: Determining whether a difference between the adjusted soft prompt parameter and the soft prompt parameter in the soft prompt parameter pool reaches a preset threshold; If yes, it is determined that the adjusted soft prompt parameter is used to update the soft prompt parameter in the soft prompt parameter pool.
7. The method according to claim 4, further comprising: Acquire pre-training sample data corresponding to at least one natural language processing task, and determine initial soft prompt parameters corresponding to each natural language processing task; Based on the pre-training sample data and the initial soft prompt parameters, generating first-type pre-training prompt data corresponding to each natural language processing task, and inputting the first-type pre-training prompt data into the language model, so that the language model performs inference based on the first-type pre-training prompt data to obtain an inference result corresponding to the first-type pre-training prompt data; Adjusting initial soft prompt parameters corresponding to each natural language processing task based on the inference result corresponding to the first type of pre-trained prompt data and the optimization target corresponding to the language model; The adjusted initial soft prompt parameters are used as soft prompt parameters corresponding to each natural language processing task and stored in the soft prompt parameter pool.
8. The method according to claim 7, further comprising: determining initial soft prompt parameters corresponding to the at least one natural language processing task; Based on the pre-training sample data and the initial soft prompt parameters, generating second-type pre-training prompt data corresponding to the at least one natural language processing task, and inputting the second-type pre-training prompt data into the language model, so that the language model performs inference based on the second-type pre-training prompt data to obtain an inference result corresponding to the second-type pre-training prompt data; adjusting initial soft prompt parameters corresponding to the at least one natural language processing task based on an inference result corresponding to the second type of pre-trained prompt data and an optimization target corresponding to the language model; The adjusted initial soft prompt parameters are used as general soft prompt parameters and stored in the soft prompt parameter pool.
9. The method according to claim 1, further comprising: Based on a preset output processing strategy, data processing is performed on the inference result, and the processed inference result is determined as a task execution result corresponding to the natural language processing task.
10. A natural language processing device based on a language model, the device comprising: An acquisition module is used to acquire fine-tuning sample data corresponding to a natural language processing task to be performed, and to acquire soft prompt parameters corresponding to the natural language processing task; An inference module, which generates fine-tuning prompt data corresponding to the natural language processing task based on the fine-tuning sample data and the soft prompt parameters, and inputs the fine-tuning prompt data into a language model, and the language model performs inference based on the fine-tuning prompt data to obtain an inference result corresponding to the fine-tuning prompt data; An adjustment module adjusts the soft prompt parameters based on an inference result corresponding to the fine-tuning prompt data and an optimization target corresponding to the language model, so as to perform the natural language processing task based on the adjusted soft prompt parameters and the language model.
11. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 9 by running the executable instructions.
12. A computer-readable storage medium having computer instructions stored thereon, wherein the instructions are executed by a processor to implement the method according to any one of claims 1 to 9.
Citation Information
Cited By
Interactive code generation method and system and storage medium
CN120276720A