v9.1.1
Menu

Chapter 1: Introduction to NLP

Week 1

Understand what Natural Language Processing is, trace its evolution from rule-based systems to modern transformers, and explore the core tasks, data representations, challenges, and real-world applications that define the field.

Topics
6
Demos
3
Videos
3
Min read
53

Chapter Overview

Natural Language Processing (NLP) is the branch of artificial intelligence concerned with giving machines the ability to read, understand, generate, and reason about human language. It sits at the intersection of computer science, linguistics, and statistics, and has become one of the most impactful areas of modern AI.

At its core, NLP transforms unstructured text---the dominant form of human knowledge---into structured representations that algorithms can manipulate. Whether we model language with hand-crafted rules, statistical counts, or billion-parameter neural networks, the fundamental goal is the same: bridge the gap between how humans communicate and how computers process information.

The field has undergone several paradigm shifts. Early systems relied on manually written grammars and dictionaries. Statistical methods introduced data-driven learning via n-grams and probabilistic models. Deep learning brought distributed representations and sequence models. Most recently, the Transformer architecture and large-scale pretraining have unified many previously separate tasks under a single framework.

This chapter covers:

  • What is NLP? Defining the field and its relationship to AI and linguistics
  • History of NLP: From rule-based parsers to neural transformers
  • Core NLP Tasks: Tokenization, POS tagging, NER, sentiment analysis, and more
  • Text as Data: Why language is uniquely challenging for machines
  • Challenges in NLP: Ambiguity, context, sarcasm, and multilingual complexity
  • Applications of NLP: Search engines, chatbots, translation, medical NLP, and beyond

Chapter Roadmap

Click any topic to jump in

Explainer videoInteractive demo
1
What is NLP

Problem formulation, language levels, and the three paradigms — framing NLP as conditional probability estimation.

The NLP Problem FormulationLevels of Language UnderstandingRule-Based vs Statistical vs Neural NLPNLP vs NLU vs NLG
Context and core tasks

How the field evolved and what problems it tackles

2
History of NLP

From symbolic rules through statistical counting to neural representation learning — each era's key insight.

The Symbolic Era (1950s--1980s)The Statistical Revolution (1990s--2010s)The Neural Era (2013--2017)The Transformer Era (2017--Present)
3
Core NLP Tasks

Tokenization, POS tagging, NER, and sentiment analysis — the building-block tasks the field is organized around.

TokenizationPart-of-Speech (POS) TaggingNamed Entity Recognition (NER)Sentiment Analysis and Text Classification
Data and difficulty

Representing text numerically and understanding why it is hard

4
Text as Data

Bag-of-words, TF-IDF, embeddings, and contextual representations — turning words into numbers machines can process.

Bag-of-Words RepresentationTF-IDF WeightingWord EmbeddingsContextual Representations
5
Challenges in NLP

Ambiguity, coreference, sarcasm, and multilinguality — why language is harder than images for machines.

Lexical and Structural AmbiguityContext and CoreferenceSarcasm, Irony, and Figurative LanguageMultilingual and Low-Resource Challenges
Where it all comes together
6
Applications

Search, translation, chatbots, and biomedical NLP — where the techniques meet real-world impact.

Search and Information RetrievalMachine TranslationConversational AI and ChatbotsHealthcare and Biomedical NLP

Topics

6 topics in this chapter

Most of what people know is written down in emails, contracts, medical notes, reviews, and chat logs, yet a computer sees all of it as a string of characters with no meaning attached. A bank that wants to route a million support emails, or a hospital that wants to find every patient whose notes mention a drug reaction, cannot hire enough people to read them. The problem is turning text, which is ambiguous, open-ended, and full of unstated context, into decisions a program can act on.

This topic opens the NLP plan and builds on the probability and machine-learning basics from the Foundations and ML plans. It starts with the problem formulation that almost every NLP task shares: estimate the most probable output yy for an input text xx. It then walks through the levels of language a system can analyze, from word structure to speaker intent, compares the rule-based, statistical, and neural paradigms, and ends by separating understanding (NLU) from generation (NLG). Later topics in this chapter build on each of these ideas.

Definition

Natural Language Processing is the field that builds computational systems to analyze, understand, and generate human language. Most NLP tasks are framed as learning a conditional distribution P(y∣x)P(y \mid x) over outputs yy, such as a label, a tag sequence, or another text, given an input text xx, and predicting the most probable yy.

In this topic

  1. 1The NLP Problem Formulation
  2. 2Levels of Language Understanding
  3. 3Rule-Based vs Statistical vs Neural NLP
  4. 4NLP vs NLU vs NLG
1 of 4
The NLP Problem Formulation

P(y∣x)=P(x∣y)⋅P(y)P(x)P(y \mid x) = \frac{P(x \mid y) \cdot P(y)}{P(x)}

Almost every NLP task can be written as one question: given input text xx, which output yy is most probable? For spam filtering yy is a label; for tagging it is a sequence of tags; for translation it is a whole sentence. Bayes' theorem gives two ways to answer it. A generative model learns how text is produced, P(x∣y)P(x \mid y), and a prior P(y)P(y), then inverts them; the evidence P(x)P(x) is the same for every yy, so it drops out of the argmax. A discriminative model learns P(y∣x)P(y \mid x) directly. Generative models such as Naive Bayes need little data but assume independence; discriminative neural models usually win when labels are plentiful.

Mathematical Intuition

Most NLP tasks reduce to estimating P(y∣x)P(y \mid x) where xx is text and yy is the desired output. Bayes' theorem decomposes this as P(y∣x)=P(x∣y)P(y)/P(x)P(y \mid x) = P(x \mid y) P(y) / P(x). A spam classifier with uniform prior needs only P(x∣spam)P(x \mid \text{spam}) vs P(x∣ham)P(x \mid \text{ham}) — whichever likelihood is larger wins. The ratio P(x∣spam)/P(x∣ham)P(x \mid \text{spam}) / P(x \mid \text{ham}) is the Bayes factor: values above 1 favor spam, below 1 favor ham.

Example:

Frame spam detection as an NLP problem. Given the email text "Win a FREE iPhone now!!!", what is xx and what is yy?

2 of 4
Levels of Language Understanding

Language is layered, and each layer asks a different question. Phonetics and phonology study sounds. Morphology studies how words are built from morphemes, the smallest meaningful units, such as 'un-' or '-ness'. Syntax studies how words combine into phrases and sentences. Semantics studies literal meaning, and pragmatics studies what a speaker intends in context, such as a request disguised as a question. A task usually needs only some layers: spell-checking is mostly morphology, while a dialogue system needs all of them. Because errors made at a lower layer feed every layer above it, a mistake in segmenting words can derail parsing and meaning further down the pipeline.

Mathematical Intuition

Analyzing language at kk levels means composing kk imperfect functions: semantics(syntax(morphology(phonology(x))))\text{semantics}(\text{syntax}(\text{morphology}(\text{phonology}(x)))). If each level has accuracy pp, the end-to-end accuracy is roughly pkp^k. With p=0.95p = 0.95 and k=4k = 4, you get 0.954≈0.810.95^4 \approx 0.81 — an 81% pipeline from 95% components. This explains why even small errors at the tokenization level propagate and compound through deeper analysis.

Example:

Analyze the sentence "Unhappiness is contagious" at the morphological and semantic levels.

3 of 4
Rule-Based vs Statistical vs Neural NLP

Three paradigms have shaped NLP. Rule-based systems encode expert knowledge as hand-written grammars, dictionaries, and patterns; they are precise and explainable, but every new phrasing needs another rule, so they break on open-ended text. Statistical systems, such as Naive Bayes or hidden Markov models, learn probabilities from counted data but depend on features that humans design, like word counts or suffixes. Neural systems learn their own features from raw text and now dominate most benchmarks, at the cost of large datasets, heavy compute, and weaker interpretability. Rules still earn their place for formats with fixed structure, such as dates or product codes, and as guardrails around learned models.

Mathematical Intuition

Rule-based systems have no trainable parameters but need a hand-written rule set whose size grows with every phrasing they must cover. Statistical models such as Naive Bayes have about ∣V∣⋅∣C∣\lvert V \rvert \cdot \lvert C \rvert parameters for a vocabulary of size ∣V∣\lvert V \rvert and ∣C∣\lvert C \rvert classes, estimated from counts. Neural models have far more: BERT-base has about 110M parameters, most of them in LL layers that each scale with d2d^2 for hidden size dd. Larger models generally need more data, which is why pretraining on unlabeled text matters: it supplies that data without labels, and fine-tuning then needs only a few thousand labeled examples.

Example:

Design a simple rule-based sentiment analyzer for product reviews using Python.

4 of 4
NLP vs NLU vs NLG

NLP is the umbrella term for any computation over language. Natural Language Understanding (NLU) maps text to a structured representation: a class label, a set of entities, an intent with slots, or a logical form. Natural Language Generation (NLG) runs the other way, producing fluent text from structured data or from other text, as in summarization or dialogue replies. Many applications chain the two, understanding the input before generating the output. The distinction matters when choosing metrics: NLU is usually scored against a single correct answer with accuracy or F1, while NLG has many acceptable outputs, so it needs overlap metrics such as BLEU or human judgment.

Mathematical Intuition

NLU maps text to a structured representation: fNLU:string→structuref_{\text{NLU}}: \text{string} \to \text{structure} (e.g., intent + entities). NLG maps structure back to text: fNLG:structure→stringf_{\text{NLG}}: \text{structure} \to \text{string}. Translation composes both: fNLG∘fNLUf_{\text{NLG}} \circ f_{\text{NLU}}. Modern seq2seq models learn this composition end-to-end, but the decomposition clarifies why translation is harder than classification — it requires both understanding and generation.

Example:

Classify each task as NLU or NLG: (1) extracting dates from emails, (2) writing a product description, (3) detecting fake news, (4) translating English to French.

Theory Exercise

Problem:

Explain why NLP is considered harder than many other AI tasks like image classification. What properties of natural language make it uniquely challenging for machines?

Coding Exercise

Problem:

Write a function that takes a sentence and returns a dictionary with basic NLP statistics: word count, unique words, average word length, and the longest word.