0Pricing
Deep Learning Academy · レッスン

ノートブック、スクリプト、再現可能な乱数シード

乱数シードを設定して、結果を再現できるようにします

「ノートブック、スクリプト、再現可能な乱数シード」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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. 🌱

よくある質問

「ノートブック、スクリプト、再現可能な乱数シード」レッスンは無料ですか?

はい。「ノートブック、スクリプト、再現可能な乱数シード」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。

「ノートブック、スクリプト、再現可能な乱数シード」で何を学びますか?

乱数シードを設定して、結果を再現できるようにします ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Deep Learning Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「ノートブック、スクリプト、再現可能な乱数シード」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDeep Learning Academyレッスンでコードを書いて実行できますか?

はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. PyTorchをインストールしてインポートを確認する
  2. CPUとGPUとMPS:デバイスを選ぶ
  3. ノートブック、スクリプト、再現可能な乱数シード
  4. はじめてのtorch.tensor
← Deep Learning Academyに戻る