TECHNOLOGIESTieInn Technologies

How LLMs work: tokens, the context window and next-word prediction

LLM Fundamentals & Prompting · 11 questions

Short notes

Key idea

A large language model predicts the next token (a word piece) given all the tokens before it, again and again. Everything it "knows" came from training text; everything it can see right now must fit in the context window.

Syntax

  • Token: roughly ¾ of an English word; Tamil and code often use more tokens per word.
  • Context window: the maximum tokens of input + output in one call.
  • Generation: the model gives a probability for every possible next token; one is picked, appended, and the loop repeats.
  • Training cutoff: the model knows nothing after its training data ends.
  • Pricing and limits are counted in tokens.

Example

Prompt: "The capital of Tamil Nadu is". The model gives high probability to " Chennai", picks it, then predicts what follows " Chennai". It isn't looking anything up; it's continuing text in the most likely way.

Traps

  • Models have no memory between calls; the app resends the history each time.
  • Fluent isn't the same as true: a likely-sounding answer can be invented (a hallucination).
  • Recent or private facts aren't in the model; supply them in the prompt (that's what RAG does).
  • Counting letters or doing exact maths is weak because the model sees tokens, not characters.

Want the full lesson with step-by-step examples, a project and a certificate? LLM Fundamentals & Prompting course, ₹180 →

Questions

Open in Code Lab5 free questions
5 questions

    How LLMs work: tokens, the context window and next-word prediction

  1. Question 1easy

    At its core, what does a large language model do?

  2. How LLMs work: tokens, the context window and next-word prediction

  3. Question 2easy

    Which statement about tokens is true?

  4. How LLMs work: tokens, the context window and next-word prediction

  5. Question 3easy

    The practice tokenizer counts one token per word and one per punctuation mark. What does this print?

    from practice_llm import count_tokens
    print(count_tokens("Refund sent, check your UPI app."))
  6. How LLMs work: tokens, the context window and next-word prediction

  7. Question 4medium

    The same customer question is written in English and in Tamil. How do their token counts usually compare?

  8. How LLMs work: tokens, the context window and next-word prediction

  9. Question 5easy

    A model scores the next token like this. With greedy decoding, which token is picked?

    probs = {"days": 0.55, "hours": 0.25, "weeks": 0.15, "minutes": 0.05}
    print(max(probs, key=probs.get))

6 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.