MACCROBAT_biomedical_ner / MACCROBAT_biomedical_ner.py
singh-aditya's picture
Rename MACCROBAT_biomedical_ner1.py to MACCROBAT_biomedical_ner.py
5326f98
raw
history blame
5.75 kB
import json
import datasets
from datasets import Sequence, ClassLabel, Value
_TRAIN_FILE = "MACCROBAT2020-V2.json"
_NAME = "MACCROBAT_biomedical_ner"
_TRAIN_URL = f"https://huggingface.co/datasets/singh-aditya/{_NAME}/raw/main/{_TRAIN_FILE}"
class MACCROBAT_biomedical_ner(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description="",
features=datasets.Features(
{
"full_text": Value(dtype="string"),
"ner_info": [
{
"text": Value(dtype="string"),
"label": Value(dtype="string"),
"start": Value(dtype="int64"),
"end": Value(dtype="int64"),
}
],
"tokens": Sequence(Value(dtype="string")),
"ner_labels": Sequence(
ClassLabel(
names=[
"O",
"B-ACTIVITY",
"I-ACTIVITY",
"I-ADMINISTRATION",
"B-ADMINISTRATION",
"B-AGE",
"I-AGE",
"I-AREA",
"B-AREA",
"B-BIOLOGICAL_ATTRIBUTE",
"I-BIOLOGICAL_ATTRIBUTE",
"I-BIOLOGICAL_STRUCTURE",
"B-BIOLOGICAL_STRUCTURE",
"B-CLINICAL_EVENT",
"I-CLINICAL_EVENT",
"B-COLOR",
"I-COLOR",
"I-COREFERENCE",
"B-COREFERENCE",
"B-DATE",
"I-DATE",
"I-DETAILED_DESCRIPTION",
"B-DETAILED_DESCRIPTION",
"I-DIAGNOSTIC_PROCEDURE",
"B-DIAGNOSTIC_PROCEDURE",
"I-DISEASE_DISORDER",
"B-DISEASE_DISORDER",
"B-DISTANCE",
"I-DISTANCE",
"B-DOSAGE",
"I-DOSAGE",
"I-DURATION",
"B-DURATION",
"I-FAMILY_HISTORY",
"B-FAMILY_HISTORY",
"B-FREQUENCY",
"I-FREQUENCY",
"I-HEIGHT",
"B-HEIGHT",
"B-HISTORY",
"I-HISTORY",
"I-LAB_VALUE",
"B-LAB_VALUE",
"I-MASS",
"B-MASS",
"I-MEDICATION",
"B-MEDICATION",
"I-NONBIOLOGICAL_LOCATION",
"B-NONBIOLOGICAL_LOCATION",
"I-OCCUPATION",
"B-OCCUPATION",
"B-OTHER_ENTITY",
"I-OTHER_ENTITY",
"B-OTHER_EVENT",
"I-OTHER_EVENT",
"I-OUTCOME",
"B-OUTCOME",
"I-PERSONAL_BACKGROUND",
"B-PERSONAL_BACKGROUND",
"B-QUALITATIVE_CONCEPT",
"I-QUALITATIVE_CONCEPT",
"I-QUANTITATIVE_CONCEPT",
"B-QUANTITATIVE_CONCEPT",
"B-SEVERITY",
"I-SEVERITY",
"B-SEX",
"I-SEX",
"B-SHAPE",
"I-SHAPE",
"B-SIGN_SYMPTOM",
"I-SIGN_SYMPTOM",
"B-SUBJECT",
"I-SUBJECT",
"B-TEXTURE",
"I-TEXTURE",
"B-THERAPEUTIC_PROCEDURE",
"I-THERAPEUTIC_PROCEDURE",
"I-TIME",
"B-TIME",
"B-VOLUME",
"I-VOLUME",
"I-WEIGHT",
"B-WEIGHT",
]
)
),
}
),
supervised_keys=None,
homepage="",
citation="",
)
def _split_generators(self, a):
"""Returns SplitGenerators."""
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": _TRAIN_URL}),
]
def _generate_examples(self, filepath):
with open(filepath, encoding="utf-8") as f:
datas = json.load(f)
datas = datas["data"]
guid = 0
for data in datas:
yield guid, data
guid += 1