# Lab Manual

course: Module 1 — Foundations of AI & ML
module: Module-1-Foundations-AI-ML
type: pdf
source_url: https://personal-learn.armco.dev/files/Module-1-Foundations-AI-ML/General/Lab_Manual.pdf
pages: 10

---
[page 1]
Google Colab Lab Manual for Beginners         
Gen AI by IIT Roorkee, powered by Futurense 
Welcome, future AI innovators! This manual is your guide to mastering Google Colaboratory (Colab). 
Colab is a powerful and free tool from Google that lets you write and run Python code directly in 
your web browser. It’s especially fantastic for learning and building projects in Artificial Intelligence 
(AI) and Machine Learning (ML) because you don’t need a super-powerful computer or go through 
complicated setup processes. 
 
1. Why Use Google Colab? (The Advantages for You)     
Google Colab offers many benefits, making it an excellent choice for students: 
• Free Access to Computing Power: Get free access to CPUs, and more importantly, powerful 
GPUs (Graphics Processing Units) and TPUs (Tensor Processing Units). These are essential for 
training AI models but can be expensive to buy. Colab levels the playing field! 
• Zero Configuration Setup: Forget about installing Python, managing complex environments, 
or struggling with library installations like TensorFlow or PyTorch. Colab comes ready to go! 
• Collaboration Made Easy: Share your notebooks with classmates or instructors with a simple 
link. You can even work on the same notebook together in real-time, just like Google Docs. 
• Seamless Google Drive Integration: Your notebooks and files can be easily saved to and 
loaded from your Google Drive. No more worrying about losing your work. 
• Pre-installed Libraries: Most common AI, ML, and data science libraries (Pandas, NumPy, 
Matplotlib, Scikit-learn, etc.) are already installed. 
• Work From Anywhere: All you need is a web browser (like Chrome) and an internet 
connection. Access your work from any computer. 
 
2. Getting Started: Accessing Colab   
• Google Account: You’ll need a Google account (your Gmail account works perfectly). 
• How to Reach Colab: 
• In LMS go to the particular course. 
• Under Lab access, click the given link for lab.

[page 2]
• You can also try the following steps: 
• Open your web browser. 
• Search for “Google Colab” on Google. 
• Click the official link, usually colab.research.google.com. 
• The Welcome Screen: When you first open Colab, you’ll often see a welcome pop-up. This is 
your launchpad! 
 
• Tabs on the Welcome Screen: 
• Examples: Explore pre-made notebooks to see what Colab can do. 
• Recent: Quickly open notebooks you’ve worked on recently. 
• Google Drive: Access notebooks stored in your Google Drive. 
• GitHub: Load notebooks directly from GitHub repositories. 
• Upload: Upload notebook files (.ipynb) from your computer. 
 
3. Understanding the Colab Notebook

[page 3]
• What is a Notebook?: Think of it as an interactive document. It’s not just a plain text file or a 
code script. A Colab notebook can contain: 
• Live, runnable Python code cells. 
• Text cells with explanations, headings, images, and even mathematical formulas. 
• The output of your code (like graphs, tables, or text results) directly below the code that 
produced it. 
• File Extension: Colab notebooks use the .ipynb extension (which stands for Interactive 
Python Notebook). This is the same format used by Jupyter Notebooks. 
 
4. The Colab Interface at a Glance         
When you open or create a notebook, you’ll see this interface: 
 
• Menu Bar (Top): Contains important menus like: 
• File: For creating, opening, saving, uploading, and downloading notebooks. 
• Edit: For cell operations, find and replace. 
• View: To customize what you see (e.g., table of contents). 
• Insert: To add new cells or special items like code snippets. 
• Runtime: To run your code, manage the computing environment (like changing to GPU/TPU), 
and restart sessions. 
• Tools: For settings, keyboard shortcuts, and command palette. 
• Help: For documentation and support. 
• File Name Area (Top Left): Shows the name of your notebook. Click here to rename it.

[page 4]
• Left Sidebar: Contains icons for: 
• Table of Contents: Helps you navigate through your notebook sections. 
• Code Snippets: Useful pre-written pieces of code for common tasks. 
• Files: Lets you see and manage files in your current session storage and your mounted 
Google Drive. 
• Main Work Area: This is where your cells (code and text) live. 
 
5. Working with Cells: The Building Blocks             
Cells are where the magic happens in your notebook. 
• Two Main Types of Cells: 
• Code Cells: 
• This is where you write your Python code. 
• It has a play button (  ) to its left. Click this (or use keyboard shortcuts) to run the code. 
• The output of the code will appear directly below the cell. 
 
• Text Cells: 
• Used for writing explanatory text, headings, notes, adding images, links, or mathematical 
equations using a simple formatting language called Markdown. 
• Double-click on a text cell to edit it. A toolbar will also appear for easy formatting. 
] 
• Adding New Cells: 
• Hover your mouse pointer below an existing cell or at the very top/bottom of the notebook. 
• Click the + Code or + Text buttons that appear.

[page 5]
• Running Code Cells: 
• Play Button: Click the    icon to the left of the cell. 
• Shift + Enter: Runs the current cell and automatically moves to the next cell (or creates a new 
one if you’re at the end). This is very commonly used! 
• Ctrl + Enter: Runs the current cell and keeps your cursor in the current cell. 
• Moving and Deleting Cells: 
• Select a cell. You’ll see up/down arrows in the top right of the cell to move it. 
• There’s also a trash can icon (   ) to delete the selected cell. 
• You can also find these options in the Edit menu. 
 
6. Managing Notebooks: Opening, Uploading, and Saving    
You’ll frequently need to create, open, and save your work. 
• Creating a New Notebook: 
• Go to File > New notebook. 
• Opening Existing Notebooks: 
• From Google Drive: 
• On the Welcome Screen, click the Google Drive tab and select your notebook. 
• Or, go to File > Open notebook… and choose the Google Drive tab.

[page 6]
• From GitHub: 
• On the Welcome Screen, click the GitHub tab, enter the repository URL, and select the 
notebook. 
• Or, go to File > Open notebook…, choose the GitHub tab, and provide the GitHub URL. 
 
• From Your Recent Files: 
• The Welcome Screen’s Recent tab is the quickest way to open files you’ve recently worked 
on. 
• Uploading a Notebook from Your Computer:

[page 7]
• If you have an .ipynb file on your computer (e.g., downloaded from somewhere or from a 
local Jupyter setup): 
• Go to File > Upload notebook… 
• Or, on the Welcome Screen, click the Upload tab. 
• Click “Choose File” and select the .ipynb file from your computer. 
• When you upload a notebook, it’s typically saved into your Google Drive’s Colab Notebooks 
folder. 
• Saving Your Work: 
• Autosave: Colab automatically saves your work to Google Drive periodically. 
• Manual Save: 
• File > Save (or Ctrl + S / Cmd + S) to save the current state. 
• File > Save a copy in Drive: Useful for creating a checkpoint or a new version of your 
notebook. 
 
7. Essential Colab Features for Beginners       
• Managing Files in Your Session: 
• Files Sidebar: Click the folder icon (  ) on the left sidebar to open the file browser. 
• Here you can see temporary files in your current Colab session (like sample_data). 
• You can upload small files directly to this session storage using the upload icon (    ↑). 
 
• Mounting Google Drive for Persistent Storage (Very Important!):

[page 8]
• Files uploaded to session storage are temporary and will be lost when your session ends! 
• For permanent storage of datasets, models, or any important files, mount your Google Drive: 
• In the Files sidebar, click the “Mount Drive” icon (often looks like a Google Drive logo with a 
folder). 
• A code cell will be automatically added to your notebook. Run this cell. 
• Follow the on-screen instructions: click a link, authorize Colab with your Google account, 
copy the authorization code, and paste it back into the Colab input box. Press Enter. 
 
• Once mounted, your Google Drive will appear as a folder named drive (usually 
/content/drive/MyDrive/) in the Files sidebar. You can now read and write files to it. 
• Using Pre-installed Libraries: 
• As mentioned, many libraries are ready. Just import them: 
• Python 
                 import pandas as pd 
                 import numpy as np 
                 import matplotlib.pyplot as plt 
                 import tensorflow as tf 
• Installing New Libraries: 
• If you need a library not already installed, use !pip install in a code cell: 
• Python  
                 !pip install beautifulsoup4 
                 !pip install -q mediapipe # -q makes the output less verbose 
• Note: This installation is only for the current Colab session. If the session restarts, you’ll need 
to run the !pip install cell again. 
• Hardware Accelerators (GPU/TPU) - Power Up for AI!:

[page 9]
• For tasks like training deep learning models, a CPU can be too slow. Colab gives you free 
access to GPUs and TPUs. 
• To change your hardware: 
• Go to Runtime > Change runtime type. 
• In the “Notebook settings” dialog, select GPU or TPU from the “Hardware accelerator” 
dropdown. 
• Click Save. 
• The runtime will restart with the new hardware. Use “None” (CPU) for simple tasks to 
conserve resources. 
 
8. Sharing and Collaboration                                                    
Colab makes teamwork easy. 
• Click the Share button (usually in the top right, often blue). 
• A dialog box will appear, similar to Google Drive’s sharing options. 
 
• You can: 
• Add people by their email addresses. 
• Set their permissions: Viewer (can only see), Commenter (can comment), or Editor (can make 
changes). 
• Get a shareable link.

[page 10]
9. Runtime Explained: What’s Happening Behind the Scenes     
• What is a Runtime?: When you run code in Colab, it’s not running on your computer. It’s 
running on a virtual machine (a server) provided by Google. This virtual machine 
environment is called the “runtime.” It has its own temporary disk space and memory (RAM). 
• Runtime Disconnections: Your connection to this runtime can be lost if: 
• You leave the notebook idle for too long (e.g., 90 minutes, but can vary). 
• You close your browser or shut down your computer. 
• The maximum session duration is reached (e.g., 12 hours for free users, can vary). 
• What Happens on Disconnection?: 
• The Python variables, installed libraries (via !pip install), and files in the temporary session 
storage are lost. 
• However, your notebook itself (the code and text cells you wrote) is safe because it’s saved in 
your Google Drive. 
• Re-running Cells: After a disconnection and reconnection, you’ll need to re-run your cells 
from the top (or the ones necessary) to redefine variables, re-import libraries, re-install 
custom packages, and re-mount your Drive. 
• Managing Runtimes: 
• Runtime > Run all: Executes all cells from top to bottom. 
• Runtime > Restart runtime: Clears all variables and restarts the Python backend. Useful if 
things get stuck. 
• Runtime > Factory reset runtime: A more drastic reset, clears temporary files too.