When you type a question into an AI assistant and a fluent answer appears a second later, it can feel like talking to a mind. It is not magic, and it is not a person. Underneath is a surprisingly simple core idea, repeated at enormous scale: predict the next piece of text. Once you understand that idea, and the training that shapes it, you will use these tools more wisely than most people around you.
Why a mental model matters
You do not need to know how an engine is built to drive a matatu, but a driver who understands brakes and fuel makes better decisions. AI assistants are the same. If you think they "know" things the way a textbook does, you will trust them in the wrong places. If you think they are just autocomplete, you will underuse them.
The truth sits in between. A large language model, or LLM, is a computer program trained on huge amounts of text to produce text. "Large" refers to its vast number of internal settings, often billions, adjusted during training. "Language model" means its job is to model how language flows. Let us walk through the pipeline, step by step, without a single equation.
Step one: text becomes tokens
Computers work with numbers, not letters. So the first thing that happens to your question is that it gets chopped into tokens. A token is a small chunk of text: sometimes a whole common word like "the", sometimes part of a longer word, sometimes a punctuation mark or a space attached to a word.
For example, "Kuza Ndoto helps students" might be split into pieces such as "K", "uza", " Nd", "oto", " helps", " students". The exact split depends on the model, because each model has its own fixed vocabulary of tokens, built from the chunks of text that appear most often. Common English words usually get one token; rarer words, names and words from less represented languages get broken into several pieces.
Each token in the vocabulary has an ID number. Your sentence therefore becomes a list of numbers, and that list is what the model actually reads.
A model never sees your words as you see them. It sees a sequence of tokens. This explains some odd behaviour, such as models sometimes struggling to count the letters in a word: the word may be one or two tokens, not a row of individual letters.
Step two: predicting the next token
Here is the heart of it. Given a sequence of tokens, the model's only job is to estimate, for every token in its vocabulary, how likely that token is to come next. The output is a list of probabilities: perhaps "Nairobi" is very likely, "Mombasa" somewhat likely, and "banana" extremely unlikely.
The system then picks one token from that list, adds it to the end of the text, and runs the whole process again with the slightly longer text. Token by token, the answer grows. That is why you often see responses appear word by word on screen: you are watching this loop happen.
The system does not always pick the single most likely token. A setting often called temperature controls how adventurous the choice is. Low temperature sticks closely to the most likely options and gives predictable answers; higher temperature lets less likely tokens through, giving more varied and sometimes less accurate text. That is one reason the same question can get two different answers.
Imagine the text so far is: "The capital city of Kenya is". Here is roughly what happens next.
- The text is split into tokens and turned into ID numbers.
- The model reads the whole sequence and produces a probability for every token in its vocabulary. "Nairobi" gets a very high probability, because in the training text this phrase was almost always followed by that word.
- One token is chosen, almost certainly " Nairobi".
- The text becomes "The capital city of Kenya is Nairobi", and the loop runs again. Now a full stop or a comma is likely next.
Notice that at no point did the model look up a fact in a database. It produced the pattern that best fits the text it had seen. Here the pattern and the fact agree. The interesting question is what happens when they do not.
Step three: pre-training on a mountain of text
How does the model learn which tokens are likely? Through pre-training. The model starts with random internal settings, so its early predictions are nonsense. It is then shown an enormous collection of text, drawn from sources such as books, articles, websites and code, and given the same task billions of times over: here is some text, guess the next token.
After each guess, the training process checks the real next token and nudges the model's settings slightly so that the correct token would have been a bit more likely. Repeat this across a vast amount of text and something remarkable happens. To get good at predicting the next token, the model has to absorb grammar, facts that appear often, styles of writing, the structure of arguments, and even patterns of reasoning, because all of these help predict what comes next.
Think of a student who has read every past paper and textbook in the library until they have an instinct for how explanations and answers usually go. That instinct is powerful, but it is an instinct about patterns, not a filing cabinet of verified facts.
Pre-training also has a cut-off. The model only learns from text gathered up to a certain date, so it does not automatically know about events after that, unless the assistant is connected to tools such as web search.
The transformer and attention, by analogy
The design used inside almost all modern language models is called the transformer, introduced in a 2017 research paper. Its key ingredient is a mechanism called attention.
Consider this sentence: "Wanjiru gave Otieno her notes because she was travelling." Who is "she"? You know instantly that it is Wanjiru. To work that out, your mind connected "she" back to the right earlier word. Attention lets a model do something similar. As it processes each token, it can look across all the other tokens in the text and decide which ones are most relevant to understanding this one.
Here is an analogy. Picture a busy group chat planning a chama meeting. When someone writes "Is it still at the same place?", you scroll up and focus on the message where the venue was mentioned, while skimming past the jokes and stickers. Attention is the model's way of scrolling up and focusing on the right messages, for every token, all at once.
A transformer stacks many layers of this, each building a richer picture of what the text means, from which words belong together up to what the overall question is asking. Because attention can connect any token to any other, transformers handle long passages far better than earlier designs, which tended to lose track of the start of a long sentence.
Ask an assistant a question that depends on something you said much earlier in the same conversation, such as a detail about your course or your budget. When it gets this right, you are seeing attention at work: it is linking your new message back to the relevant earlier text. When the conversation gets very long, models can lose track, so restating key details is a good habit.
Fine-tuning and learning from human feedback
A model fresh from pre-training is a brilliant text continuer, but not yet a helpful assistant. Ask it "How do I write a CV?" and it might continue with more questions, as if it were completing a forum page, rather than answering you.
So developers add further stages of training.
- Fine-tuning on examples. The model is trained on a smaller, carefully prepared set of example conversations in which a request is followed by a good, helpful response. This teaches it the shape of being an assistant: answer the question, follow instructions, stay on topic.
- Learning from human feedback. People compare different responses from the model and indicate which ones are better: more accurate, clearer, safer. A widely used approach, often called reinforcement learning from human feedback, uses these judgements to train a separate scoring system, which then guides further adjustments to the model so that it produces the kinds of responses people preferred.
- Safety and policy training. Developers also train models to decline harmful requests and handle sensitive topics carefully.
The result is a model whose underlying engine is still next-token prediction, but whose habits have been shaped towards being useful in conversation.
Why models "hallucinate"
A hallucination is when a model states something false with complete confidence: an invented statistic, a made-up book title, a court case that never happened, a wrong date. Once you understand the pipeline, this stops being mysterious.
- It generates what sounds right, not what is checked. The model produces the most plausible continuation. When the true answer appeared often in its training text, plausible and true usually match. When the topic is rare, local or very specific, the model may fill the gap with something that merely fits the pattern.
- It has no built-in fact checker. Unless the assistant is connected to search or documents, there is no step where it verifies a claim against a source.
- Fluency hides uncertainty. The writing style is equally confident whether the content is solid or invented, because confident writing is what it learned.
- Its knowledge has a date. Questions about recent events, new regulations or current prices can produce outdated answers presented as current.
Be most careful with specific details: names, numbers, dates, quotations, references, legal or medical claims, and anything about local institutions, fees or deadlines. Ask a model for a list of sources and it may produce realistic-looking titles that do not exist. Always confirm such details from an official or primary source before you rely on them.
A language model is a brilliant pattern engine, not an oracle. Use it to think, draft and explain, then verify what matters.
What this means for using AI well
Everything above translates into a handful of practical habits.
- Give it context. The model predicts from the text it has. The more relevant detail you provide, such as your level, your goal and your audience, the better its predictions fit your situation.
- Use it for what patterns are good at. Explaining concepts, drafting, rephrasing, summarising text you supply, brainstorming, and structuring ideas are strengths.
- Supply the facts yourself when accuracy matters. Paste in the article, notes or document and ask the model to work from that. It is far more reliable when summarising text in front of it than when recalling from memory.
- Verify specifics. Treat numbers, names and citations as claims to check, not facts to copy.
- Iterate. If the first answer misses, tell it what was wrong and ask again. Each message changes the text it predicts from.
- Protect your privacy. Do not paste ID numbers, passwords or other people's personal information into an AI tool.
This week, ask an assistant to explain a topic from one of your units, then check its explanation against your lecture notes. Notice where it is excellent and where it drifts.
Key takeaways
- Your text is split into tokens, small chunks of words that the model reads as numbers.
- At its core, a language model predicts the next token, adds it, and repeats until the answer is complete.
- Pre-training on vast amounts of text gives the model an instinct for language and common knowledge, up to a cut-off date.
- The transformer's attention mechanism lets the model link each word to the most relevant other words in the text.
- Fine-tuning and human feedback turn a text continuer into a helpful assistant.
- Hallucinations happen because the model produces plausible text, not checked facts, so always verify specifics that matter.




