cdleong commited on
Commit
bc885a9
1 Parent(s): ca6c7d3

Upload piglatin-mt.py

Browse files
Files changed (1) hide show
  1. piglatin-mt.py +125 -0
piglatin-mt.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
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
+ """TODO: Add a description here."""
16
+
17
+
18
+ import json
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ # TODO: Add BibTeX citation
25
+ # Find for instance the citation on arxiv or on the dataset repo/website
26
+ _CITATION = """\
27
+ @InProceedings{huggingface:dataset,
28
+ title = {A great new dataset},
29
+ author={huggingface, Inc.
30
+ },
31
+ year={2020}
32
+ }
33
+ """
34
+
35
+
36
+ # You can copy an official description
37
+ _DESCRIPTION = """\
38
+ Pig-latin machine and English parallel machine translation corpus.
39
+
40
+ Based on
41
+ The Project Gutenberg EBook of "De Bello Gallico" and Other Commentaries
42
+ https://www.gutenberg.org/ebooks/10657
43
+
44
+ Converted to pig-latin with https://github.com/bpabel/piglatin
45
+ """
46
+
47
+ _HOMEPAGE = "cdleong.github.io"
48
+
49
+ # TODO: Add the licence for the dataset here if you can find it
50
+ _LICENSE = "MIT License, derived from public domain text and converted with MIT-licensed software."
51
+
52
+ # TODO: Add link to the official dataset URLs here
53
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
54
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
55
+ _URLS = {
56
+ "train": "./piglatin-mt-train.json",
57
+ "dev": "./piglatin-mt-test.json",
58
+ }
59
+
60
+
61
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
62
+ class PigLatin-MT(datasets.GeneratorBasedBuilder):
63
+ """Machine Translation dataset created with """
64
+
65
+ VERSION = datasets.Version("1.0.0")
66
+
67
+ # This is an example of a dataset with multiple configurations.
68
+ # If you don't want/need to define several sub-sets in your dataset,
69
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
70
+
71
+ # If you need to make complex sub-parts in the datasets with configurable options
72
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
73
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
74
+
75
+ # You will be able to load one or the other configurations in the following list with
76
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
77
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
78
+ BUILDER_CONFIGS = [
79
+ datasets.BuilderConfig(name="piglatin-mt",
80
+ version=VERSION,
81
+ description="This part of my dataset covers a first domain"),
82
+ ]
83
+
84
+ def _info(self):
85
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
86
+ features=datasets.Features({"translation": datasets.features.Translation(languages=("eng", "engyay"))})
87
+
88
+ return datasets.DatasetInfo(
89
+ # This is the description that will appear on the datasets page.
90
+ description=_DESCRIPTION,
91
+ # This defines the different columns of the dataset and their types
92
+ features=features, # Here we define them above because they are different between the two configurations
93
+ # If there's a common (input, target) tuple from the features,
94
+ # specify them here. They'll be used if as_supervised=True in
95
+ # builder.as_dataset.
96
+ supervised_keys=None,
97
+ # Homepage of the dataset for documentation
98
+ homepage=_HOMEPAGE,
99
+ # License for the dataset if available
100
+ license=_LICENSE,
101
+ # Citation for the dataset
102
+ citation=_CITATION,
103
+ )
104
+
105
+ def _split_generators(self, dl_manager):
106
+ """Returns SplitGenerators."""
107
+ downloaded_files = dl_manager.download_and_extract(_URLS)
108
+ return [
109
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
110
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
111
+ ]
112
+
113
+ def _generate_examples(
114
+ self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
115
+ ):
116
+ """ Yields examples as (key, example) tuples. """
117
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
118
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
119
+
120
+ with open(filepath, encoding="utf-8") as f:
121
+ for id_, row in enumerate(f):
122
+ data = json.loads(row)
123
+ result = {"translation": {"eng": data["eng"], "yo": data["engyay"]}}
124
+ yield id_, result
125
+