T’is the Time … for GenAI! : Aritra Roy Gosthipaty and Ritwik Raha

T’is the Time … for GenAI!
by: Aritra Roy Gosthipaty and Ritwik Raha
blow post content copied from  PyImageSearch
click here to view original post

Table of Contents

T’is the Time … for GenAI!

In this tutorial, you will learn how to start with Generative AI Studio inside Google Cloud.

To learn how to get started with the Generative AI studio inside Google Cloud Console, just keep reading.

T’is the Time … for GenAI!

Google and Generative AI

Google has been pushing generative AI since the beginning of this year. Their strategy has been to get as many people involved in creating more and more with their suite of products. Just look at the number of times Sundar Pichai used the terms “AI” and “Generative AI” in the Google IO 2023 keynote: Google I/O 2023 keynote in 14 seconds

What’s the Buzz?

AI’s global hype has reached a feverish pitch, especially for Generative AI. Now, Google brings the power of this technology directly to you, letting you experiment and understand the magic behind tools like Bard. Imagine tinkering with AI models, witnessing their fascinating responses as you adjust parameters. This democratization of AI empowers you to play, learn, and create, opening doors to unprecedented creativity and problem-solving. Join Google’s revolution and experience the future of AI!

What Is Generative AI?

Generative AI is the term coined for ML models that can create new content (e.g., text, images, and music) based on what it has previously learned. Think of it as an artist or composer, but instead of brushes or instruments, it uses code and data to create.

Now, you can explore this exciting world with Google’s Vertex AI-Generative AI Studio. These tools allow you to experiment with Bard’s power directly, tinkering with its parameters and seeing how it responds. It’s like having a personal AI playground, perfect for learning, creating, and pushing the boundaries of what’s possible.

These tools are available both through the Python software development kit (SDK) and the Google Cloud Console: https://cloud.google.com/generative-ai-studio

Getting Started with Vertex AI-Generative AI Studio’s User Interface

This guide provides instructions on using Generative AI Studio through the Google Cloud console without using the API or Python SDK.

Vertex AI-Generative AI Studio on Google Cloud

Vertex AI-Generative AI Studio is a cloud-based platform that allows users to create and experiment with generative AI models. The platform provides various tools and resources that make it easy to get started with generative AI, even if you don’t have a background in machine learning. Simply navigate to https://console.cloud.google.com/vertex-ai after signing up for your Google Cloud Account, you will be greeted with a page as shown in Figure 1.

Figure 1


There are two ways to access the Language offerings (demonstrated in Figure 2) from Generative AI Studio on Google Cloud:

  • Click the OPEN button at the bottom of the Language box on the Generative AI Studio Overview page.
  • Click Language from the menu on the left under the Generative AI Studio tab.
Figure 2

Upon clicking, the following page will be presented (Figure 3).

Language page of Generative AI
Figure 3

Get Started

Create Prompt

Create Prompt lets you design prompts for tasks relevant to your business use case, including code generation. To get started, click on the + TEXT PROMPT button, as shown in Figure 4.

Create Prompt
Figure 4

Upon clicking, you will be redirected to the following page (Figure 5). You can hover or click on the ? buttons to find out more about each field and parameter. Also, the following image has been annotated to provide a quick overview of the interface.

Figure 5

You can feed your desired input text (e.g., a question) to the model. The model will then respond based on how you structured your prompt. The process of figuring out and designing the best input text (prompt) to get the desired response back from the model is called Prompt Design.

Currently, there is no best way to design the prompts yet. Generally, there are 3 methods that you can use to shape the model’s response in a way that you desire.

  • Zero-Shot Prompting: This is a method where the LLM is given no additional data on the specific task that it is being asked to perform. Instead, it is only given a prompt that describes the task. For example, if you want the LLM to answer a question, you just prompt, “What is prompt design?”
  • One-Shot Prompting: This is a method where the LLM is given a single example of the task that it is being asked to perform. For example, if you want the LLM to write a poem, give it a single example poem.
  • Few-Shot Prompting: This is a method where the LLM is given a small number of examples of the task that it is being asked to perform. For example, if you want the LLM to write a news article, you might give it a few news articles to read.

You may also notice the FREE-FORM and STRUCTURED tabs in the image above. Those are the two modes that you can use while designing your prompt.

  • FREE-FORM: This mode provides a free and easy approach to designing your prompt. It is suitable for small and experimental prompts with no additional examples. You will be using this to explore zero-shot prompting.
  • STRUCTURED: This mode provides an easy-to-use template approach to prompt design. Context and multiple examples can be added to the prompt in this mode. This is especially useful for one-shot and few-shot prompting methods, which we will explore later.


We will try zero-shot prompting in the FREE-FORM mode, as shown in Figure 6. To start,

  • copy “What is a prompt gallery?” over to the prompt input field
  • click on the SUBMIT button on the right side of the page

The model will respond to a comprehensive definition of the term prompt gallery.

Figure 6

Here are a few introductory exercises to get started.

  • Set the Token limit parameter to 1
  • Set the Token limit parameter to 1024
  • Set the Temperature parameter to 0.5
  • Set the Temperature parameter to 1.0

Inspect how the responses change to change the parameters.


With STRUCTURED mode, you can design prompts in more organized ways. You can also provide Context and Examples in their respective input fields. This is a good opportunity to learn one-shot and few-shot prompting.

In this section, you will ask the model to complete a sentence. Go back to the text prompt window and

  • click on the STRUCTURED tab if you have not
  • copy “the colour of the sky is” in the INPUT field
  • click on the SUBMIT button on the right side of the page

You would see a similar result, as shown in Figure 7.

Figure 7

Instead of completing the sentence, the model provided a full sentence as a response, which is not what we wanted. You can influence the model’s response with one-shot prompting, as shown in Figure 8. This time around, you will add an example for the model to base its output on.

Under the Examples field,

  • copy “the colour of the grass is” to the INPUT field
  • copy “green” to the OUTPUT field
  • click on the SUBMIT button on the right side of the page.

Now, the model will respond by completing the sentence instead. The response should be something similar to this.

Figure 8

Congrats! You have successfully influenced the way the model produces responses.

Vertex AI with Python SDK

In this section, however, you will learn how to use the Vertex AI API with the Python SDK and explore its various parameters.

A word of caution: do remember to enable your Vertex AI API (as shown in Figure 9) before starting with the following notebook.

Figure 9

By the end of the notebook, you will understand various nuances of generative model parameters like temperature, top_k, top_p, and how each parameter affects the results.

The steps performed include:

  • Installing the Python SDK
  • Using Vertex AI API
    • Text generation model with text-bison@001
      • Understanding model parameters (temperature, max_output_token, top_k, top_p)
!pip install google-cloud-aiplatform --upgrade
from google.colab import auth as google_auth
# Importing necessary modules from the vertexai library.
import vertexai
from vertexai.preview.language_models import TextGenerationModel
# Initialize the Vertex AI environment with your project ID and location.
# Choose the correct location for accessing the necessary resources.
vertexai.init(project="ml-workflows-17", location="us-central1")
# Define parameters for the text generation model.
parameters = {
    "max_output_tokens": 1024, # This sets the maximum length of the generated text.
    "temperature": 0.9,       # Adjusts randomness in text generation. Higher values make the text less predictable.
    "top_p": 0.8,             # This parameter helps in narrowing down word choices based on probability.
    "top_k": 40               # Limits the choice of next word to the top 40 most probable options.
# Load a pre-trained model for text generation.
model = TextGenerationModel.from_pretrained("text-bison-32k")
# Generate text based on the provided prompt and parameters.
response = model.predict(
    "Give me 10 ideas for a Christmas party",
# Output the generated text.
print(f"Response from Model: {response.text}")

The above script demonstrates how to use Google Cloud’s AI Platform (now Vertex AI) for text generation using Python. Let’s break down the code into its components:

  • Setup and Authentication
    • Line 1: Upgrades and installs the google-cloud-aiplatform library, which provides tools for interacting with Google Cloud’s AI Platform services.
    • Lines 2 and 3: These lines import and use the Google Colab authentication module to authenticate the user. This step is crucial for accessing Google Cloud resources from a Colab environment.
  • Importing Libraries and Initialization
    • Lines 5-10: The script imports necessary modules from the Vertex AI library, specifically for language model tasks. vertexai.init initializes the Vertex AI environment with a specified project ID and location ("ml-workflows-17" and "us-central1", respectively), which are important for billing and resource allocation.
  • Model Configuration
    • Lines 13-18: Here, parameters for text generation are defined. max_output_tokens sets the maximum length of generated text. temperature controls the randomness of the output (higher values make outputs more unpredictable). top_p and top_k are parameters for controlling the word choice based on probability, helping in fine-tuning the output.
  • Model Loading and Text Generation
    • Line 21: Loads a pre-trained text generation model named "text-bison-32k" from Vertex AI’s model repository.
    • Lines 24-27: The script generates text based on a given prompt (“Give me 10 ideas for a Christmas party”) using the defined parameters. The predict method of the TextGenerationModel is used for this purpose.
  • Output
    • Line 30: Finally, the generated text is printed out to the console.
Response from Model:  1. **Secret Santa:** This is a classic Christmas party game that is always a lot of fun. Each person draws a name from a hat, and then they are responsible for buying a gift for that person. The gifts are then exchanged on Christmas Eve or Christmas Day.
2. **White Elephant Gift Exchange:** This is another fun gift exchange game that is perfect for a Christmas party. Each person brings a wrapped gift, and then the gifts are exchanged in a random order. The person who ends up with the last gift gets to choose another gift to keep.
3. **Christmas Ornament Exchange:** This is a great way to get everyone in the holiday spirit. Each person brings a handmade or store-bought Christmas ornament, and then the ornaments are exchanged. This is a great way to add some festive cheer to your home and to remember your friends and family during the holidays.
4. **Christmas Cookie Exchange:** This is a delicious way to celebrate the holidays. Each person brings a batch of their favorite Christmas cookies, and then the cookies are exchanged. This is a great way to try new recipes and to share your favorite holiday treats with your friends and family.
5. **Christmas Karaoke:** This is a fun and festive way to get everyone involved in the party. Put together a playlist of your favorite Christmas songs, and then let everyone take turns singing along. This is a great way to get everyone in the holiday spirit and to have some fun.
6. **Christmas Movie Marathon:** This is a great way to relax and enjoy the holidays. Pick a few of your favorite Christmas movies, and then curl up on the couch with some popcorn and hot chocolate. This is a great way to spend a cozy winter evening with your friends and family.
7. **Christmas Craft Party:** This is a great way to get creative and to make some festive holiday decorations. Set up a craft table with supplies like construction paper, markers, glue, and glitter. Then, let everyone make their own Christmas cards, ornaments, and other decorations. This is a great way to get everyone in the holiday spirit and to have some fun.
8. **Christmas Scavenger Hunt:** This is a fun and active way to celebrate the holidays. Hide some Christmas-themed items around your house or yard, and then give everyone a list of the items to find. The first person to find all of the items wins a prize. This is a great way to get everyone moving and to have some fun.
9. **Christmas Party Games:** There are many different Christmas party games that you can play. Some popular games include Christmas trivia, Christmas charades, and Christmas Pictionary. These games are a great way to get everyone involved in the party and to have some fun.
10. **Christmas Dinner:** No Christmas party is complete without a delicious Christmas dinner. Serve some of your favorite holiday dishes, such as turkey, ham, stuffing, and mashed potatoes. This is a great way to end the party and to celebrate the holidays with your friends and family.

This script shows us how to interact with Google Cloud’s Vertex AI services for advanced tasks like text generation, showcasing the ease of leveraging cloud-based AI models for creative and practical applications.

What's next? We recommend PyImageSearch University.

Course information:
83 total classes • 113+ hours of on-demand code walkthrough videos • Last updated: December 2023
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled

I strongly believe that if you had the right teacher you could master computer vision and deep learning.

Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?

That’s not the case.

All you need to master computer vision and deep learning is for someone to explain things to you in simple, intuitive terms. And that’s exactly what I do. My mission is to change education and how complex Artificial Intelligence topics are taught.

If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to successfully and confidently apply computer vision to your work, research, and projects. Join me in computer vision mastery.

Inside PyImageSearch University you'll find:

  • 83 courses on essential computer vision, deep learning, and OpenCV topics
  • 83 Certificates of Completion
  • 113+ hours of on-demand video
  • Brand new courses released regularly, ensuring you can keep up with state-of-the-art techniques
  • Pre-configured Jupyter Notebooks in Google Colab
  • ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
  • ✓ Access to centralized code repos for all 532+ tutorials on PyImageSearch
  • Easy one-click downloads for code, datasets, pre-trained models, etc.
  • Access on mobile, laptop, desktop, etc.

Click here to join PyImageSearch University


Generative AI is no longer just hype — it’s a powerful tool accessible to everyone. Now, you can play and learn with Google Cloud’s Vertex AI-Generative AI Studio, experimenting with the model’s capabilities and discovering its potential for creative expression, problem-solving, and much more.

Many industries are actually training professionals to get started with these tools and leverage their powers for unique use cases pertaining to their industry. Imagine having transparent billing, a helpful UI, and an easy-to-understand Python SDK to get started with the most in-demand and sought-after models currently available.

Get ready to unlock the future with exciting multimodal models on the horizon (sshhh, Gemini is already here!). Share your cool Generative AI use cases with us at @pyimagesearch.

Citation Information

A. R. Gosthipaty and R. Raha. “T’is the Time … for GenAI!,” PyImageSearch, P. Chugh, S. Huot, and K. Kidriavsteva, eds., 2023, https://pyimg.co/qmxd9

  author = {Aritra Roy Gosthipaty and Ritwik Raha},
  title = {T'is the Time ... for {GenAI}!},
  booktitle = {PyImageSearch},
  editor = {Puneet Chugh and Susan Huot and Kseniia Kidriavsteva},
  year = {2023},
  url = {https://pyimg.co/qmxd9},

Featured Image

Unleash the potential of computer vision with Roboflow - Free!

  • Step into the realm of the future by signing up or logging into your Roboflow account. Unlock a wealth of innovative dataset libraries and revolutionize your computer vision operations.
  • Jumpstart your journey by choosing from our broad array of datasets, or benefit from PyimageSearch’s comprehensive library, crafted to cater to a wide range of requirements.
  • Transfer your data to Roboflow in any of the 40+ compatible formats. Leverage cutting-edge model architectures for training, and deploy seamlessly across diverse platforms, including API, NVIDIA, browser, iOS, and beyond. Integrate our platform effortlessly with your applications or your favorite third-party tools.
  • Equip yourself with the ability to train a potent computer vision model in a mere afternoon. With a few images, you can import data from any source via API, annotate images using our superior cloud-hosted tool, kickstart model training with a single click, and deploy the model via a hosted API endpoint. Tailor your process by opting for a code-centric approach, leveraging our intuitive, cloud-based UI, or combining both to fit your unique needs.
  • Embark on your journey today with absolutely no credit card required. Step into the future with Roboflow.

Join Roboflow Now

Join the PyImageSearch Newsletter and Grab My FREE 17-page Resource Guide PDF

Enter your email address below to join the PyImageSearch Newsletter and download my FREE 17-page Resource Guide PDF on Computer Vision, OpenCV, and Deep Learning.

The post T’is the Time … for GenAI! appeared first on PyImageSearch.

December 25, 2023 at 07:30PM
Click here for more details...

The original post is available in PyImageSearch by Aritra Roy Gosthipaty and Ritwik Raha
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.