Fuzzy Matching
Matching “persnal lon” to “personal loan” — and knowing when a close match is the wrong match.
Why this matters
Noisy transcripts rarely contain the exact strings in your product catalogue, bank list or compliance script. bridges the gap with a similarity score and a threshold.
The threshold is where engineering happens. Too low and "professional loan" matches "personal loan"; too high and "pesonal lone" is missed. That's a precision/recall trade-off — the same one you'll meet again in classification metrics — and it can only be set by measuring on labelled pairs.
Core concept
Technical explanation + simple intuition + example
Edit distance: Levenshtein and friends
How many single-character fixes turn one string into another? persnal → personal needs one insertion, so the distance is 1. Divide by the longer length to get a similarity between 0 and 1.
Jaro-Winkler, n-grams and token-level similarity
Different similarity measures notice different things: - rewards a shared beginning — great for names. - Character n-gram compares overlapping chunks — robust to small typos anywhere. - Token similarity compares words — robust to word order ("loan personal") but blind to typos inside words.
Thresholds are a precision/recall decision
Every threshold splits pairs into "match" and "no match". Raising it removes false matches (higher precision) but misses more real variants (lower recall). There is no universally correct value — only a value that's right for the cost of each error.
The 10 questions
Every important concept should answer all of these
1What is it?
Approximate string matching: scoring how similar two strings are and deciding a match above a threshold.
2Why does it exist?
Real text never matches your dictionaries exactly — misspellings, ASR substitutions, word order and spacing all vary.
3What problem does it solve?
It recovers matches that exact lookup misses, e.g. mapping noisy product mentions to a catalogue or spotting a scripted compliance phrase.
4How does it work internally?
Compute a similarity (edit distance, Jaro-Winkler, n-gram or token overlap) between a mention and each candidate, pick the best, and accept it if above a threshold.
5What does it look like on real transcript data?
persnal lon, personal lawn (ASR), loan personal (order), credit crd — all real variants of catalogue entries; hold on vs gold loan is a dangerous near-miss.
6What can go wrong?
Short strings produce high similarity by chance; different products differ by one word; synonyms are invisible; a threshold tuned on one dataset breaks on another; comparing against a huge dictionary increases false positives.
7How do I evaluate it?
Label candidate pairs as match/no-match, sweep the threshold, and report precision/recall at the chosen operating point on a held-out set.
8When should I use it?
Known closed vocabularies (products, banks, cities, scripted phrases), deduplication, and as a cheap first-pass before heavier models.
9When should I NOT use it?
When meaning matters more than spelling (synonyms, paraphrase) — use embeddings or an LLM; when strings are very short and ambiguous.
10How does it affect downstream systems?
Fuzzy matches feed NER (gazetteer entities), normalization (canonical product names) and compliance detection; a wrong threshold silently inflates or deflates every downstream count.
Interactive lab: Fuzzy matching lab
Compare two strings with seven similarity measures and inspect the edit-distance DP matrix. Then sweep a threshold over labelled catalogue pairs and watch false positives and false negatives trade off.
Threshold sweep in Python
Real Python, running in your browser (Pyodide)
Try it yourself
Conceptual (A), applied (B) and engineering (C) exercises
lon and loan?Graded by a transparent keyword rubric (not an LLM) — it checks for the key ideas, then shows a model answer for self-assessment.
Real-world application
A compliance team must check that agents read the disclosure "rates are subject to change". ASR outputs "rates are subject to chains", "rate subject to change hai" and "rates r subjected to change". An exact match found 61% of disclosures; token-sort similarity with τ = 0.8 found 94% on a labelled sample of 200 calls, with 3 false positives from "rates are subject to your credit profile". The team kept τ = 0.8, added those false positives to a regression test, and re-measured monthly.
Common mistakes
You'll see only the easy cases; the error rate depends on the distribution of near-misses.
Fix: Label 100–300 pairs including hard negatives and sweep the threshold.
two wheeler loan and vehicle loan share little surface form.
Fix: Use a synonym table, embeddings or an LLM for meaning-level matches.
Short strings (EMI, PL) reach high similarity with many unrelated strings.
Fix: Require exact match for very short strings or use a stricter threshold.
Many comparisons → many chance matches.
Fix: Restrict candidates (n-gram windows around keywords, the right speaker, the right segment).
Engineering decision
When is fuzzy matching the right tool?
- The target vocabulary is closed and known
- Variation is mostly spelling/ASR noise
- You need cheap, explainable, deterministic matching
- Matching must understand meaning (synonyms, paraphrase, negation)
- Strings are very short and ambiguous
- You can't label pairs to set a threshold
Quiz
Pass mark 60%. Missed questions go to your mistake log and spaced review.
two wheeler loan should match vehicle loan, but gets low similarity with every string measure. The right fix is…loan personal and personal loan as identical?