Skip to content

Latest commit

Β 

History

History
99 lines (71 loc) Β· 3.52 KB

File metadata and controls

99 lines (71 loc) Β· 3.52 KB

LLM Classification Finetuning

A Kaggle competition project for fine-tuning a quantized Qwen 2.5 model with LoRA adapters on a response-ranking classification task. The notebook trains a 3-way classifier to predict whether model_a, model_b, or tie is preferred based on a prompt and two model responses.

πŸš€ What this repo does

  • Loads Kaggle-formatted competition datasets from mounted input paths.
  • Builds a 3-class classification dataset from winner_model_a, winner_model_b, and winner_tie labels.
  • Applies response-swap augmentation to reduce positional bias.
  • Converts prompt/response pairs into instruction-style training samples.
  • Truncates long text using a head-and-tail strategy to preserve context.
  • Fine-tunes Qwen2.5-7B-Instruct in 4-bit mode with bitsandbytes and LoRA.
  • Evaluates validation accuracy and produces a Kaggle submission.csv.

πŸ“ Repository contents

  • llm-classification-finetuning-comp (9).ipynb β€” main Kaggle notebook with end-to-end training and inference.
  • infrencer-notebook.ipynb β€” inference notebook for model evaluation and submission generation.
  • README.md β€” project documentation.

πŸ“Œ Why this approach

This project is designed to work within Kaggle's GPU and offline package constraints while still enabling large-model fine-tuning. By combining 4-bit quantization with LoRA, the notebook keeps memory usage low and training feasible on smaller GPUs.

🧠 Model and training setup

  • Base model: Qwen/Qwen2.5-7B-Instruct
  • Quantization: 4-bit (bitsandbytes, nf4)
  • Fine-tuning: LoRA adapters
  • Label classes: A, B, C
  • Task type: sequence classification

Typical LoRA settings from the notebook:

  • rank: 16
  • alpha: 32
  • dropout: 0.05
  • target modules: q_proj, k_proj, v_proj, o_proj

Training arguments in the notebook include:

  • learning rate: 2e-4
  • epochs: 1
  • train batch size: 4
  • eval batch size: 4
  • gradient accumulation: 4
  • optimizer: paged_adamw_8bit
  • mixed precision: fp16

πŸ”§ Expected inputs

The notebook expects Kaggle input mounts structured like:

/kaggle/input/competitions/llm-classification-finetuning/train.csv
/kaggle/input/competitions/llm-classification-finetuning/test.csv
/kaggle/input/models/qwen-lm/qwen2.5/transformers/7b-instruct/1
/kaggle/input/datasets/azizkarray/my-qwen-2-5-wheels/my_wheels

If your input paths differ, update the path variables in the first notebook cells before running.

πŸ“¦ Dependencies

The notebook installs and uses the following libraries:

  • transformers
  • peft
  • bitsandbytes
  • trl
  • accelerate
  • datasets
  • torch
  • pandas
  • numpy
  • scikit-learn

▢️ How to run

  1. Open llm-classification-finetuning-comp (9).ipynb in Kaggle or a compatible Jupyter environment.
  2. Attach the Kaggle competition dataset and the local model/wheel datasets.
  3. Confirm the dataset and model input paths in the first cells.
  4. Execute the notebook from top to bottom.
  5. Use the inference notebook infrencer-notebook.ipynb for additional evaluation and submission generation.

πŸ“ˆ Outputs

Expected outputs from the notebook include:

  • saved LoRA adapter checkpoint and tokenizer files
  • a generated submission.csv
  • model validation metrics logged in the notebook cells

πŸ’‘ Notes

  • The project is notebook-first and optimized for Kaggle-style execution.
  • The training pipeline is focused on memory-efficient fine-tuning of a large language model.
  • The notebook includes dataset augmentation and prompt construction to improve classification robustness.