synthetic-NER-dataset-v1 / synthetic_NER_dataset_v1.py
rlucatoor's picture
initial commit
bb7366d
import datasets
class NERDataset(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description="A NER dataset for named entity recognition tasks.",
features=datasets.Features(
{
"text": datasets.Value("string"),
"label": datasets.Value("string"),
}
),
homepage="https://huggingface.co/datasets/tanaos/synthetic-NER-dataset-v1",
license="mit",
)
def _split_generators(self, dl_manager):
# The dataset only has one file
data_path = self.config.data_dir or "./data/data.csv"
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": data_path},
),
]
def _generate_examples(self, filepath):
"""
Yields examples as (key, example) tuples.
"""
import csv
with open(filepath, encoding="utf-8") as f:
reader = csv.DictReader(f)
for i, row in enumerate(reader):
yield i, {
"text": row["text"],
"label": int(row["label"]),
}