Search for Courses, Topics
certificate icon
Certificate

Learn on Scaler Topics and get certified.

static-certificate

What is Google Colab?

Learn everything about Google Colab in this article

28 Aug 2021-9 mins read

Everything you need to know about Google Colab

Nowadays, machine learning and deep learning has become the hottest trend of the Computer Science industry. Many students are trying to learn and build amazing projects with it. We all know that just studying or reading or watching a tutorial is of no use if you didn’t try it out on your own. But in order to do that, you need really advanced specifications, for your system to withstand such a workload. And not everyone can afford a laptop with such specifications. So what can they do to learn and practice machine learning?

Google Colab is the answer.

What is Google Colab?

Google Colab was developed by Google to provide free access to GPU’s and TPU’s to anyone who needs them to build a machine learning or deep learning model. Google Colab can be defined as an improved version of Jupyter Notebook.

What is Jupyter Notebook?

Jupyter Notebook is an application that allows editing and running Notebook documents through a web browser or an Integrated Development Environment (IDE). Instead of files, you will work with Notebooks.

What is a Notebook?

Programming Languages are an intermediate form between human-understandable language and machine understandable language. Every application is built using one of the many programming languages available. Maybe a person with a computer science background can understand, but not everyone can. Remember, as Software Developers, we develop applications for people with little computer science knowledge.

Consider you are creating a machine learning model to improve customer satisfaction for a local store, in that case you will have to explain how the model can do this task, and you can’t just explain him with your code base. Most people facing this situation will prepare a separate presentation. Notebooks were created so that it is not necessary. Notebook documents can include executable lines of code along with text, images, figures, tables, graphs, equations, and much more graphical data. In simple words, Notebook documents are a way of creating human-readable executable documents.

Google Colab Features

Google Colab provides tons of exciting features that any modern IDE offers, and much more. Some of the most exciting features are listed below.

  • Interactive tutorials to learn machine learning and neural networks.
  • Write and execute Python 3 code without having a local setup.
  • Execute terminal commands from the Notebook.
  • Import datasets from external sources such as Kaggle.
  • Save your Notebooks to Google Drive.
  • Import Notebooks from Google Drive.
  • Free cloud service, GPUs and TPUs.
  • Integrate with PyTorch, Tensor Flow, Open CV.
  • Import or publish directly from/to GitHub.

How to Use Google Colab?

Just like any other product from Google, you need a Google account to get started. You can access Google Colab using this link Welcome To Colaboratory – Colaboratory (google.com) and signing in through your Google account.

You will land on a page similar to the one shown below.

How to use Google Colab

Examples Tab:

The examples tab contains some examples to get you started with the Colab.‘The overview of Colaboratory features’ document contains most of the basics that can help you get started with how to use the Colab documents efficiently.

Examples Tab in Google Colab

Recent Tab:

The recent tab shows a list of all the recent documents you have worked with.

Recent Tab in Google Tab

Google Drive Tab:

The Google Drive tab lets you import any previous Notebooks from your Google Drive.

Google Drive Tab - Google Colab

Github Tab:

The GitHub tab lets you import Notebooks from yours or any public GitHub repository. You can import any public repository by providing the GitHub URL.

Github Tab - Google Colab

Uploads Tab:

The upload tab lets you upload and work with any of your local Notebooks that you have created with Jupyter Notebooks. You can upload any file from your local machine using the ‘choose file’ option.

Uploads Tab in Google Colab

Creating a New Notebook:

You can also create a new Notebook using the ‘New Notebook’ option available at the bottom. Clicking the New Notebook button will create a new untitled Notebook. You can rename the Notebook by clicking on the name of the Notebook currently untitled and change the name.

Creating a new notebook in Google Colab

Working with a Notebook:

In a Notebook, cells are the building blocks. Everything in a Notebook is composed of cells. There are two types of cells

  • Code cell
  • Text cell Code cell A code cell contains the executable code. A code cell has a run button to its left that lets you execute the contents of the cell. When you run a cell the output is displayed under the cell.

Working with a notebook in Google Colab

Text Cell:

A code cell can contain text, images, links and much more. You can double-click a text cell to edit its contents. The text cell supports Markdown markup language. Even if you are not familiar with Markdown, you can use the options provided on the top of the text cell. The right half of the cell shows how your text cell will be displayed when you are done editing.

Text Cell in Google Colab

Adding a new Cell:

You can add a new code cell or text cell using the option available in the top of the work area. Clicking on any of the buttons creates a new cell under the current cell (The cell in which the cursor is currently present).

Adding a new cell in Google Colab

Changing the Order of the Cell:

You can change the order of the cell by using the arrow option available over the top right corner of the cell. The up arrow moves it one cell up, and the down arrow moves the current cell down one cell.

Changing the order of the cell in Google Colab

Deleting the Current Tab:

You can also delete any unwanted cell using the delete icon available over the top of the cell.

Deleting a tab in Google Colab

Choosing the GPUs and TPUs:

One of the most popular and amazing features of Colab is that you can choose powerful GPUs or TPUs for your document, and you don’t need to worry about the workload. Everyone needs to know how to do that.

Step 1: Choose the ‘change Runtime’ option under the ‘Runtime’ option from the header.

Choosing GPUs and TPUs in Google Colab
Step 2: You will be greeted with a dialog box that allows you to choose a GPU or TPU. After selecting, exit the dialog box using the save button.

Google Colab - GPU and TPU
You can confirm that the GPU has been connected from the green tick on the top right of the page. When you hover over, it will show the details of the GPU, such as the RAM and Disk storage.

Google Colab - GPU TPU

Running Terminal Commands:

You can execute not just Python code, but also terminal commands. You can prepend any command you wish to execute with an exclamation mark (!) and execute it. This feature is very helpful if you want to install any other third-party libraries.

Examples

  • To list the files in the current directory !is

  • To install a new library !pip install library_name

  • To clone a Github repository !git clone <>

Connecting to Google Drive

Everything you execute inside the Notebook is really running in a virtual machine and your drive is not connected to the machine, so before you can save anything to your drive you have to connect to the virtual machine. You can do this by selecting the mount drive option available in the Files option in the sidebar.

Google Colab-Connecting to Google Drive

Sharing your Notebook

The amazing feature of Google Colab is that it lets real-time collaboration, just like in Google Docs. You can share with people by assigning them various roles like viewers, commenters, and editors. You can share using the share option available in the top right.

Sharing your Notebook - Google Colab

Why Should you Use Google Colab?

  • Pre-installed libraries:

Google Colab comes pre-installed with the most popular machine learning libraries. Colab comes pre-installed with Keras, PyTorch, TensorFlow, which saves you the time and hassle of setting up a local environment.

  • Saved on the cloud :

Every Notebook you create in the Google Google Colab is saved on the cloud. This lets you access and work with those Notebooks from any machine. All you need is a browser and a reliable network connection, and you can work from anywhere and anytime.

  • Collaboration :

Collaboration is another amazing reason to choose Google Google Colab when you are working on a project with a team of developers. You can share your Notebook with your teammates and assign them roles so that they can only perform operations that fit their roles. The various options available for each role is shown below:

– Editors can change permissions and share – Viewers and commenters can see the option to download, print, and copy

  • Free GPU and TPU use :

Google Colab provides free access to GPUs and TPUs developed by Google Research. So you can work on your personal projects with powerful GPUs irrespective of your local machine.

Frequently Asked Questions

  • What is a TPU?

Tensor Processing Unit, shortly known as TPU is an AI accelerator developed by Google’s own Tensor Flow. It was specifically designed for working with neural network machine learning.

  • Is Google Colab free for everyone?

Colab has both free and pro subscriptions. Google Colab pro offers Faster GPUs, Longer runtimes, and More memory for $10 per month. If you are just starting to learn, then the free plan is your best choice to go with.

  • How is Google Colab better than Jupyter Notebook?

Google Colab saves you the trouble of having to set up a local environment and maintaining all the dependencies, along with free access to faster GPUs and TPUs, so you do not have to worry about the workload crashing your system. It also allows easy collaboration just via Google Drive.

Conclusion

In this article, we learned about what Google Colab is. And also why it is better than Jupyter Notebook. And also how to get started with Colab along with some most frequently asked questions.

That’s all for now, folks!

Thanks for reading 🙂