Convolutional Embedding for Edit Distance

Xinyan Dai, Xiao Yan, Kaiwen Zhou, Yuxuan Wang, Han Yang, James Cheng

Abstract

Edit distance (Levenshtein distance) is a fundamental metric for string similarity but suffers from high computational costs, typically $O(l^2)$ for strings of length $l$. This paper presents CNN-ED, a deep learning framework that embeds strings into a low-dimensional Euclidean space where vector distances accurately approximate edit distance. By utilizing 1D convolutional layers and a hybrid loss function, CNN-ED achieves up to 200x faster inference and significantly smaller embedding vectors than traditional recurrent models, while providing theoretical guarantees on distance preservation.

Introduction

Measuring string similarity is critical for tasks such as spell-checking, genome sequencing, and data de-duplication. While edit distance is the gold standard, its quadratic complexity makes large-scale applications prohibitively slow. To address this, researchers employ metric embeddings to transform strings into vectors, allowing for efficient distance calculations. Previous data-independent methods like CGK often lack accuracy, while RNN-based models (e.g., GRU) are slow to train, produce large embeddings, and struggle with long sequences. CNN-ED overcomes these limitations by leveraging the parallel nature and shift-invariance of convolutional architectures.

The CNN-ED Framework

The CNN-ED pipeline consists of four primary stages designed to map strings into a compact metric space:

  1. One-hot Encoding: Strings are converted into binary matrices representing character positions.
  2. CNN Architecture: 1D convolutional layers followed by max-pooling capture local character interactions. This structure mimics the "shifting" effect inherent in insertions and deletions.
  3. Hybrid Loss Function: The model is trained using a combination of Triplet Loss (for relative ordering) and Approximation Error (to match absolute edit distance values).
  4. Theoretical Foundation: The authors prove that one-hot encoding combined with max-pooling naturally preserves the bounds of edit distance, justifying the CNN approach.
The CNN-ED architecture pipeline, featuring one-hot encoding, 1D convolutional layers, and a hybrid loss function.

Architectural Insights: CNNs vs. RNNs

A key finding of this research is that CNNs are inherently better suited for edit distance than RNNs. While strings are sequential, RNNs process characters linearly, making it difficult to capture global shifts caused by single-character edits. In contrast, the receptive fields and pooling mechanisms of CNNs handle these shifts more naturally. Remarkably, the authors observed that even a randomly initialized CNN (RND) often outperforms standard algorithms like CGK and matches the performance of fully trained GRUs, suggesting the convolutional structure itself is fundamentally aligned with the geometry of edit distance.

Experimental Results

CNN-ED was evaluated on diverse datasets, including UniRef (proteins), Gen50ks (genomics), and Enron (emails).

  • Accuracy and Speed: CNN-ED significantly reduced estimation errors (e.g., 0.141 vs 46.840 for GRU on the Trec dataset). Training was up to 30x faster, and inference was up to 200x faster than GRU-based baselines.
  • Search Performance: In threshold search tasks, CNN-ED achieved 0.9 recall while operating 200x faster than state-of-the-art non-embedding methods like HSsearch.
  • Memory Efficiency: CNN-ED produces compact 128-dimensional embeddings. On the Gen50ks dataset, it required only 24MB of storage, compared to 7GB for GRU embeddings.
Recall performance on the Enron dataset across various top-K settings, comparing random CNN (RND), GRU, and CGK methods.

Conclusion

CNN-ED represents a significant advancement in approximate string matching, offering a principled and highly efficient alternative to recurrent models. While it is an approximate method that may require a final exact check for 100% accuracy, its speed and memory efficiency make it ideal for large-scale filtering. Future work includes exploring advanced pooling methods and integrating these embeddings into locality-sensitive hashing (LSH) frameworks.

Summary updated

BibTeX
@inproceedings{dai2020convolutional,
  author = {Xinyan Dai and Xiao Yan and Kaiwen Zhou and Yuxuan Wang and Han Yang and James Cheng},
  title = {{Convolutional Embedding for Edit Distance}},
  booktitle = {International ACM SIGIR Conference on Research and Development in Information Retrieval},
  year = {2020},
  doi = {10.1145/3397271.3401045},
}
Figure