forked from stanford-crfm/helm
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request stanford-crfm#170 from stanford-crfm/gsm
Grade School Math with 8.5K Examples (GSM8K)
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 deletions.
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
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
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
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,47 @@ | ||
import jsonlines | ||
import os | ||
from typing import List | ||
|
||
from common.general import ensure_file_downloaded | ||
from .scenario import Scenario, Instance, Reference, CORRECT_TAG, TRAIN_SPLIT, TEST_SPLIT | ||
|
||
|
||
class GSM8KScenario(Scenario): | ||
"""Task from "Training Verifiers to Solve Math Word Problems" (Cobbe et al. 2021): https://arxiv.org/abs/2110.14168 | ||
Evaluates the capacity of a model to solve grade school math problems, when prompted to include reasoning. | ||
Encourages the model to work through the problem in a step-by-step way | ||
Example from dataset (line breaks added for readability): | ||
"question": | ||
"Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. | ||
How many clips did Natalia sell altogether in April and May?", | ||
"answer": | ||
"Natalia sold 48/2 = <<48/2=24>>24 clips in May.\n | ||
Natalia sold 48+24 = <<48+24=72>>72 clips altogether in April and May.\n | ||
#### 72" | ||
""" | ||
|
||
name = "gsm" | ||
description = "Grade school math dataset with 8.5K examples (GSM8K)." | ||
tags = ["reasoning", "math"] | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def get_instances(self) -> List[Instance]: | ||
splits = {"train": TRAIN_SPLIT, "test": TEST_SPLIT} | ||
base_url = "https://raw.githubusercontent.com/openai/grade-school-math/master/grade_school_math/data/" | ||
instances: List[Instance] = [] | ||
for split, split_tag in splits.items(): # Iterate over the splits | ||
source_url: str = f"{base_url}/{split}.jsonl" | ||
data_path: str = os.path.join(self.output_path, f"gsm_data_{split}") | ||
ensure_file_downloaded(source_url=source_url, target_path=data_path) | ||
with jsonlines.open(data_path) as reader: | ||
for example in reader: # Each example is a dictionary with a 'question' and 'answer' key | ||
instances.append( | ||
Instance( | ||
input=example["question"], | ||
references=[Reference(output=example["answer"], tags=[CORRECT_TAG])], | ||
split=split_tag, # Must assign split tag to 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