Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,21 +12,21 @@ corpus = pd.read_pickle("corpus.pkl")
|
|
12 |
|
13 |
|
14 |
def search(query, top_k=100):
|
15 |
-
print("Top
|
16 |
print()
|
17 |
ans = []
|
18 |
-
|
19 |
-
# Encode the query using the bi-encoder and find
|
20 |
question_embedding = bi_encoder.encode(query, convert_to_tensor=True)
|
21 |
hits = util.semantic_search(question_embedding, corpus_embeddings, top_k=top_k)
|
22 |
hits = hits[0] # Get the hits for the first query
|
23 |
|
24 |
-
|
25 |
# Now, score all retrieved passages with the cross_encoder
|
26 |
cross_inp = [[query, corpus[hit['corpus_id']]] for hit in hits]
|
27 |
cross_scores = cross_encoder.predict(cross_inp)
|
28 |
|
29 |
-
#
|
30 |
for idx in range(len(cross_scores)):
|
31 |
hits[idx]['cross-score'] = cross_scores[idx]
|
32 |
|
@@ -37,10 +37,10 @@ def search(query, top_k=100):
|
|
37 |
return ans[0]
|
38 |
|
39 |
|
40 |
-
exp = ["Who is steve jobs?", "
|
41 |
"What is the most interesting thing about our universe?", "What are the most beautiful places on earth?"]
|
42 |
|
43 |
-
desc = "This is a semantic search engine with
|
44 |
|
45 |
inp = gr.inputs.Textbox(lines=1, placeholder=None, default="", label="search you query here")
|
46 |
out = gr.outputs.Textbox(type="auto", label="search results")
|
|
|
12 |
|
13 |
|
14 |
def search(query, top_k=100):
|
15 |
+
print("Top Answer by the NSE:")
|
16 |
print()
|
17 |
ans = []
|
18 |
+
|
19 |
+
# Encode the query using the bi-encoder and find relevant passage
|
20 |
question_embedding = bi_encoder.encode(query, convert_to_tensor=True)
|
21 |
hits = util.semantic_search(question_embedding, corpus_embeddings, top_k=top_k)
|
22 |
hits = hits[0] # Get the hits for the first query
|
23 |
|
24 |
+
|
25 |
# Now, score all retrieved passages with the cross_encoder
|
26 |
cross_inp = [[query, corpus[hit['corpus_id']]] for hit in hits]
|
27 |
cross_scores = cross_encoder.predict(cross_inp)
|
28 |
|
29 |
+
# Sorting results by the cross-encoder scores
|
30 |
for idx in range(len(cross_scores)):
|
31 |
hits[idx]['cross-score'] = cross_scores[idx]
|
32 |
|
|
|
37 |
return ans[0]
|
38 |
|
39 |
|
40 |
+
exp = ["Who is steve jobs?", "Who is Salman Khan?", "Who is Kevin Hart?",
|
41 |
"What is the most interesting thing about our universe?", "What are the most beautiful places on earth?"]
|
42 |
|
43 |
+
desc = "This is a semantic search engine made with sentence transformer."
|
44 |
|
45 |
inp = gr.inputs.Textbox(lines=1, placeholder=None, default="", label="search you query here")
|
46 |
out = gr.outputs.Textbox(type="auto", label="search results")
|