Learn how to use declarative prompts to generate natural language outputs for various tasks and domains. This blog is a continuation of our Prompting Strategies blog series. You can view Part 1: Understanding Large Language Models for Information Retrieval here.
Author: Steven Harvey Collaboration Architect @ CyclotronÂ
Â
If you want to get the most out of AI systems that can generate natural language, such as OpenAI's GPT-3, you need to know how to write good prompts. Prompts are the way you tell the AI system what you want it to do. However, not all prompts are equally effective. Some prompts can lead to irrelevant, inconsistent, or biased outputs, while others can produce coherent, relevant, and high-quality outputs.Â
One of the best techniques for writing good prompts is called declarative prompt engineering. This technique involves writing prompts that describe the desired outcome rather than the specific steps or commands. For example, instead of telling the AI system how to write a summary of a news article, you can simply tell it to write a summary of the main points and facts of the article. Declarative prompts can help you leverage the AI system's capabilities and creativity, while also providing guidance and constraints to ensure quality and relevance.Â
In this blog post, we will explain what declarative prompts are, why they are useful, and how to write them effectively. We will also give you some examples of declarative prompts for different domains and scenarios.Â
What are declarative prompts and why do you need them?Â
Declarative prompts are a way of communicating with AI systems, often used to generate natural language responses, such as summaries, stories, or explanations, from a given context or input.
Declarative prompts have many advantages over other types of prompts, such as instructive or generative prompts. First, declarative prompts are more intuitive and natural for you, as you do not have to learn a specific syntax or format. Second, declarative prompts are more flexible and adaptable, as you can use them for a wide range of tasks and domains without requiring a lot of domain knowledge or customization. Third, declarative prompts are more robust and reliable, as they reduce the risk of ambiguity, inconsistency, or bias in the output, as well as the need for manual correction or refinement.Â
The declarative mindset: How to think and write declarativelyÂ
Writing declarative prompts is not just a technique, but also a mindset. The declarative mindset is a way of thinking and writing that focuses on the what rather than the how. It is based on the idea that you can communicate your goals and expectations to the AI system without telling it exactly how to achieve them. The declarative mindset can help you write prompts that are clear, concise, and complete, while also giving the AI system more freedom and autonomy to generate the best possible response.Â
To adopt the declarative mindset, you need to follow some guidelines and practices that can help you think and write declaratively. Here are some of them:Â
Start with the end in mind. Before you write a prompt, think about what you want the AI system to do and why. What is the purpose and the audience of the prompt and the response? What are the desired outcomes and the success criteria? How will you measure and evaluate the quality and the relevance of the response?Â
Use the declarative prompt structure. A declarative prompt consists of three main components: the goal, the context, and the input:Â
The goal is the intended outcome or result of the prompt, such as a summary, a story, or an explanation. Â
The context is the background information or knowledge that the AI system needs to understand and generate the response. Â
The input is the data or information that the AI system will use to create the response. Â
Each component should be stated in a single sentence or phrase, and they should be aligned and consistent with each other.Â
Set realistic and explicit constraints and expectations. Constraints are the rules or limitations that the AI system must follow or respect when generating the response. Expectations are the criteria or standards that the AI system must meet or exceed when generating the response. Constraints and expectations can include aspects such as the length, format, tone, style, accuracy, originality, or coherence of the response. They should be realistic, consistent, and explicit, and they should be aligned with the goal and the context.Â
Use natural and simple language. Language is the medium of communication between you and the AI system. Language should be natural and simple, meaning that it should be understandable, unambiguous, and concise. Language should also be appropriate for the domain and the audience of the prompt and the response. You should avoid using jargon, slang, or technical terms that the AI system may not know or understand. You should also avoid using vague, complex, or ambiguous words or phrases that may confuse or mislead the AI system. By following these principles, you can write declarative prompts effectively. You can also use some tips and tricks that can help you improve your prompts, such as:Â
Use examples and templates. Examples and templates are useful tools that can help you write declarative prompts faster and easier. Examples are prompts that have been written by others or by yourself for similar tasks or domains. Templates are prompts that have a generic structure and format that can be adapted and customized for different tasks or domains. You can use examples and templates as inspiration or reference, but for best results, you should not copy or modify them directly. You should always write your own prompts that suit your specific goals and needs.Â
Test and iterate. Testing and iterating are essential steps that can help you evaluate and improve your prompts. Testing is the process of running your prompts on the AI system and checking the output. Iterating is the process of modifying your prompts based on the feedback and the results. You should test and iterate your prompts until you are satisfied with the output. Testing and iterating your prompts on different inputs and contexts, can also help to ensure that they are robust and reliable.Â
Examples of declarative prompts in actionÂ
To show you how to apply the declarative mindset and the declarative prompt technique in practice, let’s look at some examples of declarative prompts for different domains and scenarios. We'll explain how each prompt follows the principles and the tips of the declarative mindset and the declarative prompt technique.Â
Example 1: Summarize a news articleÂ
Let's say you want to use an AI system to summarize a news article for you. You could write an instructive prompt that tells the system how to do the summarization, such as:Â
Read the news article from the URL. Identify the main topic, the key facts, and the sources. Write a summary that contains the most important information and facts from the article. Use formal, neutral, and factual language. Make the summary no longer than three sentences.Â
However, this prompt is not very effective, as it is too long, complex, and specific. It also limits the AI system's flexibility and creativity, as it forces it to follow a rigid and predefined process. A better way to write the prompt is to use a declarative prompt that describes the desired outcome, such as:Â
Summarize the following news article in three sentences or less. Include the most important information and facts from the article. Title: Japan earthquake: Powerful 7.3-magnitude quake strikes off coast of Fukushima URL: [URL]Â
This prompt is more effective, as it is clear, concise, and complete. It also gives the AI system more freedom and autonomy, as it allows it to decide how to do the summarization. The prompt follows the principles and the tips of the declarative mindset and the declarative prompt technique, as it:Â
Defines the goal clearly and concisely: Write a summary of the main points and facts of the news article.Â
Provides the context and the input: The news article is about a recent earthquake in Japan. The title and the URL of the article are given.Â
Sets the constraints and the expectations: The summary should be no longer than three sentences and focus on important information and facts – Meaning, the summary should be accurate, informative, and concise.Â
Uses natural and simple language: The prompt language is formal, neutral, and factual.Â
Uses an example: The prompt gives an example of a news article that can be used as an input.Â
Tests and iterates: The prompt can be tested and iterated on different news articles and contexts, to ensure that it works well and produces good outputs.Â
Here is a possible output from the AI system:Â
A powerful 7.3-magnitude earthquake struck off the coast of Fukushima, Japan, on Saturday night, causing widespread power outages and shaking buildings. The quake was felt across the country, but no major damage or injuries were reported. The authorities said there was no risk of a tsunami, but warned of aftershocks and urged people to stay alert.Â
Example 2: Write a product reviewÂ
Let's say you want to use an AI system to write a review of a product that you bought online. You could write a generative prompt that provides some examples of reviews, such as:Â
Write a review of the following product that you bought online. Here are some examples of reviews: Example 1: I love this keyboard! It's compact, lightweight, and easy to use. I can connect it to my laptop, tablet, and phone with just one button, and switch between them effortlessly. The keys are soft and responsive, and the battery life is amazing. I've been using it for months and I haven't had to change the batteries yet. Example 2: This keyboard is a waste of money. It's bulky, heavy, and hard to use. I can't connect it to any of my devices, and it keeps disconnecting and lagging. The keys are stiff and noisy, and the battery life is terrible. I've been using it for a week and I already have to replace the batteries. Example 3: This keyboard is okay, but not great. It's fairly portable and easy to use, but it has some drawbacks. I can connect it to most of my devices, but not all of them. The keys are decent, but not very comfortable. The battery life is good, but not outstanding. I've been using it for a month and I'm not sure if I like it or not.Â
However, this prompt is not very effective, as it is too broad, generic, and inconsistent. It also limits the AI system's originality and diversity, as it encourages it to copy or modify the existing examples. A better way to write the prompt is to use a declarative prompt that describes the desired outcome, such as:Â
Write a review of the following product that you bought on Amazon. Share your experience, opinion, and recommendation of the product. Name: Logitech K380 Multi-Device Bluetooth Keyboard URL: [Amazon URL]Â
This prompt is more effective, as it is clear, concise, and complete. It also gives the AI system more freedom and autonomy, as it allows it to decide how to write the review. The prompt also follows the principles and the tips of the declarative mindset and the declarative prompt technique, as it:Â
Defines the goal clearly and concisely: Write a review of the product.Â
Provides the context and the input: The product is a wireless keyboard that you bought from Amazon. The name and the URL of the product are given.Â
Sets the constraints and the expectations: The review should be honest, personal, and helpful.Â
Uses natural and simple language: The prompt language is informal, friendly, and conversational.Â
Uses a template: The above prompt example acts like a template that can be adapted and customized for different products.Â
Tests and iterates: The prompt can be tested and iterated on different products and contexts, to ensure that it works well and produces good outputs.Â
Here is a possible output from the AI system:Â
I love this keyboard! It's compact, lightweight, and easy to use. I can connect it to my laptop, tablet, and phone with just one button, and switch between them effortlessly. The keys are soft and responsive, and the battery life is amazing. I've been using it for months and I haven't had to change the batteries yet. The keyboard is also very stylish and durable. It comes in different colors, and I chose the blue one, which looks great with my devices. The keyboard is also sturdy and resistant to spills and drops. I've accidentally spilled coffee on it once, and it still worked perfectly. The only downside is that the keyboard doesn't have a backlight, so it can be hard to see the keys in the dark. But that's not a big deal for me, as I usually use it in a well-lit environment. Overall, I'm very happy with this keyboard, and I would recommend it to anyone who needs a wireless keyboard for multiple devices.Â
Conclusion: How declarative prompts can help you get the most out of AI systemsÂ
In this blog post, we have explained what declarative prompts are, why they are useful, and how to write them effectively. We have also given you some examples of declarative prompts for different domains and scenarios. We have shown you how to apply the declarative mindset, a way of thinking and writing that focuses on the what rather than the how.Â
Declarative prompts are a powerful technique for generating natural language outputs from AI systems, such as OpenAI's GPT-3. They can help you leverage the AI system's capabilities and creativity, while still providing guidance and constraints to ensure quality and relevance. As you do not have to learn a specific syntax or format, or manually correct or refine the output, declarative prompts can also save you significant time and effort.Â
If you want to get the most out of AI systems that can generate natural language, declarative prompts are a great option that can help you achieve your goals and avoid common pitfalls, all while creating better and more engaging content for your audience and your domain. Â
Looking to maximize your organization’s AI investment? Get in touch to learn more about tailored integrations, custom AI platform creation, and people-driven change strategies that ensure you’re getting the most out of your AI systems.Â
Commentaires