Saturday, November 16, 2024
Google search engine
HomeData Modelling & AIPaLM AI | Google’s Home-Grown Generative AI

PaLM AI | Google’s Home-Grown Generative AI

Introduction

Ever since the launch of Generative AI models like the GPT (Generative Pre-trained Transformers) models by OpenAI, especially ChatGPT, Google has always been on the verge to create a launch an AI Model similar to that. Though Google was the one that first brought up the topic of Transformers through the BERT Model to the world, through its Attention is All You Need paper, it failed to do so, to create a Large Language Model equally powerful and efficient like the ones developed by OpenAI. Bard AI which was first introduced by Google didn’t seem to bring that much attention. Recently Google released API access to PaLM (Pathways Language Model), which is behind the Bard AI. In this Guide, we will go through how to start with PaLM API.

Learning Objectives

  • To learn how to work with Pathways Language Model
  • To understand the key features PaLM provides
  • To create applications with PaLM 2
  • To leverage MakerSuite for Quick Prototyping of Large Language Models
  • To understand how to work with PaLM API

This article was published as a part of the Data Science Blogathon.

What is PaLM?

PaLM which stands for Pathways Language Model, is one of Google’s homegrown Large Language Models. This was first introduced in April 2022. Recently a few months ago, Google announced the next version of this, i.e. PaLM 2. Google claims that PaLM is better when coming to multilingual capabilities and is power efficient if we compare to the previous Version.

PaLM 2 was not trained in the English language, rather, it was more than a mixture of a hundred languages, which even include programming languages and mathematics too. All this was possible without dropping the English language understanding performance. Overall PaLM 2/ the current version of PaLM from Google will excel at many tasking including generating codes, understanding different languages, reasoning skills, and much more.

Like OpenAI’s GPT model comes in different types like Davinci, Ada, etc, the PaLM 2 comes 4 different sizes having the names Gecko, Otter, Bison, and Unicorn (smallest to largest). The Gecko size of PaLM 2 especially is capable of running in even mobile devices, thus opening pathways for Mobile App Developers to consider working with this Large Language Model in their mobile applications.

How are Bard and PaLM Different?

Bard is an experimental conversational AI by Google that is powered by LaMDA(Language Model for Dialogue Applications), which is a conversational AI model built on top of Transformers, use it for creating dialogue-based applications. The LaMDA model consists of 137 Billion Parameters. Bard in massive different types of datasets consisting of both textual and code data for creating engaging dialogues.

PaLM (Pathways Language Model) powered Bard later. Currently, the newly created PaLM 2 is powering Bard. PaLM 2 has been extensively trained on multi-lingual and different language types, making it a great booster for the already existing Bard. This is even letting Bard extend its capabilities from just dialogue conversation to now even generating workable codes in the programming field, extending its knowledge to more than 20 different programming languages.

PaLM 2 powers Bard and integrates it with Google Services like Gmail, Google Docs, and Google Sheets, enabling Bard to send information directly to these services. The recent announcements have even said that it has been integrating with many other third-party applications like the Adobe Fire Fly Image Generator and even Adobe Express in the near future.

MakerSuite – Access to PaLM API

To access or test Google’s new home-grown PaLM 2, one needs to have access to the PaLM API. The PaLM API lets us interact with different PaLM 2 models, similar to how OpenAI API is present to interact with the GPT models. There are two ways to get access to Google’s PaLM API. One is through the Vertex AI. PaLM API is readily available in the Vertex AI in the Google Cloud. But not all may have a GCP account to access this API. So we will be taking the second route, which is through MakerSuite.

Google’s MakerSuite provides a visual-based way to interact with the PaLM API. It’s a browser-based IDE to test and prototype Generative AI models. Simply put, it’s the quickest way to start experimenting with generative AI ideas. The MakerSuite, allows us to work with Generative Models directly through its easy UI or if we want, we can even generate an API Token so that we can leverage the power of PaLM 2 through the API in the code. In this guide, we will explore both ways: start within the MakerSuite web-based UI itself and working with the PaLM API through Python code.

Login to Start Your Journey on MarkerSuite

To get started, click here to redirect to MakerSuite, or you can simply search for it on Google. Then sign up with your Gmail account. Then you will see the following on your screen.

"

Fill up everything and finally click on the “Join with my Google account” to join the waitlist to access the PaLM API and the MakerSuite IDE. You will then receive an email within 7 days stating that you have received access to MakerSuite IDE and the PaLM API. After getting access to MakerSuite, open the website with the registered Email ID. The home page of MakerSuite will look like

"

As we can see, on the home page, we are able to see 3 types of Prompts. MakerSuite allows us to select 3 types of Prompts namely Text Prompt, Data Prompt, and Chat Prompt, each having its own importance, which allow us to interest with the PaLM 2 API visually. For code-based interactions, you can find the “Create an API Key” button below, which lets us create an application to work within our code to access the PaLM 2 models. We will be covering the Text Prompt and Data Prompt types of Prompts and even learn how to leverage the PaLM API in the code.

Rapid Prototyping with MakerSuite

As we have seen, there are three different types of Prompts to work in the MakerSuite, we will first start off with the Text Prompt. In the MakerSuite dashboard, select the Text Prompt.

"

Write Your Prompt

The white space below the “Write your prompt”, is where we will be writing the Prompt, which then will be interpreted by the PaLM 2 model. We can write any Prompt like summarising a paragraph, asking the Generative AI to create a poem, solving any logical reasoning questions, whatever you name it. Let’s ask the model to generate a Python Code to calculate Fibonacci Series for a given length “n” and then click on Run.

"

Python Code for Given Query

The Generative AI has provided us with the Python Code for the given query. It can be seen in the highlighted text in the Pic. The model did indeed provide a working code for the query asked. Below we can see the “Text Bison” and the “Text Preview”. The “Text preview” lets us see the Prompt that we have provided to the model. Let’s observe by clicking on it.

"

We also observe that the max token limit that can be sent is 8196, which is comparable to the GPT models. Now what is the “Text Bison”? If we remember clearly, a while ago I stated that PaLM 2 comes in different sizes (Gecko, Otter, Bison, and Unicon). So the model being used here is the Text Bison Model. Let’s click on it to see that does it display

"

So it contains information about the model being used. At present MakerSuite only presents us with the Text Bison Model. Temperature increases the variability/creativity within the model, though the high-temperature value can somes cause the model to hallucinate thus making up random stuff. The Max output is currently set to 1, hence we get a single answer to the query asked. However, we can increase this, enabling the model to generate multiple answers to a single query. The safety settings allow us to tweak the model by telling it to either block a few or most of the harmful content which can include toxic, derogatory, violent content, etc.

Insert Test Input

The advanced settings let us configure the output length in tokens, the Top K, and the Top P parameters. So the Text Prompt from MakerSuite lets us write any basic Prompt. There is another thing called “Insert test input”. Let’s try that out

"

Here in the Prompt section, I have set a context for the model, saying that any question we give to the Generative AI, it must take into consideration that its output must be generated as if the Large Language Model is trying to explain it to a 5-year-old kid. So the Prompt we have written is “Explain the below questions as if explaining it to a 5-year-old”. Then we click on the ”Insert test input”. We see that a green box named input has appeared in the white space. At the same time, above the Run button “Test your prompt” has appeared. Let’s expand it

"
"

When we expand the “Test your prompt”, we see a table with two columns INPUT and OUTPUT. The default of INPUT is input, which we have changed to query here. So whatever query we type under the INPUT column, gets populated in place of “query” in the white space in the Prompt Section. In the second pic, we have given the query as Machine Learning, which got replaced instead of the “query” in the Prompt space. After we type the query and hit the Run button, the output gets generated in the OUTPUT section, which we can see below. The output generated seems reasonably good because it tried to explain Machine Learning in a simple way so that even a 5-year-old can understand.

Introduction to Data Prompts – MakerSuite

In this section, we will work on the Data Prompts provided by MakerSuite. For this head to the MakerSuite homepage and click on the Data Prompts. Then you will be presented with the following

"

Input Column

As the name goes, in the Data Prompts, we need to provide example data to the model, so by learning from them, the model will be able to generate answers to the new questions. Each example contains an input in the INPUT column, that represents the user’s query and the expected output to the user’s query is present in the OUTPUT column. Like this, we are able to provide a few examples to the model. The model will then learn from these examples to generate a new output for the new query. Let’s try this out

"

Here in the INPUT column, we provided the names of two famous cricketers, Virat Kohli, and David Warner. In the OUTPUT column, we provided the respective countries for which they play. Now to test the Text Bison model, the INPUT we have given is Root, a famous cricketer who plays for England. So we expect the OUTPUT to be England. Let’s run this and test it out.

"

As expected, the LLM has generated the right response to the test query. The model understood that the data given to it is the names of the cricketers and the output it must generate is the country for which they play. If needed, we can even provide a context before the examples. The thing we have done here is basically called Few Shot Learning, where in the Prompt section, we give a few examples to the Large Language Model and expect it to generate similar output when a new query is given. So this is how Data Prompts work in MakerSuite, it sure is a feature that differentiates it from ChatGPT

Interacting with PaLM 2 Using PaLM API

To interact with PaLM 2 through code, we need to have the PaLM API Key. This can be generated through the MakerSuite itself. For this, we need to head to the MakerSuite homepage. On the homepage, below the 3 types of Prompts, we see an option to get the API Key. Click on it to generate a new API Key

"
"

Install Necessary Libraries

Click “Create API key in new project” to generate a new API Key. After it gets generated we can find the key below.  Click on the API key to copy the newly Generated API key. Now let’s get started by installing the necessary libraries. We will be working with Google Colab for this demo.

$ !pip install google-generativeai

This will download Google’s Generative AI library which we will be working with to interact with PaLM 2. Firstly we will start by assigning the API Key to the environment variable, which can be done as follows

import google.generativeai as palm
import os


os.environ['API_KEY']= 'Your API Key'
palm.configure(api_key=os.environ['API_KEY'])

We first provide the API key to the os.environ[‘API_KEY’], then pass this API to the palm.configure() object. Till now, if the code runs successfully, then we are good to start working with PaLM 2. Let’s try the text generation part of the PaLM AI, which uses the Text-Bison model to answer the queries.

Code

The code will be:

response = palm.generate_text(prompt="Tell me a joke")
print(response.result)
"

The PaLM 2’s Text-Bison model is indeed working flawlessly. Let’s expand this a bit by providing some more parameters to the model, so to understand what more can be added to the model to more accurate/right results.

prompt = """
You are an expert translator. You can translate any language to any language.

Translate the following from English to Hindi:


How are you?.
"""


completion = palm.generate_text(
    model='models/text-bison-001',
    prompt=prompt,
    temperature=0,
    max_output_tokens=800,
)


print(completion.result)
"

Here we provided a Prompt to the model. In the Prompt, we set a context telling that, the model is an expert translator that can translate any language to any language. And then we provide a query within the Prompt itself to translate a sentence from English to Hindi. Then we specify the model we are going to work with and it will be the Text Bison model because we are generating text here. Next, the temperature is set to 0 for zero variability and the max output tokens are set to 800. We can see in the output, that model has succeeded in the exact translation of the sentence given from English to Hindi.

This is an example of the text generation part of the PaLM AI. There is even a chat-type Prompt that you can look into their documentation to understand how it works. It is very much similar to what we have seen here. In the Chat Prompt, you need to provide examples of chat history between the user and AI, so the AI can learn how to converse with the user and use this knowledge to chat seamlessly with the user.

Applications and Use-Cases

Mobile Applications

PaLM 2 is available in 4 different sizes. The smallest size of PaLM 2, known as the Gecko, was designed to be integrated into mobile applications. This includes applications in Augmented Reality and Virtual Reality, where this Generative AI can be used to create realistic-looking landscapes. Additionally, it can be applied to various types of Chatbots/Assistants, spanning from Support Chatbots to Personal Chatbots.

Duet AI for Google Cloud

Duet AI is an always-on collaborative Generative AI powered by PaLM 2 developed by Google for the Google Cloud Platform. Building, securing, and scaling applications on Google Cloud has been time-consuming. Now with Duet, the process will become very much smooth for the Cloud Developers. Duet will analyze what are you doing in the cloud, and based on that it will assist you and thus speed up your development process in the cloud. Duet AI will adjust itself to suit any skill type, be it a complete beginner or a master of the cloud.

Analyzing Medical Images / Medical Questions-Answering

Med-PaLM a Large Language Model based on PaLM, is capable of analyzing complex medical images and even giving high qualitative answers to medical questions. Med-PaLM when tested on US Doctor Licensing exams, it reached 67% (where the average percentage was 60% for humans). Thus Med-PaLM can be fine-tuned and leveraging it for analyzing medical images from X-Rays to Breast Cancer, where the Generative AI not only tells if the patient has an illness or not, but even tells what may have caused this, what can happen in the future, and how to take care of it. Med-PaLM can be leveraged for answering Clinical Questions as well.

iCAD has partnered with Google to further develop Med-PaLM mainly in analyzing breast cancer to make it workable in a clinical setting. Google has also partnered with Northwestern Medicine to improve the AI capabilities in the health space, so to make it detect high-risk conditions and at the same time reduce the screening/diagnosis time.

PaLM Role in Google Applications

Google plans to integrate PaLM 2 with Gmail to handle tasks such as summarization and rewriting emails in a formal tone, among other functions. Additionally, in Google Docs, PaLM 2 will be utilized for brainstorming, proofreading, and rewriting purposes. Google is even trying to incorporate it in Google Slides, to bring in auto-generated Images, text, and videos in slides. Sheets will use AI to automatically analyze data, generate formulas, and provide other advanced features. They announced that all these AI-powered capabilities will be released gradually over the course of a year. As for BARD, an experimental AI developed by Google, it is already being powered by PaLM 2.

Conclusion

In this Guide, we have learned about Google’s very own Generative AI, i.e. PaLM(Pathways Language Model). We have seen how it is different from BARD and even understood how the PaLM 2 is significantly better than its previous versions. Then we discussed the model sizes offered by PaLM 2. Finally, we have moved on to the hands-on part, where we have seen how to get started with PaLM 2. We enlisted for the MakerSuite and then explored it, played with different types of Prompts offered by the MakerSuite, and finally created an API to interact with the PaLM 2 through the code.

Key Takeaways

Some of the key takeaways from this guide include:

  • PaLM 2 is a Generative AI Large Language Model created and maintained by Google
  • One can readily work with PaLM 2 for creating their application through the Vertex AI in Google Cloud.
  • PaLM 2 is capable of understanding different languages and is even able to generate codes in more than 20 different languages and has good reasoning skills
  • MakerSuite is a visual tool developed by Google, that enables rapid prototyping with the Large Language Models
  • MakerSuite’s different Prompt Types are suitable for testing different applications

Frequently Asked Questions

Q1. What are the different model sizes available in PaLM 2?

A. PaLM 2 comes in 4 different model sizes. They are Gecko, Otter, Bison, and Unicorn (smallest to largest). Gecko is the smallest model that can be work to incorporate Generative AI in mobile-based applications and Unicorn is the largest.

Q2. What are models currently supported by the MakerSuite?

A. Through MakerSuite or via the PaLM API, we are currently provided with 3 models.embedding-gecko-001 model for embedding text, text-bison-001 model for freeflow text generation, and chat-bison-001 model for chat-optimized generative ai language model.

Q3. How to access the PaLM 2 model?

A. There are currently two ways to access the PaLM 2 model. One is joining the waitlist for Google’s MakerSuite, which gives us the API for the PaLM 2 and even acts like a web-based IDE for quick prototyping. Another is through the Vertex AI we can access the PaLM 2.

The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.

Ajay Kumar Reddy

11 Aug 2023

RELATED ARTICLES

Most Popular

Recent Comments