Jai12345 commited on
Commit
83fc981
·
1 Parent(s): 141d82d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
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 5 Answer by the NSE:")
16
  print()
17
  ans = []
18
- ##### Sematic Search #####
19
- # Encode the query using the bi-encoder and find potentially relevant passages
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
- ##### Re-Ranking #####
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
- # Sort results by the cross-encoder scores
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?", "What is coldplay?", "What is a turing test?",
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 a retrieval and reranking system on Wikipedia corous. This will return the top 5 results. So Quest on with Transformers."
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")