Large-scale similarity search with Optimal Transport

Cléa Mehnia Laouar, Yuki Takezawa, Makoto Yamada

TL;DR

This paper tackles the computational bottleneck of Word Mover's Distance (WMD), a powerful but slow metric for comparing documents. They introduce a novel approach using tree-based approximations of Wasserstein distance combined with efficient nearest neighbor search, achieving a speedup of over 1000x while maintaining comparable accuracy.

What Problem Does This Paper Address?

In Natural Language Processing (NLP) and Information Retrieval, comparing documents based on their semantic content is crucial. The Word Mover's Distance (WMD) is a popular metric for this, as it leverages word embeddings to measure the "distance" between documents by calculating the minimum cost to transform one document's word embeddings into another's. However, WMD's computational complexity is cubic, making it impractical for large-scale datasets with millions or billions of documents. This paper aims to bridge this gap by developing a WMD approximation that is efficient enough for such large-scale applications.

Methods

The core of the proposed solution lies in approximating the Wasserstein distance using tree structures. Specifically, the authors leverage Tree-Wasserstein Distance (TWD), which embeds document representations into a tree and computes the distance on this tree. They combine this with:

  • L1 Embedding: A method to represent the tree structure and word embeddings as a single L1-norm vector. This is crucial for efficient nearest neighbor search.
  • Tree Construction: They utilize techniques like ClusterTree (and mention QuadTree) to build the tree structures. A key innovation is the use of leafless trees, which significantly reduces the dimensionality of the embedding vectors without a drastic loss in representational power.
  • Sliced TWD: To further improve efficiency and handle the reduced representational power from leafless trees, they employ a "sliced" variant of TWD, using multiple trees.
  • Efficient Nearest Neighbor Search: The final step involves using the FAISS library, a highly optimized library for similarity search, to perform the k-nearest neighbor search on the L1 embeddings.

The novelty lies in the combination of these techniques, particularly the leafless tree approximation and the integration with FAISS for scalable search.

Datasets

The authors evaluated their proposed method on four real-world datasets:

  • Twitter
  • BBCSport
  • Amazon
  • Classic

These datasets are standard benchmarks for document classification and information retrieval tasks. No new benchmarks were introduced.

Key Insights and Ideas

  • The Power of Approximation: The paper demonstrates that approximating the complex Wasserstein distance with a tree-based structure, even with simplifications like leafless trees, can yield surprisingly good results for similarity search.
  • Dimensionality Reduction is Key: The leafless tree approach is a clever way to drastically reduce the dimensionality of the embeddings, which is a major bottleneck in many high-dimensional data problems.
  • Trade-off Between Speed and Accuracy: The number of "slices" (i.e., the number of trees used) presents a clear trade-off: more slices generally lead to higher accuracy but also increase computation time. The paper suggests that a moderate number of slices (e.g., 3) offers a good balance.
  • FAISS as an Enabler: The integration with FAISS is critical, as it provides the necessary computational horsepower to handle large-scale nearest neighbor searches on the generated embeddings.

Key Results

  • Massive Speedup: The proposed method achieves a speedup of over 1000 times compared to the vanilla Word Mover's Distance (WMD) for large-scale nearest neighbor search.
  • Comparable Accuracy: The approximation method maintains comparable accuracy to the original WMD, with the accuracy generally improving with more slices, albeit at a higher computational cost.
  • Fastest Method: The "11-TWD with n_slice=1" (leafless tree with one slice) was found to be the fastest method, though it offered the lowest accuracy.
  • Balanced Performance: The "11-TWD with n_slice=3" provided a good balance between test time and accuracy, making it a practical choice.

Limitations and Future Work

  • Approximation Accuracy: The paper acknowledges that the proposed method is an approximation and its performance is generally lower than the vanilla Wasserstein distance.
  • Scalability of NN Packages: A limitation of current nearest neighbor packages is their lack of support for sparse formats. Since the tree embedding produces highly sparse vectors, addressing this is crucial for handling even larger datasets.
  • Future Work: The authors suggest exploring further improvements in tree embedding techniques and addressing the sparse format limitation in NN packages. They also note that the choice of tree construction algorithm and nearest neighbor package impacts overall scalability.

Summary updated

BibTeX
@inproceedings{laouar2023large,
  author = {Cléa Mehnia Laouar and Yuki Takezawa and Makoto Yamada},
  title = {{Large-scale similarity search with Optimal Transport}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.emnlp-main.730},
}
Figure