{"id":17141065,"url":"https://github.com/zphang/num2num","last_synced_at":"2025-03-24T08:17:45.233Z","repository":{"id":116145781,"uuid":"107599555","full_name":"zphang/num2num","owner":"zphang","description":"PyTorch RNNs on a toy example of translating between numbers in words and digits","archived":false,"fork":false,"pushed_at":"2017-10-22T15:13:44.000Z","size":26040,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-29T13:43:33.235Z","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/zphang.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-19T21:15:59.000Z","updated_at":"2017-12-15T20:52:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"f182cbe5-c8cf-4847-a30f-90323c634fcc","html_url":"https://github.com/zphang/num2num","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/zphang%2Fnum2num","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zphang%2Fnum2num/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zphang%2Fnum2num/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zphang%2Fnum2num/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zphang","download_url":"https://codeload.github.com/zphang/num2num/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245232917,"owners_count":20581703,"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-10-14T20:24:15.028Z","updated_at":"2025-03-24T08:17:45.211Z","avatar_url":"https://github.com/zphang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Home\n\nAn example (Attentional) Encoder-Decoder RNN in PyTorch, applied to a toy data set: translating back and forth between numbers-as-text (\"one thousand and two\") and numbers-as-digits (\"1002\").\n\n### Introduction\n\nThis project began as an attempt to code up an implementation of attentional RNNs against a simple data set, to understand the inner-workings of the attention mechanism. It turns out that the implementation can get fairly non-trivial.\n\nIn particular, the attention portions of the code heavily referenced the implementation in https://github.com/spro/practical-pytorch/tree/master/seq2seq-translation.\n\n![Attention Plot](static/attn.png)\n\n*Attention plot between input (top) and output (left). The attention isn't perfect because our models can be way over-parameterized compared the the problem.*\n\n\n### Requirements\n- Python 3.6\n- [PyTorch 0.2.0](http://pytorch.org/)\n- (For generating data) `num2words`, `tqdm`\n- `pandas`, `argparse`, `matplotlib`, `seaborn`\n\n\n### Data\n\nUsing `num2words`, we can generate random numbers and get the \"ground-truth\" text versions of those numbers. Commas are removed, and the remaining tokens have been pre-computed and saved in (`datafiles/word2num_tokens`)[datafiles/word2num_tokens]. \n\nNote that `num2num` supports both word-level and character-level modeling, so both tokenizations have been pre-computed.\n\n\n### Usage\n\n1. Git clone this repository.\n2. (Optional) Generate training and validation datasets. A very small sample training and validation dataset is included with the project. \n    * E.g. \n        ```bash\n        python gendata.py \\\n            --output=datafiles/train_numbers.csv \\\n            --size=100000\n\n        python gendata.py \\\n            --output=datafiles/val_numbers.csv \\ \n            --size=10000\n        ```\n    * Run `python gendata.py -h` or see `gendata.py` for details and more options.\n3. Train the model:\n    * E.g.\n        ```bash\n        python run_train.py \\\n          --train_data_path=datafiles/train_numbers.csv \\\n          --val_data_path=datafiles/val_numbers.csv \\\n          --plot_attn_show=False \\\n          --plot_attn_save_path=\"output/attn_plots\" \\\n          --model_save_path=\"output/models\n        ```\n    * Run `python run_train.py -h` or see `orchestrate.py` and `num2num/config.py` for details and more options\n4. Sample from model:\n    * E.g.\n        ```bash\n        python run_sample.py \\\n          --val_data_path=datafiles/val_numbers.csv \\\n          --model_save_path=\"output/models/my_favorite_model\n        ```\n    * Run `python run_sample.py -h` or see `orchestrate.py` and `num2num/config.py` for details and more options\n    \n### Road map\n\n- [ ] Documentation\n- [ ] Tests","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzphang%2Fnum2num","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzphang%2Fnum2num","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzphang%2Fnum2num/lists"}