Update README.md
Browse files
README.md
CHANGED
@@ -14,15 +14,14 @@ Games are stored in a format that is much faster to process than the original PG
|
|
14 |
<br>
|
15 |
Requirements:
|
16 |
```
|
17 |
-
pip install zstandard python-chess
|
18 |
```
|
19 |
|
20 |
# Quick Guide
|
21 |
-
In the following I
|
22 |
|
23 |
### 1. Loading the dataset
|
24 |
-
You can stream the data without storing it locally (~100 GB currently).
|
25 |
-
Note, `trust_remote_code=True` is needed to execute my [custom data loading script](https://huggingface.co/datasets/mauricett/lichess_sf/blob/main/lichess_sf.py), which is necessary to decompress the files.
|
26 |
See [HuggingFace's documentation](https://huggingface.co/docs/datasets/main/en/load_hub#remote-code) if you're unsure.
|
27 |
```py
|
28 |
# Load dataset.
|
@@ -42,66 +41,42 @@ print(example)
|
|
42 |
|
43 |
A single sample from the dataset contains one complete chess game as a dictionary. The dictionary keys are as follows:
|
44 |
|
45 |
-
1. `example['fens']` --- A list of FENs in a slightly stripped format, missing the
|
46 |
-
2. `example['moves'] --- A list of moves in [UCI format](https://en.wikipedia.org/wiki/Universal_Chess_Interface). `example['moves'][42]` is the move that led to position `example['fens'][42]`, etc.
|
47 |
-
3. `example['scores'] --- A list of Stockfish evaluations in
|
48 |
4. `example['WhiteElo'], example['BlackElo']` --- Player's Elos.
|
49 |
<br>
|
50 |
|
51 |
-
|
52 |
-
The FENs are slightly stripped. I removed the half-move clock aswell as the fullmove number. See the [definition of FEN](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation#Definition).
|
53 |
-
```py
|
54 |
-
fens = example['fens']
|
55 |
-
moves = example['moves']
|
56 |
-
scores = example['scores']
|
57 |
-
white_elo = example['WhiteElo']
|
58 |
-
black_elo = example['BlackElo']
|
59 |
-
```
|
60 |
-
Every sample drawn from the dataset will have a different number of FENs, moves and scores, but within a single sample we have
|
61 |
-
```py
|
62 |
-
len(fens) == len(moves) == len(scores) # True
|
63 |
-
```
|
64 |
-
|
65 |
|
66 |
-
###
|
67 |
-
|
68 |
|
69 |
|
70 |
```py
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
streaming=True,
|
75 |
-
trust_remote_code=True)
|
76 |
-
|
77 |
-
# Shuffle and apply your own preprocessing.
|
78 |
-
dataset = dataset.shuffle(seed=42)
|
79 |
-
dataset = dataset.map(preprocess, fn_kwargs={'useful_fn': useful_fn})
|
80 |
```
|
81 |
|
82 |
For a quick working example, you can try to use the following functions:
|
83 |
```py
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
```
|
103 |
-
|
104 |
-
# Data Format
|
105 |
-
Every position of every game either has a Stockfish evaluation or an outcome condition that is either checkmate, stalemate or insufficient material.
|
106 |
-
All other outcome conditions have been excluded from the data.
|
107 |
-
In the FEN dataset, the starting positions have been excluded (no player made a move yet).
|
|
|
14 |
<br>
|
15 |
Requirements:
|
16 |
```
|
17 |
+
pip install zstandard python-chess datasets
|
18 |
```
|
19 |
|
20 |
# Quick Guide
|
21 |
+
In the following, I explain the data format and how to use the dataset. At the end, you find a complete example script.
|
22 |
|
23 |
### 1. Loading the dataset
|
24 |
+
You can stream the data without storing it locally (~100 GB currently). The dataset requires `trust_remote_code=True` to execute the [custom data loading script](https://huggingface.co/datasets/mauricett/lichess_sf/blob/main/lichess_sf.py), which is necessary to decompress the files.
|
|
|
25 |
See [HuggingFace's documentation](https://huggingface.co/docs/datasets/main/en/load_hub#remote-code) if you're unsure.
|
26 |
```py
|
27 |
# Load dataset.
|
|
|
41 |
|
42 |
A single sample from the dataset contains one complete chess game as a dictionary. The dictionary keys are as follows:
|
43 |
|
44 |
+
1. `example['fens']` --- A list of FENs in a slightly stripped format, missing the halfmove clock and fullmove number (see [definitions on wiki](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation#Definition)). The starting positions have been excluded (no player made a move yet).
|
45 |
+
2. `example['moves']` --- A list of moves in [UCI format](https://en.wikipedia.org/wiki/Universal_Chess_Interface). `example['moves'][42]` is the move that led to position `example['fens'][42]`, etc.
|
46 |
+
3. `example['scores']` --- A list of Stockfish evaluations (in centipawns) from the perspective of the player who is next to move. If `example['fens'][42]` is black's move, `example['scores'][42]` will be from black's perspective. If the game ended with a terminal condition, the last element of the list is a string 'C' (checkmate), 'S' (stalemate) or 'I' (insufficient material). Games with other outcome conditions have been excluded.
|
47 |
4. `example['WhiteElo'], example['BlackElo']` --- Player's Elos.
|
48 |
<br>
|
49 |
|
50 |
+
Everything but Elos is stored as strings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
### 3. Shuffle and preprocess
|
53 |
+
Use `datasets.shuffle()` to properly shuffle the dataset. Use `datasets.map()` to transform the data to the format you require. This will process individual samples in parallel if you're using multiprocessing (e.g. with PyTorch dataloader).
|
54 |
|
55 |
|
56 |
```py
|
57 |
+
# Shuffle and apply your own preprocessing.
|
58 |
+
dataset = dataset.shuffle(seed=42)
|
59 |
+
dataset = dataset.map(preprocess, fn_kwargs={'useful_fn': useful_fn})
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
```
|
61 |
|
62 |
For a quick working example, you can try to use the following functions:
|
63 |
```py
|
64 |
+
def useful_fn(example):
|
65 |
+
return example
|
66 |
+
|
67 |
+
def preprocess(example, useful_fn):
|
68 |
+
# Get number of moves made in the game.
|
69 |
+
max_ply = len(example['moves'])
|
70 |
+
pick_random_move = random.randint(0, max_ply)
|
71 |
+
|
72 |
+
# Get the FEN, move and score for our random choice.
|
73 |
+
fen = example['fens'][pick_random_move]
|
74 |
+
move = example['moves'][pick_random_move]
|
75 |
+
score = example['scores'][pick_random_move]
|
76 |
+
|
77 |
+
# Transform data into the format of your choice.
|
78 |
+
example['fens'] = useful_fn(fen)
|
79 |
+
example['moves'] = useful_fn(move)
|
80 |
+
example['scores'] = useful_fn(score)
|
81 |
+
return example
|
82 |
+
```
|
|
|
|
|
|
|
|
|
|