NaNs in Tensor for model, decreasing learning rate doesn't help


#1

Wondering if I could get some feedback about the model below:

N, P = x_train.shape
G = tf.placeholder(tf.float32, [N, P])
weights = Normal(loc=tf.zeros(P), scale=tf.ones(P))
G_mask = Bernoulli(logits=tf.zeros(P))
eps_nm = Normal(loc=tf.zeros([N]), scale=tf.ones([N]))

def hadamard_product(X, b):
    """ X and b are expected to be
    tensorflow objects, X has shape (N, P) and
    b has shape (P,), b is transformed to have
    shape (N, P), then an element wise product
    is computed X * b_transformed, which has
    shape (N, P)
    """
    N, P = list(map(int, X.shape))
    bmat = tf.reshape(tf.tile(b, [N]), [N, P])
    return tf.multiply(X, tf.to_float(bmat))

x_nm = Normal(
    loc=ed.dot(hadamard_product(G, G_mask), weights) + eps_nm,
    scale=tf.nn.softplus(tf.ones([N]))
)

qe = Normal(loc=tf.get_variable("qe/loc", [N]), scale=tf.get_variable("qe/scale", [N]))
qw = Normal(loc=tf.get_variable("qw/loc", [P]), scale=tf.get_variable("qw/scale", [P]))
qgm = Bernoulli(logits=tf.get_variable("qgm/logits", [P]))
inference = ed.KLqp({weights:qw, G_mask:qgm, eps_nm:qe}, data={G:x_train, x_nm:y_train})
inference.run()

I’ve seen this issue come before, and the answer is to decrease the learning rate in the optimizer used which I’ve tried but the same error comes up:

InvalidArgumentError:  : Tensor had NaN values
	 [[Node: inference/sample/VerifyFinite_1/CheckNumerics = CheckNumerics[T=DT_FLOAT, _class=["loc:@Normal/sample/Reshape"], message="", _device="/job:localhost/replica:0/task:0/device:CPU:0"](inference/sample/Normal_4/sample/Reshape)]]

any suggestions?