I am running a CVAE for text generation. I am using tensorflow > 2.0.
The problem is that for my loss I use the seq2seq.sequence_loss. I tried to update the tensorflow v1 to v2 since the code was released 6 years ago.
Here below a snippet of my code:
class CustomVariationalLayer(Layer):
def __init__(self, **kwargs):
self.is_placeholder = True
super(CustomVariationalLayer, self).__init__(**kwargs)
self.target_weights = tf.constant(np.ones((batch_size, max_len)), tf.float32)
def vae_loss(self, x, x_decoded_mean):
labels = tf.cast(x, tf.int32)
xent_loss = K.sum(tf.contrib.seq2seq.sequence_loss(x_decoded_mean, labels,
weights=self.target_weights,
average_across_timesteps=False,
average_across_batch=False), axis=-1)#,
#softmax_loss_function=softmax_loss_f), axis=-1)#,
kl_loss = - 0.5 * K.sum(1 + z_log_var - K.square(z_mean) - K.exp(z_log_var), axis=-1)
xent_loss = K.mean(xent_loss)
kl_loss = K.mean(kl_loss)
return K.mean(xent_loss + kl_weight * kl_loss)
And I have this error after running the script:
File “/dm4i/work/VAE-testbyme/Textvae_v2.py”, line 193, in call *
loss = self.vae_loss(x, x_decoded_mean)
File “/dm4i/work/VAE-testbyme/Textvae_v2.py”, line 179, in vae_loss *
xent_loss = K.sum(tf.contrib.seq2seq.sequence_loss(x_decoded_mean, labels,
AttributeError: module 'tensorflow' has no attribute 'contrib'
Any hints? or tips?
Thanks a lot