{"id":18887151,"url":"https://github.com/thunlp-mt/transformer-dmb","last_synced_at":"2026-02-24T03:30:18.157Z","repository":{"id":86099788,"uuid":"456789675","full_name":"THUNLP-MT/Transformer-DMB","owner":"THUNLP-MT","description":"Codes for our paper \"Dynamic Multi-Branch Layers for On-Device Neural Machine Translation\" in TASLP","archived":false,"fork":false,"pushed_at":"2022-03-18T08:45:31.000Z","size":60,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-31T05:19:00.399Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/THUNLP-MT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-02-08T05:02:27.000Z","updated_at":"2024-11-11T08:54:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"c454202b-7b30-426c-9ad8-89757570d467","html_url":"https://github.com/THUNLP-MT/Transformer-DMB","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/THUNLP-MT%2FTransformer-DMB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUNLP-MT%2FTransformer-DMB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUNLP-MT%2FTransformer-DMB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUNLP-MT%2FTransformer-DMB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/THUNLP-MT","download_url":"https://codeload.github.com/THUNLP-MT/Transformer-DMB/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239859563,"owners_count":19708863,"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-08T07:34:47.237Z","updated_at":"2026-02-24T03:30:18.073Z","avatar_url":"https://github.com/THUNLP-MT.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dynamic Multi-Branch Layers for On-Device Neural Machine Translation\n\nThis is the codes for our work [Dynamic Multi-Branch Layers for On-Device Neural Machine Translation](https://ieeexplore.ieee.org/document/9729651). The implementation is on top of the open-source NMT toolkit [THUMT](https://github.com/THUNLP-MT/THUMT).\n\n## Contents\n\n* [Prerequisites](#prerequisites)\n* [Training](#training)\n* [Decoding](#decoding)\n* [Profile](#profile)\n* [License](#license)\n* [Citation](#citation)\n\n## Prerequisites\n\n* Python \u003e= 3.7\n* tensorflow-cpu \u003e= 2.0\n* torch \u003e= 1.7\n* torchprofile\n\nPlease read the document of [THUMT](https://github.com/THUNLP-MT/THUMT/blob/master/docs/index.md) before using this Repository.\n\n## Training\n\nTraining a Transformer-DMB model is nearly the same as a Transformer model, except for the following additional hyperparameters:\n\n* `n`: the number of branches for each layer\n* `shared_private`: enable shared-private reparameterization\n\n```\nexport PYTHONPATH=\u003cpath/to/thumt\u003e:$PYTHONPATH\n\npython thumt/bin/trainer.py \\\n  --input \u003cpath/to/src\u003e \u003cpath/to/tgt\u003e \\\n  --model transformer_dmb \\\n  --vocabulary \u003cpath/to/src-vocab\u003e \u003cpath/to/tgt-vocab\u003e \\\n  --parameters=hidden_size=128,filter_size=512,device_list=[0,1,2,3],\\\n               update_cycle=4,train_steps=100000,\\\n               shared_source_target_embedding=true,\\\n               shared_embedding_and_softmax_weights=true,n=4,\\\n               shared_private=true \\\n               --hparam_set base\n```\n\n## Decoding\n\nThe following command decodes an input file with a pre-trained checkpoint.\n```\nexport PYTHONPATH=\u003cpath/to/thumt\u003e:$PYTHONPATH\n\npython thumt/bin/translator.py \\\n  --input \u003cpath/to/input\u003e \\\n  --model transformer_dmb \\\n  --vocabulary \u003cpath/to/src-vocab\u003e \u003cpath/to/tgt-vocab\u003e \\\n  --parameters=device_list=[0,1,2,3] \\\n  --checkpoint \u003cpath/to/checkpoint\u003e \\\n  --output \u003cpath/to/output-file\u003e\n```\n\n## Profile\n\nUse the following command to count the number of MultAdds of a tiny Transformer-DMB model with 8 branches.\n```\nexport PYTHONPATH=\u003cpath/to/thumt\u003e:$PYTHONPATH\n\npython thumt/bin/trainer.py \\\n  --input \u003cdummy/src-file\u003e \u003cdummy/tgt-file\u003e \\\n  --model transformer_dmb \\\n  --vocabulary \u003cpath/to/src-vocab\u003e \u003cpath/to/tgt-vocab\u003e \\\n  --parameters=hidden_size=128,filter_size=512,n=8 \\\n  --hparam_set base --profile --output /tmp\n```\n\n## License\n\nOpen source licensing is under the [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause), which allows free use for research purposes.\n\n## Citation\n\n```\n@article{tan2022dynamic,\n  author={Tan, Zhixing and Yang, Zeyuan and Zhang, Meng and Liu, Qun and Sun, Maosong and Liu, Yang},\n  journal={IEEE/ACM Transactions on Audio, Speech, and Language Processing},\n  title={Dynamic Multi-Branch Layers for On-Device Neural Machine Translation},\n  year={2022},\n  volume={30},\n  pages={958--967},\n  doi={10.1109/TASLP.2022.3153257}}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthunlp-mt%2Ftransformer-dmb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthunlp-mt%2Ftransformer-dmb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthunlp-mt%2Ftransformer-dmb/lists"}