yet another NN library

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

yet another NN library

Post by lucasart »

I wrote a simple NN library, if anyone is interested in developping their own trainer. https://github.com/lucasart/nn
Simple code, documented, tested, easily extensible. Happy coding!

What it does:
  • Create network (fully connected MLP) with arbitrary dimensions and activation functions (linear, relu, sigmoid; trivial to add new ones).
  • Flexible functions to print network, or individual layers (for debugging or experimenting).
  • Load/Save network from/to binary file.
  • Feed forward.
  • Backpropagation (computes deltas given (input,output) example). Choice of absolute |x-y| or squared (x-y)^2 objective function (absolute probably makes more sense for chess).
  • Gradient (deduce gradient from deltas).
Computing the gradient for an example is really the fundamental building block. After that, you can calculate a more robust gradient estimation by averaging many samples (aka. batch or mini-batch). Follow constant * gradient steps (aka. SGD). And experiment with more advanced gradient descent methods. An excellent article on the topic https://ruder.io/optimizing-gradient-descent/.

Of course, you also need to some data (positions, eval, game result). Conviniently, https://github.com/lucasart/c-chess-cli can generate it with any UCI engine.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Re: yet another NN library

Post by Desperado »

lucasart wrote: Sun Apr 11, 2021 1:45 pm I wrote a simple NN library, if anyone is interested in developping their own trainer. https://github.com/lucasart/nn
Simple code, documented, tested, easily extensible. Happy coding!

What it does:
  • Create network (fully connected MLP) with arbitrary dimensions and activation functions (linear, relu, sigmoid; trivial to add new ones).
  • Flexible functions to print network, or individual layers (for debugging or experimenting).
  • Load/Save network from/to binary file.
  • Feed forward.
  • Backpropagation (computes deltas given (input,output) example). Choice of absolute |x-y| or squared (x-y)^2 objective function (absolute probably makes more sense for chess).
  • Gradient (deduce gradient from deltas).
Computing the gradient for an example is really the fundamental building block. After that, you can calculate a more robust gradient estimation by averaging many samples (aka. batch or mini-batch). Follow constant * gradient steps (aka. SGD). And experiment with more advanced gradient descent methods. An excellent article on the topic https://ruder.io/optimizing-gradient-descent/.

Of course, you also need to some data (positions, eval, game result). Conviniently, https://github.com/lucasart/c-chess-cli can generate it with any UCI engine.
Thanks!, for this and all the other contributions to chess programming.
niel5946
Posts: 174
Joined: Thu Nov 26, 2020 10:06 am
Full name: Niels Abildskov

Re: yet another NN library

Post by niel5946 »

lucasart wrote: Sun Apr 11, 2021 1:45 pm I wrote a simple NN library, if anyone is interested in developping their own trainer. https://github.com/lucasart/nn
Simple code, documented, tested, easily extensible. Happy coding!

What it does:
  • Create network (fully connected MLP) with arbitrary dimensions and activation functions (linear, relu, sigmoid; trivial to add new ones).
  • Flexible functions to print network, or individual layers (for debugging or experimenting).
  • Load/Save network from/to binary file.
  • Feed forward.
  • Backpropagation (computes deltas given (input,output) example). Choice of absolute |x-y| or squared (x-y)^2 objective function (absolute probably makes more sense for chess).
  • Gradient (deduce gradient from deltas).
Computing the gradient for an example is really the fundamental building block. After that, you can calculate a more robust gradient estimation by averaging many samples (aka. batch or mini-batch). Follow constant * gradient steps (aka. SGD). And experiment with more advanced gradient descent methods. An excellent article on the topic https://ruder.io/optimizing-gradient-descent/.

Of course, you also need to some data (positions, eval, game result). Conviniently, https://github.com/lucasart/c-chess-cli can generate it with any UCI engine.
It sounds interesting! I'll take a look at it some time.

I actually began working on something similar a couple of weeks ago, but I got stuck :( . I know the math required to train and use neural networks, but since I am a first-timer when it comes to actually creating such libraries, I struggle with the implementation.
My repository is private at the moment since the code is such a mess that it probably shouldn't see daylight anytime soon haha :D

Have you tried using the library to train an evaluation function yet? If so, how was the strength results?
Author of Loki, a C++ work in progress.
Code | Releases | Progress Log |