This repository provides a lightweight fine-tuned medical reasoning model specialized for fertility and reproductive-medicine cases.
All demos are available in notebook/demo.ipynb.
Install dependencies:
pip install torch transformers datasets peft trl unsloth huggingface_hub tqdm jupyterlabLogin to Hugging Face if your base model requires authentication:
from huggingface_hub import notebook_login
notebook_login()train/00_prepare_mixture.py is responsible for:
- Cleaning and preprocessing raw datasets
- Combining multiple sources into a unified training mixture
- Formatting examples for chain-of-thought supervised fine-tuning
Running this script will generate:
data/processed/final_mix/train/qlora_sft.py performs QLoRA-based supervised fine-tuning.
Key details:
- Base model:
SmolLM3-3B-Base - LoRA adapters for efficient training
- Long-context support (up to 32k tokens)
- Final model saved under:
models/sft_smollm3/Two evaluation scripts are provided:
Evaluates the fine-tuned model on medical-reasoning benchmarks:
- MedQA
- MedMCQA
- PubMedQA
- MMLU Clinical subsets
Evaluates the base model on the same datasets for comparison.
Both scripts report:
- Accuracy per dataset
- Overall aggregated score
- Differences between yes/no reasoning and multiple-choice grounding
Use:
inference/stream_medical_cot.pyThis script supports:
- Loading the fine-tuned model
- Passing new patient cases (JSON or text)
- Viewing chain-of-thought reasoning traces
- Getting recommended clinical actions
Useful for testing custom fertility cases or PDF-extracted patient summaries.
A complete end-to-end demo is available in:
notebook/demo.ipynbIt shows:
- Loading the fine-tuned model
- Running benchmark evaluations
- Testing inference on sample fertility cases
- Visualizing chain-of-thought reasoning