cpnepo commited on
Commit
aedc08c
1 Parent(s): 9b00e1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -39,27 +39,27 @@ st.title('Harry Potter and the Extractive Question Answering Model')
39
  # Type in HP-related query here
40
  query = st.text_area("Hello my dears! What is your question? Be patient please, I am not a Ravenclaw!")
41
 
42
- # Perform sentence embedding on query and sentence groups
43
- model_embed_name = 'sentence-transformers/msmarco-distilbert-dot-v5'
44
-
45
- model_embed = SentenceTransformer(model_embed_name)
46
- doc_emb = model_embed.encode(paragraphs)
47
- query_emb = model_embed.encode(query)
48
-
49
- #Compute dot score between query and all document embeddings
50
- scores = util.cos_sim(query_emb, doc_emb)[0].cpu().tolist()
51
-
52
- #Combine docs & scores
53
- doc_score_pairs = list(zip(paragraphs, scores))
54
-
55
- #Sort by decreasing score and get only 3 most similar groups
56
- doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1],
57
- reverse=True)[:3]
58
-
59
- # Join these similar groups to form the context
60
- context = "".join(x[0] for x in doc_score_pairs)
61
-
62
  if st.button('Ask'):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  # Perform the querying
64
  QA_input = {'question': query, 'context': context}
65
  res = pipe(QA_input)
 
39
  # Type in HP-related query here
40
  query = st.text_area("Hello my dears! What is your question? Be patient please, I am not a Ravenclaw!")
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  if st.button('Ask'):
43
+ # Perform sentence embedding on query and sentence groups
44
+ model_embed_name = 'sentence-transformers/msmarco-distilbert-dot-v5'
45
+
46
+ model_embed = SentenceTransformer(model_embed_name)
47
+ doc_emb = model_embed.encode(paragraphs)
48
+ query_emb = model_embed.encode(query)
49
+
50
+ #Compute dot score between query and all document embeddings
51
+ scores = util.cos_sim(query_emb, doc_emb)[0].cpu().tolist()
52
+
53
+ #Combine docs & scores
54
+ doc_score_pairs = list(zip(paragraphs, scores))
55
+
56
+ #Sort by decreasing score and get only 3 most similar groups
57
+ doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1],
58
+ reverse=True)[:3]
59
+
60
+ # Join these similar groups to form the context
61
+ context = "".join(x[0] for x in doc_score_pairs)
62
+
63
  # Perform the querying
64
  QA_input = {'question': query, 'context': context}
65
  res = pipe(QA_input)