|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Waleed-bin-Qamar/NER-BAILII-UK-CCA. Criminal court appeals of uk""" |
|
|
|
import csv |
|
import json |
|
import os |
|
import datasets |
|
|
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{title = "A great new dataset", |
|
author = "A great new dataset", |
|
booktitle = "A great new dataset", |
|
month = sep, |
|
year = "2050", |
|
address = "a,b", |
|
publisher = "Association in b", |
|
doi = " ", |
|
pages = " ", |
|
abstract = " ", |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
A great new dataset |
|
""" |
|
|
|
_URL = "https://drive.google.com/" |
|
_TRAINING_FILE_URL = "uc?id=1Hn30-V5tm_JxKB7Q09BpZJu1VylinpGu&export=download" |
|
_DEV_FILE_URL = "uc?id=1saGAPzk0zaj6dIo5FKa1rb5SCdHwJnAq&export=download" |
|
_TEST_FILE_URL = "uc?id=1stsN0Iq1guKNH0oJc0ZjqIj57ExR_iYT&export=download" |
|
|
|
|
|
class NER_BAILIIConfig(datasets.BuilderConfig): |
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for NER_BAILIIConfig. |
|
|
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(NER_BAILIIConfig, self).__init__(**kwargs) |
|
|
|
|
|
class NER_BAILII(datasets.GeneratorBasedBuilder): |
|
"""NER-BAILII-UK-CCA. Criminal court appeals of uk""" |
|
BUILDER_CONFIGS = [ |
|
NER_BAILIIConfig( |
|
name="NER-BAILII-UK-CCA", version=datasets.Version("1.0.0"), description="The NER-BAILII-UK-CCA Name Entities recognization 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', |
|
'B-defendant_pleaded_guilty', |
|
'I-defendant_pleaded_guilty', |
|
'B-appeal_against_sentence', |
|
'I-appeal_against_sentence', |
|
'B-defendant', |
|
'I-defendant', |
|
'B-date_of_original_trial_or_conviction', |
|
'I-date_of_original_trial_or_conviction', |
|
'B-offence', |
|
'I-offence', |
|
'B-defendant_original_sentence', |
|
'I-defendant_original_sentence', |
|
'B-decision_granted', |
|
'I-decision_granted', |
|
'B-date_of_crime', |
|
'I-date_of_crime', |
|
'B-decision_refused', |
|
'I-decision_refused', |
|
'B-expert_witness_used_at_original_trail', |
|
'I-expert_witness_used_at_original_trail', |
|
'B-victim_age', |
|
'I-victim_age', |
|
'B-defendant_is_female', |
|
'I-defendant_is_female', |
|
'B-appeal_against_conviction', |
|
'I-appeal_against_conviction', |
|
'B-defendant_custodial_sentence_years', |
|
'I-defendant_custodial_sentence_years', |
|
'B-date_of_offence', |
|
'I-date_of_offence', |
|
'B-decision_quashed', |
|
'I-decision_quashed', |
|
'B-defendant_gender', |
|
'B-victim_is_male', |
|
'B-victim_is_female', |
|
'B-victim_gender', |
|
'B-previous_convictions', |
|
'I-previous_convictions', |
|
'I-s_age', |
|
] |
|
) |
|
) |
|
|
|
} |
|
|
|
), |
|
supervised_keys=None, |
|
homepage="http://linkedin", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
urls_to_download = { |
|
"train": f"{_URL}{_TRAINING_FILE_URL}", |
|
"dev": f"{_URL}{_DEV_FILE_URL}", |
|
"test": f"{_URL}{_TEST_FILE_URL}", |
|
} |
|
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, encoding="utf-8") as f: |
|
current_tokens = [] |
|
current_labels = [] |
|
sentence_counter = 0 |
|
|
|
for row in f: |
|
row = row.rstrip() |
|
if row: |
|
token, label = row.split("\t") |
|
current_tokens.append(token) |
|
current_labels.append(label) |
|
else: |
|
|
|
if not current_tokens: |
|
|
|
continue |
|
assert len(current_tokens) == len(current_labels), "💔 between len of tokens & labels" |
|
sentence = ( |
|
sentence_counter, |
|
{ |
|
"id": str(sentence_counter), |
|
"tokens": current_tokens, |
|
"ner_tags": current_labels, |
|
}, |
|
) |
|
sentence_counter += 1 |
|
current_tokens = [] |
|
current_labels = [] |
|
yield sentence |
|
|
|
|
|
if current_tokens: |
|
yield sentence_counter, { |
|
"id": str(sentence_counter), |
|
"tokens": current_tokens, |
|
"ner_tags": current_labels, |
|
} |