class_docstr: Sonnet 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: ["Sonnet","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 tf.float32.
    name: name of the module.
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","tf.float32",".","name",":","name","of","the","module","."]
code: def __init__(
      self,
      embedding_dim: int,
      num_embeddings: int,
      commitment_cost: types.FloatLike,
      dtype: tf.DType = tf.float32,
      name: str = "vector_quantizer",
  ):
      """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 tf.float32.
        name: name of the module.
      """
      super().__init__(name=name)
      self.embedding_dim = embedding_dim
      self.num_embeddings = num_embeddings
      self.commitment_cost = commitment_cost
  
      embedding_shape = [embedding_dim, num_embeddings]
      initializer = initializers.VarianceScaling(distribution="uniform")
      self.embeddings = tf.Variable(
          initializer(embedding_shape, dtype), name="embeddings"
      )
  
file_path: sonnet/sonnet/src/nets/vqvae.py
imports: from sonnet.src import base
  from sonnet.src import initializers
  from sonnet.src import moving_averages
  from sonnet.src import types
  import tensorflow
label_desc: Use image node_id 1 to create a new VectorQuantizer object from inherited base classes: base with example: obj = VectorQuantizer(embedding_dim, num_embeddings, commitment_cost, dtype, name)