msvq#
- class diffsptk.MultiStageVectorQuantization(order, codebook_size, n_stage, **kwargs)[source]#
See this page for details.
- Parameters:
- orderint >= 0
The order of the input vector, \(M\).
- codebook_sizeint >= 1
The codebook size, \(K\).
- n_stageint >= 1
The number of stages (quantizers), \(Q\).
- **kwargsadditional keyword arguments
See this page for details.
References
[1]A. v. d. Oord et al., “Neural discrete representation learning,” Advances in Neural Information Processing Systems, pp. 6309-6318, 2017.
- forward(x, codebooks=None, **kwargs)[source]#
Perform residual vector quantization.
- Parameters:
- xTensor [shape=(…, M+1)]
The input vectors.
- codebooksTensor [shape=(Q, K, M+1)]
The external codebook. If None, use the internal codebook.
- **kwargsadditional keyword arguments
See this page for details.
- Returns:
- xqTensor [shape=(…, M+1)]
The quantized vectors.
- indicesTensor [shape=(…, Q)]
The codebook indices.
- lossesTensor [shape=(Q,)]
The commitment losses.
Examples
>>> x = diffsptk.nrand(4) >>> x tensor([-0.5206, 1.0048, -0.3370, 1.3364, -0.2933]) >>> msvq = diffsptk.MultiStageVectorQuantization(4, 3, 2).eval() >>> xq, indices, _ = msvq(x) >>> xq tensor([-0.4561, 0.9835, -0.3787, -0.1488, -0.8025]) >>> indices tensor([0, 2])