-
Notifications
You must be signed in to change notification settings - Fork 3
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 #9 from ivanleomk/gsm-8k
Adding a GSM8K Script
- Loading branch information
Showing
3 changed files
with
94 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from datasets import load_dataset, Dataset, DatasetDict | ||
|
||
splits = ["test", "train"] | ||
|
||
|
||
def generate_gsm8k(split): | ||
ds = load_dataset("gsm8k", "main", split=split, streaming=True) | ||
for row in ds: | ||
reasoning, answer = row["answer"].split("####") | ||
answer = int(answer.strip().replace(",", "")) | ||
yield { | ||
"question": row["question"], | ||
"answer": answer, | ||
"reasoning": reasoning, | ||
} | ||
|
||
|
||
# Create the dataset for train and test splits | ||
train_dataset = Dataset.from_generator(lambda: generate_gsm8k("train")) | ||
test_dataset = Dataset.from_generator(lambda: generate_gsm8k("test")) | ||
|
||
# Combine them into a DatasetDict | ||
dataset = DatasetDict({"train": train_dataset, "test": test_dataset}) | ||
|
||
dataset.push_to_hub("567-labs/gsm8k") |
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,67 @@ | ||
from braintrust import Eval, Score | ||
from autoevals.value import ExactMatch | ||
from datasets import load_dataset | ||
from openai import AsyncOpenAI | ||
from pydantic import BaseModel | ||
import instructor | ||
from asyncio import run | ||
from uuid import uuid4 | ||
|
||
dataset = load_dataset("567-labs/gsm8k") | ||
oai = AsyncOpenAI() | ||
|
||
|
||
class Answer(BaseModel): | ||
chain_of_thought: str | ||
answer: int | ||
|
||
|
||
modes = [instructor.Mode.TOOLS, instructor.Mode.TOOLS_STRICT] | ||
|
||
|
||
async def main(): | ||
uuid = uuid4() | ||
print(f"Running eval with uuid: {uuid}") | ||
for eval_mode in modes: | ||
client = instructor.from_openai(oai, mode=eval_mode) | ||
dataset = list(load_dataset("567-labs/gsm8k", split="test")) | ||
|
||
async def task(question, hooks): | ||
resp = await client.chat.completions.create( | ||
model="gpt-4o-mini", | ||
messages=[ | ||
{ | ||
"role": "system", | ||
"content": "You are a helpful assistant that can solve math problems. Answer the question with the correct response", | ||
}, | ||
{"role": "user", "content": question}, | ||
], | ||
response_model=Answer, | ||
) | ||
hooks.meta( | ||
reasoning=resp.chain_of_thought, | ||
) | ||
return resp.answer | ||
|
||
await Eval( | ||
name="567-labs/gsm8k", | ||
experiment_name=f"gsm8k-{eval_mode}-{uuid}", | ||
data=lambda: [ | ||
{ | ||
"input": row["question"], | ||
"expected": row["answer"], | ||
} | ||
for row in dataset | ||
], # Replace with your eval dataset | ||
task=task, | ||
scores=[ExactMatch], | ||
metadata={ | ||
"model": "gpt-4o-mini", | ||
"mode": str(eval_mode), | ||
"n_samples": len(dataset), | ||
}, | ||
max_concurrency=10, | ||
) | ||
|
||
|
||
run(main()) |