"""Score GauntletScore's LLM-AggreFact test-split predictions the leaderboard's way. Balanced accuracy per dataset, times 100, then the plain mean over the 11 datasets, as in the leaderboard's evaluation notebook (github.com/Liyan06/MiniCheck, benchmark_evaluation_demo.ipynb). The labels are read from the official test split at a pinned revision; this repository contains no claim, document or label from the dataset. Usage: python score.py # downloads the pinned test split from Hugging Face python score.py --parquet PATH # uses a local copy of data/test-00000-of-00001.parquet Requires pandas and pyarrow; huggingface_hub for the download. scikit-learn is used if installed, otherwise the same balanced accuracy (mean of the true-positive and true-negative rates) is computed directly. """ from __future__ import annotations import argparse import hashlib from pathlib import Path import pandas as pd REPO_ID = "lytang/LLM-AggreFact" REVISION = "981dfd0bd8e58e7238a9ab92b2e6ea44bce918e4" FILENAME = "data/test-00000-of-00001.parquet" SHA256 = "ba6976c3da990a9d7b11670efaf4e3c93c1bd0530061ec742afd6b2d5bce698c" HERE = Path(__file__).resolve().parent def balanced_accuracy(y_true, y_pred) -> float: try: from sklearn.metrics import balanced_accuracy_score return balanced_accuracy_score(y_true, y_pred) except ImportError: pairs = list(zip(y_true, y_pred)) recalls = [] for cls in sorted(set(y_true)): hits = [p == cls for t, p in pairs if t == cls] recalls.append(sum(hits) / len(hits)) return sum(recalls) / len(recalls) def load_test(parquet: str | None) -> pd.DataFrame: if parquet is None: from huggingface_hub import hf_hub_download parquet = hf_hub_download(REPO_ID, FILENAME, repo_type="dataset", revision=REVISION) digest = hashlib.sha256(Path(parquet).read_bytes()).hexdigest() if digest != SHA256: raise SystemExit(f"test split hash {digest} differs from the pinned {SHA256}") return pd.read_parquet(parquet) def main() -> None: ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) ap.add_argument("--parquet", help="local copy of the test split parquet") ap.add_argument("--predictions", default=str(HERE / "predictions.csv")) args = ap.parse_args() df = load_test(args.parquet) sub = pd.read_csv(args.predictions) if list(sub["row_index"]) != list(range(len(df))) or list(sub["dataset"]) != list(df["dataset"]): raise SystemExit("predictions.csv does not line up with the test split's row order") df["preds"] = sub["preds"].values scores = {name: balanced_accuracy(g["label"].tolist(), g["preds"].tolist()) * 100 for name, g in df.groupby("dataset", sort=False)} average = sum(scores.values()) / len(scores) without_cnn = [v for k, v in scores.items() if k != "AggreFact-CNN"] w = 24 print(f"{'Dataset':<{w}}{'BAcc':>9}") for name, value in scores.items(): print(f"{name:<{w}}{value:>9.2f}") print(f"{'Average of 11':<{w}}{average:>9.2f}") print(f"{'Average of 10 (no CNN)':<{w}}{sum(without_cnn) / len(without_cnn):>9.2f}") print(f"Claims: {len(df):,}; predicted supported: {int(df['preds'].sum()):,}") if __name__ == "__main__": main()