我试图在我的文件上运行lda模型。首先我做了一些预处理,比如标记化和停止字删除。我这样做是为了多个文件,但当我把最终输出传递给lda模型时,它给了我一个错误,我在Google中看到lda将多个文件作为输入。 现在,我想将每个文件的输出存储到一个数组中,然后将该数组作为输入传递,但这也给了我一个错误indexeror:list assignment index out of range。我不知道是什么问题。任何帮助将不胜感激谢谢!你知道吗
# URDU STOP WORDS REMOVAL
doc_clean = []
stopwords_corpus = UrduCorpusReader('./data', ['stopwords-ur.txt'])
stopwords = stopwords_corpus.words()
count = 1
# print(stopwords)
for infile in (wordlists.fileids()):
words = wordlists.words(infile)
finalized_words = remove_urdu_stopwords(stopwords, words)
doc_clean[count] = finalized_words
print(doc_clean)
count =count+1
print("\n==== WITHOUT STOPWORDS ===========\n")
print(finalized_words)
id2word = corpora.Dictionary(doc_clean)
mm = [id2word.doc2bow(text) for text in texts]
lda = models.ldamodel.LdaModel(corpus=mm, id2word=id2word, num_topics=3, update_every=1, chunksize=10000, passes=1)
您将doc\u clean定义为空列表,但在第一次迭代中,您引用doc\u clean[count],count=1,因此引用空列表的第二个元素。你知道吗
更换
与
那就不用计数了。你知道吗
这里不需要使用
count
变量。List提供append
函数将元素添加到列表中。改变这个
为了这个
相关问题 更多 >
编程相关推荐