eliwill commited on
Commit
161f0fc
·
1 Parent(s): b3a9c96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -43,15 +43,15 @@ def ask_philosopher(philosopher, question):
43
  return answer
44
 
45
  def get_similar_quotes(philosopher, question):
46
- """ Return top 5 most similar quotes to the question from a philosopher's dataframe """
47
  df = philosopher_dictionary[philosopher]['dataframe']
48
  question_embedding = model.encode(question)
49
  sims = [util.dot_score(question_embedding, quote_embedding) for quote_embedding in df['Embedding']]
50
- ind = np.argpartition(sims, -5)[-5:]
51
  similar_sentences = [df['quote'][i] for i in ind]
52
- top5quotes = pd.DataFrame(data = similar_sentences, columns=["Quotes"], index=range(1,6))
53
- top5quotes['Quotes'] = top5quotes['Quotes'].str[:-1].str[:250] + "..."
54
- return top5quotes
55
 
56
  def main(question, philosopher):
57
  return ask_philosopher(philosopher, question), get_similar_quotes(philosopher, question)
 
43
  return answer
44
 
45
  def get_similar_quotes(philosopher, question):
46
+ """ Return top 3 most similar quotes to the question from a philosopher's dataframe """
47
  df = philosopher_dictionary[philosopher]['dataframe']
48
  question_embedding = model.encode(question)
49
  sims = [util.dot_score(question_embedding, quote_embedding) for quote_embedding in df['Embedding']]
50
+ ind = np.argpartition(sims, -3)[-3:]
51
  similar_sentences = [df['quote'][i] for i in ind]
52
+ top3quotes = pd.DataFrame(data = similar_sentences, columns=["Quotes"], index=range(1,4))
53
+ top3quotes['Quotes'] = top3quotes['Quotes'].str[:-1].str[:250] + "..."
54
+ return top3quotes
55
 
56
  def main(question, philosopher):
57
  return ask_philosopher(philosopher, question), get_similar_quotes(philosopher, question)