espnet2.gan_codec.shared.quantizer.modules.core_vq.VectorQuantization
espnet2.gan_codec.shared.quantizer.modules.core_vq.VectorQuantization
class espnet2.gan_codec.shared.quantizer.modules.core_vq.VectorQuantization(dim: int, codebook_size: int, codebook_dim: int | None = None, decay: float = 0.99, epsilon: float = 1e-05, kmeans_init: bool = True, kmeans_iters: int = 50, threshold_ema_dead_code: int = 2, commitment_weight: float = 1.0, quantizer_dropout: bool = False)
Bases: Module
Vector quantization implementation. Currently supports only euclidean distance. :param dim: Dimension :type dim: int :param codebook_size: Codebook size :type codebook_size: int :param codebook_dim: Codebook dimension. If not defined, uses the specified
dimension in dim.
- Parameters:
- decay (float) – Decay for exponential moving average over the codebooks.
- epsilon (float) – Epsilon value for numerical stability.
- kmeans_init (bool) – Whether to use kmeans to initialize the codebooks.
- kmeans_iters (int) – Number of iterations used for kmeans initialization.
- threshold_ema_dead_code (int) – Threshold for dead code expiration. Replace any codes that have an exponential moving average cluster size less than the specified threshold with randomly selected vector from the current batch.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
property codebook
decode(embed_ind)
encode(x)
forward(x, mask=None)
Defines the computation performed at every call.
Should be overridden by all subclasses.
NOTE
Although the recipe for forward pass needs to be defined within this function, one should call the Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.