Category coding with neural network application

Qizhi Zhang, Kuang-chih Lee, Hongying Bao, Yuan You, Dongbai GuoarXiv 2018

Abstract

High-cardinality categorical features and labels pose significant memory and computational challenges in large-scale machine learning applications. This paper introduces Category Coding (CC), a framework based on number theory and finite field theory designed to compress massive categorical spaces into low-dimensional representations. By optimizing for the "Minimal Collision Property," the authors propose three coding schemes—Polynomial, Remainder, and Gauss CC. These methods allow neural networks to handle millions of categories with substantially fewer resources than traditional one-hot encoding or Error-Correcting Output Coding (ECOC). Experimental results on CJK character classification and MovieLens recommendation tasks demonstrate that CC variants achieve superior performance and efficiency.

Introduction

In modern industrial machine learning, models often encounter "high-cardinality" categorical features, such as user or item IDs in systems with millions of entities. The standard approach, one-hot encoding, creates two primary bottlenecks: massive memory requirements for embedding matrices and prohibitive computational costs for large output layers. While ECOC is a common alternative for output labels, it is often limited to binary learners and does not easily extend to input feature encoding.

This paper addresses these issues by proposing a unified coding scheme that satisfies the sparsity requirements of neural networks while minimizing "collisions"—instances where distinct categories are mapped to the same representation.

Methodology

The core philosophy of Category Coding is the Minimal Collision Property. A robust code ensures that when $N$ categories are mapped to a lower-dimensional space, the number of overlaps between distinct categories is minimized. The authors leverage number theory to construct three specific schemes:

  1. Polynomial CC: Based on finite field theory (Reed-Solomon codes), treating categories as polynomial coefficients evaluated at distinct points.
  2. Remainder CC: Utilizes the Chinese Remainder Theorem, encoding a category $x$ as a sequence of remainders $(x \mod p_1, x \mod p_2, \dots)$ using pairwise co-prime modules.
  3. Gauss CC: Extends the remainder concept to Gaussian integers, providing a higher-dimensional Euclidean domain to further reduce collision probability.
Mathematical framework for mapping categorical spaces using finite field theory.

For label encoding, these schemes decompose a massive $N$-class problem into $r$ smaller sub-problems. For feature encoding, they create "r-hot" representations that are significantly denser and more memory-efficient than standard one-hot vectors.

Experimental Evaluation

The researchers evaluated Category Coding on two distinct tasks:

  • CJK Characters: A dataset of 20,901 Chinese, Japanese, and Korean characters used for massive multi-class image classification with an Inception V3 backbone.
  • MovieLens (1M): A collaborative filtering dataset used to test feature encoding in a regression task (predicting movie ratings).

Beyond traditional metrics, the authors introduce Average Minimal KL-divergence (AMKL). They argue that for non-linear neural models, AMKL is superior to Hamming distance because it better captures how distinguishable the reduced distributions of the codes are to the model.

Key Results

The experimental results highlight the efficiency of the CC framework. In the CJK classification task, Category Coding with only two "sites" (sub-classifiers) outperformed a 15-bit ECOC method. As the number of sites increased to six, accuracy exceeded 99.8%, significantly surpassing state-of-the-art ECOC benchmarks while utilizing fewer parameters.

Performance comparison of CC variants vs. ECOC on the CJK character dataset, showing accuracy across epochs and parameter counts.

Among the three proposed methods, Gauss CC consistently demonstrated the best performance, followed by Remainder CC and Polynomial CC. This hierarchy is attributed to the superior minimal collision properties inherent in Gaussian integer domains. In the MovieLens task, all CC methods outperformed standard "Cut-off" and "Random Punch" embedding techniques.

Conclusion

Category Coding provides a mathematically grounded approach to scaling neural networks for high-cardinality data. By moving beyond binary base learners and leveraging the properties of finite fields, the authors achieve a better trade-off between model complexity and predictive power. Future work includes optimizing the decoding complexity for categories numbering in the billions and further refining hyperparameter selection for the modules ($p_i$) and site counts ($r$).

Summary updated

BibTeX
@misc{zhang2018category,
  author = {Qizhi Zhang and Kuang-chih Lee and Hongying Bao and Yuan You and Dongbai Guo},
  title = {{Category coding with neural network application}},
  year = {2018},
  eprint = {1805.07927},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1805.07927},
}
Figure