
    h                         S SK r S SKJrJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  \ " S S5      5       rS	\S
\S\4S jrS\S\\\\4      4S jr\	" S5      r\S:X  a  \" \5      r\R+                  5       S    r\" SSS9r\R1                  \\R2                  S9r\R4                  (       a6  \R5                  \R6                  5        \R5                  \R6                  SS9  ggg)    N)	dataclassfield)Optional)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/hh-rlhf-helpful-base"`):
        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/hh-rlhf-helpful-basez2Hugging 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       `/home/james-whalen/.local/lib/python3.13/site-packages/examples/datasets/hh-rlhf-helpful-base.pyr
   r
      sg    
 PQK  .&Bv9wGS  ',(Z['hsm r   r
   str1str2returnc                     / n[        X5       H  u  p4X4:X  a  UR                  U5        M    O   SR                  U5      $ )N )zipappendjoin)r   r    common_charsc1c2s        r   common_startr*   2   s>    Ld/8#	 " 77<  r   examplec                    [        U S   U S   5      nUR                  S5      (       d  US UR                  S5       S-   nU S   [        U5      S  nU S   [        U5      S  nUS [        S5      *  n[        R
                  " SU5      nUSS  n/ n[        S[        U5      S5       H)  nXF   S:X  a  S	OS
nXFS-      nUR                  XxS.5        M+     S
US./n	S
US./n
XYU
S.$ )Nchosenrejectedz

Assistant: z(\n\nAssistant: |\n\nHuman: )   r      z	

Human: user	assistant)rolecontent)promptr-   r.   )r*   endswithrfindlenresplitranger%   )r+   prompt_textchosen_linerejected_lineprompt_linesr5   idxr3   r4   r-   r.   s              r   extract_dialoguerA   >   s$   wx0'*2EFK  122!"HK$5$56G$HIL]] (#C$4$67KJ'K(8(:;M 7%6!7 78K 88<kJL  #LFQL)1-%*m;vQw't89 . #{;<F$?@HHEEr   a@  
---
tags: [trl]
---

# HH-RLHF-Helpful-Base Dataset

## Summary

The HH-RLHF-Helpful-Base dataset is a processed version of [Anthropic's HH-RLHF](https://huggingface.co/datasets/Anthropic/hh-rlhf) dataset, specifically curated to train models using the [TRL library](https://github.com/huggingface/trl) for preference learning and alignment tasks. It contains pairs of text samples, each labeled as either "chosen" or "rejected," based on human preferences regarding the helpfulness of the responses. This dataset enables models to learn human preferences in generating helpful responses, enhancing their ability to assist users effectively.

## 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 user query.
- `"chosen"`: A response deemed helpful by human evaluators.
- `"rejected"`: A response considered less helpful or unhelpful.

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

## Generation script

The script used to generate this dataset can be found [here](https://github.com/huggingface/trl/blob/main/examples/datasets/hh-rlhf-helpful-base.py).
__main__zAnthropic/hh-rlhfzhelpful-base)data_dir)num_procdataset)	repo_type)r9   dataclassesr   r   typingr   datasetsr   huggingface_hubr   transformersr   r
   r   r*   listdictrA   
model_cardr   parserparse_args_into_dataclassesscript_argsrE   mapr   r   r   r   r   r   <module>rS      s   
 (  ! % )   2	!s 	!# 	!# 	!Fc Fd4S>&: FD   
8 zo.F446q9K.HGkk*[5Q5QkRGK//0{22iH  r   