File size: 6,270 Bytes
0606723 4d67ec7 31969d0 4d67ec7 31969d0 4d67ec7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | ---
title: Question Answering Classification
emoji: π¦
colorFrom: blue
colorTo: indigo
sdk: docker
pinned: false
---
# 𧬠NEET Biology Q&A β AI Study Assistant
An AI-powered Question Answering system for NEET Biology built with **BERT classification**, **RAG pipeline**, and **NCERT textbook context**.
---
## ποΈ Architecture
```
User Question
β
βΌ
ββββββββββββββββββββββββββ
β BERT Classifier β β Predicts NCERT chapter (31 classes, 91.7% F1)
β (bert-base-uncased) β β Extracts 1-3 relevant topics/subtopics
ββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Supabase pgvector β β Retrieves top-k text chunks filtered by chapter
β (BGE-small-en-v1.5) β β Cosine similarity search on NCERT embeddings
ββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Groq LLM (Llama 3) β β Generates answer from retrieved context
β RAG Pipeline β β Justifies with step-by-step reasoning
β β β Verifies answer accuracy
ββββββββββ¬ββββββββββββββββ
β
βΌ
JSON Response β Frontend
```
---
## π Project Structure
```
Question_AndAnswerGeneration/
β
βββ Backend/ # FastAPI REST API
β βββ main.py # App entrypoint, CORS, model preloading
β βββ schemas.py # Pydantic request/response models
β βββ routers/
β βββ qa.py # POST /api/qa, POST /api/classify
β
βββ Frontend/ # Vanilla HTML/CSS/JS UI
β βββ index.html
β βββ styles.css
β βββ app.js
β
βββ Classification/ # BERT Chapter Classifier
β βββ config.json # Training hyperparameters
β βββ dataset.py # PyTorch Dataset class
β βββ train.py # Fine-tuning script
β βββ predict.py # Inference wrapper
β βββ classify_and_extract.py # BERT + topic extraction orchestrator
β βββ checkpoints/
β β βββ best_model/ # Trained BERT weights
β βββ data/
β β βββ generated_questions.json # 5,673 labeled questions
β β βββ label_map.json # chapter_id β chapter_name
β βββ Evaluation_metrics/
β βββ eval_metrics.json
β βββ training_log.json
β
βββ rag/ # RAG Pipeline
β βββ retriever.py # Supabase vector search
β βββ prompt_builder.py # LLM prompt templates
β βββ generator.py # Groq API calls
β βββ confidence.py # Confidence scoring
β βββ pipeline.py # Full orchestrator
β
βββ pdf_to_embedding/ # Data Ingestion
βββ clean_pdf_to_json.py # PDF β cleaned JSON chunks
βββ embed_and_upload.py # JSON β embeddings β Supabase
βββ supabase_schema.sql # Database schema + RPC function
```
---
## π Quick Start
### Prerequisites
- Python 3.10+
- Supabase account (with pgvector enabled)
- Groq API key
### 1. Clone & Setup
```bash
git clone https://github.com/PranilBankar/Question_AndAnswerGeneration.git
cd Question_AndAnswerGeneration
```
### 2. Create Virtual Environment
```bash
python -m venv .venv
# Windows
.venv\Scripts\Activate.ps1
# macOS/Linux
source .venv/bin/activate
```
### 3. Install Dependencies
```bash
pip install torch transformers sentence-transformers scikit-learn
pip install fastapi uvicorn
pip install supabase python-dotenv
pip install groq numpy
```
### 4. Environment Variables
Create `pdf_to_embedding/.env`:
```env
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your-anon-key
GROQ_API_KEY=your-groq-api-key
EMBEDDING_MODEL=BAAI/bge-small-en-v1.5
```
---
## βΆοΈ Running the Project
### Start the Backend (Terminal 1)
```bash
cd Question_AndAnswerGeneration
.venv\Scripts\Activate.ps1
uvicorn Backend.main:app --reload --port 8000
```
Wait for: `β
All models loaded β server ready!`
### Start the Frontend (Terminal 2)
```bash
cd Question_AndAnswerGeneration
python -m http.server 5500 --directory Frontend
```
### Open in Browser
```
Frontend: http://localhost:5500
Swagger: http://localhost:8000/docs
Health: http://localhost:8000/health
```
---
## π API Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| `POST` | `/api/qa` | Full pipeline: classify β retrieve β answer β verify |
| `POST` | `/api/classify` | BERT classification + topic extraction only |
| `GET` | `/health` | Health check (server + model status) |
| `GET` | `/docs` | Swagger UI (auto-generated) |
### Example: POST /api/qa
```bash
curl -X POST http://localhost:8000/api/qa \
-H "Content-Type: application/json" \
-d '{"question": "What is the role of cofactors in enzyme activity?"}'
```
### Example: POST /api/classify
```bash
curl -X POST http://localhost:8000/api/classify \
-H "Content-Type: application/json" \
-d '{"question": "What is the role of cofactors in enzyme activity?"}'
```
---
## π§ Tech Stack
| Component | Technology |
|-----------|------------|
| Classifier | BERT (bert-base-uncased), PyTorch, HuggingFace Transformers |
| Embeddings | BGE-small-en-v1.5 (384-dim), Sentence Transformers |
| Vector DB | Supabase PostgreSQL + pgvector (HNSW index) |
| LLM | Groq API (Llama 3) |
| Backend | FastAPI + Uvicorn |
| Frontend | Vanilla HTML/CSS/JS |
| Data Source | NCERT Biology Class 11 & 12 (31 chapters) |
---
## π Model Performance
| Metric | Score |
|--------|-------|
| Accuracy | 91.19% |
| F1 (macro) | 91.68% |
| Classes | 31 chapters |
| Training Data | 5,673 questions |
| Training Time | 8 min 30 sec (CPU) |
---
## π License
This project is for educational purposes.
|