Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use blunder prediction for given position/fen + next move #32

Open
int8 opened this issue Dec 16, 2021 · 5 comments
Open

How to use blunder prediction for given position/fen + next move #32

int8 opened this issue Dec 16, 2021 · 5 comments

Comments

@int8
Copy link

int8 commented Dec 16, 2021

Hello there,

I am trying to use blunder prediction for my hobby project I plan to work on - what I need is to predict blunder probability for given move at given position - how do I do it ?

P.S. I would rather avoid training my own blunder prediction model

@reidmcy
Copy link
Member

reidmcy commented Dec 16, 2021

You should be able to load our models with the standard Pytorch load function. They don't use or predict the next move though, just the board (and metadata for some models) to predict the binary will_blunder. Then the code in the validate_batch method is how we run the analysis. It's all done in large batches for efficiency so running on a singe position might require some tinkering.

@int8
Copy link
Author

int8 commented Dec 16, 2021

all right, seems like your advice + #10 helped me :)

The next step for me is to map FEN into tensor so I can pass it to forward call - any helper function I could use?

@int8
Copy link
Author

int8 commented Dec 16, 2021

ok - found it,

now I am here:

from haibrid_chess_utils import fen_to_vec

model = torch.load(
    "blunder_prediction/model_weights/leela_extra_blunder_00001-234000.pt", 
    map_location=torch.device('cpu')
)

t = torch.from_numpy(
    fen_to_vec.fenToVec(
        "r1bqkb1r/ppp2ppp/2n2n2/3Pp1N1/2B5/8/PPPP1PPP/RNBQK2R b KQkq - 0 5"
    )).reshape(-1, 17, 8, 8)

result = model.forward(
    input_x=t, 
    extra_x={
        'clock_percent': torch.tensor([.05]).float(), 
        'opponent_elo': torch.tensor([1800]).float(), 
        'active_elo': torch.tensor([1800]).float(), 
        'cp_rel': torch.tensor([0.2]).float(), 
        'move_ply': torch.tensor([30]).float()}
)

which is sort of critical moment of fried liver attack: https://lichess.org/analysis/standard/r1bqkb1r/ppp2ppp/2n2n2/3Pp1N1/2B5/8/PPPP1PPP/RNBQK2R_b_KQkq_-_0_5

  1. Can you sanity check that on your installation and check what is probability of a blunder in that setup ?
  2. What is the extra_x dict exactly, I think I understand active_elo (player to move elo, right?), opponent_elo (obvious I hope) but I am very unsure about move_ply, clock_percent and cp_rel

@reidmcy
Copy link
Member

reidmcy commented Dec 17, 2021

I don't have an easy way to run the models. This project is in an archive and the machine we used has been reallocated. So I can't check that.

You're correct about the first two values, move_ply is the ply of the current move the first move is ply 1, same indexing as Lichess. clock_percentage is the remaining time as a percentage of the initial clock, I think we assume game will be 30 moves/60 ply if there's an increment. And cp_rel is the centipawn, times 100 so actually pawns, evaluation of the position by stockfish, we do it relative instead of absolute so multiply by -1 if the active player is black.

@ibsmfar ibsmfar mentioned this issue Mar 10, 2022
@zodwick
Copy link

zodwick commented Jun 12, 2024

hey @int8 any progress on this, have you figured out how to do the prediction based on fen ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants