Skip to content

Commit

Permalink
Rename keras-nlp -> keras-hub
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdangerw committed Sep 18, 2024
1 parent 290091e commit b8a80af
Show file tree
Hide file tree
Showing 623 changed files with 4,711 additions and 4,711 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
pip install keras-nightly --progress-bar off
- name: Test with pytest
run: |
pytest keras_nlp/
pytest keras_hub/
- name: Run integration tests
run: |
python pip_build.py --install
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ __pycache__/
*.swp
*.swo

keras_nlp.egg-info/
keras_hub.egg-info/
dist/

.coverage
Expand Down
8 changes: 4 additions & 4 deletions .kokoro/github/ubuntu/gpu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ pip install huggingface_hub
# Run Extra Large Tests for Continuous builds
if [ "${RUN_XLARGE:-0}" == "1" ]
then
pytest keras_nlp --check_gpu --run_large --run_extra_large \
--cov=keras-nlp
pytest keras_hub --check_gpu --run_large --run_extra_large \
--cov=keras-hub
else
pytest keras_nlp --check_gpu --run_large \
--cov=keras-nlp
pytest keras_hub --check_gpu --run_large \
--cov=keras-hub
fi
12 changes: 6 additions & 6 deletions API_DESIGN_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Before reading this document, please read the
[Keras API design guidelines](https://github.com/keras-team/governance/blob/master/keras_api_design_guidelines.md).

Below are some design considerations specific to KerasNLP.
Below are some design considerations specific to KerasHub.

## Philosophy

Expand All @@ -18,16 +18,16 @@ Below are some design considerations specific to KerasNLP.
arbitrarily advanced use cases should be possible. There should always be a
"we need to go deeper" path available to our most expert users.

- **Grow as a platform and as a community.** KerasNLP development should be
- **Grow as a platform and as a community.** KerasHub development should be
driven by the community, with feature and release planning happening in
the open on GitHub.

## Avoid new dependencies

The core dependencies of KerasNLP are Keras, NumPy, TensorFlow, and
The core dependencies of KerasHub are Keras, NumPy, TensorFlow, and
[Tensorflow Text](https://www.tensorflow.org/text).

We strive to keep KerasNLP as self-contained as possible, and avoid adding
We strive to keep KerasHub as self-contained as possible, and avoid adding
dependencies to projects (for example NLTK or spaCy) for text preprocessing.

In rare cases, particularly with tokenizers and metrics, we may need to add
Expand Down Expand Up @@ -65,7 +65,7 @@ calling a layer, metric or loss with `@tf.function` without running into issues.
[tf.text](https://www.tensorflow.org/text/api_docs/python/text) provides a large
surface on TensorFlow operations that manipulate strings. If an low-level (c++)
operation we need is missing, we should add it in collaboration with core
TensorFlow or TensorFlow Text. KerasNLP is a python-only library.
TensorFlow or TensorFlow Text. KerasHub is a python-only library.

We should also strive to keep computation XLA compilable wherever possible (e.g.
`tf.function(jit_compile=True)`). For trainable modeling components this is
Expand All @@ -84,7 +84,7 @@ both batched and unbatched data as input to preprocessing layers.

## Prioritize multi-lingual support

We strive to keep KerasNLP a friendly and useful library for speakers of all
We strive to keep KerasHub a friendly and useful library for speakers of all
languages. In general, prefer designing workflows that are language agnostic,
and do not involve logic (e.g. stemming) that need to be rewritten
per-language.
Expand Down
38 changes: 19 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Contribution guide

KerasNLP is an actively growing project and community! We would love for you
to get involved. Below are instructions for how to plug into KerasNLP
KerasHub is an actively growing project and community! We would love for you
to get involved. Below are instructions for how to plug into KerasHub
development.

## Background reading
Expand Down Expand Up @@ -83,21 +83,21 @@ Once the pull request is approved, a team member will take care of merging.

Python 3.9 or later is required.

Setting up your KerasNLP development environment requires you to fork the
KerasNLP repository and clone it locally. With the
Setting up your KerasHub development environment requires you to fork the
KerasHub repository and clone it locally. With the
[GitHub CLI](https://github.com/cli/cli) installed, you can do this as follows:

```shell
gh repo fork keras-team/keras-nlp --clone --remote
cd keras-nlp
cd keras-hub
```

Next we must setup a python environment with the correct dependencies. We
recommend using `conda` to set up a base environment, and `pip` to install
python packages from PyPI. The exact method will depend on your OS.

**Note**: Be careful not to use mix pre-packaged tensorflow and jax libraries in
`conda` with PyPI packages from `pip`. We recommend pulling *all* KerasNLP
`conda` with PyPI packages from `pip`. We recommend pulling *all* KerasHub
dependencies via `pip` as described below.

### Linux (recommended)
Expand All @@ -108,29 +108,29 @@ want accelerator support. The easiest way to get GPU support across all of our
backends is to set up a few different python environements and pull in all cuda
dependencies via `pip`.

The shell snippet below will install four conda environments: `keras-nlp-cpu`,
`keras-nlp-jax`, `keras-nlp-torch`, and `keras-nlp-tensorflow`. The cpu
The shell snippet below will install four conda environments: `keras-hub-cpu`,
`keras-hub-jax`, `keras-hub-torch`, and `keras-hub-tensorflow`. The cpu
environement supports all backends without cuda, and each backend environement
has cuda support.

```shell
conda create -y -n keras-nlp-cpu python=3.10
conda activate keras-nlp-cpu
conda create -y -n keras-hub-cpu python=3.10
conda activate keras-hub-cpu
pip install -r requirements.txt # install deps
pip install -e . # install keras-nlp
pip install -e . # install keras-hub

for backend in "jax" "torch" "tensorflow"; do
conda create -y -n keras-nlp-${backend} python=3.10
conda activate keras-nlp-${backend}
conda create -y -n keras-hub-${backend} python=3.10
conda activate keras-hub-${backend}
pip install -r requirements-${backend}-cuda.txt # install deps
pip install -e . # install keras-nlp
pip install -e . # install keras-hub
done
```

To activate the jax environment and set keras to use jax, run:

```shell
conda activate keras-nlp-jax && export KERAS_BACKEND=jax
conda activate keras-hub-jax && export KERAS_BACKEND=jax
```

### MacOS
Expand Down Expand Up @@ -160,16 +160,16 @@ repository.

## Update Public API

Run API generation script when creating PRs that update `keras_nlp_export`
public APIs. Add the files changed in `keras_nlp/api` to the same PR.
Run API generation script when creating PRs that update `keras_hub_export`
public APIs. Add the files changed in `keras_hub/api` to the same PR.

```
./shell/api_gen.sh
```

## Testing changes

KerasNLP is tested using [PyTest](https://docs.pytest.org/en/6.2.x/).
KerasHub is tested using [PyTest](https://docs.pytest.org/en/6.2.x/).

### Run a test file

Expand All @@ -184,7 +184,7 @@ can use the following command to run all the tests in `import_test.py`
whose names contain `import`:

```shell
pytest keras_nlp/keras_nlp/integration_tests/import_test.py -k="import"
pytest keras_hub/integration_tests/import_test.py -k="import"
```

### Run the full test suite
Expand Down
56 changes: 28 additions & 28 deletions CONTRIBUTING_MODELS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Model Contribution Guide

KerasNLP has a plethora of pre-trained large language models
KerasHub has a plethora of pre-trained large language models
ranging from BERT to OPT. We are always looking for more models and are always
open to contributions!

In this guide, we will walk you through the steps one needs to take in order to
contribute a new pre-trained model to KerasNLP. For illustration purposes, let's
contribute a new pre-trained model to KerasHub. For illustration purposes, let's
assume that you want to contribute the DistilBERT model. Before we dive in, we encourage you to go through
[our getting started guide](https://keras.io/guides/keras_nlp/getting_started/)
[our getting started guide](https://keras.io/guides/keras_hub/getting_started/)
for an introduction to the library, and our
[contribution guide](https://github.com/keras-team/keras-nlp/blob/master/CONTRIBUTING.md).

Expand All @@ -22,29 +22,29 @@ Keep this checklist handy!

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

- [ ] An `xx/xx_backbone.py` file which has the model graph \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/distil_bert/distil_bert_backbone.py)\].
- [ ] 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_nlp/models/distil_bert/distil_bert_backbone_test.py)\].
- [ ] 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)\].
- [ ] 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)\].
- [ ] 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)\].

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

- [ ] An `xx/xx_tokenizer.py` file which has the tokenizer for the model \[[Example](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/distil_bert/distil_bert_tokenizer.py)\].
- [ ] 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_nlp/models/distil_bert/distil_bert_tokenizer_test.py)\].
- [ ] 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)\].
- [ ] 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)\].
- [ ] 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)].

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

- [ ] 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_nlp/models/distil_bert/distil_bert_presets.py)\].
- [ ] 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)\].
- [ ] 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)\].
- [ ] 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)\].

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

This PR is optional.

- [ ] 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_nlp/models/distil_bert/distil_bert_classifier.py)\]
- [ ] 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_nlp/models/distil_bert/distil_bert_preprocessor.py)\].
- [ ] `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_nlp/models/distil_bert/distil_bert_classifier_test.py) and [Example 2](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/distil_bert/distil_bert_preprocessor_test.py)\].
- [ ] 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)\]
- [ ] 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)\].
- [ ] `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)\].
- [ ] 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)].

## Detailed Instructions
Expand Down Expand Up @@ -81,7 +81,7 @@ around by a class to implement our models.

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

**Inputs to the model**

Expand All @@ -92,32 +92,32 @@ Generally, the standard inputs to any text model are:
**Embedding layer(s)**

Standard layers used: `keras.layers.Embedding`,
`keras_nlp.layers.PositionEmbedding`, `keras_nlp.layers.TokenAndPositionEmbedding`.
`keras_hub.layers.PositionEmbedding`, `keras_hub.layers.TokenAndPositionEmbedding`.

**Encoder layers**

Standard layers used: `keras_nlp.layers.TransformerEncoder`, `keras_nlp.layers.FNetEncoder`.
Standard layers used: `keras_hub.layers.TransformerEncoder`, `keras_hub.layers.FNetEncoder`.

**Decoder layers (possibly)**

Standard layers used: `keras_nlp.layers.TransformerDecoder`.
Standard layers used: `keras_hub.layers.TransformerDecoder`.

**Other layers which might be used**

`keras.layers.LayerNorm`, `keras.layers.Dropout`, `keras.layers.Conv1D`, etc.

<br/>

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

If the model introduces a paradigm shift, such as using relative attention instead
of vanilla attention, the contributor will have to implement complete custom layers. A case
in point is `keras_nlp.models.DebertaV3Backbone` where we had to [implement layers
from scratch](https://github.com/keras-team/keras-nlp/tree/master/keras_nlp/models/deberta_v3).
in point is `keras_hub.models.DebertaV3Backbone` where we had to [implement layers
from scratch](https://github.com/keras-team/keras-nlp/tree/master/keras_hub/models/deberta_v3).

On the other hand, if the model has a small tweak, something simpler can be done.
For instance, in the Whisper model, the self-attention and cross-attention mechanism
Expand Down Expand Up @@ -154,23 +154,23 @@ and loaded correctly, etc.
#### Tokenizer

Most text models nowadays use subword tokenizers such as WordPiece, SentencePiece
and BPE Tokenizer. Since KerasNLP has implementations of most of the popular
and BPE Tokenizer. Since KerasHub has implementations of most of the popular
subword tokenizers, the model tokenizer layer typically inherits from a base
tokenizer class.

For example, DistilBERT uses the WordPiece tokenizer. So, we can introduce a new
class, `DistilBertTokenizer`, which inherits from `keras_nlp.tokenizers.WordPieceTokenizer`.
class, `DistilBertTokenizer`, which inherits from `keras_hub.tokenizers.WordPieceTokenizer`.
All the underlying actual tokenization will be taken care of by the superclass.

The important thing here is adding "special tokens". Most models have
special tokens such as beginning-of-sequence token, end-of-sequence token,
mask token, pad token, etc. These have to be
[added as member attributes](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/distil_bert/distil_bert_tokenizer.py#L91-L105)
[added as member attributes](https://github.com/keras-team/keras-nlp/blob/master/keras_hub/models/distil_bert/distil_bert_tokenizer.py#L91-L105)
to the tokenizer class. These member attributes are then accessed by the
preprocessor layers.

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

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

The testing for presets is divided into two: "large" and "extra large".
For "large" tests, we pick the smallest preset (in terms of number of parameters)
Expand Down Expand Up @@ -228,12 +228,12 @@ and return the dictionary in the form expected by the model.

The preprocessor class might have a few intricacies depending on the model. For example,
the DeBERTaV3 tokenizer does not have the `[MASK]` in the provided sentencepiece
proto file, and we had to make some modifications [here](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/deberta_v3/deberta_v3_preprocessor.py). Secondly, we have
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
a separate preprocessor class for every task. This is because different tasks
might require different input formats. For instance, we have a [separate preprocessor](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/distil_bert/distil_bert_masked_lm_preprocessor.py)
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)
for masked language modeling (MLM) for DistilBERT.

## Conclusion

Once all three PRs (and optionally, the fourth PR) have been merged, you have
successfully contributed a model to KerasNLP. Congratulations! 🔥
successfully contributed a model to KerasHub. Congratulations! 🔥
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2024, KerasNLP authors. All rights reserved.
Copyright 2024, KerasHub authors. All rights reserved.

Apache License
Version 2.0, January 2004
Expand Down Expand Up @@ -188,7 +188,7 @@ Copyright 2024, KerasNLP authors. All rights reserved.
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2024, KerasNLP authors.
Copyright 2024, KerasHub authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit b8a80af

Please sign in to comment.