Pranil Bankar
Add Hugging Face Spaces configuration to README
0606723
|
Raw History Blame Contribute Delete
6.27 kB
metadata
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

git clone https://github.com/PranilBankar/Question_AndAnswerGeneration.git
cd Question_AndAnswerGeneration

2. Create Virtual Environment

python -m venv .venv

# Windows
.venv\Scripts\Activate.ps1

# macOS/Linux
source .venv/bin/activate

3. Install Dependencies

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:

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)

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)

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

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

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.