词汇丰富度的熵公式是
概率p-ith是用V-ith除以N来计算的,其中N是文本中标记的总数,V-ith是特定类型出现的次数(至少我是这么理解的)。在
所以,如果我有一个字符串the, the, the, a, a, over, love, one, tree
有9tokens
,但只有6types
。在
V-'theth'
(据我所知)将是3
,因此{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
以及类型的数量:
^{pr2}$我不太清楚如何用Python计算这个公式。 谢谢。在
资料来源:戴尔、莫伊尔和萨默斯(第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
要计算西格玛,可以这样做:
要获得令牌频率,可以使用一个简单的dict,其中token作为键,事件作为值。要得到完整的公式,您仍然需要得到
100*entropy/math.log(nbElements,2)
相关问题 更多 >
编程相关推荐