Divyanshusinghrajawat/Intelligent-excuse-generator
AI-powered NLP system for context-aware excuse generation with ML believability scoring
๐ญ Intelligent Excuse Generator
An AI-powered, NLP-driven Python application that generates context-aware,
realistic and customizable excuses โ with believability scoring, proof
suggestions, and multi-format output.
๐ Table of Contents
- Overview
- Features
- How It Works
- Project Structure
- Tech Stack
- Setup & Installation
- How to Use
- ML Model Details
- Output Formats
- Future Scope
- Author
๐ Overview
The Intelligent Excuse Generator is a Python-based AI application
that helps users generate realistic, context-aware excuses for different
life situations โ academic, professional, social, and emergency.
Unlike simple text generators, this system uses a hybrid approach:
- A rule-based NLP engine (spaCy + NLTK) that understands the
user's situation and extracts meaningful context - A template library of 30+ professionally written excuse templates
mapped to category, relationship and tone - A scikit-learn ML classifier that scores how believable the
generated excuse is on a scale of 1 to 10 - A clean Jupyter Notebook UI built with ipywidgets โ no web
framework needed, runs fully offline
The entire system works 100% offline โ no API keys, no internet
connection required after initial setup.
โจ Features
1. Context-Aware Excuse Generation
The system does not just pick a random excuse. It analyzes your situation
text using NLP to extract keywords, detect urgency, infer what action was
missed, and selects the most appropriate template from the library.
2. NLP Preprocessing (spaCy + NLTK)
- Named entity recognition (identifies people, places, dates)
- Part-of-speech tagging (extracts nouns, verbs, adjectives)
- Urgency detection (flags words like "emergency", "deadline", "ASAP")
- VADER sentiment analysis (adjusts excuse tone based on emotional context)
3. Rule-Based Excuse Engine
- 30+ templates organized by category and relationship type
- Dynamic placeholder filling ({event}, {action}, {deadline} etc.)
- Auto-generates realistic deadlines, recovery actions and events
- Falls back gracefully when context is ambiguous
4. ML Believability Scorer
- TF-IDF vectorizer + Logistic Regression pipeline
- Trained on 45 labeled excuse samples (3 classes)
- Scores excuses: Low (1โ4) ยท Medium (5โ7) ยท High (8โ10)
- Gives actionable feedback tips to improve weak excuses
- Model saved as
.pklfile โ loads instantly on next run
5. Emergency Mode
- Single red button โ no configuration needed
- Instantly generates a professional emergency excuse
- Works even if the situation box is empty
6. Multi-Format Output
Same excuse, three different formats:
- Plain โ simple paragraph with greeting and sign-off
- Formal Letter โ full letter with date, subject, recipient, closing
- WhatsApp โ short, casual, emoji-friendly message
7. Proof & Evidence Suggestions
- Suggests 1โ5 realistic supporting documents based on the event type
- Detects event type automatically (medical, technical, travel, family)
- Includes a clear ethical disclaimer
8. Quick Fill Templates
- 16 prebuilt situation templates across all 4 categories
- Selecting one auto-fills the situation box instantly
- Can still be edited manually after selection
- Quick fill options update dynamically when category changes
โ๏ธ How It Works
User Input (situation text + dropdowns)
โ
โผ
NLP Engine (spaCy)
โโโ Extract keywords (nouns, verbs, entities)
โโโ Detect urgency
โโโ Infer missed action
โโโ Analyze sentiment
โ
โผ
Excuse Engine (Rule-based)
โโโ Select category + relationship template
โโโ Pick fitting event + recovery action
โโโ Fill placeholders with NLP context
โโโ Generate raw excuse text
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ โผ
ML Scorer (scikit-learn) Formatter
โโโ TF-IDF vectorize โโโ Plain format
โโโ Predict believability class โโโ Formal letter
โโโ Map to score (1โ10) โโโ WhatsApp format
โโโ Generate feedback tip
โ
โผ
Proof Generator
โโโ Detect event type (medical/technical/travel/family)
โโโ Return relevant evidence suggestions
โ
โผ
Jupyter Notebook UI (ipywidgets)
โโโ Display all outputs in formatted HTML panel
๐ Project Structure
intelligent_excuse_generator/
โ
โโโ ๐ Intelligent_Excuse_Generator.ipynb โ Run this file
โ
โโโ ๐ requirements.txt โ All Python dependencies
โโโ ๐ README.md โ You are here
โ
โโโ ๐ src/ โ Backend Python modules
โ โโโ __init__.py
โ โโโ nlp_engine.py โ spaCy NLP: keyword extraction,
โ โ urgency detection, sentiment analysis
โ โโโ excuse_engine.py โ Rule-based generation: template
โ โ selection and placeholder filling
โ โโโ scorer.py โ scikit-learn ML pipeline:
โ โ TF-IDF + Logistic Regression
โ โโโ formatter.py โ Output formatting: plain, formal
โ โ letter, WhatsApp
โ โโโ proof_generator.py โ Evidence suggestions based on
โ event type detection
โ
โโโ ๐ data/ โ JSON data files
โ โโโ templates.json โ 30+ excuse templates organized
โ โ by category and relationship
โ โโโ training_data.json โ 45 labeled samples for ML
โ believability scorer training
โ
โโโ ๐ models/ โ Saved ML model
โ โโโ scorer_model.pkl โ Trained pipeline (auto-generated
โ on first run, reused after)
โ
โโโ ๐ outputs/ โ Exported excuse files
โโโ ๐ assets/ โ Images and styling
๐ ๏ธ Tech Stack
| Component | Technology | Purpose |
|---|---|---|
| Language | Python 3.12 | Core programming language |
| NLP | spaCy en_core_web_sm |
Keyword extraction, POS tagging |
| Sentiment | NLTK VADER | Tone and sentiment analysis |
| ML Classifier | scikit-learn | Believability scoring pipeline |
| Vectorizer | TF-IDF (sklearn) | Text feature extraction for ML |
| UI Framework | ipywidgets | Interactive notebook UI |
| Notebook | Jupyter Notebook | Delivery format |
| Data Format | JSON | Template and training data store |
| Environment | Python venv (.venv) | Dependency isolation |
โก Setup & Installation
Prerequisites
- Ubuntu / any Linux distro (or Windows with WSL)
- Python 3.10 or above
- Git (optional)
Step 1 โ Get the project
cd ~
# If using git:
git clone <repo-url>
# Or just navigate to the folder if already downloaded:
cd intelligent_excuse_generatorStep 2 โ Create virtual environment
python3 -m venv .venv
source .venv/bin/activateYou will see (.venv) at the start of your terminal โ this means
the environment is active.
Step 3 โ Install all dependencies
pip install -r requirements.txtThis installs spaCy, NLTK, scikit-learn, ipywidgets, and Jupyter.
Takes 2โ3 minutes on first run.
Step 4 โ Download spaCy language model
python -m spacy download en_core_web_smStep 5 โ Launch the notebook
jupyter notebook Intelligent_Excuse_Generator.ipynb \
--NotebookApp.token='' --NotebookApp.password=''The notebook will open in your browser automatically at
http://localhost:8888
๐ฎ How to Use
Once the notebook is open in your browser:
Step 1 โ Run all cells
Click Kernel โ Restart & Run All to initialize the system.
Wait for the "โ
System ready!" message in Cell 2.
Step 2 โ Select a prebuilt situation (Quick Fill)
Use the Quick Fill dropdown to pick a prebuilt situation.
The situation box auto-fills. You can edit it manually too.
Step 3 โ Configure your excuse
| Setting | Options |
|---|---|
| Category | Academic ยท Professional ยท Social ยท Emergency |
| Recipient | Teacher ยท Boss ยท Parent ยท Friend ยท Colleague ยท Client ยท Partner |
| Tone | Formal ยท Casual |
| Format | Plain ยท Formal Letter ยท WhatsApp |
| Proof tips | 1 to 5 suggestions (slider) |
Step 4 โ Generate
- Click โจ Generate Excuse for a tailored, context-aware excuse
- Click ๐จ Emergency Mode for an instant excuse with no setup
Step 5 โ Read your output
The output panel shows:
- The formatted excuse (plain / letter / WhatsApp)
- Believability score out of 10 with a color indicator
- Feedback tip to improve the excuse if needed
- Proof and evidence suggestions relevant to your situation
๐ ML Model Details
The believability scorer is a scikit-learn pipeline trained on
synthetic excuse data.
Pipeline:
TfidfVectorizer(ngram_range=(1,2), max_features=5000)
โ
โผ
LogisticRegression(max_iter=1000, C=1.0, solver='lbfgs')
| Detail | Value |
|---|---|
| Algorithm | Logistic Regression |
| Features | TF-IDF unigrams and bigrams |
| Training samples | 45 labeled excuse texts |
| Classes | 0 = Low ยท 1 = Medium ยท 2 = High |
| Test accuracy | ~77.8% |
| Model file | models/scorer_model.pkl |
| First run | Trains and saves model automatically |
| Subsequent runs | Loads saved model instantly |
Score Bands
| Score | Label | Meaning |
|---|---|---|
| 8โ10 | High | Specific, verifiable, highly convincing |
| 5โ7 | Medium | Reasonable but could use more concrete details |
| 1โ4 | Low | Vague or unconvincing โ needs improvement |
๐ Output Formats
Plain
Respected Sir/Ma'am,
Due to an unforeseen medical emergency, I was unable to submit
the assignment on time. I have notified the relevant parties
and request a brief extension until Friday, 21 March 2026.
Thank you for your consideration. I remain fully committed
to my responsibilities.
Divyanshu
Formal Letter
=======================================================
FORMAL LETTER
=======================================================
Date : 20 March 2026
To : The Class Teacher / Professor
Subject : Explanation for Absence / Delay
-------------------------------------------------------
Respected Sir/Ma'am,
Due to an unforeseen medical emergency ...
Yours sincerely,
Divyanshu
=======================================================
Sir/Ma'am really sorry to message like this ๐
Due to an unforeseen medical emergency, I was unable
to submit the assignment on time.
Will update you soon ๐
๐ฎ Future Scope
- Larger training dataset โ more samples for higher ML accuracy
- LLM integration โ plug in Anthropic/OpenAI API when online
for dynamic, truly unique excuse generation - Hindi and regional language support โ multilingual excuses
- PDF export โ download excuse as a formatted PDF document
- Streamlit web app โ browser-based UI without Jupyter
- Excuse history โ save and revisit previously generated excuses
- Custom templates โ let users add their own excuse templates
๐จโ๐ป Author
Divyanshu
B.Tech Computer Science (2nd Year)
Built with Python ยท spaCy ยท NLTK ยท scikit-learn ยท ipywidgets ยท Jupyter