Datasets:
File size: 3,545 Bytes
f3ba4e5 6bc6c66 f3ba4e5 0d4d143 f3ba4e5 a9586bc f3ba4e5 053a9a0 f3ba4e5 4554bc0 f3ba4e5 c8e9ede f3ba4e5 42bbdb8 f3ba4e5 deceb2d f3ba4e5 96777ef f3ba4e5 |
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 |
# Loading script for the COPA-ca dataset.
import json
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = ""
_DESCRIPTION = """\
The COPA-ca dataset (Choice of plausible alternatives in Catalan) is a professional translation of the English COPA dataset into Catalan, commissioned by BSC LangTech Unit. The dataset consists of 1000 premises, each given a question and two choices with a label encoding which of the choices is more plausible given the annotator.
The dataset is split into 400 training samples, 100 validation samples, and 500 test samples. It includes the following features: 'premise', 'choice1', 'choice2', 'label', 'question', 'changed' (boolean).
This work is licensed under a Attribution-ShareAlike 4.0 International License.
"""
_HOMEPAGE = "https://zenodo.org/record/8124398"
_URL = "https://huggingface.co/datasets/projecte-aina/copa-ca/resolve/main/"
_TRAIN_FILE = "copa-ca.train.jsonl"
_DEV_FILE = "copa-ca.val.jsonl"
_TEST_FILE = "copa-ca.test.jsonl"
class copaCaConfig(datasets.BuilderConfig):
""" Builder config for the COPA-ca dataset """
def __init__(self, **kwargs):
"""BuilderConfig for COPA-ca.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(copaCaConfig, self).__init__(**kwargs)
class copaCa(datasets.GeneratorBasedBuilder):
""" COPA-ca Dataset """
BUILDER_CONFIGS = [
copaCaConfig(
name="copa-ca",
version=datasets.Version("1.0.1"),
description="COPA-ca dataset",
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"premise": datasets.Value("string"),
"choice1": datasets.Value("string"),
"choice2": datasets.Value("string"),
"question": datasets.Value("string"),
'label': datasets.features.ClassLabel(names=['1', '2']),
"idx": datasets.Value("int64"),
"changed": datasets.Value("bool"),
}
),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
"train": f"{_URL}{_TRAIN_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.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
]
def _generate_examples(self, filepath):
with open(filepath, encoding='utf-8') as f:
for i, line in enumerate(f):
data = json.loads(line)
yield i, {
'premise': data['premise'],
'choice1': data['choice1'],
'choice2': data['choice2'],
'question': data['question'],
'label': str(data['label']),
'idx': data['idx'],
'changed': data['changed']
}
|