{"id":27438388,"url":"https://github.com/pmichel31415/p-dro","last_synced_at":"2026-03-11T15:02:40.773Z","repository":{"id":89121207,"uuid":"341242134","full_name":"pmichel31415/P-DRO","owner":"pmichel31415","description":"Code for the papers \"Modeling the Second Player in Distributionally Robust Optimization\" and \"Distributionally Robust Models with Parametric Likelihood Ratios\"","archived":false,"fork":false,"pushed_at":"2022-04-14T09:52:29.000Z","size":1701,"stargazers_count":27,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T20:44:34.400Z","etag":null,"topics":["dro","machine-learning","natural-language-processing"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2204.06340","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/pmichel31415.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-02-22T15:15:46.000Z","updated_at":"2024-09-20T11:44:21.000Z","dependencies_parsed_at":"2023-06-14T01:00:38.887Z","dependency_job_id":null,"html_url":"https://github.com/pmichel31415/P-DRO","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pmichel31415/P-DRO","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmichel31415%2FP-DRO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmichel31415%2FP-DRO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmichel31415%2FP-DRO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmichel31415%2FP-DRO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmichel31415","download_url":"https://codeload.github.com/pmichel31415/P-DRO/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmichel31415%2FP-DRO/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30385033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T14:10:17.325Z","status":"ssl_error","status_checked_at":"2026-03-11T14:09:37.934Z","response_time":84,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["dro","machine-learning","natural-language-processing"],"created_at":"2025-04-14T20:35:23.461Z","updated_at":"2026-03-11T15:02:40.768Z","avatar_url":"https://github.com/pmichel31415.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parametric Distributionally Robust Optimization\n\nThis repository contains code for implementing distributionally robust optimization with parametric uncertainty sets. This codebase was used to implement experiments in the ICLR 2021 paper [\"Modeling the Second Player in Distributionally Robust Optimization\"](https://arxiv.org/abs/2103.10282) and subsequent ICLR 2022 follow-up [\"Distributionally Robust Models with Parametric Likelihood Ratios\"](http://arxiv.org/abs/2204.06340).\n\n![image](https://user-images.githubusercontent.com/10391785/112060559-a320fe80-8b5d-11eb-9330-82af012f9bad.png)\n\n## How to run this code\n\nAfter checking out the repository, you need to install the dependencies, for instance in a virtual environment:\n\n```bash\nvirtualenv --system-site-packages env\nsource env/bin/activate\npip install -r requirements.txt\n```\n\nAlternatively, you can install the dedicated conda environment:\n\n```bash\nconda env create -f rp_dro.yml\n```\n\nNow you should be ready to go. Here is an example run on BiasedSST (see paper for details).\n\nNormally you should first pre-train the MLE of the data distribution (`q_{\\psi_0}` in the paper). However, to get you started you can just download our [pre-trained model](https://github.com/pmichel31415/P-DRO/releases/download/1.0/biased_SST_95_gen_LM_small_transformer_generative_wikitext103_model.pt).\n\n```bash\n# Download pre-trained models\nmkdir pretrained_models/\nwget https://github.com/pmichel31415/P-DRO/releases/download/1.0/biased_SST_95_gen_LM_small_transformer_generative_wikitext103_model.pt -P pretrained_models/\n# Create results folder\nmkdir results/\n```\n\nNow you can run P-DRO on BiasedSST using the following command:\n\n```bash\npython pdro_main.py \\\n    --force-save-name biased_sst_p_dro \\\n    --n-reruns 5 \\\n    --task biased_SST_95 \\\n    --architecture bilstm \\\n    --input-format bert-base-uncased \\\n    --lr-scheduler linear_decay \\\n    --n-epochs 50 \\\n    --valid-interval epoch \\\n    --optimizer adamw \\\n    --lr 2e-5 \\\n    --batch-size 64 \\\n    --max-tokens-per-batch 2500 \\\n    --eval-on-domains biased=True,label=0 biased=True,label=1 biased=False,label=0 biased=False,label=1 \\\n    --pdro \\\n    --adv-architecture small_transformer_generative \\\n    --adv-filename pretrained_models/biased_SST_95_gen_LM_small_transformer_generative_wikitext103_model.pt \\\n    --filter-advs-by reverse_kl \\\n    --adv-threshold 2.302585 \\\n    --adv-optimizer sgd  \\\n    --adv-lr 1e-4 \\\n    --adv-obj exp_kl \\\n    --joint \\\n    --tau 0.01 \\\n    --norm-k-adv 5\n```\n\n\nNote the parameters relevant to P-DRO:\n\n- `--pdro`: use P-DRO (deactivate this for ERM)\n- `--adv-architecture small_transformer_generative`: architecture for the adversary. You can find more architectures in `src/models/architectures.py`.\n- `--filter-advs-by reverse_kl`: filter validation adversary by reverse KL\n- `--adv-threshold 2.302585`: reject adversaries with reverse KL to the data distribution \u003e `log(10)` on the dev set\n- `--adv-optimizer sgd`: train the adversary with regular SGD\n- `--adv-lr 1e-4`: train the adversary with learning rate 1r-4 (this is `\\lambda` in the paper)\n- `--adv-obj exp_kl`: this refers to L_adv as described in the paper\n- `--joint`: this indicates that the adversary will model the joint distribution `(x, y)` (instead of just x)\n- `--tau 0.01`: Temperature for the adversary's loss\n- `--norm-k-adv`: This is the size of the window for computing the normalizer in the adversary's loss (`K` in the paper)\n\n\n## RP-DRO\n\n![image](https://user-images.githubusercontent.com/10391785/163356611-3143da35-abdf-44d5-8989-066d9f8ca72e.png)\n\n\nYou can run training for a parametric likelihood ratio model (RP-DRO, as described in [Michel et al., 2022](http://arxiv.org/abs/2204.06340)).\n\n```bash\npython pdro_main.py \\\n    --pdro \\\n    --ratio-model \\\n    --adv-architecture bilstm \\\n    --filter-advs-by reverse_kl \\\n    --adv-threshold 2.302585 \\\n    --adv-obj fwd_kl \\\n    --joint \\\n    --adv-valid-on-acc \\\n    --adv-optimizer adamw \\\n    --n-reruns 1 \\\n    --task biased_SST_95 \\\n    --architecture bilstm \\\n    --input-format bert-base-uncased \\\n    --lr-scheduler linear_decay \\\n    --n-epochs 50 \\\n    --valid-interval epoch \\\n    --optimizer adamw \\\n    --lr 2e-5 \\\n    --batch-size 64 \\\n    --max-tokens-per-batch 2500 \\\n    --eval-on-domains biased=True,label=0 biased=True,label=1 biased=False,label=0 biased=False,label=1 \\\n    --self-norm-lambda 0 \\\n    --renorm-ratios \\\n    --adv-lr 2e-5 \\\n    --tau 0.01\n```\n\nThe additional relevant parameters here are:\n\n- `--ratio-model`: Use the ratio-based version of P-DRO, RP-DRO\n- `--renorm-ratios`: Batch-level renormalization of the ratios\n- `--self-norm-lambda 0`: No self-normalization penalty. To enable self-normalization, set this to a positive value and disable `--renorm-ratios`\n- `--adv-obj fwd_kl`: This specifies that the objective for the adversary will be the reverse of the model objective, with a forward KL penalty (see e.g. Equation 9 in the paper)\n- `--tau 0.01`: Here this refers to the KL penalty weight\n\n\n## How to cite\n\nIf you use this code in your research, or if you want to build upon P-DRO, please consider citing\n\n### The original P-DRO paper:\n\n```\n@inproceedings{michel2021modeling,\n  title={Modeling the Second Player in Distributionally Robust Optimization},\n  author={Michel, Paul and Hashimoto, Tatsunori and Neubig, Graham},\n  booktitle={ICLR 2021},\n  year={2021}\n}\n```\n\n### The RP-DRO followup paper:\n\n```\n@inproceedings{michel2021modeling,\n  title={Distributionally Robust Models with Parametric Likelihood Ratios},\n  author={Michel, Paul and Hashimoto, Tatsunori and Neubig, Graham},\n  booktitle={ICLR 2022},\n  year={2022}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmichel31415%2Fp-dro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmichel31415%2Fp-dro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmichel31415%2Fp-dro/lists"}