Learning K-way D-dimensional Discrete Codes for Compact Embedding Representations

Ting Chen, Martin Renqiang Min, Yizhou Sun

The Scalability Bottleneck in Modern ML

In modern machine learning, discrete symbols—such as words in natural language processing or nodes in a graph—are typically represented using "one-hot" encoding. This sparse vector is multiplied by a massive weight matrix to produce a continuous, dense embedding vector.

While effective, this standard approach faces a severe scalability problem. The number of parameters in the embedding matrix grows linearly with the vocabulary size ($N$). For real-world databases containing millions or billions of entities, this creates two major bottlenecks:

  1. Memory Constraints: Embedding layers can consume gigabytes of memory, making models too large to deploy on mobile or edge devices.
  2. Overfitting: Following Zipf’s law, many symbols appear rarely in the training data. High-dimensional parameters for these rare symbols are poorly estimated, leading to overfitting and poor generalization.

The KD Encoding Solution

To address these massive, memory-hungry embedding tables, researchers introduce KD encoding, a method that replaces the giant lookup table with compact, discrete codes.

Instead of a single one-hot vector, each symbol is assigned a discrete code $c = (c^1, c^2, \dots, c^D)$, where each dimension $c^j$ can take one of $K$ possible values ($c^j \in \{1, \dots, K\}$). Rather than maintaining one giant table of size $N$, the model learns $D$ smaller tables, each containing only $K$ embedding vectors.

Comparison of traditional one-hot encoding with KD encoding and various composition functions.

To generate the final continuous embedding for a symbol, a composition function combines the $D$ vectors corresponding to the symbol's discrete code. This function can be a simple linear operation (like summing the vectors) or a more expressive non-linear operation (like passing them through an RNN or DNN).

Overcoming Optimization Hurdles

The primary challenge with KD encoding is that discrete codes are not naturally differentiable, making them notoriously difficult to learn via standard backpropagation. To solve this NP-hard optimization problem, the authors employ a multi-pronged strategy:

  • Continuous Relaxation: Codes are initially represented as "soft" probability distributions using a Tempering Softmax. As training progresses, the "temperature" is lowered, gradually pushing the distributions toward hard, discrete one-hot vectors.
  • Straight-Through Estimator (STE): During the forward pass, the model uses the discrete code. During the backward pass, the STE pretends the function was differentiable, allowing gradients to flow back to the parameters.
  • Distillation Guidance: To stabilize the erratic training signals of discrete optimization, the authors introduce Online Distillation Guidance (ODG) and Pre-trained Distillation Guidance (PDG). These techniques encourage the KD-generated embeddings to mimic traditional continuous embeddings, providing a smoother, more reliable learning signal.

Key Insights and Performance Gains

The researchers evaluated KD encoding across language modeling (Penn Treebank), text classification (Yahoo! Answers, AG’s News, etc.), and graph node classification (Cora, Citeseer, Pubmed). The results highlight several critical advantages:

  • Massive Compression: In text classification tasks, the embedding layer size was reduced by up to 98%. For example, the Yahoo! Answers embedding table shrank from 4.5GB down to just 86MB with virtually no loss in accuracy.
  • Performance Improvements: Surprisingly, the compact representations often outperformed full-parameter baselines. On the Penn Treebank language modeling task, the KD-encoded "Large" model achieved a better (lower) perplexity of 77.72 compared to the full embedding baseline's 78.71. Similarly, in graph node classification on the Cora dataset, the KD approach outperformed the baseline (0.823 vs 0.814 accuracy). The discrete bottleneck appears to act as a helpful regularizer against overfitting.
  • Semantic Clustering: The learned codes capture semantic meaning rather than acting as random hashes. The model learns to assign similar discrete codes to related concepts (e.g., "Monday" and "Tuesday"), allowing them to share parameters and dramatically improving the representation of rare words.
  • The Power of Redundancy: The authors discovered that using a "redundant" code system—where the total number of possible codes ($K^D$) is much larger than the vocabulary size ($N$)—makes optimization significantly easier by reducing code "collisions."

Limitations and Future Directions

While KD encoding offers massive memory savings, it comes with trade-offs. Learning discrete codes requires careful tuning of temperature schedules and distillation techniques. Additionally, there is a slight computational overhead during inference to "compose" the embedding from $D$ pieces, though this is generally minimal compared to the overall network cost.

Future work will explore applying these compact representations to information retrieval systems and investigating more complex composition functions to further push the boundaries of efficient machine learning.

Summary updated

BibTeX
@inproceedings{chen2018learning,
  author = {Ting Chen and Martin Renqiang Min and Yizhou Sun},
  title = {{Learning K-way D-dimensional Discrete Codes for Compact Embedding Representations}},
  booktitle = {International Conference on Machine Learning},
  year = {2018},
  url = {https://openreview.net/forum?id=r1NQqi-_-S},
}
Figure