Abstract
In the field of Natural Language Processing (NLP) and Digital Humanities, identifying divergent keywords between two corpora is a fundamental task. Jensen-Shannon Divergence (JSD) is frequently employed for this purpose due to its symmetric properties. However, a significant methodological split exists between the standard unweighted JSD (JSD-pechenick) and a size-weighted variant (JSD-gallagher). This paper investigates the impact of corpus size imbalance on these two metrics. Through mathematical analysis and empirical experiments on diverse datasets, we demonstrate that the weighted variant is fundamentally biased toward the smaller corpus, leading to unstable and misleading results. We recommend the exclusive use of the unweighted JSD for stable corpus comparison.
Introduction
Corpus comparison involves identifying words that distinguish one collection of text from another. For example, researchers might compare news coverage from different regions or analyze the linguistic shifts between academic disciplines. Jensen-Shannon Divergence has become a standard metric for this task because it avoids the infinite values associated with Kullback-Leibler divergence when words appear in only one corpus.
Recently, a weighted version of JSD has gained popularity. This version adjusts the "mixed" reference distribution based on the relative number of tokens in each corpus. While intuitively appealing as a correction for sample size, our research suggests this weighting introduces a mathematical trap that undermines the reliability of keyword extraction.
Methodology
Our investigation utilized three distinct approaches:
- Mathematical Refactoring: We analyzed the JSD-gallagher formula to determine how the weight parameter (representing relative corpus size) influences the divergence contribution of individual terms.
- Synthetic Scaling: We held word frequencies constant while artificially varying the size weights to observe shifts in top-ranked keywords.
- Subsampling Experiments: Using real-world datasets from the New York Times, Wikipedia, and BBC News, we physically removed documents to create size imbalances and measured the stability of the resulting keyword lists.
The "Smaller Corpus" Bias and the Flip-Flop Effect
The most critical finding is that JSD-gallagher is highly sensitive to the relative size of the corpora. When one corpus is significantly smaller than the other, the weighted metric disproportionately selects keywords from that smaller corpus, regardless of their actual statistical divergence.
This leads to what we term the "Flip-Flop" effect. In a comparison between NYT Sports and Education sections, if the sports corpus is smaller, the metric identifies sports-related terms as the most divergent. If the education corpus is then reduced to be the smaller of the two, the metric flips, identifying education-related terms as the most divergent, even if the underlying word distributions haven't changed.
Stability and Consistency
In contrast to the weighted variant, the standard JSD-pechenick demonstrates remarkable stability. It treats both corpora as equal contributors to the mixed distribution, ensuring that the "importance" of a word is determined by its relative frequency difference rather than the total number of tokens in its parent corpus.
Our experiments showed that JSD-pechenick produces nearly identical top-keyword lists even as one corpus is subsampled down to 10% of its original size. This consistency is vital for researchers who need to trust that their findings are a reflection of linguistic content rather than an artifact of collection size.
Conclusion
The size-weighted variant of Jensen-Shannon Divergence (JSD-gallagher) introduces a systematic bias that favors the smaller corpus in any comparison. This sensitivity makes it an unreliable tool for keyword extraction and corpus analysis, as results can be manipulated simply by adding or removing documents from one side of the comparison. We strongly advise researchers to utilize the standard, unweighted JSD (JSD-pechenick) to ensure stable, reproducible, and accurate corpus comparisons.
Summary updated