Videos

Creating a Chess AI with TensorFlow



Digital Secrets

Learn how to create an AI that plays chess using a convolutional neural network.

Link for the colab page:
https://colab.research.google.com/drive/1GSeBQdyZH_nHvl52XW0uhXV3Cslho24O

Link for the dataset show in the video:
https://drive.google.com/file/d/1YcFh-uBHflrRuQjh3rQ8CFfY2YKx7ytw

More matches:
https://drive.google.com/file/d/1_p3boDObEEfeRvUhQW8dhEmkD1S2l3KD
(you can load the pgn at https://lichess.org/analysis)

Note about the dataset:
I tested training the AI on two different datasets, the first Stockfish analyzed the positions up to depth 20. And on the second, depth 0. To my surprise, the AI trained in the second dataset achieved a much better result during the training and during the game, probably because it was easier for AI to learn the instant evaluation of stockfish, if you have another idea why this happened, we can talk about it in the comments below.

Source

Similar Posts

33 thoughts on “Creating a Chess AI with TensorFlow
  1. I copy-pasted the above code directly, and used the dataset he linked in the comments. I got the same loss as he did after training, yet the model played HORRIBLY when I tested it with the get_ai_move function. Im confused, and help would be appreciated

  2. Hi. This is new to me…
    Could someone give me the code to create the dataset for training? (Using random_board and stockfish eval I guess)

  3. Do i see correctly that you started your AI with min-max depth set to 1.? It would mean that you are actually not using min-max at all, just returning min-max eval value (taken directly from your NN model). Can you tell something about performance of your bot (or rather algorithm itself?): How deep can you dig inside moves tree to get correct move and a reasonable time to wait?

  4. Absolutely love your tutorial, having a fun time trying different architectures. I could really need some help on generating some more data on higher search depth, to further train the model. But I'm kinda struggling to get the stockfish to work.

  5. By the way, you can change

    def minimax_eval(board):

    board3d = split_dims(board)

    board3d = numpy.expand_dims(board3d, 0)

    return model.predict(board3d)[0][0]

    to

    def minimax_eval(board):

    board3d = split_dims(board)

    board3d = numpy.expand_dims(board3d, 0)

    return model.predict(board3d)[0][0]

    model.predict() is super slow for some reason, model() is about 10 times faster.

  6. Hello, I have been messing around with different tensorflow chess engines and it seems that your engine is the best in its simplicity (it is very simple and very effective – as we can see on your video). Although when i copy-pasted ur code into my colab with the same dataset and stockfish it plays veeeeery poorly. It's like engine is doing random moves without any sense. Did you do any changes in neural network or dataset in your video?

  7. Great video! I see that you use a 64 positions output layer. Could you explain this to me? I understand that the boardsize is 8*8, but how do you know which piece to move there?

  8. Hey, it is extremly interesting ! However I doubt that python is adapted for a performant min/max algorithm. Of course you can easily get to depth 4/5 but I don't think that you can go further without having to wait for a while. I will look if I can extract this neural network to a C or C++ program.

  9. 2:45 note : this is not the "attacked" areas, this is all the squares white can move to, this makes a difference for pawns (can only move up) and kings (can only move to unchecked squares)

  10. The reason for the AI better performance at depth 0 over depth 20 would be because at depth 0 stockfish returns an evaluation of what is happening on the board at that moment while at depth 20 it is returning an estimate if what will happen in the future.

    Training the AI on calm positions at depth 5 should be enough to make a stable AI.

  11. I would like to know if it were possible to create an AI that plays like a Romantic era player by training it on enough games?

Comments are closed.

WP2Social Auto Publish Powered By : XYZScripts.com