Ad

transformers.js: Browser-based Machine Learning

Run Hugging Face Transformers models directly in the browser. Enables NLP, computer vision, audio, and multimodal tasks without server dependency.
Screenshot of huggingface/transformers.js homepage

transformers.js enables running state-of-the-art machine learning models from the Hugging Face Transformers library directly in web browsers. It provides a JavaScript API mirroring the Python library, allowing users to leverage pre-trained models for NLP, computer vision, audio, and multimodal tasks. It primarily uses ONNX Runtime to execute models, facilitating conversion from PyTorch, TensorFlow, and JAX.

Key features include function-equivalent API to the Python Transformers library, support for various tasks (NLP, vision, audio, multimodal), and integration with ONNX Runtime for efficient inference. It offers flexible model loading with options for local models, custom configurations, and WebGPU acceleration. The library provides a straightforward way to translate existing PyTorch or TensorFlow code to JavaScript.

  • Task Support: Supports a wide range of pre-trained models for NLP (text classification, translation, etc.), computer vision, audio, and multimodal tasks.
  • API Compatibility: Provides a familiar API similar to Hugging Face's Python Transformers library, simplifying migration and enabling rapid prototyping.
  • ONNX Runtime Integration: Leverages ONNX Runtime for optimized model execution within the browser, improving performance and efficiency.
  • WebGPU Acceleration: Supports leveraging the WebGPU API for GPU-accelerated inference in modern browsers.
  • Quantization Support: Offers dtype options for model quantization, allowing for reduced model size and faster inference in resource-constrained environments.
  • Model Conversion: Enables easy conversion of PyTorch, TensorFlow, and JAX models to ONNX format using Optimum.
  • Customization: Supports custom model locations, disabling remote models, and configuring WASM settings.

transformers.js is an active project with ongoing development and maintenance. Recent commits indicate continued feature additions and bug fixes. The documentation is comprehensive, and the community is engaged. While WebGPU support is still evolving, the project offers a stable and reliable solution for running Transformers models in web browsers. Regular updates and a clear development roadmap suggest a promising future.

transformers.js benefits developers looking to deploy machine learning models directly in web applications without relying on server-side infrastructure. This value proposition is particularly useful for scenarios prioritizing low latency, offline functionality, and reduced infrastructure costs. It eliminates the need to transfer data between the browser and a server, streamlining workflows and improving user experience for well-established use cases such as real-time text analysis or automated media processing.

Summarize:
Share:
Stars
16,171
Forks
1,164
Issues
256
Created
3 years ago
Commit
13 days ago
License
APACHE-2.0
Archived
No
Updated 12 days ago

Similar Repositories