第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

當(dāng)我嘗試使用 python networkx 總結(jié)文本文檔時出現(xiàn)錯誤

當(dāng)我嘗試使用 python networkx 總結(jié)文本文檔時出現(xiàn)錯誤

慕絲7291255 2023-03-22 16:02:05
當(dāng)我嘗試使用 python networkx 總結(jié)文本文檔時,我得到了 PowerIterationFailedConvergence:(PowerIterationFailedConvergence(...), 'power iteration failed to converge within 100 iterations') 如下面的代碼所示。代碼“scores = nx.pagerank(sentence_similarity_graph)”中顯示的錯誤def read_article(file_name):    file = open(file_name, "r",encoding="utf8")    filedata = file.readlines()    text=""    for s in filedata:        text=text+s.replace("\n","")        text=re.sub(' +', ' ', text) #remove space        text=re.sub('—',' ',text)        article = text.split(". ")     sentences = []    for sentence in article:#         print(sentence)        sentences.append(sentence.replace("[^a-zA-Z]", "").split(" "))    sentences.pop()    new_sent=[]    for lst in sentences:        newlst=[]        for i in range(len(lst)):            if lst[i].lower()!=lst[i-1].lower():                newlst.append(lst[i])            else:                newlst=newlst        new_sent.append(newlst)    return new_sentdef sentence_similarity(sent1, sent2, stopwords=None):    if stopwords is None:        stopwords = []     sent1 = [w.lower() for w in sent1]    sent2 = [w.lower() for w in sent2]     all_words = list(set(sent1 + sent2))     vector1 = [0] * len(all_words)    vector2 = [0] * len(all_words)     # build the vector for the first sentence    for w in sent1:        if w in stopwords:            continue        vector1[all_words.index(w)] += 1     # build the vector for the second sentence    for w in sent2:        if w in stopwords:            continue        vector2[all_words.index(w)] += 1     return 1 - cosine_distance(vector1, vector2)def build_similarity_matrix(sentences, stop_words):    # Create an empty similarity matrix    similarity_matrix = np.zeros((len(sentences), len(sentences)))
查看完整描述

3 回答

?
回首憶惘然

TA貢獻(xiàn)1847條經(jīng)驗 獲得超11個贊

也許你現(xiàn)在已經(jīng)解決了。

問題是您使用向量的時間太長了。您的向量是使用整個詞匯表構(gòu)建的,這對于模型來說可能太長而無法在僅 100 個周期內(nèi)收斂(這是 pagerank 的默認(rèn)值)。

您可以減少詞匯表的長度(您是否檢查過它是否正確刪除了停用詞?)或使用任何其他技術(shù),例如減少不常用的單詞,或使用 TF-IDF。

就我而言,我遇到了同樣的問題,但使用的是 Glove 詞嵌入。300 維無法收斂,使用 100 維模型很容易解決。

您可以嘗試的另一件事是在調(diào)用 nx.pagerank 時擴(kuò)展 max_iter 參數(shù):

nx.pagerank(nx_graph, max_iter=600) # Or any number that will work for you.

默認(rèn)值為 100 個周期。


查看完整回答
反對 回復(fù) 2023-03-22
?
拉莫斯之舞

TA貢獻(xiàn)1820條經(jīng)驗 獲得超10個贊

當(dāng)算法未能在冪迭代方法的指定迭代次數(shù)內(nèi)收斂到指定的容差時,會發(fā)生此錯誤。因此,您可以像這樣在 nx.pagerank() 中增加錯誤容忍度:

nx.pagerank(sentence_similarity_graph,?tol=1.0e-3)

默認(rèn)值為 1.0e-6。

查看完整回答
反對 回復(fù) 2023-03-22
?
慕勒3428872

TA貢獻(xiàn)1848條經(jīng)驗 獲得超6個贊

我有同樣的問題。原來sentence_similarity_graph具有“nan”值。怎么解決?


在 def sentence_similarity中:


if np.isnan(1 - cosine_distance(vector1, vector2)):

  return 0

return 1 - cosine_distance(vector1, vector2)


查看完整回答
反對 回復(fù) 2023-03-22
  • 3 回答
  • 0 關(guān)注
  • 541 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號