Datasets:
Tasks:
Text Classification
Sub-tasks:
acceptability-classification
Languages:
Italian
ArXiv:
License:
File size: 4,881 Bytes
6b37eca 5fa2041 6b37eca c2a1a09 269d62a e977d95 b250cc4 e977d95 |
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 |
import csv
import sys
import datasets
from typing import List
csv.field_size_limit(sys.maxsize)
_CITATION = """\
@inproceedings{trotta-etal-2021-itacola,
author = {Trotta, Daniela and Guarasci, Raffaele and Leonardelli, Elisa and Tonelli, Sara},
title = {Monolingual and Cross-Lingual Acceptability Judgments with the Italian {CoLA} corpus},
journal = {Arxiv preprint},
year = {2021},
}
"""
_DESCRIPTION = """\
The Italian Corpus of Linguistic Acceptability includes almost 10k sentences taken from
linguistic literature with a binary annotation made by the original authors themselves.
The work is inspired by the English Corpus of Linguistic Acceptability (CoLA) by Warstadt et al.
Part of the dataset has been manually annotated to highlight 9 linguistic phenomena.
"""
_HOMEPAGE = "https://github.com/dhfbk/ItaCoLA-dataset"
_LICENSE = "None"
_SPLITS = ["train", "test"]
class ItaColaConfig(datasets.BuilderConfig):
"""BuilderConfig for ItaCoLA."""
def __init__(
self,
features,
data_url,
**kwargs,
):
"""
Args:
features: `list[string]`, list of the features that will appear in the
feature dict. Should not include "label".
data_url: `string`, url to download the zip file from.
**kwargs: keyword arguments forwarded to super.
"""
super().__init__(version=datasets.Version("1.0.0"), **kwargs)
self.data_url = data_url
self.features = features
class ItaCola(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
ItaColaConfig(
name="scores",
features=["unique_id", "source", "acceptability", "sentence"],
data_url="https://raw.githubusercontent.com/dhfbk/ItaCoLA-dataset/main/ItaCoLA_dataset.tsv"
),
ItaColaConfig(
name="phenomena",
features=[
"unique_id",
"source",
"acceptability",
"sentence",
"cleft_construction",
"copular_construction",
"subject_verb_agreement",
"wh_islands_violations",
"simple",
"question",
"auxiliary",
"bind",
"indefinite_pronouns",
],
data_url="https://github.com/dhfbk/ItaCoLA-dataset/raw/main/ItaCoLA_dataset_phenomenon.tsv"
),
]
DEFAULT_CONFIG_NAME = "scores"
def _info(self):
features = {feature: datasets.Value("int32") for feature in self.config.features}
features["source"] = datasets.Value("string")
features["sentence"] = datasets.Value("string")
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(features),
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_file = dl_manager.download_and_extract(self.config.data_url)
if self.config.name == "scores":
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_file,
"split": "train",
"features": self.config.features,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": data_file,
"split": "test",
"features": self.config.features,
},
),
]
else:
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_file,
"split": "train",
"features": self.config.features,
},
),
]
def _generate_examples(self, filepath: str, split: str, features: List[str]):
"""Yields examples as (key, example) tuples."""
with open(filepath, encoding="utf8") as f:
for id_, row in enumerate(f):
if id_ == 0:
continue
ex_split = None
fields = row.strip().split("\t")
if len(fields) < 6:
ex_split = fields[-1]
fields = fields[:-1],
if ex_split is None or ex_split.strip() == split:
yield id_, {
k:v.strip() for k,v in zip(features, fields[0])
}
|