提示Source是用于创建,共享和使用自然语言提示的工具包。
最近的工作表明,大型语言模型具有对新任务进行合理的零弹性概括的能力。例如,GPT-3证明了大语言模型具有强大的零和少数能力。弗兰(Flan)和T0随后证明,以大量多任务时尚的方式微调的预训练的语言模型甚至更强的零击性能。这些作品中的共同点是使用提示,该提示引起了NLP研究人员和工程师的兴趣。这强调了需要创建,共享和使用自然语言提示的新工具的必要性。
提示是将示例从数据集绘制到自然语言输入和目标输出的示例的功能。提示库包含越来越多的提示(我们称为P3 : P ROMPTS的P 3)。截至2022年1月20日,P3中有170多个英语数据集的英文提示约为2'000。

提示提供了创建和共享自然语言提示的工具(请参阅如何创建提示,然后通过简单的API使用数千个现有和新创建的提示(请参阅如何使用提示)。提示保存在独立的结构化文件中,并以简单的模板语言编写,称为Jinja。
{{premise}}
Question: Does this imply that "{{hypothesis}}"? Yes, no, or maybe? ||| {{answer_choices[labe l] }}您可以浏览托管版提示版中的现有提示。
如果您不打算创建新提示,则可以简单地运行:
pip install promptsource否则,您需要在本地安装回购:
pip install -e .要安装promptsource模块注意:出于稳定原因,您目前需要一个Python 3.7环境才能运行最后一步。但是,如果您只打算使用这些提示,而不是通过接口创建新提示,则可以在setup.py中删除此约束并在本地安装软件包。
您可以将提示应用到来自拥抱面部数据集库数据集的示例。
# 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如果您正在寻找可用于数据集特定子集的提示,则应使用以下语法:
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 } " )您还可以为其关联数据集收集所有可用的提示:
> >> 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 > ,...}您可以了解有关提示的API的更多信息,以存储,操纵和使用文档中的提示。
提示Source提供了基于Web的GUI,使开发人员能够以模板语言编写提示,并在不同示例中立即查看其输出。
应用中有3种模式:

要在本地启动该应用程序,请首先确保您遵循设置的步骤,从仓库的根目录中运行:
streamlit run promptsource/app.py您也可以在提示索的托管版本上浏览现有提示。请注意,托管版本禁用采购模式( streamlit run promptsource/app.py -- --read-only )。
在创建新提示之前,您应该阅读贡献指南,该指南逐步描述如何为提示的收集贡献。
某些数据集不是由datasets自动处理的,并且要求用户手动下载数据集(例如, story_cloze )。
为了处理这些数据集,我们要求用户下载数据集并将其放入~/.cache/promptsource中。这是包含所有手动下载数据集的根目录。
您可以使用PROMPTSOURCE_MANUAL_DATASET_DIR环境变量覆盖此默认路径。这应该指向根目录。
提示和P3最初是作为开放研究的Bigscience项目的一部分而开发的,这是针对大型模型和数据集研究的为期一年的计划。该项目的目的是在大型技术公司以外的公共环境中研究语言模型。该项目拥有来自50个国家 /地区的600名研究人员和250多家机构。
特别是,提示库和P3是纸张多任务提示培训的第一步,可以使零击任务概括。
您会在此处找到官方存储库来重现本文的结果:https://github.com/bigscience-workshop/t-zerero。我们还发布了T0*(发音为“ T Zero”),这是一系列在P3上训练并在论文中呈现的模型。检查点可在此处找到。
OS X上有关Darwin的警告或错误:尝试将Pyarrow降级至3.0.0。
ConnectionRefusedError:[ERRNO 61]连接拒绝:偶尔发生。尝试重新启动应用程序。
如果您发现P3或提示有用,请引用以下参考:
@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 }
}