Document Clustering

Machine Learning
Type
Unsupervised text-mining task

What does it do?

Document clustering is an unsupervised text-mining task that groups documents with similar content together without using any labels.

It is typically used to organise an unlabelled collection or to explore which themes it contains. The task is discussed within text mining in Aggarwal and Zhai (2012), and Steinbach, Karypis and Kumar (2000) compare document clustering techniques.

The intuition behind the method

When you face a large pile of documents and no one has tagged them, you still want to know which ones belong together. Document clustering does exactly that: it measures how similar documents are by their wording and lets similar documents fall into the same group, so structure in the collection emerges on its own rather than being imposed by predefined categories.

History

Document clustering is discussed within the wider field of text mining in Aggarwal and Zhai's Mining Text Data (2012). Steinbach, Karypis and Kumar (2000) compare document clustering techniques in a paper presented at a KDD workshop on text mining.

When to use it

Choose document clustering when you hold a set of text documents with no labels and want to group them or see what structure they contain. The text must be vectorised first, and you need to be ready to set either a target number of clusters or a distance threshold, depending on the algorithm. The collection should be large enough for the groups to be meaningful. As a rough rule of thumb, around 30 documents is a working minimum, and clusters tend to become more stable above about 100 documents. Do not use it when you already have categories you want documents assigned to, since supervised text classification is designed for that. With a small corpus, manual thematic analysis is usually the safer choice, and without any text data the method does not apply.

Limitations and considerations

  • What counts as similar is set by the vector representation. If documents discuss the same theme with different words, a wording-based vectorisation may place them in different groups.
  • The number of clusters or the distance threshold must be set in advance. The clustering step does not choose it itself, so the choice needs justification. Internal validation measures can help compare candidate settings, but they also require judgement.
  • Results on small corpora are less stable. As a rough guide, clusters drawn from fewer than about 100 documents should be checked carefully before they are relied on.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • It needs no labelled data, so it can be run on raw collections that no one has annotated.
  • Because the groups are derived from the collection's own wording, they reflect the vocabulary of that corpus rather than a predefined scheme, which suits exploratory work.
  • It produces a cluster assignment for every document, so a large collection can be divided into groups for browsing without reading each document first.

Applications

  • Organising an unlabelled document archive into groups so that related items can be browsed together.
  • Exploring a corpus of reports, articles or responses to see which themes are present before deciding on categories.
  • Pre-structuring a collection ahead of manual labelling or downstream classification.
  • Sorting open-ended text into candidate groups that a researcher can then review and name.

How it works

How it works

1

Each document is first turned into a numerical representation through text vectorisation, for example a TF-IDF vector, so that wording becomes something a distance measure can compare. The choices made here, such as which terms are kept and how they are weighted, determine which documents end up looking similar. Without this step there is nothing for the clustering algorithm to operate on.

2

Before grouping, the analyst fixes how the clusters will be formed: either a target number of clusters or a distance threshold that decides when documents are close enough to share a group. This choice shapes how many groups emerge and how tight they are.

3

A clustering algorithm assigns each document to a group so that documents within a group are more similar to one another than to documents in other groups. No labels guide this step; the grouping is driven entirely by similarity in the vector space. Similarity between TF-IDF vectors is usually measured with cosine similarity, or the corresponding cosine distance, which compares the direction of two vectors and is less sensitive to differences in document length than Euclidean distance on unnormalised vectors. Two common families of algorithms are partitional methods such as k-means, which require a target number of clusters, and hierarchical agglomerative methods, which merge documents step by step and are cut at a distance threshold or chosen level to produce the groups.

4

The resulting groups are inspected and characterised. The analyst reads representative documents and frequent terms in each cluster to judge what theme it captures, and checks whether that theme is genuine or an artefact of a few common words. Stability is checked by rerunning the analysis with different random starts or nearby cluster counts or thresholds, and comparing how documents are reassigned; groups that persist across these runs are more trustworthy. No single metric settles whether a partition is valid, so this judgement remains with the analyst.

Common pitfalls

  • Running it on very few documents (under about 100 as a rough guide) tends to yield unstable clusters. In that case manual thematic analysis is often the better option.
  • Choosing the cluster count or distance threshold without reasoning about it forces an arbitrary structure onto the data.
  • Vectorisation choices such as stop-word removal, handling of rare terms, and weighting change which documents look alike. With TF-IDF, the weights are computed from the collection itself, so adding or removing documents changes the vectors and can change the clusters. Groups from different corpora should not be treated as directly comparable.
  • Labelling a cluster from its most frequent terms can attach a theme to a group that is driven by a few common words rather than by shared content. Representative documents should be read before a cluster is named.
  • Because there are no labels, there is no built-in accuracy check. The output is a partition of the collection, not a set of verified categories.

Frequently asked questions

How is document clustering different from text classification?

Classification is supervised: it assigns documents to predefined categories learned from labelled examples. Clustering is unsupervised: there are no labels and no predefined categories. The groups emerge purely from how similar the documents are to one another.

How many documents do I need?

There is no fixed minimum. As a rough rule of thumb, around 30 documents is a working lower bound, and clusters tend to become more stable above about 100. With smaller collections the clusters are less stable, and manual thematic analysis is often the safer choice.

Do I have to decide the number of clusters in advance?

Yes, in one form or another. Depending on the algorithm you choose, you set either a target number of clusters (as in k-means) or a distance threshold or cut level (as in hierarchical agglomerative methods) before the grouping step runs.

What if my documents are not yet in numerical form?

They must be vectorised first, for example into TF-IDF vectors, so that a distance measure can compare them. Vectorisation is the first stage of the pipeline; the clustering algorithm operates on those vectors, not on raw text.

Related methods

Sources

  1. Aggarwal, C. C. & Zhai, C. (2012). Mining Text Data. Springer.

    ISBN: 9781461432227
  2. Steinbach, M., Karypis, G. & Kumar, V. (2000). A Comparison of Document Clustering Techniques. KDD Workshop on Text Mining.

    Open publication reference