Skip to content

Commit

Permalink
Make ptb_word_lm compatible with the latest TensorFlow source while m…
Browse files Browse the repository at this point in the history
…aintaining backwards compatibility with TF 1.0
  • Loading branch information
nealwu committed Mar 28, 2017
1 parent 7b4d025 commit 167b6c6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tutorials/rnn/ptb/ptb_word_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,17 @@ def __init__(self, is_training, config, input_):
# initialized to 1 but the hyperparameters of the model would need to be
# different than reported in the paper.
def lstm_cell():
return tf.contrib.rnn.BasicLSTMCell(
size, forget_bias=0.0, state_is_tuple=True)
# With the latest TensorFlow source code (as of Mar 27, 2017),
# the BasicLSTMCell will need a reuse parameter which is unfortunately not
# defined in TensorFlow 1.0. To maintain backwards compatibility, we add a
# try-except here:
try:
return tf.contrib.rnn.BasicLSTMCell(
size, forget_bias=0.0, state_is_tuple=True,
reuse=tf.get_variable_scope().reuse)
except TypeError:
return tf.contrib.rnn.BasicLSTMCell(
size, forget_bias=0.0, state_is_tuple=True)
attn_cell = lstm_cell
if is_training and config.keep_prob < 1:
def attn_cell():
Expand Down

0 comments on commit 167b6c6

Please sign in to comment.