Tensorflow 中 RNN softmax輸出層採樣 tf.multinomial(logits, num_samples)

Tensorflow 中,想要使用sequence to sequence 模型,在RNN的輸出端採樣(sampling),可以在softmax層之後,做簡單的log p 再用tf.multinomial()來實現:

tf.multinomial(logits, num_samples, seed=None, name=None)
例如:


# samples has shape [1, 5], where each value is either 0 or 1 with equal
# probability.
samples = tf.multinomial(tf.log([[10., 10.]]), 5)

Args:

  • logits: 2-D Tensor with shape [batch_size, num_classes]. Each slice [i, :] represents the unnormalized log probabilities for all classes.
  • num_samples: 0-D. Number of independent samples to draw for each row slice.
  • seed: A Python integer. Used to create a random seed for the distribution. See tf.set_random_seed for behavior.
  • name: Optional name for the operation.

Returns:

The drawn samples of shape [batch_size, num_samples].

Defined in tensorflow/python/ops/random_ops.py.


發佈了41 篇原創文章 · 獲贊 192 · 訪問量 73萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章