# KerasHub: Multi-framework Models
[![](https://github.com/keras-team/keras-hub/workflows/Tests/badge.svg?branch=master)](https://github.com/keras-team/keras-hub/actions?query=workflow%3ATests+branch%3Amaster)
![Python](https://img.shields.io/badge/python-v3.9.0+-success.svg)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/keras-team/keras-hub/issues)
> [!IMPORTANT]
> 📢 KerasNLP is now KerasHub! 📢 Read
> [the announcement](https://github.com/keras-team/keras-hub/issues/1831).
KerasHub is a library that supports natural language processing, computer
vision, audio, and multimodal backbones and task models, working natively with
TensorFlow, JAX, or PyTorch. KerasHub provides a repository of pre-trained
models and a collection of lower-level building blocks for these tasks. Built
on Keras 3, models can be trained and serialized in any framework and re-used
in another without costly migrations.
This library is an extension of the core Keras API; all high-level modules are
Layers and Models that receive that same level of polish as core Keras.
If you are familiar with Keras, congratulations! You already understand most of
KerasHub.
All models support JAX, TensorFlow, and PyTorch from a single model
definition and can be fine-tuned on GPUs and TPUs out of the box. Models can
be trained on individual accelerators with built-in PEFT techniques, or
fine-tuned at scale with model and data parallel training. See our
[Getting Started guide](https://keras.io/guides/keras_hub/getting_started)
to start learning our API. Browse our models on
[Kaggle](https://www.kaggle.com/organizations/keras/models).
We welcome contributions.
## Quick Links
### For everyone
- [Home Page](https://keras.io/keras_hub)
- [Developer Guides](https://keras.io/guides/keras_hub)
- [API Reference](https://keras.io/api/keras_hub)
- [Pre-trained Models](https://www.kaggle.com/organizations/keras/models)
### For contributors
- [Contributing Guide](CONTRIBUTING.md)
- [Roadmap](ROADMAP.md)
- [Style Guide](STYLE_GUIDE.md)
- [API Design Guide](API_DESIGN_GUIDE.md)
- [Call for Contributions](https://github.com/keras-team/keras-hub/issues?q=is%3Aissue+is%3Aopen+label%3A%22contributions+welcome%22)
## Quickstart
Fine-tune a BERT classifier on IMDb movie reviews:
```python
import os
os.environ["KERAS_BACKEND"] = "jax" # Or "tensorflow" or "torch"!
import keras_hub
import tensorflow_datasets as tfds
imdb_train, imdb_test = tfds.load(
"imdb_reviews",
split=["train", "test"],
as_supervised=True,
batch_size=16,
)
# Load a BERT model.
classifier = keras_hub.models.Classifier.from_preset(
"bert_base_en",
num_classes=2,
activation="softmax",
)
# Fine-tune on IMDb movie reviews.
classifier.fit(imdb_train, validation_data=imdb_test)
# Predict two new examples.
classifier.predict(["What an amazing movie!", "A total waste of my time."])
```
Try it out [in a colab](https://colab.research.google.com/drive/1gSWkh3yOLwmKAaNh2dQQ6kQIlnGte7P2?usp=sharing).
For more in depth guides and examples, visit
[keras.io/keras_hub](https://keras.io/keras_hub/).
## Installation
To try out the latest version of KerasHub, you can use
our nightly package:
```bash
pip install keras-hub
```
KerasHub currently requires TensorFlow to be installed for use of the
`tf.data` API for preprocessing. Even when pre-processing with `tf.data`,
training can still happen on any backend.
Read [Getting started with Keras](https://keras.io/getting_started/) for more
information on installing Keras 3 and compatibility with different frameworks.
> [!IMPORTANT]
> We recommend using KerasHub with TensorFlow 2.16 or later, as TF 2.16 packages
> Keras 3 by default.
## Configuring your backend
If you have Keras 3 installed in your environment (see installation above),
you can use KerasHub with any of JAX, TensorFlow and PyTorch. To do so, set the
`KERAS_BACKEND` environment variable. For example:
```shell
export KERAS_BACKEND=jax
```
Or in Colab, with:
```python
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras_hub
```
> [!IMPORTANT]
> Make sure to set the `KERAS_BACKEND` **before** importing any Keras libraries;
> it will be used to set up Keras when it is first imported.
## Compatibility
We follow [Semantic Versioning](https://semver.org/), and plan to
provide backwards compatibility guarantees both for code and saved models built
with our components. While we continue with pre-release `0.y.z` development, we
may break compatibility at any time and APIs should not be considered stable.
## Disclaimer
KerasHub provides access to pre-trained models via the `keras_hub.models` API.
These pre-trained models are provided on an "as is" basis, without warranties
or conditions of any kind. The following underlying models are provided by third
parties, and subject to separate licenses:
BART, BLOOM, DeBERTa, DistilBERT, GPT-2, Llama, Mistral, OPT, RoBERTa, Whisper,
and XLM-RoBERTa.
## Citing KerasHub
If KerasHub helps your research, we appreciate your citations.
Here is the BibTeX entry:
```bibtex
@misc{kerashub2024,
title={KerasHub},
author={Watson, Matthew, and Chollet, Fran\c{c}ois and Sreepathihalli,
Divyashree, and Saadat, Samaneh and Sampath, Ramesh, and Rasskin, Gabriel and
and Zhu, Scott and Singh, Varun and Wood, Luke and Tan, Zhenyu and Stenbit,
Ian and Qian, Chen, and Bischof, Jonathan and others},
year={2024},
howpublished={\url{https://github.com/keras-team/keras-hub}},
}
```
## Acknowledgements
Thank you to all of our wonderful contributors!
<a href="https://github.com/keras-team/keras-hub/graphs/contributors">
<img src="https://contrib.rocks/image?repo=keras-team/keras-hub" />
</a>
Raw data
{
"_id": null,
"home_page": "https://github.com/keras-team/keras-hub",
"name": "keras-hub",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Keras team",
"author_email": "keras-hub@google.com",
"download_url": "https://files.pythonhosted.org/packages/33/0a/8fed7c03fd7acf15f486388a7a05586d20f5546e01407ba9120d2dd4c536/keras_hub-0.18.1.tar.gz",
"platform": null,
"description": "# KerasHub: Multi-framework Models\n[![](https://github.com/keras-team/keras-hub/workflows/Tests/badge.svg?branch=master)](https://github.com/keras-team/keras-hub/actions?query=workflow%3ATests+branch%3Amaster)\n![Python](https://img.shields.io/badge/python-v3.9.0+-success.svg)\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/keras-team/keras-hub/issues)\n\n> [!IMPORTANT]\n> \ud83d\udce2 KerasNLP is now KerasHub! \ud83d\udce2 Read\n> [the announcement](https://github.com/keras-team/keras-hub/issues/1831).\n\nKerasHub is a library that supports natural language processing, computer\nvision, audio, and multimodal backbones and task models, working natively with\nTensorFlow, JAX, or PyTorch. KerasHub provides a repository of pre-trained\nmodels and a collection of lower-level building blocks for these tasks. Built\non Keras 3, models can be trained and serialized in any framework and re-used\nin another without costly migrations.\n\nThis library is an extension of the core Keras API; all high-level modules are\nLayers and Models that receive that same level of polish as core Keras.\nIf you are familiar with Keras, congratulations! You already understand most of\nKerasHub.\n\nAll models support JAX, TensorFlow, and PyTorch from a single model\ndefinition and can be fine-tuned on GPUs and TPUs out of the box. Models can\nbe trained on individual accelerators with built-in PEFT techniques, or\nfine-tuned at scale with model and data parallel training. See our\n[Getting Started guide](https://keras.io/guides/keras_hub/getting_started)\nto start learning our API. Browse our models on\n[Kaggle](https://www.kaggle.com/organizations/keras/models).\nWe welcome contributions.\n\n## Quick Links\n\n### For everyone\n\n- [Home Page](https://keras.io/keras_hub)\n- [Developer Guides](https://keras.io/guides/keras_hub)\n- [API Reference](https://keras.io/api/keras_hub)\n- [Pre-trained Models](https://www.kaggle.com/organizations/keras/models)\n\n### For contributors\n\n- [Contributing Guide](CONTRIBUTING.md)\n- [Roadmap](ROADMAP.md)\n- [Style Guide](STYLE_GUIDE.md)\n- [API Design Guide](API_DESIGN_GUIDE.md)\n- [Call for Contributions](https://github.com/keras-team/keras-hub/issues?q=is%3Aissue+is%3Aopen+label%3A%22contributions+welcome%22)\n\n## Quickstart\n\nFine-tune a BERT classifier on IMDb movie reviews:\n\n```python\nimport os\nos.environ[\"KERAS_BACKEND\"] = \"jax\" # Or \"tensorflow\" or \"torch\"!\n\nimport keras_hub\nimport tensorflow_datasets as tfds\n\nimdb_train, imdb_test = tfds.load(\n \"imdb_reviews\",\n split=[\"train\", \"test\"],\n as_supervised=True,\n batch_size=16,\n)\n\n# Load a BERT model.\nclassifier = keras_hub.models.Classifier.from_preset(\n \"bert_base_en\",\n num_classes=2,\n activation=\"softmax\",\n)\n\n# Fine-tune on IMDb movie reviews.\nclassifier.fit(imdb_train, validation_data=imdb_test)\n# Predict two new examples.\nclassifier.predict([\"What an amazing movie!\", \"A total waste of my time.\"])\n```\n\nTry it out [in a colab](https://colab.research.google.com/drive/1gSWkh3yOLwmKAaNh2dQQ6kQIlnGte7P2?usp=sharing).\nFor more in depth guides and examples, visit\n[keras.io/keras_hub](https://keras.io/keras_hub/).\n\n## Installation\n\nTo try out the latest version of KerasHub, you can use\nour nightly package:\n\n```bash\npip install keras-hub\n```\n\nKerasHub currently requires TensorFlow to be installed for use of the\n`tf.data` API for preprocessing. Even when pre-processing with `tf.data`,\ntraining can still happen on any backend.\n\nRead [Getting started with Keras](https://keras.io/getting_started/) for more\ninformation on installing Keras 3 and compatibility with different frameworks.\n\n> [!IMPORTANT]\n> We recommend using KerasHub with TensorFlow 2.16 or later, as TF 2.16 packages\n> Keras 3 by default.\n\n## Configuring your backend\n\nIf you have Keras 3 installed in your environment (see installation above),\nyou can use KerasHub with any of JAX, TensorFlow and PyTorch. To do so, set the\n`KERAS_BACKEND` environment variable. For example:\n\n```shell\nexport KERAS_BACKEND=jax\n```\n\nOr in Colab, with:\n\n```python\nimport os\nos.environ[\"KERAS_BACKEND\"] = \"jax\"\n\nimport keras_hub\n```\n\n> [!IMPORTANT]\n> Make sure to set the `KERAS_BACKEND` **before** importing any Keras libraries;\n> it will be used to set up Keras when it is first imported.\n\n## Compatibility\n\nWe follow [Semantic Versioning](https://semver.org/), and plan to\nprovide backwards compatibility guarantees both for code and saved models built\nwith our components. While we continue with pre-release `0.y.z` development, we\nmay break compatibility at any time and APIs should not be considered stable.\n\n## Disclaimer\n\nKerasHub provides access to pre-trained models via the `keras_hub.models` API.\nThese pre-trained models are provided on an \"as is\" basis, without warranties\nor conditions of any kind. The following underlying models are provided by third\nparties, and subject to separate licenses:\nBART, BLOOM, DeBERTa, DistilBERT, GPT-2, Llama, Mistral, OPT, RoBERTa, Whisper,\nand XLM-RoBERTa.\n\n## Citing KerasHub\n\nIf KerasHub helps your research, we appreciate your citations.\nHere is the BibTeX entry:\n\n```bibtex\n@misc{kerashub2024,\n title={KerasHub},\n author={Watson, Matthew, and Chollet, Fran\\c{c}ois and Sreepathihalli,\n Divyashree, and Saadat, Samaneh and Sampath, Ramesh, and Rasskin, Gabriel and\n and Zhu, Scott and Singh, Varun and Wood, Luke and Tan, Zhenyu and Stenbit,\n Ian and Qian, Chen, and Bischof, Jonathan and others},\n year={2024},\n howpublished={\\url{https://github.com/keras-team/keras-hub}},\n}\n```\n\n## Acknowledgements\n\nThank you to all of our wonderful contributors!\n\n<a href=\"https://github.com/keras-team/keras-hub/graphs/contributors\">\n <img src=\"https://contrib.rocks/image?repo=keras-team/keras-hub\" />\n</a>\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Industry-strength Natural Language Processing extensions for Keras.",
"version": "0.18.1",
"project_urls": {
"Homepage": "https://github.com/keras-team/keras-hub"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "02ed301ffa131fa576f0ed176a38c9be9be3d66af66dfc6f33e3ee792238e9c8",
"md5": "499697cc7c10082641f168b32b2aa2fe",
"sha256": "f1b83a2d2bc532ef39569e1201c03d0413f4e60aecd90293a42aca488a6ae6f2"
},
"downloads": -1,
"filename": "keras_hub-0.18.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "499697cc7c10082641f168b32b2aa2fe",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 691170,
"upload_time": "2024-12-06T00:56:22",
"upload_time_iso_8601": "2024-12-06T00:56:22.262720Z",
"url": "https://files.pythonhosted.org/packages/02/ed/301ffa131fa576f0ed176a38c9be9be3d66af66dfc6f33e3ee792238e9c8/keras_hub-0.18.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "330a8fed7c03fd7acf15f486388a7a05586d20f5546e01407ba9120d2dd4c536",
"md5": "05549f8d22a2fe452484acac7972c202",
"sha256": "2aa6b2f233574cbe8193380d919ae4b516abcff8d96b210608b5b7af3762735c"
},
"downloads": -1,
"filename": "keras_hub-0.18.1.tar.gz",
"has_sig": false,
"md5_digest": "05549f8d22a2fe452484acac7972c202",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 472629,
"upload_time": "2024-12-06T00:56:24",
"upload_time_iso_8601": "2024-12-06T00:56:24.409197Z",
"url": "https://files.pythonhosted.org/packages/33/0a/8fed7c03fd7acf15f486388a7a05586d20f5546e01407ba9120d2dd4c536/keras_hub-0.18.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-06 00:56:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "keras-team",
"github_project": "keras-hub",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "keras-hub"
}