ernestchu commited on
Commit
0d13d40
·
1 Parent(s): 8131246
Files changed (1) hide show
  1. app.py +4 -1
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
- return np.dot(x, y) / (np.linalg.norm(x) * np.linalg.norm(y))
 
 
 
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