class
VectorQuantizer
PythonVector-quantization bottleneck (VQ-VAE style) with straight-through estimator.
VectorQuantizer(num_embeddings, embedding_dim, beta=0.25, **kw={})Vector-quantization bottleneck (VQ-VAE style) with straight-through estimator.
Input: […, D] (last dim == embedding_dim) Output: […, D] (quantized/dequantized vectors; gradients pass through x)
Tracks (logged automatically via metrics property):
- vq_perplexity : effective # active codes (1..K)
- vq_usage : fraction of codes used at least once (0..1)
- vq_bits_per_index : entropy lower bound in bits/index (~ log2 perplexity)
Adds losses via add_loss:
- beta * ||stop(quant) - x||^2 (commitment)
- ||quant - stop(x)||^2 (codebook)
constant
K
PythonK = int(num_embeddings)constant
D
PythonD = int(embedding_dim)attribute
beta
Pythonbeta = float(beta)attribute
metrics
Pythonmetricsmethod
build
Pythonbuild(input_shape)method
call
Pythoncall(x, return_indices=False)method
get_config
Pythonget_config()