DEV Community

Cover image for Deep Learning in Javascript

Deep Learning in Javascript

Eduardo Opice Leao on April 01, 2024

JS-PyTorch is a Deep Learning JavaScript library built from scratch, to closely follow PyTorch's syntax. Feel free to try out a Web Demo!   ...
Collapse
 
alxwnth profile image
Alex

Okay, but why?

Collapse
 
lnahrf profile image
Lev N.

It is much easier to deploy Javascript than Python these days (Unless you want to manage your servers). Javascript is superior to Python when it comes to the project’s isolation, environment and management (it is straight forward while Python is a hot mess). Almost all developers know some Javascript, therefore I raise you the opposite question:
Why not?

Collapse
 
alxwnth profile image
Alex • Edited

Just because something CAN be done doesn’t mean it HAS to be done.

It is much easier to deploy Javascript than Python these days (Unless you want to manage your servers)

It’s not. You have anything at your disposal from EC2 to Google Colab to providers that specialize at machine learning. No management of “your” servers required. Ever Vercel has a Python runtime

Javascript is superior to Python when it comes to the project’s isolation, environment and management

It’s not. Saying that it’s “superior” just shows that you either don’t know or don’t care enough to do even basic research. I’ll just say that venv is a thing.

Almost all developers know some Javascript

This is simply hilarious. First, knowing “some JavaScript” has nothing to do with studying machine learning. Second, if you can’t stomach learning a teeny tiny bit of Python syntax, how are you going to study everything else that comes with machine learning?

A few more points:

  • PyTorch is under active development and has an active community, which contributes optimizations, improvements, and fixes.
  • Is it possible to run JS code in Jupyter notebooks? Yes, with Deno. But you’ll have to learn how Deno works first which negates the point.
  • Is it possible to run JS code in Colab? Yes, with some weird hacks, which negates the point even more.
  • Stepping aside from PyTorch, what about the larger ecosystem of libraries? Are you going to wait for them to be ported to JS too? Or, perhaps, you want to port them yourself?
Thread Thread
 
lnahrf profile image
Lev N. • Edited

Well, that is just like, your opinion man (Haha).
Languages are tools, JS is more approachable than Python and has many other advantages over it (In my opinion). I did code in Python (using Venvs mind you) professionally for a while, JS is still much simpler to handle. I can't see why we should not use JS for ML.

Edit: Also, what does Jupyter Notebook have anything to do with? As I said, languages are nothing but tools, some tools are good for some tasks. You wouldn't want to fry an egg using a sledgehammer, right? If a language offers advantages (such as ease of access, popularity, etc) for a given task over a different language, it is worth considering. I advise you not to be so attached to the languages you code with, there is no reason to.

Thread Thread
 
eduardoleao052 profile image
Eduardo Opice Leao

That’s very close to what I’d say: JavaScript can be used more easily for some applications, and while Python will likely remain the most used ML language, there’s a benefit to being able to write PyTorch-like code in native JS. Especially for simpler web demos and educational content.

Collapse
 
eduardoleao052 profile image
Eduardo Opice Leao

There are a couple of reasons why I started the project:

  • Web integration: it’s a lot easier to build demos, web apps and interfaces using simple AI if you can write PyTorch-like code directly in JavaScript.
  • Access: many programmers know JavaScript and are interested in AI. This library could be a good way to start experimenting with machine learning models and applications.
Collapse
 
ajborla profile image
Anthony J. Borla

This library could be a good way to start experimenting with machine learning models and applications.

Indeed !

I have not had the time to evaluate your library, but I applaud your efforts in implementing it. Well done !

Thread Thread
 
eduardoleao052 profile image
Eduardo Opice Leao

Thank you for the support! If you try it out and have any questions or tips, let me know!

Collapse
 
mince profile image
Mince

To further ruin our lives and computers with js

Collapse
 
mince profile image
Mince

just a legit joke

Thread Thread
 
mince profile image
Mince

Wow, I got more like to my comment than my post 🙃

Collapse
 
miketalbot profile image
Mike Talbot ⭐

Great stuff, I've been keen to add some deep learning to our code stack and would prefer not to litter the source code with multiple languages. This looks to be a great start. I am worried that it will take a lot to maintain though.

Collapse
 
eduardoleao052 profile image
Eduardo Opice Leao

Thanks for the feedback! I'm currently working really hard to make it as easy-to-use and easy-to-mantain as possible, with Developer Tools, solid documentation, unit tests and all of that. Hope it'll help you with your needs :D

Collapse
 
miketalbot profile image
Mike Talbot ⭐

Yeah, I meant hard to maintain for you too... Extra modules, keeping up to date with something else etc.

Thread Thread
 
eduardoleao052 profile image
Eduardo Opice Leao

That’s true! But having good testing and tools can help with that too.
However, that’s a good thing to keep in mind, you’re right

Collapse
 
serantu profile image
Serantu

Really cool library! I’d love to see an integration with GPU.js

Collapse
 
valadares profile image
Edson Silva

Hey, I’m not really an expert on this, it GPU.js similar to WebGPU?

Collapse
 
serantu profile image
Serantu

From what I understand about WebGPU, it provides an interface and browser support for GPU usage. GPU.js offers a back-end library to run matrix multiplications on GPU.

Thread Thread
 
valadares profile image
Edson Silva

Got it. Thanks for the reply!

Collapse
 
eduardoleao052 profile image
Eduardo Opice Leao

Thanks for the feedback! Working on it.

Collapse
 
serantu profile image
Serantu

Cool! Are you open to pull requests at all on your GitHub? I’d love to get involved

Thread Thread
 
eduardoleao052 profile image
Eduardo Opice Leao

Absolutely, any help is welcome :D

Collapse
 
eshimischi profile image
eshimischi • Edited

Deep Learning is very much about Python. Period. No need to bring everything to JS, just inappropriate and it doesn’t have any real advantages over it.

Collapse
 
eduardoleao052 profile image
Eduardo Opice Leao

As I had replied to another comment, I'm not trying to replace PyTorch or bring Deep Learning to JavaScript. I'm simply creating a tool for DL learners to be able to use.

Sometimes it's easier to have direct access to the browser to run demos or small web-based AI applications. Or, if you don't know Python, this library could be a good place for a JS programmer to start experimenting with Deep Learning as well.

So I do agree with you about Python, I just don't think that these things are mutually exclusive :)

Collapse
 
riigrey profile image
Rii amri

thanks man

Collapse
 
sachinmour profile image
Sachin Mour

Any application that can be written in JavaScript, will eventually be written in JavaScript.
Atwood's Law

Cheers to you brother 👏🏼🥃

Collapse
 
eduardoleao052 profile image
Eduardo Opice Leao

Thank you! Guess I’ve become a part of the problem lol

Collapse
 
lnahrf profile image
Lev N.

Would like to give this a try sometime, thanks for the well written overview. Is it truly native JS? No bindings at all?

Collapse
 
eduardoleao052 profile image
Eduardo Opice Leao

Glad you like it!
The source code is actually in TypeScript, but the deployed package is native JS, ready-to-use!

Collapse
 
eduardoleao052 profile image
Eduardo Opice Leao

Thank you!