This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import matplotlib.pyplot as plt | |
from IPython import display | |
""" | |
IPython Display rc0 | |
Try: | |
dsp = IDisplay() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sample_gumbel(shape, eps=1e-20): | |
"""Sample from Gumbel(0, 1)""" | |
U = tf.random_uniform(shape,minval=0,maxval=1) | |
return -tf.log(-tf.log(U + eps) + eps) | |
def gumbel_softmax_sample(logits, temperature): | |
""" Draw a sample from the Gumbel-Softmax distribution""" | |
y = logits + sample_gumbel(tf.shape(logits)) | |
return tf.nn.softmax( y / temperature) |