ronald commited on
Commit
bf36292
1 Parent(s): 09420e7

initial commit

Browse files
Files changed (1) hide show
  1. scitechnews.py +142 -0
scitechnews.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 re
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
+ <bibtext>
29
+ """
30
+
31
+ # TODO: Add description of the dataset here
32
+ # You can copy an official description
33
+ _DESCRIPTION = """\
34
+ The SciTechNews dataset consists of scientific papers paired with their corresponding
35
+ press release snippet mined from ACM TechNews.
36
+ This dataset is designed for the task for automatic science journalism, a task that requires summarization,
37
+ text simplification, and style transfer
38
+ """
39
+
40
+ # TODO: Add a link to an official homepage for the dataset here
41
+ _HOMEPAGE = "https://github.com/ronaldahmed/scitechnews"
42
+
43
+ # TODO: Add the licence for the dataset here if you can find it
44
+ _LICENSE = "CC BY-SA 3.0"
45
+
46
+ # TODO: Add link to the official dataset URLs here
47
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
48
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
49
+ _URLs = {
50
+ "train": "train.json",
51
+ "validation": "valid.json",
52
+ "test": "test.json",
53
+ }
54
+
55
+
56
+
57
+ class SciTechNews(datasets.GeneratorBasedBuilder):
58
+ """A summarization dataset with multiple domains."""
59
+
60
+ VERSION = datasets.Version("0.1.0")
61
+
62
+ # If you need to make complex sub-parts in the datasets with configurable options
63
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
64
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
65
+
66
+ # You will be able to load one or the other configurations in the following list with
67
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
68
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
69
+ BUILDER_CONFIGS = [
70
+ datasets.BuilderConfig(
71
+ name="scitechnews", version=VERSION, description="Animal domain"
72
+ ),
73
+ ]
74
+
75
+ def _info(self):
76
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
77
+ features = datasets.Features(
78
+ {
79
+ "id": datasets.Value("string"),
80
+ "pr-title": datasets.Value("string"),
81
+ "pr-article": datasets.Value("string"),
82
+ "pr-summary": datasets.Value("string"),
83
+
84
+ "sc-title": datasets.Value("string"),
85
+ "sc-article": datasets.Value("string"),
86
+ "sc-abstract": datasets.Value("string"),
87
+
88
+ "sc-section_names": datasets.features.Sequence(datasets.Value("string")),
89
+ "sc-sections": datasets.features.Sequence(datasets.Value("string")),
90
+ "sc-authors": datasets.features.Sequence(datasets.Value("string")),
91
+ }
92
+ )
93
+ return datasets.DatasetInfo(
94
+ # This is the description that will appear on the datasets page.
95
+ description=_DESCRIPTION,
96
+ # This defines the different columns of the dataset and their types
97
+ features=features, # Here we define them above because they are different between the two configurations
98
+ # If there's a common (input, target) tuple from the features,
99
+ # specify them here. They'll be used if as_supervised=True in
100
+ # builder.as_dataset.
101
+ supervised_keys=None,
102
+ # Homepage of the dataset for documentation
103
+ homepage=_HOMEPAGE,
104
+ # License for the dataset if available
105
+ license=_LICENSE,
106
+ # Citation for the dataset
107
+ citation=_CITATION,
108
+ )
109
+
110
+ def _split_generators(self, dl_manager):
111
+ """Returns SplitGenerators."""
112
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
113
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
114
+
115
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
116
+ # 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.
117
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
118
+ urls_to_download = _URLS
119
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
120
+
121
+ return [
122
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
123
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
124
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
125
+ ]
126
+
127
+
128
+ def _generate_examples(
129
+ self,
130
+ filepath,
131
+ split, # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
132
+ ):
133
+ """Yields examples as (key, example) tuples."""
134
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
135
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
136
+
137
+ with open(filepath, encoding="utf-8") as f:
138
+ for id_, row in enumerate(f):
139
+ data = json.loads(row)
140
+
141
+ yield id_, data
142
+