Skip to content

Commit

Permalink
Rewrite to use inspect.getargspec
Browse files Browse the repository at this point in the history
  • Loading branch information
nealwu committed Mar 28, 2017
1 parent 167b6c6 commit c15fada
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tutorials/rnn/ptb/ptb_word_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from __future__ import division
from __future__ import print_function

import inspect
import time

import numpy as np
Expand Down Expand Up @@ -111,13 +112,14 @@ def __init__(self, is_training, config, input_):
def lstm_cell():
# 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:
# defined in TensorFlow 1.0. To maintain backwards compatibility, we add
# an argument check here:
if 'reuse' in inspect.getargspec(
tf.contrib.rnn.BasicLSTMCell.__init__).args:
return tf.contrib.rnn.BasicLSTMCell(
size, forget_bias=0.0, state_is_tuple=True,
reuse=tf.get_variable_scope().reuse)
except TypeError:
else:
return tf.contrib.rnn.BasicLSTMCell(
size, forget_bias=0.0, state_is_tuple=True)
attn_cell = lstm_cell
Expand Down

0 comments on commit c15fada

Please sign in to comment.