11# T2T: Tensor2Tensor Transformers
22
3+ [ ![ PyPI
4+ version] ( https://badge.fury.io/py/tensor2tensor.svg )] ( https://badge.fury.io/py/tensor2tensor )
5+ [ ![ GitHub
6+ Issues] ( https://img.shields.io/github/issues/tensorflow/tensor2tensor.svg )] ( https://github.com/tensorflow/tensor2tensor/issues )
7+ [ ![ Contributions
8+ welcome] ( https://img.shields.io/badge/contributions-welcome-brightgreen.svg )] ( CONTRIBUTING.md )
9+ [ ![ License] ( https://img.shields.io/badge/License-Apache%202.0-brightgreen.svg )] ( https://opensource.org/licenses/Apache-2.0 )
10+
311[ T2T] ( https://github.com/tensorflow/tensor2tensor ) is a modular and extensible
4- library and binaries for supervised learning with TensorFlow and with a focus on
5- sequence tasks. Actively used and maintained by researchers and engineers within
6- Google Brain, T2T strives to maximize idea bandwidth and minimize execution
7- latency.
8-
9- T2T is particularly well-suited to researchers working on sequence tasks. We're
10- eager to collaborate with you on extending T2T's powers, so please feel free to
11- open an issue on GitHub to kick off a discussion and send along pull requests,
12- See [ our contribution doc] ( CONTRIBUTING.md ) for details and our [ open
12+ library and binaries for supervised learning with TensorFlow and with support
13+ for sequence tasks. It is actively used and maintained by researchers and
14+ engineers within the Google Brain team.
15+
16+ We're eager to collaborate with you on extending T2T, so please feel
17+ free to [ open an issue on
18+ GitHub] ( https://github.com/tensorflow/tensor2tensor/issues ) or
19+ send along a pull request to add your data-set or model.
20+ See [ our contribution
21+ doc] ( CONTRIBUTING.md ) for details and our [ open
1322issues] ( https://github.com/tensorflow/tensor2tensor/issues ) .
1423
15- ## T2T overview
24+ ---
25+
26+ ## Walkthrough
27+
28+ Here's a walkthrough training a good English-to-German translation
29+ model using the Transformer model from [ * Attention Is All You
30+ Need* ] ( https://arxiv.org/abs/1706.03762 ) on WMT data.
1631
1732```
1833pip install tensor2tensor
1934
35+ # See what problems, models, and hyperparameter sets are available.
36+ # You can easily swap between them (and add new ones).
37+ t2t-trainer --registry_help
38+
2039PROBLEM=wmt_ende_tokens_32k
2140MODEL=transformer
2241HPARAMS=transformer_base
42+
2343DATA_DIR=$HOME/t2t_data
2444TMP_DIR=/tmp/t2t_datagen
2545TRAIN_DIR=$HOME/t2t_train/$PROBLEM/$MODEL-$HPARAMS
@@ -35,6 +55,7 @@ t2t-datagen \
3555mv $TMP_DIR/tokens.vocab.32768 $DATA_DIR
3656
3757# Train
58+ # * If you run out of memory, add --hparams='batch_size=2048' or even 1024.
3859t2t-trainer \
3960 --data_dir=$DATA_DIR \
4061 --problems=$PROBLEM \
@@ -59,23 +80,63 @@ t2t-trainer \
5980 --output_dir=$TRAIN_DIR \
6081 --train_steps=0 \
6182 --eval_steps=0 \
62- --beam_size =$BEAM_SIZE \
63- --alpha =$ALPHA \
83+ --decode_beam_size =$BEAM_SIZE \
84+ --decode_alpha =$ALPHA \
6485 --decode_from_file=$DECODE_FILE
6586
6687cat $DECODE_FILE.$MODEL.$HPARAMS.beam$BEAM_SIZE.alpha$ALPHA.decodes
6788```
6889
69- T2T modularizes training into several components, each of which can be seen in
70- use in the above commands.
90+ ---
7191
72- See the models, problems, and hyperparameter sets that are available:
92+ ## Installation
7393
74- ` t2t-trainer --registry_help `
94+ ```
95+ pip install tensor2tensor
96+ ```
97+
98+ Binaries:
99+
100+ ```
101+ # Data generator
102+ t2t-datagen
103+
104+ # Trainer
105+ t2t-trainer --registry_help
106+ ```
107+
108+ Library usage:
109+
110+ ```
111+ python -c "from tensor2tensor.models.transformer import Transformer"
112+ ```
113+
114+ ---
115+
116+ ## Features
117+
118+ * Many state of the art and baseline models are built-in and new models can be
119+ added easily (open an issue or pull request!).
120+ * Many datasets across modalities - text, audio, image - available for
121+ generation and use, and new ones can be added easily (open an issue or pull
122+ request for public datasets!).
123+ * Models can be used with any dataset and input mode (or even multiple); all
124+ modality-specific processing (e.g. embedding lookups for text tokens) is done
125+ with ` Modality ` objects, which are specified per-feature in the dataset/task
126+ specification.
127+ * Support for multi-GPU machines and synchronous (1 master, many workers) and
128+ asynchrounous (independent workers synchronizing through a parameter server)
129+ distributed training.
130+ * Easily swap amongst datasets and models by command-line flag with the data
131+ generation script ` t2t-datagen ` and the training script ` t2t-trainer ` .
132+
133+ ---
134+
135+ ## T2T overview
75136
76137### Datasets
77138
78- ** Datasets** are all standardized on TFRecord files with ` tensorflow.Example `
139+ ** Datasets** are all standardized on ` TFRecord ` files with ` tensorflow.Example `
79140protocol buffers. All datasets are registered and generated with the
80141[ data
81142generator] ( https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/bin/t2t-datagen )
@@ -125,10 +186,12 @@ hyperparameters can be overriden with the `--hparams` flag. `--schedule` and
125186related flags control local and distributed training/evaluation
126187([ distributed training documentation] ( https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/docs/distributed_training.md ) ).
127188
189+ ---
190+
128191## Adding a dataset
129192
130- See the data generators
131- [ README] ( https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/data_generators/README.md ) .
193+ See the [ data generators
194+ README] ( https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/data_generators/README.md ) .
132195
133196---
134197
0 commit comments