Python 为什么LDA gensim实现需要语料库和词典?

Python 为什么LDA gensim实现需要语料库和词典?,python,nlp,gensim,lda,topic-modeling,Python,Nlp,Gensim,Lda,Topic Modeling,我正在研究gensim的LDA实现,它说它需要一个语料库和一个语料库字典 这是什么原因?Gensim使用字典创建构成语料库的单词包模型 # Make the dictionary from your texts common_dictionary = Dictionary(common_texts) # Use the dictionary to generate the corpus (set of bag-of-words models) common_corpus = [common_

我正在研究gensim的LDA实现,它说它需要一个语料库和一个语料库字典


这是什么原因?

Gensim使用字典创建构成语料库的单词包模型

# Make the dictionary from your texts
common_dictionary = Dictionary(common_texts)

# Use the dictionary to generate the corpus (set of bag-of-words models)
common_corpus = [common_dictionary.doc2bow(text) for text in common_texts]
然后,您可以再次使用该词典从看不见的文本生成一个新的但类似的语料库

other_corpus = [common_dictionary.doc2bow(text) for text in other_texts]

您需要词典来拥有语料库,因为语料库是由转换为单词包的文档组成的,而构建单词包需要词典。单词袋模型的其他实现(如
sklearn
的countvectorier)对您隐藏了字典,但它仍然存在。

Gensim使用字典创建构成语料库的单词袋模型

# Make the dictionary from your texts
common_dictionary = Dictionary(common_texts)

# Use the dictionary to generate the corpus (set of bag-of-words models)
common_corpus = [common_dictionary.doc2bow(text) for text in common_texts]
然后,您可以再次使用该词典从看不见的文本生成一个新的但类似的语料库

other_corpus = [common_dictionary.doc2bow(text) for text in other_texts]
您需要词典来拥有语料库,因为语料库是由转换为单词包的文档组成的,而构建单词包需要词典。单词包模型的其他实现(如
sklearn
的countvectorier)对您隐藏了字典,但它仍然存在