liveBook · Manning

Sentence boundary detection

As explained in Natural Language Processing in Action, Second Edition

A sentence boundary detector identifies and separates individual sentences in a text.

Sentence boundary detection separates a document into individual sentences. These sentence-sized units usually carry coherent meaning, making them a practical starting point for information extraction, dialogue selection, and language-model preprocessing. section 11.2

The task looks simple because periods, question marks, exclamation marks, and newlines often signal boundaries. It becomes difficult when punctuation appears in abbreviations, quotations, ellipses, decimals, informal messages, or text without surrounding spaces. section 11.2 section 11.2.2

Choose a segmentation strategy according to the text and the downstream cost of mistakes:

  • Use a regular expression or finite-state machine for a fast, general-purpose baseline; simple splitting can consume sentence-ending punctuation or mishandle quoted sentences. section 11.2.2
  • Use spaCy to tokenize text and expose detected sentences through doc.sents; its language pipeline applies sentence-boundary rules alongside linguistic annotations. section 2.1.4

A quick regex experiment

Applying re.split(r'[!.?]+[\s$]+', "Hello World.... Are you there?!?! I'm going to Mars!") returns three chunks, but the first two lose their terminating punctuation. A lookaround pattern can separate "I went to GT.You?" at the period without requiring whitespace, while abbreviation-heavy text is better handled by spaCy.

Reliable boundaries matter beyond display: they prevent word-vector training from learning across unrelated neighboring sentences and influence the accuracy of later extraction steps. Domain-specific segmenters can be retrained when corpus style differs substantially. section 6.3.5 section 11.2.2

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains punctuation heuristics, regex limitations, spaCy pipelines, runtime, and agreement testing, but stops short of formal evaluation methodology.
Examples
Demonstrates regex splits, quoted text, abbreviation handling, spaCy sentence lists, pipeline timing, and regex–spaCy agreement.
What it assumes
Assumes basic Python and text-processing familiarity while introducing sentence chunks, punctuation heuristics, and pipeline tradeoffs incrementally.
What you can do after
Apply it via regular expressions or spaCy, inspect sentence outputs, and compare segmentation behavior on domain data.
How it connects
Connects sentence segmentation with tokenization, regular expressions, finite-state machines, information extraction, chatbots, and Word2Vec.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.