class_docstr: Haiku module representing the VQ-VAE layer.
  
  Implements the algorithm presented in
  "Neural Discrete Representation Learning" by van den Oord et al.
  https://arxiv.org/abs/1711.00937
  
  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 - this variable is Beta).
class_docstr_tok: ["Haiku","module","representing","the","VQ-VAE","layer",".","Implements","the","algorithm","presented","in","''","Neural","Discrete","Representation","Learning","''","by","van","den","Oord","et","al",".","https",":","\/\/arxiv.org\/abs\/1711.00937","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","-","this","variable","is","Beta",")","."]
docstr: Initializes a VQ-VAE module.
  
  Args:
    embedding_dim: dimensionality of the tensors in the quantized space.
      Inputs to the modules must be in this format as well.
    num_embeddings: 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).
    dtype: dtype for the embeddings variable, defaults to ``float32``.
    name: name of the module.
    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 perplexity is
      calculated across all replicas on that axis.
docstr_tok: ["Initializes","a","VQ-VAE","module",".","Args",":","embedding_dim",":","dimensionality","of","the","tensors","in","the","quantized","space",".","Inputs","to","the","modules","must","be","in","this","format","as","well",".","num_embeddings",":","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",")",".","dtype",":","dtype","for","the","embeddings","variable",",","defaults","to","``","float32","``",".","name",":","name","of","the","module",".","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","perplexity","is","calculated","across","all","replicas","on","that","axis","."]
code: def __init__(
      self,
      embedding_dim: int,
      num_embeddings: int,
      commitment_cost: float,
      dtype: Any = jnp.float32,
      name: Optional[str] = None,
      cross_replica_axis: Optional[str] = None,
  ):
      """Initializes a VQ-VAE module.
  
      Args:
        embedding_dim: dimensionality of the tensors in the quantized space.
          Inputs to the modules must be in this format as well.
        num_embeddings: 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).
        dtype: dtype for the embeddings variable, defaults to ``float32``.
        name: name of the module.
        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 perplexity is
          calculated across all replicas on that axis.
      """
      super().__init__(name=name)
      self.embedding_dim = embedding_dim
      self.num_embeddings = num_embeddings
      self.commitment_cost = commitment_cost
      self.cross_replica_axis = cross_replica_axis
  
      self._embedding_shape = [embedding_dim, num_embeddings]
      self._embedding_dtype = dtype
  
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 VectorQuantizer object from inherited base classes: hk with example: obj = VectorQuantizer(embedding_dim, num_embeddings, commitment_cost, dtype, name, cross_replica_axis)