# Dyskretne kody obrazu i dźwięku (VQ-VAE, VQGAN)

EN: **Vector-quantised autoencoders (VQ-VAE, VQGAN)** · id `vqvae` · aliases: VQ-VAE, VQGAN, vector quantization, kwantyzacja wektorowa, codebook, visual tokenizer, tokenizer obrazu

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Sieci i modele generatywne](https://aiatlasgraph.com/t/neural.md) › [Rodziny modeli generatywnych](https://aiatlasgraph.com/t/generative.md) › [Autoenkodery wariacyjne (VAE)](https://aiatlasgraph.com/t/vae.md) › Dyskretne kody obrazu i dźwięku (VQ-VAE, VQGAN)

## Description

- PL: Autoenkoder, którego koder zwraca indeksy najbliższych wektorów z wyuczonej książki kodów, tworząc dyskretne tokeny dla modeli generatywnych.
- EN: An autoencoder whose encoder outputs indices of the nearest vectors in a learned codebook, producing discrete tokens for generative models.

## In one sentence

- PL: Sposób zamiany obrazu lub dźwięku na krótki ciąg „słów” z ograniczonego słownika, z którego potem da się go odtworzyć.
- EN: A way to turn an image or sound into a short string of ‘words’ from a limited vocabulary, from which it can be rebuilt.

## Problem it solves

- PL: Modele piszące tekst słowo po słowie nie umieją wprost pracować na milionach pikseli czy próbek dźwięku.
- EN: Models that write text word by word cannot work directly on millions of pixels or sound samples.

## What it does

- PL: Jak mozaika z ograniczonego zestawu kafelków: każdy fragment obrazu zastępuje się numerem najbardziej podobnego kafelka.
- EN: Like a mosaic made from a fixed set of tiles: each image patch is replaced by the number of the most similar tile.

## Everyday example

- PL: Asystent, który rysuje obrazek na twoją prośbę, w środku układa go z ciągu kodów, tak jak układa zdanie ze słów.
- EN: An assistant that draws a picture on request internally builds it from a string of codes, just as it builds a sentence from words.

## This concerns you if you…

- PL: chcesz zrozumieć, jak modele językowe generują obrazy
- PL: interesuje cię kompresja obrazu lub dźwięku siecią
- EN: want to understand how language models generate images
- EN: are curious about compressing images or sound with a network

## Keywords

VQ-VAE · VQGAN · vector quantization · codebook · straight-through estimator · commitment loss · image tokenizer

## How it works

- PL: Koder tworzy siatkę wektorów, a każdy zastępuje się najbliższym wpisem z książki kodów; dekoder odtwarza obraz z tych wpisów. Gradient przez nieróżniczkowalny wybór przenosi się sztuczką straight-through, a straty commitment trzymają koder blisko kodów. Na tokenach uczy się potem osobny model a priori, np. transformer; VQGAN dodaje straty przeciwstawną i percepcyjną.
- EN: The encoder produces a grid of vectors, each replaced by the nearest codebook entry; the decoder rebuilds the image from those entries. Gradients pass the non-differentiable lookup via a straight-through estimator, and commitment losses keep encoder outputs near codes. A separate prior, e.g. a transformer, is then trained on the tokens; VQGAN adds adversarial and perceptual losses.

## Limits

- PL: Dyskretyzacja wprowadza kompromis między stopniem kompresji a jakością rekonstrukcji. Niewykorzystywane wpisy książki kodów marnują pojemność, a cały późniejszy generator jest ograniczony informacją zachowaną przez tokenizer.
- EN: Discretisation creates a trade-off between compression and reconstruction quality. Unused codebook entries waste capacity, and every downstream generator is limited by the information retained by the tokenizer.

## Key terms

- PL: **książka kodów**: Wyuczony zestaw wektorów, którymi zastępuje się fragmenty obrazu.
- PL: **straight-through estimator**: Sztuczka przepuszczająca gradient przez nieróżniczkowalny krok, jakby go nie było.
- PL: **posterior collapse**: Sytuacja, gdy dekoder ignoruje zmienne ukryte; kody dyskretne temu zapobiegają.
- EN: **codebook**: A learned set of vectors that replace image patches.
- EN: **straight-through estimator**: A trick passing gradients through a non-differentiable step as if absent.
- EN: **posterior collapse**: When the decoder ignores latent variables; discrete codes help prevent it.

## Know first

- [Tokenizacja tekstu (BPE, WordPiece, SentencePiece) (Text tokenisation (BPE, WordPiece, SentencePiece))](https://aiatlasgraph.com/t/tokenization.md)
- [Głębokie architektury konwolucyjne (ResNet, U-Net) (Deep convolutional architectures (ResNet, U-Net))](https://aiatlasgraph.com/t/cnnarchs.md)

## Related topics

Untyped, symmetric "see also" links.

- [Autoregresyjne generowanie obrazu i dźwięku (Autoregressive image and audio generation)](https://aiatlasgraph.com/t/argen.md)

## Sources

- [Neural Discrete Representation Learning](<https://arxiv.org/abs/1711.00937>) `vandenoord-vqvae-2017` · by Aaron van den Oord, Oriol Vinyals, Koray Kavukcuoglu
- [Taming Transformers for High-Resolution Image Synthesis](<https://arxiv.org/abs/2012.09841>) `esser-vqgan-2020` · by Patrick Esser, Robin Rombach, Björn Ommer

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/vqvae · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
