update for streaming
Browse files- nld-aa-taster.py +11 -47
nld-aa-taster.py
CHANGED
|
@@ -20,7 +20,7 @@ import json
|
|
| 20 |
import os
|
| 21 |
import datasets
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
_CITATION = """\
|
| 26 |
"""
|
|
@@ -34,21 +34,11 @@ _HOMEPAGE = ""
|
|
| 34 |
_LICENSE = ""
|
| 35 |
|
| 36 |
|
| 37 |
-
|
| 38 |
-
# _URLS = {
|
| 39 |
-
# "data": [f"data/{i}.hdf5" for i in range(1, _TOTAL_EPISODES)],
|
| 40 |
-
# "metadata": ["metadata.json"],
|
| 41 |
-
# }
|
| 42 |
-
|
| 43 |
-
class NleHfDataset(datasets.GeneratorBasedBuilder):
|
| 44 |
"""Dungeons and Data: A Large-Scale NetHack Dataset."""
|
| 45 |
VERSION = datasets.Version("1.0.0")
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
# datasets.BuilderConfig(name="data", version=VERSION, description="Data for all episodes"),
|
| 49 |
-
# datasets.BuilderConfig(name="metadata", version=VERSION, description="Metadata for all episodes"),
|
| 50 |
-
# ]
|
| 51 |
-
# DEFAULT_CONFIG_NAME = "metadata"
|
| 52 |
|
| 53 |
def _info(self):
|
| 54 |
features = datasets.Features(
|
|
@@ -116,11 +106,14 @@ class NleHfDataset(datasets.GeneratorBasedBuilder):
|
|
| 116 |
]
|
| 117 |
|
| 118 |
def _generate_examples(self, data_file, metadata_file, dl_manager):
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
meta = json.load(f)
|
| 121 |
|
| 122 |
for i, (ep_key, ep_meta) in enumerate(zip(df["/"], meta)):
|
| 123 |
-
print(ep_key, ep_meta["gameid"])
|
| 124 |
assert int(ep_key) == int(ep_meta["gameid"])
|
| 125 |
|
| 126 |
yield i, {
|
|
@@ -135,35 +128,6 @@ class NleHfDataset(datasets.GeneratorBasedBuilder):
|
|
| 135 |
"metadata": ep_meta
|
| 136 |
}
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
# assert not dl_manager.is_streaming
|
| 141 |
-
# yield from self.__generate_metadata(filepaths[0])
|
| 142 |
-
# else:
|
| 143 |
-
# yield from self.__generate_data(filepaths, dl_manager)
|
| 144 |
-
|
| 145 |
-
# def __generate_metadata(self, filepath):
|
| 146 |
-
# with open(filepath, "r") as f:
|
| 147 |
-
# data = json.load(f)
|
| 148 |
-
# for i, line in enumerate(data):
|
| 149 |
-
# yield i, line
|
| 150 |
-
|
| 151 |
-
# def __generate_data(self, filepaths, dl_manager):
|
| 152 |
-
# for i, filepath in enumerate(filepaths):
|
| 153 |
-
# if dl_manager.is_streaming:
|
| 154 |
-
# filepath = xopen(filepath, "rb")
|
| 155 |
-
|
| 156 |
-
# with h5py.File(filepath, "r") as f:
|
| 157 |
-
# yield i, {
|
| 158 |
-
# "tty_chars": f["tty_chars"][()],
|
| 159 |
-
# "tty_colors": f["tty_colors"][()],
|
| 160 |
-
# "tty_cursor": f["tty_cursor"][()],
|
| 161 |
-
# "actions": f["actions"][()],
|
| 162 |
-
# "rewards": f["rewards"][()],
|
| 163 |
-
# "dones": f["dones"][()]
|
| 164 |
-
# }
|
| 165 |
-
|
| 166 |
-
# if dl_manager.is_streaming:
|
| 167 |
-
# filepath.close()
|
| 168 |
-
|
| 169 |
|
|
|
|
| 20 |
import os
|
| 21 |
import datasets
|
| 22 |
|
| 23 |
+
from datasets.download.streaming_download_manager import xopen
|
| 24 |
|
| 25 |
_CITATION = """\
|
| 26 |
"""
|
|
|
|
| 34 |
_LICENSE = ""
|
| 35 |
|
| 36 |
|
| 37 |
+
class NLEDataset(datasets.GeneratorBasedBuilder):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
"""Dungeons and Data: A Large-Scale NetHack Dataset."""
|
| 39 |
VERSION = datasets.Version("1.0.0")
|
| 40 |
+
|
| 41 |
+
DEFAULT_CONFIG_NAME = "mon-hum-neu"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def _info(self):
|
| 44 |
features = datasets.Features(
|
|
|
|
| 106 |
]
|
| 107 |
|
| 108 |
def _generate_examples(self, data_file, metadata_file, dl_manager):
|
| 109 |
+
if dl_manager.is_streaming:
|
| 110 |
+
data_file = xopen(data_file, "rb")
|
| 111 |
+
|
| 112 |
+
with h5py.File(data_file, "r") as df, xopen(metadata_file, "r") as f:
|
| 113 |
+
# this thing is super small, so we will load it all
|
| 114 |
meta = json.load(f)
|
| 115 |
|
| 116 |
for i, (ep_key, ep_meta) in enumerate(zip(df["/"], meta)):
|
|
|
|
| 117 |
assert int(ep_key) == int(ep_meta["gameid"])
|
| 118 |
|
| 119 |
yield i, {
|
|
|
|
| 128 |
"metadata": ep_meta
|
| 129 |
}
|
| 130 |
|
| 131 |
+
if dl_manager.is_streaming:
|
| 132 |
+
data_file.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|