Downloads · 30 days
0
RezaAskari/GPT2-optimal_insulin_calculator
GPT2-optimal_insulin_calculator is a machine learning model from RezaAskari. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A specialized fine-tuning project for GPT-2 to provide insulin dosage adjustment recommendations based on 7-day fasting blood glucose (FBG) measurements.
Downloads · 30 days
0
Access
Public
Updated Sep 27, 2025
Repo size
1.5 GB
Likes
0
Public
Click a slice to open those files.
.pt1 GB · 50%
From the Hugging Face model README
A specialized fine-tuning project for GPT-2 to provide insulin dosage adjustment recommendations based on 7-day fasting blood glucose (FBG) measurements.
This project fine-tunes GPT-2 language models to analyze patient blood glucose patterns and recommend insulin dosage adjustments. The system implements clinical decision rules for insulin titration based on average FBG levels and variability patterns.
fine_tuning/
├── fine_tune.py # Standard GPT-2 fine-tuning
├── fine_tune_lora.py # LoRA (Low-Rank Adaptation) fine-tuning
├── fine_tune_qlora.py # QLoRA (Quantized LoRA) fine-tuning
├── push_to_hub.py # Script to upload models to HuggingFace Hub
├── gpt2_insulin_titration/ # Standard fine-tuned model
├── gpt2_insulin_lora/ # LoRA fine-tuned model
└── gpt2_insulin_qlora/ # QLoRA fine-tuned model
pip install torch transformers datasets peft accelerate bitsandbytes huggingface-hub
Run standard GPT-2 fine-tuning:
python fine_tune.py
python fine_tune_lora.py
python fine_tune_qlora.py
| Parameter | Standard | LoRA | QLoRA |
|---|---|---|---|
| Epochs | 5 | 3 | 3 |
| Batch Size | 4 | 8 | 8 |
| Learning Rate | 5e-5 | 3e-4 | 2e-4 |
| Warmup Steps | 50 | 50 | 50 |
| Max Length | 128 | 128 | 128 |
The project generates synthetic training data with 100 samples covering four scenarios:
Each training example follows the format:
Patient's fasting blood glucose over 7 days (mg/dL): [values].
Insulin adjustment recommendation: [INCREASE/DECREASE/NO CHANGE]
The fine-tuned models are tested with three scenarios:
from transformers import GPT2LMHeadModel, GPT2Tokenizer
# Load model
model = GPT2LMHeadModel.from_pretrained("./gpt2_insulin_titration")
tokenizer = GPT2Tokenizer.from_pretrained("./gpt2_insulin_titration")
# Make prediction
fbg_values = "210, 195, 220, 205, 190, 215, 200"
prompt = f"Patient's fasting blood glucose over 7 days (mg/dL): {fbg_values}. Insulin adjustment recommendation:"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=20)
recommendation = tokenizer.decode(outputs[0], skip_special_tokens=True)
Push your model to HuggingFace Hub:
# Login to HuggingFace
huggingface-cli login
# Push model
python push_to_hub.py
Or use the model directly from the Hub:
model = GPT2LMHeadModel.from_pretrained("MohammadReza99/GPT2-optimal_insulin_calculator")
| Method | Training Time | Memory Usage | Model Size | Accuracy |
|---|---|---|---|---|
| Standard | ~10 min | 4-6 GB | 548 MB | Baseline |
| LoRA | ~5 min | 2-3 GB | 3.2 MB (adapter) | ~95% of baseline |
| QLoRA | ~7 min | 1-2 GB | 3.2 MB (adapter) | ~93% of baseline |
This is a demonstration project for educational purposes. The model should NOT be used for actual medical decisions without proper validation and regulatory approval.
This project is for educational and research purposes. Please consult appropriate medical guidelines and regulations before any clinical application.
Contributions are welcome! Please feel free to submit pull requests or open issues for improvements.
For questions or collaboration opportunities, please reach out through the HuggingFace Hub repository: MohammadReza99/GPT2-optimal_insulin_calculator