In this lecture we are going to go over a very new and exciting environment for writing deep learning
code in Python which is Google's core lab short for code laboratory.
For those of you who like to use Jupiter notebook this is an even better option.
This is basically the same as you put a notebook with the following bonuses first.
It's hosted by Google which means you don't have to use your own computing power.
You'll notice that when you need to download data files it happens extremely quickly because while Google's
network is extremely fast.
Second you get access to a GP you and even Google's new TB you which is pretty amazing a tepee you is
not something you can buy for your personal computer.
So it's pretty nice to be able to make use of one.
Remember that the way pi torch code is written you don't have to worry about what kind of device you're
using.
Well for the most part TB you is another story.
But generally speaking the same code will work whether you're using a CPA you or a GP you third the
code lab notebooks are stored in your google drive.
So it's in the cloud.
You'll never lose it and it's very easy to share with other people.
Fourth is that many of the libraries you need for a deep learning machine learning and data science
are already included.
In fact I was surprised that there were many more than I assumed there would be.
There are even competing Deep Learning libraries already included such as piano and Pi torch.
So for those of you who hate doing environments set up myself included this is really truly awesome.
So in this lecture we're not going to do anything really technically complicated.
Rather we're just going to talk about Google collab and do some short demos.
So you know how it works and can see for yourself that it's just like writing Python anywhere else to
start.
I'm going to assume you already know how to create a Google Drive account if you don't have one go to
drive dot google dot com and sign up
once you have your google drive account and you've logged in you'll see this interface from here.
You can hit the new menu which allows you to create all different kinds of files such as Google Docs
a spreadsheet a presentation and so forth.
So let's do this.
So now what you want to do is go to the more menu and hit code laboratory.
All right.
So as you can see this brings up a new notebook.
And from here you can mostly use this as you would a normal notebook.
Now one thing that might happen to you is that you might not see cool laboratory in the menu at all.
So as you can see I've hit the new menu and I've hit more but I don't see color in this case.
Here's what you can do.
You want to select connect more apps from here.
Just search for collab.
And the first thing that will pop up is Google's collab add this and Google Ecolab will become available
from the menu.
We just looked at
so if we go there again we can see that cold app and now appears where it should
so let's go in and rename this notebook to TAF 2.0 intro.
So first we're gonna get right to the good stuff.
How can we make use of a GP you or you in order to do this.
You want to go to the runtime menu and select change runtime type
as you can see there are two select boxes here.
The first one lets you select which python version you want to use.
So we'll be using Python 3 for this course.
The second lets you select what kind of device you want to use.
So that's either none which is the default or GP you or TB you now note that sometimes the GP you or
TB you might not be available.
This is because these are shared resources so your fellow peers taking this course and other machine
learning students and researchers all around the world might be using Google whole app and we are all
sharing these resources.
So if our usage of these resources hits the limit of what's available then you might not have a GP you
or you available when you need them.
For this reason some of the code you'll see in this course may be done on my local machine as well.
But remember Python code works the same anywhere so it does not make a difference
next.
You can see that there are two main types of cells that we can create in the notebook code and text.
You can click on either of these to create a new cell of that type let's click on text since that's
a little easier and it's not really something we are going to use very often.
So let's just get it out of the way
so I'm actually going to delete the very first cell
all right.
So as you can see when I click this it creates a new cell with what looks like a rich text editor.
You'll notice that it's split into halves the left half is where you enter your text and the right half
is a preview of what it will look like.
So let's enter some text.
This is my title now you can click the little T Big T icon which changes it into header text so you
can see that it makes this a little bigger and bolder appropriate for a title next let's enter some
regular text.
This is regular text
and note that there are also these arrow brackets so it looks like it's going to let us enter code snippets.
So let's try that.
And so as you can see it makes the text a mono space font which is appropriate for code.
Now there are some other options here.
So you can make a link you can add images you can indent.
You can add a numbered or bullet list and so forth.
So if you're interested play around with this.
Otherwise we're not going to mention it again.
Next we have the code cell.
So let's create one of those.
All right.
And as mentioned we're not going to write any fancy code in this lecture.
We just want to do something simple to make sure everything works as expected.
So let's start by importing num pi and map plot lib
all right beautiful.
As I mentioned earlier these already come pre installed next let's create a new code cell and make a
sine wave.
So first we need to create some x values so let's make X go from zero to 10 pi with 1000 points in between
next let's make Y.
The sign of X
next let's create a new cell and plot what we just created so that's just peels heat up plot x y
now.
Since this is a notebook there's no need to call people to you that show since the plot will just appear
in the notebook itself.
All right.
Very cool.
Works just like a regular notebook
at this point.
We've convinced ourselves that Google collab can do the usual things you'd expect from a group a notebook.
Now as I mentioned earlier one thing that's very nice about COLA is that it already comes with a bunch
of useful libraries pre installed.
In my opinion this makes Google collab way better than Jupiter notebook.
And if anyone ever asked me to write in a notebook environment I would choose color by default.
I'm not a big fan of notebook but I am a big fan of collab
so here we can see that I've written some code to try and import a bunch of libraries specifically these
libraries are libraries that have been using my causes some more than others.
Some are pretty rarely used so you might not expect that they would be included.
Libraries like word cloud which we've only used once so far and yet if we look we see that everything
I've tried to import here does not throw an error so this tells us that these libraries are indeed available.
What's interesting to me is that some of these libraries are not machine learning related at all.
Of course we've used them in my courses because they are generally useful as Python libraries but it's
nice to see the folks at Google also make use of these same libraries.
And so thought to include them.
So here you can see the usual stuff such as psychic learn name pi PSI pi map plot lib and pandas.
We also have torch and piano which is surprising because they are competing Deep Learning libraries
and development for the ATO has been stopped for a while now.
We also have seaborne word cloud beautiful soup which is for X amount CML passing requests which is
for making a CTP cause network X which is for graph functionality CV 2 which is for open CV and gym
which is open a gym.
All in all very impressive and much more than I expected.
So there's some final caveats to Colette that I want to mention first.
The main thing you have to remember is that this is the cloud.
So these are shared resources.
So one way this affects you is if you leave your notebook alone for a long time it will become inactive
and disconnect any computation that you may have run earlier won't be saved.
So for example if you define a variable A equals five AND THEN YOU COME BACK LATER AFTER your notebook
was disconnected and you tried to print a it'll say a is not defined so you see this notebook has disconnected.
So let's say to reconnect and I print a it's going to say a is not defined
another way this affects you is that you might run out of memory.
So if that happens you might want to try running the code on your local machine instead.
And as mentioned earlier the GP you A.P. you might be unavailable.
So either you can run your code without the GP you or TB you or you can run the same code locally as
always options you had previously are still available for example you can provision a GP you instance
on a W.S. which if you choose the correct EMI or Amazon machine instance will come with the usual libraries
pre installed also.