{"id":18887156,"url":"https://github.com/thunlp-mt/plm4mt","last_synced_at":"2025-04-14T22:33:50.361Z","repository":{"id":46536567,"uuid":"470903797","full_name":"THUNLP-MT/PLM4MT","owner":"THUNLP-MT","description":"Code for our work \"MSP: Multi-Stage Prompting for Making Pre-trained Language Models Better Translators\" in ACL 2022","archived":false,"fork":false,"pushed_at":"2022-03-18T13:01:23.000Z","size":48,"stargazers_count":20,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-28T10:54:18.402Z","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}},"created_at":"2022-03-17T08:16:42.000Z","updated_at":"2024-02-10T11:52:46.000Z","dependencies_parsed_at":"2022-09-07T02:52:10.303Z","dependency_job_id":null,"html_url":"https://github.com/THUNLP-MT/PLM4MT","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%2FPLM4MT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUNLP-MT%2FPLM4MT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUNLP-MT%2FPLM4MT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUNLP-MT%2FPLM4MT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/THUNLP-MT","download_url":"https://codeload.github.com/THUNLP-MT/PLM4MT/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248973080,"owners_count":21191910,"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:51.446Z","updated_at":"2025-04-14T22:33:45.341Z","avatar_url":"https://github.com/THUNLP-MT.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PLM4MT\n\nThis is the code for our ACL 2022 work [MSP: Multi-Stage Prompting for Making Pre-trained Language Models Better Translators](http://arxiv.org/abs/2110.06609). 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* [mGPT](#mgpt)\n* [Format](#format)\n* [Training](#training)\n* [Decoding](#decoding)\n* [Postprocessing](#postprocessing)\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* transformers\n\nPlease read the document of [THUMT](https://github.com/THUNLP-MT/THUMT/blob/master/docs/index.md) before using this Repository.\n\n## mGPT\nYou can download the mGPT checkpoint at [this url](https://huggingface.co/THUMT/mGPT).\n\n## Format\n\nWe use `\u003cextra_id_0\u003e` to separate a source and a target sentence. For the WMT14 En-De dataset, the training file contains lines with the following format:\n\n```\n\u003cextra_id_5\u003e Graphical artwork, corporate identity and corporate design. \u003cextra_id_0\u003e Grafische Gestaltung, Layout, Corporate Identity und Corporate Design.\n```\n\nHere `\u003cextra_id_5\u003e` is a tag to indicate the source language, which can be omitted.\n\nFor inference, the test set contains lines like:\n\n```\n\u003cextra_id_5\u003e Gutach: Increased safety for pedestrians \u003cextra_id_0\u003e\n```\n\n\n\n\n## Training\n\nUsing the following command to train a prompt for translation:\n\n```[bash]\nCODES=\u003cpath/to/this-repository\u003e\nCKPT=\u003cpath/to/mGPT-checkpoint\u003e\nexport PYTHONPATH=$CODES:$PYTHONPATH\n\nexport USE_TF=0\nexport USE_TORCH=1\n\npython $CODES/thumt/bin/trainer.py \\\n    --half \\\n    --input \u003cpath/to/traininig-file\u003e \\\n    --model \u003cmodel_name\u003e \\\n    --ptm $CKPT \\\n    --parameters=device_list=[0,1,2,3,4,5,6,7],\\\n                 train_steps=40000,update_cycle=16,batch_size=256,\\\n                 save_checkpoint_steps=2000,max_length=256 \\\n    --hparam_set base\n```\n\nHere `model_name` has the following three options:\n\n* `mgpt_prompt`: mGPT with Prompt tuning\n* `mgpt_prefix`: mGPT with Prefix-tuning\n* `mgpt_msp`: mGPT with multi-stage prompting\n\n## Decoding\n\nThe following command decodes an input file:\n```\nCODES=\u003cpath/to/this-repository\u003e\nexport PYTHONPATH=\u003cpath/to/this-repository\u003e:$PYTHONPATH\n\npython $CODES/thumt/bin/translator.py \\\n  --input \u003cpath/to/test-file\u003e \\\n  --ptm \u003cpath/to/mgpt\u003e \\\n  --output \u003cpath/to/output-file\u003e \\\n  --model \u003cmodel-name\u003e \\\n  --half --prefix \u003cpath/to/trained-prompt\u003e \\\n  --parameters=device_list=[0,1,2,3],\\\n               decode_alpha=0.0,\\\n               decode_batch_size=4,\\\n               prompt_length=128\n```\n\n## Postprocessing\n\nWe use `tools/punc.cpp` to replace punctuations for Chinese. Use the following command to compile the code:\n\n```[bash]\ng++ -std=c++11 -o punc tools/punc.cpp\n```\n\nThen use the following command to replace punctuations\n\n```[bash]\ncat \u003cpath/to/input-file\u003e | ./punc | \u003cpath/to/output-file\u003e\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{tan2021msp,\n  title={{MSP}: Multi-stage prompting for making pre-trained language models better translators},\n  author={Tan, Zhixing and Zhang, Xiangwen and Wang, Shuo and Liu, Yang},\n  journal={arXiv preprint arXiv:2110.06609},\n  year={2021}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthunlp-mt%2Fplm4mt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthunlp-mt%2Fplm4mt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthunlp-mt%2Fplm4mt/lists"}