DEV Community

Victor Muštar
Victor Muštar

Posted on

How to use machine learning in your JS applications

Maybe, like me, you always wanted to use machine learning in your JS applications: you had some problems you think ML could solve (like summarization, sentiment analysis, object detection in images, etc, etc...) or you just wanted to have fun.

But the need to learn python, Machine Learning, and the whole ML stack is pulling you away. Building a good front-end is already hard enough...

So here is a super easy way to use machine learning in your apps (through the Hugging Face inference API, note that the free-tier is quite generous).

Start by choosing a model here: hf.co/models (+30k available models, a lot of them state-of-the-art). If you don't know which one to choose you can start by checking the different tasks available.

+30k models are available on the HuggingFace Hub

Once you found a model that you like just click Deploy -> Inference API then select JavaScript. For example, here is the one I usually use to do summarization: https://huggingface.co/sshleifer/distilbart-cnn-6-6

The inference API with JavaScript code snippet selected

And that's it! You can now use this super powerful ML model anywhere you want, or even try it directly in your JS console by pasting the JS snippet (here is an example for summarization):

Trying a Hugging Face model in the Google Chrome console

Good luck and have fun!
Victor

Top comments (0)