Data Science

Wikipedia Biographical Clustering

An unsupervised machine learning pipeline designed to cluster Wikipedia biographical articles. Performs text cleaning, feature extraction via TF-IDF and Word2Vec, model training (K-Means, GMM, Hierarchical), visualization, and serves predictions via FastAPI and Streamlit.

PythonScikit-LearnGensimFastAPIStreamlitJoblib

Problem Statement

Unstructured text corpora (such as Wikipedia biographical entries) are challenging to organize and categorize without human labels. Building a robust, unsupervised text clustering system requires a multi-stage approach to clean text, represent documents numerically using both statistical (TF-IDF) and semantic (Word2Vec) features, and group them using stable clustering algorithms.

Solution

Developed an end-to-end Python pipeline that handles the entire clustering lifecycle. Implemented modular text preprocessing (tokenization, lemmatization, and stop-word removal), dual feature extraction (TF-IDF representations and mean Word2Vec word vector pooling), and three distinct clustering algorithms (K-Means, Gaussian Mixture Models, and Hierarchical Clustering). Wrapped the resulting models in a FastAPI prediction backend and an interactive Streamlit visualization dashboard.

Architecture

The pipeline downloads data, preprocesses biographical text, runs TF-IDF and Word2Vec models, and saves the trained models to disk. These are served via Streamlit (for training log analysis and visual grids) and FastAPI (for API-based inference).

Key Features

  • Modular preprocessing pipeline for clean tokenization and stop-word filtering
  • Dual vectorization strategies: TF-IDF sparse features and Word2Vec dense document vectors
  • Multi-algorithm clustering covering K-Means, GMM (Soft-Clustering), and Hierarchical linkages
  • Streamlit multi-tab web application (Training, Visualization, and Inference Playground)
  • FastAPI REST backend serving real-time biographical cluster predictions
  • Automated artifact storage exporting model weights and plotting results

Challenges

  • Capturing semantic similarity beyond simple word matching. Solved by training Word2Vec models and pooling word vectors to represent biographical documents in a continuous semantic space.
  • Rendering high-dimensional clusters for analysis. Solved by implementing visualization modules that project and plot model groupings into lower-dimensional spaces.
  • Creating a unified dashboard that couples model training with live testing. Solved by writing a custom Streamlit subprocess monitor that tracks pipeline logs and serves saved joblib model files dynamically.

Results & Metrics

Established a fully automated pipeline executing from raw text to cluster assignments

Created an interactive dashboard enabling real-time biographical cluster prediction

Successfully exported and visualized cluster grouping patterns using Seaborn and Matplotlib

Lessons Learned

  • 💡Combining statistical clustering (TF-IDF + K-Means) with semantic clustering (Word2Vec + GMM) provides complementary perspectives on grouping text datasets.
  • 💡Soft-clustering using Gaussian Mixture Models (GMM) is highly effective for biographies that cross multiple professions, as it assigns probability weights rather than hard labels.
  • 💡A unified script interface simplifies model retraining when feeding updated datasets into the pipeline.

Case Study Overview

Case Study: Wikipedia Biographical Clustering

This project implements an unsupervised document clustering pipeline for the "People Wikipedia" dataset. The goal is to group unstructured biographical descriptions into distinct thematic clusters based on their lexical and semantic features.


Technical Pipeline & System Flow

The workflow is completely modular, separating preprocessing, embedding extraction, and cluster modeling into dedicated pipeline stages:

Wikipedia People Clustering Pipeline & Multi-Vector Architecture
        ┌──────────────────────────────────────────────────────────┐
        │               Raw Wikipedia Biography Text               │
        └────────────────────────────┬─────────────────────────────┘
                                     │
                                     ▼
        ┌──────────────────────────────────────────────────────────┐
        │    Modular Preprocessing (Tokenization & Stop Words)     │
        └────────────────────────────┬─────────────────────────────┘
                                     │
                  ┌──────────────────┴──────────────────┐
                  ▼                                     ▼
        ┌────────────────────┐                ┌────────────────────┐
        │   TF-IDF Sparse    │                │  Word2Vec Dense    │
        │   Vectorization    │                │  Document Pooling  │
        └─────────┬──────────┘                └─────────┬──────────┘
                  │                                     │
          ┌───────┴───────┐                     ┌───────┴───────┐
          ▼               ▼                     ▼               ▼
    ┌───────────┐   ┌───────────┐         ┌───────────┐   ┌───────────┐
    │  K-Means  │   │    GMM    │         │  K-Means  │   │    GMM    │
    │   Clust.  │   │   Clust.  │         │   Clust.  │   │   Clust.  │
    └─────┬─────┘   └─────┬─────┘         └─────┬─────┘   └─────┬─────┘
          │               │                     │               │
          └───────┬───────┴──────────┬──────────┴───────┬───────┘
                  │                  │                  │
                  ▼                  ▼                  ▼
        ┌──────────────────┐   ┌───────────┐   ┌───────────────────┐
        │  Model Weights   │   │ Plotting  │   │ Hierarchical Link │
        │  (.pkl Exports)  │   │ & Visuals │   │   (Dendrograms)   │
        └─────────┬────────┘   └─────┬─────┘   └─────────┬─────────┘
                  │                  │                   │
                  └──────────────────┼───────────────────┘
                                     │
                                     ▼
                  ┌──────────────────┴──────────────────┐
                  ▼                                     ▼
        ┌──────────────────────────────┐       ┌──────────────────┐
        │    FastAPI Server REST API   │       │  Streamlit App   │
        │      (Prediction Ports)      │       │ (Inference / UI) │
        └──────────────────────────────┘       └──────────────────┘

Core Ingestion & Retrieval Methodology

1. Data Preprocessing

  • Tokenization & Cleaning: Cleans biographical texts by stripping special characters, converting characters to lowercase, and lemmatizing tokens.
  • Stop-word Removal: Dynamically filters out standard English stop words and collection-specific words that could skew clustering results.

2. Dual Vectorization Strategies

  • Sparse TF-IDF Representation: Extracts bag-of-words features weighted by inverse document frequency to capture rare, highly distinguishing biographical terms.
  • Dense Word2Vec Document Embedding: Projects terms into a semantic space using gensim and aggregates word vectors to create document-level embedding profiles.

3. Multi-Algorithm Clustering

  • K-Means Clustering: Groups biographical representations based on Euclidean distance boundaries.
  • Gaussian Mixture Models (GMM): Evaluates soft clustering by calculating probability distributions across multiple overlapping mixtures.
  • Hierarchical Clustering: Constructs cluster trees to identify relationships and groupings across articles.

4. Interactive Services

  • FastAPI Engine: Loads serialized model instances via joblib to expose scalable predict endpoints.
  • Streamlit UI Dashboard: Renders pipeline training logs, dynamically displays model cluster plots, and offers an input playground to classify custom biographical text blocks.

Technologies

PythonScikit-LearnGensimFastAPIStreamlitJoblib

Related Projects

Data Science

Bitcoin Forecasting Dashboard

An interactive time-series forecasting dashboard for daily BTC/USD prices using Prophet, SARIMA, and Random Forest.

Data Science

DeepFM CTR Prediction Pipeline

A PyTorch reproduction of the DeepFM architecture for Click-Through Rate prediction on the 45M-sample Criteo dataset, featuring memory-efficient pipelines and 6 architecture ablation studies.