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 ↩

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 渐变的面目拼图要我怎么拼? 我是疲乏了还是投降了? 不是不允许自己坠落, 我没有滴水不进的保护膜。 就是害怕变得面...
    闷热当乘凉阅读 4,709评论 0赞 13
  • 感觉自己有点神经衰弱,总是觉得手机响了;屋外有人走过;每次妈妈不声不响的进房间突然跟我说话,我都会被吓得半死!一整...
    章鱼的拥抱阅读 2,587评论 4赞 5
  • 夜莺2517阅读 128,777评论 1赞 9
  • 版本:ios 1.2.1 亮点: 1.app角标可以实时更新天气温度或选择空气质量,建议处女座就不要选了,不然老想...
    我就是沉沉阅读 7,990评论 1赞 6

友情链接更多精彩内容