GQ-VAE: A gated quantized VAE for learning variable length tokens

Theo Datta, Kayla Huang, Sham M. Kakade, David BrandfonbrenerarXiv 2025 · DOI · arXiv

Introduction

Modern Large Language Models (LLMs) predominantly utilize Byte-Pair Encoding (BPE), a deterministic algorithm that merges frequent character sequences into a fixed vocabulary. While BPE is computationally efficient, it is semantically agnostic and does not optimize for the downstream learnability of the resulting tokens. Previous attempts at "learned" neural tokenizers often required significant architectural changes or were restricted to fixed-length text blocks, which fail to capture the natural variability of language.

This paper introduces the GQ-VAE (Gated Quantized Variational Autoencoder), a standalone neural tokenizer that learns to encode text into discrete, variable-length tokens. By incorporating a gating mechanism, the GQ-VAE can dynamically determine token boundaries, offering a flexible and learnable alternative to traditional tokenization methods.

Architecture and Methodology

The GQ-VAE framework consists of four integrated components designed to process input bytes into discrete tokens:

  1. Encoder: A Transformer-based module that maps input characters into a sequence of continuous latent vectors.
  2. Quantizer: Maps these continuous vectors to the nearest entries in a discrete "codebook," facilitating the transition from continuous to discrete representation.
  3. Gater: The core innovation of the model. It predicts binary token boundaries ($g_t$). When the gate is activated, a new token is finalized. This allows the model to adaptively group characters into tokens of varying lengths.
  4. Decoder: Reconstructs the original input from the quantized vectors and predicts the length of each token to ensure structural consistency during decoding.
Figure 1: The GQ-VAE architecture illustrating the flow from input characters to gated, quantized tokens.

The model is trained using a composite loss function that optimizes for reconstruction accuracy, compression efficiency (by penalizing excessive gate activations), and vector quantization stability. Discrete optimization is handled via straight-through gradient estimation.

Experimental Setup

The researchers evaluated the GQ-VAE using the TinyStories dataset, a synthetic collection of short stories with a controlled vocabulary. This dataset provides a robust environment for testing architectural innovations before scaling to broader, more complex web-scale data.

Key Results and Insights

The GQ-VAE demonstrates significant advantages over both fixed-length neural baselines and traditional BPE in terms of learnability.

Learnability vs. Compression

A central thesis of this work is that a tokenizer's value should be measured by how effectively a downstream LLM can learn from its output, rather than just raw compression. Experimental results show that when an LLM is trained on GQ-VAE tokens, it achieves faster convergence compared to a BPE-based model at the same compression level (3.85 bytes/token). Specifically, the GQ-VAE-based LLM reached the BPE model's minimum loss approximately 600 steps (16.6%) earlier.

Figure 5: Evaluation loss comparison showing faster convergence for LLMs trained with GQ-VAE tokens compared to BPE at equivalent compression.

The Advantage of Variable Length

By allowing the model to choose token boundaries, GQ-VAE significantly outperforms fixed-length VQ-VAE baselines. Variable-length encoding allows the model to capture semantic units more naturally, leading to better reconstruction quality and higher compression rates than rigid block-based methods.

Token Distribution Uniformity

Analysis of the token frequency distribution reveals that GQ-VAE produces a more uniform distribution of "tail" tokens compared to the "heavy-headed" distribution typical of BPE. This uniformity may assist the model in learning rare words and concepts more effectively by providing more balanced training signals across the vocabulary.

Conclusion and Future Work

GQ-VAE represents a promising step toward fully learned, variable-length neural tokenization. It serves as a drop-in replacement for existing tokenizers and demonstrates that optimizing for learnability can yield more efficient language modeling.

While currently slightly less efficient in raw compression than BPE (within a 7% margin), the model's performance on TinyStories suggests it is a viable path forward. Future research will focus on scaling to multi-lingual datasets, exploring lossy tokenization for enhanced semantic compression, and extending the gated quantization framework to other modalities such as audio and video.

Summary updated

Abstract

While most frontier models still use deterministic frequency-based tokenization algorithms such as byte-pair encoding (BPE), there has been significant recent work to design learned neural tokenizers. However, these schemes generally add to underlying language model complexity and force large changes to architecture, making them hard to implement at large scales. To overcome these challenges, we propose the gated quantized variational autoencoder (GQ-VAE), a novel architecture that can be independently pre-trained to serve as a drop-in replacement for existing tokenizers. The key innovation of the architecture is to learn to encode variable-length discrete tokens. GQ-VAE improves compression and language modeling performance over a standard VQ-VAE tokenizer, and approaches the compression rate and language modeling performance of BPE. Interestingly, if we use BPE with a smaller vocabulary, such that the compression is equivalent between GQ-VAE and BPE, we find that GQ-VAE improves downstream language model learning. We conclude with a discussion of several exciting avenues for future work. Code can be found at https://github.com/Theo-Datta-115/gq-vae.
BibTeX
@misc{datta2025gq,
  author = {Theo Datta and Kayla Huang and Sham M. Kakade and David Brandfonbrener},
  title = {{GQ-VAE: A gated quantized VAE for learning variable length tokens}},
  year = {2025},
  eprint = {2512.21913},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.21913},
}
Figure