Majid Al-RaimiHow NLP is done: approaches and linguistic knowledge

ICS 582Lecture 01Part 03

How NLP is done: approaches and linguistic knowledge

The four families of NLP approaches, the pipeline from paragraphs to morphemes, the levels of linguistic knowledge from phonetics to discourse, and the contrast between a machine and a child who is predisposed to acquire language.

Concepts
4
Slides
14-19
Reading
24 min
Understood
0/4 concepts

Why this part matters

Everything after this lecture, from regular expressions and n-grams to classifiers, sequence labelling and transformers, is one of four approaches applied at one of a handful of linguistic levels. This part gives you both axes.

The exam questions on this material are definitional and comparative, so precise vocabulary is the whole game: which step turns sentences into words, how stemming differs from lemmatization, which levels exist only for speech. The research project will demand the same vocabulary in a different form, because every task you propose has to say which level it lives at and whether the knowledge at that level is coded by hand or learned from data. We build the four approaches first, run one paragraph through the text pipeline, climb the levels of linguistic knowledge, and finish with the observation that motivates the next part: a machine starts with none of this.

By the end you can

  1. Name the four approaches and say for each what a human writes and what the data supplies, with one strength and one weakness.
  2. Run a paragraph through sentence boundary disambiguation, tokenization, stemming and lemmatization, and predict where each step can go wrong.
  3. Define stemming versus lemmatization and give an example where they differ.
  4. Order the levels of linguistic knowledge from phonetics to discourse, place orthography and the lexical level, and say which levels apply to speech only.
  5. Explain why a machine, unlike a child, must have every level hand-coded or learned, and connect that to why NLP is difficult.

In 1966 Joseph Weizenbaum's ELIZA could take "I need some help" and answer "WHAT WOULD IT MEAN TO YOU IF YOU GOT SOME HELP". Jurafsky and Martin describe it as "a surprisingly simple program that uses pattern matching on words to recognize phrases like 'I need X' and change the words into suitable outputs", working "by having a series or cascade of regex substitutions". Every one of those rules was typed by a person. A modern translation system, by contrast, was shown millions of sentence pairs and nobody wrote a rule for any of them.

Those two systems mark the ends of one axis, and the four approaches on slide 15 are points along it. What separates them is not the task and not the programming language. It is the answer to a single question: what does a human write, and what does the data supply?

Each bar is one approach. The hatched part is what a human writes, the solid part is what the data supplies. The boundary rises from rules to end-to-end learning as data takes over, and drops back for hybrids.

Rule-based: the human writes everything

In rule-based NLP the knowledge of language lives in artefacts a person authored: a grammar, a lexicon, a set of regular expressions, a finite-state machine. The Georgetown-IBM demonstration of 7 January 1954, the first public machine translation, was in Hutchins's account "a small-scale experiment of just 250 words and six 'grammar' rules". ELIZA came twelve years later, and Jurafsky and Martin date the whole symbolic era "roughly from 1965 til the early 1990s".

The strengths follow from authorship. A rule is precise, you can read it, you can explain any output by pointing at the rule that produced it, and nothing has to be trained. Rule-based tokenizers are, in Jurafsky and Martin's words, "deterministic algorithms based on regular expressions compiled into efficient finite state automata", which is why they are fast. The weakness follows from the same fact: language keeps producing phenomena nobody wrote a rule for, and every one of them costs another rule, which may conflict with the rules already there.

Classical machine learning: the human writes the features, the data sets the weights

Machine learning based NLP moves the boundary. A person still decides what the model looks at, but the data decides how much each observation matters. For a part-of-speech tagger the designer might say "look at the word, its suffix, its capitalisation, and the previous tag". Jurafsky and Martin describe the arrangement exactly: "Although the idea of what features to use is done by the system designer by hand, the specific features are automatically populated by using feature templates", so a word-shape feature maps DC10-30 to XXdd-dd without anyone listing every flight number. A Classifier such as naive Bayes or logistic regression, or a sequence model such as a hidden Markov model or a conditional random field (Lafferty, McCallum and Pereira, 2001), then learns the weights from labelled examples.

The era began, by Jurafsky and Martin's account, with Jelinek's IBM speech group between 1975 and 1985, and "by the late 1980s statistical methods had begun to spread from speech researchers to NLP researchers working on text"; they date this "long revival of empiricism" as lasting until 2017. The strength is robustness: a probabilistic model degrades gracefully on input no rule anticipated. The price is twofold. Someone must label the training data, and someone must engineer the features, which is where the linguistic knowledge of the designer now goes.

End-to-end deep learning: the data supplies the representations too

End-to-end NLP using deep learning removes feature engineering. The model reads raw text (or audio) and learns its own intermediate representations on the way to the output. Sutskever, Vinyals and Le (2014) translated by using "a multilayered Long Short-Term Memory (LSTM) to map the input sequence to a vector of a fixed dimensionality, and then another deep LSTM to decode the target sequence". Vaswani and colleagues (2017) then proposed "a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely". Jurafsky and Martin note that the transformer, "invented for machine translation, quickly became a general-purpose neural architecture", and mark prompting in 2019 as the next inflection point. Speech went the same way: modern recognisers are encoder-decoder models with no hand-built pronunciation pipeline in front.

What the designer still writes is the architecture and the training objective. Everything else, including whatever the model knows about morphology or syntax, arrives from data. That gives the best accuracy and one model for many tasks, at the cost of very large data sets and compute, and of a system nobody can read. Jurafsky and Martin treat interpretability as an open research field for exactly this reason.

Hybrid: rules around a learned core

The Hybrid approach is what most production systems actually are. The pattern is a learned model in the middle with rules on either side: rules for normalisation before the model, and rules for constraints, safety checks or formatting after it. The clearest example is hiding inside the largest models. The GPT-2 tokenizer first runs a hand-written regular expression, which Jurafsky and Martin show as "the GPT-2 pre-tokenizer regular expression, used to split (roughly) on whitespace before running the BPE algorithm", and only then applies byte-pair encoding merges learned from data (Sennrich, Haddow and Birch, 2016). Rule first, learning second, in the front door of a language model.

ApproachWhat a human writesWhat the data suppliesStrengthsWeaknessesEra and example
Rule-basedGrammars, lexicons, regular expressions, finite-state machinesNothingPrecise, inspectable, needs no training data, fastBrittle; every new phenomenon is another rule to writeGeorgetown-IBM 1954, ELIZA 1966; symbolic era to the early 1990s
Classical machine learningFeature templates, the choice of modelThe weights, from labelled examplesRobust to noise, gives probabilities, learns from dataNeeds labelled data and hand-designed featuresNaive Bayes, HMM, CRF (2001); empiricist era starting between 1975 and 1988, lasting to 2017
End-to-end deep learningThe architecture and the lossRepresentations and weightsHighest accuracy, no feature engineering, one model for many tasksNeeds large data and compute; hard to inspectseq2seq 2014, Transformer 2017, prompting 2019
HybridNormalisation rules, constraints and checksThe learned corePractical, safe, works for low-resource languagesTwo systems to maintainGPT-2 regex pre-tokenizer plus learned BPE merges (2019)
The four approaches on one axis

Quick check

Which approach typically needs the most training data and compute to reach its accuracy?

Recall

Name the four approaches on slide 15 and give one strength and one weakness of each.

Rule-based (precise and explainable; brittle and costly to extend). Classical machine learning (robust and probabilistic; needs labelled data and hand-designed features). End-to-end deep learning (highest accuracy with no feature engineering; needs large data and compute, hard to inspect). Hybrid (practical and safe; two systems to maintain).

Take one paragraph: "Dr. Ahmad's students are running experiments. The pipeline costs 3.14 dollars per run. It works!" To a machine this is a string of characters. Before any approach from the last concept can be applied, that string has to be cut into units the approach can work on, and slide 16 names the cuts: paragraphs to sentences, sentences to words, words to their morphology.

Step through the paragraph below before reading on. Watch which periods survive as sentence boundaries, where the apostrophe goes, and what happens to are under each normaliser.

StepperFrom paragraph to stems and lemmas

Dr. Ahmad's students are running experiments. The pipeline costs 3.14 dollars per run. It works!

Step
Raw input
Changed
Nothing yet. The text is one string of characters with no structure the machine can use.
Watch
Two periods are not boundaries: the abbreviation in Dr. and the decimal point in 3.14.
Paragraphs
1
Sentences
3
Periods kept inside tokens
2
Tokens
19
Clitics split off
1
Non-word stems
3
1 / 4

Outputs precomputed with NLTK: the Punkt sentence tokenizer, the Treebank word tokenizer, the Porter stemmer in ORIGINAL_ALGORITHM mode, and the WordNet lemmatizer given each token's part of speech. Porter's own reference implementation leaves one- and two-letter words untouched, so it returns is unchanged where NLTK's original mode gives i.

Paragraphs to sentences: the period is ambiguous

Sentence boundary disambiguation looks easy because sentences end in punctuation. Jurafsky and Martin explain why it is not: "Question marks and exclamation points are relatively unambiguous markers", but "the period character '.', on the other hand, is ambiguous between a sentence boundary marker and a marker of abbreviations like Dr. or Inc.". Our paragraph has two periods that are not boundaries: the one in Dr. and the decimal point in 3.14. The stepper's second example adds the harder case, Inc., where one period closes the abbreviation and ends the sentence at the same time. Jurafsky and Martin use that case to argue that "sentence tokenization and word tokenization can be addressed jointly": the decision about the period is one decision, not two.

Practical splitters decide with an abbreviation dictionary, which "can be hand-built or machine-learned" (Kiss and Strunk, 2006, is the standard unsupervised method, and the NLTK Punkt tokenizer in the stepper implements it). Notice which approach that is: a rule, backed by a list that a person or a corpus supplies. The last concept's axis is already in play at the first step.

Sentences to words: tokenization is not splitting on spaces

Tokenization turns a sentence into tokens, and the trouble starts with the apostrophe. Jurafsky and Martin point out that "I'm is one word, grammatically it functions as two words". The 's in Ahmad's is a clitic, in their definition "a morpheme that acts syntactically like a word but is reduced in form and attached ... to another word" (a morpheme being the smallest meaningful piece of a word, defined properly below), and the Penn Treebank convention therefore splits it off, giving Ahmad and 's as two tokens. The same convention separates doesn't into does and n't, keeps hyphenated words such as San Francisco-based together, and makes every punctuation mark its own token, which is why the first sentence yields eight tokens, not six words.

The choices are language-specific. Arabic attaches the preposition b (by, with) and the conjunction w (and) to the following word, so a tokenizer for Arabic must decide whether to detach them. Chinese, Japanese and Thai, in Jurafsky and Martin's words, "simply don't have orthographic words at all": Chinese words average "roughly between 1.5 and 1.9 characters long" and a sentence such as 姚明进入总决赛 can be segmented as three words, five words or seven characters. Numbers differ too, 555,500.50 in one convention and 555 500,50 in another. This is Segmentation in its most basic form, and part 4 returns to it as a source of difficulty.

Words to morphology: chop, or look up

A word is built from morphemes, which Jurafsky and Martin define as minimal meaning-bearing units: cats is the morpheme cat plus the morpheme -s. Morphology is the level that knows this, and slide 16 lists two ways to use it. Stemming, in Manning, Raghavan and Schütze's definition, is "a crude heuristic process that chops off the ends of words in the hope of achieving this goal correctly most of the time". Lemmatization means "doing things properly with the use of a vocabulary and morphological analysis of words, normally aiming to remove inflectional endings only" and returning the lemma, the dictionary form.

The difference is visible in the stepper. Porter's 1980 algorithm, "the most common algorithm for stemming English", turns experiments into experi and are into ar: neither is a word, and the stemmer does not care, because it never consults a dictionary. The WordNet lemmatizer turns are into be. No suffix rule can do that; Manning and colleagues give exactly this case, "am, are, is" to be, as the reason lemmatization needs a vocabulary. It also needs the part of speech: running as a verb lemmatizes to run, but as a noun ("the running of the race") it stays running. The Porter stemmer gives run either way, and on that verb the two methods happen to agree.

Worked example

The first sentence through all four stages

  1. Sentence boundary disambiguation

    "Dr. Ahmad's students are running experiments." is kept as one sentence. The period in Dr. is judged an abbreviation marker, the final period a boundary.
  2. Tokenization (Penn Treebank convention)

    Dr. / Ahmad / 's / students / are / running / experiments / . The clitic is split off; the abbreviation keeps its period.
  3. Porter stems

    dr. / ahmad / ' / student / ar / run / experi / .
  4. WordNet lemmas, given the part of speech

    students to student; are to be; running (verb) to run; experiments to experiment.
  5. Result

    8 tokens, 2 stems that are not words (ar, experi), and 1 lemma that no suffix rule could reach (be).
StemmingLemmatization
MethodChops suffixes by ruleLooks up the dictionary form using a vocabulary and morphological analysis
OutputMay be a non-wordAlways a real word (the lemma)
SpeedFastSlower
NeedsNothing beyond the rulesA lexicon, and often the part of speech
Exampleexperiments to experi, are to arexperiments to experiment, are to be
Typical useSearch indexing, where recall matters more than readable outputAnything that shows text to people or feeds a parser
Stemming versus lemmatization

Quick check

In the pipeline of slide 16, which step turns sentences into words?

Recall

Define stemming and lemmatization with one example each, and name what lemmatization needs that stemming does not.

Stemming chops suffixes by rule and may return a non-word: experiments to experi, are to ar. Lemmatization returns the dictionary form using a vocabulary and morphological analysis: experiments to experiment, are to be. It needs a lexicon and usually the part of speech.

Recall

Why is the period a problem for sentence boundary disambiguation? Give a counterexample.

A period marks abbreviations (Dr.) and decimals (3.14) as well as sentence ends, so seeing one does not settle whether the sentence is over. In "Acme Inc. It is small." a single period does both jobs at once.

Extend the running example by one sentence: "Dr. Ahmad's students are running experiments. They will publish them tomorrow." Say it aloud, and something has to know that the sound wave you produced for running counts as that word and not runny. Write it down, and something has to know that they means the students and them means the experiments. Between those two ends lie the levels of linguistic knowledge, and slide 17 draws them twice: as concentric rings and as a stack with two roots.

The rings light from the centre outward, phonetics to pragmatics. On the right, the stack of slide 17: speech input reaches morphology through phonology and phonetics, text input through orthography.

Walking one sentence up the rings

Phonetics is, in Jurafsky and Martin's definition, "the study of the speech sounds used in the languages of the world, how they are produced in the human vocal tract, how they are realized acoustically, and how they can be digitized and processed". Its unit is the phone, the actual speech sound; the rings figure labels it "speech sounds", which is correct. A casual runnin' ends in a different phone from a careful running, and a recogniser must still hear one word: that variation is phonetics. Phonology abstracts over that variation to phonemes, the sound units that make one word different from another: running and runny differ by phonemes, however each is pronounced. Jurafsky and Martin put both under one heading in their list, "Phonetics and Phonology: knowledge about linguistic sounds", and note that speech recognition and synthesis need them to know "how words are pronounced in terms of sequences of sounds and how each of these sounds is realized acoustically".

On the text side the same role is played by Orthography, the writing system: the letters r-u-n-n-i-n-g, the fact that Arabic is written right to left with letters that change shape by position, the choice of Unicode code points. Both branches feed Morphology, which was the last concept: run plus -ing, student plus -s, Ahmad plus 's. Jurafsky and Martin's example is that "recognizing that doors is plural" requires morphology.

Above morphology sits the lexical level, which slide 16 calls "lexemes". A Lexeme is a vocabulary item with its senses: run as move fast, as operate, as manage. This is the level where Word sense disambiguation lives, the same task that slide 9 needed to read "heavy" as mass. Syntax is "knowledge of the structural relationships between words": the noun phrase "Dr. Ahmad's students" is the subject of "are running", and Parsing is the task that recovers such structure. Semantics is "knowledge of meaning", here the literal proposition that some students conduct experiments.

The last two levels leave the sentence (the rings stop at pragmatics; only the stack adds discourse above it). Pragmatics is "knowledge of the relationship of meaning to the goals and intentions of the speaker": "tomorrow" names a different day depending on when the sentence was written, which is exactly what the calendar extraction of slide 12 had to resolve. Discourse is "knowledge about linguistic units larger than a single utterance": deciding that they and them refer back to the students and the experiments is coreference resolution, the standard discourse task. Jurafsky and Martin close the list with the sentence that opens the next part: "most tasks in speech and language processing can be viewed as resolving ambiguity at one of these levels".

LevelUnitQuestion it answersExample task
PhoneticsPhones (speech sounds)How is it pronounced, and what does the waveform look like?Speech recognition front end, feature extraction
PhonologyPhonemesWhich sound differences change the word?Pronunciation modelling in speech recognition and synthesis
OrthographyCharacters, Unicode code pointsHow is the language written?Unicode and UTF-8 handling, script-specific normalisation
MorphologyMorphemesWhat parts is the word built from?Stemming, lemmatization, subword tokenization
LexicalLexemes and sensesWhich word, and which sense of it?Word sense disambiguation (the 'heavy' of slide 9)
SyntaxPhrases and sentencesHow do the words group?Parsing, prepositional phrase attachment (slide 21)
SemanticsPropositionsWhat does it literally mean?Semantic role labelling, question answering
PragmaticsAn utterance in contextWhat did the speaker intend?Resolving 'tomorrow' in slide 12, dialogue systems
DiscourseMulti-sentence textHow do the sentences connect?Coreference resolution, coherence modelling
Levels, units, questions and example tasks

Two figures, three omissions

The rings and the stack on slide 17 disagree in three small ways, and each is worth knowing because they are the kind of thing an exam question probes. The rings have no lexical ring: they go straight from morphology (words) to syntax (phrases and sentences), while the stack has "lexemes" between them. The rings have no orthography: they start from phonetics as if all input were speech, while the stack shows the text branch explicitly. The rings also stop at pragmatics, labelled "meaning in context of discourse", while the stack puts a separate discourse level on top. Read the stack as the complete list and the rings as the speech-first view.

Quick check

Which level of linguistic knowledge deals with meaning in the context of the discourse and the speaker's intent?

Quick check

Which two levels does speech input pass through that text input skips?

Recall

Order the levels from sound to discourse, and say which two apply to speech only.

Phonetics and phonology (speech only), orthography (text only), then morphology, lexical, syntax, semantics, pragmatics, discourse.

The lecture opens its next question, why NLP is difficult, with a picture rather than a list: a baby in a pinstriped suit sitting beside a laptop, labelled "Predisposed for acquiring language" and "Not so!". The joke carries the most important idea in the part. Jurafsky and Martin cite estimates that young adult speakers of American English know between 30,000 and 100,000 words, and conclude that children must learn "about 7 to 10 words a day, every single day" to reach that level by age 20 (the full range alone implies roughly 4 to 14 a day), most of them picked up "as a by-product of reading" with nobody teaching each one. The laptop knows nothing until someone types rules or feeds it data.

The child's column is full at rest: the levels are acquired from limited input without instruction. The machine's column fills only through two arrows, rules that a human hand-codes and data from which a model learns.

The claim on the slide is the nativist position in psycholinguistics. Its classic argument is the poverty of the stimulus: in the Stanford Encyclopedia's summary, "there are aspects of developed linguistic competence which cannot be explained with respect to the evidence available to the language learning child", so something must be built in. The debate about how much is built in remains open; the same entry notes that modern empiricists no longer defend a blank slate but "complex, innately structured minds and learning systems" while denying that any of them are specific to language. For this course you do not need to settle that. You need the part of the slide that nobody disputes: whatever a child brings to the task, a machine brings none of it.

Now put the two previous concepts side by side. The rings list the Knowledge of language that any language processor must have, from phonetics to discourse. The four approaches list the only two ways that knowledge can get into a machine: a person writes it down (rule-based), or a model extracts it from data (machine learning and Deep learning). There is no third route. Every ring, for every language the system must handle, has to be filled through one of those two arrows. That is why NLP is difficult, which part 4 takes up, and why slide 24 lists the disciplines and tools needed to do the filling.

The learned route is now the dominant one, and Jurafsky and Martin describe how far it reaches: large language models "learn this knowledge of language, knowledge of concepts, and knowledge of the world simply by being taught to predict the next word", an idea that goes back to the distributional hypothesis of the 1950s. Note what the learner is given: text, and only text. A child gets speech embedded in a situation, with gestures, objects and corrections. Jurafsky and Martin add that "grounding from real-world interaction or other modalities like vision can help build even more powerful models, but even text alone is remarkably useful".

What each learner starts with

Child
A predisposition to acquire language (the slide's claim), plus speech in context with feedback
Rule-based system
Whatever grammars, lexicons and regular expressions a person has written
Learned system
An architecture and a training objective; every level must be extracted from data

Quick check

According to slide 19, how must each level of linguistic knowledge get into a machine?

Recall

What must happen to every level of linguistic knowledge before a machine can use it, and why does the slide contrast the machine with a child?

Each level must be hand-coded as rules or learned from data; the machine has no third route. The child is contrasted because it acquires the same levels from limited, noisy input without explicit instruction, which the slide attributes to a predisposition for language that the machine lacks.

Recap

If you remember nothing else

  • The four approaches differ in who supplies the knowledge: rules (a human), classical ML (human features, data-set weights), end-to-end deep learning (data supplies the representations too), hybrid (rules around a learned core).
  • Rule-based NLP runs from the Georgetown-IBM demo of 1954 (250 words, six rules) and ELIZA in 1966 through the symbolic era to the early 1990s; statistical methods dominated until 2017; transformers (2017) and prompting (2019) define the current era.
  • The pipeline is paragraphs to sentences (sentence boundary disambiguation), sentences to words (tokenization), words to morphology (stemming or lemmatization). Parsing builds structure over tokens; it is not a splitting step.
  • The period is ambiguous: abbreviation, decimal or sentence end, and sometimes two at once, as in 'Acme Inc.' at the end of a sentence.
  • Tokenization is not trivial: clitics ('s, n't, Arabic b and w), hyphens, numbers, and Chinese, Japanese and Thai with no spaces between words.
  • Stemming chops (experiments to experi, are to ar); lemmatization looks up (experiments to experiment, are to be) and may need the part of speech.
  • Levels from sound to discourse: phonetics, phonology (speech only), orthography (text only), morphology, lexical, syntax, semantics, pragmatics, discourse. Most NLP tasks resolve ambiguity at one of these levels.
  • A child is predisposed to acquire language; a machine is not, so every level must be hand-coded or learned from data. That is the bridge to why NLP is hard.

Sources