Notebooks
G
Google Gemini
[Gemma 3]Using With Transformersjs

[Gemma 3]Using With Transformersjs

recurrentgemmagemmapaligemmagemma-cookbookcodegemma
Copyright 2025 Google LLC.
[1]

Gemma 3 - Run with Transformers.js

Author: Sitam Meur

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:

  1. In the upper-right of the Colab window, select ▾ (Additional connection options).
  2. Select Change runtime type.
  3. 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.

[ ]
[3]

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.

[4]

Run Application

[5]

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.