AnAutomaticPencil's picture
data preprocessing update
a6326c7
from preprocessor.SerialPreprocessor import SerialConfig, SerialPreprocessor
from const import (
DIALOGUE_SUMMARY,
EMOTION_RECOGNITION,
DIALOGUE_CONTEXT_TO_TEXT_GENERATION,
ABSA_TERM_OPINION_SENTIMENT,
ABSA_TERM_SENTIMENT,
ABSA_CATEGORY_SENTIMENT,
ABSA_TERM_CATEGORY_SENTIMENT,
CHARACTER_IDENTIFICATION,
DIALOGUE_STATE_TRACKING,
DOCUMENT_GROUNDED_CONVERSATION,
TEXT2SQL,
SLOT_FILLING,
)
from preprocessor.prompt_funcs import const_prompt_func_wrapper
from preprocessor.knowledge_funcs import (
None_knowledge,
concat_list_knowledge_wrapper,
extract_turn_knowledge_wrapper,
origin_knowledge,
extract_schema_knowledge_wrapper,
)
from preprocessor.label_funs import (
extract_summary,
extract_turn_emotion_wrapper,
extract_turn_utterance,
extract_aspects_wrapper,
rebuild_utterance_with_characters,
extract_belief_state_wrapper,
extract_sql,
extract_slots_without_intents_wrapper,
)
import os
if __name__ == "__main__":
# 1. Dialogue Summary
TASK = DIALOGUE_SUMMARY
input_path = r"E:\research\processed\DialogueSummary"
output_path = r"E:\research\seq\DialogueSummary"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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(
"Give a summary of this dialogue."
),
knowledge_func=None_knowledge,
label_func=extract_summary,
)
)
serial_proc.launch()
# 2. Emotion Recognition
TASK = EMOTION_RECOGNITION
input_path = r"E:\research\processed\EmotionRecognition"
output_path = r"E:\research\seq\EmotionRecognition"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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(
"With given possible emotions, select the correct answer."
),
knowledge_func=concat_list_knowledge_wrapper(
"possible choices: ", " | "
),
label_func=extract_turn_emotion_wrapper(", "),
)
)
serial_proc.launch()
# 3. Dialogue Context-to-Text Generation
TASK = DIALOGUE_CONTEXT_TO_TEXT_GENERATION
input_path = r"E:\research\processed\Dialogue-Context-to-Text Generation"
output_path = r"E:\research\seq\Dialogue-Context-to-Text Generation"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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(
"With given dialogue context, give the response."
),
knowledge_func=None_knowledge,
label_func=extract_turn_utterance,
roles_to_build_example=[["Listener"], ["third-person"]],
)
)
serial_proc.launch()
# 4. Aspect Sentiment Analysis
# 4.1 ABSA: term opinion sentiment
TASK = ABSA_TERM_OPINION_SENTIMENT
input_path = r"E:\research\processed\ABSA-term opinion sentiment\ASTE"
output_path = r"E:\research\seq\Aspect-based Sentiment Analysis\ASTE"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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("Give all the aspects."),
knowledge_func=None_knowledge,
label_func=extract_aspects_wrapper(" | ", ", "),
)
)
serial_proc.launch()
# 4.2 ABSA: term sentiment
TASK = ABSA_TERM_SENTIMENT
input_path = r"E:\research\processed\ABSA-term sentiment"
output_path = r"E:\research\seq\Aspect-based Sentiment Analysis"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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("Give all the aspects."),
knowledge_func=None_knowledge,
label_func=extract_aspects_wrapper(" | ", ", "),
)
)
serial_proc.launch()
# 4.3 ABSA: category sentiment
TASK = ABSA_CATEGORY_SENTIMENT
input_path = r"E:\research\processed\ABSA-category sentiment"
output_path = r"E:\research\seq\Aspect-based Sentiment Analysis"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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("Give all the aspects."),
knowledge_func=None_knowledge,
label_func=extract_aspects_wrapper(" | ", ", "),
)
)
serial_proc.launch()
# 4.4 ABSA: term category sentiment
TASK = ABSA_TERM_CATEGORY_SENTIMENT
input_path = r"E:\research\processed\ABSA-term category sentiment"
output_path = r"E:\research\seq\Aspect-based Sentiment Analysis"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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("Give all the aspects."),
knowledge_func=None_knowledge,
label_func=extract_aspects_wrapper(" | ", ", "),
)
)
serial_proc.launch()
# 5. Character Identification
TASK = CHARACTER_IDENTIFICATION
input_path = r"E:\research\processed\CharacterIdentification"
output_path = r"E:\research\seq\CharacterIdentification"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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("Generate with all characters."),
knowledge_func=concat_list_knowledge_wrapper("all speakers: ", " | "),
label_func=rebuild_utterance_with_characters,
)
)
serial_proc.launch()
# 6. Dialogue State Tracking
TASK = DIALOGUE_STATE_TRACKING
input_path = r"E:\research\processed\DialogueStateTracking"
output_path = r"E:\research\seq\DialogueStateTracking"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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(
"With given dialogue context, give the dialogue state."
),
knowledge_func=None_knowledge,
label_func=extract_belief_state_wrapper(", ", " | ", "; ", ": "),
roles_to_build_example=[["USER"]],
)
)
serial_proc.launch()
# 7. Document Grounded Conversation
TASK = DOCUMENT_GROUNDED_CONVERSATION
input_path = r"E:\research\processed\DocumentGroundedConversations"
output_path = r"E:\research\seq\DocumentGroundedConversation"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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(
"With given dialogue context, give the response."
),
knowledge_func=origin_knowledge,
turn_knowledge_func=extract_turn_knowledge_wrapper(": ", " | ", "; "),
label_func=extract_turn_utterance,
)
)
serial_proc.launch()
# 8. Text2SQL
TASK = TEXT2SQL
input_path = r"E:\research\processed\Text2SQL"
output_path = r"E:\research\seq\Text2SQL"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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(
"With given dialogue context, give the sql."
),
knowledge_func=origin_knowledge,
turn_knowledge_func=extract_schema_knowledge_wrapper(),
label_func=extract_sql,
)
)
serial_proc.launch()
TASK = SLOT_FILLING
input_path = r"E:\research\processed\SlotFilling\MultiDoGo"
output_path = r"E:\research\seq\SlotFilling\MultiDoGo"
for dataset in os.listdir(input_path):
input_data_path = os.path.join(input_path, dataset)
output_data_path = os.path.join(output_path, dataset)
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(
"With given utterance, fill the slots."
),
knowledge_func=None_knowledge,
label_func=extract_slots_without_intents_wrapper(", ", " | "),
)
)
serial_proc.launch()