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|
| 8 |
+
@inproceedings{tjong-kim-sang-2002-introduction,
|
| 9 |
+
title = "Introduction to the {C}o{NLL}-2002 Shared Task: Language-Independent Named Entity Recognition",
|
| 10 |
+
author = "Tjong Kim Sang, Erik F.",
|
| 11 |
+
booktitle = "{COLING}-02: The 6th Conference on Natural Language Learning 2002 ({C}o{NLL}-2002)",
|
| 12 |
+
year = "2002",
|
| 13 |
+
url = "https://www.aclweb.org/anthology/W02-2024",
|
| 14 |
+
}
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
_DESCRIPTION = """\
|
| 18 |
+
Named entities are phrases that contain the names of persons, organizations, locations, times and quantities.
|
| 19 |
+
Example:
|
| 20 |
+
[PER Wolff] , currently a journalist in [LOC Argentina] , played with [PER Del Bosque] in the final years of the seventies in [ORG Real Madrid] .
|
| 21 |
+
The shared task of CoNLL-2002 concerns language-independent named entity recognition.
|
| 22 |
+
We will concentrate on four types of named entities: persons, locations, organizations and names of miscellaneous entities that do not belong to the previous three groups.
|
| 23 |
+
The participants of the shared task will be offered training and test data for at least two languages.
|
| 24 |
+
They will use the data for developing a named-entity recognition system that includes a machine learning component.
|
| 25 |
+
Information sources other than the training data may be used in this shared task.
|
| 26 |
+
We are especially interested in methods that can use additional unannotated data for improving their performance (for example co-training).
|
| 27 |
+
The train/validation/test sets are available in Spanish and Dutch.
|
| 28 |
+
For more details see https://www.clips.uantwerpen.be/semeval2016/ner/ and https://www.aclweb.org/anthology/W02-2024/
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
_URL = "https://raw.githubusercontent.com/YaxinCui/Semeval_2020_task9_data/main/Spanglish/"
|
| 32 |
+
|
| 33 |
+
TRAINING_FILE_Dict = {
|
| 34 |
+
'Spanglish': "Spanglish_train.conll",
|
| 35 |
+
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
TEST_FILE_Dict = {
|
| 39 |
+
'Spanglish': "Spanglish_dev.conll",
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
class Semeval2016Config(datasets.BuilderConfig):
|
| 43 |
+
"""BuilderConfig for Semeval2016"""
|
| 44 |
+
|
| 45 |
+
def __init__(self, **kwargs):
|
| 46 |
+
"""BuilderConfig forSemeval2016.
|
| 47 |
+
Args:
|
| 48 |
+
**kwargs: keyword arguments forwarded to super.
|
| 49 |
+
"""
|
| 50 |
+
super(Semeval2016Config, self).__init__(**kwargs)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class Semeval2016(datasets.GeneratorBasedBuilder):
|
| 54 |
+
"""Semeval2016 dataset."""
|
| 55 |
+
|
| 56 |
+
BUILDER_CONFIGS = [
|
| 57 |
+
Semeval2016Config(name="Spanglish", version=datasets.Version("1.0.0"), description="Semeval2016 Spanish dataset"),
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
def _info(self):
|
| 61 |
+
return datasets.DatasetInfo(
|
| 62 |
+
description=_DESCRIPTION,
|
| 63 |
+
features=datasets.Features(
|
| 64 |
+
{
|
| 65 |
+
"id": datasets.Value("string"),
|
| 66 |
+
"meta": datasets.Value("string"),
|
| 67 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
| 68 |
+
# "langs": datasets.Sequence(datasets.features.ClassLabel(names=["lang1","lang2","ambiguous","other","ne","unk","mixed","fw","8","9","10","11",] ) ),
|
| 69 |
+
"label": datasets.features.ClassLabel(
|
| 70 |
+
names=[
|
| 71 |
+
"positive",
|
| 72 |
+
"neutral",
|
| 73 |
+
"negative",
|
| 74 |
+
]
|
| 75 |
+
),
|
| 76 |
+
}
|
| 77 |
+
),
|
| 78 |
+
supervised_keys=None,
|
| 79 |
+
homepage="/",
|
| 80 |
+
citation=_CITATION,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
def _split_generators(self, dl_manager):
|
| 84 |
+
"""Returns SplitGenerators."""
|
| 85 |
+
|
| 86 |
+
if self.config.name=="Spanglish":
|
| 87 |
+
urls_to_download = {
|
| 88 |
+
"train": f"{_URL}{TRAINING_FILE_Dict[self.config.name]}",
|
| 89 |
+
"test": f"{_URL}{TEST_FILE_Dict[self.config.name]}",
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 93 |
+
|
| 94 |
+
return [
|
| 95 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 96 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
def _generate_examples(self, filepath):
|
| 100 |
+
logger.info("⏳ Generating examples from = %s", filepath)
|
| 101 |
+
prev_pos = '$$$'
|
| 102 |
+
with open(filepath, encoding="utf-8") as f:
|
| 103 |
+
guid = 0
|
| 104 |
+
meta = None
|
| 105 |
+
tokens = []
|
| 106 |
+
langs = []
|
| 107 |
+
label = None
|
| 108 |
+
for line in f:
|
| 109 |
+
if len(tokens) and (line == "" or line == "\n"):
|
| 110 |
+
yield guid, {
|
| 111 |
+
"id": str(guid),
|
| 112 |
+
"meta": str(meta),
|
| 113 |
+
"tokens": tokens,
|
| 114 |
+
"label": label,
|
| 115 |
+
}
|
| 116 |
+
guid += 1
|
| 117 |
+
tokens = []
|
| 118 |
+
langs = []
|
| 119 |
+
labels = []
|
| 120 |
+
else:
|
| 121 |
+
line = line.strip()
|
| 122 |
+
# semeval2016 tokens are space separated
|
| 123 |
+
splits = [s.rstrip() for s in line.split(" ")]
|
| 124 |
+
if len(tokens)==0 and line.startswith("meta "):
|
| 125 |
+
meta = splits[1]
|
| 126 |
+
label = splits[2]
|
| 127 |
+
else:
|
| 128 |
+
tokens.append(splits[0])
|
| 129 |
+
langs.append(splits[1])
|
| 130 |
+
# last example
|
| 131 |
+
|
| 132 |
+
yield guid, {
|
| 133 |
+
"id": str(guid),
|
| 134 |
+
"meta": str(meta),
|
| 135 |
+
"tokens": tokens,
|
| 136 |
+
"label": label,
|
| 137 |
+
}
|