iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 19
0
AI & Data

跟著Google學ML系列 第 19

[Day 19] 神經網路Neural Networks介紹

Ref.: Introduction to Neural Networks

先來回想我們在Day 13 feature crosses提到的nonlinear problems,當時是用feature相乘(product)當成一個synthetic feature,如果是像下面更困難的分布,可能就沒辦法這麼簡單的解決了。
https://ithelp.ithome.com.tw/upload/images/20181019/20103835Imx4BTW57o.jpg
不用怕,還是可以的,只要有神經網路(Neural Networks)

好,我們先把一個linear model畫成圖:
https://ithelp.ithome.com.tw/upload/images/20181019/201038352UvlcZOhq2.jpg
藍色是input feature,連接線是weight,綠色output則是input feature的加權總合。
看看這樣的idea能不能解決nonlinear的問題。

Hidden Layers

改變一下,在他們中間加上一層hidden layers
https://ithelp.ithome.com.tw/upload/images/20181019/20103835nLHwklsIHd.jpg
黃色的hidden layer是藍色的加權總合,綠色的則是黃色的加權總合。
很不幸的,這樣的model 還是linear。即使多加幾層hidden layer都一樣。
https://ithelp.ithome.com.tw/upload/images/20181019/20103835DTf9AePEbf.jpg

Activation Functions

OK,我們在其中套上一個非線性轉換層,讓整個model可以有處理nonlinear的能力:
https://ithelp.ithome.com.tw/upload/images/20181019/20103835fYs1b3JCtJ.jpg
橘點是把下面的hidden layer做非線性轉換(一般不會畫出來),又稱做激勵函數Activation Function。非線性轉換後在當成上層hidden layer的input,接著讓output加權總和。這樣可以讓每一層透過raw input更有效的學習更複雜、更難的function。

常見的Activation Function

sigmoid function
https://ithelp.ithome.com.tw/upload/images/20181020/20103835zx5cG6KV7t.png
它所代表的是https://ithelp.ithome.com.tw/upload/images/20181019/20103835YRwPFlfGms.jpg

rectified linear unit(ReLU)
https://ithelp.ithome.com.tw/upload/images/20181020/20103835v1ygmoc7aS.jpg
比sigmoid做的運算簡單,就只是max(0, x),會比指數運算更有效率。


實務上,我們可以把任何數學函數視為activation function,會用一個σ去代表我們的activation function,而該node可以視為:https://ithelp.ithome.com.tw/upload/images/20181020/20103835XetaIxf2A6.jpg
TensorFlow也提供了很多activation function,但還是建議使用ReLU。

總結一下

  • Layer裡的每個node就像是神經
  • 下層可能是另一個神經網路、或其他種類的網路。Weight則把每個layer連接起來。
  • 每個node都可能有bias
  • Activation function轉換同一層的每個node output,每一層有不同的activation function(所以常常不畫出activation layer)

最後叮嚀一下 一定要記得玩一下 Playground,去體會螺旋狀(Spiral)的data怎麼被train的。


上一篇
[Day 18] Regularization - Sparsity
下一篇
[Day 20] Training神經網路
系列文
跟著Google學ML30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言