| 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" |
|
|
| micro_to_macro_ner_mapping = { |
| 'O': "O", |
| "B-AerospaceManufacturer": "B-Group", |
| 'I-AerospaceManufacturer': 'I-Group', |
| 'B-AnatomicalStructure': "B-Medical", |
| 'I-AnatomicalStructure': "I-Medical", |
| 'B-ArtWork': "B-CreativeWork", |
| 'I-ArtWork': "I-CreativeWork", |
| 'B-Artist': "B-Person", |
| 'I-Artist': "I-Person", |
| 'B-Athlete': "B-Person", |
| 'I-Athlete': "I-Person", |
| 'B-CarManufacturer': "B-Group", |
| 'I-CarManufacturer': "I-Group", |
| 'B-Cleric': "B-Person", |
| 'I-Cleric': "I-Person", |
| 'B-Clothing': "B-Product", |
| 'I-Clothing': "I-Product", |
| 'B-Disease': "B-Medical", |
| 'I-Disease': "I-Medical", |
| 'B-Drink': "B-Product", |
| 'I-Drink': "I-Product", |
| 'B-Facility': "B-Location", |
| 'I-Facility': "I-Location", |
| 'B-Food': "B-Product", |
| 'I-Food': "I-Product", |
| 'B-HumanSettlement': "B-Location", |
| 'I-HumanSettlement': "I-Location", |
| 'B-MedicalProcedure': "B-Medical", |
| 'I-MedicalProcedure': "I-Medical", |
| 'B-Medication/Vaccine': "B-Medical", |
| 'I-Medication/Vaccine': "I-Medical", |
| 'B-MusicalGRP': "B-Group", |
| 'I-MusicalGRP': "I-Group", |
| 'B-MusicalWork': "B-CreativeWork", |
| 'I-MusicalWork': "I-CreativeWork", |
| 'B-ORG': "B-Group", |
| 'I-ORG': "I-Group", |
| 'B-OtherLOC': "B-Location", |
| 'I-OtherLOC': "I-Location", |
| 'B-OtherPER': "B-Person", |
| 'I-OtherPER': "I-Person", |
| 'B-OtherPROD': "B-Product", |
| 'I-OtherPROD': "I-Product", |
| 'B-Politician': "B-Person", |
| 'I-Politician': "I-Person", |
| 'B-PrivateCorp': "B-Group", |
| 'I-PrivateCorp': "I-Group", |
| 'B-PublicCorp': "B-Group", |
| 'I-PublicCorp': "I-Group", |
| 'B-Scientist': "B-Person", |
| 'I-Scientist': "I-Person", |
| 'B-Software': "B-CreativeWork", |
| 'I-Software': "I-CreativeWork", |
| 'B-SportsGRP': "B-Group", |
| 'I-SportsGRP': "I-Group", |
| 'B-SportsManager': "B-Person", |
| 'I-SportsManager': "I-Person", |
| 'B-Station': 'B-Location', |
| 'I-Station': 'I-Location', |
| 'B-Symptom': "B-Medical", |
| 'I-Symptom': "I-Medical", |
| 'B-Vehicle': "B-Product", |
| 'I-Vehicle': "I-Product", |
| 'B-VisualWork': "B-CreativeWork", |
| 'I-VisualWork': "I-CreativeWork", |
| 'B-WrittenWork': "B-CreativeWork", |
| 'I-WrittenWork': "I-CreativeWork", |
| } |
|
|
| 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'] |
| ) |
| ), |
| "ner_macro_tags": datasets.Sequence( |
| datasets.features.ClassLabel( |
| names=['O', |
| "B-Location", "I-Location", |
| "B-CreativeWork", "I-CreativeWork", |
| "B-Group", "I-Group", |
| "B-Person", "I-Person", |
| "B-Product", "I-Product", |
| "B-Medical", "I-Medical", |
| ] |
| ) |
| ), |
| } |
| ), |
| supervised_keys=None, |
| homepage="https://www.aclweb.org/anthology/W03-0419/", |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager: datasets.DownloadManager): |
| """Returns SplitGenerators.""" |
|
|
| downloaded_files = dl_manager.download_and_extract({ |
| "train": f"{self.config.name}-train.conll", |
| "dev": f"{self.config.name}-dev.conll", |
| }) |
|
|
| return [ |
| datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), |
| datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}), |
| ] |
|
|
| 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 = [] |
| ner_macro_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, |
| "ner_macro_tags": ner_macro_tags, |
| } |
| guid += 1 |
| tokens = [] |
| ner_tags = [] |
| ner_macro_tags = [] |
| else: |
| |
| splits = line.split(" _ _ ") |
| tokens.append(splits[0]) |
| ner_tags.append(splits[1].rstrip()) |
| ner_macro_tags.append(self.micro_to_macro_ner_mapping[splits[1].rstrip()]) |
| |
| if tokens: |
| yield guid, { |
| "id": str(guid), |
| "tokens": tokens, |
| "ner_tags": ner_tags, |
| "ner_macro_tags": ner_macro_tags, |
| } |
|
|