While researching for a working solution for the Kaggle competition NDSC Shopee beginner, I’ve stumbled upon many interesting and working solutions which often times can be found in Jupyter notebook online stored securely in someone’s Github repository.
And as I’m the kind of learner that prefers execution code first before I’m able to follow along with the theory or the reasoning behind the author’s mind, I always find things easier to be done if I can break the code down into digestible chunks for myself to play with and Google Colab helps with this task tremendously, so I wanted to write a simple tutorial here for those who haven’t started to leverage on this beautiful tool.
If you haven’t already, I would urge you to sign up for a Google account just so that you can store all the notebooks which you have used before as well as having access to Google drive which you can use to store any data files to run the notebook with.
For the rest of this tutorial, I will use the notebook shared by the fourth place solution which he has kindly published on the discussion thread. Thanks Tung!
Fire up google colab here, and this should be the first thing that you would see.
Navigate into his Github repository until you find files with the *.ipynb extension. Those are Jupyter notebook files which you would soon learn to love very much.
If you click on the link to that file within Github you would realize that the notebook format is also supported directly there.
Copy that full url and paste it in your colab and hit enter for it to start searching. Select the notebook that you want to open to have Colab open and run it for you.
Once the file is loaded this is what you should be seeing.
To add extra juice to your colab you’re allowed to set the runtime to use GPU! Go to Runtime → Change runtime type.
Select GPU or TPU (Tensor Processing Unit — which in my experience sometimes can be slower than GPU) and click save.
So the next hairy part is how do you get your data to be linked to your colab notebook?
A simple approach would be to add this two line into a new Code chunk.
Click on the + Code on the top left and execute this two lines by clicking on the play button to the left of the code box.
from google.colab import drive
drive.mount(‘/content/drive’)
Ignore the warning and click Run Anyway to proceed.
To share this notebook, either use the Share link on the top right or copy the full URL to someone and let them request access for the notebook. So if you want to access this notebook, here’s the link.
One final note, the other really cool thing about colab is that you’re allowed to import or install whatever you need, just use the ! prefix to the command on a code block. For example if you need to install the keras module then just type !pip install keras. And if you want to do anything more advanced, feel free to google it up with google colab + whatever you’re trying to do.
So with that actually if you’re able to find a complete github repo with all the necessary data, you’re also able to git clone the whole repo to Google colab but without saving the files to your Google drive, the session plus all the files will be reset when the session ends. So be warned!
You can find out the correct github command to use from the Github repo. After the git clone is complete, you’re able to access the whole repository under the Files.
To wrap this up, here’s the notebook that was used for the above quick tutorial as reference.
Hope this helps! Happy Colab-borating :)