Upload NER_Gujarati_data.py
Browse files- NER_Gujarati_data.py +92 -0
NER_Gujarati_data.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
_CITATION = """\
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
_DESCRIPTION = """\
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
_URL = "https://huggingface.co/datasets/Red-8/NER_Gujarati_data/blob/main/datas.zip"
|
| 13 |
+
|
| 14 |
+
class RedConfig(datasets.BuilderConfig):
|
| 15 |
+
"""BuilderConfig for Red dataset"""
|
| 16 |
+
|
| 17 |
+
def __init__(self, **kwargs):
|
| 18 |
+
"""BuilderConfig Red datset.
|
| 19 |
+
Args:
|
| 20 |
+
**kwargs: keyword arguments forwarded to super.
|
| 21 |
+
"""
|
| 22 |
+
super(RedConfig, self).__init__(**kwargs)
|
| 23 |
+
|
| 24 |
+
class Red(datasets.GeneratorBasedBuilder):
|
| 25 |
+
|
| 26 |
+
BUILDER_CONFIGS = [
|
| 27 |
+
RedConfig(
|
| 28 |
+
name="NER_Gujarati_data", version=datasets.Version("1.0.0")
|
| 29 |
+
),
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
def _info(self):
|
| 33 |
+
return datasets.DatasetInfo(
|
| 34 |
+
description=_DESCRIPTION,
|
| 35 |
+
features=datasets.Features(
|
| 36 |
+
{
|
| 37 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
| 38 |
+
"ner_tags": datasets.Sequence(
|
| 39 |
+
datasets.features.ClassLabel(
|
| 40 |
+
names=[
|
| 41 |
+
"O",
|
| 42 |
+
"B-PERIOD",
|
| 43 |
+
"I-PERIOD",
|
| 44 |
+
"B-DURATION",
|
| 45 |
+
"I-DURATION",
|
| 46 |
+
"B-WEATHER",
|
| 47 |
+
"I-WEATHER",
|
| 48 |
+
"B-DIGIT",
|
| 49 |
+
"I-DIGIT",
|
| 50 |
+
"B-NUMINAL",
|
| 51 |
+
"I-NUMINAL",
|
| 52 |
+
]
|
| 53 |
+
)
|
| 54 |
+
),
|
| 55 |
+
}
|
| 56 |
+
),
|
| 57 |
+
supervised_keys=None,
|
| 58 |
+
citation=_CITATION,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
def _split_generators(self, dl_manager):
|
| 62 |
+
"""Returns SplitGenerators."""
|
| 63 |
+
|
| 64 |
+
data_dir = dl_manager.download_and_extract(_URL)
|
| 65 |
+
|
| 66 |
+
return [
|
| 67 |
+
datasets.SplitGenerator(
|
| 68 |
+
name=datasets.Split.TRAIN,
|
| 69 |
+
gen_kwargs={
|
| 70 |
+
"filepath": os.path.join(data_dir,"train_data.json"),
|
| 71 |
+
},
|
| 72 |
+
),
|
| 73 |
+
datasets.SplitGenerator(
|
| 74 |
+
name=datasets.Split.TEST,
|
| 75 |
+
gen_kwargs={
|
| 76 |
+
"filepath": os.path.join(data_dir,"test_data.json"),
|
| 77 |
+
},
|
| 78 |
+
),
|
| 79 |
+
datasets.SplitGenerator(
|
| 80 |
+
name=datasets.Split.VALIDATION,
|
| 81 |
+
gen_kwargs={
|
| 82 |
+
"filepath": os.path.join(data_dir,"val_data.json"),
|
| 83 |
+
},
|
| 84 |
+
),
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
+
def _generate_examples(self, filepath):
|
| 88 |
+
"""Yields examples as (key, example) tuples."""
|
| 89 |
+
with open(filepath,encoding="utf-8") as f:
|
| 90 |
+
for idx_, row in enumerate(f):
|
| 91 |
+
data = json.loads(row)
|
| 92 |
+
yield idx_, {"tokens": data["text"], "ner_tags": data["label"]}
|