Mining Text Data
1. Introduction
Text data is ubiquitous in modern applications:
- Digital libraries: digitized books and academic papers.
- Web and Web-enabled applications: hypertext (with rich side information via hyperlinks), social networks, microblogs (e.g., Weibo, WeChat).
- Newswire services: Sina, NetEase, Reuters.
Modeling choices
A document can be modeled in two fundamentally different ways:
| Model | Description | Pros | Cons |
|---|---|---|---|
| Sequence (string) | Treat text as an ordered string of tokens | Preserves word order; enables sequence mining | Vast token space; huge string length; rarely used |
| Bag-of-words (frequency-annotated) | Multidimensional record of word frequencies | Compact; supports standard vector methods | Loses ordering information; the popular choice |
Terminology
- Document = a single data point.
- Corpus = the collection (data set) of documents.
- Word / term = a feature (attribute).
- Lexicon = the set of all features (the vocabulary).
Vector-space representation
A preprocessing pipeline converts raw text into a feature vector:
- Remove common (non-discriminative) words.
- Consolidate variations of the same word (e.g., via stemming).
- Attach normalized frequencies to individual words.
Three special characteristics of text
- Sparsity — a document uses only a few hundred words, so most attributes are zero. This affects distance computation (most terms never co-occur).
- Nonnegativity — frequencies are
; the presence of a word is statistically more significant than its absence. - Side information — hyperlinks, metadata, social-network friendships, and anchor text provide additional signal beyond the raw text.
2. Document Preparation (Feature Extraction)
2.1 Stop-word removal
Drop words that are not discriminative for mining: articles, prepositions, conjunctions (e.g., "the", "of", "and").
2.2 Stemming
Consolidate morphological variants of the same root:
- singular / plural ("connect" ↔ "connects")
- tenses ("connect", "connected", "connecting")
2.3 Punctuation removal
Eliminate commas, semicolons, digits, hyphens, and other non-alphabetic tokens.
2.4 TF-IDF weighting
Two components combine into the final weight
Term Frequency (TF) — raw count
Inverse Document Frequency (IDF) — measures how rare/discriminative a term is:
where
TF-IDF combines them:
The document vector is typically normalized so that
| Scheme | Formula | Best for |
|---|---|---|
| Raw count | Rarely used alone | |
| Log-damped TF-IDF | General-purpose | |
| Boolean presence | Very short docs |
2.5 Similarity measures
- Cosine similarity (the workhorse for sparse TF-IDF vectors):
- Jaccard coefficient (for binary/sparse sets, e.g., market baskets):
Cosine is preferred for weighted vectors; Jaccard for unweighted sets.
2.6 Web-specific preprocessing
- Leverage structure: the title is more important than the body; add anchor text (a summary description that points to a target page) into that target document's representation.
- Remove noise: strip tags, ads, disclaimers, notices. Identify the main content block via:
- Block labeling as classification — extract visual features, label manually, train a classifier.
- Tree matching — extract tag trees, determine the page template.
3. Specialized Clustering Methods
3.1 Representative-based algorithms (k-means variants)
- Similarity function: use cosine similarity instead of Euclidean distance.
- Centroid computation: project out low-frequency words; maintain a cluster digest — the top 200–400 topical words of the cluster. This gives significant effectiveness gains.
- k-means step: assign each document to the nearest of
centroids; recompute each centroid as the concatenation of its member documents, then prune its low-frequency words.
3.2 Scatter/Gather seeding
k-means is efficient but sensitive to seed choice; hierarchical methods are robust but scale poorly. A two-phase approach:
- Use buckshot or fractionation (hierarchical) to create robust initial seeds.
- Run k-means on those seeds.
Buckshot: select a seed superset of size
Fractionation:
- Break the corpus into
buckets, each of size documents. - Apply agglomerative clustering to each bucket, reducing it by factor
(now docs per bucket). - Across all buckets obtain
agglomerated documents. - Repeat until exactly
agglomerated documents remain.
Fractionation refinement: sort documents by the index of the
3.3 Enhancements
- Split: identify incoherent clusters (low self-similarity = average similarity of docs to centroid/each other); re-run buckshot with
and re-cluster. - Join: merge similar clusters — compute each cluster's topical words; merge those with significant topical-word overlap.
3.4 Probabilistic text clustering (unsupervised Naïve Bayes)
Model assumptions:
- Each document is generated from a single topic (hard clustering).
- Each topic = a distribution over words.
- Words in a document are generated independently given the topic (Naïve Bayes assumption).
Algorithm steps:
- Randomly assign documents to
clusters. - Train NB models (Bernoulli or Multinomial): estimate prior
from cluster proportions; estimate . - Reassign each document to the cluster maximizing posterior
. - Repeat until convergence (EM).
E-step — compute likelihood under cluster
- Bernoulli:
- Multinomial (
= frequency of in ):
M-step — re-estimate parameters:
- Bernoulli:
- Multinomial:
Zero-probability problem (Laplace correction):
- Bernoulli:
- Multinomial:
3.5 Co-clustering (simultaneous document & word clusters)
Reorder the document-term matrix so nonzeros block-diagonalize. Cluster
Modeled as a bipartite graph:
- Node set
(documents) and node set (words). - Edge
↔ nonzero entry; weight = term frequency.
A
4. Topic Modeling
4.1 PLSA (Probabilistic Latent Semantic Analysis)
A probabilistic variant of LSA (SVD). Each document is a mixture of latent topics; each topic is a distribution over terms. Documents and words are conditionally independent given the topic. PLSA is soft clustering (a doc/term can belong to multiple topics with probabilities) and is inherently for dimensionality reduction.
Generative view: pick latent component
EM algorithm:
- Initialize
, , to , , . - E-step: estimate posterior
- M-step: re-estimate
, , .
Dimensionality reduction: Let scaled document-term matrix
Benefits:
- Synonymy — "cat" and "kitten" get positive loadings on the same aspect ("cats").
- Polysemy — a word with multiple meanings gets positive components in different aspects; other words in the doc reinforce one.
PLSA vs EM-clustering: In EM-clustering a doc comes from one hidden component; in PLSA different parts of a doc come from different aspects (mixture at the generative level).
Clustering with PLSA: (1) compute
Limitations: overfitting (too many parameters); poor out-of-sample extension (cannot score unseen docs).
4.2 LDA (Latent Dirichlet Allocation)
Adds Dirichlet priors on the topic distributions, which regularizes parameters and generalizes to new documents — the standard fix for PLSA's weaknesses.
| Model | Clustering | Out-of-sample | Handles synonymy/polysemy |
|---|---|---|---|
| LSA (SVD) | via post-hoc clustering | Yes (projection) | Yes |
| PLSA | Soft, generative | No | Yes |
| LDA | Soft, generative + prior | Yes | Yes |
5. Specialized Classification Methods
5.1 Instance-based (k-NN)
Find the top-
Modifications for sparsity / high dimensionality:
- Leverage LSA/PLSA: removing small-eigenvalue dimensions reduces synonymy/polysemy noise in cosine.
- Centroid-based classification: cluster each class proportionally to its size; keep cluster digests; run k-NN against the smaller set of centroids.
- Advantages: efficient (few centroids); robust (centroids reduce noise); handles imbalance; improves generalization; interpretable digests.
5.2 Rocchio classification
Aggregate all docs of a class into a single centroid; report the closest centroid's label. Extremely fast, but relies on the class-contiguity assumption (same-class docs form one contiguous region). Fails when a class is multi-modal (separated into distinct clusters).
5.3 Bayes classifiers
Predict
Bernoulli model — each term is 0/1; does not use frequencies.
Explicitly penalizes non-occurrence; best for short documents (where absence is informative).
Multinomial model — terms sampled from a multinomial over the document of length
Ignores non-occurrence (
| Model | Term value | Uses frequency? | Best for |
|---|---|---|---|
| Bernoulli | 0 / 1 | No | Short docs, absence informative |
| Multinomial | raw count | Yes | Long docs |
5.4 SVM classifiers
Linear classifiers work well for high-dimensional sparse text. The SVMPerf formulation uses a single slack variable
It never enumerates all (exponentially many) constraints explicitly — it maintains a small constant-size working set, so time complexity depends on
5.5 Decision boundary summary
| Method | Type | Key assumption | Strength | Weakness |
|---|---|---|---|---|
| k-NN | Lazy/instance | Local similarity | Simple, no training | Slow at query, sensitive to noise |
| Centroid (Rocchio) | Prototype | Class contiguity | Very fast | Fails multi-modal classes |
| Naïve Bayes | Generative | Feature independence | Fast, robust | Independence unrealistic |
| Linear SVM | Discriminative | Linear separability | Strong on sparse text | Needs tuning |
6. Novelty and First-Story Detection
In news streams, detect the first story on a new topic as soon as possible.
Simple approach: for the current document compute its maximum similarity to all previous docs; very low max similarity ⇒ novelty. Problems: (1) high computational cost; (2) unstable pairwise similarity (synonymy/polysemy).
Reservoir sampling: maintain a fixed-size uniform sample of a stream of unknown/large size.
- Initialize reservoir with first
items. - For item
, generate random ; if , replace reservoir[ ]. - Every item has equal inclusion probability
.
Micro-clustering method (simultaneously finds clusters and novelties):
- Maintain
cluster centroids (keep only the top ~200–400 frequent words, updated additively). - For an incoming document, compute similarity to all centroids:
- if
threshold → add to cluster, update centroid frequencies; - else → report as novelty, create a new cluster, and delete the stalest cluster (by last-update time).
- if
7. Summary
Text mining represents documents as sparse, non-negative bag-of-words vectors. Preprocessing removes stop words/stems/punctuation; TF-IDF plus cosine/Jaccard measure similarity (web docs add anchor text and block labeling). Clustering adapts k-means (cosine + cluster digest, buckshot/fractionation seeds), probabilistic NB/EM, and co-clustering (bipartite graph cuts). Topic modeling uses PLSA (and LDA for generalization). Classification uses cosine k-NN (with LSA/centroid speedups), Rocchio, Naïve Bayes (Bernoulli/Multinomial), and linear SVM. Novelty detection uses reservoir sampling and micro-clustering to find first stories in streams.