Lesson 01-02

Counting What the Model Sees

10 min
1 export
3 tests

Lesson blocked by prerequisites

Complete and save a passing attempt for your active lesson before running this one.

Go to active lesson

Lesson workspace sections

Submission + Results
Not run yet

Seed 102 • Runtime includes 1 prerequisite module
Test Results

Run tests to see case-by-case feedback.

Attempts0 saved

No saved attempts yet.

Lesson README

01-02 Counting What the Model Sees

Why this matters

Token-frequency counting is the first measurable signal a language model can extract from data.

Intuition first (no jargon)

A frequency table is the model's first memory: it records what appears often.

Code walkthrough

js
export function countChars(text) {
  const counts = {};
  // fill counts
  return counts;
}

Your task

Implement countChars(text).

  • Return an object mapping each character to count.
  • Include spaces as characters.
  • Return {} for empty input.

Hints

  • Iterate with for (const ch of text).
  • Initialize with counts[ch] = (counts[ch] || 0) + 1.
  • Keep the function pure.

Check your thinking

  1. Why might spaces matter for language?
  2. What does a high count mean?
  3. Does counting alone preserve order?

Stretch (optional)

Add countWords(text) and compare character vs word counts.

Likely test focus

  • Exact counts for toy strings.
  • Handles empty strings.
  • Includes whitespace tokens.

What should improve

You can now compute reproducible corpus statistics that drive simple probabilistic baselines.

Bridge to next lesson

Next lesson: add weighted randomness for generation.

Monaco Editor

Matches starter

Files

Editor is deferred on smaller screens to keep startup fast.

Autosave is enabled in local storage for this lesson.