frtna commited on
Commit
b1cc3a3
1 Parent(s): f677dde

initial commit

Browse files
Files changed (1) hide show
  1. jwt300_mt.py +163 -0
jwt300_mt.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 csv
19
+ import json
20
+ import os
21
+ import sys
22
+
23
+ import datasets
24
+
25
+
26
+ # TODO: Add BibTeX citation
27
+ # Find for instance the citation on arxiv or on the dataset repo/website
28
+ _CITATION = """\
29
+ @InProceedings{phd,
30
+ title = {JWT-300 OPUS Machine Translation Dataset},
31
+ author={hmtkvs, Inc.
32
+ },
33
+ year={2021}
34
+ }
35
+ """
36
+
37
+ # TODO: Add description of the dataset here
38
+ # You can copy an official description
39
+ _DESCRIPTION = """\
40
+ This new dataset is designed to be used in the scope of machine translation project.
41
+ """
42
+
43
+ # TODO: Add a link to an official homepage for the dataset here
44
+ _HOMEPAGE = ""
45
+
46
+ # TODO: Add the licence for the dataset here if you can find it
47
+ _LICENSE = ""
48
+
49
+ # TODO: Add link to the official dataset URLs here
50
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
51
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
52
+ # url = "https://drive.google.com/drive/folders/1Jvvddj0abp9rMAGhqXqpPbE8-Y28iyM3?usp=sharing"
53
+ _URLs = {
54
+ "train": "train_.json",#"https://drive.google.com/uc?export=download&id=1-0r83eGwRfmfVAEtdyiregvneJ81ev1N",
55
+ "validation": "validation_.json",#"https://drive.google.com/uc?export=download&id=1-0zTW12OKIPrH3Zmad6tvSte7bA8O4RR",
56
+ "test": "test_.json"#"https://drive.google.com/uc?export=download&id=1-2U6BeDluJxIieMA6JTjLoij_KcMhl4Y"
57
+ }
58
+
59
+
60
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
61
+ class NewDataset(datasets.GeneratorBasedBuilder):
62
+ """TODO: Short description of my dataset."""
63
+
64
+ VERSION = datasets.Version("1.1.0")
65
+
66
+ # This is an example of a dataset with multiple configurations.
67
+ # If you don't want/need to define several sub-sets in your dataset,
68
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
69
+
70
+ # If you need to make complex sub-parts in the datasets with configurable options
71
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
72
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
73
+
74
+ # You will be able to load one or the other configurations in the following list with
75
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
76
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
77
+ BUILDER_CONFIGS = [
78
+ datasets.BuilderConfig(name="jwt300_mt", version=VERSION, description="First domain")
79
+ ]
80
+
81
+ # DEFAULT_CONFIG_NAME = "opus_books_es_it" # It's not mandatory to have a default configuration. Just use one if it make sense.
82
+
83
+ def _info(self):
84
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
85
+ # if self.config.name == "opus_books_es_it": # This is the name of the configuration selected in BUILDER_CONFIGS above
86
+ features=datasets.Features({"translation": datasets.features.Translation(languages=("Spanish", "Italian"))})
87
+ # features = datasets.Features(
88
+ # {
89
+ # "Spanish": datasets.Value("string"),
90
+ # "Italian": datasets.Value("string")
91
+ # # These are the features of your dataset like images, labels ...
92
+ # }
93
+ # )
94
+
95
+ return datasets.DatasetInfo(
96
+ # This is the description that will appear on the datasets page.
97
+ description=_DESCRIPTION,
98
+ # This defines the different columns of the dataset and their types
99
+ features=features, # Here we define them above because they are different between the two configurations
100
+ # If there's a common (input, target) tuple from the features,
101
+ # specify them here. They'll be used if as_supervised=True in
102
+ # builder.as_dataset.
103
+ supervised_keys=None,
104
+ # Homepage of the dataset for documentation
105
+ homepage=_HOMEPAGE,
106
+ # License for the dataset if available
107
+ license=_LICENSE,
108
+ # Citation for the dataset
109
+ citation=_CITATION,
110
+ )
111
+
112
+ def _split_generators(self, dl_manager):
113
+ """Returns SplitGenerators."""
114
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
115
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
116
+
117
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
118
+ # 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.
119
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
120
+ dl_path = dl_manager.download_and_extract(_URLs)
121
+
122
+ return [
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.TRAIN,
125
+ # These kwargs will be passed to _generate_examples
126
+ gen_kwargs={
127
+ "filepath": dl_path['train'],
128
+ "split": "train",
129
+ },
130
+ ),
131
+ datasets.SplitGenerator(
132
+ name=datasets.Split.TEST,
133
+ # These kwargs will be passed to _generate_examples
134
+ gen_kwargs={
135
+ "filepath": dl_path['test'],
136
+ "split": "test"
137
+ },
138
+ ),
139
+ datasets.SplitGenerator(
140
+ name=datasets.Split.VALIDATION,
141
+ # These kwargs will be passed to _generate_examples
142
+ gen_kwargs={
143
+ "filepath": dl_path['validation'],
144
+ "split": "validation",
145
+ },
146
+ ),
147
+ ]
148
+
149
+ def _generate_examples(
150
+ self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
151
+ ):
152
+ """ Yields examples as (key, example) tuples. """
153
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
154
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
155
+
156
+ with open(filepath, encoding="utf-8") as f:
157
+ for id_, line in enumerate(f):
158
+ data = json.loads(line)
159
+ yield id_, {
160
+ "translation":{"Spanish": data["Spanish"],
161
+ "Italian": data["Italian"]#"" if split == "test" else data["Italian"],
162
+ }
163
+ }