[Gemma 3n]Using With Transformersjs
Copyright 2026 Google LLC.
Gemma 3n - Run with Transformers.js
Author: Sitam Meur
- GitHub: github.com/sitammeur
- X: @sitammeur
Description: This notebook demonstrates how you can run inference on Gemma 3n model using Node.js and Transformers.js. Transformers.js lets you run Hugging Face's transformer models directly in browser, offering a JavaScript API similar to Python's. It supports NLP, computer vision, audio, and multimodal tasks using ONNX Runtime and allows easy conversion of PyTorch, TensorFlow, and JAX models.
Setup
Select the Colab runtime
To complete this tutorial, you'll need to have a Colab runtime with sufficient resources to run the Gemma 3n model. In this case, you can use CPU runtime:
- In the upper-right of the Colab window, select ▾ (Additional connection options).
- Select Change runtime type.
- Under Hardware accelerator, select CPU.
Installation
Let's get started with installing the dependencies.
Create Node.js project
Create a new Node.js project and install the required transformers package via NPM.
Transformers.js Inference
Now, let's run inference on the Gemma 3n model using Transformers.js. First, create a generation pipeline for images and text, audio and text, and images and audio. Then, prepare the inputs to run inference and obtain the desired output. For reference, you can check the model's page on the Hugging Face model hub under ONNX models section here.
Image + Text Inference
Audio + Text Inference
Image + Audio Inference
Conclusion
Congratulations! You have successfully run inference on Gemma 3n model using Transformers.js via Node.js environment. You can now integrate this into your projects.
Run in Google Colab