mauricett commited on
Commit
4b2a6f3
1 Parent(s): 10d2c55

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +40 -3
README.md CHANGED
@@ -51,8 +51,45 @@ A single sample from the dataset contains one complete chess game as a dictionar
51
  Everything but Elos is stored as strings.
52
  <br>
53
 
54
- ### 3. Shuffle And Preprocess
55
- 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).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
 
58
  ```py
@@ -98,7 +135,7 @@ tokenizer = Tokenizer()
98
  <br>
99
  <br>
100
 
101
- # Complete Example
102
  You can try pasting this into Colab and it should work fine. Have fun!
103
 
104
  ```py
 
51
  Everything but Elos is stored as strings.
52
  <br>
53
 
54
+ ### 3. Define Functions for Preprocessing
55
+ To use the data, you will require to define your own functions for transforming the data into your desired format.
56
+ For this guide, let's define a few mock functions so I can show you how to use them.
57
+
58
+ ```py
59
+ # A mock tokenizer and functions for demonstration.
60
+ class Tokenizer:
61
+ def __init__(self):
62
+ pass
63
+ def __call__(self, example):
64
+ return example
65
+
66
+
67
+ # Transform Stockfish score and terminal outcomes.
68
+ def score_fn(score):
69
+ return score
70
+
71
+ def preprocess(example, tokenizer, score_fn):
72
+ # Get number of moves made in the game.
73
+ max_ply = len(example['moves'])
74
+ pick_random_move = random.randint(0, max_ply-1)
75
+
76
+ # Get the FEN, move and score for our random choice.
77
+ fen = example['fens'][pick_random_move]
78
+ move = example['moves'][pick_random_move]
79
+ score = example['scores'][pick_random_move]
80
+
81
+ # Transform data into the format of your choice.
82
+ example['fens'] = tokenizer(fen)
83
+ example['moves'] = tokenizer(move)
84
+ example['scores'] = score_fn(score)
85
+ return example
86
+
87
+ tokenizer = Tokenizer()
88
+ ```
89
+ <br>
90
+
91
+ ### 4. Shuffle And Preprocess
92
+ Use `datasets.shuffle()` to properly shuffle the dataset. Use `datasets.map()` to apply our preprocessors. This will process individual samples in parallel if you're using multiprocessing (e.g. with PyTorch dataloader).
93
 
94
 
95
  ```py
 
135
  <br>
136
  <br>
137
 
138
+ # COMPLETE EXAMPLE
139
  You can try pasting this into Colab and it should work fine. Have fun!
140
 
141
  ```py