Course: BU CS 506 - Final Project
Team: Garry Kuwanto
Final Report: December 10, 2024
- Python 3.11+
- CUDA-compatible GPU (recommended for LFM2 inference)
- ~10GB disk space for models and data
# Clone the repository
git clone https://github.com/YOUR_USERNAME/dnd-dm-copilot.git
cd dnd-dm-copilot
# Install all dependencies (includes llama-cpp-python with CUDA support)
make install# Create .env file from template
make dev-setup
# Edit .env with your API keys (required for evaluation)
# - HF_TOKEN: Hugging Face token (for downloading models/datasets)
# - DEEPSEEK_API_KEY: DeepSeek API key (for LLM-as-a-Judge evaluation)# Download the fine-tuned embedding model from Hugging Face
make download-sbert
# Download LFM2 model for answer generation (required for demo)
make download-lfm2
# Or download both at once
make download-models# Start the FastAPI server with demo UI
make run-api
# Visit http://localhost:8000/demo/ in your browsermake install
make dev-setup
make download-models
make run-apiNote:
download-lfm2downloads ~1GB model file. This is required for the demo to generate answers.
make testmake test-api # API endpoint tests
make test-eval # Evaluation pipeline tests
make test-data # Data processing tests
make test-model # Model testsmake test
# Coverage report available at htmlcov/index.html| Component | Supported |
|---|---|
| OS | Linux (tested on Ubuntu 22.04), macOS, Windows (WSL2) |
| Python | 3.11+ |
| GPU | NVIDIA CUDA 12.4+ (for LFM2 inference) |
| CPU-only | Yes (slower inference) |
| Metric | Baseline | Fine-tuned | Improvement |
|---|---|---|---|
| Accuracy@1 | 34.8% | 68.2% | +96% |
| Accuracy@3 | 50.0% | 78.2% | +56% |
| Accuracy@5 | 55.5% | 82.6% | +49% |
| MRR@10 | 43.5% | 74.9% | +72% |
| System | Correct Answers | Accuracy |
|---|---|---|
| Baseline (No RAG) | 22/500 | 4.4% |
| RAG Pipeline (Fine-tuned) | 206/500 | 41.2% |
Our fine-tuned RAG system produces 9x more correct answers than the baseline model without RAG.
- Baseline Model (Left): Query-passage pairs scattered with long connecting lines
- Fine-tuned Model (Right): Query-passage pairs cluster closer together with shorter lines
"I question whether these metric gains are truly meaningful... suggest employing additional methods to validate the effectiveness of your accuracy improvements."
- Different Distribution - Trained on D&D 3.5e, tested on D&D 5e
- LLM-as-a-Judge - DeepSeek evaluates actual answer quality (not just retrieval)
- End-to-End Evaluation - Full RAG pipeline (retrieval + generation)
- Baseline Comparison - Compare against model without RAG
500 5e Passages β Generate Q&A β Run RAG Pipeline β LLM Judge β Metrics
This rigorous evaluation demonstrates that our improvements are meaningful and generalizable.
User Query β Fine-tuned MiniLM β FAISS Search β Top-k Passages β LFM2-1.2B-RAG β Answer
- Fine-tuned MiniLM - Domain-specific embeddings (22M params)
- FAISS Vector Store - Fast similarity search
- LFM2-1.2B-RAG - Local LLM for answer generation
- FastAPI Backend - REST API at
/api/v1/mechanics/query - Demo UI - Interactive web interface at
/demo/
dnd-dm-copilot/
βββ dnd_dm_copilot/
β βββ api/ # FastAPI backend + demo UI
β βββ data/ # Data processing pipelines
β βββ evaluation/ # Evaluation pipeline (3-step)
β βββ model/ # LLM client (LFM2)
β βββ training/ # Model fine-tuning
β βββ visualization/ # t-SNE analysis
βββ tests/ # Comprehensive test suite
βββ data/
β βββ processed/ # Processed datasets
β βββ evaluation/ # Evaluation results
β βββ indices/ # FAISS indices
βββ models/
β βββ sbert/ # Fine-tuned model
βββ visualizations/ # Generated plots
βββ Makefile # Build commands
βββ README.md # This file
- Domain-Specific Fine-Tuning Works - 96% improvement in Accuracy@1
- Improvements Are Meaningful - 836% improvement on held-out test set
- Model Generalizes - Works on D&D 5e despite training on 3.5e
- Complete System Built - Production-ready RAG with demo UI
- Rigorous Validation - LLM-as-a-Judge addresses midterm concerns
# Generate 500 questions from 5e corpus
make evaluate-questions CORPUS=data/processed/5e_corpus.json
# Run RAG pipeline
make evaluate-rag LFM2_MODEL=models/lfm2/LFM2-1.2B-RAG-Q4_0.gguf
# Judge answers with LLM
make evaluate-judge
# Results saved to:
# - data/evaluation/qa_triplets.json
# - data/evaluation/rag_results.json
# - data/evaluation/judgments.jsonmake evaluate-baseline LFM2_MODEL=models/lfm2/LFM2-1.2B-RAG-Q4_0.gguf
make evaluate-judge-baseline- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
make test) - Run quality checks (
make quality-check) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
make format # Format with black
make lint # Lint with flake8
make type-check # Type check with mypy
make test # Run tests- CLAUDE.md - AI assistant guidance for development
- docs/DATA_SOURCES.md - Data source details
- docs/TECHNICAL_DETAILS.md - Technical implementation
- docs/IMPLEMENTATION_PLAN.md - Project timeline
- EVALUATION_PIPELINE.md - Evaluation guide
- sentence-transformers - Embedding model training
- FAISS - Vector similarity search
- FastAPI - Backend API
- Weights & Biases - Experiment tracking
- DeepSeek - LLM-as-a-Judge evaluation
- LiquidAI LFM2 - Answer generation
- m0no1/dnd-mechanics-dataset - Training data
- D&D 5e SRD - Test corpus
This project is for educational purposes as part of BU CS 506.
Garry Kuwanto - BU CS 506 Final Project
For questions about this project, please open an issue on GitHub.


