This project implements various fine-tuning techniques to adapt an existing base model for generating responses that effectively incorporate emojis. One of the key techniques used is ORPO (Odds Ratio Preference Optimization).
Odds Ratio Preference Optimization (ORPO) is a fine-tuning approach designed to optimize models using reinforcement learning with preference data. It refines the model to align with human-like preferences by leveraging odds ratio-based preference modeling.
The reward function for ORPO, as per the original paper, is formulated as:
where:
-
$\pi_{\theta}(y | x)$ is the fine-tuned model's probability of generating response ( y ) given input ( x ), -
$\pi_{\text{ref}}(y | x)$ is the reference model's probability, -
$A(y)$ is the advantage function, -
$\beta$ is a scaling parameter controlling preference strength.
The project consists of the following components:
This script uses distilabel to generate a preference dataset. Given a prompt, it generates two responses using different models:
- One model is prompted to use emojis.
- The other model is prompted to avoid emojis.
The scoring function is currently simple:
A more sophisticated scoring mechanism will be implemented later.
This script fine-tunes the model using Parameter-Efficient Fine-Tuning (PEFT), specifically LoRA (Low-Rank Adaptation), implemented via Hugging Face's ORPO framework.
LoRA introduces low-rank trainable matrices to efficiently fine-tune pre-trained models:
where
with:
This significantly reduces the number of trainable parameters while retaining model performance.
This script loads the fine-tuned model and generates sample responses to demonstrate the effectiveness of ORPO training.
To monitor training progress, TensorBoard is used. It can be launched with:
make tensorboard-
Install dependencies using
uv:uv sync
-
Generate preference data:
$(PYTHON) orpo/generate.py -
Train the model:
$(PYTHON) orpo/train.py -
Run inference:
$(PYTHON) orpo/inference.py