O pen P rompt: An Open-source Framework for Prompt-learning (2022)

Abstract: Prompt-learning has become a new paradigm in modern natural language processing, which directly adapts pre-trained language models (PLMs) to cloze-style prediction, autoregressive modeling, or sequence to sequence generation, resulting in promising performances on various tasks. However, no standard implementation framework of prompt-learning is proposed yet, and most existing prompt- learning codebases, often unregulated, only provide limited implementations for specific scenarios. Since there are many details such as templating strategy, initializing strategy, verbalizing strategy, etc., that need to be considered in prompt-learning, practitioners face impediments to quickly adapting the de-sired prompt learning methods to their applications. In this paper, we present Open- Prompt, a unified easy-to-use toolkit to conduct prompt-learning over PLMs. OpenPrompt is a research-friendly framework that is equipped with efficiency, modularity, and extendibility, and its combinability allows the freedom to combine different PLMs, task for- mats, and prompting modules in a unified paradigm. Users could expediently deploy prompt-learning frameworks and evaluate the generalization of them on different NLP tasks without constraints.

## introduction pre-trained language models (plms) @xcite have been widely proven to be effective in natural language understanding and generation, ushering in a new era of modern natural language processing (nlp). in the early stage of this revolution, a standard approach to adapt plms to various specific nlp tasks is the pretraining-finetuning paradigm, where additional parameters and task-specific objectives are introduced in the tuning procedure. however recently, the paradigm of the adaptation of plms is shifting. originated in t5 @xcite and @xcite , researchers find that plms can be effectively stimulated by textual prompts or demonstrations, especially in low-data scenarios. take a simple prompt-based sentiment classification for example, the pipeline consists of a template and a verbalizer, where a template is used to process the original text with some extra tokens, and a verbalizer projects original labels to words in the vocabulary for final prediction. assume the template is "<@xmath0, where the @xmath1, and the verbalizer is {"positive":"great", "negative":"terrible"}. the sentence "albert einstein was one of the greatest intellects of his time." will first be wrapped by the pre-defined template as "albert einstein was one of the greatest intellects of his time. it @xmath2. the wrapped sentence is then tokenized and fed into a plm to predict the distribution over vocabulary on @xmath3. it is expected that the word great should have a larger probability than terrible. as illustrated above, prompt-learning projects the downstream tasks to pre-training objectives for plms with the help of textual or softencoding prompts. a series of studies of promptlearning @xcite have been proposed to investigate the strategies of constructing templates @xcite @xcite , verbalizers @xcite , optimization @xcite , and application @xcite @xcite for this paradigm. a prompt-learning problem could be regarded as a synthesis of plms, human prior knowledge, and specific nlp tasks that need to be handled. example plm template verbalizer task reference naive tc mlm & seq2seq m. text m. one-many text classification -naive kp lm & seq2seq m. text -knowledge probing -naive fet mlm m. text (meta info) m. one-many entity typing (ding et al., 2021a) ptr mlm m. text (complex) m. one-one relation extratcion (han et al., 2021b) p-tuning lm soft tokens m. one-one text classification (liu et al., 2021b) prefix-tuning lm, seq2seq soft tokens -text generation (li and liang, 2021) lm-bff mlm a. text m. one-many text classification @xcite hence, it is hard to support the particular implementations of prompt-learning elegantly with the current deep learning or nlp libraries while there is also a lack of a standard paradigm. previous works pursue the most efficient way to implement promptlearning with the least modification to the existing framework for traditional fine-tuning, resulting in poor readability and even unstable reproducibility. moreover, the performance of a prompt-learning pipeline varies greatly with the choice of templates and verbalizers @xcite , creating more barriers for implementations. lastly, there is no comprehensive open-source framework particularly designed for prompt-learning at present, which makes it difficult to try out new methods and make rigorous comparisons for previous approaches. we present openprompt, an open-source, easyto-use, and extensible toolkit for prompt-learning. openprompt modularizes the whole framework of prompt-learning and considers the interactions between each module. we highlight the feature of combinability of openprompt, which supports flexible combinations of diverse task formats, plms, and prompting modules. for example, we can easily adapt prefix-tuning @xcite to a text classification task in openprompt. this feature enables users to assess the generalization of their prompt-learning models on various tasks, but not only the performance on specific tasks. specifically, a template class is used to define or generate textual or soft-encoding templates to wrap the original input. to flexibly support various templates under a unified paradigm, we design a new template language that could easily conduct token-level customization for the corresponding attributes. a verbalizer projects the classification labels to words in the vocabulary, and a promptmodel is responsible for the training and inference process. each module in openprompt is clearly defined while retaining its independence and coupling so that researchers can easily deploy a model and make targeted improvements. we also implement baselines with openprompt and evaluate them on a broad scope of nlp tasks, demonstrating the effectiveness of openprompt. the area of prompt-learning is in the exploratory stage with rapid development. hopefully, open-prompt could help beginners quickly understand prompt-learning, enable researchers to efficiently deploy prompt-learning research pipeline, and empower engineers to readily apply prompt-learning to practical nlp systems to solve real-world problems. openprompt will not only keep all the code open source, but will also continue to update the documentation to provide detailed tutorials. ## design and implementation as stated in § 1, prompt-learning is a comprehensive process that combines plms, human knowledge, and specific nlp tasks. keeping that in mind, the design philosophy is to simultaneously consider the independence and mutual coupling of each module. as illustrated in figure 1 , openprompt provides the full life-cycle of prompt-learning based on pytorch @xcite . in this section, we first introduce the combinability of openprompt, and then the detailed design and implementation of each component in openprompt. ## evaluation openprompt aims to support a broad set of nlp tasks under the paradigm of prompt-learning. in terms of evaluation, we use openprompt to implement various baselines and assess them on the corresponding nlp tasks. we show the validation space in figure 5 . and the evaluation tasks include webnlg @xcite for conditional generation, glue @xcite and super-glue @xcite for natural language understanding; semeval @xcite , few-nerd @xcite for information extraction; mnli @xcite , ag's news @xcite , dbpedia @xcite and imdb @xcite ) for text classification; lama @xcite for knowledge probing. the processors of these datasets have already been implemented in open-prompt, and they are all inherited from a common base dataprocessor class. to keep the results up to date, we are constantly updating and reporting the latest results on our github repository foot_2 . ## discussion although plms have achieved tremendous success on almost all the subtasks in nlp, one problem still hangs in the air, have we really fully exploited the potential of plms, especially the big ones? conventional fine-tuning uses extra task-specific heads and objectives for adaptation, but this strategy may face two issues. on the one hand, such an approach creates a natural gap between model tuning and pre-training. on the other hand, as the number of model parameters increases, this finetuning approach becomes increasingly difficult to operate due to the massive computational volume (e.g., @xcite )). by mimicking the process of pre-training, prompt-learning intuitively bridges the gap between pre-training and model tuning. practically, this paradigm is surprisingly effective in low-data regime @xcite . for example, with appropriate template, zero-shot prompt-learning could even outperform 32-shot fine-tuning @xcite . another promising empirical attribute of prompt-learning is the potential to stimulate large-scale plms. when it comes to a 10b model, solely optimizing prompts (the parameters of the model are fixed) could achieve comparable performance to full parameter finetuning @xcite . these practical studies imply that we may use prompts to more effectively and efficiently dig the knowledge kept in plms, leading to a deeper understanding of the underlying principles of their mechanisms @xcite @xcite . in addition to prompt-based methods, there are also other techniques exploring the parameter-efficient stimulation of large-scale plms @xcite @xcite . although it is possible to achieve non-trivial results on the large-scale plms by just adjusting the prompt. however, in small and medium-sized models, prompt still faces optimization problems that need to be addressed. from a practical implementation point of view, prompt-learning is actually complex and requires a lot of detailed consideration. with general-purpose nlp under the prompt-learning paradigm as our target, we present openprompt, a unified toolkit to effectively and efficiently implement promptlearning approaches. openprompt demonstrates a comprehensive view of the programming details of prompt-learning, and enables practitioners to quickly understand the mechanisms and practical attributes of this technique. and one can quickly deploy existing representative promptlearning algorithms that are already implemented in the package under a unified programming framework. moreover, openprompt allows researchers or developers to quickly try out new ideas of prompt-learning, which not only includes newly designed templates or verbalizers, but also the exploration of the attributes of prompt-learning, e.g., prompt-based adversarial attacking. ## conclusion and future work we propose openprompt, a unified, easy-to-use, and extensible toolkit for prompt-learning. open-prompt establishes a unified framework with clearly defined blocks and flexible interactions to support solid research on prompt-learning. at the application level, openprompt could facilitate researchers and developers to effectively and efficiently deploy prompt-learning pipelines. in the future, we will continue to integrate new techniques and features to openprompt to facilitate the research progress of prompt-learning. focusing on organizing input and output and training processes, openprompt will be easily combined with tools that focus on specific optimization execution processes in the future.