Datasets:
Tasks:
Token Classification
Sub-tasks:
named-entity-recognition
Languages:
Hindi
Size:
100K<n<1M
ArXiv:
License:
Commit
·
696ae39
1
Parent(s):
d646d9b
changes
Browse files- HiNER-original.py +108 -0
HiNER-original.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import datasets
|
| 4 |
+
from typing import List
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
logger = datasets.logging.get_logger(__name__)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
_CITATION = """
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
_DESCRIPTION = """
|
| 14 |
+
This is the dataset repository for HiNER Dataset accepted to be published at LREC 2022.
|
| 15 |
+
The dataset can help build sequence labelling models for the task Named Entity Recognitin for the Hindi language.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
class HiNERConfig(datasets.BuilderConfig):
|
| 19 |
+
"""BuilderConfig for HiNER Dataset."""
|
| 20 |
+
|
| 21 |
+
def __init__(self, **kwargs):
|
| 22 |
+
"""BuilderConfig for HiNER.
|
| 23 |
+
Args:
|
| 24 |
+
**kwargs: keyword arguments forwarded to super.
|
| 25 |
+
"""
|
| 26 |
+
super(HiNERConfig, self).__init__(**kwargs)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class HiNERConfig(datasets.GeneratorBasedBuilder):
|
| 30 |
+
"""HiNER dataset."""
|
| 31 |
+
|
| 32 |
+
BUILDER_CONFIGS = [
|
| 33 |
+
HiNERConfig(name="HiNER", version=datasets.Version("0.0.2"), description="Hindi Named Entity Recognition dataset"),
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
def _info(self):
|
| 37 |
+
return datasets.DatasetInfo(
|
| 38 |
+
description=_DESCRIPTION,
|
| 39 |
+
features=datasets.Features(
|
| 40 |
+
{
|
| 41 |
+
"id": datasets.Value("string"),
|
| 42 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
| 43 |
+
"ner_tags": datasets.Sequence(
|
| 44 |
+
datasets.features.ClassLabel(
|
| 45 |
+
names=[
|
| 46 |
+
"O",
|
| 47 |
+
"B-PERSON",
|
| 48 |
+
"I-PERSON",
|
| 49 |
+
"B-LOCATION",
|
| 50 |
+
"I-LOCATION",
|
| 51 |
+
"B-ORGANIZATION",
|
| 52 |
+
"I-ORGANIZATION",
|
| 53 |
+
"B-FESTIVAL",
|
| 54 |
+
"I-FESTIVAL",
|
| 55 |
+
"B-GAME",
|
| 56 |
+
"I-GAME",
|
| 57 |
+
"B-LANGUAGE",
|
| 58 |
+
"I-LANGUAGE",
|
| 59 |
+
"B-LITERATURE",
|
| 60 |
+
"I-LITERATURE",
|
| 61 |
+
"B-MISC",
|
| 62 |
+
"I-MISC",
|
| 63 |
+
"B-NUMEX",
|
| 64 |
+
"I-NUMEX",
|
| 65 |
+
"B-RELIGION",
|
| 66 |
+
"I-RELIGION",
|
| 67 |
+
"B-TIMEX",
|
| 68 |
+
"I-TIMEX",
|
| 69 |
+
]
|
| 70 |
+
)
|
| 71 |
+
),
|
| 72 |
+
}
|
| 73 |
+
),
|
| 74 |
+
supervised_keys=None,
|
| 75 |
+
homepage="https://github.com/cfiltnlp/HiNER",
|
| 76 |
+
citation=_CITATION,
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
_URL = "https://github.com/cfiltnlp/HiNER-original/resolve/main/original/"
|
| 80 |
+
_URLS = {
|
| 81 |
+
"train": _URL + "train.json",
|
| 82 |
+
"dev": _URL + "validation.json",
|
| 83 |
+
"test": _URL + "test.json"
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 87 |
+
urls_to_download = self._URLS
|
| 88 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 89 |
+
|
| 90 |
+
return [
|
| 91 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 92 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
| 93 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]})
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
def _generate_examples(self, filepath):
|
| 97 |
+
"""This function returns the examples in the raw (text) form."""
|
| 98 |
+
logger.info("generating examples from = %s", filepath)
|
| 99 |
+
with open(filepath) as f:
|
| 100 |
+
hiner = json.load(f)
|
| 101 |
+
for object in hiner:
|
| 102 |
+
id_ = int(object['id'])
|
| 103 |
+
yield id_, {
|
| 104 |
+
"id": str(id_),
|
| 105 |
+
"tokens": object['tokens'],
|
| 106 |
+
"pos_tags": object['pos_tags'],
|
| 107 |
+
"ner_tags": object['ner_tags'],
|
| 108 |
+
}
|