Generative AI for Beginners: Part 6 — Prompt Engineering, The Art of Communicating with AI

Raja Gupta
8 min readMar 12, 2024

This blog is part of the series Generative AI for Beginners, where we are learning basics of Generative AI, one simple step at a time.

To make it easy to grasp, I have divided the entire series in small parts. Each blog requires maximum 15–20 minutes to learn. After finishing the series, you will get a clear idea on fundamentals of Generative AI and its various aspects.

Part 1 — Introduction to AI

Part 2 — Understanding Machine Learning

Part 3 — Deep Learning: The Fundamental Pillar of Generative AI Advancement

Part 4 — Introduction to Generative AI

Part 5 — What is Large Language Model (LLM)?

Part 6 — Prompt Engineering: The Art of Communicating with AI [current blog]

Part 7 — Ethical Considerations in Generative AI

Part 8 — Challenges and Limitations in Generative AI

This is the 6th blog in this series where we will learn about prompt engineering.

Let’s quickly recap what we have learnt so far!

Artificial Intelligence (AI)

  • With a simple analogy and example, we learnt what AI is.
  • We learnt capabilities of AI and how it is changing our day-to-day life.
  • We looked into different types of AI with examples.
  • We also understood how AI is different from human intelligence.

Machine Learning (ML)

  • With a simple analogy and example we learnt what machine learning is.
  • We got a clear idea on supervised, unsupervised learning and reinforcement learning.
  • We learnt how ML is different from AI.
  • We looked into real-life examples and applications of ML

Deep Learning

  • We learnt how deep learning is inspired from human brain.
  • We understood how artificial neural network works.
  • We learnt how deep learning is used to solve complicated problems.

Generative AI

  • With a simple analogy and example, we learnt what Generative AI is.
  • We understood how Generative AI is different from AI.
  • We looked into real-life examples and applications of generative AI.

Large Language Model

  • We learnt what language model and large languga model is.
  • We understood how/why AI systems use large language model.
  • We looked into some popular large language models.

Now, let’s continue our journey and try to understand how we can have clear and effective communication with AI systems using Prompt Engineering!

Introduction

Have you seen the movie I, Robot? If yes, you will immediately understand the below image. For people who have not seen the movie, let me brief it.

In the movie, detective Spooner (played by Will Smith) is trying to investigate the death of his friend (and a scientist) Dr. Lanning. Before his death, Dr. Lanning has created his holographic image powered with AI which is supposed to help Spooner in finding answers.

However, sometimes when Spooner ask a question, the holographic image says, “I’m sorry! My responses are limited. You must ask the right questions.”.

A scene from the movie I, Robot

What’s the relevance of this scene in our discussion?

Have you Interacted with AI tools such as ChatGPT, but didn’t get the answer you were looking for? Or did you ever feel that the answer provided by ChatGPT is not up to the mark?

If you don’t get a proper/expected response from an AI system, for example ChatGPT, your first reaction would be that — The AI system is not good enough!

However, the real problem could be that you don’t know how to ask the right question or how to give right set of commands.

While interacting with ChatGPT, we need to know how to ask the right questions and give precise instructions to it — That’s exactly is Prompt Engineering!

In today’s world, where we see AI based systems everywhere, prompt engineering has emerged as a game-changing technique and is required to unlock the full potential of AI.

What exactly is a Prompt?

Prompts are the inputs or questions user gives to AI systems to get a specific response.

For example, if you want ChatGPT to write a story on animals for kids, you can use a prompt “Tell me a story which includes animal characters. The story is targeted for kids.” as shown below.

The AI systems (in this example ChatGPT) uses the prompt to generate response (in this example a text response, a kid’s story on animals). Depending on the type of AI system, the response could be either text, or image or video or something else.

Prompts can be:

  • sentences in plain English (or any other human language),
  • or code snippets
  • or commands
  • or any other combination of texts and code.

The generative AI program uses the prompt to understand what kind of content you want it to create, and then it generates new content based on that starting point.

Let’s take one more example. Below image shows a prompt used by DALL-E to generate an image — “An astronaut riding a horse in photorealistic style.”

A screenshot of DALL-E Web Page

The more specific and detailed your prompt is, the better the AI can understand what you want it to create.

What is Prompt Engineering?

Prompt engineering:

  • includes designing and optimizing prompts
  • in a strategic manner
  • to generate more accurate and desired response from AI systems.

Instead of asking a general question, prompt engineering involves providing specific instructions or context to get better results.

For example, instead of asking ChatGPT a generic question such as “Tell me about dogs,” you can use prompt engineering to get more focused results. For instance, you can ask, “What are the top 5 breeds of dogs known for their intelligence?”

By doing so, you’re guiding ChatGPT to give you a list of intelligent dog breeds.

To summarize:

  • With prompt engineering, you can tailor your questions, making them more specific and structured.
  • This way, AI systems (such as ChatGPT) can better understand your intent and provide more accurate and relevant answers.

How to use Prompt Engineering to get better results?

Let’s go deeper and understand how prompt engineering can help us to get better results. To make it simple to understand, take example of ChatGPT.

There are 3 important concepts in prompt engineering — Specificity, Contextualization and Fine-tuning.

Specificity

Specificity in prompt engineering means being clear and detailed in the instructions you give to the AI. Instead of asking a broad question, you give specific details about what you want the AI to do or talk about.

Let’s understand with below examples:

Non-specific Prompt: “Tell me about cars.”

Specific Prompt: “Can you describe the features of electric cars compared to traditional gasoline cars?”

Being specific helps the AI understand exactly what you’re asking for, so it can give you a better answer.

Contextualization

Contextualization in prompt engineering means giving the AI model clear details and information about the situation or task it’s being asked to do. It’s similar to providing a background story or setting the scene for the AI. This helps the AI system understand what it’s supposed to do and who it’s supposed to do it for.

For example, if you want the AI to write a story about a birthday party, you would provide contextualization by telling it things such as who the birthday person is, where the party is happening, and what kind of party it is (e.g., surprise party or themed party). This helps the AI create a story that fits the context you’ve provided.

Let’s take another example:

Non-contextualized Prompt: “Write a review of this product.”

Contextualized Prompt: “Write a review of this product focusing on its performance for outdoor activities.”

The contextualized prompt ensures that the generated review is tailored to the specific use case and audience, improving its relevance and usefulness.

Fine-tuning

Fine-tuning in prompt engineering involves iteratively adjusting and refining the prompt based on the AI system’s output. It is an ongoing process to optimize the prompts and guide AI system to generate desired outcomes.

Fine-tuning is a process of trial and error. We keep adjusting your prompt until you get the response you want.

Let’s understand it with an example.

Imagine you’re asking ChatGPT to write a short story about a dog.

Initial prompt: “Write a story about a dog.”

After getting the response, you might notice it’s too general or not exactly what you wanted. This is where fine-tuning comes in. You can adjust your prompt to give ChatGPT more guidance.

For example:

Initial prompt: “Write a story about a dog.”

Fine-tuned prompt: “Write a heartwarming story about a golden retriever named Max who helps a little girl overcome her fear of swimming.”

Fine-tuning is an iterative process. If the AI system’s response still isn’t quite right, you can keep adjusting the prompt until you get the desired outcome.

Some Examples of Good and Bad Prompts

Sure, here are some examples of good and bad prompts you can try with ChatGPT.

Bad Prompt: “Write a short story”

Good prompt (being more specific): “Write a short story about a detective solving a mysterious murder case.”

Explanation: The second prompt provides clear instructions and sets the context for the desired output, guiding the ChatGPT to generate a story focused on the specified theme and characters.

Bad Prompt: Explain photosynthesis”.

Good prompt (providing detail information): “Explain the process of photosynthesis in plants, including the role of chlorophyll and sunlight.”

Explanation: The second prompt specifies the topic and includes key details, helping the ChatGPT understand the specific information required and produce a coherent and informative response.

Bad Prompt: “What should I do today?”

Good Prompt: “Suggest some fun outdoor activities for a sunny day.”

Explanation: The first prompt is too general and open-ended. While the second one provides specific points and contexts.

How to Write Effective Prompts?

Here are some important points to keep in mind to write a clear and effective prompt.

Be Clear and Specific

Ensure that your prompt clearly communicates the task or question you want the AI system to address. Avoid ambiguity or overly complex language that could confuse the AI.

Provide Context

Give enough context for the AI system to understand the problem or topic it’s addressing. This helps the AI system generate more relevant and useful responses.

Use Examples

If applicable, provide examples to illustrate what you’re asking for. Examples can help the AI system understand the desired output and provide more accurate responses.

Ask Specific Questions

Instead of vague prompts, ask specific questions that guide the AI system toward the desired outcome.

Include Constraints

If there are any constraints or requirements for the response (e.g., word count limits, specific formats), make sure to include them in the prompt. This helps the AI system generate responses that meet your criteria.

Test and Iterate

Experiment with different prompts and observe how the AI system responds. Adjust your prompts based on the results to improve their effectiveness over time.

Focus on Clarity Over Creativity

While creativity can be beneficial in some cases, prioritize clarity and effectiveness in your prompts. Clear and straightforward prompts are more likely to produce the desired outcomes.

I hope that by now, you have got a clear idea on prompt engineering and how to write good prompts.

Question? Feedback? Please let me know in comment!

Next Blog

Part 7- Ethical Considerations in Generative AI

--

--

Raja Gupta

Author ◆ Blogger ◆ Solution Architect at SAP ◆ Demystifying Tech & Sharing Knowledge to Empower People