Skip to content

Commit 4813240

Browse files
Update keras-nlp to keras-hub (#584)
* Created using Colab * change from keras_nlp to keras_hub * format notebook * remove keras-nlp
1 parent cae5c57 commit 4813240

File tree

1 file changed

+90
-37
lines changed

1 file changed

+90
-37
lines changed

site/en/gemma/docs/codegemma/keras_quickstart.ipynb

Lines changed: 90 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
{
2323
"cell_type": "code",
24-
"execution_count": null,
24+
"execution_count": 1,
2525
"metadata": {
2626
"cellView": "form",
2727
"id": "tuOe1ymfHZPu"
@@ -88,7 +88,7 @@
8888
"* A 7B instruction-tuned code model\n",
8989
"* A 2B model, trained specifically for code infilling and open-ended generation.\n",
9090
"\n",
91-
"This guide walks you through using the CodeGemma 2B model with KerasNLP for a code completion task.\n"
91+
"This guide walks you through using the CodeGemma 2B model with KerasHub for a code completion task.\n"
9292
]
9393
},
9494
{
@@ -161,7 +161,7 @@
161161
},
162162
{
163163
"cell_type": "code",
164-
"execution_count": null,
164+
"execution_count": 2,
165165
"metadata": {
166166
"id": "DrBoa_Urw9Vx"
167167
},
@@ -185,13 +185,24 @@
185185
},
186186
{
187187
"cell_type": "code",
188-
"execution_count": null,
188+
"execution_count": 3,
189189
"metadata": {
190190
"id": "KWOQ2sJocj-w"
191191
},
192-
"outputs": [],
192+
"outputs": [
193+
{
194+
"name": "stdout",
195+
"output_type": "stream",
196+
"text": [
197+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m792.1/792.1 kB\u001b[0m \u001b[31m16.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
198+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m53.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
199+
"\u001b[?25h"
200+
]
201+
}
202+
],
193203
"source": [
194-
"!pip install -q -U keras-nlp"
204+
"!pip install -q -U keras-hub\n",
205+
"!pip install -q -U keras"
195206
]
196207
},
197208
{
@@ -216,7 +227,7 @@
216227
},
217228
{
218229
"cell_type": "code",
219-
"execution_count": null,
230+
"execution_count": 4,
220231
"metadata": {
221232
"id": "ww83zI9ToPso"
222233
},
@@ -233,18 +244,18 @@
233244
"source": [
234245
"### Import packages\n",
235246
"\n",
236-
"Import Keras and KerasNLP."
247+
"Import Keras and KerasHub."
237248
]
238249
},
239250
{
240251
"cell_type": "code",
241-
"execution_count": null,
252+
"execution_count": 5,
242253
"metadata": {
243254
"id": "oQkqsyE1a2YD"
244255
},
245256
"outputs": [],
246257
"source": [
247-
"import keras_nlp\n",
258+
"import keras_hub\n",
248259
"import keras\n",
249260
"\n",
250261
"# Run at half precision.\n",
@@ -259,30 +270,72 @@
259270
"source": [
260271
"### Load Model\n",
261272
"\n",
262-
"KerasNLP provides implementations of many popular [model architectures](https://keras.io/api/keras_nlp/models/){:.external}. In this tutorial, you'll create a model using `GemmaCausalLM`, an end-to-end Gemma model for causal language modeling. A causal language model predicts the next token based on previous tokens.\n",
273+
"KerasHub provides implementations of many popular [model architectures](https://keras.io/api/keras_nlp/models/){:.external}. In this tutorial, you'll create a model using `GemmaCausalLM`, an end-to-end Gemma model for causal language modeling. A causal language model predicts the next token based on previous tokens.\n",
263274
"\n",
264275
"Create the model using the `from_preset` method:"
265276
]
266277
},
267278
{
268279
"cell_type": "code",
269-
"execution_count": null,
280+
"execution_count": 7,
270281
"metadata": {
271282
"id": "yygIK9DEIldp"
272283
},
273284
"outputs": [
285+
{
286+
"name": "stdout",
287+
"output_type": "stream",
288+
"text": [
289+
"Downloading from https://www.kaggle.com/api/v1/models/keras/codegemma/keras/code_gemma_2b_en/2/download/config.json...\n"
290+
]
291+
},
292+
{
293+
"name": "stderr",
294+
"output_type": "stream",
295+
"text": [
296+
"100%|██████████| 785/785 [00:00<00:00, 1.64MB/s]\n"
297+
]
298+
},
299+
{
300+
"name": "stdout",
301+
"output_type": "stream",
302+
"text": [
303+
"Downloading from https://www.kaggle.com/api/v1/models/keras/codegemma/keras/code_gemma_2b_en/2/download/model.weights.h5...\n"
304+
]
305+
},
306+
{
307+
"name": "stderr",
308+
"output_type": "stream",
309+
"text": [
310+
"100%|██████████| 4.67G/4.67G [00:50<00:00, 99.2MB/s]\n"
311+
]
312+
},
313+
{
314+
"name": "stdout",
315+
"output_type": "stream",
316+
"text": [
317+
"Downloading from https://www.kaggle.com/api/v1/models/keras/codegemma/keras/code_gemma_2b_en/2/download/tokenizer.json...\n"
318+
]
319+
},
320+
{
321+
"name": "stderr",
322+
"output_type": "stream",
323+
"text": [
324+
"100%|██████████| 591/591 [00:00<00:00, 946kB/s]\n"
325+
]
326+
},
327+
{
328+
"name": "stdout",
329+
"output_type": "stream",
330+
"text": [
331+
"Downloading from https://www.kaggle.com/api/v1/models/keras/codegemma/keras/code_gemma_2b_en/2/download/assets/tokenizer/vocabulary.spm...\n"
332+
]
333+
},
274334
{
275335
"name": "stderr",
276336
"output_type": "stream",
277337
"text": [
278-
"Downloading from https://www.kaggle.com/api/v1/models/keras/codegemma/keras/code_gemma_2b_en/1/download/config.json...\n",
279-
"100%|██████████| 554/554 [00:00<00:00, 1.41MB/s]\n",
280-
"Downloading from https://www.kaggle.com/api/v1/models/keras/codegemma/keras/code_gemma_2b_en/1/download/model.weights.h5...\n",
281-
"100%|██████████| 4.67G/4.67G [05:06<00:00, 16.4MB/s]\n",
282-
"Downloading from https://www.kaggle.com/api/v1/models/keras/codegemma/keras/code_gemma_2b_en/1/download/tokenizer.json...\n",
283-
"100%|██████████| 401/401 [00:00<00:00, 382kB/s]\n",
284-
"Downloading from https://www.kaggle.com/api/v1/models/keras/codegemma/keras/code_gemma_2b_en/1/download/assets/tokenizer/vocabulary.spm...\n",
285-
"100%|██████████| 4.04M/4.04M [00:01<00:00, 2.41MB/s]\n"
338+
"100%|██████████| 4.04M/4.04M [00:00<00:00, 43.1MB/s]\n"
286339
]
287340
},
288341
{
@@ -301,19 +354,19 @@
301354
{
302355
"data": {
303356
"text/html": [
304-
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
305-
"┃<span style=\"font-weight: bold\"> Tokenizer (type) </span>┃<span style=\"font-weight: bold\"> Vocab # </span>┃\n",
306-
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
307-
"│ gemma_tokenizer (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">GemmaTokenizer</span>) <span style=\"color: #00af00; text-decoration-color: #00af00\">256,000</span> │\n",
308-
"└─────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n",
357+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
358+
"┃<span style=\"font-weight: bold\"> Layer (type) </span>┃<span style=\"font-weight: bold\"> Config </span>┃\n",
359+
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
360+
"│ gemma_tokenizer (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">GemmaTokenizer</span>) Vocab size: <span style=\"color: #00af00; text-decoration-color: #00af00\">256,000</span> │\n",
361+
"└─────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n",
309362
"</pre>\n"
310363
],
311364
"text/plain": [
312-
"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
313-
"\u001b[1m \u001b[0m\u001b[1mTokenizer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Vocab #\u001b[0m\u001b[1m \u001b[0m┃\n",
314-
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
315-
"│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) \u001b[38;5;34m256,000\u001b[0m │\n",
316-
"└─────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n"
365+
"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
366+
"\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Config\u001b[0m\u001b[1m \u001b[0m┃\n",
367+
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
368+
"│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) Vocab size: \u001b[38;5;34m256,000\u001b[0m │\n",
369+
"└─────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n"
317370
]
318371
},
319372
"metadata": {},
@@ -410,7 +463,7 @@
410463
}
411464
],
412465
"source": [
413-
"gemma_lm = keras_nlp.models.GemmaCausalLM.from_preset(\"code_gemma_2b_en\")\n",
466+
"gemma_lm = keras_hub.models.GemmaCausalLM.from_preset(\"code_gemma_2b_en\")\n",
414467
"gemma_lm.summary()"
415468
]
416469
},
@@ -448,7 +501,7 @@
448501
},
449502
{
450503
"cell_type": "code",
451-
"execution_count": null,
504+
"execution_count": 8,
452505
"metadata": {
453506
"id": "tGby-fi8n-Hv"
454507
},
@@ -471,7 +524,7 @@
471524
},
472525
{
473526
"cell_type": "code",
474-
"execution_count": null,
527+
"execution_count": 9,
475528
"metadata": {
476529
"id": "k1ousdBnr2j8"
477530
},
@@ -507,7 +560,7 @@
507560
},
508561
{
509562
"cell_type": "code",
510-
"execution_count": null,
563+
"execution_count": 10,
511564
"metadata": {
512565
"id": "N7UlgjSt5QnF"
513566
},
@@ -542,7 +595,7 @@
542595
},
543596
{
544597
"cell_type": "code",
545-
"execution_count": null,
598+
"execution_count": 11,
546599
"metadata": {
547600
"id": "aae5GHrdpj2_"
548601
},
@@ -556,7 +609,7 @@
556609
"'<|fim_prefix|>import <|fim_suffix|>if __name__ == \"__main__\":\\n sys.exit(0)<|fim_middle|>sys\\n<|file_separator|>'"
557610
]
558611
},
559-
"execution_count": 12,
612+
"execution_count": 11,
560613
"metadata": {},
561614
"output_type": "execute_result"
562615
}
@@ -582,7 +635,7 @@
582635
"source": [
583636
"## Summary\n",
584637
"\n",
585-
"This tutorial walked you through using CodeGemma to infill code based on the surrounding context. Next, check out the [AI Assisted Programming with CodeGemma and KerasNLP notebook](https://ai.google.dev/gemma/docs/codegemma/code_assist_keras) for more examples on how you can use CodeGemma.\n",
638+
"This tutorial walked you through using CodeGemma to infill code based on the surrounding context. Next, check out the [AI Assisted Programming with CodeGemma and KerasHub notebook](https://ai.google.dev/gemma/docs/codegemma/code_assist_keras) for more examples on how you can use CodeGemma.\n",
586639
"\n",
587640
"Also refer to The [CodeGemma model card](https://ai.google.dev/gemma/docs/codegemma/model_card) for the technical specs of the CodeGemma models.\n"
588641
]

0 commit comments

Comments
 (0)