Command Palette

Search for a command to run...

Hectal
Phase 1: How LLMs Work (for Engineers)
LLM Engineering · Exercise 1 of 5Next
Beginner

Count neighbouring pairs (the heart of BPE)

Write pair_counts(words) where words is a dictionary of word to how often it appears, e.g. {"low": 5, "lower": 2}.

Return a dictionary that counts every pair of neighbouring letters, keyed as "a b" (two letters and a space), adding the word's frequency for each occurrence.

What Check tests

  1. low x5 gives l o = 5 and o w = 5
  2. Pairs from several words add up
  3. A repeated pair inside one word counts twice
  4. A one-letter word has no pairs

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.