back to home

huggingface / transformers.js

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

15,569 stars
1,107 forks
299 issues
JavaScriptVim SnippetTypeScript

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing huggingface/transformers.js in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/huggingface/transformers.js)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

State-of-the-art Machine Learning for the Web Run šŸ¤— Transformers directly in your browser, with no need for a server! Transformers.js is designed to be functionally equivalent to Hugging Face's transformers python library, meaning you can run the same pretrained models using a very similar API. These models support common tasks in different modalities, such as: • šŸ“ **Natural Language Processing**: text classification, named entity recognition, question answering, language modeling, summarization, translation, multiple choice, and text generation. • šŸ–¼ļø **Computer Vision**: image classification, object detection, segmentation, and depth estimation. • šŸ—£ļø **Audio**: automatic speech recognition, audio classification, and text-to-speech. • šŸ™ **Multimodal**: embeddings, zero-shot audio classification, zero-shot image classification, and zero-shot object detection. Transformers.js uses ONNX Runtime to run models in the browser. The best part about it, is that you can easily convert your pretrained PyTorch, TensorFlow, or JAX models to ONNX using šŸ¤— Optimum. For more information, check out the full documentation. Installation To install via NPM, run: Alternatively, you can use it in vanilla JS, without any bundler, by using a CDN or static hosting. For example, using ES Modules, you can import the library with: Quick tour It's super simple to translate from existing code! Just like the python library, we support the API. Pipelines group together a pretrained model with preprocessing of inputs and postprocessing of outputs, making it the easiest way to run models with the library. Python (original) Javascript (ours) You can also use a different model by specifying the model id or path as the second argument to the function. For example: By default, when running in the browser, the model will be run on your CPU (via WASM). If you would like to run the model on your GPU (via WebGPU), you can do this by setting , for example: For more information, check out the WebGPU guide. > [!WARNING] > The WebGPU API is still experimental in many browsers, so if you run into any issues, > please file a bug report. In resource-constrained environments, such as web browsers, it is advisable to use a quantized version of the model to lower bandwidth and optimize performance. This can be achieved by adjusting the option, which allows you to select the appropriate data type for your model. While the available options may vary depending on the specific model, typical choices include (default for WebGPU), , (default for WASM), and . For more information, check out the quantization guide. Ready to dive in? Explore our wide variety of demo applications and templates here. You can also launch your own project instantly using the official Transformers.js template on Hugging Face! Custom usage By default, Transformers.js uses hosted pretrained models and precompiled WASM binaries, which should work out-of-the-box. You can customize this as follows: Settings For a full list of available settings, check out the API Reference. Convert your models to ONNX We recommend using Optimum to convert your PyTorch models to ONNX in a single command. For the full list of supported architectures, check out the Optimum documentation. Supported tasks/models Here is the list of all tasks and architectures currently supported by Transformers.js. If you don't see your task/model listed here or it is not yet supported, feel free to open up a feature request here. To find compatible models on the Hub, select the "transformers.js" library tag in the filter menu (or visit this link). You can refine your search by selecting the task you're interested in (e.g., text-classification). Tasks Natural Language Processing | Task | ID | Description | Supported? | |--------------------------|----|-------------|------------| | Fill-Mask | | Masking some of the words in a sentence and predicting which words should replace those masks. | āœ… (docs) (models) | | Question Answering | | Retrieve the answer to a question from a given text. | āœ… (docs) (models) | | Sentence Similarity | | Determining how similar two texts are. | āœ… (docs) (models) | | Summarization | | Producing a shorter version of a document while preserving its important information. | āœ… (docs) (models) | | Table Question Answering | | Answering a question about information from a given table. | āŒ | | Text Classification | or | Assigning a label or class to a given text. | āœ… (docs) (models) | | Text Generation | | Producing new text by predicting the next word in a sequence. | āœ… (docs) (models) | | Text-to-text Generation | | Converting one text sequence into another text sequence. | āœ… (docs) (models) | | Token Classification | or | Assigning a label to each token in a text. | āœ… (docs) (models) | | Translation | | Converting text from one language to another. | āœ… (docs) (models) | | Zero-Shot Classification | | Classifying text into classes that are unseen during training. | āœ… (docs) (models) | | Feature Extraction | | Transforming raw data into numerical features that can be processed while preserving the information in the original dataset. | āœ… (docs) (models) | Vision | Task | ID | Description | Supported? | |--------------------------|----|-------------|------------| | Background Removal | | Isolating the main subject of an image by removing or making the background transparent. | āœ… (docs) (models) | | Depth Estimation | | Predicting the depth of objects present in an image. | āœ… (docs) (models) | | Image Classification | | Assigning a label or class to an entire image. | āœ… (docs) (models) | | Image Segmentation | | Divides an image into segments where each pixel is mapped to an object. This task has multiple variants such as instance segmentation, panoptic segmentation and semantic segmentation. | āœ… (docs) (models) | | Image-to-Image | | Transforming a source image to match the characteristics of a target image or a target image domain. | āœ… (docs) (models) |…