How to test Jupyter notebook from Github via Google Colab

How to test Jupyter notebook from Github via Google ColabSteve TanBlockedUnblockFollowFollowingMar 24While 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!Every time you see the word Github, you can start to say yee-hah!Fire up google colab here, and this should be the first thing that you would see.

Google Colab — in dark themeNavigate 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.

The notebook is inside the ensemble folderIf you click on the link to that file within Github you would realize that the notebook format is also supported directly there.

The code are properly formatted along with any output is shown when you last save the notebookCopy 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.

Code and output reloaded all in it’s glory under the cool looking dark themeTo 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 drivedrive.

mount(‘/content/drive’)You will be warned that the notebook isn’t authored by Google, but since you know where it came from, that should be safe enough to run this code.

Ignore the warning and click Run Anyway to proceed.

A URL will be generated which allows you to safely log into your Google Drive to access the files thereClick Allow to continueCopy the code and paste it back into the notebookPaste the code and hit CTRL + Enter to continueClick on File then Refresh to see the drive folder appearingLocate the file in your Google Drive directory and you can now interact with them in the notebook.

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.

You can create a public access notebook by using the Share button on topOne 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!Create a new notebook and use the git clone command based on the Github repo that you want to clone fromYou 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.

Clone the whole repository to your Google Colab session with !git clone https://github.


gitChange the path to point to the correct folder and run it like usualTo wrap this up, here’s the notebook that was used for the above quick tutorial as reference.

Hope this helps! Happy Colab-borating :).

. More details

Leave a Reply