Prompting

The effectiveness of a large language model (LLM) largely depends on the quality of its input, commonly referred to as the prompt. A well-crafted prompt not only guides the model’s behavior but also encourages high-quality and relevant outputs, enabling it to perform optimally.

Learning Objectives

At the end of this lesson, you should be able to:

  1. Explain the significance of well-crafted prompts in achieving effective large language model outputs.
  2. Apply various prompt writing techniques, such as providing clear instructions and breaking down tasks, to enhance large language model performance.
  3. Differentiate between system prompts and user prompts and describe their respective functions in guiding large language model interactions.
  4. Utilize advanced prompting strategies, including chain-of-thought and reason-and-act, to elicit more reasoned and structured responses from large language models.
Provide Clear Instructions

To produce good results with large language models (LLMs), consider employing various prompt writing techniques. One effective approach is to provide clear instructions that outline the objective of the task, the expected format of the output, any constraints or limitations, and relevant context or background information. For example: “Write a 250-word summary of the main events in Shakespeare’s Hamlet.”

Break Down Large Tasks

Splitting a large task into smaller subtasks is another way to optimize an LLM’s output, allowing us to guide its attention and focus towards specific aspects of the problem. This approach becomes particularly effective when asking the LLM to provide step-by-step guidance on each subtask. For instance: “Write a plan to prepare for an 8-hour road trip. Please break down your response into three sections: planning, preparation, and execution.”

Ask for Justification

Another technique involves asking the LLM to justify its responses, which encourages it to provide well-reasoned and logical outputs. This can be achieved by adding phrases such as “explain why” or “justify your answer.” For example: “What are three possible reasons why Romeo and Juliet’s families hate each other?”

Multiple Answers

Generating multiple outputs is another powerful technique that allows the model to explore different possibilities and perspectives, making it more robust and versatile. By asking the LLM to provide several options for an answer, we can give it the freedom to experiment with different ideas and approaches. For instance: “What are three possible solutions to world hunger? Please generate at least five responses and pick the best three.”

Minimize Recency Bias

To reduce the influence of recency bias, which refers to the tendency for LLMs (and humans) to give more weight to recent information over older or established knowledge, it’s essential to repeat instructions at various stages. This can be done by adding prompts that reiterate previous questions and ask the model to revisit its reasoning process. For example: “Can you revisit your explanation of how artificial intelligence is impacting society?” By repeating instructions, users can help LLMs maintain a balanced view of information.

Use Delimiters

Using delimiters within prompts is another way to enhance a large language model’s ability to process complex questions by providing visual cues that help it distinguish between different parts of the task. Delimiters are a sequence of characters or symbols that serve as important markers, enabling the LLM to recognize key places or distinct sections within your prompt. The use of specific delimiters such as curly brackets {}, double hash signs ##, and horizontal lines — can function effectively in this context. For instance, a possible prompt could be: “Summarize the text given between double hashtags ##text## and output it as a paragraph with no more than 50 words.” By incorporating these visual cues, you can help the LLM navigate complex tasks with greater ease and accuracy.

Provide Examples

Employing a few-shot approach can leverage the model’s existing knowledge to generate more accurate outputs. The few-shot approach involves providing only a small set of relevant examples or context alongside the main prompt. For example: “Describe a character like Jack Dawson from James Cameron’s Titanic who embodies the spirit of youthful rebellion and nonconformity”

Construct Prompts with LLMs

Meta prompts are prompts that create new prompts. With meta-prompts, we can hand over the task of crafting a prompt to the model itself. For instance: “Create a prompt that asks an LLM to explain how the concept of artificial intelligence is impacting modern society.”

Try Chain-of-thought

Chain-of-thought prompting involves guiding the LLM through its thought process by asking it to explicitly justify and reason about its responses at various stages of the task. This can be achieved by adding questions such as “How would you approach solving a math problem like $2x^2 + 5x - 3 = 0$? Please explain your steps.”

Try Reason-and-act

The reason-and-act technique takes this approach a step further, involving two distinct prompts: one for the LLM to provide a justification or explanation, and another for it to generate an output based on that justification. For example: “Explain why you think climate change is a pressing issue in today’s world. Based on your previous response, what actions do you recommend individuals take to mitigate their carbon footprint?”

System Prompts Vs User Prompts

In addition to these techniques, understanding the distinction between system prompts and user prompts can aid in crafting effective prompts. System prompts are used to set the stage for interaction by including instructions or guidelines on how to proceed with conversation, and they are always placed before user input. These prompts cannot be changed once set, providing a clear foundation for the conversation. In contrast, user prompts are the questions or queries asked by the user, which can sometimes be overridden by follow-up questions. The system prompt works in conjunction with the user prompt to generate a response, allowing the model to effectively understand and respond to the user’s query.

Final Thoughts

Ultimately, the power of large language models is unlocked through the art and science of prompt engineering. By mastering techniques such as providing clear instructions, breaking down complex tasks, asking for justifications, generating multiple outputs, minimizing recency bias, utilizing delimiters, offering examples, employing meta-prompts, and leveraging chain-of-thought or reason-and-act strategies, users can significantly enhance model performance. Furthermore, a clear understanding of the roles of system and user prompts is crucial for guiding interactions effectively, ensuring that these advanced AI tools deliver precise, relevant, and high-quality responses consistently.

comments powered by Disqus

Related Posts

Tokenization and Text Embedding

Ever wondered how modern AI systems understand human language? At their core, Large Language Models (LLMs) never actually see or read words as humans do.

Read more

Beyond Guesswork: Grounding LLMs in Facts

All large language models (LLMs) have two fundamental limitations: LLMs lack knowledge of events that occurred after their training date, a phenomenon known as the knowledge cutoff, and they tend to generate incorrect or fabricated information, often referred to as hallucination.

Read more

Mapping RDKit’s Codebase via LLMs

Historically, understanding the intricate internals of large codebases demanded exhaustive manual effort, whether deciphering legacy code through physical manuals or sifting through raw source code from an open-source repository.

Read more