File size: 9,265 Bytes
943b0b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# coding=utf-8
"""SemEval 2022 Task 2: MultiCoNER II: Multilingual Complex Named Entity Recognition"""
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """\
@inproceedings{multiconer2-report,
title={{SemEval-2023 Task 2: Fine-grained Multilingual Named Entity Recognition (MultiCoNER 2)}},
author={Fetahu, Besnik and Kar, Sudipta and Chen, Zhiyu and Rokhlenko, Oleg and Malmasi, Shervin},
booktitle={Proceedings of the 17th International Workshop on Semantic Evaluation (SemEval-2023)},
year={2023},
publisher={Association for Computational Linguistics},
}
@article{multiconer2-data,
title={{MultiCoNER v2: a Large Multilingual dataset for Fine-grained and Noisy Named Entity Recognition}},
author={Fetahu, Besnik and Chen, Zhiyu and Kar, Sudipta and Rokhlenko, Oleg and Malmasi, Shervin},
year={2023},
}
"""
_DESCRIPTION = """\
Complex named entities (NE), like the titles of creative works, are not simple nouns and pose challenges for NER systems (Ashwini and Choi, 2014). They can take the form of any linguistic constituent, like an imperative clause (“Dial M for Murder”), and do not look like traditional NEs (Persons, Locations, etc.). This syntactic ambiguity makes it challenging to recognize them based on context. We organized the MultiCoNER task (Malmasi et al., 2022) at SemEval-2022 to address these challenges in 11 languages, receiving a very positive community response with 34 system papers. Results confirmed the challenges of processing complex and long-tail NEs: even the largest pre-trained Transformers did not achieve top performance without external knowledge. The top systems infused transformers with knowledge bases and gazetteers. However, such solutions are brittle against out of knowledge-base entities and noisy scenarios like the presence of spelling mistakes and typos. We propose MultiCoNER II which represents novel challenges through new tasks that emphasize the shortcomings of the current top models.
MultiCoNER II features complex NER in these languages:
1. English
2. Spanish
3. Hindi
4. Bangla
5. Chinese
6. Swedish
7. Farsi
8. French
9. Italian
10. Portugese
11. Ukranian
12. German
For more details see https://multiconer.github.io/
## References
* Sandeep Ashwini and Jinho D. Choi. 2014. Targetable named entity recognition in social media. CoRR, abs/1408.0782.
* Shervin Malmasi, Anjie Fang, Besnik Fetahu, Sudipta Kar, Oleg Rokhlenko. 2022. SemEval-2022 Task 11: Multilingual Complex Named Entity Recognition (MultiCoNER).
"""
_URL = "https://huggingface.co/datasets/MultiCoNER/multiconer_v2/resolve/main"
code_vs_lang_map = {"en": "English",
"es": "Spanish",
"pt": "Portuguese",
"uk": "Ukrainian",
"sv": "Swedish",
"fr": "French",
"fa": "Farsi",
"de": "German",
"zh": "Chinese",
"hi": "Hindi",
"bn": "Bangla",
"it": "Italian",
"multi": "Multilingual"}
label_vs_code_map = {"Bangla (BN)": 'bn',
"Chinese (ZH)": 'zh',
"English (EN)": 'en',
"Spanish (ES)": 'es',
"Swedish (SV)": 'sv',
"French (FR)": 'fr',
"Farsi (FA)": 'fa',
"German (DE)": 'de',
"Portuguese (PT)": 'pt',
"Hindi (HI)": 'hi',
"Italian (IT)": 'it',
"Ukrainian (UK)": 'uk',
"Multilingual (MULTI)": 'multi'}
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):
"""MultiCoNER2 dataset."""
BUILDER_CONFIGS = [
MultiCoNER2Config(name="Bangla (BN)", version=datasets.Version("1.0.0"),
description="MultiCoNER2 Bangla dataset"),
MultiCoNER2Config(name="English (EN)", version=datasets.Version("1.0.0"),
description="MultiCoNER2 English dataset"),
MultiCoNER2Config(name="Farsi (FA)", version=datasets.Version("1.0.0"),
description="MultiCoNER2 Farsi dataset"),
MultiCoNER2Config(name="German (DE)", version=datasets.Version("1.0.0"),
description="MultiCoNER2 German dataset"),
MultiCoNER2Config(name="Hindi (HI)", version=datasets.Version("1.0.0"),
description="MultiCoNER2 Hindi dataset"),
MultiCoNER2Config(name="Spanish (ES)", version=datasets.Version("1.0.0"),
description="MultiCoNER2 Spanish dataset"),
MultiCoNER2Config(name="Multilingual (MULTI)", version=datasets.Version("1.0.0"),
description="MultiCoNER2 Multilingual dataset"),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"sample_id": datasets.Value("string"),
"tokens": datasets.Sequence(datasets.Value("string")),
"ner_tags": datasets.Sequence(datasets.Value("string")),
"ner_tags_index": datasets.Sequence(
datasets.features.ClassLabel(
names=[
'O',
'B-PER',
'I-PER',
'B-LOC',
'I-LOC',
'B-GRP',
'I-GRP',
'B-CORP',
'I-CORP',
'B-PROD',
'I-PROD',
'B-CW',
'I-CW',
]
)
),
}
),
supervised_keys=None,
homepage="https://multiconer.github.io",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
"train": f"{_URL}/{label_vs_code_map[self.config.name].upper()}-{code_vs_lang_map[label_vs_code_map[self.config.name]]}/{label_vs_code_map[self.config.name]}_train.conll",
"dev": f"{_URL}/{label_vs_code_map[self.config.name].upper()}-{code_vs_lang_map[label_vs_code_map[self.config.name]]}/{label_vs_code_map[self.config.name]}_dev.conll",
"test": f"{_URL}/{label_vs_code_map[self.config.name].upper()}-{code_vs_lang_map[label_vs_code_map[self.config.name]]}/{label_vs_code_map[self.config.name]}_test.conll",
}
downloaded_files = dl_manager.download_and_extract(urls_to_download)
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"]}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
]
def _generate_examples(self, filepath):
logger.info("⏳ Generating examples from = %s", filepath)
with open(filepath) as f:
guid = -1
s_id = None
tokens = []
ner_tags = []
for line in f:
if line.strip().startswith("# id"):
s_id = line.split()[2].strip()
guid += 1
tokens = []
ner_tags = []
elif ' _ _ ' in line:
# Separator is " _ _ "
splits = line.split(" _ _ ")
tokens.append(splits[0].strip())
ner_tags.append(splits[1].strip())
elif len(line.strip()) == 0:
if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
yield guid, {
"id": guid,
"sample_id": s_id,
"tokens": tokens,
"ner_tags_index": ner_tags,
"ner_tags": ner_tags,
}
s_id = None
tokens = []
ner_tags = []
else:
continue
if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
yield guid, {
"id": guid,
"sample_id": s_id,
"tokens": tokens,
"ner_tags_index": ner_tags,
"ner_tags": ner_tags,
}
|