12.7

词频统计:

import nltk
tokens=[ 'my','dog','has','flea','problems','help','please',
'maybe','not','take','him','to','dog','park','stupid',
'my','dalmation','is','so','cute','I','love','him' ]
#统计词频
freq = nltk.FreqDist(tokens)

#输出词和相应的频率
for key,val in freq.items():
print (str(key) + ':' + str(val))

#可以把最常用的5个单词拿出来
standard_freq=freq.most_common(5)
print(standard_freq)

posted @ 2021-12-07 20:19  韩佳龙  阅读(112)  评论(0编辑  收藏  举报