Prompt Engineering for ChatGPT
Lecturer: Jules White, Vanderbilt University (Coursera)
Presenter: Xingyu Xie
Overview
- What are Large Language Models?
- What are Prompts?
- Points for effective prompts
- Prompt pattern examples
Large Language Model Basics
- What are Large Language Models?
- Randomness in output
What is ChatGPT?
Basic Principles of LLMs
原理:预测下一个单词!
Mary Had a Little Lamb 是一首经典童谣,在训练集中 ChatGPT 见过很多遍,所以它学会了这首童谣。告诉它前几个词,它就可以猜出下一个词。
注:所有对话都会被发给 ChatGPT,用来生成回复,比如如果我在前面说了一些中文,再跟它讲“Mary had a little”
Randomness in LLMs
Predict not only the next word but a distribution of the next words.
What are Prompts?
- What is a prompt?
- Intuition behind prompts
What are Prompts?
- To cause or encourage someone to do something
- Done without delay
- A cue or reminder that helps someone remember
- A message that appears on a computer, asking the user for input
- Adding new information
- Provide format
Examples
"strong" and "weak" prompts
- Some prompts may lead to almost the same outputs every time, while others may lead to different outputs after regenerating. We say that the former is strong and the latter is weak.
a weak prompt
a strong prompt
"general" and "specific" prompts
General prompts stimulate general responses, and specific prompts stimulate specific responses.
Intro to Prompt Patterns
- Prompt Patterns
- The Persona Pattern
- Root Prompts
Prompt Patterns
- Persona: 让 ChatGPT 饰演一个角色
- Root: 在对话的开头做一些“初始化”。
Effective Prompts
- Few-shot Examples
- Chain of Thought Prompting
- Using Large Language Models to Grade Each Other
Few-shot examples
Rather than instructing a task, ChatGPT can directly learn a task (pattern) from examples given in the prompts.
Consider examples from the FlashFill paper, 12/14 are solved at here.
Few-shot examples
Summarize the task from a few examples in natural language.
Few-shot examples
A subtle "filter" pattern: if Input1 contains "pictures", output equals input2, otherwise, output is 0.
Summarize the task from a few examples in natural language.
Few-shot examples
Examples of different formats.
Chain of Thought
- 要求它推理,可以让它的答案更准确。
- 如果把问题分解成很多步,每一步 GPT 都是可以做对的,那么通过正确的推理,它就能比较自然的得到一个正确的答案。
Chain of thought (con't)
- 一个错误的例子
- 检查过后,发现其实 ChatGPT 踩的坑都是出题人设计的坑
Using LLMs to grade each other
First, teach ChatGPT how to grade a prompt by few-shot examples.
Second, ask ChatGPT to grade a prompt.
Prompt Patterns Catalog
- Game Play Pattern:让 ChatGPT 控制对话,人跟它玩一个游戏
- Template Pattern:给出回复的模板
- Meta Language Pattern:定义新的语言和记号,比如“->”
- Outline Expansion Pattern:先写大纲,然后展开大纲中的点
- Menu Actions Pattern:定义一些“操作”函数
- Tail Generation Pattern:在每次回复最后“复习”规则
Example: 在游戏中学习写 prompt
让 ChatGPT 来“控制”对话。
Example: 如何让 ChatGPT 写长文
Tail for remembering
Define an action "write"
Outline Expansion
Take-away
- Principle: predict next word!
- given all previous conversation
- Usage:
- knowledge & Ideas
- language understanding
- Prompt:
- Tell it as it is a human assistant!
- Root: persona/template/...
- Keep trying!
- Flaw:
- forgetting
- illusion
Prompt Engineering for ChatGPT
By Xingyu Xie
Prompt Engineering for ChatGPT
- 5