-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54fb451
commit 50676b9
Showing
1 changed file
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [ | ||
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n", | ||
" <td>\n", | ||
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/google-gemini/cookbook/blob/main/quickstarts/examples/prompting/Zero_shot_prompting.ipynb\"><img src = \"https://www.tensorflow.org/images/colab_logo_32px.png\"/>Run in Google Colab</a>\n", | ||
" </td>\n", | ||
"</table>" | ||
], | ||
"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": [ | ||
"<IPython.core.display.Markdown object>" | ||
], | ||
"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": [ | ||
"<IPython.core.display.Markdown object>" | ||
], | ||
"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": [ | ||
"<IPython.core.display.Markdown object>" | ||
], | ||
"text/markdown": "- Rome\n- Berlin" | ||
}, | ||
"metadata": {}, | ||
"execution_count": 7 | ||
} | ||
] | ||
} | ||
] | ||
} |