Introduction to Locality-Sensitive Hashing (2018)
tylerneylon.com
tylerneylon.com
My original motivation for writing this was to explain (in a follow-up article) an ANN algorithm I published in 2010: https://epubs.siam.org/doi/pdf/10.1137/1.9781611973075.94
I never wrote that up (as a non-academic article), but the fact that people like this article is a nudge for me to do that.
The above paper was the first LSH algorithm which deterministically returns all close-enough points and guarantees no false positives for distant-enough points. I've heard there are also other algorithms with that property published since. If I have time, I would like to one day see how that algorithm compares against the others in Erik Bernhardsson's benchmarks.
H is the hash function and x are coordinates. But what is R Z?
Z is the set of integers {.., -2, -1, 0, 1, 2, ...}.
Z is called "Z" due to influential German mathematicians who chose the letter to stand for "zahlen" ("number" in German).
As a fun fact, the letter "N" stands for "natural numbers," meaning either positive integers, or positive integers and zero. However, that letter (N) is _not_ standardized because mathematicians disagree about whether or not to include zero. When I separately told a couple of my professors this in grad school, they didn't believe me — one of them thinking it was crazy for zero to be excluded, the other thinking it was crazy to include it!
I've read the part in the book of "Mining Massive Datasets and lots of old notes about "The Probabilistic Method".
But new things?
Thanks
The fastest way for Euclidean space that I know that works well in practice is via Leech lattice decoding: https://www.semanticscholar.org/paper/Maximum-likelihood-dec... , or https://www.semanticscholar.org/paper/Efficient-bounded-dist... .
It is possible to create an implementation based on the above that decodes 24 dimensional points to the closest Leech lattice vector in < 1 microsecond per point on my AMD Ryzen laptop. Combine with some fast random projections/Johnson Lindenstrauss as described in the article to form the LSH.
This LSH family is unfortunately not present in FALCONN, but the alternatives in FALCONN are pretty good.
Source: thought extensively about LSH for my PhD.
The author also wrote an article in which he illustrates RNN in an original and stunning way: https://tylerneylon.com/a/randnn/
[1]: Not related, but you might also enjoy the work of Bartosz Ciechanowski: https://ciechanow.ski/
my use case is here: https://geocode.xyz/2451481561372 -> https://geocode.xyz/45.17310,-75.62670 / https://geocode.xyz/2451481561373 -> https://geocode.xyz/45.17300,-75.62670
https://erikbern.com/2015/10/01/nearest-neighbors-and-vector...
In fact the described forest of trees schema can probably be interpreted as an LSH.
Disclaimer: I haven't touched this stuff for more than 10 years. Don't know what's the state of the art now.
There is another good and more technical explanation (using bands) in chapter 2 of mining massive datasets by Leskovec, Rajaraman and Ullman.
I have dim memories of using random k basis vectors to convert high dimensionality feature vectors to k dimensions, and doing m times to generate multiple projections as part of a an LSH schema. Min-hashing might have been involved.
https://ai.googleblog.com/2020/01/reformer-efficient-transfo...
Introduction to Locality-Sensitive Hashing - https://news.ycombinator.com/item?id=27614381 - June 2021 (63 comments)
I love it when I read something that upends my assumptions and opens up new possibilities.
Another design using proximity based hashing is to use a particle swarm optimization approach [1]
[1]
Proximity-based Networking: Small world overlays optimized with particle swarm optimization
[1] https://github.com/adithyabsk/datastructures/blob/main/docs/...
I mean you want to cluster data which might be autocorrelated... Does this case is taken into account or do you need to preprocess your data beforehand?
You can first run the contents through some sort of embedding model (e.g. the recent OpenAI embedding model [1]), and then apply LSH on those embeddings. The documents that have the same LSH value would have had very similar embeddings, and thus very similar content.
Although I don't have access to the proprietary code used, it's most likely that an LSH algorithm is behind the scenes in every modern search engine (to avoid serving duplicates), many modern ranking systems such as Elasticsearch (because items are typically vectorized and retrieved based on these vectors), and most recommendation systems (for similar reasons as ranking). For example, all of these pages probably have an LSH algorithm at some point (either batch processing before your request, or in some cases real-time lookups):
* Every search result page on Google * Every product page on Amazon (similar products) * All music suggestions on Spotify or similar * Every video recommendation from TikTok, YouTube, or Instagram
etc.
You can almost only check objects that inhabit the same buckets (there are caveats, usually neighboring buckets are also checked), eliminating objects that couldn't possibly collide by virtue of e.g. being on the other side of the map. Of course this is still O(n^2) because every object could be in the same bucket (but that's unlikely).