You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,7 +90,7 @@ x = torch.randn(1, 1024, 256)
90
90
quantized, indices, commit_loss = vq(x)
91
91
```
92
92
93
-
### Cosine Similarity
93
+
### Cosine similarity
94
94
95
95
The <ahref="https://openreview.net/forum?id=pfNyExj7z2">Improved VQGAN paper</a> also proposes to l2 normalize the codes and the encoded vectors, which boils down to using cosine similarity for the distance. They claim enforcing the vectors on a sphere leads to improvements in code usage and downstream reconstruction. You can turn this on by setting `use_cosine_sim = True`
96
96
@@ -108,6 +108,24 @@ x = torch.randn(1, 1024, 256)
108
108
quantized, indices, commit_loss = vq(x)
109
109
```
110
110
111
+
### Expiring stale codes
112
+
113
+
Finally, the SoundStream paper has a scheme where they replace codes that have not been used in a certain number of consecutive batches with a randomly selected vector from the current batch. You can set this threshold for consecutive misses before replacement with `max_codebook_misses_before_expiry` keyword. (I know it is a bit long, but I couldn't think of a better name)
114
+
115
+
```python
116
+
import torch
117
+
from vector_quantize_pytorch import VectorQuantize
118
+
119
+
vq = VectorQuantize(
120
+
dim=256,
121
+
codebook_size=512,
122
+
max_codebook_misses_before_expiry=5# should actively replace any codes that were missed 5 times in a row during training
0 commit comments