« Back

Transformers.js

brain/products/transformers-js.md - updated 2026-11-18
Tags: product, hugging-face, javascript, machine-learning, in-browser, embeddings - Similar notes

Transformers.js is Hugging Face's JavaScript library for running pretrained ML models in the browser.

  • The docs say: "Run 🤗 Transformers directly in your browser, with no need for a server!" It aims to match the Python transformers API.
  • Models run through ONNX Runtime. In the browser the default is WASM on the CPU; device: 'webgpu' uses the GPU (the docs note WebGPU is still experimental in many browsers).
  • dtype picks precision: fp32 (default for WebGPU), fp16, q8 (default for WASM) or q4.
  • Install: npm i @huggingface/transformers. The pipeline() function bundles a model with pre- and post-processing.
  • Embedding example from the Xenova/all-MiniLM-L6-v2 card: pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2'), then call it with { pooling: 'mean', normalize: true } to get 384-dimension vectors. See all-MiniLM-L6-v2.
  • Used by FetchMoji for in-browser semantic search. Background: Embeddings and semantic search.

Sources