
    h"                     H   S SK JrJr  S SKJr  S SKJrJr  S SKJ	r	  S SK
Jr  \ " S S5      5       rS r\	" S	5      r\S
:X  a  \" \5      r\R#                  5       S    r\" SSS9r\R)                  \\R*                  \R,                  SS9r\R                  r\R0                  " \R2                  " SS95      \S'   \R5                  \5      r\R7                  SSS9r\R8                  (       a6  \R9                  \R:                  5        \R9                  \R:                  SS9  ggg)    )	dataclassfield)Optional)featuresload_dataset)	ModelCard)HfArgumentParserc                   t    \ rS rSr% Sr\" SSS0S9r\\S'   \" SSS	0S9r	\
\S
'   \" SSS0S9r\\   \S'   Srg)ScriptArguments   a  
Arguments for the script.

Args:
    push_to_hub (`bool`, *optional*, defaults to `False`):
        Whether to push the dataset to the Hugging Face Hub.
    repo_id (`str`, *optional*, defaults to `"trl-lib/rlaif-v"`):
        Hugging Face repository ID to push the dataset to.
    dataset_num_proc (`int` or `None`, *optional*, defaults to `None`):
        Number of workers to use for dataset processing.
Fhelpz4Whether to push the dataset to the Hugging Face Hub.)defaultmetadatapush_to_hubztrl-lib/rlaif-vz2Hugging Face repository ID to push the dataset to.repo_idNz0Number of workers to use for dataset processing.dataset_num_proc )__name__
__module____qualname____firstlineno____doc__r   r   bool__annotations__r   strr   r   int__static_attributes__r       S/home/james-whalen/.local/lib/python3.13/site-packages/examples/datasets/rlaif-v.pyr   r      si    
 PQK  !NOGS  ',LM'hsm r   r   c                 h    SSS0SU S   S./S./nSSU S	   S./S./nSSU S
   S./S./nXS   /X#S.$ )z
Convert prompt from "xxx" to [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "xxx"}]}]
and chosen and rejected from "xxx" to [{"role": "assistant", "content": [{"type": "text", "text": "xxx"}]}].
Images are wrapped into a list.
usertypeimagetextquestion)r"   r$   )rolecontent	assistantchosenrejected)promptimagesr)   r*   r   )exampler+   r)   r*   s       r   to_conversationalr.   3   sp     FG+<vW^_iWj>k*lmnF"QYIZ0[/\]^F$67S]K^2_1`abH)9(:fccr   a>  
---
tags: [trl]
---

# RLAIF-V Dataset

## Summary

The RLAIF-V dataset is a processed version of the [openbmb/RLAIF-V-Dataset](https://huggingface.co/datasets/openbmb/RLAIF-V-Dataset#dataset-card-for-rlaif-v-dataset), specifically curated to train vision-language models using the [TRL library](https://github.com/huggingface/trl) for preference learning tasks. It contains 83,132 high-quality comparison pairs, each comprising an image and two textual descriptions: one preferred and one rejected. This dataset enables models to learn human preferences in visual contexts, enhancing their ability to generate and evaluate image captions.

## Data Structure

- **Format**: [Conversational](https://huggingface.co/docs/trl/main/dataset_formats#conversational)
- **Type**: [Preference](https://huggingface.co/docs/trl/main/dataset_formats#preference)

Columns:
- `"prompt"`: The task related to the image.
- `"images"`: The image.
- `"chosen"`: The preferred answer.
- `"rejected"`: An alternative answer that was not preferred.

This structure allows models to learn to prefer the _chosen_ response over the _rejected_ one, thereby aligning with human preferences in visual tasks.

## Generation script

The script used to generate this dataset can be found [here](https://github.com/huggingface/trl/blob/main/examples/datasets/rlaif-v.py).
__main__zopenbmb/RLAIF-V-Datasettrain)split   )num_procremove_columnswriter_batch_sizeT)decoder,   g{Gz?)	test_sizer5   dataset)	repo_typeN)dataclassesr   r   typingr   datasetsr   r   huggingface_hubr   transformersr	   r   r.   
model_cardr   parserparse_args_into_dataclassesscript_argsr8   mapr   column_namesfSequenceImagecasttrain_test_splitr   r   r   r   r   <module>rJ      s1   )  + % )   6	d   
: zo.F446q9K4GDGkk--++	  G 	A##HNN$$?@AhKll1oG&&&MGK//0{22iH ' r   