Menu

1 / 4

Understanding Cosine Similarity

DEV Community: nlp·Trey Tomes·4 days ago
#kRCrHhKt
#devtonlp#devto#dev#function#word
Long article (1310 words) — no AI summary yet.
Reading 0:00
15s threshold

The source for this notebook is available from my GitHub Gist here .

Spend some time working with natural language processing and it seems to come up just about everywhere. How does it work?

This notebook demonstrates how to use cosine similarity to compare words letter-by-letter based on their physical location on a QWERTY keyboard.

The keyPos map is a hand-built set of X, Y vectors that roughly specify the physical location of each key relative to the other.

keyPos = { "`": {"x": 0, "y": 0}, "1": {"x": 1, "y": 0}, "2": {"x": 2, "y": 0}, "3": {"x": 3, "y": 0}, "4": {"x": 4, "y": 0}, "5": {"x": 5, "y": 0}, "6": {"x": 6, "y": 0}, "7": {"x": 7, "y": 0}, "8": {"x": 8, "y": 0}, "9": {"x": 9, "y": 0}, "0": {"x": 10, "y": 0}, "-": {"x": 11, "y": 0}, "=": {"x": 12, "y": 0},

char(9): {"x": 0, "y": 1}, "q": {"x": 1, "y": 1}, "w": {"x": 2, "y": 1}, "e": {"x": 3, "y": 1}, "r": {"x": 4, "y": 1}, "t": {"x": 5, "y": 1}, "y": {"x": 6, "y": 1}, "u": {"x": 7, "y": 1}, "i": {"x": 8, "y": 1}, "o": {"x": 9, "y": 1}, "p":…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.