Setting up my ML environment from scratch: MedMind
Source: Dev.to
Overview – Day 1: Setting Up the Environment
I decided to build a clinical AI system from scratch—no OpenAI API, no tutorial‑style wrapper. The goal is to train my own model, create a retrieval‑augmented generation (RAG) pipeline, and deploy the whole thing.
The project, MedMind, takes a clinical question, searches a database of medical knowledge, and generates an answer using a model fine‑tuned on real medical exam questions.
Full Stack
- Download and clean a real medical dataset
- Fine‑tune a language model on that data
- Build a RAG pipeline with a vector database
- Evaluate the model honestly
- Serve it with FastAPI
- Build a UI with Streamlit
Python Version
Python 3.11 is recommended because PyTorch and Hugging Face provide the best support for this version.
Virtual Environment
python -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate
Creating a virtual environment isolates the project’s dependencies from the rest of the system.
Core Libraries
pip install torch transformers datasets peft trl accelerate
pip install chromadb sentence-transformers
pip install fastapi uvicorn streamlit
| Library | Purpose |
|---|---|
transformers | Access to pre‑trained models such as OPT, Mistral, LLaMA |
peft | Efficient fine‑tuning with LoRA |
trl | Simplifies instruction fine‑tuning |
chromadb | Vector database for storing medical knowledge |
sentence-transformers | Converts text to vectors for similarity search |
fastapi | Backend API server |
uvicorn | ASGI server for FastAPI |
streamlit | Front‑end UI framework |
Project Structure
medmind/
├── data/ # data acquisition and cleaning scripts
├── training/ # fine‑tuning code
├── rag/ # retrieval pipeline
├── eval/ # evaluation scripts
├── api/ # FastAPI backend
└── frontend/ # Streamlit UI
Hardware Considerations
My local machine has no GPU, and training a language model on CPU would take weeks. I therefore use Google Colab with a free T4 GPU, which is a common approach for developers without dedicated hardware.