Javascript Neural Networks

There are tons of neural network implementations out there, but not many in JavaScript. This is pretty surprising given that JavaScript is awesome and neural networks could really benefit from being in the browser. One partial implementation was used to do some sweet Captcha OCR, and my last post was about using them to determine whether to display black or white text over a given background color.

I ended up creating brain, the missing JavaScript neural network library. I tried to make it easy to use. To use it you don’t have to know what a hidden layer is (but you can specify hidden layers if you want), you can also specify input (and expected output, for training) as hashes instead of arrays – good for sparse or labelled input, and you can pass trained networks around in JSON, which is useful with Worker threads.

If you want to find out more using neural networks from a programmatic perspective, this is a good introduction that just popped up.


Black or White Text? WCAG vs. Neural Networks

The other day I ran into a problem that some developers of color tools probably run into, which is: given a color, do you display white or black text over it? An algorithm based on the WCAG luminosity contrast ratio measure works great on most colors, but can be spotty. After looking at the WCAG formula, it seemed this problem was a good candidate for neural networks.

A couple weeks ago I finally sat down to try out the idea, and made a page where you can train your own neural network when to use black vs. white text (bonus: Worker thread example). After training it on a dozen or so colors, it matches the WCAG algorithm in most cases and does better in others. It’s kind of crazy that you can just throw data at this network and it will learn it. Not every problem can be solved by a neural network, but it’s cool to see it work when the problem fits. Might try out some other classifiers next.

I ended up making a simple JavaScript neural network implementation, you can check out the code on github.


Follow

Get every new post delivered to your Inbox.

Join 29 other followers