liweili commited on
Commit
5555021
1 Parent(s): 62e6409

Upload c4_200m.py

Browse files
Files changed (1) hide show
  1. c4_200m.py +95 -0
c4_200m.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 glob
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{huggingface:dataset,
29
+ title = {A great new dataset},
30
+ author={huggingface, Inc.
31
+ },
32
+ year={2020}
33
+ }
34
+ """
35
+
36
+ _DESCRIPTION = """\
37
+ GEC Dataset Generated from C4
38
+ """
39
+
40
+ _HOMEPAGE = "https://www.kaggle.com/a0155991rliwei/c4-200m"
41
+
42
+ _LICENSE = ""
43
+
44
+ _URL = "data/data.zip"
45
+
46
+
47
+ class C4200M(datasets.GeneratorBasedBuilder):
48
+ VERSION = datasets.Version("1.0.0")
49
+ DEFAULT_CONFIG_NAME = "train"
50
+
51
+ def _info(self):
52
+ features = datasets.Features(
53
+ {
54
+ "text": datasets.Value("string"),
55
+ "summary": datasets.Value("string"),
56
+ }
57
+ )
58
+ return datasets.DatasetInfo(
59
+ description=_DESCRIPTION,
60
+ features=features,
61
+ supervised_keys=None,
62
+ homepage=_HOMEPAGE,
63
+ license=_LICENSE,
64
+ citation=_CITATION,
65
+ )
66
+
67
+ def _split_generators(self, dl_manager):
68
+ """Returns SplitGenerators."""
69
+ data_dir = dl_manager.download_and_extract(_URL)
70
+ return [
71
+ datasets.SplitGenerator(
72
+ name=datasets.Split.TRAIN,
73
+ gen_kwargs={
74
+ "filepath": data_dir,
75
+ },
76
+ ),
77
+ ]
78
+
79
+ def _generate_examples(
80
+ self, filepath
81
+ ):
82
+ """ Yields examples as (key, example) tuples. """
83
+ def fix_nulls(s):
84
+ for line in s:
85
+ yield line.replace('\0', ' ')
86
+
87
+ path = filepath + "/*.tsv*"
88
+ for filename in glob.glob(path):
89
+ with open(filename, encoding="utf-8") as f:
90
+ reader = csv.reader(fix_nulls(f), delimiter="\t", quoting=csv.QUOTE_NONE)
91
+ for id_, row in enumerate(reader):
92
+ yield id_, {
93
+ "text": row[0],
94
+ "summary": row[1],
95
+ }