change data config
Browse files- dataset.py +16 -39
dataset.py
CHANGED
|
@@ -1,11 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import datasets
|
| 3 |
|
| 4 |
-
_CITATION = ""
|
| 5 |
-
_DESCRIPTION = "COSC426_Mid-Project Dataset"
|
| 6 |
-
_HOMEPAGE = ""
|
| 7 |
-
_LICENSE = ""
|
| 8 |
-
|
| 9 |
_LANGUAGES = ["fon", "ibo", "kin", "sna"]
|
| 10 |
|
| 11 |
class MyDatasetConfig(datasets.BuilderConfig):
|
|
@@ -19,54 +14,36 @@ class MyDataset(datasets.GeneratorBasedBuilder):
|
|
| 19 |
name=lang,
|
| 20 |
lang=lang,
|
| 21 |
version=datasets.Version("1.0.0"),
|
| 22 |
-
description=f"Dataset for {lang}
|
| 23 |
)
|
| 24 |
for lang in _LANGUAGES
|
| 25 |
]
|
| 26 |
|
| 27 |
def _info(self):
|
| 28 |
return datasets.DatasetInfo(
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
"target": datasets.Value("string"),
|
| 35 |
-
}
|
| 36 |
-
),
|
| 37 |
-
supervised_keys=("text", "target"),
|
| 38 |
-
homepage=_HOMEPAGE,
|
| 39 |
-
license=_LICENSE,
|
| 40 |
-
citation=_CITATION,
|
| 41 |
)
|
| 42 |
|
| 43 |
def _split_generators(self, dl_manager):
|
| 44 |
lang = self.config.lang
|
| 45 |
data_dir = os.path.join(self.config.data_dir, lang)
|
| 46 |
-
|
| 47 |
return [
|
| 48 |
-
datasets.SplitGenerator(
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
datasets.SplitGenerator(
|
| 53 |
-
|
| 54 |
-
gen_kwargs={"filepath": os.path.join(data_dir, "test.tsv")}
|
| 55 |
-
),
|
| 56 |
-
datasets.SplitGenerator(
|
| 57 |
-
name=datasets.Split.VALIDATION,
|
| 58 |
-
gen_kwargs={"filepath": os.path.join(data_dir, "dev.tsv")}
|
| 59 |
-
),
|
| 60 |
]
|
| 61 |
|
| 62 |
def _generate_examples(self, filepath):
|
| 63 |
with open(filepath, encoding="utf-8") as f:
|
| 64 |
for i, line in enumerate(f):
|
| 65 |
-
if i == 0:
|
| 66 |
-
continue
|
| 67 |
-
|
| 68 |
-
yield i, {
|
| 69 |
-
"textid": parts[0],
|
| 70 |
-
"text": parts[1],
|
| 71 |
-
"target": parts[2],
|
| 72 |
-
}
|
|
|
|
| 1 |
import os
|
| 2 |
import datasets
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
_LANGUAGES = ["fon", "ibo", "kin", "sna"]
|
| 5 |
|
| 6 |
class MyDatasetConfig(datasets.BuilderConfig):
|
|
|
|
| 14 |
name=lang,
|
| 15 |
lang=lang,
|
| 16 |
version=datasets.Version("1.0.0"),
|
| 17 |
+
description=f"Dataset for {lang}"
|
| 18 |
)
|
| 19 |
for lang in _LANGUAGES
|
| 20 |
]
|
| 21 |
|
| 22 |
def _info(self):
|
| 23 |
return datasets.DatasetInfo(
|
| 24 |
+
features=datasets.Features({
|
| 25 |
+
"textid": datasets.Value("string"),
|
| 26 |
+
"text": datasets.Value("string"),
|
| 27 |
+
"target": datasets.Value("string"),
|
| 28 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
def _split_generators(self, dl_manager):
|
| 32 |
lang = self.config.lang
|
| 33 |
data_dir = os.path.join(self.config.data_dir, lang)
|
|
|
|
| 34 |
return [
|
| 35 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
| 36 |
+
gen_kwargs={"filepath": os.path.join(data_dir, "train.tsv")}),
|
| 37 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION,
|
| 38 |
+
gen_kwargs={"filepath": os.path.join(data_dir, "dev.tsv")}),
|
| 39 |
+
datasets.SplitGenerator(name=datasets.Split.TEST,
|
| 40 |
+
gen_kwargs={"filepath": os.path.join(data_dir, "test.tsv")}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
]
|
| 42 |
|
| 43 |
def _generate_examples(self, filepath):
|
| 44 |
with open(filepath, encoding="utf-8") as f:
|
| 45 |
for i, line in enumerate(f):
|
| 46 |
+
if i == 0:
|
| 47 |
+
continue # skip header
|
| 48 |
+
textid, text, target = line.strip().split("\t")
|
| 49 |
+
yield i, {"textid": textid, "text": text, "target": target}
|
|
|
|
|
|
|
|
|
|
|
|