Loading...
Find the k nearest neighbors of a query word in an embedding space using cosine similarity.
Input format:
Output: List of k nearest words (excluding the query), sorted by descending cosine similarity. Print as a Python list of strings.
cat 2 4 cat 0.9 0.1 dog 0.8 0.2 car 0.1 0.9 kitten 0.85 0.15
['kitten', 'dog']
Compute cosine similarity of each word with "cat" [0.9, 0.1]:
Top 2: kitten (0.9975), dog (0.9908)