-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt_templates.py
84 lines (62 loc) · 3.48 KB
/
prompt_templates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
PROMPTS_WITHOUT_TARGET_QUESTION_MASKING = ['NoP', 'WP-QM', "WP-TQM", "WP-v2.2-TP-QM", "WP-v2.2-TP-TQM", "FP-QM", "FP-TQM"]
def prompting(option, context_text, history_questions, history_answers, question_text, answer_text, question_mask="<mask>", question_mask_dec="<mask>"):
"""
No Prompt: <a> A1 <q> Q1 ... <a> At-1 <q> Qt-1 <a> At <sep> C
Prompt: conversation: answer: A1 question: Q1 ... answer: At-1 question: Qt-1 answer: At question: <mask> context: C
"""
# tokenizer.add_tokens(['<sep>', '<mask>', '<h>', '<\h>', '<q>', '<\q>', '<a>', '<\\a>'])
if option == "NoP":
if not history_questions:
source_text = f"{answer_text} <sep> {context_text}"
else:
history_text = ""
for h_q, h_a in zip(history_questions, history_answers):
history_text += f"<a> {h_a} <q> {h_q} "
source_text = f"{history_text} <a> {answer_text} <sep> {context_text}"
target_text = f"{question_text}"
elif option == "FP+DiffQM":
# with different enc * dec prompt
history_text = ""
for h_q, h_a in zip(history_questions, history_answers):
history_text += f"answer: {h_a} question: {h_q} "
source_text = f"conversation: {history_text} answer: {answer_text} question: {question_mask} context: {context_text}"
target_text = f"{question_mask_dec} {question_text}"
elif option == "FP-v2":
history_text = ""
for h_q, h_a in zip(history_questions, history_answers):
history_text += f"answer: {h_a} question: {h_q} "
source_text = f"conversation: {history_text} answer: {answer_text} question: <mask> context: {context_text}"
target_text = f"<mask> {question_mask} {question_text}"
elif option == "FP":
history_text = ""
for h_q, h_a in zip(history_questions, history_answers):
history_text += f"answer: {h_a} question: {h_q} "
source_text = f"conversation: {history_text} answer: {answer_text} question: {question_mask} context: {context_text}"
target_text = f"{question_mask} {question_text}"
elif option == "FP-SP":
history_text = ""
for h_q, h_a in zip(history_questions, history_answers):
history_text += f"<a> {h_a} <q> {h_q} "
source_text = f"{history_text} <a> {answer_text} <q> {question_mask} <sep> {context_text}"
target_text = f"{question_mask} {question_text}"
elif option == "FP-QM":
history_text = ""
for h_q, h_a in zip(history_questions, history_answers):
history_text += f"answer: {h_a} question: {h_q} "
source_text = f"conversation: {history_text} answer: {answer_text} context: {context_text}"
target_text = f"{question_text}"
elif option == "FP-SQM":
history_text = ""
for h_q, h_a in zip(history_questions, history_answers):
history_text += f"answer: {h_a} question: {h_q} "
source_text = f"conversation: {history_text} answer: {answer_text} context: {context_text}"
target_text = f"{question_mask} {question_text}"
elif option == "FP-TQM":
history_text = ""
for h_q, h_a in zip(history_questions, history_answers):
history_text += f"answer: {h_a} question: {h_q} "
source_text = f"conversation: {history_text} answer: {answer_text} question: {question_mask} context: {context_text}"
target_text = f"{question_text}"
else:
raise NotImplementedError
return source_text, target_text