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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: google/gemma-3n-E4B-it
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
pipeline_tag: image-text-to-text
|
| 6 |
+
library_name: transformers
|
| 7 |
+
license: gemma
|
| 8 |
+
tags:
|
| 9 |
+
- gemma3
|
| 10 |
+
- unsloth
|
| 11 |
+
- transformers
|
| 12 |
+
- gemma
|
| 13 |
+
- google
|
| 14 |
+
---
|
| 15 |
+
<div>
|
| 16 |
+
<p style="margin-bottom: 0; margin-top: 0;">
|
| 17 |
+
<strong>Learn how to run & fine-tune Gemma 3n correctly - <a href="https://docs.unsloth.ai/basics/gemma-3n">Read our Guide</a>.</strong>
|
| 18 |
+
</p>
|
| 19 |
+
<p style="margin-bottom: 0;">
|
| 20 |
+
<em>See <a href="https://huggingface.co/collections/unsloth/gemma-3n-685d3874830e49e1c93f9339">our collection</a> for all versions of Gemma 3n including GGUF, 4-bit & 16-bit formats.</em>
|
| 21 |
+
</p>
|
| 22 |
+
<p style="margin-top: 0;margin-bottom: 0;">
|
| 23 |
+
<em><a href="https://docs.unsloth.ai/basics/unsloth-dynamic-v2.0-gguf">Unsloth Dynamic 2.0</a> achieves SOTA accuracy & performance versus other quants.</em>
|
| 24 |
+
</p>
|
| 25 |
+
<div style="display: flex; gap: 5px; align-items: center; ">
|
| 26 |
+
<a href="https://github.com/unslothai/unsloth/">
|
| 27 |
+
<img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">
|
| 28 |
+
</a>
|
| 29 |
+
<a href="https://discord.gg/unsloth">
|
| 30 |
+
<img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">
|
| 31 |
+
</a>
|
| 32 |
+
<a href="https://docs.unsloth.ai/basics/gemma-3n">
|
| 33 |
+
<img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">
|
| 34 |
+
</a>
|
| 35 |
+
</div>
|
| 36 |
+
<h1 style="margin-top:0; margin-bottom: 0;">✨ Gemma 3n Usage Guidelines</h1>
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
- Currently **only text** is supported.
|
| 40 |
+
- Ollama: `ollama run hf.co/unsloth/gemma-3n-E4B-it:Q4_K_XL` - auto-sets correct chat template and settings
|
| 41 |
+
- Set temperature = 1.0, top_k = 64, top_p = 0.95, min_p = 0.0
|
| 42 |
+
- Gemma 3n max tokens (context length): 32K. Gemma 3n chat template:
|
| 43 |
+
```
|
| 44 |
+
<bos><start_of_turn>user\nHello!<end_of_turn>\n<start_of_turn>model\nHey there!<end_of_turn>\n<start_of_turn>user\nWhat is 1+1?<end_of_turn>\n<start_of_turn>model\n
|
| 45 |
+
```
|
| 46 |
+
- For complete detailed instructions, see our [step-by-step guide](https://docs.unsloth.ai/basics/gemma-3n).
|
| 47 |
+
|
| 48 |
+
# 🦥 Fine-tune Gemma 3n with Unsloth
|
| 49 |
+
|
| 50 |
+
- Fine-tune Gemma 3n (4B) for free using our Google [Colab notebook here](https://docs.unsloth.ai/get-started/unsloth-notebooks)!
|
| 51 |
+
- Read our Blog about Gemma 3n support: [unsloth.ai/blog/gemma-3n](https://unsloth.ai/blog/gemma-3n)
|
| 52 |
+
- View the rest of our notebooks in our [docs here](https://docs.unsloth.ai/get-started/unsloth-notebooks).
|
| 53 |
+
|
| 54 |
+
| Unsloth supports | Free Notebooks | Performance | Memory use |
|
| 55 |
+
|-----------------|--------------------------------------------------------------------------------------------------------------------------|-------------|----------|
|
| 56 |
+
| **Gemma-3n-E4B** | [▶️ Start on Colab](https://docs.unsloth.ai/get-started/unsloth-notebooks) | 2x faster | 80% less |
|
| 57 |
+
| **GRPO with Gemma 3 (1B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3_(1B)-GRPO.ipynb) | 2x faster | 80% less |
|
| 58 |
+
| **Gemma 3 (4B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3_(4B).ipynb) | 2x faster | 60% less |
|
| 59 |
+
| **Qwen3 (14B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_(14B)-Reasoning-Conversational.ipynb) | 2x faster | 60% less |
|
| 60 |
+
| **DeepSeek-R1-0528-Qwen3-8B (14B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/DeepSeek_R1_0528_Qwen3_(8B)_GRPO.ipynb) | 2x faster | 80% less |
|
| 61 |
+
| **Llama-3.2 (3B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.2_(1B_and_3B)-Conversational.ipynb) | 2.4x faster | 58% less |
|
| 62 |
+
<br>
|
| 63 |
+
|
| 64 |
+
# Gemma-3n-E4B model card
|
| 65 |
+
**Model Page**: [Gemma 3n](https://ai.google.dev/gemma/docs/gemma-3n)
|
| 66 |
+
|
| 67 |
+
**Resources and Technical Documentation**:
|
| 68 |
+
|
| 69 |
+
- [Responsible Generative AI Toolkit](https://ai.google.dev/responsible)
|
| 70 |
+
- [Gemma on Kaggle](https://www.kaggle.com/models/google/gemma-3n)
|
| 71 |
+
- [Gemma on HuggingFace](https://huggingface.co/collections/google/gemma-3n-685065323f5984ef315c93f4)
|
| 72 |
+
- [Gemma on Vertex Model Garden](https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/gemma3n)
|
| 73 |
+
|
| 74 |
+
**Terms of Use**: [Terms](https://ai.google.dev/gemma/terms)\
|
| 75 |
+
**Authors**: Google DeepMind
|
| 76 |
+
|
| 77 |
+
## Model Information
|
| 78 |
+
|
| 79 |
+
Summary description and brief definition of inputs and outputs.
|
| 80 |
+
|
| 81 |
+
### Description
|
| 82 |
+
|
| 83 |
+
Gemma is a family of lightweight, state-of-the-art open models from Google,
|
| 84 |
+
built from the same research and technology used to create the Gemini models.
|
| 85 |
+
Gemma 3n models are designed for efficient execution on low-resource devices.
|
| 86 |
+
They are capable of multimodal input, handling text, image, video, and audio
|
| 87 |
+
input, and generating text outputs, with open weights for pre-trained and
|
| 88 |
+
instruction-tuned variants. These models were trained with data in over 140
|
| 89 |
+
spoken languages.
|
| 90 |
+
|
| 91 |
+
Gemma 3n models use selective parameter activation technology to reduce resource
|
| 92 |
+
requirements. This technique allows the models to operate at an effective size
|
| 93 |
+
of 2B and 4B parameters, which is lower than the total number of parameters they
|
| 94 |
+
contain. For more information on Gemma 3n's efficient parameter management
|
| 95 |
+
technology, see the
|
| 96 |
+
[Gemma 3n](https://ai.google.dev/gemma/docs/gemma-3n#parameters)
|
| 97 |
+
page.
|
| 98 |
+
|
| 99 |
+
### Inputs and outputs
|
| 100 |
+
|
| 101 |
+
- **Input:**
|
| 102 |
+
- Text string, such as a question, a prompt, or a document to be
|
| 103 |
+
summarized
|
| 104 |
+
- Images, normalized to 256x256, 512x512, or 768x768 resolution
|
| 105 |
+
and encoded to 256 tokens each
|
| 106 |
+
- Audio data encoded to 6.25 tokens per second from a single channel
|
| 107 |
+
- Total input context of 32K tokens
|
| 108 |
+
- **Output:**
|
| 109 |
+
- Generated text in response to the input, such as an answer to a
|
| 110 |
+
question, analysis of image content, or a summary of a document
|
| 111 |
+
- Total output length up to 32K tokens, subtracting the request
|
| 112 |
+
input tokens
|
| 113 |
+
### Usage
|
| 114 |
+
|
| 115 |
+
Below, there are some code snippets on how to get quickly started with running
|
| 116 |
+
the model. First, install the Transformers library. Gemma 3n is supported
|
| 117 |
+
starting from transformers 4.53.0.
|
| 118 |
+
|
| 119 |
+
```sh
|
| 120 |
+
$ pip install -U transformers
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
Then, copy the snippet from the section that is relevant for your use case.
|
| 124 |
+
|
| 125 |
+
#### Running with the `pipeline` API
|
| 126 |
+
|
| 127 |
+
You can initialize the model and processor for inference with `pipeline` as
|
| 128 |
+
follows.
|
| 129 |
+
|
| 130 |
+
```python
|
| 131 |
+
from transformers import pipeline
|
| 132 |
+
import torch
|
| 133 |
+
pipe = pipeline(
|
| 134 |
+
"image-text-to-text",
|
| 135 |
+
model="google/gemma-3n-e4b-it",
|
| 136 |
+
device="cuda",
|
| 137 |
+
torch_dtype=torch.bfloat16,
|
| 138 |
+
)
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
With instruction-tuned models, you need to use chat templates to process our
|
| 142 |
+
inputs first. Then, you can pass it to the pipeline.
|
| 143 |
+
|
| 144 |
+
```python
|
| 145 |
+
messages = [
|
| 146 |
+
{
|
| 147 |
+
"role": "system",
|
| 148 |
+
"content": [{"type": "text", "text": "You are a helpful assistant."}]
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"role": "user",
|
| 152 |
+
"content": [
|
| 153 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
|
| 154 |
+
{"type": "text", "text": "What animal is on the candy?"}
|
| 155 |
+
]
|
| 156 |
+
}
|
| 157 |
+
]
|
| 158 |
+
output = pipe(text=messages, max_new_tokens=200)
|
| 159 |
+
print(output[0]["generated_text"][-1]["content"])
|
| 160 |
+
# Okay, let's take a look!
|
| 161 |
+
# Based on the image, the animal on the candy is a **turtle**.
|
| 162 |
+
# You can see the shell shape and the head and legs.
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
#### Running the model on a single GPU
|
| 166 |
+
|
| 167 |
+
```python
|
| 168 |
+
from transformers import AutoProcessor, Gemma3nForConditionalGeneration
|
| 169 |
+
from PIL import Image
|
| 170 |
+
import requests
|
| 171 |
+
import torch
|
| 172 |
+
model_id = "google/gemma-3n-e4b-it"
|
| 173 |
+
model = Gemma3nForConditionalGeneration.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16,).eval()
|
| 174 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 175 |
+
messages = [
|
| 176 |
+
{
|
| 177 |
+
"role": "system",
|
| 178 |
+
"content": [{"type": "text", "text": "You are a helpful assistant."}]
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"role": "user",
|
| 182 |
+
"content": [
|
| 183 |
+
{"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
|
| 184 |
+
{"type": "text", "text": "Describe this image in detail."}
|
| 185 |
+
]
|
| 186 |
+
}
|
| 187 |
+
]
|
| 188 |
+
inputs = processor.apply_chat_template(
|
| 189 |
+
messages,
|
| 190 |
+
add_generation_prompt=True,
|
| 191 |
+
tokenize=True,
|
| 192 |
+
return_dict=True,
|
| 193 |
+
return_tensors="pt",
|
| 194 |
+
).to(model.device)
|
| 195 |
+
input_len = inputs["input_ids"].shape[-1]
|
| 196 |
+
with torch.inference_mode():
|
| 197 |
+
generation = model.generate(**inputs, max_new_tokens=100, do_sample=False)
|
| 198 |
+
generation = generation[0][input_len:]
|
| 199 |
+
decoded = processor.decode(generation, skip_special_tokens=True)
|
| 200 |
+
print(decoded)
|
| 201 |
+
# **Overall Impression:** The image is a close-up shot of a vibrant garden scene,
|
| 202 |
+
# focusing on a cluster of pink cosmos flowers and a busy bumblebee.
|
| 203 |
+
# It has a slightly soft, natural feel, likely captured in daylight.
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
### Citation
|
| 207 |
+
|
| 208 |
+
```
|
| 209 |
+
@article{gemma_3n_2025,
|
| 210 |
+
title={Gemma 3n},
|
| 211 |
+
url={https://ai.google.dev/gemma/docs/gemma-3n},
|
| 212 |
+
publisher={Google DeepMind},
|
| 213 |
+
author={Gemma Team},
|
| 214 |
+
year={2025}
|
| 215 |
+
}
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
## Model Data
|
| 219 |
+
|
| 220 |
+
Data used for model training and how the data was processed.
|
| 221 |
+
|
| 222 |
+
### Training Dataset
|
| 223 |
+
|
| 224 |
+
These models were trained on a dataset that includes a wide variety of sources
|
| 225 |
+
totalling approximately 11 trillion tokens. The knowledge cutoff date for the
|
| 226 |
+
training data was June 2024. Here are the key components:
|
| 227 |
+
|
| 228 |
+
- **Web Documents**: A diverse collection of web text ensures the model
|
| 229 |
+
is exposed to a broad range of linguistic styles, topics, and vocabulary.
|
| 230 |
+
The training dataset includes content in over 140 languages.
|
| 231 |
+
- **Code**: Exposing the model to code helps it to learn the syntax and
|
| 232 |
+
patterns of programming languages, which improves its ability to generate
|
| 233 |
+
code and understand code-related questions.
|
| 234 |
+
- **Mathematics**: Training on mathematical text helps the model learn
|
| 235 |
+
logical reasoning, symbolic representation, and to address mathematical queries.
|
| 236 |
+
- **Images**: A wide range of images enables the model to perform image
|
| 237 |
+
analysis and visual data extraction tasks.
|
| 238 |
+
- Audio: A diverse set of sound samples enables the model to recognize
|
| 239 |
+
speech, transcribe text from recordings, and identify information in audio data.
|
| 240 |
+
The combination of these diverse data sources is crucial for training a
|
| 241 |
+
powerful multimodal model that can handle a wide variety of different tasks and
|
| 242 |
+
data formats.
|
| 243 |
+
|
| 244 |
+
### Data Preprocessing
|
| 245 |
+
|
| 246 |
+
Here are the key data cleaning and filtering methods applied to the training
|
| 247 |
+
data:
|
| 248 |
+
|
| 249 |
+
- **CSAM Filtering**: Rigorous CSAM (Child Sexual Abuse Material)
|
| 250 |
+
filtering was applied at multiple stages in the data preparation process to
|
| 251 |
+
ensure the exclusion of harmful and illegal content.
|
| 252 |
+
- **Sensitive Data Filtering**: As part of making Gemma pre-trained models
|
| 253 |
+
safe and reliable, automated techniques were used to filter out certain
|
| 254 |
+
personal information and other sensitive data from training sets.
|
| 255 |
+
- **Additional methods**: Filtering based on content quality and safety in
|
| 256 |
+
line with
|
| 257 |
+
[our policies](https://ai.google/static/documents/ai-responsibility-update-published-february-2025.pdf).
|
| 258 |
+
## Implementation Information
|
| 259 |
+
|
| 260 |
+
Details about the model internals.
|
| 261 |
+
|
| 262 |
+
### Hardware
|
| 263 |
+
|
| 264 |
+
Gemma was trained using [Tensor Processing Unit
|
| 265 |
+
(TPU)](https://cloud.google.com/tpu/docs/intro-to-tpu) hardware (TPUv4p, TPUv5p
|
| 266 |
+
and TPUv5e). Training generative models requires significant computational
|
| 267 |
+
power. TPUs, designed specifically for matrix operations common in machine
|
| 268 |
+
learning, offer several advantages in this domain:
|
| 269 |
+
|
| 270 |
+
- **Performance**: TPUs are specifically designed to handle the massive
|
| 271 |
+
computations involved in training generative models. They can speed up
|
| 272 |
+
training considerably compared to CPUs.
|
| 273 |
+
- **Memory**: TPUs often come with large amounts of high-bandwidth memory,
|
| 274 |
+
allowing for the handling of large models and batch sizes during training.
|
| 275 |
+
This can lead to better model quality.
|
| 276 |
+
- **Scalability**: TPU Pods (large clusters of TPUs) provide a scalable
|
| 277 |
+
solution for handling the growing complexity of large foundation models.
|
| 278 |
+
You can distribute training across multiple TPU devices for faster and more
|
| 279 |
+
efficient processing.
|
| 280 |
+
- **Cost-effectiveness**: In many scenarios, TPUs can provide a more
|
| 281 |
+
cost-effective solution for training large models compared to CPU-based
|
| 282 |
+
infrastructure, especially when considering the time and resources saved
|
| 283 |
+
due to faster training.
|
| 284 |
+
These advantages are aligned with
|
| 285 |
+
[Google's commitments to operate sustainably](https://sustainability.google/operating-sustainably/).
|
| 286 |
+
|
| 287 |
+
### Software
|
| 288 |
+
|
| 289 |
+
Training was done using [JAX](https://github.com/jax-ml/jax) and
|
| 290 |
+
[ML Pathways](https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture/).
|
| 291 |
+
JAX allows researchers to take advantage of the latest generation of hardware,
|
| 292 |
+
including TPUs, for faster and more efficient training of large models. ML
|
| 293 |
+
Pathways is Google's latest effort to build artificially intelligent systems
|
| 294 |
+
capable of generalizing across multiple tasks. This is specially suitable for
|
| 295 |
+
foundation models, including large language models like these ones.
|
| 296 |
+
|
| 297 |
+
Together, JAX and ML Pathways are used as described in the
|
| 298 |
+
[paper about the Gemini family of models](https://goo.gle/gemma2report):
|
| 299 |
+
*"the 'single controller' programming model of Jax and Pathways allows a single
|
| 300 |
+
Python process to orchestrate the entire training run, dramatically simplifying
|
| 301 |
+
the development workflow."*
|
| 302 |
+
|
| 303 |
+
## Evaluation
|
| 304 |
+
|
| 305 |
+
Model evaluation metrics and results.
|
| 306 |
+
|
| 307 |
+
### Benchmark Results
|
| 308 |
+
|
| 309 |
+
These models were evaluated at full precision (float32) against a large
|
| 310 |
+
collection of different datasets and metrics to cover different aspects of
|
| 311 |
+
content generation. Evaluation results marked with **IT** are for
|
| 312 |
+
instruction-tuned models. Evaluation results marked with **PT** are for
|
| 313 |
+
pre-trained models.
|
| 314 |
+
|
| 315 |
+
#### Reasoning and factuality
|
| 316 |
+
|
| 317 |
+
| Benchmark | Metric | n-shot | E2B PT | E4B PT |
|
| 318 |
+
| ------------------------------ |----------------|----------|:--------:|:--------:|
|
| 319 |
+
| [HellaSwag][hellaswag] | Accuracy | 10-shot | 72.2 | 78.6 |
|
| 320 |
+
| [BoolQ][boolq] | Accuracy | 0-shot | 76.4 | 81.6 |
|
| 321 |
+
| [PIQA][piqa] | Accuracy | 0-shot | 78.9 | 81.0 |
|
| 322 |
+
| [SocialIQA][socialiqa] | Accuracy | 0-shot | 48.8 | 50.0 |
|
| 323 |
+
| [TriviaQA][triviaqa] | Accuracy | 5-shot | 60.8 | 70.2 |
|
| 324 |
+
| [Natural Questions][naturalq] | Accuracy | 5-shot | 15.5 | 20.9 |
|
| 325 |
+
| [ARC-c][arc] | Accuracy | 25-shot | 51.7 | 61.6 |
|
| 326 |
+
| [ARC-e][arc] | Accuracy | 0-shot | 75.8 | 81.6 |
|
| 327 |
+
| [WinoGrande][winogrande] | Accuracy | 5-shot | 66.8 | 71.7 |
|
| 328 |
+
| [BIG-Bench Hard][bbh] | Accuracy | few-shot | 44.3 | 52.9 |
|
| 329 |
+
| [DROP][drop] | Token F1 score | 1-shot | 53.9 | 60.8 |
|
| 330 |
+
|
| 331 |
+
[hellaswag]: https://arxiv.org/abs/1905.07830
|
| 332 |
+
[boolq]: https://arxiv.org/abs/1905.10044
|
| 333 |
+
[piqa]: https://arxiv.org/abs/1911.11641
|
| 334 |
+
[socialiqa]: https://arxiv.org/abs/1904.09728
|
| 335 |
+
[triviaqa]: https://arxiv.org/abs/1705.03551
|
| 336 |
+
[naturalq]: https://github.com/google-research-datasets/natural-questions
|
| 337 |
+
[arc]: https://arxiv.org/abs/1911.01547
|
| 338 |
+
[winogrande]: https://arxiv.org/abs/1907.10641
|
| 339 |
+
[bbh]: https://paperswithcode.com/dataset/bbh
|
| 340 |
+
[drop]: https://arxiv.org/abs/1903.00161
|
| 341 |
+
|
| 342 |
+
#### Multilingual
|
| 343 |
+
|
| 344 |
+
| Benchmark | Metric | n-shot | E2B IT | E4B IT |
|
| 345 |
+
| ------------------------------------|-------------------------|----------|:--------:|:--------:|
|
| 346 |
+
| [MGSM][mgsm] | Accuracy | 0-shot | 53.1 | 60.7 |
|
| 347 |
+
| [WMT24++][wmt24pp] (ChrF) | Character-level F-score | 0-shot | 42.7 | 50.1 |
|
| 348 |
+
| [Include][include] | Accuracy | 0-shot | 38.6 | 57.2 |
|
| 349 |
+
| [MMLU][mmlu] (ProX) | Accuracy | 0-shot | 8.1 | 19.9 |
|
| 350 |
+
| [OpenAI MMLU][openai-mmlu] | Accuracy | 0-shot | 22.3 | 35.6 |
|
| 351 |
+
| [Global-MMLU][global-mmlu] | Accuracy | 0-shot | 55.1 | 60.3 |
|
| 352 |
+
| [ECLeKTic][eclektic] | ECLeKTic score | 0-shot | 2.5 | 1.9 |
|
| 353 |
+
|
| 354 |
+
[mgsm]: https://arxiv.org/abs/2210.03057
|
| 355 |
+
[wmt24pp]: https://arxiv.org/abs/2502.12404v1
|
| 356 |
+
[include]:https://arxiv.org/abs/2411.19799
|
| 357 |
+
[mmlu]: https://arxiv.org/abs/2009.03300
|
| 358 |
+
[openai-mmlu]: https://huggingface.co/datasets/openai/MMMLU
|
| 359 |
+
[global-mmlu]: https://huggingface.co/datasets/CohereLabs/Global-MMLU
|
| 360 |
+
[eclektic]: https://arxiv.org/abs/2502.21228
|
| 361 |
+
|
| 362 |
+
#### STEM and code
|
| 363 |
+
|
| 364 |
+
| Benchmark | Metric | n-shot | E2B IT | E4B IT |
|
| 365 |
+
| ------------------------------------|--------------------------|----------|:--------:|:--------:|
|
| 366 |
+
| [GPQA][gpqa] Diamond | RelaxedAccuracy/accuracy | 0-shot | 24.8 | 23.7 |
|
| 367 |
+
| [LiveCodeBench][lcb] v5 | pass@1 | 0-shot | 18.6 | 25.7 |
|
| 368 |
+
| Codegolf v2.2 | pass@1 | 0-shot | 11.0 | 16.8 |
|
| 369 |
+
| [AIME 2025][aime-2025] | Accuracy | 0-shot | 6.7 | 11.6 |
|
| 370 |
+
|
| 371 |
+
[gpqa]: https://arxiv.org/abs/2311.12022
|
| 372 |
+
[lcb]: https://arxiv.org/abs/2403.07974
|
| 373 |
+
[aime-2025]: https://www.vals.ai/benchmarks/aime-2025-05-09
|
| 374 |
+
|
| 375 |
+
#### Additional benchmarks
|
| 376 |
+
|
| 377 |
+
| Benchmark | Metric | n-shot | E2B IT | E4B IT |
|
| 378 |
+
| ------------------------------------ |------------|----------|:--------:|:--------:|
|
| 379 |
+
| [MMLU][mmlu] | Accuracy | 0-shot | 60.1 | 64.9 |
|
| 380 |
+
| [MBPP][mbpp] | pass@1 | 3-shot | 56.6 | 63.6 |
|
| 381 |
+
| [HumanEval][humaneval] | pass@1 | 0-shot | 66.5 | 75.0 |
|
| 382 |
+
| [LiveCodeBench][lcb] | pass@1 | 0-shot | 13.2 | 13.2 |
|
| 383 |
+
| HiddenMath | Accuracy | 0-shot | 27.7 | 37.7 |
|
| 384 |
+
| [Global-MMLU-Lite][global-mmlu-lite] | Accuracy | 0-shot | 59.0 | 64.5 |
|
| 385 |
+
| [MMLU][mmlu] (Pro) | Accuracy | 0-shot | 40.5 | 50.6 |
|
| 386 |
+
|
| 387 |
+
[gpqa]: https://arxiv.org/abs/2311.12022
|
| 388 |
+
[mbpp]: https://arxiv.org/abs/2108.07732
|
| 389 |
+
[humaneval]: https://arxiv.org/abs/2107.03374
|
| 390 |
+
[lcb]: https://arxiv.org/abs/2403.07974
|
| 391 |
+
[global-mmlu-lite]: https://huggingface.co/datasets/CohereForAI/Global-MMLU-Lite
|
| 392 |
+
|
| 393 |
+
## Ethics and Safety
|
| 394 |
+
|
| 395 |
+
Ethics and safety evaluation approach and results.
|
| 396 |
+
|
| 397 |
+
### Evaluation Approach
|
| 398 |
+
|
| 399 |
+
Our evaluation methods include structured evaluations and internal red-teaming
|
| 400 |
+
testing of relevant content policies. Red-teaming was conducted by a number of
|
| 401 |
+
different teams, each with different goals and human evaluation metrics. These
|
| 402 |
+
models were evaluated against a number of different categories relevant to
|
| 403 |
+
ethics and safety, including:
|
| 404 |
+
|
| 405 |
+
- **Child Safety**: Evaluation of text-to-text and image to text prompts
|
| 406 |
+
covering child safety policies, including child sexual abuse and
|
| 407 |
+
exploitation.
|
| 408 |
+
- **Content Safety:** Evaluation of text-to-text and image to text prompts
|
| 409 |
+
covering safety policies including, harassment, violence and gore, and hate
|
| 410 |
+
speech.
|
| 411 |
+
- **Representational Harms**: Evaluation of text-to-text and image to text
|
| 412 |
+
prompts covering safety policies including bias, stereotyping, and harmful
|
| 413 |
+
associations or inaccuracies.
|
| 414 |
+
In addition to development level evaluations, we conduct "assurance
|
| 415 |
+
evaluations" which are our 'arms-length' internal evaluations for responsibility
|
| 416 |
+
governance decision making. They are conducted separately from the model
|
| 417 |
+
development team, to inform decision making about release. High level findings
|
| 418 |
+
are fed back to the model team, but prompt sets are held-out to prevent
|
| 419 |
+
overfitting and preserve the results' ability to inform decision making. Notable
|
| 420 |
+
assurance evaluation results are reported to our Responsibility & Safety Council
|
| 421 |
+
as part of release review.
|
| 422 |
+
|
| 423 |
+
### Evaluation Results
|
| 424 |
+
|
| 425 |
+
For all areas of safety testing, we saw safe levels of performance across the
|
| 426 |
+
categories of child safety, content safety, and representational harms relative
|
| 427 |
+
to previous Gemma models. All testing was conducted without safety filters to
|
| 428 |
+
evaluate the model capabilities and behaviors. For text-to-text, image-to-text,
|
| 429 |
+
and audio-to-text, and across all model sizes, the model produced minimal policy
|
| 430 |
+
violations, and showed significant improvements over previous Gemma models'
|
| 431 |
+
performance with respect to high severity violations. A limitation of our
|
| 432 |
+
evaluations was they included primarily English language prompts.
|
| 433 |
+
|
| 434 |
+
## Usage and Limitations
|
| 435 |
+
|
| 436 |
+
These models have certain limitations that users should be aware of.
|
| 437 |
+
|
| 438 |
+
### Intended Usage
|
| 439 |
+
|
| 440 |
+
Open generative models have a wide range of applications across various
|
| 441 |
+
industries and domains. The following list of potential uses is not
|
| 442 |
+
comprehensive. The purpose of this list is to provide contextual information
|
| 443 |
+
about the possible use-cases that the model creators considered as part of model
|
| 444 |
+
training and development.
|
| 445 |
+
|
| 446 |
+
- Content Creation and Communication
|
| 447 |
+
- **Text Generation**: Generate creative text formats such as
|
| 448 |
+
poems, scripts, code, marketing copy, and email drafts.
|
| 449 |
+
- **Chatbots and Conversational AI**: Power conversational
|
| 450 |
+
interfaces for customer service, virtual assistants, or interactive
|
| 451 |
+
applications.
|
| 452 |
+
- **Text Summarization**: Generate concise summaries of a text
|
| 453 |
+
corpus, research papers, or reports.
|
| 454 |
+
- **Image Data Extraction**: Extract, interpret, and summarize
|
| 455 |
+
visual data for text communications.
|
| 456 |
+
- **Audio Data Extraction**: Transcribe spoken language, translate speech
|
| 457 |
+
to text in other languages, and analyze sound-based data.
|
| 458 |
+
- Research and Education
|
| 459 |
+
- **Natural Language Processing (NLP) and generative model
|
| 460 |
+
Research**: These models can serve as a foundation for researchers to
|
| 461 |
+
experiment with generative models and NLP techniques, develop
|
| 462 |
+
algorithms, and contribute to the advancement of the field.
|
| 463 |
+
- **Language Learning Tools**: Support interactive language
|
| 464 |
+
learning experiences, aiding in grammar correction or providing writing
|
| 465 |
+
practice.
|
| 466 |
+
- **Knowledge Exploration**: Assist researchers in exploring large
|
| 467 |
+
bodies of data by generating summaries or answering questions about
|
| 468 |
+
specific topics.
|
| 469 |
+
### Limitations
|
| 470 |
+
|
| 471 |
+
- Training Data
|
| 472 |
+
- The quality and diversity of the training data significantly
|
| 473 |
+
influence the model's capabilities. Biases or gaps in the training data
|
| 474 |
+
can lead to limitations in the model's responses.
|
| 475 |
+
- The scope of the training dataset determines the subject areas
|
| 476 |
+
the model can handle effectively.
|
| 477 |
+
- Context and Task Complexity
|
| 478 |
+
- Models are better at tasks that can be framed with clear
|
| 479 |
+
prompts and instructions. Open-ended or highly complex tasks might be
|
| 480 |
+
challenging.
|
| 481 |
+
- A model's performance can be influenced by the amount of context
|
| 482 |
+
provided (longer context generally leads to better outputs, up to a
|
| 483 |
+
certain point).
|
| 484 |
+
- Language Ambiguity and Nuance
|
| 485 |
+
- Natural language is inherently complex. Models might struggle
|
| 486 |
+
to grasp subtle nuances, sarcasm, or figurative language.
|
| 487 |
+
- Factual Accuracy
|
| 488 |
+
- Models generate responses based on information they learned
|
| 489 |
+
from their training datasets, but they are not knowledge bases. They
|
| 490 |
+
may generate incorrect or outdated factual statements.
|
| 491 |
+
- Common Sense
|
| 492 |
+
- Models rely on statistical patterns in language. They might
|
| 493 |
+
lack the ability to apply common sense reasoning in certain situations.
|
| 494 |
+
### Ethical Considerations and Risks
|
| 495 |
+
|
| 496 |
+
The development of generative models raises several ethical concerns. In
|
| 497 |
+
creating an open model, we have carefully considered the following:
|
| 498 |
+
|
| 499 |
+
- Bias and Fairness
|
| 500 |
+
- Generative models trained on large-scale, real-world text and image data
|
| 501 |
+
can reflect socio-cultural biases embedded in the training material.
|
| 502 |
+
These models underwent careful scrutiny, input data pre-processing
|
| 503 |
+
described and posterior evaluations reported in this card.
|
| 504 |
+
- Misinformation and Misuse
|
| 505 |
+
- Generative models can be misused to generate text that is
|
| 506 |
+
false, misleading, or harmful.
|
| 507 |
+
- Guidelines are provided for responsible use with the model, see the
|
| 508 |
+
[Responsible Generative AI Toolkit](https://ai.google.dev/responsible).
|
| 509 |
+
- Transparency and Accountability:
|
| 510 |
+
- This model card summarizes details on the models' architecture,
|
| 511 |
+
capabilities, limitations, and evaluation processes.
|
| 512 |
+
- A responsibly developed open model offers the opportunity to
|
| 513 |
+
share innovation by making generative model technology accessible to
|
| 514 |
+
developers and researchers across the AI ecosystem.
|
| 515 |
+
Risks identified and mitigations:
|
| 516 |
+
|
| 517 |
+
- **Perpetuation of biases**: It's encouraged to perform continuous monitoring
|
| 518 |
+
(using evaluation metrics, human review) and the exploration of de-biasing
|
| 519 |
+
techniques during model training, fine-tuning, and other use cases.
|
| 520 |
+
- **Generation of harmful content**: Mechanisms and guidelines for content
|
| 521 |
+
safety are essential. Developers are encouraged to exercise caution and
|
| 522 |
+
implement appropriate content safety safeguards based on their specific
|
| 523 |
+
product policies and application use cases.
|
| 524 |
+
- **Misuse for malicious purposes**: Technical limitations and developer
|
| 525 |
+
and end-user education can help mitigate against malicious applications of
|
| 526 |
+
generative models. Educational resources and reporting mechanisms for users
|
| 527 |
+
to flag misuse are provided. Prohibited uses of Gemma models are outlined
|
| 528 |
+
in the
|
| 529 |
+
[Gemma Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy).
|
| 530 |
+
- **Privacy violations**: Models were trained on data filtered for removal of
|
| 531 |
+
certain personal information and other sensitive data. Developers are
|
| 532 |
+
encouraged to adhere to privacy regulations with privacy-preserving
|
| 533 |
+
techniques.
|
| 534 |
+
### Benefits
|
| 535 |
+
|
| 536 |
+
At the time of release, this family of models provides high-performance open
|
| 537 |
+
generative model implementations designed from the ground up for responsible AI
|
| 538 |
+
development compared to similarly sized models.
|
| 539 |
+
|
| 540 |
+
Using the benchmark evaluation metrics described in this document, these models
|
| 541 |
+
have shown to provide superior performance to other, comparably-sized open model
|
| 542 |
+
alternatives.
|