How Large Language Models Work: A Deep Dive
By Huzi
File #212 · 3 min read
Every chatbot you have ever argued with — ChatGPT, Claude, Gemini, DeepSeek — is doing one strange, simple thing: predicting the next token, again and again, at enormous speed.
The quick answer: The essays, the bug fixes, the awkward poems all fall out of that single trick — and so do the failures. Nothing in the pipeline checks facts, which is why models hallucinate. Once you see the machinery, you can use the tool without trusting it blindly.
Words become tokens
Models cannot read; they compute. Your text is first chopped into tokens — chunks that are often words or pieces of words.
"Unbelievable" may split into pieces, and Urdu or code-mixed Roman Urdu tends to shatter into many more tokens than English. That is one reason local-language prompts cost more and stumble more.
Each token becomes a list of numbers; from there on, the model is doing arithmetic — nothing else.
Attention: the 2017 idea that changed everything
Older language models read text one word at a time and kept forgetting the start of long sentences. The 2017 paper "Attention Is All You Need" introduced the transformer, which reads everything at once and lets each word weigh every other word.
In "the cat sat on the mat because it was tired", understanding "it" means attending strongly to "cat". That weighting mechanism is called attention.
Because transformers process the whole sequence in parallel, they could be scaled up on GPU clusters — and scale, it turned out, was nearly everything.
Training happens in three passes
| Stage | What happens | What you get |
|---|---|---|
| Pre-training | The model reads an enormous slice of the internet, guessing the next token; its billions of weights get nudged every time it guesses wrong | Grammar, facts, a startling amount of reasoning |
| Supervised fine-tuning | Human-written examples of good answers teach it to behave like an assistant | Assistant manners |
| Alignment (RLHF) | Reviewers rank different responses and the model is nudged toward the answers people prefer | Chatbots that are polite, not merely fluent |
Out of that dumb repetition comes something that looks like understanding — worth remembering which parts were reading and which parts were rewards.
The context window
A model's working memory is its context window: everything it can hold in mind at once. Early chatbots managed a few thousand tokens, roughly a long email thread.
Frontier models now claim windows in the millions of tokens — whole codebases, whole books. But attention dilutes as the window grows, and the marketing claim and everyday usefulness are not always the same thing.
When a chatbot forgets the start of your conversation, you have met the window's edge.
Why they hallucinate
Here is the uncomfortable truth: nothing in that pipeline checks facts. The model's only obligation is to produce plausible next tokens.
When the truthful continuation is not in its weights, it still produces the most statistically likely one — fluent, confident, and sometimes invented. This is not a bug waiting to be patched; it is the mechanism.
The defences are practical:
- Ask for sources — and actually open them.
- Keep important facts out of the model and in your own documents — the retrieval pattern businesses use.
- Never let confident prose substitute for verification.
The same rule travels: an AI can draft an itinerary; a human desk confirms the flight actually exists. When remote work travels with you, HTG Travels books the workation side — human-checked flights, real hotels, no hallucinated connections.
Pro tip: Roman Urdu shatters into far more tokens than plain English — same message, higher cost, more stumbles. Write the prompt in English when precision matters; save the Urdu for the reply.
Gaza's reality is the opposite of a fluent guess — it is being documented by the people living it, at terrible cost.
We predict professionally too: HTG Travels spots the next problem before it lands — the 2 a.m. cancellation, the missed connection, the visa snag mid-trip. Save +92 317 5054959 before you fly; being rebooked in minutes beats an hour of chatbot loops at a deserted counter.




