def __init__(self, hparams):
    super(WidgetCaptionModel, self).__init__()
    self._hparams = hparams
    with tf.name_scope('captioning'):
        self._word_embedding_layer = EmbeddingLayer(name='word', hidden_dim=self._hparams['hidden_size'], embedding_file=self._hparams['embedding_file'], vocab_size=self._hparams['vocab_size'], embedding_dim=self._hparams['hidden_size'], trainable=self._hparams['glove_trainable'])
        self._position_embedding_layer = layers.RelativePositionEmbedding(hidden_size=self._hparams['hidden_size'])
        self._encoder = EncoderLayer(self._hparams, self._word_embedding_layer)
        self._decoder = DecoderLayer(self._hparams, self._word_embedding_layer, self._position_embedding_layer)
        self._word_layer = tf.keras.layers.Dense(units=self._hparams['vocab_size'])
    self.model_metrics = {'loss': tf.keras.metrics.Mean(name='loss'), 'global_norm': tf.keras.metrics.Mean(name='global_norm')}
    self.caption_metrics = {}
    for score_name in self._SCORE_NAMES:
        scoped_name = 'COCO/{}'.format(score_name)
        self.caption_metrics[scoped_name] = tf.keras.metrics.Mean(name=scoped_name)
    self._word_vocab = []
    with tf.io.gfile.GFile(self._hparams['word_vocab_path']) as f:
        for (index, line) in enumerate(f):
            if (index >= self._hparams['vocab_size']):
                break
            self._word_vocab.append(line.strip())
def __init__(self, hparams):
    super(WidgetCaptionModel, self).__init__()
    self._hparams = hparams
    with tf.name_scope('captioning'):
        self._word_embedding_layer = EmbeddingLayer(name='word', hidden_dim=self._hparams['hidden_size'], embedding_file=self._hparams['embedding_file'], vocab_size=self._hparams['vocab_size'], embedding_dim=self._hparams['hidden_size'], trainable=self._hparams['glove_trainable'])
        self._position_embedding_layer = layers.RelativePositionEmbedding(hidden_size=self._hparams['hidden_size'])
        self._encoder = EncoderLayer(self._hparams, self._word_embedding_layer)
        self._decoder = DecoderLayer(self._hparams, self._word_embedding_layer, self._position_embedding_layer)
        self._word_layer = tf.keras.layers.Dense(units=self._hparams['vocab_size'])
    self.model_metrics = {'loss': tf.keras.metrics.Mean(name='loss'), 'global_norm': tf.keras.metrics.Mean(name='global_norm')}
    self.caption_metrics = {}
    for score_name in self._SCORE_NAMES:
        scoped_name = 'COCO/{}'.format(score_name)
        self.caption_metrics[scoped_name] = tf.keras.metrics.Mean(name=scoped_name)
    self._word_vocab = []
    with tf.io.gfile.GFile(self._hparams['word_vocab_path']) as f:
        for (index, line) in enumerate(f):
            if (index >= self._hparams['vocab_size']):
                break
            self._word_vocab.append(line.strip())