Trying to reproduce wmt_ende_bpe32k
I' trying to reproduce wmt_ende_bpe32k. The data generations fails with the following error, however:
INFO:tensorflow:Generating training data for wmt_ende_bpe32k.
Traceback (most recent call last):
File "/usr/local/bin/t2t-datagen", line 361, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "/usr/local/bin/t2t-datagen", line 345, in main
FLAGS.data_dir, FLAGS.num_shards, FLAGS.max_cases)
File "/usr/local/lib/python2.7/dist-packages/tensor2tensor/data_generators/generator_utils.py", line 113, in generate_files
for case in generator:
File "/usr/local/lib/python2.7/dist-packages/tensor2tensor/data_generators/wmt.py", line 83, in token_generator
source_ints = token_vocab.encode(source.strip()) + eos_list
File "/usr/local/lib/python2.7/dist-packages/tensor2tensor/data_generators/text_encoder.py", line 120, in encode
ret = [self._token_to_id[tok] for tok in sentence.strip().split()]
AttributeError: 'TokenTextEncoder' object has no attribute '_token_to_id'
I'm using the following command:
PROBLEM=wmt_ende_bpe32k
MODEL=transformer
HPARAMS=transformer_base
DATA_DIR=$HOME/t2t_data
TMP_DIR=/tmp/t2t_datagen
TRAIN_DIR=$HOME/t2t_train/$PROBLEM/$MODEL-$HPARAMS
mkdir -p $DATA_DIR $TMP_DIR $TRAIN_DIR
# Generate data
t2t-datagen \
--data_dir=$DATA_DIR \
--tmp_dir=$TMP_DIR \
--num_shards=100 \
--problem=$PROBLEM
mv $TMP_DIR/vocab.bpe.32000 $DATA_DIR
# Train
# * If you run out of memory, add --hparams='batch_size=2048' or even 1024.
t2t-trainer \
--data_dir=$DATA_DIR \
--problems=$PROBLEM \
--model=$MODEL \
--hparams_set=$HPARAMS \
--output_dir=$TRAIN_DIR \
--worker_gpu=2 \
--log_dir logs
# Decode
DECODE_FILE=$DATA_DIR/decode_this.txt
echo "Hello world" >> $DECODE_FILE
echo "Goodbye world" >> $DECODE_FILE
BEAM_SIZE=4
ALPHA=0.6
t2t-trainer \
--data_dir=$DATA_DIR \
--problems=$PROBLEM \
--model=$MODEL \
--hparams_set=$HPARAMS \
--output_dir=$TRAIN_DIR \
--train_steps=0 \
--eval_steps=0 \
--decode_beam_size=$BEAM_SIZE \
--decode_alpha=$ALPHA \
--decode_from_file=$DECODE_FILE
cat $DECODE_FILE.$MODEL.$HPARAMS.beam$BEAM_SIZE.alpha$ALPHA.decodes
I've downloaded wmt16_en_de.tar.gz and placed it in /tmp/t2t_datagen as specified in wmt.py:
def _get_wmt_ende_dataset(directory, filename):
"""Extract the WMT en-de corpus `filename` to directory unless it's there."""
train_path = os.path.join(directory, filename)
if not (tf.gfile.Exists(train_path + ".de") and
tf.gfile.Exists(train_path + ".en")):
# We expect that this file has been downloaded from:
# https://drive.google.com/open?id=0B_bZck-ksdkpM25jRUN2X2UxMm8 and placed
# in `directory`.
corpus_file = os.path.join(directory, "wmt16_en_de.tar.gz")
with tarfile.open(corpus_file, "r:gz") as corpus_tar:
corpus_tar.extractall(directory)
return train_path
Could you verify the checksum for the downloaded wmt16_en_de.tar.gz:
$ sha256sum wmt16_en_de.tar.gz
86f7f6e0bab3259a34712b4c034dc933f406d6735ce03fd6de6b9ccb5191ce2e wmt16_en_de.tar.gz
I tried data generation both with tensor2tensor 1.0.4 and 1.0.5 and it worked.
It says:
86f7f6e0bab3259a34712b4c034dc933f406d6735ce03fd6de6b9ccb5191ce2e wmt16_en_de.tar.gz
Ok, so do you use the latest version of tensor2tensor? E.g.:
File "/usr/local/lib/python2.7/dist-packages/tensor2tensor/data_generators/text_encoder.py", line 120, in encode
ret = [self._token_to_id[tok] for tok in sentence.strip().split()]
In the latest version this statement is not in line 120. I guess you can simply run pip2 install --upgrade tensor2tensor to get the latest version :)
Thank you so much, Stefan! This saved my day!