Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Getting Started with AI for VLSI Engineers5
  • Just Enough AI: Models and Context15
    • What a Language Model Does
      • Next-Token Prediction and the Sampling Loop
      • Training and Inference
      • Parameters at an Intuitive Level
      • Fluency, Correctness and Knowledge Cutoff
      • Temperature and Sampling
    • Tokens and Tokenization
    • Context Window and Attention for Users
  • Prompting13
  • Trust and Verification14
  • Using AI for Engineering Work17
  • Engineering Walkthroughs7
  • Practical Foundations for AI Workflows4
  • Engineering Data5
  • Retrieval-Augmented Generation6
  • Agents and Tool Use18
  • Agent Design8
  • MCP and Skills6
  • Multi-Agent Design6
  • Practical Capstone6
  • Tokens, Cost and Latency12
  • Agentic Workflows for Chip Teams18
  • Interview and Judgment10
  • AI Skills: Full Course Index
  • Working with AI Glossary
  • Working with AI Cheatsheet
Loading lesson

‹What a Language Model Does
  1. Topics
  2. AI Skills for VLSI Engineers
  3. Just Enough AI: Models and Context
  4. What a Language Model Does
  5. Next-Token Prediction and the Sampling Loop

Just Enough AI · Beginner to Intermediate

Next-Token Prediction and the Sampling Loop

How a model scores next tokens and builds text one step at a time.

On this page

    The prediction step

    Each step takes the text so far and returns a score for every vocabulary item. Normalizing the scores gives a probability for each possible next token.

    The model never writes a sentence at once. It only answers which token could come next and how likely each candidate is.

    Input to the step

    Output of the step

    Example candidates

    Tokens so far

    One probability per vocabulary item

    reset, clock, enable with distinct probabilities

    New token appended

    Updated text for the next step

    Chosen token joins the sequence

    The generation loop

    Generation repeats the prediction step. Each sampled token is appended and the longer text is scored again.

    A short reply of 20 tokens takes 20 such steps. The early choices shape every later distribution.

    plaintext
    1
    2
    3
    4
    5
    joint probability of a 3-token continuation, exact
    p = 0.8 x 0.7 x 0.9
      = 0.56 x 0.9
      = 0.504
    result: 0.504, dimensionless probability
    plaintext
    1
    2
    3
    4
    5
    schematic illustration, not real model output, no specific system implied
    prompt tokens: [write, a, reset]
    step 1 candidates: reset 0.5, clock 0.3, enable 0.2 -> sampled: reset
    step 2 candidates: block 0.6, logic 0.3, wire 0.1 -> sampled: block
    final text: write a reset block

    Tokens in and out

    Model input and output are subword units, and the common approach is BPE-like segmentation. Boundaries rarely match whole words.

    As an approximate rule of thumb, English prose averages about 3 to 4 characters per token with common tokenizers. Code, numbers, hex and non-Latin text use more tokens per character, and the exact ratio is tokenizer-dependent.

    Text kind

    Approximate density

    Status

    English prose

    About 3 to 4 characters per token

    Approximate, tokenizer-dependent

    Code and numbers

    Fewer characters per token

    Approximate, tokenizer-dependent

    Hex and non-Latin text

    Fewer characters per token

    Approximate, tokenizer-dependent

    Common mistakes

    A frequent mistake is treating one reply as the only possible reply. The distribution admits many continuations and sampling picks one path.

    Common pitfall

    Reading the first fluent reply as the intended answer skips the loop. The same scores admit other paths, so a second sample can differ at the first step.

    Interview

    Likely probes: one step versus the full loop, and what probabilities mean.

    • One step scores every candidate next token for the text so far.

    • The loop samples, appends, and repeats until a stop condition.

    • Joint probability of a path is the product of its per-step probabilities.

    Check yourself A reply has 20 tokens. How many prediction steps produced it?

    20 steps. Each token takes one scoring and sampling step, with the growing text fed back each time.

    Check yourself Two candidate continuations have per-step probabilities 0.8, 0.7, 0.9 and 0.5, 0.5, 0.5. Which joint probability is larger?

    The first: 0.504 against 0.125. Joint probability is the product of the per-step terms.

    Related topics

    • Training and inference

    • Tokens and tokenization

    Previous

    6 / 173

    Next: Training and Inference

    Up next

    Up nextTraining and Inference

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Parameters at an Intuitive Level
    • Fluency, Correctness and Knowledge Cutoff
    • Temperature and Sampling