Computers & Internet

Google Colab Tips for Beginners

Google Colab Tips for Beginners
Spread the love

Google Colab is a free & paid cloud service that allows you to run Jupyter notebooks on Google’s servers. It is a great tool for data scientists and machine learning engineers who want to use Python and other programming languages to analyze data and build machine learning models. This article is intended for beginners.

Colab, or ‘Colaboratory’, allows you to write and execute Python in your browser, with

  • Zero configuration required
  • Access to GPUs free of charge
  • Easy sharing

1. Switch the Google Colab theme to dark

If you’re one of those killer programmers you mind interested in dark mode. The dark mode is a coder’s best friend. No daylight, just dark, dark, like no-moon night.

Now, over with tonnes of philosophy and configure your colab notebook to use dark mode.

    – Tools -> Settings -> Theme -> Dark

2. Mount Google Drive

Why mount Google Drive in Google Colab?

    – To access files from Google Drive in Google Colab

    – To save files in Google Drive from Google Colab

Let’s have some action:

    – from google.colab import drive

    – drive.mount(‘/content/drive’)

3. Install packages

Why the hell does anyone ever installs packages in Google Colab when it has a lot of modules pre-installed already? Right?

Well, Sometimes your requirements are so high on, you are not interested in their default ones or want to install very specific versions or you just want to do it anyway. You can use the following syntax to do the same.

!pip install -q <package>

Let’s have some action:

    – !pip install -q kaggle

    – !pip install -q transformers

    – !pip install -q datasets

    – !pip install -q pytorch-lightning

    – !pip install -q wandb

Cool!!! Isn’t it?

4. Import packages

You’ve got a lot of packages installed in the last step “Install packages”. So, you’ve a lot of packages with you. But, in order to use those cool things inside your code you need to import them intthe o current project.

    – import os

    – import numpy as np

    – import pandas as pd

    – import matplotlib.pyplot as plt

    – import seaborn as sns

    – import torch

    – import torch.nn as nn

    – import torch.nn.functional as F

    – import torch.optim as optim

    – from torch.utils.data import Dataset, DataLoader

    – from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments

    – from datasets import load_dataset, load_metric

    – from sklearn.model_selection import train_test_split

    – from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score

    – from pytorch_lightning.callbacks import ModelCheckpoint

    – from pytorch_lightning.loggers import WandbLogger

    – import wandb

5. How to use Google Colab with GPU?

Why the hell anyone ever wanted to use Google Colab with GPU? Why to use Google Colab with GPU? Is there any specific reason?

Yes. To train deep learning models faster.

Steps:

    – Open Google Colab

    – Edit -> Notebook settings -> Hardware Accelerator -> GPU

6. How to use Google Colab with TPU?

Why the hell has anyone ever wanted to use Google Colab with TPU? Why use Google Colab with TPU? Is there any specific reason? Hee hee hee! Same questions again.

Yes. To train deep learning models faster. Obviously.

Steps:

    – Open Google Colab

    – Edit -> Notebook settings -> Hardware Accelerator -> TPU

There is a lot more about Google Colab. We’ll soon cover more interesting things regarding Colab.