Spaces:
Runtime error
Runtime error
Commit
·
f0ca479
1
Parent(s):
e35b83c
render Graph from adjacency matrix
Browse filesuse G from cosine similarity to populate network
app.py
CHANGED
@@ -21,11 +21,17 @@ embeddings = model.encode(sentences, convert_to_tensor=True)
|
|
21 |
#Compute cosine-similarities
|
22 |
cosine_scores = util.cos_sim(embeddings, embeddings)
|
23 |
|
|
|
|
|
|
|
24 |
#Output the pairs with their score
|
25 |
for i in range(len(sentences)):
|
26 |
for j in range(i):
|
27 |
st.write("{} \t\t {} \t\t Score: {:.4f}".format(sentences[i], sentences[j], cosine_scores[i][j]))
|
|
|
|
|
28 |
|
|
|
29 |
G = nx.from_numpy_array(cosine_scores.numpy())
|
30 |
|
31 |
|
@@ -56,7 +62,7 @@ from streamlit_agraph import agraph, Node, Edge, Config
|
|
56 |
# First create a graph using the Barabasi-Albert model
|
57 |
n = 2000
|
58 |
m = 2
|
59 |
-
G = nx.generators.barabasi_albert_graph(n, m, seed=2023)
|
60 |
|
61 |
# Then find the node with the largest degree;
|
62 |
# This node's egonet will be the focus of this example.
|
|
|
21 |
#Compute cosine-similarities
|
22 |
cosine_scores = util.cos_sim(embeddings, embeddings)
|
23 |
|
24 |
+
# creating adjacency matrix
|
25 |
+
A = np.zeroes((len(sentences),len(sentences)))
|
26 |
+
|
27 |
#Output the pairs with their score
|
28 |
for i in range(len(sentences)):
|
29 |
for j in range(i):
|
30 |
st.write("{} \t\t {} \t\t Score: {:.4f}".format(sentences[i], sentences[j], cosine_scores[i][j]))
|
31 |
+
M[i][j] = cosine_scores[i][j]
|
32 |
+
M[j][i] = cosine_scores[i][j]
|
33 |
|
34 |
+
#G = nx.from_numpy_array(A)
|
35 |
G = nx.from_numpy_array(cosine_scores.numpy())
|
36 |
|
37 |
|
|
|
62 |
# First create a graph using the Barabasi-Albert model
|
63 |
n = 2000
|
64 |
m = 2
|
65 |
+
#G = nx.generators.barabasi_albert_graph(n, m, seed=2023)
|
66 |
|
67 |
# Then find the node with the largest degree;
|
68 |
# This node's egonet will be the focus of this example.
|