Spaces:
Running
Running
File size: 13,453 Bytes
da8db3e | 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | import { describe, expect, it } from "vitest"
// Executable spec for `notes/transformations/09-metric-display-name-expansion.md`.
//
// Replicates two TS transformations verbatim:
// - GENERIC_EVALUATION_NAMES + getEvaluationDisplayName + getBenchmarkName
// from lib/eval-processing.ts:27-86
// - prefersBenchmarkName (inline) from lib/model-data.ts:459-470
// ---------------------------------------------------------------------------
// Replicas
// ---------------------------------------------------------------------------
const GENERIC_EVALUATION_NAMES = new Set([
"score",
"accuracy",
"mean win rate",
"exact match",
"f1",
"pass@1",
])
type SourceObj = { dataset_name?: string; [k: string]: unknown }
type EvalLike = {
benchmark?: string
evaluation_id?: string
source_data?: SourceObj | string[] | undefined
}
type ResultLike = {
evaluation_name: string
source_data?: SourceObj | string[] | undefined
}
function getBenchmarkName(evaluation: EvalLike, result?: ResultLike): string {
const resultSource = result?.source_data
if (resultSource && !Array.isArray(resultSource) && resultSource.dataset_name) {
return resultSource.dataset_name
}
if (evaluation.benchmark) return evaluation.benchmark
if (
evaluation.source_data &&
!Array.isArray(evaluation.source_data) &&
evaluation.source_data.dataset_name
) {
return evaluation.source_data.dataset_name
}
return result?.evaluation_name ?? evaluation.evaluation_id ?? ""
}
function getEvaluationDisplayName(evaluation: EvalLike, result: ResultLike): string {
const benchmarkName = getBenchmarkName(evaluation, result)
const metricName = result.evaluation_name.trim()
if (metricName === benchmarkName) return metricName
if (GENERIC_EVALUATION_NAMES.has(metricName.toLowerCase())) {
return `${benchmarkName} - ${metricName}`
}
return metricName
}
type EvalListEntry = {
evaluation_name?: string
display_name?: string
benchmark_leaf_name?: string
eval_summary_id?: string
benchmark_parent_name?: string
benchmark?: string
}
// Replica that returns the entry's final `evaluation_name` after the
// prefersBenchmarkName decision. We pass in the resolved `benchmarkDisplayName`
// directly to keep the test independent of getBenchmarkDisplayName (which is a
// separate transformation, spec'd elsewhere).
function applyPrefersBenchmarkName(
entry: EvalListEntry,
benchmarkDisplayName: string,
): { rawDisplayName: string; prefersBenchmarkName: boolean; output: string } {
const rawDisplayName =
entry.evaluation_name ||
entry.display_name ||
entry.benchmark_leaf_name ||
entry.eval_summary_id ||
""
const normalizedDisplayName = rawDisplayName.trim().toLowerCase()
const prefersBenchmarkName =
Boolean(benchmarkDisplayName) &&
(normalizedDisplayName.startsWith("accuracy on ") ||
normalizedDisplayName.startsWith("score on ") ||
normalizedDisplayName.includes("for scorer") ||
normalizedDisplayName.includes("model_graded"))
return {
rawDisplayName,
prefersBenchmarkName,
output: prefersBenchmarkName ? benchmarkDisplayName : rawDisplayName,
}
}
// ---------------------------------------------------------------------------
// Group A β getEvaluationDisplayName: generic name expansion
// ---------------------------------------------------------------------------
describe("Group A β getEvaluationDisplayName: generic name expansion", () => {
const cases = [
{ benchmark: "MMLU", metric: "Accuracy", expected: "MMLU - Accuracy" },
{ benchmark: "GSM8K", metric: "accuracy", expected: "GSM8K - accuracy" },
{ benchmark: "MATH", metric: "EXACT MATCH", expected: "MATH - EXACT MATCH" },
{ benchmark: "RewardBench", metric: "Mean Win Rate", expected: "RewardBench - Mean Win Rate" },
{ benchmark: "HumanEval", metric: "pass@1", expected: "HumanEval - pass@1" },
{ benchmark: "SuperGLUE", metric: "f1", expected: "SuperGLUE - f1" },
{ benchmark: "OpenBookQA", metric: "Score", expected: "OpenBookQA - Score" },
]
it.each(cases)("benchmark='$benchmark' metric='$metric' β '$expected'", ({ benchmark, metric, expected }) => {
const evaluation: EvalLike = { benchmark }
const result: ResultLike = { evaluation_name: metric }
expect(getEvaluationDisplayName(evaluation, result)).toBe(expected)
})
})
// ---------------------------------------------------------------------------
// Group B β getEvaluationDisplayName: passthrough (non-generic)
// ---------------------------------------------------------------------------
describe("Group B β getEvaluationDisplayName: passthrough for non-generic metric names", () => {
const cases = [
{
desc: "metricName === benchmarkName β return metric (early return; expansion never considered)",
benchmark: "MMLU",
metric: "MMLU",
expected: "MMLU",
},
{ desc: "non-generic metric β passthrough", benchmark: "MMLU", metric: "BLEU", expected: "BLEU" },
{
desc: "non-generic distinct from benchmark β passthrough",
benchmark: "RewardBench",
metric: "Chat Hard",
expected: "Chat Hard",
},
{
desc: "substring of generic but not equal β passthrough",
benchmark: "MMLU",
metric: "accuracy_strict",
expected: "accuracy_strict",
},
{
desc: "trailing whitespace on metric is .trim()'d before set lookup β expansion fires",
benchmark: "MMLU",
metric: "Accuracy ",
expected: "MMLU - Accuracy",
},
{
desc: "leading + trailing whitespace trimmed",
benchmark: "MMLU",
metric: " accuracy ",
expected: "MMLU - accuracy",
},
]
it.each(cases)("$desc", ({ benchmark, metric, expected }) => {
const evaluation: EvalLike = { benchmark }
const result: ResultLike = { evaluation_name: metric }
expect(getEvaluationDisplayName(evaluation, result)).toBe(expected)
})
})
// ---------------------------------------------------------------------------
// Group C β getEvaluationDisplayName: getBenchmarkName precedence chain
// ---------------------------------------------------------------------------
describe("Group C β getBenchmarkName precedence chain (5 steps)", () => {
it("step 1: result.source_data.dataset_name wins over evaluation.benchmark", () => {
const evaluation: EvalLike = { benchmark: "reward-bench" }
const result: ResultLike = {
evaluation_name: "Score",
source_data: { dataset_name: "RewardBench" },
}
expect(getBenchmarkName(evaluation, result)).toBe("RewardBench")
expect(getEvaluationDisplayName(evaluation, result)).toBe("RewardBench - Score")
})
it("array source_data is skipped β falls to evaluation.benchmark", () => {
const evaluation: EvalLike = { benchmark: "reward-bench" }
const result: ResultLike = {
evaluation_name: "Chat Hard",
source_data: ["url1", "url2"],
}
expect(getBenchmarkName(evaluation, result)).toBe("reward-bench")
})
it("step 2: evaluation.benchmark when result.source_data missing", () => {
const evaluation: EvalLike = { benchmark: "reward-bench" }
const result: ResultLike = { evaluation_name: "Foo" }
expect(getBenchmarkName(evaluation, result)).toBe("reward-bench")
})
it("step 3: evaluation.source_data.dataset_name when benchmark is empty string (falsy)", () => {
const evaluation: EvalLike = { benchmark: "", source_data: { dataset_name: "MMLU" } }
const result: ResultLike = { evaluation_name: "Foo" }
expect(getBenchmarkName(evaluation, result)).toBe("MMLU")
})
it("step 4: result.evaluation_name when nothing else available", () => {
const evaluation: EvalLike = {}
const result: ResultLike = { evaluation_name: "Foo" }
expect(getBenchmarkName(evaluation, result)).toBe("Foo")
})
it("step 5: evaluation.evaluation_id final fallback (when no result)", () => {
const evaluation: EvalLike = { evaluation_id: "id-123" }
expect(getBenchmarkName(evaluation, undefined)).toBe("id-123")
})
})
// ---------------------------------------------------------------------------
// Group D β prefersBenchmarkName: heuristic matches
// ---------------------------------------------------------------------------
describe("Group D β prefersBenchmarkName: heuristic matches", () => {
const benchmarkDisplayName = "MMLU"
const cases = [
{ evaluation_name: "accuracy on subset_humanities", reason: "startsWith('accuracy on ')" },
{ evaluation_name: "Accuracy On SubsetHumanities", reason: "lowercased before startsWith" },
{ evaluation_name: "score on test_set", reason: "startsWith('score on ')" },
{ evaluation_name: "xyz for scorer judge_v2", reason: "includes('for scorer') (any position)" },
{ evaluation_name: "for scorer xyz at start", reason: "includes('for scorer') matches at start" },
{ evaluation_name: "something model_graded thing", reason: "includes('model_graded')" },
{ evaluation_name: "model_graded", reason: "substring match works on whole string" },
]
it.each(cases)("'$evaluation_name' β 'MMLU' ($reason)", ({ evaluation_name }) => {
const result = applyPrefersBenchmarkName({ evaluation_name }, benchmarkDisplayName)
expect(result.prefersBenchmarkName).toBe(true)
expect(result.output).toBe("MMLU")
})
})
// ---------------------------------------------------------------------------
// Group E β prefersBenchmarkName: passthrough (non-matching)
// ---------------------------------------------------------------------------
describe("Group E β prefersBenchmarkName: passthrough for non-matching display names", () => {
const benchmarkDisplayName = "MMLU"
const cases = [
{ evaluation_name: "MMLU - Accuracy", reason: "no token matches" },
{ evaluation_name: "Accuracy", reason: "bare 'accuracy' fails startsWith('accuracy on ')" },
{
evaluation_name: "accuracy onset",
reason: "'accuracy on ' (trailing space) does not match 'accuracy onset' (no space at pos 11)",
},
{
evaluation_name: "score onyx",
reason: "'score on ' (trailing space) does not match 'score onyx'",
},
{
evaluation_name: "Model Graded Eval",
reason: "model_graded uses underscore; 'model graded' (space) lowercased does not contain 'model_graded'",
},
{
evaluation_name: "accuracy_for_scorer",
reason: "'for scorer' uses space; 'for_scorer' does not match",
},
{
evaluation_name: "Scorer based eval",
reason: "must contain literal 'for scorer', not just 'scorer'",
},
{ evaluation_name: "BBH", reason: "none of the four conditions match" },
]
it.each(cases)("'$evaluation_name' passes through unchanged ($reason)", ({ evaluation_name }) => {
const result = applyPrefersBenchmarkName({ evaluation_name }, benchmarkDisplayName)
expect(result.prefersBenchmarkName).toBe(false)
expect(result.output).toBe(evaluation_name)
})
})
// ---------------------------------------------------------------------------
// Group F β prefersBenchmarkName: empty benchmarkDisplayName short-circuits
// ---------------------------------------------------------------------------
describe("Group F β prefersBenchmarkName: empty benchmarkDisplayName disables the rule", () => {
it("even with a matching pattern, empty benchmarkDisplayName β return raw", () => {
const entry: EvalListEntry = { evaluation_name: "accuracy on x" }
const result = applyPrefersBenchmarkName(entry, "")
expect(result.prefersBenchmarkName).toBe(false)
expect(result.output).toBe("accuracy on x")
})
})
// ---------------------------------------------------------------------------
// Group G β prefersBenchmarkName: rawDisplayName precedence
// ---------------------------------------------------------------------------
describe("Group G β rawDisplayName precedence chain (4 steps)", () => {
const benchmarkDisplayName = "MMLU"
it("step 1: evaluation_name wins", () => {
const entry: EvalListEntry = {
evaluation_name: "score on x",
display_name: "fallback_display",
benchmark_leaf_name: "leaf",
eval_summary_id: "id_xyz",
}
const result = applyPrefersBenchmarkName(entry, benchmarkDisplayName)
expect(result.rawDisplayName).toBe("score on x")
})
it("step 2: empty evaluation_name (falsy) β display_name", () => {
const entry: EvalListEntry = {
evaluation_name: "",
display_name: "MMLU display",
benchmark_leaf_name: "leaf",
eval_summary_id: "id_xyz",
}
const result = applyPrefersBenchmarkName(entry, benchmarkDisplayName)
expect(result.rawDisplayName).toBe("MMLU display")
})
it("step 3: benchmark_leaf_name when evaluation_name and display_name both empty", () => {
const entry: EvalListEntry = {
evaluation_name: "",
display_name: "",
benchmark_leaf_name: "leaf_name",
eval_summary_id: "id_xyz",
}
const result = applyPrefersBenchmarkName(entry, benchmarkDisplayName)
expect(result.rawDisplayName).toBe("leaf_name")
})
it("step 4: eval_summary_id final fallback", () => {
const entry: EvalListEntry = {
evaluation_name: "",
display_name: "",
benchmark_leaf_name: "",
eval_summary_id: "id_xyz",
}
const result = applyPrefersBenchmarkName(entry, benchmarkDisplayName)
expect(result.rawDisplayName).toBe("id_xyz")
})
})
|