Search code examples
tensorflowdeep-learningbias-neuron

Are the bias terms added by default on each layer in tensorflow models?


Are the bias terms added by default when creating the tensorflow neural network models?

To rephrase, if x is the input to a particular layer, y is the ouput, W is the weight matrix and b is the bias , then the output of the layer is given by,

  y = W^t x + b 

So is the bias added by default when we create the model ?


Solution

  • If you are creating your own model from scratch, you have to create your own trainable variables for the weights and biases explicitly. Tensorflow does not create them by default.

    x = tf.placeholder(tf.float32, shape=(None, n))
    
    W = tf.Variable(tf.random_normal([n,m], stddev=0.01))
    b = tf.Variable(tf.zeros([m]))
    
    y = tf.matmul(x,W) + b