Spaces:
Sleeping
Sleeping
app.py
CHANGED
@@ -213,7 +213,10 @@ def cosine_sim_dict(x, y):
|
|
213 |
def cosine_sim(x, y):
|
214 |
if isinstance(x, dict):
|
215 |
return cosine_sim_dict(x, y)
|
216 |
-
|
|
|
|
|
|
|
217 |
|
218 |
def dice_sim(x, y):
|
219 |
raise NotImplementedError
|
|
|
213 |
def cosine_sim(x, y):
|
214 |
if isinstance(x, dict):
|
215 |
return cosine_sim_dict(x, y)
|
216 |
+
denom = np.linalg.norm(x) * np.linalg.norm(y)
|
217 |
+
if denom == 0:
|
218 |
+
return 0
|
219 |
+
return np.dot(x, y) / denom
|
220 |
|
221 |
def dice_sim(x, y):
|
222 |
raise NotImplementedError
|