{"id":13595595,"url":"https://github.com/Kyubyong/transformer","last_synced_at":"2025-04-09T13:32:45.162Z","repository":{"id":38240309,"uuid":"94618560","full_name":"Kyubyong/transformer","owner":"Kyubyong","description":"A TensorFlow Implementation of the Transformer: Attention Is All You Need","archived":false,"fork":false,"pushed_at":"2023-05-21T17:39:56.000Z","size":5578,"stargazers_count":4272,"open_issues_count":136,"forks_count":1296,"subscribers_count":110,"default_branch":"master","last_synced_at":"2024-10-29T15:30:42.318Z","etag":null,"topics":["attention-is-all-you-need","attention-mechanism","implementation","transformer","translation"],"latest_commit_sha":null,"homepage":"","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/Kyubyong.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}},"created_at":"2017-06-17T11:08:40.000Z","updated_at":"2024-10-28T07:19:40.000Z","dependencies_parsed_at":"2022-07-13T15:59:27.923Z","dependency_job_id":"9b6fe147-a34c-46ea-a488-48aad5c4b1c5","html_url":"https://github.com/Kyubyong/transformer","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/Kyubyong%2Ftransformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyubyong%2Ftransformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyubyong%2Ftransformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyubyong%2Ftransformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kyubyong","download_url":"https://codeload.github.com/Kyubyong/transformer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223394629,"owners_count":17138587,"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":["attention-is-all-you-need","attention-mechanism","implementation","transformer","translation"],"created_at":"2024-08-01T16:01:53.151Z","updated_at":"2024-11-06T18:31:19.865Z","avatar_url":"https://github.com/Kyubyong.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# **[UPDATED]** A TensorFlow Implementation of [Attention Is All You Need](https://arxiv.org/abs/1706.03762)\n\nWhen I opened this repository in 2017, there was no official code yet.\nI tried to implement the paper as I understood, but to no surprise\nit had several bugs. I realized them mostly thanks to people who issued here, so\nI'm very grateful to all of them. Though there is the [official implementation](https://github.com/tensorflow/tensor2tensor) as well as\nseveral other unofficial github repos, I decided to update my own one.\nThis update focuses on:\n* readable / understandable code writing\n* modularization (but not too much)\n* revising known bugs. (masking, positional encoding, ...)\n* updating to TF1.12. (tf.data, ...)\n* adding some missing components (bpe, shared weight matrix, ...)\n* including useful comments in the code.\n\nI still stick to IWSLT 2016 de-en. I guess if you'd like to test on a big data such\nas WMT, you would rely on the official implementation.\nAfter all, it's pleasant to check quickly if your model works.\nThe initial code for TF1.2 is moved to the [tf1.2_lecacy](tf1.2_legacy) folder for the record.\n\n## Requirements\n* python==3.x (Let's move on to python 3 if you still use python 2)\n* tensorflow==1.12.0\n* numpy\u003e=1.15.4\n* sentencepiece==0.1.8\n* tqdm\u003e=4.28.1\n\n## Training\n* STEP 1. Run the command below to download [IWSLT 2016 German–English parallel corpus](https://wit3.fbk.eu/download.php?release=2016-01\u0026type=texts\u0026slang=de\u0026tlang=en).\n```\nbash download.sh\n```\n It should be extracted to `iwslt2016/de-en` folder automatically.\n* STEP 2. Run the command below to create preprocessed train/eval/test data.\n```\npython prepro.py\n```\nIf you want to change the vocabulary size (default:32000), do this.\n```\npython prepro.py --vocab_size 8000\n```\nIt should create two folders `iwslt2016/prepro` and `iwslt2016/segmented`.\n\n* STEP 3. Run the following command.\n```\npython train.py\n```\nCheck `hparams.py` to see which parameters are possible. For example,\n```\npython train.py --logdir myLog --batch_size 256 --dropout_rate 0.5\n```\n\n* STEP 3. Or download the pretrained models.\n```\nwget https://dl.dropbox.com/s/4lom1czy5xfzr4q/log.zip; unzip log.zip; rm log.zip\n```\n\n\n## Training Loss Curve\n\u003cimg src=\"fig/loss.png\"\u003e\n\n## Learning rate\n\u003cimg src=\"fig/lr.png\"\u003e\n\n## Bleu score on devset\n\u003cimg src=\"fig/bleu.png\"\u003e\n\n\n## Inference (=test)\n* Run\n```\npython test.py --ckpt log/1/iwslt2016_E19L2.64-29146 (OR yourCkptFile OR yourCkptFileDirectory)\n```\n\n## Results\n* Typically, machine translation is evaluated with Bleu score.\n* All evaluation results are available in [eval/1](eval/1) and [test/1](test/1).\n\n|tst2013 (dev) | tst2014 (test) |\n|--|--|\n|28.06|23.88|\n\n## Notes\n* Beam decoding will be added soon.\n* I'm going to update the code when TF2.0 comes out if possible.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKyubyong%2Ftransformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKyubyong%2Ftransformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKyubyong%2Ftransformer/lists"}