--- title: Human Preferences collection for RLHF type: templates category: LLM Fine-tuning cat: llm-fine-tuning order: 904 is_new: t meta_title: Create Dataset for Human Preferences Collection for RLHF meta_description: Template for creating dataset for human preferences collection for RLHF with Label Studio for your machine learning and data science projects. --- This project will help you to get up your LLM to the ChatGPT quality level through collecting comparison data to establish human preferences for the responses generated by the supervised model. Through ranking multiple responses based on quality, you can train a reward model that effectively captures human preferences. This reward model plays a crucial role in Reinforcement Learning, optimizing the performance of the fine-tuned foundational model. #### Further Reading and Resources - [Gathering Human Feedback Tutorial](https://github.com/HumanSignal/RLHF/blob/master/tutorials/RLHF_with_Custom_Datasets.ipynb) A Jupyter Notebook tutorial that will guide you through the step-by-step process of collecting comparison data, establishing human preferences, and incorporating this feedback into the reward model training. - [RLHF Resources](https://github.com/HumanSignal/RLHF): A collection of links, tutorials and best practices on how collect data and build an end-to-end Reinforcement Learning from Human Feedback (RLHF) system to fine-tune Generative AI models. - [Awesome-Human-in-the-Loop List](https://github.com/HumanSignal/awesome-human-in-the-loop): An awesome list of human in the loop resources and references for retraining models. - [Talk: Improving Machine Learning from Human Feedback](https://youtu.be/nx_vJpux_Sg) : A talk from PyData Berlin on how to improve machine learning from Human Feedback using RLHF. - [Workshop: Getting Started with Reinforcement Learning](https://youtu.be/Oqo8k8SyMX4) : A workshop on how to get started with Reinforcement Learning. - [Guide: Five Large Language Models you can Fine-Tune Today](https://labelstud.io/blog/five-large-language-models-you-can-fine-tune-today/) ## How to collect the dataset The dataset for RLHF consists of two parts: 1. input prompts 2. Alternative generated responses for each prompt. To simplify the task for the human labeler, it is recommended to have 2 responses per prompt to select from. Start with an initial set of prompts and responses, where each item is a JSON object with the following structure: ```json [{ "prompt": "The quick brown fox...", "answer1": "jumps over the lazy dog.", "answer2": "bags few lynx." }, ...] ``` Collect examples either by generating them manually, or use your [baseline model to generate multiple alternative hypotheses](https://huggingface.co/blog/how-to-generate). After your dataset has started to be collected in `dataset.json` file, create a project and upload the dataset to Label Studio. ## Starting your labeling project 1. Create new project in Label Studio 2. Go to `Settings > Labeling Interface > Browse Templates > Generative AI > Human Preference collection for RLHF` 3. Save the project ## Import the dataset Using python SDK you can import the dataset with input prompts into Label Studio. With the `PROJECT_ID` of the project you've just created, run the following code: ```python from label_studio_sdk import Client ls = Client(url='', api_key='') project = ls.get_project(id=PROJECT_ID) project.import_tasks('dataset.json') ``` Then you can start annotating the dataset by creating the responses. ## How to configure the labeling interface The `Human Preference collection for RLHF` template includes the following labeling interface in XML format: ```xml ``` The `