class_docstr: Bias module.
  
  Example Usage:
  
      >>> N, H, W, C = 1, 2, 3, 4
      >>> x = tf.random.normal([N, H, W, C])
  
      >>> scalar_bias = snt.Bias(bias_dims=[])
      >>> scalar_bias_output = scalar_bias(x)
      >>> assert scalar_bias.b.shape == []
  
  Create a bias over all non-minibatch dimensions:
  
      >>> all_bias = snt.Bias()
      >>> all_bias_output = all_bias(x)
      >>> assert all_bias.b.shape == [H, W, C]
  
  Create a bias over the last non-minibatch dimension:
  
      >>> last_bias = snt.Bias(bias_dims=[-1])
      >>> last_bias_output = last_bias(x)
      >>> assert last_bias.b.shape == [C]
  
  Create a bias over the first non-minibatch dimension:
  
      >>> first_bias = snt.Bias(bias_dims=[1])
      >>> first_bias_output = first_bias(x)
      >>> assert first_bias.b.shape == [H, 1, 1]
  
  Subtract and later add the same learned bias:
  
      >>> bias = snt.Bias()
      >>> h1 = bias(x, multiplier=-1)
      >>> h2 = bias(x)
      >>> h3 = bias(x, multiplier=-1)
      >>> reconstructed_x = bias(h3)
      >>> assert tf.reduce_all(tf.equal(x, reconstructed_x))
class_docstr_tok: ["Bias","module",".","Example","Usage",":",">",">",">","N",",","H",",","W",",","C","=","1",",","2",",","3",",","4",">",">",">","x","=","tf.random.normal","(","[","N",",","H",",","W",",","C","]",")",">",">",">","scalar_bias","=","snt.Bias","(","bias_dims=","[","]",")",">",">",">","scalar_bias_output","=","scalar_bias","(","x",")",">",">",">","assert","scalar_bias.b.shape","==","[","]","Create","a","bias","over","all","non-minibatch","dimensions",":",">",">",">","all_bias","=","snt.Bias","(",")",">",">",">","all_bias_output","=","all_bias","(","x",")",">",">",">","assert","all_bias.b.shape","==","[","H",",","W",",","C","]","Create","a","bias","over","the","last","non-minibatch","dimension",":",">",">",">","last_bias","=","snt.Bias","(","bias_dims=","[","-1","]",")",">",">",">","last_bias_output","=","last_bias","(","x",")",">",">",">","assert","last_bias.b.shape","==","[","C","]","Create","a","bias","over","the","first","non-minibatch","dimension",":",">",">",">","first_bias","=","snt.Bias","(","bias_dims=","[","1","]",")",">",">",">","first_bias_output","=","first_bias","(","x",")",">",">",">","assert","first_bias.b.shape","==","[","H",",","1",",","1","]","Subtract","and","later","add","the","same","learned","bias",":",">",">",">","bias","=","snt.Bias","(",")",">",">",">","h1","=","bias","(","x",",","multiplier=-1",")",">",">",">","h2","=","bias","(","x",")",">",">",">","h3","=","bias","(","x",",","multiplier=-1",")",">",">",">","reconstructed_x","=","bias","(","h3",")",">",">",">","assert","tf.reduce_all","(","tf.equal","(","x",",","reconstructed_x",")",")"]
code: def _initialize(self, inputs):
      utils.assert_minimum_rank(inputs, 2)
  
      input_shape = inputs.shape
      bias_shape = calculate_bias_shape(input_shape, self.bias_dims)
  
      input_size = input_shape[1:]
      if self.output_size is not None:
          if self.output_size != input_size:
              raise ValueError(
                  "Input shape must be {} not {}".format(
                      (-1,) + self.output_size, input_shape
                  )
              )
  
      self.input_size = input_size
      self.b = tf.Variable(
          self.b_init(bias_shape, inputs.dtype), name="b"
      )
  
file_path: sonnet/sonnet/src/bias.py
imports: from typing import Optional, Sequence
  from sonnet.src import base
  from sonnet.src import initializers
  from sonnet.src import once
  from sonnet.src import types
  from sonnet.src import utils
  import tensorflow
label_desc: Use image node_id 2 for calling the Bias obj's underlying member method code with example usage: obj._initialize(inputs) without return types