A course for the astronomy department
How LLMs actually work
— and how to work with them
From hand-built word matrices to reasoning models, in two acts.
Act I
How LLMs actually work
One mental model, built from scratch: an LLM is a statistical next-word predictor with no facts of its own. Everything that follows is a workaround for a limitation established here.
Embeddings → transformers → scale → the naked model
010 hand-built definitional matrices
Cat and kitten share no letters.
So how is a machine supposed to know they mean the same thing? The 80s–90s answer: write the meaning in by hand.
A hand-built definitional matrix
| word | is-animal? | is-small? | is-alive? |
|---|---|---|---|
| cat | 1 | 1 | 1 |
| kitten | 1 | 1 | 1 |
| rock | 0 | 0 | 0 |
| volcano | 0 | 0 | 0 |
| aardvark | 1 | 0 | 1 |
| abacus | 0 | 1 | 0 |
| abandon… | ? | ? | ? |
…449,993 more rows to hand-fill. Consistently. For all of English.
You cannot hand-write the meaning of every word as a matrix of yes/no features.
020 old-school NLP & sentiment
Every definition right — meaning missed.
Keyword dictionaries got real trading work done on scraped tweets — until the sentence structure fought back.
I really like Apple, they’re high-performing
they’re not as high-performing as they used to be
A keyword dictionary can have every word’s definition right and still miss the meaning of the sentence.
030 word2vec & GloVe
Meaning is the company a word keeps.
Two competing recipes learned it automatically from all the text there is — from opposite ends of the same spectrum.
word2vec — predict the neighbors Mikolov et al., Google, 2013
GloVe — factorize the counts Pennington, Socher & Manning, Stanford, 2014
whole-corpus co-occurrence counts
two skinny matrices of word vectors
Two roads to nearly the same place — skip-gram was later shown to be an implicit factorization of the same co-occurrence statistics.Levy & Goldberg, 2014
The early research questions — how big a window? strip “a” and “the”? collapse want / wanting / wanted to one stem? — come back later, as tokens.
A word’s meaning is captured by the company it keeps — the words it co-occurs with.
040 what embeddings bought us
Meaning becomes geometry.
Every word is now ~300 numbers — related words cluster, and you can do arithmetic on meaning itself.
Vector space (2-D shadow of ~300 dims)
king − man + woman ≈ queen
Meaning becomes geometry — related words cluster, and you can do math on meaning.
050 the polysemy limit
Four banks, one blurred vector.
A static embedding saw every context and averaged them all together — that ceiling is what the next architecture had to break.
“I was banking on getting to the bank before it closed, so I drove along the riverbank and took the turn so hard the car banked left.”
one grey averaged embedding — “bank”
A single embedding per word can’t tell the riverbank from the bank where you withdraw money.
060 transformers → next-word prediction
“Attention is all you need” — 2017
Words look at each other, so a word's vector finally depends on its sentence — and the whole enterprise becomes predicting the next word.
Mask a word; predict it from everything else
Attention lets words look at each other; masked / next-word prediction turns that into a text generator.
070 the scaling bet
The bet: more data, nothing else.
OpenAI wagered that the same architecture, fed more text, would just keep getting better.
Hold onto this intuition on purpose — it breaks, audibly, in beat 210.
Pour enough text into next-word prediction and it becomes shockingly capable.
080 post-training into a chatbot
Why does it answer instead of continue?
A raw next-word predictor just continues your text. A second training layer retargets it at answering you.
+
=
“~10,000 Q&A pairs” is the right order of magnitude for step 1 — but it wasn’t just Q&A pairs; it was a small pile of human answers plus reinforcement learning from human rankings. And it’s a knob the company controls — remember that at style control.
Post-training turns “continue the text” into “answer the question.”
090 statistical truth, not knowledge
There are no facts in here.
Nothing in training makes the model correct — it speaks English the way English was spoken, and most of that text happened to be true.
“Humans use only ___ of their brains”
If the most-repeated version in the corpus is wrong, the wrong thing is the most likely token.
It isn’t confidently wrong — because it was never confidently right.
A naked LLM has no facts; it’s a statistical next-word predictor that’s truthful only because most of its training text was.
Distrust unsourced factual claims from a bare model — and drop the word “hallucination.”
100 temperature & creativity
One distribution, reshaped.
Temperature doesn't add a second distribution on top — it stretches or squashes the one the model already produced, then you sample.
“my dad went to the store to buy ___” softmax(logits / T)
For this room: it’s literally the temperature in a Boltzmann distribution — low T freezes into the ground state, high T populates the excited states.
Creativity is not remixing
“The ___ lapped the milk from the bowl.” Even if jaguar never once appeared there in the whole corpus, the model can still land on it — jaguar’s vector sits right next to cat’s. Structured novelty, not random words.
Output varies because you sample from a probability distribution that temperature reshapes before sampling.
Raise temperature for novelty; lower it to pull the single most-likely, near-deterministic answer.
110 — the hinge
The naked model — where ChatGPT started
Launch-day ChatGPT was a next-word predictor with post-training bolted on. Remember how that felt:
Amazing
- perfect, coherent English
- writes you a poem on demand
- anything you wanted, fluently
Those two frustrations are the to-do list for the entire rest of this talk.
The naked model is fluent and coherent but has no facts and struggles with complicated, multi-part instructions.
Act II
Working with basic LLMs
Practical technique for the two frustrations. The through-line: context is everything — nearly every fix is “put the right tokens in the window.”
Tokens → the window → grounding → tools → model literacy → chain of thought
120 tokens
Models don’t read words.
They read tokens — learned sub-word chunks, the same instinct as stemming from beat 030. This is the unit everything else is priced in.
Exact splits vary by tokenizer — “something like geo + logy,” not a guaranteed split.
A token is a learned, semantically meaningful chunk of text — not necessarily a whole word.
Estimate tokens as characters ÷ ~4; expect the count to differ per model.
130 the conversation illusion
The conversation is an illusion.
The single most important reframe of Act II — watch what actually happens as you chat.
A → AB → ABC… the whole transcript is re-fed every turn to a model that has never seen a word before.
To unstick a model, don’t argue at the end of a long thread — reset or prune the history.
140 context window & context rot
A million tokens — not a million good ones.
The window has a cap, and performance is not uniform across it. This is the master lever of the whole act.
Lost in the middle
positional effect — Liu et al., 2023Context rot
all 18 frontier models degraded — Chroma Research, 2025A bigger context window is not uniformly good context — recall sags in the middle and quality degrades as it fills: context rot.
Keep the window lean and relevant; don’t dump everything in.
150 style control & few-shot
Style lives in the weights and in the window.
You can spot "LLM voice" instantly — but the model isn't stuck with it, and the overlooked lever is yours.
The Shakespeare gambit: you have a million tokens — spend 300,000 of them on the actual works of Shakespeare and it gets very, very good at Shakespeare.
Style lives both in the weights and in the window — and you can override the weights by putting examples in the window.
Paste 3+ samples of the target voice. For weak models, decompose: template → fill → write.
160 — grounding facts in the window
Context is everything.
Don't ask the weights for facts. Find the true fact and put it in the window.
Ask the weights
The paper is one of tens of thousands in the training data — drowned out. Maybe the true fact is the most likely token. Maybe.
Paste the source
Download the paper, paste it in, ask about that. Infinitely more likely to be right — the fact is sitting in the window.
Supply the source instead of hoping the weights memorized it. The context you build is what you live or die on.
Paste the paper / the data and ask about that, rather than asking the model from memory.
170 tool calling & the orchestrator
naked LLM + tool + orchestrator
Grounding by hand is manual. Now automate it — this is the architecture behind every assistant you actually use.
Three flavors of orchestrator
Windsurf ran its own in-house orchestration model for coding — until the big labs got so good at it that the in-house model couldn’t keep up.
naked LLM + tool + orchestrator — the orchestrator hijacks the request, calls the tool, and puts the result into the context window.
Think in terms of routing work to tools, not doing everything inside the chat window.
180 search & RAG
Give the orchestrator a search bar.
Search is tool calling and grounding fused — it fetches the real page and builds a better context window automatically.
Forward pointer: when we get to serious work on scientific data, this is exactly what you’ll build locally — your own RAG over your own documents.
Retrieval augments generation — pull the real source into the window at question time.
Route questions that need a live or authoritative source through search / retrieval; later, build your own RAG.
190 why code beats prose
Ask for the program, not the answer.
Code is the highest-leverage tool there is — and a big part of your job is recognizing when to reach for it.
In its head
“How many R’s in strawberry?”
“2” ✗
It doesn’t see letters — it sees tokens. Even spelling it out and counting, it would still botch it: it doesn’t know things.
Through code
“Write a program that counts letters, then use it on strawberry.”
3
3 ✓
Still using the LLM. Still not doing the work yourself. Infinitely better answer.
Code is constrained and functional, so the model is both better at it and more capable through it.
For anything code is good at — counting, math, parsing — ask the model to write and run the program, not to do it from memory.
200 model-shopping literacy
How to eyeball a model.
The specific models die in six months. The rubric — size, memory, quantization, benchmarks — survives.
A 70B model, by precision memory = parameters × bytes per parameter
Where the memory sits matters
Quantization = lossy compression you all know PCA — same idea
Semantic information isn’t linear in precision, so you can throw away bits and lose far less quality than size. Degradation is non-uniform — read the model card’s published numbers.
Parameters × precision = memory; quantization trades precision for size with sub-linear quality loss.
When picking a local model, check size and quantization level, and compare published accuracy — a quantized 36B can beat a heavily-quantized 120B.
210 the scaling era ends
The free lunch ends.
Callback to beat 070, inverted: the more-data-forever bet stopped paying — and the field changed levers.
Capability per generation (qualitative)
“Pre-training as we know it will end… data is the fossil fuel of AI. We only have one internet.”
Ilya Sutskever — NeurIPS 2024More-data-forever broke; gains now come from better data, not just more of it.
Don’t assume each new model is a giant leap from scale alone; weigh the data and technique, not just the size.
220 chain of thought & the cost of thinking
The cost of thinking.
With scale-alone exhausted, this is the current frontier — and the finale ties the whole act together.
Five blue houses + one red house = six houses on the street…
Jill is in a yellow house — but no yellow house exists on this street. So Jill doesn’t live here.
Same for Bob and the green house. Neither constraint touches this street at all…
So Sam is the one who lives on the street — which house makes him distinct?
Sam lives in the red house.
The knob you get
High thinking: better results on complex, interdependent instructions — more tokens, more money, more latency. The real payoff isn’t word puzzles; it’s instructions the model can decompose and reconsider.
The graph to read for future models illustrative shape
Chain of thought = next-word prediction over generated reasoning steps, reaching answers a single pass can’t; you pay in tokens IN and tokens OUT.
Turn thinking up for complex, interdependent instructions and down for simple ones; judge models on token-spend vs. performance, not raw size.
■ where this leaves you
Every beat left a mark.
These bubbles have been accumulating the whole way — at the end of the full course they consolidate into a single fact sheet you take home.
Act III — the agentic half (agents, skills, project context, documentation) — is being dictated now. The course closes with the consolidated fact sheet and a pointer to the working-with-llms repo.