def _build(self, X):
"""Build the graph of this layer."""
n_samples, input_dim = self._get_X_dims(X)
Wdim = (self.n_categories, self.output_dim)
n_batch = tf.shape(X)[1]
W = tf.Variable(tf.random_normal(shape=Wdim, seed=next(seedgen)),
name="W_map")
# Index into the relevant weights rather than using sparse matmul
features = tf.gather(W, X, axis=0)
f_dims = int(np.prod(features.shape[2:])) # need this for placeholders
Net = tf.reshape(features, [n_samples, n_batch, f_dims])
# Regularizers
penalty = self.l2 * tf.nn.l2_loss(W) + self.l1 * _l1_loss(W)
return Net, penalty
#
# Private module stuff
#
评论列表
文章目录