1. 程式人生 > >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'.

訓練詞向量時出現錯誤:

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