Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -54,12 +54,15 @@ def knn_get_score(knn, k, cat, vec):
|
|
54 |
# Compute cosine similiarity of vec against allvecs
|
55 |
# (both are already normalized)
|
56 |
cos_sim_table = vec @ allvecs.T
|
|
|
57 |
# Get sorted array indices by similiarity in descending order
|
58 |
sortinds = np.flip(np.argsort(cos_sim_table))
|
59 |
# Get corresponding scores for the sorted vectors
|
60 |
kscores = scores[sortinds][:k]
|
|
|
61 |
# Get actual sorted similiarity scores
|
62 |
ksims = np.expand_dims(cos_sim_table[sortinds][:k], axis=0)
|
|
|
63 |
# Apply normalization after exponential formula
|
64 |
ksims = softmax(10**ksims)
|
65 |
# Weighted sum
|
@@ -108,7 +111,7 @@ def main():
|
|
108 |
vec /= vec.norm(dim=-1, keepdim=True)
|
109 |
st.write(vec.shape)
|
110 |
k = 40
|
111 |
-
for cat in
|
112 |
st.write(cat, 'rating =', knn_get_score(knn, k, cat, vec))
|
113 |
|
114 |
except Exception as e:
|
|
|
54 |
# Compute cosine similiarity of vec against allvecs
|
55 |
# (both are already normalized)
|
56 |
cos_sim_table = vec @ allvecs.T
|
57 |
+
st.write('cos_sim_table.shape', cos_sim_table.shape)
|
58 |
# Get sorted array indices by similiarity in descending order
|
59 |
sortinds = np.flip(np.argsort(cos_sim_table))
|
60 |
# Get corresponding scores for the sorted vectors
|
61 |
kscores = scores[sortinds][:k]
|
62 |
+
st.write('kscores.shape', kscores.shape)
|
63 |
# Get actual sorted similiarity scores
|
64 |
ksims = np.expand_dims(cos_sim_table[sortinds][:k], axis=0)
|
65 |
+
st.write('ksims.shape', ksims.shape)
|
66 |
# Apply normalization after exponential formula
|
67 |
ksims = softmax(10**ksims)
|
68 |
# Weighted sum
|
|
|
111 |
vec /= vec.norm(dim=-1, keepdim=True)
|
112 |
st.write(vec.shape)
|
113 |
k = 40
|
114 |
+
for cat in ['walkability']:
|
115 |
st.write(cat, 'rating =', knn_get_score(knn, k, cat, vec))
|
116 |
|
117 |
except Exception as e:
|