【发布时间】:2016-11-27 08:29:17
【问题描述】:
我知道已经有类似标题的问题,但在您重复报告之前,请允许我说,这些问题的所有答案都是非常临时的,不适用于我的问题。
我无法理解为什么我不能在 TensorFlow 中进行两个张量的矩阵乘法(好吧,技术上是矩阵向量乘法)。我有一个形状为 (1000, 1000) 的张量 v 和另一个形状为 (1000) 的张量 h_previous。我之前在程序中用两个 完全相同形状 的张量进行了大量矩阵乘法,但这只是抛出一个神秘的错误。以下是图表的关键部分:
# Variables
# Encoder input
X = tf.placeholder(tf.float32, shape=[k, None])
we = tf.Variable(tf.truncated_normal([500, k], -0.1, 0.1))
# Encoder update gate
wz = tf.Variable(tf.truncated_normal([1000, 500], -0.1, 0.1))
uz = tf.Variable(tf.truncated_normal([1000, 1000], -0.1, 0.1))
# Encoder reset gate
wr = tf.Variable(tf.truncated_normal([1000, 500], -0.1, 0.1))
ur = tf.Variable(tf.truncated_normal([1000, 1000], -0.1, 0.1))
# Encoder h~ [find name]
w = tf.Variable(tf.truncated_normal([1000, 500], -0.1, 0.1))
u = tf.Variable(tf.truncated_normal([1000, 1000], -0.1, 0.1))
# Encoder representation weight
v = tf.Variable(tf.truncated_normal([1000, 1000], -0.1, 0.1))
# Encoder
h_previous = tf.zeros([1000])
for t in range(N):
# Current vector and its embedding
xt = tf.reshape(tf.slice(X, [t, 0], [1, k]), [k])
e = tf.matmul(we, xt)
# Reset calculation
r = tf.sigmoid(tf.matmul(wr, e) + tf.matmul(ur, h_previous))
# Update calculation
z = tf.sigmoid(tf.matmul(wz, e) + tf.matmul(uz, h_previous))
# Hidden-tilde calculation
h_tilde = tf.tanh(tf.matmul(w, e) + tf.matmul(u, r * h_previous))
# Hidden calculation
one = tf.ones([1000])
h = z * h_previous + (one - z) * h_tilde
h_previous = h
c = tf.tanh(tf.matmul(v, h_previous))
我被难住了。有没有人有任何线索?提前致谢。 :)
【问题讨论】:
标签: python python-3.x tensorflow