Search⌘ K
AI Features

K-Nearest Neighbors

Explore how to apply K-nearest neighbors to identify words with similar embeddings by computing cosine similarities. Understand how this technique helps evaluate and interpret word embedding models using TensorFlow, enabling you to analyze word relationships effectively in NLP tasks.

Chapter Goals:

  • Learn about K-nearest neighbors in terms of word similarity

  • Create a function that computes the K-nearest neighbors for a given word

A. Similar words

When comparing cosine similarities for word embeddings, a common procedure is to find the K-nearest neighbors for a given word. This means that for a given a word w and an integer K, we can find the K vocabulary words whose embedding vectors have the highest cosine similarity to the embedding vector for w.

Using K-nearest neighbors can help us evaluate our embedding ...