2013-07-17 99 views
4

我試圖確定一組政府文件中的重要條款。生成術語頻率是沒有問題的。tf-idf使用來自Google的單數頻率數據

對於文檔頻率,我希望使用Peter Norvig發佈的handy Python scripts and accompanying data在他的「美麗數據」一章中,其中包括來自Web的龐大數據集中的unigrams頻率。

我的TF-IDF的理解,但問題在於,「文檔頻率」是指含有一個詞的文檔數量,總詞這個詞,而不是數量這就是我們從弱勢族羣得到腳本。我仍然可以將這些數據用於粗略的tf-idf操作嗎?

下面是一些樣本數據:

word tf  global frequency 
china 1684  0.000121447 
the  352385 0.022573582 
economy 6602  0.0000451130774123 
and  160794 0.012681757 
iran 2779  0.0000231482902018 
romney 1159  0.000000678497795593 

廣發簡單地將TF賦予「了」得分高於「經濟」,這是不對的。是否有一些我錯過的基本數學,也許?

+0

有趣的問題。據我的理解:你所說的「gf」事實上已經是相反的了,對吧?所以,當你說'用'gf'來劃分'tf'_時,你實際上是用'gf'_表示_multiplying'tf',對吧? – jogojapan

+0

我不相信gf是相反的。 「The」構成巨型語料庫所有單詞的2.2%,而「and」爲1.2%,「china」爲0.012%。 –

+0

哦,所以你已經將全局計數除以總字數來獲得'gf'。那麼應該給出合理的結果(儘管這種劃分當然是不必要的,因爲它唯一做的是引入一個常數因子)。實際上,從桌子上用'gf'分開'tf' '和'爲15,610,504,而'經濟'爲146,343,374。這有什麼不好? – jogojapan

回答

3

據我所知,在這裏提到的全球頻率等於「反向總詞頻率」Robertson。從這個羅伯遜的紙:

One possible way to get away from this problem would be to make a fairly radical re- 
placement for IDF (that is, radical in principle, although it may be not so radical 
in terms of its practical effects). .... 
the probability from the event space of documents to the event space of term positions 
in the concatenated text of all the documents in the collection. 
Then we have a new measure, called here 
inverse total term frequency: 
... 
On the whole, experiments with inverse total term frequency weights have tended to show 
that they are not as effective as IDF weights 

根據這段文字,你可以使用逆全球頻率IDF來看,雖然比標準的一個多粗。

另外您還缺少stop words刪除。幾乎所有文件都使用這樣的詞語,因此他們不提供任何信息。在tf-idf之前,你應該刪除這樣的停用詞。

+0

好的,但是全球頻率是否可以替代文件頻率還有一個基本問題。 –

+0

我不認爲全球頻率在這裏是相反的 - 「這個」的gf最高,其次是,而「china」等則低得多。但這是一個很大的領先,謝謝! –

+0

你應該反過來,就像你所做的那樣「簡單地用gf來分割tf」 –