Mark Chang's Blog

Machine Learning, Deep Learning and Python

Ngram Smoothing / Interpolation

以下為我對於 Ngram Smoothing 這個章節的公式所做的筆記

Introduction

Ngram Smoothing 是用於出現在 Training Corpus 中沒有的 Ngram,

它的機率會是0

本文以 Bigram 為例, Bigram 的機率如下:

如果 , 則

為了避免probability為0, 我們要做 Ngram Smoothing

Laplace Smoothing

最簡單的想法, 就是把每一個 Ngramcount 都加1, 然後再做 Normalization

其中, 是所有 Ngram 的種類

若是用於 bigram , 則機率為:

Good-Turing Discounting

這種方法是由 Good (1953) 提出

是根據 Ngramcount 來估計, 例如 countnNgram, 用 Nountn+1Ngram 來估計:

其中 countcNgram 個數

例如, count0Ngram ,個數為

若當我們要計算出現 , (things with frequency zero in training) , 的機率,

可設 ,則:

舉個例子,河裡面有八種魚,釣到的次數如下:

carp perch whitefish trout salmon eel catfish bass
10 3 2 1 1 1 0 0

則下一次釣到出現 未出現過的魚 (catfish or bass) 的機率為:

若已知道未出現過的魚有兩種, 則釣到 catfish 的機率為:

再來看看釣到 trout 的機率:

Advanced Good-Turing

因為可能當 時,

這種情況, 用 linear regression 在log space去smooth ,如下:

再來, 於 Katz, S. M. (1987) 提到

discounted estimation 並不適用於所有的 ,

Interpolation:

因為 Trigramcount 可能為0,

我們可以用內插法把 TrigramCount 表示成 Trigram, BigramUnigram 的內插

如下:

我們也可以讓 可跟著前後文調整數值,像這樣:

至於 的值要怎麼算呢?可以用 Maximum Likelihood Estimation 求得

Reference:

本篇擷取自教科書:

Daniel Jurafsky & James H. Martin.Speech and Language Processing: An introduction to natural language processing,computational linguistics, and speech recognition.

其他參考文獻:

Good, I. J. (1953). The population frequencies of species and the estimation of population parameters. Biometrika, 40,16–264.

Katz, S. M. (1987). Estimation of probabilities from sparse data for the language model component of a speech recogniser

Comments