Google Colab and its integrated Generative AI, a powerful combination
What you’ll find in this article: A guide on the various ways to use Generative AI tools integrated into Google Colab (a no-installation, cloud-based platform for coding in Python), making it the easiest way to learn and work with Python.
Knowing how to code is more useful and more accessible than ever. In this article you’ll see how to start coding in a minute without any prerequisites, leveraging the power of the latest Generative AI tools.
I started coding 25 years ago; I was about 10 years old. Everything was tough, from installing development tools, to learning the commands, including debugging of course.
Today, we are very far from that era. Google Colab recently integrated a set of GenAI tools that completely revolutionize the way we code.
It has never been easier to start coding. All the barriers are now down.
This is great news because coding is virtually everywhere and becoming useful, or even required, in a growing number of jobs. Moreover, if you know a little bit of code, you can now go extremely far with minimal effort thanks to these Generative AI tools.
In this article, I will show you the most efficient way to learn and use Python today with a no-installation tool. If you are not new to Python (know what Google Colab and notebooks are, you can skip Part I). The article is organized as follows:
Part I: Preliminary:
- Why choose Python and Google Colab?
- Where to start learning Python?
Part II: Generative AI tools integrated in Google Colab:
- Code completion
- Debugging
- Suggestions
- Graph suggestion
- Getting help
Discussion
Part I: Preliminary
Why choose Python and Google Colab?
Why Python? Python is the most popular and versatile language today. Python can be used for:
- Machine Learning and Artificial Intelligence (e.g. NLP, deep learning),
- Statistics and Analytics
- Creating and working with Chatbots (e.g. LLMs, agents etc.)
- Web development (e.g. Backend Development)
- and more: Finance, Robotics, Database access, Game development etc.
Moreover, due to its popularity, Python is a requirement for many jobs, and it’s particularly easy to learn because of the vast number of resources available.
Why Google Colab? When it comes to Python there are numerous ways to code. The two most popular ways to start are IDEs (Integrated Development Environments) or Notebooks. Notebooks are a web-based interactive environment for writing code. They allow you to mix code, text, and visualizations in a single document.
You can either install a local notebook tool on your computer (e.g. Jupyter Notebook) or use an online cloud-based solution like Google Colab.
Since this guide is focused on accessibility, I picked a cloud-based tool that requires no installation. The only requirement is a Google account. All the documents will be stored on your Google Drive, and hence you can work from any computer and easily collaborate with others.
Where to start learning Python?
There are countless options to start learning Python. Here are two sources for a complete beginner’s guide to Python in different formats:
- YouTube free full course for beginners: https://www.youtube.com/watch?v=rfscVS0vtbw
- Free full course with with integrated code cells: https://www.w3schools.com/python/python_intro.asp
- Interactive platforms: DataCamp
Learning how to code is similar to learning many other skills, like swimming or biking — you need to practice. So, when you start with these tutorials or others, open Google Colab, start experimenting with code, and adapt it. Use the tools covered in Part II to support your learning journey.
Part II: Generative AI Tools Integrated in Google Colab
Since the public release of ChatGPT 3.5 in November 2022, the number of Generative AI tools to support coding has grown quickly. Large Language Models, like ChatGPT, are incredibly powerful to help us with code. Coding relies on a “language” with clear syntax, which makes it an ideal domain for LLMs.
Google Colab recently integrated a set of Generative AI tools that can support various aspects of your work, from code suggestions to debugging and explanations. Let’s now cover all of these tools:
- Code completion
- Debugging
- Suggestions
- Automatic graphs suggestions
- Help
Code completion
When you start typing code in Google Colab, you’ll quickly notice that code suggestions appear in grey and italic (see video below) beyond what you type.
The suggestions appear very quickly and adapt as you continue typing. You just need to press the Tab key to accept the suggestion.
Note that the suggestions are based not only on what you are typing but also on the rest of the file, making this feature incredibly powerful and going significantly beyond traditional simple code completion tools. For example, in the video below, the suggestion for importing a file is not generic — it’s the exact code needed to import the file in my active Google Colab document with the correct format.
Debugging
If you’ve ever tried coding, you know that debugging is often what we spend the most time doing. Historically, if you didn’t understand the error, you would refer to manuals, copy and paste the error message, and search online (e.g. Stack Overflow) for solutions. More recently, you might even ask ChatGPT or another LLM for help.
But now there’s an incredibly fast integrated solution. As you can see in the video below, I ran some code that generated an error. After each error message, you’ll see a button labeled “Explain error.” Once you click it, a pane will open on the right-hand side, and Gemini (an LLM) will explain the error and propose adjusted code. You can then adapt the code by hand, copy-paste the suggestion, or in one click, create a new cell with the corrected code in your notebook.
Suggestions
Beyond code completion, Google Colab offers two simple ways to suggest code based on your description.
The first way is by writing a comment (see the video below). I just write a comment that explains the next line of code, and Colab directly interprets it and automatically suggests the corresponding code. This functionality works mainly for simple, usually single lines of code.
When you need code suggestions for more complex requests, often requiring several lines of code, you can click on “Generate” with AI when you start a new code block (see video below). Then, you can use natural language to explain what you want to do, and the code will be automatically generated. Note that the prompt will be included as a comment on top, so try to make a clear request to save time.
Automatic graphs suggestions
There are also specific suggestions for graph creation when you work with a dataframe (see video below). When you describe or display part of a dataframe, an icon with a graph appears in the top right corner. When you click on it, you’ll see a gallery of potential graphs. By clicking on one of the graphs, a new code cell will be generated with the code required to create the selected graph.
So far, I haven’t been very impressed by this function. It crashed a few times, returned errors, or suggested numerous options, but the one I was interested in wasn’t available.
Help
Finally, you can directly chat with Gemini (a chatbot/LLM) to ask code-related questions. These questions could be about a piece of code you don’t understand, how to perform a specific task with code, or virtually anything else. You essentially have an AI tutor available 24/7, just one click away.
Discussion
While Generative AI is incredibly useful and powerful for coding, it should be used in moderation when learning. This efficiency might prevent us from truly mastering the material and could negatively affect our long-term performance.
I was blown away by the impact of these Generative AI integrations. I find myself writing less and less code — it’s more about being able to read and test code now. But reading is always easier than writing, just like when learning any language (not just programming).
However, this raises questions about the long-term effects for people who haven’t yet fully learned how to code. I remember using these tools extensively to select parts of Pandas dataframes because I often mixed up the brackets, .loc or .iloc functions, and syntax. ChatGPT helped me go faster a few times, but over the long run, I became less efficient. If I have to ask every time, it often takes longer than if I knew the solution by heart. And what happens if the tool isn’t available?
Moreover, it’s very important to remember to use AI suggestions responsibly. Always aim to understand the code you’re incorporating to avoid potential issues with plagiarism or unintended errors. Note that when using suggestions in Google Colab, you might see the source of the code inspiration (see image below). This information can help you avoid potential copyright violations.
The Easiest Way to Learn and Use Python Today was originally published in Towards Data Science on Medium, where people are continuing the conversation by highlighting and responding to this story.
Originally appeared here:
The Easiest Way to Learn and Use Python Today
Go Here to Read this Fast! The Easiest Way to Learn and Use Python Today