Slide 1

Slide 1 text

Pythonॳ৺ऀ͕PyTorchΛ͍ͬͯ͡ ػցֶशͷܭࢉΛͯ͠Έͨ Python-newbie’s machine learning learning with PyTorch ๺㝳೗๏ PyCon mini Hiroshima 2018 @޿ౡେֶ ະདྷ૑ੜηϯλʔ @2018೥10݄6೔(౔)

Slide 2

Slide 2 text

ࣗݾ঺հ

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

๺㝳೗๏ ▸ ͖͍ͨͩΏ͖ͷΓ ▸ ʮ೗๏ʯΛԻಡΈ(༗৬ಡΈ)ͯ͠ňʹΐ΄͏ʼn ▸ ϋΠύɾϝσΟΞɾτϥϯεϨʔλ ▸ ೔༵ϓϩάϥϚ

Slide 5

Slide 5 text

iPad ޿ౡห ݕࡧ ৄ͘͠͸

Slide 6

Slide 6 text

ʮ͜Μͳײ͡ͷ͕ग़͖ͯ·͢ɻʯ

Slide 7

Slide 7 text

Pythonॳ৺ऀ͕PyTorchΛ ͍ͬͯ͡ ػցֶशͷܭࢉΛͯ͠Έͨ ݁Ռwwwwwwwwww

Slide 8

Slide 8 text

Pythonॳ৺ऀ͕PyTorchΛ ͍ͬͯ͡ ػցֶशͷܭࢉΛͯ͠Έͨ ݁ՌΛൃද͠·͢ɻ

Slide 9

Slide 9 text

ʢɾ㱼ɾʣŘŘ!!

Slide 10

Slide 10 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ

Slide 11

Slide 11 text

΋͏ͪΐͬͱ ৄ͘͠

Slide 12

Slide 12 text

ຊ೔ͷϝχϡʔ ػցֶश 1Z5PSDI ΍ͬͯΈͨྫ

Slide 13

Slide 13 text

Pythonॳ৺ऀ?

Slide 14

Slide 14 text

Pythonॳ৺ऀ౓߹͍ ▸ for ͱ͔ if ͱ͔ with ͱ͔ϨϕϧͰຊɾυΩϡϝϯτɾωοτΛݟͳ͕ΒͰ ͳ͍ͱॻ͚ͳ͍ ▸ Ψνͷॳ৺ऀ

Slide 15

Slide 15 text

ػցֶश͸?

Slide 16

Slide 16 text

CourseraͷNgઌੜͷ ػցֶशͷίʔε

Slide 17

Slide 17 text

मྃ! (2016೥5݄͝Ζ)

Slide 18

Slide 18 text

͔͠΋मྃ࣌ ʹNgઌੜ͔Β

Slide 19

Slide 19 text

͔͠΋मྃ࣌ʹ Andrew Ng ઌੜ͔Β ▸ Those were the topics of this class and if you worked all the way through this course you should now consider yourself an expert in machine learning. ▸ As you know, machine learning is a technology that's having huge impact on science, technology and industry. ▸ And you're now well qualified to use these tools of machine learning to great effect. ▸ I hope that many of you in this class will find ways to use machine learning to build cool systems and cool applications and cool products. ▸ And I hope that you find ways to use machine learning not only to make your life better but maybe someday to use it to make many other people's life better as well.

Slide 20

Slide 20 text

Ngઌੜ͔Βઐ໳Ո ೝఆ͞ΕͱΔ

Slide 21

Slide 21 text

͜Γ΋͏ؒҧ͍ͳ͘Θ͠ ػցֶशͷઐ໳Ո Ͱ͢(ތுදݱ)

Slide 22

Slide 22 text

1. ػցֶश

Slide 23

Slide 23 text

ػցֶशͱ͸ ▸ ͬ͘͟Γ ▸ ڭࢣ͋Γֶश (supervised learning) ▸ ڭࢣͳֶ͠श (unsupervised learning)

Slide 24

Slide 24 text

ػցֶशͱ͸ ▸ ͍ΖΜͳσʔλͷഎޙʹજΉ๏ଇͱ͔ߏ଄ΛɺऔΓग़ͦ͏ͱ͢Δܭࢉ ▸ ͬ͘͟Γ ▸ ڭࢣ͋Γֶश (supervised learning) ▸ ڭࢣͳֶ͠श (unsupervised learning) ▸ ͷ2छྨ͕͋Δ

Slide 25

Slide 25 text

ڭࢣ͋Γֶश — ػցֶश ▸ σʔλʹରԠ͢Δσʔλ͕͋Δ ▸ ͱ͍͍ͩͨͳΓͦ͏ͳؔ਺ f Λ୳Γ౰͍ͯͨ ▸ ͔͠΋͜Ε͔ΒಘΔະ஌ͷσʔλʹ͍ͭͯ΋ͦ͏ͳͬͯཉ͍͠ x1 , x2 , …, xN (N͸ී௨େ͖͍) y1 , y2 , …, yN xn ↦ yn yn = f(xn )

Slide 26

Slide 26 text

ྫ͑͹

Slide 27

Slide 27 text

ը૾Λೖྗͨ͠Βɺ ͍ࣸͬͯΔ΋ͷ(ೣɾ ص…)Λ౴͑Δؔ਺

Slide 28

Slide 28 text

΍Γํ

Slide 29

Slide 29 text

શવҧ͏ؔ਺͔Β࢝Ί ͯɺ ͡Θ͡Θ͚͍ۙͮͯ͘

Slide 30

Slide 30 text

தֶ2೥਺ֶՊ

Slide 31

Slide 31 text

தֶߍ2೥ੜΛࢥ͍ग़͢ σʔλʹҰ൪߹͏௚ઢ 0.2 0.4 0.6 0.8 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 y = ax + b a, bΛܾΊΔ

Slide 32

Slide 32 text

͜͏͍͏ͷ΋ ཱ೿ͳػցֶश

Slide 33

Slide 33 text

͞Βʹผͷ ؔ਺Λ߹੒

Slide 34

Slide 34 text

▸ Կ͔ʹ൓Ԡ͢Δײ͡ͷؔ਺͕࡞ΕΔ ͞Βʹผͷؔ਺Λ߹੒ -1.0 -0.5 0.5 1.0 1.5 2.0 0.5 1.0 1.5 2.0 -10 -5 5 10 0.2 0.4 0.6 0.8 1.0 s(x) = 1 1 + e−x , s(f(x))

Slide 35

Slide 35 text

ࡢࠓྲྀߦͬͯ ͍Δͷ͸

Slide 36

Slide 36 text

ਂ૚ֶश Deep learning

Slide 37

Slide 37 text

͖ͬ͞ͷؔ਺Λ ͨ͘͞Μ༻ҙͯ͠ ͭͳ͛·͘Δ

Slide 38

Slide 38 text

ͭͳ͛·ͬͨ͘ͷ = χϡʔϥϧɾωοτϫʔΫ ▸ ○1ͭ1͕͖ͭͬ͞ͷؔ਺ ▸ ΍͡Δ͠ͷΑ͏ʹ ▸ ग़ྗΛ࣍ͷೖྗʹ

Slide 39

Slide 39 text

2. PyTorch

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

PyTorch ▸ ਂ૚ֶश༻ͷϑϨʔϜϫʔΫ ▸ theano, Caffe, TensorFlow, mxnet, Chainer ▸ ͍ͬͺ͍͋Δ͏ͪͷҰͭ ▸ Torch ΑΓ (Torch ͸ LuaJIT) ▸ ChainerΛେ͍ʹࢀߟʹ͍ͯ͠Δ ▸ (ʮforkͱݺͼ͚ͨΕ͹Ͳ͏ͧʯhttps://www.reddit.com/r/MachineLearning/comments/ 74md00/n_how_to_use_chainer_for_theano_users/dnzkba1/ )

Slide 42

Slide 42 text

PyTorch ▸ ಛ௃ ▸ υΩϡϝϯτɾνϡʔτϦΞϧ͕݁ߏৄ͍͠ ▸ ಈతʹܭࢉάϥϑ࡞੒ ▸ ࣗಈඍ෼ ▸ χϡʔϥϧɾωοτϫʔΫ͕ॻ͖΍͍͢ (Chainerͱࣅ͍ͯΔ)

Slide 43

Slide 43 text

ॻ͖΍ͦ͢͏ͳงғؾΛݟΔ class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(1, 10, kernel_size=5) self.conv2 = nn.Conv2d(10, 20, kernel_size=5) self.conv2_drop = nn.Dropout2d() self.fc1 = nn.Linear(320, 50) self.fc2 = nn.Linear(50, 10) def forward(self, x): x = F.relu(F.max_pool2d(self.conv1(x), 2)) x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2)) x = x.view(-1, 320) x = F.relu(self.fc1(x)) x = F.dropout(x, training=self.training) x = self.fc2(x) return F.log_softmax(x, dim=1) ‏͖ͬ͞ͷ˓Λ Կݸ༻ҙͯ͠ ͭͳ͙͔ ‏ͭͳ͛Δͱ͖ʹ߹੒͢Δؔ਺

Slide 44

Slide 44 text

ॻ͖΍ͦ͢͏ͳงғؾΛݟΔ ▸ random_split ▸ σʔλΛγϟοϑϧͭͭ͠෼ׂͯ͘͠ΕΔศརϝιου train_size = int(0.8 * len(dataset)) test_size = len(dataset) - train_size trainset, testset = torch.utils.data.random_split(dataset, [train_size, test_size]) NEW 0.4.1

Slide 45

Slide 45 text

PyTorchདྷͱΔ ▸ Frameworks mentioned @ICLR (International Conference on Learning Representations) 2018➡2019 ▸ TensorFlow 228 ➡ 266 ▸ Keras: 42 ➡ 56 ▸ PyTorch 87 ➡ 252 ▸ https://www.reddit.com/r/MachineLearning/comments/9kys38/ r_frameworks_mentioned_iclr_20182019_tensorflow/ ▸ ݁ߏݚڀͷίʔυ͕PyTorchͰॻ͔Ε͍ͯΔ ▸ ΦϯϥΠϯߨٛ΋PyTorch͕૿͖͑ͯͨ

Slide 46

Slide 46 text

PyTorch 1.0.0.dev20181002 (1.0 developer preview!) ΋͏ͪΐͬͱͰ ver.1.0 https://code.fb.com/ai-research/facebook-accelerates-ai-development-with-new-partners-and-production-capabilities-for-pytorch-1-0/

Slide 47

Slide 47 text

3. ΍ͬͯΈͨྫ

Slide 48

Slide 48 text

ᶃ΢Σϒϖʔδ෼ྨ

Slide 49

Slide 49 text

΢Σϒϖʔδ෼ྨ?

Slide 50

Slide 50 text

΢Σϒϖʔδ෼ྨ? ▸ ΢ΣϒϖʔδͷςΩετσʔλΛೖྗͱ͢Δ ▸ ͦͷϖʔδͷ಺༰ͷछྨΛਪఆ͢Δ ▸ ·ͣ͸࿅शͷͨΊʹʮ2஋෼ྨʯ

Slide 51

Slide 51 text

΍Γํ ▸ ࣗ෼ͷʮ͸ͯͳϒοΫϚʔΫʯ4ສҎ্ϒοΫϚʔΫ͍ͯ͠Δ ▸ ϒοΫϚʔΫλάΛͤͬͤͱ෇͚͍ͯΔ ▸ ʮػցֶशʯλάΛ෇͚͍ͯΔ͔Ͳ͏͔Ͱ෼ྨ ▸ 1000Ҏ্͋Δ ▸ ࣗ෼ͷϒοΫϚʔΫ͔ΒσʔλΛूΊ͖ͯͯɺֶशɻ ▸ text ➡ MeCab(ܗଶૉղੳ) ➡ fasttext ➡ จॻϕΫτϧʹ͢Δ

Slide 52

Slide 52 text

΍Γํ ࢈ۀٕज़૯߹ݚڀॴ͸ 2018೥5݄29೔ɺ౦ژେ ֶͱڞಉͰɺػցֶशͷֶ शॲཧʹඞཁͳԋࢉྔΛ࡟ ݮ͢Δܭࢉํࣜͱԋࢉճ࿏ ΛߟҊͨ͠ͱൃදͨ͠ɻ ࠓقͷΞχϝͷ ͋ͦͼ͋ͦ͹ͤͬͯ ໘ന͍Ͷɻ ػցֶशͷ͜ͱ͕ॻ͍ͯ͋Δϖʔδ͡Ό! ΢ΣϒϖʔδB ΢ΣϒϖʔδA ػցֶश͡Όͳ͍ϖʔδ͡Ό!

Slide 53

Slide 53 text

Demo

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

ͨͿΜ͏·͍ͬͨ͘!

Slide 57

Slide 57 text

Slide 58

Slide 58 text

ᶄϒοΫϚʔΫ਺ਪఆ

Slide 59

Slide 59 text

ϒοΫϚʔΫ਺ਪఆ?

Slide 60

Slide 60 text

ϒοΫϚʔΫ਺ਪఆ? ▸ ࣗ෼ͷʮ͸ͯͳϒοΫϚʔΫʯ4ສҎ্ϒοΫϚʔΫ͍ͯ͠Δ ▸ ֤ϖʔδͷϒοΫϚʔΫ਺…ଞͷਓ΋߹ΘͤͯԿਓϒοΫϚʔΫ͔ͨ͠ ▸ ·ͨࣗ෼ͷϒοΫϚʔΫ͔ΒσʔλΛूΊֶͯश ▸ text ➡ MeCab(ܗଶૉղੳ) ➡ fasttext ➡ จॻϕΫτϧʹ͢Δ ▸ ద౰ʹωοτϫʔΫΛֶͭͬͯ͘शͯ͠ΈΔ

Slide 61

Slide 61 text

Demo

Slide 62

Slide 62 text

܇࿅σʔλଛࣦ⤵ ࢼݧσʔλଛࣦ⤴ ʮաֶश͠·͘ΔΈ͍ͨͰ͢ɻʯ

Slide 63

Slide 63 text

(´ɾωɾ`) શવ͏·ֶ͘श͠ͳ͍ (աֶश͹͔Γ͢Δ)

Slide 64

Slide 64 text

ϒοΫϚʔΫ਺ਪఆ͸จॻͰ͸ແཧͰ͸? ▸ ബʑؾ෇͍͍ͯͨ ▸ ͸ͯͳϒοΫϚʔΫͷ਺Λϖʔδͷ಺༰͚͔ͩΒਪଌ͢Δͷ͸ແཧͰ͸ɻ ▸ ༗໊ਓ͕֦ࢄͨ͠ͱ͔ɺଞͷӡͷཁૉ͕ڧ͍ ▸ Ͱ΋७ਮʹจষ͚͔ͩΒજࡏతͳʮϒοΫϚʔΫ͞ΕྗʯΈ͍ͨͳͷ͕Ͱ ͳ͍͔ͳ͋ͱ୶͍ظ଴͸͋ͬͨ ▸ ݚڀଓߦ͢Δ΂͖! ͸ͯϒΛՔ͍͗ͨ!

Slide 65

Slide 65 text

ᶅGAN

Slide 66

Slide 66 text

GAN?

Slide 67

Slide 67 text

GAN? ▸ GAN = generative adversarial network (ఢରతੜ੒ωοτϫʔΫ) ▸ ੜ੒ऀ generator (G) v.s. ࣝผऀ discriminator (D) ͕ఢର͠ͳ͕Βֶशͯ͠ ͍͘ ▸ G ͱ D ͕ఢର͠ͳ͕Βֶश͍ͯ͘͠ ▸ Կ͔Λʮੜ੒͢Δʯ

Slide 68

Slide 68 text

ը૾ੜ੒ͷ࡞ྫ

Slide 69

Slide 69 text

͜͏͍͏ͷ͕ ࡞Γ͍ͨ ▸ Ҵ৔Ѫ߳ͪΌΜͱΘ͠ͷը૾Λ ֶशͯ͠ɺը૾Λੜ੒

Slide 70

Slide 70 text

epoch 25 ▸ ΄΅ϊΠζ

Slide 71

Slide 71 text

epoch 37 ▸ ΍΍إΒ͖͠΋ͷ͕ݟ͖͑ͯͨ

Slide 72

Slide 72 text

epoch 149 ▸ ੜ੒Ͱ͖͖ͯͨ!

Slide 73

Slide 73 text

epoch 192

Slide 74

Slide 74 text

ൺֱ ਖ਼ ϑΣΠΫ

Slide 75

Slide 75 text

ָ͍͠ ✌('ω'✌ )ࡾ✌('ω')✌ࡾ( ✌'ω')✌

Slide 76

Slide 76 text

·ͱΊ ▸ Pythonॳ৺ऀ͕PyTorchΛ࢖ͬͯػցֶशΛ΍ͬͯΈͨ ▸ ͔֬ʹॻ͖΍͍͢ؾ͕͢Δ ▸ ͲΜͲΜ࣮ݧͯ͠༡΂Δ ▸ ৽͍͠ઃܭ͕࣍ʑग़͍ͯΔͷͰ΍͍͖͍ͬͯͨ ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ