Code-like Prompt Templates
A code-like prompt template enhances clarity by structuring instructions and input in a format that resembles a programming language. This approach is particularly effective for Large Language Models capable of understanding and generating both natural language and code, and it serves as an alternative to other formats like question-answer or direct instruction templates.
0
1
Tags
Ch.2 Generative Models - Foundations of Large Language Models
Foundations of Large Language Models
Foundations of Large Language Models Course
Computing Sciences
Ch.3 Prompting - Foundations of Large Language Models
Related
Example of a Prompt Template for Machine Translation
Code-like Prompt Templates
A developer is testing different ways to ask a language model to translate the English sentence 'The cat sat on the mat' into French. Consider the following three approaches:
Translate the following English text to French: The cat sat on the matEnglish: The cat sat on the mat Question: What is the French translation of this English sentence? Answer:- `def translate_to_french(english_text): """Translates the given English text to French.""" return model.translate(english_text)
input = "The cat sat on the mat" output = translate_to_french(input)`
Which option correctly identifies the format of each approach?
Examples of Instruction-like Prompts for Language Models
Improving Idiomatic Machine Translation
Constructing Machine Translation Prompts
Prompt Field Labeling for Clarity and Structure
Code-like Prompt Templates
An engineer is tasked with creating a prompt that instructs a language model to summarize a given text. Below are two versions of the prompt they are considering.
Prompt A: "Please summarize the following text for me. The summary should be exactly two sentences long and maintain a formal tone. The text to summarize is: The quick brown fox jumps over the lazy dog."
Prompt B: "INSTRUCTIONS: Summarize the provided text.
CONSTRAINTS:
- Length: Exactly 2 sentences.
- Tone: Formal.
TEXT: The quick brown fox jumps over the lazy dog."
What is the primary advantage of using the formatting in Prompt B over the formatting in Prompt A?
Refining a Prompt for Clarity
Evaluating Prompt Structure for a Chatbot
Learn After
Example of a Code-like Prompt for Machine Translation
Example of a Generic Code-like Prompt Template
Name:Content Prompt Formatting Style
Example of a Demonstration in a Code-like Prompt
A developer needs a large language model to perform two tasks on a given text: create a one-sentence summary and extract the names of any people mentioned. Below are two potential prompt structures for this task.
Structure A:
Summarize the following text in one sentence and list the names of any people mentioned. Text: {input_text}Structure B:
[INPUT_TEXT] = "{input_text}" [TASK_1] = Create a one-sentence summary. [TASK_2] = Extract all names of people. [OUTPUT] summary: people:Which of the following statements best analyzes why Structure B is a more effective prompt design for ensuring reliable and consistent results?
Improving Prompt Reliability for Information Extraction
Using Descriptive Prompts for Complex Tasks
Critiquing a Multi-Task Prompt