Natural Language Processing (NLP) bridges human linguistics and computational machine learning. Because computers cannot perform mathematical matrix operations on raw strings of text, NLP transforms unstructured prose into structured numerical vectors through Text Preprocessing and Vectorization.
Figure 35.1: The Text Vectorization Pipeline — From Raw Text to Dense Semantic Vector Spaces.
The Bag-of-Words (BoW) model simply counts word occurrences, but common words dominate the counts. TF-IDF solves this by scoring words based on how informative they are across an entire corpus:
TF-IDF(t, d, D) = TF(t, d) · IDF(t, D)
Count(t in d) / Total_words(d). Measures how often word t appears in document d.log( Total_docs(D) / (1 + Count_docs_containing(t)) ). Punishes words that appear in every document (like "the"), while heavily weighting words that only appear in specific topics (like "quantum" or "leukemia").TF-IDF vectors are high-dimensional (20,000+ columns) and sparse (99% zeros). Furthermore, they completely ignore word meanings: to TF-IDF, "king" and "queen" have zero similarity! Dense Embeddings (Word2Vec, GloVe) map words into continuous low-dimensional geometric vector spaces (typically 100 to 300 dimensions) where semantic relationships are captured by spatial proximity: Vector("King") - Vector("Man") + Vector("Woman") ≈ Vector("Queen")!
Broaden your foundational and advanced Machine Learning knowledge across our curriculum:
Advance from TF-IDF and static embeddings to contextual tokens.
Store sentence embeddings in vector databases for semantic search.
Classify documents using bag-of-words and n-gram vectors.
Build an end-to-end text classifier with Scikit-Learn.