{"id":31108828,"url":"https://github.com/Linxyhaha/COR","last_synced_at":"2025-09-17T06:46:16.231Z","repository":{"id":153812788,"uuid":"556357104","full_name":"Linxyhaha/COR","owner":"Linxyhaha","description":"Causal Representation Learning for Out-of-Distribution Recommendation (WWW'22)","archived":false,"fork":false,"pushed_at":"2023-12-26T09:17:11.000Z","size":35664,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-12-26T10:22:08.766Z","etag":null,"topics":["causal-inference","ood-generalization","pytorch","recommender-system","www2022"],"latest_commit_sha":null,"homepage":"https://dl.acm.org/doi/10.1145/3485447.3512251","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Linxyhaha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-10-23T17:09:36.000Z","updated_at":"2023-12-26T10:22:09.561Z","dependencies_parsed_at":"2023-12-26T10:37:24.458Z","dependency_job_id":null,"html_url":"https://github.com/Linxyhaha/COR","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/Linxyhaha/COR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Linxyhaha%2FCOR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Linxyhaha%2FCOR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Linxyhaha%2FCOR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Linxyhaha%2FCOR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Linxyhaha","download_url":"https://codeload.github.com/Linxyhaha/COR/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Linxyhaha%2FCOR/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275549091,"owners_count":25484678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["causal-inference","ood-generalization","pytorch","recommender-system","www2022"],"created_at":"2025-09-17T06:45:25.957Z","updated_at":"2025-09-17T06:46:16.211Z","avatar_url":"https://github.com/Linxyhaha.png","language":"Python","funding_links":[],"categories":["🚀 GitHub Repositories"],"sub_categories":["🎓 Educational \u0026 Tutorial Resources"],"readme":"# Causal Representation Learning for Out-of-Distribution Recommendation\nThis is the pytorch implementation of our paper at WWW 2022:\n\u003e Causal Representation Learning for Out-of-Distribution Recommendation\n\u003e\n\u003e Wenjie Wang, Xinyu Lin, Fuli Feng, Xiangnan He, Min Lin, Tat-Seng Chua\n\n## Environment\n- Anaconda 3\n- python 3.7.3\n- pytorch 1.4.0\n- numpy 1.16.4\n\n## Usage\n\n### Data\nThe experimental data are in './data' folder, including Synthetic Data, Meituan and Yelp. Due to the large size, 'item_feature.npy' of Yelp is uploaded to [Google drive](https://drive.google.com/drive/folders/1nKk15UlYzGVKCo5yMFVmW4yewbwid0dH?usp=sharing).\n\n### Training\n```\npython main.py --model_name=$1 --dataset=$2 --mlp_dims=$3 --mlp_p1_1_dims=$4 --mlp_p1_2_dims=$5 --mlp_p2_dims=$6 --mlp_p3_dims=$7 --lr=$8 --wd=$9 --batch_size=$10 --epochs=$11 --total_anneal_steps=$12 --anneal_cap=$13 --CI=$14 --dropout=$15 --Z1_hidden_size=$16 --E2_hidden_size=$17 --Z2_hidden_size=$18 --bn=$19 --sample_freq=$20 --regs=$21 --act_function=$22 --log_name=$23 --gpu=$24 --cuda\n```\nor use run.sh\n```\nsh run.sh model_name dataset mlp_dims mlp_p1_1_dims mlp_p1_2_dims mlp_p2_dims mlp_p3_dims lr wd batch_size epochs total_anneal_steps anneal_cap CI dropout Z1_hidden_size E2_hidden_size Z2_hidden_size bn sample_freq regs act_function log_name gpu_id\n```\n- The log file will be in the './code/log/' folder. \n- The explanation of hyper-parameters can be found in './code/main.py'. \n- The default hyper-parameter settings are detailed in './code/hyper-parameters.txt'.\n\n### Inference\nGet the results of COR over iid and ood data where only user features are drifted by running inference.py:\n\n```\npython inference.py --dataset=$1 --ckpt=$2 --cuda\n```\n\n### Fine-tuneing\n```\npython main.py --model_name=$1 --dataset=$2 --X=$3 --lr=$4 --wd=$5 --batch_size=$6 --epochs=$7 --total_anneal_steps=$8 --anneal_cap=$9 --CI=$10 --dropout=$11 --bn=$12 --sample_freq=$13 --regs=$14 --log_name=$15 --ckpt=$16 --gpu=$17 --ood_finetune --cuda\n```\nor use finetune.sh\n```\nsh finetune.sh model_name dataset X lr wd batch_size epochs total_anneal_steps anneal_cap CI dropout bn sample_freq regs log_name \u003cpre-trained model directory\u003e gpu_id\n```\n- The log file will be in the './code/log/finetune/' folder.\n\n\n### Examples\n\n1. Train COR on iid meituan:\n\n```\ncd ./code\nsh run.sh COR meituan [3000] [] [1] [] [] 1e-3 0 500 300 0 0.1 1 0.5 500 1000 200 0 1 0 tanh log 0\n```\n\n2. Inference on synthetic data:\n\n```\ncd ./code\npython inference.py --dataset synthetic --ckpt \u003cpre-trained model directory\u003e --cuda\n```\n\n3. Fine-tuning COR on ood yelp:\n```\ncd ./code\nsh finetune.sh COR yelp 0 0.0001 0.03 500 0 0.5 1 0.4 0 1 0 log \u003cpre-trained model directory\u003e 0\n```\n## License\n\nNUS © [NExT++](https://www.nextcenter.org/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLinxyhaha%2FCOR","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLinxyhaha%2FCOR","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLinxyhaha%2FCOR/lists"}