Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10x Faster Levenshtein Distances #3233

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ashvardanian
Copy link

This PR replaces the native Python implementation of the Levenshtein distance with a SIMD-accelerated version from the StringZilla library.

On ~5 letter words from a typical English corpus - StringZilla is over 10x faster than current Python implementation in NLTK (1.24 s ± 57.4 ms vs 13.5 s ± 287 ms per loop across 7 runs). On a multilingual corpus with longer words - same result.

  1. StringZilla uses less if branches than most native implementations, so it's faster than many implementations in the serial mode. When AVX-512 is available it can use specialized assembly instructions to accelerate evaluation.
  2. StringZilla currently provides wheels for {manylinux, musllinux, macos, windows} × { 32-bit, 64-bit } × { x86, Arm, PowerPC } × [ Python 3.6, Python 3.12 ] making it practically the most portable hardware-accelerated library in the Python ecosystem.

This PR replaces the native Python implementation of
the Levenshtein distance with a SIMD-accelerated version
from the StringZilla library.

On ~5 letter words from a typical English corpus - StringZilla
is over 10x faster than current Python implementation in NLTK.
On a multilingual corpus with longer words - same result.
nltk/metrics/distance.py Outdated Show resolved Hide resolved
@stevenbird stevenbird self-assigned this Feb 28, 2024
@stevenbird
Copy link
Member

[CI: retest]

@ashvardanian
Copy link
Author

[CI: retest]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants