PyTorchで始めるディープラーニング入門

PyTorchで学ぶIntroduction to Deep Learning

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

ディープラーニングはあらゆる所に!

地球の周りに複数の言語が描かれたイラスト

PyTorchで学ぶIntroduction to Deep Learning

ディープラーニングはあらゆる所に!

地球と言語、そして自動運転車のイラスト

PyTorchで学ぶIntroduction to Deep Learning

ディープラーニングはあらゆる所に!

地球と言語、自動運転車、医療診断のイラスト

PyTorchで学ぶIntroduction to Deep Learning

ディープラーニングはあらゆる所に!

地球と言語、自動運転車、医療診断のイラスト

PyTorchで学ぶIntroduction to Deep Learning

ディープラーニングとは?

ディープラーニングが機械学習の一部であることを示すオニオン図

小さなニューラルネットワークの図

PyTorchで学ぶIntroduction to Deep Learning

ディープラーニングとは?

ディープラーニングが機械学習の一部であることを示すオニオン図

複数の層を持つニューラルネットワークの図

PyTorchで学ぶIntroduction to Deep Learning

ディープラーニングのネットワーク

$$

  • 人間の脳の学習から着想

脳を学習する人のイラスト

PyTorchで学ぶIntroduction to Deep Learning

ディープラーニングのネットワーク

$$

  • 人間の脳の学習から着想
  • ニューロン → ニューラルネットワーク
  • モデルには大量のデータが必要
  • 少なくとも数十万件のデータポイント

ニューロンに焦点を当てた、脳を学習する人のイラスト

PyTorchで学ぶIntroduction to Deep Learning

PyTorch: ディープラーニング向けフレームワーク

$$

$$

  • 最も人気のあるフレームワークの一つ
  • 元はMeta AIが開発、現在はLinux Foundationに所属
  • 直感的で使いやすい
  • NumPyに似ている

 

PyTorchのロゴ

PyTorchで学ぶIntroduction to Deep Learning

PyTorchのテンソル

$$

  • テンソル:
    • 配列や行列に類似
    • ニューラルネットの基本要素

$$

import torch

my_list = [[1, 2, 3], [4, 5, 6]] tensor = torch.tensor(my_list) print(tensor)
tensor([[1, 2, 3],
        [4, 5, 6]])
PyTorchで学ぶIntroduction to Deep Learning

テンソルの属性

  • テンソルの形状
my_list = [[1, 2, 3], [4, 5, 6]]
tensor = torch.tensor(my_list)
print(tensor.shape)
torch.Size([2, 3])
  • テンソルのデータ型
print(tensor.dtype)
torch.int64
PyTorchで学ぶIntroduction to Deep Learning

テンソル演算の基礎

形状が互換

a = torch.tensor([[1, 1], 
                  [2, 2]])

b = torch.tensor([[2, 2], 
                  [3, 3]])
  • 加算 / 減算
print(a + b)
tensor([[3, 3],
        [5, 5]])

形状が非互換

a = torch.tensor([[1, 1], 
                  [2, 2]])

c = torch.tensor([[2, 2, 4], 
                  [3, 3, 5]])
  • 加算 / 減算
print(a + c)
RuntimeError: The size of tensor a
(2) must match the size of tensor b (3) 
at non-singleton dimension 1
PyTorchで学ぶIntroduction to Deep Learning

要素ごとの乗算

a = torch.tensor([[1, 1], 
                  [2, 2]])
b = torch.tensor([[2, 2], 
                  [3, 3]])
print(a * b)
tensor([[2,  2],
        [6, 6]])
PyTorchで学ぶIntroduction to Deep Learning

行列積

行列の積

PyTorchで学ぶIntroduction to Deep Learning

行列積

行列積の強調表示

$$

  • $1 \cdot 2 + 1 \cdot 3 = 5$

$$

  • 加算と乗算でデータを処理し、パターンを学習
PyTorchで学ぶIntroduction to Deep Learning

Let's practice!

PyTorchで学ぶIntroduction to Deep Learning

Preparing Video For Download...