Skip to content
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

Refactor the dataset generator #335

Merged
merged 8 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
17 changes: 5 additions & 12 deletions prompt2model/dataset_generator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from abc import ABC, abstractmethod
from enum import Enum
from pathlib import Path

import datasets

Expand All @@ -26,14 +25,14 @@ class DatasetGenerator(ABC):
def generate_dataset_split(
self,
prompt_spec: PromptSpec,
expected_num_examples: int,
num_examples: int,
split: DatasetSplit,
) -> datasets.Dataset:
"""Generate data for a single named split of data.

Args:
prompt_spec: A prompt spec (containing a system description).
expected_num_examples: Expected number of examples in split.
num_examples: Expected number of examples in split.
neubig marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally expected_num_examples because we could not guarantee that this is the exact number generated (due to the way we did batching and retries)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, and I made sure the result actually matched the actual number of examples (unless we hit max_api_calls).

split: Name of dataset split to generate.

Returns:
Expand All @@ -43,14 +42,13 @@ def generate_dataset_split(
def generate_dataset_dict(
self,
prompt_spec: PromptSpec,
expected_num_examples: dict[DatasetSplit, int],
output_dir: str | None = None,
num_examples: dict[DatasetSplit, int],
) -> datasets.DatasetDict:
"""Generate full dataset splits (e.g. train/dev/test) from a prompt.

Args:
prompt_spec: A prompt specification.
expected_num_examples: Expected number of
num_examples: Expected number of
examples per split (train/val/test).

Returns:
Expand All @@ -59,13 +57,8 @@ def generate_dataset_dict(
dataset_dict = datasets.DatasetDict(
{
split.value: self.generate_dataset_split(prompt_spec, num, split=split)
for split, num in expected_num_examples.items()
for split, num in num_examples.items()
}
)

if output_dir:
save_dir = Path(output_dir)
save_dir.mkdir(parents=True, exist_ok=True)
dataset_dict.save_to_disk(str(save_dir))
Comment on lines -66 to -69
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to remove this? Saving the dataset to file allows this to be reused in the future without running dataset generation, which is key for iteration

Copy link
Collaborator Author

@neubig neubig Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree that there's a tradeoff here. But there's a major issue with the current implementation in that it (a) implicitly saves a cache, and (b) doesn't check if the cache was created with the same parameters as the current function call. If we're going to cache something, we should make sure that we check that the parameters are the same and invalidate the cache if the parameters are not the same.

I'd suggest that we just remove it for now, and if we want to add cacheing in the future we

  1. Make it explicit (the user needs to call a save_cache function), not implicit
  2. Check to make sure that the parameters of the called function match those of the cache. Zeno build has some code that I wrote to do this, so we might be able to use this (or check other libraries)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are somehow right. I feel a sense of loss that I write careful tests to test the cache and load the cache.


return dataset_dict
Loading