Skip to content

Commit 96f900f

Browse files
committed
Address comments
1 parent 7eea6c8 commit 96f900f

File tree

5 files changed

+55
-55
lines changed

5 files changed

+55
-55
lines changed

CONTRIBUTING_MODELS.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ open to contributions!
77
In this guide, we will walk you through the steps one needs to take in order to
88
contribute a new pre-trained model to KerasHub. For illustration purposes, let's
99
assume that you want to contribute the DistilBERT model. Before we dive in, we encourage you to go through
10-
[our getting started guide](https://keras.io/guides/keras_hub/getting_started/)
10+
[our getting started guide](https://keras.io/guides/keras_nlp/getting_started/)
1111
for an introduction to the library, and our
1212
[contribution guide](https://github.com/keras-team/keras-nlp/blob/master/CONTRIBUTING.md).
1313

@@ -22,29 +22,29 @@ Keep this checklist handy!
2222

2323
### Step 2: PR #1 - Add XXBackbone
2424

25-
- [ ] An `xx/xx_backbone.py` file which has the model graph \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_backbone.py)\].
26-
- [ ] An `xx/xx_backbone_test.py` file which has unit tests for the backbone \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_backbone_test.py)\].
25+
- [ ] An `xx/xx_backbone.py` file which has the model graph \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_backbone.py)\].
26+
- [ ] An `xx/xx_backbone_test.py` file which has unit tests for the backbone \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_backbone_test.py)\].
2727
- [ ] A Colab notebook link in the PR description which matches the outputs of the implemented backbone model with the original source \[[Example](https://colab.research.google.com/drive/1SeZWJorKWmwWJax8ORSdxKrxE25BfhHa?usp=sharing)\].
2828

2929
### Step 3: PR #2 - Add XXTokenizer
3030

31-
- [ ] An `xx/xx_tokenizer.py` file which has the tokenizer for the model \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_tokenizer.py)\].
32-
- [ ] An `xx/xx_tokenizer_test.py` file which has unit tests for the model tokenizer \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_tokenizer_test.py)\].
31+
- [ ] An `xx/xx_tokenizer.py` file which has the tokenizer for the model \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_tokenizer.py)\].
32+
- [ ] An `xx/xx_tokenizer_test.py` file which has unit tests for the model tokenizer \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_tokenizer_test.py)\].
3333
- [ ] A Colab notebook link in the PR description, demonstrating that the output of the tokenizer matches the original tokenizer \[[Example](https://colab.research.google.com/drive/1MH_rpuFB1Nz_NkKIAvVtVae2HFLjXZDA?usp=sharing)].
3434

3535
### Step 4: PR #3 - Add XX Presets
3636

37-
- [ ] An `xx/xx_presets.py` file with links to weights uploaded to a personal GCP bucket/Google Drive \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_presets.py)\].
37+
- [ ] An `xx/xx_presets.py` file with links to weights uploaded to a personal GCP bucket/Google Drive \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_presets.py)\].
3838
- [ ] A `tools/checkpoint_conversion/convert_xx_checkpoints.py` which is reusable script for converting checkpoints \[[Example](https://github.com/keras-team/keras-nlp/blob/master/tools/checkpoint_conversion/convert_distilbert_checkpoints.py)\].
3939
- [ ] A Colab notebook link in the PR description, showing an end-to-end task such as text classification, etc. The task model can be built using the backbone model, with the task head on top \[[Example](https://gist.github.com/mattdangerw/bf0ca07fb66b6738150c8b56ee5bab4e)\].
4040

4141
### Step 5: PR #4 and Beyond - Add XX Tasks and Preprocessors
4242

4343
This PR is optional.
4444

45-
- [ ] An `xx/xx_<task>.py` file for adding a task model like classifier, masked LM, etc. \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_classifier.py)\]
46-
- [ ] An `xx/xx_<task>_preprocessor.py` file which has the preprocessor and can be used to get inputs suitable for the task model \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_preprocessor.py)\].
47-
- [ ] `xx/xx_<task>_test.py` file and `xx/xx_<task>_preprocessor_test.py` files which have unit tests for the above two modules \[[Example 1](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_classifier_test.py) and [Example 2](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_preprocessor_test.py)\].
45+
- [ ] An `xx/xx_<task>.py` file for adding a task model like classifier, masked LM, etc. \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_classifier.py)\]
46+
- [ ] An `xx/xx_<task>_preprocessor.py` file which has the preprocessor and can be used to get inputs suitable for the task model \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_preprocessor.py)\].
47+
- [ ] `xx/xx_<task>_test.py` file and `xx/xx_<task>_preprocessor_test.py` files which have unit tests for the above two modules \[[Example 1](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_classifier_test.py) and [Example 2](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_preprocessor_test.py)\].
4848
- [ ] A Colab notebook link in the PR description, demonstrating that the output of the preprocessor matches the output of the original preprocessor \[[Example](https://colab.research.google.com/drive/1GFFC7Y1I_2PtYlWDToqKvzYhHWv1b3nC?usp=sharing)].
4949

5050
## Detailed Instructions
@@ -81,7 +81,7 @@ around by a class to implement our models.
8181

8282
A model is typically split into three/four sections. We would recommend you to
8383
compare this side-by-side with the
84-
[`keras_hub.layers.DistilBertBackbone` source code](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_backbone.py)!
84+
[`keras_hub.layers.DistilBertBackbone` source code](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_backbone.py)!
8585

8686
**Inputs to the model**
8787

@@ -110,7 +110,7 @@ Standard layers used: `keras_hub.layers.TransformerDecoder`.
110110

111111
The standard layers provided in Keras and KerasHub are generally enough for
112112
most of the usecases and it is recommended to do a thorough search
113-
[here](https://keras.io/api/layers/) and [here](https://keras.io/api/keras_hub/layers/).
113+
[here](https://keras.io/api/layers/) and [here](https://keras.io/api/keras_nlp/layers/).
114114
However, sometimes, models have small tweaks/paradigm changes in their architecture.
115115
This is when things might slightly get complicated.
116116

@@ -165,12 +165,12 @@ All the underlying actual tokenization will be taken care of by the superclass.
165165
The important thing here is adding "special tokens". Most models have
166166
special tokens such as beginning-of-sequence token, end-of-sequence token,
167167
mask token, pad token, etc. These have to be
168-
[added as member attributes](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_tokenizer.py#L91-L105)
168+
[added as member attributes](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_tokenizer.py#L91-L105)
169169
to the tokenizer class. These member attributes are then accessed by the
170170
preprocessor layers.
171171

172172
For a full list of the tokenizers KerasHub offers, please visit
173-
[this link](https://keras.io/api/keras_hub/tokenizers/) and make use of the
173+
[this link](https://keras.io/api/keras_nlp/tokenizers/) and make use of the
174174
tokenizer your model uses!
175175

176176
#### Unit Tests
@@ -193,7 +193,7 @@ files. These files will then be uploaded to GCP by us!
193193
After wrapping up the preset configuration file, you need to
194194
add the `from_preset` function to all three classes, i.e., `DistilBertBackbone`,
195195
and `DistilBertTokenizer`. Here is an
196-
[example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_backbone.py#L187-L189).
196+
[example](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_backbone.py#L187-L189).
197197

198198
The testing for presets is divided into two: "large" and "extra large".
199199
For "large" tests, we pick the smallest preset (in terms of number of parameters)
@@ -230,7 +230,7 @@ The preprocessor class might have a few intricacies depending on the model. For
230230
the DeBERTaV3 tokenizer does not have the `[MASK]` in the provided sentencepiece
231231
proto file, and we had to make some modifications [here](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/deberta_v3/deberta_v3_preprocessor.py). Secondly, we have
232232
a separate preprocessor class for every task. This is because different tasks
233-
might require different input formats. For instance, we have a [separate preprocessor](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_masked_lm_preprocessor.py)
233+
might require different input formats. For instance, we have a [separate preprocessor](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/src/models/distil_bert/distil_bert_masked_lm_preprocessor.py)
234234
for masked language modeling (MLM) for DistilBERT.
235235

236236
## Conclusion

README.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
# KerasHub: Multi-framework NLP Models
1+
# KerasNLP: Multi-framework NLP Models
22
[![](https://github.com/keras-team/keras-nlp/workflows/Tests/badge.svg?branch=master)](https://github.com/keras-team/keras-nlp/actions?query=workflow%3ATests+branch%3Amaster)
33
![Python](https://img.shields.io/badge/python-v3.9.0+-success.svg)
44
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/keras-team/keras-nlp/issues)
55

66
> [!IMPORTANT]
7-
> KerasHub is becoming KerasHub! Read the announcement [here](https://github.com/keras-team/keras-nlp/issues/1831).
7+
> KerasNLP is becoming KerasHub! Read the announcement
8+
> [in this issue](https://github.com/keras-team/keras-nlp/issues/1831). We have
9+
> renamed our repo to KerasHub in preparation for the release, but have not yet
10+
> released the new package. Follow the issue for news.
811
9-
KerasHub is a natural language processing library that works natively
10-
with TensorFlow, JAX, or PyTorch. KerasHub provides a repository of pre-trained
12+
KerasNLP is a natural language processing library that works natively
13+
with TensorFlow, JAX, or PyTorch. KerasNLP provides a repository of pre-trained
1114
models and a collection of lower-level building blocks for language modeling.
1215
Built on Keras 3, models can be trained and serialized in any framework
1316
and re-used in another without costly migrations.
1417

1518
This library is an extension of the core Keras API; all high-level modules are
1619
Layers and Models that receive that same level of polish as core Keras.
1720
If you are familiar with Keras, congratulations! You already understand most of
18-
KerasHub.
21+
KerasNLP.
1922

2023
All models support JAX, TensorFlow, and PyTorch from a single model
2124
definition and can be fine-tuned on GPUs and TPUs out of the box. Models can
2225
be trained on individual accelerators with built-in PEFT techniques, or
2326
fine-tuned at scale with model and data parallel training. See our
24-
[Getting Started guide](https://keras.io/guides/keras_hub/getting_started)
27+
[Getting Started guide](https://keras.io/guides/keras_nlp/getting_started)
2528
to start learning our API. Browse our models on
2629
[Kaggle](https://www.kaggle.com/organizations/keras/models).
2730
We welcome contributions.
@@ -30,9 +33,9 @@ We welcome contributions.
3033

3134
### For everyone
3235

33-
- [Home Page](https://keras.io/keras_hub)
34-
- [Developer Guides](https://keras.io/guides/keras_hub)
35-
- [API Reference](https://keras.io/api/keras_hub)
36+
- [Home Page](https://keras.io/keras_nlp)
37+
- [Developer Guides](https://keras.io/guides/keras_nlp)
38+
- [API Reference](https://keras.io/api/keras_nlp)
3639
- [Pre-trained Models](https://www.kaggle.com/organizations/keras/models)
3740

3841
### For contributors
@@ -51,7 +54,7 @@ Fine-tune BERT on IMDb movie reviews:
5154
import os
5255
os.environ["KERAS_BACKEND"] = "jax" # Or "tensorflow" or "torch"!
5356

54-
import keras_hub
57+
import keras_nlp
5558
import tensorflow_datasets as tfds
5659

5760
imdb_train, imdb_test = tfds.load(
@@ -61,7 +64,7 @@ imdb_train, imdb_test = tfds.load(
6164
batch_size=16,
6265
)
6366
# Load a BERT model.
64-
classifier = keras_hub.models.Classifier.from_preset(
67+
classifier = keras_nlp.models.Classifier.from_preset(
6568
"bert_base_en",
6669
num_classes=2,
6770
activation="softmax",
@@ -74,38 +77,38 @@ classifier.predict(["What an amazing movie!", "A total waste of my time."])
7477

7578
Try it out [in a colab](https://colab.research.google.com/gist/mattdangerw/e457e42d5ea827110c8d5cb4eb9d9a07/kerasnlp-quickstart.ipynb).
7679
For more in depth guides and examples, visit
77-
[keras.io/keras_hub](https://keras.io/keras_hub/).
80+
[keras.io/keras_nlp](https://keras.io/keras_nlp/).
7881

7982
## Installation
8083

81-
To install the latest KerasHub release with Keras 3, simply run:
84+
To install the latest KerasNLP release with Keras 3, simply run:
8285

8386
```
84-
pip install --upgrade keras-hub
87+
pip install --upgrade keras-nlp
8588
```
8689

87-
To install the latest nightly changes for both KerasHub and Keras, you can use
90+
To install the latest nightly changes for both KerasNLP and Keras, you can use
8891
our nightly package.
8992

9093
```
91-
pip install --upgrade keras-hub-nightly
94+
pip install --upgrade keras-nlp-nightly
9295
```
9396

94-
Note that currently, installing KerasHub will always pull in TensorFlow for use
97+
Note that currently, installing KerasNLP will always pull in TensorFlow for use
9598
of the `tf.data` API for preprocessing. Even when pre-processing with `tf.data`,
9699
training can still happen on any backend.
97100

98101
Read [Getting started with Keras](https://keras.io/getting_started/) for more
99102
information on installing Keras 3 and compatibility with different frameworks.
100103

101104
> [!IMPORTANT]
102-
> We recommend using KerasHub with TensorFlow 2.16 or later, as TF 2.16 packages
105+
> We recommend using KerasNLP with TensorFlow 2.16 or later, as TF 2.16 packages
103106
> Keras 3 by default.
104107
105108
## Configuring your backend
106109

107110
If you have Keras 3 installed in your environment (see installation above),
108-
you can use KerasHub with any of JAX, TensorFlow and PyTorch. To do so, set the
111+
you can use KerasNLP with any of JAX, TensorFlow and PyTorch. To do so, set the
109112
`KERAS_BACKEND` environment variable. For example:
110113

111114
```shell
@@ -118,7 +121,7 @@ Or in Colab, with:
118121
import os
119122
os.environ["KERAS_BACKEND"] = "jax"
120123

121-
import keras_hub
124+
import keras_nlp
122125
```
123126

124127
> [!IMPORTANT]
@@ -134,21 +137,21 @@ may break compatibility at any time and APIs should not be consider stable.
134137

135138
## Disclaimer
136139

137-
KerasHub provides access to pre-trained models via the `keras_hub.models` API.
140+
KerasNLP provides access to pre-trained models via the `keras_nlp.models` API.
138141
These pre-trained models are provided on an "as is" basis, without warranties
139142
or conditions of any kind. The following underlying models are provided by third
140143
parties, and subject to separate licenses:
141144
BART, BLOOM, DeBERTa, DistilBERT, GPT-2, Llama, Mistral, OPT, RoBERTa, Whisper,
142145
and XLM-RoBERTa.
143146

144-
## Citing KerasHub
147+
## Citing KerasNLP
145148

146-
If KerasHub helps your research, we appreciate your citations.
149+
If KerasNLP helps your research, we appreciate your citations.
147150
Here is the BibTeX entry:
148151

149152
```bibtex
150153
@misc{kerasnlp2022,
151-
title={KerasHub},
154+
title={KerasNLP},
152155
author={Watson, Matthew, and Qian, Chen, and Bischof, Jonathan and Chollet,
153156
Fran\c{c}ois and others},
154157
year={2022},

RELEASE_PROCESS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Our release process consists of two main components:
1010

1111
- Adding a new release to the [keras-hub](https://pypi.org/project/keras-hub/)
1212
project on the Python Package Index (pypi).
13-
- Updating our documentation on [keras.io](https://keras.io/keras_hub/) to match
13+
- Updating our documentation on [keras.io](https://keras.io/keras_nlp/) to match
1414
the release.
1515

1616
We follow [semantic versioning](https://semver.org/) for our releases, and

keras_hub/src/api_export.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import types
1616

17-
import keras
17+
from keras.saving import register_keras_serializable
1818

1919
try:
2020
import namex
@@ -23,22 +23,19 @@
2323

2424

2525
def maybe_register_serializable(path, symbol):
26-
# If we have multiple export names, actually make sure to register these
27-
# first. This makes sure we have a backward compat mapping of old serialized
28-
# name to new class.
2926
if isinstance(path, (list, tuple)):
27+
# If we have multiple export names, actually make sure to register these
28+
# first. This makes sure we have a backward compat mapping of old
29+
# serialized names to new class.
3030
for name in path:
3131
name = name.split(".")[-1]
32-
keras.saving.register_keras_serializable(
33-
package="keras_nlp", name=name
34-
)(symbol)
32+
register_keras_serializable(package="keras_nlp", name=name)(symbol)
33+
register_keras_serializable(package="keras_hub", name=name)(symbol)
3534
if isinstance(symbol, types.FunctionType) or hasattr(symbol, "get_config"):
36-
# We register twice, first with the old name, second with the new name,
37-
# so loading still works under the old name.
38-
# TODO replace keras_nlp with keras-hub after rename.
39-
compat_name = "keras_nlp"
40-
keras.saving.register_keras_serializable(package=compat_name)(symbol)
41-
keras.saving.register_keras_serializable(package="keras_hub")(symbol)
35+
# We register twice, first with keras_nlp, second with keras_hub,
36+
# so loading still works for classes saved as "keras_nlp".
37+
register_keras_serializable(package="keras_nlp")(symbol)
38+
register_keras_serializable(package="keras_hub")(symbol)
4239

4340

4441
if namex:

keras_hub/src/utils/preset_utils_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def test_preset_errors(self):
4343
backbone = BertBackbone.from_preset("bert_tiny_en_uncased")
4444
preset_dir = self.get_temp_dir()
4545
config = keras.utils.serialize_keras_object(backbone)
46-
config["registered_name"] = "keras_nlp>BortBackbone"
46+
config["registered_name"] = "keras_hub>BortBackbone"
4747
with open(os.path.join(preset_dir, CONFIG_FILE), "w") as config_file:
4848
config_file.write(json.dumps(config, indent=4))
49-
with self.assertRaisesRegex(ValueError, "class keras_nlp>BortBackbone"):
49+
with self.assertRaisesRegex(ValueError, "class keras_hub>BortBackbone"):
5050
BertBackbone.from_preset(preset_dir)
5151

5252
def test_upload_empty_preset(self):

0 commit comments

Comments
 (0)