KeithG33 commited on
Commit
b661446
·
1 Parent(s): 716116b

use dl manager for remote

Browse files
Files changed (1) hide show
  1. ChessBot-Dataset.py +28 -15
ChessBot-Dataset.py CHANGED
@@ -1,6 +1,12 @@
1
  from datasets import (
2
- GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split,
3
- Features, Value, Array2D
 
 
 
 
 
 
4
  )
5
  from adversarial_gym.chess_env import ChessEnv
6
 
@@ -17,21 +23,28 @@ class ChessPGNDataset(GeneratorBasedBuilder):
17
  })
18
  )
19
 
20
- def _split_generators(self, dl_manager):
21
- import glob, os
22
- # data_dir is the root of your dataset repo
23
- data_dir = self.config.data_dir
 
 
 
 
 
 
 
 
24
  return [
25
- SplitGenerator(
26
- name=Split.TRAIN,
27
- gen_kwargs={"shards": glob.glob(os.path.join(data_dir,"train","*.pgn"))}
28
- ),
29
- SplitGenerator(
30
- name=Split.TEST,
31
- gen_kwargs={"shards": glob.glob(os.path.join(data_dir,"test","*.pgn"))}
32
- ),
33
  ]
34
-
35
  def _generate_examples(self, shards):
36
  import chess.pgn
37
  uid = 0
 
1
  from datasets import (
2
+ GeneratorBasedBuilder,
3
+ DatasetInfo,
4
+ SplitGenerator,
5
+ Split,
6
+ DownloadManager,
7
+ Features,
8
+ Value,
9
+ Array2D,
10
  )
11
  from adversarial_gym.chess_env import ChessEnv
12
 
 
23
  })
24
  )
25
 
26
+ def _split_generators(self, dl_manager: DownloadManager):
27
+ import pathlib as Path
28
+ # 1) discover your shards inside the repo:
29
+ data_dir = Path(self.config.data_dir)
30
+ train_shards = sorted(data_dir.joinpath("train").glob("*.pgn"))
31
+ test_shards = sorted(data_dir.joinpath("test").glob("*.pgn"))
32
+
33
+ # 2) resolve them through the DL manager:
34
+ # if they’re URLs, this downloads; if local, returns the same paths.
35
+ train_paths = dl_manager.download([str(p) for p in train_shards])
36
+ test_paths = dl_manager.download([str(p) for p in test_shards])
37
+
38
  return [
39
+ SplitGenerator(
40
+ name=Split.TRAIN,
41
+ gen_kwargs={"shards": train_paths},
42
+ ),
43
+ SplitGenerator(
44
+ name=Split.TEST,
45
+ gen_kwargs={"shards": test_paths},
46
+ ),
47
  ]
 
48
  def _generate_examples(self, shards):
49
  import chess.pgn
50
  uid = 0