Chapter 1: Introduction to NLP
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.
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
What is NLP
Problem formulation, language levels, and the three paradigms — framing NLP as conditional probability estimation.
How the field evolved and what problems it tackles
History of NLP
From symbolic rules through statistical counting to neural representation learning — each era's key insight.
Core NLP Tasks
Tokenization, POS tagging, NER, and sentiment analysis — the building-block tasks the field is organized around.
Representing text numerically and understanding why it is hard
Text as Data
Bag-of-words, TF-IDF, embeddings, and contextual representations — turning words into numbers machines can process.
Challenges in NLP
Ambiguity, coreference, sarcasm, and multilinguality — why language is harder than images for machines.
Applications
Search, translation, chatbots, and biomedical NLP — where the techniques meet real-world impact.
Natural Language Processing is the discipline of teaching machines to work with human language in all its richness---spoken, written, formal, informal, ambiguous, and context-dependent. It encompasses everything from simple text search to complex dialogue systems that can hold multi-turn conversations.
NLP differs from related fields in scope. Computational linguistics focuses on modeling language itself; NLP focuses on building practical systems. Information retrieval deals with finding documents; NLP deals with understanding their content. Speech processing handles audio signals; NLP handles the linguistic content after speech has been transcribed.
The mathematical foundation of NLP rests on probability theory and optimization. Given a sequence of words , most NLP tasks can be framed as estimating a conditional probability where is the desired output---a label, a translation, or the next word.
In this topic
The NLP Problem Formulation
Most NLP tasks can be framed as classification or sequence prediction problems. Given input text , we seek the most probable output . Bayes' theorem provides one framework: combine a language model with a prior . Modern neural approaches learn directly via discriminative models, bypassing the need for explicit generative modeling.
Most NLP tasks reduce to estimating where is text and is the desired output. Bayes' theorem decomposes this as . A spam classifier with uniform prior needs only vs — whichever likelihood is larger wins. The ratio is the Bayes factor: values above 1 favor spam, below 1 favor ham.
Frame spam detection as an NLP problem. Given the email text "Win a FREE iPhone now!!!", what is and what is ?
Levels of Language Understanding
Language operates at multiple levels, each with its own analysis. Phonetics/Phonology handles sounds. Morphology handles word structure (prefixes, suffixes). Syntax handles sentence structure (grammar). Semantics handles meaning. Pragmatics handles context and intent. NLP systems may target one or several of these levels depending on the task.
Analyzing language at levels means composing imperfect functions: . If each level has accuracy , the end-to-end accuracy is roughly . With and , you get — an 81% pipeline from 95% components. This explains why even small errors at the tokenization level propagate and compound through deeper analysis.
Analyze the sentence "Unhappiness is contagious" at the morphological and semantic levels.
Rule-Based vs Statistical vs Neural NLP
Three paradigms have dominated NLP over the decades. Rule-based systems use hand-written grammars and dictionaries---precise but brittle. Statistical systems learn patterns from data using models like Naive Bayes and HMMs---flexible but feature-engineering-heavy. Neural systems learn representations end-to-end from raw text---powerful but data-hungry. Modern NLP is overwhelmingly neural, but rule-based and statistical methods remain valuable for specific use cases.
Rule-based systems have zero trainable parameters but hand-written rules. Statistical models like Naive Bayes have parameters for vocabulary size and class count . Neural models like BERT have parameters for layers of dimension — BERT-base has 110M. The parameter count roughly tracks with the amount of training data needed: more parameters require exponentially more data to avoid overfitting.
Design a simple rule-based sentiment analyzer for product reviews using Python.
NLP vs NLU vs NLG
NLP is the umbrella term. Natural Language Understanding (NLU) is the comprehension side: parsing, classification, entity extraction, and semantic analysis. Natural Language Generation (NLG) is the production side: summarization, translation, dialogue response generation, and creative writing. Modern transformer models blur this distinction by excelling at both understanding and generation within a single architecture.
NLU maps text to a structured representation: (e.g., intent + entities). NLG maps structure back to text: . Translation composes both: . 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.
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.