Use `tf.matmul(..., transpose_b=True)` for reverse_project.
@@ -19,12 +19,8 @@ import tensorflow as tf
class TransposableEmbedding(tf.keras.layers.Embedding):
"""A Keras Embedding layer implements a transposed projection for output."""
- def build(self, input_shape):
- super().build(input_shape)
- self.transposed_embeddings = tf.keras.backend.transpose(self.embeddings)
-
def reverse_project(self, inputs):
- return tf.matmul(inputs, self.transposed_embeddings)
+ return tf.matmul(inputs, self.embeddings, transpose_b=True)
def create_recurrent_model(vocab_size=10000,
