ML #004: ChatGPT Prompt Engineering for Developers
Here is what you must know from the "ChatGPT Prompt Engineering for Developers" by DeepLearning.ai course.
The goal of this newsletter is to give you weekly insights about designing and productionizing ML systems using MLOps good practices 🔥.
This week I will present the most essential aspects of the ChatGPT Prompt Engineering for Developers course by DeepLearning.ai.
Also, in the "Random Thought" section at the end of the newsletter, I will give you a productivity hack that most people know but still ignore its superpowers.
ChatGPT Prompt Engineering for Developers
Part 1 - Write clear and specific instructions
#1. Use delimiters to indicate distinct parts of the input clearly
Make sure your instructions are distinct and clear. A simple example is asking the model to summarize a block surrounded by a delimiter.
Example:
Summarize the text delimited by triple backticks into a single sentence:
"""
{your_text}
"""
#2. Ask for a structured output
Whether you need a list of fictional book titles or a set of historical data or to convert input from one format to another, you must say in what form you explicitly accept the data.
Example:
Generate a list of three made-up book titles and their authors and genres in JSON format with the following keys: book_id, title, author, and genre.
#3. Ask the model to check whether conditions are satisfied
You can even check if a piece of text satisfies a given condition. A great example is to check if a bulk of text CAN be converted into step-by-step instructions.
Example:
If the text contains a sequence of instructions, re-write those instructions in the following format:
Step 1: ...
Step 2: ...
Otherwise, write: "No steps provided."
#4. “Few-shot” prompting
You can even teach the LLM model how to speak. For example, guide it with a conversation model.
Example:
<you> Teach me about patience.
<master> The river that carves the deepest valley flows from a modest spring...
<you> Teach me about resilience.
So remember...
The essential 4 tips for using any LLM model are:
1. Delimit the instructions
2. Ask for structured outputs
3. Ask for various conditions
4. "Few-shot" prompting
Which tip do you think is the most useful? Leave your thoughts in the comments.
Part 2 - Give the model time to “think”
#1. Specify the steps required to complete a task
Let's consider a task where you want to build a multi-lingual summary of a text exported in JSON.
Seems complex? Here is how you can break it down into multiple smaller tasks 👇
Example:
Take the text delimited by triple brackets and perform the following actions:
a) Summarize the narrative in one sentence.
b) Translate this summary to French.
c) Extract all names from the French summary.
d) Form a JSON object with the French summary & count of the names.
Here is the text:
"""
{text}
"""
#2. Instruct the model to work out its solution before rushing to a conclusion
Let's say you are a teacher and want to evaluate a student's solution.
Instead of directly asking the model if it is correct, ask it to solve it first and then compare the solutions.
Example:
Your task is to determine if the student's solution is correct. To solve the problem, perform the following:
a) Understand the question
b) Solve the problem independently
c) Compare its solution with the student's
d) Decide if the student's solution is correct
Use the following format:
Question: """{question}"""
Student's solution: """{solution}"""
Your solution: """{solution}"""
Bonus tip!
Iterate! Iterate! Iterate!
You will never write the perfect prompt in one go.
The secret sauce is patience and constant refinement.
So remember...
To let your model "think" you have to:
1. Break complex tasks into multiple steps.
2. Let the model find its solution before taking a conclusion.
Have you used any LLM to perform any complex tasks? Leave your thoughts in the comments.
Part 3 - At what are LLMs extremely good at?
#1. Summarization
This one is quite popular and extremely useful.
For example:
"""
Your task is to generate a summary of a product review from an e-commerce site.
Summarize the review below, delimited by triple backticks, in at most 30 words.
Review: ```{prod_review}```
"""
#2. Inferring
An LLM can parse your given text and find various objectives within it.
Such as:
- sentiment analysis (positive/negative)
- types of emotions
- extract some data (e.g., company and product name)
- find top topics within the text
- all of the above within a single prompt
Before LLMs, you had to train a different model for each independent task.
#3. Transforming
An LLM is extremely good at transforming your text. For example:
- translation into multiple languages
- tone transformation
- format conversion
- grammar checker
#4. Expanding
Use an LLM to reply to emails, comments, etc., in a personalized way.
For example:
"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```,
Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for their review. If the sentiment is negative...
"""
You can move this idea forward by using an LLM to help you write a post, article, book chapter, etc.
#5. Chatbot
No surprise here.
Still, it is fascinating that you can customize an LLM by giving it an "identity."
After that, let them do the talking for you.
So remember...
An LLM is excellent at:
1. Summarizing a piece of text.
2. Inferring a given objective.
3. Transforming your text.
4. Expand your idea.
5. Chatbot...
What is the most common use case you used an LLM for? Let me know in the comments.
👇👇👇
Disclaimer: I want to thank DeepLearning.AI for making this excellent course! For the whole experience, I recommend watching it. It is free, and it takes only 1.5 hours.
Random Thought
Here is the number one productivity hack I promised you 👇
Most people know about it but still ignore it.
Let me explain.
I am talking about sleep.
If you prioritize and get enough sleep, you will:
- increase your focus
- increase output/hour
- be more creative
- think with more clarity
- stay healthy
... and everything without any effort.
Your daily program should be scheduled around your sleeping routine, not the other way around.
During sleep, your brain is:
- strengthening your memories
- strengthening what you learned during the day
- creating new connections
- cleaning redundant memories
Just let me repeat.
By prioritizing sleep, you can effortlessly make your life better.
Do you consider sleep as the number one habit for being productive?
See you next week on Thursday at 9:00 am CET.
Have a fabulous weekend!
💡 My goal is to help machine learning engineers level up in designing and productionizing ML systems. Follow me on LinkedIn and Medium for more insights!
🔥 If you enjoy reading articles like this and wish to support my writing, consider becoming a Medium member. Using my referral link, you can support me without extra cost while enjoying limitless access to Medium's rich collection of stories.
Thank you ✌🏼 !