Introduction
- So base LMMs has been trained to predict the next word based on text training data Often trained on a large amount of data from the internet and other sources to figure out what's
the next most likely word to follow.
- So for example, if you were to prompt this once upon a time there was a unicorn It may complete this, that is it may predict the next several words are That live in a magical
forest with all unicorn friends But if you were to prompt this with what is the capital
of France Then based on what articles on the internet might have It's quite possible that a
base LLMs will complete this with What is France's largest city, what is France's population and so on Because articles on the internet could quite plausibly be lists of quiz questions about the country of France.
- In contrast, an instruction tuned LLMs, which is where a lot of momentum of LLMs research and practice has been going An instruction tuned LLMs has been trained to follow instructions So if you were to ask it, what is the capital of France is much more likely to output something like the capital of France is Paris
- So the way that instruction tuned LLMs are typically trained is You start off with a base LLMs that's been trained on a huge amount of text data And further train it for the fine tune it
with inputs and outputs that are instructions and good attempts to follow those instructions And then often further refine using a technique called RLHF reinforcement learning from human feedback To make the system better able to be helpful and follow instructions Because
instruction tuned LLMs have been trained to be helpful, honest and harmless.
- So for example, they're less likely to output problematic text such as toxic outputs compared to base LLMs A lot of the practical usage scenarios have been shifting toward instruction tuned LLMs Some of the best practices you find on the internet may be more suited for a base LLMs
But for most practical applications today, we would recommend most people instead focus on
instruction tuned LLMs Which are easier to use and also because of the work of OpenAI and other LLM companies becoming safer and more aligned So this course will focus on best practices for instruction tuned LLMs Which is what we recommend you use for most of your applications.
Guidelines
- So, for the principles, the first principle is to write clear and specific instructions. And the second principle is to give the model time to think.
Guidelines for Prompting
- In this lesson, you'll practice two prompting principles and their related tactics in order to write effective prompts for large language models.
Setup
Load the API key and relevant Python libaries.
- In this course, we've provided some code that loads the OpenAI API key for you.
**import** openai
**import** os
**from** dotenv **import** load_dotenv, find_dotenv
_ **=** load_dotenv(find_dotenv())
openai.api_key **=** os.getenv('OPENAI_API_KEY')
helper function
- Throughout this course, we will use OpenAI's
gpt-3.5-turbo
model and the chat completions endpoint.
- This helper function will make it easier to use prompts and look at the generated outputs:
**def** get_completion(prompt, model**=**"gpt-3.5-turbo"):
messages **=** [{"role": "user", "content": prompt}]
response **=** openai.ChatCompletion.create(
model**=**model,
messages**=**messages,
temperature**=**0, *# this is the degree of randomness of the model's output*
)
**return** response.choices[0].message["content"]