|
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=origin_knowledge, |
|
turn_knowledge_func=extract_turn_knowledge_wrapper( |
|
": ", " | ", ", " |
|
), |
|
label_func=extract_turn_utterance, |
|
roles_to_build_example=[["user1"], ["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_dialogue_knowledge_wrapper( |
|
": ", " | ", ", " |
|
), |
|
|
|
|
|
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(": ", " | ", "; ", " "), |
|
|
|
|
|
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_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() |
|
|