LLM course · astronomy department

How LLMs
actually work

…and how to actually work with them

Carson Davis

"cat" and "kitten" share zero letters.

How is a machine supposed to know
they mean almost the same thing?

Everything in this talk grows out of that question.

The arc

ACT I How LLMs actually work hand-built meaning → embeddings → transformers → the naked model
ACT II Working with basic LLMs tokens, context, style, grounding, tools, code, model literacy, chain of thought
ACT III The agentic half agents, skills, project context windows — next session

every beat leaves behind a key idea — they all come back as one fact sheet at the end

ACT I

How LLMs actually work

embeddings → next-word prediction → the naked model

Act I · 010

Meaning, by hand

the 80s–90s move: fake dictionary definitions as a matrix

wordis-animal?is-small?is-alive?is-…??
cat111?
kitten111?
rock000?
volcano000?
…449,996 more words????

which dimensions? · consistent across the whole language? · who finishes this?

key ideaYou cannot hand-write the meaning of every word as a matrix of yes/no features.

Act I · 020

Old-school NLP got real work done

stock traders, scraping tweets, keyword sentiment dictionaries

"I really like Apple, they're high-performing." +1 ✓
"Apple's not as high-performing as they used to be." +1

same keywords · opposite meaning · the definitions weren't the problem

key ideaA keyword dictionary can have every word's definition right and still miss the meaning of the sentence.

Act I · 030

Meaning, learned from data

the quick cat sat on the mat today …

a window slides over every sentence in every book

predictive · local

word2vec — 2013

train a shallow net to predict a word from its neighbors (or the neighbors from the word)

no matrix — the embeddings are the network's weights

count-based · global

GloVe — 2014

tally a giant co-occurrence matrix over the whole corpus, then factorize it

vector dot products ≈ log co-occurrence counts

…and they turned out to be mathematically almost the same trick

key ideaA word's meaning is captured by the company it keeps — either camp gives every word a vector of ~300 numbers.

Act I · 040

Meaning becomes geometry

man king woman queen same offset cat · kitten · jaguar

king − man + woman ≈ queen

subtract the vectors, cosine-match the vocabulary — queen pops out

search leaps too:
hurricane ≈ tropical cyclone
cat food ≈ kitten food

key ideaMeaning becomes geometry — related words cluster, and you can do math on meaning.

Act I · 050

One word, one vector — the ceiling

I'm banking on getting to the bank before it closes — I drove down by the riverbank and the car banked hard to the left…

reliance money river edge tilt [ 0.21, −0.77, 0.05, … ] one averaged embedding
key ideaA single embedding per word can't tell the riverbank from the bank where you withdraw money.

Act I · 060

Attention → next-word prediction

"Attention Is All You Need" — 2017

The cat sat on the ___ every word looks at every other word mat0.6 rug0.2 floor0.1 a distribution over the next word

static vectors

word2vec / GloVe · '13–'14

ELMo

contextual, via LSTM · early 2018

BERT

contextual, via transformer · late 2018

GPT

just predict the next token

contextual embeddings fixed "bank" — the transformer is what made them cheap at scale

key ideaAttention lets words look at each other; next-word prediction turns that into a text generator — an autocomplete.

Act I · 070

The scaling bet

OpenAI's wager: same architecture, more text, better model

GPT-12018 · kind of terrible
+ more data →
GPT-22019 · way better
+ more data →
GPT-32020 · actually good

hold onto this — the free lunch runs out later

key ideaPour enough text into next-word prediction and it becomes shockingly capable.

Act I · 080

Post-training: autocomplete → assistant

base model — next-word predictorcontinues your text; doesn't answer it
+
post-training — teach it to answer~10³–10⁴ hand-written ideal answers (SFT) + reinforcement from human preference rankings (RLHF)
=
a thing that talks to youInstructGPT recipe → GPT-3.5 → ChatGPT

a knob the company controls — remember that for style, and for tools

key ideaPost-training turns "continue the text" into "answer the question."

Act I · 090

Statistical truth, not knowledge

"The capital of Australia is ___"

Sydney0.58✗ wrong Canberra0.31 Melbourne0.09 if the corpus repeats the wrong thing, the wrong thing is the likely token

not confidently wrong —
because it was never confidently right

key ideaA naked LLM has no facts — it's truthful only because most of its training text was.
doDistrust unsourced factual claims from a bare model. Drop the word "hallucination."

Act I · 100

Temperature

"my dad went to the store to buy ___ and he never came back"

low T — sharpened

milk beer cigarettes eggs longsword volcano → "milk", every time

the model's distribution

milk.50 beer.15 cigarettes.12 eggs.08 longsword.004 volcano.001

high T — flattened

milk beer cigarettes eggs longsword volcano → "a miniature volcano"

softmax(logits / T) — one distribution, reshaped · it's literally Boltzmann

key ideaOutput varies because you sample from a distribution that temperature stretches or squashes.
doRaise temperature for novelty; lower it for the single most-likely, near-deterministic answer.

Act I · 110

The naked model

launch-day ChatGPT = next-word predictor + post-training. That's it.

amazing

✓ perfect, coherent English

✓ writes you anything — a poem, on demand

✓ a computer that talks back

frustrating

✗ states things that are just not true

✗ falls apart on complex instructions

✗ …and now you know exactly why

key ideaThe naked model is fluent and coherent, but has no facts and struggles with multi-part instructions.
Coherent. Confident.
Untrue — and it drops your instructions.

Everything from here is the workaround.

ACT II

Working with basic LLMs

tokens → context → grounding → tools → judging models

Act II · 120

Tokens, not words

geology geology

("something like" — every model's split differs)

same instinct as stemming: want / wanting / wanted → want

≈ 4 characters per token (English)

learned per model, bottom-up, by merging frequent pairs (BPE)

key ideaA token is a learned, semantically meaningful chunk of text — not necessarily a whole word.
doEstimate tokens as characters ÷ 4; expect the count to differ per model.

Act II · 130

The conversation illusion

turn 1 A
fresh model
never seen a word
B
turn 2 ABC
fresh model
never seen a word
D
turn 3 ABCDE
fresh model
never seen a word
F

an hour in: the entire transcript, replayed every turn, into a model with no memory

100,000 tokens of the old idea
50 of your new one
key ideaEvery turn re-feeds the whole transcript to a stateless model — there is no memory.
doTo unstick a model, don't argue at the end of a long thread — reset or prune the history.

Act II · 140

Context window & context rot

the cap: 8k tokens (2022) → 1M+ (now) — an economics limit, not a law of math

"lost in the middle" — position

recall dips in the middle start end of window recall

"context rot" — total input

well before the limit accuracy input tokens →

every frontier model degrades as input grows (Chroma, 2025) — more tokens = more distractors

key ideaA bigger window is not uniformly good context — performance sags as it fills.
doKeep the window lean and relevant. Don't dump everything in.

Act II · 150

Steering style

few-shot prompting = in-context learning — "Language Models are Few-Shot Learners," 2020

pretraining

whatever text it happened to see

post-training

the company's "be concise" layer

the window

yours — it's still a next-word predictor

want Shakespeare? spend 300,000 tokens on the actual works of Shakespeare

want your voice? paste three of your own posts in front of the ask

weak/local model? decompose: style-guide template → fill it from your sample → write to it

key ideaStyle lives in the weights and the window — and you can override the weights from the window.
doPaste 3+ samples of the target voice before asking for a draft.

Act II · 160

Grounding facts

ask the weights

"tell me the value from this paper"

one paper among tens of thousands, drowned out

hope & pray ✗

put it in the window

paste the paper, then ask about that

the fact is now in front of the model, not buried in it

grounded ✓

context is everything.

key ideaSupply the source instead of hoping the weights memorized it.
doPaste the paper / the data and ask about that — never ask the model from memory.

Act II · 170

Tool calling & the orchestrator

you 14.7 ÷ 16.9 ? next-word predictor naked LLM feed it straight in… "≈ 0.92, probably" ✗ never seen this exact string ORCHESTRATOR sits in the middle 1 hijacks the request tool calculator 2 extract the math 0.8698 3 question + 0.8698 → into the context window reply 14.7 ÷ 16.9 ≈ 0.870 ✓ 4 phrases the answer
key ideanaked LLM + tool + orchestrator — the architecture of every assistant you actually use.
doThink in terms of routing work to tools, not doing everything inside the chat window.

Act II · 170

Flavors of orchestrator

same LLM, retrained

post-trained to pick tools instead of answering

tiny specialist

a much smaller model that only routes

just prompted

an ordinary model told to orchestrate

Windsurf ran its own in-house coding orchestrator — until the big-boy models outran it

key ideaThe orchestrator is a design choice — retrained, tiny, or just prompted — each with tradeoffs.

Act II · 180

Search — the killer tool

"what pickups are in my bass?"

orchestrator

"this needs a real fact"

search tool

manufactures queries, runs them

the real page

the maker's spec sheet

context window

question + page summary

answer

grounded ✓

tool calling's double power: better abilities and a better context window, built for you

RAG — retrieval-augmented generation

later: your own RAG over your own scientific documents

key ideaRetrieval augments generation — pull the real source into the window at question time.
doRoute questions that need a live or authoritative source through search / retrieval.

Act II · 190

Why code beats prose

count in its head

"how many R's in strawberry?"

"2" ✗

it's predicting tokens, not counting letters

ask for the program

"write a letter-counter, run it on strawberry"

>>> "strawberry".count("r")
3

3 ✓

English: ~450,000 words, infinite phrasing · Python: ~1,000 core things, brutally constrained — and the training data pairs code with what it does

key ideaCode is tiny, constrained, and functional — models are simply more capable in code than in prose.
doFor counting, math, parsing: ask the model to write and run the program, not to do it in its head.

Act II · 200

Reading a model card: size

"3B · 7B · 36B · 70B" = billions of parameters · memory = params × bytes per param

FP324 bytes / param70B → ~280 GBresearch artifact
FP16 / BF162 bytes / param70B → ~140 GBthe native footprint
INT81 byte / param70B → ~70 GB
4-bit~0.5 byte / param70B → ~40 GBthe local sweet spot

and it wants to sit in GPU memory — spill to RAM and the bus speed throttles you

key ideaParameters × precision ≈ GB — a 70B model is ~140 GB native (FP16), ~40 GB at 4-bit.

Act II · 200

Quantization is lossy compression

semantic info isn't linear in precision — you save more size than you lose quality

you all know PCA: squeeze the space, keep the signal — same idea

Q4_K_M keeps roughly 92–95% of full-precision quality

rule of thumb, not a law — 2–3-bit breaks models

quality at the same footprint

36B 120B 36 GB 120B crushed to fit — loses 36B lightly quantized — wins memory footprint → benchmark quality
key ideaQuantization trades precision for size with sub-linear quality loss — PCA for weights.
doCheck size and quant level, then read the published accuracy stats — decide from the benchmarks.

Act II · 210

The scaling era ends

GPT-12018 GPT-22019 GPT-32020 GPT-42023 GPT-4.52025 OpenAI itself: "not a frontier model"

"we only have one internet" — data is the fossil fuel of AI (Sutskever, NeurIPS 2024)

curate

filter the junk out

synthesize

generate targeted training data

hire humans

pay for new data

worry: the new internet is LLM output — recursive training collapses models (Nature, 2024) · mixture of experts: the words exist; that's all we have time for

key ideaMore-data-forever broke — gains now come from better data, not more of it.
doDon't assume each new model is a leap from scale alone; weigh the data and technique behind it.

Act II · 220

Chain of thought

"5 blue houses and a red one. Jill's in the yellow house, Bob's in the green one. Which house does Sam live in?"

thinking… five blue + one red = six houses on the street … but Jill is in a yellow house — so Jill's house isn't one of the six? … same for Bob's green … so the named houses are elsewhere; the question never places Sam … wait — re-read the puzzle … the puzzle doesn't determine Sam's house …
→ "There isn't enough information to say which house Sam lives in."

the model writes out reasoning tokens before the answer — one continuous generation

each reasoning step is still next-word prediction — but the chain reaches answers a single pass can't

the "thinking…" spinner is literally these tokens streaming out

key ideaChain of thought = the model generating its reasoning as tokens before answering — not chopping up your input.

Act II · 220

The cost of thinking

thinking: low ↔ high — a knob you set

thinking tokens are billed as output tokens

a hard problem can emit 5–10× more of them

accuracy ↗ · latency ↗ · cost ↗

the curve you'll be reading for years

the knee — where you want to sit thinking tokens spent → performance
key ideaReasoning trades money and latency for accuracy — you pay for the scratch work as output tokens.
doThinking up for complex interdependent tasks, down for simple ones; judge future models on tokens-vs-performance, not size.

consolidation

The fact sheet so far

010meaning can't be hand-written as features
020right definitions can still miss the sentence
030meaning = the company a word keeps
040meaning becomes geometry — math on vectors
050one static vector can't hold four "bank"s
060attention + next-word prediction = the LLM
070scale made next-word prediction capable
080post-training turns autocomplete into an answerer
090no facts inside — never confidently right · drop "hallucination"
100temperature reshapes one distribution · dial it deliberately
110fluent + coherent, untrue + drops instructions
120tokens ≈ 4 chars, learned per model · chars ÷ 4
130every turn replays all of it, statelessly · prune, don't argue
140more context ≠ better context · keep the window lean
150style lives in weights and window · paste 3 samples
160context is everything · paste the paper
170naked LLM + tool + orchestrator · route work to tools
180RAG = retrieval into the window · search for live facts
190models are more capable in code · ask for the program
200params × precision ≈ GB; quantization is lossy PCA · read benchmarks
210better data now beats more data
220reasoning = generated tokens, billed as output · read the tokens-vs-perf curve

the full course closes with this sheet completed through Act III

End of the first half.

You now hold: a next-word predictor with no facts —
and every lever that makes it useful anyway.


Next session — Act III: agents, skills, and crafting a project's context window

the how-to reference lives at madebycarson.com/working-with-llms

Carson Davis · LLM course, first half