Large-scale similarity search with Optimal Transport

Cléa Laouar, Yuki Takezawa, Makoto Yamada

Introduction

In Natural Language Processing, measuring document similarity is a fundamental task. While the "Bag-of-Words" (BOW) model is efficient, it fails to capture semantic relationships between synonyms (e.g., "physician" vs. "doctor"). Word Mover’s Distance (WMD), based on Optimal Transport (OT), addresses this by calculating the minimum cost to transform one document's word embeddings into another's. However, WMD's $O(n^3)$ complexity makes it unscalable for datasets with millions of documents. This research introduces a framework that approximates WMD using tree-based embeddings, achieving significant speedups while maintaining high accuracy.

Methodology: From Trees to $L_1$ Embeddings

The core of the proposed method is the transformation of the complex OT problem into a simple vector search. By projecting word embeddings onto a hierarchical tree structure, the Wasserstein distance can be represented as an $L_1$ distance (Manhattan distance) between document vectors.

The "Leafless" Tree (ll-TWD)

A significant challenge with standard tree embeddings is the high dimensionality caused by every unique word acting as a leaf node. The authors propose the "Leafless" Tree-Wasserstein Distance (ll-TWD). As shown in Figure 1, this approach removes the leaf nodes and utilizes only internal "cluster" nodes. This drastically reduces vector dimensionality and memory usage without losing the semantic "gist" necessary for effective retrieval.

The transformation from a full hierarchical tree to a "leafless" tree (ll-TWD), reducing dimensionality by focusing on internal cluster nodes.

Sliced Trees and FAISS Integration

To compensate for information loss from leaf removal, the authors employ "sliced trees"—multiple tree structures generated via different clusterings. These are concatenated into a single embedding to maintain high representation power. Once documents are converted into these efficient $L_1$ vectors, the authors utilize FAISS (Facebook AI Similarity Search) to perform billion-scale neighbor searches on GPUs.

Key Results

The proposed ll-TWD method achieves a massive speedup, performing approximately 1,000 times faster than vanilla WMD. For instance, on the Amazon dataset, classification that took over 5,000 seconds with WMD was completed in less than one second using ll-TWD.

Accuracy comparison for different retrieval methods. As the number of slices increases, the ll-TWD method's accuracy approaches the gold-standard WMD, significantly outperforming the BOW model.

As illustrated in Figure 2, the accuracy of the ll-TWD approach is highly competitive. Increasing the number of slices (n_slice) allows the model to converge toward the performance of the vanilla WMD. The authors identified that using 3 slices provides an optimal balance between computational overhead and retrieval precision.

Conclusion and Future Work

By shifting the paradigm from solving per-pair optimization problems to performing vector searches in a learned tree-based space, this research makes Optimal Transport-based similarity search viable for large-scale applications. While it remains an approximation, the "leafless" tree approach offers a powerful trade-off between semantic depth and industrial-scale performance. Future work may focus on optimizing nearest-neighbor libraries specifically for the high-dimensional, sparse nature of these tree-based embeddings.

Summary updated

BibTeX
@inproceedings{laouar2023large,
  author = {Cléa 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