DocSCAN: Unsupervised Text Classification via Learning from Neighbors

Dominik Stammbach, Elliott Ash

Introduction

Text classification is a cornerstone of Natural Language Processing (NLP), yet standard supervised approaches demand extensive human-annotated data. Labeling is costly, time-consuming, and often fails to generalize across domains. While unsupervised methods like k-means clustering exist, they frequently struggle with the complex semantic nuances captured by modern deep-learning representations.

DocSCAN (Document Semantic Clustering by Adopting Nearest neighbors) addresses this by adapting the SCAN algorithm from computer vision to the NLP domain. It offers a "pure" unsupervised approach that requires only one piece of prior knowledge: the expected number of clusters.

Methodology

DocSCAN operates through a three-step pipeline designed to learn topic assignments without explicit labels:

  1. Semantic Embedding: Documents are transformed into 768-dimensional dense vectors using SBERT (Sentence-BERT). SBERT is chosen because its pre-training on Natural Language Inference (NLI) tasks makes its embedding space particularly effective at grouping semantically similar texts.
  2. Neighbor Mining: Using the Faiss library for efficient similarity searching, the system identifies the top $k$ nearest neighbors (default $k=5$) for every document based on Euclidean distance.
  3. Fine-tuning with SCAN Loss: A classification layer is added on top of the embeddings and trained using a dual-objective loss function:
  4. Consistency Loss: This forces the model to assign the same probability distribution (and thus the same label) to a document and its neighbors.
  5. Entropy Loss: To prevent the model from assigning every document to the same cluster (cluster collapse), an entropy term encourages the model to spread probability mass across all available clusters.

Notably, the authors omit the "self-labeling" phase used in the original image-based SCAN algorithm, as robust text augmentation is significantly more challenging than image augmentation.

The Neighbor Hypothesis

The core intuition behind DocSCAN is that semantically similar documents in a high-quality embedding space likely share the same ground-truth label.

Figure 1: Percentage of nearest neighbors sharing the same ground-truth label across different datasets.

As shown in Figure 1, the nearest neighbor of a document shares its ground-truth label over 85% of the time in SBERT space for datasets like AG News and DBPedia. This high regularity provides a sufficiently strong signal to replace human-provided labels during training.

Experimental Results

The model was evaluated on three standard benchmarks: 20NewsGroup (20 classes), AG’s News (4 classes), and DBPedia (14 classes).

Figure 2: Accuracy comparison of DocSCAN against unsupervised and supervised baselines.

As detailed in Figure 2, DocSCAN consistently outperforms the traditional k-means baseline. On AG News, it achieved 84.1% accuracy, a massive jump from k-means (69.2%) and remarkably close to the supervised SVM baseline (92.1%). Even on the more complex 20NewsGroup dataset with 20 classes, DocSCAN maintained a lead with 59.4% accuracy.

Key Insights

  • Embedding Quality is Paramount: The success of DocSCAN is heavily dependent on the initial embeddings. Performance drops significantly when swapping SBERT for GloVe or Universal Sentence Encoder (USE), as SBERT’s NLI-based pre-training provides the "cleanest" neighborhoods.
  • Entropy as a Necessary Constraint: The entropy loss is the "glue" of the system. Without it, the model collapses into a single cluster; with it, the model is forced to discover the underlying diversity of the corpus.
  • Simplicity vs. Heuristics: Unlike other unsupervised methods that require "seed words" (knowing category names beforehand), DocSCAN learns categories entirely from the geometry of the embedding space.

Limitations and Future Work

DocSCAN assumes a relatively balanced dataset due to the entropy loss term and may struggle with extreme class imbalance. Furthermore, developing a robust text-augmentation strategy to re-introduce the "self-labeling" phase from the original SCAN algorithm remains a clear path for future research to further close the gap with supervised methods.

Summary updated

BibTeX
@inproceedings{stammbach2022docscan,
  author = {Dominik Stammbach and Elliott Ash},
  title = {{DocSCAN: Unsupervised Text Classification via Learning from Neighbors}},
  booktitle = {KONVENS},
  year = {2022},
}
Figure