Skip to content

Commit

Permalink
gpt2 example docs fix (#1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
sitamgithub-MSIT authored Apr 13, 2024
1 parent b316764 commit 39a09fc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions examples/generative/gpt2_text_generation_with_kerasnlp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Title: GPT2 Text Generation with KerasNLP
Author: Chen Qian
Date created: 04/17/2023
Last modified: 04/17/2023
Date created: 2023/04/17
Last modified: 2024/04/12
Description: Use KerasNLP GPT2 model and `samplers` to do text generation.
Accelerator: GPU
"""
Expand All @@ -27,8 +27,8 @@
"""
## Install KerasNLP, Choose Backend and Import Dependencies
This examples uses [Keras Core](https://keras.io/keras_core/) to work in any of
`"tensorflow"`, `"jax"` or `"torch"`. Support for Keras Core is baked into
This examples uses [Keras 3](https://keras.io/keras_3/) to work in any of
`"tensorflow"`, `"jax"` or `"torch"`. Support for Keras 3 is baked into
KerasNLP, simply change the `"KERAS_BACKEND"` environment variable to select
the backend of your choice. We select the JAX backend below.
"""
Expand Down
52 changes: 26 additions & 26 deletions examples/generative/ipynb/gpt2_text_generation_with_kerasnlp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"# GPT2 Text Generation with KerasNLP\n",
"\n",
"**Author:** Chen Qian<br>\n",
"**Date created:** 04/17/2023<br>\n",
"**Last modified:** 04/17/2023<br>\n",
"**Date created:** 2023/04/17<br>\n",
"**Last modified:** 2024/04/12<br>\n",
"**Description:** Use KerasNLP GPT2 model and `samplers` to do text generation."
]
},
Expand Down Expand Up @@ -49,15 +49,15 @@
"source": [
"## Install KerasNLP, Choose Backend and Import Dependencies\n",
"\n",
"This examples uses [Keras Core](https://keras.io/keras_core/) to work in any of\n",
"`\"tensorflow\"`, `\"jax\"` or `\"torch\"`. Support for Keras Core is baked into\n",
"This examples uses [Keras 3](https://keras.io/keras_3/) to work in any of\n",
"`\"tensorflow\"`, `\"jax\"` or `\"torch\"`. Support for Keras 3 is baked into\n",
"KerasNLP, simply change the `\"KERAS_BACKEND\"` environment variable to select\n",
"the backend of your choice. We select the JAX backend below."
]
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand All @@ -68,7 +68,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand Down Expand Up @@ -157,7 +157,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand Down Expand Up @@ -187,7 +187,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand All @@ -214,7 +214,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand Down Expand Up @@ -291,7 +291,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand All @@ -317,7 +317,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand All @@ -341,7 +341,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand Down Expand Up @@ -372,7 +372,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand Down Expand Up @@ -411,7 +411,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand Down Expand Up @@ -450,7 +450,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand Down Expand Up @@ -500,7 +500,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand All @@ -516,12 +516,12 @@
"colab_type": "text"
},
"source": [
"Load text from the json file. We only use\u300a\u5168\u5510\u8bd7\u300bfor demo purposes."
"Load text from the json file. We only use《全唐诗》for demo purposes."
]
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand All @@ -531,10 +531,10 @@
"import json\n",
"\n",
"poem_collection = []\n",
"for file in os.listdir(\"chinese-poetry/\u5168\u5510\u8bd7\"):\n",
"for file in os.listdir(\"chinese-poetry/全唐诗\"):\n",
" if \".json\" not in file or \"poet\" not in file:\n",
" continue\n",
" full_filename = \"%s/%s\" % (\"chinese-poetry/\u5168\u5510\u8bd7\", file)\n",
" full_filename = \"%s/%s\" % (\"chinese-poetry/全唐诗\", file)\n",
" with open(full_filename, \"r\") as f:\n",
" content = json.load(f)\n",
" poem_collection.extend(content)\n",
Expand All @@ -553,7 +553,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand All @@ -574,7 +574,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
Expand Down Expand Up @@ -618,13 +618,13 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab_type": "code"
},
"outputs": [],
"source": [
"output = gpt2_lm.generate(\"\u6628\u591c\u96e8\u758f\u98ce\u9aa4\", max_length=200)\n",
"output = gpt2_lm.generate(\"昨夜雨疏风骤\", max_length=200)\n",
"print(output)"
]
},
Expand All @@ -634,7 +634,7 @@
"colab_type": "text"
},
"source": [
"Not bad \ud83d\ude00"
"Not bad 😀"
]
}
],
Expand Down Expand Up @@ -667,4 +667,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
8 changes: 4 additions & 4 deletions examples/generative/md/gpt2_text_generation_with_kerasnlp.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# GPT2 Text Generation with KerasNLP

**Author:** Chen Qian<br>
**Date created:** 04/17/2023<br>
**Last modified:** 04/17/2023<br>
**Date created:** 2023/04/17<br>
**Last modified:** 2024/04/12<br>
**Description:** Use KerasNLP GPT2 model and `samplers` to do text generation.


Expand All @@ -27,8 +27,8 @@ GPT-2 model. Running this tutorial on CPU runtime will take hours.
---
## Install KerasNLP, Choose Backend and Import Dependencies

This examples uses [Keras Core](https://keras.io/keras_core/) to work in any of
`"tensorflow"`, `"jax"` or `"torch"`. Support for Keras Core is baked into
This examples uses [Keras 3](https://keras.io/keras_3/) to work in any of
`"tensorflow"`, `"jax"` or `"torch"`. Support for Keras 3 is baked into
KerasNLP, simply change the `"KERAS_BACKEND"` environment variable to select
the backend of your choice. We select the JAX backend below.

Expand Down

0 comments on commit 39a09fc

Please sign in to comment.