File size: 4,692 Bytes
6b1068d 6e96c33 12ef13a 6e96c33 6b1068d 6e96c33 6b1068d 6e96c33 6b1068d 1cff0e9 6e96c33 6b1068d 1cff0e9 6b1068d 6e96c33 6b1068d 6e96c33 6b1068d 6e96c33 6b1068d 6e96c33 6b1068d 6e96c33 6b1068d 6e96c33 6b1068d 6e96c33 |
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 |
# 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
|