Engage with this AI Powered Article

it can generate personalised TLDRs, explain content, let you build graphs and more!

Get better at Prompting LLMs

23 minutes

Nov 19, 2024

Try out this new feature!

TL;DR generator

This blog post was written as a supporting article for a talk that was done at Google DevFest 2024 Brunei.

↳ AI helper

Hi, my name is Albert. For those of you that don't know me, I didn't start out in the tech industry. I was a Process Safety Engineer in the Petrochemical Industry for 7 years before I transitioned into writing code. Since 2017, I've been dabbling into web development and when ChatGPT was released in Nov 2022, I was intrigued by the possibilities and started introducing AI into my day-to-day and also started building more applications that promote the use of AI or has used AI to improve an existing solution.

↳ AI helper

Looking back, building web applications back in 2017 to 2022 was really different. Notable projects that I've been involved in are:

↳ AI helper
  1. Manamakan - Brunei's Food & Beverage Discovery Platform
  2. Mirath - An Online Platform to donate Set Perlengkapan Jenazah to the needy
  3. Sukarelawan Belia - An Online Volunteering Management System for COVID-19

It required a lot of manual work and the applications were not as smart as they are today. Refer to my post here which goes into more detail about how LLMs have transformed my life.

↳ AI helper

Since the advent of LLMs, I've been able to build applications that were previously not possible. I introduced the first ever Online Malay Version (not just a PDF) of the Hansard of the Legislative Council of Brunei in 2023, and that's not all, I used AI to translate the Hansard into English.

↳ AI helper

During my time at Greywing, I built an AI that handled email communication between businesses and port agents to handle the initial procurement process. We also built AI that allows you to talk directly to your Data Warehouse instead of having to write SQL queries.

↳ AI helper

And now, I've created Brunei's first ever Search Engine that gives you answers and content only from this country, unpolluted by the rest of the world. Because it's localised you can easily look up specific things- like camping gear or facial products that's sold here.

↳ AI helper
Share your thoughts through this poll ⭐

In these 2 years, I've learned a lot about LLMs and how to maximise their potential in the problems I'm tackling. Prompting, is a fancy way of saying that you are giving instructions to an AI. Sure, we can talk and instruct it like how we talk to our human peers, but it won't be as effective as LLMs aren't exactly human and they have their own "language".

↳ AI helper

Prompting = Instructing AI

↳ AI helper

Don't worry, it's not like we need to learn a new programming language, but rather it's about learning to communicate to a machine in a way that it will give you the results you want.

↳ AI helper

Here's a very simple visual example to set the stage.

↳ AI helper

When I first started generating images with Dall-E, I quickly learnt that I was lacking in visual vocabulary. I would go generate me an image of "an otter". Sure the image came out pretty good, but it wasn't wow.

↳ AI helper
An otter by the streamcaption: An otter by the stream

I eventually learnt that in the world of image generation, I needed to learn things like visual styles, composition, camera lens terms, like wide-angle, telephone, and styles of prominent artists like Picasso, Van Gogh, and so on.

↳ AI helper

Here's a better prompt, "an otter that is suitable to be featured in a national geographic magazine"

↳ AI helper
An otter posingcaption: An otter posing
An otter mid-divecaption: An otter mid-dive

An you can instantly see the difference, the images are now more lively and engaging than the original.

↳ AI helper

More words, more context in the prompts we provide will, in most cases give us better results.

↳ AI helper

Now I want to quickly tell you more about prompting, but let's first do a quick dive into LLMs.

↳ AI helper

Foundational Modelscaption: Foundational Models

We've all heard of the term Large Language Models (LLMs) and some of you might have also heard about Foundational Models. Usually in our conversations, the LLMs we are actually referring to like GPT-3, GPT-4, Gemini, the ones that we (regular people) work with are actually Instruction-tuned models. The corresponding companies start train Foundational Models, then they fine-tune them for specific tasks.

↳ AI helper

It is referred to as Instruction-tuned models as they are built for the purpose of following instructions and more specifically, in a chat-like conversation. Again depending on the goal, they can also be fine-tuned for more specific tasks like with Gemma 2, that also comes in the flavour of CodeGemma that is fine-tuned to generate code and ShieldGemma that is fine-tuned to evaluate the safety of the input prompt and output responses against a set of defined safety policies.

↳ AI helper

With these instruction-tuned models, we can now install it onto machines with sufficient RAM or GPU and start generating text, code, images. We call this inferencing.

↳ AI helper
Share your thoughts through this poll ⭐

So how does inferencing work? It's actually quite simple, the model will predict 1 token at a time, but it will also use all of the preceeding tokens to predict the next token. At every step, there is a probability of occurence for each token in the vocabulary, and depending on the setting you provide, it could only choose the most probable token or it could choose a random token within a certain threshold.

↳ AI helper
Inference option 1caption: Inference option 1
Inference option 2caption: Inference option 2

The LLM will predict the next token based on ALL of the previous tokens provided and also those that are generated while answering.

↳ AI helper

If I am to draw a parallel of this with us Humans, the LLM model is akin to our Brain. The prompts that we write for the model, (can come in the form of the task, context or persona) is akin to our history, environment that we grew up in, our personality and intentions.

↳ AI helper
Models vs Humanscaption: Models vs Humans

The combination of this gives rise to the prediction of tokens (LLM) or words (Humans).

↳ AI helper

Now how many of you in the audience can relate to this? Do you think that you know exactly what you are saying in advance, or does the next word only come to you as you are speaking?

↳ AI helper
Share your thoughts through this poll ⭐

Ok, let's finally get into improving our prompts.

↳ AI helper

Here's a really useful resource that have helped me, and will surely help you too.

↳ AI helper

These are the 6 areas that you should pay attention to when writing your next prompt.

↳ AI helper
  1. Task: What do you want the model to do?
  2. Context: What information does the model need to know to do the task?
  3. Examples: What are some examples of the output you want?
  4. Persona: Who is the model speaking as?
  5. Format: How should the output be formatted? Email, Markdown, Code, etc
  6. Tone: What is the tone/vocal style of the output?

You do not need to provide all 6 in every prompt. However, providing more will tend to give you better results. It is completely normal to start without any of these, especially when you might not exactly know what you want yet at the start. As you observe the outputs you will naturally start to distil your own thoughts and preferences, and know what to include into the prompts.

↳ AI helper

In my opinion, the two most important areas are Task and Context. The Task is the instruction that you want the model to do, and the Context is the information that the model needs to know to carry out the task.

↳ AI helper

Let's go through this using an example topic - Digital Citizenship.

↳ AI helper

The task is the core instruction or objective you want the model to fulfill. Instead, provide concrete parameters around the expected output, such as length, format, tone, or level of detail.

↳ AI helper

Additionally, consider structuring the task prompt as a complete sentence or instruction, rather than a simple phrase. This can help the model better understand the context and intent behind the prompt.

↳ AI helper
What is digital citizenship?
Explain in 100 words or less, the term digital citizenship.
Tell me about digital citizenship.
Identify the top 3 key areas of digital citizenship that I should be aware of.

Loading...

Loading...

In the improved prompt, we have specified the length of the response and also to only limit the explanation to the top 3 key areas. This will help the model to focus on the most important aspects of digital citizenship.

↳ AI helper

The context refers to the additional information the model needs to understand in order to effectively complete the task. This could include background details, relevant constraints, or specific requirements.

↳ AI helper

The more specific and grounded in reality the context, the more meaningful and applicable the model's response will be. Avoid generic or vague context that leaves the model guessing.

↳ AI helper

Now let's add some context to the prompt.

↳ AI helper
Identify the top 3 key areas of digital citizenship that I should be aware of.
I am going for an interview with a company in Brunei that is looking to hire a social media marketing person to promote and educate their audience on digital citizenship.

Identify the top 3 key areas of digital citizenship that I should be aware of.

Loading...

By adding this contextual information, you give the model a clear understanding of the target audience, the objective, and the specific areas to focus on. This will result in a more tailored and actionable response.

↳ AI helper

Providing relevant examples within your prompts can be a powerful technique to guide the model and shape its output. Examples serve two key purposes:

↳ AI helper
  1. Illustrate the expected format, structure, or style of the desired output.
  2. Offer sample content that the model can use as a reference point.
I am going for an interview with a company in Brunei that is looking to hire a social media marketing person to promote and educate their audience on digital citizenship.

Identify the top 3 key areas of digital citizenship that I should be aware of.
I am going for an interview with a company in Brunei that is looking to hire a social media marketing person to promote and educate their audience on digital citizenship.

Identify the top 3 key areas of digital citizenship that I should be aware of.

Here is an example of a suitable output:

Programming language Python:
Python is one of the most commonly used coding languages to work with AI.
Application: Start and organize classes on using AI to fine-tune models.

Loading...

In the improved prompt, we are guiding the model to not just provide a list of the key areas, but also indicate how we can "apply" it into our roles as a social media marketer.

↳ AI helper

Think of the persona as the character or roel of the person that you wish you were talking with to achieve the task at hand.

↳ AI helper
I am going for an interview with a company in Brunei that is looking to hire a social media marketing person to promote and educate their audience on digital citizenship.

Identify the top 3 key areas of digital citizenship that I should be aware of.
You are an Interview Coach with 20 years of experience in helping individuals market themselves and proactively get themselves ready for their next job application.

I am going for an interview with a company in Brunei that is looking to hire a social media marketing person to promote and educate their audience on digital citizenship.

Identify the top 3 key areas of digital citizenship that I should be aware of.

Loading...

In the improved prompt, I have specified the persona of the person that I wish I was talking directly with, if I am to receive the following advise.

↳ AI helper

I have previously produced a working example that illustrates the persona of an asian uncle that always scolds or comments on you. Check it out here

↳ AI helper

Clearly specifying the desired output format can help the model structure its response appropriately. This could include details like:

↳ AI helper
  1. Content structure (paragraphs, bullet points, etc.)
  2. Markup (Markdown, HTML, JSON)
  3. Code syntax (Python, JavaScript)
I am going for an interview with a company in Brunei that is looking to hire a social media marketing person to promote and educate their audience on digital citizenship.

Identify the top 3 key areas of digital citizenship that I should be aware of.
I am going for an interview with a company in Brunei that is looking to hire a social media marketing person to promote and educate their audience on digital citizenship.

Identify the top 3 key areas of digital citizenship that I should be aware of.

Provide your answer in a bullet list with the format:

[topic]
[description]
[methods to apply]

Loading...

Here I have specified that the format should be in bullets, but also provided a structure for the bullets. This is quite similar to the "example" section, but here we are being more generic.

↳ AI helper

I am going for an interview with a company in Brunei that is looking to hire a social media marketing person to promote and educate their audience on digital citizenship.

Identify the top 3 key areas of digital citizenship that I should be aware of.
I am going for an interview with a company in Brunei that is looking to hire a social media marketing person to promote and educate their audience on digital citizenship.

Identify the top 3 key areas of digital citizenship that I should be aware of.

Be as strict and sarcastic as possible, otherwise I won’t take you seriously.

Loading...

Here, to facilitate my own learning process, I prefer when someone is strict and sarcastic with me. If they are too nice, I might not take their advice seriously. So I have specified the tone that I want the model to use.

↳ AI helper

Based on the given text, grade the degree of digital citizenship
  
{{input}}
Assign a grade to the given text based on the level of digital citizenship.

Beginner: Struggles to identify credible sources, sharing unverified content

Intermediate: Can differentiate between credible and unreliable sources, uses basic digital tools effectively.

Advanced: Actively evaluates sources, cross-checks information, promotes digital literacy among peers

{{input}}

Loading...

Here I have specified the grading criteria for the model to follow. This will help the model to understand the different levels of digital citizenship and provide a more consistent response.

↳ AI helper

Assign a grade to the given text based on the level of digital citizenship.

Beginner: Struggles to identify credible sources, sharing unverified content

Intermediate: Can differentiate between credible and unreliable sources, uses basic digital tools effectively.

Advanced: Actively evaluates sources, cross-checks information, promotes digital literacy among peers

{{input}}
Assign a grade to the given text based on the level of digital citizenship.

...

You will be provided with text obtained from the social media profile of an instagram account, including their posts and it’s accompanying comments.

{{input}}

Loading...

Here I have added context to the prompt by specifying that the text will be obtained from a social media profile of an instagram account. This will help the model to understand the source of the text and the type of text to expect.

↳ AI helper

Assign a grade to the given text based on the level of digital citizenship.
…

You will be provided with text obtained from the social media profile of an instagram account, including their posts and it’s accompanying comments.

{{input}}
Assign a grade to the given text based on the level of digital citizenship.

…

Example Input:
Post Caption: Lorem ipsum dolor sit amet …

Example Output:
```json
{
"extractedText": "..."
"grade": “beginner”
}
```

{{input}}

Loading...

Here I have explicitly provided an example of what the input might be and what the expected output should look like. This will help the model to understand the structure of the input and the expected output.

↳ AI helper

Assign a grade to the given text based on the level of digital citizenship.

...

You will be provided with text obtained from the social media profile of an instagram account, including their posts and it’s accompanying comments.

{{input}}
Assign a grade to the given text based on the level of digital citizenship.

…

Provide your response in JSON according to the following Typescript format:

```typescript
type GradedText = {
  extractedText: string // this is the excerpt obtained from the post
  grade: ‘beginner’ | ‘intermediate’ | ‘advanced’
}
```

{{input}}

Loading...

Here I have specified the output format as a typescript object, which will help the model further produce the output in the desired format.

↳ AI helper

Encouraging the model to explain its reasoning before providing the final answer can usually lead to more accurate and detailed responses.

↳ AI helper

This is one of the most useful prompts to include

↳ AI helper

think step by step.

↳ AI helper

Ambiguity is the enemy of effective prompts. Be as clear and specific as possible.

↳ AI helper

Statements like, make it good, better, best are subjective and can lead to a wide range of outputs. Instead you have to specify what you mean by good, better, best.

↳ AI helper

If you can't elaborate, you can always get the LLM to generate examples for you, just as I have done in this article.

↳ AI helper

be clear and concise.

↳ AI helper

One of the ways to prevent or limit hallucinations, is actually to include into the prompt that the model can answer with "don't know" or simply return "null" or equivalent.

↳ AI helper

Otherwise, the model will naturally be overconfident and always give you an answer.

↳ AI helper

Most of the prominent models today have multi-modal capability, i.e. the ability to accept images as an input. This can be a powerful tool to help articulate the problem, especially when you are not sure how to describe it in words.

↳ AI helper

This is especially useful when you are coding, and you've encountered a bug that transcends your immediate code, but could be due to the program, software and environment that you are using. Simply take a screenshot of everything and ask the model to help you debug. (But be cautious if you are working with sensitive work related data!)

↳ AI helper
Share your thoughts through this poll ⭐

Mastering prompting takes practice and experimentation. Try different approaches and refine your prompts based on the results.

↳ AI helper

Focus on crafting clear, specific prompts that align with your goals. Leverage visuals when helpful. Approach prompting with curiosity and an iterative mindset.

↳ AI helper

Keep honing your prompting skills - they'll serve you well across many applications. Refer to the resources below or reach out to me if you need further assistance.

↳ AI helper

Here are some resources that you might find useful that has helped me to produce this article.

↳ AI helper
  1. Prompting Guide
  2. Learn Prompting
  3. Build with Claude
  4. Gemini Prompt Guide

Connect and reach me on LinkedIn to continue the conversation.

Albert Shim

AI-assisted Human