avatarThuwarakesh Murallie

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4170

Abstract

">Look at that; this is what a perfect SEO post should look like. As a bonus, I’ve also got some additional SEO optimization tips.</p><p id="8de4">Now, both responses are correct. But for an SEO post, you should ask it from an SEO expert. For a research paper, you should ask an academic.</p><p id="5196">So, be sure to assign a role to every prompt.</p><h2 id="3363">Explain the context</h2><p id="bc2b">Context is the knowledge of your LLM to produce relevant answers.</p><p id="aa4c">Consider this. In the previous section, I asked LLM to write an SEO post about houseplants. What if our post is part of a grow light company’s blog? If you’re a writer, you’d write a different post with this new contextual information, right? So do an LLM.</p><figure id="8b2c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*PyR9zdO6HD53xfl5ig3j9w.png"><figcaption>ChatGPT’s response when a role and a context is assigned. — Image by the author.</figcaption></figure><p id="9738">The new post has a dedicated section for light requirements, as it should be on a grow light company’s website.</p><p id="bcfc">Context can be as short as this one, but it can also be an extensive document, a web page, a transcript of a YouTube video, etc. Context sets the stage and provides the required information to produce the correct answer.</p><p id="7c5e">Extended contexts are the basic building blocks of retrieval-augmented generation (RAG), which I have covered in detail in many previous posts.</p><div id="de3c" class="link-block"> <a href="https://ai.gopubby.com/build-and-deploy-rag-llm-adf38e1ae260"> <div> <div> <h2>Steal My Blueprint to Build and Deploy RAGs [In Minutes].</h2> <div><h3>Most RAGs are built on this stack; why would you redo it every time?</h3></div> <div><p>ai.gopubby.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*Vf_zKzKMnOVk2hiU)"></div> </div> </div> </a> </div><p id="9434">But let’s assume you’re creating this page programmatically and don’t want to copy and paste this information. If it’s a JSON, it would make your life much easier. Just ask.</p><h2 id="ff83">Suggest response format</h2><p id="00ca">I prefer that LLM fill in the blanks in my template rather than generate its text.</p><p id="f300">Okay, it may not apply to every use case. However, I’ve generally seen better responses when we suggest a response format.</p><p id="1c28">I like to do it in two ways.</p><p id="2539">The first method <b>suggests a template,</b> which the LLM will fill out with its response.</p><p id="1737">Here’s an example:</p><figure id="463d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*HVzcrKCz2c7QH-EMhH5BCQ.png"><figcaption></figcaption></figure><p id="700d">In my prompt, I answered the question myself but left placeholders for key information I needed from the LLM.</p><p id="02a6">I like this format, so I created it in my mind. Thus, I can understand it better than any random GPT-generated text. Look how neatly Chat GPT produces my answer. I prefer this method over the regular answering style.</p><p id="3580">Trust me, to this day, nothing beats this prompt engineering technique. It always works, and it works well.</p><p id="a931">However, I sometimes need the response in a <b>specific format,</b> such as JSON. I also often prefer to read a table rather than a whole bunch of text because it’s easier to understand.</p><p id="ecb3">Let’s request our blog post example, but this time, in JSON format.</p><figure id="640f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*8EhENdGexIyDRs26b4tkzA.png"><figcaption></figcaption></figure><h2 id="0400">Provide examples</h2><p id="dd8c">Another popular prompting technique is by providing the LLM with some examples.</p><p id="886f">You may have heard terms like zero-shot, one-shot, few-shot, and n-shot learning, which are all related to examples in prompts.</p><p id="6399"><b>Zero-shot </b>learning is asking an

Options

LLM to answer as it wishes. You don’t provide any examples. Giving no examples is okay for open-ended questions like “Why is December colder?”. Also, tasks like translation need no examples.</p><figure id="1512"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*f25VAAM-_uXdUw-PciM4QQ.png"><figcaption></figcaption></figure><p id="4e5a"><b>One-shot </b>learning involves asking the LLM for one example. In some scenarios, a single example can make a big difference. My favorite is structured data extraction. Sometimes, instruction alone is insufficient in extensive unstructured data. However, a single example would help the LLM effectively find the information.</p><figure id="d5c1"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*XImmG12_IvMhQE48A_Z5Kg.png"><figcaption></figcaption></figure><p id="478b"><b>Few-shot </b>learning, as you might have already guessed, provides the LLM with several examples to help you do a particular task more effectively. A good example is the classification task. More often, large language models are classified without any examples. But if the classification task is particular to your private knowledge base, then you must give the LLM some examples. Few-shot learning is also helpful when asking an LLM to solve a complex problem. I ask GPT to square my answers with a few shot prompting.</p><figure id="5ef1"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*DfLR5ZJvaNNK3e742VLl6Q.png"><figcaption></figcaption></figure><h1 id="ba45">Other elements of a good prompt (when others would read the response.)</h1><p id="f5eb">Assigning a role, defining a context, and suggesting an output format is always sufficient for me to get a good response. I don’t want to complicate things, so I try to stick to these three.</p><p id="01f1">However, a few other elements may be helpful in some special settings.</p><p id="70ef">If you’re emailing a customer, the GPT’s default response may lack the emotional tone. You might want to convince your customer of a defect on your side, but the GPT might not sound pleasing.</p><p id="6245">Therefore, to ensure a quality response when other people are going to read the responses, I always define the audience, tone, and style.</p><p id="f5ea"><b>Audience Specification: </b>Clearly define the audience for the response. This helps tailor the content to their level of understanding, interests, and expectations. Here’s how GPT responds when I ask the same question but for a different audience.</p><figure id="06ca"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*HkKHtqFnbqV1qfw3twwM0w.png"><figcaption></figcaption></figure><figure id="9e55"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*wIdF3J_Dw8x1SdN6ru25Vg.png"><figcaption></figcaption></figure><p id="d228"><b>Tone setting:</b> Specify the emotional tone of the response. For instance, you can say “professional and authoritative” when disagreeing with a colleague or “warm and empathetic” when winning a client.</p><p id="64fc"><b>Style setting:</b> Similar to tone, but more about the non-emotional components of writing. For instance, you could ask GPT to write with “technical words and industry jargon” in an email to your boss or ask for “short and simple sentences” to write for a wider audience.</p><h1 id="d5b0">Final thoughts</h1><p id="2fc6">Well, if there’s one thing you need to learn to make your career look 10 times better, I’d say it’s prompt engineering. That’s because when GenAI gets into everything, you need to know the language it can understand.</p><p id="3680">Complex prompting techniques like COT can produce high-quality answers. However, for everyday tasks, such complicated techniques are unnecessary.</p><p id="79f7">You could get a decent response by ensuring a few points. This post has covered them with examples.</p><p id="6b10"><i>Thanks for reading, friend! Besides <a href="https://thuwarakesh.medium.com/"><b>Medium</b></a></i>, <i>I’m on <a href="https://www.linkedin.com/in/thuwarakesh/"><b>LinkedIn</b></a> and <a href="https://twitter.com/Thuwarakesh"><b>X,</b></a><b> </b>too!</i></p></article></body>

Prompt Engineering (for Everyday Tasks) Doesn’t Have to Be So Complicated

Here’s your quick checklist to get high-quality responses every time.

Photo by Tingey Injury Law Firm on Unsplash

I recently read an article that says newer models have only a slight performance gap between them, but our ability to communicate with them is drastic.

Prompt Engineering is the language of Gen AI. Yet, we pay little attention to it because GenAI models throw back something for anything we throw in there.

We assume it’s the model’s best, but it’s not.

I wasn’t a good prompter myself. Hence, my ability to use AI for my benefit was minimal. At times, I was too lazy to type in a decent prompt or in a hurry to get the answer soon. Both times, I get superficial answers and need to spend more time on them to make them usable.

But in reality, effective prompting isn’t too hard either.

I often get high-quality responses by ensuring my prompt has only four essential elements. However, there are also advanced techniques. These advanced techniques are primarily for developers who create apps with LLMs.

This post covers the essential elements of every prompt. In the next post, I’ll cover and discuss advanced techniques, such as chains of thoughts and trees of thoughts.

Elements of every effective prompt

Suppose you are thinking of investing your money in the stock market for the first time. You phone your friend and ask which stocks to buy and how much. You get a list of suggestions, and then you buy them.

But what if your friend has never invested, too? Or your friend is not a professional financial advisor?

You’re more likely than not to lose your money.

I’ll come back to LLMs. Language models are trained on a vast collection of text. They range from medical to financial to poetry, you name it. How do you know which part of its knowledge base you are talking with? In other words, which personality of the GenAI are you asking for advice from?

There’s a way to restrict it—assign it a role.

Assign a role

The first and foremost prompt engineering tip is assigning a role. This alone would make tremendous differences in anLLMs response.

Here’s an example. I asked ChatGPT, “What’s the best way to format a document titled ‘How to grow houseplants?’” Here’s its response:

Chat GPT’s response with no role assigned — Image by the author.

This is not bad. A perfect response. But here’s what ChatGPT says when I assign it a role. This time, I added “You’re an SEO expert” at the beginning of my question.

Chat GPT’s response with a role assigned — Image by the author.

Look at that; this is what a perfect SEO post should look like. As a bonus, I’ve also got some additional SEO optimization tips.

Now, both responses are correct. But for an SEO post, you should ask it from an SEO expert. For a research paper, you should ask an academic.

So, be sure to assign a role to every prompt.

Explain the context

Context is the knowledge of your LLM to produce relevant answers.

Consider this. In the previous section, I asked LLM to write an SEO post about houseplants. What if our post is part of a grow light company’s blog? If you’re a writer, you’d write a different post with this new contextual information, right? So do an LLM.

ChatGPT’s response when a role and a context is assigned. — Image by the author.

The new post has a dedicated section for light requirements, as it should be on a grow light company’s website.

Context can be as short as this one, but it can also be an extensive document, a web page, a transcript of a YouTube video, etc. Context sets the stage and provides the required information to produce the correct answer.

Extended contexts are the basic building blocks of retrieval-augmented generation (RAG), which I have covered in detail in many previous posts.

But let’s assume you’re creating this page programmatically and don’t want to copy and paste this information. If it’s a JSON, it would make your life much easier. Just ask.

Suggest response format

I prefer that LLM fill in the blanks in my template rather than generate its text.

Okay, it may not apply to every use case. However, I’ve generally seen better responses when we suggest a response format.

I like to do it in two ways.

The first method suggests a template, which the LLM will fill out with its response.

Here’s an example:

In my prompt, I answered the question myself but left placeholders for key information I needed from the LLM.

I like this format, so I created it in my mind. Thus, I can understand it better than any random GPT-generated text. Look how neatly Chat GPT produces my answer. I prefer this method over the regular answering style.

Trust me, to this day, nothing beats this prompt engineering technique. It always works, and it works well.

However, I sometimes need the response in a specific format, such as JSON. I also often prefer to read a table rather than a whole bunch of text because it’s easier to understand.

Let’s request our blog post example, but this time, in JSON format.

Provide examples

Another popular prompting technique is by providing the LLM with some examples.

You may have heard terms like zero-shot, one-shot, few-shot, and n-shot learning, which are all related to examples in prompts.

Zero-shot learning is asking an LLM to answer as it wishes. You don’t provide any examples. Giving no examples is okay for open-ended questions like “Why is December colder?”. Also, tasks like translation need no examples.

One-shot learning involves asking the LLM for one example. In some scenarios, a single example can make a big difference. My favorite is structured data extraction. Sometimes, instruction alone is insufficient in extensive unstructured data. However, a single example would help the LLM effectively find the information.

Few-shot learning, as you might have already guessed, provides the LLM with several examples to help you do a particular task more effectively. A good example is the classification task. More often, large language models are classified without any examples. But if the classification task is particular to your private knowledge base, then you must give the LLM some examples. Few-shot learning is also helpful when asking an LLM to solve a complex problem. I ask GPT to square my answers with a few shot prompting.

Other elements of a good prompt (when others would read the response.)

Assigning a role, defining a context, and suggesting an output format is always sufficient for me to get a good response. I don’t want to complicate things, so I try to stick to these three.

However, a few other elements may be helpful in some special settings.

If you’re emailing a customer, the GPT’s default response may lack the emotional tone. You might want to convince your customer of a defect on your side, but the GPT might not sound pleasing.

Therefore, to ensure a quality response when other people are going to read the responses, I always define the audience, tone, and style.

Audience Specification: Clearly define the audience for the response. This helps tailor the content to their level of understanding, interests, and expectations. Here’s how GPT responds when I ask the same question but for a different audience.

Tone setting: Specify the emotional tone of the response. For instance, you can say “professional and authoritative” when disagreeing with a colleague or “warm and empathetic” when winning a client.

Style setting: Similar to tone, but more about the non-emotional components of writing. For instance, you could ask GPT to write with “technical words and industry jargon” in an email to your boss or ask for “short and simple sentences” to write for a wider audience.

Final thoughts

Well, if there’s one thing you need to learn to make your career look 10 times better, I’d say it’s prompt engineering. That’s because when GenAI gets into everything, you need to know the language it can understand.

Complex prompting techniques like COT can produce high-quality answers. However, for everyday tasks, such complicated techniques are unnecessary.

You could get a decent response by ensuring a few points. This post has covered them with examples.

Thanks for reading, friend! Besides Medium, I’m on LinkedIn and X, too!

Prompt Engineering
Llm
ChatGPT
Artificial Intelligence
Generative Ai Tools
Recommended from ReadMedium