svanhvit commited on
Commit
6b1068d
1 Parent(s): a3ab3da

loader file added

Browse files
Files changed (3) hide show
  1. load_iceerrorcorpus.py +146 -0
  2. test.tsv +0 -0
  3. valid.tsv +0 -0
load_iceerrorcorpus.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ import csv
3
+ import json
4
+ import os
5
+ from typing import List
6
+ import datasets
7
+
8
+
9
+ _DESCRIPTION = """\
10
+ Icelandic GEC corpus.
11
+
12
+ 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.
13
+ """
14
+
15
+ # TODO: Add a link to an official homepage for the dataset here
16
+ _HOMEPAGE = "https://repository.clarin.is/repository/xmlui/handle/20.500.12537/105"
17
+
18
+ # TODO: Add the licence for the dataset here if you can find it
19
+ _LICENSE = "CC BY 4.0"
20
+
21
+ # TODO: Add link to the official dataset URLs here
22
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
23
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
24
+ _URLS = {
25
+ "train": "train.tsv",
26
+ "dev": "valid.tsv",
27
+ "test": "test.tsv",
28
+
29
+ }
30
+
31
+ class Squad(datasets.GeneratorBasedBuilder):
32
+ """SQUAD: The Stanford Question Answering Dataset. Version 1.1."""
33
+
34
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
35
+ downloaded_files = dl_manager.download_and_extract(_URLS)
36
+
37
+ return [
38
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
39
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
40
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["test"]}),
41
+ ]
42
+
43
+
44
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
45
+ class NewDataset(datasets.GeneratorBasedBuilder):
46
+ """TODO: Short description of my dataset."""
47
+
48
+ VERSION = datasets.Version("1.0.0")
49
+
50
+ # This is an example of a dataset with multiple configurations.
51
+ # If you don't want/need to define several sub-sets in your dataset,
52
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
53
+
54
+ # If you need to make complex sub-parts in the datasets with configurable options
55
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
56
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
57
+
58
+ # You will be able to load one or the other configurations in the following list with
59
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
60
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
61
+ BUILDER_CONFIGS = [
62
+ datasets.BuilderConfig(
63
+ name="iceErrorCorpus", version=VERSION, description="Icelandic GEC corpus"
64
+ ),
65
+ ]
66
+
67
+ def _info(self):
68
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
69
+ if self.config.name == "iceErrorCorpus": # This is the name of the configuration selected in BUILDER_CONFIGS above
70
+ features = datasets.Features(
71
+ {
72
+ "src": datasets.Value("string"),
73
+ "tgt": datasets.Value("string"),
74
+ # These are the features of your dataset like images, labels ...
75
+ }
76
+ )
77
+
78
+ return datasets.DatasetInfo(
79
+ # This is the description that will appear on the datasets page.
80
+ description=_DESCRIPTION,
81
+ # This defines the different columns of the dataset and their types
82
+ features=features, # Here we define them above because they are different between the two configurations
83
+ # If there's a common (input, target) tuple from the features,
84
+ # specify them here. They'll be used if as_supervised=True in
85
+ # builder.as_dataset.
86
+ supervised_keys=None,
87
+ # Homepage of the dataset for documentation
88
+ homepage=_HOMEPAGE,
89
+ # License for the dataset if available
90
+ license=_LICENSE,
91
+ # Citation for the dataset
92
+ citation=_CITATION,
93
+ )
94
+
95
+ def _split_generators(self, dl_manager):
96
+ """Returns SplitGenerators."""
97
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
98
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
99
+
100
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
101
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
102
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
103
+ my_urls = _URLs[self.config.name]
104
+ data_dir = dl_manager.download_and_extract(my_urls)
105
+ return [
106
+ datasets.SplitGenerator(
107
+ name=datasets.Split.TRAIN,
108
+ # These kwargs will be passed to _generate_examples
109
+ gen_kwargs={
110
+ "filepath": os.path.join(data_dir, "train.tsv"),
111
+ "split": "train",
112
+ },
113
+ ),
114
+ datasets.SplitGenerator(
115
+ name=datasets.Split.TEST,
116
+ # These kwargs will be passed to _generate_examples
117
+ gen_kwargs={
118
+ "filepath": os.path.join(data_dir, "test.tsv"),
119
+ "split": "test"
120
+ },
121
+ ),
122
+ datasets.SplitGenerator(
123
+ name=datasets.Split.VALIDATION,
124
+ # These kwargs will be passed to _generate_examples
125
+ gen_kwargs={
126
+ "filepath": os.path.join(data_dir, "valid.tsv"),
127
+ "split": "dev",
128
+ },
129
+ ),
130
+ ]
131
+
132
+ def _generate_examples(
133
+ self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
134
+ ):
135
+ """ Yields examples as (key, example) tuples. """
136
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
137
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
138
+
139
+ with open(filepath, encoding="utf-8") as f:
140
+ for id_, row in enumerate(f):
141
+ data = json.loads(row)
142
+ if self.config.name == "iceErrorCorpus":
143
+ yield id_, {
144
+ "src": data["src"],
145
+ "tgt": data["tgt"],
146
+ }
test.tsv CHANGED
The diff for this file is too large to render. See raw diff
 
valid.tsv CHANGED
The diff for this file is too large to render. See raw diff