Software and platforms

Machine learning for JavaScript

JavaScript developers use machine learning to classify images from a webcam, detect hands and faces, and run text models directly in the browser or in Node.js. Running models on the user's device keeps data local and removes a server round trip.

How machine learning is used in JavaScript

Real-time video effects in the browser

A segmentation model separates a person from the background in each webcam frame, so the page can blur or replace the background. Running the model in the browser with WebAssembly or WebGL keeps video on the device and avoids a server round trip.

Real exampleGoogle Meet background blurGoogle describes how Meet's background blur and replacement run in the browser with MediaPipe, WebAssembly and on-device ML models.

Training and running neural networks in the browser and Node.js

Developers load pretrained image, pose or text models, or train small models directly from user data on the page. The same library runs in Node.js for server-side scripts.

Real exampleTensorFlow.jsThe TensorFlow.js paper describes a library for building and running machine learning models in the web browser and in Node.js.

Running language and speech models client-side

Transformer models for text classification, translation and speech recognition can now run in a web page, using WebAssembly or WebGPU. This suits private or offline features where the text or audio should not leave the device.

Real exampleTransformers.jsHugging Face's Transformers.js runs Transformers models directly in the browser with no server, and can use WebGPU.

Can you learn machine learning with JavaScript?

Yes. A JavaScript developer can run pretrained models in a web page within a day, and train small models in TensorFlow.js soon after. To build models well, also learn the maths of neural networks and enough Python to follow the training code most models are released with.

  1. Python for reading training codeMost models are trained and published from Python, so learn enough to run a notebook and export a model for the web.Learn it in Python
  2. Vectors, matrices and gradientsTensors, matrix multiplication and gradient descent are what TensorFlow.js code expresses, and shape errors make sense once you know them.Learn it in Maths
  3. Supervised learning and evaluationLearn training and test splits, baselines and accuracy before training anything in the browser.Learn it in Machine Learning
  4. Neural networks and convolutional modelsLearn how dense and convolutional networks are trained, which is what image and sketch recognisers in the browser use.Learn it in Deep Learning
  5. Shipping models to the webConvert a trained model to TensorFlow.js or ONNX, load it in a page, and measure model size, load time and inference speed on a real device.

Moving from JavaScript development into machine learning

If you already work in the field

As a JavaScript developer you already build the interfaces where predictions are shown, which is a valuable half of an ML feature. Add model basics and evaluation, then ship one on-device feature, such as a webcam classifier or a client-side text filter, end to end.

If you come from data science or ML

If you train models in Python, learn how browsers load and run them: model conversion, WebAssembly and WebGPU back ends, bundle size and memory limits. Build one small web demo of your own model to learn where the browser constrains it.

Roles that do this workFront-end engineer, machine learningMachine learning engineerCreative technologistFull-stack engineer

Tools you will use

ToolWhat you use it for
TensorFlow.jsTrain and run neural networks in the browser or Node.js, or convert existing TensorFlow and Keras models.
Transformers.jsRun pretrained Hugging Face models for text, vision and audio tasks directly in JavaScript.
ONNX Runtime WebRun ONNX models exported from PyTorch or scikit-learn in the browser with WebAssembly or WebGPU.
MediaPipeAdd ready-made hand, face, pose and object detection to web apps with a few lines of code.
ml5.jsPrototype image classification and pose tracking quickly with a beginner-friendly API built on TensorFlow.js.

Public data to practise on

  • Quick, Draw! dataset: Millions of player drawings across hundreds of categories; train a sketch recogniser that runs in a web page.
  • SMS Spam Collection (UCI): Short text messages labelled spam or ham; build a text classifier that runs client-side.

Your first project

Download ten categories of Quick, Draw! bitmaps, train a small convolutional network in TensorFlow.js to recognise the drawings, and compare it with a single dense-layer baseline using accuracy on held-out drawings.

Common questions

Can you do machine learning in JavaScript?

Yes. TensorFlow.js trains and runs neural networks in the browser and Node.js, and Transformers.js, ONNX Runtime Web and MediaPipe run pretrained models. Training large models still happens in Python.

Is JavaScript or Python better for machine learning?

Python has far more libraries and examples for training. JavaScript is strong for running models on the user's device and building interactive demos, so many projects train in Python and deploy to JavaScript.

Does machine learning in the browser send my data to a server?

Not when the model runs client-side. The model file is downloaded once, and inputs such as webcam frames or text are processed on the device.

What is the easiest way to start ML in JavaScript?

Load a pretrained model from MediaPipe, ml5.js or Transformers.js and run it on your own input. Then train a small classifier in TensorFlow.js on a dataset such as Quick, Draw!.

Courses for these skills

New to programming or maths? Start with Python, or follow the machine learning path in order. Published lessons are free to read; compare Free and Pro.