【问题标题】:Can I form corpus document for LDA model out of dictionary of type dict?我可以从字典类型的字典中形成 LDA 模型的语料库文档吗?
【发布时间】:2018-06-21 13:43:25
【问题描述】:

在形成 Gensim LDA 模型时,我使用以下命令为我的数据获取字典

    from gensim.corpora import Dictionary
    dictionary1 = Dictionary(docs)
    dictionary1.filter_extremes(no_below=10, no_above=0.75, keep_n = 1000)

在这 1000 个最常见的标记中,我手动删除了 500 个标记,以便剩余的标记与我要生成的主题直接相关。 我怎样才能从这个字典类型的新字典中进一步形成语料库文档。我应该以哪种形式使用它来训练我的 LDA 模型?

【问题讨论】:

    标签: python dictionary gensim lda


    【解决方案1】:

    您可以按如下方式训练 LDA 模型:

    ## Construct corpus and vectorize
    corpus = [dictionary1.doc2bow(content) for content in docs]
    
    ## train LDA model with 5 topics over 100 passes
    ## number of topics is chosen randomly in this case
    ## higher number of passes leads to better results but increases complexity 
    lda_model = gensim.models.ldamodel.LdaModel(corpus, num_topics=5, id2word = dictionary1, passes=100)
    
    print(lda_model.print_topics(num_topics=5, num_words=3))
    

    【讨论】:

      猜你喜欢
      • 2010-10-13
      • 2020-05-22
      • 1970-01-01
      • 1970-01-01
      • 2016-06-03
      • 2020-09-08
      • 2013-12-03
      相关资源
      最近更新 更多