5 Amazing Google Colab Hacks You Should Try Today!

Introduction Google Colab is an amazing gift to the data science community from the fine folks at Google.

Colab gives us the ability to build complex and heavy machine learning and deep learning models without having to expend our machine’s limited resources.

I can certainly appreciate this given how much I used to struggle on my machine! The ‘out of memory’ error is now quite infamous in the data science community – Google Colab provides us with the workaround and adds several cherries on top! I love the free GPU and TPU support – it’s simply unparalleled and unrivaled in any other coding IDE.

If you’re new to Google Colab, I highly recommend checking out my tutorial for beginners here.

  In this article, I have listed five awesome Google Colab hacks that I’ve personally found really useful in my data science journey.

These hacks will not just save you a lot of time but will broaden your understanding of Colab as a whole.

So, let’s make you a Google Colab expert!   (adsbygoogle = window.

adsbygoogle || []).

push({}); The 5 Google Colab Hacks We’ll Cover: Increase Google Colab RAM Stop Google Colab From Disconnecting Snippets in Google Colab Top Keyboard Shortcuts for Google Colab Modes in Colab   1.

Increase Google Colab RAM Google Colab already gives us about 13 GB of RAM for free.

That’s quite impressive but there are times when even that isn’t enough when we’re building heavy deep learning models.

Here’s how you can quickly increase the RAM in your Colab notebook.

It’s a very simple trick and it almost doubles your RAM capacity.

For getting higher RAM, you need to run the following code in your Colab code cell and wait for Google Colab to crash: i = [] while(True):     i.

append(a) Yes, you read it right – wait for Google Colab to crash.

As soon as it crashes due to a lack of RAM, it asks if you want more RAM: Now, click on Get more RAM  and you will see another popup: Just click on the YES button: And voila! You now have about 25 GB of RAM at your disposal!   2.

Stop Google Colab From Disconnecting Here’s a story I’m sure a lot of you will be familiar with.

I was working on Colab the other day and left my laptop up and running for about an hour.

When I came back, I saw that Google Colab disconnected my notebook and the model training had stopped.

Imagine my immense disappointment! Of course, I found out later that Google Colab disconnects our notebook if we leave it idle for more than 30 minutes.

But here’s the good news -from today, you will never face this issue.

Just open your Chrome DevTools by pressing F12 or Ctrl+Shift+I on Linux and run the following JavaScript code in your console: function KeepClicking(){ console.

log(“Clicking”); document.

querySelector(“colab-toolbar-button#connect”).

click() }setInterval(KeepClicking,60000) Here, the value 60,000 represents the milliseconds(equivalent to one minute).

This small piece of code makes a click on the Colab screen after every 60 seconds.

Thus, Colab thinks that the notebook is not idle and you don’t have to worry about being disconnected!   3.

Snippets in Google Colab Remembering code syntax is among the biggest issues almost every beginner faces in the starting phase of their data science journey.

Due to this, people often find it very difficult to learn data science and quickly lose their motivation.

We can’t be having that! Therefore, I have a simple solution for you.

Even if you don’t consider yourself a beginner, I am sure this trick will help you at some point in your data science journey.

The best way of tackling this situation is to create a snippet of the code that you most require, or you find it difficult to learn its syntax.

A snippet is a reusable piece of code which you can use whenever you want.

In this way, you can save yourself from the headache of remembering code and focus on the concepts of data science.

If you ask me about my favorite features of Colab then, my first answer is free GPUs and TPUs, and the second one is the ability to create custom snippets.

Yes, you can create your own custom snippets inside Google Colab.

Let me show you how it’s done.

First, you need you to create a notebook in Colab.

Then, add a text cell and type your snippet name.

Below that, add the code cells and type your code: Here, I have created a very basic snippet for import statements – you can create a snippet of whatever you want.

Next, its time to use this snippet in another notebook.

Go to Tools and open Settings: Now, you’ll see a popup like this one below.

Just paste the link of a notebook containing snippets, click SAVE, and you are ready to go: You can see all your snippets here.

Just search for your snippet by its snippet name and insert it into your code: 4.

Top Keyboard Shortcuts in Google Colab Switching between your keyboard and mouse is a tedious and time taking task.

Therefore, to speed things up, Google Colab provides us with certain really useful keyboard shortcuts.

Honestly, you can’t master the Colab experience until you’ve used and become acquainted with these keyboard shortcuts.

Honestly, I feel these keyboard shortcuts increase our productivity as data scientists.

I know it takes some time to learn these, but once you do get a hang of them, you can complete your work much faster.

I have created a list of top keyboard shortcuts that you should know when working with Google Colab.

These key combinations are what I use, but you can modify them according to whatever is more comfortable:   5.

Modes in Colab This hack is about different viewing modes offered by Google Colab and how you can switch between them.

A lot of you will appreciate this switch and your eyes will thank you in the long term! Apart from the default light mode, Google Colab also gives us a dark mode.

Yes, similar to any other code editor out there, Google Colab also has a dark mode.

Even Jupyter Notebooks don’t come with this feature by default.

To change your viewing mode to dark mode.

Go to Tools and open Settings: Here, you will see a popup like this one below.

Just select the dark mode in theme, click SAVE, and you are ready to go: As you can see, this mode is more relaxing for your eyes.

You can use this mode when you are working in the dark because it saves you from eye strain: We aren’t done yet! How about adding some fun to your Colab screen? Welcome to the Corgi and Kitty mode.

In Corgi mode, you see dogs running on your colab screen similar to the one below: You can easily guess what you get in Kitty mode.

Yes, this one is for all the cat lovers out there.

You can see your cats on the Colab screen too: Or you can have both of them and have fun while coding: Now, let’s see how you can get these modes.

Go to Tools, open Settings and go to the Miscellaneous section.

Here, you can select your Corgi and Kitty mode, click SAVE and there you have your cats and dogs strolling on your screen:   End Notes These hacks cover a broad range of things you can do in Google Colab.

From efficiently running your code to having fun while designing deep learning models, these Colab hacks will enrich your coding experience.

If you want to know more tips and tricks related to data science, I recommend taking this free course.

Do share this article and comment below in case you have any queries or feedback.

And don’t forget to sign up on Analytics Vidhya to read various exciting articles related to machine learning and data science! You can also read this article on Analytics Vidhyas Android APP Share this:Click to share on LinkedIn (Opens in new window)Click to share on Facebook (Opens in new window)Click to share on Twitter (Opens in new window)Click to share on Pocket (Opens in new window)Click to share on Reddit (Opens in new window) Related Articles (adsbygoogle = window.

adsbygoogle || []).

push({});.

Leave a Reply