Downloads · 30 days
28
3% of all-time downloads
yp-edu/gpt2-stockfish-debug
gpt2-stockfish-debug is a text generation model from yp-edu. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
See my blog post for additional details.
Downloads · 30 days
28
3% of all-time downloads
All-time downloads
849
Public
Parameters
124M
498 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors498 MB · 100%
From the Hugging Face model README
See my blog post for additional details.
The model was trained during 1 epoch on the yp-edu/stockfish-debug dataset (no hyperparameter tuning done). The samples are:
{"prompt":"FEN: {fen}\nMOVE:", "completion": " {move}"}
Two possible simple extensions:
r2qk3/... -> r11qk111/... or equivalent{"prompt":"RES: {res}\nFEN: {fen}\nMOVE:", "completion": " {move}"}
The following code requires python-chess (in addition to transformers) which you can install using pip install python-chess.
import chess
from transformers import AutoModelForCausalLM, AutoTokenizer
def next_move(model, tokenizer, fen):
input_ids = tokenizer(f"FEN: {fen}\nMOVE:", return_tensors="pt")
input_ids = {k: v.to(model.device) for k, v in input_ids.items()}
out = model.generate(
**input_ids,
max_new_tokens=10,
pad_token_id=tokenizer.eos_token_id,
do_sample=True,
temperature=0.1,
)
out_str = tokenizer.batch_decode(out)[0]
return out_str.split("MOVE:")[-1].replace("<|endoftext|>", "").strip()
board = chess.Board()
model = AutoModelForCausalLM.from_pretrained("yp-edu/gpt2-stockfish-debug")
tokenizer = AutoTokenizer.from_pretrained("yp-edu/gpt2-stockfish-debug") # or "gpt2"
tokenizer.pad_token = tokenizer.eos_token
for i in range(100):
fen = board.fen()
move_uci = next_move(model, tokenizer, fen)
try:
print(move_uci)
move = chess.Move.from_uci(move_uci)
if move not in board.legal_moves:
raise chess.IllegalMoveError
board.push(move)
outcome = board.outcome()
if outcome is not None:
print(board)
print(outcome.result())
break
except chess.IllegalMoveError:
print(board)
print("Illegal move", i)
break
else:
print(board)