Manuscript Offprint

arXiv:2609.31564

Weight Pair Encoding: Inducing a Smaller Grammar in Neural Network Weights

Irene Tallini, Daniele Solombrino, Alberto Cazzaniga, Emanuele Rodolà

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Irene Tallini*

Area Science Park

Trieste, Italy

irene.tallini@areasciencepark.it

Alberto Cazzaniga†

Université Côte d'Azur, Inria, LJAD

Maasai Project Team, Nice, France

Area Science Park, Trieste, Italy

Daniele Solombrino*

Sapienza University of Rome

Rome, Italy

solombrino@di.uniroma1.it

Emanuele Rodola†

Sapienza University of Rome and Paradigma

Rome, Italy

Abstract

We show that neural network weights can be explicitly fintuned to admit a smaller grammar. Weight Pair Encoding (WeightPE) does so by placing a lossy Re-Pair compressor inside a straight-through estimator. The int8 weights of the network are flattened into one string, and near-matching Re-Pair patterns are made exactly equal within a global L2L_{2} budget. The network computes with the rewritten weights and trains through them with a straight-through estimator. Unlike a flat codebook of fixed-size entries, a grammar offers variable-length patterns and reuses them hierarchically inside larger ones. On the MLP weights of ViT-B/16 and ViT-L/16 finetuned on CIFAR-10, WeightPE produces a Re-Pair grammar 0.43×0.43\times and 0.38×0.38\times the size of the one produced by an equivalent int8 QAT run, at a cost of 1.9 and 1.1 accuracy points. The trend extends to different grammar compressors (LZ78, SEQUITUR), over which the networks has not be finetuned against. To our knowledge, this is the first time grammar size has been used as an explicit training objective for network weights.

1 Introduction and Related Works

Identifying and imposing structure in the weights of a network has repeatedly proved valuable: weight repetition [Nowlan and Hinton, 1992, Ullrich et al., 2017], low-rank structure [Aghajanyan et al., 2021, Hu et al., 2022], permutation symmetry [Entezari et al., 2022, Ainsworth et al., 2023].

Grammar structure is another rich candidate: it compresses a string exposing its repetitions hierarchically, it supports random access in space proportional to the compressed size [Bille et al., 2015] and direct computation over the compressed representation [Ferragina et al., 2022]. The size of the smallest grammar generating a string is an expressive yet computable approximation of Kolmogorov complexity: finding it is NP-hard, but it admits heuristics with worst-case guarantees [Charikar et al., 2005].

In principle, any scheme that reduces the symbol alphabet shrinks the grammar: quantization, by leaving fewer distinct symbols, leaves fewer distinct substrings, and the grammar shrinks as a side effect. Existing compact representations of weights work this way and are flat: codebooks and clustering [Han et al., 2016, Cho et al., 2022], or size placed directly in the objective through entropy

∗^{*}Equal contribution.

†^{\dagger}Equal senior contribution.

Preprint.

Figure

Figure 1: Top: Finetuning pipeline of WeightPE. Bottom left: High-level steps of one lossy Re-Pair iteration. Bottom right: Cluster leaders emerging in one step of WeightPE.

penalties, learned bit-widths, and reusable motifs [Oktay et al., 2020, Cséfalvay and Imber, 2023, Bakhtiarifard et al., 2026]. The atom is always one weight or a fixed-size block, so variable-length substrings that recur, and recur inside one another, cannot be named. To our knowledge, grammar size has never been an explicit training objective for network weights.

We therefore introduce WeightPE, which pushes the weights at training time to admit a small grammar. WeightPE flattens the int8-quantized weights into a single string and compresses it with a lossy variant of Re-Pair: recurring patterns are first rewritten onto shared cluster leaders under a global L2 distortion budget and standard Re-Pair merges then build the grammar, similarly to a lossy tokenization of the flattened, concatenated weight matrix. The gradient is computed through STE. On ViT-B/16 and ViT-L/16 finetuned on CIFAR-10, the MLP weights WeightPE produces a Re-Pair grammar 0.43×0.43\times and 0.38×0.38\times the size of the one an equivalent int8 QAT run, at a cost of 1.9 and 1.1 accuracy points.

References (31)