Pure keras examples


Thanks for the great package, edward.

Could you please provide examples in which you utilize full Keras backend and numpy arrays instead of tensorflow background and tensors?

Moreover, could you please utilize more core layers, such as conv2, dropout, batchnormalization, …, from Keras in theses examples?


Not sure what you mean by “full Keras backend”. Keras is a neural network library on top of TensorFlow. The primary features it adds relevant to Edward are functions to compose neural net layers. You can use NumPy arrays for most heavy lifting in Edward (we do so in many examples). However, if you’d like to build nodes in your computational graph that are not fed until runtime, you need to use TensorFlow placeholders as there is no “Keras equivalent”.

For example, you can extend the vae.py example with dropout/BN layers. if you want to distinguish test time, you need to feed K.learning_phase() when making predictions. See, e.g., https://blog.keras.io/keras-as-a-simplified-interface-to-tensorflow-tutorial.html.

Hope that helps.


Thanks for the reply.

As you know, keras has its own backend containing placeholder, variable, etc…

I meant that whether we can, for example, replace tf.placeholder with keras.backend.placeholder.
In general, can we utilize keras backend and its methods instead of tf methods?

I tried this example by fully keras methods and functions.

However, I have no idea when I should set learning phase in keras when using it in edward.


Oh, that backend. I guess you can. It just wraps TensorFlow ops so it should work fine.

Just as with standard TensorFlow placeholders, you need to feed the learning phase during training time (calls to inference.update()) and prediction time.


Thank Dustin,
Of course, it’s not just simple wrapper; it has own methods to construct random variables, zero and ones vectors, etc. Everything works well though by using keras backend.

You mean inference.update() has argument to set learning phase?
I would be thankful if you could add or mention an example in the repo describing how to set it. It’s very urgent and crucial for my research.


Could you please explain in more details with some real example where you use Dropout and batchnormalization layer in keras.

Indeed, I am not still understand how to use these layers into Edward model.

Thanks in advance.


I was wondering if you had figured out how to do this using Keras?



I have already do this. but seems as if Edward is not good approach at all in very high dimensional problem. It’s not difficult at all…