class_docstr: A dense (a.k.a. fully-connected, affine) layer.
  
  Dense layers are the prototypical example of a trainable layer, i.e., a layer
  with trainable weights. Each node in a dense layer computes a weighted sum of
  all node values from the preceding layer and adds to that sum a node-specific
  bias term. The full layer computation is expressed compactly in linear
  algebra as an affine map `y = Wx + b`, where `W` is a matrix and `y`, `x`,
  and `b` are vectors. The layer is trained, or "learns", by updating the
  values in `W` and `b`.
  
  Less commonly, a dense layer can omit the bias term and be a pure linear map:
  `y = Wx`.
class_docstr_tok: ["A","dense","(","a.k.a",".","fully-connected",",","affine",")","layer",".","Dense","layers","are","the","prototypical","example","of","a","trainable","layer",",","i.e.",",","a","layer","with","trainable","weights",".","Each","node","in","a","dense","layer","computes","a","weighted","sum","of","all","node","values","from","the","preceding","layer","and","adds","to","that","sum","a","node-specific","bias","term",".","The","full","layer","computation","is","expressed","compactly","in","linear","algebra","as","an","affine","map","`","y","=","Wx","+","b","`",",","where","`","W","`","is","a","matrix","and","`","y","`",",","`","x","`",",","and","`","b","`","are","vectors",".","The","layer","is","trained",",","or","``","learns","''",",","by","updating","the","values","in","`","W","`","and","`","b","`",".","Less","commonly",",","a","dense","layer","can","omit","the","bias","term","and","be","a","pure","linear","map",":","`","y","=","Wx","`","."]
docstr: Returns a dense (fully connected) layer of width `n_units`.
  
  A dense layer maps collections of `R^m` vectors to `R^n`, where `n`
  (`= n_units`) is fixed at layer creation time, and `m` is set at layer
  initialization time.
  
  Args:
    n_units: Number of nodes in the layer, also known as the width of the
        layer.
    kernel_initializer: Function that creates a matrix of (random) initial
        connection weights `W` for the layer.
    bias_initializer: Function that creates a vector of (random) initial
        bias weights `b` for the layer.
    use_bias: If `True`, compute an affine map `y = Wx + b`; else compute
        a linear map `y = Wx`.
    use_bfloat16: If `True`, use bfloat16 weights instead of the default
      float32; this can save memory but may (rarely) lead to numerical issues.
docstr_tok: ["Returns","a","dense","(","fully","connected",")","layer","of","width","`","n_units","`",".","A","dense","layer","maps","collections","of","`","R^m","`","vectors","to","`","R^n","`",",","where","`","n","`","(","`","=","n_units","`",")","is","fixed","at","layer","creation","time",",","and","`","m","`","is","set","at","layer","initialization","time",".","Args",":","n_units",":","Number","of","nodes","in","the","layer",",","also","known","as","the","width","of","the","layer",".","kernel_initializer",":","Function","that","creates","a","matrix","of","(","random",")","initial","connection","weights","`","W","`","for","the","layer",".","bias_initializer",":","Function","that","creates","a","vector","of","(","random",")","initial","bias","weights","`","b","`","for","the","layer",".","use_bias",":","If","`","True","`",",","compute","an","affine","map","`","y","=","Wx","+","b","`",";","else","compute","a","linear","map","`","y","=","Wx","`",".","use_bfloat16",":","If","`","True","`",",","use","bfloat16","weights","instead","of","the","default","float32",";","this","can","save","memory","but","may","(","rarely",")","lead","to","numerical","issues","."]
code: def __init__(
      self,
      n_units,
      kernel_initializer=init.GlorotUniformInitializer(),
      bias_initializer=init.RandomNormalInitializer(1e-6),
      use_bias=True,
      use_bfloat16=False,
  ):
      """Returns a dense (fully connected) layer of width `n_units`.
  
      A dense layer maps collections of `R^m` vectors to `R^n`, where `n`
      (`= n_units`) is fixed at layer creation time, and `m` is set at layer
      initialization time.
  
      Args:
        n_units: Number of nodes in the layer, also known as the width of the
            layer.
        kernel_initializer: Function that creates a matrix of (random) initial
            connection weights `W` for the layer.
        bias_initializer: Function that creates a vector of (random) initial
            bias weights `b` for the layer.
        use_bias: If `True`, compute an affine map `y = Wx + b`; else compute
            a linear map `y = Wx`.
        use_bfloat16: If `True`, use bfloat16 weights instead of the default
          float32; this can save memory but may (rarely) lead to numerical issues.
      """
      super().__init__(name=f"Dense_{n_units}")
      self._n_units = n_units
      self._kernel_initializer = kernel_initializer
      self._bias_initializer = bias_initializer
      self._use_bias = use_bias
      self._use_bfloat16 = use_bfloat16
  
imports: from absl import logging
  import numpy
  import tensorflow
  from trax import fastmath
  from trax.fastmath import numpy
  from trax.layers import base
  from trax.layers import initializers
  from trax.layers.assert_shape import assert_shape
  from trax.layers.base import Fn
label_desc: Use image node_id 1 to create a new Dense object from inherited base classes: base with example: obj = Dense(n_units, kernel_initializer, bias_initializer, use_bias, use_bfloat16)