Language Model for ASR

Background

Automatic Speech Recognition (ASR) uses both acoustic model (AM) and language model (LM) to output the transcript of an input audio signal.
y^∗ = \arg \max [\log P_{AM}(y|x) + \lambda \log P_{LM}(y)]

Acoustic Model
Assigns a probability distribution over a vocabulary of characters given an audio frame.

Language Model

  • Task 1: Assigns a probability distribution over a sequence of words.
  • Task 2: Given a sequence of words, it assigns a probability to the whole sequence.
    Given a corpus of tokens x = (x_1, . . . , x_T), the task of language modeling is to estimate the joint probability P(x) (Task 2). P(x) can be auto-regressively factorized as P(x) = \prod_t P(x_t | x_{<t}) by chain rule. With the factorization, the problem reduces to estimating each conditional factor (Task 1).

Structure

A proposed structure[1] is shown bellow. With n-gram model (such as KenLM[2]) is implement for decoding and gives ASR output, and NN LM(neural network language model) complements it. Beam search in hypothesis formation is governed by the joint score of ASR and KenLM, and the resulting beams are additionally re-scored with NN LM in a single forward pass.Using NN LM instead of KenLM all the way along is too expensive due to much slower inference of the former.

ASR correction model based on NN encoder-decoder architecture

Language Model

n-gram

The n-gram model is the most widely used language models.

Definition: an n-gram model is a probability distribution based on the nth order Markov assumption
P(w_i | w_1 . . . w_{i−1}) = Pr(w_i | w_{i-n-1} . . . w_{i−1})

Maximum Likelihood Estimation
c(w_1 . . . w_k) is the count of sequence w_1 . . . w_k, the ML estimation for c(w_1 . . . w_{n-1})\neq 0:
P(w_n | w_1 . . . w_{n−1}) = \frac{c(w_1 . . . w_n)}{c(w_1 . . . w_{n-1})}
The problem: c(w_1 . . . w_n) = 0 makes P(w_n | w_1 . . . w_{n−1})=0.

N-Gram Model Problems

  • Sparsity: assigning probability zero to sequences not found in the sample ==> means speech recognition errors.
    Solution:
    • Smoothing: adjusting ML estimates to reserve probability mass for unseen events. Typical form: interpolation of n-gram models, e.g., trigram, bigram, unigram frequencies.
      P(w_3|w_1w_2) = \alpha_1c(w3|w1w2) + \alpha_2c(w_3|w_2) + \alpha_3c(w_3).
      Some widely used techniques:
      • Katz Back-off models (Katz, 1987).
      • Interpolated models (Jelinek and Mercer, 1980).
      • Kneser-Ney models (Kneser and Ney, 1995).
    • Class-based models: create models based on classes (e.g., DAY) or phrases.
  • Representation: for |\Sigma|=10^{5}, the number of bigrams is 10^{10}, the number of trigrams 10^{15}!
    Solution:
    • Weighted automata: exploiting sparsity.

In deepspeech, a n-gram model called KenLM[2] is used. KenLM exploits Hash table with linear probing. Linear probing places at most one entry in each bucket. When a collision occurs, linear probing places the entry to be inserted in the next (higher index) empty bucket, wrapping around as necessary.

Neural Network

A trainable neural network is used to encode the context x<t into a fixed size hidden state, which is multiplied with the word embeddings to obtain the logits. The logits are then fed into the Softmax function, yielding a categorical probability distribution over the next token. The central problem is how to train a Transformer to effectively encode an arbitrarily long context into a fixed size representation.

Vanilla Model

One feasible but crude approximation is to split the entire corpus into shorter segments of manageable sizes, and only train the model within each segment, ignoring all contextual information from previous segments[3] .

Masked Attention: To ensure that the model’s predictions are only conditioned on past characters, we mask our attention layers with a causal attention, so each position can only attend leftward.

Character transformer network of two layers pro- cessing a four character sequence to predict t_4. The causal attention mask limits information to left-to-right flow. Red arrows highlight the prediction task the network has to learn.

Auxiliary Losses: The training through addition auxiliary losses not only speed up convergence but also serve as an additional regularizer. Auxiliary losses only valid during training so that a number of the network parameters are only used during training--“training parameters”(distinguish between “inference parameters”). Three types of auxiliary losses, corresponding to intermediate positions, intermediate layers, and non-adjacent targets.

Positional Embeddings: The timing information may get lost during the propagation through the layers. To address this, replace the timing signal with a learned per-layer positional embedding added to the in-put sequence before each transformer layer, giving a total of L×N×512 additional parameters. (512-dimensional embedding vector, L: context positions, N: layers)

During evaluation, at each step, the vanilla model also consumes a segment of the same length as in training, but only makes one prediction at the last position. Then, at the next step, the segment is shifted to the right by only one position, and the new segment has to be processed all from scratch. The evaluation procedure is extremely expensive.

Illustration of the vanilla model with a segment length 4.

Transformer-XL

Transformer-XL (meaning extra long) is introduced to address the limitations of using a fixed-length context[4]. During training, the hidden state sequence computed for the previous segment is fixed and cached to be reused as an extended context when the model processes the next new segment. Although the gradient still remains within a segment, this additional input allows the network to exploit information in the history, leading to an ability of modeling longer-term dependency and avoiding context fragmentation.

Illustration of the Transformer-XL model with a segment length 4.

Multi-layer Dependency: the recurrent dependency between the hidden states shifts one layer downwards per-segment, which differs from the same-layer recurrence in conventional RNN-LMs.

Faster Evaluation: during evaluation, the representations from the previous segments can be reused. 1,800+ times faster than the vanilla model.

Length-M Memory Extension: We can cache M (more than one) previous segments, and reuse all of them as the extra context when processing the current segment.

Relative Positional Encodings: how can we keep the positional information coherent when we reuse the states? Traditional method: input the transformer element-wise addition of the word embeddings and the positional encodings.
h_{\tau+1} = f(h_{\tau}, E_{s_{\tau+1}}+U_{1:L})
In this way, both E_{s_{\tau+1}} and E_{s_{\tau}}are associated with the same positional encoding U_{1:L}.
In order to avoid this failure mode, the fundamental idea is to only encode the relative positional information in the hidden states. The positional encoding gives the model a temporal clue or “bias” about how information should be gathered, i.e., where to attend. Instead of incorporating bias statically into the initial embedding, one can inject the same information into the attention score of each layer.
In the standard Transformer:


The proposed relative positional encodings:

  • Replace all appearances of the absolute positional embedding U_j for computing key vectors in term (b) and (d) with its relative counterpart R_{i−j}.
  • Introduce a trainable parameter u \in \mathbb{R}^d to replace the query U_i^T W_i^T. It suggests that the attentive bias towards different words should re- main the same regardless of the query position.
  • Deliberately separate the two weight matrices W_{k,E} and W_{k,R} for producing the content-based key vectors and location-based key vectors respectively.

Summarize the computational procedure for a N-layer Transformer-XL with a single attention head:


Summary

In the analytic study[5], it has empirically shown that a standard LSTM language model can effectively use about 200 tokens of context on two benchmark datasets, regardless of hyperparameter settings such as model size. It is sensitive to word order in the nearby context, but less so in the long-range context. In addition, the model is able to regenerate words from nearby context, but heavily relies on caches to copy words from far away.

Reference


  1. Hrinchuk, O., Popova, M., & Ginsburg, B. (2020). Correction of Automatic Speech Recognition with Transformer Sequence-To-Sequence Model. ICASSP, IEEE International Conference on Acoustics, Speech and Signal Processing - Proceedings, 2020-May, 7074–7078. https://doi.org/10.1109/ICASSP40776.2020.9053051

  2. Kenneth Heafield. (2011). KenLM: Faster and Smaller Language Model Queries. Proceedings of the Sixth Workshop on Statistical Machine Translation, 187--197. http://sites.google.com/site/murmurhash/%0Ahttp://kheafield.com/professional/avenue/kenlm.pdf

  3. Al-Rfou, R., Choe, D., Constant, N., Guo, M., & Jones, L. (2019). Character-Level Language Modeling with Deeper Self-Attention. Proceedings of the AAAI Conference on Artificial Intelligence, 33, 3159–3166. https://doi.org/10.1609/aaai.v33i01.33013159

  4. Dai, Z., Yang, Z., Yang, Y., Carbonell, J., Le, Q. V., & Salakhutdinov, R. (2020). Transformer-XL: Attentive language models beyond a fixed-length context. ACL 2019 - 57th Annual Meeting of the Association for Computational Linguistics, Proceedings of the Conference, 2978–2988. https://doi.org/10.18653/v1/p19-1285

  5. Khandelwal, U., He, H., Qi, P., & Jurafsky, D. (2018). Sharp nearby, fuzzy far away: How neural language models use context. ACL 2018 - 56th Annual Meeting of the Association for Computational Linguistics, Proceedings of the Conference (Long Papers), 1, 284–294. https://doi.org/10.18653/v1/p18-1027

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,723评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,003评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,512评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,825评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,874评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,841评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,812评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,582评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,033评论 1 308
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,309评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,450评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,158评论 5 341
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,789评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,409评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,609评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,440评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,357评论 2 352

推荐阅读更多精彩内容