Annotation-Efficient Preference Optimization
This repository implements the Annotation-Efficient Preference Optimization (AEPO) algorithm.
The code is tested on Ubuntu 20.04 using Python 3.9 and CUDA 11.0 (Docker image nvidia/cuda:11.0.3-cudnn8-devel-ubuntu20.04).
Install
You can install aepo via pip.
pip install aepo
Source install is available too. Clone this repository and run pip install ..
git clone git@github.com:CyberAgentAILab/annotation-efficient-po.git
cd annotation-efficient-po
pip install .
Usage
The command line interface is available. The input dataset can be csv file or a dataset uploaded to Huggingface Hub. The dataset should have a column named prompt or instruction. aepo recognize it as the user prompt given to the system and the rest of the columns to be the responses generated by the system.
I prepared an example dataset in dataset/alpaca_samples.csv.
The csv file includes 128 responses generated by HuggingFaceH4/mistral-7b-sft-beta for each instruction of the alpaca_human_preference split of tatsu-lab/alpaca_farm.
You can try aepo using this dataset with the following command:
aepo dataset/alpaca_samples.csv --num_responses 8 --num_annotations 2 --num_instructions 10
--num_responses is the number of input responses you use. The dataset has to have responses larger than or equal to --num_responses. --num_annotations is the number of responses after the subsampling process. It is also the number of times the reward model is queried per instruction.
Example: Running AEPO
You can generate a pair of responses for each instruction using aepo using the following command.
aepo dataset/alpaca_samples.csv --num_responses 8 --num_annotations 2 --num_instructions 10
To subsample four responses for e.g., LiPO, set --num_annotations to four.
aepo dataset/alpaca_samples.csv --num_responses 8 --num_annotations 4 --num_instructions 10
Example: Running West-of-N over 8 samples
West-of-N is a strategy to pick the Best-of-N as the chosen response, and Worst-of-N as a rejected response. It is shown to be effective for DPO and reward modeling.
You can run West-of-N using this package by setting --num_annotations == --num_responses.
aepo dataset/alpaca_samples.csv --num_responses 8 --num_annotations 8 --num_instructions 10
This command will generate a dataset with 8 responses, ranked by their rewards. If you only need the best and worst of the N samples, then use --west_of_n option.
aepo dataset/alpaca_samples.csv --num_responses 8 --num_annotations 8 --num_instructions 10 --west_of_n
This will pick the best and worst responses as the chosen and rejected. The rest of the responses are discarded. It would be useful to construct a pairwise preference dataset.
Reference
Bibtex:
@misc{jinnai2024annotationefficient,
title={Annotation-Efficient Preference Optimization for Language Model Alignment},
author={Yuu Jinnai and Ukyo Honda},
year={2024},
eprint={2405.13541},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Contact
For any questions, feel free to raise an issue or contact me at jinnai_yu@cyberagent.co.jp.
Acknowledgements
AlpacaFarm dataset is licensed under Attribution-NonCommercial 4.0 International.
Metadata
Release files for aepo 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aepo-0.1.6.tar.gz | 27.4 kB | Without provenance | Details for aepo-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aepo-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for aepo-0.1.6-py3-none-any.whl |
Total release size: 45.8 kB
Release files / aepo-0.1.6.tar.gz
| Download URL | aepo-0.1.6.tar.gz |
|---|---|
| Size | 27.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ae19a214199a71d567de6a79ee89caad8276c30b37f0f2e7da9c0438ad431d5e
|
|
BLAKE2b-256 checksum How to use checksums |
3cd0148aaa2063cdaa82ca253226ddb23626cd6b7b1bc8b6952f288bf1ecb71f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.6 Linux/5.15.146.1-microsoft-standard-WSL2
|
Release files / aepo-0.1.6-py3-none-any.whl
| Download URL | aepo-0.1.6-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27a365ed0df905d83af0b59d0e0a4082755c6c82fb6d2df21600fc3905bd1e17
|
|
BLAKE2b-256 checksum How to use checksums |
39f926388e90cb0e4864da940fe1d9b705706d4b904f48b96fb856e2422644ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.6 Linux/5.15.146.1-microsoft-standard-WSL2
|
Security for aepo 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.