KeithG33 commited on
Commit
d13cf39
·
1 Parent(s): 65e73fc
Files changed (1) hide show
  1. ChessBot-Dataset.py +23 -16
ChessBot-Dataset.py CHANGED
@@ -15,20 +15,27 @@ from datasets import (
15
  from datasets.data_files import sanitize_patterns, DataFilesDict
16
  from adversarial_gym.chess_env import ChessEnv
17
 
 
 
 
 
 
 
 
 
18
  class ChessPGNDataset(GeneratorBasedBuilder):
19
  VERSION = "0.0.1"
20
  BUILDER_CONFIGS = [
21
- BuilderConfig(
22
- name="default",
23
- version=Version("0.0.2"), # bump version so HF reloads your updated code
24
- description="Chess PGN stream",
25
- data_dir=os.path.join(os.path.dirname(__file__)),
26
- data_files=DataFilesDict.from_patterns(sanitize_patterns({
27
- "train": "train/*.pgn",
28
- "test": "test/*.pgn",
29
- })),
30
- ),
31
- ]
32
 
33
  def _info(self):
34
  return DatasetInfo(
@@ -43,15 +50,15 @@ class ChessPGNDataset(GeneratorBasedBuilder):
43
  def _split_generators(self, dl_manager: DownloadManager):
44
  from pathlib import Path, os
45
 
46
- if self.config.data_dir or self.config.data_files is None:
 
 
 
 
47
  repo_root = Path(self.config.data_dir)
48
  train_files = [repo_root / 'train' / f for f in os.listdir(repo_root / 'train')]
49
  test_files = [repo_root / 'test' / f for f in os.listdir(repo_root / 'test')]
50
 
51
- elif self.config.data_files:
52
- train_files = self.config.data_files["train"]
53
- test_files = self.config.data_files["test"]
54
-
55
 
56
  train_paths = dl_manager.download(train_files)
57
  test_paths = dl_manager.download(test_files)
 
15
  from datasets.data_files import sanitize_patterns, DataFilesDict
16
  from adversarial_gym.chess_env import ChessEnv
17
 
18
+
19
+
20
+ class ChessPGNConfig(BuilderConfig):
21
+ def __init__(self, *, data_files: dict, **kwargs):
22
+ super().__init__(**kwargs)
23
+ # data_files is just {"train":"train/*.pgn", "test":"test/*.pgn"}
24
+ self.data_files = data_files
25
+
26
  class ChessPGNDataset(GeneratorBasedBuilder):
27
  VERSION = "0.0.1"
28
  BUILDER_CONFIGS = [
29
+ ChessPGNConfig(
30
+ name="default",
31
+ version=Version("0.0.3"), # bump this each time you update the script
32
+ description="PGN shards of chess games",
33
+ data_files={
34
+ "train": "train/*.pgn",
35
+ "test": "test/*.pgn",
36
+ },
37
+ ),
38
+ ]
 
39
 
40
  def _info(self):
41
  return DatasetInfo(
 
50
  def _split_generators(self, dl_manager: DownloadManager):
51
  from pathlib import Path, os
52
 
53
+ if self.config.data_files:
54
+ train_files = self.config.data_files["train"]
55
+ test_files = self.config.data_files["test"]
56
+
57
+ elif self.config.data_dir or self.config.data_files is None:
58
  repo_root = Path(self.config.data_dir)
59
  train_files = [repo_root / 'train' / f for f in os.listdir(repo_root / 'train')]
60
  test_files = [repo_root / 'test' / f for f in os.listdir(repo_root / 'test')]
61
 
 
 
 
 
62
 
63
  train_paths = dl_manager.download(train_files)
64
  test_paths = dl_manager.download(test_files)