Ad Code

Ticker

6/recent/ticker-posts

Introduction to Google CoLab for Beginners

Python Programming using Google CoLab

Introduction 

Google CoLab is a free cloud-based platform provided by Google which enables users to write Python code in a web browser. This does not require setting up a local environment on a user's machine  Practitioner's and data scientists who can specially benefit from computational resources provided by Google like running your code on a GPU (Graphics Processing Unit)  or a TPU (Tensor Processing Unit). This is quite useful as the use of such resources can significantly speed up the processing of complex data science applications. In this blogpost we are going to walk you through the basics of using the Google CoLab.

Starting Google CoLab
  1. For starting Google Google CoLab one has to sign into by using a Google account by visiting the url: https://colab.research.google.com/. In case the user doesn't have a google account then one will have to be created for using Google CoLab.
  2. The next thing to do is to create a notebook inside Google CoLab for writing and executing code.
Fig 1: Creating a Google CoLab Notebook after Signing in


 Notebook Basics

Cells
    A Colab notebook consists of cells. Each cell can contain either code or text.
    To add a new cell, click on the "+" next to the code or text button in the toolbar to create the relevant cell..
    
    
Code Cells
    You write and execute Python code inside the code cells.
    After writing your Python code in a code cell simply press Shift + Enter to execute it.
    Alternatively,  Ctrl + Enter can be pressed to execute a cell without moving to the next one.

Text Cells
    In the text cells you can write any type of text and apply appropriate formatting by making use of the widgets available with these cells.             

Markdown syntax.
     To create a text cell, change the cell type to "Text" from the dropdown menu in the toolbar.
    You can format text using Markdown syntax, such as bold, italic, or creating lists etc.

Working with Code

You can write the Python's print command in a cell like

print("Hello this is my first CoLab session")

and hit Ctrl-Enter and you will see the message inside the double quotes printed to the screen just below the cell.
Importing Libraries

CoLab allows you to import Python libraries just like you can don in the Python environment on your machine.
For example, to import the popular Pandas library you can simply write:
 
import pandas as pd

in a code cell and execute it.

Executing Code

Colab provides an interface which is interactive and allows to execute the code in real time.

The code cells can be executed sequentially and output of each is shown below it after execution. Usually the command Ctrl-Enter is used to execute the code within a cell.
Fig 2: Different parts of the Google CoLab interface illustrated



Using GPU/TPU
CoLab provides free access to GPU and TPU resources. 

To enable such resources to be executed with your code simply go to the Runtime menu from the menu bar then select Change Runtime Type and select GPU or TPU from the options given.

Saving and Sharing Notebooks

You can also save or share CoLab notebooks you created in the steps above.

CoLab saves a notebook by default to the google drive associated with your google account.

Alternatively, a notebook can also be saved to GitHub selecting File from the menu bar and selecting Save a copy in GitHub menu option.

Sharing Notebooks

CoLab notebooks can also be shared with other users by clicking on the "Share" button in the toolbar.

The notebook can be shared in real-time for editing, viewing or collaborating with other users. You can find a video tutorial about the above material in the following Youtube video.




Conclusion

Google Colab is a very powerful tool which can help people to write and execute Python code in the cloud. It provides free access for making use of GPU and TPU resources provided by Google to execute computationally intensive parts of your code. This makes it a more than ideal platform for machine learning and data science and their related concepts. With this beginner's tutorial, you should by now have developed a basic understanding of how to use Google's CoLab. Now you can start experimenting with your own code using the CoLab. Happy coding!
***********************************************************************************
As an amazon associate I earn from qualifying purchases (that does not affect your price)

Amazon link to Resources on Web Development and Programming (link1, Kindle Resource, link2)

***********************************************************************************
For getting a top notch business web application: Contact Us



Post a Comment

0 Comments