zoukankan      html  css  js  c++  java
  • 在使用sampled_softmax_loss出现的一个关于‘’nput 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a'.“错误原因以及解决办法

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

    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)

    则可以顺利解决这个问题

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

      


  • 相关阅读:
    值不丢失,虽然仅在局部函数中存在
    js 中和c类似
    天天QA
    request methods Hypertext Transfer Protocol (HTTP/1.1)
    单元测试
    access variables from the global scope 在全局范围内访问变量的2种方法
    summary
    安全跟效率之间的折中而已 记住一个大原则,安全和效率是对立的
    微信商城 Common Log Format Apache CustomLog
    僵尸进程 zombie
  • 原文地址:https://www.cnblogs.com/deeplearning1/p/11413206.html
Copyright © 2011-2022 走看看