{"id":19267723,"url":"https://github.com/harvardnlp/sa-vae","last_synced_at":"2025-04-21T19:33:05.581Z","repository":{"id":60886472,"uuid":"116478481","full_name":"harvardnlp/sa-vae","owner":"harvardnlp","description":null,"archived":false,"fork":false,"pushed_at":"2018-02-09T19:47:28.000Z","size":146,"stargazers_count":153,"open_issues_count":3,"forks_count":15,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-18T23:21:48.464Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/harvardnlp.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}},"created_at":"2018-01-06T11:45:38.000Z","updated_at":"2025-01-21T03:59:17.000Z","dependencies_parsed_at":"2022-10-06T07:26:01.987Z","dependency_job_id":null,"html_url":"https://github.com/harvardnlp/sa-vae","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harvardnlp%2Fsa-vae","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harvardnlp%2Fsa-vae/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harvardnlp%2Fsa-vae/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harvardnlp%2Fsa-vae/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harvardnlp","download_url":"https://codeload.github.com/harvardnlp/sa-vae/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250120163,"owners_count":21378149,"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","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":[],"created_at":"2024-11-09T20:13:54.502Z","updated_at":"2025-04-21T19:33:05.322Z","avatar_url":"https://github.com/harvardnlp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Semi-Amortized Variational Autoencoders\nCode for the paper:  \n[Semi-Amortized Variational Autoencoders](https://arxiv.org/pdf/1802.02550.pdf)  \nYoon Kim, Sam Wiseman, Andrew Miller, David Sontag, Alexander Rush\n\n## Dependencies\nThe code was tested in `python 3.6` and `pytorch 0.2`. We also require the `h5py` package.\n\n## Data\nThe raw datasets can be downloaded from [here](https://drive.google.com/file/d/1PecZKhrPkMZmvMyiOJfMS-FsHW3FE0rH/view?usp=sharing).\n\nText experiments use the Yahoo dataset from [Yang et al. 2017](https://arxiv.org/pdf/1702.08139.pdf), which is itself derived from [Zhang et al. 2015](https://arxiv.org/abs/1509.01626). \n\nImage experiments use the OMNIGLOT dataset [Lake et al. 2015](https://cims.nyu.edu/~brenden/LakeEtAl2015Science.pdf) with preprocessing from [Burda et al. 2015](https://arxiv.org/pdf/1509.00519.pdf).\n\nPlease cite the original papers when using the data.\n\n## Text\nAfter downloading the data, run\n```\npython preprocess_text.py --trainfile data/yahoo/train.txt --valfile data/yahoo/val.txt\n--testfile data/yahoo/test.txt --outputfile data/yahoo/yahoo\n```\nThis will create the `*.hdf5` files (data tensors) to be used by the model, as well as the `*.dict`\nfile which contains the word-to-integer mapping for each word.\n\nThe basic model command is\n```\npython train_text.py --train_file data/yahoo/yahoo-train.hdf5 --val_file data/yahoo/yahoo-val.hdf5\n--gpu 1 --checkpoint_path model-path\n```\nwhere `model-path` is the path to save the best model and the `*.hdf5` files are obtained from running `preprocess_text.py`. You can specify which GPU to use by changing the input to the `--gpu` command.\n\nTo train the various models, add the following:  \n- Autoregressive (i.e. language model): `--model autoreg`  \n- VAE: `--model vae`  \n- SVI: `--model svi --svi_steps 20 --train_n2n 0`  \n- VAE+SVI: `--model savae --svi_steps 20 --train_n2n 0 --train_kl 0`  \n- VAE+SVI+KL: `--model savae --svi_steps 20 --train_n2n 0 --train_kl 1`  \n- SA-VAE: `--model savae --svi_steps 20 --train_n2n 1`  \n\nNumber of SVI steps can be changed with the `--svi_steps` command. \n\nTo evaluate, run\n```\npython train_text.py --train_from model-path --test_file data/yahoo/yahoo-test.hdf5 --test 1 --gpu 1\n```\nMake sure the append the relevant model configuration at test time too.\n\n## Images\nAfter downloading the data, run\n```\npython preprocess_img.py --raw_file data/omniglot/chardata.mat --output data/omniglot/omniglot.pt\n```\n\nTo train, the basic command is\n```\npython train_img.py --data_file data/omniglot/omniglot.pt --gpu 1 --checkpoint_path model-path\n```\n\nTo train the various models, add the following:  \n- Autoregressive (i.e. Gated PixelCNN): `--model autoreg`  \n- VAE: `--model vae`  \n- SVI: `--model svi --svi_steps 20`  \n- VAE+SVI: `--model savae --svi_steps 20 --train_n2n 0 --train_kl 0`    \n- VAE+SVI+KL: `--model savae --svi_steps 20 --train_n2n 0 --train_kl 1`  \n- SA-VAE: `--model savae --svi_steps 20 --train_n2n 1`  \n\nTo evaluate, run\n```\npython train_img.py --train_from model-path --test 1 --gpu 1\n```\nMake sure the append the relevant model configuration at test time too.\n\n## Acknowledgements\nSome of our code is based on [VAE with a VampPrior](https://github.com/jmtomczak/vae_vampprior).\n\n## License\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharvardnlp%2Fsa-vae","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharvardnlp%2Fsa-vae","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharvardnlp%2Fsa-vae/lists"}