【问题标题】:Tensorflow Translation Tutorial fix for 0.12.10.12.1 的 TensorFlow 翻译教程修复
【发布时间】:2017-05-31 19:10:36
【问题描述】:

我正在尝试从 github 上的当前 master 分支安装 tensorflow 0.12.1 来运行翻译教程 (https://github.com/tensorflow/models/tree/master/tutorials/rnn/translate)。

我在此处 (https://github.com/tensorflow/models/issues/853) 对 Kangmo 建议的 seq2seq_model.py 进行了更改,但出现了不同的错误。

Creating 3 layers of 1024 units.

Traceback (most recent call last):
  File "translate.py", line 317, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 44, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "translate.py", line 314, in main
    train()
  File "translate.py", line 173, in train
    model = create_model(sess, False)
  File "translate.py", line 131, in create_model
    dtype=dtype)
  File "/home/TFRun/seq2seq_model.py", line 171, in __init__
    softmax_loss_function=softmax_loss_function)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1195, in model_with_buckets
    softmax_loss_function=softmax_loss_function))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1110, in sequence_loss
    softmax_loss_function=softmax_loss_function))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1067, in sequence_loss_by_example
    crossent = softmax_loss_function(target, logit)
  File "/home/TFRun/seq2seq_model.py", line 111, in sampled_loss
    num_samples, self.target_vocab_size),
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_impl.py", line 1191, in sampled_softmax_loss
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_impl.py", line 974, in _compute_sampled_logits
    array_ops.reshape(true_w, new_true_w_shape))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/math_ops.py", line 357, in multiply
    return gen_math_ops._mul(x, y, name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_math_ops.py", line 1625, in _mul
    result = _op_def_lib.apply_op("Mul", x=x, y=y, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 522, in apply_op
    inferred_from[input_arg.type_attr]))
TypeError: Input 'y' of 'Mul' Op has type float32 that does not match type int32 of argument 'x'.

有人知道解决这个错误的方法吗?

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    您需要将 x 张量转换为 float32,因此请在 seq2seq_model.py 中使用以下代码:

    def sampled_loss(inputs,labels):
                inputs= tf.cast(inputs, tf.float32)
                labels = tf.reshape(labels, [-1, 1])
                return tf.cast(tf.nn.sampled_softmax_loss(w_t, b,  labels, inputs,num_samples,
                        self.target_vocab_size),tf.float32)
    

    你还需要替​​换这一行

    crossent = softmax_loss_function(target, logit)
    

    crossent = softmax_loss_function(logit, target)
    

    在你的 seq2seq.py 中

    【讨论】:

      猜你喜欢
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-24
      • 1970-01-01
      • 2010-09-20
      • 1970-01-01
      • 2016-03-23
      相关资源
      最近更新 更多