eljanmahammadli commited on
Commit
61b027b
·
1 Parent(s): 2610f9b

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +9 -3
utils.py CHANGED
@@ -56,6 +56,12 @@ def cosineSim(text1, text2):
56
  cosine = get_cosine(vector1, vector2)
57
  return cosine
58
 
 
 
 
 
 
 
59
  def sentence_similarity(text1, text2):
60
  embedding_1= model.encode(text1, convert_to_tensor=True)
61
  embedding_2 = model.encode(text2, convert_to_tensor=True)
@@ -215,11 +221,11 @@ def matchingScoreWithTimeout(sentence, content):
215
  def timeout_handler():
216
  raise TimeoutError("Function timed out")
217
 
218
- timer = threading.Timer(2, timeout_handler) # Set a timer for 2 seconds
219
  timer.start()
220
  try:
221
- # score = sentence_similarity(sentence, content)
222
- score = matchingScore(sentence, content)
223
  timer.cancel() # Cancel the timer if calculation completes before timeout
224
  return score
225
  except TimeoutError:
 
56
  cosine = get_cosine(vector1, vector2)
57
  return cosine
58
 
59
+ def cos_sim_torch(embedding_1, embedding_2):
60
+ return util.pytorch_cos_sim(embedding_1, embedding_2).item()
61
+
62
+ def embed_text(text):
63
+ return model.encode(text, convert_to_tensor=True)
64
+
65
  def sentence_similarity(text1, text2):
66
  embedding_1= model.encode(text1, convert_to_tensor=True)
67
  embedding_2 = model.encode(text2, convert_to_tensor=True)
 
221
  def timeout_handler():
222
  raise TimeoutError("Function timed out")
223
 
224
+ timer = threading.Timer(10, timeout_handler) # Set a timer for 2 seconds
225
  timer.start()
226
  try:
227
+ score = sentence_similarity(sentence, content)
228
+ # score = matchingScore(sentence, content)
229
  timer.cancel() # Cancel the timer if calculation completes before timeout
230
  return score
231
  except TimeoutError: