# helia_edge.layers.vector_quantizer

## helia_edge.layers.vector_quantizer.VectorQuantizer

`class` · `python`

```python
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)

Source: `helia_edge/layers/vector_quantizer.py:6`

### helia_edge.layers.vector_quantizer.VectorQuantizer.K

`constant` · `python`

```python
K = int(num_embeddings)
```

Source: `helia_edge/layers/vector_quantizer.py:28`

### helia_edge.layers.vector_quantizer.VectorQuantizer.D

`constant` · `python`

```python
D = int(embedding_dim)
```

Source: `helia_edge/layers/vector_quantizer.py:29`

### helia_edge.layers.vector_quantizer.VectorQuantizer.beta

`attribute` · `python`

```python
beta = float(beta)
```

Source: `helia_edge/layers/vector_quantizer.py:30`

### helia_edge.layers.vector_quantizer.VectorQuantizer.metrics

`attribute` · `python`

```python
metrics
```

Source: `helia_edge/layers/vector_quantizer.py:82`

### helia_edge.layers.vector_quantizer.VectorQuantizer.build

`method` · `python`

```python
build(input_shape)
```

Source: `helia_edge/layers/vector_quantizer.py:35`

### helia_edge.layers.vector_quantizer.VectorQuantizer.call

`method` · `python`

```python
call(x, return_indices=False)
```

Source: `helia_edge/layers/vector_quantizer.py:49`

### helia_edge.layers.vector_quantizer.VectorQuantizer.get_config

`method` · `python`

```python
get_config()
```

Source: `helia_edge/layers/vector_quantizer.py:85`
