created datasets
Browse files- .gitattributes +1 -0
- chess_game_data.txt +3 -0
- clean_data.ipynb +304 -0
- lichess_game_data.txt +3 -0
- test_dataset.ipynb +673 -0
.gitattributes
CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
56 |
+
*.txt filter=lfs diff=lfs merge=lfs -text
|
chess_game_data.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b1f596fca8a3177bc5832e7a0f1e78fd14c3a924c53c3a15f4944a5d7ad869d1
|
3 |
+
size 168853001
|
clean_data.ipynb
ADDED
@@ -0,0 +1,304 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import numpy as np\n",
|
10 |
+
"import pandas as pd\n",
|
11 |
+
"import chess\n",
|
12 |
+
"import chess.pgn\n",
|
13 |
+
"import os\n",
|
14 |
+
"from tqdm import tqdm\n",
|
15 |
+
"import json"
|
16 |
+
]
|
17 |
+
},
|
18 |
+
{
|
19 |
+
"cell_type": "code",
|
20 |
+
"execution_count": 2,
|
21 |
+
"metadata": {},
|
22 |
+
"outputs": [
|
23 |
+
{
|
24 |
+
"name": "stderr",
|
25 |
+
"output_type": "stream",
|
26 |
+
"text": [
|
27 |
+
" 98%|█████████▊| 172350/175000 [38:39<00:35, 74.29it/s] \n"
|
28 |
+
]
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"ename": "UnicodeDecodeError",
|
32 |
+
"evalue": "'utf-8' codec can't decode byte 0xfc in position 3540: invalid start byte",
|
33 |
+
"output_type": "error",
|
34 |
+
"traceback": [
|
35 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
36 |
+
"\u001b[1;31mUnicodeDecodeError\u001b[0m Traceback (most recent call last)",
|
37 |
+
"\u001b[1;32ms:\\Documents\\chess_engine\\clean_data.ipynb Cell 2\u001b[0m line \u001b[0;36m1\n\u001b[0;32m <a href='vscode-notebook-cell:/s%3A/Documents/chess_engine/clean_data.ipynb#W1sZmlsZQ%3D%3D?line=12'>13</a>\u001b[0m games\u001b[39m.\u001b[39mappend(game\u001b[39m.\u001b[39maccept(exporter)\u001b[39m.\u001b[39mreplace(\u001b[39m\"\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39m \u001b[39m\u001b[39m\"\u001b[39m) \u001b[39m+\u001b[39m \u001b[39m'\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m'\u001b[39m)\n\u001b[0;32m <a href='vscode-notebook-cell:/s%3A/Documents/chess_engine/clean_data.ipynb#W1sZmlsZQ%3D%3D?line=13'>14</a>\u001b[0m count \u001b[39m+\u001b[39m\u001b[39m=\u001b[39m \u001b[39m1\u001b[39m\n\u001b[1;32m---> <a href='vscode-notebook-cell:/s%3A/Documents/chess_engine/clean_data.ipynb#W1sZmlsZQ%3D%3D?line=14'>15</a>\u001b[0m game \u001b[39m=\u001b[39m chess\u001b[39m.\u001b[39;49mpgn\u001b[39m.\u001b[39;49mread_game(game_file)\n\u001b[0;32m <a href='vscode-notebook-cell:/s%3A/Documents/chess_engine/clean_data.ipynb#W1sZmlsZQ%3D%3D?line=15'>16</a>\u001b[0m pbar\u001b[39m.\u001b[39mupdate(\u001b[39m1\u001b[39m)\n\u001b[0;32m <a href='vscode-notebook-cell:/s%3A/Documents/chess_engine/clean_data.ipynb#W1sZmlsZQ%3D%3D?line=16'>17</a>\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mopen\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39mchess_game_data.txt\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m'\u001b[39m\u001b[39ma\u001b[39m\u001b[39m'\u001b[39m) \u001b[39mas\u001b[39;00m data_file:\n",
|
38 |
+
"File \u001b[1;32ms:\\packages\\envs\\chess\\Lib\\site-packages\\chess\\pgn.py:1673\u001b[0m, in \u001b[0;36mread_game\u001b[1;34m(handle, Visitor)\u001b[0m\n\u001b[0;32m 1671\u001b[0m \u001b[39mwhile\u001b[39;00m line \u001b[39mand\u001b[39;00m \u001b[39m\"\u001b[39m\u001b[39m}\u001b[39m\u001b[39m\"\u001b[39m \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m line:\n\u001b[0;32m 1672\u001b[0m comment_lines\u001b[39m.\u001b[39mappend(line)\n\u001b[1;32m-> 1673\u001b[0m line \u001b[39m=\u001b[39m handle\u001b[39m.\u001b[39mreadline()\n\u001b[0;32m 1675\u001b[0m \u001b[39mif\u001b[39;00m line:\n\u001b[0;32m 1676\u001b[0m close_index \u001b[39m=\u001b[39m line\u001b[39m.\u001b[39mfind(\u001b[39m\"\u001b[39m\u001b[39m}\u001b[39m\u001b[39m\"\u001b[39m)\n",
|
39 |
+
"File \u001b[1;32m<frozen codecs>:322\u001b[0m, in \u001b[0;36mdecode\u001b[1;34m(self, input, final)\u001b[0m\n",
|
40 |
+
"\u001b[1;31mUnicodeDecodeError\u001b[0m: 'utf-8' codec can't decode byte 0xfc in position 3540: invalid start byte"
|
41 |
+
]
|
42 |
+
}
|
43 |
+
],
|
44 |
+
"source": [
|
45 |
+
"count = 0\n",
|
46 |
+
"last = 0\n",
|
47 |
+
"with tqdm(total=175000) as pbar:\n",
|
48 |
+
" for root, d_name, files in os.walk(\"S:\\Documents\\ccc-data\\ccc-data\"):\n",
|
49 |
+
" for file in files:\n",
|
50 |
+
" if os.path.splitext(file)[1] == '.pgn':\n",
|
51 |
+
" pgn_path = os.path.join(root, file)\n",
|
52 |
+
" with open(pgn_path) as game_file:\n",
|
53 |
+
" games = []\n",
|
54 |
+
" game = chess.pgn.read_game(game_file)\n",
|
55 |
+
" while game:\n",
|
56 |
+
" exporter = chess.pgn.StringExporter(headers=False, variations=False, comments=False)\n",
|
57 |
+
" games.append(game.accept(exporter).replace(\"\\n\", \" \") + '\\n')\n",
|
58 |
+
" count += 1\n",
|
59 |
+
" game = chess.pgn.read_game(game_file)\n",
|
60 |
+
" pbar.update(1)\n",
|
61 |
+
" with open(\"chess_game_data.txt\", 'a') as data_file:\n",
|
62 |
+
" data_file.writelines(games)\n",
|
63 |
+
"\n",
|
64 |
+
"\n"
|
65 |
+
]
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"cell_type": "code",
|
69 |
+
"execution_count": 6,
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [
|
72 |
+
{
|
73 |
+
"name": "stderr",
|
74 |
+
"output_type": "stream",
|
75 |
+
"text": [
|
76 |
+
" 0%| | 28/1000000 [00:00<2:01:47, 136.85it/s]"
|
77 |
+
]
|
78 |
+
},
|
79 |
+
{
|
80 |
+
"name": "stdout",
|
81 |
+
"output_type": "stream",
|
82 |
+
"text": [
|
83 |
+
"lichess_elite_2021-12.pgn\n"
|
84 |
+
]
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"name": "stderr",
|
88 |
+
"output_type": "stream",
|
89 |
+
"text": [
|
90 |
+
" 49%|████▉ | 490442/1000000 [51:38<2:35:36, 54.58it/s] "
|
91 |
+
]
|
92 |
+
},
|
93 |
+
{
|
94 |
+
"name": "stdout",
|
95 |
+
"output_type": "stream",
|
96 |
+
"text": [
|
97 |
+
"lichess_elite_2022-01.pgn\n"
|
98 |
+
]
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"name": "stderr",
|
102 |
+
"output_type": "stream",
|
103 |
+
"text": [
|
104 |
+
" 97%|█████████▋| 970547/1000000 [1:39:46<09:18, 52.71it/s] "
|
105 |
+
]
|
106 |
+
},
|
107 |
+
{
|
108 |
+
"name": "stdout",
|
109 |
+
"output_type": "stream",
|
110 |
+
"text": [
|
111 |
+
"lichess_elite_2022-02.pgn\n"
|
112 |
+
]
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"name": "stderr",
|
116 |
+
"output_type": "stream",
|
117 |
+
"text": [
|
118 |
+
"1345189it [2:17:35, 63.03it/s] "
|
119 |
+
]
|
120 |
+
},
|
121 |
+
{
|
122 |
+
"name": "stdout",
|
123 |
+
"output_type": "stream",
|
124 |
+
"text": [
|
125 |
+
"lichess_elite_2022-03.pgn\n"
|
126 |
+
]
|
127 |
+
},
|
128 |
+
{
|
129 |
+
"name": "stderr",
|
130 |
+
"output_type": "stream",
|
131 |
+
"text": [
|
132 |
+
"1711576it [2:54:32, 51.88it/s] "
|
133 |
+
]
|
134 |
+
},
|
135 |
+
{
|
136 |
+
"name": "stdout",
|
137 |
+
"output_type": "stream",
|
138 |
+
"text": [
|
139 |
+
"lichess_elite_2022-04.pgn\n"
|
140 |
+
]
|
141 |
+
},
|
142 |
+
{
|
143 |
+
"name": "stderr",
|
144 |
+
"output_type": "stream",
|
145 |
+
"text": [
|
146 |
+
"2050605it [3:28:36, 60.10it/s] "
|
147 |
+
]
|
148 |
+
},
|
149 |
+
{
|
150 |
+
"name": "stdout",
|
151 |
+
"output_type": "stream",
|
152 |
+
"text": [
|
153 |
+
"lichess_elite_2022-05.pgn\n"
|
154 |
+
]
|
155 |
+
},
|
156 |
+
{
|
157 |
+
"name": "stderr",
|
158 |
+
"output_type": "stream",
|
159 |
+
"text": [
|
160 |
+
"2406133it [4:04:30, 54.89it/s] "
|
161 |
+
]
|
162 |
+
},
|
163 |
+
{
|
164 |
+
"name": "stdout",
|
165 |
+
"output_type": "stream",
|
166 |
+
"text": [
|
167 |
+
"lichess_elite_2022-06.pgn\n"
|
168 |
+
]
|
169 |
+
},
|
170 |
+
{
|
171 |
+
"name": "stderr",
|
172 |
+
"output_type": "stream",
|
173 |
+
"text": [
|
174 |
+
"2741369it [4:38:51, 53.44it/s] "
|
175 |
+
]
|
176 |
+
},
|
177 |
+
{
|
178 |
+
"name": "stdout",
|
179 |
+
"output_type": "stream",
|
180 |
+
"text": [
|
181 |
+
"lichess_elite_2022-08.pgn\n"
|
182 |
+
]
|
183 |
+
},
|
184 |
+
{
|
185 |
+
"name": "stderr",
|
186 |
+
"output_type": "stream",
|
187 |
+
"text": [
|
188 |
+
"3087892it [5:15:18, 50.95it/s] "
|
189 |
+
]
|
190 |
+
},
|
191 |
+
{
|
192 |
+
"name": "stdout",
|
193 |
+
"output_type": "stream",
|
194 |
+
"text": [
|
195 |
+
"lichess_elite_2022-09.pgn\n"
|
196 |
+
]
|
197 |
+
},
|
198 |
+
{
|
199 |
+
"name": "stderr",
|
200 |
+
"output_type": "stream",
|
201 |
+
"text": [
|
202 |
+
"3434038it [5:53:10, 51.47it/s] "
|
203 |
+
]
|
204 |
+
},
|
205 |
+
{
|
206 |
+
"name": "stdout",
|
207 |
+
"output_type": "stream",
|
208 |
+
"text": [
|
209 |
+
"lichess_elite_2022-10.pgn\n"
|
210 |
+
]
|
211 |
+
},
|
212 |
+
{
|
213 |
+
"name": "stderr",
|
214 |
+
"output_type": "stream",
|
215 |
+
"text": [
|
216 |
+
"3761579it [6:28:19, 67.38it/s] "
|
217 |
+
]
|
218 |
+
},
|
219 |
+
{
|
220 |
+
"name": "stdout",
|
221 |
+
"output_type": "stream",
|
222 |
+
"text": [
|
223 |
+
"lichess_elite_2022-11.pgn\n"
|
224 |
+
]
|
225 |
+
},
|
226 |
+
{
|
227 |
+
"name": "stderr",
|
228 |
+
"output_type": "stream",
|
229 |
+
"text": [
|
230 |
+
"4064728it [7:00:58, 61.31it/s] "
|
231 |
+
]
|
232 |
+
},
|
233 |
+
{
|
234 |
+
"name": "stdout",
|
235 |
+
"output_type": "stream",
|
236 |
+
"text": [
|
237 |
+
"lichess_elite_2022-12.pgn\n"
|
238 |
+
]
|
239 |
+
},
|
240 |
+
{
|
241 |
+
"name": "stderr",
|
242 |
+
"output_type": "stream",
|
243 |
+
"text": [
|
244 |
+
"4343360it [7:29:28, 161.05it/s]\n"
|
245 |
+
]
|
246 |
+
}
|
247 |
+
],
|
248 |
+
"source": [
|
249 |
+
"count = 0\n",
|
250 |
+
"last = 0\n",
|
251 |
+
"with tqdm(total=1000000) as pbar:\n",
|
252 |
+
" for root, d_name, files in os.walk(\"S:\\Documents\\Lichess Elite Database\\Latest\"):\n",
|
253 |
+
" for file in files:\n",
|
254 |
+
" print(file)\n",
|
255 |
+
" if os.path.splitext(file)[1] == '.pgn':\n",
|
256 |
+
" pgn_path = os.path.join(root, file)\n",
|
257 |
+
" with open(pgn_path) as game_file:\n",
|
258 |
+
" games = []\n",
|
259 |
+
" try:\n",
|
260 |
+
" game = chess.pgn.read_game(game_file)\n",
|
261 |
+
" while game:\n",
|
262 |
+
" exporter = chess.pgn.StringExporter(headers=False, variations=False, comments=False)\n",
|
263 |
+
" games.append(game.accept(exporter).replace(\"\\n\", \" \") + '\\n')\n",
|
264 |
+
" count += 1\n",
|
265 |
+
" game = chess.pgn.read_game(game_file)\n",
|
266 |
+
" pbar.update(1)\n",
|
267 |
+
" except Exception as e:\n",
|
268 |
+
" print(e)\n",
|
269 |
+
"\n",
|
270 |
+
" with open(\"lichess_game_data.txt\", 'a') as data_file:\n",
|
271 |
+
" data_file.writelines(games)"
|
272 |
+
]
|
273 |
+
},
|
274 |
+
{
|
275 |
+
"cell_type": "code",
|
276 |
+
"execution_count": null,
|
277 |
+
"metadata": {},
|
278 |
+
"outputs": [],
|
279 |
+
"source": []
|
280 |
+
}
|
281 |
+
],
|
282 |
+
"metadata": {
|
283 |
+
"kernelspec": {
|
284 |
+
"display_name": "chess",
|
285 |
+
"language": "python",
|
286 |
+
"name": "python3"
|
287 |
+
},
|
288 |
+
"language_info": {
|
289 |
+
"codemirror_mode": {
|
290 |
+
"name": "ipython",
|
291 |
+
"version": 3
|
292 |
+
},
|
293 |
+
"file_extension": ".py",
|
294 |
+
"mimetype": "text/x-python",
|
295 |
+
"name": "python",
|
296 |
+
"nbconvert_exporter": "python",
|
297 |
+
"pygments_lexer": "ipython3",
|
298 |
+
"version": "3.11.5"
|
299 |
+
},
|
300 |
+
"orig_nbformat": 4
|
301 |
+
},
|
302 |
+
"nbformat": 4,
|
303 |
+
"nbformat_minor": 2
|
304 |
+
}
|
lichess_game_data.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fbb174f8789c9e7c4eae50f6a2bf19a3757aa13788182a3cd8c61acb039d2e97
|
3 |
+
size 2249268189
|
test_dataset.ipynb
ADDED
@@ -0,0 +1,673 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 122,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"from datasets import load_dataset\n",
|
10 |
+
"import tokenize\n",
|
11 |
+
"from tokenizers import SentencePieceBPETokenizer, pre_tokenizers, ByteLevelBPETokenizer, normalizers\n",
|
12 |
+
"from transformers import AutoTokenizer"
|
13 |
+
]
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"cell_type": "code",
|
17 |
+
"execution_count": 132,
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [
|
20 |
+
{
|
21 |
+
"name": "stderr",
|
22 |
+
"output_type": "stream",
|
23 |
+
"text": [
|
24 |
+
"Downloading data files: 100%|██████████| 1/1 [00:00<?, ?it/s]\n",
|
25 |
+
"Extracting data files: 100%|██████████| 1/1 [00:00<00:00, 111.41it/s]\n",
|
26 |
+
"Generating train split: 4343360 examples [00:24, 178753.60 examples/s]\n"
|
27 |
+
]
|
28 |
+
}
|
29 |
+
],
|
30 |
+
"source": [
|
31 |
+
"datasets = load_dataset(\"text\", data_files={\"train\": \"lichess_game_data.txt\"})"
|
32 |
+
]
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"cell_type": "code",
|
36 |
+
"execution_count": 133,
|
37 |
+
"metadata": {},
|
38 |
+
"outputs": [],
|
39 |
+
"source": [
|
40 |
+
"def get_training_corpus():\n",
|
41 |
+
" dataset = datasets[\"train\"]\n",
|
42 |
+
" for start_idx in range(0, len(dataset), 1000):\n",
|
43 |
+
" samples = dataset[start_idx : start_idx + 1000]\n",
|
44 |
+
" yield samples['text']"
|
45 |
+
]
|
46 |
+
},
|
47 |
+
{
|
48 |
+
"cell_type": "code",
|
49 |
+
"execution_count": 134,
|
50 |
+
"metadata": {},
|
51 |
+
"outputs": [],
|
52 |
+
"source": [
|
53 |
+
"tokenizer = SentencePieceBPETokenizer()"
|
54 |
+
]
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"cell_type": "code",
|
58 |
+
"execution_count": 135,
|
59 |
+
"metadata": {},
|
60 |
+
"outputs": [],
|
61 |
+
"source": [
|
62 |
+
"tokenizer.normalizer = normalizers.Sequence([normalizers.Replace(\".\", \"\"), normalizers.Replace(\"1-0\", \"\"), normalizers.Replace(\"0-1\", \"\"), normalizers.Replace(\"1/2-1/2\", \"\")])"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"cell_type": "code",
|
67 |
+
"execution_count": 136,
|
68 |
+
"metadata": {},
|
69 |
+
"outputs": [],
|
70 |
+
"source": [
|
71 |
+
"tokenizer.pre_tokenizer = pre_tokenizers.Split(\" \", 'removed')"
|
72 |
+
]
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"cell_type": "code",
|
76 |
+
"execution_count": 137,
|
77 |
+
"metadata": {},
|
78 |
+
"outputs": [],
|
79 |
+
"source": [
|
80 |
+
"tokenizer.train_from_iterator(get_training_corpus(), vocab_size=10000000, min_frequency=0, show_progress=True, special_tokens=[\"<s>\", \"<pad>\", \"</s>\", \"<unk>\", \"<cls>\", \"<sep>\", \"<mask>\"])"
|
81 |
+
]
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"cell_type": "code",
|
85 |
+
"execution_count": 138,
|
86 |
+
"metadata": {},
|
87 |
+
"outputs": [],
|
88 |
+
"source": [
|
89 |
+
"test_str = '1. e4 e5 2. Nf3 Nc6 3. d4 exd4 4. Nxd4 Nf6 5. Nxc6 bxc6 6. Bd3 d5 7. exd5 cxd5 8. O-O Be7 9. c4 O-O 10. cxd5 Bb7 11. Nc3 Nxd5 12. Bd2 Nb4 13. Be4 Bxe4 14. Nxe4 c5 15. Bc3 Qxd1 16. Rfxd1 Rad8 17. a3 Nd5 18. Ba5 Nb6 19. Nc3 Bf6 20. Rac1 Bxc3 21. Bxc3 Rxd1+ 22. Rxd1 f6 23. Kf1 Kf7 24. Rc1 Rd8 25. Ke2 Ke6 26. Bd2 c4 27. Be3 Rb8 28. Rc2 Rb7 29. h3 Kd5 30. Rd2+ Ke6 31. Rd4 a5 32. g3 Nd5 33. Bc1 Nb6 34. h4 g6 35. Bd2 Nd5 36. Bc1 Nb6 37. Bd2 Nd5 38. Rxc4 Rxb2 39. Ke1 Nb6 40. Re4+ Kd5 41. Re7 Rb1+ 42. Ke2 Nc4 43. Bc3 f5 44. Rd7+ Ke6 45. Rxh7 Rb3 46. Bd4 Rxa3 47. Rc7 Ra2+ 48. Kf3 Kd5 49. Rd7+ Kc6 50. Rg7 Kd5 51. Rd7+ Kc6 52. Rg7 Kd5 53. Rd7+ 1/2-1/2'"
|
90 |
+
]
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"cell_type": "code",
|
94 |
+
"execution_count": 139,
|
95 |
+
"metadata": {},
|
96 |
+
"outputs": [
|
97 |
+
{
|
98 |
+
"data": {
|
99 |
+
"text/plain": [
|
100 |
+
"[('1', (0, 1)),\n",
|
101 |
+
" ('e4', (2, 4)),\n",
|
102 |
+
" ('e5', (5, 7)),\n",
|
103 |
+
" ('2', (8, 9)),\n",
|
104 |
+
" ('Nf3', (10, 13)),\n",
|
105 |
+
" ('Nc6', (14, 17)),\n",
|
106 |
+
" ('3', (18, 19)),\n",
|
107 |
+
" ('d4', (20, 22)),\n",
|
108 |
+
" ('exd4', (23, 27)),\n",
|
109 |
+
" ('4', (28, 29)),\n",
|
110 |
+
" ('Nxd4', (30, 34)),\n",
|
111 |
+
" ('Nf6', (35, 38)),\n",
|
112 |
+
" ('5', (39, 40)),\n",
|
113 |
+
" ('Nxc6', (41, 45)),\n",
|
114 |
+
" ('bxc6', (46, 50)),\n",
|
115 |
+
" ('6', (51, 52)),\n",
|
116 |
+
" ('Bd3', (53, 56)),\n",
|
117 |
+
" ('d5', (57, 59)),\n",
|
118 |
+
" ('7', (60, 61)),\n",
|
119 |
+
" ('exd5', (62, 66)),\n",
|
120 |
+
" ('cxd5', (67, 71)),\n",
|
121 |
+
" ('8', (72, 73)),\n",
|
122 |
+
" ('O-O', (74, 77)),\n",
|
123 |
+
" ('Be7', (78, 81)),\n",
|
124 |
+
" ('9', (82, 83)),\n",
|
125 |
+
" ('c4', (84, 86)),\n",
|
126 |
+
" ('O-O', (87, 90)),\n",
|
127 |
+
" ('10', (91, 93)),\n",
|
128 |
+
" ('cxd5', (94, 98)),\n",
|
129 |
+
" ('Bb7', (99, 102)),\n",
|
130 |
+
" ('11', (103, 105)),\n",
|
131 |
+
" ('Nc3', (106, 109)),\n",
|
132 |
+
" ('Nxd5', (110, 114)),\n",
|
133 |
+
" ('12', (115, 117)),\n",
|
134 |
+
" ('Bd2', (118, 121)),\n",
|
135 |
+
" ('Nb4', (122, 125)),\n",
|
136 |
+
" ('13', (126, 128)),\n",
|
137 |
+
" ('Be4', (129, 132)),\n",
|
138 |
+
" ('Bxe4', (133, 137)),\n",
|
139 |
+
" ('14', (138, 140)),\n",
|
140 |
+
" ('Nxe4', (141, 145)),\n",
|
141 |
+
" ('c5', (146, 148)),\n",
|
142 |
+
" ('15', (149, 151)),\n",
|
143 |
+
" ('Bc3', (152, 155)),\n",
|
144 |
+
" ('Qxd1', (156, 160)),\n",
|
145 |
+
" ('16', (161, 163)),\n",
|
146 |
+
" ('Rfxd1', (164, 169)),\n",
|
147 |
+
" ('Rad8', (170, 174)),\n",
|
148 |
+
" ('17', (175, 177)),\n",
|
149 |
+
" ('a3', (178, 180)),\n",
|
150 |
+
" ('Nd5', (181, 184)),\n",
|
151 |
+
" ('18', (185, 187)),\n",
|
152 |
+
" ('Ba5', (188, 191)),\n",
|
153 |
+
" ('Nb6', (192, 195)),\n",
|
154 |
+
" ('19', (196, 198)),\n",
|
155 |
+
" ('Nc3', (199, 202)),\n",
|
156 |
+
" ('Bf6', (203, 206)),\n",
|
157 |
+
" ('20', (207, 209)),\n",
|
158 |
+
" ('Rac1', (210, 214)),\n",
|
159 |
+
" ('Bxc3', (215, 219)),\n",
|
160 |
+
" ('21', (220, 222)),\n",
|
161 |
+
" ('Bxc3', (223, 227)),\n",
|
162 |
+
" ('Rxd1+', (228, 233)),\n",
|
163 |
+
" ('22', (234, 236)),\n",
|
164 |
+
" ('Rxd1', (237, 241)),\n",
|
165 |
+
" ('f6', (242, 244)),\n",
|
166 |
+
" ('23', (245, 247)),\n",
|
167 |
+
" ('Kf1', (248, 251)),\n",
|
168 |
+
" ('Kf7', (252, 255)),\n",
|
169 |
+
" ('24', (256, 258)),\n",
|
170 |
+
" ('Rc1', (259, 262)),\n",
|
171 |
+
" ('Rd8', (263, 266)),\n",
|
172 |
+
" ('25', (267, 269)),\n",
|
173 |
+
" ('Ke2', (270, 273)),\n",
|
174 |
+
" ('Ke6', (274, 277)),\n",
|
175 |
+
" ('26', (278, 280)),\n",
|
176 |
+
" ('Bd2', (281, 284)),\n",
|
177 |
+
" ('c4', (285, 287)),\n",
|
178 |
+
" ('27', (288, 290)),\n",
|
179 |
+
" ('Be3', (291, 294)),\n",
|
180 |
+
" ('Rb8', (295, 298)),\n",
|
181 |
+
" ('28', (299, 301)),\n",
|
182 |
+
" ('Rc2', (302, 305)),\n",
|
183 |
+
" ('Rb7', (306, 309)),\n",
|
184 |
+
" ('29', (310, 312)),\n",
|
185 |
+
" ('h3', (313, 315)),\n",
|
186 |
+
" ('Kd5', (316, 319)),\n",
|
187 |
+
" ('30', (320, 322)),\n",
|
188 |
+
" ('Rd2+', (323, 327)),\n",
|
189 |
+
" ('Ke6', (328, 331)),\n",
|
190 |
+
" ('31', (332, 334)),\n",
|
191 |
+
" ('Rd4', (335, 338)),\n",
|
192 |
+
" ('a5', (339, 341)),\n",
|
193 |
+
" ('32', (342, 344)),\n",
|
194 |
+
" ('g3', (345, 347)),\n",
|
195 |
+
" ('Nd5', (348, 351)),\n",
|
196 |
+
" ('33', (352, 354)),\n",
|
197 |
+
" ('Bc1', (355, 358)),\n",
|
198 |
+
" ('Nb6', (359, 362)),\n",
|
199 |
+
" ('34', (363, 365)),\n",
|
200 |
+
" ('h4', (366, 368)),\n",
|
201 |
+
" ('g6', (369, 371)),\n",
|
202 |
+
" ('35', (372, 374)),\n",
|
203 |
+
" ('Bd2', (375, 378)),\n",
|
204 |
+
" ('Nd5', (379, 382)),\n",
|
205 |
+
" ('36', (383, 385)),\n",
|
206 |
+
" ('Bc1', (386, 389)),\n",
|
207 |
+
" ('Nb6', (390, 393)),\n",
|
208 |
+
" ('37', (394, 396)),\n",
|
209 |
+
" ('Bd2', (397, 400)),\n",
|
210 |
+
" ('Nd5', (401, 404)),\n",
|
211 |
+
" ('38', (405, 407)),\n",
|
212 |
+
" ('Rxc4', (408, 412)),\n",
|
213 |
+
" ('Rxb2', (413, 417)),\n",
|
214 |
+
" ('39', (418, 420)),\n",
|
215 |
+
" ('Ke1', (421, 424)),\n",
|
216 |
+
" ('Nb6', (425, 428)),\n",
|
217 |
+
" ('40', (429, 431)),\n",
|
218 |
+
" ('Re4+', (432, 436)),\n",
|
219 |
+
" ('Kd5', (437, 440)),\n",
|
220 |
+
" ('41', (441, 443)),\n",
|
221 |
+
" ('Re7', (444, 447)),\n",
|
222 |
+
" ('Rb1+', (448, 452)),\n",
|
223 |
+
" ('42', (453, 455)),\n",
|
224 |
+
" ('Ke2', (456, 459)),\n",
|
225 |
+
" ('Nc4', (460, 463)),\n",
|
226 |
+
" ('43', (464, 466)),\n",
|
227 |
+
" ('Bc3', (467, 470)),\n",
|
228 |
+
" ('f5', (471, 473)),\n",
|
229 |
+
" ('44', (474, 476)),\n",
|
230 |
+
" ('Rd7+', (477, 481)),\n",
|
231 |
+
" ('Ke6', (482, 485)),\n",
|
232 |
+
" ('45', (486, 488)),\n",
|
233 |
+
" ('Rxh7', (489, 493)),\n",
|
234 |
+
" ('Rb3', (494, 497)),\n",
|
235 |
+
" ('46', (498, 500)),\n",
|
236 |
+
" ('Bd4', (501, 504)),\n",
|
237 |
+
" ('Rxa3', (505, 509)),\n",
|
238 |
+
" ('47', (510, 512)),\n",
|
239 |
+
" ('Rc7', (513, 516)),\n",
|
240 |
+
" ('Ra2+', (517, 521)),\n",
|
241 |
+
" ('48', (522, 524)),\n",
|
242 |
+
" ('Kf3', (525, 528)),\n",
|
243 |
+
" ('Kd5', (529, 532)),\n",
|
244 |
+
" ('49', (533, 535)),\n",
|
245 |
+
" ('Rd7+', (536, 540)),\n",
|
246 |
+
" ('Kc6', (541, 544)),\n",
|
247 |
+
" ('50', (545, 547)),\n",
|
248 |
+
" ('Rg7', (548, 551)),\n",
|
249 |
+
" ('Kd5', (552, 555)),\n",
|
250 |
+
" ('51', (556, 558)),\n",
|
251 |
+
" ('Rd7+', (559, 563)),\n",
|
252 |
+
" ('Kc6', (564, 567)),\n",
|
253 |
+
" ('52', (568, 570)),\n",
|
254 |
+
" ('Rg7', (571, 574)),\n",
|
255 |
+
" ('Kd5', (575, 578)),\n",
|
256 |
+
" ('53', (579, 581)),\n",
|
257 |
+
" ('Rd7+', (582, 586))]"
|
258 |
+
]
|
259 |
+
},
|
260 |
+
"execution_count": 139,
|
261 |
+
"metadata": {},
|
262 |
+
"output_type": "execute_result"
|
263 |
+
}
|
264 |
+
],
|
265 |
+
"source": [
|
266 |
+
"tokenizer.pre_tokenizer.pre_tokenize_str(tokenizer.normalizer.normalize_str(test_str))"
|
267 |
+
]
|
268 |
+
},
|
269 |
+
{
|
270 |
+
"cell_type": "code",
|
271 |
+
"execution_count": 140,
|
272 |
+
"metadata": {},
|
273 |
+
"outputs": [
|
274 |
+
{
|
275 |
+
"data": {
|
276 |
+
"text/plain": [
|
277 |
+
"['1',\n",
|
278 |
+
" 'e4',\n",
|
279 |
+
" 'e5',\n",
|
280 |
+
" '2',\n",
|
281 |
+
" 'Nf3',\n",
|
282 |
+
" 'Nc6',\n",
|
283 |
+
" '3',\n",
|
284 |
+
" 'd4',\n",
|
285 |
+
" 'exd4',\n",
|
286 |
+
" '4',\n",
|
287 |
+
" 'Nxd4',\n",
|
288 |
+
" 'Nf6',\n",
|
289 |
+
" '5',\n",
|
290 |
+
" 'Nxc6',\n",
|
291 |
+
" 'bxc6',\n",
|
292 |
+
" '6',\n",
|
293 |
+
" 'Bd3',\n",
|
294 |
+
" 'd5',\n",
|
295 |
+
" '7',\n",
|
296 |
+
" 'exd5',\n",
|
297 |
+
" 'cxd5',\n",
|
298 |
+
" '8',\n",
|
299 |
+
" 'O-O',\n",
|
300 |
+
" 'Be7',\n",
|
301 |
+
" '9',\n",
|
302 |
+
" 'c4',\n",
|
303 |
+
" 'O-O',\n",
|
304 |
+
" '10',\n",
|
305 |
+
" 'cxd5',\n",
|
306 |
+
" 'Bb7',\n",
|
307 |
+
" '11',\n",
|
308 |
+
" 'Nc3',\n",
|
309 |
+
" 'Nxd5',\n",
|
310 |
+
" '12',\n",
|
311 |
+
" 'Bd2',\n",
|
312 |
+
" 'Nb4',\n",
|
313 |
+
" '13',\n",
|
314 |
+
" 'Be4',\n",
|
315 |
+
" 'Bxe4',\n",
|
316 |
+
" '14',\n",
|
317 |
+
" 'Nxe4',\n",
|
318 |
+
" 'c5',\n",
|
319 |
+
" '15',\n",
|
320 |
+
" 'Bc3',\n",
|
321 |
+
" 'Qxd1',\n",
|
322 |
+
" '16',\n",
|
323 |
+
" 'Rfxd1',\n",
|
324 |
+
" 'Rad8',\n",
|
325 |
+
" '17',\n",
|
326 |
+
" 'a3',\n",
|
327 |
+
" 'Nd5',\n",
|
328 |
+
" '18',\n",
|
329 |
+
" 'Ba5',\n",
|
330 |
+
" 'Nb6',\n",
|
331 |
+
" '19',\n",
|
332 |
+
" 'Nc3',\n",
|
333 |
+
" 'Bf6',\n",
|
334 |
+
" '20',\n",
|
335 |
+
" 'Rac1',\n",
|
336 |
+
" 'Bxc3',\n",
|
337 |
+
" '21',\n",
|
338 |
+
" 'Bxc3',\n",
|
339 |
+
" 'Rxd1+',\n",
|
340 |
+
" '22',\n",
|
341 |
+
" 'Rxd1',\n",
|
342 |
+
" 'f6',\n",
|
343 |
+
" '23',\n",
|
344 |
+
" 'Kf1',\n",
|
345 |
+
" 'Kf7',\n",
|
346 |
+
" '24',\n",
|
347 |
+
" 'Rc1',\n",
|
348 |
+
" 'Rd8',\n",
|
349 |
+
" '25',\n",
|
350 |
+
" 'Ke2',\n",
|
351 |
+
" 'Ke6',\n",
|
352 |
+
" '26',\n",
|
353 |
+
" 'Bd2',\n",
|
354 |
+
" 'c4',\n",
|
355 |
+
" '27',\n",
|
356 |
+
" 'Be3',\n",
|
357 |
+
" 'Rb8',\n",
|
358 |
+
" '28',\n",
|
359 |
+
" 'Rc2',\n",
|
360 |
+
" 'Rb7',\n",
|
361 |
+
" '29',\n",
|
362 |
+
" 'h3',\n",
|
363 |
+
" 'Kd5',\n",
|
364 |
+
" '30',\n",
|
365 |
+
" 'Rd2+',\n",
|
366 |
+
" 'Ke6',\n",
|
367 |
+
" '31',\n",
|
368 |
+
" 'Rd4',\n",
|
369 |
+
" 'a5',\n",
|
370 |
+
" '32',\n",
|
371 |
+
" 'g3',\n",
|
372 |
+
" 'Nd5',\n",
|
373 |
+
" '33',\n",
|
374 |
+
" 'Bc1',\n",
|
375 |
+
" 'Nb6',\n",
|
376 |
+
" '34',\n",
|
377 |
+
" 'h4',\n",
|
378 |
+
" 'g6',\n",
|
379 |
+
" '35',\n",
|
380 |
+
" 'Bd2',\n",
|
381 |
+
" 'Nd5',\n",
|
382 |
+
" '36',\n",
|
383 |
+
" 'Bc1',\n",
|
384 |
+
" 'Nb6',\n",
|
385 |
+
" '37',\n",
|
386 |
+
" 'Bd2',\n",
|
387 |
+
" 'Nd5',\n",
|
388 |
+
" '38',\n",
|
389 |
+
" 'Rxc4',\n",
|
390 |
+
" 'Rxb2',\n",
|
391 |
+
" '39',\n",
|
392 |
+
" 'Ke1',\n",
|
393 |
+
" 'Nb6',\n",
|
394 |
+
" '40',\n",
|
395 |
+
" 'Re4+',\n",
|
396 |
+
" 'Kd5',\n",
|
397 |
+
" '41',\n",
|
398 |
+
" 'Re7',\n",
|
399 |
+
" 'Rb1+',\n",
|
400 |
+
" '42',\n",
|
401 |
+
" 'Ke2',\n",
|
402 |
+
" 'Nc4',\n",
|
403 |
+
" '43',\n",
|
404 |
+
" 'Bc3',\n",
|
405 |
+
" 'f5',\n",
|
406 |
+
" '44',\n",
|
407 |
+
" 'Rd7+',\n",
|
408 |
+
" 'Ke6',\n",
|
409 |
+
" '45',\n",
|
410 |
+
" 'Rxh7',\n",
|
411 |
+
" 'Rb3',\n",
|
412 |
+
" '46',\n",
|
413 |
+
" 'Bd4',\n",
|
414 |
+
" 'Rxa3',\n",
|
415 |
+
" '47',\n",
|
416 |
+
" 'Rc7',\n",
|
417 |
+
" 'Ra2+',\n",
|
418 |
+
" '48',\n",
|
419 |
+
" 'Kf3',\n",
|
420 |
+
" 'Kd5',\n",
|
421 |
+
" '49',\n",
|
422 |
+
" 'Rd7+',\n",
|
423 |
+
" 'Kc6',\n",
|
424 |
+
" '50',\n",
|
425 |
+
" 'Rg7',\n",
|
426 |
+
" 'Kd5',\n",
|
427 |
+
" '51',\n",
|
428 |
+
" 'Rd7+',\n",
|
429 |
+
" 'Kc6',\n",
|
430 |
+
" '52',\n",
|
431 |
+
" 'Rg7',\n",
|
432 |
+
" 'Kd5',\n",
|
433 |
+
" '53',\n",
|
434 |
+
" 'Rd7+']"
|
435 |
+
]
|
436 |
+
},
|
437 |
+
"execution_count": 140,
|
438 |
+
"metadata": {},
|
439 |
+
"output_type": "execute_result"
|
440 |
+
}
|
441 |
+
],
|
442 |
+
"source": [
|
443 |
+
"tokenizer.encode(test_str).tokens"
|
444 |
+
]
|
445 |
+
},
|
446 |
+
{
|
447 |
+
"cell_type": "code",
|
448 |
+
"execution_count": 142,
|
449 |
+
"metadata": {},
|
450 |
+
"outputs": [
|
451 |
+
{
|
452 |
+
"data": {
|
453 |
+
"text/plain": [
|
454 |
+
"[11,\n",
|
455 |
+
" 48,\n",
|
456 |
+
" 53,\n",
|
457 |
+
" 12,\n",
|
458 |
+
" 79,\n",
|
459 |
+
" 116,\n",
|
460 |
+
" 13,\n",
|
461 |
+
" 45,\n",
|
462 |
+
" 307,\n",
|
463 |
+
" 14,\n",
|
464 |
+
" 193,\n",
|
465 |
+
" 74,\n",
|
466 |
+
" 15,\n",
|
467 |
+
" 434,\n",
|
468 |
+
" 391,\n",
|
469 |
+
" 16,\n",
|
470 |
+
" 154,\n",
|
471 |
+
" 46,\n",
|
472 |
+
" 17,\n",
|
473 |
+
" 190,\n",
|
474 |
+
" 199,\n",
|
475 |
+
" 18,\n",
|
476 |
+
" 51,\n",
|
477 |
+
" 150,\n",
|
478 |
+
" 19,\n",
|
479 |
+
" 65,\n",
|
480 |
+
" 51,\n",
|
481 |
+
" 71,\n",
|
482 |
+
" 199,\n",
|
483 |
+
" 229,\n",
|
484 |
+
" 76,\n",
|
485 |
+
" 102,\n",
|
486 |
+
" 244,\n",
|
487 |
+
" 78,\n",
|
488 |
+
" 253,\n",
|
489 |
+
" 405,\n",
|
490 |
+
" 80,\n",
|
491 |
+
" 342,\n",
|
492 |
+
" 345,\n",
|
493 |
+
" 82,\n",
|
494 |
+
" 228,\n",
|
495 |
+
" 63,\n",
|
496 |
+
" 83,\n",
|
497 |
+
" 400,\n",
|
498 |
+
" 832,\n",
|
499 |
+
" 84,\n",
|
500 |
+
" 1660,\n",
|
501 |
+
" 432,\n",
|
502 |
+
" 86,\n",
|
503 |
+
" 117,\n",
|
504 |
+
" 176,\n",
|
505 |
+
" 88,\n",
|
506 |
+
" 692,\n",
|
507 |
+
" 319,\n",
|
508 |
+
" 90,\n",
|
509 |
+
" 102,\n",
|
510 |
+
" 322,\n",
|
511 |
+
" 91,\n",
|
512 |
+
" 459,\n",
|
513 |
+
" 386,\n",
|
514 |
+
" 92,\n",
|
515 |
+
" 386,\n",
|
516 |
+
" 791,\n",
|
517 |
+
" 95,\n",
|
518 |
+
" 519,\n",
|
519 |
+
" 177,\n",
|
520 |
+
" 96,\n",
|
521 |
+
" 273,\n",
|
522 |
+
" 201,\n",
|
523 |
+
" 98,\n",
|
524 |
+
" 222,\n",
|
525 |
+
" 214,\n",
|
526 |
+
" 103,\n",
|
527 |
+
" 239,\n",
|
528 |
+
" 246,\n",
|
529 |
+
" 105,\n",
|
530 |
+
" 253,\n",
|
531 |
+
" 65,\n",
|
532 |
+
" 110,\n",
|
533 |
+
" 155,\n",
|
534 |
+
" 241,\n",
|
535 |
+
" 113,\n",
|
536 |
+
" 346,\n",
|
537 |
+
" 421,\n",
|
538 |
+
" 114,\n",
|
539 |
+
" 107,\n",
|
540 |
+
" 324,\n",
|
541 |
+
" 115,\n",
|
542 |
+
" 808,\n",
|
543 |
+
" 246,\n",
|
544 |
+
" 118,\n",
|
545 |
+
" 414,\n",
|
546 |
+
" 77,\n",
|
547 |
+
" 121,\n",
|
548 |
+
" 112,\n",
|
549 |
+
" 176,\n",
|
550 |
+
" 122,\n",
|
551 |
+
" 572,\n",
|
552 |
+
" 319,\n",
|
553 |
+
" 125,\n",
|
554 |
+
" 73,\n",
|
555 |
+
" 100,\n",
|
556 |
+
" 126,\n",
|
557 |
+
" 253,\n",
|
558 |
+
" 176,\n",
|
559 |
+
" 128,\n",
|
560 |
+
" 572,\n",
|
561 |
+
" 319,\n",
|
562 |
+
" 131,\n",
|
563 |
+
" 253,\n",
|
564 |
+
" 176,\n",
|
565 |
+
" 136,\n",
|
566 |
+
" 553,\n",
|
567 |
+
" 578,\n",
|
568 |
+
" 139,\n",
|
569 |
+
" 487,\n",
|
570 |
+
" 319,\n",
|
571 |
+
" 143,\n",
|
572 |
+
" 1064,\n",
|
573 |
+
" 324,\n",
|
574 |
+
" 145,\n",
|
575 |
+
" 373,\n",
|
576 |
+
" 854,\n",
|
577 |
+
" 149,\n",
|
578 |
+
" 239,\n",
|
579 |
+
" 254,\n",
|
580 |
+
" 153,\n",
|
581 |
+
" 400,\n",
|
582 |
+
" 140,\n",
|
583 |
+
" 156,\n",
|
584 |
+
" 785,\n",
|
585 |
+
" 246,\n",
|
586 |
+
" 160,\n",
|
587 |
+
" 820,\n",
|
588 |
+
" 475,\n",
|
589 |
+
" 165,\n",
|
590 |
+
" 305,\n",
|
591 |
+
" 708,\n",
|
592 |
+
" 169,\n",
|
593 |
+
" 326,\n",
|
594 |
+
" 801,\n",
|
595 |
+
" 179,\n",
|
596 |
+
" 225,\n",
|
597 |
+
" 324,\n",
|
598 |
+
" 186,\n",
|
599 |
+
" 785,\n",
|
600 |
+
" 350,\n",
|
601 |
+
" 194,\n",
|
602 |
+
" 595,\n",
|
603 |
+
" 324,\n",
|
604 |
+
" 200,\n",
|
605 |
+
" 785,\n",
|
606 |
+
" 350,\n",
|
607 |
+
" 210,\n",
|
608 |
+
" 595,\n",
|
609 |
+
" 324,\n",
|
610 |
+
" 224,\n",
|
611 |
+
" 785]"
|
612 |
+
]
|
613 |
+
},
|
614 |
+
"execution_count": 142,
|
615 |
+
"metadata": {},
|
616 |
+
"output_type": "execute_result"
|
617 |
+
}
|
618 |
+
],
|
619 |
+
"source": [
|
620 |
+
"tokenizer.encode(test_str)"
|
621 |
+
]
|
622 |
+
},
|
623 |
+
{
|
624 |
+
"cell_type": "code",
|
625 |
+
"execution_count": 143,
|
626 |
+
"metadata": {},
|
627 |
+
"outputs": [
|
628 |
+
{
|
629 |
+
"data": {
|
630 |
+
"text/plain": [
|
631 |
+
"13677"
|
632 |
+
]
|
633 |
+
},
|
634 |
+
"execution_count": 143,
|
635 |
+
"metadata": {},
|
636 |
+
"output_type": "execute_result"
|
637 |
+
}
|
638 |
+
],
|
639 |
+
"source": [
|
640 |
+
"tokenizer.get_vocab_size()"
|
641 |
+
]
|
642 |
+
},
|
643 |
+
{
|
644 |
+
"cell_type": "code",
|
645 |
+
"execution_count": null,
|
646 |
+
"metadata": {},
|
647 |
+
"outputs": [],
|
648 |
+
"source": []
|
649 |
+
}
|
650 |
+
],
|
651 |
+
"metadata": {
|
652 |
+
"kernelspec": {
|
653 |
+
"display_name": "chess",
|
654 |
+
"language": "python",
|
655 |
+
"name": "python3"
|
656 |
+
},
|
657 |
+
"language_info": {
|
658 |
+
"codemirror_mode": {
|
659 |
+
"name": "ipython",
|
660 |
+
"version": 3
|
661 |
+
},
|
662 |
+
"file_extension": ".py",
|
663 |
+
"mimetype": "text/x-python",
|
664 |
+
"name": "python",
|
665 |
+
"nbconvert_exporter": "python",
|
666 |
+
"pygments_lexer": "ipython3",
|
667 |
+
"version": "3.11.5"
|
668 |
+
},
|
669 |
+
"orig_nbformat": 4
|
670 |
+
},
|
671 |
+
"nbformat": 4,
|
672 |
+
"nbformat_minor": 2
|
673 |
+
}
|