Text Generation with Google Gemini

Nov 14 2024 · Python 3.12, Google Gemini, JupyterLab, Visual Studio Code

Lesson 01: Introduction to Google Gemini

Demo: Creating Prompts in AI Studio

Episode complete

Play next episode

Next
Transcript

First, navigate to the AI Studio interface. At the bottom, type the prompt “What are the two best features of AI studio?”, click Run and wait for the response to come up. You’ll notice this response is generated using a default selected model.

Now, come up and edit this prompt. Change the prompt to “What are the three best features of AI studio?” and stop editing. Copy this new prompt and paste it below here. Click Run and the response is generated once again. Here, you’ll see now, these arrows keys that can move up or down. You can click Save to save this prompt. Give this prompt a name Top Features of AI Studio. Click Save, this prompt is saved under this library here for you to refer at a later point.

Now, look at the Run settings in the right pane. Reset them to their defaults with a single click Reset. There is a drop-down to select a model. A counter displays how many tokens the current conversation has used. There are many options and parameters you can adjust on this side panel.

Temperature adjusts how creative the response is. The lower value gives more concise responses and a higher value gives more abstract responses.

Come down and you’ll see Code Execution. Code Execution executes code written in popular programming languages like Python.

Next, click on Edit Safety Settings. Increase the Hate Category to Block Most. Now, enter the prompt “All meanie greenie hates purple durples”. Press Command-Enter to run. You’ll see this prompt is now blocked as a low risk for hate and harassment speech.

Now, in the right pane, take a look at Advanced settings. You’ll see some more parameters here. Top P is a similar parameter to Temperature.

Above the conversation window, there is a System Instructions section. You can specify details about the AI’s role or persona. Type “You are an alien from another planet who uses lots of emojis” in this section. Now, in the prompt, type, “Tell me about yourself”. Click Run and observe the generated response. The response now has a new persona and lots of emojis. System instructions are a powerful way to customize your conversation with the model.

Next, tune a model. Select New Tuned Model from the left. Click Allow drive access if it prompts you to do so. Then, click Create a Structured prompt. In the Input column, type 5 and type 50 in the OUTPUT column. Come to the next row and type 3 in input and 30 in output. The model is going to detect the pattern of multiplying the input number by 10.

Now, Test your prompt, in the INPUT column, type 1. Click Generate response in the OUTPUT column. The model generates a response of 10 and explains its underlying pattern.

You’ve tuned a model based on a pattern. Next, you’ll tune a model based on a CSV file. First, create data using an AI prompt. Type a new prompt “Create 30 csv records with a random birth date and a corresponding zodiac sign as its emoji”. The generated response is a comma-separated value. The model also gives an additional note. Copy the rendered text and paste it in a text editor. Create a new document, paste the data and remove the details that you don’t want. Save this file as a csv.

On my Mac, I again need to rename this file as a csv file only. Open Finder and right-click on this file. Click rename and make sure that the .rtf extension is removed and your file is only a csv file now.

For the model to read these columns properly on my Mac, I again need to open this file using Numbers and then export it to CSV again. Click File, Export as a CSV file using UTF-8.

Now that you have the data, you can proceed with tuning the model using CSV. Back in AI Studio, click New tuned model on the left, then click Import. Under the Upload tab, you can drag and drop the CSV file. It takes a while for the data columns to come up. Make sure you Use first row as headers. Select this option, and then under Birth Date, assign this as a New Input Column. Zodiac will be your New Output Column. Import this data and look at the Data Preview.

Come down and click Tune. This takes a while.

When the model finishes tuning, select it from the library and then click Use in Chat. Enter any birth date “2000-06-01” in the prompt. Press Command-Enter. Your tuned model responds with the zodiac emoji.

Once you’ve engineered a prompt to your satisfaction, you can use the Get Code in the top-right to get the code for the prompt. You can select different programming languages like Python, Go or Swift.

Now, look at the left panel.

  • Open Prompt gallery. You’ll find lots of pre-engineered prompts.
  • The developer forum and the developer documentation links come in handy for more information.

You’ve used AI Studio to tune models, to create prompts and adjust parameters and settings. You can also save prompts and get an idea of how many tokens they’ll use. AI Studio is a powerful tool in our AI arena.

See forum comments
Cinema mode Download course materials from Github
Previous: AI Studio & Authoring Prompts Next: Discovering Google Colab