Datasets:
File size: 8,151 Bytes
af78b07 |
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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# coding=utf-8
"""MultiCoNER: A Large-scale Multilingual dataset for Complex Named Entity Recognition"""
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """\
@misc{malmasi2022multiconer,
title={MultiCoNER: A Large-scale Multilingual dataset for Complex Named Entity Recognition},
author={Shervin Malmasi and Anjie Fang and Besnik Fetahu and Sudipta Kar and Oleg Rokhlenko},
year={2022},
eprint={2208.14536},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
"""
_DESCRIPTION = """\
We present MultiCoNER, a large multilingual dataset for Named Entity Recognition that covers 3 domains (Wiki \
sentences, questions, and search queries) across 11 languages, as well as multilingual and code-mixing subsets. \
This dataset is designed to represent contemporary challenges in NER, including low-context scenarios (short \
and uncased text), syntactically complex entities like movie titles, and long-tail entity distributions. The \
26M token dataset is compiled from public resources using techniques such as heuristic-based sentence sampling, \
template extraction and slotting, and machine translation. We applied two NER models on our dataset: a baseline \
XLM-RoBERTa model, and a state-of-the-art GEMNET model that leverages gazetteers. The baseline achieves moderate \
performance (macro-F1=54%), highlighting the difficulty of our data. GEMNET, which uses gazetteers, improvement \
significantly (average improvement of macro-F1=+30%). MultiCoNER poses challenges even for large pre-trained \
language models, and we believe that it can help further research in building robust NER systems. MultiCoNER \
is publicly available at https://registry.opendata.aws/multiconer/ and we hope that this resource will help \
advance research in various aspects of NER.
"""
subset_to_dir = {
"bn": "BN-Bangla",
"de": "DE-German",
"en": "EN-English",
"es": "ES-Spanish",
"fa": "FA-Farsi",
"hi": "HI-Hindi",
"ko": "KO-Korean",
"nl": "NL-Dutch",
"ru": "RU-Russian",
"tr": "TR-Turkish",
"zh": "ZH-Chinese",
"multi": "MULTI_Multilingual",
"mix": "MIX_Code_mixed",
}
class MultiCoNERConfig(datasets.BuilderConfig):
"""BuilderConfig for MultiCoNER"""
def __init__(self, **kwargs):
"""BuilderConfig for MultiCoNER.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(MultiCoNERConfig, self).__init__(**kwargs)
class MultiCoNER(datasets.GeneratorBasedBuilder):
"""MultiCoNER dataset."""
BUILDER_CONFIGS = [
MultiCoNERConfig(
name="bn",
version=datasets.Version("1.0.0"),
description="MultiCoNER Bangla dataset",
),
MultiCoNERConfig(
name="de",
version=datasets.Version("1.0.0"),
description="MultiCoNER German dataset",
),
MultiCoNERConfig(
name="en",
version=datasets.Version("1.0.0"),
description="MultiCoNER English dataset",
),
MultiCoNERConfig(
name="es",
version=datasets.Version("1.0.0"),
description="MultiCoNER Spanish dataset",
),
MultiCoNERConfig(
name="fa",
version=datasets.Version("1.0.0"),
description="MultiCoNER Farsi dataset",
),
MultiCoNERConfig(
name="hi",
version=datasets.Version("1.0.0"),
description="MultiCoNER Hindi dataset",
),
MultiCoNERConfig(
name="ko",
version=datasets.Version("1.0.0"),
description="MultiCoNER Korean dataset",
),
MultiCoNERConfig(
name="nl",
version=datasets.Version("1.0.0"),
description="MultiCoNER Dutch dataset",
),
MultiCoNERConfig(
name="ru",
version=datasets.Version("1.0.0"),
description="MultiCoNER Russian dataset",
),
MultiCoNERConfig(
name="tr",
version=datasets.Version("1.0.0"),
description="MultiCoNER Turkish dataset",
),
MultiCoNERConfig(
name="zh",
version=datasets.Version("1.0.0"),
description="MultiCoNER Chinese dataset",
),
MultiCoNERConfig(
name="multi",
version=datasets.Version("1.0.0"),
description="MultiCoNER Multilingual dataset",
),
MultiCoNERConfig(
name="mix",
version=datasets.Version("1.0.0"),
description="MultiCoNER Mixed dataset",
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("int32"),
"tokens": datasets.Sequence(datasets.Value("string")),
"ner_tags": datasets.Sequence(
datasets.features.ClassLabel(
names=[
"O",
"B-PER",
"I-PER",
"B-LOC",
"I-LOC",
"B-CORP",
"I-CORP",
"B-GRP",
"I-GRP",
"B-PROD",
"I-PROD",
"B-CW",
"I-CW",
]
)
),
}
),
supervised_keys=None,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
"train": f"{subset_to_dir[self.config.name].upper()}/{self.config.name}_train.conll",
"dev": f"{subset_to_dir[self.config.name].upper()}/{self.config.name}_dev.conll",
"test": f"{subset_to_dir[self.config.name].upper()}/{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, "r", encoding="utf8") as f:
guid = -1
tokens = []
ner_tags = []
for line in f:
if line.strip().startswith("# id"):
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 len(tokens) >= 1 and len(tokens) == len(ner_tags):
yield guid, {
"id": guid,
"tokens": tokens,
"ner_tags": ner_tags,
}
tokens = []
ner_tags = []
else:
continue
if len(tokens) >= 1 and len(tokens) == len(ner_tags):
yield guid, {
"id": guid,
"tokens": tokens,
"ner_tags": ner_tags,
}
|