OpenPrompt: An Open-source Framework for Prompt-learning

Ning Ding, Shengding Hu, Weilin Zhao, Yulin Chen, Zhiyuan Liu, Haitao Zheng, Maosong Sun

Abstract

OpenPrompt is a modular, open-source framework designed to standardize and simplify prompt-learning, a paradigm where pre-trained language models (PLMs) are adapted to tasks by mimicking their original training objectives. By decoupling templates, verbalizers, and models, OpenPrompt allows researchers to easily mix and match components to deploy state-of-the-art prompting methods across a vast array of NLP tasks.

Introduction

In traditional NLP, models are typically "fine-tuned" by adding task-specific layers (heads) on top of a pre-trained model. However, a new paradigm called prompt-learning has emerged. Instead of altering the model's architecture, input text is wrapped in a "template" (e.g., adding "It was [MASK]" to a movie review), allowing the model to predict a word to fill the gap.

While powerful—especially in "few-shot" scenarios where data is scarce—prompt-learning has historically lacked standardization. Researchers often write custom, one-off code for specific papers, making it difficult to compare different methods or apply techniques across different task types. OpenPrompt addresses this lack of standardization by providing a unified, research-friendly toolkit.

Modular Architecture

The core of OpenPrompt is its modular design, which breaks the prompting pipeline into four interchangeable parts:

  1. Template: Wraps the original input with extra tokens. OpenPrompt uses a custom template language to define "hard" prompts (fixed text), "soft" prompts (trainable embeddings), and complex logic.
  2. Verbalizer: Maps the model's vocabulary predictions back to labels (e.g., mapping the predicted word "great" to a "Positive" class).
  3. PromptModel: A model-agnostic wrapper handling interactions between the PLM, template, and verbalizer. It supports Masked LMs (like BERT), Causal LMs (like GPT), and Seq2Seq models (like T5).
  4. PromptTrainer: Manages the training process, supporting strategies like parameter-efficient tuning where the PLM remains frozen while only prompt parameters are updated.
The modular architecture of OpenPrompt, illustrating the interaction between PromptModel, PromptDataset, and PromptTrainer.

Key Insights: Combinability and Alignment

A central strength of OpenPrompt is its combinability. The framework allows users to take a prompting strategy designed for one model type and adapt it to a completely different task or model. This flexibility bridges the gap between pre-training objectives and downstream tasks.

The combinability of OpenPrompt, showing how different PLMs, templates, and verbalizers can be mixed for various tasks.

By creating a dedicated syntax for templates, the authors enable sophisticated "mixed" prompts where human-readable text and learnable vectors coexist within a few lines of code. This alignment makes the transition from pre-training to task-specific application explicit and configurable.

Evaluation and Results

OpenPrompt serves as a "library of libraries," successfully implementing and reproducing several influential prompting papers within its unified framework, including:

  • PTR (Prompt Tuning with Rules)
  • P-tuning (using continuous "soft" prompts)
  • Prefix-tuning (optimizing sequence-to-sequence generation)
  • LM-BFF (Better Few-shot Fine-tuning)

The framework supports a wide range of standard benchmarks, including NLU (GLUE, SuperGLUE), classification (AG’s News, IMDB), generation (WebNLG), and information extraction (Few-NERD). It demonstrates that the three major families of PLMs—MLM, LM, and Seq2Seq—can be handled under one unified roof, significantly lowering the barrier to entry for researchers.

Conclusion and Future Work

While OpenPrompt significantly simplifies prompt-learning research, challenges remain. Optimization for small and medium-sized models is still difficult compared to massive models like GPT-3. Future work includes exploring prompt-based adversarial robustness—testing how subtle changes in prompts affect model stability—and continuously integrating new techniques as the field evolves.

Summary updated

BibTeX
@inproceedings{ding2022openprompt,
  author = {Ning Ding and Shengding Hu and Weilin Zhao and Yulin Chen and Zhiyuan Liu and Haitao Zheng and Maosong Sun},
  title = {{OpenPrompt: An Open-source Framework for Prompt-learning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2022},
  doi = {10.18653/v1/2022.acl-demo.10},
}
Figure