gpt4 book ai didi

machine-learning - 稀疏采样 Softmax Tensorflow

转载 作者:行者123 更新时间:2023-11-30 08:49:06 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

        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)。

关于machine-learning - 稀疏采样 Softmax Tensorflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46640555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com