{"id":19932250,"url":"https://github.com/amazon-science/transformer-gan","last_synced_at":"2025-07-19T04:32:09.176Z","repository":{"id":139013280,"uuid":"349561227","full_name":"amazon-science/transformer-gan","owner":"amazon-science","description":null,"archived":false,"fork":false,"pushed_at":"2021-05-18T21:02:11.000Z","size":118,"stargazers_count":50,"open_issues_count":4,"forks_count":12,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-03T11:35:54.695Z","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":"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,"zenodo":null}},"created_at":"2021-03-19T21:37:44.000Z","updated_at":"2024-04-24T12:40:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"8245cab9-78a9-43a7-8d00-69a2da46ce7d","html_url":"https://github.com/amazon-science/transformer-gan","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/amazon-science/transformer-gan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Ftransformer-gan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Ftransformer-gan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Ftransformer-gan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Ftransformer-gan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amazon-science","download_url":"https://codeload.github.com/amazon-science/transformer-gan/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2Ftransformer-gan/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265888899,"owners_count":23844527,"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-12T23:09:29.766Z","updated_at":"2025-07-19T04:32:09.168Z","avatar_url":"https://github.com/amazon-science.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Symbolic Music Generation with Transformer-GANs\n\nCode for the paper \"[Symbolic Music Generation with Transformer-GANs](https://assets.amazon.science/36/e6/95f355a24df983dfcd2fe6b5ad2a/symbolic-music-generation-with-transformer-gans.pdf)\" (AAAI 2021)\n\nIf you use this code, please cite the paper using the bibtex reference below.\n```\n@inproceedings{transformer-gan,\n    title={Symbolic Music Generation with Transformer-GANs},\n    author={Aashiq Muhamed and Liang Li and Xingjian Shi and Suri Yaddanapudi and Wayne Chi and Dylan Jackson and Rahul Suresh and Zachary C. Lipton and Alexander J. Smola},\n    booktitle={35th AAAI Conference on Artificial Intelligence, {AAAI} 2021},\n    year={2021},\n}\n```\n\n## Requirements\n- Python 3.6+\n- Pytorch\n- Transformers\n\nYou can install all required Python packages with `bash requirements.sh`. \n\n## Datasets, switching inside `data` folder\n\n* Downloaded data\n\n```bash\nbash get_data.sh\n```\n\n* Run `music_encoder.py` to generate the encoded numpy files\n  * Messages stating that pitches are out of range are expected behavior\n\n\n```bash\npython3 music_encoder.py --encode_official_maestro \\  \n    --mode midi_to_npy \\  \n    --pitch_transpose_lower -3 \\  \n    --pitch_transpose_upper 3 \\  \n    --output_folder ./maestro_magenta_s5_t3  \n```\n\n## Train and Generate: switching inside `model` folder\n\n* Train a Transformer XL (No GAN)\n\n```bash\npython3 -m torch.distributed.launch --nproc_per_node=4 ./train.py \\\n    --data_dir ../data/maestro_magenta_s5_t3 \\\n    --cfg ./training_config/experiment_baseline.yml \\\n    --work_dir exp_dir\n```\n\n* Train a Transformer XL (with GAN)\n\n```bash\npython3 -m torch.distributed.launch --nproc_per_node=4 ./train.py \\\n    --data_dir ../data/maestro_magenta_s5_t3 \\\n    --cfg ./training_config/experiment_spanbert.yml \\\n    --work_dir exp_dir\n```\n\n* Generate unconditional samples \n\n```\n# generate unconditional samples\npython3 generate.py --inference_config inference_config/inference_unconditional.yml\n```\n\nNote, if you are loading an old config.yml file which includes None/\" \" inside, please change it to a string 'Null' to make sure you can do cfg.merge_from_file.\n\n* Extend music to generate conditional samples\n\n```\n# generate conditional samples\npython3 generate.py --inference_config inference_config/inference_conditional.yml\n\n```\n\n1. Please set condition_len as well as condition_file\n2. Change memlen and genlen. memlen=genlen is recommended\n\n## Post process for data (convert `.txt` to `.mid`)\n\n* Run the following to get midi files from txt files\n  * Use `--mode to_midi` for text file conversions. Use `--mode npy_to_midi` for numpy file conversions.\n\n```bash\npython3 ../data/music_encoder.py --input_folder ./Output_Uncondtitionl --output_folder ./Output_Uncondtitionl_MIDI --mode to_midi\npython3 ../data/music_encoder.py --input_folder ./Output_Condtitionl --output_folder ./Output_Condtitionl_MIDI --mode to_midi\n```\n\ndifferent methods inside music_encoder\n\n* encoder.to_text(input.mid, output.txt)\n* encoder.from_text(input.txt, out.mid)\n* encoder.encode_vocab(input.mid) return list of ids\n* encoder.decoder_vocab(list(ids)) return out.mid\n* encoder.to_text_argumentaion(input.mid, output.txt)\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazon-science%2Ftransformer-gan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famazon-science%2Ftransformer-gan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazon-science%2Ftransformer-gan/lists"}