标签: sampled-softmax

Keras 模型中的采样 Softmax

我考虑过的一些方法:

从模型类继承 tensorflow keras 中的采样 softmax

从层类继承 如何在 Keras 模型中使用 TensorFlow 的采样 softmax 损失函数?

在这两种方法中,模型方法更简洁,因为层方法有点笨拙——它将目标作为输入的一部分推入,然后再见多输出模型。

我想在对 Model 类进行子类化方面得到一些帮助 - 具体来说:1) 与第一种方法不同 - 我想在指定标准 keras 模型时采用任意数量的层。例如,

class LanguageModel(tf.keras.Model):
    def __init__(self, **kwargs)
Run Code Online (Sandbox Code Playgroud)

2)我希望在模型类中合并以下代码 - 但想让模型类认识到

def call(self, y_true, input):
        """ reshaping of y_true and input to make them fit each other """
        input = tf.reshape(input, (-1,self.hidden_size))
        y_true = tf.reshape(y_true, (-1,1))
      weights = tf.Variable(tf.float64))
      biases = tf.Variable(tf.float64)
      loss = tf.nn.sampled_softmax_loss(
      weights=weights,
      biases=biases,
      labels=labels,
      inputs=inputs,
      ...,
      partition_strategy="div")
      logits = tf.matmul(inputs, tf.transpose(weights))
      logits = tf.nn.bias_add(logits, …
Run Code Online (Sandbox Code Playgroud)

python keras tensorflow sampled-softmax

2
推荐指数
1
解决办法
1216
查看次数

标签 统计

keras ×1

python ×1

sampled-softmax ×1

tensorflow ×1