本文整理汇总了Python中nltk.FreqDist.samples方法的典型用法代码示例。如果您正苦于以下问题:Python FreqDist.samples方法的具体用法?Python FreqDist.samples怎么用?Python FreqDist.samples使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.FreqDist
的用法示例。
在下文中一共展示了FreqDist.samples方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list
# 需要导入模块: from nltk import FreqDist [as 别名]
# 或者: from nltk.FreqDist import samples [as 别名]
#
# First
#
# Here we will determine the relative frequencies of English characters in the text
# Then we will calculate the entropy of the distribution
# here we use the expression list(var_name) to turn our string into a list
# this basically separates each character for us to make it so that it works
# directly in the freqdist function
english_unigram_fdist = FreqDist(list(english_model_content))
english_unigram_entropy = 0.0
# now loop and get the entropy for english unigrams
for unigram in english_unigram_fdist.samples():
english_unigram_entropy += english_unigram_fdist.freq(unigram) * math.log(english_unigram_fdist.freq(unigram), 2)
english_unigram_entropy = -english_unigram_entropy
print "The English Unigram Entropy is: " + str(english_unigram_entropy)
#
# Second
#
# Here we will determine the relative frequencies of English bigrams in the text
# Then we will calculate the entropy of the bigram distribution
# create a list to store bigrams in
english_model_bigrams = []