Instructions to use zeromodels/t5_base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/t5_base with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/t5_base") - Keras
How to use zeromodels/t5_base with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://zeromodels/t5_base") - Notebooks
- Google Colab
- Kaggle
File size: 2,992 Bytes
56bed4e 27cf9ad 56bed4e 27cf9ad 56bed4e a1bc0bc 56bed4e 27cf9ad 56bed4e 27cf9ad 56bed4e 27cf9ad 56bed4e 27cf9ad 56bed4e a1bc0bc 56bed4e 27cf9ad 56bed4e 27cf9ad 56bed4e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | ---
pipeline_tag: translation
license: apache-2.0
base_model: google-t5/t5-base
library_name: zeromodels
language:
- en
- fr
- de
- ro
tags:
- keras
- zeromodels
- t5
- text2text-generation
- pytorch
- jax
- tf
---
# T5-base in Keras 3: JAX, PyTorch, or TensorFlow
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/t5/) [](https://huggingface.co/collections/zeromodels/t5-6a8eadfe1bec6ae9ffc24c7f)
# zeromodels/t5_base
Pure-**Keras 3** conversion of [`google-t5/t5-base`](https://huggingface.co/google-t5/t5-base) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**, bit-exact with the Hugging Face original. T5 is a text-to-text encoder-decoder; this repo hosts the full backbone (`zm_config.json` declares `T5Model`), and every T5 class (`T5ConditionalGenerate`, `T5EncoderModel`, and the classification / QA heads) loads its subset from the one `model.weights.h5`.
For model details, license, and usage terms, see the upstream [model card](https://huggingface.co/google-t5/t5-base).
Paper: [Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer](https://arxiv.org/abs/1910.10683)
## Quick start
```python
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from zeromodels.models.t5 import T5ConditionalGenerate, T5Tokenizer
model = T5ConditionalGenerate.from_weights("zeromodels/t5_base")
tokenizer = T5Tokenizer.from_weights("zeromodels/t5_base")
inputs = tokenizer("translate English to German: The house is wonderful.")
output_ids = model.generate(
inputs["input_ids"], inputs["attention_mask"], max_new_tokens=40
)
print(tokenizer.decode(output_ids[0]))
```
Load any T5 variant the same way with `from_weights("zeromodels/<variant>")`. Browse them all in the [T5 collection](https://huggingface.co/collections/zeromodels/t5-6a8eadfe1bec6ae9ffc24c7f).
## Available classes
Load any of these from this repo with `from_weights("zeromodels/t5_base")` (or on the fly via the `hf:` prefix). The pretrained backbone is shared; task heads not stored in this checkpoint start randomly initialized, ready for fine-tuning (or load a `hf:` fine-tune).
| Class | Task |
|---|---|
| `T5Model` | Encoder backbone |
| `T5ConditionalGenerate` | Text-to-text generation |
| `T5EncoderModel` | Encoder-only features |
| `T5SequenceClassify` | Sequence classification |
| `T5TokenClassify` | Token classification (NER / POS) |
| `T5QnA` | Extractive question answering |
```python
from zeromodels.models.t5 import T5SequenceClassify
model = T5SequenceClassify.from_weights("zeromodels/t5_base")
```
## Special Thanks
Thank you to the Google T5 team for creating and releasing the T5 models.
|