-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add load_clean_dataset function to dataset.py
- Loading branch information
Jai
committed
Feb 1, 2024
1 parent
cb3976e
commit 55a1c98
Showing
1 changed file
with
15 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from datasets import load_dataset | ||
from tqdm.auto import tqdm | ||
|
||
|
||
def load_clean_dataset(split: str, tokenized: bool = False) -> list[str]: | ||
# checking just startswith, because you can include slice like "train[:1000]" | ||
assert split.startswith("train") or split.startswith("validation") | ||
hf_ds = load_dataset( | ||
f"jbrinkma/tinystories-v2-clean{'-tokenized' if tokenized else ''}" | ||
) | ||
dataset = [] | ||
# hf_ds technically isn't guaranteed to be subscriptable, but it is in this case | ||
for sample_txt in tqdm(hf_ds["tokens" if tokenized else "text"]): # type: ignore | ||
dataset.append(sample_txt) | ||
return dataset |