Nathan Lambert commited on
Commit
317a8dd
1 Parent(s): eb8badd

add basic dataloader file

Browse files
Files changed (1) hide show
  1. geodiff-example-data.py +124 -0
geodiff-example-data.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """A tiny dataset containing 5 molecule configurations for fast inference example."""
15
+
16
+
17
+ import csv
18
+ import json
19
+ import os
20
+ import torch
21
+ import datasets
22
+
23
+
24
+ # You can copy an official description
25
+ _DESCRIPTION = """\
26
+ This data is a trimmed version of the GEOM Drugs Dataset. """
27
+
28
+ _HOMEPAGE = "https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/JNGTDF"
29
+
30
+ _LICENSE = "Creative Commons 1.0 Universal: https://creativecommons.org/publicdomain/zero/1.0/"
31
+ _CITATION = """\
32
+ @data{DVN/JNGTDF_2021,
33
+ author = {Axelrod, Simon and Gomez-Bombarelli, Rafael},
34
+ publisher = {Harvard Dataverse},
35
+ title = {{GEOM}},
36
+ year = {2021},
37
+ version = {V4},
38
+ doi = {10.7910/DVN/JNGTDF},
39
+ url = {https://doi.org/10.7910/DVN/JNGTDF}
40
+ }
41
+ """
42
+
43
+ # TODO: Add link to the official dataset URLs here
44
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
45
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
46
+ _URLS = {
47
+ "drugs": "https://huggingface.co/datasets/fusing/geodiff-example-data/tree/main/data/molecules.pkl",
48
+ }
49
+
50
+
51
+ class GeoDiffExampleData(datasets.GeneratorBasedBuilder):
52
+ VERSION = datasets.Version("1.1.0")
53
+
54
+ # This is an example of a dataset with multiple configurations.
55
+ # If you don't want/need to define several sub-sets in your dataset,
56
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
57
+
58
+ # If you need to make complex sub-parts in the datasets with configurable options
59
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
60
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
61
+
62
+ # You will be able to load one or the other configurations in the following list with
63
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
64
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
65
+ BUILDER_CONFIGS = [
66
+ datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
67
+ datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
68
+ ]
69
+
70
+ DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
71
+
72
+ def _info(self):
73
+ if self.config.name == "drugs": # This is the name of the configuration selected in BUILDER_CONFIGS above
74
+ features = datasets.Features(
75
+ {
76
+ "num_molecules": 5, #datasets.Value("string"),
77
+ # These are the features of your dataset like images, labels ...
78
+ }
79
+ )
80
+ else:
81
+ raise NotImplementedError("Other Domains Not Added")
82
+ return datasets.DatasetInfo(
83
+ # This is the description that will appear on the datasets page.
84
+ description=_DESCRIPTION,
85
+ # This defines the different columns of the dataset and their types
86
+ features=features, # Here we define them above because they are different between the two configurations
87
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
88
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
89
+ # supervised_keys=("sentence", "label"),
90
+ # Homepage of the dataset for documentation
91
+ homepage=_HOMEPAGE,
92
+ # License for the dataset if available
93
+ license=_LICENSE,
94
+ # Citation for the dataset
95
+ citation=_CITATION,
96
+ )
97
+
98
+ def _split_generators(self, dl_manager):
99
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
100
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
101
+
102
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
103
+ # 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.
104
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
105
+ urls = _URLS[self.config.name]
106
+ data_dir = dl_manager.download_and_extract(urls)
107
+ return [
108
+ datasets.SplitGenerator(
109
+ name=datasets.Split.TRAIN,
110
+ # These kwargs will be passed to _generate_examples
111
+ gen_kwargs={
112
+ "filepath": data_dir,
113
+ "split": "train",
114
+ },
115
+ )
116
+ ]
117
+
118
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
119
+ def _generate_examples(self, filepath, split):
120
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
121
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
122
+ with open(filepath, encoding="utf-8") as f:
123
+ data = torch.load(f)
124
+ yield data