# JavaScript machine learning libraries

JavaScript machine learning libraries train models or run pretrained models in browsers and Node.js. Browser runtimes execute a model on the user's device through WebAssembly or WebGPU rather than on a server. These libraries let web apps classify images, detect faces, and run language models without sending user data to a remote API.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [onnxruntime-node](#onnxruntime-node) | 36.3M | 22.3K | Oct 2026 | MIT |
| [@mediapipe/tasks-vision](#mediapipe-tasks-vision) | 31.4M | 37.7K | Nov 2026 | Apache-2.0 |
| [@huggingface/transformers](#huggingface-transformers) | 19.1M | 16.4K | Oct 2026 | Apache-2.0 |
| [skmeans](#skmeans) | 8.8M | 76 | Jan 2020 | MIT |
| [@tensorflow/tfjs](#tensorflow-js) | 2.4M | 19.2K | Oct 2024 | Apache-2.0 |
| [ml-kmeans](#ml-kmeans) | 805.4K | 105 | Jun 2026 | MIT |
| [ml-logistic-regression](#ml-logistic-regression) | 769.8K | 18 | May 2020 | MIT |
| [@mlc-ai/web-llm](#mlc-ai-web-llm) | 754.5K | 19.4K | Nov 2026 | Apache-2.0 |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[ONNX Runtime Node](#onnxruntime-node) has the most monthly downloads in this comparison, at 36.3M.

## Capabilities

| Library | Browser runtime | Supervised fitting |
| --- | --- | --- |
| [onnxruntime-node](#onnxruntime-node) | No | Undocumented |
| [@mediapipe/tasks-vision](#mediapipe-tasks-vision) | Yes | No |
| [@huggingface/transformers](#huggingface-transformers) | Yes | No |
| [skmeans](#skmeans) | Yes | No |
| [@tensorflow/tfjs](#tensorflow-js) | Yes | Yes |
| [ml-kmeans](#ml-kmeans) | Undocumented | No |
| [ml-logistic-regression](#ml-logistic-regression) | Undocumented | Yes |
| [@mlc-ai/web-llm](#mlc-ai-web-llm) | Yes | No |

## Libraries

### onnxruntime-node

[GitHub](https://github.com/microsoft/onnxruntime) · [npm](https://www.npmjs.com/package/onnxruntime-node) · [Docs](https://github.com/Microsoft/onnxruntime#readme)

Runs ONNX models in Node.js through a native binding.

- Downloads / mo: 36.3M
- Stars: 22.3K
- Last release: 1.31.1
- License: MIT
- Capabilities: [From the onnxruntime-node docs](https://github.com/Microsoft/onnxruntime#readme)

```sh
npm install onnxruntime-node
```

**Quickstart**

```javascript
import * as ort from 'onnxruntime-node';
const session = await ort.InferenceSession.create('./model.onnx');
console.log(session);

```

From [InferenceSessionFactory.html](https://onnxruntime.ai/docs/api/js/interfaces/InferenceSessionFactory.html) · [Find projects using onnxruntime-node →](https://dashboard.exa.ai/playground/search?q=onnxruntime-node%20GitHub%20projects)

### @mediapipe/tasks-vision

[GitHub](https://github.com/google-ai-edge/mediapipe) · [npm](https://www.npmjs.com/package/@mediapipe/tasks-vision) · [Docs](http://mediapipe.dev)

Runs MediaPipe vision tasks in the browser.

- Downloads / mo: 31.4M
- Stars: 37.7K
- Last release: 1.2.3
- License: Apache-2.0
- Capabilities: [From the @mediapipe/tasks-vision docs](http://mediapipe.dev)

```sh
npm install @mediapipe/tasks-vision
```

**google-ai-edge/mediapipe-samples-web** (113 stars)

[google-ai-edge/mediapipe-samples-web](https://github.com/google-ai-edge/mediapipe-samples-web) 

```javascript
protected async handleCustomMessage(data: any): Promise<void> {
    if (data.type === 'DETECT_IMAGE' || data.type === 'DETECT_VIDEO') {
      const { bitmap, timestampMs } = data;
      const requiredMode = data.type === 'DETECT_IMAGE' ? 'IMAGE' : 'VIDEO';

      if (!this.taskInstance) {
        console.warn('FaceLandmarker not initialized yet.');
        bitmap.close();
        self.postMessage({ type: 'DETECT_ERROR', error: 'Not initialized' });
        return;
      }

      if (this.currentOptions.runningMode !== requiredMode) {
        this.currentOptions.runningMode = requiredMode;
        await this.updateOptions();
      }

      const startTimeMs = performance.now();
      let result: FaceLandmarkerResult;

      try {
        if (requiredMode === 'VIDEO') {
          result = this.taskInstance.detectForVideo(bitmap, timestampMs);
        } else {
          result = this.taskInstance.detect(bitmap);
        }
      } catch (e: any) {
        console.error('Worker detection error:', e);
        bitmap.close();
        self.postMessage({ type: 'DETECT_ERROR', error: e.message || 'Detection failed' });
        return;
      }

      const inferenceTime = performance.now() - startTimeMs;
      bitmap.close();

      self.postMessage({
        type: 'DETECT_RESULT',
        mode: requiredMode,
        result: result,
        inferenceTime: inferenceTime,
      });
    }
  }
```

[src/workers/face-landmarker.worker.ts](https://github.com/google-ai-edge/mediapipe-samples-web/blob/64ecdefb2a0f0d97e175e4d8fdeeff0f73b29ab5/src/workers/face-landmarker.worker.ts#L53-L96) · [More projects using @mediapipe/tasks-vision →](https://dashboard.exa.ai/playground/search?q=%40mediapipe/tasks-vision%20GitHub%20projects)

**Quickstart**

```javascript
import { FilesetResolver, FaceLandmarker } from '@mediapipe/tasks-vision';
const files = await FilesetResolver.forVisionTasks('https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@1.2.3/wasm');
const task = await FaceLandmarker.createFromOptions(files, {
  baseOptions: { modelAssetPath: './face_landmarker.task' }, runningMode: 'IMAGE',
});
console.log(task);

```

From [web_js](https://developers.google.com/edge/mediapipe/solutions/vision/face_landmarker/web_js)

### @huggingface/transformers

[GitHub](https://github.com/huggingface/transformers.js) · [npm](https://www.npmjs.com/package/@huggingface/transformers) · [Docs](https://github.com/huggingface/transformers.js#readme)

Runs Transformers models directly in the browser, with no server.

- Downloads / mo: 19.1M
- Stars: 16.4K
- Last release: 4.3.2
- License: Apache-2.0
- Capabilities: [From the @huggingface/transformers docs](https://github.com/huggingface/transformers.js#readme)

```sh
npm install @huggingface/transformers
```

**huggingface/transformers.js-examples** (2.1K stars)

[huggingface/transformers.js-examples](https://github.com/huggingface/transformers.js-examples) 

```javascript
async (event) => {
  // Retrieve the translation pipeline. When called for the first time,
  // this will load the pipeline and save it for future use.
  const translator = await MyTranslationPipeline.getInstance((x) => {
    // We also add a progress callback to the pipeline so that we can
    // track model loading.
    self.postMessage(x);
  });

  // Capture partial output as it streams from the pipeline
  const streamer = new TextStreamer(translator.tokenizer, {
    skip_prompt: true,
    skip_special_tokens: true,
    callback_function: function (text) {
      self.postMessage({
        status: "update",
        output: text,
      });
    },
  });

  // Actually perform the translation
  const output = await translator(event.data.text, {
    tgt_lang: event.data.tgt_lang,
    src_lang: event.data.src_lang,

    // Allows for partial output
    streamer,
  });

  // Send the output back to the main thread
  self.postMessage({
    status: "complete",
    output,
  });
}

```

[react-translator/src/worker.js](https://github.com/huggingface/transformers.js-examples/blob/204b0948e88cd2bdc046316e78b754359653caea/react-translator/src/worker.js#L23-L58) · [More projects using @huggingface/transformers →](https://dashboard.exa.ai/playground/search?q=%40huggingface/transformers%20GitHub%20projects)

**Quickstart**

```javascript
import { pipeline } from '@huggingface/transformers';
const classify = await pipeline('sentiment-analysis');
console.log(await classify('I love transformers!'));

```

From [README.md](https://github.com/huggingface/transformers.js/blob/205e9c2511622724bf9751b35f2afb07f1dd3aa6/README.md)

### skmeans

[GitHub](https://github.com/solzimer/skmeans) · [npm](https://www.npmjs.com/package/skmeans)

Clusters one-dimensional and multidimensional data with k-means and k-means++ in Node.js and the browser.

- Downloads / mo: 8.8M
- Stars: 76
- Last release: 0.11.3
- License: MIT
- Capabilities: [From the skmeans docs](https://www.npmjs.com/package/skmeans)

```sh
npm install skmeans
```

**Quickstart**

```javascript
import skmeans from 'skmeans';
const result = skmeans([[1], [2], [10], [11]], 2, 'kmpp');
console.log(result.centroids);

```

From [README.md](https://registry.npmjs.org/skmeans/latest) · [Find projects using skmeans →](https://dashboard.exa.ai/playground/search?q=skmeans%20GitHub%20projects)

### @tensorflow/tfjs

[GitHub](https://github.com/tensorflow/tfjs) · [npm](https://www.npmjs.com/package/@tensorflow/tfjs)

Builds, trains, and deploys machine-learning models in JavaScript.

- Downloads / mo: 2.4M
- Stars: 19.2K
- Last release: 4.22.0
- License: Apache-2.0
- Capabilities: [From the @tensorflow/tfjs docs](https://www.npmjs.com/package/@tensorflow/tfjs)

**Strengths**

- **Builds models at different levels.** Choose low-level tensor operations or the higher-level layers API.
- **Reloads saved model topology.** Save topology and weight references in a JSON model file.

**Watch out for**

- **GPU tensors need explicit cleanup.** Dispose tensors or use tidy to release unneeded WebGL memory.

```sh
npm install @tensorflow/tfjs
```

**googlecreativelab/teachablemachine-community** (1.8K stars)

[googlecreativelab/teachablemachine-community](https://github.com/googlecreativelab/teachablemachine-community) 

```typescript
export async function loadTruncatedMobileNet(modelOptions?: ModelOptions) {
    const [checkpointUrl, trainingLayer] = parseModelOptions(modelOptions);
    const mobilenet = await tf.loadLayersModel(checkpointUrl);

    if (modelOptions && modelOptions.version === 1){
        const layer = mobilenet.getLayer(trainingLayer);
        const truncatedModel = tf.model({ inputs: mobilenet.inputs, outputs: layer.output });
        const model = tf.sequential();
        model.add(truncatedModel);
        model.add(tf.layers.flatten());
        return model;
    }
    else {
        const layer = mobilenet.getLayer(trainingLayer);
        const truncatedModel = tf.model({ inputs: mobilenet.inputs, outputs: layer.output });
        const model = tf.sequential();
        model.add(truncatedModel);
        model.add(tf.layers.globalAveragePooling2d({})); // go from shape [7, 7, 1280] to [1280]
        return model;
    }
}
```

[libraries/image/src/custom-mobilenet.ts](https://github.com/googlecreativelab/teachablemachine-community/blob/55aa0bb84acaa9efcbb9a2068eaefbb72cddae2c/libraries/image/src/custom-mobilenet.ts#L289-L309) · [More projects using @tensorflow/tfjs →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20%40tensorflow/tfjs%20for%20machine-learning%20model%20training%20or%20inference&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
import * as tf from '@tensorflow/tfjs';
const model = tf.sequential();
model.add(tf.layers.dense({ units: 1, inputShape: [1] }));
model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' });
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);
await model.fit(xs, ys, { epochs: 1 });
const prediction = model.predict(tf.tensor2d([5], [1, 1]));
prediction.print();

```

From [README.md](https://www.tensorflow.org/js/guide/models_and_layers)

### ml-kmeans

[GitHub](https://github.com/mljs/kmeans) · [npm](https://www.npmjs.com/package/ml-kmeans)

Groups numeric data with k-means clustering.

- Downloads / mo: 805.4K
- Stars: 105
- Last release: 7.0.1
- License: MIT
- Capabilities: [From the ml-kmeans docs](https://github.com/mljs/kmeans)

```sh
npm install ml-kmeans
```

**Quickstart**

```javascript
import { kmeans } from 'ml-kmeans';
const result = kmeans([[1], [2], [10], [11]], 2, { seed: 42 });
console.log(result.clusters);

```

From [README.md](https://registry.npmjs.org/ml-kmeans/latest) · [Find projects using ml-kmeans →](https://dashboard.exa.ai/playground/search?q=ml-kmeans%20GitHub%20projects)

### ml-logistic-regression

[GitHub](https://github.com/mljs/logistic-regression) · [npm](https://www.npmjs.com/package/ml-logistic-regression) · [Docs](https://github.com/mljs/logistic-regression#readme)

Fits logistic regression models.

- Downloads / mo: 769.8K
- Stars: 18
- Last release: 2.0.0
- License: MIT
- Capabilities: [From the ml-logistic-regression docs](https://github.com/mljs/logistic-regression#readme)

```sh
npm install ml-logistic-regression ml-matrix
```

**apify/crawlee** (26.5K stars)

[apify/crawlee](https://github.com/apify/crawlee) 

```javascript
#retrain(): void {
        const X: FeatureVector[] = [
            [0, 1],
            [1, 0],
        ];
        const Y: number[] = [0, 1];

        for (const [renderingType, urlsByLabel] of this.#state.currentValue.detectionResults.entries()) {
            for (const [label, urls] of urlsByLabel) {
                for (const url of urls) {
                    X.push(this.#calculateFeatureVector(url, label));
                    Y.push(renderingType === 'static' ? 1 : 0);
                }
            }
        }

        this.#state.currentValue.logreg.train(new Matrix(X), Matrix.columnVector(Y));
    }
```

[packages/playwright-crawler/src/internals/utils/rendering-type-prediction.ts](https://github.com/apify/crawlee/blob/db1cf3e3ed05182f6828c51fbf86afa97e5d975d/packages/playwright-crawler/src/internals/utils/rendering-type-prediction.ts#L232-L249) · [More projects using ml-logistic-regression →](https://dashboard.exa.ai/playground/search?q=ml-logistic-regression%20GitHub%20projects)

**Quickstart**

```javascript
const { Matrix } = require('ml-matrix');
const LogisticRegression = require('ml-logistic-regression');
const model = new LogisticRegression({ numSteps: 1000, learningRate: 5e-3 });
model.train(new Matrix([[0], [1], [2], [3]]), Matrix.columnVector([0, 0, 1, 1]));
console.log(model.predict(new Matrix([[1.5]])));

```

From [README.md](https://registry.npmjs.org/ml-logistic-regression/latest)

### @mlc-ai/web-llm

[GitHub](https://github.com/mlc-ai/web-llm) · [npm](https://www.npmjs.com/package/@mlc-ai/web-llm)

Runs hardware-accelerated language model chats in the browser.

- Downloads / mo: 754.5K
- Stars: 19.4K
- Last release: 0.2.89
- License: Apache-2.0
- Capabilities: [From the @mlc-ai/web-llm docs](https://github.com/mlc-ai/web-llm)

```sh
npm install @mlc-ai/web-llm
```

**Quickstart**

```javascript
import { CreateMLCEngine } from '@mlc-ai/web-llm';
const engine = await CreateMLCEngine('Llama-3.1-8B-Instruct-q4f32_1-MLC');
const reply = await engine.chat.completions.create({ messages: [{ role: 'user', content: 'Hello' }] });
console.log(reply.choices[0].message.content);

```

From [README.md](https://registry.npmjs.org/%40mlc-ai%2Fweb-llm/latest) · [Find projects using @mlc-ai/web-llm →](https://dashboard.exa.ai/playground/search?q=%40mlc-ai/web-llm%20GitHub%20projects)

## FAQ

### Which JavaScript machine learning library should I use?

[TensorFlow.js](#tensorflow-js) suits apps that build and train models in JavaScript. [Transformers.js](#huggingface-transformers) suits apps that run pretrained models in the browser. [ONNX Runtime Node](#onnxruntime-node) suits Node.js servers that execute exported ONNX models.

### What is MediaPipe?

MediaPipe is Google's set of ready task models for image and video input. [MediaPipe Tasks Vision](#mediapipe-tasks-vision) runs those vision tasks, such as face landmark detection, in the browser.

### What is WebLLM?

[WebLLM](#mlc-ai-web-llm) runs language model chats in the browser with hardware acceleration through WebGPU. It accepts requests in an OpenAI-style chat completion format.

### What is Transformers.js?

[Transformers.js](#huggingface-transformers) runs pretrained models exported to ONNX directly in the browser. It defaults to CPU and WebAssembly, with optional WebGPU.

### TensorFlow.js vs Transformers.js: which should I use?

[TensorFlow.js](#tensorflow-js) builds and trains models from tensor operations and layers. [Transformers.js](#huggingface-transformers) runs existing pretrained models without a training step.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript machine learning libraries TensorFlow.js Brain.js ONNX Runtime Web ml5 code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
