当前位置:   article > 正文

技术动态 | 面向NLP任务的大模型Prompt设计

老刘说nlp

转载公众号 | 老刘说NLP


很久之前,我们介绍到,prompt是影响下游任务的关键所在,当我们在应用chatgpt进行nlp任务落地时,如何选择合适的prompt,对于SFT以及推理环节尤为重要。

不过,硬想不是办法,我们可以充分参考开源的一些已有工作,幸运的是,这类工作已然存在。

因此,本文主要介绍longbench、LooGLE、pclue以及firefly自然语言处理任务prompt以及PromptSource英文常用评测任务prompt生成工具包。

一、其他一些关于NLP任务的代表prompt

最近我们在看长文本说的一些评估数据集,而对于评估来说,如何针对不同的任务,设定相应的prompt,最为重要。下面介绍longbench、LooGLE、pclue以及firefly自然语言处理任务prompt。

1、longbench长文本prompt

地址:https://github.com/THUDM/LongBench

851c86c77dd9cc50e80c47c8cb92c50d.png

343460dd0fa4c4c7d41f0b534dd16b15.png

2、LooGLE长文本评测prompt

地址:https://github.com/bigai-nlco/LooGLE

f661e9d6584831fdd1c121fb39faf05e.png

4、Pclue任务评测prompt

地址:https://github.com/CLUEbenchmark/pCLUE

baf226ec16fb2aaa8bf7789c88649ff2.png

b8a4e94805c20a49c1896f4701d3a795.png

3747c9dd143a66c4b640fa5c0d4068ea.png

4、firefly自然语言处理任务prompt

地址:https://huggingface.co/datasets/YeungNLP/firefly-train-1.1M/viewer/default/train?row=3

586720cdc102d6d73c59de89e8967de9.png

二、PromptSource英文NLP prompt生成工具

PromptSource是一个用于创建、共享和使用自然语言提示的工具包,截至2022年1月20日,P3中有约2000个prompt,涵盖170多个英语数据集。

a6a70e5fdac16e89f5d0dd1e6d169019.png

项目地址:https://github.com/bigscience-workshop/promptsource

1、storycloze的prompt

  1. templates:
  2.   1a4946f9-a0e2-4fbb-aee8-b26ead2cf6b8: !Template
  3.     answer_choices: '{{sentence_quiz1}} ||| {{sentence_quiz2}}'
  4.     id: 1a4946f9-a0e2-4fbb-aee8-b26ead2cf6b8
  5.     jinja: '{{input_sentence_1}} {{input_sentence_2}} {{input_sentence_3}} {{input_sentence_4}}
  6.       What is a possible continuation for the story given the following options ?
  7.       - {{answer_choices | join("\n- ")}} ||| {{answer_choices[answer_right_ending
  8.       -1]}}'
  9.     metadata: !TemplateMetadata
  10.       choices_in_prompt: true
  11.       languages:
  12.       - en
  13.       metrics:
  14.       - Accuracy
  15.       original_task: true
  16.     name: Answer Given options
  17.     reference: ''
  18.   1a9d53bc-eb77-4e7c-af6e-3d15b79d6cf1: !Template
  19.     answer_choices: '{{sentence_quiz1}} ||| {{sentence_quiz2}}'
  20.     id: 1a9d53bc-eb77-4e7c-af6e-3d15b79d6cf1
  21.     jinja: "Read the following story :\n\n{{input_sentence_1}}\n{{input_sentence_2}}\n\
  22.       {{input_sentence_3}}\n{{input_sentence_4}}\n\nChoose a possible ending for the\
  23.       \ previous story from the following options: \n- {{answer_choices | join(\"\\\
  24.       n- \")}}\n|||\n\n{{answer_choices[answer_right_ending -1]}}"
  25.     metadata: !TemplateMetadata
  26.       choices_in_prompt: true
  27.       languages:
  28.       - en
  29.       metrics:
  30.       - Accuracy
  31.       original_task: true
  32.     name: Choose Story Ending
  33.     reference: ''

2、Squad任务的prompt

  1. templates:
  2.   3d85b5b0-51db-4d72-8ead-d0b3654025ee: !Template
  3.     answer_choices: null
  4.     id: 3d85b5b0-51db-4d72-8ead-d0b3654025ee
  5.     jinja: 'Refer to the passage below and answer the following question:
  6.       Passage: {{context}}
  7.       Question: {{question}}
  8.       |||
  9.       {{answers["text"][0]}}'
  10.     metadata: !TemplateMetadata
  11.       choices_in_prompt: false
  12.       languages:
  13.       - en
  14.       metrics:
  15.       - Squad
  16.       original_task: true
  17.     name: answer_question_given_context
  18.     reference: ''

3、MathQA任务的prompt

  1. a313a5f8-53cd-4b76-abb6-fea2ac4e9ef4: !Template
  2.     answer_choices: a ||| b ||| c ||| d ||| e
  3.     id: a313a5f8-53cd-4b76-abb6-fea2ac4e9ef4
  4.     jinja: "One of the five choices are correctly answers the math problem. Can you\
  5.       \ choose the right one? \n\n{{options}}\n\nProblem: {{Problem}}\n|||\n{{correct}}"
  6.     metadata: !TemplateMetadata
  7.       choices_in_prompt: true
  8.       languages:
  9.       - en
  10.       metrics:
  11.       - Accuracy
  12.       original_task: true
  13.     name: first_choice_then_problem
  14.     reference: First give the list of choices and then describe the problem
  15.   a3c2ec72-4af5-42aa-9e8e-ef475fa7c039: !Template
  16.     answer_choices: general ||| physics ||| gain ||| geometry ||| probability |||
  17.       other
  18.     id: a3c2ec72-4af5-42aa-9e8e-ef475fa7c039
  19.     jinja: "Given the problem below, in what category would you classify it?\n===\n\
  20.       {{Problem}} \n\nCategories:\n{{answer_choices | join(\"\\n\")}}\n|||\n{{category}}\n"
  21.     metadata: !TemplateMetadata
  22.       choices_in_prompt: true
  23.       languages:
  24.       - en
  25.       metrics:
  26.       - Accuracy
  27.       original_task: false
  28.     name: problem_set_type
  29.     reference: The template asks to generate the category of the problem set

4、使用方式

  1. # Load an example from the datasets ag_news
  2. >>> from datasets import load_dataset
  3. >>> dataset = load_dataset("ag_news", split="train")
  4. >>> example = dataset[1]
  5. # Load prompts for this dataset
  6. >>> from promptsource.templates import DatasetTemplates
  7. >>> ag_news_prompts = DatasetTemplates('ag_news')
  8. # 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
  9. >>> print(ag_news_prompts.templates)
  10. {'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>}
  11. # Select a prompt by its name
  12. >>> prompt = ag_news_prompts["classify_question_first"]
  13. # Apply the prompt to the example
  14. >>> result = prompt.apply(example)
  15. >>> print("INPUT: ", result[0])
  16. INPUT:  What label best describes this news article?
  17. 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.
  18. >>> print("TARGET: ", result[1])
  19. TARGET:  Business

总结

本文主要介绍了PromptSource英文常用评测任务prompt生成工具包以及现有NLP的一些prompt,这些对我们进行信息抽取等任务有很大的帮助。

对于具体的使用,大家可以参考参考文献链接进行进一步查看,并实践。

参考文献

1、https://github.com/bigscience-workshop/promptsource


OpenKG

OpenKG(中文开放知识图谱)旨在推动以中文为核心的知识图谱数据的开放、互联及众包,并促进知识图谱算法、工具及平台的开源开放。

4e20e92206657d5716c2f4251bd0dec0.png

点击阅读原文,进入 OpenKG 网站。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/759186
推荐阅读
相关标签
  

闽ICP备14008679号