Day04 - 端到端(end-to-end)语音辨识-attention 机制

如果近几年来有在关注深度学习技术发展的话,一定有听过 attention model 以及 Attention Is All You Need 这篇非常有名的论文,论文的细节这边就不多谈了,网路都可以找的到相当丰富的说明、实作。这边主要要探讨的是如何使用 attention 解决之前提到的输入序列过长会导辨识效果不佳的问题。

Attention 的核心概念可以以下这句话来描述:

Attention: At different steps, let a model "focus" on different parts of the input.

Attention 机制的加入,会让 decoder 在解码的过程中找出输入序列中哪些部分较为重要,因此 encoder 不需要再将输入序列压缩成一固定大小的 context vector。

而 decoder 中的每一个 hidden state 都会有不同的 context vector,也就是说如果输入序列有 N 个音框(frame),就会产生 N 个 context vector。接下来我们用数学式子来表示 attention 的运作过程:


  • all encoder hidden states: https://chart.googleapis.com/chart?cht=tx&chl=s_%7B1%7D%2Cs_%7B2%7D%2C...%2Cs_%7Bm%7D

  • decoder hidden state at timestamp t : https://chart.googleapis.com/chart?cht=tx&chl=h_%7Bt%7D

  • Attention weights: 将目前时间点 (timestamp) decoder 的 hidden state https://chart.googleapis.com/chart?cht=tx&chl=h_%7Bt%7D 对所有 encoder 的 hidden state 进行 score function,再透过 softmax function 计算出 https://chart.googleapis.com/chart?cht=tx&chl=h_%7Bt%7D 对每一个时间点 https://chart.googleapis.com/chart?cht=tx&chl=s_%7Bi%7D 的重要程度
    https://chart.googleapis.com/chart?cht=tx&chl=%5Calpha_%7Bk%7D(t)%3D%5Cfrac%7Bexp(score(h_%7Bt%7D%2Cs_%7Bk%7D))%7D%7B%5Csum_%7Bi%3D1%7D%5E%7Bm%7Dexp(score(h_%7Bt%7D%2Cs_%7Bi%7D))%7D%2C%20%5C%20k%3D1..%20m

    其中score function 的运算方式有好几种,包括 dot-product, bilinear, multi-layer perceptron 等

  • Context vector: 将 attention weights 与 encoder hidden state https://chart.googleapis.com/chart?cht=tx&chl=h_%7Bs%7D 进行 weighted sum

    https://chart.googleapis.com/chart?cht=tx&chl=c_%7Bt%7D%3D%5Csum_%7Bk%3D1%7D%5E%7Bm%7D%5Calpha_%7Bk%7D(t)s_%7Bk%7D


完整流程架构可以参考下图:
https://ithelp.ithome.com.tw/upload/images/20210916/20140944JnwvCLopo9.png
Seq2seq attention 架构图,图片来源: https://lena-voita.github.io/nlp_course/seq2seq_and_attention.html

今天的内容就到这边,接下来会介绍之前有提到过的end-to-end model 中另一个方常见的方法 -- Connectionist Temporal Classification (CTC)。

参考资料: https://lena-voita.github.io/nlp_course/seq2seq_and_attention.html


<<:  [Day02] 程序菜鸟自学C++资料结构 – 简单QA

>>:  自动化 End-End 测试 Nightwatch.js 之踩雷笔记:前言

队列

某些较耗时的工作像是寄信、发通知等,如果卡在处理请求的过程中的话就会造成使用者要多等上数秒才能收到回...

【在 iOS 开发路上的大小事-Day12】好用的 CocoaPods 套件-IQKeyboardManagerSwift

前情提要 在开发 App 的时候,有遇过键盘开启的时候,TextField 却被挡住无法输入的情况吗...

Day 18:广度优先搜寻(BFS)

上一回提到广度优先搜寻的步骤是检查图中节点,并将与其相连的节点放入伫列中,再一一检查。 光是这样的文...

温馨鬼故事 - 网购我的爱,我的个资跟着订单出去了

温馨鬼故事 - 网购我的爱,我的个资跟着订单出去了 Credit: Drake 故事开始 以下故事纯...

DAY27 深度学习-卷积神经网路-Yolo v2 (一)

今天的主题是Yolo v2,不过所找到的资料图片可能比较不好理解,有更好的再更新,Yolo v2就是...