Top Related Projects
🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
A framework for few-shot evaluation of language models.
Build high-quality LLM apps - from prototyping, testing to production deployment and monitoring.
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
Tool Learning for Big Models, Open-Source Solutions of ChatGPT-Plugins
Quick Overview
The promptsource
repository is a collection of prompts for natural language processing (NLP) tasks, created and maintained by the BigScience research workshop. It serves as a comprehensive resource for researchers and developers working on language models and other NLP applications.
Pros
- Diverse Prompt Collection: The repository contains a wide variety of prompts covering numerous NLP tasks, including text generation, question answering, sentiment analysis, and more.
- Community-Driven: The project is a collaborative effort, with contributions from researchers and developers in the NLP community.
- Structured and Organized: The prompts are organized into different categories and tasks, making it easy to find relevant prompts for specific use cases.
- Actively Maintained: The repository is regularly updated with new prompts and improvements, ensuring it remains a valuable resource.
Cons
- Potential Bias: As the prompts are contributed by the community, there may be inherent biases or inconsistencies in the dataset.
- Limited Metadata: While the prompts are well-organized, the metadata associated with each prompt may be limited, making it challenging to understand the context and intended use.
- Lack of Standardization: The format and structure of the prompts may vary, which could complicate the integration and usage of the dataset in certain applications.
- Potential Licensing Issues: The licensing and intellectual property rights of the prompts may not be clearly defined, which could create legal concerns for users.
Getting Started
To use the promptsource
dataset, you can follow these steps:
- Clone the repository:
git clone https://github.com/bigscience-workshop/promptsource.git
- Install the required dependencies:
cd promptsource
pip install -r requirements.txt
- Explore the available prompts:
from promptsource.promptsource import PromptDataset
# List all available tasks
print(PromptDataset.list_tasks())
# Load a specific task
task = PromptDataset("qa_zre")
print(task.prompts)
- Use the prompts in your NLP applications:
# Example: Generating text using a prompt
from transformers import GPT2LMHeadModel, GPT2Tokenizer
model = GPT2LMHeadModel.from_pretrained("gpt2")
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
prompt = "Once upon a time, there was a magical kingdom where"
input_ids = tokenizer.encode(prompt, return_tensors="pt")
output = model.generate(input_ids, max_length=100, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95, num_beams=1)
print(tokenizer.decode(output[0], skip_special_tokens=True))
Competitor Comparisons
🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
Pros of transformers
- Comprehensive library with support for a wide range of transformer models
- Extensive documentation and community support
- Seamless integration with PyTorch and TensorFlow
Cons of transformers
- Larger codebase, potentially more complex for beginners
- May include unnecessary features for specific use cases
- Requires more computational resources for some models
Code comparison
transformers:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased")
promptsource:
from promptsource.templates import DatasetTemplates
dataset = "squad"
templates = DatasetTemplates(dataset)
prompt = templates["generate_question_given_context"]
Summary
transformers is a comprehensive library for working with transformer models, offering extensive support and integration with popular deep learning frameworks. It provides a wide range of pre-trained models and tools for various NLP tasks. However, its large codebase may be overwhelming for beginners and might include unnecessary features for specific use cases.
promptsource, on the other hand, focuses on prompt engineering and dataset templating. It offers a more specialized approach to working with prompts and datasets, making it potentially easier to use for specific prompt-related tasks. However, it may lack the broader functionality and model support provided by transformers.
A framework for few-shot evaluation of language models.
Pros of lm-evaluation-harness
- More comprehensive evaluation suite with a wider range of tasks and metrics
- Better support for distributed evaluation across multiple GPUs
- More active development and community contributions
Cons of lm-evaluation-harness
- Steeper learning curve for new users
- Less focus on prompt engineering and template creation
- Requires more computational resources for full evaluation suite
Code Comparison
lm-evaluation-harness:
from lm_eval import evaluator, tasks
results = evaluator.simple_evaluate(
model="gpt2",
tasks=["hellaswag", "winogrande"],
num_fewshot=2,
)
promptsource:
from promptsource.templates import DatasetTemplates
templates = DatasetTemplates("squad")
prompt = templates["generate_question_by_answer"]
result = prompt.apply(example)
The lm-evaluation-harness code focuses on model evaluation across multiple tasks, while promptsource emphasizes prompt generation and application for specific datasets. lm-evaluation-harness provides a more streamlined approach for comprehensive model assessment, whereas promptsource offers greater flexibility in prompt engineering and dataset-specific template creation.
Build high-quality LLM apps - from prototyping, testing to production deployment and monitoring.
Pros of PromptFlow
- More comprehensive workflow management for prompt engineering
- Integrated with Azure AI services for easier deployment
- Supports multiple programming languages (Python, TypeScript)
Cons of PromptFlow
- Steeper learning curve due to more complex features
- Requires Azure account for full functionality
- Less focus on dataset-specific prompt generation
Code Comparison
PromptFlow (Python):
from promptflow import tool
@tool
def my_python_tool(input1: str, input2: int) -> str:
return f"Processed {input1} with {input2}"
PromptSource (Python):
from promptsource.templates import Template
template = Template(
name="example_template",
jinja="Generate a response for: {{ input }}",
reference="",
metadata={}
)
PromptFlow offers a more structured approach to defining tools and workflows, while PromptSource focuses on creating and managing prompt templates for specific datasets. PromptFlow's integration with Azure services makes it more suitable for production environments, whereas PromptSource is better suited for research and experimentation with prompt engineering across various datasets.
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
Pros of DeepSpeed
- Focuses on optimizing and scaling deep learning training
- Offers advanced distributed training techniques
- Provides significant speed improvements for large models
Cons of DeepSpeed
- Steeper learning curve for implementation
- Primarily targets large-scale training scenarios
- May be overkill for smaller projects or simpler models
Code Comparison
DeepSpeed:
import deepspeed
model_engine, optimizer, _, _ = deepspeed.initialize(
args=args,
model=model,
model_parameters=params
)
PromptSource:
from promptsource.templates import DatasetTemplates
templates = DatasetTemplates("squad")
prompt = templates["generate_question_by_answer"].apply(example)
Key Differences
- DeepSpeed is a deep learning optimization library, while PromptSource is a toolkit for prompt engineering
- DeepSpeed targets performance and scalability, PromptSource focuses on dataset preparation and prompt generation
- DeepSpeed is more suitable for large-scale model training, while PromptSource is useful for NLP task preparation
Use Cases
- DeepSpeed: Training large language models, distributed deep learning
- PromptSource: Preparing datasets for prompt-based learning, generating diverse prompts for NLP tasks
Community and Support
- DeepSpeed: Backed by Microsoft, active development, extensive documentation
- PromptSource: Part of BigScience workshop, community-driven, focused on prompt engineering research
Tool Learning for Big Models, Open-Source Solutions of ChatGPT-Plugins
Pros of BMTools
- Offers a wider range of tools and functionalities for language model interactions
- Provides a more comprehensive framework for building and deploying AI agents
- Includes pre-built tools for various tasks like web browsing, image generation, and code execution
Cons of BMTools
- May have a steeper learning curve due to its broader scope and complexity
- Less focused on prompt engineering and dataset creation compared to promptsource
- Potentially requires more setup and configuration for specific use cases
Code Comparison
promptsource:
from promptsource.templates import DatasetTemplates
dataset = DatasetTemplates("squad")
template = dataset["QA"]
prompt = template.apply(example)
BMTools:
from bmtools import load_tool
web_browser = load_tool("web_browser")
result = web_browser.run("Search for latest AI news")
Summary
BMTools offers a more comprehensive toolkit for AI agent development, while promptsource focuses on prompt engineering and dataset creation. BMTools provides a wider range of functionalities but may be more complex to use, whereas promptsource is more specialized in its approach to prompt generation and dataset manipulation.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
PromptSource
PromptSource is a toolkit for creating, sharing and using natural language prompts.
Recent work has shown that large language models exhibit the ability to perform reasonable zero-shot generalization to new tasks. For instance, GPT-3 demonstrated that large language models have strong zero- and few-shot abilities. FLAN and T0 then demonstrated that pre-trained language models fine-tuned in a massively multitask fashion yield even stronger zero-shot performance. A common denominator in these works is the use of prompts which has gained interest among NLP researchers and engineers. This emphasizes the need for new tools to create, share and use natural language prompts.
Prompts are functions that map an example from a dataset to a natural language input and target output. PromptSource contains a growing collection of prompts (which we call P3: Public Pool of Prompts). As of January 20, 2022, there are ~2'000 English prompts for 170+ English datasets in P3.
PromptSource provides the tools to create, and share natural language prompts (see How to create prompts, and then use the thousands of existing and newly created prompts through a simple API (see How to use prompts). Prompts are saved in standalone structured files and are written in a simple templating language called Jinja. An example of prompt available in PromptSource for SNLI is:
{{premise}}
Question: Does this imply that "{{hypothesis}}"? Yes, no, or maybe? ||| {{answer_choices[label]}}
You can browse through existing prompts on the hosted version of PromptSource.
Setup
If you do not intend to create new prompts, you can simply run:
pip install promptsource
Otherwise, you need to install the repo locally:
- Download the repo
- Navigate to the root directory of the repo
- Run
pip install -e .
to install thepromptsource
module
Note: for stability reasons, you will currently need a Python 3.7 environment to run the last step. However, if you only intend to use the prompts, and not create new prompts through the interface, you can remove this constraint in the setup.py
and install the package locally.
How to use prompts
You can apply prompts to examples from datasets of the Hugging Face Datasets library.
# Load an example from the datasets ag_news
>>> from datasets import load_dataset
>>> dataset = load_dataset("ag_news", split="train")
>>> example = dataset[1]
# Load prompts for this dataset
>>> from promptsource.templates import DatasetTemplates
>>> ag_news_prompts = DatasetTemplates('ag_news')
# Print all the prompts available for this dataset. The keys of the dict are the UUIDs the uniquely identify each of the prompt, and the values are instances of `Template` which wraps prompts
>>> print(ag_news_prompts.templates)
{'24e44a81-a18a-42dd-a71c-5b31b2d2cb39': <promptsource.templates.Template object at 0x7fa7aeb20350>, '8fdc1056-1029-41a1-9c67-354fc2b8ceaf': <promptsource.templates.Template object at 0x7fa7aeb17c10>, '918267e0-af68-4117-892d-2dbe66a58ce9': <promptsource.templates.Template object at 0x7fa7ac7a2310>, '9345df33-4f23-4944-a33c-eef94e626862': <promptsource.templates.Template object at 0x7fa7ac7a2050>, '98534347-fff7-4c39-a795-4e69a44791f7': <promptsource.templates.Template object at 0x7fa7ac7a1310>, 'b401b0ee-6ffe-4a91-8e15-77ee073cd858': <promptsource.templates.Template object at 0x7fa7ac7a12d0>, 'cb355f33-7e8c-4455-a72b-48d315bd4f60': <promptsource.templates.Template object at 0x7fa7ac7a1110>}
# Select a prompt by its name
>>> prompt = ag_news_prompts["classify_question_first"]
# Apply the prompt to the example
>>> result = prompt.apply(example)
>>> print("INPUT: ", result[0])
INPUT: What label best describes this news article?
Carlyle Looks Toward Commercial Aerospace (Reuters) Reuters - Private investment firm Carlyle Group,\which has a reputation for making well-timed and occasionally\controversial plays in the defense industry, has quietly placed\its bets on another part of the market.
>>> print("TARGET: ", result[1])
TARGET: Business
In the case that you are looking for the prompts available for a particular subset of a dataset, you should use the following syntax:
dataset_name, subset_name = "super_glue", "rte"
dataset = load_dataset(f"{dataset_name}/{subset_name}", split="train")
example = dataset[0]
prompts = DatasetTemplates(f"{dataset_name}/{subset_name}")
You can also collect all the available prompts for their associated datasets:
>>> from promptsource.templates import TemplateCollection
# Get all the prompts available in PromptSource
>>> collection = TemplateCollection()
# Print a dict where the key is the pair (dataset name, subset name)
# and the value is an instance of DatasetTemplates
>>> print(collection.datasets_templates)
{('poem_sentiment', None): <promptsource.templates.DatasetTemplates object at 0x7fa7ac7939d0>, ('common_gen', None): <promptsource.templates.DatasetTemplates object at 0x7fa7ac795410>, ('anli', None): <promptsource.templates.DatasetTemplates object at 0x7fa7ac794590>, ('cc_news', None): <promptsource.templates.DatasetTemplates object at 0x7fa7ac798a90>, ('craigslist_bargains', None): <promptsource.templates.DatasetTemplates object at 0x7fa7ac7a2c10>,...}
You can learn more about PromptSource's API to store, manipulate and use prompts in the documentation.
How to create prompts
PromptSource provides a Web-based GUI that enables developers to write prompts in a templating language and immediately view their outputs on different examples.
There are 3 modes in the app:
- Sourcing: create and write new prompts
- Prompted dataset viewer: check the prompts you wrote (or the existing ones) on the entire dataset
- Helicopter view: aggregate high-level metrics on the current state of P3
To launch the app locally, please first make sure you have followed the steps in Setup, and from the root directory of the repo, run:
streamlit run promptsource/app.py
You can also browse through existing prompts on the hosted version of PromptSource. Note the hosted version disables the Sourcing mode (streamlit run promptsource/app.py -- --read-only
).
Writing prompts
Before creating new prompts, you should read the contribution guidelines which give an step-by-step description of how to contribute to the collection of prompts.
Datasets that require manual downloads
Some datasets are not handled automatically by datasets
and require users to download the dataset manually (story_cloze
for instance ).
To handle those datasets as well, we require users to download the dataset and put it in ~/.cache/promptsource
. This is the root directory containing all manually downloaded datasets.
You can override this default path using PROMPTSOURCE_MANUAL_DATASET_DIR
environment variable. This should point to the root directory.
Development structure
PromptSource and P3 were originally developed as part of the BigScience project for open research ð¸, a year-long initiative targeting the study of large models and datasets. The goal of the project is to research language models in a public environment outside large technology companies. The project has 600 researchers from 50 countries and more than 250 institutions.
In particular, PromptSource and P3 were the first steps for the paper Multitask Prompted Training Enables Zero-Shot Task Generalization.
You will find the official repository to reproduce the results of the paper here: https://github.com/bigscience-workshop/t-zero. We also released T0* (pronounce "T Zero"), a series of models trained on P3 and presented in the paper. Checkpoints are available here.
Known Issues
Warning or Error about Darwin on OS X: Try downgrading PyArrow to 3.0.0.
ConnectionRefusedError: [Errno 61] Connection refused: Happens occasionally. Try restarting the app.
Citation
If you find P3 or PromptSource useful, please cite the following reference:
@misc{bach2022promptsource,
title={PromptSource: An Integrated Development Environment and Repository for Natural Language Prompts},
author={Stephen H. Bach and Victor Sanh and Zheng-Xin Yong and Albert Webson and Colin Raffel and Nihal V. Nayak and Abheesht Sharma and Taewoon Kim and M Saiful Bari and Thibault Fevry and Zaid Alyafeai and Manan Dey and Andrea Santilli and Zhiqing Sun and Srulik Ben-David and Canwen Xu and Gunjan Chhablani and Han Wang and Jason Alan Fries and Maged S. Al-shaibani and Shanya Sharma and Urmish Thakker and Khalid Almubarak and Xiangru Tang and Xiangru Tang and Mike Tian-Jian Jiang and Alexander M. Rush},
year={2022},
eprint={2202.01279},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
Top Related Projects
🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
A framework for few-shot evaluation of language models.
Build high-quality LLM apps - from prototyping, testing to production deployment and monitoring.
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
Tool Learning for Big Models, Open-Source Solutions of ChatGPT-Plugins
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot