Established 2026  ·  Free Educational Resources for All

Computer & AI · Artificial Intelligence

What Is a Large Language Model? How Chatbots Actually Work

A chatbot doesn't "know" the answer to your question the way a person does. It's predicting the most likely next word, one at a time, based on patterns learned from an enormous amount of text. Here's what's really happening behind the reply.

EDUSAMBAM Editorial Team | 13 min read | Artificial Intelligence
🔊 LISTEN TO THIS ARTICLE
SAVE YOUR EYES • IMPROVE YOUR LISTENING
Listen to the article instead of relying only on continuous screen reading.
Ready to read the article.

A large language model (LLM) is the technology behind modern AI chatbots — it is, at heart, a very large version of the prediction idea from the machine learning article in this series, applied to text. Given some text, it predicts what word is most likely to come next. Repeated over and over, one word at a time, that simple prediction is enough to write essays, hold conversations, and answer questions.

1.The Core Idea: Predicting the Next Word

Underneath a chatbot's reply is a model trained on an enormous amount of text — books, articles, websites, and more — learning to predict, for any given piece of text, what word (or part of a word) is statistically most likely to follow. That's the entire task the model is trained on. It never explicitly "knows" facts the way a person does; it has learned extremely detailed patterns about which words tend to follow which other words, across a staggering range of topics and contexts.

Key Idea

This is the same prediction loop from the house-price example in the previous article — predict, compare to the real answer, adjust — just scaled up enormously and applied to text instead of numbers, with the "answer" being the next word in billions of real sentences instead of a house price.

2.Tokens: How Text Becomes Numbers a Model Can Use

Models don't work with letters and words directly — they work with numbers. Text is first broken into pieces called tokens, which might be a whole word, part of a word, or a punctuation mark, and each token is converted into a number the model can process mathematically.

The sentence "Learning to code is rewarding." broken into tokens
Learning
to
code
is
reward
ing
.

Notice that "rewarding" was split into two tokens. Breaking uncommon or longer words into smaller familiar pieces lets a model handle new or rare words it hasn't seen as a whole, by combining tokens it already recognises.

3.Generating a Reply, One Token at a Time

When a chatbot writes a response, it isn't planning the whole sentence in advance. It predicts one token at a time: given everything written so far, it calculates a probability for every token in its vocabulary, picks one (usually the most likely, sometimes with a bit of randomness for variety), adds it to the text, and repeats the entire process again for the next token.

Prompt: "The capital of France is ___"
Paris
92%
a
4%
located
2%
known
1%

This process, repeated hundreds of times for a long reply, is why longer responses take visibly more time to generate than short ones — the model is genuinely doing the same prediction step over and over, token by token.

4.Attention: How a Model Tracks Context

Predicting the next word well requires understanding context — in the sentence "The trophy didn't fit in the suitcase because it was too big," knowing whether "it" refers to the trophy or the suitcase requires weighing the whole sentence, not just the words immediately before "it." LLMs use a mechanism called attention, part of an architecture called the Transformer, which lets the model weigh the relevance of every earlier token against every other token when producing its prediction — effectively letting it "focus" more on the words that matter most for the current decision, regardless of how far back they appeared.

This is the same layered, weighted structure introduced with neural networks in the previous article, adapted specifically to handle the order and relationships within language rather than fixed lists of numbers.

5.Training in Two Stages: Pretraining and Fine-Tuning

Building a modern chatbot generally happens in two broad stages:

Pretraining is what gives a model its broad knowledge and fluency; fine-tuning is what shapes it into something that behaves like a helpful assistant rather than simply continuing text in any direction.

2017
The Transformer architecture is introduced, providing the attention mechanism nearly all modern LLMs are built on.
2018
Early large models such as GPT-1 and BERT demonstrate the power of pretraining on large amounts of text.
2020
GPT-3 shows a dramatic leap in capability from scaling up model and data size substantially.
2022
ChatGPT brings fine-tuned conversational LLMs to mainstream, everyday use for the first time.

6.What LLMs Can — and Can't — Do Well

Understanding an LLM's real limitations is essential to using one responsibly.

1 Token
at a time — that's the full scope of a single prediction step. Every capability an LLM appears to have, from writing code to holding a conversation, emerges from repeating that one step, guided by everything generated so far.
Real-World Example

When a chatbot helps debug code, summarise an article, or draft an email, it is applying the exact same next-token prediction process described above — just guided by a prompt that steers which patterns from its training are most relevant to continue.

7.Getting Better Results: The Basics of Prompting

A Closing Thought

A large language model can feel like it's "thinking," but underneath every reply is the same mechanical loop: turn text into tokens, predict the most likely next token using patterns learned from enormous amounts of training text, add it, and repeat. It's a remarkable amount of capability to emerge from one repeated step — and understanding that step is what lets you use these tools well, instead of trusting them blindly.

Test Your Understanding

Practice Quiz

10 questions. Select an answer for each, then submit to see your score instantly.

0 of 10 answered
0/10
You scored 0%
Keep practicing
1.What is the core task a large language model is trained to do?
2.What is a "token"?
3.Why might an uncommon word be split into more than one token?
4.How does a chatbot generate a long reply?
5.What does the "attention" mechanism in a Transformer help a model do?
6.What is the difference between pretraining and fine-tuning?
7.What is "hallucination" in the context of LLMs?
8.What does a model's "knowledge cutoff" refer to?
9.Which architecture introduced in 2017 underlies nearly all modern LLMs?
10.According to the article, what generally helps get better results from a chatbot?
← Previous: Machine Learning ExplainedGatewayNext: AI Ethics: Bias, Privacy and Misinformation →