Phi-1 NumPy + Pandas Fine-Tuning (QLoRA)

This repository provides a fine-tuned variant of :contentReference[oaicite:0]{index=0} that improves Python code generation for NumPy and Pandas–based data analysis tasks.

The model addresses a known limitation of the base Phi-1 model, which was trained primarily on Python scripts using a very limited set of standard libraries.


πŸ” Motivation

The original Phi-1 model documentation states that 99.8% of its Python training data only uses:

As a result, the base model may:

  • Hallucinate APIs for external libraries
  • Misuse common NumPy / Pandas functions
  • Struggle with real-world data analysis workflows

This project demonstrates that targeted, low-rank fine-tuning (QLoRA) can significantly mitigate this limitation.


🧠 What This Model Learns

This fine-tuning focuses exclusively on:

  • numpy
  • pandas

Covered Operations

  • CSV loading (read_csv)
  • Column selection and filtering
  • GroupBy aggregations (mean, sum, count)
  • NumPy array operations
  • Pandas + NumPy interoperability (np.where, .to_numpy())

Explicitly NOT Included

  • Visualization libraries (matplotlib, seaborn)
  • Machine learning libraries (sklearn, torch)
  • SQL, file systems, or OS operations

πŸ—οΈ Training Details

  • Base model: microsoft/phi-1
  • Fine-tuning method: QLoRA (4-bit quantization)
  • LoRA rank (r): 16
  • Epochs: 2–3
  • Dataset size: ~1,500 instruction–code pairs
  • Training type: Instruction tuning (code-only responses)
  • Optimizer: paged AdamW (8-bit)

Only LoRA adapter weights were trained; the base model weights remain unchanged.


πŸ“¦ Repository Contents

Depending on the repository variant, this repo contains:

Adapter Repository (Recommended)

  • adapter_model.bin (or .safetensors)
  • adapter_config.json
  • Tokenizer files

Full Model Repository (If merged)

  • Full merged model weights
  • Tokenizer
  • No PEFT dependency required

Usage

Option 1 β€” Load Adapter (Recommended)

from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

base_model = AutoModelForCausalLM.from_pretrained(
    "microsoft/phi-1",
    load_in_4bit=True,
    device_map="auto"
)

model = PeftModel.from_pretrained(
    base_model,
    "iravikr/phi1-numpy-pandas-qlora"
)

tokenizer = AutoTokenizer.from_pretrained(
    "iravikr/phi1-numpy-pandas-qlora"
)
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for iravikr/phi1-numpy-pandas-qlora

Base model

microsoft/phi-1
Finetuned
(3)
this model

Dataset used to train iravikr/phi1-numpy-pandas-qlora