Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Stages of NLP

Concise study notes describing the common pipeline (stages) of Natural Language Processing, why each stage is needed, exact definitions, diagram instructions, key formulas, worked theory examples, common student mistakes, exam question types, and a short self-test.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Natural Language Processing (NLP) is the set of methods that let computers read, understand and generate human language. An engineer uses the stages of NLP as a practical pipeline to turn raw text or speech into structured outputs (like answers, translations, labelled entities, or summaries) and to decide where to apply models (for example, whether to clean text first, or to do syntactic parsing before semantic analysis).

Key ideas

Start with the basic assumption: real-world input (speech or text) is noisy and ambiguous; we therefore decompose processing into stages where each stage reduces ambiguity or adds structure useful for later stages.

Definitions (each term defined before use):

  • Natural Language Processing (NLP): the computational study of human language that aims to map between text/speech and structured representations (labels, trees, semantic forms, generated text). Assumes language is symbolic and statistical information about language can be learned from data.
  • Stage: a distinct processing step in a pipeline with defined input and output types (for example: tokens from a tokenizer). We assume each stage's output is useful for subsequent stages.
  • Text normalisation: converting raw text into a canonical form (for example, lowercasing, removing or normalising punctuation, Unicode normalization). Assumes target application prefers canonical case and punctuation forms.
  • Sentence segmentation: detecting sentence boundaries in running text (e.g., separating abbreviations like 'U.S.' from true sentence ends). Output: sentence spans; this typically precedes tokenisation and affects downstream tagging and parsing.
  • Tokenisation: splitting a sequence of characters into a sequence of smaller units called tokens (words, punctuation, subwords). Tokenisation must be defined per language (white-space vs morphological). Example tokens: "don't" → ["do", "n't"] if we choose to split contractions. Modern systems often use subword tokenisation (e.g., Byte-Pair Encoding, WordPiece) to handle rare words and morphology; for languages without whitespace (e.g., Chinese, Japanese), tokenisation entails word segmentation.
  • Morphological analysis: decomposition of tokens into morphemes (smallest meaning-bearing units) and derivation of lemmas (dictionary forms) and stems (root forms). Assumes morphologically complex languages need explicit analysis to reduce sparsity.
  • Part-of-speech (POS) tagging: assigning a POS tag (like NOUN, VERB) to each token. Formally: given token sequence t1..tn, produce tag sequence p1..pn maximizing some scoring function. Assumes tags are drawn from a fixed tagset.
  • Named Entity Recognition (NER): locating spans in text that correspond to entities (PERSON, ORGANISATION, LOCATION, etc.) and labelling their type.
  • Syntactic parsing: building a parse tree that shows hierarchical phrase structure (constituency parsing) or dependency relations (dependency parsing) for a sentence. Assumes sentences are well-formed and grammar rules capture structure.
  • Semantic analysis: mapping syntactic structure and tokens to semantic representations (logical forms, predicate-argument structures, frame semantic roles). Goal: represent meaning independent of surface form.
  • Coreference resolution: linking mentions that refer to the same real-world entity (e.g., "Asha" and "she").
  • Discourse and pragmatic analysis: reasoning across sentences about coherence, speech acts, implicature and context (who said what, what is presupposed).
  • Information extraction / relation extraction: extracting structured facts (subject, predicate, object) from text.
  • Generation: producing natural language text from structured representations.

Exact statement of the common pipeline (a law-like statement used in practice):

  • Pipeline principle: For many systems, a sequence of processing stages S1, S2, ..., Sk such that the output of Si is the input of Si+1 leads to modularity and easier error analysis. Assumption: Stage outputs are sufficiently accurate for downstream tasks; if not, joint models may be preferred.

Derivations and examination-style steps students are commonly asked for:

  1. Explain why tokenisation before POS tagging reduces the tagger's state space: show that treating "don't" as one token increases tag vocabulary and data sparsity; splitting reduces unique token types (derive via counting examples or illustrate with a small table of tokens).
  2. Show how morphological analysis reduces data sparsity: collect word forms (run, runs, running) and map to lemma "run"; show frequency consolidation and improved parameter estimates for models trained on lemmas.

Diagram to draw for answers (describe exactly):

  • Draw a left-to-right pipeline of rectangular boxes connected by arrows. Label boxes: "Raw input (text/speech)" → "Text normalisation" → "Sentence segmentation" → "Tokenisation" → "Morphological analysis / Lemmatisation" → "POS tagging" → "Syntactic parsing (dependency/constituency)" → "Semantic analysis (SRL / logical form)" → "Discourse / Coreference / Pragmatics" → "Application (translation / QA / IE / summarisation)". Under each box, write the type of output (e.g., sentence spans, tokens, lemmas, tags, parse tree, semantic graph). Optionally, draw dashed arrows skipping boxes to show that modern systems sometimes use end-to-end models that bypass intermediate outputs.

Notes about alternatives and assumptions:

  • The pipeline is a design choice, not a law: modern end-to-end neural systems may combine stages (for example, transformer models map tokens directly to answers), but understanding stages helps debugging and for resource-limited or low-data languages.
  • Language-specific choices: tokenisation and morphological analysis change with language (agglutinative languages need richer morphology handling).

Formulas

S_out = f_k( ... f_2(f_1(S_in)) ...)

  • S_in: raw input (text or speech); S_out: final structured output. f_i: function implemented by stage i. Unit: dimensionless (data structure). Applies when the system is designed as a strict pipeline.

P(w1..wn) = ∏_{i=1}^{n} P(wi | w1..w_{i-1})

  • wi: i-th word/token in a sequence. Unit: dimensionless (probability). Applies in language modelling; chain rule decomposition of joint probability of a word sequence.

argmax_{p1..pn} Score(t1..tn, p1..pn)

  • ti: token i; pi: POS tag for token i; Score: model scoring function (could be log-probability). Unit: dimensionless. Applies in tagging as a search/decoding problem.

Accuracy = (correct_predictions) / (total_predictions)

  • Unit: dimensionless (fraction). Applies when evaluating classification-like stages (POS tagging, NER, etc.).

Precision = TP / (TP + FP) Recall = TP / (TP + FN) F1 = 2 * Precision * Recall / (Precision + Recall)

  • Unit: dimensionless. Applies especially to sequence and span labelling tasks (NER, relation extraction); report span-level scores when appropriate.

Perplexity = exp( - (1/N) ∑_{i=1}^{N} log P(wi | context) )

  • Unit: dimensionless. Applies in language modelling as an intrinsic evaluation metric.

Worked examples

Example 1 — Explain a pipeline for building a simple Named Entity Recognition (NER) system and justify stage order (model answer):

  1. Raw input: a news sentence: "Prime Minister Modi met CEOs in Delhi."
  2. Text normalisation: maintain case (because case matters for NER), remove extraneous whitespace. Output: same sentence.
  3. Tokenisation: split into tokens ["Prime", "Minister", "Modi", "met", "CEOs", "in", "Delhi", "."] and keep punctuation as tokens.
  4. Morphological analysis: expand "CEOs" → lemma "CEO" (singular) and note plural; helps reduce sparse forms.
  5. POS tagging: assign tags [NNP, NNP, NNP, VBD, NNS, IN, NNP, .]. Here NNP = proper noun.
  6. Use features (tokens, lemmas, POS, capitalization) in an NER classifier to label spans: ["Prime Minister Modi"] → PERSON (or sometimes TITLE+PERSON broken into ROLE+PERSON depending on schema), ["CEOs"] → TITLE/ROLE, ["Delhi"] → LOCATION.
  7. Post-processing: resolve overlapping entities, map to canonical names. Justification: Tokenisation first is needed because the classifier expects tokens; morphological analysis reduces sparsity; POS gives syntactic cues that help NER.

Example 2 — Model answer: Where and how does ambiguity get resolved across stages? Use sentence: "Visiting relatives can be annoying."

  1. Tokenisation: ["Visiting", "relatives", "can", "be", "annoying", "."]
  2. POS tagging ambiguity: "Visiting" can be a verb (VBG) or an adjective (JJ). Two possible POS tag sequences produce different parses and meanings.
  3. Syntactic parsing: If POS = [VBG, NNS, ...] parse is verb phrase + object → meaning: doing the visiting is annoying. If POS = [JJ, NNS, ...] parse is adjective modifying noun → meaning: relatives who visit can be annoying.
  4. Semantic analysis & discourse: world knowledge may prefer one reading in context. Coreference with previous sentences can disambiguate. Model conclusion: Ambiguity is not always resolvable at a single stage; later stages (parsing, semantics, discourse) and context jointly decide meaning. This explains why joint models or feedback between stages can improve accuracy.

Example 3 — Short model answer: Describe how pipeline changes for morphologically rich languages (e.g., Tamil/Hindi).

  • Tokenisation may produce longer tokens; morphological analysis (using finite-state transducers or rule-based analyzers) becomes essential to split affixes. Lemmatisation reduces sparsity. POS and parsing must accept richer tagsets. Conclude: more linguistic preprocessing is usually required for agglutinative and inflectional languages.

Common mistakes

  • Using the terms "lemmatisation" and "stemming" interchangeably without defining them. (Define: stemming is crude suffix chopping; lemmatisation returns dictionary form using POS/morphology.)
  • Forgetting to state assumptions (for example, whether case is preserved in normalisation) when justifying design choices.
  • Ignoring language-specific differences (e.g., tokeniser that works for English will fail for Chinese or agglutinative languages).
  • Not describing the output type of each stage (tokens, tags, tree, graph). Examiners expect clear input/output types.

For your exam

Typical question types:

  • Define and list stages: expect short, clear definitions and a correct ordered list with explanation of why each stage exists.
  • Draw and explain a pipeline diagram: draw boxes and arrows; label outputs and mention alternatives (joint models) for full marks.
  • Compare pipeline vs end-to-end: pros and cons; mention error propagation and modularity.
  • Short notes: one-stage details (tokenisation, morphology, parsing) — include examples and language differences.
  • Long question: given a sentence, show outputs at each stage and discuss ambiguity resolution — produce concrete token lists, tags, parse or semantic forms. What full-marks answers include:
  • Precise definitions (bold terminology mentally) and explicit assumptions.
  • Correct diagram with labels and at least one justified design decision (e.g., why keep case or split contractions).
  • Example illustrating how one stage's output helps the next (e.g., lemma consolidation for language modelling).

Quick check

  1. What does tokenisation produce as output?
  2. Name two tasks that usually come after syntactic parsing in a pipeline.
  3. Why might an end-to-end model be preferred to a strict pipeline?

Answers: 1) A sequence of tokens (words, punctuation, subwords). 2) Semantic analysis (e.g., semantic role labelling) and coreference resolution (and also relation extraction / information extraction). 3) Because it can learn representations jointly, reduce error propagation between stages, and sometimes achieve better accuracy when large annotated data is available.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?