Generative AI & LLMs · Lesson 4 of 6
How Large Language Models (LLMs) Work — Without the Maths
Tokens, training, the context window and temperature: the four ideas that explain almost everything an LLM does, including its strange mistakes.
You do not need to understand transformers or attention maths to use an LLM well. But knowing four ideas — tokens, training, the context window and temperature — will explain most of the behaviour you see, including the frustrating parts.
1. Tokens: how the model reads
An LLM does not read letters or whole words. It reads tokens, which are small chunks of text. Common words like "the" are one token; a rare word like "Thiruvananthapuram" might be split into several. A rough rule for English: 100 tokens is about 75 words.
Why this matters to you:
- Pricing and limits for AI tools are counted in tokens.
- Models are sometimes bad at counting letters in a word — they never actually "see" individual letters.
- Languages like Hindi or Tamil often use more tokens for the same sentence than English does.
2. Training: two stages
Pre-training. The model reads an enormous amount of text and learns to predict the next token. This is where it picks up grammar, facts, coding patterns and general knowledge. It is extremely expensive and happens rarely.
Fine-tuning. The raw model is then trained further on examples of helpful conversations, and people rate its answers so it learns to be helpful, honest and safe. This is why a chatbot answers your question instead of just continuing your text like an autocomplete.
Training has a cut-off date. The model does not know about anything that happened after its training data was collected, unless the tool lets it search the web or you paste the information in.
3. The context window: the model’s working memory
The context window is how much text the model can consider at once — your messages, its replies and any documents you paste. Modern models can handle hundreds of pages, but it is still a limit.
Two practical effects:
- In a very long chat, early details can get less attention. If the model "forgets" an instruction, repeat it or start a fresh chat with a summary.
- The model has no memory between separate chats unless the tool has a memory feature. Each new chat starts fresh.
4. Temperature: creativity vs consistency
At every step the model has a list of possible next tokens with probabilities. Temperature controls how adventurous it is when picking one.
- Low temperature — picks the most likely token almost every time. Consistent, predictable. Good for code, facts and data extraction.
- High temperature — sometimes picks less likely tokens. More varied and creative. Good for brainstorming and stories.
This is also why you can ask the same question twice and get two different answers.
Putting it together: what happens when you press Enter
- Your message (plus the chat so far) is split into tokens.
- The model processes all of them and calculates probabilities for the next token.
- One token is chosen (temperature affects this), added to the answer, and the process repeats.
- It stops when it predicts an end-of-answer token or hits a length limit.
Notice what is missing: there is no step where the model looks up the truth in a database. It generates text that fits the patterns it learned. That single fact explains hallucinations, which is the next lesson.
Try it yourself: Ask a chatbot "Write one sentence about the monsoon" three times in fresh chats. Then ask it to "use exactly these words: monsoon, Kerala, June". See how variation shrinks when you give tighter instructions.
Common interview questions
Try answering each one aloud before you open it.
1What is a token in an LLM?
A chunk of text — a word, part of a word or punctuation — that the model processes as one unit. Model limits and pricing are measured in tokens; roughly 100 tokens is about 75 English words.
2What is a context window?
The maximum amount of text (in tokens) the model can consider at one time, including the prompt, chat history, documents and its own response.
3What does temperature do?
It controls randomness when the model chooses the next token. Low temperature gives focused, repeatable output; high temperature gives more varied and creative output.
4Why can an LLM be wrong even when it sounds confident?
It generates the most likely continuation of text based on training patterns; it does not check facts against a source, so a fluent but false answer is possible.
Practise this
Build something with it
FAQs
Does an LLM search the internet when it answers?
Only if the tool has a web-search feature turned on. The model itself answers from patterns learned during training.
Why does the chatbot forget what I told it earlier?
The conversation may be longer than its context window, or the earlier detail is getting less attention. Restate key instructions or start a new chat with a short summary.
References & further reading
Finished this lesson?
Mark it complete. Create a free account to save it on every device.