learner
learner

Reputation: 3472

Can the bias of a dense layer be set to zero in Tensorflow?

I'm trying to implement a neural network in which I need the kernel multiplication with the input only. The dense layer in Tensorflow also adds bias which I am trying to set to zero. From the documentation the only variable that is available to play with is bias_regularizer. So I tried doing the following:

def make_zero(_):
    return np.zeros(21,)

out1 = tf.layers.dense(inputs=codeword, units=21, activation=None, bias_regularizer=make_zero)

But I still see the bias values are not zero. Is there any other method to achieve this?

Upvotes: 5

Views: 4682

Answers (1)

javidcf
javidcf

Reputation: 59731

See the documentation of tf.layers.dense, you can use the option use_bias=False to remove the bias altogether:

out1 = tf.layers.dense(inputs=codeword, units=21, activation=None, use_bias=False)

Upvotes: 8

Related Questions