gpt4 book ai didi

python - 使用FreqDist,python总结词频数

转载 作者:行者123 更新时间:2023-11-28 20:28:50 24 4
gpt4 key购买 nike

如何使用 FreqDist 中的 fd.items() 来总结词频数?

>>> fd = FreqDist(text) 
>>> most_freq_w = fd.keys()[:10] #gives me the most 10 frequent words in the text
>>> #here I should sum up numbers of each of these 10 freq words appear in the text

例如如果most_freq_w中的每个词出现10次,结果应该是100

!!!我不需要文本中所有单词的数量,只需要最常见的 10 个

最佳答案

我不熟悉 nltk,但由于 FreqDist 派生自 dict,因此以下内容应该有效:

v = fd.values()
v.sort()
count = sum(v[-10:])

关于python - 使用FreqDist,python总结词频数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4206979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com