From 0e5b13f23eb9cf4818a219c2f2a20edc231065e8 Mon Sep 17 00:00:00 2001 From: t-yuxuanlei Date: Wed, 18 Dec 2024 04:28:51 +0000 Subject: [PATCH] Fix RecExplainer bug: Automatically create directory if it does not exist --- RecExplainer/preprocess/amazon_generate_v3.py | 2 ++ RecExplainer/preprocess/data_preprocess_amazon.py | 1 + RecExplainer/preprocess/eval_explan.py | 2 ++ RecExplainer/preprocess/gpt_api.py | 1 + RecExplainer/preprocess/mf_amazon_video_games_generate.py | 2 ++ RecExplainer/preprocess/unirec_utils/unirec_split.py | 2 ++ 6 files changed, 10 insertions(+) diff --git a/RecExplainer/preprocess/amazon_generate_v3.py b/RecExplainer/preprocess/amazon_generate_v3.py index c625610..66d36df 100644 --- a/RecExplainer/preprocess/amazon_generate_v3.py +++ b/RecExplainer/preprocess/amazon_generate_v3.py @@ -189,8 +189,10 @@ def gen_uid2next_rank(user_items, args): tokenizer = AutoTokenizer.from_pretrained(args.model_name, model_max_length=args.model_max_length, use_fast=True) if args.gpt_query_file is not None: + os.makedirs(os.path.dirname(args.gpt_query_file), exist_ok=True) gen_uid2summary(user_items, meta_infos, args) else: + os.makedirs(os.path.dirname(args.save_intention_file), exist_ok=True) train_intention = [] train_behavior = [] train_both = [] diff --git a/RecExplainer/preprocess/data_preprocess_amazon.py b/RecExplainer/preprocess/data_preprocess_amazon.py index 0016315..c932a24 100644 --- a/RecExplainer/preprocess/data_preprocess_amazon.py +++ b/RecExplainer/preprocess/data_preprocess_amazon.py @@ -383,4 +383,5 @@ def main_process(data_name, args, data_type='Amazon'): if __name__ == '__main__': args = parse_args() + os.makedirs(os.path.dirname(args.save_data_file), exist_ok=True) main_process(args.full_data_name, args=args, data_type='Amazon') \ No newline at end of file diff --git a/RecExplainer/preprocess/eval_explan.py b/RecExplainer/preprocess/eval_explan.py index 65c62e1..baf47bb 100644 --- a/RecExplainer/preprocess/eval_explan.py +++ b/RecExplainer/preprocess/eval_explan.py @@ -3,6 +3,7 @@ import pandas as pd import argparse +import os def parse_args(): parser = argparse.ArgumentParser(description="data process") @@ -81,6 +82,7 @@ def eval_metric(args): if __name__ == '__main__': args = parse_args() if args.judge_query_file is not None: + os.makedirs(os.path.dirname(args.judge_query_file), exist_ok=True) eval_data_gen(args) else: eval_metric(args) \ No newline at end of file diff --git a/RecExplainer/preprocess/gpt_api.py b/RecExplainer/preprocess/gpt_api.py index 7eef694..6699b13 100644 --- a/RecExplainer/preprocess/gpt_api.py +++ b/RecExplainer/preprocess/gpt_api.py @@ -165,4 +165,5 @@ def main(args): parser.add_argument("--output_file", type=str) parser.add_argument("--input_columns", type=str, default="question") args = parser.parse_args() + os.makedirs(os.path.dirname(args.output_file), exist_ok=True) main(args) diff --git a/RecExplainer/preprocess/mf_amazon_video_games_generate.py b/RecExplainer/preprocess/mf_amazon_video_games_generate.py index 7ba6d53..f3648bc 100644 --- a/RecExplainer/preprocess/mf_amazon_video_games_generate.py +++ b/RecExplainer/preprocess/mf_amazon_video_games_generate.py @@ -191,8 +191,10 @@ def gen_uid2next_rank(user_items, args): tokenizer = AutoTokenizer.from_pretrained(args.model_name, model_max_length=args.model_max_length, use_fast=True) if args.gpt_query_file is not None: + os.makedirs(os.path.dirname(args.gpt_query_file), exist_ok=True) gen_uid2summary(user_items, meta_infos, args) else: + os.makedirs(os.path.dirname(args.save_intention_file), exist_ok=True) train_intention = [] train_behavior = [] train_both = [] diff --git a/RecExplainer/preprocess/unirec_utils/unirec_split.py b/RecExplainer/preprocess/unirec_utils/unirec_split.py index 98b7548..e6c0208 100644 --- a/RecExplainer/preprocess/unirec_utils/unirec_split.py +++ b/RecExplainer/preprocess/unirec_utils/unirec_split.py @@ -3,6 +3,7 @@ import pandas as pd import argparse +import os def parse_args(): parser = argparse.ArgumentParser(description="data process") @@ -64,5 +65,6 @@ def rank_split(args): if __name__ == '__main__': args = parse_args() + os.makedirs(os.path.dirname(args.train_file), exist_ok=True) unirec_split(args) rank_split(args) \ No newline at end of file