Commit ·
6615130
1
Parent(s): 428c0dd
Fixed username 1
Browse files- tiny_text_dataset1.py +34 -0
tiny_text_dataset1.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import datasets
|
| 3 |
+
|
| 4 |
+
_DESCRIPTION = "A tiny text dataset example with built-in preprocessing."
|
| 5 |
+
|
| 6 |
+
class TinyTextDataset(datasets.GeneratorBasedBuilder):
|
| 7 |
+
def _info(self):
|
| 8 |
+
return datasets.DatasetInfo(
|
| 9 |
+
description=_DESCRIPTION,
|
| 10 |
+
features=datasets.Features({
|
| 11 |
+
"text": datasets.Value("string"),
|
| 12 |
+
"label": datasets.Value("int32"),
|
| 13 |
+
}),
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
def _split_generators(self, dl_manager):
|
| 17 |
+
urls = {
|
| 18 |
+
"train": dl_manager.download("https://huggingface.co/datasets/svinz/tiny_text_dataset/resolve/main/data/train.csv"),
|
| 19 |
+
"test": dl_manager.download("https://huggingface.co/datasets/svinz/tiny_text_dataset/resolve/main/data/test.csv"),
|
| 20 |
+
}
|
| 21 |
+
return [
|
| 22 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": urls["train"]}),
|
| 23 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": urls["test"]}),
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
def _generate_examples(self, filepath):
|
| 27 |
+
"""Yields examples."""
|
| 28 |
+
with open(filepath, encoding="utf-8") as f:
|
| 29 |
+
reader = csv.DictReader(f)
|
| 30 |
+
for i, row in enumerate(reader):
|
| 31 |
+
# Basic preprocessing example
|
| 32 |
+
text = row["text"].lower().strip()
|
| 33 |
+
label = int(row["label"])
|
| 34 |
+
yield i, {"text": text, "label": label}
|