Download plot_pass_at_k.py from tokenintelligence/LiveCodeBench-SnapShot-0406: direct link, hf CLI and curl.
- Browser
- Download file 2.24 kB
-
https://huggingface.co/datasets/tokenintelligence/LiveCodeBench-SnapShot-0406/resolve/main/plot_pass_at_k.py
- Command line
-
hf download hf://datasets/tokenintelligence/LiveCodeBench-SnapShot-0406/plot_pass_at_k.py
-
curl -L -o plot_pass_at_k.py https://huggingface.co/datasets/tokenintelligence/LiveCodeBench-SnapShot-0406/resolve/main/plot_pass_at_k.py
2.24 kB
| import json | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| def load_graded(path): | |
| with open(path) as f: | |
| data = json.load(f) | |
| return [item["graded_list"] for item in data] | |
| datasets = [ | |
| ("Qwen3-4B-Base", "output/Qwen3-4B-Base/Scenario.codegeneration_16_0.6_eval_all.json"), | |
| ("ftajwar (MaxRL 1000)", "output/ftajwar/qwen3_4B_Base_MaxRL_Polaris_1000_steps/Scenario.codegeneration_16_0.6_eval_all.json"), | |
| ("ftajwar (GRPO 1000)", "output/ftajwar/qwen3_4B_Base_GRPO_Polaris_1000_steps/Scenario.codegeneration_16_0.6_eval_all.json"), | |
| ] | |
| def bootstrap_pass_at_k(graded_lists, k, n_bootstrap=10000, rng=None): | |
| """Bootstrapping estimator for pass@k averaged over problems.""" | |
| if rng is None: | |
| rng = np.random.default_rng(42) | |
| problem_scores = [] | |
| for outcomes in graded_lists: | |
| outcomes_arr = np.array(outcomes, dtype=bool) | |
| n = len(outcomes_arr) | |
| # Sample k indices with replacement, check if any pass | |
| samples = rng.integers(0, n, size=(n_bootstrap, k)) | |
| any_pass = outcomes_arr[samples].any(axis=1) | |
| problem_scores.append(any_pass.mean()) | |
| return np.mean(problem_scores) | |
| k_values = [1, 2, 4, 8, 16] | |
| fig, ax = plt.subplots(figsize=(8, 5)) | |
| all_values = [] | |
| for label, path in datasets: | |
| graded = load_graded(path) | |
| rng = np.random.default_rng(42) | |
| pass_at_k = [bootstrap_pass_at_k(graded, k, rng=rng) for k in k_values] | |
| all_values.extend(pass_at_k) | |
| print(f"\n{label}:") | |
| for k, v in zip(k_values, pass_at_k): | |
| print(f" pass@{k}: {v:.4f}") | |
| line, = ax.plot(k_values, pass_at_k, marker="o", linewidth=2, markersize=8, label=label) | |
| for k, v in zip(k_values, pass_at_k): | |
| ax.annotate(f"{v:.3f}", (k, v), textcoords="offset points", xytext=(5, 6), | |
| fontsize=8, color=line.get_color()) | |
| ax.set_xscale("log", base=2) | |
| ax.set_xticks(k_values) | |
| ax.set_xticklabels([str(k) for k in k_values]) | |
| ax.set_xlabel("k", fontsize=12) | |
| ax.set_ylabel("pass@k", fontsize=12) | |
| ax.set_title("pass@k (bootstrapping estimator)", fontsize=13) | |
| ax.set_ylim(0, max(all_values) * 1.3) | |
| ax.legend(fontsize=10) | |
| ax.grid(True, alpha=0.3) | |
| plt.tight_layout() | |
| plt.savefig("instruct.png", dpi=150) | |
| print("\nSaved instruct.png") | |