Spaces:
Sleeping
Sleeping
liujch1998
commited on
Commit
•
1a61355
1
Parent(s):
ebb18a8
Improve outputs
Browse files
app.py
CHANGED
@@ -103,23 +103,16 @@ rainier = InteractiveRainier()
|
|
103 |
|
104 |
def predict(question, kg_model, qa_model, max_input_len, max_output_len, m, top_p):
|
105 |
result = rainier.run(question, max_input_len, max_output_len, m, top_p)
|
106 |
-
output = ''
|
107 |
-
output += f'QA model answer without knowledge: {result["knowless_pred"]}\n'
|
108 |
-
output += f'QA model answer with knowledge: {result["knowful_pred"]}\n'
|
109 |
-
output += '\n'
|
110 |
-
output += f'All generated knowledges:\n'
|
111 |
-
for knowledge in result['knowledges']:
|
112 |
-
|
113 |
-
output += '\n'
|
114 |
-
output += f'Knowledge selected to make the prediction: {result["selected_knowledge"]}\n'
|
115 |
-
return
|
116 |
-
|
117 |
-
description = '''This is a demo for the paper, <a href="https://arxiv.org/pdf/2210.03078.pdf" target="_blank">Rainier: Reinforced Knowledge Introspector for Commonsense Question Answering</a>, presented in EMNLP 2022.
|
118 |
-
[<a href="https://github.com/liujch1998/rainier" target="_blank">Code</a>] [<a href="https://huggingface.co/liujch1998/rainier-large" target="_blank">Model</a>]
|
119 |
-
This demo is made & maintained by <a href="https://liujch1998.github.io/" target="_blank">Jiacheng (Gary) Liu</a>.
|
120 |
-
|
121 |
-
Rainier is a knowledge-generating model that enhances the commonsense QA capability of a QA model.
|
122 |
-
To try this model, select an example question, or write your own question in the suggested format.'''
|
123 |
|
124 |
examples = [
|
125 |
'If the mass of an object gets bigger what will happen to the amount of matter contained within it? \\n (A) gets bigger (B) gets smaller',
|
@@ -141,12 +134,18 @@ input_m = gr.Slider(label='Number of generated knowledges:', value=10, mininum=1
|
|
141 |
info='The actual number of generated knowledges may be less than this number due to possible duplicates.',
|
142 |
)
|
143 |
input_top_p = gr.Slider(label='top_p for knowledge generation:', value=0.5, mininum=0.0, maximum=1.0, step=0.05)
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
gr.Interface(
|
147 |
fn=predict,
|
148 |
inputs=[input_question, input_kg_model, input_qa_model, input_max_input_len, input_max_output_len, input_m, input_top_p],
|
149 |
-
outputs=
|
150 |
title="Rainier Demo",
|
151 |
description=description,
|
152 |
).launch()
|
|
|
103 |
|
104 |
def predict(question, kg_model, qa_model, max_input_len, max_output_len, m, top_p):
|
105 |
result = rainier.run(question, max_input_len, max_output_len, m, top_p)
|
106 |
+
# output = ''
|
107 |
+
# output += f'QA model answer without knowledge: {result["knowless_pred"]}\n'
|
108 |
+
# output += f'QA model answer with knowledge: {result["knowful_pred"]}\n'
|
109 |
+
# output += '\n'
|
110 |
+
# output += f'All generated knowledges:\n'
|
111 |
+
# for knowledge in result['knowledges']:
|
112 |
+
# output += f' {knowledge}\n'
|
113 |
+
# output += '\n'
|
114 |
+
# output += f'Knowledge selected to make the prediction: {result["selected_knowledge"]}\n'
|
115 |
+
return result['knowless_pred'], result['knowful_pred'], '\n'.join(result['knowledges']), result['selected_knowledge']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
examples = [
|
118 |
'If the mass of an object gets bigger what will happen to the amount of matter contained within it? \\n (A) gets bigger (B) gets smaller',
|
|
|
134 |
info='The actual number of generated knowledges may be less than this number due to possible duplicates.',
|
135 |
)
|
136 |
input_top_p = gr.Slider(label='top_p for knowledge generation:', value=0.5, mininum=0.0, maximum=1.0, step=0.05)
|
137 |
+
output_knowless_answer = gr.Textbox(label='QA model answer without knowledge:', interactive=False)
|
138 |
+
output_knowful_answer = gr.Textbox(label='QA model answer with knowledge:', interactive=False)
|
139 |
+
output_all_knowledges = gr.Textbox(label='All generated knowledges:', interactive=False)
|
140 |
+
output_selected_knowledge = gr.Textbox(label='Knowledge selected to make the prediction:', interactive=False)
|
141 |
+
|
142 |
+
description = '''This is a demo for the paper, [*Rainier: Reinforced Knowledge Introspector for Commonsense Question Answering*](https://arxiv.org/pdf/2210.03078.pdf), presented at EMNLP 2022. [[Code](https://github.com/liujch1998/rainier)] [[Model](https://huggingface.co/liujch1998/rainier-large)] This demo is made & maintained by [Jiacheng (Gary) Liu](https://liujch1998.github.io).
|
143 |
+
Rainier is a knowledge-generating model that enhances the commonsense QA capability of a QA model. To try this model, select an example question, or write your own commonsense question in the suggested format.'''
|
144 |
|
145 |
gr.Interface(
|
146 |
fn=predict,
|
147 |
inputs=[input_question, input_kg_model, input_qa_model, input_max_input_len, input_max_output_len, input_m, input_top_p],
|
148 |
+
outputs=[output_knowless_answer, output_knowful_answer, output_all_knowledges, output_selected_knowledge],
|
149 |
title="Rainier Demo",
|
150 |
description=description,
|
151 |
).launch()
|