HaileyStorm
commited on
Commit
•
1bb21ac
1
Parent(s):
17dd4f5
Upload chess-gpt-eval/nanogpt/nanogpt_module.py with huggingface_hub
Browse files
chess-gpt-eval/nanogpt/nanogpt_module.py
CHANGED
@@ -95,7 +95,7 @@ class NanoGptPlayer:
|
|
95 |
vocab_size = len(stoi)
|
96 |
print(f"Vocab size {vocab_size}")
|
97 |
encode = lambda s: [stoi[c] for c in s.replace('-', '')]
|
98 |
-
decode = lambda l: "".join([itos[i] for i in l]).replace("OOO", "O-O-O").replace("OO", "O-O")
|
99 |
|
100 |
self.encode = encode
|
101 |
self.decode = decode
|
@@ -134,11 +134,14 @@ class NanoGptPlayer:
|
|
134 |
return model_response
|
135 |
|
136 |
def get_move_from_response(self, response: str) -> str:
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
140 |
|
141 |
-
return first_move
|
142 |
|
143 |
def get_move(self, board: str, game_state: str, temperature: float) -> str:
|
144 |
completion = self.get_nanogpt_response(game_state, temperature)
|
|
|
95 |
vocab_size = len(stoi)
|
96 |
print(f"Vocab size {vocab_size}")
|
97 |
encode = lambda s: [stoi[c] for c in s.replace('-', '')]
|
98 |
+
decode = lambda l: "".join([itos[i] for i in l if i < vocab_size]).replace("OOO", "O-O-O").replace("OO", "O-O")
|
99 |
|
100 |
self.encode = encode
|
101 |
self.decode = decode
|
|
|
134 |
return model_response
|
135 |
|
136 |
def get_move_from_response(self, response: str) -> str:
|
137 |
+
try:
|
138 |
+
# Parse the response to get only the first move
|
139 |
+
moves = response.split()
|
140 |
+
first_move = moves[0]
|
141 |
+
return first_move
|
142 |
+
except:
|
143 |
+
return None
|
144 |
|
|
|
145 |
|
146 |
def get_move(self, board: str, game_state: str, temperature: float) -> str:
|
147 |
completion = self.get_nanogpt_response(game_state, temperature)
|