NLTK的基本使用

NLTK词频统计(Frequency)

复制代码
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 on   季昂  阅读(139)  评论(0编辑  收藏  举报
努力加载评论中...

点击右上角即可分享
微信分享提示