rileyherchert commited on
Commit ·
a6ce923
1
Parent(s): 8f2efe7
update
Browse files- analyze_prompt_number_coverage.py +205 -7
- analyze_transfer_features.py +26 -5
- plot_language_ridgeline.py +695 -0
- ucloudeval +8 -4
analyze_prompt_number_coverage.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# /// script
|
| 2 |
-
# dependencies = ["inspect-ai"]
|
| 3 |
# ///
|
| 4 |
"""Measure whether every number in each prompt appears in the model response.
|
| 5 |
|
|
@@ -8,7 +8,7 @@ Numbers are matched as complete numeric tokens and normalized by value, so
|
|
| 8 |
values are treated as one distinct number.
|
| 9 |
|
| 10 |
Example:
|
| 11 |
-
uv run hf_dataset/analyze_prompt_number_coverage.py
|
| 12 |
"""
|
| 13 |
|
| 14 |
from __future__ import annotations
|
|
@@ -16,18 +16,54 @@ from __future__ import annotations
|
|
| 16 |
import argparse
|
| 17 |
import csv
|
| 18 |
import json
|
| 19 |
-
import
|
| 20 |
import re
|
|
|
|
| 21 |
from concurrent.futures import ProcessPoolExecutor, as_completed
|
| 22 |
from decimal import Decimal, InvalidOperation
|
| 23 |
from pathlib import Path
|
| 24 |
from typing import Any
|
| 25 |
|
|
|
|
|
|
|
| 26 |
from inspect_ai.log import read_eval_log
|
|
|
|
| 27 |
|
|
|
|
| 28 |
NUMBER_RE = re.compile(
|
| 29 |
r"(?<![\w.])[-+]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?(?!\w|\.\d)"
|
| 30 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
def normalize_number(token: str) -> Decimal | None:
|
|
@@ -175,7 +211,7 @@ def discover_logs(inputs: list[Path]) -> list[Path]:
|
|
| 175 |
def resolve_worker_count(requested: int | None, log_count: int) -> int:
|
| 176 |
if requested is not None and requested < 1:
|
| 177 |
raise ValueError("--workers must be at least 1.")
|
| 178 |
-
default =
|
| 179 |
return min(requested or default, log_count)
|
| 180 |
|
| 181 |
|
|
@@ -214,6 +250,143 @@ def write_csv(path: Path, rows: list[dict[str, Any]]) -> None:
|
|
| 214 |
writer.writerows(rows)
|
| 215 |
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
def run_self_test() -> None:
|
| 218 |
cases = [
|
| 219 |
("Use 10, 10.0, and 1,000.", "10 and 1000", True),
|
|
@@ -228,14 +401,34 @@ def run_self_test() -> None:
|
|
| 228 |
raise AssertionError(
|
| 229 |
f"Failed: prompt={prompt!r}, response={response!r}, expected={expected}, got={actual}"
|
| 230 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
print(f"Self-test passed ({len(cases)} cases).")
|
| 232 |
|
| 233 |
|
| 234 |
def main() -> None:
|
| 235 |
parser = argparse.ArgumentParser(description=__doc__)
|
| 236 |
-
parser.add_argument(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
parser.add_argument("--out-dir", type=Path, default=Path("prompt_number_coverage"))
|
| 238 |
-
parser.add_argument(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
parser.add_argument(
|
| 240 |
"--workers",
|
| 241 |
type=int,
|
|
@@ -249,7 +442,8 @@ def main() -> None:
|
|
| 249 |
if not args.inputs:
|
| 250 |
return
|
| 251 |
|
| 252 |
-
|
|
|
|
| 253 |
if not logs:
|
| 254 |
raise SystemExit("No non-empty .eval logs found.")
|
| 255 |
|
|
@@ -271,6 +465,8 @@ def main() -> None:
|
|
| 271 |
encoding="utf-8",
|
| 272 |
)
|
| 273 |
write_csv(args.out_dir / "samples.csv", sample_rows)
|
|
|
|
|
|
|
| 274 |
|
| 275 |
for summary in summaries:
|
| 276 |
breakdown = summary["number_coverage_breakdown"]
|
|
@@ -280,6 +476,8 @@ def main() -> None:
|
|
| 280 |
f"right={breakdown['final_correct']['all_prompt_numbers_present_rate']!s}, "
|
| 281 |
f"wrong={breakdown['final_incorrect']['all_prompt_numbers_present_rate']!s}"
|
| 282 |
)
|
|
|
|
|
|
|
| 283 |
print(f"Wrote {args.out_dir}")
|
| 284 |
|
| 285 |
|
|
|
|
| 1 |
# /// script
|
| 2 |
+
# dependencies = ["inspect-ai", "matplotlib", "numpy"]
|
| 3 |
# ///
|
| 4 |
"""Measure whether every number in each prompt appears in the model response.
|
| 5 |
|
|
|
|
| 8 |
values are treated as one distinct number.
|
| 9 |
|
| 10 |
Example:
|
| 11 |
+
uv run hf_dataset/analyze_prompt_number_coverage.py
|
| 12 |
"""
|
| 13 |
|
| 14 |
from __future__ import annotations
|
|
|
|
| 16 |
import argparse
|
| 17 |
import csv
|
| 18 |
import json
|
| 19 |
+
import math
|
| 20 |
import re
|
| 21 |
+
from collections import defaultdict
|
| 22 |
from concurrent.futures import ProcessPoolExecutor, as_completed
|
| 23 |
from decimal import Decimal, InvalidOperation
|
| 24 |
from pathlib import Path
|
| 25 |
from typing import Any
|
| 26 |
|
| 27 |
+
import matplotlib.pyplot as plt
|
| 28 |
+
import numpy as np
|
| 29 |
from inspect_ai.log import read_eval_log
|
| 30 |
+
from matplotlib.ticker import PercentFormatter
|
| 31 |
|
| 32 |
+
DEFAULT_LOG_DIR = Path(__file__).resolve().parent / "logs"
|
| 33 |
NUMBER_RE = re.compile(
|
| 34 |
r"(?<![\w.])[-+]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?(?!\w|\.\d)"
|
| 35 |
)
|
| 36 |
+
LANGUAGE_LABELS = {
|
| 37 |
+
"dan": "Danish",
|
| 38 |
+
"deu": "German",
|
| 39 |
+
"eng": "English",
|
| 40 |
+
"fra": "French",
|
| 41 |
+
"isl": "Icelandic",
|
| 42 |
+
"ita": "Italian",
|
| 43 |
+
"nob": "Norwegian Bokmal",
|
| 44 |
+
"por": "Portuguese",
|
| 45 |
+
"rus": "Russian",
|
| 46 |
+
"spa": "Spanish",
|
| 47 |
+
"ukr": "Ukrainian",
|
| 48 |
+
"zho": "Chinese",
|
| 49 |
+
}
|
| 50 |
+
LANGUAGE_SPEAKERS = {
|
| 51 |
+
"eng": 380_000_000,
|
| 52 |
+
"deu": 100_000_000,
|
| 53 |
+
"dan": 6_000_000,
|
| 54 |
+
"nob": 5_000_000,
|
| 55 |
+
"isl": 370_000,
|
| 56 |
+
}
|
| 57 |
+
HUMAN_VERIFIED_LANGUAGES = {"eng", "dan"}
|
| 58 |
+
|
| 59 |
+
plt.rcParams.update(
|
| 60 |
+
{
|
| 61 |
+
"axes.spines.right": False,
|
| 62 |
+
"axes.spines.top": False,
|
| 63 |
+
"figure.dpi": 160,
|
| 64 |
+
"font.family": "sans-serif",
|
| 65 |
+
}
|
| 66 |
+
)
|
| 67 |
|
| 68 |
|
| 69 |
def normalize_number(token: str) -> Decimal | None:
|
|
|
|
| 211 |
def resolve_worker_count(requested: int | None, log_count: int) -> int:
|
| 212 |
if requested is not None and requested < 1:
|
| 213 |
raise ValueError("--workers must be at least 1.")
|
| 214 |
+
default = 128
|
| 215 |
return min(requested or default, log_count)
|
| 216 |
|
| 217 |
|
|
|
|
| 250 |
writer.writerows(rows)
|
| 251 |
|
| 252 |
|
| 253 |
+
def model_name(raw_model: str) -> str:
|
| 254 |
+
"""Drop provider and organization prefixes while preserving the model id."""
|
| 255 |
+
return raw_model.rstrip("/").split("/")[-1]
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def model_sort_key(raw_model: str) -> tuple[int, float, str]:
|
| 259 |
+
"""Keep common model families and sizes together in the heatmap."""
|
| 260 |
+
name = model_name(raw_model)
|
| 261 |
+
lower = name.lower()
|
| 262 |
+
family_order = 4
|
| 263 |
+
if "qwen" in lower:
|
| 264 |
+
family_order = 0
|
| 265 |
+
elif "llama" in lower:
|
| 266 |
+
family_order = 1
|
| 267 |
+
elif "gemma" in lower:
|
| 268 |
+
family_order = 2
|
| 269 |
+
elif raw_model.lower().startswith("openai/") or lower.startswith(("gpt-", "o1", "o3", "o4")):
|
| 270 |
+
family_order = 3
|
| 271 |
+
|
| 272 |
+
size_match = re.search(r"(?<![\d.])(\d+(?:\.\d+)?)\s*b(?:\b|[-_])", lower)
|
| 273 |
+
size = float(size_match.group(1)) if size_match else math.inf
|
| 274 |
+
return family_order, size, name
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def format_speaker_count(count: int) -> str:
|
| 278 |
+
if count >= 1_000_000:
|
| 279 |
+
return f"{count / 1_000_000:g}M"
|
| 280 |
+
if count >= 1_000:
|
| 281 |
+
return f"{count / 1_000:g}K"
|
| 282 |
+
return str(count)
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def heatmap_language_label(language: str) -> str:
|
| 286 |
+
name = LANGUAGE_LABELS.get(language, language)
|
| 287 |
+
speakers = LANGUAGE_SPEAKERS.get(language)
|
| 288 |
+
return f"{name}\n({format_speaker_count(speakers)} speakers)" if speakers is not None else name
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def number_coverage_grid(
|
| 292 |
+
rows: list[dict[str, Any]],
|
| 293 |
+
) -> tuple[list[str], list[str], np.ndarray, np.ndarray]:
|
| 294 |
+
"""Aggregate sample-level number coverage into model-by-language cells."""
|
| 295 |
+
counts: dict[tuple[str, str], list[int]] = defaultdict(lambda: [0, 0])
|
| 296 |
+
for row in rows:
|
| 297 |
+
model = str(row.get("model") or "").strip()
|
| 298 |
+
language = str(row.get("language") or "").strip()
|
| 299 |
+
if not model or not language:
|
| 300 |
+
continue
|
| 301 |
+
cell = counts[(model, language)]
|
| 302 |
+
cell[0] += int(bool(row["all_prompt_numbers_present"]))
|
| 303 |
+
cell[1] += 1
|
| 304 |
+
|
| 305 |
+
models = sorted({model for model, _ in counts}, key=model_sort_key)
|
| 306 |
+
languages = sorted(
|
| 307 |
+
{language for _, language in counts},
|
| 308 |
+
key=lambda language: (-LANGUAGE_SPEAKERS.get(language, -1), language),
|
| 309 |
+
)
|
| 310 |
+
rates = np.full((len(models), len(languages)), np.nan)
|
| 311 |
+
samples = np.zeros((len(models), len(languages)), dtype=int)
|
| 312 |
+
for model_index, model in enumerate(models):
|
| 313 |
+
for language_index, language in enumerate(languages):
|
| 314 |
+
covered, total = counts.get((model, language), (0, 0))
|
| 315 |
+
if total:
|
| 316 |
+
rates[model_index, language_index] = covered / total
|
| 317 |
+
samples[model_index, language_index] = total
|
| 318 |
+
return models, languages, rates, samples
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
def plot_number_coverage_heatmap(rows: list[dict[str, Any]], path: Path) -> bool:
|
| 322 |
+
"""Plot the sample-level coverage results by evaluated model and language."""
|
| 323 |
+
models, languages, rates, samples = number_coverage_grid(rows)
|
| 324 |
+
if not models or not languages:
|
| 325 |
+
return False
|
| 326 |
+
|
| 327 |
+
display_names = [model_name(model) for model in models]
|
| 328 |
+
if len(set(display_names)) != len(display_names):
|
| 329 |
+
display_names = models
|
| 330 |
+
|
| 331 |
+
cmap = plt.colormaps["viridis"].copy()
|
| 332 |
+
cmap.set_bad("#E0E0E0")
|
| 333 |
+
fig, ax = plt.subplots(
|
| 334 |
+
figsize=(max(7, 1.35 * len(languages) + 3.5), max(4, 0.6 * len(models) + 1.8))
|
| 335 |
+
)
|
| 336 |
+
image = ax.imshow(rates, aspect="auto", cmap=cmap, vmin=0, vmax=1)
|
| 337 |
+
ax.set_xticks(
|
| 338 |
+
range(len(languages)),
|
| 339 |
+
[heatmap_language_label(language) for language in languages],
|
| 340 |
+
rotation=40,
|
| 341 |
+
ha="right",
|
| 342 |
+
)
|
| 343 |
+
for column_index, language in enumerate(languages):
|
| 344 |
+
if language not in HUMAN_VERIFIED_LANGUAGES:
|
| 345 |
+
continue
|
| 346 |
+
ax.annotate(
|
| 347 |
+
"*",
|
| 348 |
+
xy=(column_index, 0),
|
| 349 |
+
xycoords=ax.get_xaxis_transform(),
|
| 350 |
+
xytext=(1, -4),
|
| 351 |
+
textcoords="offset points",
|
| 352 |
+
color="#FFC107",
|
| 353 |
+
fontweight="bold",
|
| 354 |
+
rotation=40,
|
| 355 |
+
ha="left",
|
| 356 |
+
va="top",
|
| 357 |
+
annotation_clip=False,
|
| 358 |
+
)
|
| 359 |
+
ax.set_yticks(range(len(models)), display_names)
|
| 360 |
+
ax.set_xlabel("Problem language")
|
| 361 |
+
ax.set_ylabel("Evaluated instruction-tuned model")
|
| 362 |
+
ax.set_title("Prompt number coverage by model and language")
|
| 363 |
+
|
| 364 |
+
for row_index in range(len(models)):
|
| 365 |
+
for column_index in range(len(languages)):
|
| 366 |
+
rate = rates[row_index, column_index]
|
| 367 |
+
if np.isnan(rate):
|
| 368 |
+
continue
|
| 369 |
+
text_color = "white" if rate < 0.45 else "black"
|
| 370 |
+
ax.text(
|
| 371 |
+
column_index,
|
| 372 |
+
row_index,
|
| 373 |
+
f"{rate:.1%}\n(n={samples[row_index, column_index]:,})",
|
| 374 |
+
ha="center",
|
| 375 |
+
va="center",
|
| 376 |
+
color=text_color,
|
| 377 |
+
fontsize=7,
|
| 378 |
+
)
|
| 379 |
+
|
| 380 |
+
colorbar = fig.colorbar(image, ax=ax, label="Samples containing every prompt number")
|
| 381 |
+
colorbar.ax.yaxis.set_major_formatter(PercentFormatter(1))
|
| 382 |
+
fig.text(0.47, 0.015, "*", color="#FFC107", fontweight="bold", ha="right", fontsize=8)
|
| 383 |
+
fig.text(0.472, 0.015, "Human verified", ha="left", fontsize=8)
|
| 384 |
+
fig.subplots_adjust(left=0.22, right=0.88, bottom=0.31, top=0.9)
|
| 385 |
+
fig.savefig(path, bbox_inches="tight")
|
| 386 |
+
plt.close(fig)
|
| 387 |
+
return True
|
| 388 |
+
|
| 389 |
+
|
| 390 |
def run_self_test() -> None:
|
| 391 |
cases = [
|
| 392 |
("Use 10, 10.0, and 1,000.", "10 and 1000", True),
|
|
|
|
| 401 |
raise AssertionError(
|
| 402 |
f"Failed: prompt={prompt!r}, response={response!r}, expected={expected}, got={actual}"
|
| 403 |
)
|
| 404 |
+
models, languages, rates, samples = number_coverage_grid(
|
| 405 |
+
[
|
| 406 |
+
{"model": "provider/model-1B", "language": "eng", "all_prompt_numbers_present": True},
|
| 407 |
+
{"model": "provider/model-1B", "language": "eng", "all_prompt_numbers_present": False},
|
| 408 |
+
{"model": "provider/model-1B", "language": "dan", "all_prompt_numbers_present": True},
|
| 409 |
+
]
|
| 410 |
+
)
|
| 411 |
+
if models != ["provider/model-1B"] or languages != ["eng", "dan"]:
|
| 412 |
+
raise AssertionError("Failed to build the expected model-language coverage grid.")
|
| 413 |
+
if rates.tolist() != [[0.5, 1.0]] or samples.tolist() != [[2, 1]]:
|
| 414 |
+
raise AssertionError("Failed to aggregate model-language coverage rates.")
|
| 415 |
print(f"Self-test passed ({len(cases)} cases).")
|
| 416 |
|
| 417 |
|
| 418 |
def main() -> None:
|
| 419 |
parser = argparse.ArgumentParser(description=__doc__)
|
| 420 |
+
parser.add_argument(
|
| 421 |
+
"inputs",
|
| 422 |
+
nargs="*",
|
| 423 |
+
type=Path,
|
| 424 |
+
help=f"Inspect .eval logs or directories containing logs. Defaults to {DEFAULT_LOG_DIR}.",
|
| 425 |
+
)
|
| 426 |
parser.add_argument("--out-dir", type=Path, default=Path("prompt_number_coverage"))
|
| 427 |
+
parser.add_argument(
|
| 428 |
+
"--max-samples",
|
| 429 |
+
type=int,
|
| 430 |
+
help="Maximum samples to analyze per log. Defaults to all samples.",
|
| 431 |
+
)
|
| 432 |
parser.add_argument(
|
| 433 |
"--workers",
|
| 434 |
type=int,
|
|
|
|
| 442 |
if not args.inputs:
|
| 443 |
return
|
| 444 |
|
| 445 |
+
inputs = args.inputs or [DEFAULT_LOG_DIR]
|
| 446 |
+
logs = discover_logs(inputs)
|
| 447 |
if not logs:
|
| 448 |
raise SystemExit("No non-empty .eval logs found.")
|
| 449 |
|
|
|
|
| 465 |
encoding="utf-8",
|
| 466 |
)
|
| 467 |
write_csv(args.out_dir / "samples.csv", sample_rows)
|
| 468 |
+
heatmap_path = args.out_dir / "number_coverage_heatmap.png"
|
| 469 |
+
wrote_heatmap = plot_number_coverage_heatmap(sample_rows, heatmap_path)
|
| 470 |
|
| 471 |
for summary in summaries:
|
| 472 |
breakdown = summary["number_coverage_breakdown"]
|
|
|
|
| 476 |
f"right={breakdown['final_correct']['all_prompt_numbers_present_rate']!s}, "
|
| 477 |
f"wrong={breakdown['final_incorrect']['all_prompt_numbers_present_rate']!s}"
|
| 478 |
)
|
| 479 |
+
if wrote_heatmap:
|
| 480 |
+
print(f"Wrote {heatmap_path}")
|
| 481 |
print(f"Wrote {args.out_dir}")
|
| 482 |
|
| 483 |
|
analyze_transfer_features.py
CHANGED
|
@@ -345,6 +345,7 @@ def relationship_plot(
|
|
| 345 |
xlabel: str,
|
| 346 |
title: str,
|
| 347 |
out: Path,
|
|
|
|
| 348 |
) -> bool:
|
| 349 |
"""Plot a descriptive feature relationship separately for each split."""
|
| 350 |
plot_data = data.dropna(subset=[x_column, "transfer_gap"])
|
|
@@ -402,16 +403,26 @@ def relationship_plot(
|
|
| 402 |
|
| 403 |
ax.axhline(0, color="black", linewidth=0.8, alpha=0.4)
|
| 404 |
ax.grid(alpha=0.2)
|
| 405 |
-
ax.set_xlabel(xlabel)
|
| 406 |
ax.set_ylabel("Accuracy gap: English - target language")
|
| 407 |
ax.yaxis.set_major_formatter(PercentFormatter(1))
|
| 408 |
ax.set_title(SPLIT_LABELS[split])
|
| 409 |
|
| 410 |
handles, labels = axes[0].get_legend_handles_labels()
|
| 411 |
if handles:
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
fig.suptitle(title)
|
| 414 |
-
fig.tight_layout(rect=(0, 0.07, 1, 0.94))
|
| 415 |
fig.savefig(out, bbox_inches="tight")
|
| 416 |
plt.close(fig)
|
| 417 |
return True
|
|
@@ -510,22 +521,32 @@ def main() -> None:
|
|
| 510 |
"TFR: target-language tokens/character divided by English tokens/character. Computed on GSM8K templates.",
|
| 511 |
"English-minus-target-language accuracy gap versus tokenizer fertility ratio (TFR)",
|
| 512 |
args.out_dir / "tokenizer_fertility_vs_transfer.png",
|
|
|
|
| 513 |
),
|
| 514 |
(
|
| 515 |
"typological_distance_from_english",
|
| 516 |
"URIEL cosine distance from English (syntax + phoneme inventory features)",
|
| 517 |
"English-minus-target-language accuracy gap versus typological distance from English",
|
| 518 |
args.out_dir / "typological_distance_vs_transfer.png",
|
|
|
|
| 519 |
),
|
| 520 |
(
|
| 521 |
"log10_common_crawl_pages",
|
| 522 |
"Language-resource proxy: log10 Common Crawl page count",
|
| 523 |
"English-minus-target-language accuracy gap versus Common Crawl resource quantity",
|
| 524 |
args.out_dir / "resource_quantity_vs_transfer.png",
|
|
|
|
| 525 |
),
|
| 526 |
]
|
| 527 |
-
for column, xlabel, title, path in plots:
|
| 528 |
-
if relationship_plot(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
print(f"Saved {path}")
|
| 530 |
else:
|
| 531 |
print(f"Skipped {path.name}: no paired transfer observations with this feature.")
|
|
|
|
| 345 |
xlabel: str,
|
| 346 |
title: str,
|
| 347 |
out: Path,
|
| 348 |
+
shared_xlabel: bool = False,
|
| 349 |
) -> bool:
|
| 350 |
"""Plot a descriptive feature relationship separately for each split."""
|
| 351 |
plot_data = data.dropna(subset=[x_column, "transfer_gap"])
|
|
|
|
| 403 |
|
| 404 |
ax.axhline(0, color="black", linewidth=0.8, alpha=0.4)
|
| 405 |
ax.grid(alpha=0.2)
|
| 406 |
+
ax.set_xlabel("" if shared_xlabel else xlabel)
|
| 407 |
ax.set_ylabel("Accuracy gap: English - target language")
|
| 408 |
ax.yaxis.set_major_formatter(PercentFormatter(1))
|
| 409 |
ax.set_title(SPLIT_LABELS[split])
|
| 410 |
|
| 411 |
handles, labels = axes[0].get_legend_handles_labels()
|
| 412 |
if handles:
|
| 413 |
+
legend_y = 0.005 if shared_xlabel else None
|
| 414 |
+
fig.legend(
|
| 415 |
+
handles,
|
| 416 |
+
labels,
|
| 417 |
+
loc="lower center",
|
| 418 |
+
bbox_to_anchor=(0.5, legend_y) if legend_y is not None else None,
|
| 419 |
+
ncol=len(labels),
|
| 420 |
+
frameon=False,
|
| 421 |
+
)
|
| 422 |
+
if shared_xlabel:
|
| 423 |
+
fig.supxlabel(xlabel, y=0.09)
|
| 424 |
fig.suptitle(title)
|
| 425 |
+
fig.tight_layout(rect=(0, 0.16 if shared_xlabel else 0.07, 1, 0.94))
|
| 426 |
fig.savefig(out, bbox_inches="tight")
|
| 427 |
plt.close(fig)
|
| 428 |
return True
|
|
|
|
| 521 |
"TFR: target-language tokens/character divided by English tokens/character. Computed on GSM8K templates.",
|
| 522 |
"English-minus-target-language accuracy gap versus tokenizer fertility ratio (TFR)",
|
| 523 |
args.out_dir / "tokenizer_fertility_vs_transfer.png",
|
| 524 |
+
True,
|
| 525 |
),
|
| 526 |
(
|
| 527 |
"typological_distance_from_english",
|
| 528 |
"URIEL cosine distance from English (syntax + phoneme inventory features)",
|
| 529 |
"English-minus-target-language accuracy gap versus typological distance from English",
|
| 530 |
args.out_dir / "typological_distance_vs_transfer.png",
|
| 531 |
+
False,
|
| 532 |
),
|
| 533 |
(
|
| 534 |
"log10_common_crawl_pages",
|
| 535 |
"Language-resource proxy: log10 Common Crawl page count",
|
| 536 |
"English-minus-target-language accuracy gap versus Common Crawl resource quantity",
|
| 537 |
args.out_dir / "resource_quantity_vs_transfer.png",
|
| 538 |
+
False,
|
| 539 |
),
|
| 540 |
]
|
| 541 |
+
for column, xlabel, title, path, shared_xlabel in plots:
|
| 542 |
+
if relationship_plot(
|
| 543 |
+
transfer,
|
| 544 |
+
column,
|
| 545 |
+
xlabel,
|
| 546 |
+
title,
|
| 547 |
+
path,
|
| 548 |
+
shared_xlabel=shared_xlabel,
|
| 549 |
+
):
|
| 550 |
print(f"Saved {path}")
|
| 551 |
else:
|
| 552 |
print(f"Skipped {path.name}: no paired transfer observations with this feature.")
|
plot_language_ridgeline.py
ADDED
|
@@ -0,0 +1,695 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
# dependencies = ["inspect-ai", "matplotlib", "numpy", "pandas", "scipy"]
|
| 3 |
+
# ///
|
| 4 |
+
"""Plot original accuracy against sampled synthetic-set distributions by language.
|
| 5 |
+
|
| 6 |
+
The synthetic distribution follows the benchmark sampling scheme used in
|
| 7 |
+
``visualize_results.py``: each sampled set chooses one numerical variant from
|
| 8 |
+
every source template, then averages correctness across the selected problems.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import argparse
|
| 14 |
+
import os
|
| 15 |
+
import re
|
| 16 |
+
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor, as_completed
|
| 17 |
+
from dataclasses import dataclass
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
from typing import Any
|
| 20 |
+
|
| 21 |
+
import matplotlib.pyplot as plt
|
| 22 |
+
import numpy as np
|
| 23 |
+
import pandas as pd
|
| 24 |
+
from inspect_ai.log import read_eval_log
|
| 25 |
+
from matplotlib.lines import Line2D
|
| 26 |
+
from matplotlib.patches import Patch
|
| 27 |
+
from matplotlib.ticker import PercentFormatter
|
| 28 |
+
from scipy.stats import norm
|
| 29 |
+
|
| 30 |
+
LANGUAGE_LABELS = {
|
| 31 |
+
"eng": "English",
|
| 32 |
+
"dan": "Danish",
|
| 33 |
+
"deu": "German",
|
| 34 |
+
"nob": "Norwegian Bokmal",
|
| 35 |
+
"isl": "Icelandic",
|
| 36 |
+
}
|
| 37 |
+
LANGUAGE_SPEAKERS = {
|
| 38 |
+
"eng": 380_000_000,
|
| 39 |
+
"deu": 100_000_000,
|
| 40 |
+
"dan": 6_000_000,
|
| 41 |
+
"nob": 5_000_000,
|
| 42 |
+
"isl": 370_000,
|
| 43 |
+
}
|
| 44 |
+
HUMAN_VERIFIED_LANGUAGES = {"eng", "dan"}
|
| 45 |
+
|
| 46 |
+
SYNTHETIC_COLOR = "#173B75"
|
| 47 |
+
SYNTHETIC_FILL = "#AFC0DD"
|
| 48 |
+
ORIGINAL_COLOR = "#C61B3C"
|
| 49 |
+
GRID_COLOR = "#D8DEE8"
|
| 50 |
+
TEXT_COLOR = "#162033"
|
| 51 |
+
|
| 52 |
+
plt.rcParams.update(
|
| 53 |
+
{
|
| 54 |
+
"axes.spines.left": False,
|
| 55 |
+
"axes.spines.right": False,
|
| 56 |
+
"axes.spines.top": False,
|
| 57 |
+
"figure.dpi": 160,
|
| 58 |
+
"font.family": "sans-serif",
|
| 59 |
+
"text.color": TEXT_COLOR,
|
| 60 |
+
"axes.labelcolor": TEXT_COLOR,
|
| 61 |
+
"xtick.color": "#4A5568",
|
| 62 |
+
"ytick.color": TEXT_COLOR,
|
| 63 |
+
}
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@dataclass(frozen=True)
|
| 68 |
+
class PlotStats:
|
| 69 |
+
language: str
|
| 70 |
+
original_accuracy: float
|
| 71 |
+
synthetic_mean: float
|
| 72 |
+
synthetic_std: float
|
| 73 |
+
shift_pp: float
|
| 74 |
+
n_models: int
|
| 75 |
+
n_templates: int
|
| 76 |
+
n_sampled_sets: int
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def model_name(raw_model: str) -> str:
|
| 80 |
+
"""Remove provider prefixes while preserving the model identifier."""
|
| 81 |
+
return raw_model.rstrip("/").split("/")[-1]
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def model_family(model: str) -> str:
|
| 85 |
+
lower = model.lower()
|
| 86 |
+
if "qwen2.5" in lower:
|
| 87 |
+
return "Qwen2.5"
|
| 88 |
+
if "olmo-2" in lower:
|
| 89 |
+
return "OLMo 2"
|
| 90 |
+
if "gemma-3" in lower:
|
| 91 |
+
return "Gemma 3"
|
| 92 |
+
if re.search(r"llama[-_. ]?3", lower):
|
| 93 |
+
return "Llama 3"
|
| 94 |
+
if "apertus" in lower:
|
| 95 |
+
return "Apertus"
|
| 96 |
+
return "Other"
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def path_slug(value: str) -> str:
|
| 100 |
+
slug = re.sub(r"[^a-z0-9.]+", "-", value.lower()).strip("-")
|
| 101 |
+
return slug or "unknown"
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def format_speaker_count(count: int) -> str:
|
| 105 |
+
if count >= 1_000_000:
|
| 106 |
+
return f"{count / 1_000_000:g}M"
|
| 107 |
+
if count >= 1_000:
|
| 108 |
+
return f"{count / 1_000:g}K"
|
| 109 |
+
return str(count)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def language_title(language: str) -> str:
|
| 113 |
+
label = LANGUAGE_LABELS.get(language, language)
|
| 114 |
+
speakers = LANGUAGE_SPEAKERS.get(language)
|
| 115 |
+
speaker_label = f" ({format_speaker_count(speakers)} native speakers)" if speakers else ""
|
| 116 |
+
verified = " ★" if language in HUMAN_VERIFIED_LANGUAGES else ""
|
| 117 |
+
return f"{label}{speaker_label}{verified}"
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def parse_task(task: str) -> tuple[str, str] | None:
|
| 121 |
+
matches = re.findall(r"(original|synthetic)[_-]([a-z]{3})", task.lower())
|
| 122 |
+
return matches[-1] if matches else None
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def score_to_float(score: Any) -> float | None:
|
| 126 |
+
value = getattr(score, "value", score)
|
| 127 |
+
if isinstance(value, bool):
|
| 128 |
+
return float(value)
|
| 129 |
+
if isinstance(value, (int, float)):
|
| 130 |
+
return float(value)
|
| 131 |
+
if isinstance(value, str):
|
| 132 |
+
normalized = value.strip().upper()
|
| 133 |
+
if normalized in {"C", "CORRECT", "TRUE"}:
|
| 134 |
+
return 1.0
|
| 135 |
+
if normalized in {"I", "INCORRECT", "FALSE"}:
|
| 136 |
+
return 0.0
|
| 137 |
+
try:
|
| 138 |
+
return float(normalized)
|
| 139 |
+
except ValueError:
|
| 140 |
+
return None
|
| 141 |
+
return None
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def sample_score(sample: Any, scorer: str | None) -> float | None:
|
| 145 |
+
scores = sample.scores or {}
|
| 146 |
+
if scorer:
|
| 147 |
+
return score_to_float(scores.get(scorer)) if scorer in scores else None
|
| 148 |
+
|
| 149 |
+
for preferred in ("math", "pattern"):
|
| 150 |
+
if preferred in scores:
|
| 151 |
+
return score_to_float(scores[preferred])
|
| 152 |
+
|
| 153 |
+
for score in scores.values():
|
| 154 |
+
value = score_to_float(score)
|
| 155 |
+
if value is not None:
|
| 156 |
+
return value
|
| 157 |
+
return None
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def _read_log_header(path: Path) -> tuple[Path, Any | None, str | None]:
|
| 161 |
+
try:
|
| 162 |
+
return path, read_eval_log(str(path), header_only=True), None
|
| 163 |
+
except Exception as exc:
|
| 164 |
+
return path, None, str(exc)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def discover_selected_logs(
|
| 168 |
+
log_dir: Path,
|
| 169 |
+
requested_models: list[str] | None,
|
| 170 |
+
workers: int,
|
| 171 |
+
) -> list[Path]:
|
| 172 |
+
"""Select all successful logs and deduplicate snapshots in parallel."""
|
| 173 |
+
paths = sorted(path for path in log_dir.rglob("*.eval") if path.stat().st_size >= 1_000)
|
| 174 |
+
if not paths:
|
| 175 |
+
return []
|
| 176 |
+
|
| 177 |
+
requested = {model.lower() for model in requested_models} if requested_models else None
|
| 178 |
+
selected: dict[tuple[str, str], tuple[Path, Any]] = {}
|
| 179 |
+
|
| 180 |
+
if workers <= 1:
|
| 181 |
+
results = [_read_log_header(path) for path in paths]
|
| 182 |
+
else:
|
| 183 |
+
with ThreadPoolExecutor(max_workers=min(workers, len(paths))) as pool:
|
| 184 |
+
results = list(pool.map(_read_log_header, paths))
|
| 185 |
+
|
| 186 |
+
for path, header, error in results:
|
| 187 |
+
if error:
|
| 188 |
+
print(f"Skipping unreadable log {path.name}: {error}")
|
| 189 |
+
continue
|
| 190 |
+
if str(header.status) != "success" or parse_task(header.eval.task) is None:
|
| 191 |
+
continue
|
| 192 |
+
if requested and model_name(header.eval.model).lower() not in requested:
|
| 193 |
+
continue
|
| 194 |
+
|
| 195 |
+
key = (header.eval.eval_id, header.eval.task)
|
| 196 |
+
previous = selected.get(key)
|
| 197 |
+
if previous is None or path.stat().st_mtime_ns > previous[0].stat().st_mtime_ns:
|
| 198 |
+
selected[key] = (path, header)
|
| 199 |
+
|
| 200 |
+
return sorted(path for path, _header in selected.values())
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def _load_one_log(
|
| 204 |
+
path: Path,
|
| 205 |
+
scorer: str | None,
|
| 206 |
+
) -> tuple[str, pd.DataFrame | None, str | None]:
|
| 207 |
+
"""Read and partially aggregate one log in a worker process."""
|
| 208 |
+
try:
|
| 209 |
+
log = read_eval_log(str(path))
|
| 210 |
+
except Exception as exc:
|
| 211 |
+
return path.name, None, f"Skipping unreadable log {path.name}: {exc}"
|
| 212 |
+
|
| 213 |
+
parsed = parse_task(log.eval.task)
|
| 214 |
+
if parsed is None:
|
| 215 |
+
return path.name, None, f"Skipping unrecognized task {log.eval.task!r}"
|
| 216 |
+
if not log.samples:
|
| 217 |
+
return path.name, pd.DataFrame(), None
|
| 218 |
+
|
| 219 |
+
split, task_language = parsed
|
| 220 |
+
model = model_name(log.eval.model)
|
| 221 |
+
label = f"{model} / {task_language} / {split}"
|
| 222 |
+
rows: list[dict[str, Any]] = []
|
| 223 |
+
|
| 224 |
+
for sample in log.samples:
|
| 225 |
+
correct = sample_score(sample, scorer)
|
| 226 |
+
if correct is None:
|
| 227 |
+
continue
|
| 228 |
+
metadata = sample.metadata or {}
|
| 229 |
+
rows.append(
|
| 230 |
+
{
|
| 231 |
+
"model": model,
|
| 232 |
+
"language": metadata.get("language", task_language),
|
| 233 |
+
"split": split,
|
| 234 |
+
"sample_id": sample.id,
|
| 235 |
+
"source_id": metadata.get("source_id", sample.id),
|
| 236 |
+
"correct": correct,
|
| 237 |
+
}
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
if not rows:
|
| 241 |
+
return label, pd.DataFrame(), None
|
| 242 |
+
|
| 243 |
+
samples = pd.DataFrame(rows)
|
| 244 |
+
grouped = (
|
| 245 |
+
samples.groupby(
|
| 246 |
+
["model", "language", "split", "sample_id", "source_id"],
|
| 247 |
+
dropna=False,
|
| 248 |
+
as_index=False,
|
| 249 |
+
)["correct"]
|
| 250 |
+
.agg(correct_sum="sum", correct_count="size")
|
| 251 |
+
)
|
| 252 |
+
return label, grouped, None
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
def load_problem_scores(
|
| 256 |
+
paths: list[Path],
|
| 257 |
+
scorer: str | None,
|
| 258 |
+
workers: int,
|
| 259 |
+
) -> pd.DataFrame:
|
| 260 |
+
"""Load logs in parallel and combine repeated runs by model/problem."""
|
| 261 |
+
frames: list[pd.DataFrame] = []
|
| 262 |
+
|
| 263 |
+
if workers <= 1:
|
| 264 |
+
results = [_load_one_log(path, scorer) for path in paths]
|
| 265 |
+
for index, (label, frame, warning) in enumerate(results, start=1):
|
| 266 |
+
if warning:
|
| 267 |
+
print(warning)
|
| 268 |
+
else:
|
| 269 |
+
print(f"[{index}/{len(paths)}] {label}")
|
| 270 |
+
if frame is not None and not frame.empty:
|
| 271 |
+
frames.append(frame)
|
| 272 |
+
else:
|
| 273 |
+
with ProcessPoolExecutor(max_workers=min(workers, len(paths))) as pool:
|
| 274 |
+
futures = [pool.submit(_load_one_log, path, scorer) for path in paths]
|
| 275 |
+
for index, future in enumerate(as_completed(futures), start=1):
|
| 276 |
+
label, frame, warning = future.result()
|
| 277 |
+
if warning:
|
| 278 |
+
print(warning)
|
| 279 |
+
else:
|
| 280 |
+
print(f"[{index}/{len(paths)}] {label}")
|
| 281 |
+
if frame is not None and not frame.empty:
|
| 282 |
+
frames.append(frame)
|
| 283 |
+
|
| 284 |
+
if not frames:
|
| 285 |
+
return pd.DataFrame()
|
| 286 |
+
|
| 287 |
+
combined = pd.concat(frames, ignore_index=True)
|
| 288 |
+
keys = ["model", "language", "split", "sample_id", "source_id"]
|
| 289 |
+
problems = (
|
| 290 |
+
combined.groupby(keys, dropna=False, as_index=False)
|
| 291 |
+
.agg(correct_sum=("correct_sum", "sum"), correct_count=("correct_count", "sum"))
|
| 292 |
+
)
|
| 293 |
+
problems["correct"] = problems["correct_sum"] / problems["correct_count"]
|
| 294 |
+
return problems.drop(columns=["correct_sum", "correct_count"])
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
def sample_synthetic_sets(
|
| 298 |
+
synthetic: pd.DataFrame,
|
| 299 |
+
n_sets: int,
|
| 300 |
+
rng: np.random.Generator,
|
| 301 |
+
) -> tuple[np.ndarray, int]:
|
| 302 |
+
"""Sample one variant per source template and return set-level accuracies."""
|
| 303 |
+
variants = [
|
| 304 |
+
group["correct"].to_numpy(dtype=float)
|
| 305 |
+
for _source_id, group in synthetic.groupby("source_id", sort=True, dropna=False)
|
| 306 |
+
]
|
| 307 |
+
if not variants:
|
| 308 |
+
raise ValueError("Synthetic data contains no source templates.")
|
| 309 |
+
|
| 310 |
+
set_totals = np.zeros(n_sets, dtype=float)
|
| 311 |
+
for values in variants:
|
| 312 |
+
set_totals += rng.choice(values, size=n_sets, replace=True)
|
| 313 |
+
return set_totals / len(variants), len(variants)
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def normal_curve(values: np.ndarray) -> tuple[np.ndarray, np.ndarray, float, float]:
|
| 317 |
+
"""Fit and return a normal probability density for sampled accuracies."""
|
| 318 |
+
mean = float(values.mean())
|
| 319 |
+
std = max(float(values.std(ddof=1)), 0.005)
|
| 320 |
+
lower = max(0.0, mean - 4 * std)
|
| 321 |
+
upper = min(1.0, mean + 4 * std)
|
| 322 |
+
x = np.linspace(lower, upper, 500)
|
| 323 |
+
return x, norm.pdf(x, loc=mean, scale=std), mean, std
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def collect_plot_data(
|
| 327 |
+
problems: pd.DataFrame,
|
| 328 |
+
languages: list[str],
|
| 329 |
+
n_sets: int,
|
| 330 |
+
seed: int,
|
| 331 |
+
) -> tuple[dict[str, tuple[np.ndarray, np.ndarray, np.ndarray]], list[PlotStats]]:
|
| 332 |
+
distributions: dict[str, tuple[np.ndarray, np.ndarray, np.ndarray]] = {}
|
| 333 |
+
stats: list[PlotStats] = []
|
| 334 |
+
rng = np.random.default_rng(seed)
|
| 335 |
+
|
| 336 |
+
for language in languages:
|
| 337 |
+
rows = problems[problems["language"] == language]
|
| 338 |
+
split_models = {
|
| 339 |
+
split: set(split_rows["model"].unique())
|
| 340 |
+
for split, split_rows in rows.groupby("split")
|
| 341 |
+
}
|
| 342 |
+
paired_models = sorted(
|
| 343 |
+
split_models.get("original", set()) & split_models.get("synthetic", set())
|
| 344 |
+
)
|
| 345 |
+
if not paired_models:
|
| 346 |
+
print(f"Skipping {language}: both original and synthetic results are required.")
|
| 347 |
+
continue
|
| 348 |
+
|
| 349 |
+
original_by_model: list[float] = []
|
| 350 |
+
synthetic_by_model: list[np.ndarray] = []
|
| 351 |
+
n_templates = 0
|
| 352 |
+
for model in paired_models:
|
| 353 |
+
model_rows = rows[rows["model"] == model]
|
| 354 |
+
original = model_rows[model_rows["split"] == "original"]
|
| 355 |
+
synthetic = model_rows[model_rows["split"] == "synthetic"]
|
| 356 |
+
original_by_model.append(float(original["correct"].mean()))
|
| 357 |
+
model_set_means, model_templates = sample_synthetic_sets(
|
| 358 |
+
synthetic,
|
| 359 |
+
n_sets,
|
| 360 |
+
rng,
|
| 361 |
+
)
|
| 362 |
+
synthetic_by_model.append(model_set_means)
|
| 363 |
+
n_templates += model_templates
|
| 364 |
+
|
| 365 |
+
set_means = np.mean(np.vstack(synthetic_by_model), axis=0)
|
| 366 |
+
x, density, synthetic_mean, synthetic_std = normal_curve(set_means)
|
| 367 |
+
original_accuracy = float(np.mean(original_by_model))
|
| 368 |
+
distributions[language] = (set_means, x, density)
|
| 369 |
+
stats.append(
|
| 370 |
+
PlotStats(
|
| 371 |
+
language=language,
|
| 372 |
+
original_accuracy=original_accuracy,
|
| 373 |
+
synthetic_mean=synthetic_mean,
|
| 374 |
+
synthetic_std=synthetic_std,
|
| 375 |
+
shift_pp=(synthetic_mean - original_accuracy) * 100,
|
| 376 |
+
n_models=len(paired_models),
|
| 377 |
+
n_templates=n_templates,
|
| 378 |
+
n_sampled_sets=n_sets,
|
| 379 |
+
)
|
| 380 |
+
)
|
| 381 |
+
|
| 382 |
+
return distributions, stats
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
def plot_distributions(
|
| 386 |
+
distributions: dict[str, tuple[np.ndarray, np.ndarray, np.ndarray]],
|
| 387 |
+
stats: list[PlotStats],
|
| 388 |
+
scope_label: str,
|
| 389 |
+
out_png: Path,
|
| 390 |
+
) -> None:
|
| 391 |
+
if not stats:
|
| 392 |
+
raise ValueError("No languages have paired original and synthetic results.")
|
| 393 |
+
|
| 394 |
+
fig, axes = plt.subplots(
|
| 395 |
+
len(stats),
|
| 396 |
+
1,
|
| 397 |
+
figsize=(10.5, 2.05 * len(stats) + 1.7),
|
| 398 |
+
sharex=True,
|
| 399 |
+
squeeze=False,
|
| 400 |
+
)
|
| 401 |
+
axes = axes[:, 0]
|
| 402 |
+
|
| 403 |
+
for ax, row in zip(axes, stats, strict=True):
|
| 404 |
+
set_means, x, density = distributions[row.language]
|
| 405 |
+
peak_density = float(density.max())
|
| 406 |
+
histogram_bins = min(18, max(8, int(np.sqrt(len(set_means)) / 2)))
|
| 407 |
+
|
| 408 |
+
ax.hist(
|
| 409 |
+
set_means,
|
| 410 |
+
bins=histogram_bins,
|
| 411 |
+
density=True,
|
| 412 |
+
color=SYNTHETIC_FILL,
|
| 413 |
+
edgecolor="white",
|
| 414 |
+
linewidth=0.7,
|
| 415 |
+
alpha=0.72,
|
| 416 |
+
zorder=1,
|
| 417 |
+
)
|
| 418 |
+
ax.fill_between(
|
| 419 |
+
x,
|
| 420 |
+
0,
|
| 421 |
+
density,
|
| 422 |
+
color=SYNTHETIC_FILL,
|
| 423 |
+
alpha=0.2,
|
| 424 |
+
zorder=2,
|
| 425 |
+
)
|
| 426 |
+
ax.plot(x, density, color=SYNTHETIC_COLOR, linewidth=2.2, zorder=3)
|
| 427 |
+
ax.scatter(
|
| 428 |
+
row.synthetic_mean,
|
| 429 |
+
peak_density,
|
| 430 |
+
color=SYNTHETIC_COLOR,
|
| 431 |
+
s=34,
|
| 432 |
+
zorder=5,
|
| 433 |
+
)
|
| 434 |
+
|
| 435 |
+
ax.axvline(
|
| 436 |
+
row.original_accuracy,
|
| 437 |
+
color=ORIGINAL_COLOR,
|
| 438 |
+
linewidth=2.4,
|
| 439 |
+
zorder=4,
|
| 440 |
+
)
|
| 441 |
+
|
| 442 |
+
arrow_y = peak_density * 1.08
|
| 443 |
+
gap = abs(row.synthetic_mean - row.original_accuracy)
|
| 444 |
+
if gap < 0.025:
|
| 445 |
+
cap_height = peak_density * 0.035
|
| 446 |
+
ax.hlines(
|
| 447 |
+
arrow_y,
|
| 448 |
+
row.synthetic_mean,
|
| 449 |
+
row.original_accuracy,
|
| 450 |
+
color="black",
|
| 451 |
+
linewidth=1.2,
|
| 452 |
+
zorder=6,
|
| 453 |
+
)
|
| 454 |
+
ax.vlines(
|
| 455 |
+
[row.synthetic_mean, row.original_accuracy],
|
| 456 |
+
arrow_y - cap_height,
|
| 457 |
+
arrow_y + cap_height,
|
| 458 |
+
color="black",
|
| 459 |
+
linewidth=1.2,
|
| 460 |
+
zorder=6,
|
| 461 |
+
)
|
| 462 |
+
else:
|
| 463 |
+
ax.annotate(
|
| 464 |
+
"",
|
| 465 |
+
xy=(row.synthetic_mean, arrow_y),
|
| 466 |
+
xytext=(row.original_accuracy, arrow_y),
|
| 467 |
+
arrowprops={
|
| 468 |
+
"arrowstyle": "<->",
|
| 469 |
+
"color": "black",
|
| 470 |
+
"linewidth": 1.2,
|
| 471 |
+
"shrinkA": 2,
|
| 472 |
+
"shrinkB": 2,
|
| 473 |
+
},
|
| 474 |
+
zorder=6,
|
| 475 |
+
)
|
| 476 |
+
midpoint = (row.original_accuracy + row.synthetic_mean) / 2
|
| 477 |
+
ax.text(
|
| 478 |
+
midpoint,
|
| 479 |
+
arrow_y + peak_density * 0.045,
|
| 480 |
+
f"performance gap ({row.shift_pp:+.1f} pp)",
|
| 481 |
+
color="black",
|
| 482 |
+
fontsize=8,
|
| 483 |
+
ha="center",
|
| 484 |
+
va="bottom",
|
| 485 |
+
zorder=7,
|
| 486 |
+
)
|
| 487 |
+
|
| 488 |
+
ax.set_title(
|
| 489 |
+
language_title(row.language),
|
| 490 |
+
loc="left",
|
| 491 |
+
fontsize=11,
|
| 492 |
+
fontweight="semibold",
|
| 493 |
+
pad=8,
|
| 494 |
+
)
|
| 495 |
+
ax.set_ylim(0, peak_density * 1.32)
|
| 496 |
+
ax.grid(axis="y", color=GRID_COLOR, linewidth=0.7, alpha=0.65)
|
| 497 |
+
ax.set_axisbelow(True)
|
| 498 |
+
ax.tick_params(axis="y", labelsize=8)
|
| 499 |
+
|
| 500 |
+
axes[-1].set_xlim(0, 1)
|
| 501 |
+
axes[-1].xaxis.set_major_formatter(PercentFormatter(1))
|
| 502 |
+
axes[-1].set_xlabel("Exact-answer accuracy", fontsize=11, labelpad=10)
|
| 503 |
+
fig.supylabel("Density", fontsize=11, x=0.03)
|
| 504 |
+
fig.suptitle(
|
| 505 |
+
"Original accuracy and synthetic-set distributions",
|
| 506 |
+
x=0.08,
|
| 507 |
+
ha="left",
|
| 508 |
+
fontsize=17,
|
| 509 |
+
fontweight="bold",
|
| 510 |
+
y=0.985,
|
| 511 |
+
)
|
| 512 |
+
fig.text(
|
| 513 |
+
0.08,
|
| 514 |
+
0.955,
|
| 515 |
+
f"{scope_label} | one random variant per template in each sampled set",
|
| 516 |
+
fontsize=10,
|
| 517 |
+
color="#596579",
|
| 518 |
+
ha="left",
|
| 519 |
+
va="top",
|
| 520 |
+
)
|
| 521 |
+
|
| 522 |
+
legend_handles = [
|
| 523 |
+
Line2D(
|
| 524 |
+
[0],
|
| 525 |
+
[0],
|
| 526 |
+
color=ORIGINAL_COLOR,
|
| 527 |
+
marker="|",
|
| 528 |
+
markersize=15,
|
| 529 |
+
markeredgewidth=2.4,
|
| 530 |
+
linewidth=0,
|
| 531 |
+
label="Original benchmark accuracy",
|
| 532 |
+
),
|
| 533 |
+
Patch(
|
| 534 |
+
facecolor=SYNTHETIC_FILL,
|
| 535 |
+
edgecolor=SYNTHETIC_COLOR,
|
| 536 |
+
label="Sampled synthetic sets",
|
| 537 |
+
),
|
| 538 |
+
Line2D(
|
| 539 |
+
[0],
|
| 540 |
+
[0],
|
| 541 |
+
marker="$★$",
|
| 542 |
+
color="#E0A800",
|
| 543 |
+
markersize=10,
|
| 544 |
+
linewidth=0,
|
| 545 |
+
label="Human verified",
|
| 546 |
+
),
|
| 547 |
+
]
|
| 548 |
+
axes[0].legend(
|
| 549 |
+
handles=legend_handles,
|
| 550 |
+
loc="upper right",
|
| 551 |
+
bbox_to_anchor=(1, 1.42),
|
| 552 |
+
frameon=False,
|
| 553 |
+
ncol=3,
|
| 554 |
+
fontsize=9,
|
| 555 |
+
handlelength=1.8,
|
| 556 |
+
columnspacing=1.7,
|
| 557 |
+
)
|
| 558 |
+
|
| 559 |
+
fig.tight_layout(rect=(0.045, 0.03, 1, 0.925))
|
| 560 |
+
fig.savefig(out_png, dpi=220, bbox_inches="tight", facecolor="white")
|
| 561 |
+
plt.close(fig)
|
| 562 |
+
|
| 563 |
+
|
| 564 |
+
def write_summary(stats: list[PlotStats], out_csv: Path) -> None:
|
| 565 |
+
pd.DataFrame(
|
| 566 |
+
[
|
| 567 |
+
{
|
| 568 |
+
"language": row.language,
|
| 569 |
+
"language_label": LANGUAGE_LABELS.get(row.language, row.language),
|
| 570 |
+
"original_accuracy": row.original_accuracy,
|
| 571 |
+
"synthetic_sampled_mean": row.synthetic_mean,
|
| 572 |
+
"synthetic_sampled_std": row.synthetic_std,
|
| 573 |
+
"synthetic_minus_original_pp": row.shift_pp,
|
| 574 |
+
"paired_models": row.n_models,
|
| 575 |
+
"source_templates": row.n_templates,
|
| 576 |
+
"sampled_sets": row.n_sampled_sets,
|
| 577 |
+
}
|
| 578 |
+
for row in stats
|
| 579 |
+
]
|
| 580 |
+
).to_csv(out_csv, index=False)
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
def language_order(available: set[str], requested: list[str] | None) -> list[str]:
|
| 584 |
+
if requested:
|
| 585 |
+
return requested
|
| 586 |
+
return sorted(
|
| 587 |
+
available,
|
| 588 |
+
key=lambda language: (-LANGUAGE_SPEAKERS.get(language, -1), language),
|
| 589 |
+
)
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
def main() -> None:
|
| 593 |
+
folder = Path(__file__).resolve().parent
|
| 594 |
+
cpu_count = os.cpu_count() or 1
|
| 595 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 596 |
+
parser.add_argument(
|
| 597 |
+
"--log-dir",
|
| 598 |
+
type=Path,
|
| 599 |
+
default=folder / "logs",
|
| 600 |
+
help="Directory searched recursively for Inspect .eval logs.",
|
| 601 |
+
)
|
| 602 |
+
parser.add_argument(
|
| 603 |
+
"--model",
|
| 604 |
+
nargs="+",
|
| 605 |
+
help="Optional model identifiers without provider prefixes; defaults to all models.",
|
| 606 |
+
)
|
| 607 |
+
parser.add_argument(
|
| 608 |
+
"--languages",
|
| 609 |
+
nargs="+",
|
| 610 |
+
help="Optional three-letter language codes in display order; defaults to all discovered languages.",
|
| 611 |
+
)
|
| 612 |
+
parser.add_argument(
|
| 613 |
+
"--samples",
|
| 614 |
+
type=int,
|
| 615 |
+
default=2_000,
|
| 616 |
+
help="Number of synthetic benchmark sets to sample.",
|
| 617 |
+
)
|
| 618 |
+
parser.add_argument("--seed", type=int, default=0)
|
| 619 |
+
parser.add_argument(
|
| 620 |
+
"--scorer",
|
| 621 |
+
help="Inspect scorer name; defaults to math, pattern, then the first numeric score.",
|
| 622 |
+
)
|
| 623 |
+
parser.add_argument(
|
| 624 |
+
"--output-name",
|
| 625 |
+
help="Optional filename prefix; model identifiers are always appended.",
|
| 626 |
+
)
|
| 627 |
+
parser.add_argument(
|
| 628 |
+
"--workers",
|
| 629 |
+
type=int,
|
| 630 |
+
default=max(12, cpu_count),
|
| 631 |
+
help="Processes used for full log loading; use 1 to disable multiprocessing.",
|
| 632 |
+
)
|
| 633 |
+
parser.add_argument(
|
| 634 |
+
"--header-workers",
|
| 635 |
+
type=int,
|
| 636 |
+
default=min(32, max(4, cpu_count * 2)),
|
| 637 |
+
help="Threads used to inspect and deduplicate log headers.",
|
| 638 |
+
)
|
| 639 |
+
args = parser.parse_args()
|
| 640 |
+
|
| 641 |
+
if args.samples < 2:
|
| 642 |
+
parser.error("--samples must be at least 2")
|
| 643 |
+
if args.workers < 1 or args.header_workers < 1:
|
| 644 |
+
parser.error("--workers and --header-workers must be at least 1")
|
| 645 |
+
|
| 646 |
+
paths = discover_selected_logs(args.log_dir, args.model, args.header_workers)
|
| 647 |
+
if not paths:
|
| 648 |
+
requested = f" for models {args.model!r}" if args.model else ""
|
| 649 |
+
raise SystemExit(f"No successful logs found{requested} in {args.log_dir}.")
|
| 650 |
+
|
| 651 |
+
print(f"Selected {len(paths)} successful logs after deduplication.")
|
| 652 |
+
print(f"Loading logs with {args.workers} worker process(es).")
|
| 653 |
+
problems = load_problem_scores(paths, args.scorer, args.workers)
|
| 654 |
+
if problems.empty:
|
| 655 |
+
raise SystemExit("No scored samples found in the selected logs.")
|
| 656 |
+
|
| 657 |
+
models = sorted(problems["model"].unique(), key=lambda model: (model_family(model), model.lower()))
|
| 658 |
+
all_languages = language_order(set(problems["language"].unique()), args.languages)
|
| 659 |
+
print(f"Models ({len(models)}): {', '.join(models)}")
|
| 660 |
+
print(f"Languages ({len(all_languages)}): {', '.join(all_languages)}")
|
| 661 |
+
|
| 662 |
+
output_root = folder / "language_ridgeline"
|
| 663 |
+
for model_index, model in enumerate(models):
|
| 664 |
+
model_problems = problems[problems["model"] == model]
|
| 665 |
+
model_languages = language_order(
|
| 666 |
+
set(model_problems["language"].unique()),
|
| 667 |
+
args.languages,
|
| 668 |
+
)
|
| 669 |
+
curves, stats = collect_plot_data(
|
| 670 |
+
model_problems,
|
| 671 |
+
model_languages,
|
| 672 |
+
args.samples,
|
| 673 |
+
args.seed + model_index,
|
| 674 |
+
)
|
| 675 |
+
if not stats:
|
| 676 |
+
print(f"Skipping {model}: no languages have paired original and synthetic results.")
|
| 677 |
+
continue
|
| 678 |
+
|
| 679 |
+
family = model_family(model)
|
| 680 |
+
out_dir = output_root / path_slug(family)
|
| 681 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 682 |
+
model_slug = path_slug(model)
|
| 683 |
+
base_name = f"{path_slug(args.output_name)}-{model_slug}" if args.output_name else model_slug
|
| 684 |
+
out_png = out_dir / f"{base_name}.png"
|
| 685 |
+
out_csv = out_dir / f"{base_name}.csv"
|
| 686 |
+
|
| 687 |
+
plot_distributions(curves, stats, model, out_png)
|
| 688 |
+
write_summary(stats, out_csv)
|
| 689 |
+
|
| 690 |
+
print(f"Saved {out_png}")
|
| 691 |
+
print(f"Saved {out_csv}")
|
| 692 |
+
|
| 693 |
+
|
| 694 |
+
if __name__ == "__main__":
|
| 695 |
+
main()
|
ucloudeval
CHANGED
|
@@ -20,14 +20,18 @@ MODELS = (
|
|
| 20 |
"Qwen/Qwen2.5-7B-Instruct",
|
| 21 |
"Qwen/Qwen2.5-14B-Instruct",
|
| 22 |
"Qwen/Qwen2.5-32B-Instruct",
|
| 23 |
-
"allenai/
|
| 24 |
-
"allenai/
|
|
|
|
|
|
|
| 25 |
"google/gemma-3-1b-it",
|
| 26 |
"google/gemma-3-4b-it",
|
| 27 |
"google/gemma-3-12b-it",
|
| 28 |
"google/gemma-3-27b-it",
|
| 29 |
-
"
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
)
|
| 32 |
# Repository id (no revision) and optional revision to apply to each task
|
| 33 |
DATASET = "danish-foundation-models/multilingual-gsm-symbolic"
|
|
|
|
| 20 |
"Qwen/Qwen2.5-7B-Instruct",
|
| 21 |
"Qwen/Qwen2.5-14B-Instruct",
|
| 22 |
"Qwen/Qwen2.5-32B-Instruct",
|
| 23 |
+
"allenai/OLMo-2-0425-1B-Instruct",
|
| 24 |
+
"allenai/OLMo-2-1124-7B-Instruct",
|
| 25 |
+
"allenai/OLMo-2-1124-13B-Instruct",
|
| 26 |
+
"allenai/OLMo-2-0325-32B-Instruct",
|
| 27 |
"google/gemma-3-1b-it",
|
| 28 |
"google/gemma-3-4b-it",
|
| 29 |
"google/gemma-3-12b-it",
|
| 30 |
"google/gemma-3-27b-it",
|
| 31 |
+
"meta-llama/Llama-3.2-1B-Instruct",
|
| 32 |
+
"meta-llama/Llama-3.2-3B-Instruct",
|
| 33 |
+
"meta-llama/Llama-3.1-8B-Instruct",
|
| 34 |
+
"swiss-ai/Apertus-8B-Instruct-2509",
|
| 35 |
)
|
| 36 |
# Repository id (no revision) and optional revision to apply to each task
|
| 37 |
DATASET = "danish-foundation-models/multilingual-gsm-symbolic"
|