|
21 | 21 | }, |
22 | 22 | { |
23 | 23 | "cell_type": "code", |
24 | | - "execution_count": null, |
| 24 | + "execution_count": 1, |
25 | 25 | "metadata": { |
26 | 26 | "cellView": "form", |
27 | 27 | "id": "tuOe1ymfHZPu" |
|
88 | 88 | "* A 7B instruction-tuned code model\n", |
89 | 89 | "* A 2B model, trained specifically for code infilling and open-ended generation.\n", |
90 | 90 | "\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" |
92 | 92 | ] |
93 | 93 | }, |
94 | 94 | { |
|
161 | 161 | }, |
162 | 162 | { |
163 | 163 | "cell_type": "code", |
164 | | - "execution_count": null, |
| 164 | + "execution_count": 2, |
165 | 165 | "metadata": { |
166 | 166 | "id": "DrBoa_Urw9Vx" |
167 | 167 | }, |
|
185 | 185 | }, |
186 | 186 | { |
187 | 187 | "cell_type": "code", |
188 | | - "execution_count": null, |
| 188 | + "execution_count": 3, |
189 | 189 | "metadata": { |
190 | 190 | "id": "KWOQ2sJocj-w" |
191 | 191 | }, |
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 | + ], |
193 | 203 | "source": [ |
194 | | - "!pip install -q -U keras-nlp" |
| 204 | + "!pip install -q -U keras-hub\n", |
| 205 | + "!pip install -q -U keras" |
195 | 206 | ] |
196 | 207 | }, |
197 | 208 | { |
|
216 | 227 | }, |
217 | 228 | { |
218 | 229 | "cell_type": "code", |
219 | | - "execution_count": null, |
| 230 | + "execution_count": 4, |
220 | 231 | "metadata": { |
221 | 232 | "id": "ww83zI9ToPso" |
222 | 233 | }, |
|
233 | 244 | "source": [ |
234 | 245 | "### Import packages\n", |
235 | 246 | "\n", |
236 | | - "Import Keras and KerasNLP." |
| 247 | + "Import Keras and KerasHub." |
237 | 248 | ] |
238 | 249 | }, |
239 | 250 | { |
240 | 251 | "cell_type": "code", |
241 | | - "execution_count": null, |
| 252 | + "execution_count": 5, |
242 | 253 | "metadata": { |
243 | 254 | "id": "oQkqsyE1a2YD" |
244 | 255 | }, |
245 | 256 | "outputs": [], |
246 | 257 | "source": [ |
247 | | - "import keras_nlp\n", |
| 258 | + "import keras_hub\n", |
248 | 259 | "import keras\n", |
249 | 260 | "\n", |
250 | 261 | "# Run at half precision.\n", |
|
259 | 270 | "source": [ |
260 | 271 | "### Load Model\n", |
261 | 272 | "\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", |
263 | 274 | "\n", |
264 | 275 | "Create the model using the `from_preset` method:" |
265 | 276 | ] |
266 | 277 | }, |
267 | 278 | { |
268 | 279 | "cell_type": "code", |
269 | | - "execution_count": null, |
| 280 | + "execution_count": 7, |
270 | 281 | "metadata": { |
271 | 282 | "id": "yygIK9DEIldp" |
272 | 283 | }, |
273 | 284 | "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 | + }, |
274 | 334 | { |
275 | 335 | "name": "stderr", |
276 | 336 | "output_type": "stream", |
277 | 337 | "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" |
286 | 339 | ] |
287 | 340 | }, |
288 | 341 | { |
|
301 | 354 | { |
302 | 355 | "data": { |
303 | 356 | "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", |
309 | 362 | "</pre>\n" |
310 | 363 | ], |
311 | 364 | "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" |
317 | 370 | ] |
318 | 371 | }, |
319 | 372 | "metadata": {}, |
|
410 | 463 | } |
411 | 464 | ], |
412 | 465 | "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", |
414 | 467 | "gemma_lm.summary()" |
415 | 468 | ] |
416 | 469 | }, |
|
448 | 501 | }, |
449 | 502 | { |
450 | 503 | "cell_type": "code", |
451 | | - "execution_count": null, |
| 504 | + "execution_count": 8, |
452 | 505 | "metadata": { |
453 | 506 | "id": "tGby-fi8n-Hv" |
454 | 507 | }, |
|
471 | 524 | }, |
472 | 525 | { |
473 | 526 | "cell_type": "code", |
474 | | - "execution_count": null, |
| 527 | + "execution_count": 9, |
475 | 528 | "metadata": { |
476 | 529 | "id": "k1ousdBnr2j8" |
477 | 530 | }, |
|
507 | 560 | }, |
508 | 561 | { |
509 | 562 | "cell_type": "code", |
510 | | - "execution_count": null, |
| 563 | + "execution_count": 10, |
511 | 564 | "metadata": { |
512 | 565 | "id": "N7UlgjSt5QnF" |
513 | 566 | }, |
|
542 | 595 | }, |
543 | 596 | { |
544 | 597 | "cell_type": "code", |
545 | | - "execution_count": null, |
| 598 | + "execution_count": 11, |
546 | 599 | "metadata": { |
547 | 600 | "id": "aae5GHrdpj2_" |
548 | 601 | }, |
|
556 | 609 | "'<|fim_prefix|>import <|fim_suffix|>if __name__ == \"__main__\":\\n sys.exit(0)<|fim_middle|>sys\\n<|file_separator|>'" |
557 | 610 | ] |
558 | 611 | }, |
559 | | - "execution_count": 12, |
| 612 | + "execution_count": 11, |
560 | 613 | "metadata": {}, |
561 | 614 | "output_type": "execute_result" |
562 | 615 | } |
|
582 | 635 | "source": [ |
583 | 636 | "## Summary\n", |
584 | 637 | "\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", |
586 | 639 | "\n", |
587 | 640 | "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" |
588 | 641 | ] |
|
0 commit comments