{"slug": "what-an-llm-actually-does-predicting-the-next-word-explained", "title": "What an LLM Actually Does: Predicting the Next Word, Explained", "summary": "A developer created an interactive predictor to demonstrate how large language models generate text by repeatedly predicting the next word. The tool illustrates that the core mechanism is a loop of prediction, selection, and appending, with temperature controlling randomness. This explains both the fluency and the hallucinations of AI chatbots.", "body_md": "\"How does ChatGPT *think*?\" It doesn't. The entire mechanism behind every chatbot is almost anticlimactic: it predicts **one next word**, adds it, and repeats. I built a tiny interactive predictor so you can be the model — and it explains both the magic and the flaws.\n\n🔮 **Be the model:** [https://dev48v.infy.uk/ai/days/day6-next-token.html](https://dev48v.infy.uk/ai/days/day6-next-token.html)\n\nThis is Day 6 of AIFromZero — AI literacy, one concept a day, no code to follow.\n\nGiven everything so far, the model outputs a probability for every possible next word, picks one, appends it, and runs again with the longer text. Paragraphs, code, poems — all of it is this one step on repeat.\n\n\"the cat sat on the ___\" → P(mat) high, P(bird) low\n\nThe output isn't one word — it's a number for *every* word it knows (100,000+ for a real model). Most are near zero; a handful are plausible. The bars in the demo are that distribution, over a tiny vocabulary.\n\nAfter picking a word, it becomes part of the input for the next prediction. Predict → append → predict again. Because each new word conditions on all the previous ones, short local choices add up to coherent long text.\n\nOnce you have probabilities, how do you choose? **Temperature** reshapes them before sampling:\n\n```\np = p ** (1 / temperature);   // then renormalise and sample\n```\n\nDrag the slider in the demo and watch the bars sharpen or even out. That one knob is what an API calls \"creativity.\"\n\nIn my toy, from counting which word followed which in a few sentences (a \"bigram\" with 1-word memory). A real LLM replaces the counting with a giant neural network trained on much of the internet, and its memory spans thousands of words. **The mechanism is identical** — only the quality of the guess changes.\n\n\"Just predicting the next word\" explains the fluency (it has seen how language flows) AND the hallucinations: a plausible-sounding next word isn't always a *true* one. It optimises for *likely*, not *correct*. That gap is where made-up facts live — and it's tomorrow's topic.\n\nPredict next word → append → repeat; temperature tunes the daring. Understand this loop and \"the AI thinks…\" stops being mysterious and starts being mechanical. [Try being the model](https://dev48v.infy.uk/ai/days/day6-next-token.html) — click words and watch a sentence build.", "url": "https://wpnews.pro/news/what-an-llm-actually-does-predicting-the-next-word-explained", "canonical_source": "https://dev.to/dev48v/what-an-llm-actually-does-predicting-the-next-word-explained-iag", "published_at": "2026-06-17 15:42:15+00:00", "updated_at": "2026-06-17 15:51:14.237602+00:00", "lang": "en", "topics": ["large-language-models", "artificial-intelligence", "generative-ai", "ai-tools"], "entities": ["ChatGPT", "AIFromZero"], "alternates": {"html": "https://wpnews.pro/news/what-an-llm-actually-does-predicting-the-next-word-explained", "markdown": "https://wpnews.pro/news/what-an-llm-actually-does-predicting-the-next-word-explained.md", "text": "https://wpnews.pro/news/what-an-llm-actually-does-predicting-the-next-word-explained.txt", "jsonld": "https://wpnews.pro/news/what-an-llm-actually-does-predicting-the-next-word-explained.jsonld"}}