Skip to content

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

Open

Description

@int8

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

Activity

  1. reidmcy commented on Dec 16, 2021

    @reidmcy
    Member

    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.

  2. int8 commented on Dec 16, 2021

    @int8
    Author

    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?

  3. int8 commented on Dec 16, 2021

    @int8
    Author

    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
  4. reidmcy commented on Dec 17, 2021

    @reidmcy
    Member

    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.

  5. zodwick commented on Jun 12, 2024

    @zodwick

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions