
Introduction
Giant Language Fashions, the successors to the Transformers have largely labored inside the house of Pure Language Processing and Pure Language Understanding. From their introduction, they’ve been changing the standard rule-based chatbots. LLMs have a greater capacity to know textual content and may create pure conversations, so they’re changing the standard chatbots. However since their introduction, the LLMs are doing greater than what they’re able to. Like changing Pure Language to SQL Queries, in a position to browse the web to fetch the most recent info. And now they’ve the power even to execute code. On this article, we’ll have a look at the newly launched function of Gemini, i.e. the Code Execution.
Studying Goals
- Find out about Code Execution with LLMs.
- Get launched to Gemini Flash 1.5.
- Learn to get the API Key for Gemini.
- Understanding how the LLMs fail in mathematical duties.
- Leveraging LLMs with Code Execution for exact and correct solutions.
This text was printed as part of the Information Science Blogathon.
Gemini – Google’s Giant Language Mode
Gemini fashions are a household of enormous language fashions launched by Google. It’s launched by Google to rival the favored closed-source giant language fashions just like the GPT4 from OpenAI and Claude from Anthropic. Gemini is a multimodal giant language mannequin that’s able to understanding textual content, photographs, audio, and even movies.
GPT4 was in a position to do the identical as Gemini does however one which it differentiates from Gemini is operating the Code that it generates. And now not too long ago Google has up to date the Gemini mannequin making it run code. The code execution is feasible because of the perform calling capabilities of Gemini, the Code Execution is similar to it and the code it generates, will run and get the outcomes to generate the ultimate output to the consumer.
The code that Gemini generates will likely be run in an remoted sandboxed atmosphere. Proper now, solely the numpy and the sympy libraries are current within the sandboxed atmosphere and the generated code by no means can obtain and set up new Python libraries.
Getting Began with Code Execution
Earlier than we start coding, we have to get the free API key that Google offers to check the Gemini mannequin. The free API even helps the Code Execution. To get the free API, you may click on on the hyperlink right here. Now, we’ll begin with putting in the library.
!pip set up -q -U google-generativeai
You will need to preserve the -U flag whereas putting in the google-generativeai library. It is because the Code Execution is a brand new function and would require the most recent model of google-generativeai library to work. Now we’ll authenticate ourselves.
import google.generativeai as genai
GOOGLE_API_KEY = "YOUR API KEY"
genai.configure(api_key=GOOGLE_API_KEY)
Right here we import the google.generativeai library and name the .configure() methodology. To this, we give the API Key that we’ve obtained by signing to the Google AI Cloud. Now we will begin working with the Gemini Fashions.
mannequin = genai.GenerativeModel(model_name="gemini-1.5-flash")
response = mannequin.generate_content("How are you?")
print(response.textual content)

Clarification
- Right here we begin by creating an occasion of the GenerativeModel Class.
- Whereas instantiating this object, we give the identify of the mannequin that we’re working with, which right here is the gemini-1.5-flash, which is the most recent mannequin from Google.
- To check the mannequin, we name the .generate_content() methodology after which, give the question to it, and retailer the generated textual content within the response variable.
- Lastly, we print the response. We will observe the response in pic above.
Not the whole lot will be answered appropriately with the Giant Language Mannequin. To check this, allow us to attempt asking the Gemini Flash mannequin a easy query to show the primary 5 letters of the phrase Mississippi.
response = mannequin.generate_content("Trim this phrase to first 5 letters, Mississippi")
print(response.textual content)

Right here, operating the code and seeing the output above, we see that Google’s Gemini mannequin, the most recent LLM development from the Google group has did not reply such a simple query. This isn’t solely with the Google Gemini fashions, however even the GPT4 from OpenAI and even Claude from Anthropic fail to reply it.
It is because they don’t have the power to rely backward. That’s after producing the letter “i” the mannequin has no concept that it has outputted the second letter. It simply outputs a letter given the earlier letter, however has no concept in regards to the size of the earlier letters.
One other Instance
Allow us to check out one other query that the big language mannequin fails to reply.
response = mannequin.generate_content("What's the sum of first 100 fibonaocci numbers?")
print(response.textual content)

Right here, we ask the Gemini Flash mannequin to offer us the sum of the primary 100 Fibonacci sequence. Working the code and seeing the output pic, we will say that the mannequin has did not reply our query. As a substitute of returning the sum, it has given us the steps to get the sum of the primary 100 Fibonacci sequence. The mannequin failed as a result of giant language fashions are text-generation fashions. They don’t have any capacity to carry out mathematical operations
So in each circumstances, the mannequin has failed. Now, what if the gemini mannequin has capacity to execute Python code? The mannequin may attempt to write a code that might lead us to the reply we predict. Perhaps for the primary query, the mannequin may carry out a string operation and run the code and for the second query, it may write a perform to calculate the sum.
Gemini – Code Execution
So now, allow us to attempt to ask the mannequin the identical two questions however this time, offering it entry to the Code Execution instrument.
model2 = genai.GenerativeModel(model_name="gemini-1.5-flash",
instruments="code_execution")
response = model2.generate_content("Trim this phrase to first 5 letters,
Mississippi. Use code execution instrument")
print(response.textual content)

Right here once more, we create an occasion of the category GenerativeModel and provides it the Gemini-1.5-flash mannequin identify, however together with it, we even give it the instruments that the mannequin can work with. And right here we offer it with the code_execution instrument. Now, we ask the identical query to the mannequin. This time, we even inform it to work with the code_execution instrument.
Working the code and seeing the output pic above, we will discover that, the Gemini Flash mannequin has written a Python code to do a string operation i.e. slicing right here, it has sliced the primary 5 letters of the phrase Mississippi and has lastly given us the answered that we needed. Now allow us to attempt the identical with the second query, the place we ask the LLM to offer us the sum of the primary 100 Fibonacci numbers.
response = model2.generate_content("What's the sum of first 100 fibanocci numbers?")
print(response.textual content)

Right here, operating the coding and seeing the output, we see that the Gemini Flash has generated a perform to calculate the Fibonacci quantity. Then known as the perform by giving it 100 for n worth after which lastly printed the output. With the code_execution instrument, the gemini llm was in a position to appropriately give us the reply to the query. This manner it could possibly clear up mathematical issues by making a code out of it and operating the code to get the reply.
Conclusion
The introduction of code execution in Google’s Gemini mannequin represents a big development within the capabilities of enormous language fashions. By integrating this function, Gemini can no longer solely perceive and generate textual content but in addition execute code to resolve complicated issues. This growth enhances its utility in a wide range of purposes, from pure language processing to performing particular computational duties. The power to run code permits Gemini to beat a few of the inherent limitations of language fashions, notably in dealing with exact calculations and procedural duties.
Key Takeaways
- Gemini can perceive and course of textual content, photographs, audio, and video, making it a real multimodal.
- Giant Language Fashions typically fail to reply mathematical questions with precision, as a result of they can’t carry out calculations.
- Code Execution permits an LLM to run code in a sandboxed atmosphere.
- Giant Language Fashions can run Python Code by performing a instrument name and giving the instrument the related Python code to execute.
- Google’s free API permits customers to entry the Gemini Flash API that may Execute Code.
Steadily Requested Questions
A. Gemini is a household of enormous language fashions launched by Google, able to understanding textual content, photographs, audio, and movies.
A. Just lately, Google has introduced the function of Code Execution for the Gemini Mannequin. It’s open to the general public by the free Google Gemini API Key.
A. At the moment, solely the numpy and sympy libraries can be found in Gemini’s sandboxed atmosphere.
A. With code execution, Gemini can generate and run Python code to carry out duties comparable to string operations and mathematical calculations precisely
A. To allow code execution, create an occasion of the GenerativeModel class with the code_execution instrument and supply the suitable mannequin identify.
The media proven on this article will not be owned by Analytics Vidhya and is used on the Writer’s discretion.


