Cookies are used for the best experience on my website.

Accept Cookie Policy

No internet detected

Check your connection and try again.

Logo Image

No match found

Buy a coffee

I launched this blog in 1995. Since then, we have published 1603 articles. It's all free and means a lot of work in my spare time. I enjoy sharing knowledge and experiences with you.

Your support

Have you learned something new by reading, listening, or watching my content? With your help, I can spend enough time to keep publishing great content in the future.

Or, select an option below:

A small slice of my data processing time each month

It's ongoing work running this site and what's really great is ongoing support. Here's a sense of what goes into this site: research topics for discussion. Manage the Tech stuff: website, SEO, graphics, email, back-end servers, DNS routing, edge servers. Create advertisements and load the campaigns in Google Ads. Manage the social media forums (Facebook, Reddit, Twitter). Write updates to the blog. Keep GitHub up-to-date.

$4.50 — A large cappuccino at my local

Things just work better with coffee! I like to take the kids to school then grab a cappuccino from my local on the way home before beginning the things that take mental energy.

$8.99 — A month of Netflix for some quiet nights in

A lot of the work on this happens after hours when I should be relaxing on the couch. Help me make it so and I promise to keep off the devices for a bit!

$11.50 — Fund a month of email delivery

This site sends out thousands of emails every month. For that volume and to ensure deliverability, I need to pay MailChimp.

$20 — Pay for one month of AWS storage fees

Websites are not free. The storage alone takes some cash. If you are willing to lighten the burden, we can keep this site up online.

$30 — One hour's pay for a graphics artist

Art doesn't create itself without a hand to guide it. I can't draw, so I need to pay others to help.

$45 — Pay a full-stack web developer for one hour

Much of the work on this site happens on weekends which means giving up time with the kids. Help me pay the developers so I can give my kids more time.

Using ChatGPT Wrong?

Most of us use ChatGPT wrong. Learn how to create ⋯

Author

The PyCoach


  • 1745

  • 10147

  • 4

  • 1

  • 0

Master ChatGPT by learning prompt engineering.

Image licensed from Shutterstock

Most of us use ChatGPT wrong.

We don’t include examples in our prompts.
We ignore that we can control ChatGPT’s behavior with roles.
We let ChatGPT guess stuff instead of providing it with some information.

This happens because we mostly use standard prompts that might help us get the job done once, but not all the time.

We need to learn how to create high-quality prompts to get better results. We need to learn prompt engineering! And, in this guide, we’ll learn 4 techniques used in prompt engineering.

🎥 GPT-4 Prompt Engineering: Be Better Than 99% ChatGPT Users | Video (12:48 minutes)
In this video, we’ll learn how to make the most of ChatGPT by learning prompt engineering.

Few Shot Standard Prompts 🔗

Few shot standard prompts are the standard prompts we’ve seen before, but with examples of the task in them.

Why examples? Well, If you want to increase your chances to get the desired result, you have to add examples of the task that the prompt is trying to solve.

Few-shot standard prompts consist of a task description, examples, and the prompt. In this case, the prompt is the beginning of a new example that the model should complete by generating the missing text.

Here are the components of few shot standard prompts.

Now let’s create another prompt. Say we want to extract airport codes from the text “I want to fly from Orlando to Boston”

Here’s the standard prompt that most would use.

Extract the airport codes from this text: “I want to fly from Orlando to Boston”

This might get the job done, but sometimes it might not be enough. In such cases, you have to use few shot standard prompts.

Extract the airport codes from this text:Text: “I want to fly from Los Angeles to Miami.”
Airport codes: LAX, MIAText: “I want to fly from Nashville to Kansas City.”
Airport codes: BNA, MCIText: “I want to fly from Orlando to Boston”
Airport codes:

If we try the previous prompt on ChatGPT, we’re going to get the airport code in the format we specified in the example (MCO, BOS)

Keep in mind that previous research found that the actual answers in the examples are not important, but the labelspace is. A labelspace is all the possible labels for a given task. You could improve the results of your prompts by even providing random labels from the labelspace.

Let’s test this by typing random airport codes in our example.

Extract the airport codes from this text:Text: “I want to fly from Los Angeles to Miami.”
Airport codes: DEN, OAKText: “I want to fly from Nashville to Kansas City.”
Airport codes: DAL, IDAText: “I want to fly from Orlando to Boston”
Airport codes:

If you tried the previous prompt on ChatGPT, you’ll still get the right airport codes MCO and BOS.

Whether your examples are correct or not, include random labels from the labelspace. This will help you improve results and instruct the model on how to format the answer to the prompt.

Role Prompting 🔗

Sometimes the default behavior of ChatGPT isn’t enough to get what you want. This is when you need to set a role for ChatGPT.

Say you want to practice for a job interview. By telling ChatGPT to “act as hiring manager” and adding more details to the prompt, you’ll be able to simulate a job interview for any position.

As you can see, ChatGPT behaves like he’s interviewing me for a job position.

Just like that, you can turn ChatGPT into a language tutor to practice a foreign language like Spanish or a movie critic to analyze any movie you want. In this article, I dive more into how to turn ChatGPT into your language tutor or language buddy.

You only need to start your prompt with the words “Act as a … ” and then add as many details as possible. If you need some inspiration, check this repository where you’ll find prompts to make ChatGPT behave like a stand-up comedian, doctor, and more.

Add personality to your prompts and generate knowledge 🔗

These two prompting approaches are good when it comes to generating text for emails, blogs, stories, articles, etc.

First, by “adding personality to our prompts” I mean adding a style and descriptors. Adding a style can help our text get a specific tone, formality, domain of the writer, and more.

Write [topic] in the style of an expert in [field] with 10+ years of experience.

To customize the output even further we can add descriptors. A descriptor is simply an adjective that you can add to tweak your prompt.

Say you want to write a 500-blog post on how AI will replace humans. If you create a standard prompt with the words “write a 500-blog post on how AI will replace humans,” you’d probably get a very generic post.

However, if you add the adjectives such as inspiring, sarcastic, intriguing, and entertaining, the output will significantly change.

Let’s add descriptors to our previous prompt.

Write a witty 500-blog post on why AI will not replace humans. Write in the style of an expert in artificial intelligence with 10+ years of experience. Explain using funny examples

In our example, the style of an expert in AI and adjectives such as witty and funny are adding a different touch to the text generated by ChatGPT. A side effect of this is that our text will be hard to detect by AI detectors (in this article, I show other ways to fool AI detectors).

Finally, we can use the generated knowledge approach to improve the blog post. This consists in generating potentially useful information about a topic before generating a final response.

For example, before generating the post with the previous prompt we could first generate knowledge and only then write the post.

Generate 5 facts about “AI will not replace humans”

Once we have the 5 facts we can feed this information to the other prompt to write a better post.

Fact 1

Fact 2

Fact 3

Fact 4

Fact 5

Use the above facts to write a witty 500-blog post on why AI will not replace humans. Write in the style of an expert in artificial intelligence with 10+ years of experience. Explain using funny examples

In case you’re interested in knowing other ways to improve your posts using ChatGPT, check this guide.

Chain of Thought Prompting 🔗

Unlike standard prompting, in chain of thought prompting, the model is induced to produce intermediate reasoning steps before giving the final answer to a problem. In other words, the model will explain its reasoning instead of directly giving the answer to a problem.

Why is reasoning important? The explanation of reasoning often leads to more accurate results.

To use chain of thought prompting, we have to provide few-shot examples where the reasoning is explained in the same example. In this way, the reasoning process will also be shown when answering the prompt.

Here’s a comparison between standard and chain of thought prompting.

Google Research

As we can see, the fact that the model was induced to explain its reasoning to solve this math problem led to more accurate results in chain of thought prompting.

Note that chain of thought prompting is effective in improving results on arithmetic, commonsense, and symbolic reasoning tasks.

Update: GPT-4 was released after the original publishing of this article. GPT-4 outperforms old ChatGPT in advanced reasoning capabilities, so you may or may not need Chain of Thought Prompting in GPT-4. I encourage you to test it yourself. Here are 4 ways to access the new GPT-4.

If you’d like to learn more about prompt engineering, here are 4 Free Prompt Engineering Courses you can take to join the top 1% of ChatGPT users, and here are some Midjourney prompt engineering techniques to create better images.

Tools 🔗

GPT-4 Prompt Engineering: PromptGenerator
I got this from the Discord app, and this may be the best prompt I’ve seen so far. It asks ChatGPT to revise the prompt you want to get the best possible answer. It’s gonna blow your mind!Copy and paste or type this in:
PromptGeneratorI want you to become my Prompt Creator. Your goal is to help me craft the best possible prompt for my needs. The prompt will be used by you, ChatGPT. You will follow the following process: 1. Your first response will be to ask me what the prompt should be about. I will provide my answer, but we will need to improve it through continual iterations by going through the next steps. 2. Based on my input, you will generate 3 sections. a) Revised prompt (provide your rewritten prompt. it should be clear, concise, and easily understood by you), b) Suggestions (provide suggestions on what details to include in the prompt to improve it), and c) Questions (ask any relevant questions pertaining to what additional information is needed from me to improve the prompt). 3. We will continue this iterative process with me providing additional information to you and you updating the prompt in the Revised prompt section until it’s complete.
Keep revising until you’re happy with it, then simply copy and paste the revised prompt into a new chat. Watch the magic! You’ll have some fun with this one. 😉

Books 🔗

For further study, consider one of the following books.

This license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, so long as attribution is given to the creator. The license allows for commercial use. If you remix, adapt, or build upon the material, you must license the modified material under identical terms.