Closed sergeyf closed 7 years ago
For posterity, this is how you implement circular correlation with TensorFlow. For circular convolution, just leave out the tf.conj
. I have no idea if this will work with Theano.
def holographic_merge(inputs):
a, b = inputs
a_fft = tf.batch_fft(tf.complex(a, 0.0))
b_fft = tf.batch_fft(tf.complex(b, 0.0))
ifft = tf.batch_ifft(tf.conj(a_fft) * b_fft)
return tf.cast(tf.real(ifft), 'float32')
How do you compute the gradients for a,b ? I implement it with Theano.andbox.fourier.fft, ifft, but gradient for fft, ifft is not implemented yet, I guess (aborts with an error: Elemwise{real,no_inplace}.grad illegally returned an integer-valued variable. (Input index 0, dtype complex128))
Thanks!
On Nov 28, 2017 6:28 AM, "Hui Li" notifications@github.com wrote:
@sergeyf https://github.com/sergeyf Implementation for tensorflow can be found in OpenKE https://github.com/thunlp/OpenKE/blob/9a2cc3f838e1bddb2fe8f65b9747d3aba36a72c1/models/HolE.py
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fchollet/keras/issues/2518#issuecomment-347494786, or mute the thread https://github.com/notifications/unsubscribe-auth/ABya7C0j5KRXwk-WIsHPNlGpq8XByuj4ks5s6-5UgaJpZM4IQES6 .
@waongyi Were you able to implement it in Theano?
This is a repost from Keras-users.
Hello,
I'd like to implement Holographic Embeddings of Knowledge Graphs in Keras, but I'm stumped as to how to go about it.
The key math is in Eq. 8: the k-th entry of the circular correlation is an inner-product between
a
andb
circularly shifted forward byk
indices.I was thinking that the most direct way to do this would be to add a new merge mode, nothing in the backend documentation jumped out at me as being relevant to getting this done.
The only relevant function I found that should help is theano.tensor.roll
Any ideas of how to implement this in an efficient, elegant way with the tools available in the Keras backend? Hopefully something that would also work with TensorFlow so I could submit a pull request.
Thanks.