2017-09-07 64 views
0
def generateTopics(corpus, dictionary): 
    # Build LDA model using the above corpus 
    lda = models.ldamodel.LdaModel(corpus, id2word=dictionary, num_topics=50) 
    corpus_lda = lda[corpus] 

    # Group topics with similar words together. 
    tops = set(lda.show_topics(50)) 
    top_clusters = [] 
    for l in tops: 
     top = [] 
    for t in l.split(" + "): 
     top.append((t.split("*")[0], t.split("*")[1])) 
    top_clusters.append(top) 

我想在本代碼中使用lda.but來獲取主題,當我嘗試將具有相似詞語的主題組合在一起時,我得到此錯誤。 for lsplit(「+」): AttributeError:'元組'對象沒有屬性'split'gettinf錯誤'元組'對象沒有屬性'拆分'

回答

0

你只能拆分字符串。

嘗試

str(l).split(" + ") 

否則,不要使用一個元組。

+0

謝謝you.it工作 – user3778289

相關問題