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

  1. What Is Machine Learning?
  2. Data — Features, Labels & Splitting
  3. Linear Regression — Fitting a Line
  4. How Models Learn — Gradient Descent
  5. Classification — Predicting Categories
  6. Decision Trees
  7. Evaluating a Model Honestly
  8. Overfitting & the Bias-Variance Tradeoff
  9. The ML Workflow
  10. Mini-Project — A Spam Classifier
  11. Clustering — Finding Groups Without Labels
  12. Your First Real scikit-learn Model
  13. Words as Numbers — A Taste of NLP