Upload naamapadam.py
Browse files- naamapadam.py +91 -0
naamapadam.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
_CITATION = """\
|
7 |
+
|
8 |
+
"""
|
9 |
+
|
10 |
+
_DESCRIPTION = """\
|
11 |
+
|
12 |
+
"""
|
13 |
+
_LICENSE = "Creative Commons Attribution-NonCommercial 4.0 International Public License"
|
14 |
+
|
15 |
+
_URL = "https://huggingface.co/datasets/paricdac/naamapadam/resolve/main"
|
16 |
+
|
17 |
+
_LANGUAGES = ["kn"]
|
18 |
+
|
19 |
+
|
20 |
+
class NaamapadamPR(datasets.GeneratorBasedBuilder):
|
21 |
+
VERSION = datasets.Version("1.0.0")
|
22 |
+
|
23 |
+
BUILDER_CONFIGS = [
|
24 |
+
datasets.BuilderConfig(
|
25 |
+
name="{}".format(lang), version=datasets.Version("1.0.0")
|
26 |
+
)
|
27 |
+
for lang in _LANGUAGES
|
28 |
+
]
|
29 |
+
|
30 |
+
def _info(self):
|
31 |
+
return datasets.DatasetInfo(
|
32 |
+
description=_DESCRIPTION,
|
33 |
+
features=datasets.Features(
|
34 |
+
{
|
35 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
36 |
+
"ner_tags": datasets.Sequence(
|
37 |
+
datasets.features.ClassLabel(
|
38 |
+
names=[
|
39 |
+
"O",
|
40 |
+
"B-PER",
|
41 |
+
"I-PER",
|
42 |
+
"B-ORG",
|
43 |
+
"I-ORG",
|
44 |
+
"B-LOC",
|
45 |
+
"I-LOC",
|
46 |
+
]
|
47 |
+
)
|
48 |
+
),
|
49 |
+
}
|
50 |
+
),
|
51 |
+
supervised_keys=None,
|
52 |
+
#homepage=_HOMEPAGE,
|
53 |
+
citation=_CITATION,
|
54 |
+
license=_LICENSE,
|
55 |
+
version=self.VERSION,
|
56 |
+
)
|
57 |
+
|
58 |
+
def _split_generators(self, dl_manager):
|
59 |
+
"""Returns SplitGenerators."""
|
60 |
+
lang = str(self.config.name)
|
61 |
+
url = _URL.format(lang, self.VERSION.version_str[:-2])
|
62 |
+
|
63 |
+
data_dir = dl_manager.download_and_extract(url)
|
64 |
+
|
65 |
+
return [
|
66 |
+
datasets.SplitGenerator(
|
67 |
+
name=datasets.Split.TRAIN,
|
68 |
+
gen_kwargs={
|
69 |
+
"filepath": os.path.join(data_dir, lang + "_train.json"),
|
70 |
+
},
|
71 |
+
),
|
72 |
+
datasets.SplitGenerator(
|
73 |
+
name=datasets.Split.TEST,
|
74 |
+
gen_kwargs={
|
75 |
+
"filepath": os.path.join(data_dir, lang + "_test.json"),
|
76 |
+
},
|
77 |
+
),
|
78 |
+
datasets.SplitGenerator(
|
79 |
+
name=datasets.Split.VALIDATION,
|
80 |
+
gen_kwargs={
|
81 |
+
"filepath": os.path.join(data_dir, lang + "_val.json"),
|
82 |
+
},
|
83 |
+
),
|
84 |
+
]
|
85 |
+
|
86 |
+
def _generate_examples(self, filepath):
|
87 |
+
"""Yields examples as (key, example) tuples."""
|
88 |
+
with open(filepath, encoding="utf-8") as f:
|
89 |
+
for idx_, row in enumerate(f):
|
90 |
+
data = json.loads(row)
|
91 |
+
yield idx_, {"tokens": data["words"], "ner_tags": data["ner"]}
|