有必要将 TF-IDF 应用于 gensim LDA 模型中的新文档吗?
Necessary to apply TF-IDF to new documents in gensim LDA model?
我正在 https://radimrehurek.com/gensim/wiki.html#latent-dirichlet-allocation
上学习 'English Wikipedia' gensim 教程
其中解释了在训练过程中使用了 tf-idf(至少对于 LSA,对于 LDA 不是很清楚)。
我希望将 tf-idf 转换器应用于新文档,但在最后,它建议简单地输入一个词袋。
doc_lda = lda[doc_bow]
LDA 是否只需要词袋向量?
TL;DR: 是的,LDA 只需要一个词袋向量。
的确,在gensim教程的维基百科示例中,Radim Rehurek使用了预处理步骤中生成的TF-IDF语料库。
mm = gensim.corpora.MmCorpus('wiki_en_tfidf.mm')
我认为这只是因为这个矩阵是稀疏的并且易于处理(并且由于预处理步骤已经存在)。
LDA不一定需要在TF-IDF语料库上训练。如果您使用 gensim 教程 Corpora and Vector Spaces:
中显示的语料库,该模型工作得很好
from gensim import corpora, models
texts = [['human', 'interface', 'computer'],
['survey', 'user', 'computer', 'system', 'response', 'time'],
['eps', 'user', 'interface', 'system'],
['system', 'human', 'system', 'eps'],
['user', 'response', 'time'],
['trees'],
['graph', 'trees'],
['graph', 'minors', 'trees'],
['graph', 'minors', 'survey']]
dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]
lda = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, num_topics=10, update_every=1, chunksize =10000, passes=1)
注意 texts
是词袋向量。正如您正确指出的那样,这是 LDA 模型的核心部分。 TF-IDF在其中根本没有起到任何作用
事实上,Blei(LDA 的开发者)在 2003 年的论文(题为“Latent Dirichlet Allocation”)的引言中指出,LDA 解决了 TF-IDF 模型的缺点,而将这种方法抛在脑后。 LSA 是完全代数的,通常(但不一定)使用 TF-IDF 矩阵,而 LDA 是一种概率模型,它试图估计文档中主题和主题中单词的概率分布。 TF-IDF 的权重对此不是必需的。
并非不同意 Jérôme 的回答,tf-idf 在某种程度上被用于潜在狄利克雷分配。正如可以在论文 Topic Models by Blei and Lafferty(例如第 6 页 - 可视化主题和第 12 页)中看到的那样,tf-idf 分数对于 LDA 非常有用。它可用于可视化主题或选择词汇。 "It is often computationally expensive to use the entire vocabulary. Choosing the top V words by TFIDF is an effective way to prune the vocabulary"。
这就是说,LDA 不需要 tf-idf 来推断主题,但它很有用,可以改善您的结果。
我正在 https://radimrehurek.com/gensim/wiki.html#latent-dirichlet-allocation
上学习 'English Wikipedia' gensim 教程其中解释了在训练过程中使用了 tf-idf(至少对于 LSA,对于 LDA 不是很清楚)。
我希望将 tf-idf 转换器应用于新文档,但在最后,它建议简单地输入一个词袋。
doc_lda = lda[doc_bow]
LDA 是否只需要词袋向量?
TL;DR: 是的,LDA 只需要一个词袋向量。
的确,在gensim教程的维基百科示例中,Radim Rehurek使用了预处理步骤中生成的TF-IDF语料库。
mm = gensim.corpora.MmCorpus('wiki_en_tfidf.mm')
我认为这只是因为这个矩阵是稀疏的并且易于处理(并且由于预处理步骤已经存在)。
LDA不一定需要在TF-IDF语料库上训练。如果您使用 gensim 教程 Corpora and Vector Spaces:
中显示的语料库,该模型工作得很好from gensim import corpora, models
texts = [['human', 'interface', 'computer'],
['survey', 'user', 'computer', 'system', 'response', 'time'],
['eps', 'user', 'interface', 'system'],
['system', 'human', 'system', 'eps'],
['user', 'response', 'time'],
['trees'],
['graph', 'trees'],
['graph', 'minors', 'trees'],
['graph', 'minors', 'survey']]
dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]
lda = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, num_topics=10, update_every=1, chunksize =10000, passes=1)
注意 texts
是词袋向量。正如您正确指出的那样,这是 LDA 模型的核心部分。 TF-IDF在其中根本没有起到任何作用
事实上,Blei(LDA 的开发者)在 2003 年的论文(题为“Latent Dirichlet Allocation”)的引言中指出,LDA 解决了 TF-IDF 模型的缺点,而将这种方法抛在脑后。 LSA 是完全代数的,通常(但不一定)使用 TF-IDF 矩阵,而 LDA 是一种概率模型,它试图估计文档中主题和主题中单词的概率分布。 TF-IDF 的权重对此不是必需的。
并非不同意 Jérôme 的回答,tf-idf 在某种程度上被用于潜在狄利克雷分配。正如可以在论文 Topic Models by Blei and Lafferty(例如第 6 页 - 可视化主题和第 12 页)中看到的那样,tf-idf 分数对于 LDA 非常有用。它可用于可视化主题或选择词汇。 "It is often computationally expensive to use the entire vocabulary. Choosing the top V words by TFIDF is an effective way to prune the vocabulary"。
这就是说,LDA 不需要 tf-idf 来推断主题,但它很有用,可以改善您的结果。