Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 63 ยท Getting Started with NLP

What Is Natural Language Processing?

Meet natural language processing: the main tasks, how the field moved from hand-written rules to statistics to neural networks, and why human language is so hard for computers.

Natural language processing, or NLP, is the part of computing that deals with human language: the emails, reviews, chats, contracts, tweets and books that people write every day. Computers are good at numbers and strict formats, but language is messy, flexible and full of unwritten assumptions. NLP is the set of ideas and tools that let a program read, measure, organize, search and even write text.

You already use NLP all day. A spam filter decides whether a message is junk. A search box guesses what you meant after a typo. A phone keyboard suggests the next word. A support site routes your question to the right team, and a translation app turns a menu into your language. This course shows how each of those works, starting from tiny programs you can read in full and ending with transformers and large language models.

Because the examples run in your browser, you can change them and watch what happens. Every lesson uses Python; if you need a refresher, start with Python introduction and Python strings.

What NLP programs do

Classify Put a text into a category, like spam or not spam.
Extract Pull out names, dates, prices and facts.
Translate Turn text from one language into another.
Generate Write new text, answers and summaries.

Most real products combine several of these.

1 / 2

The main tasks

NLP work is usually grouped by what comes out of the program.

  • Text classification assigns a label to a whole text: spam or not spam, positive or negative review, the topic of a news story, the intent behind a chat message ("cancel my order"). This is the most common task in industry, and chapter 5 is devoted to it.
  • Information extraction finds specific pieces inside a text: people and companies (named entity recognition), dates, amounts, product codes, relationships such as "Ada works at Acme".
  • Machine translation maps a sentence in one language to a sentence with the same meaning in another.
  • Question answering reads a document, a database or the whole web and returns an answer instead of a list of pages.
  • Summarization shortens a long text while keeping the important points.
  • Text generation produces new text: a reply, a draft, a story, a piece of code. Modern chat assistants belong here.
  • Search and recommendation rank documents by how well they match a query or a reader's interests.

Many of these are special cases of two simple shapes. In the first, text goes in and a label or number comes out (classification, scoring). In the second, text goes in and more text comes out (translation, summarization, generation). Keep those shapes in mind; they explain why the same techniques keep reappearing.

A short history

The earliest NLP systems, from the 1950s to the 1980s, were built from rules. Linguists and programmers wrote grammars, dictionaries and patterns by hand: "if a sentence contains 'not' before a positive word, flip the sign". Rules are precise and easy to explain, and they still power tools such as address parsers and log scanners. Their weakness is coverage. Language has too many exceptions for any team to list them all, and every new domain needs new rules.

From the late 1980s, statistical methods took over. Instead of writing rules, researchers collected large amounts of text, counted what appeared and used probability to make predictions. A spelling corrector chooses the likeliest word. A tagger chooses the likeliest part of speech. Classic classifiers such as naive Bayes and logistic regression learn which words point to which label. Most of chapters 3 to 5 live here, and these methods are still strong baselines that train in seconds.

Around 2013 neural networks changed the field. Word embeddings turned words into vectors whose distances reflect meaning. Recurrent networks read text in order. In 2017 the transformer architecture introduced attention, which lets a model look at every word in a passage at once. Pre-trained models such as BERT and GPT learn general language skills from enormous text collections and are then adapted to a task. Today's large language models are a continuation of that line.

flowchart LR
    R["Rules<br/>hand-written patterns"] --> S["Statistics<br/>counts and probabilities"]
    S --> N["Neural networks<br/>learned representations"]
    N --> L["Large language models<br/>pre-trained at scale"]

Each era kept the previous one's ideas as tools instead of throwing them away.

You will build the old methods first on purpose. They are small enough to understand completely, and understanding them makes the newer methods far less mysterious.

Why language is hard

If language were as regular as arithmetic, NLP would be finished. It is not, for several reasons.

Ambiguity. The same words can mean different things. In "I saw her duck", is duck a verb or a noun? In "The bank was steep", is it a river bank or a financial one? "Time flies like an arrow" has at least two readings. People resolve these instantly from context; a program must be taught how.

Context. The meaning of a word depends on the words around it, on the speaker, and on what both people already know. "It's cold" can be a weather report, a complaint, or a request to close the window.

Variation. People misspell, abbreviate, shorten, use slang, mix languages and invent words. "gr8", "lol", "defo" and "ok boomer" appear in no dictionary from ten years ago.

Negation and subtlety. "Not bad" is mildly positive, "not good" is negative, and "I can't say I loved it" is polite disappointment. Sarcasm ("Great, another meeting") says the opposite of its words.

Scale and the long tail. A few words such as the and of appear constantly, while most words are rare. A model will meet words it has never seen, and rare words often carry the most meaning.

World knowledge. "The trophy didn't fit in the suitcase because it was too big." What was too big? You know it is the trophy because you know how suitcases work. Text alone does not say.

The NLP pipeline

Most NLP projects follow the same loop, even if the details change.

  1. Collect text and, for supervised tasks, labels.
  2. Clean and normalize it: fix encodings, lowercase, strip markup.
  3. Tokenize it into words or smaller pieces.
  4. Represent it as numbers: counts, weighted counts, or dense vectors.
  5. Model it with rules, a statistical classifier or a neural network.
  6. Evaluate honestly on text the model never saw, and read its mistakes.
  7. Deploy and monitor, because real language keeps changing.

The rest of this course follows that order, so each chapter adds one step.

Try it: text is just data

Before any clever method, a program sees text as a sequence of characters. This first demo shows what simple string operations do and where they stop being enough.

Python Splitting a sentence

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Splitting on whitespace is a first approximation of tokenization. Notice that good. keeps its period, so a program looking for the word good would miss it. Tokenization fixes this properly.

Now a first, deliberately naive NLP system: a lexicon-based sentiment scorer. It counts how many words come from a positive list and subtracts words from a negative list.

Python A tiny rule-based sentiment scorer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first two reviews are scored correctly. The last two are wrong: "not good" gets +1 because the program sees good and ignores not, and "Not bad at all" gets -1. You could add a rule for negation, then a rule for "not only ... but also", then one for sarcasm. This is exactly the endless rule-writing that pushed the field toward learning from data. Sentiment analysis returns to this example with both a better rule-based approach and a trained model.

One more demo, showing the pipeline idea on a single sentence:

Python Three pipeline steps, one at a time

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Each step takes the output of the one before it, which makes pipelines easy to test and reuse. You will build a configurable one in Building a Reusable Preprocessing Pipeline.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which task assigns one label to a whole text, such as spam or not spam?

    Classification maps a whole text to a category. Entity recognition finds pieces inside a text, translation and generation produce new text.
  2. 2. What was the main weakness of purely rule-based NLP systems?

    Rules are precise and explainable, but no team can list every exception, and each new domain needs new rules.
  3. 3. In 'I saw her duck', the word 'duck' can be a verb or a noun. What is this problem called?

    Ambiguity means the same surface text has several possible meanings that context has to resolve.
  4. 4. In the sentiment scorer, why does 'The movie was not good.' get a positive score?

    A bag of lexicon words has no notion of word order or negation, so 'not good' still scores one positive word.

Summary

  • NLP lets programs read, organize and generate human language; its tasks are mostly "text in, label or number out" or "text in, text out".
  • The field moved from hand-written rules to statistical models learned from counts, and then to neural networks and pre-trained transformers; older ideas remain useful baselines.
  • Language is hard because of ambiguity, context, variation, negation, rare words and the world knowledge people take for granted.
  • Most projects follow one pipeline: collect, clean, tokenize, represent, model, evaluate, deploy.
  • Simple string code is a good first step but fails on punctuation and negation, which motivates the rest of the course.

Next: Levels of Language: Characters to Meaning