【问题标题】:How to decode the output of seq2seq?如何解码 seq2seq 的输出?
【发布时间】:2017-08-03 02:57:40
【问题描述】:

Tensorflow translate.py 示例的代码here 让我很困惑。复制的代码是:

  # This is a greedy decoder - outputs are just argmaxes of output_logits.
  outputs = [int(np.argmax(logit, axis=1)) for logit in output_logits]

为什么argmax 有效?

output_logits 的形状是[bucket_length,batch_size,embedding_size]

【问题讨论】:

    标签: tensorflow neural-network nlp deep-learning machine-translation


    【解决方案1】:

    对于每个 logit(或:每个单词的激活),它们采用激活在所有内容中具有最高值的索引。

    对于 argmax:查看此页面上的 numpy 示例:https://docs.scipy.org/doc/numpy/reference/generated/numpy.argmax.html

    a = array([[0, 1, 2],
           [3, 4, 5]])
    >>> np.argmax(a)
    5
    >>> np.argmax(a, axis=0)
    array([1, 1, 1])
    >>> np.argmax(a, axis=1)
    array([2, 2])
    

    所以输出的作用是:

    • 对于每个单词(bucket_length的长度)
      • 获得 embedding_size 的最大激活值

    您应该查看生成的输出数组的形状。您会看到,因为 batch_size 为 1,所以一切正常!

    如果这对你有帮助,请告诉我!

    【讨论】:

    • 谢谢。但我的问题主要是关于为什么 argmax 会导致翻译后的单词 id。
    • numpy 示例有帮助吗?
    • 谢谢。我知道 argmax 是什么意思。
    • 这是否回答了您的问题?或者您不清楚如何获得 output_logits?
    • 没有。该模型要翻译。所以我的问题是如何将 output_logits 转换为词汇表中的单词 id。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 2022-07-05
    相关资源
    最近更新 更多