We use the lmsys-chat-1m dataset.
Due to its large size (1 million entries), we showcase only the first 500 entries.
You can retrieve the full dataset as described below.
The lmsys-chat-1m dataset requires authentication for download or programmatic access.
Follow these steps to log in using the Hugging Face Command Line Interface (CLI):
- Open your terminal .
- Run the login command:
huggingface-cli login
- Enter your Hugging Face access token when prompted.
If you do not have a token:
- Go to the Hugging Face website and log into your account.
- Navigate to Settings (click your profile picture).
- Click Access Tokens in the sidebar.
- Click + New token.
- Provide a name and select the required role (e.g., 'Read' or 'Write/Read').
- Copy the generated token and paste it into your terminal when prompted by
huggingface-cli login.
After logging in, run DatasetRetrieval.ipynb to obtain the data in separate train and test splits.
To get started with the project, follow these steps:
- Clone the repository:
git clone https://github.com/farhan11166/DSL501-PROJECT.git cd DSL501-PROJECT - Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
- Install dependencies:
pip install -r requirements.txt
After logging in to Hugging Face CLI (as described above) and installing dependencies, run the DatasetRetrieval.ipynb notebook to download and prepare the dataset. This will create the necessary train and test splits.
Alternatively, you can use the prepare_dataset.py script:
python scripts/prepare_dataset.pyTo train the PMPO model, use the train.py script:
python scripts/train.py --config_path configs/default.yamlYou can modify configs/default.yaml to adjust training parameters.
Explore various experimental setups and PMPO configurations using the provided Jupyter notebooks:
PMPO_ALPHA=...GPT_NEO.ipynbPMPO_On_GPT2.ipynbenvironments.ipynbEvaluation.ipynbPreprocessingForPMPO.ipynbPMPO_usingKL_Divergence.ipynb
Note:
For detailed information about the project, please refer to SoP_ML.pdf.
This project implements Preference-based Maximum a Posteriori Optimization (PMPO) for fine-tuning causal language models, primarily for tasks involving human preferences.
-
Data Handling (
pmpo/data.py,Dataset/,scripts/prepare_dataset.py):- The
PreferenceDatasetclass (inpmpo/data.py) is responsible for loading and tokenizing preference data from CSV files. It expects a 'label' column to differentiate between positive and negative examples. - The
Dataset/directory andscripts/prepare_dataset.pyare dedicated to the preparation and organization of these datasets.
- The
-
PMPO Core (
pmpo/trainer.py):- The
PMPOTrainerclass (inpmpo/trainer.py) encapsulates the core PMPO algorithm. - It leverages pre-trained causal language models (e.g., GPT-2) from the Hugging Face
transformerslibrary. - The training objective is designed to balance three key terms: a positive term (to increase the likelihood of preferred responses), a negative term (to decrease the likelihood of dispreferred responses), and a KL divergence term (to prevent the model from drifting too far from a reference model).
- For enhanced efficiency, the trainer incorporates features such as gradient checkpointing and mixed-precision training.
- The
-
Training Workflow (
scripts/train.py, Jupyter Notebooks):- The
scripts/train.pyscript orchestrates the end-to-end training process, including data loading, initialization of the PMPO trainer, and execution of the optimization loop. - Various Jupyter notebooks (e.g.,
PMPO_ALPHA=...GPT_NEO.ipynb,PMPO_On_GPT2.ipynb) are provided for experimental setups, allowing for exploration of different PMPO configurations and model architectures.
- The
-
Configuration (
configs/default.yaml):- The
configs/default.yamlfile is designated for storing configuration parameters pertinent to the training process.
- The
-
Dependencies (
requirements.txt):- The project relies on a set of standard deep learning libraries, including
torch,transformers,datasets,tokenizers,tqdm, andnumpy.
- The project relies on a set of standard deep learning libraries, including