Brief
You will build a small search tool for your own notes. Type a question, and it prints the five notes that are most similar. No search engine, no machine learning library. Just vectors and one formula.
A vector here is a list of numbers, one per word you know about. A note that says "python" three times and "matrix" once becomes a vector with a 3 in the "python" slot and a 1 in the "matrix" slot. Stack every note's vector as one row and you have a 2-D array: rows are notes, columns are words. NumPy calls this an array of shape (notes, words), and this is your first tensor: a block of numbers with a shape.
To compare two notes, measure the angle between their vectors. The dot product is big when both notes use the same words. Divide by both lengths and you get the cosine similarity:
It is 1 when two notes point the same way and 0 when they share no words. A long note and a short note on the same topic still score high, because only the direction counts, not the length.
DATA · your own notes, or any folder of .md files
Objectives
Read-only. Log in to update progress.
VICTORY CONDITIONS
- All 20 queries give exactly the same top-5 lists as sklearn cosine_similarity, recorded with `python tools/mlarena.py record BM-01 "20/20 identical"`.
- Similarity uses only your own NumPy code (no sklearn, no np.dot or @) and every normalised note vector has length 1 within 1e-12.
- A command-line tool that takes a question and prints the 5 closest notes with their scores.
Side quests
Terms in plain words
- Vector
- An ordered list of numbers. Here, one number per word in the vocabulary, counting how often that word appears in a note.
- Dot product
- Multiply two vectors entry by entry and add up the results. It is large when both vectors are big in the same places.
- Norm
- The length of a vector, the square root of the sum of its squared entries.
- Cosine similarity
- The dot product divided by both lengths. It is the cosine of the angle between two vectors, so it ignores how long a note is.
- Array shape and broadcasting
- A 2-D NumPy array has a shape like (notes, words). Broadcasting lets you divide every row by its own norm in one line, without a loop.