Skip to content

Commit c99e77b

Browse files
Migrating Abstractive Text Summarization with BART example to Keras 3 (#1807)
* migrated the bart summarization example * .md and .ipynb files are added
1 parent 215d087 commit c99e77b

3 files changed

+27
-29
lines changed

examples/nlp/abstractive_summarization_with_bart.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
Title: Abstractive Text Summarization with BART
33
Author: [Abheesht Sharma](https://github.com/abheesht17/)
44
Date created: 2023/07/08
5-
Last modified: 2023/07/08
5+
Last modified: 2024/03/20
66
Description: Use KerasNLP to fine-tune BART on the abstractive summarization task.
77
Accelerator: GPU
8+
Converted to Keras 3 by: [Sitam Meur](https://github.com/sitamgithub-MSIT)
89
"""
910

1011
"""
@@ -42,8 +43,8 @@
4243
"""
4344

4445
"""
45-
This examples uses [Keras Core](https://keras.io/keras_core/) to work in any of
46-
`"tensorflow"`, `"jax"` or `"torch"`. Support for Keras Core is baked into
46+
This examples uses [Keras 3](https://keras.io/keras_3/) to work in any of
47+
`"tensorflow"`, `"jax"` or `"torch"`. Support for Keras 3 is baked into
4748
KerasNLP, simply change the `"KERAS_BACKEND"` environment variable to select
4849
the backend of your choice. We select the JAX backend below.
4950
"""
@@ -60,11 +61,10 @@
6061
import time
6162

6263
import keras_nlp
64+
import keras
6365
import tensorflow as tf
6466
import tensorflow_datasets as tfds
6567

66-
import keras_core as keras
67-
6868
"""
6969
Let's also define our hyperparameters.
7070
"""

examples/nlp/ipynb/abstractive_summarization_with_bart.ipynb

+18-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"\n",
1111
"**Author:** [Abheesht Sharma](https://github.com/abheesht17/)<br>\n",
1212
"**Date created:** 2023/07/08<br>\n",
13-
"**Last modified:** 2023/07/08<br>\n",
13+
"**Last modified:** 2024/03/20<br>\n",
1414
"**Description:** Use KerasNLP to fine-tune BART on the abstractive summarization task."
1515
]
1616
},
@@ -56,7 +56,7 @@
5656
},
5757
{
5858
"cell_type": "code",
59-
"execution_count": 0,
59+
"execution_count": null,
6060
"metadata": {
6161
"colab_type": "code"
6262
},
@@ -71,15 +71,15 @@
7171
"colab_type": "text"
7272
},
7373
"source": [
74-
"This examples uses [Keras Core](https://keras.io/keras_core/) to work in any of\n",
75-
"`\"tensorflow\"`, `\"jax\"` or `\"torch\"`. Support for Keras Core is baked into\n",
74+
"This examples uses [Keras 3](https://keras.io/keras_3/) to work in any of\n",
75+
"`\"tensorflow\"`, `\"jax\"` or `\"torch\"`. Support for Keras 3 is baked into\n",
7676
"KerasNLP, simply change the `\"KERAS_BACKEND\"` environment variable to select\n",
7777
"the backend of your choice. We select the JAX backend below."
7878
]
7979
},
8080
{
8181
"cell_type": "code",
82-
"execution_count": 0,
82+
"execution_count": null,
8383
"metadata": {
8484
"colab_type": "code"
8585
},
@@ -101,7 +101,7 @@
101101
},
102102
{
103103
"cell_type": "code",
104-
"execution_count": 0,
104+
"execution_count": null,
105105
"metadata": {
106106
"colab_type": "code"
107107
},
@@ -111,10 +111,9 @@
111111
"import time\n",
112112
"\n",
113113
"import keras_nlp\n",
114+
"import keras\n",
114115
"import tensorflow as tf\n",
115-
"import tensorflow_datasets as tfds\n",
116-
"\n",
117-
"import keras_core as keras"
116+
"import tensorflow_datasets as tfds"
118117
]
119118
},
120119
{
@@ -128,7 +127,7 @@
128127
},
129128
{
130129
"cell_type": "code",
131-
"execution_count": 0,
130+
"execution_count": null,
132131
"metadata": {
133132
"colab_type": "code"
134133
},
@@ -156,7 +155,7 @@
156155
},
157156
{
158157
"cell_type": "code",
159-
"execution_count": 0,
158+
"execution_count": null,
160159
"metadata": {
161160
"colab_type": "code"
162161
},
@@ -187,7 +186,7 @@
187186
},
188187
{
189188
"cell_type": "code",
190-
"execution_count": 0,
189+
"execution_count": null,
191190
"metadata": {
192191
"colab_type": "code"
193192
},
@@ -215,7 +214,7 @@
215214
},
216215
{
217216
"cell_type": "code",
218-
"execution_count": 0,
217+
"execution_count": null,
219218
"metadata": {
220219
"colab_type": "code"
221220
},
@@ -255,7 +254,7 @@
255254
},
256255
{
257256
"cell_type": "code",
258-
"execution_count": 0,
257+
"execution_count": null,
259258
"metadata": {
260259
"colab_type": "code"
261260
},
@@ -285,7 +284,7 @@
285284
},
286285
{
287286
"cell_type": "code",
288-
"execution_count": 0,
287+
"execution_count": null,
289288
"metadata": {
290289
"colab_type": "code"
291290
},
@@ -322,7 +321,7 @@
322321
},
323322
{
324323
"cell_type": "code",
325-
"execution_count": 0,
324+
"execution_count": null,
326325
"metadata": {
327326
"colab_type": "code"
328327
},
@@ -351,7 +350,7 @@
351350
},
352351
{
353352
"cell_type": "code",
354-
"execution_count": 0,
353+
"execution_count": null,
355354
"metadata": {
356355
"colab_type": "code"
357356
},
@@ -399,7 +398,7 @@
399398
},
400399
{
401400
"cell_type": "code",
402-
"execution_count": 0,
401+
"execution_count": null,
403402
"metadata": {
404403
"colab_type": "code"
405404
},
@@ -454,4 +453,4 @@
454453
},
455454
"nbformat": 4,
456455
"nbformat_minor": 0
457-
}
456+
}

examples/nlp/md/abstractive_summarization_with_bart.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Author:** [Abheesht Sharma](https://github.com/abheesht17/)<br>
44
**Date created:** 2023/07/08<br>
5-
**Last modified:** 2023/07/08<br>
5+
**Last modified:** 2024/03/20<br>
66
**Description:** Use KerasNLP to fine-tune BART on the abstractive summarization task.
77

88

@@ -59,8 +59,8 @@ couple of utility libraries.
5959
6060
```
6161
</div>
62-
This examples uses [Keras Core](https://keras.io/keras_core/) to work in any of
63-
`"tensorflow"`, `"jax"` or `"torch"`. Support for Keras Core is baked into
62+
This examples uses [Keras 3](https://keras.io/keras_3) to work in any of
63+
`"tensorflow"`, `"jax"` or `"torch"`. Support for Keras 3 is baked into
6464
KerasNLP, simply change the `"KERAS_BACKEND"` environment variable to select
6565
the backend of your choice. We select the JAX backend below.
6666

@@ -79,10 +79,9 @@ import py7zr
7979
import time
8080

8181
import keras_nlp
82+
import keras
8283
import tensorflow as tf
8384
import tensorflow_datasets as tfds
84-
85-
import keras_core as keras
8685
```
8786

8887
<div class="k-default-codeblock">

0 commit comments

Comments
 (0)