| name | fuzzy-name-matching |
| version | 1 |
| description | Use when linking or deduping datasets by entity name rather than a shared key โ 'fuzzy match', 'fuzzy name matching', 'entity resolution', 'record linkage', 'match company/person names', 'dedupe entity names', 'name-based join', 'bridge identifiers' (CIK โ permno โ gvkey โ wficn โ EIN โ personid), or any use of char n-gram TF-IDF, cosine similarity on names, `sparse_dot_topn`, or RapidFuzz at scale. |
| user-invocable | true |
Contents
Fuzzy Name Matching
Fast many-to-many fuzzy entity matching: char n-gram TF-IDF + sparse top-k
cosine similarity (the ING banks recipe). Scales to ~10โต ร 10โต on a laptop
in seconds, ~10โถ ร 10โถ with chunking.
The full recipe โ code, threshold guide, gotchas, alternatives considered โ
is in references/fuzzy-name-matching.md. Read it before writing match
code; a runnable template is in examples/fuzzy_name_match_sample.py.
Match Enforcement
IRON LAW: NO FUZZY MATCH WITHOUT NORMALIZATION FIRST
Fuzzy matching is the last step of a linkage, never the first:
- NORMALIZE both sides (uppercase, punctuation โ space, strip entity
suffixes/titles) โ see the
normalize() function in the reference
- JOIN exactly on the normalized name, scoped by a secondary key
- MEASURE the exact-join hit rate
- FUZZY-MATCH only the residual rows
- INSPECT a sample of accepted pairs at the chosen threshold
- CLAIM a hit rate only after inspecting matched pairs
Skipping straight to TF-IDF is NOT HELPFUL โ every deterministic rule you
skip upfront comes back as false positives the user has to find later, in a
join they now believe is clean.
Fuzzy Matching Facts
- If the normalized-name exact join yields <70% on ground truth, normalization is leaving money on the table โ fix that before reaching for TF-IDF. Fuzzy matching a badly normalized field buys false positives, not coverage.
- IDF weights are corpus-dependent: fitting a fresh vectorizer per scoped subset makes scores incomparable across subsets.
"GABELLI MARIO JOSEPH" โ "GABELLI MARIO J" scores 0.69 in a 2-row toy fit and 0.84 in a 600K-corpus fit โ same pair, different context. Fit once on pd.concat([left_all, right_all]), reuse .transform() everywhere.
- Scoping is where the signal lives. On the 13,663-row blockholder bridge, the scoped fuzzy pass (โฅ0.80, per issuer_cik) converted 70% of unmatched rows; the global pass afterward (โฅ0.90) added 11. Scope by issuer/year/geo and the smaller candidate pool lets you lower the threshold safely.
- TF-IDF on characters is not semantic.
"IBM" โ "International Business Machines" will never match at any threshold โ that needs a name dictionary or an embedding model.
sp_matmul_topn(A, B, ...) wants B already transposed (R.T). sort only orders the hits within each row โ top-k selection always keeps the largest values, so top_n=1 returns the argmax with sort=False too (verified on 1.2.0: 60/60 rows matched a dense argmax either way). Pass sort=True when top_n>1 and you care about the order.
- Duplicate normalized names on the right side with different ids make
top_n=1 pick one of them with no defined rule โ sort does not disambiguate an exact tie (tested on 1.2.0: it kept the last duplicate in every layout, under both sort settings, but nothing documents that). Whichever it is, the id you get is an accident of row order. Deduplicate the right side first.
Red Flags โ STOP If About To:
- Run
sp_matmul_topn before an exact normalized join has been tried and measured โ STOP. You cannot tell false positives from real coverage without the exact-join baseline.
- Fit a
TfidfVectorizer inside a per-key loop โ STOP. Scores become incomparable across keys; fit once on the full corpus outside the loop.
- Accept matches below 0.75, or below 0.90 on an unscoped global pass โ STOP. The threshold guide auto-accepts 0.85โ0.95 only when scoped; the global pass floor is โฅ0.90.
- Report a hit rate without eyeballing matched pairs near the threshold โ STOP. Reporting an unverified hit rate is presenting an unverified claim as fact.
- Reach for TF-IDF on <5K ร 5K, or on strings under ~3 characters โ STOP. RapidFuzz edit distance is better there; n-grams collapse on short strings.
When to Use
Reach for this when linking two datasets whose only shared field is an
entity name โ bridging identifiers (CIK โ permno โ gvkey โ wficn โ EIN โ
TR personid), deduping filer/fund/insider names, or resolving vendor
records that share no key at all.
Don't use it for exact joins (pandas merge), for semantic equivalence, or
below ~5K ร 5K rows where RapidFuzz is simpler. The reference's
"Alternatives considered" table covers rapidfuzz, recordlinkage,
dedupe, and edit-distance metrics and when each wins.
The Pipeline
normalize both sides
โ
exact scoped join (issuer/year/geo + norm_name) โ most of your hits
โ
exact global join (unambiguous norm_names only)
โ
fuzzy SCOPED pass โ threshold โ0.80, per-key candidate pools
โ
fuzzy GLOBAL pass โ threshold โฅ0.90, residuals only, dedup right side first
โ
residual: synthetic ids / leave unmatched โ never force a match
Code for each stage, and the threshold table that governs what to accept at
each one, is in references/fuzzy-name-matching.md.
Packages
[dependencies]
scikit-learn = "*"
[pypi-dependencies]
sparse_dot_topn = ">=1.2"
conda-forge tops out at sparse_dot_topn 0.3.1, which predates the v1
sp_matmul_topn API this recipe uses (checked against the conda-forge channel
2026-07-22). pixi add sparse_dot_topn therefore installs a version without
the function โ use pixi add --pypi sparse_dot_topn to get โฅ1.2.
Additional Resources
Reference Files
references/fuzzy-name-matching.md โ the full recipe: minimal code, threshold guide, normalize-first rule, scoped + global two-pass pattern, seven gotchas, alternatives considered, end-to-end results table
Example Files
examples/fuzzy_name_match_sample.py โ runnable template: normalize(), fuzzy_match(), fuzzy_match_scoped(), plus a toy demo linking insider names to reporting-owner CIKs
Related
skills/wrds/examples/blockholders_pipeline/redo_bridge.py โ production pipeline this recipe came out of (TR personid โ SEC rptOwnerCik, 97.4% hit rate)
skills/wrds/references/linkage.md โ try a real link table first; fuzzy matching is for identifiers that genuinely don't cross vendors