diff --git a/examples/prompting/Zero_shot_prompting.ipynb b/examples/prompting/Zero_shot_prompting.ipynb new file mode 100644 index 000000000..b474461e5 --- /dev/null +++ b/examples/prompting/Zero_shot_prompting.ipynb @@ -0,0 +1,216 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Gemini API: Zero-shot prompting" + ], + "metadata": { + "id": "sP8PQnz1QrcF" + } + }, + { + "cell_type": "markdown", + "source": [ + "\n", + " \n", + "
\n", + " Run in Google Colab\n", + "
" + ], + "metadata": { + "id": "bxGr_x3MRA0z" + } + }, + { + "cell_type": "markdown", + "source": [ + "Because of the vast knowledge of Gemini 1.5 Pro model, it can answer many queries without any additional context. Zero-shot prompting is useful for situations when our queries are not complicated and do not require a specific schema." + ], + "metadata": { + "id": "ysy--KfNRrCq" + } + }, + { + "cell_type": "code", + "source": [ + "!pip install -U -q google-generativeai" + ], + "metadata": { + "id": "Ne-3gnXqR0hI" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "EconMHePQHGw" + }, + "outputs": [], + "source": [ + "import google.generativeai as genai\n", + "\n", + "from IPython.display import Markdown" + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Configure your API key\n", + "\n", + "To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key, or you're not sure how to create a Colab Secret, see [Authentication](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb) for an example." + ], + "metadata": { + "id": "eomJzCa6lb90" + } + }, + { + "cell_type": "code", + "source": [ + "from google.colab import userdata\n", + "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n", + "\n", + "genai.configure(api_key=GOOGLE_API_KEY)" + ], + "metadata": { + "id": "v-JZzORUpVR2" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Examples\n", + "\n", + "Here are a few examples with zero-shot prompting. Note that in each of these examples, we just provide the task, with zero examples." + ], + "metadata": { + "id": "GLh4oXd1VXTw" + } + }, + { + "cell_type": "code", + "source": [ + "model = genai.GenerativeModel('gemini-pro', generation_config={\"temperature\": 0})" + ], + "metadata": { + "id": "Ym4w9z3iWHlT" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "prompt = \"\"\"\n", + "Sort following animals from biggest to smallest:\n", + "fish, elephant, dog\n", + "\"\"\"\n", + "Markdown(model.generate_content(prompt).text)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 97 + }, + "id": "J580DkQPVYYp", + "outputId": "0435e167-4cad-4c9a-ab60-369031d54dbd" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ], + "text/markdown": "1. Elephant\n2. Dog\n3. Fish" + }, + "metadata": {}, + "execution_count": 5 + } + ] + }, + { + "cell_type": "code", + "source": [ + "prompt = \"\"\"\n", + "classify sentiment of review as positive, negative or neutral:\n", + "I go to this restaurant every week, i love it so much.\n", + "\"\"\"\n", + "Markdown(model.generate_content(prompt).text)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 46 + }, + "id": "K1we-_q4VZ0M", + "outputId": "3e8d7583-fe5b-4ca9-9b4c-4756ae80e86a" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ], + "text/markdown": "positive" + }, + "metadata": {}, + "execution_count": 6 + } + ] + }, + { + "cell_type": "code", + "source": [ + "prompt = \"\"\"\n", + "extract capital cities from the text:\n", + "During the summer I visited many countries in Europe. First I visited Italy, specifically Sicily and Rome. Then I visited Cologne in Germany and the trip ended in Berlin.\n", + "\"\"\"\n", + "Markdown(model.generate_content(prompt).text)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 64 + }, + "id": "4NF2OmfPVa4l", + "outputId": "dbf599f6-68d7-4c00-86ce-5267dcf13d57" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ], + "text/markdown": "- Rome\n- Berlin" + }, + "metadata": {}, + "execution_count": 7 + } + ] + } + ] +} \ No newline at end of file