← back to the map

part 1 boss 👾

Part 1 Boss: Fix the Pipeline

the hook

You've built a tokenizer. You've built cosine similarity. Now debug someone else's broken versions — 2 bugs, hidden in code that LOOKS right.

the idea

No new theory this time. You've built a tokenizer (ch2) and cosine similarity is the exact math behind ch3's embedding map — both real skills you already have. Below are two functions that LOOK right, compile fine, and are completely broken.

That's the most common way real code fails — not a crash, just a quietly wrong answer. Your job: run each cell, notice the output is off, and figure out why before you touch the fix.

One clue is built into the math itself: cosine similarity can never be greater than 1. If you ever see a number bigger than that come out of a similarity function, the function is lying to you — that's not a style nitpick, it's a hard mathematical fact you can use as a debugging tool.

Hint buttons are there if you get stuck, same as every code cell. Fix both and you clear the boss.

playground — your hands now

what: find and fix 2 planted bugs in a broken tokenizer and a broken cosine similarity function.

why: reading code critically — spotting what SHOULD happen vs what a bug makes actually happen — is half of real engineering, and you already have every skill needed to do it.

how: run each cell, notice the wrong output, use the hints if you're stuck, fix the bug, run again.

start here → run each cell first — the wrong output is your first clue.

bug 1 · the tokenizer

what: find and fix the bug in this word tokenizer.

why: a silently-wrong tokenizer feeds silently-wrong tokens into everything downstream — this is exactly the kind of bug that's easy to miss.

how: run it, compare the output to the input word count, then dig into the loop.

this should split the sentence into 6 words. run it — count what you actually get. stuck? there's a hint button.

bug 2 · cosine similarity

what: find and fix the bug in this cosine similarity function.

why: this exact function is what ch3's embedding map and ch15's RAG pipeline both run on — a broken version breaks everything built on top of it.

how: run it, and remember: cosine similarity can NEVER be greater than 1. use that fact.

this should print a number between -1 and 1. run it — is it? stuck? there's a hint button.

try this

Once both are fixed, go back and describe out loud (or to yourself) WHY each bug was wrong — not just what the fix was. 'range() started at the wrong number' is a better takeaway than just pattern-matching the fix.

checkpoint

1. A function claims to return a cosine similarity, but prints 2.0. What does that tell you immediately?

2. What's usually the more valuable skill: writing new code, or reading someone else's broken code?

recap card — keep this

reading code critically — spotting what SHOULD happen vs what a bug makes actually happen — is half of real engineering.

next chapter → Loss — how wrong was the guess?