【问题标题】:Why does the LDA gensim implemention need the corpus and a dictionary?为什么 LDA gensim 实现需要语料库和字典?
【发布时间】:2020-03-08 11:40:00
【问题描述】:

我正在查看gensim LDA 实现,它说它需要一个语料库和一个语料库字典?

https://radimrehurek.com/gensim/models/ldamodel.html

这是什么原因?

【问题讨论】:

    标签: python nlp gensim lda topic-modeling


    【解决方案1】:

    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 的 CountVectoriser)对您隐藏了字典,但它仍然存在。

    【讨论】:

      猜你喜欢
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-19
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      相关资源
      最近更新 更多