[Paper Review] Less is More: Parameter-Free Text Classification with Gzip
This paper proposes a parameter-free text classification method that combines gzip compression with a k-nearest-neighbor classifier, achieving competitive accuracy on in-distribution datasets and outperforming BERT on out-of-distribution and few-shot settings without any training or hyperparameter tuning.
Deep neural networks (DNNs) are often used for text classification tasks as they usually achieve high levels of accuracy. However, DNNs can be computationally intensive with billions of parameters and large amounts of labeled data, which can make them expensive to use, to optimize and to transfer to out-of-distribution (OOD) cases in practice. In this paper, we propose a non-parametric alternative to DNNs that's easy, light-weight and universal in text classification: a combination of a simple compressor like gzip with a $k$-nearest-neighbor classifier. Without any training, pre-training or fine-tuning, our method achieves results that are competitive with non-pretrained deep learning methods on six in-distributed datasets. It even outperforms BERT on all five OOD datasets, including four low-resource languages. Our method also performs particularly well in few-shot settings where labeled data are too scarce for DNNs to achieve a satisfying accuracy.
Motivation & Objective
- To develop a lightweight, universal, and parameter-free alternative to deep neural networks for text classification.
- To address the limitations of deep learning models in low-resource and out-of-distribution settings where labeled data is scarce.
- To explore whether lossless compression can serve as an effective, data-agnostic distance metric for text classification.
- To evaluate the method’s performance across diverse datasets, including low-resource and multilingual settings.
- To demonstrate that compressibility of text correlates with classification performance, especially in few-shot scenarios.
Proposed method
- The method uses gzip as a lossless compressor to estimate a compression-based distance metric derived from Kolmogorov complexity.
- For each test instance, the compressed length of the concatenation of a training instance and the test instance is computed, and the difference from the compressed length of the training instance alone is used as a similarity measure.
- The k-nearest-neighbor classifier selects the k training instances with the smallest compression difference to predict the class of the test instance.
- The approach avoids any model training, fine-tuning, or hyperparameter optimization, relying solely on the compressor’s ability to capture regularities in text.
- The method is applied across multiple datasets and compressors (gzip, zstd, bz2, lzma), with performance evaluated under both full and few-shot settings.
- The compression-based distance metric is compared against the traditional cross-entropy method using $C(d_c d_u) - C(d_c)$, which concatenates all training samples per class.
Experimental results
Research questions
- RQ1Can a non-parametric, parameter-free method based on gzip compression achieve competitive text classification accuracy without any training or fine-tuning?
- RQ2How does the proposed method perform compared to non-pretrained deep learning models on in-distribution datasets?
- RQ3Does the method outperform pre-trained models like BERT on out-of-distribution and low-resource datasets?
- RQ4How effective is the method in few-shot learning scenarios with limited labeled data?
- RQ5What is the relationship between text compressibility and classification accuracy, and how do different compressors affect performance?
Key findings
- The proposed method achieves competitive accuracy on six in-distribution datasets, matching or exceeding non-pretrained deep learning models without any training.
- On five out-of-distribution datasets, including four low-resource languages, the method outperforms BERT, demonstrating strong generalization capability.
- The method significantly outperforms non-pretrained deep learning models in few-shot settings, where labeled data is extremely limited.
- Gzip achieves the most stable and high performance across datasets, while lzma is competitive but slower; bz2 underperforms despite high compression ratios, likely due to order-sensitive compression.
- There is a moderate to strong linear correlation (Pearson $r_p = 0.719$) between compression ratio and test accuracy in few-shot settings, suggesting compressibility predicts classification success.
- The k-NN method using compression differences outperforms the traditional cross-entropy method ($C(d_c d_u) - C(d_c)$) on longer texts like SogouNews, where the latter fails to leverage large training sets effectively.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.