Friendly AI robot assistant waving next to a laptop
Artificial Intelligence

How Chatbots and Large Language Models Actually Work

30 Oct 202612 min readLevel: Beginner100% FreeBy Tahmeer Tech

The big idea, in one paragraph

Chatbots like ChatGPT are built on a Large Language Model (LLM): a program that was trained on enormous amounts of text and learned one skill extremely well — predicting what text should come next. Everything a chatbot does — answering questions, writing essays, explaining code, translating — is built from that single skill, repeated word-part by word-part until a full answer appears. Understand this, and chatbots stop being magic and start being a tool you can use wisely.

Step 1 — Tokens: how the model reads

An LLM does not read letters or whole words. It chops text into tokens — small chunks that might be a word, part of a word, or a punctuation mark. “Learning is fun” might become three or four tokens. Each token is turned into a list of numbers, because numbers are all a model can actually work with. As a rough guide, 100 tokens is about 75 English words — this is also how many AI services measure and charge for usage.

Step 2 — Training: learning from text

Before you ever meet it, the model was trained: shown trillions of tokens from books, articles, websites and code, and set one repeated exercise — hide the next token, guess it, check the answer, adjust. Every wrong guess nudged billions of internal numbers (called weights) a tiny step in the right direction. After enough practice on enough text, the guesses became remarkably good — the model had absorbed grammar, facts, styles and patterns of reasoning, all stored in those weights. Later, extra training with human feedback teaches it to answer helpfully and refuse harmful requests.

Step 3 — Predicting the next word, live

When you send a message, the model looks at your tokens plus the conversation so far (its context), calculates which token is most likely to come next, adds it, and repeats — hundreds of times for one reply. Two details matter. First, it can only “see” a limited amount of context at once (the context window), so in very long chats early details can fall out of view. Second, a setting called temperature controls randomness: low means careful and predictable, high means creative and surprising.

Why models make mistakes

The model’s job is to produce likely-sounding text — not verified truth. It has no database it checks and no understanding that a date or name is real. So it can invent a book that does not exist, a wrong date, or broken code, all in perfect, confident language. This failure is called hallucination. It also means the model’s knowledge stops at its training data and can be out of date. The rule follows naturally: enjoy the fluency, but verify anything important — names, numbers, dates, quotes and code you plan to run.

How to write clear, smart prompts

A prompt is an instruction, and like any instruction, clarity wins. A strong prompt usually includes:

  • Role / context: who you are and what this is for (“I am a 3rd-semester CS student preparing for an exam”)
  • Task: exactly what to do (“Explain how DNS works”)
  • Format: how the answer should look (“in 5 bullet points, with one everyday example”)
  • Limits: size and honesty rules (“under 150 words; if you are unsure, say so”)

Bad prompts vs good prompts

Bad: “Explain loops.” — the model must guess your level, language, depth and format, so you get a generic answer.

Good: “I am learning Python in semester 3. Explain for-loops in under 150 words: start with a real-life example, then show a 5-line code example that prints a shopping list, then give me one practice question without the answer.” — same topic, but now the answer is built for you.

Bad: “Write my assignment.” Good: “Here is my assignment question and my own first draft. Point out two weak arguments and ask me questions that help me fix them — do not rewrite it for me.” The second keeps the learning (and the marks) yours.

Practice task (30 minutes)

Take one topic from your current studies. Ask about it three times: (1) with a one-line prompt, (2) with role + task, (3) with role + task + format + limits. Save all three answers, score each for accuracy, clarity and usefulness out of 5, and check one factual claim from the best answer against your book. Keep the winning prompt as a reusable template.

Common mistakes to avoid

  • Believing an answer because it sounds confident — fluency is not evidence
  • Asking one giant question instead of working step by step
  • Pasting passwords, private data or other people’s personal information into a chatbot
  • Submitting AI-written work as your own without understanding it
Summary — key points

Tokens in, next-token predictions out — trained on text at massive scale. Chatbots are powerful pattern machines, not knowledge oracles: prompt clearly, and always verify what matters.