domenicrosati commited on
Commit
7cfb21e
Β·
1 Parent(s): 00e4b2e

add some UI improvements

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -136,8 +136,9 @@ st.title("Scientific Question Answering with Citations")
136
 
137
  st.write("""
138
  Ask a scientific question and get an answer drawn from [scite.ai](https://scite.ai) corpus of over 1.1bn citation statements.
139
- Answers are linked to source documents containing citations where users can explore further evidence from scientific literature for the answer. For example try:
140
- Are tanning beds safe to use? Does size of venture capital fund correlate with returns?
 
141
  """)
142
 
143
  st.markdown("""
@@ -147,7 +148,7 @@ st.markdown("""
147
  with st.expander("Settings (strictness, context limit, top hits)"):
148
  strict_mode = st.radio(
149
  "Query mode? Strict means all words must match in source snippet. Lenient means only some words must match.",
150
- ('strict', 'lenient'))
151
  use_reranking = st.radio(
152
  "Use Reranking? Reranking will rerank the top hits using semantic similarity of document and query.",
153
  ('yes', 'no'))
@@ -158,23 +159,20 @@ with st.expander("Settings (strictness, context limit, top hits)"):
158
  context_lim = st.slider('Context limit? How many documents to use for answering from. Larger is slower but higher quality', 10, 300, 25 if torch.cuda.is_available() else 10)
159
 
160
  def paraphrase(text, max_length=128):
161
-
162
- input_ids = queryexp_tokenizer.encode(text, return_tensors="pt", add_special_tokens=True)
163
-
164
- generated_ids = queryexp_model.generate(input_ids=input_ids, num_return_sequences=5, num_beams=5, max_length=max_length)
165
-
166
- preds = '\n'.join([queryexp_tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True) for g in generated_ids])
167
- return preds
168
 
169
 
170
  def run_query(query):
171
  if use_query_exp == 'yes':
172
  query_exp = paraphrase(f"question2question: {query}")
173
  st.markdown(f"""
174
- If you are not getting good results try one of:
175
-
176
- {query_exp}
177
- """)
178
  limit = top_hits_limit or 100
179
  context_limit = context_lim or 10
180
  contexts, orig_docs = search(query, limit=limit, strict=strict_mode == 'strict')
 
136
 
137
  st.write("""
138
  Ask a scientific question and get an answer drawn from [scite.ai](https://scite.ai) corpus of over 1.1bn citation statements.
139
+ Answers are linked to source documents containing citations where users can explore further evidence from scientific literature for the answer.
140
+
141
+ For example try: Are tanning beds safe to use? Does size of venture capital fund correlate with returns?
142
  """)
143
 
144
  st.markdown("""
 
148
  with st.expander("Settings (strictness, context limit, top hits)"):
149
  strict_mode = st.radio(
150
  "Query mode? Strict means all words must match in source snippet. Lenient means only some words must match.",
151
+ ('lenient', 'strict'))
152
  use_reranking = st.radio(
153
  "Use Reranking? Reranking will rerank the top hits using semantic similarity of document and query.",
154
  ('yes', 'no'))
 
159
  context_lim = st.slider('Context limit? How many documents to use for answering from. Larger is slower but higher quality', 10, 300, 25 if torch.cuda.is_available() else 10)
160
 
161
  def paraphrase(text, max_length=128):
162
+ input_ids = queryexp_tokenizer.encode(text, return_tensors="pt", add_special_tokens=True)
163
+ generated_ids = queryexp_model.generate(input_ids=input_ids, num_return_sequences=5, num_beams=5, max_length=max_length)
164
+ queries = set([queryexp_tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True) for g in generated_ids])
165
+ preds = '\n * '.join(queries)
166
+ return preds
 
 
167
 
168
 
169
  def run_query(query):
170
  if use_query_exp == 'yes':
171
  query_exp = paraphrase(f"question2question: {query}")
172
  st.markdown(f"""
173
+ If you are not getting good results try one of:
174
+ * {query_exp}
175
+ """)
 
176
  limit = top_hits_limit or 100
177
  context_limit = context_lim or 10
178
  contexts, orig_docs = search(query, limit=limit, strict=strict_mode == 'strict')