Live data from Hacker News

Deep Learning in JavaScript

github.com

51–60 of 92 posts

Re: Deep Learning in JavaScript

#51

Someone needs to do a TypeScript compiler plugin to add multidimensional array slicing and operator overloading to the language, so these libraries can actually work the way PyTorch does. I know operator overloading is controversial, but the way it allows automatic differentiation to work transparently through regular arithmetic expressions is very helpful. Without it these libraries will never feel like PyTorch. Jav…

What's wrong with creating a function that does those things? It would be less surprising to people new to the library, would be self-documenting by having a name and an easily inspected declaration with named arguments, and it would be idiomatic JS. You could also have variants that are purely functional and return a new value or ones that mutate in place that you could use depending on your needs.

In python when I try a new gpu accelerated array library, to write norm_arr = arr / lib.sqrt( lib.sum( arr*2, axis=-1, keepdims=True) , I have to read documentation for sum to see whther they use axis or dim in sum.

In javascript, to write the same thing I need to read documentation for a sum function, a broadcasted division function, a multiply function. I can probably assume that the sqrt function behaves and is named as I would expect

Re: Deep Learning in JavaScript

#52
post #6

Very very cool to see!!! So yours is SO MUCH MORE fleshed out than mine, but I have a similar (again very fledgling) one going here that uses Typescript: https://github.com/Marviel/lab-grad I think there are some really neat opportunities to increase the approachability of ML algorithms when you take advantage of the Typescript templating system to explicitly ensure you're not accidentally composing tensors of incorr…

Thanks for the tip! I will look into your project, for sure! I am still a beginner on Typescript, but when I get the hang of it, I think I might refactor my package to Typescript. Again, thanks for the tip!

Typescript is something you learn progressively over years, and from what others have posted it might not be possible to refactor your package in Typescript (some approaches to problems that are possible in JS aren't supported by TS). But type declarations at the very least should be possible

Re: Deep Learning in JavaScript

#53

Earlier quoted context omitted.

What's wrong with creating a function that does those things? It would be less surprising to people new to the library, would be self-documenting by having a name and an easily inspected declaration with named arguments, and it would be idiomatic JS. You could also have variants that are purely functional and return a new value or ones that mutate in place that you could use depending on your needs.

In python when I try a new gpu accelerated array library, to write norm_arr = arr / lib.sqrt( lib.sum( arr*2, axis=-1, keepdims=True) , I have to read documentation for sum to see whther they use axis or dim in sum. In javascript, to write the same thing I need to read documentation for a sum function, a broadcasted division function, a multiply function. I can probably assume that the sqrt function behaves and is na…

Why can you make assumptions about operation overloads but not functions?

Re: Deep Learning in JavaScript

#54

Earlier quoted context omitted.

You might already be familiar, but a GPU.js backend can provide some speedups via good old WebGL -- no need for WebGPU just yet! [0]: https://github.com/gpujs/gpu.js/

Thanks for the tip! I’ll definitely take a look. Adding GPU support is my next step!

Not a problem, I've benchmarked some GPU backed js libraries here:

[0]: https://observablehq.com/@dleeftink/ultimate-compute-show-do...

Re: Deep Learning in JavaScript

#55

Someone needs to do a TypeScript compiler plugin to add multidimensional array slicing and operator overloading to the language, so these libraries can actually work the way PyTorch does. I know operator overloading is controversial, but the way it allows automatic differentiation to work transparently through regular arithmetic expressions is very helpful. Without it these libraries will never feel like PyTorch. Jav…

Would JS be faster than Python when it comes to Pytorch? For example, I seriously doubt that would be the case for Numpy, since it's a wrapper for C code, with the ability to use Fortran libraries for optimization.

Re: Deep Learning in JavaScript

#56

Earlier quoted context omitted.

Thanks for the tip! I’ll definitely take a look. Adding GPU support is my next step!

Not a problem, I've benchmarked some GPU backed js libraries here: [0]: https://observablehq.com/@dleeftink/ultimate-compute-show-do...

Thank you! That’s going to help out a lot!

Re: Deep Learning in JavaScript

#57
post #49

Earlier quoted context omitted.

You might already be familiar, but a GPU.js backend can provide some speedups via good old WebGL -- no need for WebGPU just yet! [0]: https://github.com/gpujs/gpu.js/

FWIW also taichi is quite popular in python and seems has some javascript related implementation (I haven't used it though), taichi.js [0] [0] https://github.com/AmesingFlank/taichi.js

Cool! Will take a look

Re: Deep Learning in JavaScript

#58

Cool project! I worked on something similar a while ago to learn about automatic differentiation: https://github.com/hexhowells/onegrad.js Needs more layers to be really useful though. I always thought examples using browser extensions would be neat since their built in JS and you only need to download the model once.

Really cool implementation. Thanks for the feedback as well!

Re: Deep Learning in JavaScript

#59

Earlier quoted context omitted.

Thanks for the tip! I will look into your project, for sure! I am still a beginner on Typescript, but when I get the hang of it, I think I might refactor my package to Typescript. Again, thanks for the tip!

Typescript is something you learn progressively over years, and from what others have posted it might not be possible to refactor your package in Typescript (some approaches to problems that are possible in JS aren't supported by TS). But type declarations at the very least should be possible

Fair enough, I’m currently studying what would be the best option, but I think you are right!

Re: Deep Learning in JavaScript

#60

Wow! Thank you for doing this. It looks like a great starting point for anyone approaching deep learning from the JS ecosystem. It is very plainly written and looks like it will be a joy to learn from. Thank you for adding JSDoc comments with type hints! Are you open to pull requests? If I have the time I'd love to contribute. I'm sure others would as well. You should write up a short article on this, even something…

Thank you so much for the feedback! I’m open to pull requests, absolutely. And about the article, that’s a great tip, I’ll definitely do that as well.
Post reply on HN