|
|
|
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" |
|
|
|
|
|
|
|
|
|
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}", |
|
|
|
} |
|
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"]}), |
|
|
|
] |
|
|
|
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: |
|
|
|
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) |
|
|
|
yield guid, { |
|
"id": str(guid), |
|
"tokens": tokens, |
|
"ner_tags": ner_tags, |
|
} |
|
|