File size: 5,671 Bytes
a6326c7 |
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
import sys
sys.path.append("modules/preprocess")
from preprocessor.SerialPreprocessor import SerialConfig, SerialPreprocessor
from const import (
DIALOGUE_CONTEXT_TO_RESPONSE_GENERATION,
DOCUMENT_GROUNDED_CONVERSATION,
MULTI_REF_SEP,
)
from preprocessor.prompt_funcs import const_prompt_func_wrapper
from preprocessor.knowledge_funcs import (
extract_dialogue_knowledge_wrapper,
origin_knowledge,
None_knowledge,
extract_kg_knowledge_wrapper,
extract_turn_knowledge_wrapper,
)
from preprocessor.label_funs import (
extract_turn_utterance,
)
import sys
if __name__ == "__main__":
input_data_path = sys.argv[1]
output_data_path = sys.argv[2]
TASK = DOCUMENT_GROUNDED_CONVERSATION
if len(sys.argv) <= 3:
based_on = "dialogue"
else:
based_on = sys.argv[3]
if len(sys.argv) < 5:
if based_on == "turn-document":
serial_proc = SerialPreprocessor(
SerialConfig(
input_data_path,
output_data_path,
TASK,
logger_name=TASK,
task_bos_token=f"[{TASK}]",
prompt_func=const_prompt_func_wrapper(
"Response based on the dialogue context and given knowledge"
),
# knowledge_func=extract_kg_knowledge_wrapper(": ", " | ", "; ", " "),
# knowledge_func=extract_dialogue_knowledge_wrapper(": ", " | ", ", "),
# knowledge_func=None_knowledge,
knowledge_func=origin_knowledge,
turn_knowledge_func=extract_turn_knowledge_wrapper(
": ", " | ", ", "
),
label_func=extract_turn_utterance,
roles_to_build_example=[["user1"], ["user2"]],
# dev_and_test_roles_to_build_example=[["user2"]],
roles_in_history=None,
multi_ref_sep=None,
)
)
elif based_on == "document":
serial_proc = SerialPreprocessor(
SerialConfig(
input_data_path,
output_data_path,
TASK,
logger_name=TASK,
task_bos_token=f"[{TASK}]",
prompt_func=const_prompt_func_wrapper(
"Response based on the dialogue context and given knowledge"
),
# knowledge_func=extract_kg_knowledge_wrapper(": ", " | ", "; ", " "),
knowledge_func=extract_dialogue_knowledge_wrapper(
": ", " | ", ", "
),
# knowledge_func=None_knowledge,
# knowledge_func=origin_knowledge,
label_func=extract_turn_utterance,
roles_to_build_example=[
["third-person"],
["Listener"],
["Speaker"],
],
dev_and_test_roles_to_build_example=[
["third-person"],
["Listener"],
],
)
)
elif based_on == "None":
serial_proc = SerialPreprocessor(
SerialConfig(
input_data_path,
output_data_path,
TASK,
logger_name=TASK,
task_bos_token=f"[{TASK}]",
prompt_func=const_prompt_func_wrapper(
"Response based on the dialogue context and given knowledge"
),
knowledge_func=None_knowledge,
label_func=extract_turn_utterance,
roles_to_build_example=[["SYSTEM"]],
)
)
else:
serial_proc = SerialPreprocessor(
SerialConfig(
input_data_path,
output_data_path,
TASK,
logger_name=TASK,
task_bos_token=f"[{TASK}]",
prompt_func=const_prompt_func_wrapper(
"Response based on the dialogue context and given knowledge"
),
knowledge_func=extract_kg_knowledge_wrapper(": ", " | ", "; ", " "),
# knowledge_func=extract_dialogue_knowledge_wrapper(": ", " | ", ", "),
# knowledge_func=None_knowledge,
label_func=extract_turn_utterance,
roles_to_build_example=[["SYSTEM"], ["USER"]],
dev_and_test_roles_to_build_example=[["SYSTEM"]],
)
)
else:
serial_proc = SerialPreprocessor(
SerialConfig(
input_data_path,
output_data_path,
TASK,
logger_name=TASK,
task_bos_token=f"[{TASK}]",
prompt_func=const_prompt_func_wrapper(
"Response based on the dialogue context and given knowledge"
),
# knowledge_func=extract_kg_knowledge_wrapper(": ", " | ", "; ", " "),
knowledge_func=extract_dialogue_knowledge_wrapper(": ", " | ", ", "),
label_func=extract_turn_utterance,
roles_to_build_example=[["SYSTEM"]],
roles_in_history=[["USER"]],
multi_ref_sep=MULTI_REF_SEP,
)
)
serial_proc.launch()
|