SpellCure
SpellCure is a mathematical, dictionary-driven spelling-correction engine for heavily scrambled or distorted text, created by Saheban Khan (GitHub: Lsaheban) and maintained by Tohid Khan (GitHub: Tohid096).
Version 7.0.0 ships the v7 engine: a fourteen-channel scorer with learned dual-expert reranking that recovers both extreme scrambles (aplpe → apple) and realistic typos (recieve → receive, truely → truly) at sub-millisecond latency per token on a single thread.
What's new in 7.0.0
The jump from 1.0.x to 7.0.0 mirrors the engine's research line (v1 → v7):
- Fourteen scoring channels — presence, position, lensim, frequency prior, OSA similarity, Jaro-Winkler, prefix, keyboard-adjacency, anagram, OSA-1 nearest neighbour, distinct-count, multiset distance, anagram-count, and the new esig (pure-insertion) channel.
- Two learned softmax experts — every candidate is scored by an edit expert and a structural expert; a observable gate routes each query. Weights shipped in this package were trained on 17,963 corrupted/true pairs and selected on 4,493 held-out validation pairs (val top-1 0.8429, miss rate 2.34 %).
- Vectorized delete-2 signature gather over a packed CSR storage layer with a dominant-candidate fast path — mean 0.18 ms / median 0.10 ms / p95 0.49 ms per token (50k lexicon, single thread).
- Bundled assets — the exact 50,000-word frequency-ranked lexicon and the deployed training checkpoint used for every number in the SpellCure research paper.
- Legacy API unchanged — the 1.0.x
correctorclass is still here, byte-for-byte.
Installation
pip install spellcure
Requires Python ≥ 3.9. Dependencies: numpy, jellyfish, wordfreq, nltk.
Quick start (v7 engine)
The default engine loads the bundled 50k lexicon and trained weights on first use (index build takes a few seconds; it is cached process-wide):
import spellcure
spellcure.suggest("truely")
# ['truly', 'rudely', 'cruelty']
spellcure.suggest("recieve")
# ['receive', 'relieve', 'received']
spellcure.correct("aplpe tihs wrod is msesdy")
# 'apple/maple/ample this/thus/tips word/road/wood is/his/its messy/messed/missed'
suggest(word) returns up to three ranked candidates for one word. correct(text) applies it per token and joins each token's candidates with / (best candidate first).
Own the engine object
For custom vocabularies, tuning knobs, or training, build the engine directly:
from spellcure import SpellCureV7
engine = SpellCureV7(my_vocab_list) # any list of case-folded words
engine = SpellCureV7(my_vocab_list,
extra_vocab=hunspell_words, # optional extra lexicon
use_wordfreq=True) # zipf frequency prior
engine.suggest("speling") # ['spelling', 'sperling', 'spewing'] (50k lexicon)
engine.fit(train_pairs, val_pairs=val_pairs) # (corrupt, true) pairs, trains in place
spellcure.load_default(**kwargs) builds a fresh engine over the bundled lexicon; spellcure.get_default_engine() returns the cached singleton used by the module-level suggest/correct helpers.
Legacy API (unchanged from 1.0.x)
from spellcure import corrector
model = corrector(mode="small") # ~10k curated built-in word bank
model.correct("olve is evryetign") # 'love is everything'
model = corrector(mode="large") # ~236k NLTK words
model = corrector(custom_vocab=["spell", "cure", "engine"])
The fourteen channels
| # | Channel | Measures |
|---|---|---|
| 1 | presence |
shared-character coverage (multiset intersection / query length) |
| 2 | position |
position-weighted character agreement |
| 3 | lensim |
length similarity |
| 4 | prior |
word-frequency prior (wordfreq zipf) |
| 5 | osa_sim |
optimal-string-alignment similarity |
| 6 | jw |
Jaro-Winkler similarity |
| 7 | prefix4 |
shared 4-character prefix |
| 8 | keyboard |
QWERTY key-adjacency plausibility |
| 9 | anagram |
sorted-signature equality (full anagram) |
| 10 | osa1nn |
OSA-1 nearest-neighbour signal from the index |
| 11 | dcount |
shared delete-2 signature count (dominance) |
| 12 | m1 |
multiset distance ≤ 1 |
| 13 | anac |
anagram candidate count signal |
| 14 | esig |
exact-signature / pure-insertion signal |
Candidates are gathered by delete-2 signature lookup, cheap pools are verified by a dominant-candidate fast path, and the final ranking is produced by the two learned softmax experts (spellcure.feature_names() lists the channel order).
Accuracy and latency
From the SpellCure research paper (50k lexicon, deployed weights; see the bundled checkpoint for the exact values):
| Metric | Value |
|---|---|
| Validation top-1 | 0.8429 |
| Miss rate | 2.34 % |
| Mean latency / token | 0.181 ms |
| Median latency / token | 0.098 ms |
| p95 latency / token | 0.491 ms |
| Execution model | single thread, pure Python + NumPy |
Latency is hardware-dependent; the accuracy figures reproduce exactly with the bundled lexicon, weights, and protocol.
Package assets
| Path | Contents |
|---|---|
spellcure/data/vocab_50k.txt |
50,000-word frequency-ranked English lexicon |
spellcure/weights/v7_train.json |
deployed dual-expert checkpoint (edit + structural weights, validation metrics) |
spellcure/engine/ |
verbatim research engines: v5.py, v6.py, v7.py |
import spellcure
spellcure.load_vocab() # bundled 50k lexicon as a list
spellcure.load_weights() # deployed checkpoint as a dict
spellcure.apply_trained_weights(engine, path=None, variant=None)
How it works
For every query token SpellCure (1) enumerates the query's delete-≤2 signature set, (2) gathers candidate words sharing signatures from packed CSR indexes, (3) attempts a dominant-candidate fast path verified by an OSA ≤ 2 band check, and (4) otherwise assembles edit/structural pools and reranks them with fourteen features under two learned softmax experts. The search, tie-breaks, and determinism are identical to the published research engines, which ship verbatim in spellcure.engine for comparison and ablation.
Credits
SpellCure was created by Saheban Khan and is maintained by Tohid Khan. The v5–v7 engine line, its training protocol, and every benchmark number in this README are documented in the accompanying SpellCure research papers.
License
MIT — see LICENSE.
Metadata
Release files for spellcure 7.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spellcure-7.0.0.tar.gz | 285.5 kB | Without provenance | Details for spellcure-7.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spellcure-7.0.0-py3-none-any.whl | Python 3 | none | any | Details for spellcure-7.0.0-py3-none-any.whl |
Total release size: 571.1 kB
Release files / spellcure-7.0.0.tar.gz
| Download URL | spellcure-7.0.0.tar.gz |
|---|---|
| Size | 285.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a03565ecf56c53cbc3157a949113a0c1339d05d9084235688c5364bcf30497a8
|
|
BLAKE2b-256 checksum How to use checksums |
55d83806b21495e8314bdb91ccaab6f3381189af86fc73babb8a5d47c13b3e1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Release files / spellcure-7.0.0-py3-none-any.whl
| Download URL | spellcure-7.0.0-py3-none-any.whl |
|---|---|
| Size | 285.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc91474c87d523652bf628472898837146a25c1ca9b8969b3c819d38e6f319af
|
|
BLAKE2b-256 checksum How to use checksums |
2ba10a86786941944a0598c30fd489e29f8225702f19e7cb65f2fc3f87446cd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Security for spellcure 7.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.