Learning to speak
Foreword
Not sticking to the theme this time!
Anyways I came across this free(for now?) course earlier today and decided to give it a try. Turned out to be pretty cool. Took some notes, realised that they were already in markdown, so I’ll just store them here.
You can find a more verbose me in Prelude->2023-04-28
All information here is based on the ChatGPT Prompt Engineering for Developers short course by deeplearning.ai
Introduction
Two types of LLMs
1. Base LLM
Base LLMs are trained to predict the next most likely word to occur based on large amounts of text data fed to the model.
For example, a prompt such as:
1 | Once upon a time, there was a unicorn |
may be completed by the LLM to become
1 | Once upon a time, there was a unicorn that lived in a magical forest with all her unicorn friends. |
That sounds about right.
However, a prompt such as:
1 | What is the capital of France? |
may become
1 | What is the capital of France? |
As shown above, the Base LLM predicts the next lines to also be questions related to France, possibly due to the prompt closely resembling quizzes/question lists.
2. Instruction Tuned LLM
Instruction tuned LLMs are Base LLMs that are further “finetuned” with inputs and outputs of instructions being followed.
They are trained with RLHF, with a focus on being Helpful, Honest and Harmless.
The same prompt
1 | What is the capital of France? |
should output
1 | The capital of France is Paris. |
Strong note: if your chatgpt output is useless, you’re probably not being specific enough.
Tactics
Principals of prompting
- Write clear and specific instructions.
- Give the model time to think.
1. Use delimiters to clearly indicate distinct parts of the input
Example prompt:
1 | Summarize the text delimited by triple backticks into a single sentence. |
Example output:
1 | To guide a model towards the desired output and reduce chances of irrelevant or incorrect responses, clear and specific instructions should be provided which may be longer to provide more clarity and context for the model. |
Specifying clear delimiters can also help prevent prompt injection.
2. Ask for structured input
Example prompt:
1 | Generate a list of three made-up book titles along with their authors and genres. |
Example output:
1 | [ |
3. Ask model to check if conditions are satisfied
Example prompt:
1 | You will be provided with text delimited by triple quotes. If it contains a sequence of instructions, re-write those instructions in the following format: |
Example output:
1 | Step 1 - Get some water boiling. |
4. “Few-shot” prompting
Prior to performing our task, we give the model successful examples of task completion.
Example prompt:
1 | Your task is to answer in a consistent style. |
Example output:
1 | <grandparent>: A tree that endures the strongest winds is the one that has the deepest roots; a blade that withstands the sharpest cut is the one that has been most carefully tempered. |
5. Specify the steps required to complete the task
If the model is rushing to an incorrect conclusion, we should specify a chain of reasoning that the model should take before arriving at a final answer.
Example prompt:
1 | Your task is to perform the following actions: |
Example output:
1 | Text: <In a charming village, siblings Jack and Jill set out on a quest to fetch water from a hilltop well. As they climbed, singing joyfully, misfortune struck—Jack tripped on a stone and tumbled down the hill, with Jill following suit. Though slightly battered, the pair returned home to comforting embraces. Despite the mishap, their adventurous spirits remained undimmed, and they continued exploring with delight.> |
6. Instruct the model to work out its own solution before rushing to a conclusion
This is a useful way to force the model to spent some more processing time on the task instead of “guessing” the output.
Example prompt:
1 | Your task is to determine if the student's solution is correct or not. |
Example output:
1 | Let x be the size of the installation in square feet. |
Note: The current model is prone to hallucination
, which is spilling out made up information that sounds realistic. A trick to reducing hallucinations is to ask the model to first quote or find relevant information, then answer based on the information found. That way we can trace back the model’s output to sources which we can verify.
Iterative Prompting
Prompt engineering is an iterative process and the first prompt rarely outputs the desired result. It’s important to therefore analyze the output and ammend prompt, while sticking to the tactics mentioned above.
Some ideas include:
- Use at most 50 words.
- Focusing on <part of text>
- Include <additional information>
- Include a table with <specifications>
Honestly quite subjective so not much to take note of, apart from the fact that LLMs aren’t great at counting characters due to the nature of the tokenizer, so try to limit output by words/sentences.
Example prompt:
1 | Your task is to help a marketing team create a |
Summarizing and Inferring
A great use of LLMs at their current stage is to summarize content.
Most of the tips are already mentioned above in either the Tactics
section or the Iterative prompting
section.
One additional tip is to try using the keyword extract
instead of summarize
.
Example prompt:
1 | Your task is to extract relevant information from a product review from an ecommerce site to give feedback to the Shipping department. |
In real life this may be used by an ecommerce business owner to build a dashboard displaying summaries of reviews. LLMs can be used to identify the lexical affects of texts.
Example prompt:
1 | Identify the following items from the review text: |
Transformation
LLMs are trained on large sets of data in (hopefully)varying languages, meaning that it probably has a decent grasp of common languages.
Besides using it for sentence to sentence translation, here are some more usecases.
Tone transformation
Example prompt:
1 | Convert the following from slang to a business letter: |
Example output:
1 | Dear [Recipient], |
Format conversion
Example prompt:
1 | Translate the following python dictionary from JSON to an HTML table with column headers and title: |
Example output:
1 | <table> |
Proofreading
To signal to the LLM that you want it to proofread your text, you instruct the model to ‘proofread’ or ‘proofread and correct’.
Example prompt:
1 | Proofread and correct this review. Make it more compelling. |
Expansion
Lastly, LLMs can be used to create/extend text given a user input.
This example tasks the LLM to reply to customer review emails based on the sentiments and details in the customer’s original email.
Example prompt:
1 | You are a customer service AI assistant. |
Conclusion
See Prelude!