113113 " \n " ,
114114 " 1. Go to the [Gemma 2](https://www.kaggle.com/models/keras/gemma2) model page, and accept\n " ,
115115 " the license at the banner at the top.\n " ,
116- " 2. Generate an Kaggle API key by going to [Kaggle settings](https://www.kaggle.com/settings)\n " ,
116+ " 2. Generate a Kaggle API key by going to [Kaggle settings](https://www.kaggle.com/settings)\n " ,
117117 " and clicking \" Create New Token\" button under the \" API\" section.\n " ,
118118 " 3. Inside your colab notebook, click on the key icon on the left hand toolbar. Add two\n " ,
119119 " secrets: `KAGGLE_USERNAME` with your username, and `KAGGLE_KEY` with the API key you just\n " ,
169169 " range, or resizing inputs to a specific size. This class encapsulates the image-specific\n " ,
170170 " preprocessing.\n " ,
171171 " * **Inherits from**: `keras.layers.Layer`.\n " ,
172- " * **AudioConveter **: `keras_hub.layers.AudioConveter `.\n " ,
172+ " * **AudioConverter **: `keras_hub.layers.AudioConverter `.\n " ,
173173 " * **What it does**: Converts raw audio to model ready input.\n " ,
174174 " * **Why it's important**: Audio models often need to preprocess raw audio input before\n " ,
175175 " passing it to a model, e.g. by computing a spectrogram of the audio signal. This class\n " ,
181181 " `keras_hub.tokenizers.Tokenizer.from_preset(\" gemma2_2b_en\" )` will create a layer that\n " ,
182182 " tokenizes text using a Gemma2 tokenizer vocabulary.\n " ,
183183 " \n " ,
184- " The figure below shows how all these core classes interact. Arrow indicate composition\n " ,
184+ " The figure below shows how all these core classes interact. Arrows indicate composition\n " ,
185185 " not inheritance (e.g., a task *has a* backbone).\n " ,
186186 " \n " ,
187187 " "
294294 " can view the full list of models shipped directly by the Keras team on\n " ,
295295 " [Kaggle](https://www.kaggle.com/organizations/keras/models).\n " ,
296296 " \n " ,
297- " A task is just a subclass of `keras.Model` \u2014 you can use `fit()`, `compile()`, and\n " ,
297+ " A task is just a subclass of `keras.Model` — you can use `fit()`, `compile()`, and\n " ,
298298 " `save()` on our `classifier` object same as any other model. But tasks come with a few\n " ,
299299 " extras provided by the KerasHub library. The first and most important is `from_preset()`,\n " ,
300300 " a special constructor you will see on many classes in KerasHub.\n " ,
320320 " specific outputs, depending on what we are trying to do with the model.\n " ,
321321 " \n " ,
322322 " A **preprocessor** is just a Keras layer that does all the preprocessing for a specific\n " ,
323- " task. In our case, preprocessing with will resize our input image and rescale it to the\n " ,
323+ " task. In our case, preprocessing will resize our input image and rescale it to the\n " ,
324324 " range `[0, 1]` using some ImageNet specific mean and variance data. Let's call our\n " ,
325325 " task's preprocessor and backbone in succession to see what happens to our input shape."
326326 ]
347347 },
348348 "source" : [
349349 " Our raw image is rescaled to `(224, 224)` during preprocessing and finally\n " ,
350- " downscaled to a `(7, 7)` image of 2048 feature vectors \u2014 the latent space of the\n " ,
350+ " downscaled to a `(7, 7)` image of 2048 feature vectors — the latent space of the\n " ,
351351 " ResNet model. Note that ResNet can actually handle images of arbitrary sizes,\n " ,
352352 " though performance will eventually fall off if your image is very different\n " ,
353353 " sized than the pretrained data. If you'd like to disable the resizing in the\n " ,
562562 " The net effect is that we will explore our model's distribution much more broadly each\n " ,
563563 " time we generate output. Generation will now be a random process, each time we re-run\n " ,
564564 " generate we will get a different result. We can note that the results feel \" looser\" than\n " ,
565- " greedy search \u2014 more minor mistakes and a less consistent tone.\n " ,
565+ " greedy search — more minor mistakes and a less consistent tone.\n " ,
566566 " \n " ,
567567 " You can look at all the samplers Keras supports at [keras_hub.samplers](https://keras.io/api/keras_hub/samplers/).\n " ,
568568 " \n " ,
841841 " Huggingface models hub and share them with others. `keras_hub.upload_preset` allows you\n " ,
842842 " to upload a saved preset.\n " ,
843843 " \n " ,
844- " In this case, we will upload to Kaggle. We have already authenticated with Kaggle to, \n " ,
845- " download the Gemma model earlier. Running the following cell well upload a new model\n " ,
844+ " In this case, we will upload to Kaggle. We have already authenticated with Kaggle to\n " ,
845+ " download the Gemma model earlier. Running the following cell will upload a new model\n " ,
846846 " to Kaggle."
847847 ]
848848 },
980980 "colab_type" : " text"
981981 },
982982 "source" : [
983- " The IMDb dataset contrains a large amount of unlabeled movie reviews. We don't need those\n " ,
983+ " The IMDb dataset contains a large amount of unlabeled movie reviews. We don't need those\n " ,
984984 " here, we can simply delete them."
985985 ]
986986 },
11191119 " \" token_ids\" : x,\n " ,
11201120 " \" padding_mask\" : x != tokenizer.pad_token_id,\n " ,
11211121 " }\n " ,
1122- " return keras.utils.pack_x_y_sample_weight(x, y)\n " ,
1123- " "
1122+ " return keras.utils.pack_x_y_sample_weight(x, y)\n "
11241123 ]
11251124 },
11261125 {
11851184 " \n " ,
11861185 " Since the Gemma model is a generative model, information only passed from left to right\n " ,
11871186 " in the sequence. The only token representation that can \" see\" the entire movie review\n " ,
1188- " input is the final token in each review. We can write a simple pooling layer to do this \u2014 \n " ,
1187+ " input is the final token in each review. We can write a simple pooling layer to do this — \n " ,
11891188 " we will simply grab the last non-padding position of each input sequence. There's no special\n " ,
11901189 " process to writing a layer like this, we can use Keras and `keras.ops` normally."
11911190 ]
12061205 " end_positions = ops.sum(padding_mask, axis=1, keepdims=True) - 1\n " ,
12071206 " end_positions = ops.cast(end_positions, \" int\" )[:, :, None]\n " ,
12081207 " outputs = ops.take_along_axis(inputs, end_positions, axis=1)\n " ,
1209- " return ops.squeeze(outputs, axis=1)\n " ,
1210- " "
1208+ " return ops.squeeze(outputs, axis=1)\n "
12111209 ]
12121210 },
12131211 {
12911289 "colab_type" : " text"
12921290 },
12931291 "source" : [
1294- " After enabling LoRA, our model goes from 10GB of traininable parameters to just 20MB.\n " ,
1292+ " After enabling LoRA, our model goes from 10GB of trainable parameters to just 20MB.\n " ,
12951293 " That means the space used by optimizer variables will no longer be a concern.\n " ,
12961294 " \n " ,
12971295 " With all that set up, we can compile and train our model as normal."
13901388 },
13911389 "nbformat" : 4 ,
13921390 "nbformat_minor" : 0
1393- }
1391+ }
0 commit comments