π Prompt Engineering Introduction
Abstract
This section presents a comprehensive introduction to "Prompt Engineering".
π¦ Video lecture for this chapter - Link
LLMs are prompt-based i.e., users interact with them via prompts. LLMs receive the user input prompts, understand and interpret them to generate the desired outputs. LLMs are very powerful i.e., they are highly knowledgeable as they are trained on large volumes of text data from various sources like Wikipedia, webpages, books, etc.
However, LLMs require clear, specific and concise instructions to generate the desired output. In simple words, the quality (accuracy and relevance) of LLM-generated outputs largely depends on the quality of input prompts.
Prompt Engineering is the art and science of writing and refining prompts iteratively depending on the generated outputs to finally arrive at the desired output
.
At first, you will write a prompt and get some output.
- In the first attempt, you may not get the desired output.
- So, depending on the output you will refine (enhance) the prompt by rewriting or adding some more details which results in a better output but not the desired output.
- Again you will refine the prompt to get a much better output. In this way, sometimes you may have to write and refine the prompt iteratively.
- This
entire process of writing and refining prompts
is referred to asprompt engineering
.
Let us understand prompt engineering with a simple and intuitive example. Assume that you want to write a poem about friendship and ask ChatGPT.
Prompt
Output
In the realm where hearts entwine,
A bond of friendship, pure and fine.
Like branches of a steadfast tree,
We stand together, you and me.
Through laughter's song and tears' embrace,
We navigate life's winding race.
In every trial, every strife,
We're each other's guiding light.
Hand in hand, we stride along,
Sharing joys and sorrows strong.
In moments fleeting, or profound,
Our friendship's flame forever bound.
After seeing the output, you want the poem to be of just 4 lines. Now you will refine the prompt as
Prompt
Output
In friendship's embrace, hearts unite,
Through darkest days and brightest light.
With trust and love, we stand as one,
In the journey of life, forever spun.
Now, the poem consists of four lines. But, you may feel that the poem looks appealing if words like sun, moon, air and water are included. Now you will again refine the prompt as
Prompt
Write a poem about friendship in four lines. Constraints: Make sure to words sun, moon, air and water.
Output
In friendship's glow, we bask like the sun,
Through moonlit nights, our bond's begun.
Like air we breathe, our connection pure,
In waters deep, our friendship secure.
In this way, you will first write the prompt and then refine it iteratively depending on the outputs generated to finally arrive at the desired output. This entire process is referred to as prompt engineering.
To summarize,
- LLMs are very powerful, but not user mind readers i.e., they require clear, concise and specific instructions.
- Well-crafted prompts are necessary to have an effective interaction with LLMs.
- Prompt engineering is the secret sauce to get the desired output from LLMs.