SlideShare a Scribd company logo
1 of 44
Download to read offline
能量觀點下
的機器學習
(1) RBM, DBN
Allen Lee
this slide:
https://docs.google.com/presentation/d/1PmckAH9s1agVMO0RXkf_S5BvTii1a4YMUO5ExkFAosE/edit?usp=sharing
sample code:
https://colab.research.google.com/github/allenyllee/ML_exercise/blob/master/RBM/RBM_DBN.ipynb
參考資料:
Neural networks [5.1] : Restricted Boltzmann
machine - definition - YouTube
https://www.youtube.com/watch?v=p4Vh_zMw-
HQ&list=PL6Xpj9I5qXYEcOhn7TqghAJ6NAPrN
mUBH&index=36
Hugo Larochelle
http://info.usherbrooke.ca/hlarochelle/neural_ne
tworks/content.html
Restricted Boltzmann Machine, RBM
● RBM 是一種 Unsupervised Learning
● RBM 只有兩層:input 為visible layer, output 為
hidden layer,每個unit都是二進位值{0,1}
● 同一層間的unit 沒有連結,不同層間 採全連結,共享
一組weight,但不共用bias
● 假設系統符合波茲曼分布,因此只要建立visible 跟
hidden unit 間的能量函數E(x,h),就可得到聯合機
率分布p(x,h)
● 其中partition function Z 為所有可能組態的總和,
數量為2^N種,N為unit數,基本上無法計算
● Distribution:● Energy function:
why? 可從最大熵原理導出,參考附錄
MARKOV NETWORK VIEW
● 寫成向量形式:
● 寫成純量形式:
條件機率
● 雖然無法直接求出聯合機率P(x,h),但條件機率P(x|h)和P(h|x)卻可以計算
● 聯合機率(Joint Probability) = 條件機率(Conditional Probability) * 機率(Probability)
P(x, h) = P(h | x) * P(x)
● 邊際機率(Marginal probability) = 所有符合條件的機率加總
P(x) = Σ P(x, h’)
● 條件機率=聯合機率/邊際機率:
P(h|x) = P(x, h) / Σ P(x, h’)
貝葉斯推斷和各類機率 Bayesian Inference · 資料科學・機器・人
https://brohrer.mcknote.com/zh-Hant/statistics/how_bayesian_inference_works.html
分母消掉
hidden unit 之間互相條件獨
立
h 只有0跟1, 所以只有兩項
● sigmoid 的由來:
○ 從波茲曼分布推導出來的p(h|x)條件機率,很自然就產生sigmoid function
○ 以上推導只有用到h ∈{0,1} 的前提,這可能是為什麼類別標註喜歡用onehot
○ 後來 DNN 採用sigmoid 作為activation function 來引入非線性 (放在最後一層
就輸出機率),可能跟RBM 比較有關,而非一般常說的神經元激發。
當h=1, 分子分母可以同除exp項
得到sigmoid
條件機率
● 給定x計算p(h|x)
● 給定h計算p(x|h)
Local Markov Property
● Zi 是Markov network 中的任一變數(在此指 RBM 中的x 或 h)
● Ne(Zi) 為Zi的鄰居變數(Zi 只跟其鄰居變數有關,此即Local Markov Property)
給定其他z,zi的條件機率
聯合機率
邊際機率P(Ne(Zi))
xk
h1…...hj…….hn
P(xk|h1,...hj...hn), 這裡
xk 的鄰居為h1...hj...hn
給定zi鄰居,zi的條件機率
只跟鄰居有關的連乘積
,對應到上一頁的推導,
因此RBM 符合此性質
Free Energy
● 前面我們定義了P(x,h),其中energy E(x,h) 跟隱藏狀態有關,但我們想知道P(x)是什麼
p(x,h)
可以拆成exp連乘積
只有兩項
Free Energy
● 現在我們知道P(x)可以寫成exp(-F(x))/Z,其中F(x) 跟隱藏狀態無關,若F(x)越小,P(x)就越大
● 在統計力學中,若反應的 Free Energy 變小(ΔF(x)<0),表示這是一個自發反應(P(x)->1)
● 因此可將F(x)類比為Free Energy
Free Energy
● 我們希望,給定sample x,最大化模型輸出x 的機率p(x)
softplus(.), 相當於max(0,x)(或relu)的平滑版
c 是x的bias, 相當於給
input 一個bias
對每一個hidden unit hj,
對應的Wj 都代表不同的
feature, 當input x與
feature 越接近,輸出就越
大
b 為h的bias, 相當於給
不同feature 一個bias
Training
● 因為P(x)=exp(-F(x))/Z,兩邊取對數後
: log P(x)=-F(x)-log Z
● 因此最小化free energy 也就是最小
化 average negative log-liklihood
(NLL)
好算,因為input x是給
定的, 只須對h求和
難算,要對所有的x,h 求
和,其中包含x跟h的交
叉項
positive phase negative phase
T: batch size
Contrastive Divergence (CD)
● 為了解決Z很難算的問題,Hinton 在2002年提出了 Contrastive Divergence(對比散列)算法
● Idea:
○ 用x̃ 的點估計(point estimation) 取代期望值(expectation)
○ 透過Gibbs sampling 獲得x̃ (就是交替sampling 的過程)
○ sampling chain 從 input x(t) 開始
給定input Xt,可以計算出
p(hj=1|x) 的機率,再從均勻
分布抽樣 hj :
hj = {1, if p(hj=1|x) >
Uniform[0,1]; 0,
otherwise}
有了h之後,同樣的方法我們可以抽樣
出x(1) (感覺很像從h重建出x),此過程
重複k次,得到x(k) 當作 negative
sample
為什麼是這樣?因為 RBM 將設計簡化成visible 跟
hidden layer,同一層間的unit 條件獨立,只跟另外一
層有連結,符合 Local Markov Property,可以很方便的
兩層之間交替 sample。但對廣義的 boltzmann
machine (不分層,彼此互連 ) 就沒有這個性質。
Hinton, Neural Computation, 2002
https://www.cs.toronto.edu/~hinton/absps/tr00-004.pdf
注意:RBM 必須算出p
才有辦法sampling,但
autoencoder 並不透過
sampling
Contrastive Divergence (CD)
● 對於給定input x(t),
sample 一組h̃(t) 當作
positive phase 的估計
● 然後再經過k step 的
gibbs sampling 後,我
們得到 x̃,再從 p(h|x̃)
sample 出 h̃,用這一組
(x̃, h̃) 當作negative
phase 的估計
positive phase negative phase
loss function 可以看成由這兩項組成,其中 positive 代表真實樣本,而
negative 代表產生出來的假樣本,目標是 最小化positive 的能量,並且
最大化 negative 的能量
Contrastive Divergence (CD)
● 從機率的觀點來看,就是給定真實樣本時, p(x,h)機率要最大;反之,給定產生出來的假樣本時, p(x,h)
要最小。
● 換言之,最終訓練出來的 RBM,他的p(x,h) 會在真實樣本附近有最大的機率分布,因此可以用來 產生
接近真實樣本的x與h,其中x在樣本空間,而h在feature space。
● 對應到ising model: 如果x是spin,那h應該是spin 間的interaction
Derivation of the Learning Rule
Derivation of the Learning Rule
又看到
sigmoid,此處
代表的是給定x,
hj=1的機率。因
此在NN中,用
sigmoid 當最後
一層輸出機率並
不是沒有道理
的!
Derivation of the Learning Rule
● 給定x(t)和x̃,參數𝜃 =W 的 update rule 如下:
因此當x̃ 越來越接近真實樣本
x(t),W就穩定了
CD-k pseudo code
1. for each training sample x(t)
i. generate a negitive sample x̃ using k steps of Gibbs sampling, starting at x(t)
ii. update parameters
2. Go back to 1 until stopping criteria
homework: derive the
update rule for bias b and c
Contrastive Divergence (CD)
● CD-k: contrastive divergence with k step of Gibbs sampling
● 一般來說,k越大,對gradient 的估計就越準
● 但若只是拿RBM 做下游任務參數的pre-training,k=1結果就很好了(用訓練好
的 h 當作 x 的 representation,有點像auto-encoder的中間層)
● 從結果來看,RBM 像是共用 encoder/decoder weight 的 Autoencoder,不過
loss function 並不是input x 與 reconstructed x 直接相減,而是還要乘上h(x)
,計算x在h(x)機率分布下的期望值。因此RBM 的 h 是有機率意義的,但
Autoencoder 的中間層並沒有特殊涵義(不過,也可以在中間層加上sigmoid,
並修改 loss function 來模擬RBM)。
Persistent CD (PCD)
● 雖然訓練出來的 h 拿來當 feature 效果不錯,但是 generate 出來的 sample x̃ 的 loss 還是很高,這是
因為 Gibbs sampling 通常只會在 x(t) 附近 sampling,跳不出 local minima
● 一個很簡單的方法,就是用 上一輪產生的 negative sample 來產生這一輪的 negative sample。這跟
直接把 k 設很大不太一樣,因為每一輪模型都會 update,這時候sample 的參數會改變。藉由這個方
式,產生的 x̃ 可以跑得比較遠,就有可能跳出 local minima
● 因此,你需要把每一輪 (batch) 產生的 x̃ 存起來供下次使用
x(t)
How?
Persistent CD (PCD) Tieleman, ICML 2008
http://icml2008.cs.helsinki.fi/papers/638.pdf
Parallel Tempering (PT)
● 另外一種改進的訓練方法是,加
上溫度項:
其中r=1,...,M,總共有M個溫度Tr
,我
們可以平行地對這M個溫度做CD,然
後讓鄰近溫度間產生的sample 有機
率exchange,達到更好的估計
k=1
k=2
k=5
k=10
k=20
k=100
M=4
M=50
An Introductionto Restricted Boltzmann Machines
https://web.archive.org/web/20140211020253/http://image.diku.dk/igel/paper/AItRBM-proof.pdf
Filters
LAROCHELLE ET AL., JMLR2009
http://jmlr.org//papers/v10/larochelle09a.html
x1......xn
hj
reshape
x1......xk
….......xn
Debug
● RBM 很難debug,但有一些方法可以告訴你是否正確training
1. 畫出重構誤差 ||x(t)-x̃||^2 看是否隨訓練次數遞減
2. 畫出filter
3. 估計partition function Z並計算 NLL 是否遞減
On the Quantitative Analysis of Deep Belief Networks.
Ruslan Salakhutdinov and Iain Murray, 2008
https://www.cs.toronto.edu/~rsalakhu/papers/dbn_ais.pdf
GAUSSIAN-BERNOULLI RBM
● 如果input x 的定義域是所有實數
● 這時energy function 多加一個x平方項
● 此時唯一改變的只有 p(x|h) 會變成高斯分布,有平均 標準差單位矩陣
● 這時候建議把 training set normalized 成平均為0,標準差為1
● 應該使用更小的 learning rate
如果要讓x定義域
為所有實數,為了
讓 p(x|h) 分母的積
分有 close form,
最簡單是加上平方
項
Other Types of Observations
● Real-valued: Gaussian-Bernoulli RBM
● Binomial observations:
○ Rate-coded Restricted Boltzmann Machines for Face
Recognition. Yee Whye Teh and Geoffrey Hinton, 2001
https://papers.nips.cc/paper/1886-rate-coded-restricted-b
oltzmann-machines-for-face-recognition.pdf
● Multinomial observations:
○ Replicated Softmax: an Undirected Topic Model. Ruslan
Salakhutdinov and Geoffrey Hinton, 2009
https://papers.nips.cc/paper/3856-replicated-softmax-an-u
ndirected-topic-model
○ Training Restricted Boltzmann Machines on Word
Observations. George Dahl, Ryan Adam and Hugo
Larochelle, 2012 https://arxiv.org/pdf/1202.5695.pdf
當input 為0~N時,例如每個pixel 有
0~255 的強度,可以很簡單的將 input
x表示為重複出現幾個1,出現越多強度
越強,最多255個1,結果變成一個
binomial distribution 問題。
當 input 為多個 words 的時候,每個
word 可以用 onehot 表示,因此很多
個words 的排列組合,就是很 多組
onehot 的排列組合,即為
multinomial distribution。
想想如何用在N spin system上?
Boltzmann Machine
● 原始的 Boltzmann Machine 在每一層內部都有連結,因此能量函數會多兩項
● 當只有一層內部有連結,稱為 semi-restricted Boltzmann Machine
● 因為沒有辦法像 RBM 用Gibbs sampling 方式來training,因此很少人討論此model
Deep Belief Network
● DBN 是一種生成模型,結合無向和有向的變數
連結
● 最上面兩層p(h(2),h(3)) 是RBM
● 其他層是貝氏網路(Bayesian network)
○ 每一層在給定了上一層的條件分布為:
○ 又稱為sigmoid belief network (SBN)
● DBN 不是前饋網路(feed-forward network)
Neural networks [7.7] : Deep learning - deep belief network - YouTube
https://www.youtube.com/watch?v=vkb6AWYXZ5I&list=PL6Xpj9I5qXYEcOhn
7TqghAJ6NAPrNmUBH&index=57
Hugo Larochelle
http://info.usherbrooke.ca/hlarochelle/neural_networks/content.html
Deep Belief Network
● DBN 是一種生成模型,結合無向和有向的變數
連結
● 最上面兩層p(h(2),h(3)) 是RBM
● 其他層是貝氏網路(Bayesian network)
○ 每一層在給定了上一層的條件分布為:
○ 又稱為sigmoid belief network (SBN)
● DBN 不是前饋網路(feed-forward network)
Neural networks [7.7] : Deep learning - deep belief network - YouTube
https://www.youtube.com/watch?v=vkb6AWYXZ5I&list=PL6Xpj9I5qXYEcOhn
7TqghAJ6NAPrNmUBH&index=57
Hugo Larochelle
http://info.usherbrooke.ca/hlarochelle/neural_networks/content.html
所謂貝氏網路是一
種有向無環圖,每
一個可見的效應
(visible effect)都由
數個隨機隱變因
(Stochastic
hidden cause) 造
成
Deep Belief Nets: CS590M 2008 Fall Paper Presentation
https://www.slideshare.net/butest/deep-belief-nets
Inference
● The full distribution of a DBN is as follows:
● where:
先從最上面兩層的 RBM 用 Gibbs sampling 產生
h(2),下面的SBN 都是單向的,給定h(2) 產生h(1),
給定h(1)產生x
Training
● 先把第1,2層當
RBM訓練
● 固定1,2層的參數
W1
,用W1
T
初始
化2,3層參數,把
2,3層當RBM訓
練
● 固定2,3層參數
W2
,用W2
T
初始
化3,4層參數,把
3,4層當RBM 做
訓練
● 以此類推
W1
W1
W1
T
W1
W2
W2
T
p(h(1)) 可以寫成 sum over h(2) p(h(1),h(2))
每增加一層,代表用更高階的 feature 來表示前一
層 feature。
● log p(x)可以寫成:
Variational bound
● 上述training 法是利用 Variational bound
● 首先,利用log 函數的凹性(concave)
Variational bound
● 若 q(h(1)|x) 等於真實分布p(h(1)|x),則等號成立
● 當 q(h(1)|x) 與p(h(1)|x) 差距越大,則下界越鬆
● 事實上,不等式兩邊同減 log p(x),可以得到KL divergence:
log p(x,h(1)) = log p(h(1)|x) + log p(x)
Variational bound
● 只有一層隱藏層時,p(x|h(1)) 與 p(h(1)) 都只跟第一層有關
● 加入第二層隱藏層後,p(h(1)) 可寫成對 h(2)的積分
● 因此,訓練第二層就相當於最小化下式:
● 這就相當於在由 q(h(1)|x) 所產生的data 上訓練一個RBM!
q(h(1)|x) 是第一層
近似的h(1)的條件
分布,但離真實的
p(h(1)) 還有差距,
所以用第二層h(2)
來近似
Variational bound
● 我們可以從第一層RBM 得到q(h(1)|x)
○ 相當於feed-forward (sigmoidal) layer, followed by sampling
● 藉由初始化第二層 RBM weight 成為第一層 RBM weight 的transpose,the bound
is initially tight
○ 事實上,2 layer DBN with tied weight 等同於 1 layer RBM
W
WT
h(1)
h(2)
x
Variational bound
● 上述增加layer 的過程可以反覆迭代
● 訓練目標是最大化 bound 下界
○ 理論上,如果一開始估計的 q(h(1)|x) 離真實後驗(ture posterior) 非常遠,bound 就會很
鬆
○ 這只代表我們可能無法改善true likelihood
○ 但我們仍可取出更好的feature
W
WT
h(1)
h(2)
x
Fine-Tuning
● Up-Down algorithm:
○ A fast learning algorithm for deep
belief nets.Hinton, Teh, Osindero,
2006
https://www.cs.toronto.edu/~hinton/a
bsps/fastnc.pdf
○ 將input x從下方傳到最頂層,由最頂層
RBM 做Gibbs sampling,再往下傳回
來,產生x̃,修正最頂層參數
● Back Propagation:
○ 从自联想神经网络到深度神经网络
https://blog.csdn.net/celerychen2009/
article/details/9079715
○ 如果有 label 的話,就直接在最頂層再
接上一層BP 層,用BP做fine-tuning
Deep Belief Nets: CS590M
2008 Fall Paper Presentation
https://www.slideshare.net/bute
st/deep-belief-nets
Deep Autoencoder
● 因為深層的autoencoder
非常難train,所以有人就
想到了可以拆成好幾個
RBM 訓練,最後再做
fine-tune
Deep Belief Nets: CS590M 2008 Fall Paper
Presentation
https://www.slideshare.net/butest/deep-belie
f-nets
附錄:最大熵原理
● 已知系統的熵為 ,且機率和為1,即
給定k個限制條件 求熵的極大值?
● 使用 Lagrange multiplier method ,等同於求解下式之極 值: ● 解得:
附錄:最大熵原理
● 對照 RBM 的energy function:
● 最大熵原理告訴我們,如果系統有k個限制條件,若用最少參數來描述這個系統,就是波茲曼分布,只需要k個參數。其他
的分布形式必然需要更多參數才能描述該系統。
● RBM 的energy function 組成了多組限制條件,代表的就是這個dataset 的守恆量,如果data 是來自同一個分布,那這
些量應該要一樣,例如每個pixel的期望值,再根據這些守恆量,找出最少參數能符合這些限制條件的分布。
● 顯然的,如果圖片稍微轉動,那麼pixel 的期望值也會跟著變,所以pixel 不是一個很好的守恆量。
● 如果CNN的最後一層接上softmax,只看倒數第一、二層,其實就很像RBM。因此倒數第二層所代表的應該是dataset 中
會守恆的特徵,這樣子期望值算出來是固定的,才是一個好的守恆量。而這些好的守恆量,其實就是人眼看起來比較高層
次的結構!
● 想想看,現代神經網路最後一層為什麼要加上 softmax?只是單純湊個機率的樣子嗎?
“熵”不起:从熵、最大熵原理到最大熵模型(二) - 科学空间|Scientific Spaces
https://kexue.fm/archives/3552
這裡的ck
對應到λi
是個待定係數,而對應的限制條件是𝔼
(x)=𝜏,如果x是圖片的pixel,就是該pixel 在dataset 的期
望值,其物理意義為:如果data 是來自同一個分布,每個
pixel 的期望值應該是守恆的;如果生成的data 與真實
data 期望值差太多,學到的係數ck
就無法代表λi
的解,所
以就不是屬於同個分布。
附錄:最大熵原理
● 對照 RBM 的energy function:
● 最大熵原理告訴我們,如果系統有k個限制條件,若用最少參數來描述這個系統,就是波茲曼分布,只需要k個參數。其他
的分布形式必然需要更多參數才能描述該系統。
● RBM 的energy function 組成了多組限制條件,代表的就是這個dataset 的守恆量,如果data 是來自同一個分布,那這
些量應該要一樣,例如每個pixel的期望值,再根據這些守恆量,找出最少參數能符合這些限制條件的分布。
● 顯然的,如果圖片稍微轉動,那麼pixel 的期望值也會跟著變,所以pixel 不是一個很好的守恆量。
● 如果CNN的最後一層接上softmax,只看倒數第一、二層,其實就很像RBM。因此倒數第二層所代表的應該是dataset 中
會守恆的特徵,這樣子期望值算出來是固定的,才是一個好的守恆量。而這些好的守恆量,其實就是人眼看起來比較高層
次的結構!
● 想想看,現代神經網路最後一層為什麼要加上 softmax?只是單純湊個機率的樣子嗎?
“熵”不起:从熵、最大熵原理到最大熵模型(二) - 科学空间|Scientific Spaces
https://kexue.fm/archives/3552
這裡的ck
對應到λi
是個待定係數,而對應的限制條件是𝔼
(x)=𝜏,如果x是圖片的pixel,就是該pixel 在dataset 的期
望值,其物理意義為:如果data 是來自同一個分布,每個
pixel 的期望值應該是守恆的;如果生成的data 與真實
data 期望值差太多,學到的係數ck
就無法代表λi
的解,所
以就不是屬於同個分布。
● 簡單說,RBM 所謂的energy 指的其實就是dataset 中的守恆量;如果dataset 是圖片,而你預期來自同一個分布
的圖片,每個pixel 的期望值應該要一樣,那這個pixel 的期望值就是這個分布的圖片的限制條件。
● 然而,pixel 並不是一個好的守恆特徵,因為很顯然只要把圖片轉一下,pixel 期望值就改變了。所以一個好的特徵
應該是在各種可能的狀況底下,取期望值之後能夠保持守恆。
● 如果看CNN,通常最後一層是接softmax,只看倒數兩層的話,就是RBM。我們可以知道,如果RBM 結果要好,倒
數第二層的特徵應該是一個好的守恆量。換句話說,它應該是一個不會因為稍微轉動而改變的特徵。而這對應到
就是人眼所看的高層次特徵(眼睛鼻子嘴巴...等)。
● 因為倒數第二層要找的是這樣一個守恆量,所以前面一大堆好幾層,目的其實就是為了湊出這些高層次的特徵,
所以才會有CNN 到越後面幾層出現越高層次的結構。
● 所以什麼是圖像中的守恆量呢?就是那些正著看、歪著看都不太會認錯的結構;那什麼是語言中的守恆量呢?這
有點難,因為語序改變通常意思就會變,除非整個上下文意思是連貫而且明確的,即使語序調換也不影響所表達
意思的,而這個"意思"就是我們想要的高層次特徵。
● 所以帶到法律判決分類問題上,法官的"意思"是一種高層次特徵,不管他整篇判決書寫了甚麼,他的"意思"是不變
的,可以說在所有這些判決書中,有一些"意思"可以做為好的特徵,因為不管怎麼看它都代表那個意思。這也就是
我們之所以可以用有利不利句子來做分類的基礎。
● 這就給出了NLP的一個限制,這些語言中的"意思"很可能只有在特定情況下才有那個"意思",不像圖片拿到哪裡,
貓就是貓,狗就是狗。所以文字只有在特定某個語料庫中,用詞跟它的"意思"沒有改變太大的情況下,分類才有好
的結果。
End
● Thank you very much
● Any questions?

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

20190515 energy perspective-ml(1)_rbm_dbn-allen_lee

  • 1. 能量觀點下 的機器學習 (1) RBM, DBN Allen Lee this slide: https://docs.google.com/presentation/d/1PmckAH9s1agVMO0RXkf_S5BvTii1a4YMUO5ExkFAosE/edit?usp=sharing sample code: https://colab.research.google.com/github/allenyllee/ML_exercise/blob/master/RBM/RBM_DBN.ipynb 參考資料: Neural networks [5.1] : Restricted Boltzmann machine - definition - YouTube https://www.youtube.com/watch?v=p4Vh_zMw- HQ&list=PL6Xpj9I5qXYEcOhn7TqghAJ6NAPrN mUBH&index=36 Hugo Larochelle http://info.usherbrooke.ca/hlarochelle/neural_ne tworks/content.html
  • 2. Restricted Boltzmann Machine, RBM ● RBM 是一種 Unsupervised Learning ● RBM 只有兩層:input 為visible layer, output 為 hidden layer,每個unit都是二進位值{0,1} ● 同一層間的unit 沒有連結,不同層間 採全連結,共享 一組weight,但不共用bias ● 假設系統符合波茲曼分布,因此只要建立visible 跟 hidden unit 間的能量函數E(x,h),就可得到聯合機 率分布p(x,h) ● 其中partition function Z 為所有可能組態的總和, 數量為2^N種,N為unit數,基本上無法計算 ● Distribution:● Energy function: why? 可從最大熵原理導出,參考附錄
  • 3. MARKOV NETWORK VIEW ● 寫成向量形式: ● 寫成純量形式:
  • 4. 條件機率 ● 雖然無法直接求出聯合機率P(x,h),但條件機率P(x|h)和P(h|x)卻可以計算 ● 聯合機率(Joint Probability) = 條件機率(Conditional Probability) * 機率(Probability) P(x, h) = P(h | x) * P(x) ● 邊際機率(Marginal probability) = 所有符合條件的機率加總 P(x) = Σ P(x, h’) ● 條件機率=聯合機率/邊際機率: P(h|x) = P(x, h) / Σ P(x, h’) 貝葉斯推斷和各類機率 Bayesian Inference · 資料科學・機器・人 https://brohrer.mcknote.com/zh-Hant/statistics/how_bayesian_inference_works.html
  • 6. ● sigmoid 的由來: ○ 從波茲曼分布推導出來的p(h|x)條件機率,很自然就產生sigmoid function ○ 以上推導只有用到h ∈{0,1} 的前提,這可能是為什麼類別標註喜歡用onehot ○ 後來 DNN 採用sigmoid 作為activation function 來引入非線性 (放在最後一層 就輸出機率),可能跟RBM 比較有關,而非一般常說的神經元激發。 當h=1, 分子分母可以同除exp項 得到sigmoid
  • 8. Local Markov Property ● Zi 是Markov network 中的任一變數(在此指 RBM 中的x 或 h) ● Ne(Zi) 為Zi的鄰居變數(Zi 只跟其鄰居變數有關,此即Local Markov Property) 給定其他z,zi的條件機率 聯合機率 邊際機率P(Ne(Zi)) xk h1…...hj…….hn P(xk|h1,...hj...hn), 這裡 xk 的鄰居為h1...hj...hn 給定zi鄰居,zi的條件機率 只跟鄰居有關的連乘積 ,對應到上一頁的推導, 因此RBM 符合此性質
  • 9. Free Energy ● 前面我們定義了P(x,h),其中energy E(x,h) 跟隱藏狀態有關,但我們想知道P(x)是什麼 p(x,h) 可以拆成exp連乘積 只有兩項
  • 10. Free Energy ● 現在我們知道P(x)可以寫成exp(-F(x))/Z,其中F(x) 跟隱藏狀態無關,若F(x)越小,P(x)就越大 ● 在統計力學中,若反應的 Free Energy 變小(ΔF(x)<0),表示這是一個自發反應(P(x)->1) ● 因此可將F(x)類比為Free Energy
  • 11. Free Energy ● 我們希望,給定sample x,最大化模型輸出x 的機率p(x) softplus(.), 相當於max(0,x)(或relu)的平滑版 c 是x的bias, 相當於給 input 一個bias 對每一個hidden unit hj, 對應的Wj 都代表不同的 feature, 當input x與 feature 越接近,輸出就越 大 b 為h的bias, 相當於給 不同feature 一個bias
  • 12. Training ● 因為P(x)=exp(-F(x))/Z,兩邊取對數後 : log P(x)=-F(x)-log Z ● 因此最小化free energy 也就是最小 化 average negative log-liklihood (NLL) 好算,因為input x是給 定的, 只須對h求和 難算,要對所有的x,h 求 和,其中包含x跟h的交 叉項 positive phase negative phase T: batch size
  • 13. Contrastive Divergence (CD) ● 為了解決Z很難算的問題,Hinton 在2002年提出了 Contrastive Divergence(對比散列)算法 ● Idea: ○ 用x̃ 的點估計(point estimation) 取代期望值(expectation) ○ 透過Gibbs sampling 獲得x̃ (就是交替sampling 的過程) ○ sampling chain 從 input x(t) 開始 給定input Xt,可以計算出 p(hj=1|x) 的機率,再從均勻 分布抽樣 hj : hj = {1, if p(hj=1|x) > Uniform[0,1]; 0, otherwise} 有了h之後,同樣的方法我們可以抽樣 出x(1) (感覺很像從h重建出x),此過程 重複k次,得到x(k) 當作 negative sample 為什麼是這樣?因為 RBM 將設計簡化成visible 跟 hidden layer,同一層間的unit 條件獨立,只跟另外一 層有連結,符合 Local Markov Property,可以很方便的 兩層之間交替 sample。但對廣義的 boltzmann machine (不分層,彼此互連 ) 就沒有這個性質。 Hinton, Neural Computation, 2002 https://www.cs.toronto.edu/~hinton/absps/tr00-004.pdf 注意:RBM 必須算出p 才有辦法sampling,但 autoencoder 並不透過 sampling
  • 14. Contrastive Divergence (CD) ● 對於給定input x(t), sample 一組h̃(t) 當作 positive phase 的估計 ● 然後再經過k step 的 gibbs sampling 後,我 們得到 x̃,再從 p(h|x̃) sample 出 h̃,用這一組 (x̃, h̃) 當作negative phase 的估計 positive phase negative phase loss function 可以看成由這兩項組成,其中 positive 代表真實樣本,而 negative 代表產生出來的假樣本,目標是 最小化positive 的能量,並且 最大化 negative 的能量
  • 15. Contrastive Divergence (CD) ● 從機率的觀點來看,就是給定真實樣本時, p(x,h)機率要最大;反之,給定產生出來的假樣本時, p(x,h) 要最小。 ● 換言之,最終訓練出來的 RBM,他的p(x,h) 會在真實樣本附近有最大的機率分布,因此可以用來 產生 接近真實樣本的x與h,其中x在樣本空間,而h在feature space。 ● 對應到ising model: 如果x是spin,那h應該是spin 間的interaction
  • 16. Derivation of the Learning Rule
  • 17. Derivation of the Learning Rule 又看到 sigmoid,此處 代表的是給定x, hj=1的機率。因 此在NN中,用 sigmoid 當最後 一層輸出機率並 不是沒有道理 的!
  • 18. Derivation of the Learning Rule ● 給定x(t)和x̃,參數𝜃 =W 的 update rule 如下: 因此當x̃ 越來越接近真實樣本 x(t),W就穩定了
  • 19. CD-k pseudo code 1. for each training sample x(t) i. generate a negitive sample x̃ using k steps of Gibbs sampling, starting at x(t) ii. update parameters 2. Go back to 1 until stopping criteria homework: derive the update rule for bias b and c
  • 20. Contrastive Divergence (CD) ● CD-k: contrastive divergence with k step of Gibbs sampling ● 一般來說,k越大,對gradient 的估計就越準 ● 但若只是拿RBM 做下游任務參數的pre-training,k=1結果就很好了(用訓練好 的 h 當作 x 的 representation,有點像auto-encoder的中間層) ● 從結果來看,RBM 像是共用 encoder/decoder weight 的 Autoencoder,不過 loss function 並不是input x 與 reconstructed x 直接相減,而是還要乘上h(x) ,計算x在h(x)機率分布下的期望值。因此RBM 的 h 是有機率意義的,但 Autoencoder 的中間層並沒有特殊涵義(不過,也可以在中間層加上sigmoid, 並修改 loss function 來模擬RBM)。
  • 21. Persistent CD (PCD) ● 雖然訓練出來的 h 拿來當 feature 效果不錯,但是 generate 出來的 sample x̃ 的 loss 還是很高,這是 因為 Gibbs sampling 通常只會在 x(t) 附近 sampling,跳不出 local minima ● 一個很簡單的方法,就是用 上一輪產生的 negative sample 來產生這一輪的 negative sample。這跟 直接把 k 設很大不太一樣,因為每一輪模型都會 update,這時候sample 的參數會改變。藉由這個方 式,產生的 x̃ 可以跑得比較遠,就有可能跳出 local minima ● 因此,你需要把每一輪 (batch) 產生的 x̃ 存起來供下次使用 x(t) How?
  • 22. Persistent CD (PCD) Tieleman, ICML 2008 http://icml2008.cs.helsinki.fi/papers/638.pdf
  • 23. Parallel Tempering (PT) ● 另外一種改進的訓練方法是,加 上溫度項: 其中r=1,...,M,總共有M個溫度Tr ,我 們可以平行地對這M個溫度做CD,然 後讓鄰近溫度間產生的sample 有機 率exchange,達到更好的估計 k=1 k=2 k=5 k=10 k=20 k=100 M=4 M=50 An Introductionto Restricted Boltzmann Machines https://web.archive.org/web/20140211020253/http://image.diku.dk/igel/paper/AItRBM-proof.pdf
  • 24. Filters LAROCHELLE ET AL., JMLR2009 http://jmlr.org//papers/v10/larochelle09a.html x1......xn hj reshape x1......xk ….......xn
  • 25. Debug ● RBM 很難debug,但有一些方法可以告訴你是否正確training 1. 畫出重構誤差 ||x(t)-x̃||^2 看是否隨訓練次數遞減 2. 畫出filter 3. 估計partition function Z並計算 NLL 是否遞減 On the Quantitative Analysis of Deep Belief Networks. Ruslan Salakhutdinov and Iain Murray, 2008 https://www.cs.toronto.edu/~rsalakhu/papers/dbn_ais.pdf
  • 26. GAUSSIAN-BERNOULLI RBM ● 如果input x 的定義域是所有實數 ● 這時energy function 多加一個x平方項 ● 此時唯一改變的只有 p(x|h) 會變成高斯分布,有平均 標準差單位矩陣 ● 這時候建議把 training set normalized 成平均為0,標準差為1 ● 應該使用更小的 learning rate 如果要讓x定義域 為所有實數,為了 讓 p(x|h) 分母的積 分有 close form, 最簡單是加上平方 項
  • 27. Other Types of Observations ● Real-valued: Gaussian-Bernoulli RBM ● Binomial observations: ○ Rate-coded Restricted Boltzmann Machines for Face Recognition. Yee Whye Teh and Geoffrey Hinton, 2001 https://papers.nips.cc/paper/1886-rate-coded-restricted-b oltzmann-machines-for-face-recognition.pdf ● Multinomial observations: ○ Replicated Softmax: an Undirected Topic Model. Ruslan Salakhutdinov and Geoffrey Hinton, 2009 https://papers.nips.cc/paper/3856-replicated-softmax-an-u ndirected-topic-model ○ Training Restricted Boltzmann Machines on Word Observations. George Dahl, Ryan Adam and Hugo Larochelle, 2012 https://arxiv.org/pdf/1202.5695.pdf 當input 為0~N時,例如每個pixel 有 0~255 的強度,可以很簡單的將 input x表示為重複出現幾個1,出現越多強度 越強,最多255個1,結果變成一個 binomial distribution 問題。 當 input 為多個 words 的時候,每個 word 可以用 onehot 表示,因此很多 個words 的排列組合,就是很 多組 onehot 的排列組合,即為 multinomial distribution。 想想如何用在N spin system上?
  • 28. Boltzmann Machine ● 原始的 Boltzmann Machine 在每一層內部都有連結,因此能量函數會多兩項 ● 當只有一層內部有連結,稱為 semi-restricted Boltzmann Machine ● 因為沒有辦法像 RBM 用Gibbs sampling 方式來training,因此很少人討論此model
  • 29. Deep Belief Network ● DBN 是一種生成模型,結合無向和有向的變數 連結 ● 最上面兩層p(h(2),h(3)) 是RBM ● 其他層是貝氏網路(Bayesian network) ○ 每一層在給定了上一層的條件分布為: ○ 又稱為sigmoid belief network (SBN) ● DBN 不是前饋網路(feed-forward network) Neural networks [7.7] : Deep learning - deep belief network - YouTube https://www.youtube.com/watch?v=vkb6AWYXZ5I&list=PL6Xpj9I5qXYEcOhn 7TqghAJ6NAPrNmUBH&index=57 Hugo Larochelle http://info.usherbrooke.ca/hlarochelle/neural_networks/content.html
  • 30. Deep Belief Network ● DBN 是一種生成模型,結合無向和有向的變數 連結 ● 最上面兩層p(h(2),h(3)) 是RBM ● 其他層是貝氏網路(Bayesian network) ○ 每一層在給定了上一層的條件分布為: ○ 又稱為sigmoid belief network (SBN) ● DBN 不是前饋網路(feed-forward network) Neural networks [7.7] : Deep learning - deep belief network - YouTube https://www.youtube.com/watch?v=vkb6AWYXZ5I&list=PL6Xpj9I5qXYEcOhn 7TqghAJ6NAPrNmUBH&index=57 Hugo Larochelle http://info.usherbrooke.ca/hlarochelle/neural_networks/content.html 所謂貝氏網路是一 種有向無環圖,每 一個可見的效應 (visible effect)都由 數個隨機隱變因 (Stochastic hidden cause) 造 成 Deep Belief Nets: CS590M 2008 Fall Paper Presentation https://www.slideshare.net/butest/deep-belief-nets
  • 31. Inference ● The full distribution of a DBN is as follows: ● where: 先從最上面兩層的 RBM 用 Gibbs sampling 產生 h(2),下面的SBN 都是單向的,給定h(2) 產生h(1), 給定h(1)產生x
  • 32. Training ● 先把第1,2層當 RBM訓練 ● 固定1,2層的參數 W1 ,用W1 T 初始 化2,3層參數,把 2,3層當RBM訓 練 ● 固定2,3層參數 W2 ,用W2 T 初始 化3,4層參數,把 3,4層當RBM 做 訓練 ● 以此類推 W1 W1 W1 T W1 W2 W2 T p(h(1)) 可以寫成 sum over h(2) p(h(1),h(2)) 每增加一層,代表用更高階的 feature 來表示前一 層 feature。
  • 33. ● log p(x)可以寫成: Variational bound ● 上述training 法是利用 Variational bound ● 首先,利用log 函數的凹性(concave)
  • 34. Variational bound ● 若 q(h(1)|x) 等於真實分布p(h(1)|x),則等號成立 ● 當 q(h(1)|x) 與p(h(1)|x) 差距越大,則下界越鬆 ● 事實上,不等式兩邊同減 log p(x),可以得到KL divergence: log p(x,h(1)) = log p(h(1)|x) + log p(x)
  • 35. Variational bound ● 只有一層隱藏層時,p(x|h(1)) 與 p(h(1)) 都只跟第一層有關 ● 加入第二層隱藏層後,p(h(1)) 可寫成對 h(2)的積分 ● 因此,訓練第二層就相當於最小化下式: ● 這就相當於在由 q(h(1)|x) 所產生的data 上訓練一個RBM! q(h(1)|x) 是第一層 近似的h(1)的條件 分布,但離真實的 p(h(1)) 還有差距, 所以用第二層h(2) 來近似
  • 36. Variational bound ● 我們可以從第一層RBM 得到q(h(1)|x) ○ 相當於feed-forward (sigmoidal) layer, followed by sampling ● 藉由初始化第二層 RBM weight 成為第一層 RBM weight 的transpose,the bound is initially tight ○ 事實上,2 layer DBN with tied weight 等同於 1 layer RBM W WT h(1) h(2) x
  • 37. Variational bound ● 上述增加layer 的過程可以反覆迭代 ● 訓練目標是最大化 bound 下界 ○ 理論上,如果一開始估計的 q(h(1)|x) 離真實後驗(ture posterior) 非常遠,bound 就會很 鬆 ○ 這只代表我們可能無法改善true likelihood ○ 但我們仍可取出更好的feature W WT h(1) h(2) x
  • 38. Fine-Tuning ● Up-Down algorithm: ○ A fast learning algorithm for deep belief nets.Hinton, Teh, Osindero, 2006 https://www.cs.toronto.edu/~hinton/a bsps/fastnc.pdf ○ 將input x從下方傳到最頂層,由最頂層 RBM 做Gibbs sampling,再往下傳回 來,產生x̃,修正最頂層參數 ● Back Propagation: ○ 从自联想神经网络到深度神经网络 https://blog.csdn.net/celerychen2009/ article/details/9079715 ○ 如果有 label 的話,就直接在最頂層再 接上一層BP 層,用BP做fine-tuning Deep Belief Nets: CS590M 2008 Fall Paper Presentation https://www.slideshare.net/bute st/deep-belief-nets
  • 39. Deep Autoencoder ● 因為深層的autoencoder 非常難train,所以有人就 想到了可以拆成好幾個 RBM 訓練,最後再做 fine-tune Deep Belief Nets: CS590M 2008 Fall Paper Presentation https://www.slideshare.net/butest/deep-belie f-nets
  • 40. 附錄:最大熵原理 ● 已知系統的熵為 ,且機率和為1,即 給定k個限制條件 求熵的極大值? ● 使用 Lagrange multiplier method ,等同於求解下式之極 值: ● 解得:
  • 41. 附錄:最大熵原理 ● 對照 RBM 的energy function: ● 最大熵原理告訴我們,如果系統有k個限制條件,若用最少參數來描述這個系統,就是波茲曼分布,只需要k個參數。其他 的分布形式必然需要更多參數才能描述該系統。 ● RBM 的energy function 組成了多組限制條件,代表的就是這個dataset 的守恆量,如果data 是來自同一個分布,那這 些量應該要一樣,例如每個pixel的期望值,再根據這些守恆量,找出最少參數能符合這些限制條件的分布。 ● 顯然的,如果圖片稍微轉動,那麼pixel 的期望值也會跟著變,所以pixel 不是一個很好的守恆量。 ● 如果CNN的最後一層接上softmax,只看倒數第一、二層,其實就很像RBM。因此倒數第二層所代表的應該是dataset 中 會守恆的特徵,這樣子期望值算出來是固定的,才是一個好的守恆量。而這些好的守恆量,其實就是人眼看起來比較高層 次的結構! ● 想想看,現代神經網路最後一層為什麼要加上 softmax?只是單純湊個機率的樣子嗎? “熵”不起:从熵、最大熵原理到最大熵模型(二) - 科学空间|Scientific Spaces https://kexue.fm/archives/3552 這裡的ck 對應到λi 是個待定係數,而對應的限制條件是𝔼 (x)=𝜏,如果x是圖片的pixel,就是該pixel 在dataset 的期 望值,其物理意義為:如果data 是來自同一個分布,每個 pixel 的期望值應該是守恆的;如果生成的data 與真實 data 期望值差太多,學到的係數ck 就無法代表λi 的解,所 以就不是屬於同個分布。
  • 42. 附錄:最大熵原理 ● 對照 RBM 的energy function: ● 最大熵原理告訴我們,如果系統有k個限制條件,若用最少參數來描述這個系統,就是波茲曼分布,只需要k個參數。其他 的分布形式必然需要更多參數才能描述該系統。 ● RBM 的energy function 組成了多組限制條件,代表的就是這個dataset 的守恆量,如果data 是來自同一個分布,那這 些量應該要一樣,例如每個pixel的期望值,再根據這些守恆量,找出最少參數能符合這些限制條件的分布。 ● 顯然的,如果圖片稍微轉動,那麼pixel 的期望值也會跟著變,所以pixel 不是一個很好的守恆量。 ● 如果CNN的最後一層接上softmax,只看倒數第一、二層,其實就很像RBM。因此倒數第二層所代表的應該是dataset 中 會守恆的特徵,這樣子期望值算出來是固定的,才是一個好的守恆量。而這些好的守恆量,其實就是人眼看起來比較高層 次的結構! ● 想想看,現代神經網路最後一層為什麼要加上 softmax?只是單純湊個機率的樣子嗎? “熵”不起:从熵、最大熵原理到最大熵模型(二) - 科学空间|Scientific Spaces https://kexue.fm/archives/3552 這裡的ck 對應到λi 是個待定係數,而對應的限制條件是𝔼 (x)=𝜏,如果x是圖片的pixel,就是該pixel 在dataset 的期 望值,其物理意義為:如果data 是來自同一個分布,每個 pixel 的期望值應該是守恆的;如果生成的data 與真實 data 期望值差太多,學到的係數ck 就無法代表λi 的解,所 以就不是屬於同個分布。
  • 43. ● 簡單說,RBM 所謂的energy 指的其實就是dataset 中的守恆量;如果dataset 是圖片,而你預期來自同一個分布 的圖片,每個pixel 的期望值應該要一樣,那這個pixel 的期望值就是這個分布的圖片的限制條件。 ● 然而,pixel 並不是一個好的守恆特徵,因為很顯然只要把圖片轉一下,pixel 期望值就改變了。所以一個好的特徵 應該是在各種可能的狀況底下,取期望值之後能夠保持守恆。 ● 如果看CNN,通常最後一層是接softmax,只看倒數兩層的話,就是RBM。我們可以知道,如果RBM 結果要好,倒 數第二層的特徵應該是一個好的守恆量。換句話說,它應該是一個不會因為稍微轉動而改變的特徵。而這對應到 就是人眼所看的高層次特徵(眼睛鼻子嘴巴...等)。 ● 因為倒數第二層要找的是這樣一個守恆量,所以前面一大堆好幾層,目的其實就是為了湊出這些高層次的特徵, 所以才會有CNN 到越後面幾層出現越高層次的結構。 ● 所以什麼是圖像中的守恆量呢?就是那些正著看、歪著看都不太會認錯的結構;那什麼是語言中的守恆量呢?這 有點難,因為語序改變通常意思就會變,除非整個上下文意思是連貫而且明確的,即使語序調換也不影響所表達 意思的,而這個"意思"就是我們想要的高層次特徵。 ● 所以帶到法律判決分類問題上,法官的"意思"是一種高層次特徵,不管他整篇判決書寫了甚麼,他的"意思"是不變 的,可以說在所有這些判決書中,有一些"意思"可以做為好的特徵,因為不管怎麼看它都代表那個意思。這也就是 我們之所以可以用有利不利句子來做分類的基礎。 ● 這就給出了NLP的一個限制,這些語言中的"意思"很可能只有在特定情況下才有那個"意思",不像圖片拿到哪裡, 貓就是貓,狗就是狗。所以文字只有在特定某個語料庫中,用詞跟它的"意思"沒有改變太大的情況下,分類才有好 的結果。
  • 44. End ● Thank you very much ● Any questions?