Downloads · 30 days
0
rohiiit/lora-tuning-text
lora-tuning-text is a machine learning model from rohiiit. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Fine-tunes gpt2 on the SQuAD dataset using LoRA (Low-Rank Adaptation) via the PEFT library. Trained on MacBook Pro M2 using the MPS backend.
Downloads · 30 days
0
Access
Public
Updated Mar 24, 2026
Repo size
2.4 MB
Likes
0
Public
Click a slice to open those files.
.json7.1 MB · 75%
From the Hugging Face model README
Fine-tunes gpt2 on the SQuAD dataset using LoRA (Low-Rank Adaptation) via the PEFT library. Trained on MacBook Pro M2 using the MPS backend.
Stock GPT-2 was trained for text continuation, not Q&A. When asked a direct question it wanders and generates off-topic text. LoRA fine-tuning on SQuAD teaches it the Question → Answer response shape.
| Property | Value |
|---|---|
| Dataset | rajpurkar/squad |
| Task | Extractive Q&A |
| Train subset | 8,000 examples |
| Eval subset | 500 examples |
| Format | Question: <q>\nAnswer: <a><eos> |
LoRA injects small trainable rank-decomposition matrices into the attention layers, keeping the base model frozen.
c_attn), so LoRA targets that single module| Hyperparameter | Value |
|---|---|
| Base model | gpt2 |
LoRA rank (r) | 8 |
| LoRA alpha | 32 |
| LoRA dropout | 0.05 |
| Target modules | c_attn |
| Epochs | 3 |
| Batch size | 8 (effective 16 with grad accum) |
| Learning rate | 3e-4 |
| Max sequence length | 256 |
lora-tuning-text/
├── lora_train.py # Training script
├── test_base_model.py # Inference with base GPT-2 (no fine-tuning)
├── test_tuned_model.py # Inference with the LoRA-tuned adapter
├── requirements.txt
└── lora-gpt2-squad/ # Output directory (auto-generated)
└── final/ # Saved LoRA adapter
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Step 1 — See how bad base GPT-2 is:
python test_base_model.py
Step 2 — Fine-tune with LoRA:
python lora_train.py
Step 3 — Compare with the tuned model:
python test_tuned_model.py
./lora-gpt2-squad/final/We partially achieved the result. The LoRA-tuned GPT-2 did learn the Question → Answer response shape and stopped wandering as much as the base model. However, it still occasionally hallucinated or gave incomplete answers — full factual accuracy was not consistently reached.