-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(evaluate): allow loading local datasets for evaluation (#362)
- Loading branch information
Showing
2 changed files
with
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
## Unreleased | ||
|
||
- Add local data loader (#334). | ||
|
||
## 0.8.0 (2025-01-29) | ||
|
||
### Changed | ||
|
45 changes: 45 additions & 0 deletions
45
packages/ragbits-evaluate/src/ragbits/evaluate/dataloaders/local.py
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,45 @@ | ||
from typing import TypeAlias | ||
|
||
from datasets import Dataset, DatasetDict, IterableDataset, IterableDatasetDict, load_dataset | ||
|
||
from .base import DataLoader | ||
|
||
HFData: TypeAlias = DatasetDict | Dataset | IterableDatasetDict | IterableDataset | ||
|
||
|
||
class LocalDataLoader(DataLoader[DatasetDict]): | ||
""" | ||
Local data loader. | ||
""" | ||
|
||
AVAILABLE_BUILDERS = { | ||
"json", | ||
"csv", | ||
"parquet", | ||
"arrow", | ||
"text", | ||
"xml", | ||
"webdataset", | ||
"imagefolder", | ||
"audiofolder", | ||
"videofolder", | ||
} | ||
|
||
def __init__(self, path: str, split: str, builder: str) -> None: | ||
self.path = path | ||
self.split = split | ||
self.builder = builder | ||
|
||
if self.builder not in self.AVAILABLE_BUILDERS: | ||
raise ValueError( | ||
f"Unsupported builder '{self.builder}'. Available builders: {', '.join(self.AVAILABLE_BUILDERS)}" | ||
) | ||
|
||
async def load(self) -> DatasetDict: | ||
""" | ||
Load the data from the local file. | ||
Returns: | ||
The loaded data. | ||
""" | ||
return load_dataset(self.builder, data_files=self.path, split=self.split) |