UltraFeedback Documentation

repository·main·Indexed 18 days ago

https://github.com/openbmb/ultrafeedback

UltraFeedback provides a large-scale, fine-grained preference dataset with approximately 64k prompts and 256k responses, alongside SOTA models UltraRM (reward model) and UltraCM (critique model). The dataset features high-density feedback across four dimensions: instruction-following, truthfulness, honesty, and helpfulness. It includes tools for generating comparison data, managing conversation templates via the Conversation class, and annotating completions with critiques and scores using LLM-based evaluation.

Tokens
5.1K
Snippets
11
Records
18
Agent score
63%

What's inside UltraFeedback

  1. Overview of UltraFeedback

    main
    UltraFeedback is a large-scale, fine-grained, and diverse preference dataset designed for training powerful reward models and critic models. It contains approximately 64k prompts and 256k responses. The dataset provides high-density feedback, including both numerical scores and textual critiques across four key dimensions: instruction-following, truthfulness, honesty, and helpfulness.
  2. UltraRM: Reward Model

    main

    UltraRM is a reward model initialized by LLaMA2-13B and trained on UltraFeedback. Two versions are available:

    • UltraRM-UF: Fine-tuned exclusively on UltraFeedback.
    • UltraRM: Fine-tuned on a mixture of UltraFeedback and an equal-size sample from Anthropic HH-RLHF, Stanford SHP, and Summarization datasets.
  3. Principle Sampling for Model Alignment

    main

    UltraFeedback employs 'Principle Sampling' to align model behaviors. For each instruction, 4 models are sampled, and a specific principle is added to the system prompt to guide the model's response style. The four principles are:

    1. Helpfulness
    2. Truthfulness
    3. Honesty
    4. Verbalized Calibration

    The distribution of these principles varies by dataset (e.g., Evol-Instruct is 100% Helpful, while ShareGPT is 60% Helpful, 20% Truthful, 18% Honesty, and 2% Verbalized Calibration).

  4. Model Sampling and Diversity

    main

    To prevent reward models from overfitting to specific text styles or spurious correlations, UltraFeedback uses a pool of 17 diverse models across different architectures and sizes, including:

    • Commercial Models: GPT-4, GPT-3.5 Turbo, Bard
    • LLaMA family: LLaMA-2 (7B, 13B, 70B), UltraLM (13B, 65B), WizardLM (7B, 13B, 70B), Vicuna-33B, Alpaca-7B
    • Non-LLaMA series: Falcon-40B-instruct, MPT-30B-chat, StarChat-Beta, Pythia-12B
  5. Note on `overall_score` corrections

    main

    In the initial version of the dataset, some completions were incorrectly assigned an overall_score of 10. This has been rectified:

    • Completions with fine-grained scores <= 2 have had their overall_score adjusted to 1.
    • Completions with fine-grained scores > 4 retain their overall_score of 10.
    • Other completions underwent re-annotation based on original critiques.

    Implementation details for this fix can be found in ./src/fix_overall_score_issue.py.

  6. Understand the UltraFeedback dataset format

    main

    The UltraFeedback dataset uses a JSON structure where each entry contains a single instruction and multiple model completions. This format is designed to support preference learning and multi-dimensional evaluation (e.g., helpfulness, honesty, truthfulness).

    Key components of the schema:

    • source: The origin dataset (e.g., sharegpt).
    • instruction: The user prompt.
    • models: A list of model names that generated completions for this instruction.
    • completions: An array of objects, one for each model, containing:
      • model: The name of the model.
      • principle: The alignment principle used (e.g., helpfulness).
      • custom_system_prompt: The system prompt used to align the model behavior.
      • response: The actual text generated by the model.
      • annotations: A dictionary of multi-dimensional ratings (e.g., instruction_following, honesty, truthfulness, helpfulness). Each annotation includes a Rating and a Rationale. For certain metrics like truthfulness, it may also include a Type field.
    {
        "source": "sharegpt",
        "instruction": "I am going to cairo in June of this year...",
        "models": [
            "falcon-40b-instruct",
            "gpt-4",
            "starchat",
            "wizardlm-7b"
        ],
        "correct_answers": ["None"],
        "incorrect_answers": ["None"],
        "completions": [
            {
                "model": "falcon-40b-instruct",
                "principle": "helpfulness",
                "custom_system_prompt": "As an AI assistant...",
                "response": "Cairo is a city that has something for everyone...",
                "annotations": {
                    "instruction_following": {
                        "Rating": "2",
                        "Rationale": "The text only partially addresses the task goal..."
                    },
                    "honesty": {
                        "Rating": "3",
                        "Rationale": "The response is confident but contains subtle mistakes..."
                    },
                    "truthfulness": {
                        "Type": ["1", "2"],
                        "Rationale": "The text suggests whitewater rafting on the Nile...",
                        "Rating": "3",
                        "Rationale For Rating": "The text provides some truthful information..."
                    },
                    "helpfulness": {
                        "Type": ["1", "2"],
                        "Rationale": "The response is clear and relevant...",
                        "Rating": "3",
                        "Rationale For Rating": "The text is correct and provides useful information..."
                    }
                }
            }
        ]
    }
  7. Get LLM evaluations with `get_eval`

    main

    The get_eval function is a wrapper for OpenAI ChatCompletion calls designed to retrieve text responses from a model with built-in retry logic. It attempts to call the API up to 10 times before raising an exception.

    Parameters:

    • model (str): The model identifier (e.g., `
  8. Instruction Sampling Statistics

    main

    The dataset's 63,967 instructions are sampled from six high-quality sources using various strategies (random, stratified, or full inclusion). The distribution is as follows:

    {
        "evol_instruct": 10000, 
        "false_qa": 2339,
        "flan": 20939, 
        "sharegpt": 19949, 
        "truthful_qa": 811,
        "ultrachat": 9929 
    }
  9. Parse LLM annotations with `process()`

    main

    The process(responses, aspect) function parses the raw string output from the LLM evaluator into structured JSON-like dictionaries. It uses regex patterns to extract ratings and rationales based on the specific aspect being evaluated.

    Supported Aspect Formats:

    1. instruction_following or honesty Expects a pattern: Rating: <value>\nRationale: <text> Returns: [{'Rating': '...', 'Rationale': '...'}]

    2. truthfulness or helpfulness Expects a pattern: Type: <value>\nRationale: <text>\nRating: <value>\nRationale For Rating: <text> Returns: [{'Type': '...', 'Rationale': '...', 'Rating': '...', 'Rationale For Rating': '...'}]

    Error Handling: If the LLM output does not strictly follow the expected regex pattern, the function raises ValueError or AttributeError.

    # Example of what the process function expects as input 'responses'
    # For 'instruction_following':
    responses = """
    Rating: 5
    Rationale: The model followed all constraints perfectly.
    """
    
    # For 'truthfulness':
    responses = """
    Type: 1
    Rationale: The model provided incorrect info.
    Rating: 2
    Rationale For Rating: The response was partially true but misleading.
    """
  10. Annotate completions with critiques and scores using `annotate`

    main

    The annotate function processes a dataset entry (an example dictionary) to generate constructive feedback and an overall quality score for each completion within that entry. It uses an LLM (typically GPT-4) to act as a teacher, evaluating the response based on helpfulness, truthfulness, honesty, and instruction following.

    Input Format Requirements:

    • The example must be a dictionary containing an instruction key.
    • The example must contain a completions list, where each item is a dictionary containing:
      • response: The text generated by the model.
      • principle: A string used to determine how to handle the custom_system_prompt (specifically checking for verbalized_calibration).
      • custom_system_prompt: A string providing additional context for the instruction.

    Output Format:

    • The function modifies the example in-place, adding two keys to each completion dictionary:
      • critique: A string containing the qualitative feedback.
      • overall_score: A numeric score (derived from the LLM's Overall Score: [1-10] output).

    Prompting Logic: The feedback is generated using a template that expects the following structure in the LLM response:

    ### Feedback
    [Your feedback]
    Overall Score: [1-10]
    # Example structure of an input 'example' dictionary
    example = {
        "instruction": "Explain quantum physics.",
        "completions": [
            {
                "response": "Quantum physics is...",
                "principle": "standard",
                "custom_system_prompt": "Be concise."
            }
        ]
    }
    
    # After calling annotate(example):
    # example["completions"][0]["critique"] = "..."
    # example["completions"][0]["overall_score"] = 8.0
  11. Manage conversation templates with the Conversation class

    main

    The Conversation class is used to manage prompt templates and maintain conversation history for various LLM architectures. It handles the formatting of system prompts, roles, and messages into a single string suitable for model generation based on a specific SeparatorStyle.

    Key attributes:

    • name: The name of the template.
    • system: The system prompt.
    • roles: A list of strings representing the roles (e.g., ['USER', 'ASSISTANT']).
    • messages: A list of [role, message] pairs.
    • sep_style: A SeparatorStyle enum determining how messages are delimited.
    • sep and sep2: Primary and secondary separators.
    • stop_str: A string used to stop generation.
    • stop_token_ids: A list of integer token IDs used to stop generation.

    Common methods:

    • get_prompt(): Returns the formatted prompt string.
    • append_message(role, message): Adds a new message to the history.
    • update_last_message(message): Updates the last message (typically used to fill in the assistant's response after generation).
    • to_openai_api_messages(): Converts the history to the OpenAI chat completion format.
    • to_gradio_chatbot(): Converts the history to Gradio's chatbot format.
    from src.comparison_data_generation.fastchat import conv_vicuna_v1_1
    
    conv = conv_vicuna_v1_1.copy()
    conv.append_message(conv.roles[0], "Hello!")
    conv.append_message(conv.roles[1], "Hi!")
    conv.append_message(conv.roles[0], "How are you?")
    
    # The last message is often None before generation to act as a placeholder
    conv.append_message(conv.roles[1], None)
    
    print(conv.get_prompt())