Skip to content

Latest commit

 

History

History
274 lines (210 loc) · 10.5 KB

README.md

File metadata and controls

274 lines (210 loc) · 10.5 KB

GAMUT Evaluation Harness

Rubric-graded evaluation for the GAMUT benchmark. You bring a file of model responses; an LLM judge scores each response against per-example rubrics using a 4-way verdict scheme (meets / partially_meets / missing / contradicts); the harness applies the weighted rubric scoring and reports a final metric plus a full breakdown.

The judge runs over the OpenAI Chat Completions API, which is the de-facto standard interface — the exact same command works against OpenAI, Azure OpenAI, and any OpenAI-compatible server (vLLM, SGLang, TGI, Together, Fireworks, Groq, OpenRouter, Ollama, …). Just point --base-url at your endpoint.

No proprietary dependencies — everything runs on public PyPI packages.


Installation

Requires Python ≥ 3.9. Dependencies are declared once at the repo root:

# from the repository root
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

Or install the whole project as a package (exposes a gamut-eval console command) from the repo root:

pip install -e .

Dependencies used by the harness: openai, pydantic, datasets (the latter only needed if you load the benchmark from HuggingFace; local files work without network access).


Quick start

export OPENAI_API_KEY=sk-...

python evaluate.py \
    --dataset facebook/GAMUT \        # HuggingFace name, or a local .jsonl/.csv
    --responses my_model_responses.jsonl \
    --judge-model gpt-4o \
    --output-dir results/my_model

Self-hosted / vLLM judge (OpenAI-compatible):

# vLLM: python -m vllm.entrypoints.openai.api_server --model Qwen/Qwen2.5-72B-Instruct
export OPENAI_API_KEY=EMPTY            # vLLM ignores the key but the client needs one

python evaluate.py \
    --dataset data/gamut.jsonl \
    --responses my_model_responses.jsonl \
    --judge-model Qwen/Qwen2.5-72B-Instruct \
    --base-url http://localhost:8000/v1 \
    --output-dir results/my_model

Smoke test with the bundled sample (needs a reachable judge endpoint):

python evaluate.py \
    --dataset examples/sample_dataset.jsonl \
    --responses examples/sample_responses.jsonl \
    --judge-model gpt-4o \
    --output-dir results/sample

Inputs

1. Dataset (ground-truth rubrics)

Either a HuggingFace dataset name (--dataset ORG/name [--split test] [--hf-config cfg]) or a local .jsonl / .csv file. Each example provides:

field required aliases description
id ✅ session_id Unique example id (used to join responses).
question ✅ prompt, query The question posed to the model.
rubrics ✅ rubric The rubric (JSON string or nested object).

Rubric schema (rubrics) — three weighted tiers, each a list of elements. Each element has an Ingredient (the requirement), a short Handle, and optional Specifics (supporting citations):

{
  "Question": "What species of tree is shown and its typical mature height?",
  "Answer Critical": [
    {
      "Handle": "Species",
      "Ingredient": "Identifies the tree as a coast redwood (Sequoia sempervirens).",
      "Specifics": [
        {"Text": "Sequoia sempervirens is the sole living species of the genus Sequoia.",
         "Citation": "s1"}
      ]
    },
    {"Handle": "MatureHeight",
     "Ingredient": "States a typical mature height of roughly 60–100 m.",
     "Specifics": []}
  ],
  "Valuable": [
    {"Handle": "Range", "Ingredient": "Notes the native U.S. Pacific-coast range.", "Specifics": []}
  ],
  "Context": [
    {"Handle": "Longevity", "Ingredient": "Mentions individuals can live over 1,000 years.", "Specifics": []}
  ]
}

In JSONL the rubrics value may be either the JSON object above or a JSON-encoded string of it (both are accepted). In CSV it must be a JSON string.

2. Model responses (what you're evaluating)

A local JSONL file, one object per line:

field required aliases description
id ✅ session_id Must match a dataset id.
response ✅ answer, model_answer, output, prediction The model's answer text.
{"id": "ex_0001", "response": "This is a coast redwood (Sequoia sempervirens)..."}
{"id": "ex_0002", "response": "The bridge is the Golden Gate Bridge, completed in 1937..."}

Extra fields are ignored. Dataset examples with no matching response are scored as an empty answer (and a warning is printed). The judge is text-only — it never sees images; the rubric encodes the ground truth.


Hyperparameters

Tier weights and the contradiction penalty are configurable:

flag default meaning
--weight-answer-critical 0.6 Weight of the Answer Critical tier.
--weight-valuable 0.3 Weight of the Valuable tier.
--weight-context 0.1 Weight of the Context tier.
--contradiction-penalty -2.0 Value assigned to a contradicts verdict.

Weights need not sum to 1 — for each example they are renormalized over the tiers that actually have rubric elements.

Judge / runtime controls: --temperature (default 0.0), --max-tokens (4096), --no-temperature (omit the temperature field for models that reject it), --concurrency (default 8), --max-retries (5), --timeout (180s), --limit (cap examples, for debugging), --api-key-env (env var name, default OPENAI_API_KEY).


Scoring

Each rubric element gets a verdict, mapped to a value (λ = partial credit, μ = contradiction penalty):

verdict value
meets +1.0
partially_meets +λ (+0.5)
missing 0.0
contradicts μ (-2.0)

Per-tier score over its verdicts, with M/P/S/C = counts of meets/partial/missing/contradicts:

score = (M + λ·P + μ·C) / (M + P + S + |μ|·C)

Per-example = weighted sum of per-tier scores (default weights Answer Critical = 0.6 / Valuable = 0.3 / Context = 0.1, renormalized over tiers that have rubric elements). Final metric = mean per-example score over all scored examples.

Notes:

  • If the judge returns fewer verdicts than a tier has elements, the missing ones are padded with missing (no free credit for skipped elements).
  • The contradiction penalty (μ = -2.0) means confident wrong answers can push a tier score negative.

Coverage guarantee (no silent drops)

The reported metric always covers every dataset example, or the run fails. Before computing a score the harness validates, and aborts with exit code 2 (writing a validation_report.json but no summary.json) if any of these would cause an example to be silently dropped or partially scored:

  • an example has no matching response, or a duplicate dataset/response id;
  • a response id has no matching dataset example (orphan);
  • the judge call errored or the output was truncated (finish_reason == "length", i.e. it hit --max-tokens) — truncated output is never accepted even if a partial JSON happens to parse;
  • the judge produced too few / too many verdicts for a tier (the verdict count must match the rubric element count), or used an unknown verdict value.

Verdicts are aligned to rubric elements by count within each tier (what the score is computed from); the rubric "handle" is a human-readable label only and is never used for matching.

The judge client itself re-requests on truncation / incomplete verdict sets (up to --max-retries) before giving up. Pass --allow-partial to downgrade these to warnings and report a metric over the subset anyway; in that case summary.json records "full_coverage": false and "n_problems" > 0.

Outputs

Written to --output-dir:

  • per_example_results.jsonl — one record per example with the input (id, question, response, rubrics), the judge's parsed judge_evaluations (tier, handle, verdict, justification), the raw judge text (judge_raw), the finish_reason, and any judge_error. Always written (even when the run aborts), so nothing is lost.
  • summary.json — run config, the final_score, full_coverage (bool), per-tier means, verdict totals, and counts (n_expected / n_total / n_scored / n_skipped / n_judge_errors / n_problems). Only written when a metric is reported (i.e. no problems, or --allow-partial).
  • validation_report.json — every coverage/integrity problem found (id, kind, detail). Always written.

The summary is also printed to stdout, ending with the FINAL SCORE.


Layout

evaluation/
├── evaluate.py            # CLI entry point
├── gamut_eval/
│   ├── data.py            # dataset + response loading (HF / jsonl / csv)
│   ├── rubric.py          # rubric schema, parsing, judge-prompt formatting
│   ├── judge.py           # judge prompt + OpenAI-compatible client
│   ├── scoring.py         # weighted rubric scoring + aggregate metrics
│   └── validation.py      # coverage + integrity checks (no silent drops)
├── tests/
│   ├── e2e_test.py            # end-to-end mock-inference + mock-judge test
│   ├── mock_openai_server.py  # mock OpenAI endpoint (injects failure modes)
│   └── test_validation.py     # validation unit tests
└── examples/              # tiny sample dataset + responses

# (dependencies + packaging live at the repo root: requirements.txt, pyproject.toml)

Run the end-to-end test (spins up a mock OpenAI-compatible judge; no network). Install deps from the repo root first (pip install -r requirements.txt), then:

python evaluation/tests/e2e_test.py

License

The GAMUT Dataset and this evaluation code are licensed CC-BY-NC-4.0 and are intended for benchmarking purposes only. See the LICENSE file in the repository root for the full license text.