A spelling correction and error-categorization engine designed for adaptive learning. This project goes beyond simple autocorrect by utilizing a multi-layered inference pipeline to identify why a student made a mistake, providing the granular feedback necessary for effective language acquisition.
- π§ Adaptive TTS: dynamic text-to-speech generation via gTTS for auditory-based practice.
- β Hybrid Correction: Combines the precision of deterministic lookups with the "intuition" of Transformer-based models.
- π Pedagogical Error ID: Categorizes mistakes into specific types (e.g., Vowel Confusion, Letter Swaps) to track student progress.
- π₯ Gamified Learning: Streak tracking, confetti animations, and adaptive difficulty levels (Easy β Medium β Hard).
- β¨ Word of the Day: Daily focused practice with offline fallbacks.
- π Result: Confetti animation on correct answers.
graph TD
Start([Start]) --> Home[Home / Dashboard]
Home --> Practice[Practice Selection]
Practice --> Session[Start Session]
Session --> Audio[Listen] --> Input[Type] --> Check{Check}
Check -->|Correct| Success[Success & Streak]
Check -->|Wrong| Feedback[Error ID & Tip]
Success --> Next[Next Word / Stats]
Feedback --> Session
Next --> Home
graph LR
Input([User Input]) --> Pipeline
subgraph Pipeline [Hybrid Waterfall Inference]
direction LR
S{Symbolic} --> O{Override} --> N{Neural} --> St{Statistical}
end
S -->|Match| OK([Correct])
O -->|Match| OK
St -->|Verdict| OK
St -->|Error| Feed([Pedagogical Feedback])
AI-Spelling-Tutor/
βββ api_server.py β FastAPI backend entry point
βββ requirements.txt
βββ data/
β βββ correct_words.txt β Word bank
βββ src/
β βββ hybrid_inference.py β DistilBERT + char-level pipeline
β βββ bert_model.py β DistilBERT model loader
β βββ char_model.py β Character-level classifier
β βββ word_bank.py β Word selection by difficulty
β βββ tts.py β Google TTS (gTTS)
βββ models/
β βββ char_model/
β βββ spelling_binary_model.pkl
β βββ spelling_binary_vectorizer.pkl
β βββ spelling_error_model.pkl
β βββ spelling_error_vectorizer.pkl
βββ distilbert_spelling/ β Fine-tuned DistilBERT weights
βββ app/
β βββ agent.py
β βββ streamlit_app.py β Streamlit web demo
βββ mobile_app/
β βββ app/
β β βββ (tabs)/
β β β βββ index.tsx β Home screen
β β β βββ practice.tsx β Spelling practice screen
β β β βββ progress.tsx β Progress & stats screen
β β βββ feedback.tsx
β β βββ _layout.tsx
β βββ components/
β β βββ common/ β Badge, BigButton, LoadingSpinner
β β βββ feedback/ β ConfettiEffect, ResultCard, ErrorExplanation
β β βββ home/ β WordOfTheDay
β β βββ practice/ β WordAudioPlayer, SpellingInput, HintReveal, DifficultySelector
β β βββ progress/ β StatCard, StreakCounter
β βββ hooks/
β β βββ useAudio.ts
β β βββ useProgress.ts
β β βββ useSpellCheck.ts
β β βββ useWord.ts
β βββ services/
β β βββ api.ts
β β βββ spellcheck.ts
β β βββ wordBank.ts
β βββ store/
β β βββ gameStore.ts
β β βββ progressStore.ts
β βββ constants/ β colors, typography, difficulty
β βββ types/ β TypeScript interfaces
β βββ utils/ β storage, hintGenerator, errorMessages
β βββ assets/
β βββ fonts/ β Nunito font family
βββ notebooks/
βββ spelling.ipynb β Model training notebook
| Component | Technology |
|---|---|
| Backend | Python 3.12, FastAPI, Uvicorn |
| Deep Learning | PyTorch, HuggingFace Transformers (DistilBERT) |
| Classical ML | Scikit-learn, Logistic Regression (Character N-grams) |
| Mobile | React Native, Expo SDK 54, TypeScript, Zustand |
| Audio | gTTS (Google Text-to-Speech), expo-av |
| Infrastructure | Render (Deployment), Ngrok (Dev Tunneling) |
The system employs a Waterfall Hybrid Inference Pipeline to balance latency, accuracy, and interpretability:
- Symbolic layer (Dictionary): Instant O(1) check against a curated word bank for exact matches.
- Override Layer (Common Misspellings): A deterministic map for high-frequency linguistic "traps."
- Neural Layer (DistilBERT): Evaluates the "plausibility" of the word. Trained on balanced synthetic data to identify valid English-like structures.
- Statistical Layer (Char-level LogReg): A character-level n-gram (2-5 grams) Logistic Regression model that performs the final binary classification and, if incorrect, routes to a multi-class classifier to identify the Error Type.
letter_drop: Missing characters (e.g., "hapening" instead of "happening").letter_swap: Transparent transpositions (e.g., "reiceve").extra_letter: Redundant characters.vowel_confusion: Phonetically similar vowel swaps (e.g., "separgate").
To train a robust classifier without a proprietary dataset, I developed a custom synthetic error generator that simulates common human cognitive biases in spelling:
- Phonetic Vowel Confusion: Targeted swaps of
a, e, i, o, u. - Typographical Swaps: Simulating keyboard adjacent or cognitive order errors.
- Random Drops/Injections: Simulating fast-typing or phonetic omission.
For the character-level classifier, Macro F1-score was chosen as the primary metric (achieving ~0.71).
Why Macro F1? Our dataset (Synthetic vs. Correct) is inherently imbalanced. Macro F1 ensures we treat the 'Incorrect' class (the minority) with equal importance to the 'Correct' class, preventing the model from over-biasing toward a 1.0 accuracy score by simply guessing "Correct" every time.
Download the fine-tuned DistilBERT weights and save them to a directory named distilbert_spelling/ in the root of the project.
- Download Link: DistilBERT Weights (Google Drive)
# Set up environment
python -m venv .venv
source .venv/bin/activate # Or .venv\Scripts\Activate.ps1 on Windows
# Install dependencies
pip install -r requirements.txt
# Launch FastAPI
uvicorn api_server:app --host 0.0.0.0 --port 8000cd mobile_app
npm install --legacy-peer-deps
npx expo startThe Challenge: Standard Sub-word tokenizers (like BERT's WordPiece) often obscure spelling errors by breaking misspelled words into nonsensical sub-tokens. The Solution: Future iterations will explore Character-BERT or ByT5, which operate directly on raw bytes/characters, making them significantly more robust for character-level tasks.
The Challenge: Synthetic data, while useful for bootstrapping, lacks the nuance of real student errors. The Next Step: Integration of the BEA 2019 Shared Task dataset or the GitHub Typo Corpus to fine-tune the DistilBERT layer on actual human behavioral patterns.
Performance: To achieve sub-100ms inference on the neural layer for real-time tutoring, the next phase involves exporting the DistilBERT model to ONNX Runtime with INT8 Quantization, allowing for CPU-optimized high-throughput deployment on Render or AWS Lambda.
Distributed under the MIT License.





