-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bayesian layers #240
Comments
@dustinvtran Please help me. I want to build a sequential model with LSTMCellReparameterization. |
There's a minimal code snippet in the paper. It should be plug-and-play with any LSTM example you currently have. |
Here's a runnable snippet using the reparameterized LSTM cell. As Dustin said, import tensorflow.compat.v2 as tf
import edward2 as ed
num_examples = 2
num_timesteps = 3
input_dim = 4
rnn_dim = 10
inputs = tf.random.normal([num_examples, num_timesteps, input_dim])
labels = tf.random.normal([num_examples])
cell = ed.layers.LSTMCellReparameterization(rnn_dim)
model = tf.keras.Sequential([
tf.keras.layers.RNN(cell),
tf.keras.layers.Dense(1)])
optimizer = tf.keras.optimizers.Adam(0.001)
for i in range(10):
with tf.GradientTape() as tape:
outputs = model(inputs)
nll = tf.reduce_mean((labels-outputs)**2)
kl = sum(model.losses)
loss = nll + kl
grads = tape.gradient(loss, model.variables)
grads_and_vars = zip(grads, model.variables)
optimizer.apply_gradients(grads_and_vars)
print(f"Loss at step {i}: {loss}")
|
@dusenberrymw Hi. Thanks a lot for your help. One another question, why the value of loss function is so high in this approach? |
@dusenberrymw Hi. I have some questions. What is the benefit of this LSTMCellReparameterization compared to ordinary lstm? Because I think the value of loss function is so high in this approach. And what is the difference between LSTMCellReparameterization and LSTMCellFlipout? |
@dusenberrymw Hi, could you please help me with my questions? I really need them for my master thesis and there isn't so much information about that questions anywhere else. Thanks a lot. |
@dustinvtran lstm_cell = ed.layers.LSTMCellReparameterization(self.lstm_hidden_dim, activation='tanh') {TypeError}Failed to convert object of type <class 'tuple'> to Tensor. Contents: (Dimension(3), 256). Consider casting elements to a supported type. The error comes from the input tensor lstm_in. I'm using TF1.14, is this causing trouble? |
@dustinvtran |
@dustinvtran
Hi, I have a question. Can I build bayesian layers with sequential models with lstm using edward2?
I mean building sequential model with LSTMCellReparameterization.
If yes please help me. I dont know how to build a sequential model with LSTMCellReparameterization layers.
The text was updated successfully, but these errors were encountered: