在使用sampled_softmax_loss出现的一个关于‘’nput 'b' of 'MatMul' Op has type float32 that does not match type in...

在使用负采样函数的时候出现了该错误,错误代码:

tf.nn.sampled_softmax_loss(softmax_weights, softmax_biases,
                tf.reduce_sum(embeds, 1),
                train_labels,
                num_sampled, vocabulary_size)
原因:参数赋值错误
查看sampled_softmax_loss的源代码可知其参数定义为
def sampled_softmax_loss(weights,
biases,
labels,
inputs,
num_sampled,
num_classes,
num_true=1,
sampled_values=None,
remove_accidental_hits=True,
partition_strategy="mod",
name="sampled_softmax_loss",
seed=None):
因此 代码中的参数赋值顺序错误 labels 对应的应是train_labels inputs对应的应是tf.reduce_sum(embeds, 1)

解决办法:
采用指定赋值的方式:tf.nn.sampled_softmax_loss(weights=softmax_weights,
                 biases=softmax_biases,
                inputs=tf.reduce_sum(embeds, 1),
                labels=train_labels,
                num_sampled=num_sampled,
                num_classes=vocabulary_size
)

或者 更改赋值变量位置:
tf.nn.sampled_softmax_loss(softmax_weights, softmax_biases,
train_labels, tf.reduce_sum(embeds, 1),num_sampled, vocabulary_size)

则可以顺利解决这个问题

同时也是对平时编写程序的一个习惯问题,在参数较多的情况下,最好采用指定复制的方式!

  


转载于:https://www.cnblogs.com/deeplearning1/p/11413206.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值