An intelligent flashcard generation system powered by T5 Transformer model. Automatically converts study materials into interactive flashcards and MCQ quizzes with comprehensive analytics tracking.
- Features
- ML Pipeline Overview
- Project Structure
- Installation
- Usage
- Training
- Evaluation
- Technology Stack
- Automatic Question Generation: T5 transformer converts context into meaningful questions
- Smart Answer Extraction: Intelligent answer identification from text
- Multi-format Support: PDF, TXT, direct text input
- Text Summarization: Generate concise summaries of study material
- MCQ Generation: Concept-based multiple-choice questions
- Smart Distractors: Context-aware wrong answer generation
- Real-time Scoring: Instant feedback and performance tracking
- Retake Capability: Shuffle and retake quizzes anytime
- Progress Tracking: Historical performance visualization
- Topic Analysis: Per-topic performance metrics
- Learning Trends: 30-day score trends with Plotly charts
- Comprehensive Stats: Global metrics, learning streaks, activity logs
- SQLite Database: Persistent quiz attempt storage
- Session Management: Streamlit session state for user data
- Export Capabilities: JSON export for flashcards
- Privacy-First: 100% local processing, no cloud APIs
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ML PIPELINE ARCHITECTURE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. DATA COLLECTION
βββ SQuAD v1.1 Dataset (87,599 training examples)
βββ Context-Question-Answer triplets
βββ Train/Val/Test split (80/10/10)
2. DATA PREPROCESSING
βββ Text Tokenization (T5Tokenizer - SentencePiece)
βββ Text-to-Text Format: "generate question: <context>"
βββ Sequence Padding/Truncation (max_length=512)
βββ Special Token Handling ([CLS], [SEP], [PAD])
βββ Token ID Conversion (vocabulary size: 32,128)
3. MODEL ARCHITECTURE (T5-base)
βββ Encoder: 12 transformer layers
β βββ Multi-Head Self-Attention (8 heads)
β βββ Feed-Forward Networks
β βββ Layer Normalization + Residual Connections
β
βββ Decoder: 12 transformer layers
β βββ Masked Self-Attention
β βββ Cross-Attention (to encoder)
β βββ Feed-Forward Networks
β
βββ Hidden Dimensions: 512
βββ Total Parameters: 220 million
βββ Pre-training: C4 dataset (750GB of text)
4. TRAINING (Supervised Fine-tuning)
βββ Learning Type: Supervised Learning
βββ Task: Sequence-to-Sequence Text Generation
βββ Loss Function: Cross-Entropy (token-level classification)
βββ Optimizer: AdamW (learning_rate=1e-4, weight_decay=0.01)
βββ Scheduler: Linear warmup (500 steps) + decay
βββ Batch Size: 16 (with gradient accumulation)
βββ Epochs: 3-5
βββ Regularization: Dropout (0.1), Gradient Clipping (1.0)
βββ Hardware: GPU (CUDA) recommended, CPU fallback
5. INFERENCE (Autoregressive Generation)
βββ Decoding Strategy: Beam Search (num_beams=6)
βββ Generation Process:
β βββ Encoder processes input context
β βββ Decoder generates tokens one-by-one
β βββ Each token = classification over 32k vocabulary
β βββ Continues until [EOS] or max_length
β
βββ Hyperparameters:
β βββ Temperature: 0.7 (creativity control)
β βββ Top-p: 0.9 (nucleus sampling)
β βββ Repetition Penalty: 1.2
β βββ Length Penalty: 1.0
β
βββ Output: Variable-length question text
6. EVALUATION
βββ Generation Quality Metrics:
β βββ BLEU Score (translation quality metric)
β βββ ROUGE-1/2/L (summarization metrics)
β βββ Perplexity (language model confidence)
β
βββ Task-Specific Metrics:
β βββ Question Relevance (manual evaluation)
β βββ Answer Accuracy
β βββ Fluency Assessment
β
βββ Performance Metrics:
βββ Training Loss Curve
βββ Validation Loss
βββ Inference Speed (tokens/second)
7. DEPLOYMENT
βββ Web Application: Streamlit
βββ Model Serving: HuggingFace Transformers
βββ Database: SQLite3 (analytics & progress tracking)
βββ Document Processing: PyPDF2
βββ Visualization: Plotly + Matplotlib
| Aspect | Classification |
|---|---|
| Learning Type | Supervised Learning (Deep Learning) |
| Task Category | Sequence-to-Sequence (Seq2Seq) |
| Architecture | Transformer (Encoder-Decoder) |
| Domain | Natural Language Processing (NLP) |
| Application | Generative AI (Text Generation) |
| Output Type | Variable-length text sequences |
| Training Method | Transfer Learning + Fine-tuning |
| Loss Function | Cross-Entropy (token classification Γ sequence_length) |
Key Insight: This project uses Classification internally (32,128-class classification per token), but chains multiple classifications together autoregressively to generate complete sequences. This makes it Sequence-to-Sequence Generation, not traditional classification or regression.
AI-FLASHCARD-TUTOR/
β
βββ app.py # Main Streamlit application entry point
βββ requirements.txt # Python dependencies (production)
βββ README.md # Comprehensive project documentation
βββ .gitignore # Git ignore rules
β
βββ config/ # ποΈ Configuration Management
β βββ __init__.py # Module initialization
β βββ config.yaml # Centralized configuration (YAML)
β βββ model_config.py # Config loader & parser class
β
βββ src/ # π§ Source Code Modules
β βββ __init__.py
β β
β βββ models/ # π€ ML Model Components
β β βββ __init__.py
β β βββ generate_simple.py # Lightweight flashcard generator
β β βββ generate.py # Full-featured generator (advanced)
β β
β βββ inference/ # π― Inference & Prediction
β β βββ __init__.py
β β βββ quiz.py # Quiz generation & MCQ logic
β β
β βββ features/ # π Application Features
β β βββ __init__.py
β β βββ dashboard.py # Database operations & analytics
β β βββ pages_quiz.py # Quiz UI page components
β β βββ pages_dashboard.py # Analytics UI page components
β β
β βββ utils/ # π οΈ Utility Functions
β β βββ __init__.py
β β βββ utils.py # Helper functions
β β
β βββ training/ # π Training Utilities (future)
β βββ __init__.py
β
βββ scripts/ # π ML Pipeline Scripts
β βββ train.py # Training/fine-tuning script (SQuAD)
β βββ evaluate.py # Evaluation script (BLEU, ROUGE)
β
βββ models/ # πΎ Saved Models & Checkpoints
β βββ flashcard_t5/ # Fine-tuned T5 model directory
β βββ config.json # Model architecture configuration
β βββ metadata.json # Training metadata & hyperparameters
β βββ README.md # Model-specific documentation
β βββ pytorch_model.bin # Model weights (~440MB)
β
βββ data/ # π Data Storage
β βββ progress.db # SQLite database (quiz attempts, metrics)
β βββ cache/ # Cached data (tokenized inputs, etc.)
β βββ raw/ # Raw datasets (SQuAD, custom)
β βββ processed/ # Processed/preprocessed data
β
βββ notebooks/ # π Jupyter Notebooks
β βββ (exploratory data analysis, model experiments)
β
βββ docs/ # π Documentation
β βββ QUICK_START.md # Quick installation & usage guide
β βββ PROJECT_STRUCTURE.md # Detailed structure explanation
β βββ COLAB_INTEGRATION.md # Google Colab integration guide
β
βββ tests/ # β
Unit Tests (future)
βββ __init__.py
| Directory | Purpose | Key Responsibilities |
|---|---|---|
config/ |
Configuration management | Centralized settings, hyperparameters, paths |
src/models/ |
ML model loading & inference | T5 model, tokenizer, generation logic |
src/inference/ |
Prediction & generation | Quiz creation, question generation |
src/features/ |
Application functionality | UI components, database operations |
src/utils/ |
Helper functions | Text processing, file I/O, utilities |
scripts/ |
ML pipeline execution | Training, evaluation, data processing |
models/ |
Model storage | Checkpoints, fine-tuned weights |
data/ |
Data management | Database, datasets, cache |
notebooks/ |
Experimentation | EDA, prototyping, analysis |
docs/ |
Documentation | Guides, explanations, API docs |
tests/ |
Quality assurance | Unit tests, integration tests |
- Python: 3.8 or higher
- pip: Latest version
- (Optional) CUDA-enabled GPU for training (CPU works for inference)
git clone https://github.com/puneeth-webdev218/AI-FLASHCARD-TUTOR.git
cd AI-FLASHCARD-TUTORFor Application Use (Inference Only):
pip install -r requirements.txtFor Training & Development:
# Install core dependencies
pip install -r requirements.txt
# Install training-specific packages
pip install datasets transformers[torch] nltk rouge-score pyyaml
# Download NLTK data
python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"python -c "import streamlit, torch, transformers; print('β
All dependencies installed')"# Start Streamlit app
streamlit run app.py
# Custom port
streamlit run app.py --server.port 8502
# Headless mode (server deployment)
streamlit run app.py --server.headless trueThe app will open automatically at http://localhost:8501
- Navigate to "π Flashcard Generator" tab
- Choose input method:
- Paste Text: Copy-paste study material
- Upload PDF: Click "Browse files" and select PDF
- Adjust settings in sidebar:
- Number of flashcards (1-10)
- Beam search quality (3-8)
- Click "β¨ Generate Flashcards"
- Review generated flashcards:
- Click card to flip (Question β Answer)
- Download as JSON (optional)
- Generate β₯4 flashcards first (required)
- Navigate to "π― Take Quiz" tab
- Select number of questions (4-10)
- Click "Start Quiz"
- Answer multiple-choice questions
- Click "Submit Quiz" to view:
- Score percentage
- Correct/incorrect breakdown
- Time taken
- Detailed explanations
- Click "Retake Quiz" to shuffle and retry
- Navigate to "π Progress Dashboard" tab
- Review key metrics:
- KPI Cards: Total flashcards, quizzes taken, average score, learning streak
- Score Trend: 30-day line chart (interactive Plotly)
- Topic Performance: Bar chart by subject
- Answer Distribution: Pie chart (correct vs incorrect)
- Activity Log: Detailed quiz history table
- Use "Refresh Dashboard" button to update
- Clear Data (if needed) from settings
# Basic training (uses config.yaml defaults)
python scripts/train.py
# Custom hyperparameters
python scripts/train.py \
--model_name t5-base \
--epochs 5 \
--batch_size 16 \
--learning_rate 0.0001 \
--save_dir models/my_flashcard_model
# Quick test run (limited samples)
python scripts/train.py --epochs 1 --max_samples 1000
# Advanced: Custom dataset
python scripts/train.py \
--epochs 5 \
--batch_size 8 \
--learning_rate 5e-5 \
--save_dir models/custom_t5 \
--max_samples 10000| Parameter | Default | Range | Description |
|---|---|---|---|
--model_name |
t5-base |
t5-small, base, large | Base T5 model to fine-tune |
--epochs |
3 |
1-10 | Number of training passes |
--batch_size |
16 |
4-32 | Samples per batch (adjust for GPU memory) |
--learning_rate |
1e-4 |
1e-5 to 1e-3 | AdamW learning rate |
--max_samples |
None |
Any int | Limit training samples (for testing) |
--save_dir |
models/flashcard_t5_finetuned |
Any path | Checkpoint save directory |
Edit config/config.yaml to adjust:
training:
batch_size: 16
learning_rate: 0.0001
num_epochs: 5
warmup_steps: 500
weight_decay: 0.01
gradient_accumulation_steps: 2
max_grad_norm: 1.0
model:
generation:
num_beams: 6
temperature: 0.7
top_p: 0.9
repetition_penalty: 1.2Epoch 1/5
Training: 100%|ββββββββββ| 5475/5475 [1:23:45<00:00, loss=2.1234, lr=9.8e-05]
Validation Loss: 1.9876
Model saved to models/flashcard_t5_finetuned/checkpoint-epoch-1
Epoch 2/5
Training: 100%|ββββββββββ| 5475/5475 [1:22:18<00:00, loss=1.8765, lr=8.2e-05]
...
Training complete! Final model saved to models/flashcard_t5_finetuned
# Basic evaluation
python scripts/evaluate.py --model_path models/flashcard_t5_finetuned
# With sample generation examples
python scripts/evaluate.py \
--model_path models/flashcard_t5_finetuned \
--show_examples \
--num_examples 10
# Limited evaluation (faster)
python scripts/evaluate.py \
--model_path models/flashcard_t5_finetuned \
--max_samples 500
# Full evaluation on test set
python scripts/evaluate.py \
--model_path models/flashcard_t5_finetuned \
--split validation \
--max_samples 2000| Metric | Range | Interpretation | Good Score |
|---|---|---|---|
| BLEU | 0-1 | Translation/generation quality (word overlap) | >0.3 |
| ROUGE-1 | 0-1 | Unigram overlap with reference | >0.4 |
| ROUGE-2 | 0-1 | Bigram overlap (fluency) | >0.2 |
| ROUGE-L | 0-1 | Longest common subsequence | >0.35 |
| Perplexity | 1-β | Model confidence (lower is better) | <50 |
============================================================
EVALUATION RESULTS
============================================================
Number of samples: 1000
BLEU Score:
Mean: 0.3245 Β± 0.1234
Range: [0.0823, 0.7654]
ROUGE Scores:
ROUGE-1: 0.4123 Β± 0.0987
ROUGE-2: 0.2345 Β± 0.0654
ROUGE-L: 0.3876 Β± 0.0876
============================================================
Example 1:
Context: Photosynthesis is the process by which plants...
Reference: What is photosynthesis?
Generated: What process do plants use to convert light?
------------------------------------------------------------
| Technology | Version | Purpose |
|---|---|---|
| PyTorch | 2.0+ | Deep learning framework (GPU acceleration) |
| Transformers | 4.30+ | HuggingFace model library (T5 implementation) |
| T5 Model | Base (220M params) | Text-to-Text Transfer Transformer |
| SQuAD Dataset | v1.1 | 87,599 question-answer pairs for training |
| NLTK | 3.8+ | Natural language processing utilities |
| Datasets | 2.0+ | HuggingFace dataset loading |
| Technology | Version | Purpose |
|---|---|---|
| Streamlit | 1.22+ | Interactive web UI framework |
| Plotly | 5.0+ | Interactive data visualizations |
| Matplotlib | 3.7+ | Static plotting |
| Technology | Version | Purpose |
|---|---|---|
| Pandas | 2.0+ | Data manipulation & analysis |
| NumPy | 1.24+ | Numerical computing |
| PyPDF2 | 3.0+ | PDF text extraction |
| SQLite3 | Built-in | Embedded database (no server needed) |
| Technology | Purpose |
|---|---|
| PyYAML | Configuration file parsing |
| pathlib | Cross-platform file path handling |
| logging | Application logging |
| tqdm | Progress bars for training |
Contributions are welcome! Here's how:
- Fork the repository
- Create feature branch:
git checkout -b feature/AmazingFeature - Commit changes:
git commit -m 'Add AmazingFeature' - Push to branch:
git push origin feature/AmazingFeature - Open Pull Request
Contribution Areas:
- π Bug fixes
- β¨ New features (e.g., spaced repetition)
- π Documentation improvements
- π§ͺ Unit tests
- π¨ UI enhancements
- π Performance optimizations
- Google Research: T5 model architecture and pre-training
- Stanford NLP Group: SQuAD dataset creation
- HuggingFace: Transformers library and model hub
- Streamlit Team: Excellent web framework for ML apps
- PyTorch Community: Deep learning framework
- T5 Paper (2019) - "Exploring the Limits of Transfer Learning"
- Attention Is All You Need (2017) - Original Transformer paper
- SQuAD Paper (2016) - Stanford Question Answering Dataset
- π Spaced repetition algorithm (Anki-style)
- π Multi-language support (mT5 integration)
- π― Adaptive difficulty adjustment
- π± Mobile-responsive UI
- π Export to Anki format
- π€ Collaborative study sessions
- π Advanced analytics (confusion matrices)
- π¨ Custom themes & branding
- β Structured ML project layout
- β Training & evaluation scripts
- β Comprehensive documentation
- π§ͺ Unit test coverage
- π³ Docker containerization
- π¦ PyPI package release
- Convert lecture notes β flashcards
- Generate practice questions from textbooks
- Track learning progress across subjects
- Prepare for exams with MCQ quizzes
- Create quizzes for students automatically
- Generate study materials from lesson plans
- Assess understanding with analytics
- Save time on quiz creation
- Continuous learning & skill development
- Certification exam preparation
- Knowledge retention tracking
- Onboarding material creation
- Literature review flashcards
- Methodology Q&A cards
- Conference presentation prep
- Paper concept reinforcement
- Context Length: Max 512 tokens input (T5 limitation)
- Language: English only (use mT5 for multilingual)
- GPU Memory: Training requires ~8GB VRAM for T5-base
- Generation Time: 2-5 seconds per flashcard (CPU mode)
- Large PDFs (>50 pages) may cause extraction lag
- Very technical/domain-specific text may generate generic questions
- Database locked error if multiple sessions access simultaneously
- Split large documents into chunks
- Provide more context for better question quality
- Use only one Streamlit session per database
β
100% Local Processing - All ML inference runs on your machine
β
No Cloud APIs - No data sent to external services
β
No Telemetry - Zero usage tracking or analytics
β
Offline Capable - Works without internet (after initial setup)
π SQLite Database (data/progress.db)
- Quiz attempts with timestamps
- Global learning metrics
- No personally identifiable information
- Easily deletable (just remove file)
π Temporary Files
- PDF uploads stored in memory (not saved)
- Cache cleared on session end
# In config/config.yaml
model:
generation:
num_beams: 3 # Reduce from 6 (faster, slightly lower quality)model:
generation:
num_beams: 8 # Increase from 6 (slower, better quality)
temperature: 0.5 # Lower = more conservative/accurate# Install CUDA-enabled PyTorch
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118Q: How long does training take?
A: On GPU (RTX 3080): ~2-3 hours for 5 epochs on full SQuAD. On CPU: 24+ hours.
Q: Can I use a different model?
A: Yes! Edit config.yaml to use t5-small (faster) or t5-large (better quality).
Q: How accurate are generated flashcards?
A: Depends on input quality. Structured, detailed text β better results. BLEU scores typically 0.3-0.4.
Q: Can I export my progress?
A: Flashcards export as JSON. Progress data in data/progress.db (SQLite).
Q: Does it work offline?
A: Yes! After initial model download, fully offline.
Q: Can I add my own training data?
A: Yes! Modify scripts/train.py to load custom datasets.
Q: What if quiz questions are too hard?
A: Provide more detailed context in input. Adjust num_beams to 4-5 for balanced difficulty.
| Problem | Solution |
|---|---|
ModuleNotFoundError: transformers |
Run pip install transformers torch |
| "Not enough flashcards for quiz" | Generate β₯4 flashcards before taking quiz |
| Database locked error | Close other Streamlit sessions |
| Out of memory during training | Reduce batch_size to 8 or 4 |
| Slow generation | Use GPU or reduce num_beams |
| PDF extraction fails | Try converting PDF to TXT first |
| Dashboard shows no data | Take at least one quiz to populate data |
π Ready to transform your learning?
streamlit run app.pyThen visit: http://localhost:8501
Powered by Transformers, PyTorch, and Streamlit