Export
Flax seq2seq Example
Demonstration notebook for https://github.com/google/flax/tree/main/examples/seq2seq
The Flax Notebook Workflow:
- Run the entire notebook end-to-end and check out the outputs.
- This will open Python files in the right-hand editor!
- You'll be able to interactively explore metrics in TensorBoard.
- Change some of the hyperparameters in the command-line flags in
train.pyfor different hyperparameters. Check out the updated TensorBoard plots. - Update the code in
train.py,models.py, andinput_pipeline.py. Thanks to%autoreload, any changes you make in the file will automatically appear in the notebook. Some ideas to get you started:- Change the model.
- Log some per-batch metrics during training.
- Add new hyperparameters to
models.pyand use them intrain.py. - Train on a different vocabulary by initializing
CharacterTablewith a different character set.
- At any time, feel free to paste code from the source code into the notebook and modify it directly there!
Setup
[ ]
|████████████████████████████████| 77 kB 3.1 MB/s
|████████████████████████████████| 176 kB 30.2 MB/s
|████████████████████████████████| 77 kB 5.2 MB/s
|████████████████████████████████| 136 kB 45.5 MB/s
|████████████████████████████████| 65 kB 2.8 MB/s
|████████████████████████████████| 462 kB 44.3 MB/s
Building wheel for ml-collections (setup.py) ... done
[ ]
[ ]
mount_gdrive no
Cloning into 'flaxrepo'... remote: Enumerating objects: 349, done. remote: Counting objects: 100% (349/349), done. remote: Compressing objects: 100% (286/286), done. remote: Total 349 (delta 63), reused 220 (delta 51), pack-reused 0 Receiving objects: 100% (349/349), 2.12 MiB | 13.39 MiB/s, done. Resolving deltas: 100% (63/63), done.
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
[ ]
/content/examples/seq2seq
Imports
[ ]
[ ]
The autoreload extension is already loaded. To reload it, use: %reload_ext autoreload
Dataset
[ ]
[('72+789', '=861'),
, ('58+858', '=916'),
, ('77+358', '=435'),
, ('99+264', '=363'),
, ('94+115', '=209')] [ ]
array([[0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], , [0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], , [0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.], , [0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.], , [0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.], , [0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], , [1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], , [1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]], , dtype=float32)
[ ]
array(['1+243'], dtype='<U5')
Training
[ ]
[ ]
[ ]
['seq2seq']
[ ]
INFO:absl:[100] accuracy=0.015625, loss=0.6936355233192444 INFO:absl:DECODE: 96+964 = 1002 (INCORRECT) correct=1060 INFO:absl:DECODE: 71+545 = 608 (INCORRECT) correct=616 INFO:absl:DECODE: 42+729 = 730 (INCORRECT) correct=771 INFO:absl:DECODE: 28+588 = 684 (INCORRECT) correct=616 INFO:absl:DECODE: 39+648 = 618 (INCORRECT) correct=687 INFO:absl:[200] accuracy=0.03125, loss=0.5422528982162476 INFO:absl:DECODE: 18+70 = 70 (INCORRECT) correct=88 INFO:absl:DECODE: 43+123 = 145 (INCORRECT) correct=166 INFO:absl:DECODE: 72+406 = 460 (INCORRECT) correct=478 INFO:absl:DECODE: 53+443 = 492 (INCORRECT) correct=496 INFO:absl:DECODE: 74+844 = 936 (INCORRECT) correct=918 INFO:absl:[300] accuracy=0.0703125, loss=0.462927907705307 INFO:absl:DECODE: 40+598 = 643 (INCORRECT) correct=638 INFO:absl:DECODE: 2+72 = 75 (INCORRECT) correct=74 INFO:absl:DECODE: 70+742 = 814 (INCORRECT) correct=812 INFO:absl:DECODE: 22+943 = 963 (INCORRECT) correct=965 INFO:absl:DECODE: 85+890 = 975 (CORRECT) INFO:absl:[400] accuracy=0.0390625, loss=0.4398380219936371 INFO:absl:DECODE: 79+562 = 647 (INCORRECT) correct=641 INFO:absl:DECODE: 47+987 = 1043 (INCORRECT) correct=1034 INFO:absl:DECODE: 92+959 = 1064 (INCORRECT) correct=1051 INFO:absl:DECODE: 38+291 = 334 (INCORRECT) correct=329 INFO:absl:DECODE: 95+476 = 571 (CORRECT) INFO:absl:[500] accuracy=0.0703125, loss=0.4079001545906067 INFO:absl:DECODE: 9+871 = 872 (INCORRECT) correct=880 INFO:absl:DECODE: 58+633 = 696 (INCORRECT) correct=691 INFO:absl:DECODE: 6+98 = 113 (INCORRECT) correct=104 INFO:absl:DECODE: 8+325 = 345 (INCORRECT) correct=333 INFO:absl:DECODE: 43+540 = 580 (INCORRECT) correct=583 INFO:absl:[600] accuracy=0.0390625, loss=0.4265238344669342 INFO:absl:DECODE: 67+554 = 613 (INCORRECT) correct=621 INFO:absl:DECODE: 38+189 = 233 (INCORRECT) correct=227 INFO:absl:DECODE: 28+843 = 878 (INCORRECT) correct=871 INFO:absl:DECODE: 11+948 = 969 (INCORRECT) correct=959 INFO:absl:DECODE: 9+121 = 148 (INCORRECT) correct=130 INFO:absl:[700] accuracy=0.078125, loss=0.38418614864349365 INFO:absl:DECODE: 38+528 = 562 (INCORRECT) correct=566 INFO:absl:DECODE: 57+317 = 372 (INCORRECT) correct=374 INFO:absl:DECODE: 64+246 = 300 (INCORRECT) correct=310 INFO:absl:DECODE: 73+296 = 373 (INCORRECT) correct=369 INFO:absl:DECODE: 14+321 = 336 (INCORRECT) correct=335 INFO:absl:[800] accuracy=0.1171875, loss=0.3908345401287079 INFO:absl:DECODE: 26+902 = 931 (INCORRECT) correct=928 INFO:absl:DECODE: 15+818 = 843 (INCORRECT) correct=833 INFO:absl:DECODE: 19+348 = 359 (INCORRECT) correct=367 INFO:absl:DECODE: 79+878 = 959 (INCORRECT) correct=957 INFO:absl:DECODE: 64+824 = 889 (INCORRECT) correct=888 INFO:absl:[900] accuracy=0.203125, loss=0.3021599352359772 INFO:absl:DECODE: 6+477 = 482 (INCORRECT) correct=483 INFO:absl:DECODE: 11+18 = 39 (INCORRECT) correct=29 INFO:absl:DECODE: 35+777 = 814 (INCORRECT) correct=812 INFO:absl:DECODE: 45+156 = 200 (INCORRECT) correct=201 INFO:absl:DECODE: 11+432 = 445 (INCORRECT) correct=443 INFO:absl:[1000] accuracy=0.6015625, loss=0.16906459629535675 INFO:absl:DECODE: 41+156 = 198 (INCORRECT) correct=197 INFO:absl:DECODE: 45+177 = 222 (CORRECT) INFO:absl:DECODE: 94+845 = 937 (INCORRECT) correct=939 INFO:absl:DECODE: 10+73 = 93 (INCORRECT) correct=83 INFO:absl:DECODE: 62+598 = 661 (INCORRECT) correct=660 INFO:absl:[1100] accuracy=0.6796875, loss=0.12802045047283173 INFO:absl:DECODE: 95+134 = 218 (INCORRECT) correct=229 INFO:absl:DECODE: 69+508 = 577 (CORRECT) INFO:absl:DECODE: 74+636 = 710 (CORRECT) INFO:absl:DECODE: 11+522 = 533 (CORRECT) INFO:absl:DECODE: 0+620 = 620 (CORRECT) INFO:absl:[1200] accuracy=0.96875, loss=0.027045272290706635 INFO:absl:DECODE: 93+376 = 469 (CORRECT) INFO:absl:DECODE: 65+474 = 549 (INCORRECT) correct=539 INFO:absl:DECODE: 33+35 = 58 (INCORRECT) correct=68 INFO:absl:DECODE: 87+527 = 615 (INCORRECT) correct=614 INFO:absl:DECODE: 40+77 = 107 (INCORRECT) correct=117 INFO:absl:[1300] accuracy=0.9453125, loss=0.025903644040226936 INFO:absl:DECODE: 9+341 = 350 (CORRECT) INFO:absl:DECODE: 29+59 = 88 (CORRECT) INFO:absl:DECODE: 83+473 = 556 (CORRECT) INFO:absl:DECODE: 51+339 = 390 (CORRECT) INFO:absl:DECODE: 29+63 = 92 (CORRECT) INFO:absl:[1400] accuracy=0.890625, loss=0.03969202935695648 INFO:absl:DECODE: 77+177 = 254 (CORRECT) INFO:absl:DECODE: 66+692 = 759 (INCORRECT) correct=758 INFO:absl:DECODE: 24+321 = 345 (CORRECT) INFO:absl:DECODE: 23+180 = 203 (CORRECT) INFO:absl:DECODE: 67+898 = 965 (CORRECT) INFO:absl:[1500] accuracy=0.984375, loss=0.009904923848807812 INFO:absl:DECODE: 13+119 = 132 (CORRECT) INFO:absl:DECODE: 34+467 = 501 (CORRECT) INFO:absl:DECODE: 20+661 = 681 (CORRECT) INFO:absl:DECODE: 51+779 = 830 (CORRECT) INFO:absl:DECODE: 12+101 = 113 (CORRECT) INFO:absl:[1600] accuracy=0.9375, loss=0.021177640184760094 INFO:absl:DECODE: 61+275 = 336 (CORRECT) INFO:absl:DECODE: 48+831 = 879 (CORRECT) INFO:absl:DECODE: 25+628 = 653 (CORRECT) INFO:absl:DECODE: 87+933 = 1020 (CORRECT) INFO:absl:DECODE: 75+405 = 480 (CORRECT) INFO:absl:[1700] accuracy=0.96875, loss=0.015190182253718376 INFO:absl:DECODE: 83+347 = 430 (CORRECT) INFO:absl:DECODE: 45+832 = 877 (CORRECT) INFO:absl:DECODE: 47+867 = 914 (CORRECT) INFO:absl:DECODE: 39+450 = 489 (CORRECT) INFO:absl:DECODE: 2+357 = 359 (CORRECT) INFO:absl:[1800] accuracy=0.9921875, loss=0.008457459509372711 INFO:absl:DECODE: 64+97 = 161 (CORRECT) INFO:absl:DECODE: 66+335 = 401 (CORRECT) INFO:absl:DECODE: 15+656 = 671 (CORRECT) INFO:absl:DECODE: 40+689 = 729 (CORRECT) INFO:absl:DECODE: 42+104 = 146 (CORRECT) INFO:absl:[1900] accuracy=0.90625, loss=0.026923568919301033 INFO:absl:DECODE: 34+92 = 116 (INCORRECT) correct=126 INFO:absl:DECODE: 52+466 = 518 (CORRECT) INFO:absl:DECODE: 46+47 = 93 (CORRECT) INFO:absl:DECODE: 61+240 = 301 (CORRECT) INFO:absl:DECODE: 86+951 = 1037 (CORRECT)
[ ]
upload_data yes
***** TensorBoard Uploader ***** This will upload your TensorBoard logs to https://tensorboard.dev/ from the following directory: ./workdirs This TensorBoard will be visible to everyone. Do not upload sensitive data. Your use of this service is subject to Google's Terms of Service <https://policies.google.com/terms> and Privacy Policy <https://policies.google.com/privacy>, and TensorBoard.dev's Terms of Service <https://tensorboard.dev/policy/terms/>. This notice will not be shown again while you are logged into the uploader. To log out, run `tensorboard dev auth revoke`. Continue? (yes/NO) yes Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=373649185512-8v619h5kft38l4456nm2dj4ubeqsrvh6.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&state=IjociK9llsm6dSiC1TDFvFmJksFy49&prompt=consent&access_type=offline Enter the authorization code: 4/1AX4XfWi6J9MqoDpbZ5Z_jd1AVheW7277VuUoTOEz5_8NRs_3oP9M7S4T81c New experiment created. View your TensorBoard at: https://tensorboard.dev/experiment/pgfmdFlaQTy9odov72ZvVQ/ [2022-02-25T09:34:21] Started scanning logdir. [2022-02-25T09:34:22] Total uploaded: 38 scalars, 0 tensors, 0 binary objects [2022-02-25T09:34:22] Done scanning logdir. Done. View your TensorBoard at https://tensorboard.dev/experiment/pgfmdFlaQTy9odov72ZvVQ/
Inference
[ ]
(1, 8, 15)
[ ]
[ ]
array(['42'], dtype='<U2')