Skip to main content
CodingMarble

AI for everyone

How Large Language Models Work, Explained Simply

A large language model is a program trained on huge amounts of text to predict what piece of text comes next, and it writes answers by repeating that prediction one small step at a time. Because it is built to produce likely, fluent text rather than to look up verified facts, it can sound sure and still be wrong.

By CodingMarble · Published · 5 min read

A robot hand and a human hand reaching toward each other
Photo: Cash Macanaya on Unsplash

Step one: learning from a very large amount of text

A large language model, often shortened to LLM, begins as a program that knows nothing. It is then trained on an enormous collection of written material: books, articles, websites, forum posts and code. Training is not like reading with understanding. It is a repeated exercise in which the program is shown a piece of text with the next part hidden, makes a guess, and is told how far off it was. Each time, it adjusts itself slightly so that the next guess would be a little better.

Repeated an astronomically large number of times, this simple exercise forces the program to absorb grammar, common facts, writing styles, how arguments are structured and how code is laid out, since all of those help predict what comes next. Nobody types in rules about English or about the capital of a country. Whatever it knows is a by-product of getting good at prediction.

Tokens and next-token prediction

Models do not read words the way you do. Text is first cut into tokens, which are small pieces: sometimes a whole short word, sometimes part of a longer word, sometimes a space or a punctuation mark. The word 'unhappiness' might be split into a few tokens. Each token is converted to numbers so the program can work with it.

Given the tokens so far, the model calculates how likely each possible next token is. Suppose the text so far is 'The sun rises in the'. The token 'east' gets a high likelihood, 'morning' a fair one, and 'refrigerator' almost none. The model picks one token, adds it to the text, and repeats the calculation for the next. An answer of several paragraphs is built this way, token after token, each choice depending on everything before it.

Parameters: what the model has learned

The adjustments made during training are stored as parameters, which are simply numbers. You can picture a huge control panel with a vast number of dials. Training turns each dial slightly, millions of times, until the settings together produce good predictions. The finished model is those dial settings plus the fixed arithmetic that uses them.

This matters for two reasons. First, knowledge is not stored as a list of facts you could open and read; it is spread across the numbers, which is why nobody can point to the exact place where it 'knows' something. Second, once training is finished, the numbers do not change during an ordinary chat. The model is not learning from you in real time, although a service may keep your conversation or past notes in some other way, depending on its features and settings.

Why the same question can get different answers

When several next tokens are plausible, the model does not have to pick the most likely every time. A setting, often called temperature, controls how adventurous the choice is. Low values keep to the most likely token and give steadier answers. Higher values allow less likely tokens and give more varied, sometimes more creative, sometimes more erratic text. Because early choices shape later ones, a small difference at the start can lead to a quite different answer.

So if you ask the same question twice and get different wording, nothing is broken. It is also why you should not treat one answer as the answer. If the facts differ between attempts, at least one is wrong, and that disagreement is a useful warning.

The context window: working memory

A model can only consider a limited amount of text at a time, called its context window. It includes your instructions, anything you pasted, the earlier messages in the chat and the reply it is writing. You can think of it as a desk of limited size: everything on the desk can be used, and anything that does not fit is simply not seen.

In a long conversation early details can fall off or be handled less reliably, which is why a model may contradict something you told it an hour earlier. If a detail matters, repeat it in your latest message. The size of the window differs between systems and changes over time, so check the current documentation of whichever tool you use.

From text predictor to helpful assistant

A model trained only to continue text is not yet a good assistant. If you typed a question, it might continue with more questions, because that is what a list of questions looks like. To turn it into something that follows instructions, developers do additional training on examples of good requests and helpful answers, and often gather human ratings of which answers are better so the model learns to prefer them. This stage is generally called fine-tuning, and part of it is called instruction following.

The result is a model that answers politely, follows formatting requests and declines some harmful requests. It is still the same predictor underneath. The extra training changes its habits and style, not its basic way of producing text.

Why that explains fluent but sometimes wrong answers

Put the pieces together. The model is rewarded for producing likely text, not for checking a fact against reality. If its training contained little about a topic, it may still produce an answer that has the right shape: a believable name, a plausible date, a neat citation. Fluency comes from pattern, not from verification, so a confident tone says nothing about accuracy. Some tools reduce this by searching documents or the web and showing sources, but you still need to open the sources and read them.

Practical tip: when you need facts, ask the model to quote the passage it relied on from text you pasted in, then compare that quote with the original. Answers grounded in your own supplied document are easier to verify than answers from memory.

An analogy, and what we do not fully know

Imagine someone who has read an enormous library but has no way to check anything afterwards and is always expected to answer immediately. They have absorbed how people write about nearly everything, so they can produce a lovely answer on almost any subject. But when asked about something obscure, they do not say 'I never read about that'; they produce what such an answer would look like. The analogy is imperfect, since the model has no memories of reading and no sense of itself, but it captures the fluent-yet-unchecked quality.

It is also honest to say that researchers do not fully understand how these systems work inside. They can describe the training method and the arithmetic, but explaining exactly why a given set of numbers produces a particular behaviour is an active research area. Debates continue about what, if anything, these systems understand, how reliably they can reason and how to measure that. Be wary of anyone, whether enthusiast or sceptic, who claims certainty about it.

Need this built properly for your business?

CodingMarble is a remote studio in India that builds websites, apps and games on fixed packages with the scope written down before payment. Try the free tools we run, or start a project when you are ready.