Table of contents
1.
Introduction
2.
What makes Colab different?
3.
Features Of Google Colab
4.
Getting Started With Google Colab
4.1.
Renaming the Cell
4.2.
Running a Cell
4.3.
Moving Cell
4.4.
Deleting Cells
4.5.
Saving the Notebook To Google Drive
4.6.
Saving the Notebook in Github
4.7.
Sharing Notebooks
4.8.
Google Colab Runtimes
4.9.
Using Terminal Commands on Colab
4.10.
Uploading Datasets and Files
4.11.
Mounting Drive
4.12.
Installing ML Libraries
4.13.
Importing Libraries
5.
Frequently Asked Questions
6.
Key Takeaways
Last Updated: Mar 27, 2024

Google Colab

Author Mayank Goyal
2 upvotes
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

It is a magic moment when you realize something unbelievable is happening. Yeah, google colab is one of those magic. Providing free GPU's and TPU's for free and being able to use them how much we want is nothing less than magic and, above all, it's independent of our devices and specifications. Anyone who has a google drive and a browser can use google colab for free.

Using colab is a piece of cake for anyone who has previously used a jupyter notebook. Colab is an enhanced version of the notebook. Colab is simple and valuable to use.

So what's colab? Google colaboratory is a free cloud-based notebook environment that allows us to train our machine and deep learning models with the help of CPUs, GPUs, TPUs. Colab supports many top machine learning libraries. Colab lets us and our teammates edit documents simultaneously, just like google docs.

Also, see -  Locally Weighted Regression.

What makes Colab different?

Anyone into deep learning knows the numerous hours it takes to train models in our local machine with the help of CPUs. GPUs and TPUs can train the same model in a matter of minutes or even seconds. They are lightning faster than the CPU. Anyone will prefer GPU over CPU for its computational power and speed but affording GPU is not possible for everyone. This is where the magic happens. Google colab provides this service for free. We can continuously use GPU for 12 hours to meet our computational needs. It will cost you A LOT to buy a GPU or TPU from the market. Why not save that money and use Google Colab from the comfort of your machine?

Features Of Google Colab

  • We can write and execute code in Python.
  • We can document our code that supports mathematical quotations.
  • We can create, upload, and share notebooks.
  • We can import or save notebooks from or to Google drive.
  • We can import external datasets from Kaggle.
  • We can import or publish notebooks from Github.
  • We can integrate different deep learning libraries like PyTorch, TensorFlow, Keras, etc.
  • Colab provides free GPU and TPU.

Getting Started With Google Colab

Click on this link, and it will redirect you to google colab. Click at the bottom New notebook to create a new colab notebook. We can also upload it from our local machine.

  

Renaming the Cell

We can rename our notebook by clicking on the notebook's name and renaming it or by clicking on the "File" menu down to "Rename."

 

Running a Cell

We can run a cell just by clicking on the arrow symbol at the starting of the cell or just by entering shift+enter.

 

Moving Cell

After selecting the specific cells, we can move up and down the cell by clicking on the arrow option.

 

Deleting Cells

We can delete the cell just by right-clicking on the cell and choosing the specific operation we want to perform.

 

Saving the Notebook To Google Drive

Colab allows us to save our work to google drive by clicking on the file menu and choosing the save a copy in drive option.

 

Saving the Notebook in Github

We can save our work in our GitHub repository by following the exact instructions above but choosing to save a copy in the GitHub option.

Now we have to enter the credentials of GitHub and, after successful login, create a new repository if you don't have one and if you have directly saved it.

 

Sharing Notebooks

We can directly share our notebooks by clicking on the top right corner share option and following the same choice while sharing google docs, like to whom you want to share, what kind of access you have given like view, edit, or comment.

We can also share our notebooks from Google drive if we have a copy. We can share in it a public place by saving a copy in Github.

 

Google Colab Runtimes

The ability to change the runtime makes colab more powerful. We can change the runtime by clicking on the Runtime option on the top menu and selecting 'Change Runtime Type,' and choosing the runtime as our choice.

 

Using Terminal Commands on Colab

We can run terminal commands on colab cells. We have to add '!' before every command statement.

Suppose we want to add a library in colab.

 

Uploading Datasets and Files

Uploading is one of the essential aspects for every data scientist. Uploading datasets is the most primary part of the data science journey.

We can upload our dataset in colab directly, as shown in the below screenshot.

 

We can also upload via Google drive, and we have to upload the dataset to our drive and mount it.

 

Mounting Drive

Suppose we have already had datasets in our drive or some Python code needed for work. We can directly use them by mounting them with colab. Yes, colab provides us a feature to access everything in the drive.

We have to click on the command palette on the bottom left of the screen and search mount on the popped-up dialog box.

After clicking on it, we have access to the drive, and we are good to go. The drive folder will appear on the left side of the screen; if not, refresh once.

Installing ML Libraries

Colab has most of the available libraries in open source, but there are a few exceptions. We can install those libraries just by executing a simple command.

!pip install

Or

!apt-get install

 

For example,

!pip install -q keras

 

Importing Libraries

Importing is pretty standard. We have to execute the same command we use while working on other notebooks

 

That is all from the basics of colab. Colab is user-friendly. It won't take much time before you get used to it.

 

Frequently Asked Questions

  1. What is TPU?
    TPU is an AI accelerator developed by google's tensor flow, designed to work with neural networks. TPU stands for Tensor Processing Unit.
     
  2. How colab is better than Jupyter Notebook?
    Colab has already pre-installed libraries required, which is not in the jupyter notebook. Jupyter notebook occupies space in our local disk, while colab uses the cloud to save notebooks. In the case of jupyter, we have to set up the environment to prevent workload crashing of the system, and last but not least, colab provides us with free GPUs and TPUs, not in the case of jupyter.
     
  3. Is there a limit in google colab?
    Google Colab has a maximum limit of running notebooks that is 12 hours with the browser open, and the 'Idle' notebook instance is interrupted after 90 minutes.

Key Takeaways

Let us brief out the article,

We saw basic features of colab and why it has the upper hand over jupyter notebook. And the most crucial topic is what makes colab different. Later, we saw some of the primary methods to perform various tasks.

Thus Colab is a powerful platform for developing machine learning models only in Python. It is an extension of the jupyter notebook and supports collaborative development. Considering the benefits we get from colab, there are a few sacrifices too, like there is a limit of the session(12 hours), and secondly, it does not support any language apart from Python.

I hope you like this article. Stay tuned for further updates.

Keep Learning Ninjas!

Live masterclass