UltraFeedback Documentation
repository·main·Indexed 18 days ago
https://github.com/openbmb/ultrafeedbackUltraFeedback 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.
What's inside UltraFeedback
- 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.
UltraRM: Reward Model
mainUltraRM is a reward model initialized by
LLaMA2-13Band 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.
UltraCM: Critique Model
mainUltraCM is a critique model initialized byLLaMA2-13Band trained on UltraFeedback. It is designed for automatic critique generation and performs competitively against ChatGPT on various benchmarks.Principle Sampling for Model Alignment
mainUltraFeedback 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:
- Helpfulness
- Truthfulness
- Honesty
- 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).
Model Sampling and Diversity
mainTo 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
Note on `overall_score` corrections
mainIn the initial version of the dataset, some completions were incorrectly assigned an
overall_scoreof10. This has been rectified:- Completions with fine-grained scores
<= 2have had theiroverall_scoreadjusted to1. - Completions with fine-grained scores
> 4retain theiroverall_scoreof10. - Other completions underwent re-annotation based on original critiques.
Implementation details for this fix can be found in
./src/fix_overall_score_issue.py.- Completions with fine-grained scores
Understand the UltraFeedback dataset format
mainThe 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 aRatingand aRationale. For certain metrics liketruthfulness, it may also include aTypefield.
{ "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..." } } } ] }Get LLM evaluations with `get_eval`
mainThe
get_evalfunction 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., `
Instruction Sampling Statistics
mainThe 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 }Parse LLM annotations with `process()`
mainThe
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 specificaspectbeing evaluated.Supported Aspect Formats:
instruction_followingorhonestyExpects a pattern:Rating: <value>\nRationale: <text>Returns:[{'Rating': '...', 'Rationale': '...'}]truthfulnessorhelpfulnessExpects 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
ValueErrororAttributeError.# 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. """Annotate completions with critiques and scores using `annotate`
mainThe
annotatefunction processes a dataset entry (anexampledictionary) 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
examplemust be a dictionary containing aninstructionkey. - The
examplemust contain acompletionslist, where each item is a dictionary containing:response: The text generated by the model.principle: A string used to determine how to handle thecustom_system_prompt(specifically checking forverbalized_calibration).custom_system_prompt: A string providing additional context for the instruction.
Output Format:
- The function modifies the
examplein-place, adding two keys to each completion dictionary:critique: A string containing the qualitative feedback.overall_score: A numeric score (derived from the LLM'sOverall 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- The
Manage conversation templates with the Conversation class
mainThe
Conversationclass 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 specificSeparatorStyle.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: ASeparatorStyleenum determining how messages are delimited.sepandsep2: 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())