gitmyhub

transformers.js

JavaScript ★ 16k updated 3d ago

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!

Transformers.js lets you run Hugging Face machine-learning models directly in a browser or Node.js app with no server needed, covering text, image, audio, and multimodal tasks through a simple pipeline API.

JavaScriptONNX RuntimeWebAssemblyWebGPUnpmsetup: easycomplexity 2/5

Transformers.js is a JavaScript library that lets web pages and Node.js apps run pretrained machine-learning models directly on the user's device, with no server doing the work. The README pitches it as state-of-the-art machine learning for the web and describes it as functionally equivalent to Hugging Face's Python transformers library, so similar code works in both places.

The library covers a broad mix of tasks. For text it can do sentiment classification, named-entity recognition, question answering, summarization, translation, and text generation. For images it handles classification, object detection, segmentation, and depth estimation. For sound there is automatic speech recognition, audio classification, and text-to-speech. Multimodal tasks like embeddings and zero-shot classification across text, images, and audio are also supported. The main entry point is a pipeline function that bundles a model with input preprocessing and output postprocessing, so a sentiment-analysis call is a one-liner returning labels and scores. Under the hood it uses ONNX Runtime to execute models, which is why you convert PyTorch, TensorFlow, or JAX models to the ONNX format (typically via Optimum) before using them. By default it runs on the CPU through WebAssembly; setting a device option to webgpu uses the GPU through the experimental WebGPU API, and a dtype option picks a quantized variant such as fp16, q8, or q4 to shrink downloads.

Someone would reach for Transformers.js to build privacy-friendly browser demos, offline-capable extensions, or embedded AI features that avoid the cost and latency of a server. It is JavaScript, installed via npm or loaded directly from a CDN.

Where it fits