Prompt learning method and related device
Optimizing prompt parameters through parallel corpus and prompt conversion modules solves the problem of poor target language task processing performance in cross-language transfer and achieves more efficient language understanding and processing performance.
Patent Information
- Application Number
- PCT/CN2024/070338
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-20
- Filing Date
- 2024-01-03
- Publication Date
- 2024-10-24
AI Technical Summary
During the cross-language transfer process, existing cue learning methods use the same source language-based cues, resulting in poor task processing performance in the target language and inability to effectively capture the characteristics of the target language, resulting in performance loss after cross-language transfer.
By obtaining parallel corpus, adjusting the pre-trained language model and prompt parameters to better align the source language and target language, using continuous prompts and prompt conversion modules, optimizing prompt parameters to reduce language representation differences and achieve more accurate goals Language understanding.
It improves the processing performance after cross-language migration, enhances the pre-trained language model's ability to understand the target language, improves the accuracy of downstream tasks, and alleviates the performance loss caused by differences in language representation.
Smart Images

Figure CN2024070338_24102024_PF_FP_ABST
Abstract
Description
A prompt learning method and related equipment
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on April 20, 2023, with application number CN202310429346.2 and invention name “A prompt learning method and related equipment”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the technical field of natural language processing, and in particular to a prompt learning method and related equipment. Background Art
[0003] With the advancement of globalization, users often desire cross-language applications in real-world language processing scenarios. To this end, various large-scale pre-trained language models have been widely used in natural language processing. Language models pre-trained on large multilingual datasets acquire multilingual knowledge and possess excellent transfer learning capabilities.
[0004] Currently, one method of cross-language transfer is a cross-language transfer learning method based on prompt learning.
[0005] In prompt learning, without significantly changing the structure and parameters of the pre-trained language model, the downstream task can be reformulated by adding "prompt information" to the input data, making its form close to the pre-training stage, reducing the gap between the pre-trained task and the downstream task, thereby reducing the demand for downstream task data and enabling the pre-trained language model to better solve downstream tasks.
[0006] However, in cross-language transfer, the current prompt learning method uses the same source language-based prompts for various target languages. Using the source language-based prompts is not conducive to the cross-language transfer of the pre-trained language model, resulting in poor processing performance of the target language tasks after cross-language transfer.
[0007] Summary of the Invention
[0008] This application provides a prompt learning method to solve the problem of poor task processing performance in the target language after cross-language transfer. This application also provides corresponding devices, equipment, computer-readable storage media, and computer program products.
[0009] The first aspect of the present application provides a prompt learning method, which includes: obtaining at least one set of data pairs, any one set of data pairs including first data and second data, the first data including a first prompt and a first corpus in a source language, the second data including a second prompt and a second corpus in a target language, the first corpus and the second corpus forming a pair of parallel corpora; performing prompt learning based on the at least one set of data pairs and a pre-trained language model, so that the pre-trained language model after training can perform a natural language processing task based on the target language according to the second prompt after training, the pre-trained language model being obtained by pre-training based on training data in the source language and training data in the target language.
[0010] In the first aspect, the ability of a pre-trained language model to process natural language processing tasks based on the source language is generally better than its ability to process natural language processing tasks based on the target language. During the training process, parameters such as the pre-trained language model and / or the second prompt can be adjusted based on data pairs constructed from parallel corpora, so that the trained pre-trained language model and / or the trained second prompt can align the source language and the target language, so as to better learn the knowledge of the target language, thereby achieving cross-language transfer, so that the trained pre-trained language model can more accurately perform natural language processing tasks based on the target language based on the trained second prompt, thereby alleviating the performance loss caused by the differences in language representation during the cross-language transfer process, so that the trained pre-trained language model has better cross-language understanding capabilities when performing downstream tasks such as natural language processing tasks based on the target language based on the trained second prompt, thereby improving the accuracy when performing related downstream tasks.
[0011] In a possible implementation manner of the first aspect, the first prompt and the second prompt are consecutive prompts.
[0012] Currently, when performing cross-language transfer through prompt learning, traditional solutions use discrete prompts, and the same source language (e.g., English) prompt templates and prompts are applied to all target languages. This approach makes it difficult to capture target language-specific features in natural language processing tasks. In addition, discrete prompts are mainly based on manual experience, which can also have an adverse effect on the performance after cross-language transfer.
[0013] In this possible implementation, the first prompt and the second prompt are both continuous prompts. In this case, the prompt parameters in the first prompt may include a first tensor whose length and content can be learned, and the prompt parameters in the second prompt may also include a second tensor whose length and content can be learned.
[0014] In this way, there is no need to manually design the first and second prompts. Instead, the learnable first and second prompts can be optimized during the training process, and better prompt parameters can be found in a space outside the manually constructed vocabulary of the pre-trained language model, thereby improving the processing performance after cross-language transfer.
[0015] In a possible implementation of the first aspect, the first data includes a first mask, the second data includes a second mask, and the prompt learning includes multiple iterative processes; prompt learning is performed based on at least one set of data and a pre-trained language model, including: in the Nth iteration of the multiple iterative processes: inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process regarding the first mask of the Nth iteration process, and a second output result regarding the second mask of the Nth iteration process, where N is a positive integer; updating the first prompt of the Nth iteration process and the second prompt of the Nth iteration process according to the first output result, the second output result, and a first loss function, where the first loss function is used to evaluate the difference between the probability space of the first output result and the probability space of the second output result.
[0016] In this possible implementation, for example, a Kullback-Leibler divergence loss (KLD loss) between the first output result and the second output result can be calculated and regularized using a first loss function to obtain a first loss value. Then, the first prompt of the Nth iteration process and the second prompt of the Nth iteration process can be updated based on the first loss value to make the probability distribution corresponding to the first output result and the probability distribution corresponding to the second output result as close as possible, thereby aligning the source language and the target language. This helps the pre-trained language model after training better understand the data in the target language based on the second prompt after training, thereby facilitating the execution of tasks related to the target language.
[0017] In a possible implementation manner of the first aspect, the second prompt is obtained by converting the first prompt through a prompt conversion module.
[0018] In this possible implementation, the prompt conversion module can be used to implement the conversion between the first prompt and the second prompt, thereby reducing the differences in language representation between different languages.
[0019] In prompt learning, the first prompt, the second prompt, and the prompt conversion module can all be adjusted in parameters based on data pairs including parallel corpora, so that the trained prompt conversion module can align the prompts of the source language and the target language, reducing the differences in language representation between different languages, so that the trained second prompt can better represent the information of the target language, which is conducive to the execution of natural language processing tasks based on the target language.
[0020] In a possible implementation of the first aspect, the first data includes a first mask, the second data includes a second mask, and the prompt learning includes multiple iterative processes; prompt learning is performed based on at least one set of data and a pre-trained language model, including: in the Nth iteration of the multiple iterative processes: inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process with respect to the first mask of the Nth iteration process, and a second output result with respect to the second mask of the Nth iteration process, where N is a positive integer; updating a first prompt of the Nth iteration process and a prompt conversion module of the Nth iteration process based on the first output result and the second output result; and converting the updated first prompt of the Nth iteration process through the prompt conversion module updated in the Nth iteration process to obtain an updated second prompt of the Nth iteration process.
[0021] In this possible implementation, the first prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process can be updated according to the first output result and the second output result, so that the probability distribution corresponding to the first output result and the probability distribution corresponding to the second output result are as close as possible, thereby reducing the difference in language representation, which is beneficial for the pre-trained language model after training to understand the data in the target language according to the second prompt after training, thereby facilitating the execution of tasks related to the target language.
[0022] In a possible implementation of the first aspect, the first data of the Nth iteration process corresponds to a first label; prompt learning is performed based on at least one set of data and a pre-trained language model, including: updating the first prompt of the Nth iteration process and / or the pre-trained language model of the Nth iteration process based on the first output result, the second output result, the first label corresponding to the first data of the Nth iteration process, and a second loss function, wherein the second loss function is used to evaluate the difference between the first output result and the first label corresponding to the first data of the Nth iteration process.
[0023] In this possible implementation, in prompt learning, training can be performed based on the difference between the first label corresponding to the first data and the first output result corresponding to the first data, so that the difference tends to decrease, so that the pre-trained language model after training can more accurately perform natural language processing tasks based on the source language according to the first prompt after training, thereby improving the processing performance of natural language processing tasks on the source language.
[0024] On this basis, by using at least one set of data pairs containing parallel corpora, the superior processing performance of the pre-trained language model for natural language processing tasks in the source language can be well transferred to natural language processing tasks in the target language, thereby reducing the negative impact of differences in language representation.
[0025] In a possible implementation of the first aspect, the method further includes: obtaining third data and a second label corresponding to the third data, the third data including a third prompt, a third mask, and a third corpus in a source language; performing prompt learning on a pre-trained language model based on at least one set of data, including: inputting the third data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a third output result of the pre-trained language model of the Nth iteration process regarding the third mask of the Nth iteration process; and updating the first prompt of the Nth iteration process, the second prompt of the Nth iteration process, and / or the pre-trained language model of the Nth iteration process based on the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process.
[0026] In this possible implementation, in prompt learning, the input data includes not only data pairs including parallel corpora and continuous prompts, but also third data as labeled data.
[0027] In this way, training can be carried out based on a variety of data with relatively rich data information, so that the processing performance of the natural language processing task of the source language and the processing performance after cross-language migration from the source language to the target language are comprehensively improved. After cross-language migration, the pre-trained language model can accurately perform natural language processing tasks based on the target language according to the second prompt after training.
[0028] In a possible implementation of the first aspect, the third prompt is a discrete prompt; and the first prompt of the N-th iterative process and the second prompt of the N-th iterative process, and / or the pre-trained language model of the N-th iterative process are updated according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the N-th iterative process, including: updating the pre-trained language model of the N-th iterative process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the N-th iterative process; and updating the first prompt of the N-th iterative process and the second prompt of the N-th iterative process according to the first output result and the second output result.
[0029] In a possible implementation of the first aspect, the third prompt is a continuous prompt; the second prompt is obtained by converting the first prompt through a prompt conversion module; according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the N-th iteration process, the first prompt of the N-th iteration process and the second prompt of the N-th iteration process, and / or, the pre-trained language model of the N-th iteration process are updated, including: according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the N-th iteration process, the third prompt of the N-th iteration process and the prompt conversion module of the N-th iteration process are updated; and the updated third prompt in the N-th iteration process is used as the updated first prompt in the N-th iteration process.
[0030] A second aspect of the present application provides a prompt learning device that has the function of implementing the method of the first aspect or any possible implementation of the first aspect. This function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-mentioned functions, such as an acquisition module and a training module.
[0031] A third aspect of the present application provides a computing device cluster, which includes at least one computing device, each computing device including a processor and a memory, and the memory of at least one computing device stores computer execution instructions that can be run on the processor. When the computer execution instructions are executed by the processor, the processor executes the method as described in the first aspect or any possible implementation of the first aspect.
[0032] In a fourth aspect, the present application provides a computer-readable storage medium storing one or more computer-executable instructions. When the computer-executable instructions are executed by a computing device cluster, the computing device cluster executes the method as described in the first aspect or any possible implementation of the first aspect.
[0033] In a fifth aspect, the present application provides a computer program product storing one or more computer-executable instructions. The computer program product includes computer-executable instructions. When the computer-executable instructions are executed by a computing device cluster, the computing device cluster executes the method as described in the first aspect or any possible implementation of the first aspect.
[0034] A sixth aspect of the present application provides a chip system, which includes a processor for supporting a computing device cluster to implement the functions involved in the first aspect or any possible implementation of the first aspect. In one possible design, the chip system may also include a memory for storing necessary program instructions and data. The chip system may be composed of a chip or may include a chip and other discrete devices.
[0035] Among them, the technical effects brought about by the second to sixth aspects or any possible implementation methods thereof can refer to the technical effects brought about by the first aspect or the relevant possible implementation methods of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] FIG1 is an exemplary schematic diagram of a data center provided in an embodiment of the present application;
[0037] FIG2 is a schematic diagram of an embodiment of a prompt learning method provided in an embodiment of the present application;
[0038] FIG3 is an exemplary schematic diagram of a data pair provided in an embodiment of the present application;
[0039] FIG4 is an exemplary schematic diagram of a first prompt, a second prompt, and a prompt conversion module provided in an embodiment of the present application;
[0040] FIG5 is an exemplary schematic diagram of a training method provided in an embodiment of the present application;
[0041] FIG6 is an exemplary schematic diagram of a training method provided in an embodiment of the present application;
[0042] FIG7 a is an exemplary schematic diagram of a training method provided in an embodiment of the present application;
[0043] FIG7 b is an exemplary schematic diagram of a training method provided in an embodiment of the present application;
[0044] FIG8 is a schematic diagram of an embodiment of a prompt learning device provided in an embodiment of the present application;
[0045] FIG9 is a schematic diagram of a structure of a computing device provided in an embodiment of the present application;
[0046] FIG10 is a schematic diagram of a structure of a computing device cluster provided in an embodiment of the present application;
[0047] FIG11 is another structural diagram of a computing device cluster provided in an embodiment of the present application. DETAILED DESCRIPTION
[0048] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0049] In this application, "at least one" means one or more, and "more" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate. This is merely a way of distinguishing objects with the same properties when describing them in the embodiments of this application. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a list of elements is not necessarily limited to those elements but may include other elements not expressly listed or inherent to such process, method, product, or apparatus.
[0050] Natural language processing (NLP) is a key area of research in computer science and artificial intelligence. Natural language processing tasks encompass two broad areas: natural language understanding (NLU) and natural language generation (NLG). NLU requires understanding the meaning of natural language text, while NLG requires expressing intended meanings and ideas in natural language text.
[0051] In recent years, machine learning models have achieved exciting results in these two categories of tasks. However, during the corresponding training process, machine learning models usually require a certain amount of labeled data, which is not conducive to their application in multilingual scenarios.
[0052] Specifically, in actual scenarios, only a few high-resource languages have sufficient annotated data (such as English), but it is difficult to collect a large amount of annotated data for low-resource languages such as Urdu.
[0053] However, with the advancement of globalization, users often desire cross-language applications in real-world language processing scenarios. For example, in search engines, users want to be able to search for information not only in Chinese but also in English, and even in more languages. However, in actual development, training a language model for each language would be extremely labor-intensive, making both development and application difficult.
[0054] To this end, various large-scale pretrained language models (PLMs) have been widely used in the field of natural language processing. Language models pretrained on large multilingual datasets can solve the problem of designing a class of language models for each language.
[0055] Through pre-training tasks, this language model learns multilingual knowledge and possesses excellent transfer learning capabilities. Cross-lingual transfer can leverage high-resource source languages to improve the accuracy of low-resource target languages, thereby addressing resource shortages in low-resource languages. It is an important tool for improving natural language processing performance in low-resource language scenarios.
[0056] One approach to cross-lingual transfer is the pre-training and fine-tuning method. In this method, a language model can be pre-trained using a dataset covering multiple languages (where the training samples for each language are generally unrelated). When applied to a specific downstream task, the pre-trained language model (hereinafter referred to as the pre-trained language model) is fine-tuned based solely on the English dataset for that task. It can then be directly tested on the other language for that task (also called the target language). Word embeddings enable effective cross-lingual alignment, allowing the fine-tuned language model to perform downstream tasks in the target language.
[0057] Another cross-language transfer method is the cross-language transfer learning method based on prompt learning.
[0058] In prompt learning, without significantly changing the structure and parameters of the pre-trained language model, the downstream task can be reformulated by adding "prompt information" to the input data, making its form close to the pre-training stage, reducing the gap between the pre-trained task and the downstream task, thereby reducing the demand for downstream task data and enabling the pre-trained language model to better solve downstream tasks.
[0059] Currently, a commonly used prompt learning method is to fill the input sentence into a prompt template containing fixed prompt parameters, converting the corresponding natural language processing task (such as classification task, etc.) into a masked language modeling task to stimulate the knowledge learned by the pre-trained language model during pre-training. This prompt learning method is called discrete prompt (hard prompt).
[0060] The subsequent soft prompt replaces the prompt parameters in the meaningful prompt template with learnable vectors. During the subsequent prompt learning process, only the prompt parameters need to be trained, while the language model remains fixed, significantly reducing the number of learnable parameters. Because the pre-trained language model inherently has cross-lingual capabilities, fixing the model parameters during training and only fine-tuning the prompt parameters preserves the pre-trained language model's inherent multilingual capabilities while enabling the prompt parameters to learn the capabilities of downstream tasks.
[0061] However, in cross-language transfer, the current prompt learning method uses the same source language-based prompts for various target languages. Using the source language-based prompts is not conducive to the cross-language transfer of the pre-trained language model, resulting in poor processing performance of the target language tasks after cross-language transfer.
[0062] Based on this, an embodiment of the present application provides a prompt learning method to solve the problem of poor task processing performance corresponding to the target language after cross-language transfer.
[0063] The method of the embodiment of the present application can be applied to a computing device cluster, which may include one or more computing devices.
[0064] The type of any computing device is not limited herein. For example, any computing device may be a terminal device, or a server, a container, or a virtual machine.
[0065] In one example, the computing device cluster can be used to implement a cloud platform. In this case, the embodiments of the present application can be applied to the cloud platform.
[0066] The cloud platform can provide computing, network and storage capabilities based on services of hardware resources and software resources. Exemplarily, the cloud platform can include one or more data centers to provide cloud resources through one or more data centers.
[0067] The following describes a data center with reference to an architecture diagram shown in FIG1 .
[0068] In Figure 1, in the data center, the cloud management platform exchanges information with one or more servers (such as server 1 and server 2 in Figure 1) through the data center's internal network. The server includes a hardware layer and a software layer. The hardware layer includes the hardware configured on the server, where PCI devices can be, for example, network cards, graphics processing units (GPUs), offload cards, and other devices that can be plugged into the server's peripheral component interconnect (PCI) or peripheral component interconnect express (PCIe) slots. The software layer includes an operating system installed and running on the server (relative to the virtual machine's operating system, it can be called a host operating system). The host operating system is equipped with a virtual machine manager (also known as a hypervisor). The role of the virtual machine manager is to implement computing virtualization, network virtualization, and storage virtualization of the virtual machine, and to manage the virtual machine. Among them, a virtual machine refers to a complete computer system with complete hardware system functions simulated by software and running in a completely isolated environment. In the system architecture shown in Figure 1, a data center is equipped with multiple servers, which can be used to run virtual machines. The specifications of each virtual machine can be the same or different. Among them, virtual machines can also be called cloud servers (elastic compute services, ECS), elastic instances, etc. Different cloud service providers may have different names.
[0069] In one example of an embodiment of the present application, the cloud platform may be a public cloud platform. In this case, cloud service providers such as individuals or software developers with cloud resource development capabilities can provide cloud services to users. Users obtain cloud services through the Internet but do not own cloud computing resources.
[0070] Specifically, in the example shown in Figure 1, the cloud management platform can provide an access interface (such as an interface or application programming interface (API)). Users of the cloud platform and cloud service providers can operate the client remote access access interface to register a cloud account and password on the cloud management platform, and after the cloud management platform successfully authenticates the cloud account and password, log in to the cloud management platform, thereby creating, managing, logging in and operating virtual machines in the cloud data center.
[0071] For example, when it is necessary to perform training tasks on machine learning models such as natural language models, some enterprises, organizations or individuals can purchase cloud services to perform related training tasks through the cloud resources of the cloud platform. After the training is completed, they can obtain the trained machine learning model and other parameters from the cloud platform (for example, in the prompt learning scenario, the prompt parameters of continuous prompts can be obtained after training), so as to perform subsequent model deployment and related reasoning tasks.
[0072] Of course, the cloud platform may also be other types of cloud platforms, which is not limited in the embodiments of the present application.
[0073] Based on the computing device cluster described above, as shown in FIG2 , the prompt learning method may include steps 201 - 202 .
[0074] Step 201: Obtain at least one set of data pairs.
[0075] Any set of data pairs includes first data and second data, the first data includes a first prompt and a first corpus in a source language, the second data includes a second prompt and a second corpus in a target language, and the first corpus and the second corpus form a pair of parallel corpora.
[0076] In the embodiment of the present application, different data pairs may contain different data. The following takes any set of data pairs as an example to exemplify the training method of the embodiment of the present application.
[0077] In the embodiment of the present application, any data pair includes first data and second data, and the first corpus in the first data and the second corpus in the second data constitute a set of parallel corpora.
[0078] Parallel texts refer to texts written in different languages that have a "translation relationship" with each other. In other words, the first and second texts have the same semantics but are written in different languages.
[0079] There are many ways to obtain each set of parallel corpora.
[0080] For example, in one example, multiple sets of parallel corpora are obtained from a third-party parallel corpus.
[0081] Alternatively, in another example, multiple first corpora may be obtained, and then each first corpus may be translated into a corresponding second corpus in the target language, thereby combining a first corpus and the second corpus corresponding to the first corpus into a set of parallel corpora.
[0082] The specific types of source and target languages are not limited here.
[0083] In some examples, the source language may be a high-resource language, such as English. Low-resource languages have more abundant resources, such as labeled data. The target language may be a low-resource language, such as Urdu or Arabic, which has fewer resources for labeled data.
[0084] In this example, data pairs of a high-resource source language and a low-resource target language can be constructed. In this way, in subsequent training, cross-language transfer can be achieved through the data pairs, thereby utilizing the resources of the high-resource source language to improve the processing performance of the pre-trained language model for related tasks in the low-resource target language.
[0085] In addition, in some examples, the first data and the second data may each include a mask. For example, the first data may include a first mask, and the second data may include a second mask, so that in prompt learning, the corresponding mask part can be predicted by the pre-trained language model, and the corresponding parameters can be updated based on the prediction results of each mask.
[0086] In addition, the first data of the data pair also includes a first prompt, and the second data of the data pair also includes a second prompt.
[0087] The specific types of the first prompt and the second prompt are not limited here.
[0088] In one example, the first prompt and the second prompt may be consecutive prompts.
[0089] The first hint may include a first tensor that can be learned in the hint learning, and the second hint may include a second tensor that can be learned in the hint learning. The weight and / or size of the first tensor, as well as the weight and / or size of the second tensor, can be updated and adjusted in the hint learning. In this case, the hint parameters may include the weight value of the corresponding tensor and / or the size of the corresponding tensor.
[0090] In addition, in some examples, the conversion between the first prompt and the second prompt can be achieved through a prompt conversion module.
[0091] Specifically, in this example, the second prompt is obtained by converting the first prompt through the prompt conversion module.
[0092] In this example, the prompt conversion module can convert a first prompt based on the source language into a second prompt based on the target language. That is, it can convert the prompt information in the source language into the prompt information in the target language to alleviate the performance loss caused by the differences in language representation during cross-language migration.
[0093] The specific structure of the prompt conversion module is not limited here. Exemplarily, the prompt conversion module may include a two-layer multilayer perceptron (MLP).
[0094] In this example, the prompt conversion module is also a machine learning model. In this case, the prompt conversion module can also perform parameter updates based on subsequent prompt learning.
[0095] For the prompt learning related to the prompt conversion module, please refer to the embodiments related to Figures 5 to 7b, which will not be described in detail here.
[0096] In other examples, the first prompt and the second prompt may also be discrete prompts, that is, the first prompt and the second prompt are fixed prompt parameters obtained based on human experience.
[0097] There are many ways to obtain data pairs.
[0098] In one example, multiple sets of parallel corpora may be obtained from a third-party parallel corpus, and multiple sets of data pairs may be constructed based on the multiple sets of parallel corpora and preset templates.
[0099] The form of the preset template corresponding to the data pair may be determined based on the type of natural language processing task to be performed during a specific application process.
[0100] Exemplarily, the preset template may include the location of the corresponding corpus, the location of the prompt parameter, and the location of the mask.
[0101] The following example illustrates how to construct and what the data pair contains.
[0102] In one example, the natural language processing task to be transferred across languages is a relational reasoning task. In the relational reasoning task, a sentence pair can be input, and a pre-trained language model can be used to determine which of the three relationships (implication, contradiction, or irrelevance) the relationship between the sentence pairs belongs to.
[0103] The preset template corresponding to this natural language processing task can be [X][Y][Z][mask], where [X][Y] can be the two sentences in the input sentence pair, Z can be the prompt parameter, and mask can be the mask.
[0104] In this example, multiple sets of parallel corpora can be obtained from a third-party parallel corpus, where one set of parallel corpora includes English sentence pairs and Chinese sentence pairs.
[0105] For example, as shown in the example of FIG3 , a set of parallel corpora may include English sentence pairs: “Flowers are yellow with brown spots” and “The flowers are brown with yellow spots”, and Chinese sentence pairs: “The flowers are yellow with brown spots” and “The flowers are brown with yellow spots”.
[0106] In this example, the source language is English, the target language is Chinese, the first corpus is the aforementioned English sentence pair, and the second corpus is the aforementioned Chinese sentence pair.
[0107] Furthermore, as shown in the example of FIG3 , the preset template used may be [X][Y][Z][mask], where [X][Y] is the corresponding corpus, which is the corresponding sentence pair in this example; [Z] is the prompt parameter; and [mask] is the mask.
[0108] According to the English sentence pairs and the Chinese sentence pairs included in the set of parallel corpora in the above example, a set of data pairs as shown in FIG3 can be obtained.
[0109] Based on a similar approach, at least one set of data pairs can be obtained.
[0110] It should be noted that the above examples are merely illustrative of the embodiments of the present application and are not limiting. For example, in other examples of the embodiments of the present application, the natural language processing task to be performed may be a classification task, a text generation task, or a question-answering task, and the preset template may also be in other forms.
[0111] Step 202: Prompt learning is performed based on at least one set of data and a pre-trained language model, so that the pre-trained language model can perform a natural language processing task based on the target language according to a second prompt after training, and the pre-trained language model is obtained by pre-training based on training data using the source language and training data using the target language.
[0112] In an embodiment of the present application, a pretrained language model (PLM) may be a language model obtained by pretraining based on a training dataset. The training dataset includes training data in a source language and training data in a target language. In other words, the training dataset may be a large-scale multilingual dataset, including training data corresponding to multiple languages such as the source language and the target language. For example, the training dataset may be obtained by preprocessing CommonCrawl data in 100 languages and exceeding 2TB, including deduplication, language identification, and quality screening.
[0113] For example, the training data set may include a large amount of training data in a source language and labels corresponding to the training data. The source language may be a high-resource language such as English, which has relatively rich sample resources.
[0114] The language model is pre-trained based on the training data of the source language and the corresponding labels. The pre-trained language model obtained after training has good performance in the natural language processing tasks corresponding to the source language, which can enable the pre-trained language model to have the ability to better perform tasks related to the source language.
[0115] In addition, multilingual datasets can also include training data in the target language. During pre-training, the language model can be trained using self-supervision or other methods based on the training data in the target language. After pre-training, the resulting pre-trained language model also possesses knowledge related to the target language. However, in many cases, because the amount of training data in the source language is relatively sufficient and the quality is usually good, while the amount of training data in the target language is often insufficient, the pre-trained language model is usually better at handling natural language processing tasks based on the source language than on natural language processing tasks based on the target language.
[0116] The pre-training method of the pre-trained language model is not limited herein. For example, the pre-trained language model may be obtained by pre-training in a computing device cluster; or the pre-trained language model may be obtained by pre-training by a third party and then provided to the computing device cluster.
[0117] The specific type and structure of the pre-trained language model are not limited here.
[0118] Exemplarily, the pre-trained language model may be a masked language model (MLM), or an encoder-decoder language model, a prefix language model, or one or more other existing and subsequently developed language models.
[0119] In the embodiment of the present application, the natural language processing task based on the target language can be considered as a downstream task that one wants to solve in an actual scenario.
[0120] The specific type of the natural language processing task is not limited here. For example, the natural language processing task can be a natural language understanding task such as a relational reasoning task or a classification task, or a natural language generation task such as a text generation task or a question-answering task.
[0121] In an embodiment of the present application, in prompt learning, parameters such as the pre-trained language model and / or the second prompt can be adjusted according to the data constructed by the parallel corpus, so that the trained pre-trained language model and / or the trained second prompt can align the source language and the target language, so as to better learn the knowledge of the target language, thereby realizing cross-language transfer, so that the trained pre-trained language model can more accurately perform natural language processing tasks based on the target language according to the trained second prompt, alleviate the performance loss caused by the difference in language representation in the cross-language transfer process, and enable the trained pre-trained language model to have better cross-language understanding ability when performing downstream tasks such as natural language processing tasks based on the target language based on the trained second prompt.
[0122] In an embodiment of the present application, during the training process based on at least one set of data and a pre-trained language model, the updated parameters may be in various situations.
[0123] For example, in some examples, the parameters of the pre-trained language model can be updated during prompt learning to fine-tune the pre-trained language model, while in other examples, the parameters of the pre-trained language model can be fixed during prompt learning.
[0124] In addition, in addition to the pre-trained language model, other learnable parameters may also be involved in prompt learning, such as the first prompt, the second prompt and / or the prompt conversion module.
[0125] It can be seen that in the embodiments of the present application, for different parameter types and training architectures, prompt learning can have multiple training methods.
[0126] For example, the parameter updating method in the prompt learning may include but is not limited to one or more of the following situations or a combination thereof:
[0127] 1. Update the parameters of the pre-trained language model to fine-tune the pre-trained language model.
[0128] 2. Update the first prompt and the parameters of the prompt conversion module in the data pair to update the prompt parameters of the second prompt according to the updated first prompt and the updated prompt conversion module.
[0129] 3. Update the prompt parameters of the first prompt and the second prompt in the data pair.
[0130] Below, various training architectures and corresponding prompt learning in the embodiments of the present application are exemplarily introduced.
[0131] 1. Update the parameters of the pre-trained language model to fine-tune the pre-trained language model.
[0132] In this example, a pre-trained language model can be fine-tuned during prompt learning.
[0133] For example, in one example, the first data in any data pair includes a first corpus, a first prompt, and a first mask, and the first data corresponds to a preset first label, while the second data in the data pair includes a second corpus, a second prompt, and a second mask.
[0134] The first prompt and the second prompt may be discrete prompts, that is, the first prompt and the second prompt are fixed prompt parameters obtained based on human experience.
[0135] Alternatively, the first prompt and the second prompt may be continuous prompts. In this case, the parameter updating method in the prompt learning may be combined with the second and third cases described later.
[0136] In this example, there are multiple specific ways to update the parameters of the pre-trained language model.
[0137] For example, in one example, the first data also corresponds to a first label. In this case, in the prompt learning, at least one set of data pairs can be input into the pre-trained language model to obtain a first output result corresponding to the first mask and a second output result corresponding to the second mask through the pre-trained language model.
[0138] In this way, the pre-trained language model can be updated according to the first output result, the second output result, and the first label corresponding to the first data.
[0139] Specifically, the loss value can be calculated based on the first loss function, the second loss function, the first output result, the second output result, and the first label corresponding to the first data.
[0140] The first loss function evaluates the difference between the probability space of the first output result and the probability space of the second output result. Exemplarily, the first loss function can calculate the Kullback-Leibler divergence loss (KLD loss) between the first output result and the second output result and regularize to obtain a first loss value.
[0141] The second loss function evaluates the difference between the first output result and the first label. Exemplarily, the second loss function can calculate the cross entropy loss between the first output result and the first label to obtain a second loss value.
[0142] The sum of the first loss value and the second loss value is calculated as the loss value of the corresponding iterative process, and the parameters of the pre-trained language model are updated by the gradient descent method according to the loss value until the loss value corresponding to the updated pre-trained language model converges to the desired state, or until the number of training times reaches a preset number, the training is completed, and the trained pre-trained language model is obtained.
[0143] In other examples, the parameters of the pre-trained language model may be updated based on other methods, and the embodiments of the present application are not limited to this.
[0144] 2. Update the first prompt and the parameters of the prompt conversion module in the data pair to update the prompt parameters of the second prompt according to the updated first prompt and the updated prompt conversion module.
[0145] In this example, the parameters of the pre-trained language model can be updated or not.
[0146] In some embodiments, the first prompt and the second prompt are consecutive prompts.
[0147] Currently, when performing cross-language transfer through prompt learning, traditional solutions use discrete prompts, and the same source language (such as English) templates and prompts are applied to all target languages. This approach makes it difficult to capture target language-specific features in natural language processing tasks. In addition, discrete prompts are mainly based on manual experience, which will also have an adverse impact on the performance after cross-language transfer.
[0148] Therefore, in an embodiment of the present application, the first prompt and the second prompt are both continuous prompts. At this time, the prompt parameters in the first prompt may include a first tensor whose length and content can be learned, and the prompt parameters in the second prompt may also include a second tensor whose length and content can be learned.
[0149] In this way, there is no need to manually design the first and second prompts. Instead, the learnable first and second prompts can be optimized in prompt learning, and better prompt parameters can be found in a space outside the manually constructed vocabulary of the pre-trained language model, thereby improving the processing performance after cross-language transfer.
[0150] In addition, in some examples of the embodiments of the present application, the prompt conversion module can be used to achieve conversion between the first prompt and the second prompt, thereby reducing the differences in language representation between different languages.
[0151] Specifically, in some embodiments, the second prompt is obtained by converting the first prompt through a prompt conversion module.
[0152] The first prompt and the second prompt can be continuous prompts. During prompt learning, the prompt parameters in the first prompt and the second prompt need to be updated. However, due to the unexplainability of the prompt parameters in the first prompt and the second prompt during prompt learning and after training, in this example, the prompt conversion module can be used to achieve the conversion from the first prompt to the second prompt. In other words, the prompt information in the source language can be converted into the prompt information in the target language through the prompt conversion module to alleviate the performance loss caused by the differences in language representation during cross-language transfer.
[0153] FIG4 is a schematic diagram showing an exemplary embodiment of a first prompt, a second prompt, and a prompt conversion module.
[0154] The second prompt in the second data is obtained by converting the first prompt by the prompt conversion module.
[0155] The prompt conversion module is a trainable machine learning model. During prompt learning, the accuracy of the conversion between the first prompt and the second prompt is improved by adjusting the parameters in the prompt conversion module, so that the trained prompt conversion module can accurately realize the conversion from the first prompt to the second prompt, reducing the performance loss caused by the differences in language representation.
[0156] In this way, in prompt learning, in addition to updating the parameters of the pre-trained language model and the prompt parameters of the first prompt and the second prompt in the data pair, the parameters of the prompt conversion module can also be updated to realize the conversion between the first prompt and the second prompt through the prompt conversion module, thereby reducing the differences in language representation between different languages.
[0157] The structure of the prompt conversion module is not limited herein. Exemplarily, the prompt conversion module may include a two-layer multilayer perceptron (MLP).
[0158] Currently, when using prompt learning to perform cross-lingual transfer on pre-trained language models, whether discrete prompts or continuous prompts are used, and regardless of the type of the target language of the cross-lingual transfer, the same source language prompts are used to achieve cross-lingual transfer.
[0159] This means that after completing cross-language transfer, the pre-trained language model will use source language prompts when executing downstream tasks in the target language, regardless of the target language. For example, if the source language prompts are continuous, the pre-trained language model can be transferred across languages using the source language training dataset to obtain continuous prompts in the source language, which can then be used in downstream tasks in the target language.
[0160] However, there are representation differences between different languages. Directly using the continuous prompts obtained by training on the training dataset of the source language for other languages will have adverse effects on performance and is not conducive to cross-language migration of the model.
[0161] In the embodiment of the present application, in the data pair constructed through parallel corpora, the conversion from the first prompt to the second prompt can be achieved through the prompt conversion module, thereby migrating the prompt parameters in the source language scenario to the target language scenario across languages, thereby optimizing the prompt parameters in the target language scenario and reducing the negative impact of cross-language migration due to differences in language representation.
[0162] It can be seen that in this example, in prompt learning, the first prompt, the second prompt and the prompt conversion module can all adjust parameters based on the data pairs including the parallel corpus, so that the trained prompt conversion module can align the prompts of the source language and the target language, reducing the differences in language representation between different languages, so that the trained second prompt can better represent the information of the target language, which is conducive to the execution of natural language processing tasks based on the target language.
[0163] At this time, training can be performed based on at least one set of data pairs, a prompt conversion module, and a pre-trained language model, so that the trained pre-trained language model can perform a natural language processing task based on the target language according to the trained second prompt.
[0164] In some embodiments, the first data includes a first mask, the second data includes a second mask, and the hint learning includes multiple iterative processes.
[0165] Perform prompt learning based on at least one set of data pairs and a pre-trained language model, including:
[0166] During the Nth iteration of the multi-iteration process:
[0167] Inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process with respect to the first mask of the Nth iteration process, and a second output result with respect to the second mask of the Nth iteration process, where N is a positive integer;
[0168] updating the first prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process according to the first output result and the second output result;
[0169] The updated prompt conversion module in the Nth iteration process converts the first prompt in the Nth iteration process to obtain the updated second prompt in the Nth iteration process.
[0170] In an embodiment of the present application, the first prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process can be updated based on the first output result and the second output result, so that the probability distribution corresponding to the first output result and the probability distribution corresponding to the second output result are as close as possible, thereby reducing the difference in language representation, which is beneficial for the pre-trained language model after training to understand the data using the target language according to the second prompt after training, thereby facilitating the execution of tasks related to the target language.
[0171] In some embodiments, updating the first prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process according to the first output result and the second output result includes:
[0172] The first prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process are updated according to the first output result, the second output result and the first loss function, and the first loss function is used to evaluate the difference between the probability space of the first output result and the probability space of the second output result.
[0173] The following is an exemplary introduction to a prompt learning method involved in an embodiment of the present application through Figure 5.
[0174] The first loss function may evaluate the difference between the probability space of the first output result and the probability space of the second output result.
[0175] Exemplarily, the first loss function may be used to calculate a Kullback-Leibler divergence loss (KLD loss) between the first output result and the second output result and regularize the result to obtain a first loss value.
[0176] Then, the first prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process can be updated according to the first loss value; then, the first prompt updated in the Nth iteration process is converted by the prompt conversion module updated in the Nth iteration process to obtain the second prompt updated in the Nth iteration process, so that the probability distribution corresponding to the first output result and the probability distribution corresponding to the second output result are as close as possible, which is conducive to the trained pre-trained language model to better understand the data using the target language according to the trained second prompt, thereby facilitating the execution of tasks related to the target language.
[0177] In addition, in some examples of the embodiments of the present application, training can also be performed through labeled data to improve the performance of the pre-trained language model after training in performing natural language processing tasks in the source language according to the second prompt after training, providing a better performance foundation for cross-language transfer, and improving the performance of the pre-trained language model after cross-language transfer in performing natural language processing tasks based on the target language according to the second prompt after training in all aspects.
[0178] The specific forms of the annotation data can be various, which are introduced below with examples.
[0179] A. The first data corresponds to a first label.
[0180] In some embodiments, the first data of the Nth iteration process corresponds to a first label;
[0181] Prompt learning based on at least one set of data pairs and a pre-trained language model, including:
[0182] The first prompt of the Nth iteration process and / or the pre-trained language model of the Nth iteration process are updated according to the first output result, the second output result, the first label corresponding to the first data of the Nth iteration process, and the second loss function, where the second loss function is used to evaluate the difference between the first output result and the first label corresponding to the first data of the Nth iteration process.
[0183] The specific method for obtaining the first label is not limited herein. For example, the first data and the first label corresponding to the first data can be obtained from an open source dataset, or can be manually annotated by a developer, or can be obtained from other third parties.
[0184] In an example, the first label corresponding to the first data may be a correct label corresponding to the first mask in the first data.
[0185] In another example, the first label corresponding to the first data may also be a correct label obtained by mapping a correct result corresponding to the first mask in the first data.
[0186] For example, in one example, the correct result corresponding to the first mask in a certain first data may be bad, terrible, etc., and bad, terrible may be mapped to negative. In this case, the first label corresponding to the first data is negative.
[0187] In this way, in prompt learning, training can be performed based on the difference between the first label corresponding to the first data and the first output result corresponding to the first data, so that the difference tends to decrease, so that the pre-trained language model after training can more accurately perform natural language processing tasks based on the source language according to the first prompt after training, thereby improving the processing performance of natural language processing tasks on the source language.
[0188] On this basis, by using at least one set of data pairs containing parallel corpora, the superior processing performance of the pre-trained language model for natural language processing tasks in the source language can be well transferred to natural language processing tasks in the target language, thereby reducing the negative impact of differences in language representation.
[0189] The loss value used to update the first prompt and the loss value used to update the prompt conversion module may be the same or different.
[0190] For example, in some examples, as shown in FIG6 , it is an exemplary prompt learning process in an embodiment of the present application.
[0191] Among them, the first loss value can be calculated by the first loss function, the first output result and the second output result, and the second loss value can be calculated by the second loss function, the first output result and the first label, so as to update the first prompt and the pre-trained language model according to the sum of the first loss value and the second loss value, and update the prompt conversion module according to the first loss value.
[0192] It can be seen that in this example, the loss value used to update the first prompt is different from the loss value used to update the prompt conversion module.
[0193] B. The third data corresponds to the second label.
[0194] In some embodiments, the method further comprises:
[0195] Obtaining third data and a second label corresponding to the third data, where the third data includes a third prompt, a third mask, and a third corpus in a source language;
[0196] Perform prompt learning based on at least one set of data pairs and a pre-trained language model, including:
[0197] Inputting the third data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a third output result of the pre-trained language model of the Nth iteration process with respect to the third mask of the Nth iteration process;
[0198] According to the first output result, the second output result, the third output result and the second label corresponding to the third data of the Nth iteration process, the first prompt of the Nth iteration process and the second prompt of the Nth iteration process, and / or the pre-trained language model of the Nth iteration process are updated.
[0199] In the embodiment of the present application, at least one set of third data and a second label corresponding to each set of third data may be obtained.
[0200] The specific source of the third data is not limited here. Exemplarily, the third data can be obtained from a third-party data set.
[0201] In prompted learning, a set of data pairs can correspond to a set of third data, that is, in any iteration process, a set of data pairs and a set of third data can be included in a set of input sets, which can be input into the pre-trained language model as a set of input data.
[0202] The third data may include a third prompt, and the third prompt may be a discrete prompt or a continuous prompt.
[0203] When there are multiple types of the third prompt, the corresponding prompt learning may also be different.
[0204] Below, an exemplary introduction is given to the prompt learning involved in different types of third prompts.
[0205] (1) The third prompt is a discrete prompt.
[0206] Specifically, in some embodiments, updating the first prompt of the Nth iteration process and the second prompt of the Nth iteration process, and / or the pre-trained language model of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process includes:
[0207] Updating the pre-trained language model of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process;
[0208] The first prompt of the Nth iteration process and the second prompt of the Nth iteration process are updated according to the first output result and the second output result.
[0209] As shown in FIG. 7 a , this is an exemplary prompt learning in an embodiment of the present application.
[0210] In this example, the second loss function can be used to calculate the cross-entropy loss between the third output result and the second label corresponding to the third data of the Nth iteration process as the second loss value, so as to fine-tune the pre-trained language model according to the cross-entropy loss, thereby improving the accuracy of the pre-trained language model in performing natural language processing tasks based on the source language.
[0211] Furthermore, a Kullback-Leibler divergence loss (KLD loss) between the first output result and the second output result may be calculated and regularized using a first loss function to obtain a first loss value.
[0212] Then, the pre-trained language model can be fine-tuned based on the sum of the first loss value and the second loss value, and the first and second prompts can be updated based on the first loss value. For example, the first and second prompts can be directly updated based on the first loss value; or the first prompt and the prompt conversion module can be updated based on the first loss value, and the updated first prompt can be converted using the updated prompt conversion module to obtain the updated second prompt.
[0213] (2) The third prompt is a continuous prompt.
[0214] In some embodiments, the third prompt is a continuous prompt, and the second prompt is obtained by converting the first prompt through a prompt conversion module;
[0215] Updating the first prompt of the Nth iteration process and the second prompt of the Nth iteration process, and / or the pre-trained language model of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process, including:
[0216] updating the third prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process;
[0217] The third prompt updated during the Nth iteration is used as the first prompt updated during the Nth iteration.
[0218] As shown in FIG7 b , it is an exemplary prompt learning process in an embodiment of the present application.
[0219] Among them, the third prompt of the Nth iteration process can be updated according to the first output result, the second output result, the third output result and the second label corresponding to the third data of the Nth iteration process; and the prompt conversion module of the Nth iteration process can be updated according to the first output result and the second output result.
[0220] Specifically, the Kullback-Leibler divergence loss (KLD loss) between the first output result and the second output result may be calculated using a first loss function and regularized to obtain a first loss value.
[0221] Furthermore, the cross entropy loss between the first output result and the first label can be calculated by a second loss function to obtain a second loss value.
[0222] Then, the pre-trained language model and the third prompt in the Nth iteration process can be updated according to the sum of the first loss value and the second loss value, and the updated third prompt in the Nth iteration process can be used as the updated first prompt in the Nth iteration process.
[0223] In addition, the parameters of the prompt conversion module in the Nth iteration process can also be updated according to the first loss value.
[0224] Of course, in some other examples of the embodiments of the present application, the pre-trained language model may not be trained, but only the prompt parameters of the first prompt, the second prompt, and the third prompt, as well as the parameters of the prompt conversion module, may be adjusted.
[0225] In an embodiment of the present application, in prompt learning, the input data includes not only data pairs containing parallel corpus and continuous prompts, but also third data as labeled data. In this way, training can be performed based on a variety of data with relatively rich data information, thereby comprehensively improving the processing performance of the natural language processing task of the source language and the processing performance after cross-language migration from the source language to the target language. After cross-language migration, the pre-trained language model can accurately perform natural language processing tasks based on the target language according to the second prompt after training.
[0226] 3. Update the prompt parameters of the first prompt and the second prompt in the data pair.
[0227] In this example, the parameters of the pre-trained language model can be updated or not.
[0228] In this example, the first prompt and the second prompt can be continuous prompts. The first prompt can include a first tensor that can be learned during prompt learning, and the second prompt can include a second tensor that can be learned during prompt learning. The weight and / or size of the first tensor and the weight and / or size of the second tensor can both be updated and adjusted during prompt learning. In this case, the prompt parameters can include the weight and / or size of the corresponding tensor.
[0229] In some embodiments, the first data includes a first mask, the second data includes a second mask, and the prompt learning includes multiple iterative processes;
[0230] Perform prompt learning based on at least one set of data pairs and a pre-trained language model, including:
[0231] During the Nth iteration of the multi-iteration process:
[0232] Inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process with respect to the first mask of the Nth iteration process, and a second output result with respect to the second mask of the Nth iteration process, where N is a positive integer;
[0233] The first prompt of the Nth iteration process and the second prompt of the Nth iteration process are updated according to the first output result, the second output result and the first loss function, and the first loss function is used to evaluate the difference between the probability space of the first output result and the probability space of the second output result.
[0234] The updating of the first prompt of the Nth iteration process and the second prompt of the Nth iteration process according to the first output result and the second output result may include but is not limited to the following two situations:
[0235] (1) Calculating a first loss value based on the first output result and the second output result to update a first prompt of the Nth iteration process based on the first loss value, and updating a parameter of a second prompt of the Nth iteration process based on the first loss value, without using a prompt conversion module to update the second prompt.
[0236] (2) updating the first prompt of the Nth iteration process and the parameters of the prompt conversion module of the Nth iteration process according to the first output result and the second output result, so as to update the prompt parameters of the second prompt of the Nth iteration process according to the updated first prompt of the Nth iteration process and the updated prompt conversion module of the Nth iteration process.
[0237] In this example, the first prompt of the Nth iteration process and the second prompt of the Nth iteration process can be updated based on the first output result and the second output result, so that the probability distribution corresponding to the first output result and the probability distribution corresponding to the second output result are as close as possible, thereby reducing the difference in language representation, which is beneficial for the trained pre-trained language model to understand the data in the target language based on the trained second prompt, thereby facilitating the execution of tasks related to the target language.
[0238] It should be noted that the above-mentioned examples of the updating method of each update parameter can be independent examples or combined with each other, and the embodiments of the present application are not limited to this.
[0239] After the training is completed, the trained pre-trained language model, the trained first prompt, the trained prompt conversion module, and the trained second prompt can be obtained.
[0240] The trained pre-trained language model and the trained second prompt may be used in a subsequent reasoning stage.
[0241] The inference phase can be performed in a computing device cluster, or the computing device cluster can send the trained pre-trained language model and the trained second prompt to other devices so that other devices can perform natural language processing tasks based on the target language in the inference phase.
[0242] In the reasoning stage, the input data can be constructed according to the format of the second data shown in Figure 4 based on the trained second prompt and the data to be processed, and the input data can be input into the trained pre-trained language model to obtain the output result of the trained pre-trained language model regarding the input data, so as to determine the processing result of the corresponding reasoning task based on the output result.
[0243] The above describes the prompt learning method provided by the embodiment of the present application from multiple aspects. The following describes the prompt learning device provided by the embodiment of the present application in conjunction with the accompanying drawings.
[0244] As shown in FIG8 , an embodiment of the present application provides a prompt learning device 80 , which includes:
[0245] An acquisition module 801 is configured to acquire at least one data pair, wherein any data pair includes first data and second data, wherein the first data includes a first prompt and a first corpus in a source language, and the second data includes a second prompt and a second corpus in a target language, wherein the first corpus and the second corpus constitute a pair of parallel corpora;
[0246] A training module 802 is configured to perform prompt learning based on at least one set of data and a pre-trained language model, so that the pre-trained language model can perform a natural language processing task based on a target language according to a second prompt after training, wherein the pre-trained language model is obtained by pre-training based on training data using a source language and training data using a target language.
[0247] Optionally, the first prompt and the second prompt are consecutive prompts.
[0248] Optionally, the first data includes a first mask, the second data includes a second mask, and the prompt learning includes multiple iterative processes;
[0249] The training module 802 is used to:
[0250] During the Nth iteration of the multi-iteration process:
[0251] Inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process with respect to the first mask of the Nth iteration process, and a second output result with respect to the second mask of the Nth iteration process, where N is a positive integer;
[0252] The first prompt of the Nth iteration process and the second prompt of the Nth iteration process are updated according to the first output result, the second output result and the first loss function, and the first loss function is used to evaluate the difference between the probability space of the first output result and the probability space of the second output result.
[0253] Optionally, the second prompt is obtained by converting the first prompt through a prompt conversion module.
[0254] Optionally, the first data includes a first mask, the second data includes a second mask, and the prompt learning includes multiple iterative processes;
[0255] The training module 802 is used to:
[0256] During the Nth iteration of the multi-iteration process:
[0257] Inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process with respect to the first mask of the Nth iteration process, and a second output result with respect to the second mask of the Nth iteration process, where N is a positive integer;
[0258] updating the first prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process according to the first output result and the second output result;
[0259] The updated prompt conversion module in the Nth iteration converts the first prompt in the Nth iteration to obtain the updated second prompt in the Nth iteration.
[0260] Optionally, the first data of the Nth iteration process corresponds to a first label;
[0261] The training module 802 is used to:
[0262] The first prompt of the Nth iteration process and / or the pre-trained language model of the Nth iteration process are updated according to the first output result, the second output result, the first label corresponding to the first data of the Nth iteration process, and the second loss function, where the second loss function is used to evaluate the difference between the first output result and the first label corresponding to the first data of the Nth iteration process.
[0263] Optionally, the acquisition module 801 is used to:
[0264] Obtaining third data and a second label corresponding to the third data, where the third data includes a third prompt, a third mask, and a third corpus in a source language;
[0265] The training module 802 is used to:
[0266] Inputting the third data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a third output result of the pre-trained language model of the Nth iteration process with respect to the third mask of the Nth iteration process;
[0267] According to the first output result, the second output result, the third output result and the second label corresponding to the third data of the Nth iteration process, the first prompt of the Nth iteration process and the second prompt of the Nth iteration process, and / or the pre-trained language model of the Nth iteration process are updated.
[0268] Optionally, the third prompt is a discrete prompt;
[0269] The training module 802 is used to:
[0270] Updating the pre-trained language model of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process;
[0271] The first prompt of the Nth iteration process and the second prompt of the Nth iteration process are updated according to the first output result and the second output result.
[0272] Optionally, the third prompt is a continuous prompt;
[0273] The training module 802 is used to:
[0274] updating the third prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process;
[0275] The third prompt updated during the Nth iteration is used as the first prompt updated during the Nth iteration.
[0276] In an embodiment of the present application, a module is used as an example of a software functional unit, and the prompt learning device may include code running on a computing instance. The computing instance may be at least one of a physical host (computing device), a virtual machine, a container, and other computing devices. Furthermore, the above-mentioned computing device may be one or more. For example, the prompt learning device may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the application may be distributed in the same region or in different regions. The multiple hosts / virtual machines / containers used to run the code may be distributed in the same available zone (AZ) or in different AZs, each AZ including one data center or multiple geographically close data centers. Typically, a region may include multiple AZs.
[0277] Similarly, the multiple hosts / virtual machines / containers used to run this code can be distributed within the same virtual private cloud (VPC) or across multiple VPCs. Typically, a VPC is located within a region. Cross-region communication between two VPCs within the same region, or between VPCs in different regions, requires a communication gateway within each VPC to interconnect the VPCs.
[0278] As an example of a hardware functional unit, a module can include at least one computing device, such as a server. Alternatively, the learning device can be implemented using an application specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD can be a complex PLD (CPLD), a field programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0279] The multiple computing devices included in the prompt learning device can be distributed in the same region or in different regions. The multiple computing devices included in the prompt learning device can be distributed in the same AZ or in different AZs. Similarly, the multiple computing devices included in the prompt learning device can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
[0280] It should be noted that, in other embodiments, the acquisition module can be used to execute any step in the prompt learning method, and the training module can be used to execute any step in the prompt learning method. The steps that the acquisition module, the processing module, and the sending module are responsible for implementing can be specified as needed. The full functions of the prompt learning device can be realized by respectively implementing different steps in the prompt learning method through the acquisition module and the training module.
[0281] The present application also provides a computing device 90. As shown in FIG9 , computing device 90 includes a bus 92, a processor 94, a memory 96, and a communication interface 98. Processor 94, memory 96, and communication interface 98 communicate with each other via bus 92. Computing device 90 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in computing device 90.
[0282] Bus 92 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, among others. Buses may be classified as address buses, data buses, control buses, and the like. For ease of illustration, FIG9 illustrates a single bus line, but this does not imply a single bus or type of bus. Bus 94 may include a pathway for transmitting information between various components of computing device 90 (e.g., memory 96, processor 94, and communication interface 98).
[0283] The processor 94 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0284] The memory 96 may include volatile memory, such as random access memory (RAM). The processor 94 may also include non-volatile memory, such as read-only memory (ROM), flash memory, a hard disk drive (HDD), or a solid state drive (SSD).
[0285] The memory 96 stores executable program code, and the processor 94 executes the executable program code to respectively implement the functions of the aforementioned acquisition module and training module, thereby realizing the prompt learning method applied to the computing device cluster in the above-mentioned embodiment, that is, the memory 96 stores instructions for executing the prompt learning method applied to the computing device cluster in the above-mentioned embodiment.
[0286] The communication interface 98 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 90 and other devices or a communication network.
[0287] Embodiments of the present application also provide a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0288] As shown in Figure 10, the computing device cluster includes at least one computing device 90. The memory 96 in one or more computing devices 90 in the computing device cluster may store the same instructions for executing the prompt learning method.
[0289] In some possible implementations, the memory 96 of one or more computing devices 90 in the computing device cluster may also store some instructions for executing the prompt learning method. In other words, the combination of one or more computing devices 90 can jointly execute the instructions for executing the prompt learning method.
[0290] It should be noted that the memory 96 in different computing devices 90 in the computing device cluster can store different instructions, each for executing a portion of the functions of the prompt learning method. In other words, the instructions stored in the memory 96 in different computing devices 90 can implement the functions of one or more modules in the acquisition module and the training module.
[0291] In some possible implementations, one or more computing devices in a computing device cluster may be connected via a network. The network may be a wide area network or a local area network, etc. FIG11 shows a possible implementation. As shown in FIG11 , two computing devices 90A and 90B are connected via a network. Specifically, the connection to the network is made through a communication interface in each computing device. In this type of possible implementation, the memory 96 in the computing device 90A may store instructions for executing the functions of the acquisition module. At the same time, the memory 96 in the computing device 90B may store instructions for executing the functions of the training module. Alternatively, the memory 96 in the computing device 90A may store instructions for executing part of the functions of the training module. At the same time, the memory 96 in the computing device 90B may store instructions for executing another part of the functions of the training module.
[0292] It should be understood that the functionality of the computing device 90A shown in FIG11 may also be accomplished by multiple computing devices 90. Similarly, the functionality of the computing device 90B may also be accomplished by multiple computing devices 90.
[0293] The present application also provides another computing device cluster. The connection relationship between the computing devices in this computing device cluster can be similar to the connection relationship between computing device clusters in Figures 10 and 11. However, the memory 96 in one or more computing devices 90 in this computing device cluster can store the same instructions for executing the prompt learning method.
[0294] In some possible implementations, the memory 96 of one or more computing devices 90 in the computing device cluster may also store some instructions for executing the prompt learning method. In other words, the combination of one or more computing devices 90 can jointly execute the instructions for executing the prompt learning method.
[0295] It should be noted that the memory 96 in different computing devices 90 in the computing device cluster can store different instructions for executing part of the functions of the prompt learning method. In other words, the instructions stored in the memory 96 in different computing devices 90 can implement the functions of one or more modules in the acquisition module and the training module.
[0296] The present application also provides a computer program product including instructions. The computer program product may be software or a program product including instructions that can be executed on a computing device or stored in any available medium. When the computer program product is executed on at least one computing device, the at least one computing device executes the prompt learning method.
[0297] The present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center that contains one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the prompt learning method.
[0298] The present application also provides a chip system, which includes a processor configured to implement the steps performed by the computing device cluster. In one possible design, the chip system may also include a memory configured to store necessary program instructions and data. The chip system may be composed solely of a chip or may include a chip and other discrete components.
[0299] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the protection scope of the technical solutions of the embodiments of the present application.
Claims
1. A prompt learning method, characterized in that: The method comprises: Acquire at least one set of data pairs, any set of the data pairs includes first data and second data, the first data includes a first prompt and a first corpus in a source language, the second data includes a second prompt and a second corpus in a target language, the first corpus and the second corpus form a pair of parallel corpora; Prompt learning is performed based on the at least one set of data and the pre-trained language model, so that the trained pre-trained language model can perform a natural language processing task based on the target language according to a second prompt after training, and the pre-trained language model is obtained by pre-training based on training data using the source language and training data using the target language.
2. The method according to claim 1, characterized in that: The first prompt and the second prompt are consecutive prompts.
3. The method according to claim 2, characterized in that The first data includes a first mask, the second data includes a second mask, and the hint learning includes multiple iterations; The performing prompt learning according to the at least one set of data and the pre-trained language model comprises: In the Nth iteration of the multiple iterations: Inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process with respect to the first mask of the Nth iteration process and a second output result with respect to the second mask of the Nth iteration process, where N is a positive integer; The first prompt of the Nth iteration process and the second prompt of the Nth iteration process are updated according to the first output result, the second output result and a first loss function, wherein the first loss function is used to evaluate the difference between the probability space of the first output result and the probability space of the second output result.
4. The method according to claim 2 or 3, characterized in that: The second prompt is obtained by converting the first prompt through a prompt conversion module.
5. The method according to claim 4, characterized in that The first data includes a first mask, the second data includes a second mask, and the hint learning includes multiple iterations; The performing prompt learning according to the at least one set of data and the pre-trained language model comprises: In the Nth iteration of the multiple iterations: Inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process with respect to the first mask of the Nth iteration process and a second output result with respect to the second mask of the Nth iteration process, where N is a positive integer; updating the first prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process according to the first output result and the second output result; The updated prompt conversion module in the Nth iteration process converts the first prompt updated in the Nth iteration process to obtain the updated second prompt in the Nth iteration process.
6. The method according to claim 3 or 5, characterized in that: The first data of the Nth iteration process corresponds to a first label; The performing prompt learning according to the at least one set of data and the pre-trained language model comprises: The first prompt of the Nth iteration process and / or the pre-trained language model of the Nth iteration process are updated according to the first output result, the second output result, the first label corresponding to the first data of the Nth iteration process, and the second loss function, wherein the second loss function is used to evaluate the difference between the first output result and the first label corresponding to the first data of the Nth iteration process.
7. The method according to claim 3 or 5, characterized in that: The method further comprises: Acquire third data and a second label corresponding to the third data, wherein the third data includes a third prompt, a third mask, and a third corpus in the source language; The performing prompt learning according to the at least one set of data and the pre-trained language model comprises: Inputting the third data of the Nth iteration process into the pre-trained language model of the Nth iteration process, and obtaining a third output result of the pre-trained language model of the Nth iteration process with respect to the third mask of the Nth iteration process; According to the first output result, the second output result, the third output result and the second label corresponding to the third data of the N-th iteration process, the first prompt of the N-th iteration process and the second prompt of the N-th iteration process, and / or the pre-trained language model of the N-th iteration process are updated.
8. The method according to claim 7, characterized in that The third prompt is a discrete prompt; The updating of the first prompt of the Nth iteration process and the second prompt of the Nth iteration process and / or the pre-trained language model of the Nth iteration process according to the first output result, the second output result, the third output result and the second label corresponding to the third data of the Nth iteration process includes: updating the pre-trained language model of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process; The first prompt of the Nth iteration process and the second prompt of the Nth iteration process are updated according to the first output result and the second output result.
9. The method according to claim 7, characterized in that: The third prompt is a continuous prompt, and the second prompt is obtained by converting the first prompt through a prompt conversion module; The updating of the first prompt of the Nth iteration process and the second prompt of the Nth iteration process and / or the pre-trained language model of the Nth iteration process according to the first output result, the second output result, the third output result and the second label corresponding to the third data of the Nth iteration process includes: updating the third prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process; The third prompt updated during the Nth iteration is used as the first prompt updated during the Nth iteration.
10. A prompt learning device, characterized in that: include: an acquisition module, configured to acquire at least one set of data pairs, wherein any set of the data pairs includes first data and second data, wherein the first data includes a first prompt and a first corpus in a source language, and the second data includes a second prompt and a second corpus in a target language, and the first corpus and the second corpus form a pair of parallel corpora; A training module is used to perform prompt learning based on the at least one set of data pairs and a pre-trained language model, so that the trained pre-trained language model can perform a natural language processing task based on the target language according to a second prompt after training, and the pre-trained language model is obtained by pre-training based on training data using the source language and training data using the target language.
11. The device according to claim 10, characterized in that The first prompt and the second prompt are consecutive prompts.
12. The device according to claim 11, characterized in that The first data includes a first mask, the second data includes a second mask, and the hint learning includes multiple iterations; The training module is used to: In the Nth iteration of the multiple iterations: Inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process with respect to the first mask of the Nth iteration process and a second output result with respect to the second mask of the Nth iteration process, where N is a positive integer; The first prompt of the Nth iteration process and the second prompt of the Nth iteration process are updated according to the first output result, the second output result and a first loss function, wherein the first loss function is used to evaluate the probability space of the first output result The difference between the probability space of the first and second output results.
13. The device according to claim 11 or 12, characterized in that The second prompt is obtained by converting the first prompt through a prompt conversion module.
14. The device according to claim 13, characterized in that The first data includes a first mask, the second data includes a second mask, and the hint learning includes multiple iterations; The training module is used to: In the Nth iteration of the multiple iterations: Inputting the first data of the Nth iteration process and the second data of the Nth iteration process into the pre-trained language model of the Nth iteration process, obtaining a first output result of the pre-trained language model of the Nth iteration process with respect to the first mask of the Nth iteration process and a second output result with respect to the second mask of the Nth iteration process, where N is a positive integer; updating the first prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process according to the first output result and the second output result; The updated prompt conversion module in the Nth iteration process converts the first prompt updated in the Nth iteration process to obtain the updated second prompt in the Nth iteration process.
15. The device according to claim 12 or 14, characterized in that The first data of the Nth iteration process corresponds to a first label; The training module is used to: The first prompt of the Nth iteration process and / or the pre-trained language model of the Nth iteration process are updated according to the first output result, the second output result, the first label corresponding to the first data of the Nth iteration process, and the second loss function, wherein the second loss function is used to evaluate the difference between the first output result and the first label corresponding to the first data of the Nth iteration process.
16. The device according to claim 12 or 14, characterized in that The acquisition module is used for: Acquire third data and a second label corresponding to the third data, wherein the third data includes a third prompt, a third mask, and a third corpus in the source language; The training module is used to: Inputting the third data of the Nth iteration process into the pre-trained language model of the Nth iteration process, and obtaining a third output result of the pre-trained language model of the Nth iteration process with respect to the third mask of the Nth iteration process; According to the first output result, the second output result, the third output result and the second label corresponding to the third data of the N-th iteration process, the first prompt of the N-th iteration process and the second prompt of the N-th iteration process, and / or the pre-trained language model of the N-th iteration process are updated.
17. The device according to claim 16, characterized in that The third prompt is a discrete prompt; The training module is used to: updating the pre-trained language model of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process; The first prompt of the Nth iteration process and the second prompt of the Nth iteration process are updated according to the first output result and the second output result.
18. The device according to claim 16, characterized in that The third prompt is a continuous prompt, and the second prompt is obtained by converting the first prompt through a prompt conversion module; The training module is used to: updating the third prompt of the Nth iteration process and the prompt conversion module of the Nth iteration process according to the first output result, the second output result, the third output result, and the second label corresponding to the third data of the Nth iteration process; The third prompt updated during the Nth iteration is used as the first prompt updated during the Nth iteration.
19. A computing device cluster, characterized in that: comprising at least one computing device, each computing device comprising a processor and a memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster executes the method according to any one of claims 1 to 9.
20. A computer-readable storage medium, characterized in that: The method comprises computer program instructions. When the computer program instructions are executed by a computing device cluster, the computing device cluster performs the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Method for machine translation, device and medium
CN113887253A
Cross-language abstract generation method and device based on multi-language model
CN115455175A
Cross-language question answering system construction method and device based on generative multi-language model
CN115795009A
Multi-lingual model training method, apparatus, electronic device and readable storage medium
US20220171941A1
