def __init__(self, vocab_size, emb_size, region_sizes=[3,4,5], \ region_merge_fn=tf.reduce_max, \ name="multi_region_embedding", \ initializer=None, \ **kwargs): BaseLayer.__init__(self, name, **kwargs) self._emb_size = emb_size self._region_sizes = region_sizes[:] self._region_sizes.sort() self._region_merge_fn = region_merge_fn region_num = len(region_sizes) self._K = [None] * region_num self._K[-1] = tf.get_variable(name + '_K_%d' % (region_num - 1), \ shape=[vocab_size, self._region_sizes[-1], emb_size], \ initializer=initializer) for i in range(region_num - 1): st = int(self._region_sizes[-1] / 2 - self._region_sizes[i] / 2) ed = st + self._region_sizes[i] self._K[i] = self._K[-1][:, st:ed, :] super(MultiRegionEmbedding, self).__init__(vocab_size, emb_size, name, initializer, **kwargs)
def __init__(self, vocab_size, emb_size, region_size=3, \ region_merge_fn=tf.reduce_max, \ name="win_pool_embedding", \ initializer=None, \ **kwargs): BaseLayer.__init__(self, name, **kwargs) self._region_size = region_size self._region_merge_fn = region_merge_fn super(WinPoolEmbedding, self).__init__(vocab_size, emb_size, name, initializer, **kwargs)
def __init__(self, vocab_size, emb_size, name="embedding", initializer=None, **kwargs): BaseLayer.__init__(self, name, **kwargs) self._emb_size = emb_size if not initializer: initializer = tf.contrib.layers.variance_scaling_initializer() self._W = self.get_variable(name + '_W', shape=[vocab_size, emb_size], initializer=initializer)
def __init__(self, vocab_size, emb_size, region_size=3, \ region_merge_fn=tf.reduce_max, \ name="scalar_region_embedding", \ initializer=None, \ **kwargs): BaseLayer.__init__(self, name, **kwargs) self._emb_size = emb_size self._region_size = region_size self._region_merge_fn = region_merge_fn if not initializer: initializer = tf.contrib.layers.variance_scaling_initializer() self._K = self.get_variable(name + '_K', shape=[vocab_size, region_size, 1], initializer=initializer) super(ScalarRegionEmbedding, self).__init__(vocab_size, emb_size, name, initializer, **kwargs)
def __init__(self, vocab_size, emb_size, name="character_embedding", initializer=None, **kwargs): """ Params: emb_size: embedding dim vocab_size: character vocab size hiddden_size: hidden_layer size """ BaseLayer.__init__(self, name, **kwargs) self._emb_size = emb_size self.hidden_size = kwargs[ "hidden_size"] if "hidden_size" in kwargs else 64 if not initializer: initializer = tf.contrib.layers.variance_scaling_initializer() self._W = self.get_variable(name + '_W', shape=[vocab_size, emb_size], initializer=initializer)
def __init__(self, region_size, name="RegionAlig", **args): BaseLayer.__init__(self, name, **args) self._region_size = region_size