Chun commited on
Commit
26b4b74
1 Parent(s): 51b66c6

Create dataset.py

Browse files
Files changed (1) hide show
  1. dataset.py +94 -0
dataset.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """dataset.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1sNXmgV-J4w6JSdtXK-0TckTP5SFkGPtz
8
+
9
+ ###Create a file.py
10
+ """
11
+
12
+ import datasets
13
+ import csv
14
+ import pandas as pd
15
+
16
+ _URLS = {
17
+ "zh-en": {
18
+ "TRAIN_DOWNLOAD_URL": "https://drive.google.com/u/0/uc?id=1bGzmCXre__7mY7DhGFTWH2tJS4ZtTm5L&export=download",
19
+ "VALIDATION_DOWNLOAD_URL": "https://drive.google.com/u/0/uc?id=15xUzB1fj2U7eWDZIjEUWkgVKjv14r43_&export=download",
20
+ "TEST_DOWNLOAD_URL": "https://drive.google.com/u/0/uc?id=18r8dCsLazDyliRoEDtbt3aOcPh8d_baJ&export=download"
21
+ }
22
+ }
23
+
24
+ class NewDataset(datasets.GeneratorBasedBuilder):
25
+
26
+ VERSION = datasets.Version("1.0.0")
27
+
28
+ BUILDER_CONFIGS = [
29
+ datasets.BuilderConfig(
30
+ name = "zh-en",
31
+ version = VERSION,
32
+ description = "The translation dataset between Traditional Chinese and English"
33
+ )
34
+ ]
35
+
36
+ def _info(self):
37
+
38
+ if self.config.name == "zh-en": # This is the name of the configuration selected in BUILDER_CONFIGS above
39
+ features = datasets.Features(
40
+ { "translation": datasets.features.Translation( languages=["en", "zh"] ) }
41
+ )
42
+
43
+ return datasets.DatasetInfo(
44
+ # This is the description that will appear on the datasets page.
45
+ # description=_DESCRIPTION,
46
+ # This defines the different columns of the dataset and their types
47
+ features=features, # Here we define them above because they are different between the two configurations
48
+ # If there's a common (input, target) tuple from the features,
49
+ # specify them here. They'll be used if as_supervised=True in
50
+ # builder.as_dataset.
51
+ supervised_keys=None,
52
+ # Homepage of the dataset for documentation
53
+ # homepage=_HOMEPAGE,
54
+ # License for the dataset if available
55
+ # license=_LICENSE,
56
+ # Citation for the dataset
57
+ # citation=_CITATION,
58
+ )
59
+
60
+ def _split_generators(self, dl_manager):
61
+ """ Returns SplitGenerators"""
62
+
63
+ my_urls = _URLS[self.config.name]
64
+
65
+ train_path = dl_manager.download_and_extract(my_urls["TRAIN_DOWNLOAD_URL"])
66
+ validation_path = dl_manager.download_and_extract(my_urls["VALIDATION_DOWNLOAD_URL"])
67
+ test_path = dl_manager.download_and_extract(my_urls["TEST_DOWNLOAD_URL"])
68
+
69
+ return [
70
+ datasets.SplitGenerator(
71
+ name=datasets.Split.TRAIN,
72
+ gen_kwargs = { "filepath" : train_path, "split" : "train" }
73
+ ),
74
+ datasets.SplitGenerator(
75
+ name=datasets.Split.VALIDATION,
76
+ gen_kwargs = { "filepath" : validation_path, "split" : "validation" }
77
+ ),
78
+ datasets.SplitGenerator(
79
+ name=datasets.Split.TEST,
80
+ gen_kwargs = { "filepath" : test_path, "split" : "test"},
81
+ )
82
+ ]
83
+
84
+ def _generate_examples(self, filepath, split):
85
+ """ Generate Dravidian MT examples"""
86
+
87
+ with open(filepath, encoding="utf-8") as f:
88
+ reader = csv.DictReader(f)
89
+ for idx, row in enumerate(reader):
90
+
91
+ if self.config.name == "zh-en":
92
+ result = { "translation" : { "en" : row["en"], "zh" : row["zh"] } }
93
+
94
+ yield idx, result