How AI Language Models Actually Work
You type a question, and a few seconds later an AI writes back a clear, confident answer. It feels like talking to something that knows things. But under the hood, a large language model (LLM) does one surprisingly simple job, over and over. Once you understand that job, a lot of AI behaviour starts to make sense: why it's brilliant at some tasks, why it forgets things, and why it sometimes makes things up.
This post walks through how it works in four pictures. No maths needed.
1. Text becomes tokens
A model can't read letters. Before your text reaches it, a tokenizer chops it into small pieces called tokens and turns each one into a number. Common words are usually one token; longer or rarer words get split into several.

This explains a few everyday quirks:
- Pricing and limits are counted in tokens, not words. In English, one token is roughly three quarters of a word.
- Models can be oddly bad at spelling and counting letters. They see "believ" as one unit, not as six letters.
- Other languages often cost more tokens. Tokenizers are trained mostly on English, so Indonesian or Malay text may be split into more pieces.
2. Predict the next token, then repeat
Here's the core idea: an LLM is a very sophisticated next-token predictor. Given the text so far, it scores every token in its vocabulary by how likely it is to come next. Then one token is picked, added to the text, and the whole process runs again. A long answer is just this loop running hundreds of times.

Where does the "intelligence" come from, then? From training. The model has seen an enormous amount of text, and to predict it well it had to pick up grammar, facts, reasoning patterns and coding conventions along the way. Prediction is the job; knowledge is the side effect.
You'll often see a setting called temperature. It controls how adventurous the picking step is. Low temperature almost always takes the top choice, which is great for code and facts. Higher temperature lets less likely tokens through, which is useful for brainstorming but more likely to wander off.
3. The context window is the model's whole world
A model doesn't remember your conversation the way a person does. Every time it replies, the app sends it the conversation so far: your messages, its earlier replies, any files or instructions. That bundle has a hard size limit called the context window, measured in tokens.

Practical consequences:
- Long chats drift. When a conversation outgrows the window, older parts get dropped or summarised, so the model can genuinely "forget" what you agreed earlier.
- A new chat starts from zero. Unless the app adds a memory feature, nothing carries over between conversations.
- Put the important things in front of it. Restating key requirements, or pasting the relevant file, often beats hoping the model remembers.
4. Why models make things up, and how grounding helps
Because the model's job is to produce likely text, it will always produce something. When it knows the answer, likely and true line up. When it doesn't, say a niche API, a recent event, or your company's internal process, it still fills the gap with text that sounds right. That's a hallucination: not a lie, just a fluent guess.

The most reliable fix is grounding: give the model the facts instead of asking it to recall them. The common pattern is called RAG (retrieval-augmented generation). The app first searches documents, a database or the web, then places the relevant passages into the context window along with your question. Now the model is summarising text in front of it rather than guessing from memory, and it can point to its source.
Tools like the Model Context Protocol (MCP) are a big part of this: they give a model a standard way to fetch real data, like reading files or querying an API, instead of improvising.
What this means when you use AI
- Give context, not just instructions. The model only knows what's in its window, so paste the error, the file or the spec.
- Ask for sources on factual questions, and check them. A grounded answer is checkable; a guess isn't.
- Start fresh when a chat goes sideways. A clean window with a clear summary often works better than ten more corrections.
- Verify anything that matters. Run the code, check the numbers, read the docs. The model is a fast, capable assistant, not an oracle.
An LLM is, at heart, a remarkably good next-word predictor working inside a fixed-size window. Keep that picture in mind and you'll know when to trust it, when to check it, and how to give it what it needs to do its best work.

