diff --git a/.ipynb_checkpoints/environment-checkpoint.txt b/.ipynb_checkpoints/environment-checkpoint.txt new file mode 100644 index 0000000..b2f91e3 --- /dev/null +++ b/.ipynb_checkpoints/environment-checkpoint.txt @@ -0,0 +1,12 @@ +python==3.9.7 +transformers==4.26.0 +torch==1.8.1+cu111 +sklearn==1.1.2 +torchvision==0.9.1+cu111 +tqdm==4.64.1 +time +collections +argparse +os +sys +numpy==1.23.1 diff --git a/.ipynb_checkpoints/prompt-checkpoint.txt b/.ipynb_checkpoints/prompt-checkpoint.txt new file mode 100644 index 0000000..0e131a8 --- /dev/null +++ b/.ipynb_checkpoints/prompt-checkpoint.txt @@ -0,0 +1,22 @@ +sequential; seen; Considering {dataset} user_{user_id} has interacted with {dataset} items {history} . What is the next recommendation for the user ?; {dataset} {target} +sequential; seen; Here is the purchase history of {dataset} user_{user_id} : {dataset} item {history} . I wonder what is the next recommended item for the user .; {dataset} {target} +sequential; seen; {dataset} user_{user_id} has purchased {dataset} items {history}, predict next possible item to be bought by the user ?; {dataset} {target} +sequential; seen; I find the purchase list of {dataset} user_{user_id} : {dataset} items {history} , I wonder what other itmes does the user need . Can you help me decide ?; {dataset} {target} +sequential; seen; According to what items {dataset} user_{user_id} has purchased : {dataset} items {history} , Can you recommend another item to the user ?; {dataset} {target} +sequential; seen; What would {dataset} user_{user_id} be likely to purchase next after buying {dataset} items {history} ?; {dataset} {target} +sequential; seen; By analyzing the {dataset} user_{user_id} 's purchase of {dataset} items {history} , what is the next item expected to be bought ?; {dataset} {target} +sequential; seen; Can you recommend the next item for {dataset} user_{user_id} , given the user 's purchase of {dataset} items {history} ?; {dataset} {target} +sequential; seen; After buying {dataset} items {history} , what is the next item that could be recommended for {dataset} user_{user_id} ?; {dataset} {target} +sequential; seen; The {dataset} user_{user_id} has bought items : {dataset} items {history} , What else do you think is necessary for the user ?; {dataset} {target} +sequential; unseen; What is the top recommended item for {dataset} user_{user_id} who interacted with {dataset} item {history} ?; {dataset} {target} +straightforward; seen; What should we recommend for {dataset} user_{user_id} ?; {dataset} {target} +straightforward; seen; {dataset} user_{user_id} is looking for some items . Do you have any recommendations ?; {dataset} {target} +straightforward; seen; Do you have any suggested items for {dataset} user_{user_id} ?; {dataset} {target} +straightforward; seen; Which recommendation should we provide to {dataset} user_{user_id} ?; {dataset} {target} +straightforward; seen; How can we assist {dataset} user_{user_id} with a recommendation ?; {dataset} {target} +straightforward; seen; What would be a suitable recommendation for {dataset} user_{user_id} ?; {dataset} {target} +straightforward; seen; What would be a helpful recommendation for {dataset} user_{user_id} ?; {dataset} {target} +straightforward; seen; Can you recommend an item for {dataset} user_{user_id} ?; {dataset} {target} +straightforward; seen; Based on {dataset} user_{user_id} 's interests and requirements , what item would you suggest to try ?; {dataset} {target} +straightforward; seen; For {dataset} user_{user_id} , what item stands out as a top recommendation that they should consider ?; {dataset} {target} +straightforward; unseen; What is the top recommendation for {dataset} user_{user_id} ?; {dataset} {target} \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Beauty_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/Beauty_collaborative-checkpoint.sh new file mode 100644 index 0000000..bb251ad --- /dev/null +++ b/command/.ipynb_checkpoints/Beauty_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1 --tasks sequential --item_indexing collaborative --epochs 20 --batch_size 64 --master_port 1112 --prompt_file ../prompt.txt --sample_prompt 0 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --test_filtered_batch 0 --test_before_train 0 --test_epoch 2 diff --git a/command/.ipynb_checkpoints/Beauty_random-checkpoint.sh b/command/.ipynb_checkpoints/Beauty_random-checkpoint.sh new file mode 100644 index 0000000..3fdd004 --- /dev/null +++ b/command/.ipynb_checkpoints/Beauty_random-checkpoint.sh @@ -0,0 +1,2 @@ +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 + diff --git a/command/.ipynb_checkpoints/Beauty_sequential-checkpoint.sh b/command/.ipynb_checkpoints/Beauty_sequential-checkpoint.sh new file mode 100644 index 0000000..62aa6cc --- /dev/null +++ b/command/.ipynb_checkpoints/Beauty_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Beauty --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 diff --git a/command/.ipynb_checkpoints/CDs_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/CDs_collaborative-checkpoint.sh new file mode 100644 index 0000000..195ba88 --- /dev/null +++ b/command/.ipynb_checkpoints/CDs_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 diff --git a/command/.ipynb_checkpoints/CDs_random-checkpoint.sh b/command/.ipynb_checkpoints/CDs_random-checkpoint.sh new file mode 100644 index 0000000..8f79815 --- /dev/null +++ b/command/.ipynb_checkpoints/CDs_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 diff --git a/command/.ipynb_checkpoints/CDs_sequential-checkpoint.sh b/command/.ipynb_checkpoints/CDs_sequential-checkpoint.sh new file mode 100644 index 0000000..616ac17 --- /dev/null +++ b/command/.ipynb_checkpoints/CDs_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 64 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Clothing_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/Clothing_collaborative-checkpoint.sh new file mode 100644 index 0000000..b38efa1 --- /dev/null +++ b/command/.ipynb_checkpoints/Clothing_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 diff --git a/command/.ipynb_checkpoints/Clothing_random-checkpoint.sh b/command/.ipynb_checkpoints/Clothing_random-checkpoint.sh new file mode 100644 index 0000000..cf18ff3 --- /dev/null +++ b/command/.ipynb_checkpoints/Clothing_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 diff --git a/command/.ipynb_checkpoints/Clothing_sequential-checkpoint.sh b/command/.ipynb_checkpoints/Clothing_sequential-checkpoint.sh new file mode 100644 index 0000000..9cc9206 --- /dev/null +++ b/command/.ipynb_checkpoints/Clothing_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 5,6 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1124 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 diff --git a/command/.ipynb_checkpoints/Electronics_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/Electronics_collaborative-checkpoint.sh new file mode 100644 index 0000000..41e3999 --- /dev/null +++ b/command/.ipynb_checkpoints/Electronics_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Electronics_random-checkpoint.sh b/command/.ipynb_checkpoints/Electronics_random-checkpoint.sh new file mode 100644 index 0000000..51651ed --- /dev/null +++ b/command/.ipynb_checkpoints/Electronics_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Electronics_sequential-checkpoint.sh b/command/.ipynb_checkpoints/Electronics_sequential-checkpoint.sh new file mode 100644 index 0000000..b41954b --- /dev/null +++ b/command/.ipynb_checkpoints/Electronics_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/LastFM_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/LastFM_collaborative-checkpoint.sh new file mode 100644 index 0000000..7e3d0b9 --- /dev/null +++ b/command/.ipynb_checkpoints/LastFM_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 0 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 2 --collaborative_token_size 50 --collaborative_cluster 10 diff --git a/command/.ipynb_checkpoints/LastFM_random-checkpoint.sh b/command/.ipynb_checkpoints/LastFM_random-checkpoint.sh new file mode 100644 index 0000000..c5b20b5 --- /dev/null +++ b/command/.ipynb_checkpoints/LastFM_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/LastFM_sequential-checkpoint.sh b/command/.ipynb_checkpoints/LastFM_sequential-checkpoint.sh new file mode 100644 index 0000000..fbcee0f --- /dev/null +++ b/command/.ipynb_checkpoints/LastFM_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/ML100K_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/ML100K_collaborative-checkpoint.sh new file mode 100644 index 0000000..3aeae62 --- /dev/null +++ b/command/.ipynb_checkpoints/ML100K_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/ML100K_random-checkpoint.sh b/command/.ipynb_checkpoints/ML100K_random-checkpoint.sh new file mode 100644 index 0000000..9d8089c --- /dev/null +++ b/command/.ipynb_checkpoints/ML100K_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/ML100K_sequential-checkpoint.sh b/command/.ipynb_checkpoints/ML100K_sequential-checkpoint.sh new file mode 100644 index 0000000..ee3509b --- /dev/null +++ b/command/.ipynb_checkpoints/ML100K_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/ML1M_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/ML1M_collaborative-checkpoint.sh new file mode 100644 index 0000000..a17155a --- /dev/null +++ b/command/.ipynb_checkpoints/ML1M_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/ML1M_random-checkpoint.sh b/command/.ipynb_checkpoints/ML1M_random-checkpoint.sh new file mode 100644 index 0000000..e668c93 --- /dev/null +++ b/command/.ipynb_checkpoints/ML1M_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/ML1M_sequential-checkpoint.sh b/command/.ipynb_checkpoints/ML1M_sequential-checkpoint.sh new file mode 100644 index 0000000..23676ef --- /dev/null +++ b/command/.ipynb_checkpoints/ML1M_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 1984 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Movies_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/Movies_collaborative-checkpoint.sh new file mode 100644 index 0000000..eceb4b8 --- /dev/null +++ b/command/.ipynb_checkpoints/Movies_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Movies_random-checkpoint.sh b/command/.ipynb_checkpoints/Movies_random-checkpoint.sh new file mode 100644 index 0000000..f38b1cf --- /dev/null +++ b/command/.ipynb_checkpoints/Movies_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Movies_sequential-checkpoint.sh b/command/.ipynb_checkpoints/Movies_sequential-checkpoint.sh new file mode 100644 index 0000000..997c8b8 --- /dev/null +++ b/command/.ipynb_checkpoints/Movies_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/SP5_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/SP5_collaborative-checkpoint.sh new file mode 100644 index 0000000..9292262 --- /dev/null +++ b/command/.ipynb_checkpoints/SP5_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/SP5_random-checkpoint.sh b/command/.ipynb_checkpoints/SP5_random-checkpoint.sh new file mode 100644 index 0000000..f294729 --- /dev/null +++ b/command/.ipynb_checkpoints/SP5_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/SP5_sequential-checkpoint.sh b/command/.ipynb_checkpoints/SP5_sequential-checkpoint.sh new file mode 100644 index 0000000..0e9092f --- /dev/null +++ b/command/.ipynb_checkpoints/SP5_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Taobao_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/Taobao_collaborative-checkpoint.sh new file mode 100644 index 0000000..e9bf349 --- /dev/null +++ b/command/.ipynb_checkpoints/Taobao_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Taobao_random-checkpoint.sh b/command/.ipynb_checkpoints/Taobao_random-checkpoint.sh new file mode 100644 index 0000000..f5addac --- /dev/null +++ b/command/.ipynb_checkpoints/Taobao_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Taobao_sequential-checkpoint.sh b/command/.ipynb_checkpoints/Taobao_sequential-checkpoint.sh new file mode 100644 index 0000000..7cd5564 --- /dev/null +++ b/command/.ipynb_checkpoints/Taobao_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Yelp_collaborative-checkpoint.sh b/command/.ipynb_checkpoints/Yelp_collaborative-checkpoint.sh new file mode 100644 index 0000000..bc225c5 --- /dev/null +++ b/command/.ipynb_checkpoints/Yelp_collaborative-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 1 --test_prompt seen:0 --lr 1e-3 --collaborative_token_size 500 --test_before_train 0 --test_epoch 0 --collaborative_float32 1 \ No newline at end of file diff --git a/command/.ipynb_checkpoints/Yelp_random-checkpoint.sh b/command/.ipynb_checkpoints/Yelp_random-checkpoint.sh new file mode 100644 index 0000000..a5bc238 --- /dev/null +++ b/command/.ipynb_checkpoints/Yelp_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 diff --git a/command/.ipynb_checkpoints/Yelp_sequential-checkpoint.sh b/command/.ipynb_checkpoints/Yelp_sequential-checkpoint.sh new file mode 100644 index 0000000..06d6d0b --- /dev/null +++ b/command/.ipynb_checkpoints/Yelp_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 64 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/Beauty_collaborative.sh b/command/Beauty_collaborative.sh index 74051f9..bb251ad 100644 --- a/command/Beauty_collaborative.sh +++ b/command/Beauty_collaborative.sh @@ -1,3 +1 @@ -python ../src/main.py --datasets Beauty --distributed 1 --gpu 1,2 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 64 --master_port 2023 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 - -# wiser -r 9 \ No newline at end of file +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1 --tasks sequential --item_indexing collaborative --epochs 20 --batch_size 64 --master_port 1112 --prompt_file ../prompt.txt --sample_prompt 0 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --test_filtered_batch 0 --test_before_train 0 --test_epoch 2 diff --git a/command/Beauty_random.sh b/command/Beauty_random.sh index 13ffb9f..3fdd004 100644 --- a/command/Beauty_random.sh +++ b/command/Beauty_random.sh @@ -1,3 +1,2 @@ -python ../src/main.py --datasets Beauty --distributed 1 --gpu 3,4 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 -# wiser -r 1646 \ No newline at end of file diff --git a/command/Beauty_sequential.sh b/command/Beauty_sequential.sh index fa79f5d..62aa6cc 100644 --- a/command/Beauty_sequential.sh +++ b/command/Beauty_sequential.sh @@ -1,3 +1 @@ -python ../src/main.py --datasets Beauty --distributed 1 --gpu 5,6 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 - -# wiser -r 1647 \ No newline at end of file +python ../src/main.py --datasets Beauty --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 diff --git a/command/CDs_collaborative.sh b/command/CDs_collaborative.sh new file mode 100644 index 0000000..195ba88 --- /dev/null +++ b/command/CDs_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 diff --git a/command/CDs_random.sh b/command/CDs_random.sh new file mode 100644 index 0000000..8f79815 --- /dev/null +++ b/command/CDs_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 diff --git a/command/CDs_sequential.sh b/command/CDs_sequential.sh new file mode 100644 index 0000000..616ac17 --- /dev/null +++ b/command/CDs_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 64 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/Clothing_collaborative.sh b/command/Clothing_collaborative.sh new file mode 100644 index 0000000..b38efa1 --- /dev/null +++ b/command/Clothing_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 diff --git a/command/Clothing_random.sh b/command/Clothing_random.sh new file mode 100644 index 0000000..cf18ff3 --- /dev/null +++ b/command/Clothing_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 diff --git a/command/Clothing_sequential.sh b/command/Clothing_sequential.sh new file mode 100644 index 0000000..9cc9206 --- /dev/null +++ b/command/Clothing_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 5,6 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1124 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 diff --git a/command/Electronics_collaborative.sh b/command/Electronics_collaborative.sh new file mode 100644 index 0000000..41e3999 --- /dev/null +++ b/command/Electronics_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/Electronics_random.sh b/command/Electronics_random.sh new file mode 100644 index 0000000..51651ed --- /dev/null +++ b/command/Electronics_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/Electronics_sequential.sh b/command/Electronics_sequential.sh new file mode 100644 index 0000000..b41954b --- /dev/null +++ b/command/Electronics_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 \ No newline at end of file diff --git a/command/LastFM_collaborative.sh b/command/LastFM_collaborative.sh new file mode 100644 index 0000000..7e3d0b9 --- /dev/null +++ b/command/LastFM_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 0 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 2 --collaborative_token_size 50 --collaborative_cluster 10 diff --git a/command/LastFM_random.sh b/command/LastFM_random.sh new file mode 100644 index 0000000..c5b20b5 --- /dev/null +++ b/command/LastFM_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 \ No newline at end of file diff --git a/command/LastFM_sequential.sh b/command/LastFM_sequential.sh new file mode 100644 index 0000000..fbcee0f --- /dev/null +++ b/command/LastFM_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 \ No newline at end of file diff --git a/command/ML100K_collaborative.sh b/command/ML100K_collaborative.sh new file mode 100644 index 0000000..3aeae62 --- /dev/null +++ b/command/ML100K_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/ML100K_random.sh b/command/ML100K_random.sh new file mode 100644 index 0000000..9d8089c --- /dev/null +++ b/command/ML100K_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/ML100K_sequential.sh b/command/ML100K_sequential.sh new file mode 100644 index 0000000..ee3509b --- /dev/null +++ b/command/ML100K_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/ML1M_collaborative.sh b/command/ML1M_collaborative.sh new file mode 100644 index 0000000..a17155a --- /dev/null +++ b/command/ML1M_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/ML1M_random.sh b/command/ML1M_random.sh new file mode 100644 index 0000000..e668c93 --- /dev/null +++ b/command/ML1M_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/ML1M_sequential.sh b/command/ML1M_sequential.sh new file mode 100644 index 0000000..23676ef --- /dev/null +++ b/command/ML1M_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 1984 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/Movies_collaborative.sh b/command/Movies_collaborative.sh new file mode 100644 index 0000000..eceb4b8 --- /dev/null +++ b/command/Movies_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/Movies_random.sh b/command/Movies_random.sh new file mode 100644 index 0000000..f38b1cf --- /dev/null +++ b/command/Movies_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/Movies_sequential.sh b/command/Movies_sequential.sh new file mode 100644 index 0000000..997c8b8 --- /dev/null +++ b/command/Movies_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 \ No newline at end of file diff --git a/command/SP5_collaborative.sh b/command/SP5_collaborative.sh new file mode 100644 index 0000000..9292262 --- /dev/null +++ b/command/SP5_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/SP5_random.sh b/command/SP5_random.sh new file mode 100644 index 0000000..f294729 --- /dev/null +++ b/command/SP5_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/SP5_sequential.sh b/command/SP5_sequential.sh new file mode 100644 index 0000000..0e9092f --- /dev/null +++ b/command/SP5_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/Taobao_collaborative.sh b/command/Taobao_collaborative.sh new file mode 100644 index 0000000..e9bf349 --- /dev/null +++ b/command/Taobao_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 \ No newline at end of file diff --git a/command/Taobao_random.sh b/command/Taobao_random.sh new file mode 100644 index 0000000..f5addac --- /dev/null +++ b/command/Taobao_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/Taobao_sequential.sh b/command/Taobao_sequential.sh new file mode 100644 index 0000000..7cd5564 --- /dev/null +++ b/command/Taobao_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 \ No newline at end of file diff --git a/command/Yelp_collaborative.sh b/command/Yelp_collaborative.sh new file mode 100644 index 0000000..bc225c5 --- /dev/null +++ b/command/Yelp_collaborative.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 1 --test_prompt seen:0 --lr 1e-3 --collaborative_token_size 500 --test_before_train 0 --test_epoch 0 --collaborative_float32 1 \ No newline at end of file diff --git a/command/Yelp_random.sh b/command/Yelp_random.sh new file mode 100644 index 0000000..a5bc238 --- /dev/null +++ b/command/Yelp_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 diff --git a/command/Yelp_sequential.sh b/command/Yelp_sequential.sh new file mode 100644 index 0000000..20cfd75 --- /dev/null +++ b/command/Yelp_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 diff --git a/prompt.txt b/prompt.txt index 7ef4503..0e131a8 100644 --- a/prompt.txt +++ b/prompt.txt @@ -19,4 +19,4 @@ straightforward; seen; What would be a helpful recommendation for {dataset} user straightforward; seen; Can you recommend an item for {dataset} user_{user_id} ?; {dataset} {target} straightforward; seen; Based on {dataset} user_{user_id} 's interests and requirements , what item would you suggest to try ?; {dataset} {target} straightforward; seen; For {dataset} user_{user_id} , what item stands out as a top recommendation that they should consider ?; {dataset} {target} -straightforward; unseen; What is the top recommendation for {dataset} user {user_id} ?; {dataset} {target} \ No newline at end of file +straightforward; unseen; What is the top recommendation for {dataset} user_{user_id} ?; {dataset} {target} \ No newline at end of file diff --git a/src/.ipynb_checkpoints/main-checkpoint.py b/src/.ipynb_checkpoints/main-checkpoint.py index 297cbb7..c270d7d 100644 --- a/src/.ipynb_checkpoints/main-checkpoint.py +++ b/src/.ipynb_checkpoints/main-checkpoint.py @@ -9,7 +9,7 @@ from data.MultiTaskDataset import MultiTaskDataset from runner.SingleRunner import SingleRunner from runner.DistributedRunner import DistributedRunner -from processor.Collator import Collator +from processor.Collator import Collator, TestCollator from processor.SingleMultiDataTaskSampler import SingleMultiDataTaskSampler from processor.DistMultiDataTaskSampler import DistMultiDataTaskSampler from torch.utils.data.distributed import DistributedSampler @@ -32,15 +32,21 @@ def get_dataset(args): for data in datasets: TrainDataset = MultiTaskDataset(args, data, 'train') train_all_datasets.append(TrainDataset) - ValidDataset = MultiTaskDataset(args, data, 'validation') - valid_all_datasets.append(ValidDataset) + if args.valid_select > 0: + ValidDataset = MultiTaskDataset(args, data, 'validation') + valid_all_datasets.append(ValidDataset) TrainSet = ConcatDataset(train_all_datasets) - ValidSet = ConcatDataset(valid_all_datasets) + if args.valid_select > 0: + ValidSet = ConcatDataset(valid_all_datasets) + else: + ValidSet = None return TrainSet, ValidSet def get_loader(args, tokenizer, TrainSet, ValidSet, rank=0): + + # generate training validation loader. ngpus_per_node = torch.cuda.device_count() if ngpus_per_node == 1: args.distributed = 0 @@ -48,15 +54,20 @@ def get_loader(args, tokenizer, TrainSet, ValidSet, rank=0): train_sampler = DistMultiDataTaskSampler(TrainSet, args.batch_size, args.world_size, rank, args.seed, shuffle=True) if args.distributed else SingleMultiDataTaskSampler(TrainSet, args.batch_size, args.seed, shuffle=True) else: train_sampler = DistributedSampler(TrainSet) if args.distributed else None - valid_sampler = DistributedSampler(ValidSet) if args.distributed else None + if args.valid_select > 0: + valid_sampler = DistributedSampler(ValidSet) if args.distributed else None collator = Collator(tokenizer) train_loader = DataLoader(dataset=TrainSet, sampler=train_sampler, batch_size=args.batch_size, collate_fn=collator, shuffle=False) - valid_loader = DataLoader(dataset=ValidSet, sampler=valid_sampler, batch_size=args.batch_size, collate_fn=collator, shuffle=False) + if args.valid_select > 0: + valid_loader = DataLoader(dataset=ValidSet, sampler=valid_sampler, batch_size=args.batch_size, collate_fn=collator, shuffle=False) + else: + valid_loader = None return train_loader, valid_loader def single_main(): + # running on single gpu. # init args parser = argparse.ArgumentParser(description='OpenP5') @@ -73,16 +84,17 @@ def single_main(): args.rank = 0 - # device = torch.device("cuda", int(args.gpu.split(',')[0])) - device = "cuda:0" + device = torch.device("cuda", int(args.gpu.split(',')[0])) + logging.info(vars(args)) tokenizer = AutoTokenizer.from_pretrained(args.backbone) - # init dataset + # init dataset and dataloader TrainSet, ValidSet = get_dataset(args) - train_loader, valid_loader = get_loader(args, tokenizer, TrainSet, TestSet) + + train_loader, valid_loader = get_loader(args, tokenizer, TrainSet, ValidSet) if 't5' in args.backbone: config = T5Config.from_pretrained(args.backbone) @@ -116,7 +128,6 @@ def single_main(): runner.test(args.model_path) -# pdb.set_trace() def distributed_launch(): parser = argparse.ArgumentParser(description='OpenP5') @@ -138,7 +149,7 @@ def distributed_launch(): def distributed_main(local_rank, args): - + # distributed learning args.rank = local_rank utils.set_seed(args.seed) os.environ['MASTER_ADDR'] = args.master_addr @@ -174,6 +185,8 @@ def distributed_main(local_rank, args): model.to(device) + + if args.item_indexing == 'collaborative': for ds in train_loader.dataset.datasets: tokenizer.add_tokens(ds.new_token) @@ -189,7 +202,7 @@ def distributed_main(local_rank, args): logging.info(f"Load model from {args.model_path}") model = utils.load_model(model, args.model_path, args, loc=device) model.to(device) - + runner = DistributedRunner(model, tokenizer, train_loader, valid_loader, device, args, local_rank) if args.train: diff --git a/src/data/.ipynb_checkpoints/MultiTaskDataset-checkpoint.py b/src/data/.ipynb_checkpoints/MultiTaskDataset-checkpoint.py index 3388c7c..45251f4 100644 --- a/src/data/.ipynb_checkpoints/MultiTaskDataset-checkpoint.py +++ b/src/data/.ipynb_checkpoints/MultiTaskDataset-checkpoint.py @@ -9,6 +9,7 @@ from utils import utils from utils import indexing from collections import defaultdict +import torch.distributed as dist import logging import re import pdb @@ -30,6 +31,8 @@ def parse_dataset_args(parser): parser.add_argument("--sequential_order", type=str, default='original', help='The rank of user history during ') parser.add_argument("--collaborative_token_size", type=int, default=200, help='the number of tokens used for indexing') parser.add_argument("--collaborative_cluster", type=int, default=20, help='the number of clusters in each level for collaborative indexing.') + parser.add_argument("--collaborative_last_token", type=str, default='sequential', help='how to assign the last token to items within the same clusters, random or sequential') + parser.add_argument("--collaborative_float32", type=int, default=0, help='1 for use float32 during indexing, 0 for float64.') # arguments related to sequential task parser.add_argument("--max_his", type=int, default=-1, help='the max number of items in history sequence, -1 means no limit') @@ -37,10 +40,6 @@ def parse_dataset_args(parser): parser.add_argument("--his_sep", type=str, default=' , ', help='The separator used for history') parser.add_argument("--skip_empty_his", type=int, default=1, help='whether include data with empty history.') - # arguments related to direct task - parser.add_argument("--candidate_neg_num", type=int, default=100, help='the number of negative candidate itmes in direct task.') - parser.add_argument("--candidate_sep", type=str, default=', ', help='The separator used for candidate items') - # arguments related for evaluation parser.add_argument("--valid_prompt", type=str, default='seen:0', help='The prompt used for evaluation, seen/unseen: id') parser.add_argument("--valid_prompt_sample", type=int, default=1, help='use sampled prompt for validation every epoch.') @@ -69,6 +68,8 @@ def __init__(self, args, dataset, mode): self.skip_empty_his = args.skip_empty_his self.collaborative_token_size = self.args.collaborative_token_size self.collaborative_cluster_num = self.args.collaborative_cluster + self.collaborative_last_token = self.args.collaborative_last_token + self.collaborative_float32 = self.args.collaborative_float32 if self.rank == 0: logging.info(f"Generating data for {self.dataset} dataset") @@ -87,33 +88,62 @@ def __init__(self, args, dataset, mode): if 'history' in self.info: self.max_his = args.max_his self.his_sep = args.his_sep - if 'candidate_items' in self.info: - self.candidate_neg_num = args.candidate_neg_num - self.candidate_sep = args.candidate_sep # load user sequence data self.user_sequence = utils.ReadLineFromFile(os.path.join(self.data_path, self.dataset, 'user_sequence.txt')) self.user_sequence_dict = indexing.construct_user_sequence_dict(self.user_sequence) - # apply indexing method - if self.item_indexing == 'sequential': - if self.rank == 0: + # apply indexing method and avoid generate data multiple times + if args.distributed: + if self.item_indexing == 'sequential': + if self.rank == 0: + logging.info("Reindex data with sequential indexing method") + indexing.sequential_indexing(self.data_path, self.dataset, self.user_sequence_dict, args.sequential_order) + dist.barrier() + else: + dist.barrier() + self.reindex_user_seq_dict, self.item_map = indexing.sequential_indexing(self.data_path, self.dataset, self.user_sequence_dict, args.sequential_order) + elif self.item_indexing == 'random': + if self.rank == 0: + logging.info("Reindex data with random indexing method") + indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) + dist.barrier() + else: + dist.barrier() + self.reindex_user_seq_dict, self.item_map = indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) + elif self.item_indexing == 'collaborative': + if self.rank == 0: + logging.info(f"Reindex data with collaborative indexing method with token_size {self.collaborative_token_size} and {self.collaborative_cluster_num} cluster") + indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, self.collaborative_token_size, \ + self.collaborative_cluster_num, self.collaborative_last_token, self.collaborative_float32) + dist.barrier() + else: + dist.barrier() + self.reindex_user_seq_dict, self.item_map = indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, \ + self.collaborative_token_size, self.collaborative_cluster_num, \ + self.collaborative_last_token, self.collaborative_float32) + self.new_token = [] + for idx in list(self.item_map.values()): + self.new_token += re.findall(r'\<.*?\>', idx) + else: + raise NotImplementedError + else: + if self.item_indexing == 'sequential': logging.info("Reindex data with sequential indexing method") - self.reindex_user_seq_dict, self.item_map = indexing.sequential_indexing(self.data_path, self.dataset, self.user_sequence_dict, args.sequential_order) - elif self.item_indexing == 'random': - if self.rank == 0: + self.reindex_user_seq_dict, self.item_map = indexing.sequential_indexing(self.data_path, self.dataset, self.user_sequence_dict, args.sequential_order) + elif self.item_indexing == 'random': logging.info("Reindex data with random indexing method") - self.reindex_user_seq_dict, self.item_map = indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) - elif self.item_indexing == 'collaborative': - if self.rank == 0: + self.reindex_user_seq_dict, self.item_map = indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) + elif self.item_indexing == 'collaborative': logging.info(f"Reindex data with collaborative indexing method with token_size {self.collaborative_token_size} and {self.collaborative_cluster_num} cluster") - self.reindex_user_seq_dict, self.item_map = indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, \ - self.collaborative_token_size, self.collaborative_cluster_num) - self.new_token = [] - for idx in list(self.item_map.values()): - self.new_token += re.findall(r'\<.*?\>', idx) - else: - raise NotImplementedError + self.reindex_user_seq_dict, self.item_map = indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, \ + self.collaborative_token_size, self.collaborative_cluster_num, \ + self.collaborative_last_token, self.collaborative_sparse, self.collaborative_float32) + self.new_token = [] + for idx in list(self.item_map.values()): + self.new_token += re.findall(r'\<.*?\>', idx) + else: + raise NotImplementedError self.all_items = list(self.item_map.values()) @@ -136,11 +166,6 @@ def __init__(self, args, dataset, mode): else: raise NotImplementedError - # sample candidate items - if 'candidate_items' in self.info: - if self.rank == 0: - logging.info(f"Generating candidates for {self.mode} in {self.dataset} dataset") - self.generate_candidates() # get prompt related info, including numbers and index self.get_prompt_info() @@ -258,54 +283,10 @@ def load_validation(self): data_samples.append(one_sample) return data_samples - def generate_candidates(self): - """ - Generate candidate items for each data sample, the candidate items include the target item and negative items - """ - - for i in range(len(self.data_samples)): - row = self.data_samples[i] - user = row['user_id'] - item = row['target'] - i = 0 - neg = [] - while i < self.candidate_neg_num: - n = random.randint(0, len(self.all_items) - 1) - if self.all_items[n] not in self.positive[user]: - neg.append(self.all_items[n]) - i += 1 - neg.append(item) - random.shuffle(neg) - row['candidate_items'] = self.candidate_sep.join(neg) - return def __len__(self): return len(self.data['input']) - # def identify_prompt(self, idx): - # for i in range(len(self.tasks)): - # if idx < self.task_index[i]: - # if i == 0: - # intask_id = idx - # else: - # intask_id = idx - self.task_index[i-1] - # task = self.tasks[i] - # task_id = i - # break - # if self.mode == 'train': - # data_id = intask_id // self.task_prompt_num[task_id] - # prompt_id = intask_id % self.task_prompt_num[task_id] - # prompt = self.prompt[task]['seen'][str(prompt_id)] - # if self.mode == 'validation': - # data_id = intask_id - # info = self.valid_prompt.split(':') - # prompt = self.prompt[task][info[0]][info[1]] - # if self.mode == 'test': - # data_id = intask_id - # info = self.test_prompt.split(':') - # prompt = self.prompt[task][info[0]][info[1]] - # return data_id, prompt - def construct_sentence(self): if self.mode == 'train': diff --git a/src/data/.ipynb_checkpoints/TestDataset-checkpoint.py b/src/data/.ipynb_checkpoints/TestDataset-checkpoint.py index 0246a21..28e01bf 100644 --- a/src/data/.ipynb_checkpoints/TestDataset-checkpoint.py +++ b/src/data/.ipynb_checkpoints/TestDataset-checkpoint.py @@ -24,6 +24,8 @@ def __init__(self, args, dataset, task): self.collaborative_token_size = args.collaborative_token_size self.collaborative_cluster_num = args.collaborative_cluster + self.collaborative_last_token = args.collaborative_last_token + self.collaborative_float32 = args.collaborative_float32 self.prompt = load_prompt_template(args.prompt_file, [self.task]) check_task_prompt(self.prompt, [self.task]) @@ -49,7 +51,8 @@ def __init__(self, args, dataset, task): self.reindex_user_seq_dict, self.item_map = indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) elif self.item_indexing == 'collaborative': self.reindex_user_seq_dict, self.item_map = indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, \ - self.collaborative_token_size, self.collaborative_cluster_num) + self.collaborative_token_size, self.collaborative_cluster_num, \ + self.collaborative_last_token, self.collaborative_float32) self.new_token = [] for idx in list(self.item_map.values()): self.new_token += re.findall(r'\<.*?\>', idx) @@ -57,19 +60,28 @@ def __init__(self, args, dataset, task): raise NotImplementedError self.all_items = list(self.item_map.values()) - - # get positive samples for each user to sample negative candidates or evaluation - self.positive = self.get_positive() + + self.test_prompt = args.test_prompt + self.test_filtered = args.test_filtered + + if args.test_filtered > 0: + self.user2id = dict() + self.id2user = dict() + for user in self.reindex_user_seq_dict: + if user not in self.user2id: + self.user2id[user] = len(self.user2id) + self.id2user[len(self.id2user)] = user + + # get positive samples for each user to sample negative candidates or evaluation + if args.test_filtered_batch > 0: + self.positive, self.max_positive = self.get_positive_batch() + self.positive = self.get_positive() # load data self.data_samples = self.load_test() - self.test_prompt = args.test_prompt - - # sample candidate items - if 'candidate_items' in self.info: - self.generate_candidates() - + + self.construct_sentence() # get prompt related info, including numbers and index # self.get_prompt_info() @@ -105,32 +117,37 @@ def get_positive(self): """ positive = dict() for user in self.reindex_user_seq_dict: - positive[user] = set(self.reindex_user_seq_dict[user]) + positive[user] = set(self.reindex_user_seq_dict[user][:-1]) + return positive - def __len__(self): - return len(self.data_samples) - - def generate_candidates(self): + def get_positive_batch(self): """ - Generate candidate items for each data sample, the candidate items include the target item and negative items + Get a dict of set to save the positive interactions for negative candidate sampling """ - - for i in range(len(self.data_samples)): - row = self.data_samples[i] - user = row['user_id'] - item = row['target'] - i = 0 - neg = [] - while i < self.candidate_neg_num: - n = random.randint(0, len(self.all_items) - 1) - if self.all_items[n] not in self.positive[user]: - neg.append(self.all_items[n]) - i += 1 - neg.append(item) - random.shuffle(neg) - row['candidate_items'] = self.candidate_sep.join(neg) - return + max_positive = 0 + positive = dict() + info = self.test_prompt.split(':') + prompt = self.prompt[self.task][info[0]][info[1]] + data_format = dict() + data_format['dataset'] = self.dataset + for user in self.reindex_user_seq_dict: + positive[user] = set() + positive_id = self.reindex_user_seq_dict[user][:-1] + + for item in positive_id: + if self.prefix > 0: + data_format['target'] = 'item_' + item + else: + data_format['target'] = item + positive[user].add(prompt['Output'].format(**data_format)) + + if len(positive[user]) > max_positive: + max_positive = len(positive[user]) + return positive, max_positive + + def __len__(self): + return len(self.data_samples) def construct_sentence(self): self.data = {} @@ -142,14 +159,22 @@ def construct_sentence(self): datapoint = self.data_samples[i] self.data['input'].append(prompt['Input'].format(**datapoint)) self.data['output'].append(prompt['Output'].format(**datapoint)) + + def __getitem__(self, idx): + if self.test_filtered > 0: + return self.get_item_filtered(idx) + else: + return self.get_item(idx) + def get_item_filtered(self, idx): + + + return {'user_idx': self.user2id[self.data_samples[idx]['user_id']], + 'input': self.data['input'][idx], + 'output': self.data['output'][idx]} - def __getitem__(self, idx): - # data_id, prompt = self.identify_prompt(idx) - # datapoint = self.data_samples[data_id] + def get_item(self, idx): - # return {'input': prompt['Input'].format(**datapoint), - # 'output': prompt['Output'].format(**datapoint)} return {'input': self.data['input'][idx], 'output': self.data['output'][idx]} diff --git a/src/data/MultiTaskDataset.py b/src/data/MultiTaskDataset.py index ac94330..45251f4 100644 --- a/src/data/MultiTaskDataset.py +++ b/src/data/MultiTaskDataset.py @@ -9,6 +9,7 @@ from utils import utils from utils import indexing from collections import defaultdict +import torch.distributed as dist import logging import re import pdb @@ -31,6 +32,7 @@ def parse_dataset_args(parser): parser.add_argument("--collaborative_token_size", type=int, default=200, help='the number of tokens used for indexing') parser.add_argument("--collaborative_cluster", type=int, default=20, help='the number of clusters in each level for collaborative indexing.') parser.add_argument("--collaborative_last_token", type=str, default='sequential', help='how to assign the last token to items within the same clusters, random or sequential') + parser.add_argument("--collaborative_float32", type=int, default=0, help='1 for use float32 during indexing, 0 for float64.') # arguments related to sequential task parser.add_argument("--max_his", type=int, default=-1, help='the max number of items in history sequence, -1 means no limit') @@ -38,10 +40,6 @@ def parse_dataset_args(parser): parser.add_argument("--his_sep", type=str, default=' , ', help='The separator used for history') parser.add_argument("--skip_empty_his", type=int, default=1, help='whether include data with empty history.') - # arguments related to direct task - parser.add_argument("--candidate_neg_num", type=int, default=100, help='the number of negative candidate itmes in direct task.') - parser.add_argument("--candidate_sep", type=str, default=', ', help='The separator used for candidate items') - # arguments related for evaluation parser.add_argument("--valid_prompt", type=str, default='seen:0', help='The prompt used for evaluation, seen/unseen: id') parser.add_argument("--valid_prompt_sample", type=int, default=1, help='use sampled prompt for validation every epoch.') @@ -71,6 +69,7 @@ def __init__(self, args, dataset, mode): self.collaborative_token_size = self.args.collaborative_token_size self.collaborative_cluster_num = self.args.collaborative_cluster self.collaborative_last_token = self.args.collaborative_last_token + self.collaborative_float32 = self.args.collaborative_float32 if self.rank == 0: logging.info(f"Generating data for {self.dataset} dataset") @@ -89,33 +88,62 @@ def __init__(self, args, dataset, mode): if 'history' in self.info: self.max_his = args.max_his self.his_sep = args.his_sep - if 'candidate_items' in self.info: - self.candidate_neg_num = args.candidate_neg_num - self.candidate_sep = args.candidate_sep # load user sequence data self.user_sequence = utils.ReadLineFromFile(os.path.join(self.data_path, self.dataset, 'user_sequence.txt')) self.user_sequence_dict = indexing.construct_user_sequence_dict(self.user_sequence) - # apply indexing method - if self.item_indexing == 'sequential': - if self.rank == 0: + # apply indexing method and avoid generate data multiple times + if args.distributed: + if self.item_indexing == 'sequential': + if self.rank == 0: + logging.info("Reindex data with sequential indexing method") + indexing.sequential_indexing(self.data_path, self.dataset, self.user_sequence_dict, args.sequential_order) + dist.barrier() + else: + dist.barrier() + self.reindex_user_seq_dict, self.item_map = indexing.sequential_indexing(self.data_path, self.dataset, self.user_sequence_dict, args.sequential_order) + elif self.item_indexing == 'random': + if self.rank == 0: + logging.info("Reindex data with random indexing method") + indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) + dist.barrier() + else: + dist.barrier() + self.reindex_user_seq_dict, self.item_map = indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) + elif self.item_indexing == 'collaborative': + if self.rank == 0: + logging.info(f"Reindex data with collaborative indexing method with token_size {self.collaborative_token_size} and {self.collaborative_cluster_num} cluster") + indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, self.collaborative_token_size, \ + self.collaborative_cluster_num, self.collaborative_last_token, self.collaborative_float32) + dist.barrier() + else: + dist.barrier() + self.reindex_user_seq_dict, self.item_map = indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, \ + self.collaborative_token_size, self.collaborative_cluster_num, \ + self.collaborative_last_token, self.collaborative_float32) + self.new_token = [] + for idx in list(self.item_map.values()): + self.new_token += re.findall(r'\<.*?\>', idx) + else: + raise NotImplementedError + else: + if self.item_indexing == 'sequential': logging.info("Reindex data with sequential indexing method") - self.reindex_user_seq_dict, self.item_map = indexing.sequential_indexing(self.data_path, self.dataset, self.user_sequence_dict, args.sequential_order) - elif self.item_indexing == 'random': - if self.rank == 0: + self.reindex_user_seq_dict, self.item_map = indexing.sequential_indexing(self.data_path, self.dataset, self.user_sequence_dict, args.sequential_order) + elif self.item_indexing == 'random': logging.info("Reindex data with random indexing method") - self.reindex_user_seq_dict, self.item_map = indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) - elif self.item_indexing == 'collaborative': - if self.rank == 0: + self.reindex_user_seq_dict, self.item_map = indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) + elif self.item_indexing == 'collaborative': logging.info(f"Reindex data with collaborative indexing method with token_size {self.collaborative_token_size} and {self.collaborative_cluster_num} cluster") - self.reindex_user_seq_dict, self.item_map = indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, \ - self.collaborative_token_size, self.collaborative_cluster_num, self.collaborative_last_token) - self.new_token = [] - for idx in list(self.item_map.values()): - self.new_token += re.findall(r'\<.*?\>', idx) - else: - raise NotImplementedError + self.reindex_user_seq_dict, self.item_map = indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, \ + self.collaborative_token_size, self.collaborative_cluster_num, \ + self.collaborative_last_token, self.collaborative_sparse, self.collaborative_float32) + self.new_token = [] + for idx in list(self.item_map.values()): + self.new_token += re.findall(r'\<.*?\>', idx) + else: + raise NotImplementedError self.all_items = list(self.item_map.values()) @@ -138,11 +166,6 @@ def __init__(self, args, dataset, mode): else: raise NotImplementedError - # sample candidate items - if 'candidate_items' in self.info: - if self.rank == 0: - logging.info(f"Generating candidates for {self.mode} in {self.dataset} dataset") - self.generate_candidates() # get prompt related info, including numbers and index self.get_prompt_info() @@ -260,54 +283,10 @@ def load_validation(self): data_samples.append(one_sample) return data_samples - def generate_candidates(self): - """ - Generate candidate items for each data sample, the candidate items include the target item and negative items - """ - - for i in range(len(self.data_samples)): - row = self.data_samples[i] - user = row['user_id'] - item = row['target'] - i = 0 - neg = [] - while i < self.candidate_neg_num: - n = random.randint(0, len(self.all_items) - 1) - if self.all_items[n] not in self.positive[user]: - neg.append(self.all_items[n]) - i += 1 - neg.append(item) - random.shuffle(neg) - row['candidate_items'] = self.candidate_sep.join(neg) - return def __len__(self): return len(self.data['input']) - # def identify_prompt(self, idx): - # for i in range(len(self.tasks)): - # if idx < self.task_index[i]: - # if i == 0: - # intask_id = idx - # else: - # intask_id = idx - self.task_index[i-1] - # task = self.tasks[i] - # task_id = i - # break - # if self.mode == 'train': - # data_id = intask_id // self.task_prompt_num[task_id] - # prompt_id = intask_id % self.task_prompt_num[task_id] - # prompt = self.prompt[task]['seen'][str(prompt_id)] - # if self.mode == 'validation': - # data_id = intask_id - # info = self.valid_prompt.split(':') - # prompt = self.prompt[task][info[0]][info[1]] - # if self.mode == 'test': - # data_id = intask_id - # info = self.test_prompt.split(':') - # prompt = self.prompt[task][info[0]][info[1]] - # return data_id, prompt - def construct_sentence(self): if self.mode == 'train': diff --git a/src/data/TestDataset.py b/src/data/TestDataset.py index 7661d5b..28e01bf 100644 --- a/src/data/TestDataset.py +++ b/src/data/TestDataset.py @@ -25,6 +25,7 @@ def __init__(self, args, dataset, task): self.collaborative_token_size = args.collaborative_token_size self.collaborative_cluster_num = args.collaborative_cluster self.collaborative_last_token = args.collaborative_last_token + self.collaborative_float32 = args.collaborative_float32 self.prompt = load_prompt_template(args.prompt_file, [self.task]) check_task_prompt(self.prompt, [self.task]) @@ -50,7 +51,8 @@ def __init__(self, args, dataset, task): self.reindex_user_seq_dict, self.item_map = indexing.random_indexing(self.data_path, self.dataset, self.user_sequence_dict) elif self.item_indexing == 'collaborative': self.reindex_user_seq_dict, self.item_map = indexing.collaborative_indexing(self.data_path, self.dataset, self.user_sequence_dict, \ - self.collaborative_token_size, self.collaborative_cluster_num, self.collaborative_last_token) + self.collaborative_token_size, self.collaborative_cluster_num, \ + self.collaborative_last_token, self.collaborative_float32) self.new_token = [] for idx in list(self.item_map.values()): self.new_token += re.findall(r'\<.*?\>', idx) @@ -58,19 +60,28 @@ def __init__(self, args, dataset, task): raise NotImplementedError self.all_items = list(self.item_map.values()) - - # get positive samples for each user to sample negative candidates or evaluation - self.positive = self.get_positive() + + self.test_prompt = args.test_prompt + self.test_filtered = args.test_filtered + + if args.test_filtered > 0: + self.user2id = dict() + self.id2user = dict() + for user in self.reindex_user_seq_dict: + if user not in self.user2id: + self.user2id[user] = len(self.user2id) + self.id2user[len(self.id2user)] = user + + # get positive samples for each user to sample negative candidates or evaluation + if args.test_filtered_batch > 0: + self.positive, self.max_positive = self.get_positive_batch() + self.positive = self.get_positive() # load data self.data_samples = self.load_test() - self.test_prompt = args.test_prompt - - # sample candidate items - if 'candidate_items' in self.info: - self.generate_candidates() - + + self.construct_sentence() # get prompt related info, including numbers and index # self.get_prompt_info() @@ -106,32 +117,37 @@ def get_positive(self): """ positive = dict() for user in self.reindex_user_seq_dict: - positive[user] = set(self.reindex_user_seq_dict[user]) + positive[user] = set(self.reindex_user_seq_dict[user][:-1]) + return positive - def __len__(self): - return len(self.data_samples) - - def generate_candidates(self): + def get_positive_batch(self): """ - Generate candidate items for each data sample, the candidate items include the target item and negative items + Get a dict of set to save the positive interactions for negative candidate sampling """ - - for i in range(len(self.data_samples)): - row = self.data_samples[i] - user = row['user_id'] - item = row['target'] - i = 0 - neg = [] - while i < self.candidate_neg_num: - n = random.randint(0, len(self.all_items) - 1) - if self.all_items[n] not in self.positive[user]: - neg.append(self.all_items[n]) - i += 1 - neg.append(item) - random.shuffle(neg) - row['candidate_items'] = self.candidate_sep.join(neg) - return + max_positive = 0 + positive = dict() + info = self.test_prompt.split(':') + prompt = self.prompt[self.task][info[0]][info[1]] + data_format = dict() + data_format['dataset'] = self.dataset + for user in self.reindex_user_seq_dict: + positive[user] = set() + positive_id = self.reindex_user_seq_dict[user][:-1] + + for item in positive_id: + if self.prefix > 0: + data_format['target'] = 'item_' + item + else: + data_format['target'] = item + positive[user].add(prompt['Output'].format(**data_format)) + + if len(positive[user]) > max_positive: + max_positive = len(positive[user]) + return positive, max_positive + + def __len__(self): + return len(self.data_samples) def construct_sentence(self): self.data = {} @@ -143,14 +159,22 @@ def construct_sentence(self): datapoint = self.data_samples[i] self.data['input'].append(prompt['Input'].format(**datapoint)) self.data['output'].append(prompt['Output'].format(**datapoint)) + + def __getitem__(self, idx): + if self.test_filtered > 0: + return self.get_item_filtered(idx) + else: + return self.get_item(idx) + def get_item_filtered(self, idx): + + + return {'user_idx': self.user2id[self.data_samples[idx]['user_id']], + 'input': self.data['input'][idx], + 'output': self.data['output'][idx]} - def __getitem__(self, idx): - # data_id, prompt = self.identify_prompt(idx) - # datapoint = self.data_samples[data_id] + def get_item(self, idx): - # return {'input': prompt['Input'].format(**datapoint), - # 'output': prompt['Output'].format(**datapoint)} return {'input': self.data['input'][idx], 'output': self.data['output'][idx]} diff --git a/src/data/__pycache__/MultiTaskDataset.cpython-39.pyc b/src/data/__pycache__/MultiTaskDataset.cpython-39.pyc index 5684f2e..e06b4ee 100644 Binary files a/src/data/__pycache__/MultiTaskDataset.cpython-39.pyc and b/src/data/__pycache__/MultiTaskDataset.cpython-39.pyc differ diff --git a/src/data/__pycache__/TestDataset.cpython-39.pyc b/src/data/__pycache__/TestDataset.cpython-39.pyc index 8eb9c81..6eabd34 100644 Binary files a/src/data/__pycache__/TestDataset.cpython-39.pyc and b/src/data/__pycache__/TestDataset.cpython-39.pyc differ diff --git a/src/draft.ipynb b/src/draft.ipynb new file mode 100644 index 0000000..b576650 --- /dev/null +++ b/src/draft.ipynb @@ -0,0 +1,2943 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 38, + "id": "c6ae3f02-1087-4bf5-af62-5befabd97bef", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4.27.3\n" + ] + } + ], + "source": [ + "import transformers\n", + "print(transformers.__version__)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "31a3e886-77d3-42b4-b5e0-f284d2a0782d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2}" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = set()\n", + "a.add(1)\n", + "a.add(2)\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "cdd61e04-4cd1-4995-bece-75e22cf120b7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['item_1', 'item_3', 'item_4']" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "candidate = [1,2,3,4,5]\n", + "positive = {2,5,7}\n", + "candi = set(candidate)-positive\n", + "can = [f'item_{cand}' for cand in candi]\n", + "can" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "c322eead-6f6f-4098-bd20-2ebcc911550a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 3, 4}" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set(candidate)-positive" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "50918e01-fa45-44e4-bac9-4bc70111eacd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.14.1\n" + ] + } + ], + "source": [ + "import torchvision\n", + "print(torchvision.__version__)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "03cc609b-38cc-4b1a-89b3-4534ae0e4d93", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 2, 3], [3, 4, 5]]" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {1:[1,2,3],2:[3,4,5]}\n", + "list(a.values())" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7a9c7701-da84-431c-981d-c91283294547", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'', '', '', ''}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import re\n", + "info = []\n", + "cand = ['', '']\n", + "for text in cand:\n", + " info += re.findall(r'\\<.*?\\>', text)\n", + "set(info)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "cf23d4b0-a9e8-49e6-9708-ce7ff3684a2d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import os\n", + "data_path = '../data/Yelp/user_sequence.txt'\n", + "os.path.exists(data_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "ebf78958-f4cc-4332-8831-297c72203b71", + "metadata": {}, + "outputs": [], + "source": [ + "lines = []\n", + "with open(data_path,'r') as fd:\n", + " for line in fd:\n", + " lines.append(line.rstrip('\\n'))" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "28417090-6b39-4e65-b24d-7afdb56bde1c", + "metadata": {}, + "outputs": [], + "source": [ + "user_seq_dict = dict()\n", + "for line in lines:\n", + " user_seq = line.split(\" \")\n", + " user_seq_dict[user_seq[0]] = user_seq[1:]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "a72ad7d2-e165-4ac6-93bf-9524422171cb", + "metadata": {}, + "outputs": [], + "source": [ + "all_items = set()\n", + "train_items = set()\n", + "for user in user_seq_dict:\n", + " all_items.update(set(user_seq_dict[user]))\n", + " train_items.update(set(user_seq_dict[user][:-2]))" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "363931b2-50c4-423c-ab16-5552ec6d58b6", + "metadata": {}, + "outputs": [], + "source": [ + "item_id = dict()\n", + "for line in lines:\n", + " idx = line.split(' ')[1]\n", + " if idx not in item_id:\n", + " item_id[idx] = 1\n", + " else:\n", + " print(line)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "19b9f579-09d8-4069-8da1-823356b3f6e5", + "metadata": {}, + "outputs": [], + "source": [ + "item2id = dict()\n", + "id2item = dict()\n", + "for item in train_items:\n", + " item2id[item] = len(item2id)\n", + " id2item[len(id2item)] = item" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "4e1dff0a-839d-46c6-9a9f-5fd623d63bb8", + "metadata": {}, + "outputs": [], + "source": [ + "pair_count = dict()\n", + "for user in user_seq_dict:\n", + " interactions = user_seq_dict[user][:-2]\n", + " for pairs in combinations(interactions, 2):\n", + " if (item2id[pairs[0]],item2id[pairs[1]]) not in pair_count:\n", + " pair_count[(item2id[pairs[0]],item2id[pairs[1]])] = 0\n", + " pair_count[(item2id[pairs[1]],item2id[pairs[0]])] = 0\n", + " pair_count[(item2id[pairs[0]],item2id[pairs[1]])] += 1\n", + " pair_count[(item2id[pairs[1]],item2id[pairs[0]])] += 1\n", + "row = []\n", + "col = []\n", + "data = []\n", + "for (x,y) in pair_count:\n", + " row.append(x)\n", + " col.append(y)\n", + " data.append(pair_count[(x,y)])\n", + "adj_matrix = csr_matrix((data, (row, col)), shape = (len(item2id), len(item2id)), dtype=np.float32)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "933b1c1c-653a-4c8c-9697-9ed07da957fc", + "metadata": {}, + "outputs": [], + "source": [ + "clustering = SpectralClustering(\n", + " n_clusters=20,\n", + " assign_labels=\"cluster_qr\",\n", + " random_state=0,\n", + " affinity=\"precomputed\",\n", + ").fit(adj_matrix)\n", + "labels = clustering.labels_.tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "85e82e7a-74a1-406c-ada0-bdefe4e2ffd6", + "metadata": {}, + "outputs": [], + "source": [ + "all_data = [line.split(' ')[1:] for line in lines]\n", + "train_data = [line[0:-2] for line in all_data]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "4f9b4023-4bfe-4f29-ae4f-ab4a5dabefa5", + "metadata": {}, + "outputs": [], + "source": [ + "all_items = set()\n", + "train_items = set()\n", + "for i in range(len(all_data)):\n", + " all_items.update(set(all_data[i]))\n", + " train_items.update(set(train_data[i]))" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "e49c017d-83bb-4730-83c5-fbe7d77d9a5b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['B00AA8DRHA',\n", + " 'B00FAVBKX0',\n", + " 'B005JDPJ3G',\n", + " 'B00JTUOVAM',\n", + " 'B00I6RD7DQ',\n", + " 'B00KVE7R0Q',\n", + " 'B008A76RKW',\n", + " 'B0055FF2XU',\n", + " 'B00GTXB51K',\n", + " 'B001SFRS2O',\n", + " 'B00G9MV6TM',\n", + " 'B00HLV4EB2',\n", + " 'B00EZMBD9Q',\n", + " 'B00F029PWC',\n", + " 'B00BVSA1AY',\n", + " 'B00H997F6M',\n", + " 'B005MXAFH8',\n", + " 'B008KNK7UW',\n", + " 'B00IKKORVU',\n", + " 'B00I1ISDZM',\n", + " 'B00L6Q3BH6',\n", + " 'B00HERKPXY',\n", + " 'B00B8P5CTA',\n", + " 'B00I33UL3W',\n", + " 'B0038IA8XA',\n", + " 'B00CIZ0DNO',\n", + " 'B00B0JPSRK',\n", + " 'B00AHKC7PO',\n", + " 'B00DQ47V3G',\n", + " 'B00GRTQBTM',\n", + " 'B00B2G03K8',\n", + " 'B00FFWQFCK',\n", + " 'B00BB17Y1K']" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(all_items - train_items)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "74c473d5-8b79-4552-82cf-0d8cb73b6258", + "metadata": {}, + "outputs": [], + "source": [ + "item_map = dict()\n", + "item_map_rev = dict()\n", + "for item in train_items:\n", + " item_map[item] = len(item_map)\n", + " item_map_rev[len(item_map_rev)] = item" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "edc1beb0-b750-4a69-a82a-efb166c56502", + "metadata": {}, + "outputs": [], + "source": [ + "from scipy.sparse import csr_matrix\n", + "from itertools import combinations\n", + "from sklearn.cluster import SpectralClustering\n", + "import numpy as np\n", + "pair_count = dict()\n", + "for interactions in train_data:\n", + " for pairs in combinations(interactions, 2):\n", + " if (item_map[pairs[0]],item_map[pairs[1]]) not in pair_count:\n", + " pair_count[(item_map[pairs[0]],item_map[pairs[1]])] = 0\n", + " pair_count[(item_map[pairs[1]],item_map[pairs[0]])] = 0\n", + " pair_count[(item_map[pairs[0]],item_map[pairs[1]])] += 1\n", + " pair_count[(item_map[pairs[1]],item_map[pairs[0]])] += 1\n", + "row = []\n", + "col = []\n", + "data = []\n", + "for (x,y) in pair_count:\n", + " row.append(x)\n", + " col.append(y)\n", + " data.append(pair_count[(x,y)])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "8333d4eb-15f0-4316-8774-4872b0ee2e03", + "metadata": {}, + "outputs": [], + "source": [ + "adj_matrix = csr_matrix((data, (row, col)), shape = (len(item_map), len(item_map)), dtype=np.float32)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "5616b777-fb91-4bda-b3b7-9098cccc8221", + "metadata": {}, + "outputs": [], + "source": [ + "clustering = SpectralClustering(\n", + " n_clusters=20,\n", + " assign_labels=\"cluster_qr\",\n", + " random_state=0,\n", + " affinity=\"precomputed\",\n", + ").fit(adj_matrix)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "57210cb7-e2c0-4272-99d0-f05db06a606c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1.2.0'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import sklearn\n", + "sklearn.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "fd83c40f-d05b-4d1c-9e36-1870caefc88a", + "metadata": {}, + "outputs": [], + "source": [ + "from itertools import combinations\n", + "from sklearn.cluster import SpectralClustering\n", + "import numpy as np\n", + "adj_matrix = np.zeros((len(item_map), len(item_map)))\n", + "for interactions in train_data:\n", + " for pairs in combinations(interactions, 2):\n", + " adj_matrix[item_map[pairs[0]]][item_map[pairs[1]]] += 1\n", + " adj_matrix[item_map[pairs[1]]][item_map[pairs[0]]] += 1" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "c88f3316-675c-47de-861d-4128855f0657", + "metadata": {}, + "outputs": [], + "source": [ + "clustering = SpectralClustering(\n", + " n_clusters=20,\n", + " assign_labels=\"cluster_qr\",\n", + " random_state=0,\n", + " affinity=\"precomputed\",\n", + ").fit(adj_matrix)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "ea6194ba-2c26-4156-aabc-a19eb055c083", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "18" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "labels = clustering.labels_.tolist()\n", + "labels[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "004b11e9-a67e-4d50-ac2a-b7133916f3fa", + "metadata": {}, + "outputs": [], + "source": [ + "from collections import defaultdict\n", + "grouping = defaultdict(list)\n", + "for i in range(len(labels)):\n", + " grouping[labels[i]].append((item_map_rev[i],i))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "027d3ff6-6230-4b73-8be7-23c292c7d27e", + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "def add_token_to_indexing(item_indexing, grouping, index_now, token_size):\n", + " for group in grouping:\n", + " index_now = index_now % token_size\n", + " for (item, idx) in group:\n", + " if item not in item_indexing:\n", + " item_indexing[item] = ''\n", + " item_indexing[item] += f''\n", + " index_now += 1\n", + " return item_indexing, index_now\n", + "\n", + "def add_last_token_to_indexing(item_indexing, item_list, token_size):\n", + " last_tokens = random.sample([i for i in range(token_size)], len(item_list))\n", + " for i in range(len(item_list)):\n", + " item = item_list[i]\n", + " if item not in item_indexing:\n", + " item_indexing[item] = ''\n", + " item_indexing[item] += f''\n", + " return item_indexing" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2778838c-3ddd-41ce-a1a6-5a0144d156a9", + "metadata": {}, + "outputs": [], + "source": [ + "def generate_collaborative_id(user_sequence_dict, token_size, cluster_num):\n", + " \"\"\"\n", + " Generate collaborative index for items.\n", + " \"\"\"\n", + " # get the items in training data and all data.\n", + " all_items = set()\n", + " train_items = set()\n", + " for user in user_sequence_dict:\n", + " all_items.update(set(user_sequence_dict[user]))\n", + " train_items.update(set(user_sequence_dict[user][:-2]))\n", + " \n", + " # reindex all training items for calculating the adjacency matrix\n", + " item2id = dict()\n", + " id2item = dict()\n", + " for item in train_items:\n", + " item2id[item] = len(item2id)\n", + " id2item[len(id2item)] = item\n", + " \n", + " # calculate the co-occurrence of items in the training data as an adjacency matrix\n", + " adj_matrix = np.zeros((len(item_map), len(item_map)))\n", + " for user in user_sequence_dict:\n", + " interactions = user_sequence_dict[user][:-2]\n", + " for pairs in combinations(interactions, 2):\n", + " adj_matrix[item2id[pairs[0]]][item2id[pairs[1]]] += 1\n", + " adj_matrix[item2id[pairs[1]]][item2id[pairs[0]]] += 1\n", + " \n", + " # get the clustering results for the first layer\n", + " clustering = SpectralClustering(\n", + " n_clusters=cluster_num,\n", + " assign_labels=\"cluster_qr\",\n", + " random_state=0,\n", + " affinity=\"precomputed\",\n", + " ).fit(adj_matrix)\n", + " labels = clustering.labels_.tolist()\n", + " \n", + " # count the clustering results\n", + " grouping = defaultdict(list)\n", + " for i in range(len(labels)):\n", + " grouping[labels[i]].append((id2item[i],i))\n", + " \n", + " item_map = dict()\n", + " index_now = 0\n", + " \n", + " # add current clustering information into the item indexing results.\n", + " item_map, index_now = add_token_to_indexing(item_map, grouping, index_now, token_size)\n", + " \n", + " # add current clustering info into a queue for BFS\n", + " queue = []\n", + " for group in grouping:\n", + " queue.append(grouping[group])\n", + " \n", + " # apply BFS to further use spectral clustering for large groups (> token_size)\n", + " while queue:\n", + " group_items = queue.pop(0)\n", + " \n", + " # if current group is small enough, add the last token to item indexing\n", + " if len(group_items) <= token_size:\n", + " item_list = [items[0] for items in group_items]\n", + " item_map = add_last_token_to_indexing(item_map, item_list, token_size)\n", + " else:\n", + " # calculate the adjacency matrix for current group\n", + " sub_adj_matrix = np.zeros((len(group_items), len(group_items)))\n", + " for i in range(len(group_items)):\n", + " for j in range(i+1, len(group_items)):\n", + " sub_adj_matrix[i][j] = adj_matrix[group_items[i][1]][group_items[j][1]]\n", + " \n", + " # get the clustering results for current group \n", + " clustering = SpectralClustering(\n", + " n_clusters=cluster_num,\n", + " assign_labels=\"cluster_qr\",\n", + " random_state=0,\n", + " affinity=\"precomputed\",\n", + " ).fit(sub_adj_matrix)\n", + " labels = clustering.labels_.tolist()\n", + " \n", + " # count current clustering results\n", + " grouping = defaultdict(list)\n", + " for i in range(len(labels)):\n", + " grouping[labels[i]].append(group_items[i])\n", + " \n", + " # add current clustering information into the item indexing results.\n", + " item_map, index_now = add_token_to_indexing(item_map, grouping, index_now, token_size)\n", + " \n", + " # push current clustering info into the queue\n", + " for group in grouping:\n", + " queue.append(grouping[group])\n", + " \n", + " return item_map" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "27efb999-27e3-418f-a9dd-fe66e1d39b2e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1,2)\n", + "(1,3)\n", + "(1,4)\n", + "(2,3)\n", + "(2,4)\n", + "(3,4)\n" + ] + } + ], + "source": [ + "a = [1,2,3,4]\n", + "for i in range(len(a)):\n", + " for j in range(i+1,len(a)):\n", + " print(f'({a[i]},{a[j]})')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f284f2da-5b82-49dc-9a83-7ed20b11f27c", + "metadata": {}, + "outputs": [], + "source": [ + "for " + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "c3cf5740-bb3e-43fe-9852-93ff988dac94", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "''" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "index_now = 1\n", + "f''" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "6f2eee69-e524-40e8-a3da-a44cf4b63660", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5]" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "queue = list()\n", + "queue.append([1,2,3,4,5])\n", + "queue.append([0,3,4,2])\n", + "queue.append([9,4,5,1,2])\n", + "queue.pop(0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb578cd2-eff0-4173-8087-b2da27ce3c43", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "16f345f1-812a-4504-8e87-cb6b3b0b5562", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'B004756YJA'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[pairs for pairs in combinations(train_data[0],2)][0][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "43a5ea3c-4dd6-49fb-a6d3-87778370fe1e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['B004756YJA', 'B004ZT0SSG', 'B0020YLEYK']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "train_data[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "5f8e213b-377d-437b-80d0-001626e57769", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "unhashable type: 'list'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[13], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;43mset\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m4\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'list'" + ] + } + ], + "source": [ + "set([[0,1,2],[2,4]])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4706a6f7-09d7-4ab4-be0c-0da052999e9e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a0723adb-a310-4766-b232-bc1cbdd0eadb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4b0fb6fc-7445-4e6e-87cf-a7aaa042a925", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b3b6f69c-1a57-4f7d-9b77-0619bead8cb8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69c6a806-1298-4c68-89e3-9393b7cb44e3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "b69a4395-7cc3-441d-acb3-16ea6915f99f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "generate_num = max([int(me.split('@')[1]) for me in metrics])\n", + "generate_num" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "44d93339-354d-49d1-89b7-4379c4aedb79", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0.2376494451866188,\n", + " 0.2662636264172097,\n", + " 0.6300008642048527,\n", + " 0.8496540608171874]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import random\n", + "a = [random.random() for i in range(4)]\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "bb1119e4-ba77-4782-8c21-9c2356e3d5f0", + "metadata": {}, + "outputs": [], + "source": [ + "from sklearn.metrics import ndcg_score, recall_score, precision_score" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "ac1f3d2f-bcd4-4bc3-bb6a-89d1c2712d89", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.48711477971984807" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "gt = np.array([[1.0,0.0,0.0,0.0,0.0]])\n", + "pred = np.array([[0.0,1.0,0.0,0.0,0.0]])\n", + "# pred = np.array([[0.0,0.7,0.3,0.2,0.1]])\n", + "ndcg_score(gt, pred)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "6db82b05-7782-47a7-9bb8-2e416878cc04", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6309297535714574" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import math\n", + "1 / math.log(3,2)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "53764805-37e8-40a3-9865-4d149a160e99", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = 'hit@10'\n", + "a.lower().startswith('hit')" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "b4d93959-b0b2-4fa4-bab7-9d071ca8e1ea", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([3, 5, 7])" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = np.array([2,3,4]) + np.array([1,2,3])\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "8fc7586c-b46f-4595-a0b4-073b7635fb81", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = [1,2,3,4,5,6,7,8,9,10]\n", + "sum(a[:5])" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "f0749b7e-1b90-4a53-a6c9-760f4f8a9d91", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[2, 0, 1],\n", + " [0, 2, 1]])" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = np.array([[3, 4, 2], [1, 3, 1]])\n", + "index_array = np.argpartition(x, -2)\n", + "index_array" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "00567024-ae15-4cec-8107-46cbde83748e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['sequential', 'direct', 'straightforward']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = 'sequential,direct,straightforward'\n", + "a = a.split(',')\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "75757b6b-9573-4e4c-a891-c7b27843dd12", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is the 10\n" + ] + } + ], + "source": [ + "template = 'This is the {value}'\n", + "context = {'value': 10}\n", + "print(template.format(**context))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "da84a97e-ce55-4d62-a9fb-c02b25deb673", + "metadata": {}, + "outputs": [], + "source": [ + "def ReadLineFromFile(path):\n", + " lines = []\n", + " with open(path,'r') as fd:\n", + " for line in fd:\n", + " lines.append(line.rstrip('\\n'))\n", + " return lines" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "180dc3b4-5d47-4ae3-8579-f5c68e1f6ed7", + "metadata": {}, + "outputs": [], + "source": [ + "file_path = './prompt_template.txt'\n", + "data = ReadLineFromFile(file_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "6974fddf-1e95-4172-92fc-acb41072b374", + "metadata": {}, + "outputs": [], + "source": [ + "prompt_template = dict()\n", + "for prompt in data:\n", + " t = [sens.strip() for sens in prompt.split(';')]\n", + " if t[0] not in prompt_template:\n", + " prompt_template[t[0]] = dict()\n", + " if t[1] not in prompt_template[t[0]]:\n", + " prompt_template[t[0]][t[1]] = dict()\n", + " num = len(prompt_template[t[0]][t[1]])\n", + " prompt_template[t[0]][t[1]][str(num)] = dict()\n", + " prompt_template[t[0]][t[1]][str(num)]['Input'] = t[2]\n", + " prompt_template[t[0]][t[1]][str(num)]['Output'] = t[3] " + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "ab2e1b82-b66a-46e4-afb8-8a70de111a90", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'sequential': {'seen': {'0': {'Input': 'Considering {dataset} user {user_id} has interacted with {dataset} items {history}. What is the next recommendation for the user?',\n", + " 'Output': '{dataset} item {target}'},\n", + " '1': {'Input': 'Here is the purchase history of {dataset} user {user_id}: {dataset} item {history}. I wonder what is the next recommended item for the user.',\n", + " 'Output': '{dataset} item {target}'}},\n", + " 'unseen': {'0': {'Input': 'What is the top recommended item for {dataset} user {user_id} who interacted with {dataset} item {history}?',\n", + " 'Output': '{dataset} item {target}'}}},\n", + " 'straightforward': {'seen': {'0': {'Input': 'What should we recommend for {dataset} user {user_id}?',\n", + " 'Output': '{dataset} item {target}'},\n", + " '1': {'Input': '{dataset} user {user_id} is looking for some items. Do you have any recommendations?',\n", + " 'Output': '{dataset} item {target}'}},\n", + " 'unseen': {'0': {'Input': 'What is the top recommendation for {dataset} user {user_id}?',\n", + " 'Output': '{dataset} item {target}'}}}}" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prompt_template" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "5e4a87c2-882d-4084-b915-4150102ac9e5", + "metadata": {}, + "outputs": [], + "source": [ + "datapoint = {'dataset':'amazon', 'user_id': 11, 'history':'2,3,4,5', 'target': 23}" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "dd698da1-3125-4561-954b-3763b31a5dbf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Considering amazon user 11 has interacted with amazon items 2,3,4,5. What is the next recommendation for the user?'" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prompt_template['sequential']['seen']['0']['Input'].format(**datapoint)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "14663bc3-036c-45d1-9915-4e3d5ff12155", + "metadata": {}, + "outputs": [ + { + "ename": "AssertionError", + "evalue": "No prompt for review task", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[1], line 5\u001b[0m\n\u001b[1;32m 3\u001b[0m prompt_template \u001b[38;5;241m=\u001b[39m load_prompt_template(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m../prompt_template.txt\u001b[39m\u001b[38;5;124m'\u001b[39m,task_list)\n\u001b[1;32m 4\u001b[0m prompt_info \u001b[38;5;241m=\u001b[39m get_info_from_prompt(prompt_template)\n\u001b[0;32m----> 5\u001b[0m \u001b[43mcheck_task_prompt\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_template\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtask_list\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Projects/SP5/src/utils/prompt.py:60\u001b[0m, in \u001b[0;36mcheck_task_prompt\u001b[0;34m(prompt_templates, task_list)\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 54\u001b[0m \u001b[38;5;124;03mCheck if all tasks have prompt templates. Raise Error if training tasks have no prompt.\u001b[39;00m\n\u001b[1;32m 55\u001b[0m \u001b[38;5;124;03mInput:\u001b[39;00m\n\u001b[1;32m 56\u001b[0m \u001b[38;5;124;03m- prompt_templates: A dictionary of prompt templates.\u001b[39;00m\n\u001b[1;32m 57\u001b[0m \u001b[38;5;124;03m- task_list: A list of training tasks.\u001b[39;00m\n\u001b[1;32m 58\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 59\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m task \u001b[38;5;129;01min\u001b[39;00m task_list:\n\u001b[0;32m---> 60\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m task \u001b[38;5;129;01min\u001b[39;00m prompt_templates, \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNo prompt for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mtask\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m task\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", + "\u001b[0;31mAssertionError\u001b[0m: No prompt for review task" + ] + } + ], + "source": [ + "from utils.prompt import load_prompt_template, get_info_from_prompt, check_task_prompt\n", + "task_list = ['sequential', 'straightforward', 'direct', 'review']\n", + "prompt_template = load_prompt_template('../prompt_template.txt',task_list)\n", + "prompt_info = get_info_from_prompt(prompt_template)\n", + "check_task_prompt(prompt_template, task_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "fb153e99-70ee-4355-bf0e-07cc54a8585b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'sequential': {'seen': {'0': {'Input': 'Considering {dataset} user {user_id} has interacted with {dataset} items {history}. What is the next recommendation for the user?',\n", + " 'Output': '{dataset} item {target}'},\n", + " '1': {'Input': 'Here is the purchase history of {dataset} user {user_id}: {dataset} item {history}. I wonder what is the next recommended item for the user.',\n", + " 'Output': '{dataset} item {target}'}},\n", + " 'unseen': {'0': {'Input': 'What is the top recommended item for {dataset} user {user_id} who interacted with {dataset} item {history}?',\n", + " 'Output': '{dataset} item {target}'}}},\n", + " 'direct': {'seen': {'0': {'Input': 'Choose the best item from the candidates to recommend for {dataset} user {user_id}: {dataset} items {candidate_items}',\n", + " 'Output': '{dataset} item {target}'},\n", + " '1': {'Input': 'Pick the most suitable item from the following list and recommend to {dataset} user {user_id}: {dataset} items {candidate_items}',\n", + " 'Output': '{dataset} item {target}'}},\n", + " 'unseen': {'0': {'Input': 'We want to make recommendation for {dataset} user {user_id}. Select the best item from these candidates: {dataset} items {candidate_items}',\n", + " 'Output': '{dataset} item {target}'}}},\n", + " 'straightforward': {'seen': {'0': {'Input': 'What should we recommend for {dataset} user {user_id}?',\n", + " 'Output': '{dataset} item {target}'},\n", + " '1': {'Input': '{dataset} user {user_id} is looking for some items. Do you have any recommendations?',\n", + " 'Output': '{dataset} item {target}'}},\n", + " 'unseen': {'0': {'Input': 'What is the top recommendation for {dataset} user {user_id}?',\n", + " 'Output': '{dataset} item {target}'}}}}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prompt_template" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3848a5d5-8bd7-4360-a753-762c19dd7f55", + "metadata": {}, + "outputs": [], + "source": [ + "inp = prompt_template['sequential']['seen']['0']['Input']" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "c38c5328-98f0-432b-8de6-f80e47c07b00", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['{dataset}', '{user_id}', '{dataset}', '{history}']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import re\n", + "re.findall(r'\\{.*?\\}', inp)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "dbae0b3c-4b13-4911-ad66-8dcc5bc0776c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['user_id', 'history', 'target', 'dataset', 'candidate_items']" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "info = []\n", + "for task in prompt_template:\n", + " for see in prompt_template[task]:\n", + " for i in prompt_template[task][see]:\n", + " info += re.findall(r'\\{.*?\\}', prompt_template[task][see][i]['Input'])\n", + " info += re.findall(r'\\{.*?\\}', prompt_template[task][see][i]['Output'])\n", + "info = [i[1:-1] for i in set(info)]\n", + "info" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "25aa7ef8-0ad1-4f4f-99df-0eda1810e948", + "metadata": {}, + "outputs": [], + "source": [ + "from torch.utils.data import Dataset, DataLoader\n", + "class MyFirstDataset(Dataset):\n", + " def __init__(self):\n", + " # dummy dataset\n", + " self.samples = [i+1 for i in range(30)]\n", + "\n", + " def __getitem__(self, index):\n", + " # change this to your samples fetching logic\n", + " return self.samples[index]\n", + "\n", + " def __len__(self):\n", + " # change this to return number of samples in your dataset\n", + " return len(self.samples)\n", + " \n", + "class MySecondDataset(Dataset):\n", + " def __init__(self):\n", + " # dummy dataset\n", + " self.samples = [i+1 for i in range(30,90)]\n", + "\n", + " def __getitem__(self, index):\n", + " # change this to your samples fetching logic\n", + " return self.samples[index]\n", + "\n", + " def __len__(self):\n", + " # change this to return number of samples in your dataset\n", + " return len(self.samples)\n", + " \n", + "fd = MyFirstDataset()\n", + "sd = MySecondDataset()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "2209bf24-c47f-4f6c-917e-8879dcda32ce", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n", + "10\n", + "11\n", + "12\n", + "13\n", + "14\n", + "15\n", + "16\n", + "17\n", + "18\n", + "19\n", + "20\n", + "21\n", + "22\n", + "23\n", + "24\n", + "25\n", + "26\n", + "27\n", + "28\n", + "29\n", + "30\n", + "31\n", + "32\n", + "33\n", + "34\n", + "35\n", + "36\n", + "37\n", + "38\n", + "39\n", + "40\n", + "41\n", + "42\n", + "43\n", + "44\n", + "45\n", + "46\n", + "47\n", + "48\n", + "49\n", + "50\n", + "51\n", + "52\n", + "53\n", + "54\n", + "55\n", + "56\n", + "57\n", + "58\n", + "59\n", + "60\n", + "61\n", + "62\n", + "63\n", + "64\n", + "65\n", + "66\n", + "67\n", + "68\n", + "69\n", + "70\n", + "71\n", + "72\n", + "73\n", + "74\n", + "75\n", + "76\n", + "77\n", + "78\n", + "79\n", + "80\n", + "81\n", + "82\n", + "83\n", + "84\n", + "85\n", + "86\n", + "87\n", + "88\n", + "89\n", + "90\n" + ] + } + ], + "source": [ + "from torch.utils.data.dataset import ConcatDataset\n", + "cd = ConcatDataset([fd, sd])\n", + "for i in range(len(cd)):\n", + " print(cd[i])" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "6c1aac4c-2f6a-4aab-adfa-a83e49703cc3", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/common/home/sx86/anaconda3/envs/SP5/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n" + ] + } + ], + "source": [ + "import torch\n", + "print(torch.cuda.device_count())" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "eb7fa571-31ea-40b9-a95d-ea78ead1118d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[4, 11, 10, 9, 6, 1, 7, 8, 3, 5, 2]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import random\n", + "a = dict()\n", + "a['1'] = [1,2,3,4,5]\n", + "a['2'] = [6,7,8]\n", + "a['3'] = [1,2,3,9,10,11]\n", + "items = set()\n", + "for i in a:\n", + " items.update(a[i])\n", + "items = list(items)\n", + "random.shuffle(items)\n", + "items" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "8e6ec461-e394-449f-b9fb-a01867905f8a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_items([('1', [1, 2, 3, 4, 5]), ('2', [6, 7, 8]), ('3', [1, 2, 3, 9, 10, 11])])" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.items()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "31aaaee1-e144-4103-89e3-9627ed65e3fe", + "metadata": {}, + "outputs": [], + "source": [ + "user_list = sorted(a, key=lambda x: len(a[x]), reverse=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "0a0e7dcc-a74e-4891-8ed4-95014604e4f8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6, 7, 8]\n", + "[1, 2, 3, 4, 5]\n", + "[1, 2, 3, 9, 10, 11]\n" + ] + } + ], + "source": [ + "for u in user_list:\n", + " print(a[u])" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "id": "fd90c844-1583-4f67-aa42-71c886bcb3d3", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "list indices must be integers or slices, not list", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[72], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m a \u001b[38;5;241m=\u001b[39m [i \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m10\u001b[39m,\u001b[38;5;241m20\u001b[39m)]\n\u001b[1;32m 5\u001b[0m indices \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mrandperm(\u001b[38;5;28mlen\u001b[39m(a), generator\u001b[38;5;241m=\u001b[39mg)\u001b[38;5;241m.\u001b[39mtolist()\n\u001b[0;32m----> 6\u001b[0m \u001b[43ma\u001b[49m\u001b[43m[\u001b[49m\u001b[43m[\u001b[49m\u001b[43mindices\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\n", + "\u001b[0;31mTypeError\u001b[0m: list indices must be integers or slices, not list" + ] + } + ], + "source": [ + "import torch\n", + "g = torch.Generator()\n", + "g.manual_seed(2018)\n", + "a = [i for i in range(10,20)]\n", + "indices = torch.randperm(len(a), generator=g).tolist()\n", + "a[[indices]]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "053e5dfe-76c4-4c3c-b422-c92d6a00e08f", + "metadata": {}, + "outputs": [], + "source": [ + "from torch.utils.data import Dataset, DataLoader\n", + "class MyFirstDataset(Dataset):\n", + " def __init__(self):\n", + " # dummy dataset\n", + " self.samples = [i for i in range(30)]\n", + " self.task_data = dict()\n", + " self.task_data['1'] = [i for i in range(10)]\n", + " self.task_data['2'] = [i for i in range(10,20)]\n", + " self.task_data['3'] = [i for i in range(20,30)]\n", + "\n", + " def __getitem__(self, index):\n", + " # change this to your samples fetching logic\n", + " return self.samples[index]\n", + "\n", + " def __len__(self):\n", + " # change this to return number of samples in your dataset\n", + " return len(self.samples)\n", + " \n", + " def shuffle(self, seed):\n", + " g = torch.Generator()\n", + " g.manual_seed(seed)\n", + " for task in self.task_data:\n", + " indices = torch.randperm(len(self.task_data[task]), generator=g).tolist()\n", + " self.task_data[task] = [self.task_data[task][i] for i in indices]\n", + " \n", + "class MySecondDataset(Dataset):\n", + " def __init__(self):\n", + " # dummy dataset\n", + " self.samples = [i for i in range(30,90)]\n", + " self.task_data = dict()\n", + " self.task_data['1'] = [i for i in range(20)]\n", + " self.task_data['2'] = [i for i in range(20,40)]\n", + " self.task_data['3'] = [i for i in range(40,60)]\n", + "\n", + " def __getitem__(self, index):\n", + " # change this to your samples fetching logic\n", + " return self.samples[index]\n", + "\n", + " def __len__(self):\n", + " # change this to return number of samples in your dataset\n", + " return len(self.samples)\n", + " \n", + " def shuffle(self, seed):\n", + " g = torch.Generator()\n", + " g.manual_seed(seed)\n", + " \n", + " for task in self.task_data:\n", + " indices = torch.randperm(len(self.task_data[task]), generator=g).tolist()\n", + " self.task_data[task] = [self.task_data[task][i] for i in indices]" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "e4612df1-7c9a-4083-bda5-04596a436135", + "metadata": {}, + "outputs": [], + "source": [ + "from torch.utils.data.sampler import Sampler, RandomSampler, SequentialSampler\n", + "import math\n", + "import torch\n", + "class MySampler(Sampler):\n", + " def __init__(self, data_source, batch_size):\n", + " self.data_source = data_source\n", + " self.batch_size = batch_size\n", + " self.dataset_task_size = []\n", + " for ds in self.data_source.datasets:\n", + " for task in ds.task_data:\n", + " self.dataset_task_size.append(len(ds.task_data[task]))\n", + " self.largest_task_size = max(self.dataset_task_size)\n", + " def set_epoch(self, epoch):\n", + " self.epoch = epoch\n", + " def __iter__(self):\n", + " sampler_list = []\n", + " iterator_list = []\n", + " for i in range(len(self.data_source.datasets)):\n", + " ds = self.data_source.datasets[i]\n", + " # ds.shuffle(self.epoch)\n", + " for task in ds.task_data:\n", + " print(ds.task_data[task])\n", + " sampler = SequentialSampler(ds.task_data[task])\n", + " sampler_list.append(sampler)\n", + " iterator = sampler.__iter__()\n", + " iterator_list.append(iterator)\n", + " \n", + " cum_index = [0] + self.data_source.cumulative_sizes[:-1]\n", + " task_cum_index = []\n", + " for i in range(len(self.data_source.datasets)):\n", + " ds = self.data_source.datasets[i]\n", + " cur_cum_index = cum_index[i]\n", + " for task in ds.task_data:\n", + " task_cum_index.append(cur_cum_index)\n", + " cur_cum_index += len(ds.task_data[task])\n", + " \n", + " \n", + " step = self.batch_size * len(self.dataset_task_size)\n", + " epoch_data_size = self.largest_task_size * len(self.dataset_task_size)\n", + " \n", + " final_list = []\n", + " for _ in range(0, epoch_data_size, step):\n", + " for i in range(len(self.dataset_task_size)):\n", + " cur_iterator = iterator_list[i]\n", + " cur_samples = []\n", + " for _ in range(self.batch_size):\n", + " try:\n", + " cur_element = cur_iterator.__next__()\n", + " cur_element += task_cum_index[i]\n", + " cur_samples.append(cur_element)\n", + " \n", + " except StopIteration:\n", + " iterator_list[i] = sampler_list[i].__iter__()\n", + " cur_iterator = iterator_list[i]\n", + " cur_element = cur_iterator.__next__()\n", + " cur_element += task_cum_index[i]\n", + " cur_samples.append(cur_element)\n", + " final_list.extend(cur_samples)\n", + " print(final_list)\n", + " return iter(final_list)\n", + " \n", + " def __len__(self):\n", + " return self.batch_size * math.ceil(self.largest_task_size / self.batch_size) * len(self.dataset_task_size)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "fa9ea375-c159-4e99-8ad0-0c5f31c9ee1d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + "[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n", + "[20, 21, 22, 23, 24, 25, 26, 27, 28, 29]\n", + "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n", + "[20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]\n", + "[40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]\n", + "[0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 30, 31, 32, 33, 34, 50, 51, 52, 53, 54, 70, 71, 72, 73, 74, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19, 25, 26, 27, 28, 29, 35, 36, 37, 38, 39, 55, 56, 57, 58, 59, 75, 76, 77, 78, 79, 0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 40, 41, 42, 43, 44, 60, 61, 62, 63, 64, 80, 81, 82, 83, 84, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19, 25, 26, 27, 28, 29, 45, 46, 47, 48, 49, 65, 66, 67, 68, 69, 85, 86, 87, 88, 89]\n" + ] + } + ], + "source": [ + "from torch.utils.data import ConcatDataset, DataLoader\n", + "fd = MyFirstDataset()\n", + "sd = MySecondDataset()\n", + "cd = ConcatDataset([fd, sd])\n", + "bs = 5\n", + "dataloader = DataLoader(dataset=cd, sampler=MySampler(cd,bs), batch_size=bs, shuffle=False)\n", + "# print(len(dataloader))\n", + "dataloader.sampler.set_epoch(0)\n", + "for data in dataloader:\n", + " continue\n", + "# for i in range(3):\n", + "# print(f\"epoch {i}\")\n", + "# dataloader.sampler.set_epoch(i)\n", + "# for data in dataloader:\n", + "# print(data)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "e0f0f097-d70d-4eee-afd1-6d02c2b2fe2c", + "metadata": {}, + "outputs": [], + "source": [ + "from torch.utils.data.distributed import DistributedSampler\n", + "class DistMultiDataTaskSampler(DistributedSampler):\n", + " def __init__(self, dataset, batch_size):\n", + " super().__init__(dataset)\n", + " self.batch_size = batch_size\n", + " self.dataset_task_size = []\n", + " for ds in self.dataset.datasets:\n", + " for task in ds.task_data:\n", + " self.dataset_task_size.append(len(ds.task_data[task]))\n", + " self.largest_task_size = max(self.dataset_task_size)\n", + " \n", + " def __iter__(self):\n", + " sampler_list = []\n", + " iterator_list = []\n", + " for i in range(len(self.dataset.datasets)):\n", + " ds = self.dataset.datasets[i]\n", + " for task in ds.task_data:\n", + " sampler = DistributedSampler(ds.task_data[task])\n", + " sampler_list.append(sampler)\n", + " iterator = sampler.__iter__()\n", + " iterator_list.append(iterator)\n", + " \n", + " cum_index = [0] + self.dataset.cumulative_sizes[:-1]\n", + " task_cum_index = []\n", + " for i in range(len(self.dataset.datasets)):\n", + " ds = self.dataset.datasets[i]\n", + " cur_cum_index = cum_index[i]\n", + " for task in ds.task_data:\n", + " task_cum_index.append(cur_cum_index)\n", + " cur_cum_index += len(ds.task_data[task])\n", + " \n", + " \n", + " step = self.batch_size * len(self.dataset_task_size)\n", + " epoch_data_size = self.largest_task_size * len(self.dataset_task_size)\n", + " \n", + " final_list = []\n", + " for _ in range(0, epoch_data_size, step):\n", + " for i in range(len(self.dataset_task_size)):\n", + " cur_iterator = iterator_list[i]\n", + " cur_samples = []\n", + " for _ in range(self.batch_size):\n", + " try:\n", + " cur_element = cur_iterator.__next__()\n", + " cur_element += task_cum_index[i]\n", + " cur_samples.append(cur_element)\n", + " \n", + " except StopIteration:\n", + " iterator_list[i] = sampler_list[i].__iter__()\n", + " cur_iterator = iterator_list[i]\n", + " cur_element = cur_iterator.__next__()\n", + " cur_element += task_cum_index[i]\n", + " cur_samples.append(cur_element)\n", + " final_list.extend(cur_samples)\n", + " \n", + " return iter(final_list)\n", + " \n", + " def __len__(self):\n", + " return self.batch_size * math.ceil(self.largest_task_size / self.batch_size) * len(self.dataset_task_size)" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "a8622baf-72c7-43e8-abec-c6b050b1d128", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n", + "To disable this warning, you can either:\n", + "\t- Avoid using `tokenizers` before the fork if possible\n", + "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n", + "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n", + "To disable this warning, you can either:\n", + "\t- Avoid using `tokenizers` before the fork if possible\n", + "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Traceback (most recent call last):\n", + " File \"\", line 1, in \n", + " File \"/common/home/sx86/anaconda3/envs/SP5/lib/python3.9/multiprocessing/spawn.py\", line 116, in spawn_main\n", + " exitcode = _main(fd, parent_sentinel)\n", + " File \"/common/home/sx86/anaconda3/envs/SP5/lib/python3.9/multiprocessing/spawn.py\", line 126, in _main\n", + " self = reduction.pickle.load(from_parent)\n", + "AttributeError: Can't get attribute 'main' on \n" + ] + }, + { + "ename": "ProcessExitedException", + "evalue": "process 1 terminated with exit code 1", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mProcessExitedException\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[55], line 22\u001b[0m\n\u001b[1;32m 20\u001b[0m args[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mngpus_per_node\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m2\u001b[39m\n\u001b[1;32m 21\u001b[0m os\u001b[38;5;241m.\u001b[39menviron[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCUDA_VISIBLE_DEVICES\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m0,1\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m---> 22\u001b[0m \u001b[43mmp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mspawn\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 23\u001b[0m \u001b[43m \u001b[49m\u001b[43mmain\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnprocs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mngpus_per_node\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mjoin\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\n\u001b[1;32m 24\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/anaconda3/envs/SP5/lib/python3.9/site-packages/torch/multiprocessing/spawn.py:240\u001b[0m, in \u001b[0;36mspawn\u001b[0;34m(fn, args, nprocs, join, daemon, start_method)\u001b[0m\n\u001b[1;32m 236\u001b[0m msg \u001b[38;5;241m=\u001b[39m (\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThis method only supports start_method=spawn (got: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m).\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 237\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTo use a different start_method use:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 238\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m torch.multiprocessing.start_processes(...)\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m%\u001b[39m start_method)\n\u001b[1;32m 239\u001b[0m warnings\u001b[38;5;241m.\u001b[39mwarn(msg)\n\u001b[0;32m--> 240\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mstart_processes\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfn\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnprocs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mjoin\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdaemon\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstart_method\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mspawn\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/anaconda3/envs/SP5/lib/python3.9/site-packages/torch/multiprocessing/spawn.py:198\u001b[0m, in \u001b[0;36mstart_processes\u001b[0;34m(fn, args, nprocs, join, daemon, start_method)\u001b[0m\n\u001b[1;32m 195\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m context\n\u001b[1;32m 197\u001b[0m \u001b[38;5;66;03m# Loop on join until it returns True or raises an exception.\u001b[39;00m\n\u001b[0;32m--> 198\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mjoin\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m:\n\u001b[1;32m 199\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m\n", + "File \u001b[0;32m~/anaconda3/envs/SP5/lib/python3.9/site-packages/torch/multiprocessing/spawn.py:149\u001b[0m, in \u001b[0;36mProcessContext.join\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 140\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ProcessExitedException(\n\u001b[1;32m 141\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mprocess \u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m terminated with signal \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m\n\u001b[1;32m 142\u001b[0m (error_index, name),\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 146\u001b[0m signal_name\u001b[38;5;241m=\u001b[39mname\n\u001b[1;32m 147\u001b[0m )\n\u001b[1;32m 148\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 149\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ProcessExitedException(\n\u001b[1;32m 150\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mprocess \u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m terminated with exit code \u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m\n\u001b[1;32m 151\u001b[0m (error_index, exitcode),\n\u001b[1;32m 152\u001b[0m error_index\u001b[38;5;241m=\u001b[39merror_index,\n\u001b[1;32m 153\u001b[0m error_pid\u001b[38;5;241m=\u001b[39mfailed_process\u001b[38;5;241m.\u001b[39mpid,\n\u001b[1;32m 154\u001b[0m exit_code\u001b[38;5;241m=\u001b[39mexitcode\n\u001b[1;32m 155\u001b[0m )\n\u001b[1;32m 157\u001b[0m original_trace \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39merror_queues[error_index]\u001b[38;5;241m.\u001b[39mget()\n\u001b[1;32m 158\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m-- Process \u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m terminated with the following error:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m error_index\n", + "\u001b[0;31mProcessExitedException\u001b[0m: process 1 terminated with exit code 1" + ] + } + ], + "source": [ + "import torch.multiprocessing as mp\n", + "import os\n", + "from torch.utils.data.dataset import ConcatDataset\n", + "def main(rank, cd):\n", + " fd = MyFirstDataset()\n", + " sd = MySecondDataset()\n", + " cd = ConcatDataset([fd, sd])\n", + " os.environ['MASTER_ADDR'] = 'localhost'\n", + " os.environ['MASTER_PORT'] = '12355'\n", + " torch.cuda.set_device(local_rank)\n", + " dist.init_process_group(\n", + " backend=\"nccl\", world_size=2, rank=local_rank\n", + " )\n", + " dataloader = DataLoader(dataset=cd, sampler=DistMultiDataTaskSampler(cd,args['bs']), batch_size=['bs'], shuffle=False)\n", + " for data in dataloader:\n", + " print(f\"rank {rank}: {data}\")\n", + "\n", + "args = dict()\n", + "args['bs'] = 5\n", + "args['ngpus_per_node'] = 2\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = '0,1'\n", + "mp.spawn(\n", + " main, args=(args,), nprocs=args['ngpus_per_node'], join=True\n", + " )\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "id": "79a2ff5e-985f-4908-b58b-0ade641742b2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[8, 5, 0, 6, 2, 3, 9, 4, 1, 7]" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dataloader.dataset.datasets[0].task_data['1']" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "a85d99fa-7068-4cc3-964e-751ba5600048", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[3, 6, 7, 9, 2, 11, 18, 19, 17, 14, 26, 25, 20, 22, 23, 34, 39, 36, 31, 32, 40, 46, 45, 43, 44, 52, 54, 51, 58, 50, 1, 8, 5, 4, 0, 16, 12, 13, 10, 15, 28, 24, 27, 29, 21, 33, 35, 38, 30, 37, 48, 42, 47, 41, 49, 56, 53, 55, 57, 59]\n", + "60\n", + "tensor([3, 6, 7, 9, 2])\n", + "tensor([11, 18, 19, 17, 14])\n", + "tensor([26, 25, 20, 22, 23])\n", + "tensor([34, 39, 36, 31, 32])\n", + "tensor([40, 46, 45, 43, 44])\n", + "tensor([52, 54, 51, 58, 50])\n", + "tensor([1, 8, 5, 4, 0])\n", + "tensor([16, 12, 13, 10, 15])\n", + "tensor([28, 24, 27, 29, 21])\n", + "tensor([33, 35, 38, 30, 37])\n", + "tensor([48, 42, 47, 41, 49])\n", + "tensor([56, 53, 55, 57, 59])\n" + ] + } + ], + "source": [ + "for data in dataloader:\n", + " print(data)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "048bb939-6576-4996-8e78-1e8752044b04", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[11, 12, 13, 14, 15, 16, 17, 18, 19]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[i for i in range(11,20)]" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "3a7b31af-4f7e-4449-86f5-2612555c4669", + "metadata": {}, + "outputs": [], + "source": [ + "iterator = iter([1,2,3,4,5,6,7,8,9,0])" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "a5bdfb74-ecf4-40d1-af52-15c047319512", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "iterator.__next__()" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "08a7014a-9020-44ec-a745-7147026b6f1a", + "metadata": {}, + "outputs": [], + "source": [ + "sampler = SequentialSampler([i for i in range(10,20)])\n", + "iterator = sampler.__iter__()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "b0ced435-2c2b-4d08-b655-b22da0951635", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "iterator.__next__()" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "id": "05e52ae5-92ce-4719-953d-dbda9d48817e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "[]\n", + "[]\n", + "2\n", + "[1]\n", + "[1]\n", + "3\n", + "[1, 2]\n", + "[1, 2]\n", + "4\n", + "[1, 2, 3]\n", + "[1, 2, 3]\n", + "5\n", + "[1, 2, 3, 4]\n", + "[2, 3, 4]\n", + "6\n", + "[1, 2, 3, 4, 5]\n", + "[3, 4, 5]\n" + ] + } + ], + "source": [ + "a = [1,2,3,4,5,6]\n", + "for i in range(len(a)):\n", + " print(a[i])\n", + " print(a[:i])\n", + " print(a[:i][-3:])" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "id": "77970cdb-ca6d-4f77-9467-d32220be1337", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4]" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a[:-2][-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "379645ad-1dc4-4243-b25f-d989871811b2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'2'" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {'a':'1', 'b':'2', 'c':'3'}\n", + "list(a.values())[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "62c139e7-eb59-459c-8f8a-88e370952034", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import random\n", + "random.randint(0,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "fcbdb4ca-8319-420c-96c3-112eda060cf9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 1, 5, 4, 2]" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = [1,2,3,4,5]\n", + "random.shuffle(a)\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "id": "789491f3-475c-451b-bbcd-c96c22c7f85a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'a': '3', 'b': '2'}, {'a': '3', 'b': '2'}, {'a': '3', 'b': '2'}]" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_list = []\n", + "for i in range(3):\n", + " a = dict()\n", + " a['a'] = '1'\n", + " a['b'] = '2'\n", + " all_list.append(a)\n", + "for a in all_list:\n", + " a['a'] = '3'\n", + "all_list" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "d6342f66-c550-46d1-a405-61cf50dccc36", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[20]" + ] + }, + "execution_count": 105, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "num = [2]\n", + "idx = [num[0] * 10]\n", + "for i in range(1, len(num)):\n", + " idx.append(num[i] * 10 + idx[i-1])\n", + "idx" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "bc4d79cd-9773-4c76-9c31-a5764281bd7d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sum([1,2,3,4])" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "51c87925-2d7d-40e0-b4c0-32b0bb3c9d96", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['seen', '1']" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'seen:1'.split(':')" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "2e7e8814-e7d1-41d7-8762-1a985115c693", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'a': [1, 3], 'b': [2]}" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = dict()\n", + "a['a'] = [1]\n", + "a['b'] = [2]\n", + "a['a'].append(3)\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "id": "03b95048-eb42-40e3-857f-4724b7582aa8", + "metadata": {}, + "outputs": [], + "source": [ + "a = 0\n", + "if a:\n", + " print('a is true')" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "cad3178b-0956-4b59-aa82-9050d168c073", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[i for i in range(10,20)]" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "id": "d85d0702-a1a0-430f-97f7-ab9a74d12b25", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "a = False\n", + "b = 1 if a else 0\n", + "print(b)" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "id": "d0dd497a-6dcc-44fb-8082-e73c6631c688", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'t5' in 't5-small'" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "195aee63-b947-4937-806a-9888b0f3e02f", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/common/home/sx86/anaconda3/envs/SP5/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n", + "/common/home/sx86/anaconda3/envs/SP5/lib/python3.9/site-packages/transformers/models/t5/tokenization_t5_fast.py:155: FutureWarning: This tokenizer was incorrectly instantiated with a model max length of 512 which will be corrected in Transformers v5.\n", + "For now, this behavior is kept to avoid breaking backwards compatibility when padding/encoding with `truncation is True`.\n", + "- Be aware that you SHOULD NOT rely on t5-small automatically truncating your input to 512 when padding/encoding.\n", + "- If you want to encode/pad to sequences longer than 512 you can either instantiate this tokenizer with `model_max_length` or pass `max_length` when encoding/padding.\n", + "- To avoid this warning, please instantiate this tokenizer with `model_max_length` set to your preferred value.\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "from transformers import AutoTokenizer, AutoModelForSeq2SeqLM\n", + "\n", + "tokenizer = AutoTokenizer.from_pretrained(\"t5-small\")\n", + "model = AutoModelForSeq2SeqLM.from_pretrained(\"t5-small\")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "1f47917b-c3fd-414b-90dd-9d8c0c21596c", + "metadata": {}, + "outputs": [], + "source": [ + "Input_text = 'Here is the purchase history of Beauty user 1: Beauty item 1,2,3,4,5. I wonder what is the next recommended item for the user.'\n", + "force_word = ['Beauty']\n", + "input_ids = tokenizer(Input_text,return_tensors=\"pt\").input_ids\n", + "force_word_ids = tokenizer(force_word).input_ids" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "22cd9c03-9478-4194-87c3-f0ee9edacc42", + "metadata": {}, + "outputs": [], + "source": [ + "candidates = [\n", + " \"3560\",\n", + " \"554\",\n", + " \"1825\",\n", + " \"1062\",\n", + " \"680\",\n", + " \"1683\",\n", + " \"363\",\n", + " \"927\",\n", + " \"2345\",\n", + " \"1398\",\n", + " \"2000\",\n", + " \"599\",\n", + " \"375\",\n", + " \"3637\",\n", + " \"3272\",\n", + " \"153\",\n", + " ]\n", + "force_words_ids = [\n", + " tokenizer(force_word, add_special_tokens=False).input_ids,\n", + " tokenizer(candidates, add_special_tokens=False).input_ids,\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "f768d3e4-dbe5-4ece-8a02-0651bddb399f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[292]]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "force_words = [\"Sie\"]\n", + "force_words_ids = tokenizer(force_words, add_special_tokens=False).input_ids\n", + "force_words_ids" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "d134b999-b072-4c40-b6b1-d9171556ce56", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Beauty item 1,2,3,4,5\n" + ] + } + ], + "source": [ + "prediction = model.generate(\n", + " input_ids=input_ids,\n", + " force_words_ids=force_words_ids,\n", + " max_length=8,\n", + " num_beams=5,\n", + " num_return_sequences=5,\n", + ")\n", + "print(tokenizer.decode(prediction[0], skip_special_tokens=True))" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "417dc3d0-d091-40b4-9584-39af2c0566b1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 1]" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tokenizer.encode(\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "d437089c-849e-46a6-9433-58fd8e873349", + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'list' object has no attribute 'shape'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m outputs \u001b[38;5;241m=\u001b[39m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[43m \u001b[49m\u001b[43minput_ids\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[43m \u001b[49m\u001b[43mforce_words_ids\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mforce_word_ids\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[43m \u001b[49m\u001b[43mnum_beams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 5\u001b[0m \u001b[43m \u001b[49m\u001b[43mnum_return_sequences\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 6\u001b[0m \u001b[43m \u001b[49m\u001b[43mno_repeat_ngram_size\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[43mremove_invalid_values\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[43m)\u001b[49m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(tokenizer\u001b[38;5;241m.\u001b[39mdecode(outputs[\u001b[38;5;241m0\u001b[39m], skip_special_tokens\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m))\n", + "File \u001b[0;32m~/anaconda3/envs/SP5/lib/python3.9/site-packages/torch/autograd/grad_mode.py:27\u001b[0m, in \u001b[0;36m_DecoratorContextManager.__call__..decorate_context\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(func)\n\u001b[1;32m 25\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdecorate_context\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 26\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclone():\n\u001b[0;32m---> 27\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/anaconda3/envs/SP5/lib/python3.9/site-packages/transformers/generation/utils.py:1239\u001b[0m, in \u001b[0;36mGenerationMixin.generate\u001b[0;34m(self, inputs, generation_config, logits_processor, stopping_criteria, prefix_allowed_tokens_fn, synced_gpus, **kwargs)\u001b[0m\n\u001b[1;32m 1231\u001b[0m \u001b[38;5;66;03m# 3. Define model inputs\u001b[39;00m\n\u001b[1;32m 1232\u001b[0m \u001b[38;5;66;03m# inputs_tensor has to be defined\u001b[39;00m\n\u001b[1;32m 1233\u001b[0m \u001b[38;5;66;03m# model_input_name is defined if model-specific keyword input is passed\u001b[39;00m\n\u001b[1;32m 1234\u001b[0m \u001b[38;5;66;03m# otherwise model_input_name is None\u001b[39;00m\n\u001b[1;32m 1235\u001b[0m \u001b[38;5;66;03m# all model-specific keyword inputs are removed from `model_kwargs`\u001b[39;00m\n\u001b[1;32m 1236\u001b[0m inputs_tensor, model_input_name, model_kwargs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_prepare_model_inputs(\n\u001b[1;32m 1237\u001b[0m inputs, generation_config\u001b[38;5;241m.\u001b[39mbos_token_id, model_kwargs\n\u001b[1;32m 1238\u001b[0m )\n\u001b[0;32m-> 1239\u001b[0m batch_size \u001b[38;5;241m=\u001b[39m \u001b[43minputs_tensor\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshape\u001b[49m[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 1241\u001b[0m \u001b[38;5;66;03m# 4. Define other model kwargs\u001b[39;00m\n\u001b[1;32m 1242\u001b[0m model_kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moutput_attentions\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m generation_config\u001b[38;5;241m.\u001b[39moutput_attentions\n", + "\u001b[0;31mAttributeError\u001b[0m: 'list' object has no attribute 'shape'" + ] + } + ], + "source": [ + "outputs = model.generate(\n", + " input_ids,\n", + " force_words_ids=force_word_ids,\n", + " max_length=8,\n", + " num_beams=5,\n", + " num_return_sequences=1,\n", + " no_repeat_ngram_size=1,\n", + " remove_invalid_values=True,\n", + ")\n", + "print(tokenizer.decode(outputs[0], skip_special_tokens=True))" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "1d354103-d75c-4658-a926-37e3659cd8e7", + "metadata": {}, + "outputs": [], + "source": [ + "from utils.generation_trie import Trie\n", + "candidates = [\n", + " \"3560\",\n", + " \"554\",\n", + " \"1825\",\n", + " \"1062\",\n", + " \"680\",\n", + " \"1683\",\n", + " \"363\",\n", + " \"927\",\n", + " \"2345\",\n", + " \"1398\",\n", + " \"2000\",\n", + " \"599\",\n", + " \"375\",\n", + " \"3637\",\n", + " \"3272\",\n", + " \"153\",\n", + " ]\n", + "candidate_trie = Trie([tokenizer.encode(\"Beauty\") + tokenizer.encode(\"{}\".format(e)) for e in candidates])\n", + "def prefix_allowed_tokens_fn(candidate_trie):\n", + " def prefix_allowed_tokens(batch_id, sentence):\n", + " sentence = sentence.tolist()\n", + " trie_out = candidate_trie.get(sentence)\n", + " return trie_out\n", + "\n", + " return prefix_allowed_tokens\n" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "id": "cff48f4c-4faa-4fb9-9eab-115bf82c7cc1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 12587, 2118, 3097, 3328, 1],\n", + " [0, 12587, 2118, 305, 5062, 1],\n", + " [0, 12587, 2118, 507, 1828, 1],\n", + " [0, 12587, 2118, 335, 4056, 1],\n", + " [0, 12587, 2118, 431, 2079, 1],\n", + " [0, 12587, 2118, 898, 4591, 1],\n", + " [0, 12587, 2118, 220, 3891, 1],\n", + " [0, 12587, 2118, 668, 2555, 1],\n", + " [0, 12587, 2118, 1902, 2128, 1],\n", + " [0, 12587, 2118, 1179, 3916, 1],\n", + " [0, 12587, 2118, 2766, 1],\n", + " [0, 12587, 2118, 305, 3264, 1],\n", + " [0, 12587, 2118, 3, 22954, 1],\n", + " [0, 12587, 2118, 4475, 4118, 1],\n", + " [0, 12587, 2118, 3538, 5865, 1],\n", + " [0, 12587, 2118, 3, 27025, 1]]" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[[0] + tokenizer.encode(\"Beauty item {}\".format(e)) for e in candidates]" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "687a2083-a348-4880-960e-befebef83aa7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "torch.Size([20, 4])\n", + "[' 153', ' 375', ' 599', ' 1398', ' 1825', ' 1683', ' 554', ' 2345', ' 927', ' 363', ' 153', ' 375', ' 599', ' 1825', ' 1398', ' 554', ' 1683', ' 2345', ' 1062', ' 680']\n" + ] + } + ], + "source": [ + "input_s = [\n", + " \"Here is the purchase history of Beauty user 1: Beauty item 1,2,3,4,5. I wonder what is the next recommended item for the user.\",\n", + " \"Here is the purchase history of Beauty user 3: Beauty item 27,52,97,2. I wonder what is the next recommended item for the user.\",\n", + " ]\n", + "input_ids = tokenizer.batch_encode_plus(\n", + " input_s, padding=\"longest\", return_tensors=\"pt\"\n", + " )[\"input_ids\"]\n", + "prefix_allowed_tokens = prefix_allowed_tokens_fn(candidate_trie)\n", + "output_ids = model.generate(\n", + " input_ids,\n", + " max_length=150,\n", + " prefix_allowed_tokens_fn=prefix_allowed_tokens,\n", + " num_beams=20,\n", + " num_return_sequences=10,\n", + " )\n", + "\n", + "print(output_ids.size())\n", + "print(tokenizer.batch_decode(output_ids))" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "d236113c-9586-475c-86eb-17ddbbab2a6c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0: {3097: {3328: {1: {}}}, 305: {5062: {1: {}}, 3264: {1: {}}}, 507: {1828: {1: {}}}, 335: {4056: {1: {}}}, 431: {2079: {1: {}}}, 898: {4591: {1: {}}}, 220: {3891: {1: {}}}, 668: {2555: {1: {}}}, 1902: {2128: {1: {}}}, 1179: {3916: {1: {}}}, 2766: {1: {}}, 3: {22954: {1: {}}, 27025: {1: {}}}, 4475: {4118: {1: {}}}, 3538: {5865: {1: {}}}}}\n" + ] + } + ], + "source": [ + "print(candidate_trie.trie_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "d118c817-60ae-420c-bfb1-d4caf0f306d0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 3097, 3328, 1],\n", + " [0, 305, 5062, 1],\n", + " [0, 507, 1828, 1],\n", + " [0, 335, 4056, 1],\n", + " [0, 431, 2079, 1],\n", + " [0, 898, 4591, 1],\n", + " [0, 220, 3891, 1],\n", + " [0, 668, 2555, 1],\n", + " [0, 1902, 2128, 1],\n", + " [0, 1179, 3916, 1],\n", + " [0, 2766, 1],\n", + " [0, 305, 3264, 1],\n", + " [0, 3, 22954, 1],\n", + " [0, 4475, 4118, 1],\n", + " [0, 3538, 5865, 1],\n", + " [0, 3, 27025, 1]]" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[[0] + tokenizer.encode(\"{}\".format(e)) for e in candidates]" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "56e41322-3c4a-4267-a0cc-94badeab9860", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3097, 3328, 1]" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tokenizer.encode(\"3560\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "66e6c47b-d4ab-4212-b984-d4d57f5e5884", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[12587, 1, 3097, 3328, 1],\n", + " [12587, 1, 305, 5062, 1],\n", + " [12587, 1, 507, 1828, 1],\n", + " [12587, 1, 335, 4056, 1],\n", + " [12587, 1, 431, 2079, 1],\n", + " [12587, 1, 898, 4591, 1],\n", + " [12587, 1, 220, 3891, 1],\n", + " [12587, 1, 668, 2555, 1],\n", + " [12587, 1, 1902, 2128, 1],\n", + " [12587, 1, 1179, 3916, 1],\n", + " [12587, 1, 2766, 1],\n", + " [12587, 1, 305, 3264, 1],\n", + " [12587, 1, 3, 22954, 1],\n", + " [12587, 1, 4475, 4118, 1],\n", + " [12587, 1, 3538, 5865, 1],\n", + " [12587, 1, 3, 27025, 1]]" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[tokenizer.encode(\"Beauty\") + tokenizer.encode(\"{}\".format(e)) for e in candidates]" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "c076ab8d-c16a-41df-bd14-375f90e7a998", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a= [1,2,3,4,5]\n", + "min(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "838a9773-9431-4c08-a2e6-338ad72e542f", + "metadata": {}, + "outputs": [], + "source": [ + "a = [1,2,3,4]\n", + "# a[1::4]" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "d5820bbc-5531-4bd7-8182-c2eb55ccd568", + "metadata": {}, + "outputs": [], + "source": [ + "sampler = RandomSampler(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "296848af-96d8-4134-8cd1-1529df364e62", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "0\n", + "2\n", + "3\n", + "1\n", + "0\n", + "2\n", + "3\n" + ] + } + ], + "source": [ + "iterator = sampler.__iter__()\n", + "for i in range(8):\n", + " try:\n", + " print(iterator.__next__())\n", + " except StopIteration:\n", + " iterator = sampler.__iter__()\n", + " print(iterator.__next__())" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "0c113f62-331b-4709-8d2a-7f57e7bcd1c6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[5, 2, 123, 3]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from torch.utils.data.sampler import Sampler, RandomSampler, SequentialSampler\n", + "a = [4,5,3,2,2,123,5,3,2]\n", + "a[1::2]" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "b6776080-ef1b-4b8e-aa08-fa0600962bc2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n" + ] + } + ], + "source": [ + "sampler = SequentialSampler(a)\n", + "iterator = sampler.__iter__()\n", + "for i in range(4):\n", + " print(iterator.__next__())" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "96dbfe65-f974-4103-b447-2b577b10552b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'prompt_template'" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = '../prompt_template.txt'\n", + "a[3:-4]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ebe9f519-3f6e-4224-b805-62ec18392524", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SP5", + "language": "python", + "name": "sp5" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.16" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/main.py b/src/main.py index 297cbb7..c270d7d 100644 --- a/src/main.py +++ b/src/main.py @@ -9,7 +9,7 @@ from data.MultiTaskDataset import MultiTaskDataset from runner.SingleRunner import SingleRunner from runner.DistributedRunner import DistributedRunner -from processor.Collator import Collator +from processor.Collator import Collator, TestCollator from processor.SingleMultiDataTaskSampler import SingleMultiDataTaskSampler from processor.DistMultiDataTaskSampler import DistMultiDataTaskSampler from torch.utils.data.distributed import DistributedSampler @@ -32,15 +32,21 @@ def get_dataset(args): for data in datasets: TrainDataset = MultiTaskDataset(args, data, 'train') train_all_datasets.append(TrainDataset) - ValidDataset = MultiTaskDataset(args, data, 'validation') - valid_all_datasets.append(ValidDataset) + if args.valid_select > 0: + ValidDataset = MultiTaskDataset(args, data, 'validation') + valid_all_datasets.append(ValidDataset) TrainSet = ConcatDataset(train_all_datasets) - ValidSet = ConcatDataset(valid_all_datasets) + if args.valid_select > 0: + ValidSet = ConcatDataset(valid_all_datasets) + else: + ValidSet = None return TrainSet, ValidSet def get_loader(args, tokenizer, TrainSet, ValidSet, rank=0): + + # generate training validation loader. ngpus_per_node = torch.cuda.device_count() if ngpus_per_node == 1: args.distributed = 0 @@ -48,15 +54,20 @@ def get_loader(args, tokenizer, TrainSet, ValidSet, rank=0): train_sampler = DistMultiDataTaskSampler(TrainSet, args.batch_size, args.world_size, rank, args.seed, shuffle=True) if args.distributed else SingleMultiDataTaskSampler(TrainSet, args.batch_size, args.seed, shuffle=True) else: train_sampler = DistributedSampler(TrainSet) if args.distributed else None - valid_sampler = DistributedSampler(ValidSet) if args.distributed else None + if args.valid_select > 0: + valid_sampler = DistributedSampler(ValidSet) if args.distributed else None collator = Collator(tokenizer) train_loader = DataLoader(dataset=TrainSet, sampler=train_sampler, batch_size=args.batch_size, collate_fn=collator, shuffle=False) - valid_loader = DataLoader(dataset=ValidSet, sampler=valid_sampler, batch_size=args.batch_size, collate_fn=collator, shuffle=False) + if args.valid_select > 0: + valid_loader = DataLoader(dataset=ValidSet, sampler=valid_sampler, batch_size=args.batch_size, collate_fn=collator, shuffle=False) + else: + valid_loader = None return train_loader, valid_loader def single_main(): + # running on single gpu. # init args parser = argparse.ArgumentParser(description='OpenP5') @@ -73,16 +84,17 @@ def single_main(): args.rank = 0 - # device = torch.device("cuda", int(args.gpu.split(',')[0])) - device = "cuda:0" + device = torch.device("cuda", int(args.gpu.split(',')[0])) + logging.info(vars(args)) tokenizer = AutoTokenizer.from_pretrained(args.backbone) - # init dataset + # init dataset and dataloader TrainSet, ValidSet = get_dataset(args) - train_loader, valid_loader = get_loader(args, tokenizer, TrainSet, TestSet) + + train_loader, valid_loader = get_loader(args, tokenizer, TrainSet, ValidSet) if 't5' in args.backbone: config = T5Config.from_pretrained(args.backbone) @@ -116,7 +128,6 @@ def single_main(): runner.test(args.model_path) -# pdb.set_trace() def distributed_launch(): parser = argparse.ArgumentParser(description='OpenP5') @@ -138,7 +149,7 @@ def distributed_launch(): def distributed_main(local_rank, args): - + # distributed learning args.rank = local_rank utils.set_seed(args.seed) os.environ['MASTER_ADDR'] = args.master_addr @@ -174,6 +185,8 @@ def distributed_main(local_rank, args): model.to(device) + + if args.item_indexing == 'collaborative': for ds in train_loader.dataset.datasets: tokenizer.add_tokens(ds.new_token) @@ -189,7 +202,7 @@ def distributed_main(local_rank, args): logging.info(f"Load model from {args.model_path}") model = utils.load_model(model, args.model_path, args, loc=device) model.to(device) - + runner = DistributedRunner(model, tokenizer, train_loader, valid_loader, device, args, local_rank) if args.train: diff --git a/src/processor/.ipynb_checkpoints/Collator-checkpoint.py b/src/processor/.ipynb_checkpoints/Collator-checkpoint.py index fd0143b..bf0f1e4 100644 --- a/src/processor/.ipynb_checkpoints/Collator-checkpoint.py +++ b/src/processor/.ipynb_checkpoints/Collator-checkpoint.py @@ -32,6 +32,40 @@ def __call__(self, batch): torch.tensor(output_ids), torch.tensor(output_attention), ) + +class TestCollator: + def __init__(self, tokenizer): + self.tokenizer = tokenizer + + def __call__(self, batch): + user_idx = [input_text['user_idx'] for input_text in batch] + input_texts = [input_text['input'] for input_text in batch] + output_texts = [input_text['output'] for input_text in batch] + + inputs = self.tokenizer.batch_encode_plus( + input_texts, padding="longest", truncation=True, max_length=512 + ) + input_ids = inputs["input_ids"] + whole_word_ids = [] + for input_id in input_ids: + tokenized_text = self.tokenizer.convert_ids_to_tokens(input_id) + whole_word_id = calculate_whole_word_ids(tokenized_text, input_id) + whole_word_ids.append(whole_word_id) + input_attention = inputs["attention_mask"] + outputs = self.tokenizer.batch_encode_plus( + output_texts, padding="longest", truncation=True, max_length=512 + ) + output_ids = outputs["input_ids"] + output_attention = outputs["attention_mask"] + + return ( + torch.tensor(input_ids), + torch.tensor(input_attention), + torch.tensor(whole_word_ids), + torch.tensor(output_ids), + torch.tensor(output_attention), + torch.tensor(user_idx), + ) diff --git a/src/processor/Collator.py b/src/processor/Collator.py index fd0143b..bf0f1e4 100644 --- a/src/processor/Collator.py +++ b/src/processor/Collator.py @@ -32,6 +32,40 @@ def __call__(self, batch): torch.tensor(output_ids), torch.tensor(output_attention), ) + +class TestCollator: + def __init__(self, tokenizer): + self.tokenizer = tokenizer + + def __call__(self, batch): + user_idx = [input_text['user_idx'] for input_text in batch] + input_texts = [input_text['input'] for input_text in batch] + output_texts = [input_text['output'] for input_text in batch] + + inputs = self.tokenizer.batch_encode_plus( + input_texts, padding="longest", truncation=True, max_length=512 + ) + input_ids = inputs["input_ids"] + whole_word_ids = [] + for input_id in input_ids: + tokenized_text = self.tokenizer.convert_ids_to_tokens(input_id) + whole_word_id = calculate_whole_word_ids(tokenized_text, input_id) + whole_word_ids.append(whole_word_id) + input_attention = inputs["attention_mask"] + outputs = self.tokenizer.batch_encode_plus( + output_texts, padding="longest", truncation=True, max_length=512 + ) + output_ids = outputs["input_ids"] + output_attention = outputs["attention_mask"] + + return ( + torch.tensor(input_ids), + torch.tensor(input_attention), + torch.tensor(whole_word_ids), + torch.tensor(output_ids), + torch.tensor(output_attention), + torch.tensor(user_idx), + ) diff --git a/src/processor/__pycache__/Collator.cpython-39.pyc b/src/processor/__pycache__/Collator.cpython-39.pyc index 9af6a3c..536b69e 100644 Binary files a/src/processor/__pycache__/Collator.cpython-39.pyc and b/src/processor/__pycache__/Collator.cpython-39.pyc differ diff --git a/src/runner/.ipynb_checkpoints/DistributedRunner-checkpoint.py b/src/runner/.ipynb_checkpoints/DistributedRunner-checkpoint.py index 4a9a349..675371e 100644 --- a/src/runner/.ipynb_checkpoints/DistributedRunner-checkpoint.py +++ b/src/runner/.ipynb_checkpoints/DistributedRunner-checkpoint.py @@ -11,19 +11,22 @@ from torch.utils.data.distributed import DistributedSampler from data.TestDataset import TestDataset from torch.utils.data import DataLoader -from processor.Collator import Collator +from processor.Collator import Collator, TestCollator import time import numpy as np import random +import pdb + class DistributedRunner(SingleRunner): def __init__(self, model, tokenizer, train_loader, valid_loader, device, args, rank): super().__init__(model, tokenizer, train_loader, valid_loader, device, args) self.rank = rank + self.model = DDP(self.model, device_ids=[self.args.gpu], find_unused_parameters=True) def train(self): - self.model = DDP(self.model, device_ids=[self.args.gpu], find_unused_parameters=True) + self.model.zero_grad() train_losses = [] valid_losses = [] @@ -49,6 +52,7 @@ def train(self): self.model.train() losses = [] + for batch in tqdm(self.train_loader): input_ids = batch[0].to(self.device) attn = batch[1].to(self.device) @@ -83,13 +87,13 @@ def train(self): self.model.zero_grad() - dist.all_reduce(loss, op=dist.ReduceOp.SUM) + dist.all_reduce(loss.detach(), op=dist.ReduceOp.SUM) loss /= dist.get_world_size() dist.barrier() if self.rank == 0: - losses.append(loss) + losses.append(loss.detach()) if self.rank == 0: train_epoch_loss = sum(losses)/len(losses) @@ -171,7 +175,10 @@ def get_testloader(self): self.testloaders = [] datasets = self.args.datasets.split(',') tasks = self.args.tasks.split(',') - collator = Collator(self.tokenizer) + if self.test_filtered > 0: + collator = TestCollator(self.tokenizer) + else: + collator = Collator(self.tokenizer) for dataset in datasets: for task in tasks: @@ -185,8 +192,149 @@ def test(self, path=None): if path: self.model.module.load_state_dict(torch.load(path, map_location=self.device)) for loader in self.testloaders: - self.test_dataset_task(loader) + if self.test_filtered > 0: + if self.test_filtered_batch > 0: + self.test_dataset_task_filtered_batch(loader) + else: + assert self.args.eval_batch_size == 1 + self.test_dataset_task_filtered(loader) + else: + self.test_dataset_task(loader) + + def test_dataset_task_filtered_batch(self, testloader): + if self.rank == 0: + logging.info(f'testing filtered {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') + test_total = 0 + with torch.no_grad(): + candidates = set(testloader.dataset.all_items) + candidate_trie = gt.Trie( + [ + [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") + for candidate in candidates + ] + ) + prefix_allowed_tokens = gt.prefix_allowed_tokens_fn(candidate_trie) + + metrics_res = np.array([0.0] * len(self.metrics)) + for batch in tqdm(testloader): + input_ids = batch[0].to(self.device) + attn = batch[1].to(self.device) + whole_input_ids = batch[2].to(self.device) + output_ids = batch[3].to(self.device) + output_attention = batch[4].to(self.device) + user_idx = batch[5] + + + + prediction = self.model.module.generate( + input_ids=input_ids, + attention_mask=attn, + whole_word_ids=whole_input_ids, + max_length=30, + prefix_allowed_tokens_fn=prefix_allowed_tokens, + num_beams=self.generate_num + testloader.dataset.max_positive, + num_return_sequences=self.generate_num + testloader.dataset.max_positive, + output_scores=True, + return_dict_in_generate=True, + ) + + prediction_ids = prediction["sequences"] + prediction_scores = prediction["sequences_scores"] + + gold_sents = self.tokenizer.batch_decode( + output_ids, skip_special_tokens=True + ) + generated_sents = self.tokenizer.batch_decode( + prediction_ids, skip_special_tokens=True + ) + + rel_results = evaluate.rel_results_filtered(testloader.dataset.positive, testloader.dataset.id2user, user_idx.detach().cpu().numpy(), \ + self.generate_num+testloader.dataset.max_positive, \ + generated_sents, gold_sents, prediction_scores, self.generate_num) + + test_total += len(rel_results) + + metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) + + dist.barrier() + metrics_res = torch.tensor(metrics_res).to(self.device) + test_total = torch.tensor(test_total).to(self.device) + dist.all_reduce(metrics_res, op=dist.ReduceOp.SUM) + dist.all_reduce(test_total, op=dist.ReduceOp.SUM) + + metrics_res /= test_total + + if self.rank == 0: + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') + + def test_dataset_task_filtered(self, testloader): + if self.rank == 0: + logging.info(f'testing filtered {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') + test_total = 0 + with torch.no_grad(): + candidates = set(testloader.dataset.all_items) + + + metrics_res = np.array([0.0] * len(self.metrics)) + for batch in tqdm(testloader): + input_ids = batch[0].to(self.device) + attn = batch[1].to(self.device) + whole_input_ids = batch[2].to(self.device) + output_ids = batch[3].to(self.device) + output_attention = batch[4].to(self.device) + user_idx = int(batch[5][0]) + positive = testloader.dataset.positive[testloader.dataset.id2user[user_idx]] + + user_candidate = candidates - positive + + candidate_trie = gt.Trie( + [ + [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") + for candidate in user_candidate + ] + ) + prefix_allowed_tokens = gt.prefix_allowed_tokens_fn(candidate_trie) + + prediction = self.model.module.generate( + input_ids=input_ids, + attention_mask=attn, + whole_word_ids=whole_input_ids, + max_length=30, + prefix_allowed_tokens_fn=prefix_allowed_tokens, + num_beams=self.generate_num, + num_return_sequences=self.generate_num, + output_scores=True, + return_dict_in_generate=True, + ) + + prediction_ids = prediction["sequences"] + prediction_scores = prediction["sequences_scores"] + + gold_sents = self.tokenizer.batch_decode( + output_ids, skip_special_tokens=True + ) + generated_sents = self.tokenizer.batch_decode( + prediction_ids, skip_special_tokens=True + ) + + rel_results = evaluate.rel_results(generated_sents, gold_sents, prediction_scores, self.generate_num) + + test_total += len(rel_results) + + metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) + + dist.barrier() + metrics_res = torch.tensor(metrics_res).to(self.device) + test_total = torch.tensor(test_total).to(self.device) + dist.all_reduce(metrics_res, op=dist.ReduceOp.SUM) + dist.all_reduce(test_total, op=dist.ReduceOp.SUM) + + metrics_res /= test_total + if self.rank == 0: + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') def test_dataset_task(self, testloader): if self.rank == 0: @@ -196,7 +344,6 @@ def test_dataset_task(self, testloader): candidates = testloader.dataset.all_items candidate_trie = gt.Trie( [ - # [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item {candidate}") [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") for candidate in candidates ] @@ -215,7 +362,7 @@ def test_dataset_task(self, testloader): input_ids=input_ids, attention_mask=attn, whole_word_ids=whole_input_ids, - max_length=8, + max_length=50, prefix_allowed_tokens_fn=prefix_allowed_tokens, num_beams=self.generate_num, num_return_sequences=self.generate_num, diff --git a/src/runner/.ipynb_checkpoints/SingleRunner-checkpoint.py b/src/runner/.ipynb_checkpoints/SingleRunner-checkpoint.py index fde29bc..62ee226 100644 --- a/src/runner/.ipynb_checkpoints/SingleRunner-checkpoint.py +++ b/src/runner/.ipynb_checkpoints/SingleRunner-checkpoint.py @@ -6,7 +6,7 @@ import utils.generation_trie as gt from data.TestDataset import TestDataset from torch.utils.data import DataLoader -from processor.Collator import Collator +from processor.Collator import Collator, TestCollator import time import pdb @@ -34,6 +34,8 @@ def parse_runner_args(parser): parser.add_argument("--test_epoch", type=int, default=1, help='test once for how many epochs, 0 for no test during training.') parser.add_argument("--valid_select", type=int, default=0, help='use validation loss to select models') parser.add_argument("--test_before_train", type=int, default=1, help='whether test before training') + parser.add_argument("--test_filtered", type=int, default=0, help='whether filter out the items in the training data.') + parser.add_argument("--test_filtered_batch", type=int, default=1, help='whether testing with filtered data in batch.') return parser @@ -49,6 +51,8 @@ def __init__(self, model, tokenizer, train_loader, valid_loader, device, args): self.test_epoch = self.args.test_epoch self.valid_select = self.args.valid_select self.test_before_train = self.args.test_before_train + self.test_filtered = self.args.test_filtered + self.test_filtered_batch = self.args.test_filtered_batch self.get_testloader() @@ -218,22 +222,156 @@ def get_testloader(self): self.testloaders = [] datasets = self.args.datasets.split(',') tasks = self.args.tasks.split(',') - collator = Collator(self.tokenizer) + if self.test_filtered > 0: + collator = TestCollator(self.tokenizer) + else: + collator = Collator(self.tokenizer) for dataset in datasets: for task in tasks: testdata = TestDataset(self.args, dataset, task) testloader = DataLoader(dataset=testdata, batch_size=self.args.eval_batch_size, collate_fn=collator, shuffle=False) self.testloaders.append(testloader) + def test(self, path=None): self.model.eval() if path: self.model.load_state_dict(torch.load(path, map_location=self.device)) for loader in self.testloaders: - self.test_dataset_task(loader) + if self.test_filtered > 0: + if self.test_filtered_batch > 0: + self.test_dataset_task_filtered_batch(loader) + else: + assert self.args.eval_batch_size == 1 + self.test_dataset_task_filtered(loader) + else: + self.test_dataset_task(loader) + + + def test_dataset_task_filtered_batch(self, testloader): + logging.info(f'testing filtered {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') + test_total = 0 + with torch.no_grad(): + candidates = testloader.dataset.all_items + candidate_trie = gt.Trie( + [ + [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") + for candidate in candidates + ] + ) + prefix_allowed_tokens = gt.prefix_allowed_tokens_fn(candidate_trie) + + metrics_res = np.array([0.0] * len(self.metrics)) + for batch in tqdm(testloader): + input_ids = batch[0].to(self.device) + attn = batch[1].to(self.device) + whole_input_ids = batch[2].to(self.device) + output_ids = batch[3].to(self.device) + output_attention = batch[4].to(self.device) + user_idx = batch[5].to(self.device) - - + prediction = self.model.module.generate( + input_ids=input_ids, + attention_mask=attn, + whole_word_ids=whole_input_ids, + max_length=30, + prefix_allowed_tokens_fn=prefix_allowed_tokens, + num_beams=self.generate_num + testloader.dataset.max_positive, + num_return_sequences=self.generate_num + testloader.dataset.max_positive, + output_scores=True, + return_dict_in_generate=True, + ) + + prediction_ids = prediction["sequences"] + prediction_scores = prediction["sequences_scores"] + + gold_sents = self.tokenizer.batch_decode( + output_ids, skip_special_tokens=True + ) + generated_sents = self.tokenizer.batch_decode( + prediction_ids, skip_special_tokens=True + ) + + rel_results = evaluate.rel_results_filtered(testloader.dataset.positive, testloader.dataset.id2user, user_idx, \ + self.generate_num+testloader.dataset.max_positive, \ + generated_sents, gold_sents, prediction_scores, self.generate_num) + + test_total += len(rel_results) + + metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) + + metrics_res = torch.tensor(metrics_res).to(self.device) + test_total = torch.tensor(test_total).to(self.device) + + metrics_res /= test_total + + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') + + def test_dataset_task_filtered(self, testloader): + logging.info(f'testing filtered {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') + test_total = 0 + with torch.no_grad(): + candidates = set(testloader.dataset.all_items) + + + metrics_res = np.array([0.0] * len(self.metrics)) + for batch in tqdm(testloader): + input_ids = batch[0].to(self.device) + attn = batch[1].to(self.device) + whole_input_ids = batch[2].to(self.device) + output_ids = batch[3].to(self.device) + output_attention = batch[4].to(self.device) + user_idx = int(batch[5][0]) + positive = testloader.dataset.positive[testloader.dataset.id2user[user_idx]] + + user_candidate = candidates - positive + + candidate_trie = gt.Trie( + [ + [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") + for candidate in user_candidate + ] + ) + prefix_allowed_tokens = gt.prefix_allowed_tokens_fn(candidate_trie) + + prediction = self.model.module.generate( + input_ids=input_ids, + attention_mask=attn, + whole_word_ids=whole_input_ids, + max_length=30, + prefix_allowed_tokens_fn=prefix_allowed_tokens, + num_beams=self.generate_num, + num_return_sequences=self.generate_num, + output_scores=True, + return_dict_in_generate=True, + ) + + prediction_ids = prediction["sequences"] + prediction_scores = prediction["sequences_scores"] + + gold_sents = self.tokenizer.batch_decode( + output_ids, skip_special_tokens=True + ) + generated_sents = self.tokenizer.batch_decode( + prediction_ids, skip_special_tokens=True + ) + + rel_results = evaluate.rel_results(generated_sents, gold_sents, prediction_scores, self.generate_num) + + test_total += len(rel_results) + + metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) + + metrics_res = torch.tensor(metrics_res).to(self.device) + test_total = torch.tensor(test_total).to(self.device) + + metrics_res /= test_total + + + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') + def test_dataset_task(self, testloader): logging.info(f'testing {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') test_total = 0 @@ -259,7 +397,7 @@ def test_dataset_task(self, testloader): input_ids=input_ids, attention_mask=attn, whole_word_ids=whole_input_ids, - max_length=8, + max_length=30, prefix_allowed_tokens_fn=prefix_allowed_tokens, num_beams=self.generate_num, num_return_sequences=self.generate_num, @@ -285,14 +423,10 @@ def test_dataset_task(self, testloader): metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) - dist.barrier() metrics_res = torch.tensor(metrics_res).to(self.device) test_total = torch.tensor(test_total).to(self.device) - dist.all_reduce(metrics_res, op=dist.ReduceOp.SUM) - dist.all_reduce(test_total, op=dist.ReduceOp.SUM) metrics_res /= test_total - if self.rank == 0: - for i in range(len(self.metrics)): - logging.info(f'{self.metrics[i]}: {metrics_res[i]}') \ No newline at end of file + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') \ No newline at end of file diff --git a/src/runner/DistributedRunner.py b/src/runner/DistributedRunner.py index 6be8f74..675371e 100644 --- a/src/runner/DistributedRunner.py +++ b/src/runner/DistributedRunner.py @@ -11,19 +11,22 @@ from torch.utils.data.distributed import DistributedSampler from data.TestDataset import TestDataset from torch.utils.data import DataLoader -from processor.Collator import Collator +from processor.Collator import Collator, TestCollator import time import numpy as np import random +import pdb + class DistributedRunner(SingleRunner): def __init__(self, model, tokenizer, train_loader, valid_loader, device, args, rank): super().__init__(model, tokenizer, train_loader, valid_loader, device, args) self.rank = rank + self.model = DDP(self.model, device_ids=[self.args.gpu], find_unused_parameters=True) def train(self): - self.model = DDP(self.model, device_ids=[self.args.gpu], find_unused_parameters=True) + self.model.zero_grad() train_losses = [] valid_losses = [] @@ -49,6 +52,7 @@ def train(self): self.model.train() losses = [] + for batch in tqdm(self.train_loader): input_ids = batch[0].to(self.device) attn = batch[1].to(self.device) @@ -132,13 +136,13 @@ def train(self): dist.barrier() - dist.all_reduce(loss.detach(), op=dist.ReduceOp.SUM) + dist.all_reduce(loss, op=dist.ReduceOp.SUM) loss /= dist.get_world_size() dist.barrier() if self.rank == 0: - losses.append(loss.detach()) + losses.append(loss) if self.rank == 0: valid_epoch_loss = sum(losses)/len(losses) @@ -171,7 +175,10 @@ def get_testloader(self): self.testloaders = [] datasets = self.args.datasets.split(',') tasks = self.args.tasks.split(',') - collator = Collator(self.tokenizer) + if self.test_filtered > 0: + collator = TestCollator(self.tokenizer) + else: + collator = Collator(self.tokenizer) for dataset in datasets: for task in tasks: @@ -185,8 +192,149 @@ def test(self, path=None): if path: self.model.module.load_state_dict(torch.load(path, map_location=self.device)) for loader in self.testloaders: - self.test_dataset_task(loader) + if self.test_filtered > 0: + if self.test_filtered_batch > 0: + self.test_dataset_task_filtered_batch(loader) + else: + assert self.args.eval_batch_size == 1 + self.test_dataset_task_filtered(loader) + else: + self.test_dataset_task(loader) + + def test_dataset_task_filtered_batch(self, testloader): + if self.rank == 0: + logging.info(f'testing filtered {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') + test_total = 0 + with torch.no_grad(): + candidates = set(testloader.dataset.all_items) + candidate_trie = gt.Trie( + [ + [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") + for candidate in candidates + ] + ) + prefix_allowed_tokens = gt.prefix_allowed_tokens_fn(candidate_trie) + + metrics_res = np.array([0.0] * len(self.metrics)) + for batch in tqdm(testloader): + input_ids = batch[0].to(self.device) + attn = batch[1].to(self.device) + whole_input_ids = batch[2].to(self.device) + output_ids = batch[3].to(self.device) + output_attention = batch[4].to(self.device) + user_idx = batch[5] + + + + prediction = self.model.module.generate( + input_ids=input_ids, + attention_mask=attn, + whole_word_ids=whole_input_ids, + max_length=30, + prefix_allowed_tokens_fn=prefix_allowed_tokens, + num_beams=self.generate_num + testloader.dataset.max_positive, + num_return_sequences=self.generate_num + testloader.dataset.max_positive, + output_scores=True, + return_dict_in_generate=True, + ) + + prediction_ids = prediction["sequences"] + prediction_scores = prediction["sequences_scores"] + + gold_sents = self.tokenizer.batch_decode( + output_ids, skip_special_tokens=True + ) + generated_sents = self.tokenizer.batch_decode( + prediction_ids, skip_special_tokens=True + ) + + rel_results = evaluate.rel_results_filtered(testloader.dataset.positive, testloader.dataset.id2user, user_idx.detach().cpu().numpy(), \ + self.generate_num+testloader.dataset.max_positive, \ + generated_sents, gold_sents, prediction_scores, self.generate_num) + + test_total += len(rel_results) + + metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) + + dist.barrier() + metrics_res = torch.tensor(metrics_res).to(self.device) + test_total = torch.tensor(test_total).to(self.device) + dist.all_reduce(metrics_res, op=dist.ReduceOp.SUM) + dist.all_reduce(test_total, op=dist.ReduceOp.SUM) + + metrics_res /= test_total + + if self.rank == 0: + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') + + def test_dataset_task_filtered(self, testloader): + if self.rank == 0: + logging.info(f'testing filtered {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') + test_total = 0 + with torch.no_grad(): + candidates = set(testloader.dataset.all_items) + + + metrics_res = np.array([0.0] * len(self.metrics)) + for batch in tqdm(testloader): + input_ids = batch[0].to(self.device) + attn = batch[1].to(self.device) + whole_input_ids = batch[2].to(self.device) + output_ids = batch[3].to(self.device) + output_attention = batch[4].to(self.device) + user_idx = int(batch[5][0]) + positive = testloader.dataset.positive[testloader.dataset.id2user[user_idx]] + + user_candidate = candidates - positive + + candidate_trie = gt.Trie( + [ + [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") + for candidate in user_candidate + ] + ) + prefix_allowed_tokens = gt.prefix_allowed_tokens_fn(candidate_trie) + + prediction = self.model.module.generate( + input_ids=input_ids, + attention_mask=attn, + whole_word_ids=whole_input_ids, + max_length=30, + prefix_allowed_tokens_fn=prefix_allowed_tokens, + num_beams=self.generate_num, + num_return_sequences=self.generate_num, + output_scores=True, + return_dict_in_generate=True, + ) + + prediction_ids = prediction["sequences"] + prediction_scores = prediction["sequences_scores"] + + gold_sents = self.tokenizer.batch_decode( + output_ids, skip_special_tokens=True + ) + generated_sents = self.tokenizer.batch_decode( + prediction_ids, skip_special_tokens=True + ) + + rel_results = evaluate.rel_results(generated_sents, gold_sents, prediction_scores, self.generate_num) + + test_total += len(rel_results) + + metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) + + dist.barrier() + metrics_res = torch.tensor(metrics_res).to(self.device) + test_total = torch.tensor(test_total).to(self.device) + dist.all_reduce(metrics_res, op=dist.ReduceOp.SUM) + dist.all_reduce(test_total, op=dist.ReduceOp.SUM) + + metrics_res /= test_total + if self.rank == 0: + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') def test_dataset_task(self, testloader): if self.rank == 0: @@ -196,7 +344,6 @@ def test_dataset_task(self, testloader): candidates = testloader.dataset.all_items candidate_trie = gt.Trie( [ - # [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item {candidate}") [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") for candidate in candidates ] @@ -215,7 +362,7 @@ def test_dataset_task(self, testloader): input_ids=input_ids, attention_mask=attn, whole_word_ids=whole_input_ids, - max_length=8, + max_length=50, prefix_allowed_tokens_fn=prefix_allowed_tokens, num_beams=self.generate_num, num_return_sequences=self.generate_num, diff --git a/src/runner/SingleRunner.py b/src/runner/SingleRunner.py index 13bea5a..62ee226 100644 --- a/src/runner/SingleRunner.py +++ b/src/runner/SingleRunner.py @@ -6,7 +6,7 @@ import utils.generation_trie as gt from data.TestDataset import TestDataset from torch.utils.data import DataLoader -from processor.Collator import Collator +from processor.Collator import Collator, TestCollator import time import pdb @@ -34,6 +34,8 @@ def parse_runner_args(parser): parser.add_argument("--test_epoch", type=int, default=1, help='test once for how many epochs, 0 for no test during training.') parser.add_argument("--valid_select", type=int, default=0, help='use validation loss to select models') parser.add_argument("--test_before_train", type=int, default=1, help='whether test before training') + parser.add_argument("--test_filtered", type=int, default=0, help='whether filter out the items in the training data.') + parser.add_argument("--test_filtered_batch", type=int, default=1, help='whether testing with filtered data in batch.') return parser @@ -49,6 +51,8 @@ def __init__(self, model, tokenizer, train_loader, valid_loader, device, args): self.test_epoch = self.args.test_epoch self.valid_select = self.args.valid_select self.test_before_train = self.args.test_before_train + self.test_filtered = self.args.test_filtered + self.test_filtered_batch = self.args.test_filtered_batch self.get_testloader() @@ -108,7 +112,7 @@ def train(self): self.optimizer.step() self.scheduler.step() self.model.zero_grad() - losses.append(loss.detach()) + losses.append(loss) train_epoch_loss = sum(losses)/len(losses) train_losses.append(train_epoch_loss) logging.info(f"The average training loss for epoch {epoch+1} is {train_epoch_loss}") @@ -143,7 +147,7 @@ def train(self): loss = loss.view(B, L) * lm_mask loss = (loss.sum(dim=1) / lm_mask.sum(dim=1).clamp(min=1)).mean() - losses.append(loss.detach()) + losses.append(loss) valid_epoch_loss = sum(losses)/len(losses) valid_losses.append(valid_epoch_loss) logging.info(f"The average valid loss for epoch {epoch+1} is {valid_epoch_loss}") @@ -218,22 +222,156 @@ def get_testloader(self): self.testloaders = [] datasets = self.args.datasets.split(',') tasks = self.args.tasks.split(',') - collator = Collator(self.tokenizer) + if self.test_filtered > 0: + collator = TestCollator(self.tokenizer) + else: + collator = Collator(self.tokenizer) for dataset in datasets: for task in tasks: testdata = TestDataset(self.args, dataset, task) testloader = DataLoader(dataset=testdata, batch_size=self.args.eval_batch_size, collate_fn=collator, shuffle=False) self.testloaders.append(testloader) + def test(self, path=None): self.model.eval() if path: self.model.load_state_dict(torch.load(path, map_location=self.device)) for loader in self.testloaders: - self.test_dataset_task(loader) + if self.test_filtered > 0: + if self.test_filtered_batch > 0: + self.test_dataset_task_filtered_batch(loader) + else: + assert self.args.eval_batch_size == 1 + self.test_dataset_task_filtered(loader) + else: + self.test_dataset_task(loader) + + + def test_dataset_task_filtered_batch(self, testloader): + logging.info(f'testing filtered {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') + test_total = 0 + with torch.no_grad(): + candidates = testloader.dataset.all_items + candidate_trie = gt.Trie( + [ + [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") + for candidate in candidates + ] + ) + prefix_allowed_tokens = gt.prefix_allowed_tokens_fn(candidate_trie) + + metrics_res = np.array([0.0] * len(self.metrics)) + for batch in tqdm(testloader): + input_ids = batch[0].to(self.device) + attn = batch[1].to(self.device) + whole_input_ids = batch[2].to(self.device) + output_ids = batch[3].to(self.device) + output_attention = batch[4].to(self.device) + user_idx = batch[5].to(self.device) - - + prediction = self.model.module.generate( + input_ids=input_ids, + attention_mask=attn, + whole_word_ids=whole_input_ids, + max_length=30, + prefix_allowed_tokens_fn=prefix_allowed_tokens, + num_beams=self.generate_num + testloader.dataset.max_positive, + num_return_sequences=self.generate_num + testloader.dataset.max_positive, + output_scores=True, + return_dict_in_generate=True, + ) + + prediction_ids = prediction["sequences"] + prediction_scores = prediction["sequences_scores"] + + gold_sents = self.tokenizer.batch_decode( + output_ids, skip_special_tokens=True + ) + generated_sents = self.tokenizer.batch_decode( + prediction_ids, skip_special_tokens=True + ) + + rel_results = evaluate.rel_results_filtered(testloader.dataset.positive, testloader.dataset.id2user, user_idx, \ + self.generate_num+testloader.dataset.max_positive, \ + generated_sents, gold_sents, prediction_scores, self.generate_num) + + test_total += len(rel_results) + + metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) + + metrics_res = torch.tensor(metrics_res).to(self.device) + test_total = torch.tensor(test_total).to(self.device) + + metrics_res /= test_total + + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') + + def test_dataset_task_filtered(self, testloader): + logging.info(f'testing filtered {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') + test_total = 0 + with torch.no_grad(): + candidates = set(testloader.dataset.all_items) + + + metrics_res = np.array([0.0] * len(self.metrics)) + for batch in tqdm(testloader): + input_ids = batch[0].to(self.device) + attn = batch[1].to(self.device) + whole_input_ids = batch[2].to(self.device) + output_ids = batch[3].to(self.device) + output_attention = batch[4].to(self.device) + user_idx = int(batch[5][0]) + positive = testloader.dataset.positive[testloader.dataset.id2user[user_idx]] + + user_candidate = candidates - positive + + candidate_trie = gt.Trie( + [ + [0] + self.tokenizer.encode(f"{testloader.dataset.dataset} item_{candidate}") + for candidate in user_candidate + ] + ) + prefix_allowed_tokens = gt.prefix_allowed_tokens_fn(candidate_trie) + + prediction = self.model.module.generate( + input_ids=input_ids, + attention_mask=attn, + whole_word_ids=whole_input_ids, + max_length=30, + prefix_allowed_tokens_fn=prefix_allowed_tokens, + num_beams=self.generate_num, + num_return_sequences=self.generate_num, + output_scores=True, + return_dict_in_generate=True, + ) + + prediction_ids = prediction["sequences"] + prediction_scores = prediction["sequences_scores"] + + gold_sents = self.tokenizer.batch_decode( + output_ids, skip_special_tokens=True + ) + generated_sents = self.tokenizer.batch_decode( + prediction_ids, skip_special_tokens=True + ) + + rel_results = evaluate.rel_results(generated_sents, gold_sents, prediction_scores, self.generate_num) + + test_total += len(rel_results) + + metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) + + metrics_res = torch.tensor(metrics_res).to(self.device) + test_total = torch.tensor(test_total).to(self.device) + + metrics_res /= test_total + + + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') + def test_dataset_task(self, testloader): logging.info(f'testing {testloader.dataset.dataset} dataset on {testloader.dataset.task} task') test_total = 0 @@ -259,7 +397,7 @@ def test_dataset_task(self, testloader): input_ids=input_ids, attention_mask=attn, whole_word_ids=whole_input_ids, - max_length=8, + max_length=30, prefix_allowed_tokens_fn=prefix_allowed_tokens, num_beams=self.generate_num, num_return_sequences=self.generate_num, @@ -285,14 +423,10 @@ def test_dataset_task(self, testloader): metrics_res += evaluate.get_metrics_results(rel_results, self.metrics) - dist.barrier() metrics_res = torch.tensor(metrics_res).to(self.device) test_total = torch.tensor(test_total).to(self.device) - dist.all_reduce(metrics_res, op=dist.ReduceOp.SUM) - dist.all_reduce(test_total, op=dist.ReduceOp.SUM) metrics_res /= test_total - if self.rank == 0: - for i in range(len(self.metrics)): - logging.info(f'{self.metrics[i]}: {metrics_res[i]}') + for i in range(len(self.metrics)): + logging.info(f'{self.metrics[i]}: {metrics_res[i]}') \ No newline at end of file diff --git a/src/runner/__pycache__/DistributedRunner.cpython-39.pyc b/src/runner/__pycache__/DistributedRunner.cpython-39.pyc index 68bb8a1..eb5c801 100644 Binary files a/src/runner/__pycache__/DistributedRunner.cpython-39.pyc and b/src/runner/__pycache__/DistributedRunner.cpython-39.pyc differ diff --git a/src/runner/__pycache__/SingleRunner.cpython-39.pyc b/src/runner/__pycache__/SingleRunner.cpython-39.pyc index 2bc4e81..dd63f71 100644 Binary files a/src/runner/__pycache__/SingleRunner.cpython-39.pyc and b/src/runner/__pycache__/SingleRunner.cpython-39.pyc differ diff --git a/src/utils/.ipynb_checkpoints/evaluate-checkpoint.py b/src/utils/.ipynb_checkpoints/evaluate-checkpoint.py index 383865b..10adf8c 100644 --- a/src/utils/.ipynb_checkpoints/evaluate-checkpoint.py +++ b/src/utils/.ipynb_checkpoints/evaluate-checkpoint.py @@ -3,7 +3,36 @@ import random - +def rel_results_filtered(user_positive, id2user, user_idx, return_num, predictions, targets, scores, k): + results = [] + batch_length = len(targets) + for b in range(batch_length): + uidx = user_idx[b] + user_id = id2user[uidx] + positive = user_positive[user_id] + one_batch_sequence = predictions[ + b * return_num : (b + 1) * return_num + ] + one_batch_score = scores[ + b * return_num : (b + 1) * return_num + ] + pairs = [(a, b) for a, b in zip(one_batch_sequence, one_batch_score)] + sorted_pairs = sorted(pairs, key=lambda x: x[1], reverse=True) + gt = targets[b] + one_results = [] + for sorted_pred in sorted_pairs: + if sorted_pred[0] not in positive: + if sorted_pred[0] == gt: + one_results.append(1) + else: + one_results.append(0) + if len(one_results) >= k: + break + else: + continue + + results.append(one_results) + return results def rel_results(predictions, targets, scores, k): results = [] diff --git a/src/utils/.ipynb_checkpoints/indexing-checkpoint.py b/src/utils/.ipynb_checkpoints/indexing-checkpoint.py index 6aee010..2eefdaa 100644 --- a/src/utils/.ipynb_checkpoints/indexing-checkpoint.py +++ b/src/utils/.ipynb_checkpoints/indexing-checkpoint.py @@ -5,6 +5,7 @@ from utils import utils from collections import defaultdict import os +from scipy.sparse import csr_matrix import pdb def sequential_indexing(data_path, dataset, user_sequence_dict, order): @@ -108,13 +109,13 @@ def random_indexing(data_path, dataset, user_sequence_dict): utils.WriteDictToFile(reindex_sequence_file, reindex_user_sequence_dict) return reindex_user_sequence_dict, item_map -def collaborative_indexing(data_path, dataset, user_sequence_dict, token_size, cluster_num): +def collaborative_indexing(data_path, dataset, user_sequence_dict, token_size, cluster_num, last_token, float32): """ Use collaborative indexing method to index the given user seuqnece dict. """ user_index_file = os.path.join(data_path, dataset, 'user_indexing.txt') - item_index_file = os.path.join(data_path, dataset, f'item_collaborative_indexing_{token_size}_{cluster_num}.txt') - reindex_sequence_file = os.path.join(data_path, dataset, f'user_sequence_collaborative_indexing_{token_size}_{cluster_num}.txt') + item_index_file = os.path.join(data_path, dataset, f'item_collaborative_indexing_{token_size}_{cluster_num}_{last_token}.txt') + reindex_sequence_file = os.path.join(data_path, dataset, f'user_sequence_collaborative_indexing_{token_size}_{cluster_num}_{last_token}.txt') if os.path.exists(reindex_sequence_file): user_sequence = utils.ReadLineFromFile(reindex_sequence_file) @@ -138,16 +139,14 @@ def collaborative_indexing(data_path, dataset, user_sequence_dict, token_size, c item_info = utils.ReadLineFromFile(item_index_file) item_map = get_dict_from_lines(item_info) else: - item_map = generate_collaborative_id(user_sequence_dict, token_size, cluster_num) + item_map = generate_collaborative_id(user_sequence_dict, token_size, cluster_num, last_token, float32) utils.WriteDictToFile(item_index_file, item_map) reindex_user_sequence_dict = reindex(user_sequence_dict, user_map, item_map) utils.WriteDictToFile(reindex_sequence_file, reindex_user_sequence_dict) return reindex_user_sequence_dict, item_map - - -def generate_collaborative_id(user_sequence_dict, token_size, cluster_num): +def generate_collaborative_id(user_sequence_dict, token_size, cluster_num, last_token, float32): """ Generate collaborative index for items. """ @@ -167,7 +166,10 @@ def generate_collaborative_id(user_sequence_dict, token_size, cluster_num): # calculate the co-occurrence of items in the training data as an adjacency matrix - adj_matrix = np.zeros((len(item2id), len(item2id))) + if float32 > 0: + adj_matrix = np.zeros((len(item2id), len(item2id)), dtype=np.float32) + else: + adj_matrix = np.zeros((len(item2id), len(item2id))) for user in user_sequence_dict: interactions = user_sequence_dict[user][:-2] for pairs in combinations(interactions, 2): @@ -207,13 +209,20 @@ def generate_collaborative_id(user_sequence_dict, token_size, cluster_num): # if current group is small enough, add the last token to item indexing if len(group_items) <= token_size: item_list = [items[0] for items in group_items] - item_map = add_last_token_to_indexing(item_map, item_list, token_size) + if last_token == 'sequential': + item_map = add_last_token_to_indexing_sequential(item_map, item_list, token_size) + elif last_token == 'random': + item_map = add_last_token_to_indexing_random(item_map, item_list, token_size) else: # calculate the adjacency matrix for current group - sub_adj_matrix = np.zeros((len(group_items), len(group_items))) + if float32 > 0: + sub_adj_matrix = np.zeros((len(group_items), len(group_items)), dtype=np.float32) + else: + sub_adj_matrix = np.zeros((len(group_items), len(group_items))) for i in range(len(group_items)): for j in range(i+1, len(group_items)): sub_adj_matrix[i][j] = adj_matrix[group_items[i][1]][group_items[j][1]] + sub_adj_matrix[j][i] = adj_matrix[group_items[j][1]][group_items[i][1]] # get the clustering results for current group clustering = SpectralClustering( @@ -239,7 +248,10 @@ def generate_collaborative_id(user_sequence_dict, token_size, cluster_num): # if some items are not in the training data, assign an index for them remaining_items = list(all_items - train_items) if len(remaining_items) > 0: - add_last_token_to_indexing(item_map, remaining_items, token_size) + if last_token == 'sequential': + item_map = add_last_token_to_indexing_sequential(item_map, remaining_items, token_size) + elif last_token == 'random': + item_map = add_last_token_to_indexing_random(item_map, remaining_items, token_size) return item_map @@ -255,7 +267,7 @@ def add_token_to_indexing(item_map, grouping, index_now, token_size): index_now += 1 return item_map, index_now -def add_last_token_to_indexing(item_map, item_list, token_size): +def add_last_token_to_indexing_random(item_map, item_list, token_size): last_tokens = random.sample([i for i in range(token_size)], len(item_list)) for i in range(len(item_list)): item = item_list[i] @@ -263,6 +275,14 @@ def add_last_token_to_indexing(item_map, item_list, token_size): item_map[item] = '' item_map[item] += f'' return item_map + +def add_last_token_to_indexing_sequential(item_map, item_list, token_size): + for i in range(len(item_list)): + item = item_list[i] + if item not in item_map: + item_map[item] = '' + item_map[item] += f'' + return item_map def get_dict_from_lines(lines): diff --git a/src/utils/.ipynb_checkpoints/utils-checkpoint.py b/src/utils/.ipynb_checkpoints/utils-checkpoint.py index 4c89dbd..846b353 100644 --- a/src/utils/.ipynb_checkpoints/utils-checkpoint.py +++ b/src/utils/.ipynb_checkpoints/utils-checkpoint.py @@ -12,6 +12,8 @@ def parse_global_args(parser): parser.add_argument("--seed", type=int, default=2023, help="Random seed") parser.add_argument("--model_dir", type=str, default='../model', help='The model directory') + parser.add_argument("--checkpoint_dir", type=str, default='../checkpoint', help='The checkpoint directory') + parser.add_argument("--model_name", type=str, default='model.pt', help='The model name') parser.add_argument("--log_dir", type=str, default='../log', help='The log directory') parser.add_argument("--distributed", type=int, default=1, help='use distributed data parallel or not.') parser.add_argument("--gpu", type=str, default='0,1,2,3', help='gpu ids, if not distributed, only use the first one.') @@ -75,10 +77,14 @@ def get_init_paras_dict(class_name, paras_dict): def setup_logging(args): args.log_name = log_name(args) - folder = os.path.join(args.log_dir, args.datasets) + if len(args.datasets.split(',')) > 1: + folder_name = 'SP5' + else: + folder_name = args.datasets + folder = os.path.join(args.log_dir, folder_name) if not os.path.exists(folder): os.makedirs(folder) - log_file = os.path.join(args.log_dir, args.datasets, args.log_name + '.log') + log_file = os.path.join(args.log_dir, folder_name, args.log_name + '.log') for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) @@ -89,14 +95,25 @@ def setup_logging(args): def log_name(args): - params = [str(args.distributed), str(args.sample_prompt), str(args.his_prefix), str(args.skip_empty_his), str(args.max_his), str(args.master_port), args.datasets, args.tasks, args.backbone, args.item_indexing, str(args.lr), str(args.epochs), str(args.batch_size), args.sample_num, args.prompt_file[3:-4]] + if len(args.datasets.split(',')) > 1: + folder_name = 'SP5' + else: + folder_name = args.datasets + params = [str(args.distributed), str(args.sample_prompt), str(args.his_prefix), str(args.skip_empty_his), str(args.max_his), str(args.master_port), folder_name, args.tasks, args.backbone, args.item_indexing, str(args.lr), str(args.epochs), str(args.batch_size), args.sample_num, args.prompt_file[3:-4]] return '_'.join(params) def setup_model_path(args): - model_path = os.path.join(args.model_dir, args.datasets) - if not os.path.exists(model_path): - os.makedirs(model_path) - args.model_path = os.path.join(model_path, args.log_name+'.pt') + if len(args.datasets.split(',')) > 1: + folder_name = 'SP5' + else: + folder_name = args.datasets + if args.model_name == 'model.pt': + model_path = os.path.join(args.model_dir, folder_name) + if not os.path.exists(model_path): + os.makedirs(model_path) + args.model_path = os.path.join(model_path, args.log_name+'.pt') + else: + args.model_path = os.path.join(args.checkpoint_dir, args.model_name) return def save_model(mode, path): diff --git a/src/utils/__pycache__/evaluate.cpython-39.pyc b/src/utils/__pycache__/evaluate.cpython-39.pyc index 99f0dd7..7de0f9d 100644 Binary files a/src/utils/__pycache__/evaluate.cpython-39.pyc and b/src/utils/__pycache__/evaluate.cpython-39.pyc differ diff --git a/src/utils/__pycache__/indexing.cpython-39.pyc b/src/utils/__pycache__/indexing.cpython-39.pyc index 3791c48..0de7a3d 100644 Binary files a/src/utils/__pycache__/indexing.cpython-39.pyc and b/src/utils/__pycache__/indexing.cpython-39.pyc differ diff --git a/src/utils/__pycache__/utils.cpython-39.pyc b/src/utils/__pycache__/utils.cpython-39.pyc index 90a3e59..2ab5a77 100644 Binary files a/src/utils/__pycache__/utils.cpython-39.pyc and b/src/utils/__pycache__/utils.cpython-39.pyc differ diff --git a/src/utils/evaluate.py b/src/utils/evaluate.py index 383865b..10adf8c 100644 --- a/src/utils/evaluate.py +++ b/src/utils/evaluate.py @@ -3,7 +3,36 @@ import random - +def rel_results_filtered(user_positive, id2user, user_idx, return_num, predictions, targets, scores, k): + results = [] + batch_length = len(targets) + for b in range(batch_length): + uidx = user_idx[b] + user_id = id2user[uidx] + positive = user_positive[user_id] + one_batch_sequence = predictions[ + b * return_num : (b + 1) * return_num + ] + one_batch_score = scores[ + b * return_num : (b + 1) * return_num + ] + pairs = [(a, b) for a, b in zip(one_batch_sequence, one_batch_score)] + sorted_pairs = sorted(pairs, key=lambda x: x[1], reverse=True) + gt = targets[b] + one_results = [] + for sorted_pred in sorted_pairs: + if sorted_pred[0] not in positive: + if sorted_pred[0] == gt: + one_results.append(1) + else: + one_results.append(0) + if len(one_results) >= k: + break + else: + continue + + results.append(one_results) + return results def rel_results(predictions, targets, scores, k): results = [] diff --git a/src/utils/indexing.py b/src/utils/indexing.py index 69d3755..2eefdaa 100644 --- a/src/utils/indexing.py +++ b/src/utils/indexing.py @@ -5,6 +5,7 @@ from utils import utils from collections import defaultdict import os +from scipy.sparse import csr_matrix import pdb def sequential_indexing(data_path, dataset, user_sequence_dict, order): @@ -108,7 +109,7 @@ def random_indexing(data_path, dataset, user_sequence_dict): utils.WriteDictToFile(reindex_sequence_file, reindex_user_sequence_dict) return reindex_user_sequence_dict, item_map -def collaborative_indexing(data_path, dataset, user_sequence_dict, token_size, cluster_num, last_token): +def collaborative_indexing(data_path, dataset, user_sequence_dict, token_size, cluster_num, last_token, float32): """ Use collaborative indexing method to index the given user seuqnece dict. """ @@ -138,16 +139,14 @@ def collaborative_indexing(data_path, dataset, user_sequence_dict, token_size, c item_info = utils.ReadLineFromFile(item_index_file) item_map = get_dict_from_lines(item_info) else: - item_map = generate_collaborative_id(user_sequence_dict, token_size, cluster_num, last_token) + item_map = generate_collaborative_id(user_sequence_dict, token_size, cluster_num, last_token, float32) utils.WriteDictToFile(item_index_file, item_map) reindex_user_sequence_dict = reindex(user_sequence_dict, user_map, item_map) utils.WriteDictToFile(reindex_sequence_file, reindex_user_sequence_dict) return reindex_user_sequence_dict, item_map - - -def generate_collaborative_id(user_sequence_dict, token_size, cluster_num, last_token): +def generate_collaborative_id(user_sequence_dict, token_size, cluster_num, last_token, float32): """ Generate collaborative index for items. """ @@ -167,7 +166,10 @@ def generate_collaborative_id(user_sequence_dict, token_size, cluster_num, last_ # calculate the co-occurrence of items in the training data as an adjacency matrix - adj_matrix = np.zeros((len(item2id), len(item2id))) + if float32 > 0: + adj_matrix = np.zeros((len(item2id), len(item2id)), dtype=np.float32) + else: + adj_matrix = np.zeros((len(item2id), len(item2id))) for user in user_sequence_dict: interactions = user_sequence_dict[user][:-2] for pairs in combinations(interactions, 2): @@ -213,10 +215,14 @@ def generate_collaborative_id(user_sequence_dict, token_size, cluster_num, last_ item_map = add_last_token_to_indexing_random(item_map, item_list, token_size) else: # calculate the adjacency matrix for current group - sub_adj_matrix = np.zeros((len(group_items), len(group_items))) + if float32 > 0: + sub_adj_matrix = np.zeros((len(group_items), len(group_items)), dtype=np.float32) + else: + sub_adj_matrix = np.zeros((len(group_items), len(group_items))) for i in range(len(group_items)): for j in range(i+1, len(group_items)): sub_adj_matrix[i][j] = adj_matrix[group_items[i][1]][group_items[j][1]] + sub_adj_matrix[j][i] = adj_matrix[group_items[j][1]][group_items[i][1]] # get the clustering results for current group clustering = SpectralClustering( diff --git a/src/utils/utils.py b/src/utils/utils.py index 4c89dbd..846b353 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -12,6 +12,8 @@ def parse_global_args(parser): parser.add_argument("--seed", type=int, default=2023, help="Random seed") parser.add_argument("--model_dir", type=str, default='../model', help='The model directory') + parser.add_argument("--checkpoint_dir", type=str, default='../checkpoint', help='The checkpoint directory') + parser.add_argument("--model_name", type=str, default='model.pt', help='The model name') parser.add_argument("--log_dir", type=str, default='../log', help='The log directory') parser.add_argument("--distributed", type=int, default=1, help='use distributed data parallel or not.') parser.add_argument("--gpu", type=str, default='0,1,2,3', help='gpu ids, if not distributed, only use the first one.') @@ -75,10 +77,14 @@ def get_init_paras_dict(class_name, paras_dict): def setup_logging(args): args.log_name = log_name(args) - folder = os.path.join(args.log_dir, args.datasets) + if len(args.datasets.split(',')) > 1: + folder_name = 'SP5' + else: + folder_name = args.datasets + folder = os.path.join(args.log_dir, folder_name) if not os.path.exists(folder): os.makedirs(folder) - log_file = os.path.join(args.log_dir, args.datasets, args.log_name + '.log') + log_file = os.path.join(args.log_dir, folder_name, args.log_name + '.log') for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) @@ -89,14 +95,25 @@ def setup_logging(args): def log_name(args): - params = [str(args.distributed), str(args.sample_prompt), str(args.his_prefix), str(args.skip_empty_his), str(args.max_his), str(args.master_port), args.datasets, args.tasks, args.backbone, args.item_indexing, str(args.lr), str(args.epochs), str(args.batch_size), args.sample_num, args.prompt_file[3:-4]] + if len(args.datasets.split(',')) > 1: + folder_name = 'SP5' + else: + folder_name = args.datasets + params = [str(args.distributed), str(args.sample_prompt), str(args.his_prefix), str(args.skip_empty_his), str(args.max_his), str(args.master_port), folder_name, args.tasks, args.backbone, args.item_indexing, str(args.lr), str(args.epochs), str(args.batch_size), args.sample_num, args.prompt_file[3:-4]] return '_'.join(params) def setup_model_path(args): - model_path = os.path.join(args.model_dir, args.datasets) - if not os.path.exists(model_path): - os.makedirs(model_path) - args.model_path = os.path.join(model_path, args.log_name+'.pt') + if len(args.datasets.split(',')) > 1: + folder_name = 'SP5' + else: + folder_name = args.datasets + if args.model_name == 'model.pt': + model_path = os.path.join(args.model_dir, folder_name) + if not os.path.exists(model_path): + os.makedirs(model_path) + args.model_path = os.path.join(model_path, args.log_name+'.pt') + else: + args.model_path = os.path.join(args.checkpoint_dir, args.model_name) return def save_model(mode, path): diff --git a/test_command/.ipynb_checkpoints/Beauty_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/Beauty_collaborative-checkpoint.sh new file mode 100644 index 0000000..15fbc5c --- /dev/null +++ b/test_command/.ipynb_checkpoints/Beauty_collaborative-checkpoint.sh @@ -0,0 +1,7 @@ +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3,4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 64 --master_port 1235 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --collaborative_token_size 100 --train 0 --model_name Beauty_collaborative.pt --test_filtered 1 --test_filtered_batch 0 + +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3,4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 64 --master_port 1235 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt unseen:0 --lr 1e-3 --collaborative_token_size 100 --train 0 --model_name Beauty_collaborative.pt --test_filtered 1 --test_filtered_batch 0 + + + +# wiser -r 9 \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Beauty_random-checkpoint.sh b/test_command/.ipynb_checkpoints/Beauty_random-checkpoint.sh new file mode 100644 index 0000000..e7db98b --- /dev/null +++ b/test_command/.ipynb_checkpoints/Beauty_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --train 0 --model_name Beauty_random.pt + +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --train 0 --model_name Beauty_random.pt diff --git a/test_command/.ipynb_checkpoints/Beauty_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/Beauty_sequential-checkpoint.sh new file mode 100644 index 0000000..81795fb --- /dev/null +++ b/test_command/.ipynb_checkpoints/Beauty_sequential-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --train 0 --model_name Beauty_sequential.pt + +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --train 0 --model_name Beauty_sequential.pt diff --git a/test_command/.ipynb_checkpoints/CDs_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/CDs_collaborative-checkpoint.sh new file mode 100644 index 0000000..bb1f72f --- /dev/null +++ b/test_command/.ipynb_checkpoints/CDs_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --train 0 --test_filtered 0 --model_name CDs_collaborative.pt + +python ../src/main.py --datasets CDs --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --train 0 --test_filtered 0 --model_name CDs_collaborative.pt diff --git a/test_command/.ipynb_checkpoints/CDs_random-checkpoint.sh b/test_command/.ipynb_checkpoints/CDs_random-checkpoint.sh new file mode 100644 index 0000000..f188e82 --- /dev/null +++ b/test_command/.ipynb_checkpoints/CDs_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name CDs_random.pt + +python ../src/main.py --datasets CDs --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name CDs_random.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/CDs_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/CDs_sequential-checkpoint.sh new file mode 100644 index 0000000..8287f27 --- /dev/null +++ b/test_command/.ipynb_checkpoints/CDs_sequential-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name CDs_sequential.pt + +python ../src/main.py --datasets CDs --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name CDs_sequential.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Clothing_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/Clothing_collaborative-checkpoint.sh new file mode 100644 index 0000000..33136fd --- /dev/null +++ b/test_command/.ipynb_checkpoints/Clothing_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Clothing_collaborative.pt + +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Clothing_collaborative.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Clothing_random-checkpoint.sh b/test_command/.ipynb_checkpoints/Clothing_random-checkpoint.sh new file mode 100644 index 0000000..4ec8caf --- /dev/null +++ b/test_command/.ipynb_checkpoints/Clothing_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Clothing_random.pt + +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Clothing_random.pt diff --git a/test_command/.ipynb_checkpoints/Clothing_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/Clothing_sequential-checkpoint.sh new file mode 100644 index 0000000..62927eb --- /dev/null +++ b/test_command/.ipynb_checkpoints/Clothing_sequential-checkpoint.sh @@ -0,0 +1,4 @@ +# python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1124 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_filtered 0 --model_name Clothing_sequential.pt + +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1124 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_filtered 0 --model_name Clothing_sequential.pt + diff --git a/test_command/.ipynb_checkpoints/Electronics_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/Electronics_collaborative-checkpoint.sh new file mode 100644 index 0000000..75d94e9 --- /dev/null +++ b/test_command/.ipynb_checkpoints/Electronics_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2009 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Electronics_collaborative.pt + +python ../src/main.py --datasets Electronics --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2009 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Electronics_collaborative.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Electronics_random-checkpoint.sh b/test_command/.ipynb_checkpoints/Electronics_random-checkpoint.sh new file mode 100644 index 0000000..c9e3df6 --- /dev/null +++ b/test_command/.ipynb_checkpoints/Electronics_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Electronics_random.pt + +python ../src/main.py --datasets Electronics --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Electronics_random.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Electronics_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/Electronics_sequential-checkpoint.sh new file mode 100644 index 0000000..4a4fd70 --- /dev/null +++ b/test_command/.ipynb_checkpoints/Electronics_sequential-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_filtered 0 --model_name Electronics_sequential.pt + +python ../src/main.py --datasets Electronics --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_filtered 0 --model_name Electronics_sequential.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/LastFM_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/LastFM_collaborative-checkpoint.sh new file mode 100644 index 0000000..1fad1dd --- /dev/null +++ b/test_command/.ipynb_checkpoints/LastFM_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 128 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name LastFM_collaborative.pt + +python ../src/main.py --datasets LastFM --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 128 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_collaborative.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/LastFM_random-checkpoint.sh b/test_command/.ipynb_checkpoints/LastFM_random-checkpoint.sh new file mode 100644 index 0000000..de6b8e5 --- /dev/null +++ b/test_command/.ipynb_checkpoints/LastFM_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_random.pt + +python ../src/main.py --datasets LastFM --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_random.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/LastFM_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/LastFM_sequential-checkpoint.sh new file mode 100644 index 0000000..e47f6d2 --- /dev/null +++ b/test_command/.ipynb_checkpoints/LastFM_sequential-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_sequential.pt + +python ../src/main.py --datasets LastFM --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_sequential.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/ML100K_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/ML100K_collaborative-checkpoint.sh new file mode 100644 index 0000000..b6b5be8 --- /dev/null +++ b/test_command/.ipynb_checkpoints/ML100K_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name ML100K_collaborative.pt + +python ../src/main.py --datasets ML100K --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name ML100K_collaborative.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/ML100K_random-checkpoint.sh b/test_command/.ipynb_checkpoints/ML100K_random-checkpoint.sh new file mode 100644 index 0000000..e3f6777 --- /dev/null +++ b/test_command/.ipynb_checkpoints/ML100K_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1998 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name ML100K_random.pt + +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1998 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name ML100K_random.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/ML100K_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/ML100K_sequential-checkpoint.sh new file mode 100644 index 0000000..a070643 --- /dev/null +++ b/test_command/.ipynb_checkpoints/ML100K_sequential-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1998 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name ML100K_sequential.pt + +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1998 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name ML100K_sequential.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/ML1M_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/ML1M_collaborative-checkpoint.sh new file mode 100644 index 0000000..2037064 --- /dev/null +++ b/test_command/.ipynb_checkpoints/ML1M_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 20 --train 0 --model_name ML1M_collaborative.pt + +python ../src/main.py --datasets ML1M --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 20 --train 0 --model_name ML1M_collaborative.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/ML1M_random-checkpoint.sh b/test_command/.ipynb_checkpoints/ML1M_random-checkpoint.sh new file mode 100644 index 0000000..76b5b77 --- /dev/null +++ b/test_command/.ipynb_checkpoints/ML1M_random-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 1 --test_filtered_batch 0 --model_name ML1M_random.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/ML1M_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/ML1M_sequential-checkpoint.sh new file mode 100644 index 0000000..3c83274 --- /dev/null +++ b/test_command/.ipynb_checkpoints/ML1M_sequential-checkpoint.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 1984 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 1 --test_filtered_batch 0 --model_name ML1M_sequential.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Movies_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/Movies_collaborative-checkpoint.sh new file mode 100644 index 0000000..4b83d2f --- /dev/null +++ b/test_command/.ipynb_checkpoints/Movies_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2010 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Movies_collaborative.pt + +python ../src/main.py --datasets Movies --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2010 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Movies_collaborative.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Movies_random-checkpoint.sh b/test_command/.ipynb_checkpoints/Movies_random-checkpoint.sh new file mode 100644 index 0000000..16d445f --- /dev/null +++ b/test_command/.ipynb_checkpoints/Movies_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Movies_random.pt + +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Movies_random.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Movies_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/Movies_sequential-checkpoint.sh new file mode 100644 index 0000000..e380e27 --- /dev/null +++ b/test_command/.ipynb_checkpoints/Movies_sequential-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_filtered 0 --model_name Movies_sequential.pt + +python ../src/main.py --datasets Movies --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_filtered 0 --model_name Movies_sequential.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/SP5_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/SP5_collaborative-checkpoint.sh new file mode 100644 index 0000000..65e6d98 --- /dev/null +++ b/test_command/.ipynb_checkpoints/SP5_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2018 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --train 0 --model_name SP5_collaborative.pt --test_filtered 0 + +python ../src/main.py --datasets ML1M,LastFM,Beauty,Yelp,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --train 0 --model_name SP5_collaborative.pt --test_filtered 0 \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/SP5_random-checkpoint.sh b/test_command/.ipynb_checkpoints/SP5_random-checkpoint.sh new file mode 100644 index 0000000..d093764 --- /dev/null +++ b/test_command/.ipynb_checkpoints/SP5_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --test_filtered 0 + +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name SP5_random.pt --test_filtered 0 --test_filtered_batch 1 \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/SP5_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/SP5_sequential-checkpoint.sh new file mode 100644 index 0000000..4a3cabf --- /dev/null +++ b/test_command/.ipynb_checkpoints/SP5_sequential-checkpoint.sh @@ -0,0 +1,5 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name SP5_sequential.pt --test_filtered 0 + +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2018 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name SP5_sequential.pt --test_filtered 0 --test_filtered_batch 1 + +# ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Taobao_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/Taobao_collaborative-checkpoint.sh new file mode 100644 index 0000000..73c21ac --- /dev/null +++ b/test_command/.ipynb_checkpoints/Taobao_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name Taobao_collaborative.pt + +python ../src/main.py --datasets Taobao --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name Taobao_collaborative.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Taobao_random-checkpoint.sh b/test_command/.ipynb_checkpoints/Taobao_random-checkpoint.sh new file mode 100644 index 0000000..7fd6600 --- /dev/null +++ b/test_command/.ipynb_checkpoints/Taobao_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Taobao_random.pt + +python ../src/main.py --datasets Taobao --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Taobao_random.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Taobao_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/Taobao_sequential-checkpoint.sh new file mode 100644 index 0000000..5cd4d28 --- /dev/null +++ b/test_command/.ipynb_checkpoints/Taobao_sequential-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Taobao_sequential.pt + +python ../src/main.py --datasets Taobao --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Taobao_sequential.pt \ No newline at end of file diff --git a/test_command/.ipynb_checkpoints/Yelp_collaborative-checkpoint.sh b/test_command/.ipynb_checkpoints/Yelp_collaborative-checkpoint.sh new file mode 100644 index 0000000..3ff8ff3 --- /dev/null +++ b/test_command/.ipynb_checkpoints/Yelp_collaborative-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 0 --test_prompt seen:0 --lr 1e-3 --collaborative_token_size 500 --test_before_train 0 --test_epoch 0 --collaborative_float32 1 --test_filtered 0 --model_name Yelp_collaborative.pt + +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 0 --test_prompt unseen:0 --lr 1e-3 --collaborative_token_size 500 --test_before_train 0 --test_epoch 0 --collaborative_float32 1 --test_filtered 0 --model_name Yelp_collaborative.pt diff --git a/test_command/.ipynb_checkpoints/Yelp_random-checkpoint.sh b/test_command/.ipynb_checkpoints/Yelp_random-checkpoint.sh new file mode 100644 index 0000000..3a518f3 --- /dev/null +++ b/test_command/.ipynb_checkpoints/Yelp_random-checkpoint.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name Yelp_random.pt --test_filtered 0 + +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name Yelp_random.pt --test_filtered 0 diff --git a/test_command/.ipynb_checkpoints/Yelp_sequential-checkpoint.sh b/test_command/.ipynb_checkpoints/Yelp_sequential-checkpoint.sh new file mode 100644 index 0000000..e232f13 --- /dev/null +++ b/test_command/.ipynb_checkpoints/Yelp_sequential-checkpoint.sh @@ -0,0 +1,3 @@ +# python ../src/main.py --datasets Yelp --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --model_name Yelp_sequential.pt --test_filtered 0 + +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --model_name Yelp_sequential.pt --test_filtered 0 \ No newline at end of file diff --git a/test_command/Beauty_collaborative.sh b/test_command/Beauty_collaborative.sh new file mode 100644 index 0000000..15fbc5c --- /dev/null +++ b/test_command/Beauty_collaborative.sh @@ -0,0 +1,7 @@ +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3,4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 64 --master_port 1235 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --collaborative_token_size 100 --train 0 --model_name Beauty_collaborative.pt --test_filtered 1 --test_filtered_batch 0 + +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3,4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 64 --master_port 1235 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt unseen:0 --lr 1e-3 --collaborative_token_size 100 --train 0 --model_name Beauty_collaborative.pt --test_filtered 1 --test_filtered_batch 0 + + + +# wiser -r 9 \ No newline at end of file diff --git a/test_command/Beauty_random.sh b/test_command/Beauty_random.sh new file mode 100644 index 0000000..e7db98b --- /dev/null +++ b/test_command/Beauty_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --train 0 --model_name Beauty_random.pt + +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --train 0 --model_name Beauty_random.pt diff --git a/test_command/Beauty_sequential.sh b/test_command/Beauty_sequential.sh new file mode 100644 index 0000000..81795fb --- /dev/null +++ b/test_command/Beauty_sequential.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --train 0 --model_name Beauty_sequential.pt + +python ../src/main.py --datasets Beauty --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 2000 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --train 0 --model_name Beauty_sequential.pt diff --git a/test_command/CDs_collaborative.sh b/test_command/CDs_collaborative.sh new file mode 100644 index 0000000..bb1f72f --- /dev/null +++ b/test_command/CDs_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --train 0 --test_filtered 0 --model_name CDs_collaborative.pt + +python ../src/main.py --datasets CDs --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --train 0 --test_filtered 0 --model_name CDs_collaborative.pt diff --git a/test_command/CDs_random.sh b/test_command/CDs_random.sh new file mode 100644 index 0000000..f188e82 --- /dev/null +++ b/test_command/CDs_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name CDs_random.pt + +python ../src/main.py --datasets CDs --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name CDs_random.pt \ No newline at end of file diff --git a/test_command/CDs_sequential.sh b/test_command/CDs_sequential.sh new file mode 100644 index 0000000..8287f27 --- /dev/null +++ b/test_command/CDs_sequential.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets CDs --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name CDs_sequential.pt + +python ../src/main.py --datasets CDs --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name CDs_sequential.pt \ No newline at end of file diff --git a/test_command/Clothing_collaborative.sh b/test_command/Clothing_collaborative.sh new file mode 100644 index 0000000..33136fd --- /dev/null +++ b/test_command/Clothing_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Clothing_collaborative.pt + +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Clothing_collaborative.pt \ No newline at end of file diff --git a/test_command/Clothing_random.sh b/test_command/Clothing_random.sh new file mode 100644 index 0000000..4ec8caf --- /dev/null +++ b/test_command/Clothing_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Clothing_random.pt + +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Clothing_random.pt diff --git a/test_command/Clothing_sequential.sh b/test_command/Clothing_sequential.sh new file mode 100644 index 0000000..62927eb --- /dev/null +++ b/test_command/Clothing_sequential.sh @@ -0,0 +1,4 @@ +# python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1124 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_filtered 0 --model_name Clothing_sequential.pt + +python ../src/main.py --datasets Clothing --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1124 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_filtered 0 --model_name Clothing_sequential.pt + diff --git a/test_command/Electronics_collaborative.sh b/test_command/Electronics_collaborative.sh new file mode 100644 index 0000000..75d94e9 --- /dev/null +++ b/test_command/Electronics_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2009 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Electronics_collaborative.pt + +python ../src/main.py --datasets Electronics --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2009 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Electronics_collaborative.pt \ No newline at end of file diff --git a/test_command/Electronics_random.sh b/test_command/Electronics_random.sh new file mode 100644 index 0000000..c9e3df6 --- /dev/null +++ b/test_command/Electronics_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Electronics_random.pt + +python ../src/main.py --datasets Electronics --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Electronics_random.pt \ No newline at end of file diff --git a/test_command/Electronics_sequential.sh b/test_command/Electronics_sequential.sh new file mode 100644 index 0000000..4a4fd70 --- /dev/null +++ b/test_command/Electronics_sequential.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Electronics --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_filtered 0 --model_name Electronics_sequential.pt + +python ../src/main.py --datasets Electronics --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_filtered 0 --model_name Electronics_sequential.pt \ No newline at end of file diff --git a/test_command/LastFM_collaborative.sh b/test_command/LastFM_collaborative.sh new file mode 100644 index 0000000..1fad1dd --- /dev/null +++ b/test_command/LastFM_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 128 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name LastFM_collaborative.pt + +python ../src/main.py --datasets LastFM --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing collaborative --epochs 20 --batch_size 128 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_collaborative.pt \ No newline at end of file diff --git a/test_command/LastFM_random.sh b/test_command/LastFM_random.sh new file mode 100644 index 0000000..de6b8e5 --- /dev/null +++ b/test_command/LastFM_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_random.pt + +python ../src/main.py --datasets LastFM --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_random.pt \ No newline at end of file diff --git a/test_command/LastFM_sequential.sh b/test_command/LastFM_sequential.sh new file mode 100644 index 0000000..e47f6d2 --- /dev/null +++ b/test_command/LastFM_sequential.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets LastFM --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_sequential.pt + +python ../src/main.py --datasets LastFM --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --collaborative_sparse 0 --collaborative_float32 0 --test_filtered 1 --test_filtered_batch 0 --model_name LastFM_sequential.pt \ No newline at end of file diff --git a/test_command/ML100K_collaborative.sh b/test_command/ML100K_collaborative.sh new file mode 100644 index 0000000..b6b5be8 --- /dev/null +++ b/test_command/ML100K_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name ML100K_collaborative.pt + +python ../src/main.py --datasets ML100K --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name ML100K_collaborative.pt \ No newline at end of file diff --git a/test_command/ML100K_random.sh b/test_command/ML100K_random.sh new file mode 100644 index 0000000..e3f6777 --- /dev/null +++ b/test_command/ML100K_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1998 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name ML100K_random.pt + +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing random --epochs 20 --batch_size 64 --master_port 1998 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name ML100K_random.pt \ No newline at end of file diff --git a/test_command/ML100K_sequential.sh b/test_command/ML100K_sequential.sh new file mode 100644 index 0000000..a070643 --- /dev/null +++ b/test_command/ML100K_sequential.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1998 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name ML100K_sequential.pt + +python ../src/main.py --datasets ML100K --distributed 1 --gpu 6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 20 --batch_size 64 --master_port 1998 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name ML100K_sequential.pt \ No newline at end of file diff --git a/test_command/ML1M_collaborative.sh b/test_command/ML1M_collaborative.sh new file mode 100644 index 0000000..2037064 --- /dev/null +++ b/test_command/ML1M_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 20 --train 0 --model_name ML1M_collaborative.pt + +python ../src/main.py --datasets ML1M --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 20 --train 0 --model_name ML1M_collaborative.pt \ No newline at end of file diff --git a/test_command/ML1M_random.sh b/test_command/ML1M_random.sh new file mode 100644 index 0000000..76b5b77 --- /dev/null +++ b/test_command/ML1M_random.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1991 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 1 --test_filtered_batch 0 --model_name ML1M_random.pt \ No newline at end of file diff --git a/test_command/ML1M_sequential.sh b/test_command/ML1M_sequential.sh new file mode 100644 index 0000000..3c83274 --- /dev/null +++ b/test_command/ML1M_sequential.sh @@ -0,0 +1 @@ +python ../src/main.py --datasets ML1M --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 1984 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 1 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 1 --test_filtered_batch 0 --model_name ML1M_sequential.pt \ No newline at end of file diff --git a/test_command/Movies_collaborative.sh b/test_command/Movies_collaborative.sh new file mode 100644 index 0000000..4b83d2f --- /dev/null +++ b/test_command/Movies_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2010 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Movies_collaborative.pt + +python ../src/main.py --datasets Movies --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2010 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --test_filtered 0 --model_name Movies_collaborative.pt \ No newline at end of file diff --git a/test_command/Movies_random.sh b/test_command/Movies_random.sh new file mode 100644 index 0000000..16d445f --- /dev/null +++ b/test_command/Movies_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Movies_random.pt + +python ../src/main.py --datasets Movies --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2008 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Movies_random.pt \ No newline at end of file diff --git a/test_command/Movies_sequential.sh b/test_command/Movies_sequential.sh new file mode 100644 index 0000000..e380e27 --- /dev/null +++ b/test_command/Movies_sequential.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Movies --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_filtered 0 --model_name Movies_sequential.pt + +python ../src/main.py --datasets Movies --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_filtered 0 --model_name Movies_sequential.pt \ No newline at end of file diff --git a/test_command/SP5_collaborative.sh b/test_command/SP5_collaborative.sh new file mode 100644 index 0000000..65e6d98 --- /dev/null +++ b/test_command/SP5_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2018 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --train 0 --model_name SP5_collaborative.pt --test_filtered 0 + +python ../src/main.py --datasets ML1M,LastFM,Beauty,Yelp,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 500 --collaborative_cluster 20 --train 0 --model_name SP5_collaborative.pt --test_filtered 0 \ No newline at end of file diff --git a/test_command/SP5_random.sh b/test_command/SP5_random.sh new file mode 100644 index 0000000..d093764 --- /dev/null +++ b/test_command/SP5_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --test_filtered 0 + +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 4,5 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 256 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name SP5_random.pt --test_filtered 0 --test_filtered_batch 1 \ No newline at end of file diff --git a/test_command/SP5_sequential.sh b/test_command/SP5_sequential.sh new file mode 100644 index 0000000..4a3cabf --- /dev/null +++ b/test_command/SP5_sequential.sh @@ -0,0 +1,5 @@ +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2017 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name SP5_sequential.pt --test_filtered 0 + +python ../src/main.py --datasets ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 2018 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 10 --sample_num 1,1 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name SP5_sequential.pt --test_filtered 0 --test_filtered_batch 1 + +# ML1M,Yelp,LastFM,Beauty,ML100K,Clothing,CDs,Movies,Taobao,Electronics \ No newline at end of file diff --git a/test_command/Taobao_collaborative.sh b/test_command/Taobao_collaborative.sh new file mode 100644 index 0000000..73c21ac --- /dev/null +++ b/test_command/Taobao_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 1 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name Taobao_collaborative.pt + +python ../src/main.py --datasets Taobao --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 64 --master_port 1996 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --collaborative_token_size 100 --collaborative_cluster 10 --test_filtered 0 --model_name Taobao_collaborative.pt \ No newline at end of file diff --git a/test_command/Taobao_random.sh b/test_command/Taobao_random.sh new file mode 100644 index 0000000..7fd6600 --- /dev/null +++ b/test_command/Taobao_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Taobao_random.pt + +python ../src/main.py --datasets Taobao --distributed 1 --gpu 0,1 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 1994 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Taobao_random.pt \ No newline at end of file diff --git a/test_command/Taobao_sequential.sh b/test_command/Taobao_sequential.sh new file mode 100644 index 0000000..5cd4d28 --- /dev/null +++ b/test_command/Taobao_sequential.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Taobao --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Taobao_sequential.pt + +python ../src/main.py --datasets Taobao --distributed 1 --gpu 2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 256 --master_port 1995 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 3,3 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --test_filtered 0 --model_name Taobao_sequential.pt \ No newline at end of file diff --git a/test_command/Yelp_collaborative.sh b/test_command/Yelp_collaborative.sh new file mode 100644 index 0000000..3ff8ff3 --- /dev/null +++ b/test_command/Yelp_collaborative.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 0 --test_prompt seen:0 --lr 1e-3 --collaborative_token_size 500 --test_before_train 0 --test_epoch 0 --collaborative_float32 1 --test_filtered 0 --model_name Yelp_collaborative.pt + +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing collaborative --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 0 --test_prompt unseen:0 --lr 1e-3 --collaborative_token_size 500 --test_before_train 0 --test_epoch 0 --collaborative_float32 1 --test_filtered 0 --model_name Yelp_collaborative.pt diff --git a/test_command/Yelp_random.sh b/test_command/Yelp_random.sh new file mode 100644 index 0000000..3a518f3 --- /dev/null +++ b/test_command/Yelp_random.sh @@ -0,0 +1,3 @@ +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name Yelp_random.pt --test_filtered 0 + +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing random --epochs 10 --batch_size 128 --master_port 2019 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --train 0 --model_name Yelp_random.pt --test_filtered 0 diff --git a/test_command/Yelp_sequential.sh b/test_command/Yelp_sequential.sh new file mode 100644 index 0000000..e232f13 --- /dev/null +++ b/test_command/Yelp_sequential.sh @@ -0,0 +1,3 @@ +# python ../src/main.py --datasets Yelp --distributed 1 --gpu 4,5,6,7 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 0 --test_prompt seen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --model_name Yelp_sequential.pt --test_filtered 0 + +python ../src/main.py --datasets Yelp --distributed 1 --gpu 0,1,2,3 --tasks sequential,straightforward --item_indexing sequential --epochs 10 --batch_size 128 --master_port 2024 --prompt_file ../prompt.txt --sample_prompt 1 --eval_batch_size 20 --dist_sampler 0 --max_his 20 --sample_num 2,2 --train 0 --test_prompt unseen:0 --lr 1e-3 --test_before_train 0 --test_epoch 0 --model_name Yelp_sequential.pt --test_filtered 0 \ No newline at end of file