亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我遇到 AttributeError:

為什么我遇到 AttributeError:

開滿天機 2021-07-23 16:01:50
下面是我嘗試編碼的一種方法。但是,在代碼的第 3 行中,它表示存在屬性錯誤,并且“WordListCorpusReader”對象在 python 中沒有屬性“word”。請幫我看看下面的代碼:(('''step 3. conduct preprocessing steps'''# setting up the resources for the preprocessing stepsstop = set(stopwords.word('english'))exclude = set(string.punctuation)lemma = WordNetLemmatizer()def clean(doc):    stop_free = ''.join([i for i in doc.lower().split() if i not in stop])    punc_free = ''.join([ch for ch in stop_free if ch not in exclude])    normalized = ''.join(wn.lemma.lemmatize(word) for word in punc_free.split())    return normalized    doc_clean = [clean(doc).split() for doc in corpus]    '''step 4. prepare word representation'''    dictionary = corpora.Dictionary(doc_clean)    doc_term_matrix = [dictionary.doc2bow(doc) for doc in doc_clean]    '''step 5. create lda model'''    topic_num = 5    word_num = 5    Lda = gensim.models.ldamodel.LdaModel    ldamodel = Lda(doc_term_matrix, num_topics=topic_num, id2word=dictionary, passes=20)    pprint(ldamodel.print_topics(num_topics=topic_num, num_words=word_num))這是運行代碼后的回溯:Traceback (most recent call last):  File "C:/Users/user/PycharmProjects/topicmodel/topicmodel.py", line 41, in <module>    stop = set(stopwords.word('english'))  File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\nltk\corpus\util.py", line 119, in __getattr__    return getattr(self, attr)AttributeError: 'WordListCorpusReader' object has no attribute 'word'
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 496 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號