lucidrains / lucidrains/vector-quantize-pytorch

Seeking clarifications regarding learnable codebook

Open
#147 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
4k
Forks
338
PR merge metrics
No merged PRs in 30d

Description

Hi,

I am interested in learning codewords (not using EMA) that are L2-normalized and orthonormal with each other. To do so, I created the vector quantizer using the following configuration:
```
vq = VectorQuantize(
dim = 256,
codebook_size = 256,
use_cosine_sim = True,
orthogonal_reg_weight = 10,
orthogonal_reg_max_codes = 128,
orthogonal_reg_active_codes_only = False,
learnable_codebook=True,
ema_update=False
)
```
However, I noticed in the [implementation](https://github.com/lucidrains/vector-quantize-pytorch/blob/master/vector_quantize_pytorch/vector_quantize_pytorch.py#L1038) at line 1071 that there is only a single term that enforces input embedding to push towards their corresponding quantized (codeword) embeddings. It does not include a second term that would enforce the other way round. Am I missing something here?

Also, if I create a vector quantizer that learns codebook using EMA with the following configuration:

```
vq = VectorQuantize(
dim = 256,
codebook_size = 256,
use_cosine_sim = True,
orthogonal_reg_weight = 10,
orthogonal_reg_max_codes = 128,
orthogonal_reg_active_codes_only = False,
learnable_codebook=False,
ema_update=True,
decay=0.8
)

```
Will it still learn codewords to ensure their orthonormalilty?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with vector_quantize_pytorch/vector_quantize_pytorch.py around the linked line 1071, then trace the learnable_codebook and EMA update paths alongside the orthogonal regularization settings. Done means a maintainer-confirmed explanation addresses whether each configuration enforces the requested codebook properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.