From 205dda726bff4062d06954d96d4e0b28b5d40b99 Mon Sep 17 00:00:00 2001 From: Juyeong Ji Date: Thu, 27 Jun 2024 20:34:26 +0900 Subject: [PATCH 1/4] update the gemma 2 quickstart chat --- Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb | 1225 ++++++--------------- 1 file changed, 316 insertions(+), 909 deletions(-) diff --git a/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb b/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb index c02d0ec..ec29f13 100644 --- a/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb +++ b/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb @@ -37,16 +37,13 @@ "id": "PXNm5_p_oxMF" }, "source": [ - "This is a quick demo of Gemma running on KerasNLP. To run this you will need:\n", - "- To be added to a private github repo for Gemma.\n", - "- To be added to a private Kaggle model for weights.\n", + "This is a quick demo of Gemma running on KerasNLP.\n", "\n", "Note that you will need a large GPU (e.g. A100) to run this as well.\n", "\n", "General Keras reading:\n", "- [Getting started with Keras](https://keras.io/getting_started/)\n", "- [Getting started with KerasNLP](https://keras.io/guides/keras_nlp/getting_started/)\n", - "- [Generation and fine-tuning guide for GPT2](https://keras.io/guides/keras_nlp/getting_started/)\n", "\n", "\n", "
\n", @@ -76,7 +73,9 @@ "from google.colab import userdata\n", "\n", "os.environ[\"KAGGLE_USERNAME\"] = userdata.get('KAGGLE_USERNAME')\n", - "os.environ[\"KAGGLE_KEY\"] = userdata.get('KAGGLE_KEY')" + "os.environ[\"KAGGLE_KEY\"] = userdata.get('KAGGLE_KEY')\n", + "\n", + "os.environ[\"KERAS_BACKEND\"] = \"jax\" # Or \"tensorflow\" or \"torch\"." ] }, { @@ -97,8 +96,8 @@ "outputs": [], "source": [ "# Install all deps\n", - "!pip install keras\n", - "!pip install keras-nlp" + "!pip install -U keras-nlp\n", + "!pip install -U keras==3.3.3" ] }, { @@ -112,78 +111,53 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": { - "id": "ww83zI9ToPso" - }, - "outputs": [], - "source": [ - "os.environ[\"KERAS_BACKEND\"] = \"jax\" # Or \"tensorflow\" or \"torch\".\n", - "import os\n", - "import textwrap\n", - "\n", - "import keras_nlp\n", - "import keras\n", - "\n", - "from IPython.display import Markdown" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "id": "UhbtacN1yqe4" - }, - "outputs": [], - "source": [ - "# Run at half precision.\n", - "keras.config.set_floatx(\"bfloat16\")\n", - "\n", - "def to_markdown(text):\n", - " text = text.replace('•', ' *')\n", - " return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "id": "yygIK9DEIldp" + "id": "yygIK9DEIldp", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 544 + }, + "outputId": "3cd1d22f-7c55-4e62-e44d-895a82f22553" }, "outputs": [ { - "name": "stderr", "output_type": "stream", + "name": "stderr", "text": [ - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/metadata.json...\n", - "100%|██████████| 143/143 [00:00<00:00, 173kB/s]\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors.index.json...\n", "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/task.json...\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/config.json...\n", - "100%|██████████| 780/780 [00:00<00:00, 1.16MB/s]\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.weights.h5...\n", - "100%|██████████| 17.2G/17.2G [18:19<00:00, 16.8MB/s]\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/preprocessor.json...\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/tokenizer.json...\n", - "100%|██████████| 315/315 [00:00<00:00, 781kB/s]\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/assets/tokenizer/vocabulary.spm...\n", - "100%|██████████| 4.04M/4.04M [00:01<00:00, 2.40MB/s]\n" + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors.index.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors.index.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/preprocessor.json...\n" ] }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1mPreprocessor: \"gemma_causal_lm_preprocessor\"\u001b[0m\n" + ], "text/html": [ "
Preprocessor: \"gemma_causal_lm_preprocessor\"\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1mPreprocessor: \"gemma_causal_lm_preprocessor\"\u001b[0m\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\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", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) │ \u001b[38;5;34m256,000\u001b[0m │\n", + "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n" + ], "text/html": [ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
               "┃ Tokenizer (type)                                                                                Vocab # ┃\n",
@@ -191,33 +165,41 @@
               "│ gemma_tokenizer (GemmaTokenizer)                   │                                             256,000 │\n",
               "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n",
               "
\n" - ], - "text/plain": [ - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", - "┃\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", - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", - "│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) │ \u001b[38;5;34m256,000\u001b[0m │\n", - "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1mModel: \"gemma_causal_lm\"\u001b[0m\n" + ], "text/html": [ "
Model: \"gemma_causal_lm\"\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1mModel: \"gemma_causal_lm\"\u001b[0m\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ padding_mask (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ token_ids (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ gemma_backbone │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3584\u001b[0m) │ \u001b[38;5;34m9,241,705,984\u001b[0m │ padding_mask[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", + "│ (\u001b[38;5;33mGemmaBackbone\u001b[0m) │ │ │ token_ids[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ token_embedding │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256000\u001b[0m) │ \u001b[38;5;34m917,504,000\u001b[0m │ gemma_backbone[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mReversibleEmbedding\u001b[0m) │ │ │ │\n", + "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n" + ], "text/html": [ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
               "┃ Layer (type)                   Output Shape                       Param #  Connected to               ┃\n",
@@ -233,1007 +215,430 @@
               "│ (ReversibleEmbedding)         │                           │                 │                            │\n",
               "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n",
               "
\n" - ], - "text/plain": [ - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", - "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", - "│ padding_mask (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ token_ids (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ gemma_backbone │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3584\u001b[0m) │ \u001b[38;5;34m9,241,705,984\u001b[0m │ padding_mask[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", - "│ (\u001b[38;5;33mGemmaBackbone\u001b[0m) │ │ │ token_ids[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ token_embedding │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256000\u001b[0m) │ \u001b[38;5;34m917,504,000\u001b[0m │ gemma_backbone[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", - "│ (\u001b[38;5;33mReversibleEmbedding\u001b[0m) │ │ │ │\n", - "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" + ], "text/html": [ "
 Total params: 9,241,705,984 (17.21 GB)\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" + ], "text/html": [ "
 Trainable params: 9,241,705,984 (17.21 GB)\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n" + ], "text/html": [ "
 Non-trainable params: 0 (0.00 B)\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} } ], "source": [ - "# Connect using the default `gemma2_instruct_9b_keras` or through huggingface weights `hf://google/gemma-2-9b-keras`\n", + "import keras_nlp\n", + "import keras\n", + "\n", + "# Run at half precision.\n", + "keras.config.set_floatx(\"bfloat16\")\n", + "\n", + "# using 9B instruction-tuned model\n", "gemma_lm = keras_nlp.models.GemmaCausalLM.from_preset(\"gemma2_instruct_9b_en\")\n", "gemma_lm.summary()" ] }, + { + "cell_type": "markdown", + "source": [ + "### Define formatting helper functions" + ], + "metadata": { + "id": "CQ837Wrra_d3" + } + }, { "cell_type": "code", - "execution_count": 6, + "source": [ + "from IPython.display import Markdown\n", + "import textwrap\n", + "\n", + "def display_chat(prompt, text):\n", + " formatted_prompt = \"🙋‍♂️
\" + prompt + \"
\"\n", + " text = text.replace('•', ' *')\n", + " text = textwrap.indent(text, '> ', predicate=lambda _: True)\n", + " formatted_text = \"🤖\\n\\n\" + text + \"\\n\"\n", + " return Markdown(formatted_prompt+formatted_text)\n", + "\n", + "def to_markdown(text):\n", + " text = text.replace('•', ' *')\n", + " return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))" + ], "metadata": { - "id": "aae5GHrdpj2_" + "id": "z6nQPPU7bFk6" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "CPU times: user 56.7 s, sys: 627 ms, total: 57.3 s\n", - "Wall time: 37.3 s\n" - ] - }, - { - "data": { - "text/markdown": [ - "> what is the meaning of life?.\n", - "> \n", - "> That's a question that has been pondered by philosophers and theologians for centuries, and there's no one answer that will satisfy everyone. \n", - "> \n", - "> Here are some perspectives to consider:\n", - "> \n", - "> * **Meaning is created, not found:** Many believe that life has no inherent meaning, and it's up to each individual to create their own purpose and find what gives their life value. This could involve pursuing passions, building relationships, contributing to society, or simply enjoying the experience of being alive.\n", - "> * **Meaning is found in connection:** Others find meaning in their connections with others, whether it's through family, friends, community, or a sense of belonging to something larger than themselves.\n", - "> \n", - "> * **Meaning is found in service:** Some find meaning in helping others and making a difference in the world. This could involve volunteering, activism, or simply being kind and compassionate to those around them.\n", - "> * **Meaning is found in the journey:** Some believe that the meaning of life is not about reaching a specific destination, but about the journey itself. This involves embracing the challenges and joys of life, learning and growing along the way, and appreciating the present moment.\n", - "> \n", - "> Ultimately, the meaning of life is a deeply personal question." - ], - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": 3, + "outputs": [] + }, + { + "cell_type": "markdown", "source": [ - "%time result = gemma_lm.generate(\"what is the meaning of life?.\", max_length=256)\n", - "to_markdown(result)" - ] + "### Create a chat helper to manage the conversation state" + ], + "metadata": { + "id": "vro4q-yCbG-f" + } }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": { "id": "O0TkvhOASI9f" }, "outputs": [], "source": [ - "class GemmaChat():\n", + "class ChatState():\n", + " \"\"\"\n", + " Manages the conversation history for a turn-based chatbot\n", + " Follows the turn-based conversation guidelines for the Gemma family of models\n", + " documented at https://ai.google.dev/gemma/docs/formatting\n", + " \"\"\"\n", "\n", - " __START_TURN__ = \"\"\n", - " __END_TURN__ = \"\"\n", - " __SYSTEM_STOP__ = \"\"\n", + " __START_TURN_USER__ = \"user\\n\"\n", + " __START_TURN_MODEL__ = \"model\\n\"\n", + " __END_TURN__ = \"\\n\"\n", "\n", - " def __init__(self, model, system=\"\", history=None):\n", + " def __init__(self, model, system=\"\"):\n", + " \"\"\"\n", + " Initializes the chat state.\n", + "\n", + " Args:\n", + " model: The language model to use for generating responses.\n", + " system: (Optional) System instructions or bot description.\n", + " \"\"\"\n", " self.model = model\n", " self.system = system\n", - " if not history:\n", - " self.history = []\n", - " else:\n", - " self.history = history\n", + " self.history = []\n", + "\n", + " def add_to_history_as_user(self, message):\n", + " \"\"\"\n", + " Adds a user message to the history with start/end turn markers.\n", + " \"\"\"\n", + " self.history.append(self.__START_TURN_USER__ + message + self.__END_TURN__)\n", "\n", - " def format_message(self, message, prefix=\"\"):\n", - " return f\"{self.__START_TURN__}{prefix}\\n{message}{self.__END_TURN__}\\n\"\n", + " def add_to_history_as_model(self, message):\n", + " \"\"\"\n", + " Adds a model response to the history with start/end turn markers.\n", + " \"\"\"\n", + " self.history.append(self.__START_TURN_MODEL__ + message + self.__END_TURN__)\n", "\n", - " def add_to_history(self, message, prefix=\"\"):\n", - " formated_message = self.format_message(message, prefix)\n", - " self.history.append(formated_message)\n", + " def get_history(self):\n", + " \"\"\"\n", + " Returns the entire chat history as a single string.\n", + " \"\"\"\n", + " return \"\".join([*self.history])\n", "\n", " def get_full_prompt(self):\n", - " prompt = \"\\n\".join([self.system + \"\\n\", *self.history])\n", + " \"\"\"\n", + " Builds the prompt for the language model, including history and system description.\n", + " \"\"\"\n", + " prompt = self.get_history() + self.__START_TURN_MODEL__\n", + " if len(self.system)>0:\n", + " prompt = self.system + \"\\n\" + prompt\n", " return prompt\n", "\n", " def send_message(self, message):\n", - " self.add_to_history(message, \"user\")\n", - " prompt = self.get_full_prompt()\n", - " response = self.model.generate(prompt, max_length=2048)\n", - " # print('--------------------response---------------------------')\n", - " # print(response)\n", - " # print('--------------------response---------------------------')\n", - " result = response.replace(prompt, \"\")\n", - " result = response.replace(self.__SYSTEM_STOP__, \"\")\n", - " self.add_to_history(result, \"model\")\n", - " return result\n", + " \"\"\"\n", + " Handles sending a user message and getting a model response.\n", "\n", - " def show_history(self):\n", - " for h in self.history:\n", - " print(h)\n" + " Args:\n", + " message: The user's message.\n", + "\n", + " Returns:\n", + " The model's response.\n", + " \"\"\"\n", + " self.add_to_history_as_user(message)\n", + " prompt = self.get_full_prompt()\n", + " response = self.model.generate(prompt, max_length=4096)\n", + " result = response.replace(prompt, \"\") # Extract only the new response\n", + " self.add_to_history_as_model(result)\n", + " return result\n" ] }, + { + "cell_type": "markdown", + "source": [ + "### Chat with the model" + ], + "metadata": { + "id": "52Ell80sbRmy" + } + }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": { - "id": "shfCZDFPKghT" + "id": "shfCZDFPKghT", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "4841bbbb-f11d-45e1-9dd6-4c2bfd91688a" }, "outputs": [ { + "output_type": "execute_result", "data": { - "text/markdown": [ - "> \n", - "> \n", - "> user\n", - "> help me understand how to make coffee\n", - "> \n", - "> \n", - "> ## Let's Brew Some Coffee! ☕️\n", - "> \n", - "> Making coffee is a simple process, but there are many ways to do it. Here's a breakdown of some popular methods:\n", - "> \n", - "> **1. Drip Coffee Maker:**\n", - "> \n", - "> * **What you need:** Drip coffee maker, coffee filter, ground coffee, water.\n", - "> * **How to do it:**\n", - "> 1. Fill the water reservoir with fresh, cold water.\n", - "> 2. Place a filter in the filter basket.\n", - "> 3. Add ground coffee to the filter (follow the coffee maker's instructions for the right amount).\n", - "> 4. Turn on the coffee maker and let it brew.\n", - "> 5. Enjoy your freshly brewed coffee!\n", - "> \n", - "> **2. French Press:**\n", - "> \n", - "> * **What you need:** French press, coarse ground coffee, hot water.\n", - "> * **How to do it:**\n", - "> 1. Heat water to just off the boil (around 200°F).\n", - "> 2. Add coarse ground coffee to the French press.\n", - "> 3. Pour hot water over the coffee grounds, making sure all grounds are saturated.\n", - "> 4. Stir gently and place the lid on the press, but don't plunge yet.\n", - "> 5. Let the coffee steep for 4 minutes.\n", - "> 6. Slowly press the plunger down to separate the grounds from the brewed coffee.\n", - "> 7. Pour and enjoy!\n", - "> \n", - "> **3. Pour Over:**\n", - "> \n", - "> * **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water.\n", - "> * **How to do it:**\n", - "> 1. Place a filter in the cone and rinse it with hot water to remove any paper taste.\n", - "> 2. Add medium-fine ground coffee to the filter.\n", - "> 3. Slowly pour hot water over the coffee grounds in a circular motion, making sure all grounds are saturated.\n", - "> 4. Let the coffee drip through into your cup.\n", - "> 5. Enjoy!\n", - "> \n", - "> **4. Cold Brew:**\n", - "> \n", - "> * **What you need:** Coarse ground coffee, cold water, container.\n", - "> * **How to do it:**\n", - "> 1. Combine coarse ground coffee and cold water in a container (ratio of 1:8 coffee to water).\n", - "> 2. Stir well and cover the container.\n", - "> 3. Let the coffee steep in the refrigerator for 12-24 hours.\n", - "> 4. Strain the coffee through a fine-mesh sieve or cheesecloth.\n", - "> 5. Serve over ice and enjoy!\n", - "> \n", - "> **Tips for Better Coffee:**\n", - "> \n", - "> * **Use fresh, high-quality beans:** The better the beans, the better the coffee.\n", - "> * **Grind your beans right before brewing:** This preserves the flavor and aroma.\n", - "> * **Use filtered water:** Impurities in water can affect the taste of your coffee.\n", - "> * **Experiment with different brewing methods:** Find the method that you enjoy the most.\n", - "> * **Clean your coffee maker regularly:** This will help to prevent buildup and ensure that your coffee tastes its best.\n", - "> \n", - "> \n", - "> \n", - "> Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n" - ], "text/plain": [ "" - ] + ], + "text/markdown": "🙋‍♂️
help me understand how to make coffee
🤖\n\n> ## Let's Brew Some Coffee! ☕️\n> \n> Making coffee can be as simple or complex as you like. Here's a breakdown of some popular methods, from beginner-friendly to more advanced:\n> \n> **1. The Quick & Easy: Instant Coffee**\n> \n> * **What you need:** Instant coffee granules, hot water\n> * **How to:** Simply add a spoonful of instant coffee to a mug, pour hot water over it, stir, and enjoy!\n> \n> **2. The Classic: Drip Coffee Maker**\n> \n> * **What you need:** Drip coffee maker, ground coffee, filter\n> * **How to:**\n> * Fill the water reservoir with fresh, cold water.\n> * Place a filter in the filter basket.\n> * Add the desired amount of ground coffee to the filter.\n> * Turn on the coffee maker and let it do its thing!\n> \n> **3. The French Press:**\n> \n> * **What you need:** French press, coarse ground coffee, hot water\n> * **How to:**\n> * Add coarse ground coffee to the French press.\n> * Pour hot water (just off the boil) over the coffee grounds.\n> * Stir gently and let it steep for 4 minutes.\n> * Slowly press the plunger down to separate the grounds from the coffee.\n> * Pour and enjoy!\n> \n> **4. The Pour Over:**\n> \n> * **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water\n> * **How to:**\n> * Place a filter in the cone and rinse it with hot water to remove any paper taste.\n> * Add medium-fine ground coffee to the filter.\n> * Slowly pour hot water over the grounds in a circular motion, ensuring all grounds are saturated.\n> * Let the coffee drip through into your cup.\n> \n> **5. The Espresso Machine:**\n> \n> * **What you need:** Espresso machine, finely ground coffee, tamper\n> * **How to:**\n> * Grind your coffee beans finely.\n> * Tamp the coffee grounds firmly into the portafilter.\n> * Lock the portafilter into the espresso machine.\n> * Brew your espresso shot!\n> \n> **Tips for Delicious Coffee:**\n> \n> * **Use fresh, quality beans:** The better the beans, the better the coffee.\n> * **Grind your beans right before brewing:** This preserves freshness and flavor.\n> * **Use filtered water:** Impurities in water can affect the taste of your coffee.\n> * **Experiment with different brewing methods:** Find what you like best!\n> * **Don't be afraid to adjust:** Play with the amount of coffee, water, and brewing time to find your perfect cup.\n> \n> \n> Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n\n" }, - "execution_count": 8, "metadata": {}, - "output_type": "execute_result" + "execution_count": 5 } ], "source": [ - "chat = GemmaChat(gemma_lm)\n", - "result = chat.send_message(\"help me understand how to make coffee\")\n", - "to_markdown(result)" + "chat = ChatState(gemma_lm)\n", + "message = \"help me understand how to make coffee\"\n", + "display_chat(message, chat.send_message(message))" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "metadata": { - "id": "bLxtlhjtLkWQ" + "id": "bLxtlhjtLkWQ", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 761 + }, + "outputId": "4c8d72f6-2067-40f0-c380-f2c8882c6620" }, "outputs": [ { + "output_type": "execute_result", "data": { - "text/markdown": [ - "> \n", - "> \n", - "> user\n", - "> help me understand how to make coffee\n", - "> \n", - "> model\n", - "> \n", - "> \n", - "> user\n", - "> help me understand how to make coffee\n", - "> \n", - "> \n", - "> ## Let's Brew Some Coffee! ☕️\n", - "> \n", - "> Making coffee is a simple process, but there are many ways to do it. Here's a breakdown of some popular methods:\n", - "> \n", - "> **1. Drip Coffee Maker:**\n", - "> \n", - "> * **What you need:** Drip coffee maker, coffee filter, ground coffee, water.\n", - "> * **How to do it:**\n", - "> 1. Fill the water reservoir with fresh, cold water.\n", - "> 2. Place a filter in the filter basket.\n", - "> 3. Add ground coffee to the filter (follow the coffee maker's instructions for the right amount).\n", - "> 4. Turn on the coffee maker and let it brew.\n", - "> 5. Enjoy your freshly brewed coffee!\n", - "> \n", - "> **2. French Press:**\n", - "> \n", - "> * **What you need:** French press, coarse ground coffee, hot water.\n", - "> * **How to do it:**\n", - "> 1. Heat water to just off the boil (around 200°F).\n", - "> 2. Add coarse ground coffee to the French press.\n", - "> 3. Pour hot water over the coffee grounds, making sure all grounds are saturated.\n", - "> 4. Stir gently and place the lid on the press, but don't plunge yet.\n", - "> 5. Let the coffee steep for 4 minutes.\n", - "> 6. Slowly press the plunger down to separate the grounds from the brewed coffee.\n", - "> 7. Pour and enjoy!\n", - "> \n", - "> **3. Pour Over:**\n", - "> \n", - "> * **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water.\n", - "> * **How to do it:**\n", - "> 1. Place a filter in the cone and rinse it with hot water to remove any paper taste.\n", - "> 2. Add medium-fine ground coffee to the filter.\n", - "> 3. Slowly pour hot water over the coffee grounds in a circular motion, making sure all grounds are saturated.\n", - "> 4. Let the coffee drip through into your cup.\n", - "> 5. Enjoy!\n", - "> \n", - "> **4. Cold Brew:**\n", - "> \n", - "> * **What you need:** Coarse ground coffee, cold water, container.\n", - "> * **How to do it:**\n", - "> 1. Combine coarse ground coffee and cold water in a container (ratio of 1:8 coffee to water).\n", - "> 2. Stir well and cover the container.\n", - "> 3. Let the coffee steep in the refrigerator for 12-24 hours.\n", - "> 4. Strain the coffee through a fine-mesh sieve or cheesecloth.\n", - "> 5. Serve over ice and enjoy!\n", - "> \n", - "> **Tips for Better Coffee:**\n", - "> \n", - "> * **Use fresh, high-quality beans:** The better the beans, the better the coffee.\n", - "> * **Grind your beans right before brewing:** This preserves the flavor and aroma.\n", - "> * **Use filtered water:** Impurities in water can affect the taste of your coffee.\n", - "> * **Experiment with different brewing methods:** Find the method that you enjoy the most.\n", - "> * **Clean your coffee maker regularly:** This will help to prevent buildup and ensure that your coffee tastes its best.\n", - "> \n", - "> \n", - "> \n", - "> Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n", - "> \n", - "> \n", - "> user\n", - "> what is the best coffee?\n", - "> \n", - "> \n", - "> Ah, the eternal question! There's no single \"best\" coffee because taste is subjective. What one person finds delicious, another might find bitter or bland. \n", - "> \n", - "> However, I can give you some pointers to help you find YOUR best coffee:\n", - "> \n", - "> **Factors that influence coffee taste:**\n", - "> \n", - "> * **Bean Origin:** Different regions produce beans with unique flavor profiles. \n", - "> * **Latin America:** Often known for chocolatey, nutty, and smooth flavors. (Colombia, Brazil, Guatemala)\n", - "> * **Africa:** Can have bright acidity, fruity notes, and floral aromas. (Ethiopia, Kenya, Tanzania)\n", - "> * **Asia/Pacific:** Often earthy, spicy, and full-bodied. (Indonesia, Vietnam)\n", - "> * **Roast Level:**\n", - "> * **Light:** More acidic, delicate flavors, higher caffeine.\n", - "> * **Medium:** Balanced acidity and body, versatile.\n", - "> * **Dark:** Bold, smoky, bittersweet flavors, lower caffeine.\n", - "> * **Brewing Method:** Each method extracts flavors differently, impacting the final taste.\n", - "> \n", - "> **Finding YOUR Best:**\n", - "> \n", - "> 1. **Explore Different Origins:** Try coffees from various regions to discover what flavor profiles you enjoy.\n", - "> 2. **Experiment with Roast Levels:** Sample light, medium, and dark roasts to see your preference.\n", - "> 3. **Consider Your Brewing Method:** Different beans work better with certain brewing methods. Ask your local coffee shop for recommendations.\n", - "> 4. **Read Reviews:** Online reviews and coffee blogs can offer insights into specific beans and roasters.\n", - "> 5. **Visit a Local Coffee Shop:** Talk to baristas, ask for recommendations, and try different coffees.\n", - "> \n", - "> **Remember:** Coffee is a journey of discovery! Enjoy the process of exploring and finding your perfect cup.\n" - ], "text/plain": [ "" - ] + ], + "text/markdown": "🙋‍♂️
what is the best coffee?
🤖\n\n> Ah, the eternal question! There's no single \"best\" coffee because taste is subjective. What one person finds delicious, another might find bitter or bland. \n> \n> It all depends on your personal preferences:\n> \n> **Consider these factors:**\n> \n> * **Roast Level:**\n> * **Light:** Bright acidity, delicate flavors, often fruity or floral.\n> * **Medium:** Balanced acidity and body, with more pronounced flavors.\n> * **Dark:** Bold, smoky, sometimes bittersweet, with less acidity.\n> * **Origin:** Different regions produce beans with unique flavor profiles:\n> * **Latin America:** Often chocolatey, nutty, with medium acidity.\n> * **Africa:** Known for bright acidity, fruity notes, and floral aromas.\n> * **Asia/Pacific:** Earthy, spicy, sometimes with chocolate or caramel notes.\n> * **Brewing Method:** The method you use can significantly impact the flavor.\n> \n> **Some Popular and Highly-Regarded Coffees:**\n> \n> * **Ethiopian Yirgacheffe:** Known for its floral, citrusy, and tea-like qualities.\n> * **Kenyan AA:** Bright acidity, black currant, and berry flavors.\n> * **Sumatran Mandheling:** Earthy, spicy, with low acidity and a full body.\n> * **Colombian Supremo:** Balanced, smooth, with notes of caramel and chocolate.\n> \n> **My Recommendation:**\n> \n> * **Start exploring!** Visit a local coffee shop or roaster and ask for recommendations based on your preferences.\n> * **Try different roasts and origins.**\n> * **Keep a coffee journal:** Note what you like and dislike about each coffee you try.\n> \n> Ultimately, the best coffee is the one that you enjoy the most! Happy brewing! ☕️\n\n" }, - "execution_count": 9, "metadata": {}, - "output_type": "execute_result" + "execution_count": 6 } ], "source": [ - "result = chat.send_message(\"what is the best coffee?\")\n", - "to_markdown(result)" + "message = \"what is the best coffee?\"\n", + "display_chat(message, chat.send_message(message))" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "metadata": { - "id": "tfvgl4sC9g2p" + "id": "tfvgl4sC9g2p", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 743 + }, + "outputId": "2dc92415-d6cd-4fde-cd10-ed615732f3b3" }, "outputs": [ { + "output_type": "execute_result", "data": { - "text/markdown": [ - "> \n", - "> \n", - "> user\n", - "> help me understand how to make coffee\n", - "> \n", - "> model\n", - "> \n", - "> \n", - "> user\n", - "> help me understand how to make coffee\n", - "> \n", - "> \n", - "> ## Let's Brew Some Coffee! ☕️\n", - "> \n", - "> Making coffee is a simple process, but there are many ways to do it. Here's a breakdown of some popular methods:\n", - "> \n", - "> **1. Drip Coffee Maker:**\n", - "> \n", - "> * **What you need:** Drip coffee maker, coffee filter, ground coffee, water.\n", - "> * **How to do it:**\n", - "> 1. Fill the water reservoir with fresh, cold water.\n", - "> 2. Place a filter in the filter basket.\n", - "> 3. Add ground coffee to the filter (follow the coffee maker's instructions for the right amount).\n", - "> 4. Turn on the coffee maker and let it brew.\n", - "> 5. Enjoy your freshly brewed coffee!\n", - "> \n", - "> **2. French Press:**\n", - "> \n", - "> * **What you need:** French press, coarse ground coffee, hot water.\n", - "> * **How to do it:**\n", - "> 1. Heat water to just off the boil (around 200°F).\n", - "> 2. Add coarse ground coffee to the French press.\n", - "> 3. Pour hot water over the coffee grounds, making sure all grounds are saturated.\n", - "> 4. Stir gently and place the lid on the press, but don't plunge yet.\n", - "> 5. Let the coffee steep for 4 minutes.\n", - "> 6. Slowly press the plunger down to separate the grounds from the brewed coffee.\n", - "> 7. Pour and enjoy!\n", - "> \n", - "> **3. Pour Over:**\n", - "> \n", - "> * **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water.\n", - "> * **How to do it:**\n", - "> 1. Place a filter in the cone and rinse it with hot water to remove any paper taste.\n", - "> 2. Add medium-fine ground coffee to the filter.\n", - "> 3. Slowly pour hot water over the coffee grounds in a circular motion, making sure all grounds are saturated.\n", - "> 4. Let the coffee drip through into your cup.\n", - "> 5. Enjoy!\n", - "> \n", - "> **4. Cold Brew:**\n", - "> \n", - "> * **What you need:** Coarse ground coffee, cold water, container.\n", - "> * **How to do it:**\n", - "> 1. Combine coarse ground coffee and cold water in a container (ratio of 1:8 coffee to water).\n", - "> 2. Stir well and cover the container.\n", - "> 3. Let the coffee steep in the refrigerator for 12-24 hours.\n", - "> 4. Strain the coffee through a fine-mesh sieve or cheesecloth.\n", - "> 5. Serve over ice and enjoy!\n", - "> \n", - "> **Tips for Better Coffee:**\n", - "> \n", - "> * **Use fresh, high-quality beans:** The better the beans, the better the coffee.\n", - "> * **Grind your beans right before brewing:** This preserves the flavor and aroma.\n", - "> * **Use filtered water:** Impurities in water can affect the taste of your coffee.\n", - "> * **Experiment with different brewing methods:** Find the method that you enjoy the most.\n", - "> * **Clean your coffee maker regularly:** This will help to prevent buildup and ensure that your coffee tastes its best.\n", - "> \n", - "> \n", - "> \n", - "> Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n", - "> \n", - "> \n", - "> user\n", - "> what is the best coffee?\n", - "> \n", - "> model\n", - "> \n", - "> \n", - "> user\n", - "> help me understand how to make coffee\n", - "> \n", - "> model\n", - "> \n", - "> \n", - "> user\n", - "> help me understand how to make coffee\n", - "> \n", - "> \n", - "> ## Let's Brew Some Coffee! ☕️\n", - "> \n", - "> Making coffee is a simple process, but there are many ways to do it. Here's a breakdown of some popular methods:\n", - "> \n", - "> **1. Drip Coffee Maker:**\n", - "> \n", - "> * **What you need:** Drip coffee maker, coffee filter, ground coffee, water.\n", - "> * **How to do it:**\n", - "> 1. Fill the water reservoir with fresh, cold water.\n", - "> 2. Place a filter in the filter basket.\n", - "> 3. Add ground coffee to the filter (follow the coffee maker's instructions for the right amount).\n", - "> 4. Turn on the coffee maker and let it brew.\n", - "> 5. Enjoy your freshly brewed coffee!\n", - "> \n", - "> **2. French Press:**\n", - "> \n", - "> * **What you need:** French press, coarse ground coffee, hot water.\n", - "> * **How to do it:**\n", - "> 1. Heat water to just off the boil (around 200°F).\n", - "> 2. Add coarse ground coffee to the French press.\n", - "> 3. Pour hot water over the coffee grounds, making sure all grounds are saturated.\n", - "> 4. Stir gently and place the lid on the press, but don't plunge yet.\n", - "> 5. Let the coffee steep for 4 minutes.\n", - "> 6. Slowly press the plunger down to separate the grounds from the brewed coffee.\n", - "> 7. Pour and enjoy!\n", - "> \n", - "> **3. Pour Over:**\n", - "> \n", - "> * **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water.\n", - "> * **How to do it:**\n", - "> 1. Place a filter in the cone and rinse it with hot water to remove any paper taste.\n", - "> 2. Add medium-fine ground coffee to the filter.\n", - "> 3. Slowly pour hot water over the coffee grounds in a circular motion, making sure all grounds are saturated.\n", - "> 4. Let the coffee drip through into your cup.\n", - "> 5. Enjoy!\n", - "> \n", - "> **4. Cold Brew:**\n", - "> \n", - "> * **What you need:** Coarse ground coffee, cold water, container.\n", - "> * **How to do it:**\n", - "> 1. Combine coarse ground coffee and cold water in a container (ratio of 1:8 coffee to water).\n", - "> 2. Stir well and cover the container.\n", - "> 3. Let the coffee steep in the refrigerator for 12-24 hours.\n", - "> 4. Strain the coffee through a fine-mesh sieve or cheesecloth.\n", - "> 5. Serve over ice and enjoy!\n", - "> \n", - "> **Tips for Better Coffee:**\n", - "> \n", - "> * **Use fresh, high-quality beans:** The better the beans, the better the coffee.\n", - "> * **Grind your beans right before brewing:** This preserves the flavor and aroma.\n", - "> * **Use filtered water:** Impurities in water can affect the taste of your coffee.\n", - "> * **Experiment with different brewing methods:** Find the method that you enjoy the most.\n", - "> * **Clean your coffee maker regularly:** This will help to prevent buildup and ensure that your coffee tastes its best.\n", - "> \n", - "> \n", - "> \n", - "> Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n", - "> \n", - "> \n", - "> user\n", - "> what is the best coffee?\n", - "> \n", - "> \n", - "> Ah, the eternal question! There's no single \"best\" coffee because taste is subjective. What one person finds delicious, another might find bitter or bland. \n", - "> \n", - "> However, I can give you some pointers to help you find YOUR best coffee:\n", - "> \n", - "> **Factors that influence coffee taste:**\n", - "> \n", - "> * **Bean Origin:** Different regions produce beans with unique flavor profiles. \n", - "> * **Latin America:** Often known for chocolatey, nutty, and smooth flavors. (Colombia, Brazil, Guatemala)\n", - "> * **Africa:** Can have bright acidity, fruity notes, and floral aromas. (Ethiopia, Kenya, Tanzania)\n", - "> * **Asia/Pacific:** Often earthy, spicy, and full-bodied. (Indonesia, Vietnam)\n", - "> * **Roast Level:**\n", - "> * **Light:** More acidic, delicate flavors, higher caffeine.\n", - "> * **Medium:** Balanced acidity and body, versatile.\n", - "> * **Dark:** Bold, smoky, bittersweet flavors, lower caffeine.\n", - "> * **Brewing Method:** Each method extracts flavors differently, impacting the final taste.\n", - "> \n", - "> **Finding YOUR Best:**\n", - "> \n", - "> 1. **Explore Different Origins:** Try coffees from various regions to discover what flavor profiles you enjoy.\n", - "> 2. **Experiment with Roast Levels:** Sample light, medium, and dark roasts to see your preference.\n", - "> 3. **Consider Your Brewing Method:** Different beans work better with certain brewing methods. Ask your local coffee shop for recommendations.\n", - "> 4. **Read Reviews:** Online reviews and coffee blogs can offer insights into specific beans and roasters.\n", - "> 5. **Visit a Local Coffee Shop:** Talk to baristas, ask for recommendations, and try different coffees.\n", - "> \n", - "> **Remember:** Coffee is a journey of discovery! Enjoy the process of exploring and finding your perfect cup.\n", - "> \n", - "> \n", - "> user\n", - "> what are similar drinks?\n", - "> \n", - "> \n", - "> Here are some drinks similar to coffee, categorized by what aspect of coffee they resemble:\n", - "> \n", - "> **Similar Caffeine Kick:**\n", - "> \n", - "> * **Tea:** Wide variety of flavors and caffeine levels, from delicate green tea to robust black tea.\n", - "> * **Matcha:** Powdered green tea with a unique earthy flavor and higher caffeine content than regular green tea.\n", - "> * **Yerba Mate:** South American herbal tea with a slightly bitter, grassy flavor and moderate caffeine.\n", - "> * **Energy Drinks:** High caffeine content, often with added sugar and other stimulants.\n", - "> \n", - "> **Similar Flavor Profiles:**\n", - "> \n", - "> * **Chocolate:** Rich, bittersweet flavors can complement coffee's roasted notes.\n", - "> * **Caramel:** Sweet and buttery, caramel adds a creamy dimension similar to coffee's body.\n", - "> * **Vanilla:** A classic pairing with coffee, vanilla adds a warm, comforting sweetness.\n", - "> * **Espresso-Based Drinks:** Lattes, cappuccinos, macchiatos, and mochas all feature espresso as a base, offering variations in milk and flavorings.\n", - "> \n", - "> **Similar Ritual and Experience:**\n", - "> \n", - "> * **Hot Chocolate:** A comforting and warming drink often enjoyed in the morning or evening.\n", - "> * **Herbal Teas:** A relaxing and flavorful alternative to coffee, enjoyed for their health benefits and calming effects.\n", - "> * **Golden Milk:** A turmeric-based drink with" - ], "text/plain": [ "" - ] + ], + "text/markdown": "🙋‍♂️
what are similar drinks?
🤖\n\n> You're looking for drinks similar to coffee? Great question! Here are some options, categorized by what aspect of coffee you might be drawn to:\n> \n> **If you like the caffeine kick:**\n> \n> * **Tea:** Black tea offers a similar caffeine level to coffee, with a wider range of flavors from robust to floral. Green tea has less caffeine but is packed with antioxidants.\n> * **Matcha:** A powdered green tea with a unique earthy flavor and a sustained energy boost.\n> * **Yerba Mate:** A South American beverage with a slightly bitter, grassy flavor and a moderate caffeine content.\n> \n> **If you like the rich, roasted flavor:**\n> \n> * **Chicory Coffee:** Made from roasted chicory root, it has a coffee-like flavor but is caffeine-free.\n> * **Roasted Barley Tea:** A caffeine-free option with a nutty, toasty flavor.\n> * **Carob:** Made from roasted carob pods, it has a naturally sweet, chocolatey flavor.\n> \n> **If you like the ritual and warmth:**\n> \n> * **Hot Chocolate:** A comforting and indulgent treat, especially with marshmallows!\n> * **Golden Milk:** A turmeric-based drink with warming spices and a creamy texture.\n> * **Herbal Teas:** A wide variety of flavors and aromas to choose from, perfect for relaxation.\n> \n> **If you like the customization options:**\n> \n> * **Espresso-based drinks:** Lattes, cappuccinos, macchiatos, and more offer endless possibilities for flavor combinations.\n> * **Smoothies:** Blend fruits, vegetables, and other ingredients for a refreshing and nutritious drink.\n> \n> Remember, there are countless variations and combinations within these categories. Don't be afraid to experiment and find your new favorite drink!\n\n" }, - "execution_count": 10, "metadata": {}, - "output_type": "execute_result" + "execution_count": 7 } ], "source": [ - "result = chat.send_message(\"what are similar drinks?\")\n", - "to_markdown(result)" + "message = \"what are similar drinks?\"\n", + "display_chat(message, chat.send_message(message))" ] }, + { + "cell_type": "markdown", + "source": [ + "Use the `get_history` method to see how all the context was retained by the Chat class." + ], + "metadata": { + "id": "Y85tod32c7lA" + } + }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": { - "id": "P2GjAVybBez3" + "id": "P2GjAVybBez3", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "c72ea9a9-911b-47ed-a47c-a621b2cf9b7d" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ "user\n", "help me understand how to make coffee\n", - "\n", "model\n", - "\n", - "\n", - "user\n", - "help me understand how to make coffee\n", - "\n", - "\n", "## Let's Brew Some Coffee! ☕️\n", "\n", - "Making coffee is a simple process, but there are many ways to do it. Here's a breakdown of some popular methods:\n", + "Making coffee can be as simple or complex as you like. Here's a breakdown of some popular methods, from beginner-friendly to more advanced:\n", "\n", - "**1. Drip Coffee Maker:**\n", + "**1. The Quick & Easy: Instant Coffee**\n", "\n", - "* **What you need:** Drip coffee maker, coffee filter, ground coffee, water.\n", - "* **How to do it:**\n", - " 1. Fill the water reservoir with fresh, cold water.\n", - " 2. Place a filter in the filter basket.\n", - " 3. Add ground coffee to the filter (follow the coffee maker's instructions for the right amount).\n", - " 4. Turn on the coffee maker and let it brew.\n", - " 5. Enjoy your freshly brewed coffee!\n", + "* **What you need:** Instant coffee granules, hot water\n", + "* **How to:** Simply add a spoonful of instant coffee to a mug, pour hot water over it, stir, and enjoy!\n", "\n", - "**2. French Press:**\n", + "**2. The Classic: Drip Coffee Maker**\n", "\n", - "* **What you need:** French press, coarse ground coffee, hot water.\n", - "* **How to do it:**\n", - " 1. Heat water to just off the boil (around 200°F).\n", - " 2. Add coarse ground coffee to the French press.\n", - " 3. Pour hot water over the coffee grounds, making sure all grounds are saturated.\n", - " 4. Stir gently and place the lid on the press, but don't plunge yet.\n", - " 5. Let the coffee steep for 4 minutes.\n", - " 6. Slowly press the plunger down to separate the grounds from the brewed coffee.\n", - " 7. Pour and enjoy!\n", + "* **What you need:** Drip coffee maker, ground coffee, filter\n", + "* **How to:**\n", + " * Fill the water reservoir with fresh, cold water.\n", + " * Place a filter in the filter basket.\n", + " * Add the desired amount of ground coffee to the filter.\n", + " * Turn on the coffee maker and let it do its thing!\n", "\n", - "**3. Pour Over:**\n", + "**3. The French Press:**\n", "\n", - "* **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water.\n", - "* **How to do it:**\n", - " 1. Place a filter in the cone and rinse it with hot water to remove any paper taste.\n", - " 2. Add medium-fine ground coffee to the filter.\n", - " 3. Slowly pour hot water over the coffee grounds in a circular motion, making sure all grounds are saturated.\n", - " 4. Let the coffee drip through into your cup.\n", - " 5. Enjoy!\n", + "* **What you need:** French press, coarse ground coffee, hot water\n", + "* **How to:**\n", + " * Add coarse ground coffee to the French press.\n", + " * Pour hot water (just off the boil) over the coffee grounds.\n", + " * Stir gently and let it steep for 4 minutes.\n", + " * Slowly press the plunger down to separate the grounds from the coffee.\n", + " * Pour and enjoy!\n", "\n", - "**4. Cold Brew:**\n", + "**4. The Pour Over:**\n", "\n", - "* **What you need:** Coarse ground coffee, cold water, container.\n", - "* **How to do it:**\n", - " 1. Combine coarse ground coffee and cold water in a container (ratio of 1:8 coffee to water).\n", - " 2. Stir well and cover the container.\n", - " 3. Let the coffee steep in the refrigerator for 12-24 hours.\n", - " 4. Strain the coffee through a fine-mesh sieve or cheesecloth.\n", - " 5. Serve over ice and enjoy!\n", - "\n", - "**Tips for Better Coffee:**\n", - "\n", - "* **Use fresh, high-quality beans:** The better the beans, the better the coffee.\n", - "* **Grind your beans right before brewing:** This preserves the flavor and aroma.\n", - "* **Use filtered water:** Impurities in water can affect the taste of your coffee.\n", - "* **Experiment with different brewing methods:** Find the method that you enjoy the most.\n", - "* **Clean your coffee maker regularly:** This will help to prevent buildup and ensure that your coffee tastes its best.\n", + "* **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water\n", + "* **How to:**\n", + " * Place a filter in the cone and rinse it with hot water to remove any paper taste.\n", + " * Add medium-fine ground coffee to the filter.\n", + " * Slowly pour hot water over the grounds in a circular motion, ensuring all grounds are saturated.\n", + " * Let the coffee drip through into your cup.\n", "\n", + "**5. The Espresso Machine:**\n", "\n", + "* **What you need:** Espresso machine, finely ground coffee, tamper\n", + "* **How to:**\n", + " * Grind your coffee beans finely.\n", + " * Tamp the coffee grounds firmly into the portafilter.\n", + " * Lock the portafilter into the espresso machine.\n", + " * Brew your espresso shot!\n", "\n", - "Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n", - "\n", - "\n", - "user\n", - "what is the best coffee?\n", + "**Tips for Delicious Coffee:**\n", "\n", - "model\n", - "\n", - "\n", - "user\n", - "help me understand how to make coffee\n", - "\n", - "model\n", - "\n", - "\n", - "user\n", - "help me understand how to make coffee\n", - "\n", - "\n", - "## Let's Brew Some Coffee! ☕️\n", - "\n", - "Making coffee is a simple process, but there are many ways to do it. Here's a breakdown of some popular methods:\n", - "\n", - "**1. Drip Coffee Maker:**\n", - "\n", - "* **What you need:** Drip coffee maker, coffee filter, ground coffee, water.\n", - "* **How to do it:**\n", - " 1. Fill the water reservoir with fresh, cold water.\n", - " 2. Place a filter in the filter basket.\n", - " 3. Add ground coffee to the filter (follow the coffee maker's instructions for the right amount).\n", - " 4. Turn on the coffee maker and let it brew.\n", - " 5. Enjoy your freshly brewed coffee!\n", - "\n", - "**2. French Press:**\n", - "\n", - "* **What you need:** French press, coarse ground coffee, hot water.\n", - "* **How to do it:**\n", - " 1. Heat water to just off the boil (around 200°F).\n", - " 2. Add coarse ground coffee to the French press.\n", - " 3. Pour hot water over the coffee grounds, making sure all grounds are saturated.\n", - " 4. Stir gently and place the lid on the press, but don't plunge yet.\n", - " 5. Let the coffee steep for 4 minutes.\n", - " 6. Slowly press the plunger down to separate the grounds from the brewed coffee.\n", - " 7. Pour and enjoy!\n", - "\n", - "**3. Pour Over:**\n", - "\n", - "* **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water.\n", - "* **How to do it:**\n", - " 1. Place a filter in the cone and rinse it with hot water to remove any paper taste.\n", - " 2. Add medium-fine ground coffee to the filter.\n", - " 3. Slowly pour hot water over the coffee grounds in a circular motion, making sure all grounds are saturated.\n", - " 4. Let the coffee drip through into your cup.\n", - " 5. Enjoy!\n", - "\n", - "**4. Cold Brew:**\n", - "\n", - "* **What you need:** Coarse ground coffee, cold water, container.\n", - "* **How to do it:**\n", - " 1. Combine coarse ground coffee and cold water in a container (ratio of 1:8 coffee to water).\n", - " 2. Stir well and cover the container.\n", - " 3. Let the coffee steep in the refrigerator for 12-24 hours.\n", - " 4. Strain the coffee through a fine-mesh sieve or cheesecloth.\n", - " 5. Serve over ice and enjoy!\n", - "\n", - "**Tips for Better Coffee:**\n", - "\n", - "* **Use fresh, high-quality beans:** The better the beans, the better the coffee.\n", - "* **Grind your beans right before brewing:** This preserves the flavor and aroma.\n", + "* **Use fresh, quality beans:** The better the beans, the better the coffee.\n", + "* **Grind your beans right before brewing:** This preserves freshness and flavor.\n", "* **Use filtered water:** Impurities in water can affect the taste of your coffee.\n", - "* **Experiment with different brewing methods:** Find the method that you enjoy the most.\n", - "* **Clean your coffee maker regularly:** This will help to prevent buildup and ensure that your coffee tastes its best.\n", - "\n", + "* **Experiment with different brewing methods:** Find what you like best!\n", + "* **Don't be afraid to adjust:** Play with the amount of coffee, water, and brewing time to find your perfect cup.\n", "\n", "\n", "Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n", "\n", - "\n", "user\n", "what is the best coffee?\n", - "\n", - "\n", + "model\n", "Ah, the eternal question! There's no single \"best\" coffee because taste is subjective. What one person finds delicious, another might find bitter or bland. \n", "\n", - "However, I can give you some pointers to help you find YOUR best coffee:\n", + "It all depends on your personal preferences:\n", "\n", - "**Factors that influence coffee taste:**\n", + "**Consider these factors:**\n", "\n", - "* **Bean Origin:** Different regions produce beans with unique flavor profiles. \n", - " * **Latin America:** Often known for chocolatey, nutty, and smooth flavors. (Colombia, Brazil, Guatemala)\n", - " * **Africa:** Can have bright acidity, fruity notes, and floral aromas. (Ethiopia, Kenya, Tanzania)\n", - " * **Asia/Pacific:** Often earthy, spicy, and full-bodied. (Indonesia, Vietnam)\n", "* **Roast Level:**\n", - " * **Light:** More acidic, delicate flavors, higher caffeine.\n", - " * **Medium:** Balanced acidity and body, versatile.\n", - " * **Dark:** Bold, smoky, bittersweet flavors, lower caffeine.\n", - "* **Brewing Method:** Each method extracts flavors differently, impacting the final taste.\n", + " * **Light:** Bright acidity, delicate flavors, often fruity or floral.\n", + " * **Medium:** Balanced acidity and body, with more pronounced flavors.\n", + " * **Dark:** Bold, smoky, sometimes bittersweet, with less acidity.\n", + "* **Origin:** Different regions produce beans with unique flavor profiles:\n", + " * **Latin America:** Often chocolatey, nutty, with medium acidity.\n", + " * **Africa:** Known for bright acidity, fruity notes, and floral aromas.\n", + " * **Asia/Pacific:** Earthy, spicy, sometimes with chocolate or caramel notes.\n", + "* **Brewing Method:** The method you use can significantly impact the flavor.\n", "\n", - "**Finding YOUR Best:**\n", + "**Some Popular and Highly-Regarded Coffees:**\n", "\n", - "1. **Explore Different Origins:** Try coffees from various regions to discover what flavor profiles you enjoy.\n", - "2. **Experiment with Roast Levels:** Sample light, medium, and dark roasts to see your preference.\n", - "3. **Consider Your Brewing Method:** Different beans work better with certain brewing methods. Ask your local coffee shop for recommendations.\n", - "4. **Read Reviews:** Online reviews and coffee blogs can offer insights into specific beans and roasters.\n", - "5. **Visit a Local Coffee Shop:** Talk to baristas, ask for recommendations, and try different coffees.\n", + "* **Ethiopian Yirgacheffe:** Known for its floral, citrusy, and tea-like qualities.\n", + "* **Kenyan AA:** Bright acidity, black currant, and berry flavors.\n", + "* **Sumatran Mandheling:** Earthy, spicy, with low acidity and a full body.\n", + "* **Colombian Supremo:** Balanced, smooth, with notes of caramel and chocolate.\n", "\n", - "**Remember:** Coffee is a journey of discovery! Enjoy the process of exploring and finding your perfect cup.\n", - "\n", - "\n", - "user\n", - "what are similar drinks?\n", - "\n", - "model\n", - "\n", - "\n", - "user\n", - "help me understand how to make coffee\n", - "\n", - "model\n", - "\n", - "\n", - "user\n", - "help me understand how to make coffee\n", - "\n", - "\n", - "## Let's Brew Some Coffee! ☕️\n", - "\n", - "Making coffee is a simple process, but there are many ways to do it. Here's a breakdown of some popular methods:\n", - "\n", - "**1. Drip Coffee Maker:**\n", + "**My Recommendation:**\n", "\n", - "* **What you need:** Drip coffee maker, coffee filter, ground coffee, water.\n", - "* **How to do it:**\n", - " 1. Fill the water reservoir with fresh, cold water.\n", - " 2. Place a filter in the filter basket.\n", - " 3. Add ground coffee to the filter (follow the coffee maker's instructions for the right amount).\n", - " 4. Turn on the coffee maker and let it brew.\n", - " 5. Enjoy your freshly brewed coffee!\n", + "* **Start exploring!** Visit a local coffee shop or roaster and ask for recommendations based on your preferences.\n", + "* **Try different roasts and origins.**\n", + "* **Keep a coffee journal:** Note what you like and dislike about each coffee you try.\n", "\n", - "**2. French Press:**\n", - "\n", - "* **What you need:** French press, coarse ground coffee, hot water.\n", - "* **How to do it:**\n", - " 1. Heat water to just off the boil (around 200°F).\n", - " 2. Add coarse ground coffee to the French press.\n", - " 3. Pour hot water over the coffee grounds, making sure all grounds are saturated.\n", - " 4. Stir gently and place the lid on the press, but don't plunge yet.\n", - " 5. Let the coffee steep for 4 minutes.\n", - " 6. Slowly press the plunger down to separate the grounds from the brewed coffee.\n", - " 7. Pour and enjoy!\n", - "\n", - "**3. Pour Over:**\n", - "\n", - "* **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water.\n", - "* **How to do it:**\n", - " 1. Place a filter in the cone and rinse it with hot water to remove any paper taste.\n", - " 2. Add medium-fine ground coffee to the filter.\n", - " 3. Slowly pour hot water over the coffee grounds in a circular motion, making sure all grounds are saturated.\n", - " 4. Let the coffee drip through into your cup.\n", - " 5. Enjoy!\n", - "\n", - "**4. Cold Brew:**\n", - "\n", - "* **What you need:** Coarse ground coffee, cold water, container.\n", - "* **How to do it:**\n", - " 1. Combine coarse ground coffee and cold water in a container (ratio of 1:8 coffee to water).\n", - " 2. Stir well and cover the container.\n", - " 3. Let the coffee steep in the refrigerator for 12-24 hours.\n", - " 4. Strain the coffee through a fine-mesh sieve or cheesecloth.\n", - " 5. Serve over ice and enjoy!\n", - "\n", - "**Tips for Better Coffee:**\n", - "\n", - "* **Use fresh, high-quality beans:** The better the beans, the better the coffee.\n", - "* **Grind your beans right before brewing:** This preserves the flavor and aroma.\n", - "* **Use filtered water:** Impurities in water can affect the taste of your coffee.\n", - "* **Experiment with different brewing methods:** Find the method that you enjoy the most.\n", - "* **Clean your coffee maker regularly:** This will help to prevent buildup and ensure that your coffee tastes its best.\n", - "\n", - "\n", - "\n", - "Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n", + "Ultimately, the best coffee is the one that you enjoy the most! Happy brewing! ☕️\n", "\n", - "\n", - "user\n", - "what is the best coffee?\n", - "\n", - "model\n", - "\n", - "\n", "user\n", - "help me understand how to make coffee\n", - "\n", + "what are similar drinks?\n", "model\n", + "You're looking for drinks similar to coffee? Great question! Here are some options, categorized by what aspect of coffee you might be drawn to:\n", "\n", + "**If you like the caffeine kick:**\n", "\n", - "user\n", - "help me understand how to make coffee\n", - "\n", - "\n", - "## Let's Brew Some Coffee! ☕️\n", - "\n", - "Making coffee is a simple process, but there are many ways to do it. Here's a breakdown of some popular methods:\n", - "\n", - "**1. Drip Coffee Maker:**\n", - "\n", - "* **What you need:** Drip coffee maker, coffee filter, ground coffee, water.\n", - "* **How to do it:**\n", - " 1. Fill the water reservoir with fresh, cold water.\n", - " 2. Place a filter in the filter basket.\n", - " 3. Add ground coffee to the filter (follow the coffee maker's instructions for the right amount).\n", - " 4. Turn on the coffee maker and let it brew.\n", - " 5. Enjoy your freshly brewed coffee!\n", - "\n", - "**2. French Press:**\n", + "* **Tea:** Black tea offers a similar caffeine level to coffee, with a wider range of flavors from robust to floral. Green tea has less caffeine but is packed with antioxidants.\n", + "* **Matcha:** A powdered green tea with a unique earthy flavor and a sustained energy boost.\n", + "* **Yerba Mate:** A South American beverage with a slightly bitter, grassy flavor and a moderate caffeine content.\n", "\n", - "* **What you need:** French press, coarse ground coffee, hot water.\n", - "* **How to do it:**\n", - " 1. Heat water to just off the boil (around 200°F).\n", - " 2. Add coarse ground coffee to the French press.\n", - " 3. Pour hot water over the coffee grounds, making sure all grounds are saturated.\n", - " 4. Stir gently and place the lid on the press, but don't plunge yet.\n", - " 5. Let the coffee steep for 4 minutes.\n", - " 6. Slowly press the plunger down to separate the grounds from the brewed coffee.\n", - " 7. Pour and enjoy!\n", + "**If you like the rich, roasted flavor:**\n", "\n", - "**3. Pour Over:**\n", + "* **Chicory Coffee:** Made from roasted chicory root, it has a coffee-like flavor but is caffeine-free.\n", + "* **Roasted Barley Tea:** A caffeine-free option with a nutty, toasty flavor.\n", + "* **Carob:** Made from roasted carob pods, it has a naturally sweet, chocolatey flavor.\n", "\n", - "* **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water.\n", - "* **How to do it:**\n", - " 1. Place a filter in the cone and rinse it with hot water to remove any paper taste.\n", - " 2. Add medium-fine ground coffee to the filter.\n", - " 3. Slowly pour hot water over the coffee grounds in a circular motion, making sure all grounds are saturated.\n", - " 4. Let the coffee drip through into your cup.\n", - " 5. Enjoy!\n", + "**If you like the ritual and warmth:**\n", "\n", - "**4. Cold Brew:**\n", + "* **Hot Chocolate:** A comforting and indulgent treat, especially with marshmallows!\n", + "* **Golden Milk:** A turmeric-based drink with warming spices and a creamy texture.\n", + "* **Herbal Teas:** A wide variety of flavors and aromas to choose from, perfect for relaxation.\n", "\n", - "* **What you need:** Coarse ground coffee, cold water, container.\n", - "* **How to do it:**\n", - " 1. Combine coarse ground coffee and cold water in a container (ratio of 1:8 coffee to water).\n", - " 2. Stir well and cover the container.\n", - " 3. Let the coffee steep in the refrigerator for 12-24 hours.\n", - " 4. Strain the coffee through a fine-mesh sieve or cheesecloth.\n", - " 5. Serve over ice and enjoy!\n", + "**If you like the customization options:**\n", "\n", - "**Tips for Better Coffee:**\n", + "* **Espresso-based drinks:** Lattes, cappuccinos, macchiatos, and more offer endless possibilities for flavor combinations.\n", + "* **Smoothies:** Blend fruits, vegetables, and other ingredients for a refreshing and nutritious drink.\n", "\n", - "* **Use fresh, high-quality beans:** The better the beans, the better the coffee.\n", - "* **Grind your beans right before brewing:** This preserves the flavor and aroma.\n", - "* **Use filtered water:** Impurities in water can affect the taste of your coffee.\n", - "* **Experiment with different brewing methods:** Find the method that you enjoy the most.\n", - "* **Clean your coffee maker regularly:** This will help to prevent buildup and ensure that your coffee tastes its best.\n", - "\n", - "\n", - "\n", - "Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n", + "Remember, there are countless variations and combinations within these categories. Don't be afraid to experiment and find your new favorite drink!\n", "\n", - "\n", - "user\n", - "what is the best coffee?\n", - "\n", - "\n", - "Ah, the eternal question! There's no single \"best\" coffee because taste is subjective. What one person finds delicious, another might find bitter or bland. \n", - "\n", - "However, I can give you some pointers to help you find YOUR best coffee:\n", - "\n", - "**Factors that influence coffee taste:**\n", - "\n", - "* **Bean Origin:** Different regions produce beans with unique flavor profiles. \n", - " * **Latin America:** Often known for chocolatey, nutty, and smooth flavors. (Colombia, Brazil, Guatemala)\n", - " * **Africa:** Can have bright acidity, fruity notes, and floral aromas. (Ethiopia, Kenya, Tanzania)\n", - " * **Asia/Pacific:** Often earthy, spicy, and full-bodied. (Indonesia, Vietnam)\n", - "* **Roast Level:**\n", - " * **Light:** More acidic, delicate flavors, higher caffeine.\n", - " * **Medium:** Balanced acidity and body, versatile.\n", - " * **Dark:** Bold, smoky, bittersweet flavors, lower caffeine.\n", - "* **Brewing Method:** Each method extracts flavors differently, impacting the final taste.\n", - "\n", - "**Finding YOUR Best:**\n", - "\n", - "1. **Explore Different Origins:** Try coffees from various regions to discover what flavor profiles you enjoy.\n", - "2. **Experiment with Roast Levels:** Sample light, medium, and dark roasts to see your preference.\n", - "3. **Consider Your Brewing Method:** Different beans work better with certain brewing methods. Ask your local coffee shop for recommendations.\n", - "4. **Read Reviews:** Online reviews and coffee blogs can offer insights into specific beans and roasters.\n", - "5. **Visit a Local Coffee Shop:** Talk to baristas, ask for recommendations, and try different coffees.\n", - "\n", - "**Remember:** Coffee is a journey of discovery! Enjoy the process of exploring and finding your perfect cup.\n", - "\n", - "\n", - "user\n", - "what are similar drinks?\n", - "\n", - "\n", - "Here are some drinks similar to coffee, categorized by what aspect of coffee they resemble:\n", - "\n", - "**Similar Caffeine Kick:**\n", - "\n", - "* **Tea:** Wide variety of flavors and caffeine levels, from delicate green tea to robust black tea.\n", - "* **Matcha:** Powdered green tea with a unique earthy flavor and higher caffeine content than regular green tea.\n", - "* **Yerba Mate:** South American herbal tea with a slightly bitter, grassy flavor and moderate caffeine.\n", - "* **Energy Drinks:** High caffeine content, often with added sugar and other stimulants.\n", - "\n", - "**Similar Flavor Profiles:**\n", - "\n", - "* **Chocolate:** Rich, bittersweet flavors can complement coffee's roasted notes.\n", - "* **Caramel:** Sweet and buttery, caramel adds a creamy dimension similar to coffee's body.\n", - "* **Vanilla:** A classic pairing with coffee, vanilla adds a warm, comforting sweetness.\n", - "* **Espresso-Based Drinks:** Lattes, cappuccinos, macchiatos, and mochas all feature espresso as a base, offering variations in milk and flavorings.\n", - "\n", - "**Similar Ritual and Experience:**\n", - "\n", - "* **Hot Chocolate:** A comforting and warming drink often enjoyed in the morning or evening.\n", - "* **Herbal Teas:** A relaxing and flavorful alternative to coffee, enjoyed for their health benefits and calming effects.\n", - "* **Golden Milk:** A turmeric-based drink with\n", "\n" ] } ], "source": [ - "chat.show_history()" + "print(chat.get_history())" ] } ], @@ -1241,7 +646,9 @@ "accelerator": "GPU", "colab": { "name": "Keras_Gemma_2_Quickstart_Chat.ipynb", - "toc_visible": true + "toc_visible": true, + "provenance": [], + "gpuType": "A100" }, "kernelspec": { "display_name": "Python 3", @@ -1250,4 +657,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file From 50d086282ab8abd39635aed88fc54e12c3436d8f Mon Sep 17 00:00:00 2001 From: Juyeong Ji Date: Thu, 27 Jun 2024 20:53:17 +0900 Subject: [PATCH 2/4] fix the chat helper class --- Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb | 111 ++++++++++++---------- 1 file changed, 62 insertions(+), 49 deletions(-) diff --git a/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb b/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb index ec29f13..00394b1 100644 --- a/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb +++ b/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb @@ -111,14 +111,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": { "id": "yygIK9DEIldp", "colab": { "base_uri": "https://localhost:8080/", - "height": 544 + "height": 717 }, - "outputId": "3cd1d22f-7c55-4e62-e44d-895a82f22553" + "outputId": "648d8223-9cc2-44e7-ec8a-6d1c3185ad1a" }, "outputs": [ { @@ -127,12 +127,22 @@ "text": [ "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors...\n", "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors.index.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/metadata.json...\n", + "100%|██████████| 143/143 [00:00<00:00, 209kB/s]\n", "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/task.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/config.json...\n", + "100%|██████████| 780/780 [00:00<00:00, 1.18MB/s]\n", "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors...\n", "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors.index.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.weights.h5...\n", + "100%|██████████| 17.2G/17.2G [02:41<00:00, 114MB/s]\n", "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors...\n", "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors.index.json...\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/preprocessor.json...\n" + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/preprocessor.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/tokenizer.json...\n", + "100%|██████████| 315/315 [00:00<00:00, 500kB/s]\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/assets/tokenizer/vocabulary.spm...\n", + "100%|██████████| 4.04M/4.04M [00:00<00:00, 16.9MB/s]\n" ] }, { @@ -300,7 +310,7 @@ "metadata": { "id": "z6nQPPU7bFk6" }, - "execution_count": 3, + "execution_count": 4, "outputs": [] }, { @@ -314,7 +324,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": { "id": "O0TkvhOASI9f" }, @@ -351,9 +361,10 @@ "\n", " def add_to_history_as_model(self, message):\n", " \"\"\"\n", - " Adds a model response to the history with start/end turn markers.\n", + " Adds a model response to the history with the start turn marker.\n", + " Model will generate end turn marker.\n", " \"\"\"\n", - " self.history.append(self.__START_TURN_MODEL__ + message + self.__END_TURN__)\n", + " self.history.append(self.__START_TURN_MODEL__ + message)\n", "\n", " def get_history(self):\n", " \"\"\"\n", @@ -399,14 +410,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": { "id": "shfCZDFPKghT", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, - "outputId": "4841bbbb-f11d-45e1-9dd6-4c2bfd91688a" + "outputId": "935de9aa-c225-4063-f2b1-5c51759beb08" }, "outputs": [ { @@ -418,7 +429,7 @@ "text/markdown": "🙋‍♂️
help me understand how to make coffee
🤖\n\n> ## Let's Brew Some Coffee! ☕️\n> \n> Making coffee can be as simple or complex as you like. Here's a breakdown of some popular methods, from beginner-friendly to more advanced:\n> \n> **1. The Quick & Easy: Instant Coffee**\n> \n> * **What you need:** Instant coffee granules, hot water\n> * **How to:** Simply add a spoonful of instant coffee to a mug, pour hot water over it, stir, and enjoy!\n> \n> **2. The Classic: Drip Coffee Maker**\n> \n> * **What you need:** Drip coffee maker, ground coffee, filter\n> * **How to:**\n> * Fill the water reservoir with fresh, cold water.\n> * Place a filter in the filter basket.\n> * Add the desired amount of ground coffee to the filter.\n> * Turn on the coffee maker and let it do its thing!\n> \n> **3. The French Press:**\n> \n> * **What you need:** French press, coarse ground coffee, hot water\n> * **How to:**\n> * Add coarse ground coffee to the French press.\n> * Pour hot water (just off the boil) over the coffee grounds.\n> * Stir gently and let it steep for 4 minutes.\n> * Slowly press the plunger down to separate the grounds from the coffee.\n> * Pour and enjoy!\n> \n> **4. The Pour Over:**\n> \n> * **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water\n> * **How to:**\n> * Place a filter in the cone and rinse it with hot water to remove any paper taste.\n> * Add medium-fine ground coffee to the filter.\n> * Slowly pour hot water over the grounds in a circular motion, ensuring all grounds are saturated.\n> * Let the coffee drip through into your cup.\n> \n> **5. The Espresso Machine:**\n> \n> * **What you need:** Espresso machine, finely ground coffee, tamper\n> * **How to:**\n> * Grind your coffee beans finely.\n> * Tamp the coffee grounds firmly into the portafilter.\n> * Lock the portafilter into the espresso machine.\n> * Brew your espresso shot!\n> \n> **Tips for Delicious Coffee:**\n> \n> * **Use fresh, quality beans:** The better the beans, the better the coffee.\n> * **Grind your beans right before brewing:** This preserves freshness and flavor.\n> * **Use filtered water:** Impurities in water can affect the taste of your coffee.\n> * **Experiment with different brewing methods:** Find what you like best!\n> * **Don't be afraid to adjust:** Play with the amount of coffee, water, and brewing time to find your perfect cup.\n> \n> \n> Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n\n" }, "metadata": {}, - "execution_count": 5 + "execution_count": 6 } ], "source": [ @@ -429,14 +440,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": { "id": "bLxtlhjtLkWQ", "colab": { "base_uri": "https://localhost:8080/", - "height": 761 + "height": 784 }, - "outputId": "4c8d72f6-2067-40f0-c380-f2c8882c6620" + "outputId": "db883963-943e-4519-eff1-f9ca7cdfe9ac" }, "outputs": [ { @@ -445,10 +456,10 @@ "text/plain": [ "" ], - "text/markdown": "🙋‍♂️
what is the best coffee?
🤖\n\n> Ah, the eternal question! There's no single \"best\" coffee because taste is subjective. What one person finds delicious, another might find bitter or bland. \n> \n> It all depends on your personal preferences:\n> \n> **Consider these factors:**\n> \n> * **Roast Level:**\n> * **Light:** Bright acidity, delicate flavors, often fruity or floral.\n> * **Medium:** Balanced acidity and body, with more pronounced flavors.\n> * **Dark:** Bold, smoky, sometimes bittersweet, with less acidity.\n> * **Origin:** Different regions produce beans with unique flavor profiles:\n> * **Latin America:** Often chocolatey, nutty, with medium acidity.\n> * **Africa:** Known for bright acidity, fruity notes, and floral aromas.\n> * **Asia/Pacific:** Earthy, spicy, sometimes with chocolate or caramel notes.\n> * **Brewing Method:** The method you use can significantly impact the flavor.\n> \n> **Some Popular and Highly-Regarded Coffees:**\n> \n> * **Ethiopian Yirgacheffe:** Known for its floral, citrusy, and tea-like qualities.\n> * **Kenyan AA:** Bright acidity, black currant, and berry flavors.\n> * **Sumatran Mandheling:** Earthy, spicy, with low acidity and a full body.\n> * **Colombian Supremo:** Balanced, smooth, with notes of caramel and chocolate.\n> \n> **My Recommendation:**\n> \n> * **Start exploring!** Visit a local coffee shop or roaster and ask for recommendations based on your preferences.\n> * **Try different roasts and origins.**\n> * **Keep a coffee journal:** Note what you like and dislike about each coffee you try.\n> \n> Ultimately, the best coffee is the one that you enjoy the most! Happy brewing! ☕️\n\n" + "text/markdown": "🙋‍♂️
what is the best coffee?
🤖\n\n> Ah, the eternal question! There's no single \"best\" coffee because taste is subjective. What one person finds delicious, another might find bitter or bland. \n> \n> It all depends on your personal preferences:\n> \n> **Consider these factors:**\n> \n> * **Roast Level:**\n> * **Light:** Bright acidity, delicate flavors, often fruity or floral.\n> * **Medium:** Balanced acidity and body, with more pronounced flavors.\n> * **Dark:** Bold, smoky, sometimes bittersweet, with less acidity.\n> * **Origin:** Different regions produce beans with unique flavor profiles:\n> * **Latin America:** Often chocolatey, nutty, with medium acidity.\n> * **Africa:** Known for bright acidity, fruity notes, and floral aromas.\n> * **Asia/Pacific:** Earthy, spicy, sometimes with chocolate or caramel notes.\n> * **Brewing Method:** The method you use can significantly impact the flavor.\n> \n> **Some Popular and Highly-Regarded Coffees:**\n> \n> * **Ethiopian Yirgacheffe:** Known for its floral, citrusy, and tea-like qualities.\n> * **Kenyan AA:** Bright acidity, black currant, and berry flavors.\n> * **Sumatran Mandheling:** Earthy, spicy, with low acidity.\n> * **Colombian Supremo:** Balanced, with chocolate and caramel notes.\n> \n> **My Recommendation:**\n> \n> * **Start exploring!** Try different roasts, origins, and brewing methods to discover what you enjoy most.\n> * **Talk to your local coffee shop:** Baristas are passionate about coffee and can offer great recommendations based on your preferences.\n> * **Don't be afraid to experiment:** The world of coffee is vast and exciting!\n> \n> \n> Happy brewing!\n\n" }, "metadata": {}, - "execution_count": 6 + "execution_count": 7 } ], "source": [ @@ -458,14 +469,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": { "id": "tfvgl4sC9g2p", "colab": { "base_uri": "https://localhost:8080/", - "height": 743 + "height": 733 }, - "outputId": "2dc92415-d6cd-4fde-cd10-ed615732f3b3" + "outputId": "69db12a1-425d-4989-a9b3-d9a58794f13e" }, "outputs": [ { @@ -474,10 +485,10 @@ "text/plain": [ "" ], - "text/markdown": "🙋‍♂️
what are similar drinks?
🤖\n\n> You're looking for drinks similar to coffee? Great question! Here are some options, categorized by what aspect of coffee you might be drawn to:\n> \n> **If you like the caffeine kick:**\n> \n> * **Tea:** Black tea offers a similar caffeine level to coffee, with a wider range of flavors from robust to floral. Green tea has less caffeine but is packed with antioxidants.\n> * **Matcha:** A powdered green tea with a unique earthy flavor and a sustained energy boost.\n> * **Yerba Mate:** A South American beverage with a slightly bitter, grassy flavor and a moderate caffeine content.\n> \n> **If you like the rich, roasted flavor:**\n> \n> * **Chicory Coffee:** Made from roasted chicory root, it has a coffee-like flavor but is caffeine-free.\n> * **Roasted Barley Tea:** A caffeine-free option with a nutty, toasty flavor.\n> * **Carob:** Made from roasted carob pods, it has a naturally sweet, chocolatey flavor.\n> \n> **If you like the ritual and warmth:**\n> \n> * **Hot Chocolate:** A comforting and indulgent treat, especially with marshmallows!\n> * **Golden Milk:** A turmeric-based drink with warming spices and a creamy texture.\n> * **Herbal Teas:** A wide variety of flavors and aromas to choose from, perfect for relaxation.\n> \n> **If you like the customization options:**\n> \n> * **Espresso-based drinks:** Lattes, cappuccinos, macchiatos, and more offer endless possibilities for flavor combinations.\n> * **Smoothies:** Blend fruits, vegetables, and other ingredients for a refreshing and nutritious drink.\n> \n> Remember, there are countless variations and combinations within these categories. Don't be afraid to experiment and find your new favorite drink!\n\n" + "text/markdown": "🙋‍♂️
what are similar drinks?
🤖\n\n> You're looking for drinks that share similarities with coffee! Here are some options, categorized by what aspect of coffee they resemble:\n> \n> **Similar Caffeine Kick:**\n> \n> * **Tea:** Comes in endless varieties, with varying caffeine levels. Black tea has the most caffeine, followed by green, white, and herbal teas.\n> * **Matcha:** A powdered green tea with a unique earthy flavor and a good amount of caffeine.\n> * **Yerba Mate:** A South American beverage with a slightly bitter, grassy flavor and a caffeine boost comparable to coffee.\n> \n> **Similar Rich, Roasted Flavor:**\n> \n> * **Chicory Coffee:** Made from roasted chicory root, it has a coffee-like flavor but is caffeine-free.\n> * **Roasted Barley Tea:** A caffeine-free option with a nutty, roasted flavor.\n> \n> **Similar Creamy, Indulgent Experience:**\n> \n> * **Hot Chocolate:** A classic comfort drink with a rich, chocolatey flavor.\n> * **Golden Milk:** A warming drink made with turmeric, ginger, cinnamon, and milk.\n> \n> **Similar Ritual and Experience:**\n> \n> * **Chai Tea Latte:** A spiced black tea latte with a creamy, comforting flavor.\n> * **London Fog:** A blend of Earl Grey tea, steamed milk, and vanilla syrup.\n> \n> **Beyond the Usual:**\n> \n> * **Kava:** A Polynesian drink made from the kava root, known for its relaxing and social effects.\n> * **Guayusa:** A South American tea with a smooth, slightly sweet flavor and a moderate caffeine boost.\n> \n> \n> Remember, taste is subjective! Explore these options and see what you enjoy most.\n\n" }, "metadata": {}, - "execution_count": 7 + "execution_count": 8 } ], "source": [ @@ -496,13 +507,13 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": { "id": "P2GjAVybBez3", "colab": { "base_uri": "https://localhost:8080/" }, - "outputId": "c72ea9a9-911b-47ed-a47c-a621b2cf9b7d" + "outputId": "fba217c9-61de-4995-d337-9dca9570704c" }, "outputs": [ { @@ -568,7 +579,6 @@ "\n", "\n", "Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n", - "\n", "user\n", "what is the best coffee?\n", "model\n", @@ -592,47 +602,50 @@ "\n", "* **Ethiopian Yirgacheffe:** Known for its floral, citrusy, and tea-like qualities.\n", "* **Kenyan AA:** Bright acidity, black currant, and berry flavors.\n", - "* **Sumatran Mandheling:** Earthy, spicy, with low acidity and a full body.\n", - "* **Colombian Supremo:** Balanced, smooth, with notes of caramel and chocolate.\n", + "* **Sumatran Mandheling:** Earthy, spicy, with low acidity.\n", + "* **Colombian Supremo:** Balanced, with chocolate and caramel notes.\n", "\n", "**My Recommendation:**\n", "\n", - "* **Start exploring!** Visit a local coffee shop or roaster and ask for recommendations based on your preferences.\n", - "* **Try different roasts and origins.**\n", - "* **Keep a coffee journal:** Note what you like and dislike about each coffee you try.\n", + "* **Start exploring!** Try different roasts, origins, and brewing methods to discover what you enjoy most.\n", + "* **Talk to your local coffee shop:** Baristas are passionate about coffee and can offer great recommendations based on your preferences.\n", + "* **Don't be afraid to experiment:** The world of coffee is vast and exciting!\n", + "\n", "\n", - "Ultimately, the best coffee is the one that you enjoy the most! Happy brewing! ☕️\n", - "\n", + "Happy brewing!\n", "user\n", "what are similar drinks?\n", "model\n", - "You're looking for drinks similar to coffee? Great question! Here are some options, categorized by what aspect of coffee you might be drawn to:\n", + "You're looking for drinks that share similarities with coffee! Here are some options, categorized by what aspect of coffee they resemble:\n", + "\n", + "**Similar Caffeine Kick:**\n", + "\n", + "* **Tea:** Comes in endless varieties, with varying caffeine levels. Black tea has the most caffeine, followed by green, white, and herbal teas.\n", + "* **Matcha:** A powdered green tea with a unique earthy flavor and a good amount of caffeine.\n", + "* **Yerba Mate:** A South American beverage with a slightly bitter, grassy flavor and a caffeine boost comparable to coffee.\n", + "\n", + "**Similar Rich, Roasted Flavor:**\n", "\n", - "**If you like the caffeine kick:**\n", + "* **Chicory Coffee:** Made from roasted chicory root, it has a coffee-like flavor but is caffeine-free.\n", + "* **Roasted Barley Tea:** A caffeine-free option with a nutty, roasted flavor.\n", "\n", - "* **Tea:** Black tea offers a similar caffeine level to coffee, with a wider range of flavors from robust to floral. Green tea has less caffeine but is packed with antioxidants.\n", - "* **Matcha:** A powdered green tea with a unique earthy flavor and a sustained energy boost.\n", - "* **Yerba Mate:** A South American beverage with a slightly bitter, grassy flavor and a moderate caffeine content.\n", + "**Similar Creamy, Indulgent Experience:**\n", "\n", - "**If you like the rich, roasted flavor:**\n", + "* **Hot Chocolate:** A classic comfort drink with a rich, chocolatey flavor.\n", + "* **Golden Milk:** A warming drink made with turmeric, ginger, cinnamon, and milk.\n", "\n", - "* **Chicory Coffee:** Made from roasted chicory root, it has a coffee-like flavor but is caffeine-free.\n", - "* **Roasted Barley Tea:** A caffeine-free option with a nutty, toasty flavor.\n", - "* **Carob:** Made from roasted carob pods, it has a naturally sweet, chocolatey flavor.\n", + "**Similar Ritual and Experience:**\n", "\n", - "**If you like the ritual and warmth:**\n", + "* **Chai Tea Latte:** A spiced black tea latte with a creamy, comforting flavor.\n", + "* **London Fog:** A blend of Earl Grey tea, steamed milk, and vanilla syrup.\n", "\n", - "* **Hot Chocolate:** A comforting and indulgent treat, especially with marshmallows!\n", - "* **Golden Milk:** A turmeric-based drink with warming spices and a creamy texture.\n", - "* **Herbal Teas:** A wide variety of flavors and aromas to choose from, perfect for relaxation.\n", + "**Beyond the Usual:**\n", "\n", - "**If you like the customization options:**\n", + "* **Kava:** A Polynesian drink made from the kava root, known for its relaxing and social effects.\n", + "* **Guayusa:** A South American tea with a smooth, slightly sweet flavor and a moderate caffeine boost.\n", "\n", - "* **Espresso-based drinks:** Lattes, cappuccinos, macchiatos, and more offer endless possibilities for flavor combinations.\n", - "* **Smoothies:** Blend fruits, vegetables, and other ingredients for a refreshing and nutritious drink.\n", "\n", - "Remember, there are countless variations and combinations within these categories. Don't be afraid to experiment and find your new favorite drink!\n", - "\n", + "Remember, taste is subjective! Explore these options and see what you enjoy most.\n", "\n" ] } From 7142085173ad567803fa2911e2b58d8a720dbef9 Mon Sep 17 00:00:00 2001 From: Juyeong Ji Date: Thu, 27 Jun 2024 21:12:27 +0900 Subject: [PATCH 3/4] update the gemma 2 quickstart --- Gemma/Keras_Gemma_2_Quickstart.ipynb | 273 ++++++++++++++------------- 1 file changed, 142 insertions(+), 131 deletions(-) diff --git a/Gemma/Keras_Gemma_2_Quickstart.ipynb b/Gemma/Keras_Gemma_2_Quickstart.ipynb index a4f7bab..95fdac4 100644 --- a/Gemma/Keras_Gemma_2_Quickstart.ipynb +++ b/Gemma/Keras_Gemma_2_Quickstart.ipynb @@ -37,16 +37,13 @@ "id": "PXNm5_p_oxMF" }, "source": [ - "This is a quick demo of Gemma running on KerasNLP. To run this you will need:\n", - "- To be added to a private github repo for Gemma.\n", - "- To be added to a private Kaggle model for weights.\n", + "This is a quick demo of Gemma running on KerasNLP.\n", "\n", "Note that you will need a large GPU (e.g. A100) to run this as well.\n", "\n", "General Keras reading:\n", "- [Getting started with Keras](https://keras.io/getting_started/)\n", "- [Getting started with KerasNLP](https://keras.io/guides/keras_nlp/getting_started/)\n", - "- [Generation and fine-tuning guide for GPT2](https://keras.io/guides/keras_nlp/getting_started/)\n", "\n", "\n", "
\n", @@ -76,7 +73,9 @@ "from google.colab import userdata\n", "\n", "os.environ[\"KAGGLE_USERNAME\"] = userdata.get('KAGGLE_USERNAME')\n", - "os.environ[\"KAGGLE_KEY\"] = userdata.get('KAGGLE_KEY')" + "os.environ[\"KAGGLE_KEY\"] = userdata.get('KAGGLE_KEY')\n", + "\n", + "os.environ[\"KERAS_BACKEND\"] = \"jax\" # Or \"tensorflow\" or \"torch\"." ] }, { @@ -90,36 +89,15 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "id": "bMboT70Xop8G" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", - " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", - " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m21.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.2/5.2 MB\u001b[0m \u001b[31m72.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m311.2/311.2 kB\u001b[0m \u001b[31m35.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m589.8/589.8 MB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.3/5.3 MB\u001b[0m \u001b[31m95.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m76.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.5/5.5 MB\u001b[0m \u001b[31m107.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25h Building wheel for keras-nlp (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", - "\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", - "tf-keras 2.15.1 requires tensorflow<2.16,>=2.15, but you have tensorflow 2.16.1 which is incompatible.\u001b[0m\u001b[31m\n", - "\u001b[0m" - ] - } - ], + "outputs": [], "source": [ "# Install all deps\n", - "!pip install keras\n", - "!pip install keras-nlp" + "!pip install -U keras-nlp\n", + "!pip install -U keras==3.3.3" ] }, { @@ -135,61 +113,61 @@ "cell_type": "code", "execution_count": 3, "metadata": { - "id": "ww83zI9ToPso" - }, - "outputs": [], - "source": [ - "import os\n", - "\n", - "os.environ[\"KERAS_BACKEND\"] = \"jax\" # Or \"tensorflow\" or \"torch\".\n", - "\n", - "import keras_nlp\n", - "import keras\n", - "\n", - "# Run at half precision.\n", - "keras.config.set_floatx(\"bfloat16\")" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "id": "yygIK9DEIldp" + "id": "ww83zI9ToPso", + "outputId": "2ffbb6b0-e3b2-4f8f-b614-0c5e1dfa4adf", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 717 + } }, "outputs": [ { - "name": "stderr", "output_type": "stream", + "name": "stderr", "text": [ - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/3/download/metadata.json...\n", - "100%|██████████| 143/143 [00:00<00:00, 179kB/s]\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/3/download/task.json...\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/3/download/config.json...\n", - "100%|██████████| 780/780 [00:00<00:00, 895kB/s]\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/3/download/model.weights.h5...\n", - "100%|██████████| 17.2G/17.2G [18:34<00:00, 16.6MB/s]\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/3/download/preprocessor.json...\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/3/download/tokenizer.json...\n", - "100%|██████████| 315/315 [00:00<00:00, 431kB/s]\n", - "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/3/download/assets/tokenizer/vocabulary.spm...\n", - "100%|██████████| 4.04M/4.04M [00:01<00:00, 2.41MB/s]\n" + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/model.safetensors...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/model.safetensors.index.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/metadata.json...\n", + "100%|██████████| 143/143 [00:00<00:00, 153kB/s]\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/task.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/config.json...\n", + "100%|██████████| 780/780 [00:00<00:00, 884kB/s]\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/model.safetensors...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/model.safetensors.index.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/model.weights.h5...\n", + "100%|██████████| 17.2G/17.2G [04:22<00:00, 70.5MB/s]\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/model.safetensors...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/model.safetensors.index.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/preprocessor.json...\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/tokenizer.json...\n", + "100%|██████████| 315/315 [00:00<00:00, 434kB/s]\n", + "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/assets/tokenizer/vocabulary.spm...\n", + "100%|██████████| 4.04M/4.04M [00:00<00:00, 14.6MB/s]\n" ] }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1mPreprocessor: \"gemma_causal_lm_preprocessor\"\u001b[0m\n" + ], "text/html": [ "
Preprocessor: \"gemma_causal_lm_preprocessor\"\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1mPreprocessor: \"gemma_causal_lm_preprocessor\"\u001b[0m\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\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", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) │ \u001b[38;5;34m256,000\u001b[0m │\n", + "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n" + ], "text/html": [ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
               "┃ Tokenizer (type)                                                                                Vocab # ┃\n",
@@ -197,33 +175,41 @@
               "│ gemma_tokenizer (GemmaTokenizer)                   │                                             256,000 │\n",
               "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n",
               "
\n" - ], - "text/plain": [ - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", - "┃\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", - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", - "│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) │ \u001b[38;5;34m256,000\u001b[0m │\n", - "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1mModel: \"gemma_causal_lm\"\u001b[0m\n" + ], "text/html": [ "
Model: \"gemma_causal_lm\"\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1mModel: \"gemma_causal_lm\"\u001b[0m\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ padding_mask (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ token_ids (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ gemma_backbone │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3584\u001b[0m) │ \u001b[38;5;34m9,241,705,984\u001b[0m │ padding_mask[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", + "│ (\u001b[38;5;33mGemmaBackbone\u001b[0m) │ │ │ token_ids[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ token_embedding │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256000\u001b[0m) │ \u001b[38;5;34m917,504,000\u001b[0m │ gemma_backbone[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mReversibleEmbedding\u001b[0m) │ │ │ │\n", + "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n" + ], "text/html": [ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
               "┃ Layer (type)                   Output Shape                       Param #  Connected to               ┃\n",
@@ -239,95 +225,118 @@
               "│ (ReversibleEmbedding)         │                           │                 │                            │\n",
               "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n",
               "
\n" - ], - "text/plain": [ - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", - "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", - "│ padding_mask (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ token_ids (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ gemma_backbone │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3584\u001b[0m) │ \u001b[38;5;34m9,241,705,984\u001b[0m │ padding_mask[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", - "│ (\u001b[38;5;33mGemmaBackbone\u001b[0m) │ │ │ token_ids[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ token_embedding │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256000\u001b[0m) │ \u001b[38;5;34m917,504,000\u001b[0m │ gemma_backbone[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", - "│ (\u001b[38;5;33mReversibleEmbedding\u001b[0m) │ │ │ │\n", - "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" + ], "text/html": [ "
 Total params: 9,241,705,984 (17.21 GB)\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" + ], "text/html": [ "
 Trainable params: 9,241,705,984 (17.21 GB)\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} }, { + "output_type": "display_data", "data": { + "text/plain": [ + "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n" + ], "text/html": [ "
 Non-trainable params: 0 (0.00 B)\n",
               "
\n" - ], - "text/plain": [ - "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n" ] }, - "metadata": {}, - "output_type": "display_data" + "metadata": {} } ], "source": [ - "# Connect using the default `gemma2_9b_keras` or through huggingface weights `hf://google/gemma-2-9b-keras`\n", + "import keras_nlp\n", + "import keras\n", + "\n", + "# Run at half precision.\n", + "keras.config.set_floatx(\"bfloat16\")\n", + "\n", + "# using 9B base model\n", "gemma_lm = keras_nlp.models.GemmaCausalLM.from_preset(\"gemma2_9b_en\")\n", "gemma_lm.summary()" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": { - "id": "aae5GHrdpj2_" + "id": "aae5GHrdpj2_", + "outputId": "718a5755-f7d8-42ad-f2af-a2a2b57ae710", + "colab": { + "base_uri": "https://localhost:8080/" + } }, "outputs": [ { - "data": { - "application/vnd.google.colaboratory.intrinsic+json": { - "type": "string" - }, - "text/plain": [ - "'What is the meaning of life?\\n\\n[Answer 1]\\n\\nThe meaning of life is to live it.\\n\\n[Answer 2]\\n\\nThe'" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" + "output_type": "stream", + "name": "stdout", + "text": [ + "It was a dark and stormy night.\n", + "\n", + "The wind was howling, the rain was pouring, and the thunder was rumbling.\n", + "\n", + "I was sitting in my living room, watching the storm rage outside.\n", + "\n", + "Suddenly, I heard a knock at the door.\n", + "\n", + "I got up and opened it, and there stood a man in a black cloak.\n", + "\n", + "He had a strange look in his eyes, and he was holding a lantern.\n", + "\n", + "\"Who are you?\" I asked.\n", + "\n", + "\"I am the storm,\" he replied.\n", + "\n", + "\"And I have come to take you away.\"\n", + "\n", + "I was terrified, but I couldn't move.\n", + "\n", + "The man in the black cloak grabbed my arm and pulled me out into the storm.\n", + "\n", + "We walked for what seemed like hours, until we came to a clearing in the woods.\n", + "\n", + "There, the man in the black cloak stopped and turned to me.\n", + "\n", + "\"You are mine now,\" he said.\n", + "\n", + "\"And I will take you to my castle.\"\n", + "\n", + "I tried to fight him off, but he was too strong.\n", + "\n", + "He dragged me into the castle, and I was never seen again.\n", + "\n", + "The end.\n" + ] } ], "source": [ - "gemma_lm.generate(\"What is the meaning of life?\", max_length=32)" + "result = gemma_lm.generate(\"It was a dark and stormy night.\", max_length=256)\n", + "print(result)" ] } ], @@ -335,7 +344,9 @@ "accelerator": "GPU", "colab": { "name": "Keras_Gemma_2_Quickstart.ipynb", - "toc_visible": true + "toc_visible": true, + "provenance": [], + "gpuType": "A100" }, "kernelspec": { "display_name": "Python 3", @@ -344,4 +355,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file From 01ddfd4e3d073e0075b7aa60580e005cdf10e0cb Mon Sep 17 00:00:00 2001 From: Juyeong Ji Date: Thu, 27 Jun 2024 21:19:09 +0900 Subject: [PATCH 4/4] fix notebook formatting --- Gemma/Keras_Gemma_2_Quickstart.ipynb | 125 ++++++------- Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb | 214 ++++++++++------------ 2 files changed, 151 insertions(+), 188 deletions(-) diff --git a/Gemma/Keras_Gemma_2_Quickstart.ipynb b/Gemma/Keras_Gemma_2_Quickstart.ipynb index 95fdac4..4de94fe 100644 --- a/Gemma/Keras_Gemma_2_Quickstart.ipynb +++ b/Gemma/Keras_Gemma_2_Quickstart.ipynb @@ -113,17 +113,12 @@ "cell_type": "code", "execution_count": 3, "metadata": { - "id": "ww83zI9ToPso", - "outputId": "2ffbb6b0-e3b2-4f8f-b614-0c5e1dfa4adf", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 717 - } + "id": "ww83zI9ToPso" }, "outputs": [ { - "output_type": "stream", "name": "stderr", + "output_type": "stream", "text": [ "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/model.safetensors...\n", "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_9b_en/1/download/model.safetensors.index.json...\n", @@ -146,28 +141,20 @@ ] }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1mPreprocessor: \"gemma_causal_lm_preprocessor\"\u001b[0m\n" - ], "text/html": [ "
Preprocessor: \"gemma_causal_lm_preprocessor\"\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1mPreprocessor: \"gemma_causal_lm_preprocessor\"\u001b[0m\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", - "┃\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", - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", - "│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) │ \u001b[38;5;34m256,000\u001b[0m │\n", - "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n" - ], "text/html": [ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
               "┃ Tokenizer (type)                                                                                Vocab # ┃\n",
@@ -175,41 +162,33 @@
               "│ gemma_tokenizer (GemmaTokenizer)                   │                                             256,000 │\n",
               "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n",
               "
\n" + ], + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\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", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) │ \u001b[38;5;34m256,000\u001b[0m │\n", + "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1mModel: \"gemma_causal_lm\"\u001b[0m\n" - ], "text/html": [ "
Model: \"gemma_causal_lm\"\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1mModel: \"gemma_causal_lm\"\u001b[0m\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", - "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", - "│ padding_mask (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ token_ids (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ gemma_backbone │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3584\u001b[0m) │ \u001b[38;5;34m9,241,705,984\u001b[0m │ padding_mask[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", - "│ (\u001b[38;5;33mGemmaBackbone\u001b[0m) │ │ │ token_ids[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ token_embedding │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256000\u001b[0m) │ \u001b[38;5;34m917,504,000\u001b[0m │ gemma_backbone[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", - "│ (\u001b[38;5;33mReversibleEmbedding\u001b[0m) │ │ │ │\n", - "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n" - ], "text/html": [ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
               "┃ Layer (type)                   Output Shape                       Param #  Connected to               ┃\n",
@@ -225,48 +204,64 @@
               "│ (ReversibleEmbedding)         │                           │                 │                            │\n",
               "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n",
               "
\n" + ], + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ padding_mask (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ token_ids (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ gemma_backbone │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3584\u001b[0m) │ \u001b[38;5;34m9,241,705,984\u001b[0m │ padding_mask[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", + "│ (\u001b[38;5;33mGemmaBackbone\u001b[0m) │ │ │ token_ids[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ token_embedding │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256000\u001b[0m) │ \u001b[38;5;34m917,504,000\u001b[0m │ gemma_backbone[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mReversibleEmbedding\u001b[0m) │ │ │ │\n", + "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" - ], "text/html": [ "
 Total params: 9,241,705,984 (17.21 GB)\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" - ], "text/html": [ "
 Trainable params: 9,241,705,984 (17.21 GB)\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n" - ], "text/html": [ "
 Non-trainable params: 0 (0.00 B)\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -285,16 +280,12 @@ "cell_type": "code", "execution_count": 9, "metadata": { - "id": "aae5GHrdpj2_", - "outputId": "718a5755-f7d8-42ad-f2af-a2a2b57ae710", - "colab": { - "base_uri": "https://localhost:8080/" - } + "id": "aae5GHrdpj2_" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "It was a dark and stormy night.\n", "\n", @@ -344,9 +335,7 @@ "accelerator": "GPU", "colab": { "name": "Keras_Gemma_2_Quickstart.ipynb", - "toc_visible": true, - "provenance": [], - "gpuType": "A100" + "toc_visible": true }, "kernelspec": { "display_name": "Python 3", @@ -355,4 +344,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb b/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb index 00394b1..e742b68 100644 --- a/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb +++ b/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb @@ -113,17 +113,12 @@ "cell_type": "code", "execution_count": 3, "metadata": { - "id": "yygIK9DEIldp", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 717 - }, - "outputId": "648d8223-9cc2-44e7-ec8a-6d1c3185ad1a" + "id": "yygIK9DEIldp" }, "outputs": [ { - "output_type": "stream", "name": "stderr", + "output_type": "stream", "text": [ "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors...\n", "Downloading from https://www.kaggle.com/api/v1/models/keras/gemma2/keras/gemma2_instruct_9b_en/1/download/model.safetensors.index.json...\n", @@ -146,28 +141,20 @@ ] }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1mPreprocessor: \"gemma_causal_lm_preprocessor\"\u001b[0m\n" - ], "text/html": [ "
Preprocessor: \"gemma_causal_lm_preprocessor\"\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1mPreprocessor: \"gemma_causal_lm_preprocessor\"\u001b[0m\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", - "┃\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", - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", - "│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) │ \u001b[38;5;34m256,000\u001b[0m │\n", - "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n" - ], "text/html": [ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
               "┃ Tokenizer (type)                                                                                Vocab # ┃\n",
@@ -175,41 +162,33 @@
               "│ gemma_tokenizer (GemmaTokenizer)                   │                                             256,000 │\n",
               "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n",
               "
\n" + ], + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\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", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ gemma_tokenizer (\u001b[38;5;33mGemmaTokenizer\u001b[0m) │ \u001b[38;5;34m256,000\u001b[0m │\n", + "└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1mModel: \"gemma_causal_lm\"\u001b[0m\n" - ], "text/html": [ "
Model: \"gemma_causal_lm\"\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1mModel: \"gemma_causal_lm\"\u001b[0m\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", - "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", - "│ padding_mask (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ token_ids (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ gemma_backbone │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3584\u001b[0m) │ \u001b[38;5;34m9,241,705,984\u001b[0m │ padding_mask[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", - "│ (\u001b[38;5;33mGemmaBackbone\u001b[0m) │ │ │ token_ids[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", - "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", - "│ token_embedding │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256000\u001b[0m) │ \u001b[38;5;34m917,504,000\u001b[0m │ gemma_backbone[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", - "│ (\u001b[38;5;33mReversibleEmbedding\u001b[0m) │ │ │ │\n", - "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n" - ], "text/html": [ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
               "┃ Layer (type)                   Output Shape                       Param #  Connected to               ┃\n",
@@ -225,48 +204,64 @@
               "│ (ReversibleEmbedding)         │                           │                 │                            │\n",
               "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n",
               "
\n" + ], + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ padding_mask (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ token_ids (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ gemma_backbone │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3584\u001b[0m) │ \u001b[38;5;34m9,241,705,984\u001b[0m │ padding_mask[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", + "│ (\u001b[38;5;33mGemmaBackbone\u001b[0m) │ │ │ token_ids[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────────┼───────────────────────────┼─────────────────┼────────────────────────────┤\n", + "│ token_embedding │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256000\u001b[0m) │ \u001b[38;5;34m917,504,000\u001b[0m │ gemma_backbone[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mReversibleEmbedding\u001b[0m) │ │ │ │\n", + "└───────────────────────────────┴───────────────────────────┴─────────────────┴────────────────────────────┘\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" - ], "text/html": [ "
 Total params: 9,241,705,984 (17.21 GB)\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" - ], "text/html": [ "
 Trainable params: 9,241,705,984 (17.21 GB)\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m9,241,705,984\u001b[0m (17.21 GB)\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/plain": [ - "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n" - ], "text/html": [ "
 Non-trainable params: 0 (0.00 B)\n",
               "
\n" + ], + "text/plain": [ + "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n" ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -283,15 +278,20 @@ }, { "cell_type": "markdown", - "source": [ - "### Define formatting helper functions" - ], "metadata": { "id": "CQ837Wrra_d3" - } + }, + "source": [ + "### Define formatting helper functions" + ] }, { "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "z6nQPPU7bFk6" + }, + "outputs": [], "source": [ "from IPython.display import Markdown\n", "import textwrap\n", @@ -306,21 +306,16 @@ "def to_markdown(text):\n", " text = text.replace('•', ' *')\n", " return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))" - ], - "metadata": { - "id": "z6nQPPU7bFk6" - }, - "execution_count": 4, - "outputs": [] + ] }, { "cell_type": "markdown", - "source": [ - "### Create a chat helper to manage the conversation state" - ], "metadata": { "id": "vro4q-yCbG-f" - } + }, + "source": [ + "### Create a chat helper to manage the conversation state" + ] }, { "cell_type": "code", @@ -401,35 +396,30 @@ }, { "cell_type": "markdown", - "source": [ - "### Chat with the model" - ], "metadata": { "id": "52Ell80sbRmy" - } + }, + "source": [ + "### Chat with the model" + ] }, { "cell_type": "code", "execution_count": 6, "metadata": { - "id": "shfCZDFPKghT", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 1000 - }, - "outputId": "935de9aa-c225-4063-f2b1-5c51759beb08" + "id": "shfCZDFPKghT" }, "outputs": [ { - "output_type": "execute_result", "data": { + "text/markdown": "🙋‍♂️
help me understand how to make coffee
🤖\n\n> ## Let's Brew Some Coffee! ☕️\n> \n> Making coffee can be as simple or complex as you like. Here's a breakdown of some popular methods, from beginner-friendly to more advanced:\n> \n> **1. The Quick & Easy: Instant Coffee**\n> \n> * **What you need:** Instant coffee granules, hot water\n> * **How to:** Simply add a spoonful of instant coffee to a mug, pour hot water over it, stir, and enjoy!\n> \n> **2. The Classic: Drip Coffee Maker**\n> \n> * **What you need:** Drip coffee maker, ground coffee, filter\n> * **How to:**\n> * Fill the water reservoir with fresh, cold water.\n> * Place a filter in the filter basket.\n> * Add the desired amount of ground coffee to the filter.\n> * Turn on the coffee maker and let it do its thing!\n> \n> **3. The French Press:**\n> \n> * **What you need:** French press, coarse ground coffee, hot water\n> * **How to:**\n> * Add coarse ground coffee to the French press.\n> * Pour hot water (just off the boil) over the coffee grounds.\n> * Stir gently and let it steep for 4 minutes.\n> * Slowly press the plunger down to separate the grounds from the coffee.\n> * Pour and enjoy!\n> \n> **4. The Pour Over:**\n> \n> * **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water\n> * **How to:**\n> * Place a filter in the cone and rinse it with hot water to remove any paper taste.\n> * Add medium-fine ground coffee to the filter.\n> * Slowly pour hot water over the grounds in a circular motion, ensuring all grounds are saturated.\n> * Let the coffee drip through into your cup.\n> \n> **5. The Espresso Machine:**\n> \n> * **What you need:** Espresso machine, finely ground coffee, tamper\n> * **How to:**\n> * Grind your coffee beans finely.\n> * Tamp the coffee grounds firmly into the portafilter.\n> * Lock the portafilter into the espresso machine.\n> * Brew your espresso shot!\n> \n> **Tips for Delicious Coffee:**\n> \n> * **Use fresh, quality beans:** The better the beans, the better the coffee.\n> * **Grind your beans right before brewing:** This preserves freshness and flavor.\n> * **Use filtered water:** Impurities in water can affect the taste of your coffee.\n> * **Experiment with different brewing methods:** Find what you like best!\n> * **Don't be afraid to adjust:** Play with the amount of coffee, water, and brewing time to find your perfect cup.\n> \n> \n> Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n\n", "text/plain": [ "" - ], - "text/markdown": "🙋‍♂️
help me understand how to make coffee
🤖\n\n> ## Let's Brew Some Coffee! ☕️\n> \n> Making coffee can be as simple or complex as you like. Here's a breakdown of some popular methods, from beginner-friendly to more advanced:\n> \n> **1. The Quick & Easy: Instant Coffee**\n> \n> * **What you need:** Instant coffee granules, hot water\n> * **How to:** Simply add a spoonful of instant coffee to a mug, pour hot water over it, stir, and enjoy!\n> \n> **2. The Classic: Drip Coffee Maker**\n> \n> * **What you need:** Drip coffee maker, ground coffee, filter\n> * **How to:**\n> * Fill the water reservoir with fresh, cold water.\n> * Place a filter in the filter basket.\n> * Add the desired amount of ground coffee to the filter.\n> * Turn on the coffee maker and let it do its thing!\n> \n> **3. The French Press:**\n> \n> * **What you need:** French press, coarse ground coffee, hot water\n> * **How to:**\n> * Add coarse ground coffee to the French press.\n> * Pour hot water (just off the boil) over the coffee grounds.\n> * Stir gently and let it steep for 4 minutes.\n> * Slowly press the plunger down to separate the grounds from the coffee.\n> * Pour and enjoy!\n> \n> **4. The Pour Over:**\n> \n> * **What you need:** Pour over cone, filter, medium-fine ground coffee, hot water\n> * **How to:**\n> * Place a filter in the cone and rinse it with hot water to remove any paper taste.\n> * Add medium-fine ground coffee to the filter.\n> * Slowly pour hot water over the grounds in a circular motion, ensuring all grounds are saturated.\n> * Let the coffee drip through into your cup.\n> \n> **5. The Espresso Machine:**\n> \n> * **What you need:** Espresso machine, finely ground coffee, tamper\n> * **How to:**\n> * Grind your coffee beans finely.\n> * Tamp the coffee grounds firmly into the portafilter.\n> * Lock the portafilter into the espresso machine.\n> * Brew your espresso shot!\n> \n> **Tips for Delicious Coffee:**\n> \n> * **Use fresh, quality beans:** The better the beans, the better the coffee.\n> * **Grind your beans right before brewing:** This preserves freshness and flavor.\n> * **Use filtered water:** Impurities in water can affect the taste of your coffee.\n> * **Experiment with different brewing methods:** Find what you like best!\n> * **Don't be afraid to adjust:** Play with the amount of coffee, water, and brewing time to find your perfect cup.\n> \n> \n> Let me know if you have any other questions or want to explore a specific brewing method in more detail!\n\n" + ] }, + "execution_count": 6, "metadata": {}, - "execution_count": 6 + "output_type": "execute_result" } ], "source": [ @@ -442,24 +432,19 @@ "cell_type": "code", "execution_count": 7, "metadata": { - "id": "bLxtlhjtLkWQ", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 784 - }, - "outputId": "db883963-943e-4519-eff1-f9ca7cdfe9ac" + "id": "bLxtlhjtLkWQ" }, "outputs": [ { - "output_type": "execute_result", "data": { + "text/markdown": "🙋‍♂️
what is the best coffee?
🤖\n\n> Ah, the eternal question! There's no single \"best\" coffee because taste is subjective. What one person finds delicious, another might find bitter or bland. \n> \n> It all depends on your personal preferences:\n> \n> **Consider these factors:**\n> \n> * **Roast Level:**\n> * **Light:** Bright acidity, delicate flavors, often fruity or floral.\n> * **Medium:** Balanced acidity and body, with more pronounced flavors.\n> * **Dark:** Bold, smoky, sometimes bittersweet, with less acidity.\n> * **Origin:** Different regions produce beans with unique flavor profiles:\n> * **Latin America:** Often chocolatey, nutty, with medium acidity.\n> * **Africa:** Known for bright acidity, fruity notes, and floral aromas.\n> * **Asia/Pacific:** Earthy, spicy, sometimes with chocolate or caramel notes.\n> * **Brewing Method:** The method you use can significantly impact the flavor.\n> \n> **Some Popular and Highly-Regarded Coffees:**\n> \n> * **Ethiopian Yirgacheffe:** Known for its floral, citrusy, and tea-like qualities.\n> * **Kenyan AA:** Bright acidity, black currant, and berry flavors.\n> * **Sumatran Mandheling:** Earthy, spicy, with low acidity.\n> * **Colombian Supremo:** Balanced, with chocolate and caramel notes.\n> \n> **My Recommendation:**\n> \n> * **Start exploring!** Try different roasts, origins, and brewing methods to discover what you enjoy most.\n> * **Talk to your local coffee shop:** Baristas are passionate about coffee and can offer great recommendations based on your preferences.\n> * **Don't be afraid to experiment:** The world of coffee is vast and exciting!\n> \n> \n> Happy brewing!\n\n", "text/plain": [ "" - ], - "text/markdown": "🙋‍♂️
what is the best coffee?
🤖\n\n> Ah, the eternal question! There's no single \"best\" coffee because taste is subjective. What one person finds delicious, another might find bitter or bland. \n> \n> It all depends on your personal preferences:\n> \n> **Consider these factors:**\n> \n> * **Roast Level:**\n> * **Light:** Bright acidity, delicate flavors, often fruity or floral.\n> * **Medium:** Balanced acidity and body, with more pronounced flavors.\n> * **Dark:** Bold, smoky, sometimes bittersweet, with less acidity.\n> * **Origin:** Different regions produce beans with unique flavor profiles:\n> * **Latin America:** Often chocolatey, nutty, with medium acidity.\n> * **Africa:** Known for bright acidity, fruity notes, and floral aromas.\n> * **Asia/Pacific:** Earthy, spicy, sometimes with chocolate or caramel notes.\n> * **Brewing Method:** The method you use can significantly impact the flavor.\n> \n> **Some Popular and Highly-Regarded Coffees:**\n> \n> * **Ethiopian Yirgacheffe:** Known for its floral, citrusy, and tea-like qualities.\n> * **Kenyan AA:** Bright acidity, black currant, and berry flavors.\n> * **Sumatran Mandheling:** Earthy, spicy, with low acidity.\n> * **Colombian Supremo:** Balanced, with chocolate and caramel notes.\n> \n> **My Recommendation:**\n> \n> * **Start exploring!** Try different roasts, origins, and brewing methods to discover what you enjoy most.\n> * **Talk to your local coffee shop:** Baristas are passionate about coffee and can offer great recommendations based on your preferences.\n> * **Don't be afraid to experiment:** The world of coffee is vast and exciting!\n> \n> \n> Happy brewing!\n\n" + ] }, + "execution_count": 7, "metadata": {}, - "execution_count": 7 + "output_type": "execute_result" } ], "source": [ @@ -471,24 +456,19 @@ "cell_type": "code", "execution_count": 8, "metadata": { - "id": "tfvgl4sC9g2p", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 733 - }, - "outputId": "69db12a1-425d-4989-a9b3-d9a58794f13e" + "id": "tfvgl4sC9g2p" }, "outputs": [ { - "output_type": "execute_result", "data": { + "text/markdown": "🙋‍♂️
what are similar drinks?
🤖\n\n> You're looking for drinks that share similarities with coffee! Here are some options, categorized by what aspect of coffee they resemble:\n> \n> **Similar Caffeine Kick:**\n> \n> * **Tea:** Comes in endless varieties, with varying caffeine levels. Black tea has the most caffeine, followed by green, white, and herbal teas.\n> * **Matcha:** A powdered green tea with a unique earthy flavor and a good amount of caffeine.\n> * **Yerba Mate:** A South American beverage with a slightly bitter, grassy flavor and a caffeine boost comparable to coffee.\n> \n> **Similar Rich, Roasted Flavor:**\n> \n> * **Chicory Coffee:** Made from roasted chicory root, it has a coffee-like flavor but is caffeine-free.\n> * **Roasted Barley Tea:** A caffeine-free option with a nutty, roasted flavor.\n> \n> **Similar Creamy, Indulgent Experience:**\n> \n> * **Hot Chocolate:** A classic comfort drink with a rich, chocolatey flavor.\n> * **Golden Milk:** A warming drink made with turmeric, ginger, cinnamon, and milk.\n> \n> **Similar Ritual and Experience:**\n> \n> * **Chai Tea Latte:** A spiced black tea latte with a creamy, comforting flavor.\n> * **London Fog:** A blend of Earl Grey tea, steamed milk, and vanilla syrup.\n> \n> **Beyond the Usual:**\n> \n> * **Kava:** A Polynesian drink made from the kava root, known for its relaxing and social effects.\n> * **Guayusa:** A South American tea with a smooth, slightly sweet flavor and a moderate caffeine boost.\n> \n> \n> Remember, taste is subjective! Explore these options and see what you enjoy most.\n\n", "text/plain": [ "" - ], - "text/markdown": "🙋‍♂️
what are similar drinks?
🤖\n\n> You're looking for drinks that share similarities with coffee! Here are some options, categorized by what aspect of coffee they resemble:\n> \n> **Similar Caffeine Kick:**\n> \n> * **Tea:** Comes in endless varieties, with varying caffeine levels. Black tea has the most caffeine, followed by green, white, and herbal teas.\n> * **Matcha:** A powdered green tea with a unique earthy flavor and a good amount of caffeine.\n> * **Yerba Mate:** A South American beverage with a slightly bitter, grassy flavor and a caffeine boost comparable to coffee.\n> \n> **Similar Rich, Roasted Flavor:**\n> \n> * **Chicory Coffee:** Made from roasted chicory root, it has a coffee-like flavor but is caffeine-free.\n> * **Roasted Barley Tea:** A caffeine-free option with a nutty, roasted flavor.\n> \n> **Similar Creamy, Indulgent Experience:**\n> \n> * **Hot Chocolate:** A classic comfort drink with a rich, chocolatey flavor.\n> * **Golden Milk:** A warming drink made with turmeric, ginger, cinnamon, and milk.\n> \n> **Similar Ritual and Experience:**\n> \n> * **Chai Tea Latte:** A spiced black tea latte with a creamy, comforting flavor.\n> * **London Fog:** A blend of Earl Grey tea, steamed milk, and vanilla syrup.\n> \n> **Beyond the Usual:**\n> \n> * **Kava:** A Polynesian drink made from the kava root, known for its relaxing and social effects.\n> * **Guayusa:** A South American tea with a smooth, slightly sweet flavor and a moderate caffeine boost.\n> \n> \n> Remember, taste is subjective! Explore these options and see what you enjoy most.\n\n" + ] }, + "execution_count": 8, "metadata": {}, - "execution_count": 8 + "output_type": "execute_result" } ], "source": [ @@ -498,27 +478,23 @@ }, { "cell_type": "markdown", - "source": [ - "Use the `get_history` method to see how all the context was retained by the Chat class." - ], "metadata": { "id": "Y85tod32c7lA" - } + }, + "source": [ + "Use the `get_history` method to see how all the context was retained by the Chat class." + ] }, { "cell_type": "code", "execution_count": 9, "metadata": { - "id": "P2GjAVybBez3", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "fba217c9-61de-4995-d337-9dca9570704c" + "id": "P2GjAVybBez3" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "user\n", "help me understand how to make coffee\n", @@ -659,9 +635,7 @@ "accelerator": "GPU", "colab": { "name": "Keras_Gemma_2_Quickstart_Chat.ipynb", - "toc_visible": true, - "provenance": [], - "gpuType": "A100" + "toc_visible": true }, "kernelspec": { "display_name": "Python 3", @@ -670,4 +644,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}