Matīss commited on
Commit
b6cfcca
1 Parent(s): cbff5e1

Upload liv4ever.py

Browse files
Files changed (1) hide show
  1. liv4ever.py +76 -41
liv4ever.py CHANGED
@@ -1,4 +1,3 @@
1
- # coding=utf-8
2
  # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
  #
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,14 +11,19 @@
12
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
  # See the License for the specific language governing permissions and
14
  # limitations under the License.
 
15
  """Liv4ever dataset."""
16
 
17
 
 
18
  import json
 
19
 
20
  import datasets
21
 
22
 
 
 
23
  _CITATION = """\
24
  @inproceedings{rikters-etal-2022,
25
  title = "Machine Translation for Livonian: Catering for 20 Speakers",
@@ -35,7 +39,8 @@ _CITATION = """\
35
  }
36
  """
37
 
38
-
 
39
  _DESCRIPTION = """\
40
  Livonian is one of the most endangered languages in Europe with just a tiny handful of speakers and virtually no publicly available corpora.
41
  In this paper we tackle the task of developing neural machine translation (NMT) between Livonian and English, with a two-fold aim: on one hand,
@@ -52,88 +57,118 @@ Fields:
52
  - liv: sentence in Livonian
53
  """
54
 
55
- _HOMEPAGE = "https://huggingface.co/datasets/tartuNLP/liv4ever-data"
 
56
 
 
57
  _LICENSE = "CC BY-NC-SA 4.0"
58
 
59
- _REPO = "https://huggingface.co/datasets/tartuNLP/liv4ever/raw/main/"
60
-
61
- _URLs = {
62
- "train": _REPO + "train.json",
63
- "dev": _REPO + "dev.json",
64
- "test": _REPO + "test.json",
 
65
  }
66
 
67
 
 
68
  class liv4ever(datasets.GeneratorBasedBuilder):
69
  """Liv4ever dataset."""
70
 
71
  VERSION = datasets.Version("1.0.0")
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  def _info(self):
 
74
  features = datasets.Features(
75
  {
76
  "source": datasets.Value("string"),
77
  "en": datasets.Value("string"),
78
- "liv": datasets.Value("string"),
 
79
  }
80
  )
81
  return datasets.DatasetInfo(
 
82
  description=_DESCRIPTION,
83
- features=features,
84
- supervised_keys=None,
 
 
 
 
85
  homepage=_HOMEPAGE,
 
86
  license=_LICENSE,
 
87
  citation=_CITATION,
88
  )
89
 
90
  def _split_generators(self, dl_manager):
91
- """Returns SplitGenerators."""
92
- data_dir = dl_manager.download_and_extract(_URLs)
93
-
 
 
 
 
 
94
  return [
95
  datasets.SplitGenerator(
96
  name=datasets.Split.TRAIN,
 
97
  gen_kwargs={
98
- "filepath": data_dir["train"],
99
  "split": "train",
100
  },
101
  ),
102
  datasets.SplitGenerator(
103
  name=datasets.Split.TEST,
104
- gen_kwargs={"filepath": data_dir["test"], "split": "test"},
 
 
 
 
105
  ),
106
  datasets.SplitGenerator(
107
  name=datasets.Split.VALIDATION,
 
108
  gen_kwargs={
109
- "filepath": data_dir["dev"],
110
  "split": "dev",
111
  },
112
  ),
113
  ]
114
 
 
115
  def _generate_examples(self, filepath, split):
116
- """Yields examples."""
117
-
118
  with open(filepath, encoding="utf-8") as f:
119
- data = json.load(f)
120
-
121
-
122
- for dialogue in data:
123
- source = dialogue["source"]
124
- sentences = dialogue["sentences"]
125
-
126
- i=0
127
-
128
- for turn in sentences:
129
- i = i+1
130
- sent_no = i
131
- en = dialogue["en"]
132
- liv = dialogue["liv"]
133
-
134
- yield f"{sent_no}", {
135
- "no": sent_no,
136
- "source": source,
137
- "en": en,
138
- "liv": liv,
139
- }
 
 
1
  # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
  #
3
  # Licensed under the Apache License, Version 2.0 (the "License");
 
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
  # See the License for the specific language governing permissions and
13
  # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
  """Liv4ever dataset."""
16
 
17
 
18
+ import csv
19
  import json
20
+ import os
21
 
22
  import datasets
23
 
24
 
25
+ # TODO: Add BibTeX citation
26
+ # Find for instance the citation on arxiv or on the dataset repo/website
27
  _CITATION = """\
28
  @inproceedings{rikters-etal-2022,
29
  title = "Machine Translation for Livonian: Catering for 20 Speakers",
 
39
  }
40
  """
41
 
42
+ # TODO: Add description of the dataset here
43
+ # You can copy an official description
44
  _DESCRIPTION = """\
45
  Livonian is one of the most endangered languages in Europe with just a tiny handful of speakers and virtually no publicly available corpora.
46
  In this paper we tackle the task of developing neural machine translation (NMT) between Livonian and English, with a two-fold aim: on one hand,
 
57
  - liv: sentence in Livonian
58
  """
59
 
60
+ # TODO: Add a link to an official homepage for the dataset here
61
+ _HOMEPAGE = "https://huggingface.co/datasets/tartuNLP/liv4ever"
62
 
63
+ # TODO: Add the licence for the dataset here if you can find it
64
  _LICENSE = "CC BY-NC-SA 4.0"
65
 
66
+ # TODO: Add link to the official dataset URLs here
67
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
68
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
69
+ _URLS = {
70
+ "train": "https://huggingface.co/datasets/tartuNLP/liv4ever/raw/main/train.json",
71
+ "dev": "https://huggingface.co/datasets/tartuNLP/liv4ever/raw/main/dev.json",
72
+ "test": "https://huggingface.co/datasets/tartuNLP/liv4ever/raw/main/test.json",
73
  }
74
 
75
 
76
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
77
  class liv4ever(datasets.GeneratorBasedBuilder):
78
  """Liv4ever dataset."""
79
 
80
  VERSION = datasets.Version("1.0.0")
81
 
82
+ # This is an example of a dataset with multiple configurations.
83
+ # If you don't want/need to define several sub-sets in your dataset,
84
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
85
+
86
+ # If you need to make complex sub-parts in the datasets with configurable options
87
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
88
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
89
+
90
+ # You will be able to load one or the other configurations in the following list with
91
+ # data = datasets.load_dataset('my_dataset', 'train')
92
+ # data = datasets.load_dataset('my_dataset', 'dev')
93
+ BUILDER_CONFIGS = [
94
+ datasets.BuilderConfig(name="train", version=VERSION, description="This part of my dataset covers a first domain"),
95
+ datasets.BuilderConfig(name="dev", version=VERSION, description="This part of my dataset covers a second domain"),
96
+ ]
97
+
98
+ DEFAULT_CONFIG_NAME = "train" # It's not mandatory to have a default configuration. Just use one if it make sense.
99
+
100
  def _info(self):
101
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
102
  features = datasets.Features(
103
  {
104
  "source": datasets.Value("string"),
105
  "en": datasets.Value("string"),
106
+ "liv": datasets.Value("string")
107
+ # These are the features of your dataset like images, labels ...
108
  }
109
  )
110
  return datasets.DatasetInfo(
111
+ # This is the description that will appear on the datasets page.
112
  description=_DESCRIPTION,
113
+ # This defines the different columns of the dataset and their types
114
+ features=features, # Here we define them above because they are different between the two configurations
115
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
116
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
117
+ # supervised_keys=("sentence", "label"),
118
+ # Homepage of the dataset for documentation
119
  homepage=_HOMEPAGE,
120
+ # License for the dataset if available
121
  license=_LICENSE,
122
+ # Citation for the dataset
123
  citation=_CITATION,
124
  )
125
 
126
  def _split_generators(self, dl_manager):
127
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
128
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
129
+
130
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
131
+ # 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.
132
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
133
+ urls = _URLS[self.config.name]
134
+ data_dir = dl_manager.download_and_extract(urls)
135
  return [
136
  datasets.SplitGenerator(
137
  name=datasets.Split.TRAIN,
138
+ # These kwargs will be passed to _generate_examples
139
  gen_kwargs={
140
+ "filepath": os.path.join(data_dir, "train.jsonl"),
141
  "split": "train",
142
  },
143
  ),
144
  datasets.SplitGenerator(
145
  name=datasets.Split.TEST,
146
+ # These kwargs will be passed to _generate_examples
147
+ gen_kwargs={
148
+ "filepath": os.path.join(data_dir, "test.jsonl"),
149
+ "split": "test"
150
+ },
151
  ),
152
  datasets.SplitGenerator(
153
  name=datasets.Split.VALIDATION,
154
+ # These kwargs will be passed to _generate_examples
155
  gen_kwargs={
156
+ "filepath": os.path.join(data_dir, "dev.jsonl"),
157
  "split": "dev",
158
  },
159
  ),
160
  ]
161
 
162
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
163
  def _generate_examples(self, filepath, split):
164
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
165
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
166
  with open(filepath, encoding="utf-8") as f:
167
+ for key, row in enumerate(f):
168
+ data = json.loads(row)
169
+ # Yields examples as (key, example) tuples
170
+ yield key, {
171
+ "source": data["source"],
172
+ "en": data["en"],
173
+ "liv": data["liv"],
174
+ }