|
Download README.md from PranilB/Question_Answering_Classification: direct link, hf CLI and curl.
- Browser
- Download file 6.27 kB
-
https://huggingface.co/spaces/PranilB/Question_Answering_Classification/resolve/main/README.md
- Command line
-
hf download hf://spaces/PranilB/Question_Answering_Classification/README.md
-
curl -L -o README.md https://huggingface.co/spaces/PranilB/Question_Answering_Classification/resolve/main/README.md
6.27 kB
| 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. | |