I am using the TextRan algorithm for inferential text summarization.I used Glove model for word embedding. I wrote a code that can draw a graph to display how a similarity matrix.Although I get the same summary text every time I run the code, I see a different graph drawing each time. What is the reason of this? Is this a problem or is it normal? If it is a problem, how can I provide a solution? If you have information, I would appreciate it if you reply.
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()