├── README.md └── google_gemma_get_started.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # open-source-llms -------------------------------------------------------------------------------- /google_gemma_get_started.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "gpuType": "T4", 8 | "authorship_tag": "ABX9TyNU3z09FX+Y8fzBLQZN7riR", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | }, 18 | "accelerator": "GPU" 19 | }, 20 | "cells": [ 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "id": "view-in-github", 25 | "colab_type": "text" 26 | }, 27 | "source": [ 28 | "\"Open" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "source": [ 34 | "# Google Gemma Get Started\n", 35 | "\n", 36 | "`Gemma` is a family of lightweight, state-of-the-art open models built from the same research and technology used to create the `Gemini` models,developed by Google DeepMind and other teams across Google.\n", 37 | "\n", 38 | "## Key details\n", 39 | "\n", 40 | "- 2 sizes: 2B and 7B, each of which is released with pre-trained and instruction-tuned variants.\n", 41 | "- Toolchains for inference and supervised fine-tuning (SFT) across all major frameworks: `JAX`, `PyTorch`, and `TensorFlow` through native **Keras 3.0**.\n", 42 | "- Ready-to-use Colab and Kaggle notebooks\n", 43 | " - Colab notebook: https://ai.google.dev/gemma/docs/get_started\n", 44 | "- Optimization across multiple AI hardware platforms ensures industry-leading performance, including NVIDIA GPUs and Google Cloud TPUs.\n", 45 | "- Terms of use permit responsible commercial usage and distribution for all organizations, regardless of size.\n", 46 | "\n", 47 | "## Keras 3\n", 48 | "\n", 49 | "Keras version 3 is required to run Gemma model on Keras.\n", 50 | "\n", 51 | "Keras is a simple, flexible and powerful deep learning API written in Python and capable of running on top of either JAX, TensorFlow, or PyTorch.\n", 52 | "\n", 53 | "## Gemma on Kaggle\n", 54 | "\n", 55 | "`Kaggle` is an online community platform for data scientists and machine learning enthusiasts.\n", 56 | "\n", 57 | "We can find Gemma models information @ https://www.kaggle.com/models/google/gemma/frameworks/keras.\n", 58 | "\n", 59 | "\n", 60 | "\n", 61 | "\n", 62 | "\n" 63 | ], 64 | "metadata": { 65 | "id": "h1EfSJIrRzfH" 66 | } 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": { 72 | "colab": { 73 | "base_uri": "https://localhost:8080/" 74 | }, 75 | "id": "rSq38qIPwBFX", 76 | "outputId": "d4c37d67-db4b-48fa-87ee-d8ec1120767a" 77 | }, 78 | "outputs": [ 79 | { 80 | "output_type": "stream", 81 | "name": "stdout", 82 | "text": [ 83 | "Collecting keras-nlp\n", 84 | " Downloading keras_nlp-0.8.0-py3-none-any.whl (465 kB)\n", 85 | "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/465.2 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━\u001b[0m \u001b[32m337.9/465.2 kB\u001b[0m \u001b[31m10.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m465.2/465.2 kB\u001b[0m \u001b[31m9.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 86 | "\u001b[?25hCollecting keras-core (from keras-nlp)\n", 87 | " Downloading keras_core-0.1.7-py3-none-any.whl (950 kB)\n", 88 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m950.8/950.8 kB\u001b[0m \u001b[31m17.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 89 | "\u001b[?25hRequirement already satisfied: absl-py in /usr/local/lib/python3.10/dist-packages (from keras-nlp) (1.4.0)\n", 90 | "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from keras-nlp) (1.25.2)\n", 91 | "Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from keras-nlp) (23.2)\n", 92 | "Requirement already satisfied: regex in /usr/local/lib/python3.10/dist-packages (from keras-nlp) (2023.12.25)\n", 93 | "Requirement already satisfied: rich in /usr/local/lib/python3.10/dist-packages (from keras-nlp) (13.7.0)\n", 94 | "Requirement already satisfied: dm-tree in /usr/local/lib/python3.10/dist-packages (from keras-nlp) (0.1.8)\n", 95 | "Requirement already satisfied: kagglehub in /usr/local/lib/python3.10/dist-packages (from keras-nlp) (0.1.9)\n", 96 | "Collecting tensorflow-text (from keras-nlp)\n", 97 | " Downloading tensorflow_text-2.15.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.2 MB)\n", 98 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.2/5.2 MB\u001b[0m \u001b[31m34.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 99 | "\u001b[?25hRequirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from kagglehub->keras-nlp) (2.31.0)\n", 100 | "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from kagglehub->keras-nlp) (4.66.2)\n", 101 | "Collecting namex (from keras-core->keras-nlp)\n", 102 | " Downloading namex-0.0.7-py3-none-any.whl (5.8 kB)\n", 103 | "Requirement already satisfied: h5py in /usr/local/lib/python3.10/dist-packages (from keras-core->keras-nlp) (3.9.0)\n", 104 | "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich->keras-nlp) (3.0.0)\n", 105 | "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich->keras-nlp) (2.16.1)\n", 106 | "Requirement already satisfied: tensorflow-hub>=0.13.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow-text->keras-nlp) (0.16.1)\n", 107 | "Requirement already satisfied: tensorflow<2.16,>=2.15.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow-text->keras-nlp) (2.15.0)\n", 108 | "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich->keras-nlp) (0.1.2)\n", 109 | "Requirement already satisfied: astunparse>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (1.6.3)\n", 110 | "Requirement already satisfied: flatbuffers>=23.5.26 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (23.5.26)\n", 111 | "Requirement already satisfied: gast!=0.5.0,!=0.5.1,!=0.5.2,>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (0.5.4)\n", 112 | "Requirement already satisfied: google-pasta>=0.1.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (0.2.0)\n", 113 | "Requirement already satisfied: libclang>=13.0.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (16.0.6)\n", 114 | "Requirement already satisfied: ml-dtypes~=0.2.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (0.2.0)\n", 115 | "Requirement already satisfied: opt-einsum>=2.3.2 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (3.3.0)\n", 116 | "Requirement already satisfied: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (3.20.3)\n", 117 | "Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (67.7.2)\n", 118 | "Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (1.16.0)\n", 119 | "Requirement already satisfied: termcolor>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (2.4.0)\n", 120 | "Requirement already satisfied: typing-extensions>=3.6.6 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (4.9.0)\n", 121 | "Requirement already satisfied: wrapt<1.15,>=1.11.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (1.14.1)\n", 122 | "Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (0.36.0)\n", 123 | "Requirement already satisfied: grpcio<2.0,>=1.24.3 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (1.60.1)\n", 124 | "Requirement already satisfied: tensorboard<2.16,>=2.15 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (2.15.2)\n", 125 | "Requirement already satisfied: tensorflow-estimator<2.16,>=2.15.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (2.15.0)\n", 126 | "Requirement already satisfied: keras<2.16,>=2.15.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (2.15.0)\n", 127 | "Requirement already satisfied: tf-keras>=2.14.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow-hub>=0.13.0->tensorflow-text->keras-nlp) (2.15.0)\n", 128 | "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->kagglehub->keras-nlp) (3.3.2)\n", 129 | "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->kagglehub->keras-nlp) (3.6)\n", 130 | "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->kagglehub->keras-nlp) (2.0.7)\n", 131 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->kagglehub->keras-nlp) (2024.2.2)\n", 132 | "Requirement already satisfied: wheel<1.0,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from astunparse>=1.6.0->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (0.42.0)\n", 133 | "Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (2.27.0)\n", 134 | "Requirement already satisfied: google-auth-oauthlib<2,>=0.5 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (1.2.0)\n", 135 | "Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (3.5.2)\n", 136 | "Requirement already satisfied: tensorboard-data-server<0.8.0,>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (0.7.2)\n", 137 | "Requirement already satisfied: werkzeug>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (3.0.1)\n", 138 | "Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (5.3.2)\n", 139 | "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (0.3.0)\n", 140 | "Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (4.9)\n", 141 | "Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from google-auth-oauthlib<2,>=0.5->tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (1.3.1)\n", 142 | "Requirement already satisfied: MarkupSafe>=2.1.1 in /usr/local/lib/python3.10/dist-packages (from werkzeug>=1.0.1->tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (2.1.5)\n", 143 | "Requirement already satisfied: pyasn1<0.6.0,>=0.4.6 in /usr/local/lib/python3.10/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (0.5.1)\n", 144 | "Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.10/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<2,>=0.5->tensorboard<2.16,>=2.15->tensorflow<2.16,>=2.15.0->tensorflow-text->keras-nlp) (3.2.2)\n", 145 | "Installing collected packages: namex, keras-core, tensorflow-text, keras-nlp\n", 146 | "Successfully installed keras-core-0.1.7 keras-nlp-0.8.0 namex-0.0.7 tensorflow-text-2.15.0\n", 147 | "Requirement already satisfied: keras in /usr/local/lib/python3.10/dist-packages (2.15.0)\n", 148 | "Collecting keras\n", 149 | " Downloading keras-3.0.5-py3-none-any.whl (1.0 MB)\n", 150 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m13.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 151 | "\u001b[?25hRequirement already satisfied: absl-py in /usr/local/lib/python3.10/dist-packages (from keras) (1.4.0)\n", 152 | "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from keras) (1.25.2)\n", 153 | "Requirement already satisfied: rich in /usr/local/lib/python3.10/dist-packages (from keras) (13.7.0)\n", 154 | "Requirement already satisfied: namex in /usr/local/lib/python3.10/dist-packages (from keras) (0.0.7)\n", 155 | "Requirement already satisfied: h5py in /usr/local/lib/python3.10/dist-packages (from keras) (3.9.0)\n", 156 | "Requirement already satisfied: dm-tree in /usr/local/lib/python3.10/dist-packages (from keras) (0.1.8)\n", 157 | "Requirement already satisfied: ml-dtypes in /usr/local/lib/python3.10/dist-packages (from keras) (0.2.0)\n", 158 | "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich->keras) (3.0.0)\n", 159 | "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich->keras) (2.16.1)\n", 160 | "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich->keras) (0.1.2)\n", 161 | "Installing collected packages: keras\n", 162 | " Attempting uninstall: keras\n", 163 | " Found existing installation: keras 2.15.0\n", 164 | " Uninstalling keras-2.15.0:\n", 165 | " Successfully uninstalled keras-2.15.0\n", 166 | "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", 167 | "tensorflow 2.15.0 requires keras<2.16,>=2.15.0, but you have keras 3.0.5 which is incompatible.\u001b[0m\u001b[31m\n", 168 | "\u001b[0mSuccessfully installed keras-3.0.5\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "!pip install -U keras-nlp\n", 174 | "!pip install -U keras" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "source": [ 180 | "from google.colab import userdata\n", 181 | "import os\n", 182 | "\n", 183 | "os.environ[\"KAGGLE_USERNAME\"] = userdata.get('KAGGLE_USERNAME')\n", 184 | "os.environ[\"KAGGLE_KEY\"] = userdata.get('KAGGLE_KEY')\n", 185 | "\n", 186 | "def generate_kaggle_json():\n", 187 | " username = userdata.get(\"KAGGLE_USERNAME\")\n", 188 | " key = userdata.get(\"KAGGLE_KEY\")\n", 189 | "\n", 190 | " home_dir = os.path.expanduser(\"~\")\n", 191 | " dot_kaggle_dir = f\"{home_dir}/.kaggle\"\n", 192 | "\n", 193 | " if not os.path.exists(dot_kaggle_dir) or not os.path.isdir(dot_kaggle_dir):\n", 194 | " os.makedirs(dot_kaggle_dir)\n", 195 | "\n", 196 | " with open(f\"{dot_kaggle_dir}/kaggle.json\", \"w\") as file:\n", 197 | " file.write('{\"username\":\"' + username + '\",\"key\":\"' + key + '\"}')\n" 198 | ], 199 | "metadata": { 200 | "id": "G6Cho1nz549D" 201 | }, 202 | "execution_count": null, 203 | "outputs": [] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "source": [ 208 | "# generate_kaggle_json()" 209 | ], 210 | "metadata": { 211 | "id": "08lFr9Hi7wjO" 212 | }, 213 | "execution_count": null, 214 | "outputs": [] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "source": [ 219 | "import keras\n", 220 | "import keras_nlp\n", 221 | "import numpy as np" 222 | ], 223 | "metadata": { 224 | "id": "Ty7VqJWXwGIv" 225 | }, 226 | "execution_count": null, 227 | "outputs": [] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "source": [ 232 | "print(keras.__version__)" 233 | ], 234 | "metadata": { 235 | "colab": { 236 | "base_uri": "https://localhost:8080/" 237 | }, 238 | "id": "f8KUp23y-szu", 239 | "outputId": "b1e7c739-479b-40fb-c511-3436ee7531a6" 240 | }, 241 | "execution_count": 12, 242 | "outputs": [ 243 | { 244 | "output_type": "stream", 245 | "name": "stdout", 246 | "text": [ 247 | "3.0.5\n" 248 | ] 249 | } 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "source": [ 255 | "gemma_lm = keras_nlp.models.GemmaCausalLM.from_preset(\"gemma_instruct_2b_en\")\n", 256 | "gemma_lm.generate(\"Keras is a\", max_length=30)" 257 | ], 258 | "metadata": { 259 | "colab": { 260 | "base_uri": "https://localhost:8080/", 261 | "height": 128 262 | }, 263 | "id": "9LqUwDEKxtcc", 264 | "outputId": "1a5cb0e8-b5ff-44ae-ef06-14c8853c4c6d" 265 | }, 266 | "execution_count": null, 267 | "outputs": [ 268 | { 269 | "output_type": "stream", 270 | "name": "stderr", 271 | "text": [ 272 | "Attaching 'config.json' from model 'keras/gemma/keras/gemma_instruct_2b_en/1' to your Colab notebook...\n", 273 | "Attaching 'config.json' from model 'keras/gemma/keras/gemma_instruct_2b_en/1' to your Colab notebook...\n", 274 | "Attaching 'model.weights.h5' from model 'keras/gemma/keras/gemma_instruct_2b_en/1' to your Colab notebook...\n", 275 | "Attaching 'tokenizer.json' from model 'keras/gemma/keras/gemma_instruct_2b_en/1' to your Colab notebook...\n", 276 | "Attaching 'assets/tokenizer/vocabulary.spm' from model 'keras/gemma/keras/gemma_instruct_2b_en/1' to your Colab notebook...\n" 277 | ] 278 | }, 279 | { 280 | "output_type": "execute_result", 281 | "data": { 282 | "text/plain": [ 283 | "'Keras is a deep learning library for Python that provides a wide range of tools and functionalities for building, training, and evaluating deep learning models.'" 284 | ], 285 | "application/vnd.google.colaboratory.intrinsic+json": { 286 | "type": "string" 287 | } 288 | }, 289 | "metadata": {}, 290 | "execution_count": 5 291 | } 292 | ] 293 | }, 294 | { 295 | "cell_type": "markdown", 296 | "source": [ 297 | "### Batch Prompts" 298 | ], 299 | "metadata": { 300 | "id": "W_C0ZAKmXf5w" 301 | } 302 | }, 303 | { 304 | "cell_type": "code", 305 | "source": [ 306 | "gemma_lm.generate([\"Keras is a\", \"The sky is blue because\"], max_length=30)" 307 | ], 308 | "metadata": { 309 | "colab": { 310 | "base_uri": "https://localhost:8080/" 311 | }, 312 | "id": "2MQHqANrXTmo", 313 | "outputId": "64b73cfd-0c98-46e6-a62e-72124f93d1f1" 314 | }, 315 | "execution_count": null, 316 | "outputs": [ 317 | { 318 | "output_type": "execute_result", 319 | "data": { 320 | "text/plain": [ 321 | "['Keras is a deep learning library for Python that provides a wide range of tools and functionalities for building, training, and evaluating deep learning models.',\n", 322 | " 'The sky is blue because of Rayleigh scattering. Rayleigh scattering is the scattering of light by particles of a similar size to the wavelength of light. In']" 323 | ] 324 | }, 325 | "metadata": {}, 326 | "execution_count": 6 327 | } 328 | ] 329 | }, 330 | { 331 | "cell_type": "markdown", 332 | "source": [ 333 | "### Different Sampler\n", 334 | "\n", 335 | "By default, `greedy` sampling is used for GemmaCausalLM. Let's switch it to `top_k`." 336 | ], 337 | "metadata": { 338 | "id": "cMwd_BgCYA4x" 339 | } 340 | }, 341 | { 342 | "cell_type": "code", 343 | "source": [ 344 | "gemma_lm.compile(sampler=\"top_k\")\n", 345 | "gemma_lm.generate(\"Premier league is the best league in Europe because\", max_length=64)" 346 | ], 347 | "metadata": { 348 | "id": "2dzNkyw3YSH8", 349 | "colab": { 350 | "base_uri": "https://localhost:8080/", 351 | "height": 54 352 | }, 353 | "outputId": "1f97e312-22eb-44e3-84f1-70372e4a67e2" 354 | }, 355 | "execution_count": 13, 356 | "outputs": [ 357 | { 358 | "output_type": "execute_result", 359 | "data": { 360 | "text/plain": [ 361 | "'Premier league is the best league in Europe because it offers the most competitive, challenging, and exciting football experience. The league is consistently one of the most-watched sporting events globally, and it attracts the best players in the world.\\n\\n**a) True**\\nb) False\\n\\n\\n**Answer: a) True'" 362 | ], 363 | "application/vnd.google.colaboratory.intrinsic+json": { 364 | "type": "string" 365 | } 366 | }, 367 | "metadata": {}, 368 | "execution_count": 13 369 | } 370 | ] 371 | } 372 | ] 373 | } --------------------------------------------------------------------------------