< Return to Video

Google Colab Tutorial for Beginners | Get Started with Google Colab

  • 0:00 - 0:02
    INSTRUCTOR: Google
    Colaboratory, or Colab for short
  • 0:02 - 0:05
    is the best way to get started
    with artificial intelligence
  • 0:05 - 0:06
    and data science.
  • 0:06 - 0:09
    Everything you need all the
    major libraries and tools
  • 0:09 - 0:11
    are already pre-installed for
    you and pre-set up for you.
  • 0:11 - 0:14
    So by the time it
    takes you to search
  • 0:14 - 0:15
    how to install
    another software, you
  • 0:15 - 0:19
    can already be up and running
    coding your data science
  • 0:19 - 0:21
    and artificial
    intelligence code.
  • 0:21 - 0:23
    With Google Colab, you
    can write, run, and share
  • 0:23 - 0:25
    Python code in your
    browser, and this
  • 0:25 - 0:28
    allows you to get started
    from your phone, tablet,
  • 0:28 - 0:30
    or laptop without
    any configuration,
  • 0:30 - 0:31
    and you can immediately
    share your code
  • 0:31 - 0:33
    with anyone with a simple link.
  • 0:33 - 0:36
    And everything you do in Colab
    will be saved under your Google
  • 0:36 - 0:36
    account.
  • 0:36 - 0:38
    So you can access
    them, share them,
  • 0:38 - 0:41
    just like the rest of your
    files under your Google Drive.
  • 0:41 - 0:43
    If you are familiar with
    the Jupyter Notebooks,
  • 0:43 - 0:46
    Google Colab is essentially
    a Jupyter Notebook hosted
  • 0:46 - 0:48
    on Google servers with
    additional functionalities
  • 0:48 - 0:51
    that makes it especially
    popular among data science
  • 0:51 - 0:53
    artificial intelligence
    communities.
  • 0:53 - 0:54
    So without further
    ado, let's go ahead
  • 0:54 - 0:56
    and get started with Colab.
  • 0:56 - 0:59
    So first thing you want to do
    is to search for Google Colab,
  • 0:59 - 1:03
    and it should be the one that
    says colab.research.google.com.
  • 1:03 - 1:04
    Let's go into that.
  • 1:04 - 1:07
    So the very first thing you
    should know about Google Colab
  • 1:07 - 1:10
    is that everything is
    organized under notebooks.
  • 1:10 - 1:12
    So the first thing you see
    when you come to the website
  • 1:12 - 1:14
    are basically your
    recent notebooks.
  • 1:14 - 1:16
    And the first one you
    will see will probably
  • 1:16 - 1:18
    be the Welcome to
    Colaboratory notebook.
  • 1:18 - 1:20
    So to get started, first
    thing we want to do
  • 1:20 - 1:23
    is to go ahead and
    create a new notebook.
  • 1:23 - 1:26
    So the first time you
    open a Colab notebook,
  • 1:26 - 1:29
    it will name it for
    you with untitled 0.
  • 1:29 - 1:30
    In this case, it is 3 for me.
  • 1:30 - 1:33
    And one thing you want to do
    is to rename this notebook
  • 1:33 - 1:35
    so that it's more
    meaningful to us.
  • 1:35 - 1:38
    It can be something like
    Colab Intro Tutorial.
  • 1:38 - 1:41
    Since many times, you will be
    working with multiple notebooks
  • 1:41 - 1:44
    at a time, it can be really
    helpful to appropriately name
  • 1:44 - 1:46
    your notebooks so if you
    come back to it months
  • 1:46 - 1:49
    after writing it, it will be
    descriptive and much easier
  • 1:49 - 1:52
    for you to know what you
    were doing in that notebook.
  • 1:52 - 1:54
    And everything I
    do in this notebook
  • 1:54 - 1:56
    will be saved to my Google
    Drive under my Google account.
  • 1:56 - 1:59
    So when first we take a look at
    Google Colab, the first thing
  • 1:59 - 2:01
    we will see, and the
    major thing we will see
  • 2:01 - 2:04
    is something called a code
    cell and a Play button.
  • 2:04 - 2:06
    We can go ahead and write
    some Python code here
  • 2:06 - 2:09
    and it will be executed
    not on our laptop,
  • 2:09 - 2:11
    but it will be run
    on Google servers.
  • 2:11 - 2:13
    And currently, we are not
    connected to that servers,
  • 2:13 - 2:16
    but we don't have to click
    here to be connected.
  • 2:16 - 2:18
    But instead, usually
    what you want to do
  • 2:18 - 2:21
    is to write some code here and
    it will be automatically connect
  • 2:21 - 2:23
    to Google servers.
  • 2:23 - 2:26
    So let's write a
    simple Python code.
  • 2:26 - 2:29
    Now, there are a couple of
    ways I can run this code.
  • 2:29 - 2:32
    First one and the default one
    is to click on this Play button.
  • 2:32 - 2:37
  • 2:37 - 2:39
    And we just ran our
    first Python code.
  • 2:39 - 2:42
    Usually, you'll want to
    use keyboard shortcuts.
  • 2:42 - 2:44
    And the shortcut to
    run a single cell
  • 2:44 - 2:47
    is Command Enter, which does
    the same thing as clicking
  • 2:47 - 2:48
    on that Play button.
  • 2:48 - 2:50
    But most of the
    time, chances are
  • 2:50 - 2:52
    you'll want to run a code
    cell and create a new code
  • 2:52 - 2:54
    cell under it so
    you can keep coding.
  • 2:54 - 2:57
    To do that, we will
    use Shift Enter.
  • 2:57 - 3:00
  • 3:00 - 3:01
    Which I just did.
  • 3:01 - 3:04
    Notice that there are two
    types of cells I can create.
  • 3:04 - 3:05
    One of them is a code cell.
  • 3:05 - 3:07
    And this is where
    we write our code.
  • 3:07 - 3:08
    Another one is a text cell.
  • 3:08 - 3:10
    So although it says
    text cell, text
  • 3:10 - 3:12
    is not the only thing
    we can write here.
  • 3:12 - 3:15
    Once we write some text,
    using the icons above,
  • 3:15 - 3:18
    we can turn it
    into bold, italic,
  • 3:18 - 3:20
    title, as well as
    other features,
  • 3:20 - 3:23
    such as images or videos,
    lists, and bullet points.
  • 3:23 - 3:26
    And there's actually even
    a language for that called
  • 3:26 - 3:28
    markdown language.
  • 3:28 - 3:30
    And as you're getting
    started with Colab,
  • 3:30 - 3:32
    it's not necessary to
    learn markdown language,
  • 3:32 - 3:34
    but if you are
    interested, you can
  • 3:34 - 3:37
    do that, especially later on
    in your artificial intelligence
  • 3:37 - 3:38
    or data science journey.
  • 3:38 - 3:40
    For now, what you
    should know is that we
  • 3:40 - 3:42
    can create code cells
    that are modular,
  • 3:42 - 3:45
    and we can also use text cells
    to make more explanations
  • 3:45 - 3:48
    or display images
    that will be helpful
  • 3:48 - 3:50
    and maybe explain
    our code better
  • 3:50 - 3:52
    with some rich text format.
  • 3:52 - 3:54
    So when we write code
    inside code cells,
  • 3:54 - 3:56
    we said that it's not
    running in our own laptop,
  • 3:56 - 3:58
    but it's running
    at Google servers.
  • 3:58 - 4:00
    And there are actually
    three types of servers
  • 4:00 - 4:03
    that Google can allocate to us,
    and we can change it from here.
  • 4:03 - 4:06
    If we go to Runtime and
    Change Runtime Type,
  • 4:06 - 4:08
    you will see that
    you have the option
  • 4:08 - 4:09
    to have a hardware accelerator.
  • 4:09 - 4:11
    Right now, by
    default, you are not
  • 4:11 - 4:14
    given a hardware accelerator,
    but if you need one,
  • 4:14 - 4:17
    it's possible to have
    either a GPU or a TPU.
  • 4:17 - 4:18
    So why would you need them?
  • 4:18 - 4:21
    If you're just getting started
    and writing Python code
  • 4:21 - 4:24
    or simple machine learning
    code that runs fast enough,
  • 4:24 - 4:27
    most likely, you'll be fine
    with the default version, which
  • 4:27 - 4:29
    has no hardware
    accelerator, meaning
  • 4:29 - 4:31
    that it will run on CPUs.
  • 4:31 - 4:33
    But Azure artificial
    intelligence code
  • 4:33 - 4:36
    gets larger and more complex
    as you do more operations.
  • 4:36 - 4:39
    That operations you make
    will take more time,
  • 4:39 - 4:42
    and you will want to use some
    kind of hardware accelerator.
  • 4:42 - 4:46
    And the most common hardware
    accelerator is a GPU.
  • 4:46 - 4:49
    And we have access to
    three GPUs within Colab.
  • 4:49 - 4:51
    One thing you will
    notice is that when
  • 4:51 - 4:53
    you change the hardware
    accelerator type from none
  • 4:53 - 4:57
    to GPU or a TPU, it
    will basically tell you
  • 4:57 - 5:00
    that if you don't need
    a hardware accelerator,
  • 5:00 - 5:02
    do not use a
    hardware accelerator.
  • 5:02 - 5:06
    And this way, Google can
    allocate its GPUs or TPUs
  • 5:06 - 5:08
    to people who need more
    computational power.
  • 5:08 - 5:11
    For now, I'm just writing
    simple Python code
  • 5:11 - 5:12
    so I can change it to none.
  • 5:12 - 5:14
    One thing you should
    know is that when
  • 5:14 - 5:16
    you leave your notebook
    unused for hours,
  • 5:16 - 5:19
    your notebook will be
    disconnected from Google servers
  • 5:19 - 5:21
    to more efficiently
    allocate its resources.
  • 5:21 - 5:22
    But do not worry.
  • 5:22 - 5:24
    When that happens,
    all of your code
  • 5:24 - 5:26
    will be still safe and
    nothing changed on them.
  • 5:26 - 5:28
    But you will need
    to rerun your code.
  • 5:28 - 5:33
    And to do that, you can also
    do it from Runtime and Run All.
  • 5:33 - 5:37
    So we talked about CPUs and
    GPUs that you can connect to,
  • 5:37 - 5:39
    but there is also
    another one which
  • 5:39 - 5:42
    we can access from Change
    Runtime Type and Hardware
  • 5:42 - 5:44
    Accelerator, and that was TPU.
  • 5:44 - 5:47
    And TPUs are Tensor
    Processing Units.
  • 5:47 - 5:50
    And do not be
    scared by the name.
  • 5:50 - 5:53
    These are basically processing
    units or processing chips
  • 5:53 - 5:57
    that are specifically designed
    for significantly accelerating
  • 5:57 - 5:58
    artificial intelligence code.
  • 5:58 - 6:02
    And we also have free
    access to them from Colab.
  • 6:02 - 6:04
    And this can be
    especially useful
  • 6:04 - 6:06
    if you have larger
    machine learning
  • 6:06 - 6:08
    models or artificial
    intelligence models.
  • 6:08 - 6:10
    But if you are using
    a smaller model,
  • 6:10 - 6:13
    you will be most likely
    fine with the GPU
  • 6:13 - 6:16
    or non-hardware accelerator.
  • 6:16 - 6:18
    So until now, we just
    seen Python code,
  • 6:18 - 6:21
    but we didn't see anything about
    data science, machine learning,
  • 6:21 - 6:23
    or artificial intelligence code.
  • 6:23 - 6:26
    But one of the major advantages
    of using Google Colab
  • 6:26 - 6:29
    is that you can't only code
    Python code in the browser,
  • 6:29 - 6:31
    but all of the
    major data science
  • 6:31 - 6:33
    and artificial intelligence
    libraries and tools
  • 6:33 - 6:36
    come already
    pre-installed in Colab.
  • 6:36 - 6:39
    And we can start using them
    with import statements such as--
  • 6:39 - 6:45
  • 6:45 - 6:49
    so in order to use TensorFlow,
    NumPy, pandas, matplotlib,
  • 6:49 - 6:51
    and PyTorch, and
    many more of them,
  • 6:51 - 6:53
    since they are already
    pre-installed for us,
  • 6:53 - 6:56
    we can start using them with
    these import statements.
  • 6:56 - 6:58
    And if you want, we can
    also check their versions.
  • 6:58 - 7:02
  • 7:02 - 7:05
    And as you can see, we're
    using the latest versions
  • 7:05 - 7:09
    of the libraries, such as
    using TensorFlow 2.4, which is
  • 7:09 - 7:10
    the latest one as of right now.
  • 7:10 - 7:14
    And if you're not familiar with
    any of these, do not worry.
  • 7:14 - 7:15
    As you get started
    with Colab, it
  • 7:15 - 7:18
    will be much easier to learn
    them as you're coding them.
  • 7:18 - 7:20
    So as you're getting
    started, you're not
  • 7:20 - 7:21
    required to know
    what this code does
  • 7:21 - 7:24
    or what are these
    libraries are about,
  • 7:24 - 7:26
    and you can learn them
    one video at a time.
  • 7:26 - 7:28
    And every now and
    then, you will want
  • 7:28 - 7:31
    to use libraries that
    are not inside Colab.
  • 7:31 - 7:32
    And when you want
    to do that, you
  • 7:32 - 7:37
    will want to prefix your code
    with an exclamation mark.
  • 7:37 - 7:41
    And with that, you can install
    other libraries to Colab
  • 7:41 - 7:41
    as well.
  • 7:41 - 7:43
    And when you want
    to use them, you
  • 7:43 - 7:47
    can start using them with
    import statements as well.
  • 7:47 - 7:49
    So as you are working
    within a notebook,
  • 7:49 - 7:50
    if you want to create
    a new notebook,
  • 7:50 - 7:53
    you can do that from
    File and New Notebook.
  • 7:53 - 7:56
    And similar notebook actions,
    such as opening the existing
  • 7:56 - 7:58
    ones, you can also do
    them from here as well.
  • 7:58 - 8:02
    A lot of the times, many of the
    machine learning, data science,
  • 8:02 - 8:05
    or artificial intelligence
    codes are written in Colab,
  • 8:05 - 8:08
    and when you're learning from
    them, one thing you want to do
  • 8:08 - 8:10
    is to save a copy in Drive.
  • 8:10 - 8:12
    And when you save
    a copy in Drive,
  • 8:12 - 8:14
    you can have a copy
    of that tutorial
  • 8:14 - 8:18
    and save it under your
    Google Drive as well.
  • 8:18 - 8:21
    And if I do that, I
    will have all the code
  • 8:21 - 8:24
    from that previous notebook,
    except in this one,
  • 8:24 - 8:25
    I am not connected.
  • 8:25 - 8:27
    Which I can connect
    in a second as well.
  • 8:27 - 8:29
    And I will have
    this title change
  • 8:29 - 8:33
    to a copy of Colab Intro
    Tutorial from Colab Intro
  • 8:33 - 8:34
    Tutorial.
  • 8:34 - 8:37
    And if I want to run
    this code, you can either
  • 8:37 - 8:40
    run that code cell
    by cell or you
  • 8:40 - 8:43
    can run that from
    Runtime and Run
  • 8:43 - 8:49
    All, which will run all
    the cells sequentially.
  • 8:49 - 8:51
    And that's one of
    the reasons why
  • 8:51 - 8:54
    Colab is so popular among
    data science and machine
  • 8:54 - 8:55
    learning communities.
  • 8:55 - 8:57
    And you can find
    a lot of tutorials
  • 8:57 - 9:00
    are written in Colab for
    ease of shareability,
  • 9:00 - 9:03
    because you can literally
    share them with a single link,
  • 9:03 - 9:06
    and everyone that has an
    internet connection and a Google
  • 9:06 - 9:08
    account can have
    access to that code
  • 9:08 - 9:13
    and run them themselves,
    as well as modifying it.
  • 9:13 - 9:15
    And if you want to
    download the notebook,
  • 9:15 - 9:18
    you can also do that from here.
  • 9:18 - 9:21
    Under File, you can go
    Download this notebook
  • 9:21 - 9:25
    as a ipynb file, which is
    what we are using here.
  • 9:25 - 9:28
    And you can also download
    it as a Python file.
  • 9:28 - 9:30
    One thing you should know
    is that currently, we
  • 9:30 - 9:34
    are working with the ipynb
    file, and this is the same file
  • 9:34 - 9:37
    format that you use
    in Jupyter Notebooks.
  • 9:37 - 9:40
    And ipynb files are more popular
    with data science and machine
  • 9:40 - 9:44
    learning because they have
    additional capabilities on top
  • 9:44 - 9:45
    of Python files.
  • 9:45 - 9:47
    Some of those features
    are code cells,
  • 9:47 - 9:50
    which you can save your
    outputs of the code cells.
  • 9:50 - 9:53
    You can also change the
    order of the code cells
  • 9:53 - 9:56
    more easily from this
    up or down arrows.
  • 9:56 - 9:58
    You can delete
    them, comment them,
  • 9:58 - 10:00
    and they're overall in
    a more modular structure
  • 10:00 - 10:03
    that are a better fit for data
    science and machine learning
  • 10:03 - 10:04
    code.
  • 10:04 - 10:06
    So these were everything
    you needed to get
  • 10:06 - 10:08
    started with Google Colab.
  • 10:08 - 10:11
    As you just have seen, you can
    just search for Google Colab
  • 10:11 - 10:14
    and get coding within
    seconds without any setup.
  • 10:14 - 10:17
    And everything you do will be
    saved under your Google account
  • 10:17 - 10:19
    and you can reach them
    from your Google Drive
  • 10:19 - 10:21
    and share them
    with a single link.
  • 10:21 - 10:22
    So this was it
    for this tutorial.
  • 10:22 - 10:24
    If you learn better by
    reading, by the way,
  • 10:24 - 10:27
    I also have this tutorial
    in article format as well,
  • 10:27 - 10:30
    and I will make sure to put a
    link to it in the description
  • 10:30 - 10:30
    box.
  • 10:30 - 10:32
    With that, I hope you got
    some value out of this video.
  • 10:32 - 10:34
    If you want to see
    more machine learning
  • 10:34 - 10:36
    and artificial
    intelligence tutorials,
  • 10:36 - 10:40
    make sure to like and subscribe,
    and I will see you next time.
Title:
Google Colab Tutorial for Beginners | Get Started with Google Colab
Description:

more » « less
Video Language:
English
Duration:
10:39

English subtitles

Revisions