arman-ner / arman-ner.py
arxyzan's picture
Create arman-ner.py
fe85b14
raw
history blame
3.62 kB
import csv
from ast import literal_eval
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """
@inproceedings{poostchi-etal-2018-bilstm,
title = "{B}i{LSTM}-{CRF} for {P}ersian Named-Entity Recognition {A}rman{P}erso{NERC}orpus: the First Entity-Annotated {P}ersian Dataset",
author = "Poostchi, Hanieh and
Zare Borzeshi, Ehsan and
Piccardi, Massimo",
booktitle = "Proceedings of the Eleventh International Conference on Language Resources and Evaluation ({LREC} 2018)",
month = may,
year = "2018",
address = "Miyazaki, Japan",
publisher = "European Language Resources Association (ELRA)",
url = "https://aclanthology.org/L18-1701",
}
"""
_DESCRIPTION = """"""
_DOWNLOAD_URLS = {
"train": "https://huggingface.co./datasets/hezarai/arman-ner/resolve/main/arman-ner_train.csv",
"test": "https://huggingface.co./datasets/hezarai/arman-ner/resolve/main/arman-ner_test.csv",
}
class ArmanNERConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(ArmanNERConfig, self).__init__(**kwargs)
class ArmanNER(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
ArmanNERConfig(
name="Arman-NER",
version=datasets.Version("1.0.0"),
description=_DESCRIPTION,
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"tokens": datasets.Sequence(datasets.Value("string")),
"ner_tags": datasets.Sequence(
datasets.features.ClassLabel(
names=[
"O",
"B-pro",
"I-pro",
"B-pers",
"I-pers",
"B-org",
"I-org",
"B-loc",
"I-loc",
"B-fac",
"I-fac",
"B-event",
"I-event"
]
)
),
}
),
homepage="https://huggingface.co./datasets/hezarai/arman-ner",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""
Return SplitGenerators.
"""
train_path = dl_manager.download_and_extract(_DOWNLOAD_URLS["train"])
test_path = dl_manager.download_and_extract(_DOWNLOAD_URLS["test"])
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}
),
datasets.SplitGenerator(
name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}
),
]
def _generate_examples(self, filepath):
logger.info("⏳ Generating examples from = %s", filepath)
with open(filepath, encoding="utf-8") as csv_file:
csv_reader = csv.reader(
csv_file, quotechar='"', skipinitialspace=True
)
next(csv_reader, None)
for id_, row in enumerate(csv_reader):
tokens, ner_tags = row
# Optional preprocessing here
tokens = literal_eval(tokens)
ner_tags = literal_eval(ner_tags)
yield id_, {"tokens": tokens, "ner_tags": ner_tags}