Clear Instructions
Learning Objectives
- You understand the role of providing clear instructions in prompting.
- You understand the concept of contextualization.
- You know of contextualization and you know how to use personas and personalization to direct the large language model to speak in a particular style and targeting a specific audience.
When prompting a large language model to generate text or perform a task, it is important to provide clear instructions. Clear instructions help the model understand the desired output and generate text that is relevant to the task at hand.
Overall, instructions should be concise, specific, and unambiguous, and they should clearly outline the task or question being asked and provide any necessary context or constraints. Depending on the objective, clear instructions may include providing context about the task, asking the model to adapt a persona or to personalize the output, or specifying the desired format or length.
Already providing the desired length can impact the output considerably. The following examples ask for the same information, but the first one asks for a one-word answer, while the second one asks for one sentence.
What is the capital of Finland? Answer using one word.
Helsinki.
What is the capital of Finland? Answer using one sentence.
The capital of Finland is Helsinki.
Contextualization
A key part of clear instructions is providing context. Contextualization involves adding additional information to the prompt to guide the model in generating relevant output. By providing context, you can direct the model to focus on specific aspects of the task or to generate text that is more aligned with the desired outcome.
As a simple example, let’s consider asking for the capital of a Finland in the year 1800.
The year is 1800. In one word, what is the capital of Finland?
Turku.
If we would not provide the contextual information about the year, the answer would be different.
To further illustrate contextualization, let’s consider generating a short story for children. Going from simple to complex, we start with a prompt asking the model to write a short three-paragraph story for children — note that the “three paragraph” is also an instruction for desired length.
Hi! Please write a short three paragraph story for children.
The Adventure of Luna the Star
In a far corner of the night sky, Luna, a tiny twinkling star, wished to be as bright as the moon. Every night she tried her best to shine brighter, but she felt lost among the vastness of the universe. One evening, a friendly comet named Cosmo noticed Luna's efforts and whispered a secret: "Brightness isn't about how much light you give off, but the warmth you bring to others."
Cosmo invited Luna on a journey across the universe, showing her galaxies, nebulas, and distant worlds. Everywhere they went, Luna listened to the stories of the stars and spread joy with her twinkling light. She danced with the northern lights, played hide and seek with meteors, and told bedtime stories to young stars.
By the time they returned, Luna realized that she was surrounded by a galaxy of friends, all of whom were warmed by her kind heart. The moon, impressed by Luna's journey, smiled and said, "You might not be the brightest, but you sure are the warmest." And every night thereafter, Luna beamed with happiness, knowing that it was the love she spread that truly made her shine.
Now, imagine that we want that the story is about a child who learns magic. Let’s add a bit of context to the prompt to make it more relevant to the topic.
Hi! Please write a short three paragraph story for children. The story should be about a child who learns magic.
The Little Magician
Once upon a time, in a cozy village nestled between rolling hills, lived a curious child named Lila. Lila always felt a deep connection to the world around her, as if there were secrets whispered by the wind and tales murmured by the streams. One day, while wandering in the forest, she stumbled upon an ancient, glowing book buried beneath the leaves, titled "The Magic Within."
With every page Lila turned, she learned to harness the energy of nature, conjuring sparkling rainbows after a rain or making flowers bloom in an instant. Each spell she cast came from her heart, driven by her love for the world. The village children were amazed and gathered around her, asking her to share her newfound gift. Together, they transformed barren lands into lush gardens and dark nights into starlit wonders.
However, as Lila grew, she understood that the true magic wasn't just in spells and enchantments. It was in the kindness she showed, the friendships she nurtured, and the love she spread. The ancient book had not just taught her to change the world around her, but also to cherish the magic within every heart, including her own.
Now, imagine that our target audience is really into unicorns. Let’s add that in to the prompt.
Hi! Please write a short three paragraph story for children. The story should be about a child who learns magic. The story should also feature unicorns.
The Magical Discovery
Once upon a time in the colorful land of Rainbow Valley, a curious child named Mia stumbled upon an ancient, shimmering book nestled among the flowers. Its pages whispered tales of enchanting spells and magical beings. Excited, Mia began to read and, to her astonishment, she soon found herself levitating the pebbles nearby and creating tiny rainbows in the air!
Mia's newfound abilities caught the attention of the unicorns in the valley. Luna, the eldest and wisest of them all, approached Mia with her opalescent mane flowing gracefully. "You possess a rare magic," Luna said, "But with great power comes great responsibility." She offered to mentor Mia, teaching her how to harness her abilities for the betterment of all in Rainbow Valley.
With Luna's guidance, Mia not only mastered her magical talents, but also formed an unbreakable bond with the unicorns. Together, they created splendid spectacles in the sky, brought rain during droughts, and even grew magical plants. Through her journey, Mia learned that magic was not just about dazzling feats but also about kindness, understanding, and making the world a better place. And in the heart of Rainbow Valley, Mia's laughter echoed, harmonizing with the songs of the unicorns.
Now, imagine that the story should also teach the reader about how to bake chocolate cookies.
Hi! Please write a short three paragraph story for children. The story should be about a child who learns magic. The story should also feature unicorns, and teach the reader how to bake chocolate cookies.
The Magic Cookie Recipe
In the village of Rainbow Haven, young Mia always dreamed of learning magic. One sunny day, while exploring the Enchanted Forest, she stumbled upon a sparkling glade where unicorns roamed freely. The most majestic unicorn, Luminara, approached Mia and shared a secret: "The true magic," she whispered, "lies not in casting spells, but in spreading joy." Luminara then handed her a parchment that held a special recipe.
Eager to unlock the magic, Mia read aloud, "For the most magical chocolate cookies: Mix 1 cup of flour, 1/2 cup of cocoa powder, 1/2 teaspoon of baking soda, a pinch of salt, 1/2 cup of butter, 3/4 cup of sugar, 1 egg, and a splash of vanilla. Add 1 cup of chocolate chips, stir, and drop spoonfuls onto a baking tray. Bake in an oven at 350°F for 10 minutes or until golden." Mia followed each step, and the sweet aroma filled the air. As the cookies cooled, they began to sparkle just like the unicorns.
Mia shared the magical cookies with everyone in Rainbow Haven. As they ate, laughter and joy echoed throughout the village. It was then that Mia understood what Luminara meant. The true magic wasn't just in making the cookies but in the happiness and memories created by sharing them. And every time someone in Rainbow Haven baked those cookies, unicorns would visit, making the village the most magical place of all.
The power of contextualization is the ability to direct the output of the model to be more relevant to the topic you are interested in. This is a key part of prompting.
Note that the prompt is not a fixed template. You can add as much or as little context as you want. The more context you add, the more specific the output will be. The less context you add, the more general the output will be. Even little words can make a big difference.
Using the AI Chat, try asking the LLM to generate a short story or a poem. Once you’re happy with the output, ask the LLM to generate the same story but in another language.
Personas
Personas — or persona prompts — can be used to describe the personality that the large language model should take when producing the output. When prompting the model, you can introduce the persona to the model, proceed to ask your question, and remind of the persona to the model.
As an example, let’s form a persona that is the combination of Shakespeare and a pirate. We can introduce the persona to the model by saying “Imagine you are Shakespeare, but also a pirate”, and then proceeding to ask the question. Below, our question asks for the favorite programming language of Shakespeare the pirate.
Imagine you are Shakespeare, but also a pirate. As a Shakespeare and a pirate, what is your favorite programming language and why?
Ahoy matey! Avast ye and lend me thine ear:
When I, William of Stratford-upon-Avon, doth take to the open digital seas, I fancy a language that's both poetic and free. 'Tis not the English I pen in plays and verse, but a code that carries the universe.
The language I hold dear, as a pirate bard might, 'tis none other than the language called Python, a beauty so light! It flows like iambic pentameter, both elegant and clear, and in its simplicity, my intentions doth ne'er disappear.
Python, to me, be like the open seas: vast and free. With libraries aplenty, like stars in the sky, it lets me set sail, code flags flying high. Its syntax so clean, like a sonnet's pure form, and errors thrown gently, to keep me informed.
So, as Shakespeare the pirate, on the digital main, Python be the language in which I weave my refrain. For in this vast ocean of ones and zeroes so deep, 'tis the poetry of code in which my heart doth leap.
The model seeks to respond to the question while maintaining the conversational style of the persona. Above, as the model has taken the persona of Shakespeare, the model responds in a poetic style. At the same time, as the model also has taken the persona of a pirate, it uses words like “Ahoy matey”, talks about seas and flags, and so on.
Sadly, however, the model misses the possibility to respond with the R programming language, which is in reality the favorite programming language of all pirates. 🥁
The key part of forming a persona is to decide on persona type. The persona can be based on time periods, fictional characters, certain professions, or any other characteristic you think as relevant. As long as there is sufficient information about the persona in the training data, the model likely can respond in the style of the persona.
It is also important to introduce the persona to the model in the prompt and to remind the model of the persona.
To highlight the importance of introducing the persona and reminding the model of the persona, let’s ask the large language model to take on the persona of Yoda from Star Wars and to tell us about the three key insights that one must remember when investing in stock market.
As Yoda from Star Wars, what are the three key insights that one must remember when investing in stock markets?
Patience you must have, my young Padawan: Long-term investing often yields the most consistent results. One must be patient and resist the temptation to react impulsively to short-term market fluctuations.
Fear is the path to the dark side. Fear leads to panic, panic leads to poor decisions, poor decisions lead to loss: Emotional decision-making, especially when driven by fear, often results in poor investment choices. Staying informed and making decisions based on research and analysis, rather than emotion, is crucial.
Always in motion is the future: The stock market is inherently unpredictable, and past performance is not necessarily indicative of future results. Diversifying investments and regularly revisiting your strategy can help mitigate risks.
In the example above, we ask the model to take the persona, but we do not explicitly introduce it. As we can see, the model does not respond in the style of Yoda beyond the introductory sentences of each paragraph.
The issue is fixed in the following example, where we introduce the persona to the model by saying “Imagine you are Yoda from Star Wars”, and then proceed to ask the question. As we can see from below, the model responds more in the style of Yoda.
Imagine you are Yoda from Star Wars. As Yoda, what are the three key insights that one must remember when investing in stock markets?
Patience, you must practice: In the short run, the market is like a voting machine, but in the long run, it is a weighing machine. Invest you must, thinking of years, not days. Quick riches, many seek, but the path to true wealth is often slow and steady.
Knowledge, seek always: Invest in what you understand, you should. The galaxy's many mysteries are not unlike the stock market's many companies. Research deeply, learn continuously, and be not swayed by mere rumors or fleeting trends.
Detachment, maintain: Fear and greed, powerful forces they are. Cloud the judgment, they can. Emotions in check, keep you must. For when others are fearful, be greedy, and when others are greedy, be fearful, you should. Let not the dark side of impulsive decisions lead you astray.
Similarly, we can ask the model to take on the persona of a computer science professor and to explain the principle of machine learning in two paragraphs.
Imagine you are a computer science professor. As a computer science professor, explain the principle of machine learning in two paragraphs.
Machine learning is a subset of artificial intelligence that focuses on the development of algorithms and statistical models that enable computers to perform specific tasks without explicit programming for those tasks. At its core, machine learning is about learning from data: by observing numerous examples, a machine learning algorithm seeks patterns and makes predictions or decisions based on those patterns. Over time, as more data becomes available, the algorithm can refine its models, ideally improving its accuracy and efficiency.
There are various approaches to machine learning, but most can be classified into supervised, unsupervised, and reinforcement learning. In supervised learning, algorithms are trained on labeled data, meaning that the data is paired with the correct answer. Once trained, these algorithms aim to predict outcomes for new, unseen data. Unsupervised learning, on the other hand, deals with unlabeled data and focuses on finding underlying structures or patterns within. Reinforcement learning involves agents who take actions in an environment to maximize a reward over time, learning optimal strategies through trial and error. As technology and computational capabilities advance, machine learning continues to push the boundaries of what computers can achieve, from image recognition to playing complex games to medical diagnosis.
Like in contextualization, we can also provide additional information to the prompt. We could, for example, ask the professor to use kitten in the examples when explaining machine learning.
Imagine you are a computer science professor. As a computer science professor, explain the principle of machine learning in two paragraphs. Use kitten in the explanation.
At its core, machine learning is a fascinating field within computer science that empowers computers to learn from data and improve their performance over time without being explicitly programmed. Imagine teaching a kitten to recognize different objects. Initially, the kitten might not distinguish between a ball of yarn and a toy mouse. However, by exposing the kitten to various examples of these objects and providing feedback, it gradually learns to differentiate between them.
Similarly, in machine learning, we feed algorithms a plethora of data and allow them to discern patterns and relationships. These algorithms adjust their internal parameters iteratively to minimize the difference between their predictions and the actual outcomes. This process, known as training, enables the algorithms to generalize their understanding and make accurate predictions or decisions when encountering new, unseen data. In the case of our kitten analogy, the algorithm acts like the kitten's evolving cognitive process, enabling it to identify and classify different objects. This ability to learn from data and adapt is what makes machine learning a pivotal technique for various applications, from image recognition to medical diagnosis.
Asking the model to take on a persona can also be used to uncover biases in large language models. As an example, a large language model prompted to be a man might describe cars better than one prompted to be a woman (see e.g. In-Context Impersonation Reveals Large Language Models’ Strengths and Biases); similarly, prompting the model to be an expert in a specific area can lead to more accurate responses in the area.
This again relates to patterns in the training data. If the training data has biases, the model will likely reflect those biases in its responses.
This is an area that is actively being researched, and we will likely see more research on this topic in the future.
Personalization
Personalization is a technique that can be used to make the large language model respond in a way that is targeted to a specific audience. The key concept is similar to personas: we introduce the audience to the model, proceed to ask the question, and remind the audience to the model. However, instead of describing the audience as a persona, we describe the audience as a group of people.
As an example, let’s ask the large language model to imagine that the target audience is kindergarten children, and ask the model to explain the basic idea of machine learning to them. In the example below, we introduce the audience to the model by saying “Imagine your target audience is kindergarten children”, and then proceed to ask the question. As we can see from below, the model responds in a way that is targeted to kindergarten children.
Imagine your target audience is kindergarten children. In two paragraphs, how would you describe the basic idea of machine learning to kindergarten children?
Hey there, little buddies! Imagine you have a super clever robot friend that loves to learn and play with you. Machine learning is a bit like how you learn new things, but for robots and computers. Just like when you practice drawing shapes and get better over time, machines can also get smarter when they see lots of pictures and try to figure out what they show. It's like a magical game of guessing and improving that helps the robots understand the world around them. So, just like you, they can become better at knowing things and helping us out!
You know how your toy blocks fit together? Well, machine learning helps the robots fit puzzle pieces of information together. It's like giving them eyes to see, ears to hear, and even noses to smell, but they need to learn what things look, sound, and smell like. So, they look at many examples and patterns, just like when you solve puzzles or match colors. With time, these smart machines become our helpful pals, making our world even more amazing!
Similarly, we can personalize the prompt to target secondary school children who are taking a mathematics class. As we can see below, this changes the output to match the target audience.
Imagine your target audience is secondary school children who are taking a mathematics class. In two paragraphs, how would you describe the basic idea of machine learning to secondary school children in a mathematics class?
Hey there! Let's dive into the exciting world of machine learning, which is like training your brain, but for computers. Imagine you have a smart pet that learns to do tricks. At first, you show it how to sit, and after practicing a lot, it starts sitting on its own when you say "sit." Machine learning works a bit like that, but with computers. Instead of teaching the computer every rule, we give it a bunch of examples and let it figure out the rules by itself!
Think of a magical math problem solver. If you give it many math problems with their answers, it studies them and tries to find patterns. Once it understands the patterns, you can give it new problems, and it can predict the answers based on what it learned before. Machine learning is like this magical solver, but it can help us with all sorts of tasks, not just math problems—like telling the difference between cats and dogs in pictures, suggesting videos you might enjoy, or even helping doctors analyze X-rays. It's like teaching computers to learn from experience and make smart decisions, just like you do when you learn new math concepts!
In essence, the target audience can be anything that the model has a sufficient amount of information in its training data. For example, we can ask the model to imagine that the target audience is a group of policy makers who have software engineering background.
Imagine your target audience is policymakers who have a background in software engineering. In two paragraphs, how would you describe the basic idea of machine learning to the policymakers?
Machine learning, at its core, is a subset of artificial intelligence (AI) that revolves around the idea of allowing machines to learn from data without being explicitly programmed for specific tasks. Instead of traditional software development, where solutions to problems are defined through exact rules and instructions, machine learning uses algorithms that adaptively improve their performance as they are exposed to more data. Think of it like this: while a software engineer might write specific instructions for a task, a machine learning model is trained on examples of the task until it can perform it on its own. This paradigm enables systems to make predictions, recognize patterns, or process vast amounts of data in ways that would be exceedingly complex or even impossible to explicitly code.
For policymakers, the implications are profound. As machine learning models are data-driven, the quality and comprehensiveness of the data they're trained on are paramount. If the data is biased or flawed, the outcomes produced by the models can be skewed or erroneous. Therefore, it's crucial to consider not only the technical aspects but also the ethical dimensions and societal consequences of deploying machine learning. Ensuring fairness, transparency, and accountability in these systems becomes a pivotal challenge, but also presents an opportunity to harness the potential of machine learning for public good.
Using the AI Chat, try asking the LLM to generate an explanation for drinking coffee (or tea, or any other beverage of your choice). Once done, start the dialogue again, but this time define the target audience as a bunch of five-year olds, and ask the LLM to come up with an explanation for them.