mauricett commited on
Commit
92dd194
1 Parent(s): 4ff47d0

Update lichess_sf.py

Browse files
Files changed (1) hide show
  1. lichess_sf.py +24 -58
lichess_sf.py CHANGED
@@ -2,7 +2,7 @@ import datasets
2
  import zstandard as zstd
3
  import io
4
 
5
- #%%
6
  class LichessConfig(datasets.BuilderConfig):
7
  def __init__(self, features, **kwargs):
8
  super(LichessConfig, self).__init__(**kwargs)
@@ -11,29 +11,18 @@ class LichessConfig(datasets.BuilderConfig):
11
 
12
  class Lichess(datasets.GeneratorBasedBuilder):
13
  BUILDER_CONFIG_CLASS = LichessConfig
14
- BUILDER_CONFIGS = [LichessConfig(name="pgn",
15
- features=["WhiteElo",
16
- "BlackElo",
17
- "pgn"]),
18
-
19
- LichessConfig(name="fen",
20
- features=["WhiteElo",
21
  "BlackElo",
22
  "fens",
23
  "moves",
24
- "scores"]),]
25
 
26
  def _info(self):
27
  features_dict = {feature: datasets.Value("uint16") for feature in self.config.features}
28
 
29
- if self.config.name == "pgn":
30
- features_dict["pgn"] = datasets.Value("string")
31
-
32
-
33
- if self.config.name == "fen":
34
- features_dict["fens"] = datasets.Value("string")
35
- features_dict["moves"] = datasets.Value("string")
36
- features_dict["scores"] = datasets.Value("string")
37
 
38
  info = datasets.DatasetInfo(datasets.Features(features_dict))
39
  return info
@@ -42,18 +31,11 @@ class Lichess(datasets.GeneratorBasedBuilder):
42
  months = ["01", "02", "03", "04", "05", "06",
43
  "07", "08", "09", "10", "11", "12"]
44
  shards = ["0", "1", "2", "3"]
45
- filepaths = [self.config.name + "/2023/" + m for m in months]
46
-
47
- if self.config.name == "pgn":
48
- paths = []
49
- for shard in shards:
50
- paths.extend([filepath + "/" + shard + ".zst" for filepath in filepaths])
51
-
52
- if self.config.name == "fen":
53
- paths = []
54
- for shard in shards:
55
- paths.extend([filepath + "/" + shard + "_fen.zst" for filepath in filepaths])
56
 
 
 
 
57
  return paths
58
 
59
  def _split_generators(self, dl_manager: datasets.DownloadManager):
@@ -83,34 +65,18 @@ class Lichess(datasets.GeneratorBasedBuilder):
83
  # cycle through the different shards
84
  pgn = pgns[n % n_files]
85
 
86
- if self.config.name == "pgn":
87
- elos = pgn.readline()
88
- game_pgn = pgn.readline()
89
- next_line = pgn.readline()
90
-
91
- if game_pgn:
92
- white_elo, black_elo = elos.split(" ")
93
- _id = n
94
- n += 1
95
- yield _id, {"WhiteElo": int(white_elo),
96
- "BlackElo": int(black_elo),
97
- "pgn": game_pgn}
98
- else:
99
- break
100
-
101
- elif self.config.name == "fen":
102
- elos = pgn.readline()
103
- game = pgn.readline()
104
 
105
- if game:
106
- white_elo, black_elo = elos.split(" ")
107
- fens, moves, scores = game.split(";")
108
- _id = n
109
- n += 1
110
- yield _id, {"WhiteElo": int(white_elo),
111
- "BlackElo": int(black_elo),
112
- "fens": fens.split(","),
113
- "moves": moves.split(","),
114
- "scores": scores.rstrip("\n").split(",")}
115
- else:
116
- break
 
2
  import zstandard as zstd
3
  import io
4
 
5
+
6
  class LichessConfig(datasets.BuilderConfig):
7
  def __init__(self, features, **kwargs):
8
  super(LichessConfig, self).__init__(**kwargs)
 
11
 
12
  class Lichess(datasets.GeneratorBasedBuilder):
13
  BUILDER_CONFIG_CLASS = LichessConfig
14
+ BUILDER_CONFIGS = [LichessConfig(features=["WhiteElo",
 
 
 
 
 
 
15
  "BlackElo",
16
  "fens",
17
  "moves",
18
+ "scores"])]
19
 
20
  def _info(self):
21
  features_dict = {feature: datasets.Value("uint16") for feature in self.config.features}
22
 
23
+ features_dict["fens"] = datasets.Value("null")
24
+ features_dict["moves"] = datasets.Value("null")
25
+ features_dict["scores"] = datasets.Value("null")
 
 
 
 
 
26
 
27
  info = datasets.DatasetInfo(datasets.Features(features_dict))
28
  return info
 
31
  months = ["01", "02", "03", "04", "05", "06",
32
  "07", "08", "09", "10", "11", "12"]
33
  shards = ["0", "1", "2", "3"]
34
+ filepaths = ["fen/2023/" + m for m in months]
 
 
 
 
 
 
 
 
 
 
35
 
36
+ paths = []
37
+ for shard in shards:
38
+ paths.extend([filepath + "/" + shard + "_fen.zst" for filepath in filepaths])
39
  return paths
40
 
41
  def _split_generators(self, dl_manager: datasets.DownloadManager):
 
65
  # cycle through the different shards
66
  pgn = pgns[n % n_files]
67
 
68
+ elos = pgn.readline()
69
+ game = pgn.readline()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
+ if game:
72
+ white_elo, black_elo = elos.split(" ")
73
+ fens, moves, scores = game.split(";")
74
+ _id = n
75
+ n += 1
76
+ yield _id, {"WhiteElo": int(white_elo),
77
+ "BlackElo": int(black_elo),
78
+ "fens": fens.split(","),
79
+ "moves": moves.split(","),
80
+ "scores": scores.rstrip("\n").split(",")}
81
+ else:
82
+ break