Skip to content

afianas/SpellCheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

56 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐻 AI Spelling Tutor

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.


πŸš€ Key Features

  • 🎧 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.

πŸ“½ DEMO

Watch the Application Demo


πŸ“± App Screens


Practice Screen
Listen and spell the word

Home Screen
Dashboard and Word of the Day

Spelling Input
Typing with active hints

Error Feedback
Analysis of a 'Tricky Vowel' mistake

Results Screen
Summary after a practice set

Performance Stats
Streak and accuracy tracking

πŸ—Ί App Flow

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
Loading

πŸ— Architecture Diagram

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])
Loading

πŸ—‚ Project Structure

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

πŸ›  Tech Stack

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)

🧠 Architecture & Logic

The system employs a Waterfall Hybrid Inference Pipeline to balance latency, accuracy, and interpretability:

  1. Symbolic layer (Dictionary): Instant O(1) check against a curated word bank for exact matches.
  2. Override Layer (Common Misspellings): A deterministic map for high-frequency linguistic "traps."
  3. Neural Layer (DistilBERT): Evaluates the "plausibility" of the word. Trained on balanced synthetic data to identify valid English-like structures.
  4. 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.

Error Classification Types

  • 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").

πŸ§ͺ Machine Learning Deep Dive

Synthetic Data Generation

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.

Model Evaluation

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.


πŸ— Installation

1. Model Setup

Download the fine-tuned DistilBERT weights and save them to a directory named distilbert_spelling/ in the root of the project.

2. Backend Setup

# 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 8000

2. Mobile Setup

cd mobile_app
npm install --legacy-peer-deps
npx expo start

πŸŽ“ Lessons Learned & Future Work

1. Tokenizer Constraints

The 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.

2. Data Realism

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.

3. Deployment Optimization

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.


πŸ“„ License & Contact

Distributed under the MIT License.

About

Hybrid AI spelling tutor combining rule-based logic, character-level ML, and a fine-tuned DistilBERT model to detect spelling errors and deliver educational feedback.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors