 All right, let's give it up for Abro. So hi, my name is Abro. So a little bit about me. I'm going to be a senior in high school when the summer ends. And I go to high school in San Jose, California. Yeah, that's my github and my Twitter in case you guys want to know. Okay, so I've been interested in chess for a long time. And I really wanted to create a chess engine. And since I knew Python, I figured, you know, why not? So there are a couple of ways to do this. First of all, you can theoretically brute force chess. So like just calculate every single move and every single position on the board until victory. But I hear some of you guys laughing. Yeah, there's like 10 to the power of 43 moves out there. So you're going to have a bad time with that. So conventional chess engines, therefore, they kind of quote unquote hard-coded. In terms of like a lot of there's, when a chess engine looks at a position, it'll look for certain tells like double ponds, king safety, or things like that in order to determine if the position is beneficial or harmful to a certain side. And so the problem with this, though, is that if you like strategies evolve and obviously different people have different ideas of what means what. And so this becomes really hard to maintain now because you have to keep changing this code in order to look for different tells on board in order to look for different signs of how a position is. And on top of that, these two don't work particularly well on Python because Python isn't the best language out there. So you'll see most chess engines nowadays do C++. So yeah, I'm not learning C++. So I figured, you know, why not use machine learning? So let's back up a bit. So essentially at a core chess engine is a function that converts a position into a move. So in order, the way it does that is it looks at all the possible moves a player can play and then it selects what it thinks is the best move and chooses that. But there's a problem and let me show you what I mean. So first of all, the way it does that is it uses something called an evaluation function. An evaluation function looks at the board and determines how good that position is for a certain player. So then chess engine can look at all the positions that will result from someone playing a move and then look at which is the best one and play that move. So the very simplest one is using piece weight. So I don't know if you guys know, but like a pawn is worth the 1, knight is worth 3, bishop 3.5, so on. And you can add your pieces and subtract your opponent's pieces and get like a net value of how good a position is for you. But let's play a game for a while. Okay, so imagine that it's me versus all you guys. So you guys are trying to get the highest number and I'm trying to get the lowest number out there. And how this works is I start at 1 and then I either go left or right to level, I start at level 0 and I go left or right to level 1. And after that you guys go left or right to level 2 and then I go left or right to level 3 and so on and so forth. So I'm trying to reach the lowest, you're trying to reach the highest. So initially it might look like the best position to play is go towards that negative 10 right there because that's a lower number than negative 7. But then if you look even further you'll see that that doesn't lead to any good results because on that side of the tree all the numbers are higher than on the other side. So if you are smart you go to the other side of negative 7 because even though it looks like that position is worse, if you look further down the line you'll see that that position is actually better. So that's the, it's something really really similar in chess because chess works in a similar way. So in order to accomplish the same feat we have an algorithm called minimax. So minimax, this is a code example, but minimax essentially recursively goes through the move tree and looks farther, a couple moves ahead and then decides like, hey is this position, which is the best position for me? Assuming my opponent plays well. So this is like, I'm not going to explain that code word line for line, but yeah that's the code if you want to like see it. Okay so back to evaluation functions, right? Because minimax still needs an evaluation function, right? Because you still have to evaluate the board even if it's 10 positions in the future. So the problem is again, as I mentioned earlier, a lot of us like handcrafted because chess didn't look for certain tells of what's a good or bad position. And that's sort of a hard coded way to do it. And as well as that you need like chess experts on your side in order to determine those tells. So if you're a normal programmer like it's kind of hard to do that. So enter TensorFlow, Google's library for deep learning. And TensorFlow is obviously a very amazing library because you can do deep learning really easily in it and it's also pretty fast. So basically I built a neural network and this is like a basic description about what it does, but essentially it'll take an input, in this case the board, and feed it through a series of layers which consist of neurons which kind of fire depending on what the input is. So then the output will be like if the position is good for you or good for the opponent. And now a neural network, essentially it requires a lot of data. You have to like give it a bunch of data of position that are good for you, good for the opponent. And then it'll tweak itself in order to match that and create a sort of a model. So yeah, to basically solve the problem. So training data. Obviously I mentioned you need a lot of training data. Luckily chess training data is really, really easy to get. So there's a file from that called PGN which let me just show you an example of. This is like a very basic example of a PGN. Oh wait, oops. Okay, whatever. Let me do this there. Can you see that now? Wait, okay, whatever. So essentially what a PGN is is, so essentially what I wanted to show you guys is that a PGN is essentially a text file. And it contains all the moves written in algebraic notation one by one. So like E4, E5, and so on and so forth for a bunch of different games. So the nice thing is since it's a text file we can open it in Python and really easily convert it into like a move that the computer knows and then feed that. So how I fed it in was I assumed that because I got like a game from a bunch of grandmasters they're gonna play right moves. So after the grandmaster, like after somebody moves I'm assuming that that position that that results in is better for that player. So like if white moves then I'm gonna assume that that position is better for white and then if black moves then I'm gonna assume that that position is better for black and so on and so forth. There are exceptions like I look for extreme material deficits meaning if somebody's obviously doing worse depending on material I'm not gonna count it for better just because that player moved. So that results in like a really, really big training set that I can use which is really nice. So here to get into a bit more detail these are the features and labels. So the input is an 8x8 array representing the chess board and I'm storing the pieces as their words. So like a rook will be stored as the number 5 a white rook and a black rook will be stored as negative 5 and a white pawn will be stored as 1 say and a black pawn will be stored as negative 1. So essentially what that means now is that like I have an 8x8 array of a bunch, mostly 0s because most of the position on chess board are unoccupied but with a few negative numbers and positive numbers and then the output will be a one hot vector meaning like a vector in which either the consisting of two elements in which either the first one is one or the second one is one. So if the first one is one then that means it's black. If the second one is one it means white as you can see up there. So like 0 1 is white and 1 0 is black. So that's the output of my whole neural network. So now I have to construct a neural network that converts that to that. So I decided to use a convolutional neural network because a chess board in some ways is a lot like an image. So convolutional neural networks do really well with analyzing images and what they do is they kind of look at different parts of the image and run convolutions on them and like kind of simplify them to look for distinct features that can be used to determine whatever is trying to determine. So specifically my neural network consisted of two convolutional layers and one fully connected layer which is just a normal standard layer in a neural network. So here's kind of the graph of it. It looks a lot prettier. So you can see that there's con 1, con 2 and then the fully connected layer as well as some other things that I generated this using tensorboard. So yeah, here's the code. I wanted to show a snippet of it. So I also use dropout and what dropout does is it tries to prevent overfitting of the model so it'll like randomly drop some neurons in order to make the thing a little more randomized so that way the model will try to fit to, will kind of generalize the situation and try to fit to what's important and not look at little bit of like the noise in every model because there's going to be a certain amount of noise and you don't want to fit to that noise. You want to fit to the essential relationship. So dropout kind of helps with that issue. Okay, so a couple of future improvements I'm going to make is number one, like right now, the thing is pretty slow which I want to show demo. I don't know if I'm going to get that to work. But basically, so I want to make it faster and hopefully I'm going to write some things in Cython later because Python is still slow with some of the computational stuff and I also want more training data. So the issue is like right now, I'm not using that much data in a PGN so like you know there's loads and loads of chess data out there so I have to like curate each one and make sure it's like actually like good games and there's a wide variety. And I also want to build features to let the chess engine play itself. So the problem with playing chess engine and playing itself initially is that it can get if it doesn't know anything initially, it can't do much. So I want to kind of get it off on a good footing with data that already exists and then have it train itself from there. Okay, yeah, that worked. So I want to show the demo. I'm not sure how to exactly. Let's try this. Oh, here it is. Okay, awesome. Okay. How do I... Let me see if I can mirror this. Oh, here. There. That's better. Okay. Now I can show you guys what I wanted to show you guys. Okay. So here's what a PGN looks like. So as you can see, it's just a bunch of like moves written in algebraic notation with some metadata with like some ones and two tunes first. So kind of have to parse this out and get rid of all the numbers and the metadata and like just purely feed the moves into the engine. So now I want to show you guys a demo. So here it is like running right here. So like if I... I don't know what move do you guys want to play? Which one? Queen. Queen? Queen pawn, D4. Okay. Take a while. Okay. So I decided that was the best move, probably because everything is like the same like initially. E4? Okay. Yeah, yeah. But the issue right now is the fact that to it since the data is not like... it's having a hard time with openings as you can see obviously with this current moves because with openings it's harder to tell whether position is good for you or good for the opponent because there's less material loss. Like for instance you wouldn't want to move an edge pawn like that like if you were a human usually but you know the computer it's all the same because you're not losing anything by doing that. For two or more moves. Yeah, exactly. Exactly, that's the thing. It still looks good like a couple moves down the road. Now if I were to play like B4 then it would probably capture it. Let's see. No. Not yet. Yeah, got it. So yeah, that works. And like if I were to play C3 I think it would still capture it but let's see. Yeah, I did. So yeah, I guess it's very aggressive. So you guys have any questions? Yeah. So first of all, thanks a lot. This is really cool stuff. When you said high school you meant grad school, right? No, I actually meant high school. Second question. Can it beat you creation and is it defeating its master yet? So I haven't actually played a game. I probably should but the thing is me now is a lot worse than like me before because I used to play chess a lot in middle school like competitively but now I just code I guess I don't. Third question. Machine learning. Like in chess it solves chess but like in the problems that we face like where are the limits for machine learning? So he's asking where the limits to machine learning? For me personally I think it's the fact that machine learning right now it still like requires a lot of effort meaning you still have to go get a bunch of data curated by hand most of the times and like still mess around with the model like for instance I had a model that legitimately was not working and I had to mess around with it and realize that the learning rate wasn't going to do it. So things like that right? I mean you're not going to make you know SkyNet happen if the learning rate isn't right right? Yeah exactly. So it still requires a lot of like human and manual effort so I would like to see in the future machine learning become smarter and more able to tune itself and more able to not maybe not select its own data but like better at getting data. So that's kind of where I would like to see it go. So that's the current limits yeah. Any more questions? Yeah. Can you get like the chess engine playing itself and beat that? Oh yeah. So you would have to make it much better that way? Yeah. So yeah it's theoretically possible. I'm probably going to try to tackle it next. So the thing is like obviously you need it to be a little good before doing that. So but yeah it is definitely possible which I'm probably going to tackle next. Any more questions? That one in the back I think. If you tried to compare this approach to old school kind of mini-max how far ahead do you think your approach thinks? Can you follow me? Yeah. So he's asking how far ahead my approach would reach compared to traditional chess engines I think? Yeah. So traditional ones would obviously beat mine right now because they're you know written in like C++ they're written in like extremely handcrafted code and whatnot but like this has the potential to do a lot better because it you know it's machine learning but as of so I do think it has the potential to beat any chess engine but as of right now obviously not. Any other questions? Oh yeah that one right there. So you're asking if, sorry what? Self training. Yeah okay. So can it update its own database that way you're asking? Oh okay. That would be interesting you'd have to write rules for that. Probably something along the lines of if I lose added to my database but there's obviously a lot of trouble with that too because some moves might still be bad. So that would be an interesting problem to tackle but as of now the database is pretty constant. Any other questions? Oh okay one over there. Oh so it does have some like in one I remember playing it and I tried to get it into a fork and it got out of that. Even though like the way I was playing like if you had taken a pawn say it would have been a fork but it didn't choose to do that. So it can do basic things because like it could look ahead and see that hey it's queen and Rook is going to get forked and that's bad news. So it can do basic things like that but as far as like sacrifices and stuff I'm not quite sure because there's some pretty advanced like queen sacks out there and stuff that you know you don't see coming in so yeah it can handle some basic strategy but I don't know about that. Theoretically there's no limit. Yeah theoretically I guess there's none. Oh yeah so I had actually some problem with that but what I basically did was I had two cases. Either if the material deficit was high then I kind of knew who to give it to like better for white or better for black meaning if white had way more pieces than black it was obviously better and if black had way more pieces than white it was obviously better but in terms of things in the middle since the grandmaster games if it's even then I chose to give it to whoever last moved because I assumed they're going to you know they're planning something tactical and they're in a good place so I'd like if white had just moved I'd give it to white even if it's even if black had just moved I'd give it to black so this approach kind of worked but it kind of didn't also so I guess the only real way to do it would be like to go by hand and decide yourself again going back to one of the limits I've discussed and where I see like machine learning has anyone else? I have a question I'm sorry okay