| 85 | class Dense(Layer): |
| 86 | """Dense layer.""" |
| 87 | def __init__(self, input_dim, output_dim, placeholders, dropout=0., sparse_inputs=False, |
| 88 | act=tf.nn.relu, bias=False, featureless=False, **kwargs): |
| 89 | super(Dense, self).__init__(**kwargs) |
| 90 | |
| 91 | if dropout: |
| 92 | self.dropout = placeholders['dropout'] |
| 93 | else: |
| 94 | self.dropout = 0. |
| 95 | |
| 96 | self.act = act |
| 97 | self.sparse_inputs = sparse_inputs |
| 98 | self.featureless = featureless |
| 99 | self.bias = bias |
| 100 | |
| 101 | # helper variable for sparse dropout |
| 102 | self.num_features_nonzero = placeholders['num_features_nonzero'] |
| 103 | |
| 104 | with tf.variable_scope(self.name + '_vars'): |
| 105 | self.vars['weights'] = glorot([input_dim, output_dim], |
| 106 | name='weights') |
| 107 | if self.bias: |
| 108 | self.vars['bias'] = zeros([output_dim], name='bias') |
| 109 | |
| 110 | if self.logging: |
| 111 | self._log_vars() |
| 112 | |
| 113 | def _call(self, inputs): |
| 114 | x = inputs |