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",")",")"]
docstr: Constructs a `Bias` module that supports broadcasting.
  
  Args:
    output_size: Output size (output shape without batch dimension). If
      `output_size` is left as `None`, the size will be directly inferred by
      the input.
    bias_dims: Sequence of which dimensions to retain from the input shape
      when constructing the bias. The remaining dimensions will be broadcast
      over (given size of 1), and leading dimensions will be removed
      completely. See class doc for examples.
    b_init: Optional initializer for the bias. Default to zeros.
    name: Name of the module.
docstr_tok: ["Constructs","a","`","Bias","`","module","that","supports","broadcasting",".","Args",":","output_size",":","Output","size","(","output","shape","without","batch","dimension",")",".","If","`","output_size","`","is","left","as","`","None","`",",","the","size","will","be","directly","inferred","by","the","input",".","bias_dims",":","Sequence","of","which","dimensions","to","retain","from","the","input","shape","when","constructing","the","bias",".","The","remaining","dimensions","will","be","broadcast","over","(","given","size","of","1",")",",","and","leading","dimensions","will","be","removed","completely",".","See","class","doc","for","examples",".","b_init",":","Optional","initializer","for","the","bias",".","Default","to","zeros",".","name",":","Name","of","the","module","."]
code: def __init__(
      self,
      output_size: Optional[int] = None,
      bias_dims: Optional[Sequence[int]] = None,
      b_init: Optional[initializers.Initializer] = None,
      name: Optional[str] = None,
  ):
      """Constructs a `Bias` module that supports broadcasting.
  
      Args:
        output_size: Output size (output shape without batch dimension). If
          `output_size` is left as `None`, the size will be directly inferred by
          the input.
        bias_dims: Sequence of which dimensions to retain from the input shape
          when constructing the bias. The remaining dimensions will be broadcast
          over (given size of 1), and leading dimensions will be removed
          completely. See class doc for examples.
        b_init: Optional initializer for the bias. Default to zeros.
        name: Name of the module.
      """
      super().__init__(name=name)
      self.output_size = output_size
      self.bias_dims = bias_dims
      self.b_init = initializers.Zeros() if b_init is None else b_init
  
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 1 to create a new Bias object from inherited base classes: base with example: obj = Bias(output_size, bias_dims, b_init, name)