Ch 13 · Words as Numbers — A Taste of NLP · Machine Learning & AI
Topic 13 of 13 in Machine Learning & AI — Foundations — 3 lessons.
Turning Sentences into Vectors
Models only eat numbers, so before you can classify text you must vectorise it. The simplest way is a bag of words: build a vocabulary of every word seen, then count how often each appears in a sentence. CountVectorizer does exactly that.
A Tiny Sentiment Classifier
Stack the vectoriser with MultinomialNB (the same Naive Bayes from the spam card) and you have a working sentiment model. Six labelled sentences are enough to learn the gist, then we predict on brand-new ones.
Now You Try!
Try writing your own code below — the AI tutor is here if you get stuck. Take any block from these last three chapters and bend it:
All topics in Machine Learning & AI Beginner
- What Is Machine Learning?
- Data — Features, Labels & Splitting
- Linear Regression — Fitting a Line
- How Models Learn — Gradient Descent
- Classification — Predicting Categories
- Decision Trees
- Evaluating a Model Honestly
- Overfitting & the Bias-Variance Tradeoff
- The ML Workflow
- Mini-Project — A Spam Classifier
- Clustering — Finding Groups Without Labels
- Your First Real scikit-learn Model
- Words as Numbers — A Taste of NLP