Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Locality Sensitive Hashing at Lyst

Locality Sensitive Hashing at Lyst

Description of the intuition behind locality sensitive hashing and its application at Lyst.

Maciej Kula

July 24, 2015
Tweet

More Decks by Maciej Kula

Other Decks in Programming

Transcript

  1. Convert image to points in space (vectors) & use nearest

    neighbour search to get similar images. 1. Image Search (-0.3, 2.1, 0.5)
  2. Convert products and users to points in space & use

    nearest neighbour search to get related products for the user. 2. Recommendations user = (-0.3, 2.1, 0.5) product = (5.2, 0.3, -0.5)
  3. Locality sensitive hashing to the rescue! Use a hash table.

    Pick a hash function that puts similar points in the same bucket. Only search within the bucket.
  4. Points to note Keep splitting until the nodes are small

    enough. Median splits give nicely balanced trees. Build a forest of trees.
  5. Why do we need a forest? Some partitions split the

    true neighbourhood of a point. Because partitions are random, other trees will not repeat the error. Build more trees to trade off query speed for precision.
  6. LSH in Python annoy, Python wrapper for C++ code. LSHForest,

    part of scikit-learn FLANN, an auto-tuning ANN index
  7. But… LSHForest is slow. FLANN is a pain to deploy.

    annoy is great, but can’t add points to an existing index.
  8. rpforest Quite fast. Allows adding new items to the index.

    Does not require us to store points in memory.
  9. We use it in conjunction with PostgreSQL Send the query

    point to the ANN index. Get ANN row ids back Plug them into postgres for filtering Final scoring done in postgres using C extensions.
  10. Gives us a fast and reliable ANN service 100x speed-up

    with 0.6 10-NN precision Allows us to serve real-time results All on top of a real database.