LLMs

LLMs

witten
Written By:Posistrength
6ab75e0bd1e10_LLMs.png
Share

Large Language Models (LLMs) like GPT, Claude, and Gemini can write essays, answer questions, and even code — but underneath the impressive output is a surprisingly mechanical process. Here's a breakdown of how they actually work.

1. It Starts With Tokens, Not Words

LLMs don't read text the way humans do. Before anything else happens, your input is broken into tokens — small chunks of text that might be whole words, parts of words, or even punctuation. "Understanding" might become "under" + "stand" + "ing," for example.

Each token is mapped to a number, because neural networks only understand numbers, not letters. This vocabulary of tokens (often 50,000–100,000+ entries) is fixed once the model is built.

2. Turning Tokens Into Meaning: Embeddings

Once text is tokenized, each token gets converted into an embedding — a long list of numbers (a vector) that represents its meaning in a high-dimensional space. Words with similar meanings end up with similar vectors. This is how a model captures the idea that "king" and "queen" are related, or that "Paris" relates to "France" the way "Tokyo" relates to "Japan."

3. The Transformer Architecture

The core engine behind virtually every modern LLM is the transformer, introduced in a landmark 2017 paper. Its key innovation is a mechanism called self-attention.

Self-attention lets the model weigh how relevant every other word in a sentence is to the word it's currently processing. In the sentence "The trophy didn't fit in the suitcase because it was too big," attention helps the model figure out whether "it" refers to the trophy or the suitcase — by looking at context across the whole sentence rather than just nearby words.

Transformers stack many layers of this attention mechanism (plus other neural network components) on top of each other — sometimes dozens or over a hundred layers — allowing the model to build increasingly abstract representations of language, from grammar to logic to reasoning-like patterns.

4. Training: Learning From Massive Amounts of Text

LLMs are trained in stages:

Pretraining — The model is fed enormous amounts of text (books, websites, code, articles) and given one simple task repeatedly: predict the next token. By doing this billions of times across trillions of tokens, the model implicitly learns grammar, facts, reasoning patterns, and writing styles — without ever being explicitly taught rules.

Fine-tuning — After pretraining, the model is refined on curated, higher-quality examples — often demonstrations of helpful, well-structured responses — to shape its behavior into something more useful and conversational.

Reinforcement Learning from Human Feedback (RLHF) — Humans rank different model outputs by quality, and this feedback is used to further adjust the model so it favors responses people actually prefer — more helpful, more honest, less harmful.

5. Generating Text: One Token at a Time

When you ask an LLM a question, it doesn't "think" of the whole answer at once. It generates text one token at a time: given everything so far (your prompt plus whatever it's already written), it calculates a probability distribution over every possible next token, then picks one — sometimes the most likely one, sometimes a sampled one to introduce variety — and repeats the process, feeding its own output back in as input for the next step.

This is why LLMs can occasionally go off track: each token is generated based on probability, and small early choices can shape everything that follows.

6. Why This Matters for Understanding LLM Behavior

This architecture explains a lot about LLM quirks:

  • Hallucinations happen because the model is fundamentally predicting plausible-sounding text, not looking up verified facts.
  • Context windows are limited because attention mechanisms get computationally expensive as the input grows longer.
  • Consistency issues can arise because each token is generated somewhat independently, guided by probability rather than a fixed plan.

Join our 5000+ Club

Get the latest updates on design, development, and technology trends right in your inbox.


But enough about us

we are keen to know about you!