All work

Survey Analytics NLP Pipeline

End-to-end NLP pipeline for analyzing open-ended survey responses using clustering algorithms with Huggingface transformers, UMAP, and HDBSCAN.

2023Data Science InternPredli Consulting AB3 monthsarchived

Stack:pythonnlphdbscanumaphuggingface

The problem

Open-ended survey questions such as "What would you improve about our product?" or "Describe your experience with customer support" can produce thousands of responses. Manually assigning categories takes time, and different reviewers can tag the same response differently.

The client needed to identify the main themes automatically, without defining the categories in advance.

Approach

I built an NLP pipeline with three stages: embed, reduce, cluster.

Embed, reduce, clusterSurvey Responsesopen-ended · thousandsSentence TransformerHugging Face · dense vectorsUMAPdimension reduction · neighborhood preservedHDBSCANno k upfront · noise as a labelLLM Topic Labelshuman-readable names · counts · examples

Scroll sideways to see the full diagram. Use the arrow keys when focused.

From responses to topics

First, I used Hugging Face sentence transformers to convert each survey response into a dense embedding vector. These embeddings capture semantic meaning — responses about "long wait times" and "took forever to get help" end up close together in the embedding space even though they share no keywords.

Second, UMAP reduces the high-dimensional embeddings down to a lower-dimensional space while preserving the local neighborhood structure. This step is critical because clustering algorithms struggle in high dimensions — the curse of dimensionality makes distance metrics unreliable.

Third, HDBSCAN identifies clusters in the reduced space. Unlike k-means, HDBSCAN does not require you to specify the number of clusters upfront, and it handles noise well — not every response needs to belong to a topic. Outlier responses get labeled as noise rather than being forced into an ill-fitting cluster.

After clustering, I used the LLM to generate human-readable topic labels by looking at representative responses from each cluster. The final output is a set of topics, each with a label, a count, and example responses.

Results

The pipeline processed several thousand survey responses in minutes and identified coherent topic clusters that matched what manual analysis had found — plus a few themes the manual process had missed because they were less common but still meaningful. The client used the output to prioritize product improvements based on the actual frequency and sentiment of customer feedback.

Reflection

This was my first professional data science project. Handling typos, removing empty responses, and normalizing language improved cluster quality more than tuning UMAP or HDBSCAN parameters.

Early on I tried to force every response into a cluster, which produced overlapping topics. Leaving ambiguous responses labeled as noise gave the remaining clusters clearer boundaries.