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
    • Tokens and Tokenization
      • Tokens, Words and Characters
      • Subword Tokens and Byte-Pair Encoding
      • Why Some Text Costs More Tokens
      • Approximate Rules of Thumb
      • Estimating Tokens Before Sending
    • 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

‹Tokens and Tokenization
  1. Topics
  2. AI Skills for VLSI Engineers
  3. Just Enough AI: Models and Context
  4. Tokens and Tokenization
  5. Tokens, Words and Characters

Just Enough AI · Beginner to Intermediate

Tokens, Words and Characters

Characters, words and tokens compared, with counts on short fixed examples.

On this page

    Three different units

    Characters are stable: every tool counts the same ones. Words are spans between whitespace, a convenience for people.

    Tokens are the pieces a model consumes. Their boundaries come from a fixed table and vary by model, so measure them.

    Text

    Characters

    Words

    Fixed 3-wide chunks

    hello world

    11

    2

    4 (3 + 3 + 3 + 2)

    token

    5

    1

    2 (3 + 2)

    empty string

    0

    0

    0

    A worked count

    The calc block counts hello world by hand. The program below checks the same arithmetic on fixed strings.

    plaintext
    1
    2
    3
    4
    5
    text: "hello world"
    characters = 5 + 1 + 5 = 11
    words = 2 ("hello", "world")
    3-wide chunks = ceil(11 / 3) = 4, pieces 3 + 3 + 3 + 2 = 11
    check: 4 chunks cover 11 characters with no remainder lost

    Why the distinction matters

    Cost and fit are counted in tokens, not words or characters. A word budget can miss the token budget by a wide margin on code.

    Chunking here is illustrative only. Real splitters use learned pieces, and the rate varies by model, so measure it.

    example.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    import sys
    
    TEXTS = ["hello world", "assign wdata = 8'hff;", "token"]
    CHUNK = 3
    
    def count_words(s):
        return len(s.split())
    
    def count_chunks(n, size):
        return (n + size - 1) // size
    
    bad = 0
    for s in TEXTS:
        n_chars = len(s)
        n_words = count_words(s)
        n_chunks = count_chunks(n_chars, CHUNK)
        if n_chunks * CHUNK < n_chars:
            bad += 1
        if n_chunks > 0 and (n_chunks - 1) * CHUNK >= n_chars:
            bad += 1
    if count_words("hello world") != 2:
        bad += 1
    if count_words("") != 0:
        bad += 1
    if count_chunks(11, 3) != 4:
        bad += 1
    if len("hello world") != 11:
        bad += 1
    if not (count_chunks(len("assign wdata = 8'hff;"), 3) > count_words("assign wdata = 8'hff;")):
        bad += 1
    if bad != 0:
        print("FAIL: " + str(bad) + " checks wrong")
        sys.exit(1)
    print("PASS: 3 texts counted with chunk size 3; hello world is 11 chars and 2 words")

    Common mistakes

    Common pitfall

    Word count is not token count. Short identifiers and symbols split into more pieces than prose words of the same length.

    Interview

    Likely probes: the three units and one worked count.

    • Characters are stable, words are whitespace spans, tokens are model pieces.

    • hello world is 11 characters, 2 words and 4 three-wide chunks.

    • Token boundaries vary by model, so measure them.

    Check yourself hello world has 2 words. How many 3-wide chunks does it fill, and why is neither number a token count?

    4 chunks (3 + 3 + 3 + 2). Words and fixed chunks are human rules, while tokens follow a learned table that varies by model.

    Check yourself The program compares chunks against words on assign wdata = 8'hff;. What does that comparison prove?

    It proves the units differ on code input: 7 three-wide chunks against 4 whitespace words for that fixed string.

    Related topics

    • Subword tokens and byte-pair encoding

    • Cost arithmetic

    Previous

    11 / 173

    Next: Subword Tokens and Byte-Pair Encoding

    Up next

    Up nextSubword Tokens and Byte-Pair Encoding

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Why Some Text Costs More Tokens
    • Approximate Rules of Thumb
    • Estimating Tokens Before Sending