Creating a Chess AI with TensorFlow

  Рет қаралды 73,090

Digital Secrets

Digital Secrets

Күн бұрын

Learn how to create an AI that plays chess using a convolutional neural network.
Link for the colab page:
colab.research...
Link for the dataset show in the video:
drive.google.c...
More matches:
drive.google.c...
(you can load the pgn at lichess.org/an...)
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.

Пікірлер: 101
@Philgob
@Philgob Жыл бұрын
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)
@floowkrunker6610
@floowkrunker6610 4 жыл бұрын
Underrated video
@akhilvashist1339
@akhilvashist1339 3 жыл бұрын
@@DigitalSecrets can you reply i have a question to ask
@DigitalSecrets
@DigitalSecrets 3 жыл бұрын
@@akhilvashist1339 Hi, sure! Sorry for the delay.
@akhilvashist1339
@akhilvashist1339 3 жыл бұрын
@@DigitalSecrets Can you create a chess AI using machine learning and feeding it only the games of Mikhail tal and making him use all of Mikhail tal's games as a database and learn from that to mimic his playstyle?
@Champignon1000
@Champignon1000 3 жыл бұрын
@@akhilvashist1339 that would be possible yes. if you can find the dataset..
@xuehuapiaopiao3549
@xuehuapiaopiao3549 3 жыл бұрын
@@akhilvashist1339 technically yes, but the total of games that mikail tal has played isnt enough for an AI algorithm to learn from.
@noahbond7179
@noahbond7179 Жыл бұрын
Hello! The link to the dataset is no longer working, where did you get the dataset file from originally?
@scasci3929
@scasci3929 4 жыл бұрын
Nice video! About the dataset: It probably works better with depth 0 because a long-term prediction of the game is not required while having a pure intuitive analysis of the current board... so, thanks to that, the network training is more accurate and then, during games, that "long-term prediction" that I mentioned is probably achieved by the minimax algorithm that you implemented to let the ai play.
@user-dh8oi2mk4f
@user-dh8oi2mk4f 3 ай бұрын
this is just not true. Nearly all of the strongest chess engines train their networks on a combination of a low-depth search and the game result(1.0 = win, 0.5 = draw, 0.0 = loss). The only reason that the network trained on depth 20 searches did worse is that depth 20 searches is much too difficult of a training target for a network of that size to learn effectively. If the network were trained on depth 8-9 searches I guarantee it would've performed much better than either of the 2(Also, the testing methodology was very questionable. Looking at the games is not testing, at the very least you should have them play against each other)
@BPGHchess
@BPGHchess 11 ай бұрын
The links don't work anymore.
@gustavboye6691
@gustavboye6691 3 жыл бұрын
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.
@CyanuricMusic
@CyanuricMusic 3 жыл бұрын
I think you mean changing model.predict(board3d)[0][0]) to just be model(board3d)[0][0]). The two examples above are the same..
@Champignon1000
@Champignon1000 Жыл бұрын
@@CyanuricMusic Yes exactly, thats what i meant, sorry.
@nguyenucvinh-BDCCN
@nguyenucvinh-BDCCN Жыл бұрын
@@Champignon1000 do you have link for source code and dataset ? If you have, can you send it for me ? thanks a lot
@Champignon1000
@Champignon1000 Жыл бұрын
@@nguyenucvinh-BDCCN hey no sorry i dont. But recently went back to my own version of this project. Id strongly recoment getting stockfish to work so you can generate your own data on the fly. you need a endless stream of data to train on
@nguyenucvinh-BDCCN
@nguyenucvinh-BDCCN Жыл бұрын
@@Champignon1000 can you send me your version, pls ? KZbin don't allow to write the gmail, so I put my gmail on my description. I'm beginner, so I really want to learn from it. Thanks
@soccerstuff
@soccerstuff 8 ай бұрын
Great Video, the colab link and the google drive doesn't work, is it possible for you to fix it? Thanks!
@senyoohene3021
@senyoohene3021 6 ай бұрын
Excellent video. I'm doing a project on this stuff, and this is really helpful.
@henry-db
@henry-db 3 жыл бұрын
That's WONDERFUL 🤩🤩🤩 !!! 10/10
@owenjones6784
@owenjones6784 3 жыл бұрын
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
@DigitalSecrets
@DigitalSecrets 3 жыл бұрын
Sorry for not making it clear, I made some small improvements to the final model that I did not mention in the video (to make the video not too long). I used "principal variation search" to speed up the searching and concatenated coordinates before the convolutions to help the network encode positions. Let me know if I can clarify any more questions.
@nguyenucvinh-BDCCN
@nguyenucvinh-BDCCN Жыл бұрын
@@DigitalSecrets Can you send me a new link for source code and dataset, pls ? the old one is not working now
@ahmadwahab962
@ahmadwahab962 Жыл бұрын
@@DigitalSecrets Can you send me a new link for source code and dataset too ? the old one is not working
@migueltutu1
@migueltutu1 Жыл бұрын
​@@DigitalSecrets can you send me the link too please? Great video by the way
@RRPLD_Ambassador
@RRPLD_Ambassador 11 ай бұрын
@@DigitalSecrets The link doesn't work anymore, can you send a new link please?
@lordseidon9
@lordseidon9 Жыл бұрын
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.
@nguyenucvinh-BDCCN
@nguyenucvinh-BDCCN Жыл бұрын
do you have link for source code and dataset ? If you have, can you send it for me ? thanks a lot
@lordseidon9
@lordseidon9 Жыл бұрын
@@nguyenucvinh-BDCCN No, not yet
@Champignon1000
@Champignon1000 3 жыл бұрын
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.
@nikosalexoudis8874
@nikosalexoudis8874 2 жыл бұрын
I do too get permision denied. I mean I could continue without it but it would be much better to be able to use stockfish. Did you have any luck from then?
@Champignon1000
@Champignon1000 2 жыл бұрын
@@nikosalexoudis8874 Im afraid not :(
@Muhammad-id6rt
@Muhammad-id6rt 3 ай бұрын
You play chess too ! My respect
@ponmuthu..4796
@ponmuthu..4796 5 ай бұрын
where can i find the dataset
@wojciechadamiec8167
@wojciechadamiec8167 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?
@cokechan1956
@cokechan1956 3 жыл бұрын
Very concise explanation, thanks
@FSstan
@FSstan 2 жыл бұрын
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?
@EK-rw9sw
@EK-rw9sw Жыл бұрын
i think the output layer is just size 1, to output the score given a board state. then you can use this evaluation inside a minimax algorithm or plug it into stockfish.
@askurmom3513
@askurmom3513 2 жыл бұрын
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?
@aesop1451
@aesop1451 Жыл бұрын
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?
@anto1756
@anto1756 Жыл бұрын
I'm doing something similar. I think it's the same code but you need to use your own dataset in npz format
@tornadoreaper
@tornadoreaper Жыл бұрын
fantastic
@wacimo16
@wacimo16 3 жыл бұрын
Very useful 👍
@subbox1
@subbox1 Жыл бұрын
Hi, I just wanted to clarify that in your code it states "h3->17" but it should be 12
@anto1756
@anto1756 Жыл бұрын
I can’t access the google colab file. Apparently it’s not available. Anyone else having the issue ?
@BPGHchess
@BPGHchess 11 ай бұрын
Yes
@sahildas.
@sahildas. 7 ай бұрын
yes
@beaverbuoy3011
@beaverbuoy3011 2 жыл бұрын
Great Video
@beaverbuoy3011
@beaverbuoy3011 Жыл бұрын
Wow
@Muhammad-id6rt
@Muhammad-id6rt 3 ай бұрын
I came from "the dark pursuer" game I want to know how to make a match with somebody else ?
@Lord_Liverpool
@Lord_Liverpool 2 жыл бұрын
I keep getting an error when I try to train the model.
@nikosalexoudis8874
@nikosalexoudis8874 2 жыл бұрын
Did you manage to fix it?
@Lord_Liverpool
@Lord_Liverpool 2 жыл бұрын
@@nikosalexoudis8874 Sorry no, I didn't have enough time to fix it and was forced to move on.
@ponmuthu..4796
@ponmuthu..4796 6 ай бұрын
hey do you have source code@@Lord_Liverpool
@dlep9221
@dlep9221 2 ай бұрын
Hi very interesting, are the links off ?
@trondamlie5853
@trondamlie5853 3 жыл бұрын
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)
@Philgob
@Philgob Жыл бұрын
i also don’t understand this part… how to create the dataset from the random_board() and stockfish() functions
@jorgeguzmanjmga
@jorgeguzmanjmga Жыл бұрын
Which could be the difference if we use reinforcement learning? How can we use that method with the same libraries?
@HarshKaushik-wv2do
@HarshKaushik-wv2do 2 ай бұрын
I think the difference would be that this model isnt able to think much in future(higher depth) but deep reinforcement learning one would be able to
@topasta7411
@topasta7411 2 жыл бұрын
why do i get "No such file or directory: '/content/stockfish': '/content/stockfish'" when i try to "print(stockfish(board, 10))"?
@MrKoszmaro
@MrKoszmaro 2 жыл бұрын
if you are working with a copy of the colaboratory then you need to import stockfish and the dataset yourself
@topasta7411
@topasta7411 2 жыл бұрын
@@MrKoszmaro ty
@WoodyDataAI
@WoodyDataAI 2 жыл бұрын
@@MrKoszmaro Author gives dataset link, but no stockfish link, where is the stockfish?
@CooperNicolaysen
@CooperNicolaysen 2 жыл бұрын
I keep getting a graph execution error after using model.fit(x_train, y_train)
@Lord_Liverpool
@Lord_Liverpool 2 жыл бұрын
I got the exact same error, did you manage to fix it?
@CooperNicolaysen
@CooperNicolaysen 2 жыл бұрын
@@Lord_Liverpool Yes. If you’re using newer versions of all these APIs, then the dimensions are in different spaces. So remove the data_format= whatever part of the code where you write 14,8,8,8.
@Lord_Liverpool
@Lord_Liverpool 2 жыл бұрын
@@CooperNicolaysen Thanks for the fast reply. OK, great I will investigate your advice, thanks very much!
@CooperNicolaysen
@CooperNicolaysen 2 жыл бұрын
@@Lord_Liverpool If you don’t end up getting it, i’ll send you a copy of my working code.
@Lord_Liverpool
@Lord_Liverpool 2 жыл бұрын
​@@CooperNicolaysen KZbin won't let me post a comment containing my address. If you click my name and go to the about section of my channel there's a button to reveal my address. Thank you very much for your help, I'm very grateful.
@davidnguyen6724
@davidnguyen6724 4 ай бұрын
the files are deleted bro plz update it
@RaushanBharadwaj
@RaushanBharadwaj 5 ай бұрын
Can you send me the link of dataset
@midasscheffers7610
@midasscheffers7610 3 жыл бұрын
How did you use stockfish in your program, im trying to make a chass bot aswell but that part I can't figure out
@trondamlie5853
@trondamlie5853 3 жыл бұрын
Just duwnload stockfish from their site and unpack it to your python-folder... and the code works... (using relative path)
@WoodyDataAI
@WoodyDataAI 2 жыл бұрын
@@trondamlie5853 can you give me the site for stockfish? thanks
@theterror2895
@theterror2895 4 жыл бұрын
Good!
@nikhilmarepally9341
@nikhilmarepally9341 2 жыл бұрын
Could you upload the whole code, I see you implemented 'principla variation search' and encoding could you upload that ?
@walney2008
@walney2008 Жыл бұрын
links off, download please, convert png images in FEN ?
@shivmu1642
@shivmu1642 3 жыл бұрын
where did you get the dataset from?
@shaynegoldstein1329
@shaynegoldstein1329 3 жыл бұрын
its in the description
@iuexwo
@iuexwo Жыл бұрын
I like your horror gamem❤
@JohnDuthie
@JohnDuthie Жыл бұрын
Can ChatGPT write this for me?
@forge8807
@forge8807 4 ай бұрын
You should try learning it yourself, its significantly more rewarding than just using an ai that clearly cant do it
@theterrorconsumes9021
@theterrorconsumes9021 4 жыл бұрын
this video was interesting! (;
@protibadimon4169
@protibadimon4169 2 жыл бұрын
I need help can you help me? I need chess developer
@lordseidon9
@lordseidon9 Жыл бұрын
Do you still need now?
@rotrot.graddiv.-.3766
@rotrot.graddiv.-.3766 Жыл бұрын
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.
@TayyabTV
@TayyabTV Жыл бұрын
the gains in C/C++ would be marginal imo, you would have to improve the algorithm as a whole to get better computation.
@rotrot.graddiv.-.3766
@rotrot.graddiv.-.3766 Жыл бұрын
@@TayyabTV Well I don't think it is ! Python is much much slower than a compiled language. And when I mean slower, it can do from 10 to 100 times slower in some cases. One of other the reasons for that is that on a C/C++ program you can use multiple cores of your CPU while on a Python program you are limited to only one core. Let's pretend that you have 12 cores (the standard for nowdays CPUs), not even considering the execution, you have access to 12 times less power ! And believe me even on a single core this is not even close. C is just way faster. But for the AI thing however you are totaly right since TensorFlow is built on C++ such as most of the Python libraries. In fact Python is initialy meant to make the link between performant libraries by an easy way. Python is slow but the libraries are fast. This is part of the reasons why Numpy is so popular even to just create lists. As a good developper, you have to use the right tools depending on the problem you are facing. You wanna make a quick script that doesn't require much performances ? Python is probably one of the best options ! You wanna build a performant program that does an enormous amount of operations ? You have to use a compiled language, mostly C/C++ or any C-built on language.
@machamemes3766
@machamemes3766 3 жыл бұрын
Algum br
Coding Adventure: Chess
29:22
Sebastian Lague
Рет қаралды 3,8 МЛН
ML Was Hard Until I Learned These 5 Secrets!
13:11
Boris Meinardus
Рет қаралды 304 М.
когда не обедаешь в школе // EVA mash
00:57
EVA mash
Рет қаралды 1,2 МЛН
Nastya and balloon challenge
00:23
Nastya
Рет қаралды 60 МЛН
Training AI to Play Pokemon with Reinforcement Learning
33:53
Peter Whidden
Рет қаралды 7 МЛН
Google's self-learning AI AlphaZero masters chess in 4 hours
18:10
ChessNetwork
Рет қаралды 1,5 МЛН
AI Learns Insane Monopoly Strategies
11:30
b2studios
Рет қаралды 10 МЛН
I Built a Neural Network from Scratch
9:15
Green Code
Рет қаралды 300 М.
Why Does Diffusion Work Better than Auto-Regression?
20:18
Algorithmic Simplicity
Рет қаралды 320 М.
The rarest move in chess
17:01
Paralogical
Рет қаралды 1,8 МЛН
Training an unbeatable AI in Trackmania
20:41
Yosh
Рет қаралды 14 МЛН
How to Create a Chess Engine with TensorFlow (Python)
14:59
Nick Tech
Рет қаралды 4,8 М.
Simulating the Evolution of Rock, Paper, Scissors
15:00
Primer
Рет қаралды 1,7 МЛН