对gensim中filter_extreme用法的误解

2024-04-26 02:38:40 发布

您现在位置:Python中文网/ 问答频道 /正文

import gensim
corpus = [["a","b","c"],["a","d","e"],["a","f","g"]]
from gensim.corpora import Dictionary
dct = Dictionary(corpus)
print(dct)
dct.filter_extremes(no_below=1)
print(dct)

当我运行上面的代码时,我的输出是-

^{pr2}$

我想既然“a”出现在两个文档中,就不应该删除它。然而,事实并非如此。我错过什么了吗?在


Tags: no代码from文档importdictionarycorpusfilter
1条回答
网友
1楼 · 发布于 2024-04-26 02:38:40

看看documentation of ^{}

filter_extremes(no_below=5, no_above=0.5, keep_n=100000, keep_tokens=None)

Notes:    
This removes all tokens in the dictionary that are:

    1. Less frequent than no_below documents (absolute number, e.g. 5) or
    2. More frequent than no_above documents (fraction of the total corpus size, e.g. 0.3).
    3. After (1) and (2), keep only the first keep_n most frequent tokens (or keep all if keep_n=None).

您只传递no_below=1。这意味着出现在少于1个文档(共3个)中的标记将被删除。这意味着a以及语料库中的任何其他标记。在

但是no_above=0.5将根据其默认值进行检查,因为您没有为此关键字传递显式值。这意味着超过50%的文档(3个文档中,即至少2个文档中出现的)中出现的令牌将被删除。并且'a'出现在所有3个文档中,它是唯一一个至少出现在2个文档中的文档。这就是为什么要从结果中删除这个标记和这个标记。(keep_n的默认值10000表示步骤3在您的示例中是一个no-op。)

如果想要剥离低频极值标记,请将显式的no_above=1.0传递给filter_extremes。在

相关问题 更多 >