TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a'.

训练词向量时出现错误:

TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a'.

错误出现在:

loss = tf.reduce_mean(tf.nn.sampled_softmax_loss(softmax_weights, softmax_biases, embed,train_labels, num_sampled, vocabulary_size))

原因是tensorflow的sampled_softmax_loss的定义如下:

tf.nn.sampled_softmax_loss(weights=None, biases=None, labels=None, inputs=None, num_sampled=None, vocabulary_size=None)

参数代入位置错误,修改为:

loss = tf.reduce_mean(tf.nn.sampled_softmax_loss(
    softmax_weights, softmax_biases, tf_train_labels, inputs, num_sampled, vocabulary_size))

word2vec的代码:

https://github.com/shelleyHLX/word2vec_tensorflow

猜你喜欢

转载自blog.csdn.net/qq_27009517/article/details/84618270