Spaces:
Build error
Build error
Update app.py
Browse files
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
|
| 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, -
|
| 51 |
similar_sentences = [df['quote'][i] for i in ind]
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
return
|
| 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)
|