Datasets:

ArXiv:
License:
kxzxvbk commited on
Commit
a126cd7
1 Parent(s): 96c14ad

Upload Pong-v4-expert-MCTS.py

Browse files
Files changed (1) hide show
  1. Pong-v4-expert-MCTS.py +94 -0
Pong-v4-expert-MCTS.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+
3
+ import datasets
4
+
5
+ _DESCRIPTION = """\
6
+ Data sampled from an efficient-zero policy in the pong environment. The MCTS hidden state is included in the dataset.
7
+ """
8
+
9
+ _HOMEPAGE = "https://github.com/opendilab/DI-engine"
10
+
11
+ _LICENSE = "Apache-2.0"
12
+
13
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
14
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
15
+ _BASE_URL = "https://huggingface.co/datasets/OpenDILabCommunity/Pong-v4-expert-MCTS/resolve/main"
16
+ _URLS = {
17
+ "Pong-v4-expert-MCTS": f"{_BASE_URL}/Pong-v4-expert-MCTS.pkl",
18
+ }
19
+
20
+
21
+ class DecisionTransformerGymDataset(datasets.GeneratorBasedBuilder):
22
+
23
+ VERSION = datasets.Version("0.0.1")
24
+
25
+ # This is an example of a dataset with multiple configurations.
26
+ # If you don't want/need to define several sub-sets in your dataset,
27
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
28
+
29
+ # If you need to make complex sub-parts in the datasets with configurable options
30
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
31
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
32
+
33
+ # You will be able to load one or the other configurations in the following list with
34
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
35
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
36
+ BUILDER_CONFIGS = [
37
+ datasets.BuilderConfig(
38
+ name="Pong-v4-expert-MCTS",
39
+ version=VERSION,
40
+ description="Data sampled from an efficient-zero policy in the pong environment",
41
+ )
42
+ ]
43
+
44
+ def _info(self):
45
+
46
+ features = datasets.Features(
47
+ {
48
+ "observation": datasets.Sequence(datasets.Sequence(datasets.Sequence(datasets.Value("uint8")))),
49
+ "action": datasets.Sequence(datasets.Value("float32")),
50
+ "hidden_state": datasets.Sequence(datasets.Sequence(datasets.Sequence(datasets.Value("float32")))),
51
+ # These are the features of your dataset like images, labels ...
52
+ }
53
+ )
54
+
55
+ return datasets.DatasetInfo(
56
+ # This is the description that will appear on the datasets page.
57
+ description=_DESCRIPTION,
58
+ # This defines the different columns of the dataset and their types
59
+ # Here we define them above because they are different between the two configurations
60
+ features=features,
61
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
62
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
63
+ # supervised_keys=("sentence", "label"),
64
+ # Homepage of the dataset for documentation
65
+ homepage=_HOMEPAGE,
66
+ # License for the dataset if available
67
+ license=_LICENSE,
68
+ )
69
+
70
+ def _split_generators(self, dl_manager):
71
+ urls = _URLS[self.config.name]
72
+ data_dir = dl_manager.download_and_extract(urls)
73
+ return [
74
+ datasets.SplitGenerator(
75
+ name=datasets.Split.TRAIN,
76
+ # These kwargs will be passed to _generate_examples
77
+ gen_kwargs={
78
+ "filepath": data_dir,
79
+ "split": "train",
80
+ },
81
+ )
82
+ ]
83
+
84
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
85
+ def _generate_examples(self, filepath, split):
86
+ with open(filepath, "rb") as f:
87
+ data = pickle.load(f)
88
+
89
+ for idx in range(len(data['obs'])):
90
+ yield idx, {
91
+ 'observation': data['obs'][idx],
92
+ 'action': data['actions'][idx],
93
+ 'hidden_state': data['hidden_state'][idx],
94
+ }