-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GPQA scenario and tests added #3068
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import datasets | ||
import os | ||
import random | ||
from typing import List | ||
from helm.benchmark.scenarios.scenario import ( | ||
Scenario, | ||
Instance, | ||
Reference, | ||
TEST_SPLIT, | ||
CORRECT_TAG, | ||
Input, | ||
Output, | ||
) | ||
from helm.common.general import ensure_directory_exists | ||
|
||
|
||
SUBSETS = ["gpqa_main", "gpqa_diamond", "gpqa_extended"] | ||
|
||
# Train example indices below are found by indexing examples given in the original paper repo | ||
EXCLUDED_TRAIN_EXAMPLES = { | ||
"gpqa_main": [339, 105], | ||
"gpqa_diamond": [124, 39], | ||
"gpqa_extended": [146, 330, 436], | ||
} | ||
|
||
|
||
class GPQAScenario(Scenario): | ||
"""GPQA | ||
|
||
GPQA is a multiple-choice, Q&A dataset of very hard questions written and validated by experts in biology, physics, | ||
and chemistry. When attempting questions out of their own domain (e.g., a physicist answers a chemistry question), | ||
these experts get only 34% accuracy, despite spending >30m with full access to Google.""" | ||
|
||
name = "gpqa" | ||
description = "A Graduate-Level Google-Proof Q&A Benchmark" | ||
tags = ["question answering"] | ||
|
||
def __init__(self, subset: str, random_seed=42): | ||
super().__init__() | ||
assert subset in SUBSETS, "Unknown subset: {}".format(subset) | ||
self.subset = subset | ||
self.random_seed = random_seed | ||
|
||
def get_instances(self, output_path: str) -> List[Instance]: | ||
# Get GPQA from HuggingFace | ||
cache_dir = os.path.join(output_path, "data") | ||
ensure_directory_exists(cache_dir) | ||
dataset = datasets.load_dataset( | ||
"Idavidrein/gpqa", self.subset, trust_remote_code=True, cache_dir=cache_dir, split="train" | ||
) | ||
assert isinstance(dataset, datasets.Dataset) | ||
|
||
# Read all instances | ||
random.seed(self.random_seed) | ||
instances: List[Instance] = [] | ||
for idx, row in enumerate(dataset): | ||
if idx in EXCLUDED_TRAIN_EXAMPLES[self.subset]: | ||
continue | ||
input = Input(text=row["Question"].strip()) | ||
references = [ | ||
Reference(Output(text=row["Correct Answer"].strip()), tags=[CORRECT_TAG]), | ||
Reference(Output(text=row["Incorrect Answer 1"].strip()), tags=[]), | ||
Reference(Output(text=row["Incorrect Answer 2"].strip()), tags=[]), | ||
Reference(Output(text=row["Incorrect Answer 3"].strip()), tags=[]), | ||
] | ||
random.shuffle(references) | ||
instance = Instance(input=input, references=references, split=TEST_SPLIT) | ||
instances.append(instance) | ||
|
||
return instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
from tempfile import TemporaryDirectory | ||
from helm.benchmark.scenarios.gpqa_scenario import GPQAScenario | ||
from helm.benchmark.scenarios.scenario import CORRECT_TAG | ||
|
||
|
||
@pytest.mark.scenarios | ||
def test_gpqa_scenario(): | ||
with TemporaryDirectory() as tmpdir: | ||
scenario = GPQAScenario(subset="gpqa_main") | ||
instances = scenario.get_instances(tmpdir) | ||
assert len(instances) == 446 | ||
assert instances[0].split == "test" | ||
assert len(instances[0].input.text) == 689 | ||
references = instances[0].references | ||
assert len(references[0].output.text) == 10 | ||
assert len(references[1].output.text) == 6 | ||
assert len(references[2].output.text) == 9 | ||
assert len(references[3].output.text) == 7 | ||
assert references[3].tags == [CORRECT_TAG] | ||
|
||
scenario = GPQAScenario(subset="gpqa_diamond") | ||
instances = scenario.get_instances(tmpdir) | ||
assert len(instances) == 196 | ||
assert instances[0].split == "test" | ||
assert len(instances[0].input.text) == 262 | ||
references = instances[0].references | ||
assert len(references[0].output.text) == 8 | ||
assert len(references[1].output.text) == 9 | ||
assert len(references[2].output.text) == 8 | ||
assert len(references[3].output.text) == 8 | ||
assert references[3].tags == [CORRECT_TAG] | ||
|
||
scenario = GPQAScenario(subset="gpqa_extended") | ||
instances = scenario.get_instances(tmpdir) | ||
assert len(instances) == 543 | ||
assert instances[0].split == "test" | ||
assert len(instances[0].input.text) == 689 | ||
references = instances[0].references | ||
assert len(references[0].output.text) == 10 | ||
assert len(references[1].output.text) == 6 | ||
assert len(references[2].output.text) == 9 | ||
assert len(references[3].output.text) == 7 | ||
assert references[3].tags == [CORRECT_TAG] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has no train split examples currently; let's address this in a different PR.