| import os |
| import datasets |
|
|
| logger = datasets.logging.get_logger(__name__) |
|
|
|
|
| |
| |
| _CITATION = """\ |
| @InProceedings{huggingface:dataset, |
| title = {A great new dataset}, |
| author={huggingface, Inc. |
| }, |
| year={2020} |
| } |
| """ |
|
|
| |
| |
| _DESCRIPTION = """\ |
| SemEval 2023 Task 2: MultiCoNER II |
| Multilingual Complex Named Entity Recognition |
| """ |
|
|
| |
| _HOMEPAGE = "https://multiconer.github.io/" |
|
|
| |
| _LICENSE = "" |
|
|
| |
| |
| |
| _URLS = "" |
|
|
|
|
| class Multiconer2Config(datasets.BuilderConfig): |
| """BuilderConfig for Multiconer2""" |
|
|
| def __init__(self, **kwargs): |
| """BuilderConfig for Multiconer2. |
| Args: |
| **kwargs: keyword arguments forwarded to super. |
| """ |
| super(Multiconer2Config, self).__init__(**kwargs) |
|
|
|
|
| class Multiconer2(datasets.GeneratorBasedBuilder): |
| VERSION = datasets.Version("1.0.0") |
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
| BUILDER_CONFIGS = [ |
| Multiconer2Config(name="bn", version=VERSION), |
| Multiconer2Config(name="de", version=VERSION), |
| Multiconer2Config(name="en", version=VERSION), |
| Multiconer2Config(name="es", version=VERSION), |
| Multiconer2Config(name="fa", version=VERSION), |
| Multiconer2Config(name="fr", version=VERSION), |
| Multiconer2Config(name="hi", version=VERSION), |
| Multiconer2Config(name="it", version=VERSION), |
| Multiconer2Config(name="pt", version=VERSION), |
| Multiconer2Config(name="sv", version=VERSION), |
| Multiconer2Config(name="uk", version=VERSION), |
| Multiconer2Config(name="zh", version=VERSION), |
| ] |
|
|
| DEFAULT_CONFIG_NAME = "en" |
|
|
| def _info(self): |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=datasets.Features( |
| { |
| "id": datasets.Value("string"), |
| "tokens": datasets.Sequence(datasets.Value("string")), |
| "ner_tags": datasets.Sequence( |
| datasets.features.ClassLabel( |
| names=['O', |
| "B-AerospaceManufacturer", 'I-AerospaceManufacturer', |
| 'B-AnatomicalStructure', 'I-AnatomicalStructure', |
| 'B-ArtWork', 'I-ArtWork', |
| 'B-Artist', 'I-Artist', |
| 'B-Athlete', 'I-Athlete', |
| 'B-CarManufacturer', 'I-CarManufacturer', |
| 'B-Cleric', 'I-Cleric', |
| 'B-Clothing', 'I-Clothing', |
| 'B-Disease', 'I-Disease', |
| 'B-Drink', 'I-Drink', |
| 'B-Facility', 'I-Facility', |
| 'B-Food', 'I-Food', |
| 'B-HumanSettlement', 'I-HumanSettlement', |
| 'B-MedicalProcedure', 'I-MedicalProcedure', |
| 'B-Medication/Vaccine', 'I-Medication/Vaccine', |
| 'B-MusicalGRP', 'I-MusicalGRP', |
| 'B-MusicalWork', 'I-MusicalWork', |
| 'B-ORG', 'I-ORG', |
| 'B-OtherLOC', 'I-OtherLOC', |
| 'B-OtherPER', 'I-OtherPER', |
| 'B-OtherPROD', 'I-OtherPROD', |
| 'B-Politician', 'I-Politician', |
| 'B-PrivateCorp', 'I-PrivateCorp', |
| 'B-PublicCorp', 'I-PublicCorp', |
| 'B-Scientist', 'I-Scientist', |
| 'B-Software', 'I-Software', |
| 'B-SportsGRP', 'I-SportsGRP', |
| 'B-SportsManager', 'I-SportsManager', |
| 'B-Station', 'I-Station', |
| 'B-Symptom', 'I-Symptom', |
| 'B-Vehicle', 'I-Vehicle', |
| 'B-VisualWork', 'I-VisualWork', |
| 'B-WrittenWork', 'I-WrittenWork'] |
| ) |
| ), |
| } |
| ), |
| supervised_keys=None, |
| homepage="https://www.aclweb.org/anthology/W03-0419/", |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager: datasets.DownloadManager): |
| """Returns SplitGenerators.""" |
| base_path = dl_manager.download_and_extract([ |
| f"{self.config.name}-train.conll", |
| f"{self.config.name}-dev.conll", |
| ]) |
|
|
| return [ |
| datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": os.path.join(base_path, |
| f"{self.config.name}-train.conll")}), |
| datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": os.path.join(base_path, |
| f"{self.config.name}-dev.conll")}), |
| ] |
|
|
| def _generate_examples(self, filepath): |
| logger.info("⏳ Generating examples from = %s", filepath) |
| with open(filepath, encoding="utf-8") as f: |
| guid = 0 |
| tokens = [] |
| ner_tags = [] |
| for line in f: |
| if line.startswith("#") or line == "" or line == "\n": |
| if tokens: |
| yield guid, { |
| "id": str(guid), |
| "tokens": tokens, |
| "ner_tags": ner_tags, |
| } |
| guid += 1 |
| tokens = [] |
| ner_tags = [] |
| else: |
| |
| splits = line.split(" _ _ ") |
| tokens.append(splits[0]) |
| ner_tags.append(splits[1].rstrip()) |
| |
| if tokens: |
| yield guid, { |
| "id": str(guid), |
| "tokens": tokens, |
| "ner_tags": ner_tags, |
| } |
|
|