Create finstsb_dataset.py
Browse files- finstsb_dataset.py +54 -0
finstsb_dataset.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
class Finstsb(datasets.GeneratorBasedBuilder):
|
5 |
+
"""Finstsb dataset."""
|
6 |
+
|
7 |
+
VERSION = datasets.Version("1.0.0")
|
8 |
+
|
9 |
+
def _info(self):
|
10 |
+
return datasets.DatasetInfo(
|
11 |
+
description="Finstsb dataset",
|
12 |
+
features=datasets.Features(
|
13 |
+
{
|
14 |
+
"sentence1": datasets.Value("string"),
|
15 |
+
"sentence2": datasets.Value("string"),
|
16 |
+
"gpt_score": datasets.Value("int32"),
|
17 |
+
"score": datasets.Value("int32"),
|
18 |
+
}
|
19 |
+
),
|
20 |
+
supervised_keys=None,
|
21 |
+
homepage="https://huggingface.co/datasets",
|
22 |
+
citation="",
|
23 |
+
)
|
24 |
+
|
25 |
+
def _split_generators(self, dl_manager):
|
26 |
+
"""Returns SplitGenerators."""
|
27 |
+
urls_to_download = {
|
28 |
+
"dev": "path/to/your/finstsb_to_dev.csv",
|
29 |
+
"test": "path/to/your/finstsb_to_test.csv",
|
30 |
+
}
|
31 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
32 |
+
|
33 |
+
return [
|
34 |
+
datasets.SplitGenerator(
|
35 |
+
name=datasets.Split.VALIDATION,
|
36 |
+
gen_kwargs={"filepath": downloaded_files["dev"]},
|
37 |
+
),
|
38 |
+
datasets.SplitGenerator(
|
39 |
+
name=datasets.Split.TEST,
|
40 |
+
gen_kwargs={"filepath": downloaded_files["test"]},
|
41 |
+
),
|
42 |
+
]
|
43 |
+
|
44 |
+
def _generate_examples(self, filepath):
|
45 |
+
"""Yields examples."""
|
46 |
+
with open(filepath, encoding="utf-8") as f:
|
47 |
+
reader = csv.DictReader(f)
|
48 |
+
for id_, row in enumerate(reader):
|
49 |
+
yield id_, {
|
50 |
+
"sentence1": row["sentence1"],
|
51 |
+
"sentence2": row["sentence2"],
|
52 |
+
"gpt_score": int(row["gpt_score"]),
|
53 |
+
"score": int(row["score"]),
|
54 |
+
}
|