Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/eval_framework/benchmarks/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Grade-school science multiple-choice questions, split into the ARC-Easy and ARC-Challenge subjects. The
base task scores the full answer text (cloze); the OLMES variant shows the options as space-prefixed
lettered choices and scores the letters; the IDK variant lets the model abstain with "I do not know".
lettered choices and scores the letters; the BPB variant uses the cloze prompt but scores only the BPB of the
gold answer; the IDK variant lets the model abstain with "I do not know".
"""

from typing import Any, final, override
Expand All @@ -13,7 +14,7 @@
from eval_framework.subjects import ListOfSubjects
from eval_framework.tasks.dataset_loading import DatasetPolicy
from eval_framework.tasks.dataset_revisions import pinned_by_framework
from eval_framework.tasks.task_style import ClozeStyle, MCStyle, TaskStyler, answer_key_to_index
from eval_framework.tasks.task_style import BPBStyle, ClozeStyle, MCStyle, TaskStyler, answer_key_to_index

_IDK_PREAMBLE = (
"Answer only if you are confident, since mistakes may be penalised, while correct answers receive points. "
Expand Down Expand Up @@ -57,11 +58,15 @@ def arc_olmes(dataset: DatasetPolicy | None = None) -> Benchmark:
return _arc_benchmark("ARC_OLMES", styler, dataset)


def arc_bpb(dataset: DatasetPolicy | None = None) -> Benchmark:
return _arc_benchmark("ARC_AllenAI_EN_BPB", BPBStyle(question_prefix="Question: ", cue_text="Answer:"), dataset)


def arc_idk(dataset: DatasetPolicy | None = None) -> Benchmark:
styler = ClozeStyle(
question_prefix="Question: ", cue_text="Answer:", initial_prompt=lambda _subject: _IDK_PREAMBLE
).with_abstention_option(" I do not know.")
return _arc_benchmark("ARC_IDK", styler, dataset)


ARC_BENCHMARKS: list[Benchmark] = [arc(), arc_olmes(), arc_idk()]
ARC_BENCHMARKS: list[Benchmark] = [arc(), arc_olmes(), arc_bpb(), arc_idk()]
89 changes: 85 additions & 4 deletions src/eval_framework/benchmarks/global_mmlu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
"""Global-MMLU: https://huggingface.co/datasets/CohereLabs/Global-MMLU

MMLU translated into many languages; we evaluate French, German, Spanish, Italian, Portuguese and Arabic.

Variants:

- ``GlobalMMLU`` / ``GlobalMMLU_German``: multiple choice over all languages / German only, scored over the
letter labels. The language is part of each subject label, so these use a hand-written kind.
- ``GlobalMMLU_Cohere_{lang}_BPB`` / ``GlobalMMLULite_Cohere_{lang}_BPB``: one task per language (e.g.
``GlobalMMLU_Cohere_DE_BPB``), options hidden, BPB of the gold option's full text. Global-MMLU-Lite
(https://huggingface.co/datasets/CohereLabs/Global-MMLU-Lite) is a 400-question subset per language.
"""

import ast
Expand All @@ -12,6 +20,7 @@
from eval_framework.answer import PickFromCandidates
from eval_framework.benchmarks.mmlu import MMLU_SUBJECTS
from eval_framework.benchmarks.utils.global_mmlu_languages import GLOBAL_MMLU_LOCALES
from eval_framework.choices import ChoiceFields, ChoiceReader
from eval_framework.composed import ComposedBenchmark
from eval_framework.contract import Benchmark
from eval_framework.eval_kind import EvalKind, SampleBody, assemble_messages
Expand All @@ -26,6 +35,7 @@
from eval_framework.subjects import ListOfSubjects
from eval_framework.tasks.dataset_loading import DatasetLoader, DatasetPolicy
from eval_framework.tasks.dataset_revisions import pinned_by_framework
from eval_framework.tasks.task_style import BPBStyle
from eval_framework.tasks.utils import get_n_letters
from template_formatting.formatter import Message

Expand All @@ -35,6 +45,28 @@
GLOBAL_MMLU_DATASET_PATH = "CohereLabs/Global-MMLU"
GLOBAL_MMLU_LANGUAGES = ["fr", "de", "es", "it", "pt", "ar", "nl", "pl", "tr", "ru", "uk", "ro"]

GLOBAL_MMLU_LITE_DATASET_PATH = "CohereLabs/Global-MMLU-Lite"
# Our languages that Global-MMLU-Lite also has (it lacks nl, pl, tr, ru, uk and ro).
GLOBAL_MMLU_LITE_LANGUAGES = ["fr", "de", "es", "it", "pt", "ar"]
# Lite's test split covers only 43 of the 57 MMLU subjects (the same ones in every language).
_LITE_MISSING_SUBJECTS = {
"abstract_algebra",
"anatomy",
"clinical_knowledge",
"college_computer_science",
"college_physics",
"computer_security",
"conceptual_physics",
"econometrics",
"formal_logic",
"high_school_biology",
"machine_learning",
"medical_genetics",
"moral_scenarios",
"world_religions",
}
GLOBAL_MMLU_LITE_SUBJECTS = [subject for subject in MMLU_SUBJECTS if subject not in _LITE_MISSING_SUBJECTS]

_OPTION_KEYS = {"A": "option_a", "B": "option_b", "C": "option_c", "D": "option_d"}
_KEYS = get_n_letters(4) # A, B, C, D

Expand Down Expand Up @@ -81,16 +113,17 @@ class _GlobalMmluDataset(DatasetPolicy):
"""Global-MMLU's data policy: each subject is a ``(language, subject)`` pair — config by language,
filtered by the ``subject`` column."""

def __init__(self, inner: DatasetPolicy) -> None:
def __init__(self, inner: DatasetPolicy, dataset_path: str) -> None:
self._inner = inner
self._dataset_path = dataset_path

@override
def loader(self, custom_hf_revision: str | None) -> DatasetLoader:
return _GlobalMmluLoader(self._inner.loader(custom_hf_revision))

@override
def documentation(self) -> str:
url = f"https://huggingface.co/datasets/{GLOBAL_MMLU_DATASET_PATH}"
url = f"https://huggingface.co/datasets/{self._dataset_path}"
return (
f"- Link to dataset: [{url}]({url})\n"
"- Each subject is a `(language, subject)` pair: the language selects the config, and the subject "
Expand Down Expand Up @@ -142,7 +175,11 @@ def _global_mmlu_demo(row: dict[str, Any]) -> FewshotExample:


def _global_mmlu_dataset(dataset: DatasetPolicy | None) -> DatasetPolicy:
return dataset if dataset is not None else _GlobalMmluDataset(pinned_by_framework(GLOBAL_MMLU_DATASET_PATH))
return dataset if dataset is not None else _global_mmlu_pinned(GLOBAL_MMLU_DATASET_PATH)


def _global_mmlu_pinned(dataset_path: str) -> DatasetPolicy:
return _GlobalMmluDataset(pinned_by_framework(dataset_path), dataset_path)


def _global_mmlu(id: str, subjects: ListOfSubjects, dataset: DatasetPolicy | None) -> Benchmark:
Expand All @@ -167,4 +204,48 @@ def global_mmlu_german(dataset: DatasetPolicy | None = None) -> Benchmark:
return _global_mmlu("GlobalMMLU_German", subjects, dataset)


GLOBAL_MMLU_BENCHMARKS: list[Benchmark] = [global_mmlu(), global_mmlu_german()]
# --- per-language BPB variants ------------------------------------------------------------------------------


@final
class GlobalMmluReader(ChoiceReader):
"""Reads a Global-MMLU (or -Lite) item: the question, its four options and the gold letter as an index."""

@override
def read(self, item: dict[str, Any]) -> ChoiceFields:
return ChoiceFields(
raw_question=item["question"].strip(),
choices=[item[_OPTION_KEYS[key]] for key in _KEYS],
correct_index=_KEYS.index(item["answer"]),
)


def global_mmlu_bpb(language: str, lite: bool = False, dataset: DatasetPolicy | None = None) -> Benchmark:
"""Build ``GlobalMMLU[Lite]_Cohere_{language}_BPB``, e.g. ``global_mmlu_bpb("de")``: the localized cloze prompt
(no options, no "multiple choice" in the preamble), scoring only the gold option's full text."""
locale = GLOBAL_MMLU_LOCALES[language]
styler = BPBStyle(
question_prefix=f"{locale.question_label}: ",
cue_text=f"{locale.answer_label}:",
initial_prompt=lambda subject_label: locale.cloze_preamble(_lang_and_subject(subject_label)[1]),
)
subjects = GLOBAL_MMLU_LITE_SUBJECTS if lite else MMLU_SUBJECTS
dataset_path = GLOBAL_MMLU_LITE_DATASET_PATH if lite else GLOBAL_MMLU_DATASET_PATH
return ComposedBenchmark.choice(
id=f"GlobalMMLU{'Lite' if lite else ''}_Cohere_{language.upper()}_BPB",
reader=GlobalMmluReader(),
styler=styler,
sample_split="test",
fewshot_split="dev",
# Same (language, subject) labels as the multiple-choice tasks, so the same loader serves them.
subjects=ListOfSubjects([str((language, subject)) for subject in subjects]),
dataset_policy=dataset if dataset is not None else _global_mmlu_pinned(dataset_path),
)


GLOBAL_MMLU_BENCHMARKS: list[Benchmark] = [
global_mmlu(),
global_mmlu_german(),
*(global_mmlu_bpb(language) for language in GLOBAL_MMLU_LANGUAGES),
*(global_mmlu_bpb(language, lite=True) for language in GLOBAL_MMLU_LITE_LANGUAGES),
]
12 changes: 9 additions & 3 deletions src/eval_framework/benchmarks/goldenswag.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""GoldenSwag: https://huggingface.co/datasets/PleIAs/GoldenSwag

A curated subset of HellaSwag, read identically (sentence completion, scored as cloze — see
``HellaswagReader``). ``GoldenSwag_IDK`` additionally lets the model abstain with an "I do not know" answer.
``HellaswagReader``). ``GoldenSwag_PleIAs_EN_BPB`` scores only the BPB of the gold ending. ``GoldenSwag_IDK``
additionally lets the model abstain with an "I do not know" answer.
"""

from eval_framework.benchmarks.hellaswag import HellaswagReader
from eval_framework.composed import ComposedBenchmark
from eval_framework.contract import Benchmark
from eval_framework.tasks.dataset_loading import DatasetPolicy
from eval_framework.tasks.dataset_revisions import pinned_by_framework
from eval_framework.tasks.task_style import ClozeStyle, TaskStyler
from eval_framework.tasks.task_style import BPBStyle, ClozeStyle, TaskStyler

_IDK_PREAMBLE = (
"Complete the sentence only if you are confident, since mistakes may be penalised, while correct "
Expand All @@ -35,6 +36,11 @@ def goldenswag(dataset: DatasetPolicy | None = None) -> Benchmark:
return _goldenswag_benchmark("GoldenSwag", cloze, dataset)


def goldenswag_bpb(dataset: DatasetPolicy | None = None) -> Benchmark:
bpb = BPBStyle(question_prefix="", cue_text="", trailing_newline=False)
return _goldenswag_benchmark("GoldenSwag_PleIAs_EN_BPB", bpb, dataset)


def goldenswag_idk(dataset: DatasetPolicy | None = None) -> Benchmark:
cloze = ClozeStyle(
question_prefix="", cue_text="", trailing_newline=False, initial_prompt=lambda _subject: _IDK_PREAMBLE
Expand All @@ -43,4 +49,4 @@ def goldenswag_idk(dataset: DatasetPolicy | None = None) -> Benchmark:
return _goldenswag_benchmark("GoldenSwag_IDK", styler, dataset)


GOLDENSWAG_BENCHMARKS: list[Benchmark] = [goldenswag(), goldenswag_idk()]
GOLDENSWAG_BENCHMARKS: list[Benchmark] = [goldenswag(), goldenswag_bpb(), goldenswag_idk()]
15 changes: 13 additions & 2 deletions src/eval_framework/benchmarks/mmlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

* ``MMLU`` / ``MMLU_OLMES`` — score the letter labels; OLMES adds a space before each option label.
* ``Full Text MMLU`` — shows the options as a bulleted list and scores the full answer text.
* ``MMLU_CAIS_EN_BPB`` — hides the options (cloze prompt) and scores the BPB of the gold answer's full text.
* ``MMLU_IDK`` — lets the model abstain with ``"?"`` and reports confidence-aware metrics.
* ``MMLU_COT`` — the model reasons freely and concludes with the answer, which is regex-extracted from
the generation (free-form completion, 0-shot).
Expand All @@ -23,7 +24,7 @@
from eval_framework.subjects import ListOfSubjects
from eval_framework.tasks.dataset_loading import DatasetPolicy
from eval_framework.tasks.dataset_revisions import pinned_by_framework
from eval_framework.tasks.task_style import ClozeStyle, MCStyle, TaskStyler
from eval_framework.tasks.task_style import BPBStyle, ClozeStyle, MCStyle, TaskStyler
from eval_framework.tasks.utils import get_n_letters

# The 57 MMLU subjects; each is an HF config of ``cais/mmlu`` (also reused by GlobalMMLU).
Expand Down Expand Up @@ -127,6 +128,11 @@ def _full_text_preamble(subject_label: str) -> str:
)


def _bpb_preamble(subject_label: str) -> str:
# The options are hidden, so unlike the MC preamble it must not claim multiple choice.
return f"The following are questions (with answers) about {_humanized(subject_label)}."


def _idk_preamble(subject_label: str) -> str:
# Unlike the other variants, the IDK preamble names the subject by its raw (underscored) key.
return (
Expand Down Expand Up @@ -191,6 +197,11 @@ def mmlu_full_text(dataset: DatasetPolicy | None = None) -> Benchmark:
return _mmlu_choice("FullTextMMLU", styler, dataset, display_name="Full Text MMLU")


def mmlu_bpb(dataset: DatasetPolicy | None = None) -> Benchmark:
styler = BPBStyle(question_prefix="Question: ", cue_text="Answer:", initial_prompt=_bpb_preamble)
return _mmlu_choice("MMLU_CAIS_EN_BPB", styler, dataset)


def mmlu_idk(dataset: DatasetPolicy | None = None) -> Benchmark:
styler = MCStyle(
question_prefix="Question: ", cue_text="Answer:", initial_prompt=_idk_preamble
Expand All @@ -216,4 +227,4 @@ def mmlu_cot(dataset: DatasetPolicy | None = None) -> Benchmark:
)


MMLU_BENCHMARKS: list[Benchmark] = [mmlu(), mmlu_olmes(), mmlu_full_text(), mmlu_idk(), mmlu_cot()]
MMLU_BENCHMARKS: list[Benchmark] = [mmlu(), mmlu_olmes(), mmlu_full_text(), mmlu_bpb(), mmlu_idk(), mmlu_cot()]
4 changes: 4 additions & 0 deletions src/eval_framework/benchmarks/mmlu_prox.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def cloze_preamble(self, subject: str) -> str:
"physics": "Physik",
"psychology": "Psychologie",
},
# XXX: "Die folgenden sind ..." is a stiff, literal translation of MMLU's English preamble (lm-eval uses
# "Im Folgenden sind ..."); it is kept so results stay comparable to earlier runs (#1372). Remove once both
# German preambles are reworded (e.g. "Es folgen Fragen (mit Antworten) zu {category}."), a prompt change
# of its own PR that should also reword Global-MMLU's German preambles, which share this wording.
mc_template="Die folgenden sind Multiple-Choice-Fragen (mit Antworten) über {category}.",
cloze_template="Die folgenden sind Fragen (mit Antworten) über {category}.",
),
Expand Down
18 changes: 15 additions & 3 deletions src/eval_framework/benchmarks/piqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

Each item is a goal with two candidate solutions (``sol1``, ``sol2``); ``label`` selects the correct one.
The base task scores the full solution text (cloze); the OLMES variant shows the solutions as lettered
options (multiple choice); the IDK variant lets the model abstain with an "I do not know" answer.
options (multiple choice); the BPB variant uses the OLMES ``Goal:`` prompt without the options and scores only
the BPB of the gold solution (validation split, train fewshots); the IDK variant lets the model abstain with an
"I do not know" answer.
"""

from typing import Any, final, override
Expand All @@ -14,7 +16,7 @@
from eval_framework.contract import Benchmark
from eval_framework.tasks.dataset_loading import DatasetPolicy
from eval_framework.tasks.dataset_revisions import pinned_frozen
from eval_framework.tasks.task_style import ClozeStyle, MCStyle, TaskStyler
from eval_framework.tasks.task_style import BPBStyle, ClozeStyle, MCStyle, TaskStyler

_IDK_PREAMBLE = (
"Complete the sentence only if you are confident, since mistakes may be penalised, while correct "
Expand Down Expand Up @@ -69,6 +71,16 @@ def piqa_olmes(dataset: DatasetPolicy | None = None) -> Benchmark:
)


def piqa_bpb(dataset: DatasetPolicy | None = None) -> Benchmark:
return _piqa_benchmark(
"PIQA_AllenAI_EN_BPB",
BPBStyle(question_prefix="Goal: "),
Comment thread
fsschneider marked this conversation as resolved.
Resolved
sample_split="validation",
fewshot_split="train",
dataset=dataset,
)


def piqa_idk(dataset: DatasetPolicy | None = None) -> Benchmark:
return _piqa_benchmark(
"PIQA_IDK",
Expand All @@ -79,4 +91,4 @@ def piqa_idk(dataset: DatasetPolicy | None = None) -> Benchmark:
)


PIQA_BENCHMARKS: list[Benchmark] = [piqa(), piqa_olmes(), piqa_idk()]
PIQA_BENCHMARKS: list[Benchmark] = [piqa(), piqa_olmes(), piqa_bpb(), piqa_idk()]
Loading