The nearest neighbor problem is very common in data science. It's useful in recommender situations but also with neural embeddings in general. It's an expensive thing to calculate so it is common to calculate approximate distances as a proxy. In python a very likeable tool for this is annoy.
The code below should be more accurate than before.
annoy = AnnoyIndex(columns, 'euclidean') for i in range(vecs.shape): annoy.add_item(i, vecs[i, :]) # this is the line that we changed from 1 -> 10 annoy.build(n_trees=10) plt.figure(figsize=(5, 5)) plt.scatter(vecs[:, 0], vecs[:, 1], s=1); indices = annoy.get_nns_by_vector(np.array([-1., -1.]), 2000) subset = vecs[indices, :] # this should now show a proper circle plt.scatter(subset[:, 0], subset[:, 1], s=1);
Feedback? See an issue? Something unclear? Feel free to mention it here.
If you want to be kept up to date, consider signing up for the newsletter.