Skip to main content

A dual-channel ML-based spelling correction engine for Movies and TV search, trained on TMDB vocabulary.

Project description

Re-Spell Engine

A production-ready, high-performance spelling correction engine for Movie and TV Show searches, trained on TMDB content.

This engine implements a Dual-Channel Retrieval Model (character n-gram TF-IDF on full titles and consonant-only skeletons) backed by Damerau-Levenshtein distance alignment and custom phonetic vowel-substitution heuristics to resolve complex structural and phonetic typos (e.g., betmen, batmen, batmn $\rightarrow$ Batman, and bahubli $\rightarrow$ Bāhubali).


Installation

Install the package directly from PyPI:

pip install re-spell-engine

Using as a Python Library

You can import and integrate the spelling engine directly into other Python applications. The package includes a pre-trained default model binary of over 107,000+ Movies and TV Shows.

from respell_engine import SpellingCorrector

# 1. Initialize the corrector
corrector = SpellingCorrector()

# 2. Load the default pre-trained model shipped with the package
# (You can optionally pass a custom path to corrector.load("/path/to/custom/model.pkl"))
corrector.load()

# 3. Correct a misspelled query
query = "betmen"
result = corrector.correct(query)

if result["is_corrected"]:
    print(f"Original: {result['original_query']}")
    print(f"Corrected Suggestion: {result['corrected_query']}")
    print(f"Confidence: {result['confidence']:.4f}")
    print(f"Autocorrect Recommended: {result.get('is_autocorrect', False)}")
else:
    print("Spelling is correct or no confident correction was found.")

Correction Response Schema

The .correct() method returns a dictionary with the following fields:

  • original_query (str): The input query string.
  • corrected_query (str): The clean base corrected title (e.g. Bāhubali instead of Bāhubali: The Epic) to maximize the downstream search scope.
  • did_you_mean (str | None): Suggestion string if correction is confident; otherwise None.
  • is_corrected (bool): True if a spelling correction was determined.
  • is_autocorrect (bool): True if correction confidence is extremely high (e.g., $\ge 0.83$ or edit distance $\le 1.0$) recommending immediate query substitution.
  • confidence (float): Score representing the quality of match (bounded between 0.0 and 1.0).
  • candidate_details (dict | None): Underlying metadata of matched candidate (id, media_type, distance, raw score, etc.).

Web API Integration

Start the web server locally using uvicorn (runs CPU-bound NLP logic on a worker thread pool for production concurrency):

uvicorn respell_engine.main:app --host 127.0.0.1 --port 8000

Endpoints

1. Search with Spelling Correction

  • Route: GET /api/search
  • Parameters:
    • query (str, required): The search input query.
    • autocorrect (bool, optional, default=true): If set to false, disables correction logic and returns query literally.
  • Example request: GET /api/search?query=betmen
  • Example Response:
    {
        "original_query": "betmen",
        "corrected_query": "Batman",
        "did_you_mean": "Batman",
        "is_corrected": true,
        "is_autocorrect": true,
        "confidence": 0.9035,
        "candidate_details": {
            "movie_id": 2287,
            "display_title": "Batman",
            "media_type": "tv",
            "distance": 1.0,
            "norm_dist": 0.1666,
            "cosine_sim": 0.0787,
            "score": 0.9035
        }
    }
    

2. Get Engine Status

  • Route: GET /api/status

3. Trigger Retraining

  • Route: POST /api/train

Ingestion & Training Workflow

If you want to train on a fresh dataset from TMDB:

1. Set environment variables

Create a .env file at the root of your project directory containing your TMDB Read Access Token (Bearer Token):

TMDB_API_TOKEN=your_bearer_token_here

2. Ingest Content

python3 -m respell_engine.scripts.fetch_data

3. Re-train Model

python3 -m respell_engine.scripts.train

4. Verify Accuracy

python3 -m respell_engine.scripts.verify_correction

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

re_spell_engine-1.0.0.tar.gz (71.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

re_spell_engine-1.0.0-py3-none-any.whl (71.8 MB view details)

Uploaded Python 3

File details

Details for the file re_spell_engine-1.0.0.tar.gz.

File metadata

  • Download URL: re_spell_engine-1.0.0.tar.gz
  • Upload date:
  • Size: 71.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for re_spell_engine-1.0.0.tar.gz
Algorithm Hash digest
SHA256 13591ee1759f254e8ba6d680db653b9c3f5ab47f4c659eaa2da48b397e975b51
MD5 8e2a37985a0b5a99165303dc907b0270
BLAKE2b-256 4c18b41ccb8e08102ab7c6eefed0c4097c3fa6a28ac465116cfcaa780a92f1f2

See more details on using hashes here.

File details

Details for the file re_spell_engine-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for re_spell_engine-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be29b31270ecae9f80103a1f68e00de18b9ed49dc145ccd87a9ad8d2f79ece83
MD5 0fe2d2063ca280a9192619ea2c5a4a77
BLAKE2b-256 28ddb5fd2649bc639962c2363d9addee8654678489ea1846cce81b4bf77747a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page