Abstract
Recent advances in Natural Language Processing (NLP) are dominated by large-scale Deep Neural Networks (DNNs). However, these models are computationally expensive and often struggle in low-resource or out-of-distribution (OOD) scenarios. This paper demonstrates that a simple, parameter-free method—combining the standard gzip compressor with a $k$-nearest-neighbor (kNN) classifier—can rival or even outperform state-of-the-art models like BERT. Without any training or hyperparameter tuning, this approach proves remarkably robust, particularly in few-shot settings.
Introduction
Deep Neural Networks currently define the state-of-the-art in NLP, but they come with significant costs: high data requirements, massive computational overhead, and the need for extensive hyperparameter tuning. Furthermore, DNNs often exhibit poor generalization when faced with out-of-distribution (OOD) data or limited labeled examples. This research explores a lightweight, "universal" alternative that treats text as raw byte sequences, bypassing the need for specialized hardware or complex preprocessing.
Methodology: Compression-Based Classification
The proposed method relies on the concept of Normalized Compression Distance (NCD). The core intuition is that data compressors (such as gzip) are inherently designed to detect statistical regularities. If two documents are similar, they will share patterns, and concatenating them will result in a compressed size significantly smaller than the sum of their individual compressed sizes.
The classification pipeline follows four steps:
- Compress: Calculate the compressed length of a test document $x$ and a training document $y$.
- Concatenate and Compress: Calculate the compressed length of the concatenated string $xy$.
- Calculate Distance: Compute the NCD score, a metric between 0 and 1 representing the distance between $x$ and $y$.
- Classify: Apply a $k$-Nearest Neighbor (kNN) algorithm to assign the test document to the class most prevalent among its closest neighbors in the training set.
This approach is entirely parameter-free, requiring no training phase or GPU acceleration.
Experimental Evaluation
The authors evaluated the gzip+kNN method across diverse scenarios:
- In-distribution (ID): Seven standard datasets (e.g., AG News, DBpedia, YahooAnswers).
- Out-of-distribution (OOD) / Low-resource: Five datasets featuring languages or formats typically unseen by pre-trained models like BERT (e.g., Kinyarwanda news, SogouNews in Pinyin).
- Few-shot settings: Performance was measured with only 5, 10, 50, or 100 labeled examples per class.
Key Results and Insights
The "low-tech" compression method yielded several surprising results:
Superiority in Low-Resource and OOD Settings
The method consistently outperformed BERT on all five OOD datasets. In extreme low-data (5-shot) scenarios, gzip demonstrated a significant lead over traditional baselines. For instance, on AG News with only 5 samples per class, gzip was 115% more accurate than fastText.
Robustness through Simplicity
Unlike DNNs, which may overfit to specific training nuances (inductive bias), gzip is data-type agnostic. It relies on surface-level statistical regularity, which serves as a powerful proxy for category in topic classification. This lack of "weights" allows it to generalize to new languages and domains where a model's prior pre-training might be a hindrance.
Limitations and Conclusion
While highly effective, the method faces a computational bottleneck during inference: the kNN search requires $O(n^2)$ comparisons, which can become slow for very large training sets. Additionally, while statistical regularity captures "orthographic similarity," it may struggle with tasks requiring deep semantic understanding, such as detecting subtle sarcasm.
In conclusion, this work highlights a minimalist path for NLP. A 14-line Python script can provide a robust, efficient, and surprisingly competitive alternative to billion-parameter transformers, especially when data is scarce or unconventional.
Summary updated