vector_quantizer
Classes
VectorQuantizer
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)