Machine learning / Text representation
NLP & Document Clustering
Compare representations. Measure what survives.
A reproducible comparison of lexical and learned text features: headline classification across 42 categories, held-out topic clustering, and a linked investigation of rare-word probability estimation.
Which representation supports prediction?

01 / The question
Which text representations preserve the signal needed for classification and clustering?
Useful text systems need more than plausible semantic neighbours. This study tests whether representations support category prediction and whether unsupervised groups recover known topics. The experiments separate feature learning, model selection, and held-out evaluation.
My contributionBuilt the text-cleaning and evaluation workflow, trained lexical and embedding baselines, evaluated held-out document clusters, and produced reproducible result exports.
02 / System walkthrough
From input to evidence.
The main stages of the implemented analytical workflow.
- 01
Clean and partition
Remove empty headlines, normalized duplicates, and conflicting-label groups. Run three stratified 80/20 splits with identical partitions for each classifier.
- 02
Fit training-only representations
Compare unigram/bigram TF-IDF with 200-dimensional CBOW Word2Vec averages. Fit embedding scaling on training rows and use the same Logistic Regression regularization.
- 03
Evaluate every category
Compare against the majority-class baseline; retain macro-F1, accuracy, precision, recall, support, and full confusion counts for all 42 categories.
- 04
Test document clusters
Strip headers, footers, and quotations from 20 Newsgroups. Fit TF-IDF and normalized 100-component LSA on the earlier partition, then evaluate K-means on the later partition.
03 / Engineering decisions
Why the implementation matters.
Make leakage checks part of preparation
Deduplicating normalized headlines before splitting prevents identical text from appearing on both sides. Document clustering also removes exact normalized train/test overlap.
Separate model selection from evaluation
For each clustering representation, choose k using mean training silhouette across three seeds. Report held-out ARI and NMI for every candidate; known topics do not train the clusters.
Keep sparse text sparse
TF-IDF stays sparse. Truncated SVD provides a bounded 100-dimensional semantic representation; no dense document-by-vocabulary conversion is required.
Show all categories
Aggregate scores are paired with a 42-category performance chart and full CSV exports, so frequent categories do not hide weaker parts of the task.
04 / Results & interpretation
What the experiment showed.
Headline scores are means across three overlapping stratified splits. Cluster scores use the official later 20 Newsgroups partition. All transformations are fitted on training text.
Headline classification / three splits
0.410 macro-F1TF-IDF + LR averages 57.2% accuracy. Averaged Word2Vec + LR records 0.257 macro-F1 under the declared settings.
Topic clustering / held-out partition
0.185 mean ARINormalized LSA-100 at training-selected k=20 produces mean NMI 0.372. Topic recovery remains partial; cluster separation and semantic agreement are different questions.
Reproducible evidence
9 + 18 runsNine classifier runs and eighteen clustering configurations, with source checksums, fixed settings, full metric tables, and prediction reconciliation.
Look beyond the headline score

Measure topic recovery on unseen documents

Further investigation / Statistical NLP
How much probability belongs to words not yet observed?
Text classification asks which words distinguish a category. Probability estimation asks a complementary question: how should a model account for words absent from a small sample? I implemented and evaluated MLE, Simple Good–Turing, and absolute discounting to examine that trade-off.
At 1k tokens / 50k vocabulary
0.179 vs 0.285 JSAbsolute discounting reduced mean Jensen–Shannon divergence relative to MLE; Simple Good–Turing achieved 0.182. Lower is better.
Unseen probability mass / same setting
1.88 vs 45.63 ppMean absolute error, in percentage points, for Simple Good–Turing versus MLE. Reserving probability for unseen words makes a substantial difference at small sample sizes.
At 1M tokens
Vocabulary mattersSimple Good–Turing led mean JS for the 50k vocabulary; MLE was slightly lower for the full vocabulary. More data changes the ranking rather than creating one universal winner.
120 estimator runs: four exact sample sizes from 1k to 1M tokens, five seeded draws, and two training-derived vocabulary settings. A disjoint 3.40-million-token Text8 reference evaluates the estimates. Charts show means and sample standard deviations across draws.
Sample size changes the value of smoothing

Look beyond overall divergence

05 / Scope & limitations
Scope & limitations.
- GeneralizationHeadline results use repeated random splits from one publisher corpus. The splits overlap and do not establish future-period or cross-publisher performance. Historical category conventions and related labels remain part of the task.
- Representation scopeWord2Vec is a fixed CBOW average with no pretrained contextual model. Equal regularization and training data do not make the two feature families equally expressive or independently optimized.
- Cluster interpretationHeaders, signatures, and quotations are removed with heuristics. Exact normalized overlaps are removed; paraphrases and thread-level similarities can remain. Silhouette uses a fixed sample and different representation geometries, so its absolute values should not rank feature families.
- Runtime and reproducibilityThese are single-machine Python experiments. No distributed speedup or production-serving claim is made. Fixed seeds and one Word2Vec worker improve repeatability; numerical libraries and versions can still change exact results.
- Probability-estimation experimentOne ordered Text8 split and five draws measure sampling variability, not cross-domain generalization. Vocabulary is fixed from the training pool; unseen mass is allocated uniformly. This is a unigram study, not an evaluated contextual language model. MLE KL is infinite where reference events have zero estimated probability; the outputs preserve that fact.
06 / Next iteration
Where I would take it next.
The next technical priorities for this project.
Evaluate temporal transfer
Reserve a future news period or a second publisher and keep all tuning inside the training period.
Test modern semantic encoders
Compare sentence representations and supervised tuning under the same deduplication and hold-out rules.
Inspect useful cluster labels
Add human assessment of cluster themes and document retrieval quality before proposing operational categories.
07 / Code & reproducibility
Explore the implementation.
Explore the implementation, selected results, and technical documentation on GitHub.
- Nine freshly executed classifier runs, full per-class reports, and confusion counts.
- Eighteen clustering runs with held-out ARI/NMI, sampled silhouette, and cluster/topic tables.
- Input and code hashes, pinned versions, eight preparation/resume tests, and reconciled predictions.
- The separate rare-word probability study retains its verified 120 estimator runs.
Figures are generated from the executed result tables. Seed ranges describe observed variation, not confidence intervals.