2025 · NLP · UofA

Heroes & villains of Treasure Island

Can a program read a novel and work out who the heroes and villains are? An end-to-end NLP pipeline that tries.

Where
University of Adelaide, Master of Data Science
When
January to September 2025
Data
Treasure Island, from Project Gutenberg
Tools
Python, spaCy, regex, sentiment analysis, KDE
34chapters structured
149raw character mentions
22canonical characters
4role classes

The question

A character in a novel appears under many names, and their role is never stated outright. The aim was to classify every character in Treasure Island as Hero, Villain, Morally Complex or Support/Neutral, using only the text.

The pipeline

  1. Structure the novel

    Cleaned the Project Gutenberg text and split it into 34 chapters with regex chapter detection, then into sentences with spaCy sentence tokenisation.

  2. Find the characters

    Extracted character mentions with spaCy named-entity recognition, then used alias mapping to collapse 149 raw mentions into 22 canonical characters, with manual role-based mapping such as "doctor" → Dr. Livesey.

  3. Point the sentiment at the right person

    Added quotation attribution and dependency-based sentiment targeting so sentiment lands on the correct character, falling back to sentence-level sentiment when needed.

  4. Measure each character

    Produced sentiment summary statistics, chapter-by-chapter sentiment arcs and a volatility score for every character.

  5. Infer the role

    Placed characters on a 2D map of sentiment against volatility and set the role boundaries with a KDE-based threshold.

What came out of it

  • Visualisations of each character's sentiment arc across the book.
  • A reproducible, long-form character-by-sentence dataset that supports interpretation and explainability.

Where this sits in the story