Sequence Model - Sequence Models & Attention Mechanism

时间:2021-08-24 09:41:27   收藏:0   阅读:19

Various Sequence To Sequence Architectures

Basic Models

Sequence to sequence model

技术分享图片

Image captioning

use CNN(AlexNet) first to get a 4096-dimensional vector, feed it to a RNN

Picking the Most Likely Sentence

translate a French sentence \(x\) to the most likely English sentence \(y\) .

it‘s to find

\[\argmax_{y^{<1>}, \dots, y^{<T_y>}} P(y^{<1>}, \dots, y^{<T_y>} | x) \]

if \(B = 1\), it‘s just greedy search.

Length normalization

\[\argmax_{y} \prod_{t = 1}^{T_y} P(y^{<t>}|x, y^{<1>}, y^{<t - 1>}) \]

\(P\) is much less than \(1\) (close to \(0\)) take \(\log\)

\[\argmax_{y} \sum_{t = 1}^{T_y} \log P(y^{<t>}|x, y^{<1>}, y^{<t - 1>}) \]

it tends to give the short sentences.

So you can normalize it (\(\alpha\) is a hyperparameter)

\[\argmax_{y} \frac 1 {T_y^{\alpha}} \sum_{t = 1}^{T_y} \log P(y^{<t>}|x, y^{<1>}, y^{<t - 1>}) \]

Beam search discussion

let \(y^*\) be human high quality translation, and \(\hat y\) be algorithm output.

Bleu(bilingual evaluation understudy) Score

if you have some good referrences to evaluate the score.

\[p_n = \frac{\sum_{\text{n-grams} \in \hat y} \text{Count}_{\text{clip}}(\text{n-grams})} {\sum_{\text{n-grams} \in \hat y} \text{Count}(\text{n-grams})} \]

Bleu details

calculate it with \(\exp(\frac{1}{4} \sum_{n = 1}^4 p_n)\)

BP = brevity penalty

\[BP = \begin{cases} 1 & \text{if~~MT\_output\_length > reference\_output\_length}\\exp(1 - \text{reference\_output\_length / MT\_output\_length}) & \text{otherwise} \end{cases} \]

don‘t want short translation.

Attention Model Intuition

it‘s hard for network to memorize the whole sentence.

技术分享图片

compute the attention weight to predict the word from the context

技术分享图片

Attention Model

Use a BiRNN or BiLSTM.

\[\begin{aligned} a^{<t‘>} &= (\vec a^{<t‘>}, \overleftarrow a^{<t‘>})\\sum_{t‘} \alpha^{<i, t‘>} &= 1\c^{<i>} &= \sum_{t‘} \alpha^{<i, t‘>} \alpha^{<t‘>} \end{aligned} \]

技术分享图片

Computing attention

\[\begin{aligned} \alpha^{<t, t‘>} &= \text{amount of "attention" } y^{<t>} \text{ should pay to } a^{<t‘>}\&= \frac{\exp(e^{<t, t‘>})}{\sum_{t‘ = 1}^{T_x} \exp(e^{<t, t‘>})} \end{aligned} \]

train a very small network to learn what the function is

the complexity is \(\mathcal O(T_x T_y)\) , which is so big (quadratic cost)

技术分享图片

Speech Recognition - Audio Data

Speech recognition

\(x(\text{audio clip}) \to y(\text{transcript})\)

Attention model for sppech recognition

generate character by character

CTC cost for speech recognition

CTC(Connectionist temporal classification)

"ttt_h_eee___ ____qqq\(\dots\)" \(\rightarrow\) "the quick brown fox"

Basic rule: collapse repeated characters not separated by "blank"

Trigger Word Detection

label the trigger word, let the output be \(1\)s

原文:https://www.cnblogs.com/zjp-shadow/p/15178221.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!