2018-12-06

If you pay peanuts, you get monkey.

Computation on HMM

Viterbi Algorithm

\delta(t) = \max_{Z_{1:t-1}} P(Z_{1:t-1}, Z_t , x_{1:t})\\ \delta(t) = \max_{Z_{t-1} \in \mathbb Z}\left[\vec\delta(t-1) \times P(Z_t|Z_{t-1})\times P(x_t|Z_t)\right]

Please compute this term using logrithm, will underflow otherwise.

Forward Backward

\begin{aligned} \pi & = \pi(Z_1) = P(Z_1)\\ a(1) & = \pi, b(T) = \vec 1\\ a(t) & = P(x_{1:t}, Z_t) = P(x_t|Z_t)\sum_{Z_{t-1}}P(x_{1:t-1}, Z_{t-1})P(Z_t|Z_{t-1})\\ & = P(x_t|Z_t)\sum_{Z_{t-1}}a(t-1)P(Z_t|Z_{t-1})\\ b(t) & = P(x_{t+1: T}|Z_t) = \sum_{Z_{t+1}}[P(x_{t+2:T}|Z_{t+1})P(Z_{t+1}|Z_t)P(x_{t+1}|Z_{t+1})]\\ & = \sum_{Z_{t+1}} [b(t+1) P(Z_{t+1}|Z_t)]P(x_{t+1}|Z_{t+1}) \end{aligned}

Scaled Forward

Perhaps using P(Z_t|x_{1:t}) rather than using P(Z_t, x_{1:t})?

We define \bold {\hat a}(t) = P(Z_t|x_{1:t}) . We just re-normalizes at each step.
\begin{aligned} \sum_{Z_{t-1}} & P(Z_{t-1}|x_{1:{t-1}}) P(Z_{t}|Z_{t-1}) = P(Z_{t}|x_{1:{t-1}})\\ a'(t) & = P(Z_{t}|x_{1:t-1}) P(x_{t}|Z_{t}) = P(x_{t}, Z_{t}|x_{1:t-1})\\ c(t) & = \sum_{Z_{t}} P(x_{t}, Z_{t}|x_{1:t-1}) = P(x_{t}|x_{1:t-1})\\ \hat a(t) &= \frac{a'(t)}{c(t)} = P(Z_{t}|x_{1:t}) \end{aligned}

c(1) = P(x_1)\\ \prod_{t=s}^e c(t)= P(x_{s:e}|x_{1:s-1})

Scaled Backward

Mostly for working with the scaled forward algorithm. Notice that the backward term was originally a conditional distribution, so not really necessary.

\begin{aligned} \hat b(t) & = \frac{\sum_{Z_{t+1}}{\hat b(t + 1)}P(Z_t|Z_{t+1})P(x_{t+1}|Z_{t+1}) }{c(t+1)}\\ \end{aligned}

Equalities in Scaled Forward-Backward

\left [\prod_{\tau=1}^t c(\tau)\right ]\hat a(t) = P(x_{1:t}) P(Z_t|x_{1:t}) = P(Z_t, x_{1:t}) = a(t)\\ \hat a(t) \hat b(t) P(x) = a(t) b(t) = P(Z_t, x_{1:T})

When you want to do a replacement for the product a(t) b(t+1)
a(t)b(t+1)=\frac{P(x) \hat a(t) \hat b(t)}{c(t+1)}

EM Algorithm

Notice that we are discussing only for MLE(Maximum Likelihood Estimation) of Parameters here. It is possible to use EM in Bayesian Estimation of Parameters.

Problem Formulation in General PGM(Probabilitistic Graphical Models)

Suppose we have a Bayesian Network \mathcal N, which contains parameters \Theta.

Suppose we start from some random parameter estimation \Theta^0.

Suppose we have database D = \left \{D_1, D_2, ..., D_n\right \} , where each D_i = X gives a possibly partial assignment to all the variables in the network.

Assume all data are iid.

For some data sample D_l, we denote the missing variable set to be X_{l}. Denote one possible assignment to the missing variable to be x_l.

Algorithm

The algorithm is iterative, suppose we are at step t of the algorithm.

Step One : Fixing up existing Data

Filling up the fractured dataset, the filled up sample is called a fractional sample(碎权样本). The filled up samples are given a possibility rather than a certainty.

We combine the filled up sample and the normal samples together to form the completed dataset D^c. And the completed data points are denoted D_l^c

D

X_1 X_2 X_3
D_1 1 1 1
D_2 1 2 2
D_3 1 ? 1
D_4 2 ? 2

D_c

X_1 X_2 X_3 P
D_1 1 1 1 1
D_2 1 2 2 1
D_{3, 1} 1 1 1 4/5
D_{3, 2} 1 2 1 1/5
D_{4, 1} 2 1 2 1/5
D_{4, 2} 2 2 2 4/5

P(X_2 = 1|D_3, \Theta^0) = \frac{4}{5}\\ P(X_2 = 2|D_3, \Theta^0) = \frac{1}{5}\\

Step Two : Maximize Weighted Likelihood

We define the weighted (log) likelihood to be the following:
Q(\Theta|\Theta^t) = \sum_{l=1}^m \sum _{x_l \in \mathcal X_l} P(X_l=x_l|D_l, \Theta^t) \log P(D_l,X_l = x_l|\Theta)
This equation is also called the Expected LogLikelihood Function The weight is estimated using the last model parameter step.

The next step is to maximize this function for \Theta^{t+1}.

Step Three : Evaluating Current Step*

Using VE requires recalculate likelihood again on the new parameters completely. Instead, we could another algorithm for efficient continuous evaluation.

Proving EM Algorithm

Monotonicity of the EM Algorithm is guaranteed:
P(D |\Theta^t) \le P(D|\Theta^{t+1})

Observe that:
\sum_{X_l} P(X_l | D_l, \Theta) =1,\quad P(D_l|\Theta) = \frac{P(D_l, X_l|\Theta)}{P(X_l|D_l, \Theta)}\\
Then we can do the following transformation:
\begin{aligned} \log P( D|\Theta) & = &\sum_{l=1}^m \sum_{X_l} P(X_l | D_l, \Theta^t) \log \frac{P(D_l, X_l|\Theta)}{P(X_l|D_l, \Theta)}\\ & = &\sum_{l=1}^m \sum_{X_l} P(X_l | D_l, \Theta^t) \log P(D_l, X_l|\Theta)\\ & &+H(P(X_l|D_l,\Theta^t)||P(X_l|D_l,\Theta))\\ &= & Q(\Theta|\Theta^t) + H(P(X_l|D_l,\Theta^t)||P(X_l|D_l,\Theta)) \\ \end{aligned}

Now this is a fairly interesting result.
\log P(D|\Theta^t) = Q(\Theta^t|\Theta^t) + H_{t|t} = Q(\Theta^t|\Theta^t)\\ \log P(D|\Theta^{t+1}) = Q(\Theta^{t+1}|\Theta^t) + H_{t|t+1}

  • Clearly Q(\Theta^{t+1}|\Theta^t) is guaranteed to be larger than the original Q
  • Cross Entropy is guaranteed to be larger then corss entropy with self, which is 0.

Therefore, EM Algorithm is both converging and monotonic. Although it does not guarantee to converge to any of the global minimums. It might converge to some saddle point or local minimum.

In practice, we rerun the program multiple times and take the best result.

EM in GMM*

P(x) = \sum_{k=1}^K \pi_k \mathcal N(x|\mu_k, \Sigma_k)

We can introduce latent variables to GMM model, making it a latent graphical model:

Z_k \in \left \{ 0, 1\right \}, \sum_{k}Z_k = 1\\ \begin{aligned} P(X) & = \sum_Z P(Z) P(X|Z)\\ & = \sum_Z (\prod_{k=1}^K \pi_k^{Z_k} \mathcal N(x|\mu_k, \Sigma_k)^{Z_k}) \end{aligned}

\begin{aligned} \gamma(i, k) & = P(Z_k = 1|x_i)\\ & = \frac{P(Z_k = 1) P(x_i|Z_k = 1)}{\sum_{j=1}^K P(Z_j = 1)P(x_i|Z_j = 1)}\\ & = \frac{\pi_k \mathcal N(x_i|\mu_k, \Sigma_k)}{\sum_j \pi_j \mathcal N(x_i|\mu_j, \Sigma_j)} \end{aligned}

Then we maximize for the expected log likelihood:
N_k = \sum_{n=1}^N \gamma(i, k), \pi_k = \frac{N_k}{N}\\ \mu_k = \frac{1}{N_k} \sum_{i=1}^N \gamma(i, k) x_i\\ \Sigma_k = \frac{1}{N_k} \sum_{i=1}^N \gamma(i, k) (x_i - \mu_k)(x_i - \mu_k)^T\\

EM in Discrete HMM*

Single Instance Training with non Scaled Forward-Backward

\psi(t) = P(x_{1:T}, Z_t, Z_{t+1}) = P(x_{1:t}, Z_t) \times P(x_{t+2:T}|Z_{t+1}) \times P(Z_{t+1}|Z_{t}) \times P(x_{t+1}|Z_{t+1})\\ \psi(t) = a(t) \times b(t+1) \times P(Z_{t+1}|Z_{t}) \times P(x_{t+1}|Z_{t+1})

\gamma(t) = P(x_{1:T}, Z_t) = \sum_{Z_{t+1}} \psi(t) =a(t) b(t)

\vec \pi = \gamma(1)\\ P'(z'_{t+1}|z'_{t}) = \frac{\sum_{t=1..T-1} \psi(t)(z'_{t+1}|z'_t)}{\sum_{t=1..T-1} \gamma(t)(z'_t)}\\ P'(x'_{t}|z'_{t}) = \frac{\sum_{t=1..T-1} 1(x_t= x'_t)\gamma(t)(z'_t)} {\sum_{t=1..T-1}\gamma(t)(z'_t)}

Batched Training with non Scaled Forward-Backward

Clearly we need to extend the EM algorithm to multiple training samples. Notice that the training results are of variable lengths.

Extend the definition and equations above:

  • We first extend the notations for a single instance of forward and backward:

    a_n(t) Representing the forward result of x^{(n)}

    b_n(t) Representing the backward result of x^{(n)}

  • We introduce the probability of sequence x^{(n)} under current model

    P(x^{(n)}) = P_n

  • Then we extend the equations:
    \psi_n(t) = P(x^{(n)}_{1:T}, Z_t, Z_{t+1})= a_n(t) \times b_n(t+1) \times P(Z_{t+1}|Z_{t}) \times P(x^{(n)}_{t+1}|Z_{t+1})\\ \gamma_n(t) = P(x_{1:T}^{(n)}, Z_t) = \sum_{z_{t+1}} \psi_n(t) = a_n(t) b_n(t)\\

  • Then the updating criterions with probability weighting
    \vec \pi = \frac{\sum_n \frac{1}{P_n} \gamma_n(1)}{\sum_n \frac{1}{P_n}}\\ P'(z'_{t+1}|z'_{t}) = \frac{\sum_n \frac{1}{P_n}\sum_{t=1}^{T_n-1} \psi_n(t)(z'_{t+1}|z'_t)}{\sum_n \frac{1}{P_n} \sum_{t=1}^{T_n-1} \gamma_n(t)(z'_t)}\\ P'(x'_{t}|z'_{t}) = \frac{\sum_n \frac{1}{P_n} \sum_{t=1}^{T_n-1} 1(x_t= x'_t)\gamma_n(t)(z'_t)}{\sum_n \frac{1}{P_n} \sum_{t=1}^{T_n-1}\gamma_n(t)(z'_t)}

  • We will give the update of the not so probable result more weight

  • You can easily modify the equations using the scaled version.

Training HMM in ASR*

Training data is typically not aligned, audio and non-time-stamped text.

Feature Extraction and Forced Alignment

[图片上传失败...(image-4a6351-1544038499224)]

キ|ジ|ノ|ナ|ガ|サ|ワ|ジュ|ゴ|ヲ|コ|エ|テ|ワ|ナ|ラ|ナ|イ

Baum-Welch Training

Optimizing criterion of BW Training:
\Theta = \mathop{\arg\max}_\Theta \sum_ZP(Z, X|\Theta)

  • We set certain transitions in the transition matrix to 0, they will stay 0 during training.
    • Restricting the structure of the path
    • Set the rest possible values to identical ones at the beginning of training.
  • Initialize the mean and variance of gaussians to the corresponding distribution observed in training data.
image-20181205185829859-4007510.png
image-20181205182826102-4005706.png

Viterbi Training

  • Instead of summing over all possible paths, just take the single most likely path
  • Use the Viterbi Algorithm to compute this Viterbi Path
    • This fills in the probability of the missing data determinstically.
  • Much faster than Baum-Welch

\Theta = \mathop{\arg\max}_\Theta \max_ZP(Z, X|\Theta)

It is possible to train using Gradient Descent. Perhaps it is less stable and slower. I haven't compared EM and Gradient Descent yet.

More Variance

  • Standard Training Process:
    • Start with the monophone, do EM Training
    • Clone Gaussians to form triphones
    • Build Decision Tree to cluster Gaussians
    • Clone and train mixtures
  • Increasing Complexity
    • Single State
      • Single Gaussian
      • Multivariate Gaussian
      • Mixture of Multivariate Gaussian
    • What is a state
      • Context Independent Phone
      • Context Independent SubPhone
      • Context Dependent Phone
      • State tied CDPhone
    • Training Scheme
      • BW Training
      • Viterbi Training
image-20181205184306948-4006587.png
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,921评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,635评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,393评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,836评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,833评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,685评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,043评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,694评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,671评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,670评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,779评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,424评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,027评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,984评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,214评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,108评论 2 351
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,517评论 2 343

推荐阅读更多精彩内容

  • 今天记者节 这节日似乎过的越来越羞涩 这几天疯传于朋友圈的关于卫视难以为继的帖子更让圈外人扼腕圈里人黯然。 但是 ...
    車鉴阅读 241评论 0 0
  • 拙政园 拙政园,位于江苏省苏州市,始建于明正德初年(16世纪初),是江南古典园林的代表作品。与北京颐和园、承德避暑...
    小小吴家莹阅读 879评论 0 0
  • 2017-11-14超宇佳珥YA 好多人说过生日要送我kindle,投其所好的事情真的是太棒了。 其实喔,大家慢慢...
    给我一只猴子阅读 139评论 0 0