diff --git a/src/eval_framework/benchmarks/arc.py b/src/eval_framework/benchmarks/arc.py index 426422c30..c7a28ded9 100644 --- a/src/eval_framework/benchmarks/arc.py +++ b/src/eval_framework/benchmarks/arc.py @@ -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 @@ -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. " @@ -57,6 +58,10 @@ 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 @@ -64,4 +69,4 @@ def arc_idk(dataset: DatasetPolicy | None = None) -> Benchmark: 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()] diff --git a/src/eval_framework/benchmarks/global_mmlu.py b/src/eval_framework/benchmarks/global_mmlu.py index 1772015c1..31266add9 100644 --- a/src/eval_framework/benchmarks/global_mmlu.py +++ b/src/eval_framework/benchmarks/global_mmlu.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -81,8 +113,9 @@ 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: @@ -90,7 +123,7 @@ def loader(self, custom_hf_revision: str | None) -> DatasetLoader: @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 " @@ -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: @@ -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), +] diff --git a/src/eval_framework/benchmarks/goldenswag.py b/src/eval_framework/benchmarks/goldenswag.py index f77313a71..a0d82adb3 100644 --- a/src/eval_framework/benchmarks/goldenswag.py +++ b/src/eval_framework/benchmarks/goldenswag.py @@ -1,7 +1,8 @@ """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 @@ -9,7 +10,7 @@ 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 " @@ -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 @@ -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()] diff --git a/src/eval_framework/benchmarks/mmlu.py b/src/eval_framework/benchmarks/mmlu.py index 2184120a9..1d5ff041b 100644 --- a/src/eval_framework/benchmarks/mmlu.py +++ b/src/eval_framework/benchmarks/mmlu.py @@ -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). @@ -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). @@ -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 ( @@ -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 @@ -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()] diff --git a/src/eval_framework/benchmarks/mmlu_prox.py b/src/eval_framework/benchmarks/mmlu_prox.py index 60c7b287b..9ebb05b66 100644 --- a/src/eval_framework/benchmarks/mmlu_prox.py +++ b/src/eval_framework/benchmarks/mmlu_prox.py @@ -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}.", ), diff --git a/src/eval_framework/benchmarks/piqa.py b/src/eval_framework/benchmarks/piqa.py index 5690f1c09..f9ee48bb4 100644 --- a/src/eval_framework/benchmarks/piqa.py +++ b/src/eval_framework/benchmarks/piqa.py @@ -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 @@ -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 " @@ -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: "), + sample_split="validation", + fewshot_split="train", + dataset=dataset, + ) + + def piqa_idk(dataset: DatasetPolicy | None = None) -> Benchmark: return _piqa_benchmark( "PIQA_IDK", @@ -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()] diff --git a/src/eval_framework/benchmarks/utils/global_mmlu_languages.py b/src/eval_framework/benchmarks/utils/global_mmlu_languages.py index cd2b16d52..336e504bf 100644 --- a/src/eval_framework/benchmarks/utils/global_mmlu_languages.py +++ b/src/eval_framework/benchmarks/utils/global_mmlu_languages.py @@ -56,6 +56,9 @@ class GlobalMMLULocale: subject_names: dict[str, str] preamble_template: str + """Opens a prompt that shows the answer options; ``{subject}`` is the subject name.""" + cloze_preamble_template: str + """Opens a prompt that hides the answer options (BPB), so it must not claim multiple choice.""" question_label: str answer_label: str @@ -64,12 +67,16 @@ def __post_init__(self) -> None: missing = sorted(set(MMLU_SUBJECTS) - set(self.subject_names)) extra = sorted(set(self.subject_names) - set(MMLU_SUBJECTS)) raise ValueError(f"subject_names must name exactly the MMLU subjects; missing {missing}, extra {extra}") - if "{subject}" not in self.preamble_template: - raise ValueError(f"preamble_template must contain '{{subject}}': {self.preamble_template!r}") + for template in (self.preamble_template, self.cloze_preamble_template): + if "{subject}" not in template: + raise ValueError(f"preamble templates must contain '{{subject}}': {template!r}") def preamble(self, subject: str) -> str: return self.preamble_template.format(subject=self.subject_names[subject]) + def cloze_preamble(self, subject: str) -> str: + return self.cloze_preamble_template.format(subject=self.subject_names[subject]) + # Keyed by Global-MMLU language config. GLOBAL_MMLU_LOCALES: dict[str, GlobalMMLULocale] = { @@ -134,6 +141,7 @@ def preamble(self, subject: str) -> str: "world_religions": "Religions du Monde", }, preamble_template="Les questions suivantes sont des questions à choix multiples (avec réponses) sur {subject}.", + cloze_preamble_template="Les questions suivantes sont des questions (avec réponses) sur {subject}.", question_label="Question", answer_label="Réponse", ), @@ -197,7 +205,12 @@ def preamble(self, subject: str) -> str: "virology": "Virologie", "world_religions": "Weltreligionen", }, + # XXX: "Die folgenden sind ..." is a stiff, literal translation of MMLU's English preamble with no upstream + # source; 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 {subject}."), a prompt change of its own PR that + # should also reword MMLU-ProX's German preambles, which share this wording. preamble_template="Die folgenden sind Multiple-Choice-Fragen (mit Antworten) über {subject}.", + cloze_preamble_template="Die folgenden sind Fragen (mit Antworten) über {subject}.", question_label="Frage", answer_label="Antwort", ), @@ -262,6 +275,7 @@ def preamble(self, subject: str) -> str: "world_religions": "Religiones del Mundo", }, preamble_template="Las siguientes son preguntas de opción múltiple (con respuestas) sobre {subject}.", + cloze_preamble_template="Las siguientes son preguntas (con respuestas) sobre {subject}.", question_label="Pregunta", answer_label="Respuesta", ), @@ -326,6 +340,7 @@ def preamble(self, subject: str) -> str: "world_religions": "Religioni del Mondo", }, preamble_template="Le seguenti sono domande a scelta multipla (con risposte) su {subject}.", + cloze_preamble_template="Le seguenti sono domande (con risposte) su {subject}.", question_label="Domanda", answer_label="Risposta", ), @@ -390,6 +405,7 @@ def preamble(self, subject: str) -> str: "world_religions": "Religiões Mundiais", }, preamble_template="As seguintes são perguntas de múltipla escolha (com respostas) sobre {subject}.", + cloze_preamble_template="As seguintes são perguntas (com respostas) sobre {subject}.", question_label="Pergunta", answer_label="Resposta", ), @@ -454,6 +470,7 @@ def preamble(self, subject: str) -> str: "world_religions": "الديانات العالمية", }, preamble_template="فيما يلي أسئلة اختيار من متعدد (مع الإجابات) حول {subject}.", + cloze_preamble_template="فيما يلي أسئلة (مع الإجابات) حول {subject}.", question_label="السؤال", answer_label="الإجابة", ), @@ -518,6 +535,7 @@ def preamble(self, subject: str) -> str: "world_religions": "wereldreligies", }, preamble_template="Hieronder volgen meerkeuzevragen (met antwoorden) over {subject}.", + cloze_preamble_template="Hieronder volgen vragen (met antwoorden) over {subject}.", question_label="Vraag", answer_label="Antwoord", ), @@ -582,6 +600,7 @@ def preamble(self, subject: str) -> str: "world_religions": "religie świata", }, preamble_template="Poniżej znajdują się pytania wielokrotnego wyboru (z odpowiedziami) dotyczące {subject}.", + cloze_preamble_template="Poniżej znajdują się pytania (z odpowiedziami) dotyczące {subject}.", question_label="Pytanie", answer_label="Odpowiedź", ), @@ -646,6 +665,7 @@ def preamble(self, subject: str) -> str: "world_religions": "мировые религии", }, preamble_template="Ниже приведены вопросы с множественным выбором (с ответами) по теме {subject}.", + cloze_preamble_template="Ниже приведены вопросы (с ответами) по теме {subject}.", question_label="Вопрос", answer_label="Ответ", ), @@ -710,6 +730,7 @@ def preamble(self, subject: str) -> str: "world_religions": "світові релігії", }, preamble_template="Нижче наведено запитання з множинним вибором (з відповідями) з теми {subject}.", + cloze_preamble_template="Нижче наведено запитання (з відповідями) з теми {subject}.", question_label="Запитання", answer_label="Відповідь", ), @@ -774,6 +795,7 @@ def preamble(self, subject: str) -> str: "world_religions": "dünya dinleri", }, preamble_template="Aşağıdakiler, {subject} hakkında çoktan seçmeli sorulardır (cevaplarıyla birlikte).", + cloze_preamble_template="Aşağıdakiler, {subject} hakkında sorulardır (cevaplarıyla birlikte).", question_label="Soru", answer_label="Cevap", ), @@ -838,6 +860,7 @@ def preamble(self, subject: str) -> str: "world_religions": "religii mondiale", }, preamble_template="Următoarele sunt întrebări cu variante de răspuns (cu răspunsuri) despre {subject}.", + cloze_preamble_template="Următoarele sunt întrebări (cu răspunsuri) despre {subject}.", question_label="Întrebare", answer_label="Răspuns", ), diff --git a/src/eval_framework/tasks/hf-dataset-revisions.json b/src/eval_framework/tasks/hf-dataset-revisions.json index 657543791..bc3b1c560 100644 --- a/src/eval_framework/tasks/hf-dataset-revisions.json +++ b/src/eval_framework/tasks/hf-dataset-revisions.json @@ -1,5 +1,6 @@ { "CohereLabs/Global-MMLU": "0e619dbeb34206cd48705a1a0ea7fb21cae09993", + "CohereLabs/Global-MMLU-Lite": "36c2fd756f19ccf13a9a96c8e53ccecc02192b8b", "CohereLabs/lbpp": "054f32b5c7a168003d230e34288f689955fd9866", "EleutherAI/drop": "619386fc7ffe6dace3cc6d3483c69b164ebf6bf3", "EleutherAI/hendrycks_math": "21a5633873b6a120296cce3e2df9d5550074f4a3", diff --git a/src/eval_framework/tasks/task_names.py b/src/eval_framework/tasks/task_names.py index 669ef8305..27fdaf28c 100644 --- a/src/eval_framework/tasks/task_names.py +++ b/src/eval_framework/tasks/task_names.py @@ -129,7 +129,7 @@ def register_math_reasoning_tasks(registry: Registry) -> None: def register_mmlu_tasks(registry: Registry) -> None: """Register mmlu benchmark tasks.""" - for benchmark in MMLU_BENCHMARKS: # composed: MMLU, MMLU_OLMES, FullTextMMLU, MMLU_IDK, MMLU_COT + for benchmark in MMLU_BENCHMARKS: # composed: MMLU, MMLU_OLMES, FullTextMMLU, MMLU_CAIS_EN_BPB, MMLU_IDK, MMLU_COT registry.add(benchmark) diff --git a/tests/tests_eval_framework/benchmarks/task-prompts-hashes.json b/tests/tests_eval_framework/benchmarks/task-prompts-hashes.json index eea9cd76c..8dfcea2ea 100644 --- a/tests/tests_eval_framework/benchmarks/task-prompts-hashes.json +++ b/tests/tests_eval_framework/benchmarks/task-prompts-hashes.json @@ -5,6 +5,9 @@ "ARC.ConcatFormatter": "5bd6320272965b8698986f8cd58f27e4", "ARC.Llama3Formatter": "72d16cae76c0f739583e6a4fa5f27f11", "ARC.NoStripConcatFormatter": "5bd6320272965b8698986f8cd58f27e4", + "ARC_AllenAI_EN_BPB.ConcatFormatter": "22e8b84ee9255f3ddcc66fe2099c7183", + "ARC_AllenAI_EN_BPB.Llama3Formatter": "464512c1af8e60537a9c68e43d8afbb2", + "ARC_AllenAI_EN_BPB.NoStripConcatFormatter": "22e8b84ee9255f3ddcc66fe2099c7183", "ARC_DE.ConcatFormatter": "dfab1e36603cb81696e44c2741347313", "ARC_DE.Llama3Formatter": "b4d91e79ce7a02a02c35b58b76c40af9", "ARC_DE.NoStripConcatFormatter": "dfab1e36603cb81696e44c2741347313", @@ -181,6 +184,60 @@ "GlobalMMLU.ConcatFormatter": "85ea2761878e7bf61a2d9c0ed44a460e", "GlobalMMLU.Llama3Formatter": "bf8fff177651c02c54ae5bde8336c9ce", "GlobalMMLU.NoStripConcatFormatter": "85ea2761878e7bf61a2d9c0ed44a460e", + "GlobalMMLULite_Cohere_AR_BPB.ConcatFormatter": "0afec554525df922e44f6987a2a41c97", + "GlobalMMLULite_Cohere_AR_BPB.Llama3Formatter": "ccfc36b9ac2f3a46b8b8b65c5a63e8d5", + "GlobalMMLULite_Cohere_AR_BPB.NoStripConcatFormatter": "0afec554525df922e44f6987a2a41c97", + "GlobalMMLULite_Cohere_DE_BPB.ConcatFormatter": "d092021ae6d4d280ff0c6ff2a77471dd", + "GlobalMMLULite_Cohere_DE_BPB.Llama3Formatter": "097be3d0ab482328d773dddb452083db", + "GlobalMMLULite_Cohere_DE_BPB.NoStripConcatFormatter": "d092021ae6d4d280ff0c6ff2a77471dd", + "GlobalMMLULite_Cohere_ES_BPB.ConcatFormatter": "6c67d9ff3e5417f1a6588546a6b5f94a", + "GlobalMMLULite_Cohere_ES_BPB.Llama3Formatter": "72ae5a8ec55f6a14326d4787b4cb282c", + "GlobalMMLULite_Cohere_ES_BPB.NoStripConcatFormatter": "6c67d9ff3e5417f1a6588546a6b5f94a", + "GlobalMMLULite_Cohere_FR_BPB.ConcatFormatter": "3d3d390eaa5135b8d8548f4c1df30444", + "GlobalMMLULite_Cohere_FR_BPB.Llama3Formatter": "92188b37d56e9a304d4c0126a363f2f5", + "GlobalMMLULite_Cohere_FR_BPB.NoStripConcatFormatter": "3d3d390eaa5135b8d8548f4c1df30444", + "GlobalMMLULite_Cohere_IT_BPB.ConcatFormatter": "46ac87c14b42763583e9fad9bb914d3d", + "GlobalMMLULite_Cohere_IT_BPB.Llama3Formatter": "32ce825fc5a4530be20b1a71d988f01f", + "GlobalMMLULite_Cohere_IT_BPB.NoStripConcatFormatter": "46ac87c14b42763583e9fad9bb914d3d", + "GlobalMMLULite_Cohere_PT_BPB.ConcatFormatter": "44d000d379e9175dca7740de090e420d", + "GlobalMMLULite_Cohere_PT_BPB.Llama3Formatter": "fe710d85c0731af971f77ad079b107d6", + "GlobalMMLULite_Cohere_PT_BPB.NoStripConcatFormatter": "44d000d379e9175dca7740de090e420d", + "GlobalMMLU_Cohere_AR_BPB.ConcatFormatter": "bfc032c60ebab35753e829df72974a02", + "GlobalMMLU_Cohere_AR_BPB.Llama3Formatter": "1b50069fee7d4eb3040279cda984bbd5", + "GlobalMMLU_Cohere_AR_BPB.NoStripConcatFormatter": "bfc032c60ebab35753e829df72974a02", + "GlobalMMLU_Cohere_DE_BPB.ConcatFormatter": "df49269b2a8c5b4b50dc3275ec3ad926", + "GlobalMMLU_Cohere_DE_BPB.Llama3Formatter": "4e67389cdf15dacabe771fe6c7915a51", + "GlobalMMLU_Cohere_DE_BPB.NoStripConcatFormatter": "df49269b2a8c5b4b50dc3275ec3ad926", + "GlobalMMLU_Cohere_ES_BPB.ConcatFormatter": "c236139aebc925c834ba2000aa1a983a", + "GlobalMMLU_Cohere_ES_BPB.Llama3Formatter": "bcbfe0e053bd52bc611070bbb226bcfe", + "GlobalMMLU_Cohere_ES_BPB.NoStripConcatFormatter": "c236139aebc925c834ba2000aa1a983a", + "GlobalMMLU_Cohere_FR_BPB.ConcatFormatter": "4d2a016fa6792793e4a851a67fa82b78", + "GlobalMMLU_Cohere_FR_BPB.Llama3Formatter": "d735f5c5651e375e0b29c98ad0f222c4", + "GlobalMMLU_Cohere_FR_BPB.NoStripConcatFormatter": "4d2a016fa6792793e4a851a67fa82b78", + "GlobalMMLU_Cohere_IT_BPB.ConcatFormatter": "8ab3b7bf0449d591dd19c26689465466", + "GlobalMMLU_Cohere_IT_BPB.Llama3Formatter": "7aa2834d0761342a1dce06a0b03c2b81", + "GlobalMMLU_Cohere_IT_BPB.NoStripConcatFormatter": "8ab3b7bf0449d591dd19c26689465466", + "GlobalMMLU_Cohere_NL_BPB.ConcatFormatter": "1a0fcca90663ed0e622247abdd57cbbf", + "GlobalMMLU_Cohere_NL_BPB.Llama3Formatter": "be69d7d5f6cf0d80dc6dff88f191a68b", + "GlobalMMLU_Cohere_NL_BPB.NoStripConcatFormatter": "1a0fcca90663ed0e622247abdd57cbbf", + "GlobalMMLU_Cohere_PL_BPB.ConcatFormatter": "0ee0d57925d40585fa737a17b8c6edba", + "GlobalMMLU_Cohere_PL_BPB.Llama3Formatter": "9c42217cae4dd64947eb846f2fd9eec5", + "GlobalMMLU_Cohere_PL_BPB.NoStripConcatFormatter": "0ee0d57925d40585fa737a17b8c6edba", + "GlobalMMLU_Cohere_PT_BPB.ConcatFormatter": "0337948eb830044ccf2af6ede0b01342", + "GlobalMMLU_Cohere_PT_BPB.Llama3Formatter": "3a430fef4679ec00d2ba8690343d0d34", + "GlobalMMLU_Cohere_PT_BPB.NoStripConcatFormatter": "0337948eb830044ccf2af6ede0b01342", + "GlobalMMLU_Cohere_RO_BPB.ConcatFormatter": "f58f7b20648a01c4a43db30ed2874629", + "GlobalMMLU_Cohere_RO_BPB.Llama3Formatter": "36b1a63fb32dbc799a2c4bd927eff866", + "GlobalMMLU_Cohere_RO_BPB.NoStripConcatFormatter": "f58f7b20648a01c4a43db30ed2874629", + "GlobalMMLU_Cohere_RU_BPB.ConcatFormatter": "81c1bf69d1093e42116d6a6b61550df4", + "GlobalMMLU_Cohere_RU_BPB.Llama3Formatter": "bf620f5a45e743dc407f3626df9142f2", + "GlobalMMLU_Cohere_RU_BPB.NoStripConcatFormatter": "81c1bf69d1093e42116d6a6b61550df4", + "GlobalMMLU_Cohere_TR_BPB.ConcatFormatter": "865ab6474bdc6f5485eec527d4685b95", + "GlobalMMLU_Cohere_TR_BPB.Llama3Formatter": "69f0e0d881469b6bf91034eeb36ea4d4", + "GlobalMMLU_Cohere_TR_BPB.NoStripConcatFormatter": "865ab6474bdc6f5485eec527d4685b95", + "GlobalMMLU_Cohere_UK_BPB.ConcatFormatter": "acfeefbba976518b8b9eb48b961b5d8e", + "GlobalMMLU_Cohere_UK_BPB.Llama3Formatter": "5fffdc560bdd69c4ec45669516fa8eef", + "GlobalMMLU_Cohere_UK_BPB.NoStripConcatFormatter": "acfeefbba976518b8b9eb48b961b5d8e", "GlobalMMLU_German.ConcatFormatter": "f6c08eeec8ba39b04937bba8717b14a3", "GlobalMMLU_German.Llama3Formatter": "73f90c386bf7fb3d35435f227b3dbda8", "GlobalMMLU_German.NoStripConcatFormatter": "f6c08eeec8ba39b04937bba8717b14a3", @@ -190,6 +247,9 @@ "GoldenSwag_IDK.ConcatFormatter": "59ce1a466cbe4e53055e3185d658e4d7", "GoldenSwag_IDK.Llama3Formatter": "2f0bf16b82db9a645d9a1c9fb710c0d1", "GoldenSwag_IDK.NoStripConcatFormatter": "59ce1a466cbe4e53055e3185d658e4d7", + "GoldenSwag_PleIAs_EN_BPB.ConcatFormatter": "87f873207eed866979bc67da68353d15", + "GoldenSwag_PleIAs_EN_BPB.Llama3Formatter": "07af3ac09e0bcbd33462de1736f0fb92", + "GoldenSwag_PleIAs_EN_BPB.NoStripConcatFormatter": "87f873207eed866979bc67da68353d15", "HELLASWAG.ConcatFormatter": "fb0db820785df792f9bb2c948d7fb4d6", "HELLASWAG.Llama3Formatter": "9b88a5a4b97c3287ef9750918a7d38e0", "HELLASWAG.NoStripConcatFormatter": "fb0db820785df792f9bb2c948d7fb4d6", @@ -531,6 +591,9 @@ "MMLUProX_LiLab_UK_MC.Llama3Formatter": "625a7190fb4e3a6e82624bcfa855888c", "MMLUProX_LiLab_UK_MC_OLMES.ConcatFormatter": "bc8f073bc62a8c25a4cbe68174b028c5", "MMLUProX_LiLab_UK_MC_OLMES.Llama3Formatter": "ee6f8f086b289deb09c883993338318a", + "MMLU_CAIS_EN_BPB.ConcatFormatter": "68d674d5e43ee53e7b447fd0356a2586", + "MMLU_CAIS_EN_BPB.Llama3Formatter": "f2599946fd838833bfbd2497194c7b5c", + "MMLU_CAIS_EN_BPB.NoStripConcatFormatter": "68d674d5e43ee53e7b447fd0356a2586", "MMLU_COT.ConcatFormatter": "6fee800bd04c46edc8b21d9740a314c6", "MMLU_COT.Llama3Formatter": "90761597023088acf12b9b69d276bdf4", "MMLU_COT.NoStripConcatFormatter": "6fee800bd04c46edc8b21d9740a314c6", @@ -600,6 +663,9 @@ "PIQA.ConcatFormatter": "1e096157843ec0f814ebe544c77b7fdd", "PIQA.Llama3Formatter": "96e11026cfefc1a5cff849dbd801543c", "PIQA.NoStripConcatFormatter": "1e096157843ec0f814ebe544c77b7fdd", + "PIQA_AllenAI_EN_BPB.ConcatFormatter": "104b691ad8b2e5483af96dcc0d9e612f", + "PIQA_AllenAI_EN_BPB.Llama3Formatter": "bf0c2d8ea208e1222bd0558625e15afc", + "PIQA_AllenAI_EN_BPB.NoStripConcatFormatter": "104b691ad8b2e5483af96dcc0d9e612f", "PIQA_ELLAMIND_BPB_DE.ConcatFormatter": "75b7bc44d27d7e81d3a859d237618815", "PIQA_ELLAMIND_BPB_DE.Llama3Formatter": "301c85d9c2a4411877cf5e804979ad41", "PIQA_ELLAMIND_BPB_DE.NoStripConcatFormatter": "75b7bc44d27d7e81d3a859d237618815", diff --git a/tests/tests_eval_framework/benchmarks/test_arc.py b/tests/tests_eval_framework/benchmarks/test_arc.py index 33b8f64ee..52d658d6c 100644 --- a/tests/tests_eval_framework/benchmarks/test_arc.py +++ b/tests/tests_eval_framework/benchmarks/test_arc.py @@ -12,7 +12,7 @@ import pytest -from eval_framework.benchmarks.arc import _IDK_PREAMBLE, ARC_BENCHMARKS, arc, arc_idk, arc_olmes +from eval_framework.benchmarks.arc import _IDK_PREAMBLE, ARC_BENCHMARKS, arc, arc_bpb, arc_idk, arc_olmes from eval_framework.contract import Benchmark from template_formatting.formatter import ( BaseFormatter, @@ -79,6 +79,12 @@ class _ExpectedPrompt: ground_truth=" A", possible_completions=[" A", " B", " C", " D"], ) +# BPB: the cloze prompt, but only the gold answer text is scored. +_BPB = _ExpectedPrompt( + messages=_CLOZE.messages, + ground_truth=" Oxygen", + possible_completions=[" Oxygen"], +) # IDK: cloze plus an appended "I do not know." option, preceded once by the confidence preamble. _IDK = _ExpectedPrompt( messages=[ @@ -98,6 +104,7 @@ class _ExpectedPrompt: [ pytest.param(arc, _CLOZE, id="cloze"), pytest.param(arc_olmes, _OLMES, id="olmes"), + pytest.param(arc_bpb, _BPB, id="bpb"), pytest.param(arc_idk, _IDK, id="idk"), ], ) @@ -141,6 +148,7 @@ def _oneshot(fewshot: list[Message], eval_expected: _ExpectedPrompt) -> _Expecte [ pytest.param(arc, _CLOZE_FEWSHOT, _CLOZE, id="cloze"), pytest.param(arc_olmes, _OLMES_FEWSHOT, _OLMES, id="olmes"), + pytest.param(arc_bpb, _CLOZE_FEWSHOT, _BPB, id="bpb"), ], ) def test_arc_oneshot_prompt( diff --git a/tests/tests_eval_framework/benchmarks/test_global_mmlu.py b/tests/tests_eval_framework/benchmarks/test_global_mmlu.py index e3ecf39db..659029b91 100644 --- a/tests/tests_eval_framework/benchmarks/test_global_mmlu.py +++ b/tests/tests_eval_framework/benchmarks/test_global_mmlu.py @@ -10,7 +10,12 @@ import pytest -from eval_framework.benchmarks.global_mmlu import GLOBAL_MMLU_BENCHMARKS, global_mmlu +from eval_framework.benchmarks.global_mmlu import ( + GLOBAL_MMLU_BENCHMARKS, + GLOBAL_MMLU_LITE_SUBJECTS, + global_mmlu, + global_mmlu_bpb, +) from eval_framework.contract import Benchmark from template_formatting.formatter import ( BaseFormatter, @@ -75,3 +80,65 @@ def test_global_mmlu_prompt_is_localized( ] assert sample.ground_truth == " B" assert sample.possible_completions == [" A", " B", " C", " D"] + + +@pytest.mark.parametrize( + "language, preamble, question_word, answer_word", + [ + ("de", "Die folgenden sind Fragen (mit Antworten) über Abstrakte Algebra.", "Frage", "Antwort"), + ( + "fr", + "Les questions suivantes sont des questions (avec réponses) sur Algèbre Abstraite.", + "Question", + "Réponse", + ), + ], +) +def test_global_mmlu_bpb_prompt_is_localized_and_hides_the_options( + language: str, preamble: str, question_word: str, answer_word: str +) -> None: + # Given the per-language BPB benchmark over one fictional row, with a demonstration row in the dev split + fewshot_row = {**_EVAL_ROW, "question": "What is 1+1?", "option_b": "2", "answer": "B"} + benchmark = global_mmlu_bpb(language, dataset=DatasetStub({"test": [_EVAL_ROW], "dev": [fewshot_row]})) + # When we assemble its first sample (one-shot) + sample = first_sample(benchmark, num_fewshot=1, custom_subjects=[str((language, "abstract_algebra"))]) + # Then the preamble does not claim multiple choice, no options are shown, and only the gold text is scored + assert benchmark.id() == f"GlobalMMLU_Cohere_{language.upper()}_BPB" + assert sample.messages == [ + Message(role=Role.USER, content=f"{preamble}\n\n{question_word}: What is 1+1?\n"), + Message(role=Role.ASSISTANT, content=f"{answer_word}: 2"), + Message(role=Role.USER, content=f"{question_word}: What is 2+2?\n"), + Message(role=Role.ASSISTANT, content=f"{answer_word}:"), + ] + assert sample.ground_truth == " 4" + assert sample.possible_completions == [" 4"] + + +def test_global_mmlu_lite_bpb_covers_only_the_subjects_lite_has() -> None: + # Lite's test split has 43 of the 57 MMLU subjects; the Lite task offers exactly those. + benchmark = global_mmlu_bpb("de", lite=True) + assert benchmark.id() == "GlobalMMLULite_Cohere_DE_BPB" + assert len(GLOBAL_MMLU_LITE_SUBJECTS) == 43 + assert "abstract_algebra" not in GLOBAL_MMLU_LITE_SUBJECTS + + +def test_global_mmlu_lite_bpb_oneshot_prompt() -> None: + # Given the German Lite BPB benchmark over one fictional row, with a demonstration row in the dev split + # (on astronomy: abstract_algebra is one of the subjects Lite lacks) + eval_row = {**_EVAL_ROW, "subject": "astronomy"} + fewshot_row = {**eval_row, "question": "What is 1+1?", "option_b": "2", "answer": "B"} + benchmark = global_mmlu_bpb("de", lite=True, dataset=DatasetStub({"test": [eval_row], "dev": [fewshot_row]})) + # When we assemble its first sample (one-shot) + sample = first_sample(benchmark, num_fewshot=1, custom_subjects=[str(("de", "astronomy"))]) + # Then it is the same localized cloze prompt as the full Global-MMLU task + assert sample.messages == [ + Message( + role=Role.USER, + content="Die folgenden sind Fragen (mit Antworten) über Astronomie.\n\nFrage: What is 1+1?\n", + ), + Message(role=Role.ASSISTANT, content="Antwort: 2"), + Message(role=Role.USER, content="Frage: What is 2+2?\n"), + Message(role=Role.ASSISTANT, content="Antwort:"), + ] + assert sample.ground_truth == " 4" + assert sample.possible_completions == [" 4"] diff --git a/tests/tests_eval_framework/benchmarks/test_goldenswag.py b/tests/tests_eval_framework/benchmarks/test_goldenswag.py index 804508e89..d3cc66609 100644 --- a/tests/tests_eval_framework/benchmarks/test_goldenswag.py +++ b/tests/tests_eval_framework/benchmarks/test_goldenswag.py @@ -10,7 +10,13 @@ import pytest -from eval_framework.benchmarks.goldenswag import _IDK_PREAMBLE, GOLDENSWAG_BENCHMARKS, goldenswag, goldenswag_idk +from eval_framework.benchmarks.goldenswag import ( + _IDK_PREAMBLE, + GOLDENSWAG_BENCHMARKS, + goldenswag, + goldenswag_bpb, + goldenswag_idk, +) from eval_framework.contract import Benchmark from template_formatting.formatter import ( BaseFormatter, @@ -42,6 +48,17 @@ def test_formatter_hash(benchmark: Benchmark, formatter_cls: type[BaseFormatter] "label": "0", } +_FEWSHOT_ROW: dict[str, Any] = { + "activity_label": "Making tea", + "ctx_a": "A man places a kettle of water on the stove.", + "ctx_b": "he", + "endings": [ + "puts the kettle in the freezer to warm it up.", + "waits for it to boil, then pours it over a tea bag.", + ], + "label": "1", +} + _QUESTION = "Cleaning windows: A woman stands at a tall window holding a spray bottle and a cloth. She" _ENDINGS = [ " sprays the glass and wipes it until it is clear.", @@ -60,6 +77,34 @@ def test_goldenswag_zeroshot_prompt() -> None: assert sample.possible_completions == _ENDINGS +def test_goldenswag_bpb_scores_only_the_gold_ending() -> None: + # Given the BPB benchmark over one fictional row + benchmark = goldenswag_bpb(dataset=DatasetStub({"validation": [_EVAL_ROW]})) + # When we assemble its first sample (zero-shot) + sample = first_sample(benchmark, num_fewshot=0) + # Then the prompt is the cloze one, but only the gold ending is scored + assert sample.messages == [Message(role=Role.USER, content=_QUESTION)] + assert sample.ground_truth == _ENDINGS[0] + assert sample.possible_completions == [_ENDINGS[0]] + + +def test_goldenswag_bpb_oneshot_prompt() -> None: + # Given the BPB benchmark with a fewshot row and the eval row, both in the validation split (GoldenSwag draws + # its fewshots from the same split it evaluates on; the eval item itself is never its own demonstration) + benchmark = goldenswag_bpb(dataset=DatasetStub({"validation": [_FEWSHOT_ROW, _EVAL_ROW]})) + # When we assemble its first sample (one-shot) + sample = first_sample(benchmark, num_fewshot=1) + # Then the fewshot context is continued with its gold ending, followed by the eval context; only the eval + # row's gold ending is scored + assert sample.messages == [ + Message(role=Role.USER, content="Making tea: A man places a kettle of water on the stove. He"), + Message(role=Role.ASSISTANT, content=" waits for it to boil, then pours it over a tea bag."), + Message(role=Role.USER, content=_QUESTION), + ] + assert sample.ground_truth == _ENDINGS[0] + assert sample.possible_completions == [_ENDINGS[0]] + + def test_goldenswag_idk_prepends_preamble_and_scores_an_abstention_option() -> None: # Given the IDK benchmark over one fictional row benchmark = goldenswag_idk(dataset=DatasetStub({"validation": [_EVAL_ROW]})) diff --git a/tests/tests_eval_framework/benchmarks/test_mmlu.py b/tests/tests_eval_framework/benchmarks/test_mmlu.py index 168fe307a..168508a42 100644 --- a/tests/tests_eval_framework/benchmarks/test_mmlu.py +++ b/tests/tests_eval_framework/benchmarks/test_mmlu.py @@ -18,6 +18,7 @@ _MMLU_COT_ANSWER_RE, MMLU_BENCHMARKS, mmlu, + mmlu_bpb, mmlu_cot, mmlu_full_text, mmlu_idk, @@ -105,6 +106,42 @@ def test_mmlu_full_text_prompt() -> None: assert sample.possible_completions == [" 3", " 4", " 5", " 6"] +def test_mmlu_bpb_prompt() -> None: + # BPB: options hidden, the preamble does not claim multiple choice; only the gold answer text is scored. + benchmark = mmlu_bpb(dataset=DatasetStub({"test": [_EVAL_ROW]})) + sample = first_sample(benchmark, num_fewshot=0) + assert sample.messages == [ + Message( + role=Role.USER, + content="The following are questions (with answers) about abstract algebra.\n\nQuestion: What is 2 + 2?\n", + ), + Message(role=Role.ASSISTANT, content="Answer:"), + ] + assert sample.ground_truth == " 4" + assert sample.possible_completions == [" 4"] + + +def test_mmlu_bpb_oneshot_prompt() -> None: + # Given the BPB benchmark with a fewshot row (dev split) and the eval row (test split) + fewshot_row = {**_EVAL_ROW, "question": "What is 1 + 1?", "choices": ["1", "2", "3", "4"], "answer": 1} + benchmark = mmlu_bpb(dataset=DatasetStub({"test": [_EVAL_ROW], "dev": [fewshot_row]})) + # When we assemble its first sample (one-shot) + sample = first_sample(benchmark, num_fewshot=1) + # Then the preamble opens the first (fewshot) turn only, the demonstration answers with the full gold text, + # and only the eval row's gold text is scored + assert sample.messages == [ + Message( + role=Role.USER, + content="The following are questions (with answers) about abstract algebra.\n\nQuestion: What is 1 + 1?\n", + ), + Message(role=Role.ASSISTANT, content="Answer: 2"), + Message(role=Role.USER, content="Question: What is 2 + 2?\n"), + Message(role=Role.ASSISTANT, content="Answer:"), + ] + assert sample.ground_truth == " 4" + assert sample.possible_completions == [" 4"] + + def test_mmlu_idk_prompt() -> None: # IDK: an abstention option "?" is scored; the preamble names the subject by its raw (underscored) key. benchmark = mmlu_idk(dataset=DatasetStub({"test": [_EVAL_ROW]})) diff --git a/tests/tests_eval_framework/benchmarks/test_piqa.py b/tests/tests_eval_framework/benchmarks/test_piqa.py index afd5856ad..de34debf2 100644 --- a/tests/tests_eval_framework/benchmarks/test_piqa.py +++ b/tests/tests_eval_framework/benchmarks/test_piqa.py @@ -12,7 +12,7 @@ import pytest -from eval_framework.benchmarks.piqa import _IDK_PREAMBLE, PIQA_BENCHMARKS, piqa, piqa_idk, piqa_olmes +from eval_framework.benchmarks.piqa import _IDK_PREAMBLE, PIQA_BENCHMARKS, piqa, piqa_bpb, piqa_idk, piqa_olmes from eval_framework.contract import Benchmark from template_formatting.formatter import ( BaseFormatter, @@ -82,6 +82,15 @@ class _ExpectedPrompt: ground_truth=" A", possible_completions=[" A", " B"], ) +# BPB: the OLMES "Goal:" prompt without the options; scores only the gold solution text. +_BPB = _ExpectedPrompt( + messages=[ + Message(role=Role.USER, content="Goal: How do you dig a hole?\n"), + Message(role=Role.ASSISTANT, content="Answer:"), + ], + ground_truth=" Use a shovel to remove the dirt.", + possible_completions=[" Use a shovel to remove the dirt."], +) # IDK: cloze plus an appended "I do not know" option, preceded once by the confidence preamble. _IDK = _ExpectedPrompt( messages=[ @@ -102,6 +111,7 @@ class _ExpectedPrompt: [ pytest.param(piqa, "validation", _CLOZE, id="cloze"), pytest.param(piqa_olmes, "train", _OLMES, id="olmes"), + pytest.param(piqa_bpb, "validation", _BPB, id="bpb"), pytest.param(piqa_idk, "validation", _IDK, id="idk"), ], ) @@ -132,6 +142,11 @@ def test_piqa_zeroshot_prompt( Message(role=Role.ASSISTANT, content="Answer: B"), ] +_BPB_FEWSHOT_MESSAGES = [ + Message(role=Role.USER, content="Goal: How do you light a candle?\n"), + Message(role=Role.ASSISTANT, content="Answer: Touch a lit match to the wick."), +] + def _oneshot(fewshot_messages: list[Message], eval_expected: _ExpectedPrompt) -> _ExpectedPrompt: return _ExpectedPrompt( @@ -144,7 +159,8 @@ def _oneshot(fewshot_messages: list[Message], eval_expected: _ExpectedPrompt) -> @pytest.mark.parametrize( "make_benchmark, splits, expected", [ - # Base/IDK draw few-shot from a separate split (validation/test); OLMES from its own (train). + # Base/IDK draw few-shot from a separate split (validation/test), BPB too (validation/train); + # OLMES from its own (train). pytest.param( piqa, {"validation": [_EVAL_ROW], "test": [_FEWSHOT_ROW]}, @@ -157,6 +173,12 @@ def _oneshot(fewshot_messages: list[Message], eval_expected: _ExpectedPrompt) -> _oneshot(_OLMES_FEWSHOT_MESSAGES, _OLMES), id="olmes", ), + pytest.param( + piqa_bpb, + {"validation": [_EVAL_ROW], "train": [_FEWSHOT_ROW]}, + _oneshot(_BPB_FEWSHOT_MESSAGES, _BPB), + id="bpb", + ), ], ) def test_piqa_oneshot_prompt(