class_docstr: Haiku module representing the VQ-VAE layer.
  
  Implements a slightly modified version of the algorithm presented in
  "Neural Discrete Representation Learning" by van den Oord et al.
  https://arxiv.org/abs/1711.00937
  
  The difference between :class:`VectorQuantizerEMA` and
  :class:`VectorQuantizer` is that this module uses
  :class:`~haiku.ExponentialMovingAverage`\ s to update the embedding vectors
  instead of an auxiliary loss. This has the advantage that the embedding
  updates are independent of the choice of optimizer (SGD, RMSProp, Adam, K-Fac,
  ...) used for the encoder, decoder and other parts of the architecture. For
  most experiments the EMA version trains faster than the non-EMA version.
  
  Input any tensor to be quantized. Last dimension will be used as space in
  which to quantize. All other dimensions will be flattened and will be seen
  as different examples to quantize.
  
  The output tensor will have the same shape as the input.
  
  For example a tensor with shape ``[16, 32, 32, 64]`` will be reshaped into
  ``[16384, 64]`` and all ``16384`` vectors (each of 64 dimensions)  will be
  quantized independently.
  
  Attributes:
    embedding_dim: integer representing the dimensionality of the tensors in
      the quantized space. Inputs to the modules must be in this format as well.
    num_embeddings: integer, the number of vectors in the quantized space.
    commitment_cost: scalar which controls the weighting of the loss terms
      (see equation 4 in the paper).
    decay: float, decay for the moving averages.
    epsilon: small float constant to avoid numerical instability.
class_docstr_tok: ["Haiku","module","representing","the","VQ-VAE","layer",".","Implements","a","slightly","modified","version","of","the","algorithm","presented","in","''","Neural","Discrete","Representation","Learning","''","by","van","den","Oord","et","al",".","https",":","\/\/arxiv.org\/abs\/1711.00937","The","difference","between",":","class",":","`","VectorQuantizerEMA","`","and",":","class",":","`","VectorQuantizer","`","is","that","this","module","uses",":","class",":","`","~haiku.ExponentialMovingAverage","`","\\","s","to","update","the","embedding","vectors","instead","of","an","auxiliary","loss",".","This","has","the","advantage","that","the","embedding","updates","are","independent","of","the","choice","of","optimizer","(","SGD",",","RMSProp",",","Adam",",","K-Fac",",","...",")","used","for","the","encoder",",","decoder","and","other","parts","of","the","architecture",".","For","most","experiments","the","EMA","version","trains","faster","than","the","non-EMA","version",".","Input","any","tensor","to","be","quantized",".","Last","dimension","will","be","used","as","space","in","which","to","quantize",".","All","other","dimensions","will","be","flattened","and","will","be","seen","as","different","examples","to","quantize",".","The","output","tensor","will","have","the","same","shape","as","the","input",".","For","example","a","tensor","with","shape","``","[","16",",","32",",","32",",","64","]","``","will","be","reshaped","into","``","[","16384",",","64","]","``","and","all","``","16384","``","vectors","(","each","of","64","dimensions",")","will","be","quantized","independently",".","Attributes",":","embedding_dim",":","integer","representing","the","dimensionality","of","the","tensors","in","the","quantized","space",".","Inputs","to","the","modules","must","be","in","this","format","as","well",".","num_embeddings",":","integer",",","the","number","of","vectors","in","the","quantized","space",".","commitment_cost",":","scalar","which","controls","the","weighting","of","the","loss","terms","(","see","equation","4","in","the","paper",")",".","decay",":","float",",","decay","for","the","moving","averages",".","epsilon",":","small","float","constant","to","avoid","numerical","instability","."]
docstr: Initializes a VQ-VAE EMA module.
  
  Args:
    embedding_dim: integer representing the dimensionality of the tensors in
      the quantized space. Inputs to the modules must be in this format as
      well.
    num_embeddings: integer, the number of vectors in the quantized space.
    commitment_cost: scalar which controls the weighting of the loss terms
      (see equation 4 in the paper - this variable is Beta).
    decay: float between 0 and 1, controls the speed of the Exponential Moving
      Averages.
    epsilon: small constant to aid numerical stability, default ``1e-5``.
    dtype: dtype for the embeddings variable, defaults to ``float32``.
    cross_replica_axis: If not ``None``, it should be a string representing
      the axis name over which this module is being run within a
      :func:`jax.pmap`. Supplying this argument means that cluster statistics
      and the perplexity are calculated across all replicas on that axis.
    name: name of the module.
docstr_tok: ["Initializes","a","VQ-VAE","EMA","module",".","Args",":","embedding_dim",":","integer","representing","the","dimensionality","of","the","tensors","in","the","quantized","space",".","Inputs","to","the","modules","must","be","in","this","format","as","well",".","num_embeddings",":","integer",",","the","number","of","vectors","in","the","quantized","space",".","commitment_cost",":","scalar","which","controls","the","weighting","of","the","loss","terms","(","see","equation","4","in","the","paper","-","this","variable","is","Beta",")",".","decay",":","float","between","0","and","1",",","controls","the","speed","of","the","Exponential","Moving","Averages",".","epsilon",":","small","constant","to","aid","numerical","stability",",","default","``","1e-5","``",".","dtype",":","dtype","for","the","embeddings","variable",",","defaults","to","``","float32","``",".","cross_replica_axis",":","If","not","``","None","``",",","it","should","be","a","string","representing","the","axis","name","over","which","this","module","is","being","run","within","a",":","func",":","`","jax.pmap","`",".","Supplying","this","argument","means","that","cluster","statistics","and","the","perplexity","are","calculated","across","all","replicas","on","that","axis",".","name",":","name","of","the","module","."]
code: def __init__(
      self,
      embedding_dim,
      num_embeddings,
      commitment_cost,
      decay,
      epsilon: float = 1e-5,
      dtype: Any = jnp.float32,
      cross_replica_axis: Optional[str] = None,
      name: Optional[str] = None,
  ):
      """Initializes a VQ-VAE EMA module.
  
      Args:
        embedding_dim: integer representing the dimensionality of the tensors in
          the quantized space. Inputs to the modules must be in this format as
          well.
        num_embeddings: integer, the number of vectors in the quantized space.
        commitment_cost: scalar which controls the weighting of the loss terms
          (see equation 4 in the paper - this variable is Beta).
        decay: float between 0 and 1, controls the speed of the Exponential Moving
          Averages.
        epsilon: small constant to aid numerical stability, default ``1e-5``.
        dtype: dtype for the embeddings variable, defaults to ``float32``.
        cross_replica_axis: If not ``None``, it should be a string representing
          the axis name over which this module is being run within a
          :func:`jax.pmap`. Supplying this argument means that cluster statistics
          and the perplexity are calculated across all replicas on that axis.
        name: name of the module.
      """
      super().__init__(name=name)
      if not 0 <= decay <= 1:
          raise ValueError("decay must be in range [0, 1]")
  
      self.embedding_dim = embedding_dim
      self.num_embeddings = num_embeddings
      self.decay = decay
      self.commitment_cost = commitment_cost
      self.epsilon = epsilon
      self.cross_replica_axis = cross_replica_axis
  
      self._embedding_shape = [embedding_dim, num_embeddings]
      self._dtype = dtype
  
      self._ema_cluster_size = hk.ExponentialMovingAverage(
          decay=self.decay, name="ema_cluster_size"
      )
      self._ema_dw = hk.ExponentialMovingAverage(
          decay=self.decay, name="ema_dw"
      )
  
imports: from typing import Any, Optional
  from haiku._src import base
  from haiku._src import initializers
  from haiku._src import module
  from haiku._src import moving_averages
  import jax
  import jax.numpy
label_desc: Use image node_id 1 to create a new VectorQuantizerEMA object from inherited base classes: hk with example: obj = VectorQuantizerEMA(embedding_dim, num_embeddings, commitment_cost, decay, epsilon, dtype, cross_replica_axis, name)