Skip to content

Commit 23f2be0

Browse files
author
The TensorFlow Datasets Authors
committed
Release of ASIMOV datasets.
PiperOrigin-RevId: 734655315
1 parent 84c04e4 commit 23f2be0

File tree

4 files changed

+275
-0
lines changed

4 files changed

+275
-0
lines changed

tensorflow_datasets/robotics/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515

1616
"""Robotics datasets."""
1717

18+
from tensorflow_datasets.robotics.asimov.asimov import AsimovDilemmasAutoVal
19+
from tensorflow_datasets.robotics.asimov.asimov import AsimovDilemmasScifiTrain
20+
from tensorflow_datasets.robotics.asimov.asimov import AsimovDilemmasScifiVal
21+
from tensorflow_datasets.robotics.asimov.asimov import AsimovInjuryVal
22+
from tensorflow_datasets.robotics.asimov.asimov import AsimovMultimodalAutoVal
23+
from tensorflow_datasets.robotics.asimov.asimov import AsimovMultimodalManualVal
1824
from tensorflow_datasets.robotics.mt_opt import MtOpt
1925
from tensorflow_datasets.robotics.rtx import AlohaMobile
2026
from tensorflow_datasets.robotics.rtx import AsuTableTopConvertedExternallyToRlds
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# coding=utf-8
2+
# Copyright 2024 The TensorFlow Datasets Authors.
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+
16+
"""All Asimov datasets."""
17+
18+
from tensorflow_datasets.robotics.asimov.asimov import AsimovDilemmasAutoVal
19+
from tensorflow_datasets.robotics.asimov.asimov import AsimovDilemmasScifiTrain
20+
from tensorflow_datasets.robotics.asimov.asimov import AsimovDilemmasScifiVal
21+
from tensorflow_datasets.robotics.asimov.asimov import AsimovInjuryVal
22+
from tensorflow_datasets.robotics.asimov.asimov import AsimovMultimodalAutoVal
23+
from tensorflow_datasets.robotics.asimov.asimov import AsimovMultimodalManualVal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# coding=utf-8
2+
# Copyright 2024 The TensorFlow Datasets Authors.
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+
16+
"""Asimov datasets."""
17+
18+
from tensorflow_datasets.robotics import dataset_importer_builder
19+
20+
ASIMOV_CITATION = """
21+
@article{Sermanet2025RobotConstitutions,
22+
author = {Pierre Sermanet and Anirudha Majumdar and Alex Irpan and Dmitry Kalashnikov and Vikas Sindhwani},
23+
title = {Generating Robot Constitutions & Benchmarks for Semantic Safety},
24+
journal = {arXiv preprint arXiv:FIXME},
25+
url = {https://arxiv.org/abs/FIXME},
26+
year = {2025},
27+
}
28+
"""
29+
30+
ASIMOV_HOMEPAGE = 'https://asimov-benchmark.github.io/'
31+
32+
33+
class AsimovDilemmasAutoVal(
34+
dataset_importer_builder.TFDSDatasetImporterBuilder
35+
):
36+
"""DatasetBuilder for `asimov_dilemmas_auto_val` dataset."""
37+
38+
def get_description(self):
39+
return (
40+
'Binary dilemma questions generated from counterfactual situations used'
41+
' to auto-amend generated constitutions (validation set).'
42+
)
43+
44+
def get_citation(self):
45+
return ASIMOV_CITATION
46+
47+
def get_homepage(self):
48+
return ASIMOV_HOMEPAGE
49+
50+
def get_relative_dataset_location(self):
51+
return 'asimov_dilemmas_auto_val/0.1.0'
52+
53+
54+
class AsimovDilemmasScifiTrain(
55+
dataset_importer_builder.TFDSDatasetImporterBuilder
56+
):
57+
"""DatasetBuilder for `asimov_dilemmas_scifi_train` dataset."""
58+
59+
def get_description(self):
60+
return (
61+
'Multiple-choice ethical questions (with desirable and undesirable'
62+
' answers) based on situations inspired from Science Fiction literature'
63+
' (training set).'
64+
)
65+
66+
def get_citation(self):
67+
return ASIMOV_CITATION
68+
69+
def get_homepage(self):
70+
return ASIMOV_HOMEPAGE
71+
72+
def get_relative_dataset_location(self):
73+
return 'asimov_dilemmas_scifi_train/0.1.0'
74+
75+
76+
class AsimovDilemmasScifiVal(
77+
dataset_importer_builder.TFDSDatasetImporterBuilder
78+
):
79+
"""DatasetBuilder for `asimov_dilemmas_scifi_val` dataset."""
80+
81+
def get_description(self):
82+
return (
83+
'Multiple-choice ethical questions (with desirable and undesirable'
84+
' answers) based on situations inspired from Science Fiction literature'
85+
' (validation set).'
86+
)
87+
88+
def get_citation(self):
89+
return ASIMOV_CITATION
90+
91+
def get_homepage(self):
92+
return ASIMOV_HOMEPAGE
93+
94+
def get_relative_dataset_location(self):
95+
return 'asimov_dilemmas_scifi_val/0.1.0'
96+
97+
98+
class AsimovInjuryVal(dataset_importer_builder.TFDSDatasetImporterBuilder):
99+
"""DatasetBuilder for `asimov_injury_val` dataset."""
100+
101+
def get_description(self):
102+
return (
103+
'Situations generated from real hospital injury reports (validation'
104+
' set).'
105+
)
106+
107+
def get_citation(self):
108+
return ASIMOV_CITATION
109+
110+
def get_homepage(self):
111+
return ASIMOV_HOMEPAGE
112+
113+
def get_relative_dataset_location(self):
114+
return 'asimov_injury_val/0.1.0'
115+
116+
117+
class AsimovMultimodalAutoVal(
118+
dataset_importer_builder.TFDSDatasetImporterBuilder
119+
):
120+
"""DatasetBuilder for `asimov_multimodal_auto_val` dataset."""
121+
122+
def get_description(self):
123+
return (
124+
'(Image, context, instruction) triplets generated from real images'
125+
' (from RoboVQA dataset) which are modified to contain undesirable'
126+
' elements, generated instructions can be desirable or undesirable'
127+
' (validation set).'
128+
)
129+
130+
def get_citation(self):
131+
return ASIMOV_CITATION
132+
133+
def get_homepage(self):
134+
return ASIMOV_HOMEPAGE
135+
136+
def get_relative_dataset_location(self):
137+
return 'asimov_multimodal_auto_val/0.1.0'
138+
139+
140+
class AsimovMultimodalManualVal(
141+
dataset_importer_builder.TFDSDatasetImporterBuilder
142+
):
143+
"""DatasetBuilder for `asimov_multimodal_manual_val` dataset."""
144+
145+
def get_description(self):
146+
return (
147+
'(Image, context, instruction) triplets manually taken and written by'
148+
' humans while ensuring that the instruction desirability can only be'
149+
' determined by looking at the image (validation set)'
150+
)
151+
152+
def get_citation(self):
153+
return ASIMOV_CITATION
154+
155+
def get_homepage(self):
156+
return ASIMOV_HOMEPAGE
157+
158+
def get_relative_dataset_location(self):
159+
return 'asimov_multimodal_manual_val/0.1.0'

tensorflow_datasets/robotics/dataset_importer_builder.py

+87
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,90 @@ def get_ds_builder(self):
148148
ds_location = self.get_dataset_location()
149149
ds_builder = tfds.builder_from_directory(ds_location)
150150
return ds_builder
151+
152+
153+
class TFDSDatasetImporterBuilder(
154+
tfds.core.GeneratorBasedBuilder, skip_registration=True
155+
):
156+
"""DatasetBuilder for TFDS datasets which proxies data files from GCS.
157+
158+
This builder just effectively downloads already converted datasets from GCS.
159+
"""
160+
161+
VERSION = tfds.core.Version('0.1.0')
162+
RELEASE_NOTES = {
163+
'0.1.0': 'Initial release.',
164+
}
165+
_GCS_BUCKET = 'gs://gresearch/robotics/'
166+
167+
168+
@abc.abstractmethod
169+
def get_description(self):
170+
pass
171+
172+
@abc.abstractmethod
173+
def get_citation(self):
174+
pass
175+
176+
@abc.abstractmethod
177+
def get_homepage(self):
178+
pass
179+
180+
@abc.abstractmethod
181+
def get_relative_dataset_location(self):
182+
pass
183+
184+
def get_dataset_location(self):
185+
return os.path.join(
186+
str(self._GCS_BUCKET), self.get_relative_dataset_location()
187+
)
188+
189+
def _info(self) -> tfds.core.DatasetInfo:
190+
"""Returns the dataset metadata."""
191+
description = self.get_description()
192+
features = self.get_ds_builder().info.features
193+
194+
return tfds.core.DatasetInfo(
195+
builder=self,
196+
description=description,
197+
features=features,
198+
supervised_keys=None,
199+
homepage=self.get_homepage(),
200+
citation=self.get_citation(),
201+
)
202+
203+
def _split_generators(self, dl_manager: tfds.download.DownloadManager):
204+
"""Returns SplitGenerators."""
205+
ds_builder = self.get_ds_builder()
206+
splits = {}
207+
for split, split_info in ds_builder.info.splits.items():
208+
splits[split] = self._generate_examples(ds_builder, split_info)
209+
return splits
210+
211+
def _generate_examples(
212+
self,
213+
builder: dataset_builder.DatasetBuilder,
214+
split_info: splits_lib.SplitInfo,
215+
):
216+
beam = tfds.core.lazy_imports.apache_beam
217+
split = split_info.name
218+
read_config = read_config_lib.ReadConfig(add_tfds_id=True)
219+
220+
def converter_fn(example):
221+
example_out = dataset_utils.as_numpy(example)
222+
example_id = example_out['tfds_id'].decode('utf-8')
223+
del example_out['tfds_id']
224+
225+
yield example_id, example_out
226+
227+
return f'read_tfds_dataset@{split}' >> beam_utils.ReadFromTFDS(
228+
builder=builder,
229+
split=split,
230+
read_config=read_config,
231+
workers_per_shard=1,
232+
) | f'convert_to_numpy@{split}' >> beam.FlatMap(converter_fn)
233+
234+
def get_ds_builder(self):
235+
ds_location = self.get_dataset_location()
236+
ds_builder = tfds.builder_from_directory(ds_location)
237+
return ds_builder

0 commit comments

Comments
 (0)