Skip to content

Commit 8fe2d55

Browse files
committed
Rename keras-nlp to keras-hub
1 parent 8436d18 commit 8fe2d55

File tree

97 files changed

+1527
-1531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1527
-1531
lines changed

call_for_contributions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mixing numerical, categorical, and text features, doing feature engineering with
2121

2222
## Text-to-image
2323

24-
A text-to-image diffusion model in the style of Imagen, using a frozen BERT encoder from KerasNLP
24+
A text-to-image diffusion model in the style of Imagen, using a frozen BERT encoder from KerasHub
2525
and a multi-stage diffusion model.
2626

2727

examples/generative/gpt2_text_generation_with_kerasnlp.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
2-
Title: GPT2 Text Generation with KerasNLP
2+
Title: GPT2 Text Generation with KerasHub
33
Author: Chen Qian
44
Date created: 2023/04/17
55
Last modified: 2024/04/12
6-
Description: Use KerasNLP GPT2 model and `samplers` to do text generation.
6+
Description: Use KerasHub GPT2 model and `samplers` to do text generation.
77
Accelerator: GPU
88
"""
99

1010
"""
11-
In this tutorial, you will learn to use [KerasNLP](https://keras.io/keras_nlp/) to load a
11+
In this tutorial, you will learn to use [KerasHub](https://keras.io/keras_hub/) to load a
1212
pre-trained Large Language Model (LLM) - [GPT-2 model](https://openai.com/research/better-language-models)
1313
(originally invented by OpenAI), finetune it to a specific text style, and
1414
generate text based on users' input (also known as prompt). You will also learn
@@ -25,23 +25,23 @@
2525
"""
2626

2727
"""
28-
## Install KerasNLP, Choose Backend and Import Dependencies
28+
## Install KerasHub, Choose Backend and Import Dependencies
2929
3030
This examples uses [Keras 3](https://keras.io/keras_3/) to work in any of
3131
`"tensorflow"`, `"jax"` or `"torch"`. Support for Keras 3 is baked into
32-
KerasNLP, simply change the `"KERAS_BACKEND"` environment variable to select
32+
KerasHub, simply change the `"KERAS_BACKEND"` environment variable to select
3333
the backend of your choice. We select the JAX backend below.
3434
"""
3535

3636
"""shell
37-
pip install git+https://github.com/keras-team/keras-nlp.git -q
37+
pip install git+https://github.com/keras-team/keras-hub.git -q
3838
"""
3939

4040
import os
4141

4242
os.environ["KERAS_BACKEND"] = "jax" # or "tensorflow" or "torch"
4343

44-
import keras_nlp
44+
import keras_hub
4545
import keras
4646
import tensorflow as tf
4747
import time
@@ -70,22 +70,22 @@
7070
"""
7171

7272
"""
73-
## Introduction to KerasNLP
73+
## Introduction to KerasHub
7474
7575
Large Language Models are complex to build and expensive to train from scratch.
76-
Luckily there are pretrained LLMs available for use right away. [KerasNLP](https://keras.io/keras_nlp/)
76+
Luckily there are pretrained LLMs available for use right away. [KerasHub](https://keras.io/keras_hub/)
7777
provides a large number of pre-trained checkpoints that allow you to experiment
7878
with SOTA models without needing to train them yourself.
7979
80-
KerasNLP is a natural language processing library that supports users through
81-
their entire development cycle. KerasNLP offers both pretrained models and
80+
KerasHub is a natural language processing library that supports users through
81+
their entire development cycle. KerasHub offers both pretrained models and
8282
modularized building blocks, so developers could easily reuse pretrained models
8383
or stack their own LLM.
8484
85-
In a nutshell, for generative LLM, KerasNLP offers:
85+
In a nutshell, for generative LLM, KerasHub offers:
8686
8787
- Pretrained models with `generate()` method, e.g.,
88-
`keras_nlp.models.GPT2CausalLM` and `keras_nlp.models.OPTCausalLM`.
88+
`keras_hub.models.GPT2CausalLM` and `keras_hub.models.OPTCausalLM`.
8989
- Sampler class that implements generation algorithms such as Top-K, Beam and
9090
contrastive search. These samplers can be used to generate text with
9191
custom models.
@@ -94,21 +94,21 @@
9494
"""
9595
## Load a pre-trained GPT-2 model and generate some text
9696
97-
KerasNLP provides a number of pre-trained models, such as [Google
97+
KerasHub provides a number of pre-trained models, such as [Google
9898
Bert](https://ai.googleblog.com/2018/11/open-sourcing-bert-state-of-art-pre.html)
9999
and [GPT-2](https://openai.com/research/better-language-models). You can see
100-
the list of models available in the [KerasNLP repository](https://github.com/keras-team/keras-nlp/tree/master/keras_nlp/models).
100+
the list of models available in the [KerasHub repository](https://github.com/keras-team/keras-hub/tree/master/keras_hub/models).
101101
102102
It's very easy to load the GPT-2 model as you can see below:
103103
"""
104104

105105
# To speed up training and generation, we use preprocessor of length 128
106106
# instead of full length 1024.
107-
preprocessor = keras_nlp.models.GPT2CausalLMPreprocessor.from_preset(
107+
preprocessor = keras_hub.models.GPT2CausalLMPreprocessor.from_preset(
108108
"gpt2_base_en",
109109
sequence_length=128,
110110
)
111-
gpt2_lm = keras_nlp.models.GPT2CausalLM.from_preset(
111+
gpt2_lm = keras_hub.models.GPT2CausalLM.from_preset(
112112
"gpt2_base_en", preprocessor=preprocessor
113113
)
114114

@@ -150,35 +150,35 @@
150150
"""
151151

152152
"""
153-
## More on the GPT-2 model from KerasNLP
153+
## More on the GPT-2 model from KerasHub
154154
155155
Next up, we will actually fine-tune the model to update its parameters, but
156156
before we do, let's take a look at the full set of tools we have to for working
157157
with for GPT2.
158158
159159
The code of GPT2 can be found
160-
[here](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/gpt2/).
160+
[here](https://github.com/keras-team/keras-hub/blob/master/keras_hub/models/gpt2/).
161161
Conceptually the `GPT2CausalLM` can be hierarchically broken down into several
162-
modules in KerasNLP, all of which have a *from_preset()* function that loads a
162+
modules in KerasHub, all of which have a *from_preset()* function that loads a
163163
pretrained model:
164164
165-
- `keras_nlp.models.GPT2Tokenizer`: The tokenizer used by GPT2 model, which is a
165+
- `keras_hub.models.GPT2Tokenizer`: The tokenizer used by GPT2 model, which is a
166166
[byte-pair encoder](https://huggingface.co/course/chapter6/5?fw=pt).
167-
- `keras_nlp.models.GPT2CausalLMPreprocessor`: the preprocessor used by GPT2
167+
- `keras_hub.models.GPT2CausalLMPreprocessor`: the preprocessor used by GPT2
168168
causal LM training. It does the tokenization along with other preprocessing
169169
works such as creating the label and appending the end token.
170-
- `keras_nlp.models.GPT2Backbone`: the GPT2 model, which is a stack of
171-
`keras_nlp.layers.TransformerDecoder`. This is usually just referred as
170+
- `keras_hub.models.GPT2Backbone`: the GPT2 model, which is a stack of
171+
`keras_hub.layers.TransformerDecoder`. This is usually just referred as
172172
`GPT2`.
173-
- `keras_nlp.models.GPT2CausalLM`: wraps `GPT2Backbone`, it multiplies the
173+
- `keras_hub.models.GPT2CausalLM`: wraps `GPT2Backbone`, it multiplies the
174174
output of `GPT2Backbone` by embedding matrix to generate logits over
175175
vocab tokens.
176176
"""
177177

178178
"""
179179
## Finetune on Reddit dataset
180180
181-
Now you have the knowledge of the GPT-2 model from KerasNLP, you can take one
181+
Now you have the knowledge of the GPT-2 model from KerasHub, you can take one
182182
step further to finetune the model so that it generates text in a specific
183183
style, short or long, strict or casual. In this tutorial, we will use reddit
184184
dataset for example.
@@ -217,7 +217,7 @@
217217
"""
218218
Now you can finetune the model using the familiar *fit()* function. Note that
219219
`preprocessor` will be automatically called inside `fit` method since
220-
`GPT2CausalLM` is a `keras_nlp.models.Task` instance.
220+
`GPT2CausalLM` is a `keras_hub.models.Task` instance.
221221
222222
This step takes quite a bit of GPU memory and a long time if we were to train
223223
it all the way to a fully trained state. Here we just use part of the dataset
@@ -261,7 +261,7 @@
261261
"""
262262
## Into the Sampling Method
263263
264-
In KerasNLP, we offer a few sampling methods, e.g., contrastive search,
264+
In KerasHub, we offer a few sampling methods, e.g., contrastive search,
265265
Top-K and beam sampling. By default, our `GPT2CausalLM` uses Top-k search, but
266266
you can choose your own sampling method.
267267
@@ -270,7 +270,7 @@
270270
271271
- Use a string identifier, such as "greedy", you are using the default
272272
configuration via this way.
273-
- Pass a `keras_nlp.samplers.Sampler` instance, you can use custom configuration
273+
- Pass a `keras_hub.samplers.Sampler` instance, you can use custom configuration
274274
via this way.
275275
"""
276276

@@ -281,16 +281,16 @@
281281
print(output)
282282

283283
# Use a `Sampler` instance. `GreedySampler` tends to repeat itself,
284-
greedy_sampler = keras_nlp.samplers.GreedySampler()
284+
greedy_sampler = keras_hub.samplers.GreedySampler()
285285
gpt2_lm.compile(sampler=greedy_sampler)
286286

287287
output = gpt2_lm.generate("I like basketball", max_length=200)
288288
print("\nGPT-2 output:")
289289
print(output)
290290

291291
"""
292-
For more details on KerasNLP `Sampler` class, you can check the code
293-
[here](https://github.com/keras-team/keras-nlp/tree/master/keras_nlp/samplers).
292+
For more details on KerasHub `Sampler` class, you can check the code
293+
[here](https://github.com/keras-team/keras-hub/tree/master/keras_hub/samplers).
294294
"""
295295

296296
"""

0 commit comments

Comments
 (0)