Datasets:
File size: 8,439 Bytes
d360720 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | """HelpSteer3 human preference adapter; no downloading or training side effects.
References (schema inspected through HF first-rows on 2026-09-17):
https://huggingface.co/datasets/nvidia/HelpSteer3/blob/main/README.md#preference
https://arxiv.org/abs/2505.11475
Each preference pair produces ONE ordered seven-bin score distribution. Feedback
produces up to two independent five-bin single-response rubric tasks. Targets are
empirical human vote frequencies, not objective correctness probabilities or
confidence estimates. Up to three votes are sparse evidence of preferences.
Do not also emit a winner task for the same pair and inflate its weight. Never
derive probabilities from overall_preference, an average, or a rationale.
The caller owns fetching, revision verification, deduplication and group splits.
Metadata is audit-only and MUST NOT be included in model inputs.
"""
from collections import Counter
import json
import re
SOURCE = {
"repo": "nvidia/HelpSteer3",
"revision": "f6d145777bcbde96137596340fab89793acd1031",
"license": "cc-by-4.0",
"config": "preference",
"paper": "https://arxiv.org/abs/2505.11475",
"card": "https://huggingface.co/datasets/nvidia/HelpSteer3/blob/"
"f6d145777bcbde96137596340fab89793acd1031/README.md",
}
SCORES = tuple(range(-3, 4))
CANDIDATES = (
"Response 1 is much better than Response 2",
"Response 1 is better than Response 2",
"Response 1 is slightly better than Response 2",
"Response 1 is about the same as Response 2",
"Response 2 is slightly better than Response 1",
"Response 2 is better than Response 1",
"Response 2 is much better than Response 1",
)
INSTRUCTIONS = (
"Evaluate the overall helpfulness of the two responses to the full conversation. "
"Predict the distribution of human preference ratings across the seven ordered "
"categories: -3 strongly favors Response 1, -2 favors Response 1, -1 slightly "
"favors Response 1, 0 means about the same, +1 slightly favors Response 2, "
"+2 favors Response 2, and +3 strongly favors Response 2. "
"These probabilities describe human preferences, not probabilities of objective truth."
)
HELPFULNESS = ("not", "slightly", "partially", "mostly", "perfectly")
_RATING = re.compile(r"\A\s*The response is (not|slightly|partially|mostly|perfectly) helpful\.", re.IGNORECASE)
def _json(value):
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
def adapt(record, config="preference"):
"""Return preference or single-response tasks with valid human vote records.
Requires the canonical JSONL/HF List schema, not a dict-of-lists conversion.
Context is nonempty [{role: str, content: str}, ...]; responses are nonempty
strings. Every individual_preference entry must have an integer score -3..3.
Invalid votes invalidate the whole pair: silently dropping dissenting votes
would change the observed distribution. Labels/feedback are never input text.
group_key includes only the whole prompt conversation in canonical JSON,
with line endings normalized; case, spacing and code indentation are retained.
"""
if config not in ("preference", "feedback"):
raise ValueError("Only human-labeled preference and feedback configs are supported")
if not isinstance(record, dict):
return []
raw_context = record.get("context")
if not isinstance(raw_context, list) or not raw_context:
return []
context = []
for message in raw_context:
if not isinstance(message, dict):
return []
role, content = message.get("role"), message.get("content")
if not isinstance(role, str) or not role.strip() or not isinstance(content, str):
return []
context.append({"role": role, "content": content.replace("\r\n", "\n").replace("\r", "\n")})
if not any(message["content"].strip() for message in context):
return []
responses = [record.get("response1"), record.get("response2")]
if any(not isinstance(response, str) or not response.strip() for response in responses):
return []
if config == "feedback":
return _feedback(record, context, responses)
annotations = record.get("individual_preference")
if not isinstance(annotations, list) or not annotations:
return []
votes = []
for annotation in annotations:
if not isinstance(annotation, dict):
return []
score = annotation.get("score")
if type(score) is not int or score not in SCORES:
return []
votes.append(score)
counts = Counter(votes)
metadata = {
"source": SOURCE["repo"],
"source_config": config,
"source_license": SOURCE["license"],
"source_card": SOURCE["card"],
"source_paper": SOURCE["paper"],
"label_method": "empirical_individual_human_preference_votes",
"target_semantics": "human_preference_frequency_not_objective_truth",
"individual_preference_scores": votes,
"vote_counts": [counts[score] for score in SCORES],
"original_score_values": list(SCORES),
"n_annotations": len(votes),
"domain": record.get("domain"),
"language": record.get("language"),
"overall_preference_audit_only": record.get("overall_preference"),
}
return [{
"state": _json({"context": context, "response1": responses[0], "response2": responses[1]}),
"instructions": INSTRUCTIONS,
"candidates": list(CANDIDATES),
"keys": [str(index) for index in range(len(SCORES))],
"target": [counts[score] / len(votes) for score in SCORES],
"kind": "score",
"group_key": _json(context),
"metadata": metadata,
}]
def _feedback(record, context, responses):
"""Parse only the documented categorical opening, never infer from prose.
Each response has a list of human feedback strings in feedback1/feedback2.
Require at least two raters and ALL openings to parse. If one is ambiguous,
exclude the whole response rather than biasing its distribution by dropping
that rater. Builder can count rejected responses as 2 - len(adapt(record)).
"""
tasks = []
for number, response in enumerate(responses, start=1):
annotations = record.get(f"feedback{number}")
if not isinstance(annotations, list) or len(annotations) < 2:
continue
votes = []
for annotation in annotations:
match = _RATING.match(annotation) if isinstance(annotation, str) else None
if match:
votes.append(HELPFULNESS.index(match.group(1).lower()))
if len(votes) != len(annotations):
continue
counts = Counter(votes)
tasks.append({
"state": _json({"context": context, "response": response}),
"instructions": "Rate the overall helpfulness of the response to the full conversation. "
"Predict the human rating distribution on this ordered rubric: 0 not helpful, "
"1 slightly helpful, 2 partially helpful, 3 mostly helpful, 4 perfectly helpful. "
"These probabilities describe human judgments, not objective truth.",
"candidates": [f"The response is {level} helpful" for level in HELPFULNESS],
"keys": [str(score) for score in range(5)],
"target": [counts[score] / len(votes) for score in range(5)],
"kind": "score",
"group_key": _json(context),
"metadata": {
"source": SOURCE["repo"], "source_config": "feedback",
"source_license": SOURCE["license"], "source_card": SOURCE["card"],
"source_paper": "https://arxiv.org/abs/2503.04378",
"label_method": "empirical_human_feedback_anchored_rubric_votes",
"target_semantics": "human_helpfulness_frequency_not_objective_truth",
"domain": record.get("domain"), "language": record.get("language"),
"source_response": f"response{number}",
"individual_helpfulness_scores": votes,
"vote_counts": [counts[score] for score in range(5)],
"n_annotations": len(votes), "excluded_annotation_count": 0,
"annotation_parse_policy": "all_raters_parse_and_at_least_two",
},
})
return tasks
|