The NLP Pipeline

The case study uses Natural Language Processing (NLP), namely computational methods for working with human language. This page explains the key concepts you’ll use: named-entity recognition, pre-trained models, tokenization, and the Hugging Face ecosystem. It also explains how the small, specialized model in the case study differs from the chat assistants you used in Unit 2.

Named-Entity Recognition

Named-Entity Recognition (NER) is the task of finding and classifying names in a text: people, places, organizations, and sometimes dates, works, or other categories (Grishman and Sundheim 1996; Nadeau and Sekine 2007; Jurafsky and Martin 2026, chap. 18).

Given a sentence like Robert Louis Stevenson wrote to Sidney Colvin from Edinburgh in August 1877., an NER model returns something like:

Entity Type Confidence
Robert Louis Stevenson PER (person) 1.00
Sidney Colvin PER (person) 1.00
Edinburgh LOC (location) 1.00
Note

The table above is the actual output of the case study’s model. Notice that August 1877 isn’t there: that’s because this model isn’t trained to label dates (its model card lists only people, places, and organizations).

For researchers, NER is a way to turn unstructured text into structured data: who is mentioned, where, and how often. It’s a common first step for network analysis, mapping, and indexing collections (Ehrmann et al. 2023).

Pre-Trained Models

The NER models in the case study are pre-trained: someone else has already trained them, on a large annotated dataset, and published them for others to use. You don’t train anything. You download the model and run it on your own text.

This works because of supervised learning: people annotated thousands of sentences, marking every name and its type, and the model learned to reproduce those labels on new text (Tjong Kim Sang and De Meulder 2003). It also means the model inherits everything about that training data: what kind of text it was, which languages, which period, and which decisions the annotators made.

Most widely used NER models were trained largely on modern news text. That shapes what they’re good and bad at. News has lots of politicians, companies, and cities, written in standard modern spelling. Nineteenth-century letters have nicknames, initials, archaic place names, ALL-CAPS headers, and people known only to the writer. Expect the model to do well on the first kind of thing and worse on the second (Ehrmann et al. 2023, 2020). The evaluation in the case study will measure how much worse.

Pre-Trained Models vs. General-Purpose LLMs

Both are pre-trained neural networks, and both are built on the transformer architecture (Devlin et al. 2019; Jurafsky and Martin 2026, chap. 9). But they are different tools:

NER model (e.g. BERT-based) General-purpose LLM (e.g. ChatGPT)
Task One narrow task: label names in text Almost any text task, described in a prompt
Output Structured: entity, type, position, confidence score Free text (which can be asked to look like data)
Consistency Same input, same settings, same versions, same output Varies between runs by default
Size and cost Small, runs on a laptop Very large, usually runs on a company’s servers
Transparency Published model with a documented training set Often opaque about training data (Bommasani et al. 2023)
Flexibility Low: only does what it was trained for High: can explain, summarize, translate, reason about context

Neither is simply better. The NER model gives you fast, consistent, structured output at scale, but it only gives you predictions, not explanations. You can’t ask it why it labelled something as it did, or ask it follow-up questions, and it doesn’t reason about context the way Gemini Notebook did when it worked out that S. C. was Colvin. And its confidence scores aren’t explanations either: a score of 0.99 says how confident the model is, which isn’t the same as how likely it is to be right, and says nothing about why (Guo et al. 2017; Desai and Durrett 2020). That’s the trade-off this unit explores.

NoteTokenization: The Problem of ALL-CAPS Text

Language Models explained that models don’t read words, but tokens. The NER models in the case study use a scheme called WordPiece: common words are single tokens, and rarer words are split into pieces from a fixed vocabulary, with the pieces that continue a word marked ## (Devlin et al. 2019; Jurafsky and Martin 2026, chap. 9).

This causes a concrete problem in the case study. The letters are full of ALL-CAPS text: headings (TO SIDNEY COLVIN), salutations (MY DEAR COLVIN), and signatures (LOUIS STEVENSON). The model’s vocabulary was built mostly from normally capitalized text, so the capitalized forms are broken into fragments that rarely appeared in its training data:

Text Tokens
Sidney Sidney
SIDNEY SI ##D ##NE ##Y
Colvin Col ##vin
COLVIN CO ##L ##VI ##N
LOUIS L ##O ##UI ##S

Normally, the pipeline merges the ## pieces back into whole words (that’s what aggregation_strategy='simple' does). But the model has rarely seen fragments like these in training, so it may give different labels to different pieces of the same word. Then they can’t be merged, and they come out as meaningless entities like SI or L.

The simplest fix is to convert ALL-CAPS words to title case (Sidney Colvin) before running the model. The notebook does this with a small function called normalize_caps, and shows the output before and after in Section 2. (A different aggregation strategy, such as 'first', would keep each word in one piece, but the model would still be reading fragments it rarely saw in training.)

This is a small example of a general lesson: preprocessing decisions matter, and a mismatch between your text and the model’s training data can cause failures that look mysterious until you know where to look.

The Pipeline

Put together, the case study is a pipeline, a sequence of steps each feeding the next:

  1. Load the letters and their metadata.
  2. Preprocess the text (normalize capitalization).
  3. Run the NER model on each letter.
  4. Structure the output as a table, and export it as CSV.
  5. Resolve different names for the same entity (Colvin, Sidney Colvin).
  6. Analyze and visualize: frequencies, a network, a timeline, a map.
  7. Evaluate the model against human annotations.

Each step can introduce errors, and errors compound (Finkel et al. 2006): a fragment from step 3 becomes a person in the network, or a dot on the map. That’s why evaluation matters so much.

Hugging Face

Hugging Face hosts millions of pre-trained models, including many for NER in different languages and domains. The transformers library (Wolf et al. 2020) lets you load any of them in a few lines:

from transformers import pipeline

ner_pipeline = pipeline('ner', model='Davlan/bert-base-multilingual-cased-ner-hrl', aggregation_strategy='simple')
ner_pipeline('Robert Louis Stevenson wrote to Sidney Colvin from Edinburgh in August 1877.')

Each model has a model card: a page describing what it was trained on, which labels it predicts, how it was evaluated, and its known limitations (Mitchell et al. 2019). Reading the model card is the first step in choosing a model, and the first thing you’d cite about it. The case study uses:

Read both model cards before you start. What do they tell you about how each model might handle Stevenson’s letters?

Key Takeaways

  • Named-entity recognition turns unstructured text into structured data about the people, places, and organizations it mentions.
  • Pre-trained models inherit the strengths and blind spots of their training data. Most NER models were trained on modern news, not nineteenth-century letters.
  • A narrow NER model gives fast, consistent, structured predictions, but no explanations. A general-purpose LLM is flexible, but less consistent.
  • Preprocessing matters: a mismatch between your text and the model’s training data, such as ALL-CAPS headers, can cause failures that look mysterious.
  • Errors compound along a pipeline, which is why evaluation comes last and matters most. Start by reading the model card.
NoteGoing Further

If you want to read more, the following are a good place to start:

  • Ehrmann et al. (2023): a survey of named-entity recognition on historical documents, written partly with humanities researchers in mind. The introduction and the sections on the challenges of historical text are readable without the technical detail.
  • Megan S. Kane, Corpus Analysis with spaCy (2023): a Programming Historian lesson that walks through NER and related techniques on a real corpus, step by step.
  • Mitchell et al. (2019): the short paper that proposed model cards, and what they should contain. Worth reading before you rely on one.

References

Bommasani, Rishi, Kevin Klyman, Shayne Longpre, et al. 2023. “The Foundation Model Transparency Index.” arXiv:2310.12941.
Desai, Shrey, and Greg Durrett. 2020. “Calibration of Pre-Trained Transformers.” In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP), edited by Bonnie Webber, Trevor Cohn, Yulan He, and Yang Liu. Association for Computational Linguistics.
Devlin, Jacob, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. “BERT: Pre-Training of Deep Bidirectional Transformers for Language Understanding.” In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), edited by Jill Burstein, Christy Doran, and Thamar Solorio. Association for Computational Linguistics.
Ehrmann, Maud, Ahmed Hamdi, Elvys Linhares Pontes, Matteo Romanello, and Antoine Doucet. 2023. “Named Entity Recognition and Classification in Historical Documents: A Survey.” ACM Computing Surveys 56 (2): 27:1–47.
Ehrmann, Maud, Matteo Romanello, Alex Flückiger, and Simon Clematide. 2020. “Extended Overview of CLEF HIPE 2020: Named Entity Processing on Historical Newspapers.” CLEF 2020 Working Notes. Conference and Labs of the Evaluation Forum, CEUR Workshop Proceedings; 2696, vol. 2696 (October).
Finkel, Jenny Rose, Christopher D. Manning, and Andrew Y. Ng. 2006. “Solving the Problem of Cascading Errors: Approximate Bayesian Inference for Linguistic Annotation Pipelines.” In Proceedings of the 2006 Conference on Empirical Methods in Natural Language Processing, edited by Dan Jurafsky and Eric Gaussier. Association for Computational Linguistics.
Grishman, Ralph, and Beth Sundheim. 1996. “Message Understanding Conference- 6: A Brief History.” COLING 1996 Volume 1: The 16th International Conference on Computational Linguistics.
Guo, Chuan, Geoff Pleiss, Yu Sun, and Kilian Q. Weinberger. 2017. “On Calibration of Modern Neural Networks.” arXiv:1706.04599.
Jurafsky, Daniel, and James H. Martin. 2026. Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition, with Language Models. 3rd ed.
Mitchell, Margaret, Simone Wu, Andrew Zaldivar, et al. 2019. “Model Cards for Model Reporting.” Proceedings of the Conference on Fairness, Accountability, and Transparency, January 29, 220–29.
Nadeau, David, and Satoshi Sekine. 2007. “A Survey of Named Entity Recognition and Classification.” Lingvisticæ Investigationes 30 (1): 3–26.
Tjong Kim Sang, Erik F., and Fien De Meulder. 2003. Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition. arXiv:cs/0306050.
Wolf, Thomas, Lysandre Debut, Victor Sanh, et al. 2020. “Transformers: State-of-the-Art Natural Language Processing.” In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations, edited by Qun Liu and David Schlangen. Association for Computational Linguistics.