Beispiel #1
0
    def embed_inputs(self, inputs: tf.Tensor) -> tf.Tensor:
        embedded = tf.nn.embedding_lookup(self.embedding_matrix, inputs)

        if (self.embeddings_source is not None
                and self.embeddings_source.scale_embeddings_by_depth):

            # Pylint @property-related bug
            # pylint: disable=no-member
            embedding_size = self.embedding_matrix.shape.as_list()[-1]
            # pylint: enable=no-member

            embedded *= math.sqrt(embedding_size)

        length = tf.shape(inputs)[1]
        return embedded + position_signal(self.dimension, length)
Beispiel #2
0
    def embed_input_symbol(self, inputs: tf.Tensor) -> tf.Tensor:
        embedded = tf.nn.embedding_lookup(self.embedding_matrix, inputs)

        if (self.embeddings_source is not None
                and self.embeddings_source.scale_embeddings_by_depth):

            # Pylint @property-related bug
            # pylint: disable=no-member
            embedding_size = self.embedding_matrix.shape.as_list()[-1]
            # pylint: enable=no-member

            embedded *= math.sqrt(embedding_size)

        length = tf.shape(inputs)[1]
        return dropout(embedded + position_signal(self.dimension, length),
                       self.dropout_keep_prob,
                       self.train_mode)
Beispiel #3
0
 def embed_inputs(self, inputs: tf.Tensor) -> tf.Tensor:
     embedded = tf.nn.embedding_lookup(self.embedding_matrix, inputs)
     length = tf.shape(inputs)[1]
     return embedded + position_signal(self.dimension, length)