Buckets:
| # /// script | |
| # requires-python = ">=3.12" | |
| # dependencies = ["matplotlib==3.10.8", "numpy==2.2.6", "huggingface-hub==1.31.0"] | |
| # /// | |
| """Plot completed evaluations with their frozen source revision.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| import matplotlib | |
| matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from huggingface_hub import hf_hub_download | |
| from matplotlib.patches import Patch | |
| from matplotlib.ticker import MultipleLocator | |
| REPO = "tomaarsen/encoder-comparison-20261014" | |
| OUTPUT = Path(__file__).resolve().parent / "plots" | |
| TASKS = ["dense", "multivector", "reranker"] | |
| GROUPS = [ | |
| ("150M parameters", ["modernbert-base", "ettin-encoder-150m", "ultrabert-150m"]), | |
| ("380M to 400M parameters", ["modernbert-large", "ettin-encoder-400m", "ultrabert-380m"]), | |
| ] | |
| COLORS = ["#8293A6", "#438BC0", "#E87832"] | |
| def main(): | |
| OUTPUT.mkdir(exist_ok=True) | |
| revision = "20fa7471e57123c320fae1e2ebb697a35829aefe" | |
| results = {} | |
| for _, models in GROUPS: | |
| for model in models: | |
| for task in TASKS: | |
| filename = f"results/{model}/{task}/selected.json" | |
| path = hf_hub_download(REPO, filename, repo_type="dataset", revision=revision) | |
| results[model, task] = json.loads(Path(path).read_text()) | |
| source = { | |
| "repository": REPO, | |
| "revision": revision, | |
| "metric": "Equally weighted mean nDCG@10 over NanoNQ, NanoFiQA2018 and NanoSciFact", | |
| "results": [ | |
| { | |
| "model": model, | |
| "task": task, | |
| "ndcg@10": r["mean_ndcg@10"], | |
| "selected_lr": r["selected_trial"]["lr"], | |
| } | |
| for (model, task), r in results.items() | |
| ], | |
| } | |
| (OUTPUT / "plot_data.json").write_text(json.dumps(source, indent=2), encoding="utf-8") | |
| plt.rcParams.update( | |
| { | |
| "font.family": "DejaVu Sans", | |
| "font.size": 11, | |
| "axes.titleweight": "bold", | |
| "text.color": "#172C41", | |
| "axes.labelcolor": "#172C41", | |
| "xtick.color": "#34485C", | |
| "ytick.color": "#536475", | |
| "svg.fonttype": "none", | |
| "pdf.fonttype": 42, | |
| } | |
| ) | |
| fig, axes = plt.subplots(1, 2, figsize=(14, 7.8), sharey=True) | |
| fig.patch.set_facecolor("#FFFFFF") | |
| fig.subplots_adjust(left=0.075, right=0.98, bottom=0.29, top=0.73, wspace=0.12) | |
| fig.text(0.075, 0.94, "Encoder comparison after equivalent retrieval fine-tuning", fontsize=22, fontweight="bold") | |
| fig.text( | |
| 0.075, | |
| 0.895, | |
| "UltraBERT achieves the highest mean score in all six comparisons across recipes and size groups", | |
| fontsize=13, | |
| color="#536475", | |
| ) | |
| fig.legend( | |
| handles=[ | |
| Patch(facecolor=color, label=name) for color, name in zip(COLORS, ["ModernBERT", "Ettin", "UltraBERT"]) | |
| ], | |
| loc="upper left", | |
| bbox_to_anchor=(0.069, 0.865), | |
| frameon=False, | |
| ncol=3, | |
| fontsize=12, | |
| handlelength=1.3, | |
| columnspacing=2.2, | |
| ) | |
| x = np.arange(3) | |
| width = 0.24 | |
| for ax, (title, models) in zip(axes, GROUPS): | |
| ax.set_title(title, loc="left", fontsize=15, pad=18) | |
| ax.set_axisbelow(True) | |
| ax.grid(axis="y", color="#E7ECF1", linewidth=0.9) | |
| for i, model in enumerate(models): | |
| values = [results[model, task]["mean_ndcg@10"] for task in TASKS] | |
| bars = ax.bar(x + (i - 1) * width, values, width=width * 0.9, color=COLORS[i], zorder=3) | |
| ax.bar_label( | |
| bars, | |
| labels=[f"{value:.3f}" for value in values], | |
| padding=6, | |
| fontsize=10, | |
| color="#AD4A12" if i == 2 else "#34485C", | |
| fontweight="bold" if i == 2 else "normal", | |
| ) | |
| ax.set_xticks(x, ["Dense", "Multi-Vector", "Reranker"], fontsize=12) | |
| ax.set_ylim(0, 0.75) | |
| ax.yaxis.set_major_locator(MultipleLocator(0.1)) | |
| ax.tick_params(axis="both", length=0, pad=9) | |
| for spine in ax.spines.values(): | |
| spine.set_visible(False) | |
| axes[0].set_ylabel("Mean nDCG@10 (higher is better)", labelpad=14) | |
| fig.text(0.075, 0.20, "Matched training budget", fontsize=11, fontweight="bold") | |
| fig.text( | |
| 0.075, | |
| 0.17, | |
| "32,768 MS MARCO triplets | Up to 1 epoch | 3 learning rates | Validation-selected checkpoints and LR", | |
| fontsize=10.5, | |
| color="#536475", | |
| ) | |
| fig.text( | |
| 0.075, | |
| 0.125, | |
| "Test: equally weighted NanoNQ, NanoFiQA2018 and NanoSciFact. One seed per LR, with matched recipes within each comparison.", | |
| fontsize=9.5, | |
| color="#536475", | |
| ) | |
| fig.text( | |
| 0.075, | |
| 0.098, | |
| "Dense and Multi-Vector search the full corpus. Rerankers score BM25 top-100 candidates. Training-seed uncertainty is not shown.", | |
| fontsize=9.5, | |
| color="#536475", | |
| ) | |
| for extension in ("png", "svg", "pdf"): | |
| path = OUTPUT / f"encoder_comparison.{extension}" | |
| fig.savefig(path, dpi=200, facecolor="white") | |
| print(path) | |
| plt.close(fig) | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 5.23 kB
- Xet hash:
- 3a3ce2d1c571e5b5c3c6c8e825c49640b113e8f36c2174e2fb1712d8325a8c57
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.