back to home

thunlp / OpenPrompt

An Open-Source Framework for Prompt-Learning.

4,842 stars
486 forks
100 issues
PythonShell

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing thunlp/OpenPrompt in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/thunlp/OpenPrompt)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

**An Open-Source Framework for Prompt-learning.** ------ Overview • Installation • How To Use • Docs • Paper • Citation • Performance • What's New? • ❗️ April 2023: $\color{red}{\normalsize{\textbf{Want to build your Chat AI?}}}$ **We are releasing UltraChat, use OpenPrompt and UltraChat to conduct supervised instruction tuning, see** . • Aug 2022: Thanks to contributor zhiyongLiu1114, OpenPrompt now supports ERNIE 1.0 in PaddlePaddle. • July 2022: OpenPrompt supports OPT now. • June 2022: OpenPrompt wins ACL 2022 Best Demo Paper Award. • Mar 2022: We add a tutorial as the response to issue 124, which uses a customized tokenizer_wrapper to perform tasks that are not in the default configuration of OpenPrompt (e.g., Bert tokenizer+T5 model). • Feb 2022: Check out our sister repo OpenDelta! • Dec 2021: • Dec 2021: SuperGLUE performance are added • Dec 2021: We support **generation paradigm for all tasks** by adding a new verbalizer:GenerationVerbalizer and a tutorial: 4.1_all_tasks_are_generation.py • Nov 2021: Now we have released a paper OpenPrompt: An Open-source Framework for Prompt-learning. • Nov 2021 PrefixTuning supports t5 now. • Nov 2021: We made some major changes from the last version, where a flexible template language is newly introduced! Part of the docs is outdated and we will fix it soon. Overview **Prompt-learning** is the latest paradigm to adapt pre-trained language models (PLMs) to downstream NLP tasks, which modifies the input text with a textual template and directly uses PLMs to conduct pre-trained tasks. This library provides a standard, flexible and extensible framework to deploy the prompt-learning pipeline. OpenPrompt supports loading PLMs directly from huggingface transformers. In the future, we will also support PLMs implemented by other libraries. For more resources about prompt-learning, please check our paper list. What Can You Do via OpenPrompt? • Use the implementations of current prompt-learning approaches.* We have implemented various of prompting methods, including templating, verbalizing and optimization strategies under a unified standard. You can easily call and understand these methods. • *Design your own prompt-learning work.* With the extensibility of OpenPrompt, you can quickly practice your prompt-learning ideas. Installation **Note: Please use Python 3.8+ for OpenPrompt** Using Pip Our repo is tested on Python **3.8+** and PyTorch **1.8.1+**, install OpenPrompt using pip as follows: To play with the latest features, you can also install OpenPrompt from the source. Using Git Clone the repository from github: Modify the code Use OpenPrompt Base Concepts A object contains a , a (or multiple) and a (or multiple) , where the class is defined to wrap the original input with templates, and the class is to construct a projection between labels and target words in the current vocabulary. And a object practically participates in training and inference. Introduction by a Simple Example With the modularity and flexibility of OpenPrompt, you can easily develop a prompt-learning pipeline. Step 1: Define a task The first step is to determine the current NLP task, think about what’s your data looks like and what do you want from the data! That is, the essence of this step is to determine the   and the   of the task. For simplicity, we use Sentiment Analysis as an example. tutorial_task. Step 2: Define a Pre-trained Language Models (PLMs) as backbone. Choose a PLM to support your task. Different models have different attributes, we encourge you to use OpenPrompt to explore the potential of various PLMs. OpenPrompt is compatible with models on huggingface. Step 3: Define a Template. A   is a modifier of the original input text, which is also one of the most important modules in prompt-learning.  We have defined in Step 1. Step 4: Define a Verbalizer A   is another important (but not necessary) in prompt-learning,which projects the original labels (we have defined them as  , remember?) to a set of label words. Here is an example that we project the   class to the word bad, and project the   class to the words good, wonderful, great. Step 5: Combine them into a PromptModel Given the task, now we have a  , a   and a  , we combine them into a  . Note that although the example naively combine the three modules, you can actually define some complicated interactions among them. Step 6: Define a DataLoader A PromptDataLoader is basically a prompt version of pytorch Dataloader, which also includes a Tokenizer , a Template and a TokenizerWrapper . Step 7: Train and inference Done! We can conduct training and inference the same as other processes in Pytorch. Please refer to our tutorial scripts, and documentation for more details. Datasets We provide a series of download scripts in the folder, feel free to use them to download benchmarks. Performance Report There are too many possible combinations powered by OpenPrompt. We are trying our best to test the performance of different methods as soon as possible. The performance will be constantly updated into the Tables. We also encourage the users to find the best hyper-parameters for their own tasks and report the results by making pull request. Known Issues Major improvement/enhancement in future. • We made some major changes from the last version, so part of the docs is outdated. We will fix it soon. Citation Please cite our paper if you use OpenPrompt in your work Contributors We thank all the contributors to this project, more contributors are welcome!