我正在使用 TextRan 算法进行推理文本摘要。我使用 Glove 模型进行词嵌入。我写了一个可以绘制图形的代码,以显示相似度矩阵的方式。虽然每次运行代码都会得到相同的摘要文本,但每次都看到不同的图形绘制。这是什么原因?这是问题还是正常?如果这是一个问题,我该如何提供解决方案?如果您有信息,如果您回复,我将不胜感激。
def GloveİleSentenceEmbed(sentence_list,sentence_stem):
word_embeddings = {}
f = open('/content/drive/MyDrive/MetinAnalizi/glove.6B.100d.txt', encoding='utf-8')
for line in f:
values = line.split()
word = values[0]
coefs = np.asarray(values[1:], dtype='float32')
word_embeddings[word] = coefs
f.close()
sentence_vectors = []
for i in sentence_stem:
if len(i) != 0:
v = sum([word_embeddings.get(w, np.zeros((100,))) for w in i])/(len(i)+0.001)
else:
v = np.zeros((100,))
sentence_vectors.append(v)
return sentence_vectors
def SimilariytMatrix(sentence_list,sentence_vectors):
similarity_matrix=np.zeros([len(sentence_list), len(sentence_list)])
for i in range(len(sentence_list)):
for j in range(len(sentence_list)):
if (i!=j):
similarity_matrix[i][j] = cosine_similarity(sentence_vectors[i].reshape(1,100), sentence_vectors[j].reshape(1,100))[0,0]
similarity_matrix = np.round(similarity_matrix,3)
return similarity_matrix
def PageRankAlgorithm(similarity_matrix,sentence_list):
nx_graph = nx.from_numpy_array(similarity_matrix)
plt.figure(figsize=(10, 10))
pos = nx.spring_layout(nx_graph)
nx.draw(nx_graph, with_labels=True, font_weight='bold')
plt.show()