0

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()

enter image description here

Seda Yılmaz
  • 31
  • 1
  • 8
  • How do you display the graphs ? What are the differences between the graphs? How are word embeddings used in this case ? – ygorg May 20 '21 at 14:27
  • I have added a few examples of codes and graphic results for your better understanding.As far as I observe, the locations of the nodes are constantly changing. Is this something that shouldn't happen? you can look. @ygorg – Seda Yılmaz May 20 '21 at 17:06
  • According to [the documentation](https://networkx.org/documentation/stable/reference/generated/networkx.drawing.layout.spring_layout.html), you can try to set a fixed seed to see whether it solves your problem. Or use a non random layout. – ygorg May 26 '21 at 12:26

0 Answers0