What Is a Large Language Model? How LLMs Work, Explained Without the Hype
Understand what is really happening when an AI writes text. Learn about tokens, embeddings and attention in plain language, run a tiny next-word predictor, and see why these models can be brilliant and wrong at once.
- A large language model is a neural network trained on huge amounts of text to predict what comes next.
- It works on tokens, and uses attention to weigh which earlier tokens matter most.
- It generates a reply one token at a time, by choosing from a set of probabilities.
- It can sound confident while being wrong, so important output needs checking.
Tools that chat, summarize and write code seem almost magical, until you see the mechanism underneath. A large language model, or LLM, is at heart a very sophisticated system for predicting the next piece of text. That one idea explains both what these tools do well and why they fail in the ways they do.
This guide explains the main concepts without any maths, then builds a tiny next-word predictor to make the idea concrete. We ran that code on Python 3.13, and the output comes from that run. It is a simple counting toy rather than a neural network, and real LLMs are vastly more capable. We also avoid quoting figures for specific models, because they change quickly.
What is a large language model?
An LLM is a type of artificial intelligence trained to understand and generate human language. Let us take the name one word at a time:
- Large: it has a huge number of adjustable internal values, called parameters, and it learns from an enormous amount of text.
- Language: it works with text, including natural language and code.
- Model: it is a mathematical system that captures patterns from data and uses them to make predictions.
Models are the engine, and products such as chat assistants are the car built around them. A product often adds a user interface, safety systems, search and other tools.
The core idea: predicting what comes next
You do this yourself. If you read “the capital of France is”, your mind offers “Paris” right away. An LLM does something comparable, but on a much larger scale. Given some text, it calculates how likely each possible next token is, picks one, adds it to the text and repeats.
There is no database of stored answers being looked up. The model holds patterns learned during training, in the form of numbers. When those patterns line up with the truth, you get a correct answer. When they do not, you can still get a fluent answer, and that is an important difference from a search engine.
A tiny working demo
To see next-token prediction in its simplest form, this script counts which word follows which in a tiny text. It then generates new text from those counts. Statisticians call this a bigram model.
import random
from collections import Counter, defaultdict
TEXT = """the cat sat on the mat . the dog sat on the rug .
the cat saw the dog . the dog saw the cat ."""
tokens = TEXT.split()
follows = defaultdict(Counter)
for current, following in zip(tokens, tokens[1:]):
follows[current][following] += 1
def probabilities(word):
counts = follows[word]
total = sum(counts.values())
return {w: round(n / total, 2) for w, n in counts.most_common()}
print(probabilities("the"))
print(probabilities("sat"))
# {'cat': 0.38, 'dog': 0.38, 'mat': 0.12, 'rug': 0.12}
# {'on': 1.0}
That output is a probability distribution. After “the”, the model considers “cat” and “dog” most likely. Now we generate text by repeatedly sampling from those probabilities:
def generate(start, length, seed):
rng = random.Random(seed)
words = [start]
for _ in range(length):
counts = follows[words[-1]]
words.append(rng.choices(list(counts), weights=counts.values())[0])
return " ".join(words)
print(generate("the", 6, seed=1))
print(generate("the", 6, seed=2))
print(generate("the", 6, seed=3))
# the cat . the cat saw the
# the rug . the cat . the
# the cat saw the dog . the
Notice three things. The same start can produce different text, because the choice is random. The output resembles its training data, even for sequences that never appeared in it. And it has no understanding at all, which is why “the rug . the cat” reads like nonsense.
Ask it about a word that it has never seen, and it has nothing to offer: follows["elephant"] is empty. Our toy only looks at one previous word. The enormous leap in real LLMs comes from considering long stretches of context, and learning from far more data, using a neural network rather than a simple count.
Tokens: how a model reads
LLMs do not read whole words as we do. Text is first split into tokens, which may be a word, part of a word or punctuation. Each token maps to a number, and the model works entirely with numbers.
Tokens matter in practice for two reasons. Usage of hosted models is commonly priced by tokens, and each model has a limit on how many it can handle at once. Tokenization also explains some famous odd behaviour. Because models see chunks rather than letters, tasks such as counting the letters in a word have traditionally been surprisingly hard for them.
Embeddings: meaning as numbers
Each token is turned into an embedding, a long list of numbers that places it in a kind of meaning space. Related concepts end up close together, so “cat” and “kitten” have nearby positions, while “cat” and “invoice” do not.
The same idea powers semantic search, in which you find documents by meaning rather than exact words. Our vector database guide covers that use.
Attention and the transformer
Most modern LLMs are based on the transformer architecture, introduced by Google researchers in the 2017 paper “Attention Is All You Need”. Its key mechanism is self-attention.
Consider this sentence: “The trophy did not fit in the suitcase because it was too big.” What does “it” refer to? You know it means the trophy. Attention lets a model weigh every earlier token when processing each new one, so it can link “it” to the most relevant words, even when they are far apart.
Earlier approaches processed text step by step and tended to lose track of distant words. Transformers look across the context together, and they can run much of this work in parallel on specialized hardware, which made training on such large amounts of text practical.
How an LLM is trained
| Stage | What happens |
|---|---|
| Data collection | Large amounts of text are gathered and cleaned |
| Pre-training | The model repeatedly predicts the next token, and its parameters are nudged whenever it is wrong |
| Fine-tuning | It learns from examples of helpful answers, with human feedback often used to rank responses |
| Evaluation | Teams test it for quality, safety and failure cases |
Pre-training gives a model broad language ability, but it may just continue your text rather than answer it. The later stages shape it into a useful assistant. Training large models takes substantial computing power and is expensive. Using a finished model, known as inference, is far cheaper per request.
How it generates text
- Your prompt is split into tokens and converted to embeddings.
- The network processes them, using attention to relate them to each other.
- It outputs a probability for every possible next token.
- One token is selected and added to the context.
- Steps 2 to 4 repeat until it reaches a stop condition.
This is why replies typically appear word by word when streamed. The text is literally being produced in sequence. Temperature controls how adventurous step 4 is: low values favour the most likely tokens, while higher values allow more variety.
Tip: For extraction, classification and other repeatable tasks, use a low temperature where the setting is available. For brainstorming, a higher setting can be useful. Even so, a low value does not guarantee identical answers every time.
Terms you will meet
| Term | Meaning |
|---|---|
| Prompt | The input you give the model |
| Context window | The maximum number of tokens it can consider at once |
| Parameters | The internal values learned during training |
| Inference | Running a trained model to get output |
| Hallucination | Confident output that is false |
| Knowledge cutoff | The point after which training data ends |
| RAG | Fetching documents to give a model extra context |
| Open-weight model | A model whose parameters you can download and run yourself |
Limitations you should know
- Hallucinations. A model can invent facts, citations or code functions. Because it produces likely text, false statements can look completely plausible.
- Knowledge cutoff. Unless a product connects it to search or other tools, it may not know about recent events.
- Limited context. If a conversation exceeds the context window, earlier details may be dropped or summarized. Models also do not automatically remember past chats, unless a product adds that feature.
- Bias. Training data reflects human biases, and those can appear in output.
- Inconsistency. The same question can produce different answers, which matters when you build software on top of one.
- Security risks. Hidden instructions in text can manipulate a model, a problem known as prompt injection.
Using LLMs well
Treat an LLM as a fast, capable assistant whose work needs reviewing. A few habits make a big difference:
- Be specific. Clear instructions, context and examples give better results. Our guide to prompt engineering shows how.
- Supply the facts. When answers must come from your own documents, use RAG rather than relying on memory.
- Verify what matters. Check figures, citations and legal or medical claims against reliable sources.
- Test generated code. Run it and write tests for it, as you would for a colleague’s. Our AI code review tools guide covers some assistance.
- Protect sensitive data. Check your organization’s rules before sharing confidential information with a hosted tool.
If you are deciding how to customize a model for your own work, our comparison of RAG vs fine-tuning vs prompt engineering will help you choose.
Final thoughts
An LLM is a next-token predictor trained at an extraordinary scale, and it is more useful and more fallible than that description suggests. Keeping the mechanism in mind helps you use it well: it is strong with language and patterns, and it needs your supervision on facts. To make it concrete, run the small script above with your own text, then try the same prompt several times in a real assistant and compare the answers.
Frequently asked questions
What is a large language model in simple terms?
It is an AI system trained on huge amounts of text to predict what comes next. By repeating that prediction, it can answer questions, write and summarize.
What is the difference between AI and an LLM?
AI is the broad field of building intelligent systems. An LLM is one specific type of AI model, focused on processing and generating language.
Do LLMs understand what they say?
This is debated. They capture rich patterns of meaning and can reason through many problems, but they do not experience the world and can fail in ways a person would not.
Why do LLMs make things up?
They generate likely text rather than retrieve verified facts. When patterns point towards a plausible but false answer, the model can state it with apparent confidence.
What is a token in an LLM?
A token is a chunk of text the model processes, such as a word, part of a word or punctuation. Limits and pricing are often measured in tokens.
Keep learning
Need help with testing, WordPress or SEO?
We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.