graug commited on
Commit
0118c66
·
verified ·
1 Parent(s): c710424

Chess Challenge submission by graug

Browse files
Files changed (5) hide show
  1. README.md +2 -2
  2. config.json +1 -1
  3. model.safetensors +2 -2
  4. tokenizer.py +18 -21
  5. vocab.json +64 -70
README.md CHANGED
@@ -14,13 +14,13 @@ Chess model submitted to the LLM Course Chess Challenge.
14
  ## Submission Info
15
 
16
  - **Submitted by**: [graug](https://huggingface.co/graug)
17
- - **Parameters**: 704,000
18
  - **Organization**: LLM-course
19
 
20
  ## Model Details
21
 
22
  - **Architecture**: Chess Transformer (GPT-style)
23
- - **Vocab size**: 74
24
  - **Embedding dim**: 128
25
  - **Layers**: 4
26
  - **Heads**: 4
 
14
  ## Submission Info
15
 
16
  - **Submitted by**: [graug](https://huggingface.co/graug)
17
+ - **Parameters**: 703,232
18
  - **Organization**: LLM-course
19
 
20
  ## Model Details
21
 
22
  - **Architecture**: Chess Transformer (GPT-style)
23
+ - **Vocab size**: 68
24
  - **Embedding dim**: 128
25
  - **Layers**: 4
26
  - **Heads**: 4
config.json CHANGED
@@ -20,5 +20,5 @@
20
  "pad_token_id": 0,
21
  "tie_weights": true,
22
  "transformers_version": "4.57.5",
23
- "vocab_size": 74
24
  }
 
20
  "pad_token_id": 0,
21
  "tie_weights": true,
22
  "transformers_version": "4.57.5",
23
+ "vocab_size": 68
24
  }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:59b83e6a044a255f31154ccfed055dc4cc9ff42d3ceba06068732294fa6ce406
3
- size 2820400
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f4ad5a4f30494574e79f1987ece70a031bd032836128bad310028653d2a0def
3
+ size 2817328
tokenizer.py CHANGED
@@ -183,7 +183,7 @@ class ChessTokenizer(PreTrainedTokenizer):
183
  @classmethod
184
  def build_vocab_uci(cls):
185
 
186
- pièces = ['P', 'N', 'B', 'R', 'Q', 'K']
187
  files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
188
  ranks = ['1', '2', '3', '4', '5', '6', '7', '8']
189
 
@@ -192,7 +192,7 @@ class ChessTokenizer(PreTrainedTokenizer):
192
  for rank in ranks:
193
  cases.append(f"{file}{rank}")
194
 
195
- vocab_list = pièces + cases
196
  return cls.build_vocab_from_iterator(vocab_list)
197
 
198
 
@@ -229,27 +229,30 @@ class ChessTokenizer(PreTrainedTokenizer):
229
  tokens.append(word)
230
  continue
231
 
232
- # Remove W/B color prefix
233
  if len(word) > 0 and word[0] in 'WB':
234
  move = word[1:]
235
  else:
236
  move = word
 
 
 
 
237
 
238
  # Remove suffixes like (x), (+), (+*), (o), (O)
239
  for symbol in ['(x+*)', '(x+)', '(x)', '(+*)', '(+)', '(o)', '(O)']:
240
  move = move.replace(symbol, '')
241
 
242
- # Handle promotion: Pe7e8=Q -> extract piece, from, to (ignore promotion for now)
243
  if '=' in move:
244
  move = move.split('=')[0]
245
 
246
- # Now move should be like "Pe2e4" (5 chars) or longer
247
- if len(move) >= 5:
248
- piece = move[0] # 'P', 'N', 'B', 'R', 'Q', 'K'
249
- from_sq = move[1:3] # 'e2'
250
- to_sq = move[3:5] # 'e4'
251
- tokens.extend([piece, from_sq, to_sq])
252
-
253
  return tokens
254
 
255
 
@@ -269,19 +272,13 @@ class ChessTokenizer(PreTrainedTokenizer):
269
 
270
  tokens = [t for t in tokens if t not in special]
271
 
272
- #Grouper les tokens par 3
273
- grouped_tokens = ["".join(tokens[i:i+3]) for i in range(0, len(tokens), 3)]
 
274
 
275
- # mettre une fois sur deux B avant les coups noirs sinon W
276
- final_tokens = []
277
 
278
- for i, token in enumerate(grouped_tokens):
279
- if i % 2 == 0:
280
- final_tokens.append('W' + token)
281
- else:
282
- final_tokens.append('B' + token)
283
 
284
- return " ".join(final_tokens)
285
 
286
  def save_vocabulary(
287
  self,
 
183
  @classmethod
184
  def build_vocab_uci(cls):
185
 
186
+
187
  files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
188
  ranks = ['1', '2', '3', '4', '5', '6', '7', '8']
189
 
 
192
  for rank in ranks:
193
  cases.append(f"{file}{rank}")
194
 
195
+ vocab_list = cases
196
  return cls.build_vocab_from_iterator(vocab_list)
197
 
198
 
 
229
  tokens.append(word)
230
  continue
231
 
232
+ # Remove W/B color prefix
233
  if len(word) > 0 and word[0] in 'WB':
234
  move = word[1:]
235
  else:
236
  move = word
237
+ #remove piece
238
+ if word[1] in 'PNBRQK':
239
+ move = move[1:]
240
+
241
 
242
  # Remove suffixes like (x), (+), (+*), (o), (O)
243
  for symbol in ['(x+*)', '(x+)', '(x)', '(+*)', '(+)', '(o)', '(O)']:
244
  move = move.replace(symbol, '')
245
 
246
+ # suppress promotion for now
247
  if '=' in move:
248
  move = move.split('=')[0]
249
 
250
+
251
+ # Now move should be in format from_square + to_square (e.g., e2e4)
252
+ if len(move) == 4:
253
+ from_sq = move[:2]
254
+ to_sq = move[2:]
255
+ tokens.extend([from_sq, to_sq])
 
256
  return tokens
257
 
258
 
 
272
 
273
  tokens = [t for t in tokens if t not in special]
274
 
275
+ #Grouper les tokens par 2 (from_square, to_square)
276
+ grouped_tokens = ["".join(tokens[i:i+2]) for i in range(0, len(tokens), 2)]
277
+
278
 
 
 
279
 
 
 
 
 
 
280
 
281
+ return " ".join(grouped_tokens)
282
 
283
  def save_vocabulary(
284
  self,
vocab.json CHANGED
@@ -3,74 +3,68 @@
3
  "[BOS]": 1,
4
  "[EOS]": 2,
5
  "[UNK]": 3,
6
- "B": 4,
7
- "K": 5,
8
- "N": 6,
9
- "P": 7,
10
- "Q": 8,
11
- "R": 9,
12
- "a1": 10,
13
- "a2": 11,
14
- "a3": 12,
15
- "a4": 13,
16
- "a5": 14,
17
- "a6": 15,
18
- "a7": 16,
19
- "a8": 17,
20
- "b1": 18,
21
- "b2": 19,
22
- "b3": 20,
23
- "b4": 21,
24
- "b5": 22,
25
- "b6": 23,
26
- "b7": 24,
27
- "b8": 25,
28
- "c1": 26,
29
- "c2": 27,
30
- "c3": 28,
31
- "c4": 29,
32
- "c5": 30,
33
- "c6": 31,
34
- "c7": 32,
35
- "c8": 33,
36
- "d1": 34,
37
- "d2": 35,
38
- "d3": 36,
39
- "d4": 37,
40
- "d5": 38,
41
- "d6": 39,
42
- "d7": 40,
43
- "d8": 41,
44
- "e1": 42,
45
- "e2": 43,
46
- "e3": 44,
47
- "e4": 45,
48
- "e5": 46,
49
- "e6": 47,
50
- "e7": 48,
51
- "e8": 49,
52
- "f1": 50,
53
- "f2": 51,
54
- "f3": 52,
55
- "f4": 53,
56
- "f5": 54,
57
- "f6": 55,
58
- "f7": 56,
59
- "f8": 57,
60
- "g1": 58,
61
- "g2": 59,
62
- "g3": 60,
63
- "g4": 61,
64
- "g5": 62,
65
- "g6": 63,
66
- "g7": 64,
67
- "g8": 65,
68
- "h1": 66,
69
- "h2": 67,
70
- "h3": 68,
71
- "h4": 69,
72
- "h5": 70,
73
- "h6": 71,
74
- "h7": 72,
75
- "h8": 73
76
  }
 
3
  "[BOS]": 1,
4
  "[EOS]": 2,
5
  "[UNK]": 3,
6
+ "a1": 4,
7
+ "a2": 5,
8
+ "a3": 6,
9
+ "a4": 7,
10
+ "a5": 8,
11
+ "a6": 9,
12
+ "a7": 10,
13
+ "a8": 11,
14
+ "b1": 12,
15
+ "b2": 13,
16
+ "b3": 14,
17
+ "b4": 15,
18
+ "b5": 16,
19
+ "b6": 17,
20
+ "b7": 18,
21
+ "b8": 19,
22
+ "c1": 20,
23
+ "c2": 21,
24
+ "c3": 22,
25
+ "c4": 23,
26
+ "c5": 24,
27
+ "c6": 25,
28
+ "c7": 26,
29
+ "c8": 27,
30
+ "d1": 28,
31
+ "d2": 29,
32
+ "d3": 30,
33
+ "d4": 31,
34
+ "d5": 32,
35
+ "d6": 33,
36
+ "d7": 34,
37
+ "d8": 35,
38
+ "e1": 36,
39
+ "e2": 37,
40
+ "e3": 38,
41
+ "e4": 39,
42
+ "e5": 40,
43
+ "e6": 41,
44
+ "e7": 42,
45
+ "e8": 43,
46
+ "f1": 44,
47
+ "f2": 45,
48
+ "f3": 46,
49
+ "f4": 47,
50
+ "f5": 48,
51
+ "f6": 49,
52
+ "f7": 50,
53
+ "f8": 51,
54
+ "g1": 52,
55
+ "g2": 53,
56
+ "g3": 54,
57
+ "g4": 55,
58
+ "g5": 56,
59
+ "g6": 57,
60
+ "g7": 58,
61
+ "g8": 59,
62
+ "h1": 60,
63
+ "h2": 61,
64
+ "h3": 62,
65
+ "h4": 63,
66
+ "h5": 64,
67
+ "h6": 65,
68
+ "h7": 66,
69
+ "h8": 67
 
 
 
 
 
 
70
  }