Update README.md
Browse files
README.md
CHANGED
|
@@ -23,28 +23,33 @@ The ChessBot model is a transformer-based architecture designed for chess gamepl
|
|
| 23 |
|
| 24 |
```python
|
| 25 |
import torch
|
| 26 |
-
from
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# Add to path and import
|
| 32 |
-
import sys
|
| 33 |
-
sys.path.append(model_path)
|
| 34 |
-
from modeling_chessbot import ChessBotModel, ChessBotConfig
|
| 35 |
-
|
| 36 |
-
# Load the model
|
| 37 |
-
config = ChessBotConfig()
|
| 38 |
-
model = ChessBotModel.from_pretrained(model_path)
|
| 39 |
|
| 40 |
# Example usage
|
| 41 |
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
| 42 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 43 |
-
model = model.to(device)
|
| 44 |
|
| 45 |
# Get the best move
|
| 46 |
move = model.get_move_from_fen_no_thinking(fen, T=0.1, device=device)
|
| 47 |
-
print(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
```
|
| 49 |
|
| 50 |
## Requirements
|
|
|
|
| 23 |
|
| 24 |
```python
|
| 25 |
import torch
|
| 26 |
+
from transformers import AutoModel
|
| 27 |
|
| 28 |
+
model = AutoModel.from_pretrained("Maxlegrec/ChessBot", trust_remote_code=True)
|
| 29 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 30 |
+
model = model.to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Example usage
|
| 33 |
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# Get the best move
|
| 36 |
move = model.get_move_from_fen_no_thinking(fen, T=0.1, device=device)
|
| 37 |
+
print(f"Policy-based move: {move}")
|
| 38 |
+
|
| 39 |
+
# Get the best move using value analysis
|
| 40 |
+
value_move = model.get_best_move_value(fen, T=0, device=device)
|
| 41 |
+
print(f"Value-based move: {value_move}")
|
| 42 |
+
|
| 43 |
+
# Get position evaluation
|
| 44 |
+
position_value = model.get_position_value(fen, device=device)
|
| 45 |
+
print(f"Position value [black_win, draw, white_win]: {position_value}")
|
| 46 |
+
|
| 47 |
+
# Get move probabilities
|
| 48 |
+
probs = model.get_move_from_fen_no_thinking(fen, T=1, device=device, return_probs=True)
|
| 49 |
+
top_moves = sorted(probs.items(), key=lambda x: x[1], reverse=True)[:5]
|
| 50 |
+
print("Top 5 moves:")
|
| 51 |
+
for move, prob in top_moves:
|
| 52 |
+
print(f" {move}: {prob:.4f}")
|
| 53 |
```
|
| 54 |
|
| 55 |
## Requirements
|