Views
No views yet
1import torch
2from transformers import AutoModel
3
4model = AutoModel.from_pretrained("Maxlegrec/ChessBot", trust_remote_code=True)
5device = "cuda" if torch.cuda.is_available() else "cpu"
6model = model.to(device)
7
8# Example usage
9fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
10
11# Sample move from policy
12move = model.get_move_from_fen_no_thinking(fen, T=0.1, device=device)
13print(f"Policy-based move: {move}")
14#e2e4
15
16# Get the best move using value analysis
17value_move = model.get_best_move_value(fen, T=0, device=device)
18print(f"Value-based move: {value_move}")
19#e2e4
20
21# Get position evaluation
22position_value = model.get_position_value(fen, device=device)
23print(f"Position value [black_win, draw, white_win]: {position_value}")
24#[0.2318, 0.4618, 0.3064]
25
26# Get move probabilities
27probs = model.get_move_from_fen_no_thinking(fen, T=1, device=device, return_probs=True)
28top_moves = sorted(probs.items(), key=lambda x: x[1], reverse=True)[:5]
29print("Top 5 moves:")
30for move, prob in top_moves:
31 print(f" {move}: {prob:.4f}")
32#Top 5 moves:
33# e2e4: 0.9285
34# d2d4: 0.0712
35# g1f3: 0.0001
36# e2e3: 0.0000
37# c2c3: 0.0000