Anatomy of the Prompt

Anatomy of the Prompt

When we talk to each other, we use questions and statements to start a conversation. In the world of artificial intelligence, we do something similar with what's called a "prompt." A prompt is like a question or a command that we give to a computer program to get a response. Think of it as a starting point for a conversation with a machine.

Prompts help us tell the computer exactly what we want to know or do. Whether we're asking for the weather forecast, seeking help with homework, or even telling a joke, prompts guide the computer in understanding and answering our requests. In this article, we'll explore the different parts of a prompt, breaking it down to understand how it works, but we do not want to dive into details. (Writing a prompt is a different thing than knowing its parts.)

Task Definition

The only mandatory part of the prompt is the "task definition." It's the heart of the prompt, the core instruction that tells the computer program exactly what you want it to do. The task definition can be a question, a command, or a request. The task definition sets the scope and direction for the AI's response. A good prompt is carefully crafted to be clear and specific, so the AI knows exactly what's expected.

What if the prompt does not contain a task definition? Without it, the interaction can become directionless, ambiguous, and AI will not know what it should do.

No alt text provided for this image

The main task categories:

  • Explain
  • Describe
  • Create (Write)
  • Update (Rewrite)
  • Translate
  • Summarize
  • Role-play
  • Predict
  • Advise

Persona/Context

I believe this should be a mandatory part of the prompt, even though it currently isn't. Let's see why it is important, and why it is a problem if it is missing from the prompt. Persona/Context is a crucial component of a prompt. It provides the AI with a reference, which can significantly influence the nature and quality of the AI's responses. Let's break it down:

  • Persona: This refers to the role that the AI is expected to play in the interaction. For example, the AI could be asked to act as a historian, a scientist, a teacher, a doctor and so on. By defining the persona, you're essentially instructing the AI to generate responses that are consistent with how that persona would typically communicate and the kind of knowledge they would have.
  • Context: This refers to the specific situation, environment, or background information that the AI should consider when generating responses. The context could be a specific event, a particular time period, a certain location, or any other relevant circumstances.

A picture is worth a thousand words, so here are some different prompts to demonstrate the power of the context.

No alt text provided for this image
when the persona is a storyteller


No alt text provided for this image
when the persona is an AI expert

For simple questions or tasks, where the desired response is straightforward and doesn't require a specific tone or perspective, omitting the persona/context can lead to quicker and more direct answers. For example, if you ask, "What's the capital of France?", you don't really need a persona or context. But if you're looking for a more nuanced or tailored response, providing a persona or context can be very beneficial.

If the Persona/Context is not explicitly defined in a prompt, the AI will use a default persona and a generalist context. This is the standard behaviour of models like GPT-4. In this default mode, the AI doesn't adopt a specific role or persona. The AI will attempt to understand the context from the prompt itself and any other information provided in the conversation.

  • Without a defined persona, the AI's responses may lack the specificity or expert tone that might be desired in certain situations.
  • Without a defined context, the AI might not match the tone you're expecting.
  • In some cases, the lack of persona or context might lead to misunderstandings or confusion. If the task is complex and relies on understanding a specific situation or role, the AI might not generate the desired response without that guidance.

Examples

This part of a prompt is an optional but often highly valuable component. Providing examples can help guide the AI's response. Examples act as a bridge between the human's intent and the AI's understanding, providing a clear path for the AI to follow.

Why do we use examples?

  • Examples can clarify ambiguous or complex tasks by showing the AI exactly what you want.
  • If you need the AI to follow a specific format, providing an example can be the most straightforward way to communicate that requirement.
  • The examples, you're essentially giving the AI a mini-training session on the specific task you want it to perform. This can help the AI adapt to your specific needs.

No alt text provided for this image
one-shot prompt

While examples can be highly effective, there are some limitations and considerations to keep in mind. If you provide too many examples that are too specific, the AI might overfit to those examples and struggle to generalize to new inputs. So, too many examples might confuse the AI, while too few might not provide enough guidance.

expected behaviour/constraints

This part of the prompt outlines the specific rules, limitations, or guidelines that the AI should follow when generating a response. It helps to shape the AI's behaviour to align with particular requirements or expectations.

The use of Expected Behaviour/Constraints in a prompt serves several vital purposes. Firstly, it provides a level of control over the AI's output. By clearly defining the expected behaviour or constraints, you can tailor the AI's responses to align with specific needs or preferences. Secondly, the definition of constraints can act as a form of Quality Assurance. By setting specific standards or criteria that the AI must follow, you can ensure that its responses meet certain quality benchmarks. Finally, safety is an essential consideration, especially in contexts where there might be risks associated with the AI's output. By constraining the AI's behaviour, you can prevent it from generating content that might be harmful, inappropriate, or misleading.

No alt text provided for this image
using constraints gives us control

definition of the good response

The definition of a good response is essentially a set of criteria or guidelines that describe what an ideal answer to the prompt would look like. It's not merely about correctness; it encompasses various dimensions such as relevance, completeness, coherence, and adherence to specific instructions or constraints.

Defining what constitutes a good response is like setting a target for the AI to aim for. Without this definition, the AI might generate responses that are technically correct but miss the mark in terms of what's actually desired or needed.

For example, if you ask the AI to summarize a complex scientific paper, a good response might not only be concise and accurate but also accessible to a non-expert audience. Without specifying that this accessibility is part of what makes a response "good", the AI might generate a summary that's correct but still too technical for the intended readers.

No alt text provided for this image
the definition of "good" is a set of criteria or guidelines

expected steps towards the goal

Defining the expected steps can be particularly important in situations where - without clear guidance - the AI might generate an incorrect or suboptimal response, or we really want to see all steps for any reason. This component serves as a roadmap, outlining the process or sequence of steps that the AI should follow to reach the desired outcome.

In some tasks, the path to the correct answer is as important as the answer itself. Without clear guidance on the expected steps towards the goal, the AI might take shortcuts, make incorrect assumptions, or overlook important nuances, leading to a wrong or inadequate response.

For example, if you ask the AI to solve a complex mathematical problem (Please never do that! ??), merely providing the final answer might not be sufficient. You might also want the AI to show the step-by-step process it followed to reach that answer. Without specifying these expected steps, the AI might skip directly to the final result, missing the opportunity to demonstrate understanding or provide insight into the underlying logic. In other cases, the final result can be wrong, and checking the steps one by one can help to get the correct response.

No alt text provided for this image
sometimes you would like to check the logic

Prompt engineering is both an art and a science, a delicate balance of defining the task, setting the context, providing examples, outlining expected behaviour, clarifying what constitutes a good response, and delineating the expected steps towards the goal. Each of these components plays a unique role in guiding the AI to generate responses that are not only accurate but also relevant, engaging, and aligned with specific needs and expectations.

The first step on the long journey to becoming a prompt engineer is to understand the structure of a prompt. I hope this short article clarified a few things and helped you take this step.

Ali Usman

Mathematics || Python Developer || Aspiring Data scientist || HTML || CSS || Good Communicator

8 个月

Easy explanation. Well done sir

Sandra Kwentua

SEO content writer| Ghost Writer| Copywriter| Guest Writer

1 年

Thanks for sharing this. This is so educative!

要查看或添加评论,请登录

gyorgy bakocs的更多文章

社区洞察

其他会员也浏览了