Machine Learning for Beginners

Module 9 of 12

Module 9: Natural Language Processing — Machines and Human Language

5 min read864 words
What you'll learn
Explain what natural language processing (NLP) isUnderstand why human language is so hard for computersDescribe how text gets turned into numbers a model can useExplain sentiment analysis with a real exampleSee how simple rules created the first chatbots

"Teaching a computer to add is easy. Teaching it to understand a joke, a hint, or a heartfelt review — that's the beautiful challenge of NLP."

Learning Objectives

By the end of this module, you will be able to:

  • Explain what natural language processing (NLP) is
  • Understand why human language is so hard for computers
  • Describe how text gets turned into numbers a model can use
  • Explain sentiment analysis with a real example
  • See how simple rules created the first chatbots

1. Teaching Computers to Read

Natural Language Processing (NLP) is the branch of machine learning that helps computers work with human language — reading it, understanding it, translating it, even writing it.

You use it every day, probably without noticing:

  • Dictating a text instead of typing it
  • Asking a voice assistant a question
  • Autocomplete finishing your sentence
  • Spam filters reading your email
  • Translation apps turning a menu into your language
An illustration of the challenge of true language comprehension by machines
An illustration of the challenge of true language comprehension by machines

Concept: NLP sits at the crossroads of language and computation. The easy part is handling the words. The hard part — the part researchers have chased for decades — is capturing the meaning behind them.

2. Why Language Is So Hard

Numbers are precise. Language is gloriously messy. Consider:

  • Ambiguity: "I saw her duck" — did she own a duck, or dodge?
  • Sarcasm: "Oh, great." Is that delight or despair?
  • Context: "It's cold" might be a fact, a complaint, or a hint to close the window.

Humans handle this effortlessly using context, tone, and shared experience. Computers have none of that by default — which is why early promises of machines that "just understand us" turned out to be far harder than anyone expected.

Did You Know? Computers are actually excellent at the mechanical side of grammar — labeling nouns, verbs, and sentence structure by formal rules (this is called parsing). What trips them up is meaning. A machine can perfectly diagram a sentence it doesn't understand at all — like reciting a poem in a language you can't speak.

3. From Words to Numbers

Here's the core trick of NLP. Models only understand numbers, so the first job is always to turn text into numbers.

  • Tokenization: chop text into pieces (usually words). "I love pizza" → ["I", "love", "pizza"].
  • Bag of words: count how often each word appears — a simple numeric fingerprint of a text.
  • Embeddings: the clever modern approach — represent each word as a list of numbers that captures its meaning, so that "king" and "queen" land near each other, and far from "pizza."

Concept: Embeddings are the big idea that powers modern language AI. By turning words into coordinates in a "meaning space," math can suddenly do things like king − man + woman ≈ queen. Meaning becomes measurable.

4. Sentiment Analysis: Reading the Mood

One of the most useful NLP tasks is sentiment analysis — deciding whether a piece of text is positive or negative. The source curriculum uses a wonderful real dataset: hotel reviews. Was this guest delighted or furious?

The idea: feed the model thousands of reviews already labeled positive or negative (that's classification, from Module 7, applied to text!). It learns which words and patterns signal each mood, then judges new reviews on its own.

python
review = ,[object Object],
prediction = model.predict([to_numbers(review)])   ,[object Object],

Businesses use exactly this to scan thousands of reviews, tweets, or support tickets in seconds — impossible to do by hand.

Pro Tip: Sentiment isn't only about spotting words like "great" or "terrible." Context flips meaning: "not bad at all" is positive despite the word "bad." Good sentiment models learn these patterns from lots of examples — another reminder that in ML, data quality beats clever rules.

5. The First Chatbots

Long before today's assistants, a 1960s program called Eliza could hold a surprisingly convincing conversation by playing a therapist. Its secret was almost embarrassingly simple: pattern matching. Say "I feel sad," and it would flip your words into "Why do you feel sad?"

No understanding at all — just clever rules. Yet people happily confided in it. It's a humbling lesson: a system can seem intelligent while understanding nothing, which is exactly why measuring real comprehension is so tricky.

Try This! Be Eliza for a moment. Write a rule that turns any sentence starting with "I am ___" into the question "How long have you been ___?" Try it on "I am tired." Feel how a dead-simple rule can mimic conversation — and why that's not the same as understanding.

Key Takeaway: NLP helps computers work with human language. The mechanics (parsing, grammar) are easy for machines; meaning is the hard part, thanks to ambiguity and sarcasm. Everything starts by turning text into numbers — via tokenization, bag-of-words, or meaning-rich embeddings — which lets us do tasks like sentiment analysis. And early bots like Eliza remind us that seeming smart and being smart aren't the same.

This module is adapted from Microsoft's open-source ML-For-Beginners curriculum (MIT License). NLP lessons by Stephen Howell.