Spaces:
Runtime error
Runtime error
carrie
commited on
Commit
•
15c3a36
1
Parent(s):
c8b4824
reformat
Browse files
app.py
CHANGED
@@ -9,6 +9,28 @@ model = AutoModelForSeq2SeqLM.from_pretrained("fangyuan/lfqa_role_classification
|
|
9 |
tokenizer = AutoTokenizer.from_pretrained("fangyuan/lfqa_role_classification")
|
10 |
en_nlp = stanza.Pipeline('en', processors='tokenize')
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def get_ans_sentence_with_stanza(answer_paragraph, pipeline,
|
13 |
is_offset=False):
|
14 |
'''sentence segmentation with stanza'''
|
@@ -35,7 +57,6 @@ def create_input_to_t5(question, answer):
|
|
35 |
def process_t5_output(input_txt, output_txt):
|
36 |
pred_roles = []
|
37 |
answer_sentence = re.split('\[\d+\] ', input_txt)
|
38 |
-
question = answer_sentence[0].strip()
|
39 |
answer_sentence = answer_sentence[1:]
|
40 |
sentence_idx = re.findall('\[\d+\]', input_txt)
|
41 |
idx_to_sentence = zip(sentence_idx, answer_sentence)
|
@@ -45,7 +66,10 @@ def process_t5_output(input_txt, output_txt):
|
|
45 |
idx: role.strip() for (idx, role) in zip(pred_idx, pred_role)
|
46 |
}
|
47 |
for _, (idx, sentence) in enumerate(idx_to_sentence):
|
48 |
-
|
|
|
|
|
|
|
49 |
return '\n'.join(pred_roles)
|
50 |
|
51 |
|
@@ -71,7 +95,9 @@ gr.Interface(
|
|
71 |
theme="peach",
|
72 |
title="Discourse structure of long-form answer",
|
73 |
description="Input a question with its long-form answer to see the predicted discourse structure by our role classifier.",
|
|
|
74 |
examples=[
|
|
|
75 |
]
|
76 |
).launch(enable_queue=True)
|
77 |
|
|
|
9 |
tokenizer = AutoTokenizer.from_pretrained("fangyuan/lfqa_role_classification")
|
10 |
en_nlp = stanza.Pipeline('en', processors='tokenize')
|
11 |
|
12 |
+
|
13 |
+
article='''
|
14 |
+
# Discourse Structure of Long-form Answers.
|
15 |
+
## About
|
16 |
+
This is a demo for our paper: [How Do We Answer Complex Questions: Discourse Structure of Long-form Answers](https://aclanthology.org/2022.acl-long.249/).
|
17 |
+
Fangyuan Xu, Junyi Jessy Li, Eunsol Choi. 2022.
|
18 |
+
Contact: [Fangyuan Xu](https://www.cs.utexas.edu/~fxu/) via firstname@utexas.edu
|
19 |
+
## Model
|
20 |
+
The model served here is a T5(large)-based role classification model trained on functional roles of ELI5 answers.
|
21 |
+
## Resources
|
22 |
+
Please see more information (paper/code/data/datasheet) at our [website](https://www.cs.utexas.edu/~fxu/lfqa_discourse/index.html)!
|
23 |
+
'''
|
24 |
+
|
25 |
+
role_mappings = {
|
26 |
+
'Answer': 'Answer',
|
27 |
+
'Answer (Summary)': 'Summary',
|
28 |
+
'Auxiliary Information': 'Auxiliary Information',
|
29 |
+
'Answer - Example': 'Example',
|
30 |
+
'Miscellaneous': 'Miscellaneous',
|
31 |
+
'Answer - Organizational sentence': 'Organizational sentence',
|
32 |
+
}
|
33 |
+
|
34 |
def get_ans_sentence_with_stanza(answer_paragraph, pipeline,
|
35 |
is_offset=False):
|
36 |
'''sentence segmentation with stanza'''
|
|
|
57 |
def process_t5_output(input_txt, output_txt):
|
58 |
pred_roles = []
|
59 |
answer_sentence = re.split('\[\d+\] ', input_txt)
|
|
|
60 |
answer_sentence = answer_sentence[1:]
|
61 |
sentence_idx = re.findall('\[\d+\]', input_txt)
|
62 |
idx_to_sentence = zip(sentence_idx, answer_sentence)
|
|
|
66 |
idx: role.strip() for (idx, role) in zip(pred_idx, pred_role)
|
67 |
}
|
68 |
for _, (idx, sentence) in enumerate(idx_to_sentence):
|
69 |
+
pred_role = ' ' if idx not in idx_to_role else idx_to_role[idx]
|
70 |
+
mapped_pred_role = role_mappings[pred_role]
|
71 |
+
pred_roles.append('{}: {}'.format(sentence, mapped_pred_role))
|
72 |
+
pred_roles.append(output_txt)
|
73 |
return '\n'.join(pred_roles)
|
74 |
|
75 |
|
|
|
95 |
theme="peach",
|
96 |
title="Discourse structure of long-form answer",
|
97 |
description="Input a question with its long-form answer to see the predicted discourse structure by our role classifier.",
|
98 |
+
article=article,
|
99 |
examples=[
|
100 |
+
#['', '']
|
101 |
]
|
102 |
).launch(enable_queue=True)
|
103 |
|