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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Quantization made by Richard Erkhov.
|
2 |
+
|
3 |
+
[Github](https://github.com/RichardErkhov)
|
4 |
+
|
5 |
+
[Discord](https://discord.gg/pvy7H8DZMG)
|
6 |
+
|
7 |
+
[Request more models](https://github.com/RichardErkhov/quant_request)
|
8 |
+
|
9 |
+
|
10 |
+
gemma-7b-it - bnb 8bits
|
11 |
+
- Model creator: https://huggingface.co/google/
|
12 |
+
- Original model: https://huggingface.co/google/gemma-7b-it/
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
Original model description:
|
18 |
+
---
|
19 |
+
library_name: transformers
|
20 |
+
tags: []
|
21 |
+
widget:
|
22 |
+
- messages:
|
23 |
+
- role: user
|
24 |
+
content: How does the brain work?
|
25 |
+
inference:
|
26 |
+
parameters:
|
27 |
+
max_new_tokens: 200
|
28 |
+
extra_gated_heading: Access Gemma on Hugging Face
|
29 |
+
extra_gated_prompt: >-
|
30 |
+
To access Gemma on Hugging Face, you’re required to review and agree to
|
31 |
+
Google’s usage license. To do this, please ensure you’re logged-in to Hugging
|
32 |
+
Face and click below. Requests are processed immediately.
|
33 |
+
extra_gated_button_content: Acknowledge license
|
34 |
+
license: gemma
|
35 |
+
---
|
36 |
+
|
37 |
+
# Gemma Model Card
|
38 |
+
|
39 |
+
**Model Page**: [Gemma](https://ai.google.dev/gemma/docs)
|
40 |
+
|
41 |
+
This model card corresponds to the 7B instruct version of the Gemma model. You can also visit the model card of the [2B base model](https://huggingface.co/google/gemma-2b), [7B base model](https://huggingface.co/google/gemma-7b), and [2B instruct model](https://huggingface.co/google/gemma-2b-it).
|
42 |
+
|
43 |
+
**Resources and Technical Documentation**:
|
44 |
+
|
45 |
+
* [Responsible Generative AI Toolkit](https://ai.google.dev/responsible)
|
46 |
+
* [Gemma on Kaggle](https://www.kaggle.com/models/google/gemma)
|
47 |
+
* [Gemma on Vertex Model Garden](https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/335?version=gemma-7b-it-gg-hf)
|
48 |
+
|
49 |
+
**Terms of Use**: [Terms](https://www.kaggle.com/models/google/gemma/license/consent)
|
50 |
+
|
51 |
+
**Authors**: Google
|
52 |
+
|
53 |
+
## Model Information
|
54 |
+
|
55 |
+
Summary description and brief definition of inputs and outputs.
|
56 |
+
|
57 |
+
### Description
|
58 |
+
|
59 |
+
Gemma is a family of lightweight, state-of-the-art open models from Google,
|
60 |
+
built from the same research and technology used to create the Gemini models.
|
61 |
+
They are text-to-text, decoder-only large language models, available in English,
|
62 |
+
with open weights, pre-trained variants, and instruction-tuned variants. Gemma
|
63 |
+
models are well-suited for a variety of text generation tasks, including
|
64 |
+
question answering, summarization, and reasoning. Their relatively small size
|
65 |
+
makes it possible to deploy them in environments with limited resources such as
|
66 |
+
a laptop, desktop or your own cloud infrastructure, democratizing access to
|
67 |
+
state of the art AI models and helping foster innovation for everyone.
|
68 |
+
|
69 |
+
### Usage
|
70 |
+
|
71 |
+
Below we share some code snippets on how to get quickly started with running the model. First make sure to `pip install -U transformers`, then copy the snippet from the section that is relevant for your usecase.
|
72 |
+
|
73 |
+
#### Fine-tuning the model
|
74 |
+
|
75 |
+
You can find fine-tuning scripts and notebook under the [`examples/` directory](https://huggingface.co/google/gemma-7b/tree/main/examples) of [`google/gemma-7b`](https://huggingface.co/google/gemma-7b) repository. To adapt it to this model, simply change the model-id to `google/gemma-7b-it`.
|
76 |
+
In that repository, we provide:
|
77 |
+
|
78 |
+
* A script to perform Supervised Fine-Tuning (SFT) on UltraChat dataset using QLoRA
|
79 |
+
* A script to perform SFT using FSDP on TPU devices
|
80 |
+
* A notebook that you can run on a free-tier Google Colab instance to perform SFT on English quotes dataset
|
81 |
+
|
82 |
+
|
83 |
+
#### Running the model on a CPU
|
84 |
+
|
85 |
+
As explained below, we recommend `torch.bfloat16` as the default dtype. You can use [a different precision](#precisions) if necessary.
|
86 |
+
|
87 |
+
```python
|
88 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
89 |
+
import torch
|
90 |
+
|
91 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
|
92 |
+
model = AutoModelForCausalLM.from_pretrained(
|
93 |
+
"google/gemma-7b-it",
|
94 |
+
torch_dtype=torch.bfloat16
|
95 |
+
)
|
96 |
+
|
97 |
+
input_text = "Write me a poem about Machine Learning."
|
98 |
+
input_ids = tokenizer(input_text, return_tensors="pt")
|
99 |
+
|
100 |
+
outputs = model.generate(**input_ids)
|
101 |
+
print(tokenizer.decode(outputs[0]))
|
102 |
+
```
|
103 |
+
|
104 |
+
|
105 |
+
#### Running the model on a single / multi GPU
|
106 |
+
|
107 |
+
|
108 |
+
```python
|
109 |
+
# pip install accelerate
|
110 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
111 |
+
import torch
|
112 |
+
|
113 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
|
114 |
+
model = AutoModelForCausalLM.from_pretrained(
|
115 |
+
"google/gemma-7b-it",
|
116 |
+
device_map="auto",
|
117 |
+
torch_dtype=torch.bfloat16
|
118 |
+
)
|
119 |
+
|
120 |
+
input_text = "Write me a poem about Machine Learning."
|
121 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
122 |
+
|
123 |
+
outputs = model.generate(**input_ids)
|
124 |
+
print(tokenizer.decode(outputs[0]))
|
125 |
+
```
|
126 |
+
|
127 |
+
<a name="precisions"></a>
|
128 |
+
#### Running the model on a GPU using different precisions
|
129 |
+
|
130 |
+
The native weights of this model were exported in `bfloat16` precision. You can use `float16`, which may be faster on certain hardware, indicating the `torch_dtype` when loading the model. For convenience, the `float16` revision of the repo contains a copy of the weights already converted to that precision.
|
131 |
+
|
132 |
+
You can also use `float32` if you skip the dtype, but no precision increase will occur (model weights will just be upcasted to `float32`). See examples below.
|
133 |
+
|
134 |
+
* _Using `torch.float16`_
|
135 |
+
|
136 |
+
```python
|
137 |
+
# pip install accelerate
|
138 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
139 |
+
import torch
|
140 |
+
|
141 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
|
142 |
+
model = AutoModelForCausalLM.from_pretrained(
|
143 |
+
"google/gemma-7b-it",
|
144 |
+
device_map="auto",
|
145 |
+
torch_dtype=torch.float16,
|
146 |
+
revision="float16",
|
147 |
+
)
|
148 |
+
|
149 |
+
input_text = "Write me a poem about Machine Learning."
|
150 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
151 |
+
|
152 |
+
outputs = model.generate(**input_ids)
|
153 |
+
print(tokenizer.decode(outputs[0]))
|
154 |
+
```
|
155 |
+
|
156 |
+
* _Using `torch.bfloat16`_
|
157 |
+
|
158 |
+
```python
|
159 |
+
# pip install accelerate
|
160 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
161 |
+
|
162 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
|
163 |
+
model = AutoModelForCausalLM.from_pretrained("google/gemma-7b-it", device_map="auto", torch_dtype=torch.bfloat16)
|
164 |
+
|
165 |
+
input_text = "Write me a poem about Machine Learning."
|
166 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
167 |
+
|
168 |
+
outputs = model.generate(**input_ids)
|
169 |
+
print(tokenizer.decode(outputs[0]))
|
170 |
+
```
|
171 |
+
|
172 |
+
* _Upcasting to `torch.float32`_
|
173 |
+
|
174 |
+
```python
|
175 |
+
# pip install accelerate
|
176 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
177 |
+
|
178 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
|
179 |
+
model = AutoModelForCausalLM.from_pretrained(
|
180 |
+
"google/gemma-7b-it",
|
181 |
+
device_map="auto"
|
182 |
+
)
|
183 |
+
|
184 |
+
input_text = "Write me a poem about Machine Learning."
|
185 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
186 |
+
|
187 |
+
outputs = model.generate(**input_ids)
|
188 |
+
print(tokenizer.decode(outputs[0]))
|
189 |
+
```
|
190 |
+
|
191 |
+
#### Quantized Versions through `bitsandbytes`
|
192 |
+
|
193 |
+
* _Using 8-bit precision (int8)_
|
194 |
+
|
195 |
+
```python
|
196 |
+
# pip install bitsandbytes accelerate
|
197 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
198 |
+
|
199 |
+
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
200 |
+
|
201 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
|
202 |
+
model = AutoModelForCausalLM.from_pretrained("google/gemma-7b-it", quantization_config=quantization_config)
|
203 |
+
|
204 |
+
input_text = "Write me a poem about Machine Learning."
|
205 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
206 |
+
|
207 |
+
outputs = model.generate(**input_ids)
|
208 |
+
print(tokenizer.decode(outputs[0]))
|
209 |
+
```
|
210 |
+
|
211 |
+
* _Using 4-bit precision_
|
212 |
+
|
213 |
+
```python
|
214 |
+
# pip install bitsandbytes accelerate
|
215 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
216 |
+
|
217 |
+
quantization_config = BitsAndBytesConfig(load_in_4bit=True)
|
218 |
+
|
219 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
|
220 |
+
model = AutoModelForCausalLM.from_pretrained("google/gemma-7b-it", quantization_config=quantization_config)
|
221 |
+
|
222 |
+
input_text = "Write me a poem about Machine Learning."
|
223 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
224 |
+
|
225 |
+
outputs = model.generate(**input_ids)
|
226 |
+
print(tokenizer.decode(outputs[0]))
|
227 |
+
```
|
228 |
+
|
229 |
+
|
230 |
+
#### Other optimizations
|
231 |
+
|
232 |
+
* _Flash Attention 2_
|
233 |
+
|
234 |
+
First make sure to install `flash-attn` in your environment `pip install flash-attn`
|
235 |
+
|
236 |
+
```diff
|
237 |
+
model = AutoModelForCausalLM.from_pretrained(
|
238 |
+
model_id,
|
239 |
+
torch_dtype=torch.float16,
|
240 |
+
+ attn_implementation="flash_attention_2"
|
241 |
+
).to(0)
|
242 |
+
```
|
243 |
+
|
244 |
+
### Chat Template
|
245 |
+
|
246 |
+
The instruction-tuned models use a chat template that must be adhered to for conversational use.
|
247 |
+
The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.
|
248 |
+
|
249 |
+
Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:
|
250 |
+
|
251 |
+
```py
|
252 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
253 |
+
import transformers
|
254 |
+
import torch
|
255 |
+
|
256 |
+
model_id = "google/gemma-7b-it"
|
257 |
+
dtype = torch.bfloat16
|
258 |
+
|
259 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
260 |
+
model = AutoModelForCausalLM.from_pretrained(
|
261 |
+
model_id,
|
262 |
+
device_map="cuda",
|
263 |
+
torch_dtype=dtype,
|
264 |
+
)
|
265 |
+
|
266 |
+
chat = [
|
267 |
+
{ "role": "user", "content": "Write a hello world program" },
|
268 |
+
]
|
269 |
+
prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
270 |
+
```
|
271 |
+
|
272 |
+
At this point, the prompt contains the following text:
|
273 |
+
|
274 |
+
```
|
275 |
+
<bos><start_of_turn>user
|
276 |
+
Write a hello world program<end_of_turn>
|
277 |
+
<start_of_turn>model
|
278 |
+
```
|
279 |
+
|
280 |
+
As you can see, each turn is preceded by a `<start_of_turn>` delimiter and then the role of the entity
|
281 |
+
(either `user`, for content supplied by the user, or `model` for LLM responses). Turns finish with
|
282 |
+
the `<end_of_turn>` token.
|
283 |
+
|
284 |
+
You can follow this format to build the prompt manually, if you need to do it without the tokenizer's
|
285 |
+
chat template.
|
286 |
+
|
287 |
+
After the prompt is ready, generation can be performed like this:
|
288 |
+
|
289 |
+
```py
|
290 |
+
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
|
291 |
+
outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
|
292 |
+
print(tokenizer.decode(outputs[0]))
|
293 |
+
```
|
294 |
+
|
295 |
+
### Inputs and outputs
|
296 |
+
|
297 |
+
* **Input:** Text string, such as a question, a prompt, or a document to be
|
298 |
+
summarized.
|
299 |
+
* **Output:** Generated English-language text in response to the input, such
|
300 |
+
as an answer to a question, or a summary of a document.
|
301 |
+
|
302 |
+
## Model Data
|
303 |
+
|
304 |
+
Data used for model training and how the data was processed.
|
305 |
+
|
306 |
+
### Training Dataset
|
307 |
+
|
308 |
+
These models were trained on a dataset of text data that includes a wide variety
|
309 |
+
of sources, totaling 6 trillion tokens. Here are the key components:
|
310 |
+
|
311 |
+
* Web Documents: A diverse collection of web text ensures the model is exposed
|
312 |
+
to a broad range of linguistic styles, topics, and vocabulary. Primarily
|
313 |
+
English-language content.
|
314 |
+
* Code: Exposing the model to code helps it to learn the syntax and patterns of
|
315 |
+
programming languages, which improves its ability to generate code or
|
316 |
+
understand code-related questions.
|
317 |
+
* Mathematics: Training on mathematical text helps the model learn logical
|
318 |
+
reasoning, symbolic representation, and to address mathematical queries.
|
319 |
+
|
320 |
+
The combination of these diverse data sources is crucial for training a powerful
|
321 |
+
language model that can handle a wide variety of different tasks and text
|
322 |
+
formats.
|
323 |
+
|
324 |
+
### Data Preprocessing
|
325 |
+
|
326 |
+
Here are the key data cleaning and filtering methods applied to the training
|
327 |
+
data:
|
328 |
+
|
329 |
+
* CSAM Filtering: Rigorous CSAM (Child Sexual Abuse Material) filtering was
|
330 |
+
applied at multiple stages in the data preparation process to ensure the
|
331 |
+
exclusion of harmful and illegal content
|
332 |
+
* Sensitive Data Filtering: As part of making Gemma pre-trained models safe and
|
333 |
+
reliable, automated techniques were used to filter out certain personal
|
334 |
+
information and other sensitive data from training sets.
|
335 |
+
* Additional methods: Filtering based on content quality and safely in line with
|
336 |
+
[our policies](https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11).
|
337 |
+
|
338 |
+
## Implementation Information
|
339 |
+
|
340 |
+
Details about the model internals.
|
341 |
+
|
342 |
+
### Hardware
|
343 |
+
|
344 |
+
Gemma was trained using the latest generation of
|
345 |
+
[Tensor Processing Unit (TPU)](https://cloud.google.com/tpu/docs/intro-to-tpu) hardware (TPUv5e).
|
346 |
+
|
347 |
+
Training large language models requires significant computational power. TPUs,
|
348 |
+
designed specifically for matrix operations common in machine learning, offer
|
349 |
+
several advantages in this domain:
|
350 |
+
|
351 |
+
* Performance: TPUs are specifically designed to handle the massive computations
|
352 |
+
involved in training LLMs. They can speed up training considerably compared to
|
353 |
+
CPUs.
|
354 |
+
* Memory: TPUs often come with large amounts of high-bandwidth memory, allowing
|
355 |
+
for the handling of large models and batch sizes during training. This can
|
356 |
+
lead to better model quality.
|
357 |
+
* Scalability: TPU Pods (large clusters of TPUs) provide a scalable solution for
|
358 |
+
handling the growing complexity of large foundation models. You can distribute
|
359 |
+
training across multiple TPU devices for faster and more efficient processing.
|
360 |
+
* Cost-effectiveness: In many scenarios, TPUs can provide a more cost-effective
|
361 |
+
solution for training large models compared to CPU-based infrastructure,
|
362 |
+
especially when considering the time and resources saved due to faster
|
363 |
+
training.
|
364 |
+
* These advantages are aligned with
|
365 |
+
[Google's commitments to operate sustainably](https://sustainability.google/operating-sustainably/).
|
366 |
+
|
367 |
+
### Software
|
368 |
+
|
369 |
+
Training was done using [JAX](https://github.com/google/jax) and [ML Pathways](https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture).
|
370 |
+
|
371 |
+
JAX allows researchers to take advantage of the latest generation of hardware,
|
372 |
+
including TPUs, for faster and more efficient training of large models.
|
373 |
+
|
374 |
+
ML Pathways is Google's latest effort to build artificially intelligent systems
|
375 |
+
capable of generalizing across multiple tasks. This is specially suitable for
|
376 |
+
[foundation models](https://ai.google/discover/foundation-models/), including large language models like
|
377 |
+
these ones.
|
378 |
+
|
379 |
+
Together, JAX and ML Pathways are used as described in the
|
380 |
+
[paper about the Gemini family of models](https://arxiv.org/abs/2312.11805); "the 'single
|
381 |
+
controller' programming model of Jax and Pathways allows a single Python
|
382 |
+
process to orchestrate the entire training run, dramatically simplifying the
|
383 |
+
development workflow."
|
384 |
+
|
385 |
+
## Evaluation
|
386 |
+
|
387 |
+
Model evaluation metrics and results.
|
388 |
+
|
389 |
+
### Benchmark Results
|
390 |
+
|
391 |
+
These models were evaluated against a large collection of different datasets and
|
392 |
+
metrics to cover different aspects of text generation:
|
393 |
+
|
394 |
+
| Benchmark | Metric | 2B Params | 7B Params |
|
395 |
+
| ------------------------------ | ------------- | ----------- | --------- |
|
396 |
+
| [MMLU](https://arxiv.org/abs/2009.03300) | 5-shot, top-1 | 42.3 | 64.3 |
|
397 |
+
| [HellaSwag](https://arxiv.org/abs/1905.07830) | 0-shot |71.4 | 81.2 |
|
398 |
+
| [PIQA](https://arxiv.org/abs/1911.11641) | 0-shot | 77.3 | 81.2 |
|
399 |
+
| [SocialIQA](https://arxiv.org/abs/1904.09728) | 0-shot | 49.7 | 51.8 |
|
400 |
+
| [BooIQ](https://arxiv.org/abs/1905.10044) | 0-shot | 69.4 | 83.2 |
|
401 |
+
| [WinoGrande](https://arxiv.org/abs/1907.10641) | partial score | 65.4 | 72.3 |
|
402 |
+
| [CommonsenseQA](https://arxiv.org/abs/1811.00937) | 7-shot | 65.3 | 71.3 |
|
403 |
+
| [OpenBookQA](https://arxiv.org/abs/1809.02789) | | 47.8 | 52.8 |
|
404 |
+
| [ARC-e](https://arxiv.org/abs/1911.01547) | | 73.2 | 81.5 |
|
405 |
+
| [ARC-c](https://arxiv.org/abs/1911.01547) | | 42.1 | 53.2 |
|
406 |
+
| [TriviaQA](https://arxiv.org/abs/1705.03551) | 5-shot | 53.2 | 63.4 |
|
407 |
+
| [Natural Questions](https://github.com/google-research-datasets/natural-questions) | 5-shot | 12.5 | 23 |
|
408 |
+
| [HumanEval](https://arxiv.org/abs/2107.03374) | pass@1 | 22.0 | 32.3 |
|
409 |
+
| [MBPP](https://arxiv.org/abs/2108.07732) | 3-shot | 29.2 | 44.4 |
|
410 |
+
| [GSM8K](https://arxiv.org/abs/2110.14168) | maj@1 | 17.7 | 46.4 |
|
411 |
+
| [MATH](https://arxiv.org/abs/2108.07732) | 4-shot | 11.8 | 24.3 |
|
412 |
+
| [AGIEval](https://arxiv.org/abs/2304.06364) | | 24.2 | 41.7 |
|
413 |
+
| [BIG-Bench](https://arxiv.org/abs/2206.04615) | | 35.2 | 55.1 |
|
414 |
+
| ------------------------------ | ------------- | ----------- | --------- |
|
415 |
+
| **Average** | | **45.0** | **56.9** |
|
416 |
+
|
417 |
+
|
418 |
+
## Ethics and Safety
|
419 |
+
|
420 |
+
Ethics and safety evaluation approach and results.
|
421 |
+
|
422 |
+
### Evaluation Approach
|
423 |
+
|
424 |
+
Our evaluation methods include structured evaluations and internal red-teaming
|
425 |
+
testing of relevant content policies. Red-teaming was conducted by a number of
|
426 |
+
different teams, each with different goals and human evaluation metrics. These
|
427 |
+
models were evaluated against a number of different categories relevant to
|
428 |
+
ethics and safety, including:
|
429 |
+
|
430 |
+
* Text-to-Text Content Safety: Human evaluation on prompts covering safety
|
431 |
+
policies including child sexual abuse and exploitation, harassment, violence
|
432 |
+
and gore, and hate speech.
|
433 |
+
* Text-to-Text Representational Harms: Benchmark against relevant academic
|
434 |
+
datasets such as [WinoBias](https://arxiv.org/abs/1804.06876) and [BBQ Dataset](https://arxiv.org/abs/2110.08193v2).
|
435 |
+
* Memorization: Automated evaluation of memorization of training data, including
|
436 |
+
the risk of personally identifiable information exposure.
|
437 |
+
* Large-scale harm: Tests for "dangerous capabilities," such as chemical,
|
438 |
+
biological, radiological, and nuclear (CBRN) risks.
|
439 |
+
|
440 |
+
### Evaluation Results
|
441 |
+
|
442 |
+
The results of ethics and safety evaluations are within acceptable thresholds
|
443 |
+
for meeting [internal policies](https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11) for categories such as child
|
444 |
+
safety, content safety, representational harms, memorization, large-scale harms.
|
445 |
+
On top of robust internal evaluations, the results of well known safety
|
446 |
+
benchmarks like BBQ, BOLD, Winogender, Winobias, RealToxicity, and TruthfulQA
|
447 |
+
are shown here.
|
448 |
+
|
449 |
+
| Benchmark | Metric | 2B Params | 7B Params |
|
450 |
+
| ------------------------------ | ------------- | ----------- | --------- |
|
451 |
+
| [RealToxicity](https://arxiv.org/abs/2009.11462) | average | 6.86 | 7.90 |
|
452 |
+
| [BOLD](https://arxiv.org/abs/2101.11718) | | 45.57 | 49.08 |
|
453 |
+
| [CrowS-Pairs](https://aclanthology.org/2020.emnlp-main.154/) | top-1 | 45.82 | 51.33 |
|
454 |
+
| [BBQ Ambig](https://arxiv.org/abs/2110.08193v2) | 1-shot, top-1 | 62.58 | 92.54 |
|
455 |
+
| [BBQ Disambig](https://arxiv.org/abs/2110.08193v2) | top-1 | 54.62 | 71.99 |
|
456 |
+
| [Winogender](https://arxiv.org/abs/1804.09301) | top-1 | 51.25 | 54.17 |
|
457 |
+
| [TruthfulQA](https://arxiv.org/abs/2109.07958) | | 44.84 | 31.81 |
|
458 |
+
| [Winobias 1_2](https://arxiv.org/abs/1804.06876) | | 56.12 | 59.09 |
|
459 |
+
| [Winobias 2_2](https://arxiv.org/abs/1804.06876) | | 91.10 | 92.23 |
|
460 |
+
| [Toxigen](https://arxiv.org/abs/2203.09509) | | 29.77 | 39.59 |
|
461 |
+
| ------------------------------ | ------------- | ----------- | --------- |
|
462 |
+
|
463 |
+
|
464 |
+
## Usage and Limitations
|
465 |
+
|
466 |
+
These models have certain limitations that users should be aware of.
|
467 |
+
|
468 |
+
### Intended Usage
|
469 |
+
|
470 |
+
Open Large Language Models (LLMs) have a wide range of applications across
|
471 |
+
various industries and domains. The following list of potential uses is not
|
472 |
+
comprehensive. The purpose of this list is to provide contextual information
|
473 |
+
about the possible use-cases that the model creators considered as part of model
|
474 |
+
training and development.
|
475 |
+
|
476 |
+
* Content Creation and Communication
|
477 |
+
* Text Generation: These models can be used to generate creative text formats
|
478 |
+
such as poems, scripts, code, marketing copy, and email drafts.
|
479 |
+
* Chatbots and Conversational AI: Power conversational interfaces for customer
|
480 |
+
service, virtual assistants, or interactive applications.
|
481 |
+
* Text Summarization: Generate concise summaries of a text corpus, research
|
482 |
+
papers, or reports.
|
483 |
+
* Research and Education
|
484 |
+
* Natural Language Processing (NLP) Research: These models can serve as a
|
485 |
+
foundation for researchers to experiment with NLP techniques, develop
|
486 |
+
algorithms, and contribute to the advancement of the field.
|
487 |
+
* Language Learning Tools: Support interactive language learning experiences,
|
488 |
+
aiding in grammar correction or providing writing practice.
|
489 |
+
* Knowledge Exploration: Assist researchers in exploring large bodies of text
|
490 |
+
by generating summaries or answering questions about specific topics.
|
491 |
+
|
492 |
+
### Limitations
|
493 |
+
|
494 |
+
* Training Data
|
495 |
+
* The quality and diversity of the training data significantly influence the
|
496 |
+
model's capabilities. Biases or gaps in the training data can lead to
|
497 |
+
limitations in the model's responses.
|
498 |
+
* The scope of the training dataset determines the subject areas the model can
|
499 |
+
handle effectively.
|
500 |
+
* Context and Task Complexity
|
501 |
+
* LLMs are better at tasks that can be framed with clear prompts and
|
502 |
+
instructions. Open-ended or highly complex tasks might be challenging.
|
503 |
+
* A model's performance can be influenced by the amount of context provided
|
504 |
+
(longer context generally leads to better outputs, up to a certain point).
|
505 |
+
* Language Ambiguity and Nuance
|
506 |
+
* Natural language is inherently complex. LLMs might struggle to grasp subtle
|
507 |
+
nuances, sarcasm, or figurative language.
|
508 |
+
* Factual Accuracy
|
509 |
+
* LLMs generate responses based on information they learned from their
|
510 |
+
training datasets, but they are not knowledge bases. They may generate
|
511 |
+
incorrect or outdated factual statements.
|
512 |
+
* Common Sense
|
513 |
+
* LLMs rely on statistical patterns in language. They might lack the ability
|
514 |
+
to apply common sense reasoning in certain situations.
|
515 |
+
|
516 |
+
### Ethical Considerations and Risks
|
517 |
+
|
518 |
+
The development of large language models (LLMs) raises several ethical concerns.
|
519 |
+
In creating an open model, we have carefully considered the following:
|
520 |
+
|
521 |
+
* Bias and Fairness
|
522 |
+
* LLMs trained on large-scale, real-world text data can reflect socio-cultural
|
523 |
+
biases embedded in the training material. These models underwent careful
|
524 |
+
scrutiny, input data pre-processing described and posterior evaluations
|
525 |
+
reported in this card.
|
526 |
+
* Misinformation and Misuse
|
527 |
+
* LLMs can be misused to generate text that is false, misleading, or harmful.
|
528 |
+
* Guidelines are provided for responsible use with the model, see the
|
529 |
+
[Responsible Generative AI Toolkit](http://ai.google.dev/gemma/responsible).
|
530 |
+
* Transparency and Accountability:
|
531 |
+
* This model card summarizes details on the models' architecture,
|
532 |
+
capabilities, limitations, and evaluation processes.
|
533 |
+
* A responsibly developed open model offers the opportunity to share
|
534 |
+
innovation by making LLM technology accessible to developers and researchers
|
535 |
+
across the AI ecosystem.
|
536 |
+
|
537 |
+
Risks identified and mitigations:
|
538 |
+
|
539 |
+
* Perpetuation of biases: It's encouraged to perform continuous monitoring
|
540 |
+
(using evaluation metrics, human review) and the exploration of de-biasing
|
541 |
+
techniques during model training, fine-tuning, and other use cases.
|
542 |
+
* Generation of harmful content: Mechanisms and guidelines for content safety
|
543 |
+
are essential. Developers are encouraged to exercise caution and implement
|
544 |
+
appropriate content safety safeguards based on their specific product policies
|
545 |
+
and application use cases.
|
546 |
+
* Misuse for malicious purposes: Technical limitations and developer and
|
547 |
+
end-user education can help mitigate against malicious applications of LLMs.
|
548 |
+
Educational resources and reporting mechanisms for users to flag misuse are
|
549 |
+
provided. Prohibited uses of Gemma models are outlined in the
|
550 |
+
[Gemma Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy).
|
551 |
+
* Privacy violations: Models were trained on data filtered for removal of PII
|
552 |
+
(Personally Identifiable Information). Developers are encouraged to adhere to
|
553 |
+
privacy regulations with privacy-preserving techniques.
|
554 |
+
|
555 |
+
### Benefits
|
556 |
+
|
557 |
+
At the time of release, this family of models provides high-performance open
|
558 |
+
large language model implementations designed from the ground up for Responsible
|
559 |
+
AI development compared to similarly sized models.
|
560 |
+
|
561 |
+
Using the benchmark evaluation metrics described in this document, these models
|
562 |
+
have shown to provide superior performance to other, comparably-sized open model
|
563 |
+
alternatives.
|
564 |
+
|
565 |
+
|
566 |
+
|