0Pricing
Deep Learning Academy · Lesson

Notebooks, Scripts & Reproducible Seeds

Set random seeds so results repeat.

Notebooks, Scripts & Reproducible Seeds is a free Deep Learning Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Deep Learning Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Two Ways to Work

You will write code in notebooks for quick experiments and in plain scripts for repeatable runs. Each suits a different moment.

Notebooks for Exploring

A notebook runs code in cells, showing plots and results inline. It is perfect for poking at data and trying ideas fast. 📓

Scripts for Real Runs

A script runs top to bottom in one go. Use it for training jobs you want to launch, share, and reproduce exactly.

python train.py

Watch Out for Cell Order

Notebook cells keep state even when you run them out of order, which can hide bugs. A script always starts from a clean slate.

The Reproducibility Problem

Deep learning uses random numbers for weights and shuffling. Run twice and you get different results unless you control that randomness.

Seeds to the Rescue

A seed fixes the starting point of the random number generator, so the same code produces the same numbers every single run.

Seed PyTorch

Set PyTorch's generator with one call. manual_seed makes weight initialization and any torch randomness repeatable.

torch.manual_seed(42)

Don't Forget NumPy and Python

Your code often pulls randomness from NumPy and Python too, so seed all three to make a run fully reproducible.

import numpy as np, random
np.random.seed(42)
random.seed(42)

Seed the GPU Too

When you train on CUDA, also seed the GPU generators. cuda.manual_seed_all covers every GPU device in your machine.

torch.cuda.manual_seed_all(42)

Wrap It in a Function

Bundle every seed call into one set_seed helper. Call it at the top of each run so you never forget a source of randomness.

def set_seed(s):
    torch.manual_seed(s)
    np.random.seed(s)

Why It Matters

Reproducible runs let you compare experiments fairly. If accuracy improves, you know it was your change, not random luck.

Quick Check

Recall what makes a run repeatable.

Recap

You saw when to use notebooks versus scripts and how seeding torch, NumPy, and Python makes every run reproducible. 🌱

Frequently asked questions

Is the “Notebooks, Scripts & Reproducible Seeds” lesson free?

Yes — the full text of “Notebooks, Scripts & Reproducible Seeds” is free to read here on the web, and the Deep Learning Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Deep Learning Academy course, upgrade to CoddyKit PRO.

What will I learn in “Notebooks, Scripts & Reproducible Seeds”?

Set random seeds so results repeat. You practise Deep Learning Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Deep Learning Academy?

No prior experience is required. Deep Learning Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Notebooks, Scripts & Reproducible Seeds” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Deep Learning Academy lesson?

Yes. Every Deep Learning Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Install PyTorch and Verify It Imports
  2. CPU vs GPU vs MPS: Pick a Device
  3. Notebooks, Scripts & Reproducible Seeds
  4. Your First torch.tensor
← Back to Deep Learning Academy