Neural Networks in JavaScript
blog.webkid.io
blog.webkid.io
> Within the last years, multiple Javascript frameworks were developed that can help you to create, train and use Neural Networks for different purposes.
Due to the popular discourse on how 'unsuitable' JS is for anything but front-end development°, does anybody have any insight on how the efficiency of JS neural net libraries compares to that of the classic Python et al. tools? I've been trying to get started in neural nets for a while now, but am curious as to if learning it via JS will be a limiting factor that I will ultimately have to switch to a more efficient/suited platform.
° Something that I do not agree with myself, as a Node.js and back-end JS developer
> Something that I do not agree with myself, as a Node.js and back-end JS developer
NodeJS mostly works when CPU time is not the limiting factor, that is, powering the Web. Neural network is the polar opposite.
It sounds like what you actually mean here is that Python is equally as unsuitable and must instead use native binaries. Which one could just as easily do with JS...
A reasonable argument could be that such native binaries are available in the Python community and already in use as stable existing solutions, but that's more about ecosystem than language suitability.
Additionally, while I'm not too sure what convnet, node-mind, brain.js, etc. referenced in the article are using internally, there are gpu-oriented solutions being written in JS like https://www.npmjs.com/package/weblas
Later on, when the speed is not so critical, you can do inference with those pretrained weights and your model implemented in Javascript.
But I don't know how well you can talk to the GPU
This is one of the reasons I was hoping WebCL[1] (now dead[2]) would take off. It would have enabled GPGPU work that is pretty much a prerequisite for anything that would be taken seriously by the community.
There was talk of ARB_compute_shader support as mentioned in the second ref link, but I haven't seen anything else in that area.
Does that mean that using an already trained model would be slow? If I wrote something to train a model on a GPU, could I then export the data to use with JS in a browser?
What JS really needs is WebCL. That will revolutionize JS capabilities.
Eample:
A page declares that it will use library foo, e.g. <lib name="foo" version="^1.0"/>. Browser, e.g. firefox, looks into common repository and sees that there is two versions of "foo": one generic, and one optimized for firefox-x86_64, with native code, so it used optimized version instead.
Of course, code must come from trusted source and be signed, to reduce risks.
However there is some possibility that technologies like WebCL and replacements will overcome this limitation by allowing access to GPU resources. Further reading: [1][2][3]
[1] https://github.com/waylonflinn/weblas
[2] https://github.com/karpathy/convnetjs/issues/13
It worked well for us because we had to stream the data into the network for training, --all the training data did not fit into RAM on Heroku's 1G dyno. Node.js does this IO transfer really well. (Full disclosure, I wrote the streaming implementation for brain.js.)
Also, training artificial neural networks is a serial computation for the most part. (Lots of sigmas). There are parallel optimizations you can make but probably won't see the benefits (in terms of training speed) until you have high dimensional data. Doing this sort of thing on a GPU is also orders of magnitude faster.
One thing to note however, if you plan on serving a high number predictions from trained models in Javascript, you will see blocking because each prediction does require a small bit of computation and Javascript / Node.js is single threaded.