Probably you’ve heard a lot about ChatGPT and large language models that it is like they are plagiarism tools and helping students writing essays. But the truth is, the best way to leverage the immense capabilities of ChatGPT and large language models are to explore concepts, get ideas, and refine them over interactions. To use them effectively, you have to be a skilled writer, a creative thinker, and a great problem solver. The more creative you are, the better the outputs are going to be.
The way we tap into these immense capabilities of large language models is by using a pattern (for example a persona pattern) when writing a prompt, which is something we ask the model to act like a particular persona. With a little bit of the right structure in the prompts, we can create really powerful ways of giving form to our ideas and our thoughts, through large language models like ChatGPT.
Simply put, large language models use contextual knowledge to generate text word-by-word. We (the users of these models) produce prompts which will trigger the model to produce the next and the next words. Large language models are “large” because they have so many different parameters, they were trained on so much data and they have learned the patterns from our human languages.
Large language models keep evolving. More than likely, some parts of the discipline of prompt engineering are going to be hopefully timeless, while other parts of it will probably evolve and adapt as the different capabilities of these models evolve. What you’ll want to do is always have that openness to experimentation, to creativity, and to trying things out. There’s always some randomness, some ability to generate new and different ideas each time you put a prompt in. And this can be really good sometimes.
On the other hand, if we’re trying to have the large language model do some type of reasoning on a system, we may not want it to have a lot of variation on what it gives us out. We need certainty. A lot of the prompt engineering techniques are going to be dealing with this randomness, and get the large language models to do certain things.
Prompts
“Prompt” is more than just a question that you are asking to the large language model. It can be a call to action to the large language model, meanwhile, it can also be soliciting information from users, i.e. asking us (human) for input. Prompt can be something immediate, but it does not have to be. It can setup a context for the conversation and continue to influence the output of the model. We can use a prompt to provide information to the large language model about what happened after it was trained.
One of the most important things we can do in a prompt is provide the large language model with information that it doesn’t have access to. All we have to do is up front in the prompt, we give it the data. It’s really important that we provided enough information to make sound decisions. We don’t go and retrain. We don’t go and do some weird thing behind the scenes, we just put it into the prompt. Then we give it the instruction that we’re looking for.
Prompts As Conversations
Opposed to thinking about asking a question and getting the answer, or giving an instruction and getting a result, the most powerful ways of working with a large language model is to think about a prompt as a conversation. Conversations are all about refining either our understanding to build some shared understanding or to interact together in order to solve a problem.
We can’t go and create a prompt of unlimited size. Every single large language model is going to have some fundamental limit on how much we can put into our prompt and send to it. This is an important thing to note because it has a lot of ramifications on thinking about prompt design. What do we do?
- Query and get a subset of information that are relevant.
- Filter and remove information that is extraneous.
- Summarize and compress in order to preserve aspects of the information.
Root Prompt
The root prompt is basically a seed to the whole conversation and that seed will influence everything that comes later. All of the tools are going to have some probably root prompts that try to put guard rails on what can and can’t be done, for instance, doesn’t say anything offensive, do harm, suggest inappropriate actions. But also to try to make the output more important. Now, one of the things that we’ve seen in the community is people try to figure out how:
- Figure out what are the root prompts that were built into these systems
- Trick the tool into disregarding whatever the root prompt was
- Generate prompts that will override those root prompts
Prompt Patterns
A prompt pattern is a way that we document a certain structure of phrases and statements in order to solve a particular problem in with a large language model. If we know the right patterns, we can tap into things that the model has been trained on and seen over and over again, we will be more likely to get a particular sort of ability to tap into the model and get a consistent response. So when you are writing a prompt, always ask the questions that:
- “What patterns do I have in the prompt?”
- “What patterns will probably tap into the large language model was trained on?”
- “Is the prompt really specific and providing enough detail?”
If there’s a very strong pattern in the prompt, you’re more likely to get a response to that pattern, and the model will know the right level of detail to put into the output. Further more, you can actually use prompts to program the interaction, for example; ask language model to generate data in comma separated value (CSV) format.
When you want to build really sophisticated prompts, you will start combining different patterns together. You need to think through how to apply multiple patterns in conjunction with each other in order to solve the problem that you’re dealing with. When you’re trying to tackle some new complicated prompt, you want to think about:
- What is the fundamental pieces to this problem?
- Do I have existing patterns that I know about that I can use to hopefully tackle all of it?
- If I can’t tackle all of it, can I use patterns and apply them to as many different pieces as possible so that the unknown piece is as small as possible?
Persona Pattern
In the real world, if you had an accounting question, you would call up your accountant and ask for their advice. The accountant is an example of persona that you will go to. When interacting with language models, the persona pattern is meant to give us that same type of behavior, to allow us to go to that expert and ask that question, without having to know what exactly the experts is going to say, how they’re going to format it, or what they might know or not know. A typical persona pattern starts with:
Act as [a persona], ...
This is a very information dense pattern and statement that can trigger all kinds of different behavior. For instance:
You
Act as the linux terminal
ChatGPT
Sure, go ahead and type in the Linux terminal command you'd like to execute, and I'll respond with the output.
Then I said ls -alt
, I got this response from ChatGPT:
You:
ls -alt
ChatGPT:
total 64
drwxr-xr-x 8 user user 4096 Feb 28 12:00 .
drwxr-xr-x 5 user user 4096 Feb 28 11:45 Documents
drwxr-xr-x 3 user user 4096 Feb 28 11:30 Downloads
drwxr-xr-x 2 user user 4096 Feb 28 11:15 Pictures
drwxr-xr-x 2 user user 4096 Feb 28 11:10 Music
drwxr-xr-x 2 user user 4096 Feb 28 11:05 Videos
drwxr-xr-x 2 user user 4096 Feb 28 10:55 Desktop
I only gave ChatGPT a little information (the persona) but the persona pattern is giving my really powerful behavior, ChatGPT’s giving us output that looks like a computer. You can create all kinds of interesting personas to produce output for, even the persona is an inanimate object.
Question Refinement Pattern
When we want to ask questions about a particular topic, we may not have as much information or underlying thought behind our question as chat GPT has from it’s training data. So the idea behind this simple pattern is that we watch the response from large language models whenever we ask a question to try to improve our question:
- Intuitively we use a general question to tap into the large language model
- Understand the pattern on which the large language mode was trained
- Create an improved version of original question
A typical question refinement pattern is like:
Whenever I ask a question, suggest a better question and ask me if I would like to use it instead.
This is a really nice pattern because once we’ve turned it on, we can begin asking questions and automatically getting better versions of our question. It also helps us to realize a question can be asked in many different ways, and help us to reflect on what we’re asking for. More pieces of information that may be needed to make an effective decision.
Cognitive Verifier Pattern
In many cases, large language models can actually reason better if they break a problem down into a bunch of smaller problems. A simple way to do that is just to ask the large language model to always take questions or problems and subdivide them into a series of individual questions or sub problems that could be useful in answering the overall question or in solving the overall problem.
When you are asked a question, follow these rules:
1. Generate a number of additional questions that would help more accurately answer the question.
2. Combine the answers to the individual questions to produce the final answer to the overall question.
Audience Persona Pattern
Above we talked about Persona Pattern, which focuses on who the large language model is supposed to act like. But sometime, we want large language models to produce an output for a particular persona, this is called audience persona pattern.
Explain ... to me. Assume that I am ...
Flipped Interaction Pattern
Whenever we want the large language model to ask us questions, the pattern that we can use is called flipped interaction pattern. This is incredibly helpful when you don’t necessarily know everything that’s needed. When you need to collect information and then take action, this pattern is really helpful.
Ask me questions about ... until you have enough information to suggest ...
When you have enough information, show me ...
Then if you want to get that one question at a time conversation, usually a reliable way of doing that is to say:
Ask me the first question now.
Game Play Pattern
Playing games is a great way to learn new topic or improve your skills. The idea behind this pattern is to ask ChatGPT to play a game with us. Usually the large language models are the game master in most cases, they know all the rules and drive the game. The nice thing is that if we say create a game and we give it some basic structure around the game, the large language model can tap into its training data in order to populate the game with content. The basic pattern of this is to say:
We are going to play a game involving ...
Then we decide some more information about what are the rules of the game:
You are going to give me a simple task that can be accomplished via prompting you.
I will try to write a prompt for you to solve the task.
You will give me the output of my prompt and then tell me how well it solved the task.
Ask me questions until I tell you to stop.
Your task should ...
Template Pattern
Getting a large language models output in exactly the format that we want can be a challenge. This pattern is basically giving the large language model a template and then the model is going to fill in your template.
I am going to give you a template for your output. CAPITALIZED WORDS are my placeholders. Fill in my placeholders with your output. My template is:
...
The placeholder can not only format the information, do simple extracting and matching, but it can also follow rules or do time-consuming things like extracting information that would require a human to read through, understand and then put it in.
Meta Language Creation Pattern
Describing everything in full sentences in whatever language you speak isn’t always the easiest way to give the input to the large language model. We may create our own little languages (like shorthand notation) to able to capture information in a more concise way than if we wrote it out in full sentences. But these languages are usually designed for specific group of people who use it day-in and day-out.
We can teach large language model a new language (like shorthand notation) then communicate with the model in that new language. This is called the Meta Language Creation pattern. Note the notation is much shorter than the full sentence.
I am going to create a trip route. To describe my route, I am going to use a shorthand notation.
When I say "Shanghai,3->London,2", I mean that my route will go from Shanghai to London, and I will stay 3 days in Shanghai, and 2 days in London.
Recipe Pattern
Sometimes we have a problem but know only part of the solution. We are providing essentially an incomplete recipe. We need the large language model to help us fill in the blanks, to put together the missing steps to complete a “recipe”.
Alternative Approaches Pattern
A large language model was trained on a big corpus of material and it’s probably seen lots of problems and seen discussions of different solutions to that problem or different alternative approaches for a particular problem. The idea behind the Alternative Approaches Pattern is within some particular scope, we always suggest alternative approaches for solving a particular problem or performing a particular task. It is like brainstorming in a group.
From now on, if there are alternative ways to accomplish the same thing, list the best alternative approaches. Compare and contrast the alternatives and ask me which one I want to use.
Ask for Input Pattern
We often want to set the rules, then apply them to an input that we are going to provide later. We want to get the large language model to listen to the rules and then ask us for the input to apply the rules to. The idea behind this is we just do one simple thing: at the end of the prompt, we tell the large language model to ask for the next input.
Here are the rules: ...
...
Now ask me for the first task/idea/thing/whatever...
Outline Expansion Pattern
Large language models fundamentally have a limit to the size of the input we can give them, and a limit on how much output they can generate at once. More than likely, everybody is going to face some limitation on how big we can go. Now the way that we work around that is we’re typically generating pieces of the solution, then we take them, put all the pieces back together. One of the ways that we can do that is to build an outline of what we’re trying to put together, and fill in the pieces once we’ve gotten enough detail into our outline.
The Outline Expansion Pattern can help us generate the outlines and continue to expand them down to the level of granularity that we need in order to build the individual pieces then be able to put them together.
Menu Action Pattern
When we have a long conversation, it can be helpful to develop and codify a set of actions that we can run, without repeat long prompts again and again. The Menu Action Pattern allows us develop a menu that is a series of actions that we can run. Actions are basically essentially a prompt. It’s basically a set of instructions that we’re going to give the large language model into order to do something at a particular point in the conversation.
Fact Check List Pattern
We can use the fact checklist pattern to help us figure out what facts are actually in the output and need to be followed up on.
Whenever you output text, generate a set of facts that are contained in the output.
The set of facts should be inserted at the end of the output.
This is a tool that can help us get into the fact checking of the output. However it may be incorrect, but we still don’t know for sure until we actually fully follow up on it.
Tail Generation Pattern
When we’re having a long conversation with a large language model, sometimes we’ll run into the challenge that the large language model will forget the rules of the game. It’ll forget what we’re trying to accomplish or what is the task that we’re working on. We need to remind the model what we are doing. We’d like it to remind itself if possible. In this pattern, we are going to generate a tail at the end of the output that the large language model produces that will help remind it what we’re doing.
Semantic Filter Pattern
Semantic Filter is basically a filter that can take in text and remove information from it or only keep information that has certain meaning or has a certain qualities that we specify. For example:
Filter this information to remove all dates and rewrite the text as little as possible to fix the issues caused by the date removals.
Prompting Techniques
Few-Shots Prompting
We can actually teach the large language model to follow a pattern using something called few-shot examples or few-shot prompting. The idea behind is we’re going to give the large language model examples of input that we would give it and then the output that we would expect. This is actually we are developing a pattern that the model can learn to follow. We’re basically showing it what we want it to do and how we want it to format the output within a series of examples. Prefixes are usually applied, say Input:
and Output:
, however which are too generic, and they don’t provide much information and context to the model. Actually we can use any words as prefixes, say Sentiment:
in the example below, which is actually telling the model that the output is about sentiment.
You
Input: The movie was good but a bit too long.
Sentiment: Neutral
Input: I didn't really like this book.
Sentiment: Negative
Input: I loved this book.
Sentiment: Positive
Input: I wasn't sure what to think of this new restrant.
ChatGPT
Sentiment: Neutral
Further more, large language models can actually do some planning. They can actually go through and take patterns and with few-shot examples and they can learn what the next action should be given a particular situation. Again, prefixes Situation:
and Action:
are used.
You
Situation: ....
Action: ...
Situation: ...
Action: ...
Situation: ...
Action: ...
Situation: ...
ChatGPT
Action: ...
The examples that we give in few shot prompts don’t have to just be an input and an output. We can actually show intermediate steps to reach a particular goal. When we begin showing the intermediate steps, the large language model can learn how to apply a series of intermediate steps in order to reach the goal.
Chain of Thought Prompting
When it comes to writing prompts, explanation of reasoning can be really, really important. Getting a large language model to explain its reasoning behind the scene actually can make the large language model perform better for us, because the right answer intuitively should come after the correct reasoning.
React Prompting
There are occasions that large language model need to use other tools to query new information. We can build prompts that can allow this happen. React prompting is the idea that we want to teach the large language model how to think through a process and understand steps where it needs to use some other tools, such as search engine, and takes some actions outside of it, and gets / incorporate the result of that tool.
This is similar to chain of thought prompting, but we’re going to expand the approach to have this concept of certain things that the large language model knows it needs to use some external tool to perform.
Task: ...
Think: ...
Action: SEARCH https://......
Result: ...
Trustworthy Generative AI
We want to facilitate the power of generative AI to do valuable work, to increase our productivity but in a way that is trustworthy. One of the most common inappropriate uses of these tools is to think of them as sources of facts. No, the purpose of the generative AI tools is a computational engine that can help you to do natural language analyses and various kinds of interesting things. It can help you navigate to facts, but it itself is not necessarily going to give you correct facts. You want to use it in a way where you put guardrails on it and you’re not trying to generate random, arbitrary stuff.
Hallucination is a primary reason that people don’t believe the output of this technology. However hallucination should not be treated as a bug, it is a feature if you use it properly. It is a part of the tool that makes technology amazingly suitable for brainstorming. To use it appropriately in a trustworthy way, you will have to elect the right problem, formulate the problem in right way, and do the prompt engineering correctly. One example of using generative AI correctly is to give generative AI all of the relevant documents and ask generative AI to summarize them, i.e. using it as a computational engine to summarize outline, to help answer the question with respect to facts that they’ve given.
If you’re going to use the output and if you require correctness, make sure that you can check the correctness very cheaply, easily. Or another way to think about it, is whether the cost to check the correctness of the answer lower than actually producing the answer in the first place ourselves? If your use case really requires correctness and you can’t easily check the correctness, you shouldn’t be going forward with it.
Instead of replacing people, generative AI amplify and augment human creativity and problem solving skills where it basically gives people new capabilities. How to achieve this augmented intelligence? The ACHIEVE framework will help develop a new vision:
- Aid human coordinate
- Cut out tedious tasks
- Help provide a safety net to make sure things aren’t missed
- Inspire bEtter problem solving and creatiVity
- Enable great ideas to scale faster
My Certificate
For more on ChatGPT: Prompt Engineering, please refer to the wonderful course here https://www.coursera.org/learn/prompt-engineering
I am Kesler Zhu, thank you for visiting my website. Check out more course reviews at https://KZHU.ai