File size: 10,096 Bytes
3e0a9fa b11eb39 3e0a9fa 5586f00 3e0a9fa 4e31f2e 3e0a9fa 5586f00 3e0a9fa 5586f00 3e0a9fa af7ae07 3e0a9fa af7ae07 3e0a9fa |
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 |
# Loading script for the Ancora NER dataset.
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """ """
_DESCRIPTION = """CEIL (Catalan Entity Identification and Linking).
This is a dataset for complex Named Eentity Reacognition (NER) created by the AINA project in the BSC for
Machine Learning and Language Model evaluation purposes.
CEIL corpus is used under [CC-by] (https://creativecommons.org/licenses/by/4.0/) licence.
This dataset was developed by BSC as part of the AINA project, and to enrich the Catalan Language Understanding Benchmark (CLUB).
"""
_HOMEPAGE = """https://aina.bsc.es"""
_URL = "https://huggingface.co/datasets/crodri/ceil/resolve/main/"
_TRAINING_FILE = "train.conll"
_DEV_FILE = "dev.conll"
#_TEST_FILE = "test.conll"
#_TEST_FILE = "test.conll"
class CEILConfig(datasets.BuilderConfig):
""" Builder config for the CEIL dataset """
def __init__(self, **kwargs):
"""BuilderConfig for CEIL.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(CEILConfig, self).__init__(**kwargs)
class CEIL(datasets.GeneratorBasedBuilder):
""" CEIL dataset."""
BUILDER_CONFIGS = [
CEILConfig(
name="CEIL",
version=datasets.Version("2.0.0"),
description="CEIL dataset"
),
]
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',
'I-product-vehicle',
'I-organization-sportsteam',
'B-location-road/railway/highway/transit',
'I-CW-other',
'B-event-other',
'I-CW-painting',
'I-person-group',
'B-CW-music',
'I-location-other',
'B-organization-religious',
'I-product-E-device',
'B-product-software',
'B-event-attack/terrorism/militaryconflict',
'B-organization-politicalparty',
'B-person-scholar/scientist',
'I-person-artist/author',
'B-CW-other',
'I-person-influencer',
'B-event-protest',
'I-building-other',
'I-organization-other',
'B-organization-sportsteam',
'B-organization-media',
'I-event-disaster',
'I-organization-privatecompany',
'I-event-other',
'B-location-other',
'B-product-clothing',
'B-organization-education',
'B-building-sportsfacility',
'I-building-shops',
'I-location-park',
'B-organization-government',
'I-person-politician',
'B-building-airport',
'B-CW-writtenart',
'B-location-park',
'B-location-island',
'I-building-hotel',
'B-Other',
'B-organization-other',
'B-person-group',
'B-event-disaster',
'I-organization-onlinebusiness',
'B-product-consumer_good',
'I-CW-broadcastprogram',
'I-person-other',
'B-building-hotel',
'B-product-vehicle',
'I-organization-politicalparty',
'B-event-political',
'B-location-mountain',
'I-organization-religious',
'B-GPE',
'I-location-mountain',
'I-CW-film',
'I-CW-music',
'B-location-bodiesofwater',
'I-location-road/railway/highway/transit',
'I-event-sportsevent',
'B-organization-onlinebusiness',
'I-organization-government',
'I-person-actor/director',
'B-person-athlete',
'I-organization-education',
'I-event-attack/terrorism/militaryconflict',
'I-product-consumer_good',
'I-building-hospital',
'B-building-shops',
'I-event-political',
'I-building-religious',
'B-CW-painting',
'I-building-sportsfacility',
'I-event-protest',
'B-building-restaurant',
'B-person-politician',
'B-product-other',
'I-CW-writtenart',
'I-product-other',
'I-product-food',
'B-event-sportsevent',
'B-CW-film',
'I-product-clothing',
'B-CW-broadcastprogram',
'I-product-software',
'I-person-athlete',
'B-product-E-device',
'B-person-actor/director',
'B-building-religious',
'I-GPE',
'B-person-artist/author',
'B-organization-privatecompany',
'I-building-restaurant',
'B-building-hospital',
'I-Other',
'I-person-scholar/scientist',
'B-person-influencer',
'B-person-other',
'I-location-bodiesofwater',
'I-building-airport',
'I-organization-media',
'B-product-food',
'B-building-other',
'B-building-governmentfacility',
'I-building-governmentfacility',
'I-location-island'
]
)
),
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
"train": f"{_URL}{_TRAINING_FILE}",
"dev": f"{_URL}{_DEV_FILE}",
# "test": f"{_URL}{_TEST_FILE}",
}
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.VALIDATION, gen_kwargs={"filepath": downloaded_files["test"]}),
]
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 = []
n = 0
for line in f:
try:
n += 1
if line.startswith("-DOCSTART-") or line == "" or line == "\n" or line == "\xa0\n":
if tokens:
yield guid, {
"id": str(guid),
"tokens": tokens,
"ner_tags": ner_tags,
}
guid += 1
tokens = []
ner_tags = []
else:
# CEIL tokens are tab separated
splits = line.split('\t')
tokens.append(splits[0])
ner_tags.append(splits[-1].rstrip())
except Exception as error:
print(error)
print("line: ",n)
print("Error line: ",line)
# last example
yield guid, {
"id": str(guid),
"tokens": tokens,
"ner_tags": ner_tags,
}
|