的熵公式词法丰富是词汇丰富性为香农熵;蟒
的概率p-i个是由N,其中N是在文本和V-第i是代币的总数除以V-第i个计算特定类型发生的次数(至少这是我的理解)。
所以,如果我有一个字符串the, the, the, a, a, over, love, one, tree
有9 tokens
,但只有6 types
。
V-'theth'
(据我所知)将是3
因此p-'theth'
将计算为3/9 = 0.33
。 V-'ath'
然后将是0.22
,依此类推。 H
在这种情况下将-100*((0.33*log0.33 + 0.22*log0.22 + 0.11*log0.11 + 0.11*log0.11 + 0.11*log0.11+ 0.11*log0.11)/log9)
虽然我可以得到一个字符串的Python的长度(标记):
string = ['the', 'the', 'the', 'a', 'a', 'over', 'love', 'one', 'tree']
len(string)
9
和种类数量:
len(set(string))
6
我不完全当然我该如何在Python中计算这个公式。 谢谢。
来源:Dale,Moisl和Somers(p.551)。 “自然语言处理手册”(2000年)。 https://books.google.at/books?id=VoOLvxyX0BUC&pg=PA551&lpg=PA551&dq=entropy+vocabulary+richness&source=bl&ots=wucWFF1Rn_&sig=Hms1qwhXlcOaPEXI84eDqxsTEdo&hl=en&sa=X&ved=0CC8Q6AEwAmoVChMIjvvQnvPVxwIVhJ5yCh35ZAb_#v=onepage&q&f=false