[Gemma 3]Using With Transformersjs
Copyright 2025 Google LLC.
Gemma 3 - Run with Transformers.js
Author: Sitam Meur
- GitHub: github.com/sitamgithub-MSIT
- X: @sitammeur
Description: This notebook demonstrates how you can run inference on Gemma 3 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 3 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 3 model using Transformers.js. First, create a text generation pipeline and then prepare input (list of text messages) to run inference and get the output as desired response. For reference, you can check the model's page on the Hugging Face model hub under ONNX models section here.
Run Application
Conclusion
Congratulations! You have successfully run inference on Gemma 3 model using Transformers.js via Node.js environment. You can now integrate this into your projects.
Run in Google Colab