Machine Learning GuideOCDevelAll episodes
MLG 020 Natural Language Processing 3
Syntax parsing turns a tagged sentence into a tree, by probabilistic context-free grammars with CKY or, more often today, dependency parsing; classical NLP then combines it with TF-IDF and named entity recognition to answer questions. Also covers the Penn Treebank, TextRank summarization, statistical vs neural machine translation and NLP data pipelines.
Links • Notes and resources at ocdevel.com/mlg/20
- Join the free MLG group: listen to my other AI shows, ask me questions, and talk with other listeners
Classical NLP pipeline Text moves through stages, each feeding the next one downstream:
ingest documents -> clean (tokenize, lowercase, stem/lemmatize, drop stop words) -> POS tagging -> syntax parsing -> goal Text classification with naive Bayes needs only the bag of words, and search uses TF-IDF with cosine similarity (MLG 019). Named entity recognition (NER) is both a goal and a tool for later stages. At scale each stage gets its own machines. Hadoop and Spark are the classic distributed data-processing frameworks, and Spark is the one still in wide use.
Constituency parsing with context-free grammars Syntax parsing builds a tree over a part-of-speech-tagged sentence. A constituency parse groups words into phrases: in "The boy with blonde hair walked up the mountain", "the boy with blonde hair" is a noun phrase (NP) and "walked up the mountain" a verb phrase (VP), each breaking down further to POS tags. A context-free grammar (CFG) writes these groupings as production rules:
S -> NP VP VP -> V NP NP -> Det N | Adj NP Hand-written rules fail on ambiguity: the headline "Pope's baby steps on gays" parses two ways. A probabilistic CFG (PCFG) learns how often each production occurs from parsed sentences. The CKY (Cocke–Kasami–Younger) algorithm, a dynamic-programming parser for grammars in Chomsky normal form, then finds the most likely tree.
Penn Treebank and WordNet The Penn Treebank is an annotated corpus: sentences tagged with their parse trees in bracketed notation, used to train parsers and POS taggers. WordNet is a lexical database of English that groups words into synonym sets; NLTK includes it.
Dependency parsing A dependency parse draws arcs from head words to the words that depend on them, optionally labeled with the relation. In "Alice saw Bob reading in the hallway", "saw" is the root, with arcs to its subject "Alice" and to "Bob". Dependency parsing is the common approach today. Transition-based parsers read left to right with a stack and a buffer, at each step moving a word onto the stack or attaching words with an arc; a greedy parser takes the best-scoring move each time.
Google's SyntaxNet and its English model Parsey McParseface (2016) are retired. spaCy and Stanford's Stanza ship neural dependency parsers, and transformer models, LLMs included, are state of the art for parsing.
Relationship extraction and Google's knowledge panel A parse shows which entity does what to which, so relationship extraction can pull facts like spouse(A, B) out of a sentence. Google's knowledge panel, the card beside the results for a person, company or band, shows facts from its Knowledge Graph: birth date, spouse, founders, members.
Question answering with classical NLP For "Who is the prime minister of the United Kingdom?":
- TF-IDF and cosine similarity retrieve documents containing the rare query words. Common words like "who" and "the" score low, so they needn't be removed.
- TF-IDF narrows each document to a few candidate sentences.
- Parse the question, replace the question word ("who") with a blank, and score candidate sentences by how well