iceErrorCorpus / iceErrorCorpus.py
svanhvit's picture
loader
1cff0e9
raw history blame
No virus
4.69 kB
# coding=utf-8
import csv
import json
import os
from typing import List
import datasets
_DESCRIPTION = """\
Icelandic GEC corpus.
The Icelandic Error Corpus (IceEC) is a collection of texts in modern Icelandic annotated for mistakes related to spelling, grammar, and other issues. The texts are organized by genre, if which there are three: student essays, online news texts and Icelandic Wikipedia articles. Each mistake is marked according to error type using an error code, of which there are 253. The corpus consists of 4,046 texts with 56,956 categorized error instances. The corpus is divided into a development corpus, which comprises 90% of the corpus, and a test corpus, which comprises the other 10% of the corpus.
"""
_HOMEPAGE = "https://repository.clarin.is/repository/xmlui/handle/20.500.12537/105"
_CITATION = """
@misc{20.500.12537/105,
title = {Icelandic Error Corpus ({IceEC}) Version 1.1},
author = {Ingason, Anton Karl and Stef{\'a}nsd{\'o}ttir, Lilja Bj{\"o}rk and Arnard{\'o}ttir, {\TH}{\'o}runn and Xu, Xindan},
url = {http://hdl.handle.net/20.500.12537/105},
note = {{CLARIN}-{IS}},
copyright = {Creative Commons - Attribution 4.0 International ({CC} {BY} 4.0)},
year = {2021} }
"""
_LICENSE = "CC BY 4.0"
_URLS = {
"train": "train.tsv",
"dev": "valid.tsv",
"test": "test.tsv",
}
class iceErrorCorpus(datasets.GeneratorBasedBuilder):
"""TODO: Short description of my dataset."""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="iceErrorCorpus", version=VERSION, description="Icelandic GEC corpus"
),
]
DEFAULT_CONFIG_NAME = "iceErrorCorpus"
def _info(self):
if self.config.name == "iceErrorCorpus":
features = datasets.Features(
{
"src": datasets.Value("string"),
"tgt": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features, # Here we define them above because they are different between the two configurations
# If there's a common (input, target) tuple from the features,
# specify them here. They'll be used if as_supervised=True in
# builder.as_dataset.
supervised_keys=None,
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
# License for the dataset if available
license=_LICENSE,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_dir = dl_manager.download_and_extract(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": data_dir["train"],
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": data_dir["test"],
"split": "test"
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": data_dir["dev"],
"split": "dev",
},
),
]
def _generate_examples(
self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
):
""" Yields examples as (key, example) tuples. """
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
# The `key` is here for legacy reason (tfds) and is not important in itself.
with open(filepath, encoding="utf-8") as f:
key = 0
tsv_f = csv.reader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
for row in tsv_f:
if self.config.name == "iceErrorCorpus":
yield key, {
"src": row[0],
"tgt": row[1],
}
key += 1