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

feat: add from_parquet to dataloader #483

Closed
Changes from all 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
9 changes: 8 additions & 1 deletion dspy/datasets/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ def from_json(self, file_path:str, fields: List[str] = None, input_keys: Tuple[s

return [dspy.Example({field:row[field] for field in fields}).with_inputs(*input_keys) for row in dataset]

def from_parquet(self, file_path: str, fields: List[str] = None, input_keys: Tuple[str] = ()) -> List[dspy.Example]:
dataset = load_dataset("parquet", data_files=file_path)["train"]

if not fields:
fields = list(dataset.features)

return [dspy.Example({field: row[field] for field in fields}).with_inputs(input_keys) for row in dataset]

def sample(
self,
dataset: List[dspy.Example],
Expand Down Expand Up @@ -110,4 +117,4 @@ def train_test_split(
train_dataset = dataset_shuffled[:train_end]
test_dataset = dataset_shuffled[train_end:train_end + test_end]

return {'train': train_dataset, 'test': test_dataset}
return {'train': train_dataset, 'test': test_dataset}
Loading