【问题标题】:Sparse Sampled Softmax Tensorflow稀疏采样 Softmax 张量流
【发布时间】:2018-03-20 07:33:58
【问题描述】:

您将如何转换 tf.nn.sparse_softmax_cross_entropy_with_logits 以使用 采样的 softmax 而不是常规的 softmax?

我有一个序列到序列模型,目标词汇量很大(500K 词),它会触发 OOM 错误。

softmax 函数的输入如下:[batch, max_time_steps, 512]

【问题讨论】:

    标签: machine-learning tensorflow


    【解决方案1】:

    我遇到了同样的问题,使用以下方法解决了:

            labels = tf.reshape(labels, [-1, 1])
            loss = tf.nn.sampled_softmax_loss(
                weights=self.W_softmax,
                biases=self.b_softmax,
                labels=labels,
                inputs=logits,
                num_sampled=20,
                num_true=1,
                num_classes=20000,
                partition_strategy="div")
    

    对我来说,关键是将num_sampled=20 设置得相当低,512 太大了,无法容纳我的 GPU 内存 (8GB)。

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 2012-01-03
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 2018-10-27
      • 2020-08-05
      相关资源
      最近更新 更多