enoriega commited on
Commit
0a8efaf
·
1 Parent(s): 5c19536

Upload 2 files

Browse files
Files changed (2) hide show
  1. odinsynth_sequence_dataset.py +161 -0
  2. out.jsonl.gz +3 -0
odinsynth_sequence_dataset.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Dataset builder script for the Odinsynth sequence generation dataset"""
15
+
16
+
17
+ import csv
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
+ Dataset for Odinsynth sequence data generation
39
+ """
40
+
41
+ # TODO: Add a link to an official homepage for the dataset here
42
+ _HOMEPAGE = ""
43
+
44
+ _LICENSE = ""
45
+
46
+
47
+ class OdinsynthSequenceDataset(datasets.GeneratorBasedBuilder):
48
+ """This contains a dataset for odinsynth rule synthesis in a supervised manner"""
49
+
50
+ VERSION = datasets.Version("1.0.0")
51
+
52
+ # This is an example of a dataset with multiple configurations.
53
+ # If you don't want/need to define several sub-sets in your dataset,
54
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
55
+
56
+ # If you need to make complex sub-parts in the datasets with configurable options
57
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
58
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
59
+
60
+ # You will be able to load one or the other configurations in the following list with
61
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
62
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
63
+
64
+ BUILDER_CONFIGS = [
65
+ datasets.BuilderConfig(name="synthetic_surface",
66
+ version=VERSION,
67
+ description="Synthetic data with surface rules only"),
68
+ ]
69
+
70
+ DEFAULT_CONFIG_NAME = "synthetic_surface"
71
+
72
+ def _info(self):
73
+
74
+ features = datasets.Features(
75
+ {
76
+ "rule": datasets.Value("string"),
77
+ "spec": datasets.Sequence(
78
+ {
79
+ "sentence": datasets.Value("string"),
80
+ "matched_text": datasets.Value("string"),
81
+ "words": datasets.Sequence(datasets.Value("string")),
82
+ "match_start": datasets.Value("int16"),
83
+ "match_end": datasets.Value("int16"),
84
+ }
85
+ ),
86
+ "generation_info": [
87
+ {
88
+ "transitions": datasets.Sequence(datasets.Value("string")),
89
+ "generation_rules": datasets.Sequence(datasets.Value("string")),
90
+ "delexicalized_generation_rules": datasets.Sequence(datasets.Value("string")),
91
+ "innermost_substitutions": datasets.Sequence(datasets.Value("string")),
92
+ }
93
+ ]
94
+
95
+ }
96
+ )
97
+
98
+ return datasets.DatasetInfo(
99
+ # This is the description that will appear on the datasets page.
100
+ description=_DESCRIPTION,
101
+ # This defines the different columns of the dataset and their types
102
+ features=features, # Here we define them above because they are different between the two configurations
103
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
104
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
105
+ # supervised_keys=("sentence", "label"),
106
+ # Homepage of the dataset for documentation
107
+ homepage=_HOMEPAGE,
108
+ # License for the dataset if available
109
+ license=_LICENSE,
110
+ # Citation for the dataset
111
+ # citation=_CITATION,
112
+ )
113
+
114
+ def _split_generators(self, dl_manager):
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
+
121
+ data_path = dl_manager.download_and_extract("out.jsonl.gz")
122
+
123
+ return [
124
+ datasets.SplitGenerator(
125
+ name=datasets.Split.TRAIN,
126
+ # These kwargs will be passed to _generate_examples
127
+ gen_kwargs={
128
+ "filepath": data_path,
129
+ "split": "train",
130
+ },
131
+ ),
132
+ ]
133
+
134
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
135
+ def _generate_examples(self, filepath, split):
136
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
137
+ with open(filepath, encoding="utf-8") as f:
138
+ for key, row in enumerate(f):
139
+ data = json.loads(row)
140
+ yield key, {
141
+ "rule": data["rule"],
142
+ "spec": [
143
+ {
144
+ "sentence": s[0],
145
+ "matched_text": s[1],
146
+ "words": s[3],
147
+ "match_start": s[4],
148
+ "match_end": s[5]
149
+ }
150
+ for s in data['spec']
151
+ ],
152
+ "generation_info": [
153
+ {
154
+ "transitions": i["transitions"],
155
+ "generation_rules": i["generation_rules"],
156
+ "delexicalized_generation_rules": i["delexicalized_generation_rules"],
157
+ "innermost_substitutions": i["innermost_substitutions"],
158
+ }
159
+ for i in data['generation_info']
160
+ ]
161
+ }
out.jsonl.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ad9505cd0526bea591491b88f7964a6f2f53e4f68d06333c3a1db4a4da97b5d
3
+ size 108196388