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
lowx5 givesl o= 5 ando w= 5- Pairs from several words add up
- A repeated pair inside one word counts twice
- 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.