Sunday, April 14, 2024
HomeMachine LearningCodey: Google’s Generative AI for Coding Duties

Codey: Google’s Generative AI for Coding Duties


Since its introduction, OpenAI has launched numerous Generative AI and Massive Language Fashions constructed on prime of their top-tier GPT frameworks, together with ChatGPT, their Generative Conversational AI. After the profitable creation of conversational language fashions, builders are continually making an attempt to create Massive Language Fashions that may both develop or help builders in coding functions. Many corporations have began researching these LLMs, together with OpenAI, that might assist builders construct functions sooner with the LLMs figuring out programming languages. Google constructed Codey, a fine-tuned mannequin of PaLM 2, able to performing various coding duties.

Additionally Learn: PaLM 2 By Google To Sort out GPT-4 Impact

Studying Aims

  • Understanding how Codey was constructed
  • Studying how one can work with Codey on the Google Cloud Platform
  • Understanding the kind of prompts that Codey can take
  • Exploring and Participating with completely different fashions inside Codey
  • Leveraging Codey to generate workable Python Code
  • Testing Codey to see the way it identifies and solves errors in code

This text was printed as part of the Information Science Blogathon.

What’s Codey?

Codey is among the foundational fashions constructed and launched by Google not too long ago. The Codey is predicated on the PaLM 2 Massive Language Mannequin. Codey is a fine-tuned mannequin of the PaLM 2 Massive Language Mannequin. A big corpus of high-quality codes and coding paperwork has fine-tuned Codey. Google claims that Codey can code in additional than 20+ programming languages, together with Python, C, Javascript, Java, and extra. Codey was used to boost Google merchandise like Google Colab, Android Studio, and so forth.

Codey is constructed to resolve three functions. One is code completion. Codey can analyze your writing code and make helpful options primarily based on it. Thus it’s context-aware of the code you might be writing. One other is code era. Codey can generate full workable code in any language, supplied the immediate. Lastly, you’ll be able to chat together with your code. You’ll be able to present your code to Codey and chat with Codey associated to the code. Codey is now out there to most people via Vertex AI within the Google Cloud Platform.

Additionally Learn: Google’s Med-PaLM 2 to Be Most Superior Medical AI

Getting Began with Codey

To work with Google’s Codey, we should have an account with the Google Cloud Platform. Google Cloud Platform hosts the service referred to as Vertex AI, which holds all of the fashions developed by Google and even the Open Supply fashions fine-tuned by Google. Google has not too long ago made out there the not too long ago introduced Google Foundational fashions, which embody PaLM 2, Codey, Chirp, and Imagen. GCP customers can discover them right here.

After creating an account within the Google Cloud Platform, we should allow the Vertex AI API to work with Vertex AI. For this, go to the API & Companies -> Library, then seek for the Vertex AI API. We are able to see the Vertex AI API within the first pic beneath. Then click on on it. After clicking on it, we are going to discover a blue field with “Allow API” written on it. Click on on the blue field to allow the API, which is able to look much like the second pic.

How to enable Vertex AI API in Google Cloud Platform? | Coding | Generative AI | Codey
How to enable Vertex AI API in Google Cloud Platform? | Coding | Generative AI | Codey

This affirmation permits us to work with any of the AI providers Google supplies, together with Google’s basis fashions like Chirp, Imagen, and Codey.

Code Technology with Codey

This part will look into Code Technology with the Codey mannequin. The prerequisite for this will likely be enabling the Vertex AI API within the GCP, which now we have already performed. The code walkthrough right here will happen in Google Colab. Earlier than attending to the code, we should set up some crucial packages to work with Vertex AI, which we are going to do via pip.

!pip set up shapely

!pip set up google-cloud-aiplatform>=1.27.0

The Shapley and the google-cloud-aiplatform are the one two required packages to begin working with the Codey mannequin. Now we are going to import the packages and even authenticate our Google account, so Colab can use our GCP credentials to run the Codey mannequin from Vertex AI.

from google.colab import auth as google_auth

import vertexai
from vertexai.preview.language_models import CodeGenerationModel

vertexai.init(mission="your_project_id", location="us-west1")
parameters = {
    "temperature": 0.3,
    "max_output_tokens": 1024
  • Firstly, we import the google_auth from Google.colab package deal. That is crucial as a result of this may assist us authenticate by permitting the Colab to make use of our credentials for operating the Codey mannequin from Vertex AI.
  • Then we import the vertex, the package deal containing all of the machine studying and AI-related fashions composed by Google. Lastly, we even import the CodeGenerationModel from vertexai with which we are going to work.
  • Now we provoke the Vertex AI with the mission we are going to work with. Right here we offer the Challenge ID to the mission variable and provides any one of many areas to the location variable and the 2 variables as handed to the init() technique of vertexai.
  • We even specify the parameters beforehand. These embody the parameters like temperature, which is how artistic our mannequin needs to be, and the max_out_tokens parameter, which is the restrict set to the size of the output generated by the Massive Language Mannequin.

We are going to take this imported mannequin, i.e., the CodeGenerationModel, and check it by passing a immediate.


code_model = CodeGenerationModel.from_pretrained("[email protected]")
response = code_model.predict(
    prefix = """Write a code in Python to depend the occurence of the 
    phrase "rocket" from a given enter sentence utilizing Common Expressions""",

print(f"Response from Mannequin: {response.textual content}")
  • Right here is the mannequin for code era. We’re working with a pre-trained mannequin from Google, i.e., the “[email protected]” mannequin, which is the fine-tuned PaLM 2 mannequin. This mannequin is liable for the era of code given the immediate.
  • For passing the immediate, we move it to the predict() perform of the mannequin. To the prefix variable, we move the immediate. Right here we would like the mannequin to generate Python code to depend the occurrences of the phrase “rocket” utilizing Regex.
  • And we even move the beforehand outlined parameters to the predict() perform.
  • The responses generated by this code era mannequin are saved within the variable response, and to get the response, we name the textual content technique to get the response from the mannequin.

The output for the code might be seen beneath

Code Output | Coding with Codey

We get a Python code because the output for the immediate now we have supplied. The mannequin has written a Python script matching the question we equipped. Now the one method to check that is to repeat the response, paste it into the opposite cell within the colab and run it. Right here we see the output for a similar.


The sentence now we have supplied when the code is run is “Now we have launched our first rocket. The rocket is constructed with 100% recycled materials. Now we have efficiently launched our rocket into area.” The output efficiently states that the phrase “rocket” has occurred thrice. This manner, Codey’s CodeGenerataionModel might be labored with to create fast working codes by simply offering easy prompts to the Massive Language Mannequin.

Code Chat with Codey

The Code Chat perform permits us to work together with Codey on our code. We offer the Code to Codey and chat with the Codey mannequin concerning the code. It may be both to grasp higher the code, like the way it works, or if we would like alternate approaches for the given code, which Codey can do by wanting on the present code. If we face any errors, then we could present each the code and the error, which Codey will take a look at and provides an answer to resolve the error. We have to navigate to the Vertex AI within the GCP for this. Within the Vertex AI service, we then navigate to the Language Part beneath the Generative AI Studio, which might be seen beneath

Navigating to the Language Section under the Generative AI Studio

Navigating to the Language Part

We are going to undergo a non-coding strategy, i.e., initially, now we have seen how one can work with Code Technology via Python with the Vertex AI API. Now we are going to do this sort of job instantly via the GCP itself. Now to speak with Codey on our code, we proceed with the Code Chat choice within the middle throughout the blue field. We are going to click on on it to maneuver, then take us to the interface beneath.

Navigating to the Language Section under the Generative AI Studio

Right here, we see that the mannequin we are going to use is the “[email protected] mannequin. Now, what we are going to do is we are going to introduce an error to the Common Expression code that we generated earlier. Then we are going to give this error code and the error brought about to the Code Chat and see if the mannequin corrects our code. Within the Python Regex code, we are going to substitute the re.findall() with and run the code. We are going to get the next error.


Right here we see within the output that we get an error close to the technique. Now we are going to move this modified code and the error we received to the Code Chat within the “Enter a immediate to start a dialog.” We get the next output as quickly as we hit the Enter button.


We see that the Codey mannequin has analyzed our code and advised the place the error was. It even supplied the corrected code for us to work with. This manner, the Code Chat can determine and proper errors, perceive the code, and even get finest code practices.


On this article, now we have checked out certainly one of Google’s not too long ago publicly introduced basis fashions, the Codey, a fine-tuned model of PaLM 2 (Google’s homegrown Generative Massive Language Mannequin). The Codey mannequin is fine-tuned on a wealthy high quality of code, thus permitting it to jot down code in additional than 20 completely different programming languages, together with Python, Java, JavaScript, and so forth. The Codey mannequin is available via the Vertex AI, which we will entry via the GCP or with the Vertex AI API via API, each of those strategies now we have seen on this article.

Be taught Extra: Generative AI: Definition, Instruments, Fashions, Advantages & Extra

A few of the key takeaways from this text embody:

  • Codey is a fine-tuned mannequin constructed on the PaLM 2, making it strong and dependable.
  • It’s able to writing code in additional than 20 completely different programming languages.
  • With Codey, we will generate code from a easy immediate and even chat with the mannequin to appropriate the errors that come up within the code.
  • Codey even supplies options, a Code Completion function, the place the mannequin analyzes the code you might be writing and presents helpful options
  • We are able to work with Codey instantly via the UI from the Generative AI Studio within the Vertex AI supplied by the GCP.

Ceaselessly Requested Questions

Q1. Is Codey able to producing code from scratch?

A. Completely. You solely want to offer a immediate, what code you need, and by which language. Codeys’s Code Technology then will use this immediate to generate the code in your required language on your desired software that you’ve acknowledged within the immediate

Q2. Is Codey primarily based on the PaLM 2?

A. Sure. The Codey basis mannequin is only a fine-tuned mannequin of the PaLM 2, which is fine-tuned on an unlimited dataset containing codes in several languages.

Q3. What Codey is able to?

A. Codey is especially able to doing three issues. One is code era from a given immediate, the second is code completion, the place the mannequin seems on the code you might be writing and supplies helpful options, and the ultimate is the code chat, the place you’ll be able to chat with Codey in your code, the place you present your code and error if any after which chat with the Codey mannequin associated to your code

This fall. Are Codey and GitHub Copilot the identical?

A. They don’t seem to be the identical however are related in some methods. GitHub Copilot is predicated on OpenAI’s mannequin and is able to auto-code-complete and code options. Codey can do that as properly, but it surely even has the function of Code Chat, which lets the person ask the mannequin questions associated to their code

The media proven on this article is just not owned by Analytics Vidhya and is used on the Writer’s discretion. 



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments