Levenshtein Distance Calculator for Machine Learning

Compare text sequences, inspect every edit, adjust costs, test similarity thresholds, and rank batch matches for dependable machine learning workflows and data cleaning projects.

Calculation result

Enter two sequences, then select Calculate distance.

Levenshtein distance inputs

0 characters · 0 words
0 characters · 0 words

Batch matching and duplicate detection

Calculation history

History stays in this browser using local storage.

TimeSourceTargetDistanceSimilarity

Formula used

Levenshtein distance finds the cheapest edit sequence. It allows insertion, deletion, and substitution operations. Optional transposition adds Damerau-style adjacent swaps.

D(i, 0) = i × deletion cost
D(0, j) = j × insertion cost
D(i, j) = min(
  D(i - 1, j) + deletion cost,
  D(i, j - 1) + insertion cost,
  D(i - 1, j - 1) + substitution cost
)

Normalised distance = distance ÷ selected length denominator
Similarity (%) = max(0, 1 - normalised distance) × 100

How to use

  1. Enter source and target text sequences.
  2. Select character, word, or token comparison.
  3. Adjust preprocessing and operation cost settings.
  4. Set similarity and distance acceptance thresholds.
  5. Select Calculate distance to inspect every result.
  6. Use batch mode to rank many candidate strings.
  7. Export results using CSV, PDF, copy, or print.

Example data

SourceTargetStandard distanceTypical use
kittensitting3Classic edit-distance example
flawlawn2Spell-check comparison
machine learningmachine-learning1Text normalisation testing
colourcolor1Regional spelling matching

Machine learning applications

Use distance for entity resolution and fuzzy matching. It also supports OCR and speech evaluation. Search systems can rank near-duplicate text candidates.

Data teams can detect spelling variants quickly. Classification labels can be checked for drift. Cleaning pipelines gain transparent, reproducible matching rules.

Frequently asked questions

What does Levenshtein distance measure?

It measures the minimum edit cost between sequences. Standard edits are insertions, deletions, and substitutions. Smaller values indicate more similar sequences.

Is zero distance always an exact match?

Zero means the processed sequences are identical. Preprocessing can remove case, spaces, or punctuation. Review enabled options before interpreting exact matches.

How is similarity percentage calculated?

The distance is divided by a selected length. That normalised value is subtracted from one. The calculator then converts it into percentage form.

What are weighted edit costs?

Weighted costs value some edits differently. They model domain-specific correction or matching behaviour. Zero costs should be used very carefully.

What does transposition support change?

Transposition treats adjacent swaps as one operation. This follows a restricted Damerau-Levenshtein calculation. It helps analyse common typing mistakes.

Can this compare entire sentences?

Yes, character and word modes support sentences. Token mode uses whitespace-separated sequence elements. Large matrices may be hidden for performance.

How should thresholds be selected?

Choose thresholds from validated examples in your domain. Names often need stricter settings than noisy OCR. Test false matches before production use.

Can batch results detect duplicates?

Yes, low-distance or high-similarity rows are highlighted. Pairwise mode compares every candidate combination. Exported reports support further review.

Does the calculator support Unicode?

Modern browsers split Unicode characters safely with Array.from. Punctuation filtering also uses Unicode character classes. Complex grapheme clusters may still vary.

Related Calculators

Word Frequency CalculatorCosine Text Similarity CalculatorJaccard Text Similarity CalculatorBLEU Score CalculatorROUGE Score CalculatorPerplexity CalculatorVocabulary Size CalculatorToken Count CalculatorText Classification Metrics CalculatorNatural Language Processing Basics Quiz

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.