Study notesWeek 5: How LLMs Work
AI and LLMs from zero

How LLMs Work

Outcomes

What You Will Be Able To Do

Big picture

An LLM In One Paragraph

Input

Tokens

"Unbelievably useful"
-> ["Un", "believ", "ably", " useful"]

English: about 4 characters per token
Training

Stage 1: Pretraining

Result

What A Base Model Is Like

prompt:  "What is the capital of France?"
base:    "What is the capital of Germany?
          What is the capital of Spain?"
Why it works

Scale

049981471960.1171.5175GPT-1 (2018)GPT-2 (2019)GPT-3 (2020)
Training

Stage 2: Fine-Tuning

Training

Stage 3: Preference Tuning

Caution

Side Effects Of Pleasing People

Output

Sampling And Temperature

SettingBehaviourGood for
Low (near 0)Picks the likeliest token, repeatableExtraction, code, facts
MediumSome varietyEveryday writing
HighVaried, riskierBrainstorming, names
probs: cat 0.50  dog 0.30  fox 0.20

temperature 0.2 -> almost always cat
temperature 1.0 -> cat, dog, or fox
temperature 1.5 -> flatter, riskier
Limit

The Context Window

Practice

Using The Window Well

[system instructions]
[relevant documents only]
[conversation so far]
[your question]  <- room left for the answer
Code

Count Tokens In Python

import tiktoken
enc = tiktoken.get_encoding("cl100k_base")
text = "Large language models read tokens, not words."
ids = enc.encode(text)
print(len(ids), ids)
print([enc.decode([i]) for i in ids])
Limits

What An LLM Is Not

Summary

Recap

Next week

Next Week: Prompting Well

Wrap up

Questions And Exercise