kleinay commited on
Commit
111d053
β€’
1 Parent(s): 5153e30

add 'layers' to interface

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -7,13 +7,15 @@ pipeline = QASemEndToEndPipeline()
7
 
8
  description = f"""This is a demo of the QASem Parsing pipeline. It wraps models of three QA-based semantic tasks, composing a comprehensive semi-structured representation of sentence meaning - covering verbal and nominal semantic role labeling together with discourse relations."""
9
  title="QASem Parsing Demo"
10
- examples = [["Both were shot in the confrontation with police and have been recovering in hospital since the attack .", 0.75],
11
- ["the construction of the officer 's building was delayed by the lockdown and is expected to continue for at least 10 more months.", 0.75],
12
- ["While President Obama expressed condolences regarding the death of Margaret Thatcher upon her death earlier this year , he did not issue an executive order that flags be lowered in her honor .", 0.75],
13
- ["We made a very clear commitment : if there is any proposal in the next parliament for a transfer of powers to Brussels ( the EU ) we will have an in/out referendum .", 0.75],
14
- ["The doctor asked about the progress in Luke 's treatment .", 0.75],
15
- ["The Veterinary student was interested in Luke 's treatment of sea animals .", 0.7],
16
- ["Some reviewers agreed that the criticism raised by the AC is mostly justified .", 0.6]]
 
 
17
 
18
 
19
  input_sent_box_label = "Insert sentence here, or select from the examples below"
@@ -22,7 +24,7 @@ links = """<p style='text-align: center'>
22
  </p>"""
23
 
24
 
25
- def call(sentence, detection_threshold):
26
 
27
  outputs = pipeline([sentence], nominalization_detection_threshold=detection_threshold)[0]
28
  def pretty_qadisc_qas(qa_infos) -> List[str]:
@@ -33,6 +35,10 @@ def call(sentence, detection_threshold):
33
  if not pred_info or not pred_info['QAs']: return []
34
  return ["- " + f"{qa['question']} --- {';'.join(qa['answers'])}".lstrip()
35
  for qa in pred_info['QAs'] if qa is not None]
 
 
 
 
36
  qasrl_qas = [qa for pred_info in outputs['qasrl'] for qa in pretty_qasrl_qas(pred_info)]
37
  qanom_qas = [qa for pred_info in outputs['qanom'] for qa in pretty_qasrl_qas(pred_info)]
38
  qadisc_qas= pretty_qadisc_qas(outputs['qadiscourse'])
@@ -55,6 +61,7 @@ def call(sentence, detection_threshold):
55
 
56
  iface = gr.Interface(fn=call,
57
  inputs=[gr.inputs.Textbox(placeholder=input_sent_box_label, label="Sentence", lines=4),
 
58
  gr.inputs.Slider(minimum=0., maximum=1., step=0.01, default=0.75, label="Nominalization Detection Threshold")],
59
  outputs=[gr.outputs.HTML(label="Detected Predicates"),
60
  gr.outputs.Textbox(label="Generated QAs"),
 
7
 
8
  description = f"""This is a demo of the QASem Parsing pipeline. It wraps models of three QA-based semantic tasks, composing a comprehensive semi-structured representation of sentence meaning - covering verbal and nominal semantic role labeling together with discourse relations."""
9
  title="QASem Parsing Demo"
10
+
11
+ all_layers = ["qasrl", "qanom", "qadiscourse"]
12
+ examples = [["Both were shot in the confrontation with police and have been recovering in hospital since the attack .", all_layers, 0.75],
13
+ ["the construction of the officer 's building was delayed by the lockdown and is expected to continue for at least 10 more months.", all_layers, 0.75],
14
+ ["While President Obama expressed condolences regarding the death of Margaret Thatcher upon her death earlier this year , he did not issue an executive order that flags be lowered in her honor .", all_layers, 0.75],
15
+ ["We made a very clear commitment : if there is any proposal in the next parliament for a transfer of powers to Brussels ( the EU ) we will have an in/out referendum .", all_layers, 0.75],
16
+ ["The doctor asked about the progress in Luke 's treatment .", all_layers, 0.75],
17
+ ["The Veterinary student was interested in Luke 's treatment of sea animals .", all_layers, 0.7],
18
+ ["Some reviewers agreed that the criticism raised by the AC is mostly justified .", all_layers, 0.6]]
19
 
20
 
21
  input_sent_box_label = "Insert sentence here, or select from the examples below"
 
24
  </p>"""
25
 
26
 
27
+ def call(sentence, layers, detection_threshold):
28
 
29
  outputs = pipeline([sentence], nominalization_detection_threshold=detection_threshold)[0]
30
  def pretty_qadisc_qas(qa_infos) -> List[str]:
 
35
  if not pred_info or not pred_info['QAs']: return []
36
  return ["- " + f"{qa['question']} --- {';'.join(qa['answers'])}".lstrip()
37
  for qa in pred_info['QAs'] if qa is not None]
38
+ # filter outputs by requested `layers`
39
+ outputs = {layer: qas if layer in layers else []
40
+ for layer, qas in outputs.items()}
41
+ # Prettify outputs
42
  qasrl_qas = [qa for pred_info in outputs['qasrl'] for qa in pretty_qasrl_qas(pred_info)]
43
  qanom_qas = [qa for pred_info in outputs['qanom'] for qa in pretty_qasrl_qas(pred_info)]
44
  qadisc_qas= pretty_qadisc_qas(outputs['qadiscourse'])
 
61
 
62
  iface = gr.Interface(fn=call,
63
  inputs=[gr.inputs.Textbox(placeholder=input_sent_box_label, label="Sentence", lines=4),
64
+ gr.inputs.CheckboxGroup(all_layers, value=all_layers, label="Annotation Layers"),
65
  gr.inputs.Slider(minimum=0., maximum=1., step=0.01, default=0.75, label="Nominalization Detection Threshold")],
66
  outputs=[gr.outputs.HTML(label="Detected Predicates"),
67
  gr.outputs.Textbox(label="Generated QAs"),