{"id":19932113,"url":"https://github.com/amazon-science/contrastive_emc2","last_synced_at":"2025-10-04T06:50:22.576Z","repository":{"id":241196971,"uuid":"804580385","full_name":"amazon-science/contrastive_emc2","owner":"amazon-science","description":"Code the ICML 2024 paper: \"EMC^2: Efficient MCMC Negative Sampling for Contrastive Learning with Global Convergence\"","archived":false,"fork":false,"pushed_at":"2024-05-22T21:47:19.000Z","size":8144,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-09T05:11:56.551Z","etag":null,"topics":["contrastive-learning","deep-neural-networks","machine-learning","machine-learning-algorithms","mcmc-sampling","multi-modal","multi-modal-learning"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2404.10575","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amazon-science.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-22T21:31:05.000Z","updated_at":"2024-11-27T08:14:11.000Z","dependencies_parsed_at":"2024-05-23T00:35:22.306Z","dependency_job_id":null,"html_url":"https://github.com/amazon-science/contrastive_emc2","commit_stats":null,"previous_names":["amazon-science/contrastive_emc2"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/amazon-science/contrastive_emc2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Fcontrastive_emc2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Fcontrastive_emc2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Fcontrastive_emc2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Fcontrastive_emc2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amazon-science","download_url":"https://codeload.github.com/amazon-science/contrastive_emc2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Fcontrastive_emc2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278277871,"owners_count":25960430,"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-10-04T02:00:05.491Z","response_time":63,"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":["contrastive-learning","deep-neural-networks","machine-learning","machine-learning-algorithms","mcmc-sampling","multi-modal","multi-modal-learning"],"created_at":"2024-11-12T23:09:09.577Z","updated_at":"2025-10-04T06:50:22.552Z","avatar_url":"https://github.com/amazon-science.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## EMC2: Efficient MCMC Negative Sampling for Contrastive Learning with Global Convergence\n\n**Authors: Chung-Yiu Yau, Hoi-To Wai, Parameswaran Raman, Soumajyoti Sarkar, Mingyi Hong**\n\nThis repository contains the PyTorch code used to perform the experiments of the [paper](https://arxiv.org/pdf/2404.10575). \n\nCheck system_setup.md if you find your environment not compatible with the code.\n\nUse the following commands to reproduce the main experiment results.\n\n## ResNet-18 on STL-10:\n- SimCLR\n\n`main_simclr.py --beta 14.28 --lr 1e-4 --disable_batchnorm --pos_batch_size 32 --compute_batch_size 256 --epoch 100 --num_workers 4 --eval_freq 5 --data_root /path/to/data/directory`\n\n- Embedding Cache\n\n`main_gumbel.py --beta 14.28 --lr 1e-4 --rho 0.01024 --neg_batch_size 1 --pos_batch_size 32 --compute_batch_size 512 --disable_batchnorm --disable_proj --sampler gumbel_max --transform_batch_size 1 --num_workers 2 --eval_freq 5 --data_root /path/to/data/directory`\n\n- SogCLR\n\n`main_sogclr.py --beta 14.28 --lr 1e-4 --disable_batchnorm --pos_batch_size 32 --compute_batch_size 256 --epoch 100 --num_workers 4 --eval_freq 5 --data_root /path/to/data/directory`\n\n- EMC\u003csup\u003e2\u003c/sup\u003e\n\n`main_mcmc.py --beta 14.28 --lr 1e-4 --disable_batchnorm --pos_batch_size 32 --compute_batch_size 256 --epoch 100 --sampler mcmc --mcmc_burn_in 0.5 --num_workers 4 --eval_freq 5 --data_root /path/to/data/directory`\n\n## ResNet-50 on ImageNet-100:\n- SimCLR\n\n`main_simclr.py --beta 14.28 --lr 1.2 --disable_batchnorm --dataset imagenet100 --model_name resnet50 --dim 128 --mlp_dim 2048 --projector_hidden_layers 1 --weight_decay 1e-6 --optimizer lars --epoch 800 --eval_freq 10 --num_workers 4 --data_root /path/to/data/directory`\n\n- SogCLR\n\n`main_sogclr.py --beta 14.28 --lr 1.2 --disable_batchnorm --dataset imagenet100 --model_name resnet50 --dim 128 --mlp_dim 2048 --projector_hidden_layers 1 --weight_decay 1e-6 --optimizer lars --epoch 800 --eval_freq 10 --num_workers 4 --data_root /path/to/data/directory`\n\n- EMC\u003csup\u003e2\u003c/sup\u003e\n\n`main_mcmc.py --beta 14.28 --lr 1.2 --disable_batchnorm --dataset imagenet100 --model_name resnet50 --dim 128 --mlp_dim 2048 --projector_hidden_layers 1 --weight_decay 1e-6 --optimizer lars --sampler mcmc --mcmc_burn_in 0.5 --epoch 800 --eval_freq 10 --num_workers 4 --data_root /path/to/data/directory`\n\n## ResNet-18 on STL-10 Subset with SGD:\nUse preaugmentation.py to generate the pre-augmented STL-10 with 2 augmentations per image.\n\n- SimCLR\n\n`main_simclr.py --beta 5 --lr 1e-3 --disable_batchnorm --pos_batch_size 4 --compute_batch_size 8 --epoch 10 --num_workers 1 --eval_freq 25 --check_gradient_error --finite_aug --n_aug 2 --optimizer sgd --eval_iteration --data_root /path/to/data/directory`\n\n- Embedding Cache\n\n`main_gumbel.py --beta 5 --lr 1e-3 --rho 0.1 --neg_batch_size 1 --pos_batch_size 4 --compute_batch_size 8 --disable_batchnorm --disable_proj --sampler gumbel_max --transform_batch_size 1 --epoch 10 --num_workers 1 --eval_freq 25 --check_gradient_error --finite_aug --n_aug 2 --optimizer sgd --eval_iteration --data_root /path/to/data/directory`\n\n- SogCLR\n\n`main_sogclr.py --beta 5 --lr 1e-3 --disable_batchnorm --pos_batch_size 4 --compute_batch_size 8 --epoch 10 --num_workers 1 --eval_freq 25 --check_gradient_error --finite_aug --n_aug 2 --optimizer sgd --eval_iteration --data_root /path/to/data/directory`\n\n- EMC\u003csup\u003e2\u003c/sup\u003e\n\n`main_mcmc.py --beta 5 --lr 1e-3 --disable_batchnorm --pos_batch_size 4 --compute_batch_size 8 --epoch 10 --sampler mcmc --mcmc_burn_in 0.5 --num_workers 1 --eval_freq 25 --check_gradient_error --finite_aug --n_aug 2 --optimizer sgd --eval_iteration --data_root /path/to/data/directory`\n\n\n## Citation\n\nPlease consider citing our paper if you use our code:\n```text\n@misc{yau2024emc2,\n      title={EMC$^2$: Efficient MCMC Negative Sampling for Contrastive Learning with Global Convergence}, \n      author={Chung-Yiu Yau and Hoi-To Wai and Parameswaran Raman and Soumajyoti Sarkar and Mingyi Hong},\n      year={2024},\n      eprint={2404.10575},\n      archivePrefix={arXiv},\n      primaryClass={cs.LG}\n}\n```\n\n## Security\n\nSee [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazon-science%2Fcontrastive_emc2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famazon-science%2Fcontrastive_emc2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazon-science%2Fcontrastive_emc2/lists"}