keras-hub text-generation keras arxiv:2211.05100 license:openrail region:us
---
library_name: keras-hub
license: openrail
pipeline_tag: text-generation
tags:
- text-generation
- keras
---
### Model Overview
BLOOM as described in as descriped in [BLOOM: A 176B-Parameter Open-Access Multilingual Language Model](https://arxiv.org/pdf/2211.05100.pdf), is a large language model published by BigScience. BLOOM is able to output coherent text in 46 languages and 13 programming languages. BLOOM models range in size from 0.5 billion to 3 billion parameters. See the model card below for benchmarks, data sources, and intended use cases.

Weights are released under the [RAIL License](https://www.licenses.ai/ai-licenses). Keras model code is released under the [Apache 2 License](https://github.com/keras-team/keras-hub/blob/master/LICENSE).

## Links

* [BLOOM Quickstart Notebook](https://www.kaggle.com/code/laxmareddypatlolla/bloom-quickstart)
* [BLOOM API Documentation](https://keras.io/api/keras_hub/models/bloom/)
* [BLOOM Model Card](https://huggingface.co/bigscience/bloom)
* [KerasHub Beginner Guide](https://keras.io/guides/keras_hub/getting_started/)
* [KerasHub Model Publishing Guide](https://keras.io/guides/keras_hub/upload/)

## Installation

Keras and KerasHub can be installed with:

```
pip install -U -q keras-hub
pip install -U -q keras>=3
```

Jax, TensorFlow, and Torch come preinstalled in Kaggle Notebooks. For instructions on installing them in another environment see the [Keras Getting Started](https://keras.io/getting_started/) page.

## Presets

The following model checkpoints are provided by the Keras team. Full code examples for each are available below.

| Preset name         | Parameters | Description                  |
|---------------------|------------|------------------------------|
| `bloom_560m_multi`  | 559M       | 560M base model              |
| `bloom_1.1b_multi`  | 1.06B      | 1B base model                |
| `bloom_1.7b_multi`  | 1.72B      | 1.7B base model              |
| `bloom_3b_multi`    | 3B         | 3B base model                |
| `bloomz_560m_multi` | 559M       | 560m instruction-tuned model |
| `bloomz_1.1b_multi` | 1.06B      | 1B instruction-tuned model   |
| `bloomz_1.7b_multi` | 1.72B      | 1.7B instruction-tuned model |
| `bloomz_3b_multi`   | 3B         | 3B instruction-tuned model   |

## Prompts

The performance may vary depending on the prompt. For BLOOMZ models, we recommend making it very clear when the input stops to avoid the model trying to continue it. For example, the prompt "Translate to English: Je t'aime" without the full stop (.) at the end, may result in the model trying to continue the French sentence. Better prompts are e.g. "Translate to English: Je t'aime.", "Translate to English: Je t'aime. Translation:" "What is "Je t'aime." in English?", where it is clear for the model when it should answer. Further, we recommend providing the model as much context as possible. For example, if you want it to answer in Telugu, then tell the model, e.g. "Explain in a sentence in Telugu what is backpropagation in neural networks.".

## Example Usage
```python

import os

os.environ["KERAS_BACKEND"] = "jax"

import keras
import keras_hub

# When running only inference, bfloat16 saves memory usage significantly.
keras.config.set_floatx("bfloat16")

bloom_lm = keras_hub.models.BloomCausalLM.from_preset(
    "bloom_1.7b_multi"
)
bloom_lm.summary()

outputs = bloom_lm.generate([
    "What is Keras?",
], max_length=512)

for output in outputs:
    print(output)
```

## Example Usage with Hugging Face URI

```python

import os

os.environ["KERAS_BACKEND"] = "jax"

import keras
import keras_hub

# When running only inference, bfloat16 saves memory usage significantly.
keras.config.set_floatx("bfloat16")

bloom_lm = keras_hub.models.BloomCausalLM.from_preset(
    "hf://keras/bloom_1.7b_multi"
)
bloom_lm.summary()

outputs = bloom_lm.generate([
    "What is Keras?",
], max_length=512)

for output in outputs:
    print(output)
```
