|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | + |
| 4 | +@description: |
| 5 | +""" |
| 6 | + |
| 7 | + |
| 8 | +# See what problems, models, and hyperparameter sets are available. |
| 9 | +# You can easily swap between them (and add new ones). |
| 10 | +t2t-trainer --registry_help |
| 11 | + |
| 12 | +PROBLEM=translate_ende_wmt32k |
| 13 | +MODEL=transformer |
| 14 | +HPARAMS=transformer_base_single_gpu |
| 15 | + |
| 16 | +DATA_DIR=$HOME/t2t_data |
| 17 | +TMP_DIR=/tmp/t2t_datagen |
| 18 | +TRAIN_DIR=$HOME/t2t_train/$PROBLEM/$MODEL-$HPARAMS |
| 19 | + |
| 20 | +mkdir -p $DATA_DIR $TMP_DIR $TRAIN_DIR |
| 21 | + |
| 22 | +# Generate data |
| 23 | +t2t-datagen \ |
| 24 | + --data_dir=$DATA_DIR \ |
| 25 | + --tmp_dir=$TMP_DIR \ |
| 26 | + --problem=$PROBLEM |
| 27 | + |
| 28 | +# Train |
| 29 | +# * If you run out of memory, add --hparams='batch_size=1024'. |
| 30 | +t2t-trainer \ |
| 31 | + --data_dir=$DATA_DIR \ |
| 32 | + --problem=$PROBLEM \ |
| 33 | + --model=$MODEL \ |
| 34 | + --hparams_set=$HPARAMS \ |
| 35 | + --output_dir=$TRAIN_DIR |
| 36 | + |
| 37 | +# Decode |
| 38 | + |
| 39 | +DECODE_FILE=$DATA_DIR/decode_this.txt |
| 40 | +echo "Hello world" >> $DECODE_FILE |
| 41 | +echo "Goodbye world" >> $DECODE_FILE |
| 42 | +echo -e 'Hallo Welt\nAuf Wiedersehen Welt' > ref-translation.de |
| 43 | + |
| 44 | +BEAM_SIZE=4 |
| 45 | +ALPHA=0.6 |
| 46 | + |
| 47 | +t2t-decoder \ |
| 48 | + --data_dir=$DATA_DIR \ |
| 49 | + --problem=$PROBLEM \ |
| 50 | + --model=$MODEL \ |
| 51 | + --hparams_set=$HPARAMS \ |
| 52 | + --output_dir=$TRAIN_DIR \ |
| 53 | + --decode_hparams="beam_size=$BEAM_SIZE,alpha=$ALPHA" \ |
| 54 | + --decode_from_file=$DECODE_FILE \ |
| 55 | + --decode_to_file=translation.en |
| 56 | + |
| 57 | +# See the translations |
| 58 | +cat translation.en |
| 59 | + |
| 60 | +# Evaluate the BLEU score |
| 61 | +# Note: Report this BLEU score in papers, not the internal approx_bleu metric. |
| 62 | +t2t-bleu --translation=translation.en --reference=ref-translation.de |
0 commit comments