[英]Tensorflow throws “Dimensions must be equal, but are 100 and 0 for 'MatMul' (op: 'MatMul') with input shapes: [0,100], [0,100].”
[英]Shape must be rank 2 but is rank 3 for 'MatMul_46' (op: 'MatMul') with input shapes: [100,100], [?,15,100]
尝试实现此行代码时出现错误
对于输入形状为[100,100],[?, 15,100]的'MatMul_46'(op:'MatMul'),形状必须为等级2,但等级3。
Q = tf.placeholder(tf.float32, shape=(None, 15))
word_level = Embedding ( vocab_size , 100 , input_length=15)(Q)
#shape(?,15,100)
Wb = tf.Variable(tf.zeros([100, 100]))
C = tf.matmul( word_level ,Wb)
我认为问题是因为3维和2维矩阵的等级不同,但我不知道如何修改
要修改张量以适合特定形状,可以使用tf.reshape
,但要小心以tf.reshape
的方式对其进行重塑。
请参阅说明文件
reshape = tf.reshape(word_level, [-1, 100])
Wb = tf.Variable(tf.zeros([100, 100]))
C = tf.matmul(reshape ,Wb)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.