Getting Started

Getting Started with Google Colab: A Beginner's Guide

June 10, 2024
3
mins read
In the realm of data science and machine learning, having a powerful, flexible, and accessible computational environment is essential. Google Colab, short for Colaboratory, offers just that. It's a free, cloud-based platform that allows you to write and execute Python code in a Jupyter notebook environment, making it an excellent tool for both beginners and experienced practitioners. This guide will walk you through the basics of getting started with Google Colab.

What is Google Colab?

Google Colab is a product from Google Research that allows anyone to write and execute arbitrary Python code through the browser. It's especially well-suited for machine learning, data analysis, and educational purposes. With Colab, you can leverage the power of GPUs and TPUs for free, making it a popular choice for resource-intensive tasks.

Why Use Google Colab?

  1. Free Access to Powerful Hardware: Google Colab provides free access to GPUs and TPUs, which can significantly speed up computations compared to a standard CPU.
  2. No Installation Required: Being a cloud-based service, there's no need to install any software on your computer. All you need is a web browser and a Google account.
  3. Collaborative Features: Just like Google Docs, Colab notebooks can be shared and edited by multiple users in real-time, making collaboration seamless.
  4. Integration with Google Drive: You can save your notebooks directly to your Google Drive, ensuring easy access and sharing.

Getting Started

Step 1: Accessing Google Colab

  1. Open your web browser and go to Google Colab.
  2. Sign in with your Google account if you haven't already. Note, you are encouraged to use a Google account you have had for a while. Setting up new Google accounts can sometimes limit you when utilising GPUs in Colab.

Step 2: Creating a New Notebook

  1. Once on the Colab homepage, click on the New notebook button. You might get a pop-up like the image below where you can click the button New notebook in the lower left corner. If not you can always click File → New notebook.
  1. This will open a new tab with a fresh notebook where you can start writing and executing Python code.

Step 3: Changing Run-Time

When running deep-learning scripts, you will need to change from CPU to GPU. To do this, click Runtime → Change runtime type, then select T4 GPU. Then click Save.

Note: You are encouraged to sign up to Google Colab with an existing Google account. If you create a new Google account, your GPU usage may be cut off.

Step 4: Run Python on Your Notebook

  1. To execute Python code, click the ‘run’ button to the left of the cell. This is the circle with the triangle inside
  1. To change the title of your Google Colab notebook, just click on the title and rename as you wish.
  1. To save a copy of your notebook on your local computer. You can navigate to File → Download and pick the appropriate extension.

Loading Someone Else’s Google Colab Notebook

You may find yourself doing a tutorial where the creator provides you with a link to a Google Colab link. Just like in our Fine-Tuning Embedding Models Course, we provided a link to this Google Colab book.

To run external Colab notebooks, you run them as you would any notebook you’ve built yourself. Just click the run icon that’s located to the left of the cell and it will execute the code. It’s important to run each cell in succession.

When you do run the script, this message may pop up. It’s a security measure so that you understand you are running someone else’s notebook. If you trust the author, click Run Anyway.

Conclusion

Google Colab is a powerful tool that allows access to advanced computational resources. Whether you're just starting out in data science or are a seasoned professional, Colab offers a flexible, collaborative, and resource-rich environment. So, dive in, experiment, and take advantage of everything Colab has to offer!

Questions?

If you have any questions about this article then join our Slack Community and ask away!

Happy learning!

Ellie Sleightholm
Head of Software Developer Relations at Marqo