栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

来自nltk模块的类似方法在不同的机器上产生不同的结果。为什么?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

来自nltk模块的类似方法在不同的机器上产生不同的结果。为什么?

在您的示例中,有40个其他单词与该单词 恰好 具有 一个
共同点

'monstrous'
。在该
similar
函数中,使用一个
Counter
对象对上下文相似的单词进行计数,然后打印最常见的单词(默认为20)。由于所有40个频率相同,因此顺序可以不同。

从文档的

Counter.most_common

相等计数的元素可以任意排序


我用以下代码检查了类似单词的出现频率(该代码实质上是功能代码相关部分的副本):

from nltk.book import *from nltk.util import tokenwrapfrom nltk.compat import Counterword = 'monstrous'num = 20text1.similar(word)wci = text1._word_context_index._word_to_contextsif word in wci.conditions(): contexts = set(wci[word]) fd = Counter(w for w in wci.conditions() for c in wci[w]    if c in contexts and not w == word) words = [w for w, _ in fd.most_common(num)] # print(tokenwrap(words))print(fd)print(len(fd))print(fd.most_common(num))

输出:(不同的运行给我不同的输出)

Counter({'doleful': 1, 'curious': 1, 'delightfully': 1, 'careful': 1, 'uncommon': 1, 'mean': 1, 'perilous': 1, 'fearless': 1, 'imperial': 1, 'christian': 1, 'trustworthy': 1, 'untoward': 1, 'maddens': 1, 'true': 1, 'contemptible': 1, 'subtly': 1, 'wise': 1, 'lamentable': 1, 'tyrannical': 1, 'puzzled': 1, 'vexatious': 1, 'part': 1, 'gamesome': 1, 'determined': 1, 'reliable': 1, 'lazy': 1, 'passing': 1, 'modifies': 1, 'few': 1, 'horrible': 1, 'candid': 1, 'exasperate': 1, 'pitiable': 1, 'abundant': 1, 'mystifying': 1, 'mouldy': 1, 'loving': 1, 'domineering': 1, 'impalpable': 1, 'singular': 1})


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661832.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号