Spaces:
Runtime error
Runtime error
acmc
commited on
Commit
·
115f2ee
1
Parent(s):
36c5b68
new model
Browse files- app.py +40 -40
- institutions.csv +0 -0
- model/.data-00000-of-00001 +2 -2
- model/.index +1 -1
- model/model_metadata.ampkl +2 -2
app.py
CHANGED
|
@@ -112,30 +112,30 @@ def process_user_input_concept(concept_chooser):
|
|
| 112 |
|
| 113 |
# Now, average the similarities
|
| 114 |
scores = np.stack(list(all_similarities.values()), axis=0)
|
| 115 |
-
scores = np.mean(
|
| 116 |
|
| 117 |
table_df = pd.DataFrame(
|
| 118 |
{
|
| 119 |
-
"
|
| 120 |
-
"
|
| 121 |
-
"
|
| 122 |
# "num_articles": all_ids_institutions[:, 2].astype(int),
|
| 123 |
}
|
| 124 |
)
|
| 125 |
|
| 126 |
# Add the individual similarities
|
| 127 |
for i, concept in enumerate(chosen_concepts):
|
| 128 |
-
table_df[f"
|
| 129 |
|
| 130 |
# Reorder the columns so that the mean similarity is after the individual similarities and before the institution name
|
| 131 |
table_df = table_df[
|
| 132 |
-
["
|
| 133 |
-
+ [f"
|
| 134 |
-
+ ["
|
| 135 |
]
|
| 136 |
|
| 137 |
# Sort by mean similarity
|
| 138 |
-
table_df = table_df.sort_values(by=["
|
| 139 |
|
| 140 |
concept_names = [get_concept_name(concept_uri) for concept_uri in chosen_concepts]
|
| 141 |
return (
|
|
@@ -151,7 +151,7 @@ def calculate_emdeddings_and_pca(table):
|
|
| 151 |
gr.Info("Performing PCA and clustering...")
|
| 152 |
# Perform PCA
|
| 153 |
embeddings_of_institutions = model.get_embeddings(
|
| 154 |
-
entities=np.array(table["
|
| 155 |
)
|
| 156 |
|
| 157 |
entity_embeddings_pca = pca(embeddings_of_institutions)
|
|
@@ -161,9 +161,9 @@ def calculate_emdeddings_and_pca(table):
|
|
| 161 |
|
| 162 |
plot_df = pd.DataFrame(
|
| 163 |
{
|
| 164 |
-
"
|
| 165 |
-
"
|
| 166 |
-
"
|
| 167 |
}
|
| 168 |
)
|
| 169 |
|
|
@@ -173,16 +173,16 @@ def calculate_emdeddings_and_pca(table):
|
|
| 173 |
|
| 174 |
|
| 175 |
def click_on_institution(table, embeddings_var, evt: gr.SelectData):
|
| 176 |
-
institution_id = table["
|
| 177 |
try:
|
| 178 |
embeddings_df = embeddings_var["embeddings_df"]
|
| 179 |
plot_df = pd.DataFrame(
|
| 180 |
{
|
| 181 |
-
"
|
| 182 |
-
"
|
| 183 |
-
"
|
| 184 |
-
"
|
| 185 |
-
"
|
| 186 |
# "num_articles": table["num_articles"].values,
|
| 187 |
}
|
| 188 |
)
|
|
@@ -196,11 +196,11 @@ def click_on_show_plot(table):
|
|
| 196 |
|
| 197 |
plot_df = pd.DataFrame(
|
| 198 |
{
|
| 199 |
-
"
|
| 200 |
-
"Institution_name": table["
|
| 201 |
-
"
|
| 202 |
-
"
|
| 203 |
-
"
|
| 204 |
# "num_articles": table["num_articles"].values,
|
| 205 |
}
|
| 206 |
)
|
|
@@ -215,17 +215,17 @@ def plot_embeddings(plot_df, institution_id):
|
|
| 215 |
# fig.title("{} embeddings".format(parameter).capitalize())
|
| 216 |
ax = sns.scatterplot(
|
| 217 |
data=plot_df,
|
| 218 |
-
x="
|
| 219 |
-
y="
|
| 220 |
-
hue="
|
| 221 |
)
|
| 222 |
|
| 223 |
-
row_of_institution = plot_df[plot_df["
|
| 224 |
if not row_of_institution.empty:
|
| 225 |
ax.text(
|
| 226 |
-
row_of_institution["
|
| 227 |
-
row_of_institution["
|
| 228 |
-
row_of_institution["
|
| 229 |
horizontalalignment="left",
|
| 230 |
size="medium",
|
| 231 |
color="black",
|
|
@@ -233,20 +233,20 @@ def plot_embeddings(plot_df, institution_id):
|
|
| 233 |
)
|
| 234 |
# Also draw a point for the institution
|
| 235 |
ax.scatter(
|
| 236 |
-
row_of_institution["
|
| 237 |
-
row_of_institution["
|
| 238 |
color="black",
|
| 239 |
s=100,
|
| 240 |
marker="x",
|
| 241 |
)
|
| 242 |
# texts = []
|
| 243 |
# for i, point in plot_df.iterrows():
|
| 244 |
-
# if point["
|
| 245 |
# texts.append(
|
| 246 |
# fig.text(
|
| 247 |
-
# point["
|
| 248 |
-
# point["
|
| 249 |
-
# str(point["
|
| 250 |
# )
|
| 251 |
# )
|
| 252 |
# adjust_text(texts)
|
|
@@ -257,9 +257,9 @@ def get_authors_of_institution(institutions_table, concept_chooser, evt: gr.Sele
|
|
| 257 |
"""
|
| 258 |
Get the authors of an institution
|
| 259 |
"""
|
| 260 |
-
institution = institutions_table["
|
| 261 |
number_of_row = evt.index[0]
|
| 262 |
-
institution = institutions_table["
|
| 263 |
concepts = separate_concepts(concept_chooser)
|
| 264 |
results_dfs = []
|
| 265 |
for concept in concepts:
|
|
@@ -269,7 +269,7 @@ def get_authors_of_institution(institutions_table, concept_chooser, evt: gr.Sele
|
|
| 269 |
WHERE {{
|
| 270 |
?author a <urn:acmcmc:unis:Author> .
|
| 271 |
?author <urn:acmcmc:unis:name> ?name .
|
| 272 |
-
?article <urn:acmcmc:unis:written_in_institution> <{
|
| 273 |
?article <urn:acmcmc:unis:has_author> ?author .
|
| 274 |
?article <urn:acmcmc:unis:related_to_concept> <{concept}> .
|
| 275 |
}}
|
|
|
|
| 112 |
|
| 113 |
# Now, average the similarities
|
| 114 |
scores = np.stack(list(all_similarities.values()), axis=0)
|
| 115 |
+
scores = np.mean(scores, axis=0)
|
| 116 |
|
| 117 |
table_df = pd.DataFrame(
|
| 118 |
{
|
| 119 |
+
"institution": s,
|
| 120 |
+
"mean_similarity": scores.flatten(),
|
| 121 |
+
"institution_name": all_ids_institutions[:, 1],
|
| 122 |
# "num_articles": all_ids_institutions[:, 2].astype(int),
|
| 123 |
}
|
| 124 |
)
|
| 125 |
|
| 126 |
# Add the individual similarities
|
| 127 |
for i, concept in enumerate(chosen_concepts):
|
| 128 |
+
table_df[f"similarity_to_{chosen_concepts_names[i]}"] = all_similarities[concept]
|
| 129 |
|
| 130 |
# Reorder the columns so that the mean similarity is after the individual similarities and before the institution name
|
| 131 |
table_df = table_df[
|
| 132 |
+
["institution"]
|
| 133 |
+
+ [f"similarity_to_{chosen_concepts_names[i]}" for i in range(len(chosen_concepts))]
|
| 134 |
+
+ ["mean_similarity", "institution_name"]
|
| 135 |
]
|
| 136 |
|
| 137 |
# Sort by mean similarity
|
| 138 |
+
table_df = table_df.sort_values(by=["mean_similarity"], ascending=False)
|
| 139 |
|
| 140 |
concept_names = [get_concept_name(concept_uri) for concept_uri in chosen_concepts]
|
| 141 |
return (
|
|
|
|
| 151 |
gr.Info("Performing PCA and clustering...")
|
| 152 |
# Perform PCA
|
| 153 |
embeddings_of_institutions = model.get_embeddings(
|
| 154 |
+
entities=np.array(table["institution"])
|
| 155 |
)
|
| 156 |
|
| 157 |
entity_embeddings_pca = pca(embeddings_of_institutions)
|
|
|
|
| 161 |
|
| 162 |
plot_df = pd.DataFrame(
|
| 163 |
{
|
| 164 |
+
"embedding_x": entity_embeddings_pca[:, 0],
|
| 165 |
+
"embedding_y": entity_embeddings_pca[:, 1],
|
| 166 |
+
"cluster": "cluster" + pd.Series(clusters).astype(str),
|
| 167 |
}
|
| 168 |
)
|
| 169 |
|
|
|
|
| 173 |
|
| 174 |
|
| 175 |
def click_on_institution(table, embeddings_var, evt: gr.SelectData):
|
| 176 |
+
institution_id = table["institution"][evt.index[0]]
|
| 177 |
try:
|
| 178 |
embeddings_df = embeddings_var["embeddings_df"]
|
| 179 |
plot_df = pd.DataFrame(
|
| 180 |
{
|
| 181 |
+
"institution": table["institution"].values,
|
| 182 |
+
"institution_name": table["institution_name"].values,
|
| 183 |
+
"embedding_x": embeddings_df["embedding_x"].values,
|
| 184 |
+
"embedding_y": embeddings_df["embedding_y"].values,
|
| 185 |
+
"cluster": embeddings_df["cluster"].values,
|
| 186 |
# "num_articles": table["num_articles"].values,
|
| 187 |
}
|
| 188 |
)
|
|
|
|
| 196 |
|
| 197 |
plot_df = pd.DataFrame(
|
| 198 |
{
|
| 199 |
+
"institution": table["institution"].values,
|
| 200 |
+
"Institution_name": table["institution Name"].values,
|
| 201 |
+
"embedding_x": embeddings_df["embedding_x"].values,
|
| 202 |
+
"embedding_y": embeddings_df["embedding_y"].values,
|
| 203 |
+
"cluster": embeddings_df["cluster"].values,
|
| 204 |
# "num_articles": table["num_articles"].values,
|
| 205 |
}
|
| 206 |
)
|
|
|
|
| 215 |
# fig.title("{} embeddings".format(parameter).capitalize())
|
| 216 |
ax = sns.scatterplot(
|
| 217 |
data=plot_df,
|
| 218 |
+
x="embedding_x",
|
| 219 |
+
y="embedding_y",
|
| 220 |
+
hue="cluster",
|
| 221 |
)
|
| 222 |
|
| 223 |
+
row_of_institution = plot_df[plot_df["institution"] == institution_id]
|
| 224 |
if not row_of_institution.empty:
|
| 225 |
ax.text(
|
| 226 |
+
row_of_institution["embedding_x"],
|
| 227 |
+
row_of_institution["embedding_y"],
|
| 228 |
+
row_of_institution["institution_name"].values[0],
|
| 229 |
horizontalalignment="left",
|
| 230 |
size="medium",
|
| 231 |
color="black",
|
|
|
|
| 233 |
)
|
| 234 |
# Also draw a point for the institution
|
| 235 |
ax.scatter(
|
| 236 |
+
row_of_institution["embedding_x"],
|
| 237 |
+
row_of_institution["embedding_y"],
|
| 238 |
color="black",
|
| 239 |
s=100,
|
| 240 |
marker="x",
|
| 241 |
)
|
| 242 |
# texts = []
|
| 243 |
# for i, point in plot_df.iterrows():
|
| 244 |
+
# if point["institution"] == institution_id:
|
| 245 |
# texts.append(
|
| 246 |
# fig.text(
|
| 247 |
+
# point["embedding_x"] + 0.02,
|
| 248 |
+
# point["embedding_y"] + 0.01,
|
| 249 |
+
# str(point["institution_name"]),
|
| 250 |
# )
|
| 251 |
# )
|
| 252 |
# adjust_text(texts)
|
|
|
|
| 257 |
"""
|
| 258 |
Get the authors of an institution
|
| 259 |
"""
|
| 260 |
+
institution = institutions_table["institution"][0]
|
| 261 |
number_of_row = evt.index[0]
|
| 262 |
+
institution = institutions_table["institution"][number_of_row]
|
| 263 |
concepts = separate_concepts(concept_chooser)
|
| 264 |
results_dfs = []
|
| 265 |
for concept in concepts:
|
|
|
|
| 269 |
WHERE {{
|
| 270 |
?author a <urn:acmcmc:unis:Author> .
|
| 271 |
?author <urn:acmcmc:unis:name> ?name .
|
| 272 |
+
?article <urn:acmcmc:unis:written_in_institution> <{institution}> .
|
| 273 |
?article <urn:acmcmc:unis:has_author> ?author .
|
| 274 |
?article <urn:acmcmc:unis:related_to_concept> <{concept}> .
|
| 275 |
}}
|
institutions.csv
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model/.data-00000-of-00001
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b1c911cf8812ae52e3a75dbb51ddf610067a96eb3b807a6f0bd7deb6dfc95ffc
|
| 3 |
+
size 1411474077
|
model/.index
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 294
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:49e9e5e144cbd54aa3a0a2a2e0a77395d682d9850b38ecd925622e386ea25f34
|
| 3 |
size 294
|
model/model_metadata.ampkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cdcc9837fd93c7604c58c02ff89219154fa4129cccae86f4d5995feb32d4726a
|
| 3 |
+
size 406330271
|