LDA主題模型評估方法–Perplexity


在LDA主題模型之后,需要對模型的好壞進行評估,以此依據,判斷改進的參數或者算法的建模能力。

Blei先生在論文《Latent Dirichlet Allocation》實驗中用的是Perplexity值作為評判標准。

一、Perplexity定義

源於wiki:http://en.wikipedia.org/wiki/Perplexity

perplexity是一種信息理論的測量方法,b的perplexity值定義為基於b的熵的能量(b可以是一個概率分布,或者概率模型),通常用於概率模型的比較

wiki上列舉了三種perplexity的計算:

1.1 概率分布的perplexity

公式:  20130718161536515

其中H(p)就是該概率分布的熵。當概率P的K平均分布的時候,帶入上式可以得到P的perplexity值=K。

1.2 概率模型的perplexity

公式: 20130718161551531

公式中的Xi為測試局,可以是句子或者文本,N是測試集的大小(用來歸一化),對於未知分布q,perplexity的值越小,說明模型越好。

指數部分也可以用交叉熵來計算,略過不表。

1.3單詞的perplexity

perplexity經常用於語言模型的評估,物理意義是單詞的編碼大小。例如,如果在某個測試語句上,語言模型的perplexity值為2^190,說明該句子的編碼需要190bits

 

二、如何對LDA建模的主題模型

Blei先生在論文里只列出了perplexity的計算公式,並沒有做過多的解釋。

 

在摸索過得知,M代表測試語料集的文本數量(即多少篇文本),Nd代表第d篇文本的大小(即單詞的個數),P(Wd)代表文本的概率,文本的概率是怎么算出來的呢?

在解決這個問題的時候,看到rickjin這樣解釋的:

20130718161618453

 

p(z)表示的是文本d在該主題z上的分布,應該是p(z|d)

這里有個誤區需要注意:Blei是從每篇文本的角度來計算perplexity的,而rickjin是從單詞的角度計算perplexity的,不要弄混了。

總結一下:

測試文本集中有M篇文本,對詞袋模型里的任意一個單詞w,P(w)=∑z p(z|d)*p(w|z),即該詞在所有主題分布值和該詞所在文本的主題分布乘積。

模型的perplexity就是exp^{ – (∑log(p(w))) / (N) },∑log(p(w))是對所有單詞取log(直接相乘一般都轉化成指數和對數的計算形式),N的測試集的單詞數量(不排重)

 

評估LDA主題模型-perflexity

 

LDA主題模型好壞的評估,判斷改進的參數或者算法的建模能力。

perplexity is only a crude measure, it's helpful (when using LDA) to get 'close' to the appropriate number of topics in a corpus. 

Blei先生在論文《Latent Dirichlet Allocation》實驗中用的是Perplexity值作為評判標准,並在論文里只列出了perplexity的計算公式。

Note:M代表測試語料集的文本數量,Nd代表第d篇文本的大小(即單詞的個數),P(Wd)代表文本的概率

文本的概率的計算:

p(z)表示的是文本d在該主題z上的分布,應該是p(z|d)

Note:

1. Blei是從每篇文本的角度來計算perplexity的,而上面是從單詞的角度計算perplexity。

2. 測試文本集中有M篇文本,對詞袋模型里的任意一個單詞w,P(w)=∑z p(z|d)*p(w|z),即該詞在所有主題分布值和該詞所在文本的主題分布乘積。

3. 模型的perplexity就是exp^{ - (∑log(p(w))) / (N) },∑log(p(w))是對所有單詞取log(直接相乘一般都轉化成指數和對數的計算形式),N的測試集的單詞數量(不排重)

4. P(w)=∑z p(z|d)*p(w|z)這個w是測試集上的詞匯

[http://blog.csdn.net/pipisorry/article/details/42460023]

[http://faculty.cs.byu.edu/~ringger/CS601R/papers/Heinrich-GibbsLDA.pdf - 29頁]

 

Estimate the perplexity within gensim

The `LdaModel.bound()` method computes a lower bound on perplexity, based on a supplied corpus (~of held-out documents).
This is the method used in Hoffman&Blei&Bach in their "Online Learning for LDA" NIPS article.

[https://groups.google.com/forum/#!topic/gensim/LM619SB57zM]

you can also use model.log_perplexity(heldout), which is a convenience wrapper.

[Questions find in : the mailing list of gensim]

皮皮blog

 

 

評價一個語言模型Evaluating Language

假設我們有一些測試數據,test data.測試數據中有m個句子;s1,s2,s3…,sm

我們可以查看在某個模型下面的概率:image

我們也知道,如果計算相乘是非常麻煩的,可以在此基礎上,以另一種形式來計算模型的好壞程度。

在相乘的基礎上,運用Log,來把乘法轉換成加法來計算。

image

 

補充一下,在這里的p(Si)其實就等於我們前面所介紹的q(the|*,*)*q(dog|*,the)*q(…)…

有了上面的式子,評價一個模型是否好壞的原理在於:

a good model should assign as high probability as possible to these test data sentences.

image,this value as being a measure of how well the alleviate to make sth less painful or difficult to deal with language model predict these test data sentences.

The higher the better.

上面的意思也就是說,如果image的值越大,那么這個模型就越好。

  • 實際上,普遍的評價的指標是perplexity

image

其中,M的值是測試數據test data中的所有的數量。

那么從公式當中查看,可以知道。perplexity的值越小越好。

為了更好的理解perplexity,看下面這個例子:

  • 我們現在有一個單詞集V,N=|V|+1

image

有了上面的條件,可以很容易的計算出:

image

Perplexity是測試branching factor的數值。

branching factor又是什么呢?有的翻譯為分叉率。如果branching factor高,計算起來代價會越大。也可以理解成,分叉率越高,可能性就越多,需要計算的量就越大。

上面的例子q=1/N只是一個舉例,再看看下面這些真實的數據:

  • Goodman的結果,其中|V|=50000,在trigram model的image中,Perplexity=74
  • 在bigram model中,image,Perplexity=137
  • 在unigram model中,image,perplexity=955

在這里也看到了,幾個模型的perplexity的值是不同的,這也就表明了三元模型一般是性能良好的。

[評價一個語言模型Evaluating Language Models:Perplexity]

皮皮blog

 

 

Topic Coherence

一種可能更好的主題模型評價標准

[Optimizing semantic coherence in topic models.]

from:http://blog.csdn.net/pipisorry/article/details/42460023

ref:Topic models evaluation in Gensim

http://stackoverflow.com/questions/19615951/topic-models-evaluation-in-gensim

http://www.52ml.net/14623.html

Ngram model and perplexity in NLTK

http://www.researchgate.net/publication/221484800_Improving_language_model_perplexity_and_recognition_accuracy_for_medical_dictations_via_within-domain_interpolation_with_literal_and_semi-literal_corpora

Investigating the relationship between language model perplexity and IR precision-recall measures.

LDA/NMF/LSA多模型/多主題一致性評價方法《Exploring topic coherence over many models and many topics》K Stevens, P Kegelmeyer, D Andrzejewski... [University of California Los Angeles] (2012)  GITHUB

論文:(概率)生成模型評價方法研究《A note on the evaluation of generative models》Lucas Theis, Aäron van den Oord, Matthias Bethge (2015) 

Notes on A note on the evaluation of generative models by Hugo Larochelle 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM