def build(self, input_shape):
    if self._embedding_file:
        logging.info('Load embedding file for %s of vocab size %s: %s', self._name, self._vocab_size, self._embedding_file)
        (_, embedding_weights, depth) = load_embed(file_name=self._embedding_file, vocab_size=self._vocab_size)
        self._embedding_dim = depth
        initializer = tf.constant_initializer(embedding_weights[:self._vocab_size, :])
    else:
        logging.info('Create random embedding matrix for %s of size %s', self._name, self._vocab_size)
        initializer = tf.keras.initializers.RandomNormal(mean=0.0, stddev=0.1, seed=None)
    self.embeddings = self.add_weight(name='{}_weights'.format(self._name), shape=(self._vocab_size, self._embedding_dim), initializer=initializer, trainable=self._trainable, dtype='float32')
    if self._hidden_dim:
        self._project_layer = tf.keras.layers.Dense(self._hidden_dim)
def build(self, input_shape):
    if self._embedding_file:
        logging.info('Load embedding file for %s of vocab size %s: %s', self._name, self._vocab_size, self._embedding_file)
        (_, embedding_weights, depth) = load_embed(file_name=self._embedding_file, vocab_size=self._vocab_size)
        self._embedding_dim = depth
        initializer = tf.constant_initializer(embedding_weights[:self._vocab_size, :])
    else:
        logging.info('Create random embedding matrix for %s of size %s', self._name, self._vocab_size)
        initializer = tf.keras.initializers.RandomNormal(mean=0.0, stddev=0.1, seed=None)
    self.embeddings = self.add_weight(name='{}_weights'.format(self._name), shape=(self._vocab_size, self._embedding_dim), initializer=initializer, trainable=self._trainable, dtype='float32')
    if self._hidden_dim:
        self._project_layer = tf.keras.layers.Dense(self._hidden_dim)