在Tensorflow中输入占位符时要使用哪些值



在下面的代码中,有许多张量运算和计算。我想看看其中一些计算的结果,这样我就能更好地理解它们。具体来说,我想看看在使用print(Session.Run(h))执行图形时h是什么样子的。然而,计算依赖于占位符X。因此,为了查看它们,我需要使用提要词典。

我已经阅读了这个SO问题:如何提供占位符?以及其他几个。我仍然不知道我应该在这个占位符中输入什么。

要查看h的值,在尝试打印时,我应该如何或更确切地说,在提要字典中放入什么?

def expand_tile(value, size):
"""Add a new axis of given size."""
value = tf.convert_to_tensor(value, name='value')
ndims = value.shape.ndims
return tf.tile(tf.expand_dims(value, axis=0), [size] + [1]*ndims)
def positions_for(tokens, past_length):
batch_size = tf.shape(tokens)[0]
nsteps = tf.shape(tokens)[1]
return expand_tile(past_length + tf.range(nsteps), batch_size)

def model(hparams, X, past=None, scope='model', reuse=tf.AUTO_REUSE):
with tf.variable_scope(scope, reuse=reuse):
results = {}
batch_size = 1
X = tf.placeholder(tf.int32, [batch_size, None])
batch, sequence = shape_list(X)
wpe = tf.get_variable('wpe', [1024, 768],
initializer=tf.random_normal_initializer(stddev=0.01))
wte = tf.get_variable('wte', [50256, 768],
initializer=tf.random_normal_initializer(stddev=0.02))
past_length = 0 if past is None else tf.shape(past)[-2]
h = tf.gather(wte, X) + tf.gather(wpe, positions_for(X, past_length))

当您使用交互式会话时,您只需在python x=57中设置值,完全绕过占位符,然后根据需要评估图的其余部分。

最新更新