Stylometry

..or how do you know it's Shakespeare?

Agenda for today

  • Definition
  • Method & motivation
  • Origins of stylometry
  • State of the art
  • Stylo package
  • Hands-on 
  • Weekend 🌴

Stylometry

is the statistical analysis of variations in literary style between one writer or genre and another


Oxford Dictionary


in all their variety of material and method, have two features in common: the <...> texts they study have to be coaxed to yield numbers, and the numbers themselves have to be processed via statistics.

 

M. Eder, M. Kestemont, J. Rybicki. ‘Stylo’: a package for stylometric analyses

Stylometric studies

 underlying stylometric studies is that authors have an unconscious as well as conscious aspect to their style

 

Encyclopaedia of Statistical Sciences

 

The main assumption

How?

По-видимому, в разных стилях книжной и разговорной речи <...> частота употребления разных типов слов различна. Точные изыскания в этой области помогли бы установить структурно-грамматические, а отчасти и семантические различия между стилями <...>
 

В.В. Виноградов (1938) Введение в грамматическое учение о слове

 

It's mostly about frequencies

  • Words/word forms 
    • especially function words
  • Symbol N-grams
  • POS tags
  • Syntactic structures
  • Metric structures

 

Frequencies of

  • general vocabulary diversity
  • hapax legomena (see A. Q. Morton. 'Once. A Test of Authorship Based on Words Which Are Not Repeated in the Sample')
  • sentence length
  • punctuation
  • (in unedited text) spelling mistakes and specifics

 

Other features

Why?

Motivation, or why try and measure style?

  • Authorship disputes
  • Exploring genre differences
  • Capturing human stylome/idiostyle
  • Forensic linguistics, security and anonymity

Origins

  • authorship disputes and the rise of quantitative research on style
  • early stylostatistics/stylometrics/stylometry
  • XX century: from failures to successes

Authorship disputes

Presumably, each national literature has its own famous unsolved attribution case, such as the Shakespearean canon, a collection of Polish erotic poems of the 16th century ascribed to Mikołaj Sęp Szarzyński, the Russian epic poem The Tale of Igor’s Campaign, and many other. 

 

Eder M. (2011) Style-markers in authorship attribution: A cross-language study of the authorial fingerprint.

Слово о полку Игореве

Уже двести лет не прекращается дискуссия о том, что представляет собой «Слово о полку Игореве», — подлинное древнерусское произведение или искусную подделку под древность, созданную в XVIII веке. <...> Гибель единственного списка этого произведения лишает исследователей возможности произвести анализ почерка, бумаги, чернил и прочих материальных характеристик первоисточника. Наиболее прочным основанием для решения проблемы подлинности или поддельности «Слова о полку Игореве» оказывается в таких условиях язык этого памятника.

 

A.А. Зализняк. "Слово о полку Игореве": взгляд лингвиста.

Attribution through style

Lorenzo Valla  (1407 – 1457)

  • Italian humanist, rhetorician, educator and Catholic priest
  • in 1439 proved that the Donation of Constantine was a forgery
  • demonstrated that it could not have been written in the era of Constantine I  (IV century), as its style dated to XIII century

Quantifying style

  • 1851 — A. De Morgan suggests mean word-length as an authorship feature

  • 1873 — New Shakespeare Society (Furnival, Fleay et al)

  • 1887 — T. Mendenhall, The Characteristic Curves of Composition, the first known work on quantitative authorship attribution

Early stylometry

  • 1867 — Campbell L. The Sophisties and Polilicus of Plato.

  • 1880 — W. Dittenberger,

    Sprachliche Kriterien für die Chronologie der Platonischen Dialoge

  • 1890 — W. Lutosławski, Principes de stylométrie

Early stylometry in Russia

  • 1915 — Морозов Н.А. Лингвистические спектры
    Acknowledges the importance of function words (see pic.)

  • 1916 — Марков А.А. (the Markov!) Об одном применении статистического метода
     

     

Stylometry advances

  • 1937 — Bolling, G.M. The Past Tense of 'To Be' in Homer

  • 1938 — Carroll, J.B. Diversity of vocabulary and the harmonic series law of word-frequency distribution

From spoofs & failures...

  • in 1901 a scholar attempted to use John Fletcher's preference for "'em," the contractional form of "them," as a marker to distinguish between Fletcher and Philip Massinger in their collaborations—but he mistakenly employed an edition of Massinger's works in which the editor had expanded all instances of "'em" to "them"
  • A lot of speculation on Shakespeare could not stand scientific tests

...to successes

the breakthrougs came in the 1960-ies, as usual

Federalist papers

  • 12 disputed papers (Hamilton or Madison)
  • Mosteller F., Wallace D., (1963) Inference in an Authorship Problem.  
  • '<...> to solve the authorship question of The Federalist papers; and to propose routine methods for solving other authorship problems'.

 

Mosteller, Wallace, 1963

Mosteller, Wallace, 1963

  • The function words of the language appear to be a fertile source of discriminators, and luckily the high-frequency words are the strongest.
  • <...>it is important to have a variety of sources of material, to allow “between writings” variability to emerge
  •  

Mosteller, Wallace, 1963

In summary, the following points are clear:

  • Madison is the principal author. These data make it possible to say far more than ever before that the odds are enormously high that Madison wrote the 12 disputed papers. <...>
  • <...> While choice of under­lying constants (choice of prior distributions) matters, it doesn’t matter very much, once one is in the neighborhood of a distribution suggested by a fair body of data.

Yep, size matters!

J. F. Burrows

Most readers and critics behave as though common prepositions, conjunctions, personal pronouns, and articles — the parts of speech which make up at least a third of fictional works in English — do not really exist. But far from being a largely inert linguistic mass which has a simple but uninteresting function, these words and their frequency of use can tell us a great deal about the characters who speak them.

Preface to Computation into Criticism, 1987

Meanwhile in (Soviet) Russia

  • Виноградов В. В. (1961) Проблема авторства и теория стилей

  • Мартыненко Г.Я. (1988) Основы стилеметрии (a monograph)
  • Мухин М.Ю. (2011) Лексическая статистика и идиостиль автора: корпусное идеографическое исследование на материале произведений М. Булгакова, В. Набокова, А. Платонова и М. Шолохова

Modern stylometry

state of the art

Not limited to attribution

  • Dating the text
  • Exploring genre styles
  • Author demographics (age, gender) 
  • Internal evolution of style

Goes beyond literature

Beyond literature

  • Unabomber Theodore Kaczynski perpetrated a number of bomb attacks on universities and airlines between 1978 and 1995

  • Promised to stop if his 35,000-word anti-industrialist “manifesto was published in major newspapers

  • Distinctive writing style and turns of phrase enabled him to be identified

Beyond literature

  • Authorship of Primary Colors

  • Derek Bentley and his disputed murder ‘confession’ 

  • Adversarial stylometry

Adversarial stylometry

  • deceiving authorship detection
  • countermeasures to deception
  • de-anonymization
  • demographics detection
  • native language identification

  • ...potentially allows you to harrypoterize your fanfic =)

Nerd is the new sexy  

now in stylometry!

А.А. Зализняк 

Burrows Delta 

  • Benchmark since 2002
  • Makes use of most frequent words/char.n-grams (though more complex features are also possible) 
  • Has relatively simple mathematics behind (counting z-scores)

Z-score

Text

где

  • x – величина
  • µ - среднее по корпусу
  • σ - стандартное отклонение

Delta algorithm 

  1. Для всего тренировочного корпуса вычисляется N наиболее частотных слов; сохраняется частотность каждого.
  2. Далее для каждого текста в обеих выборках вычисляется z-score 
  3. z-score текстов из тестовой выборки сравниваются с z-показателями тренировочной
  4. обнаруживается текст из тренировочной, наиболее близкий классифицируемому.
  5. Его автор и объявляется автором классифицируемого текста.

Stylo: main functions

  • stylo () 
  • classify ()
  • rolling.delta (), rolling.classify ()
  • oppose ()

Stylo

  • R package for stylometry
  • Stylometry with R: a suite of tools. M. Eder, M. Kestemont, J. Rybicki.
  • Delta implementation 
  • ...and a handful of other measures
  • nice GUI :)

stylo () function

  • explanatory analysis with stylometric features
    • Clustering
    • Principal Component Analysis
    • MDS, tSNE and other beasts
  • visualizations of said analyses
  • wordlists, frequencies and other

classify ()

  • text classification with stylometry features
  • main tool for actual authorship attribution
  • employs standard machine-learning algorithms
  • requires two sets of documents
    • training (primary_set)
    • test (secondary_set) 

rolling.delta ()

  • dynamic changes in the text
  • text window of adjustable size

oppose ()

  • contrastive analysis 
  • words significantly preferred/avoided
  • comparison studies (e.g. male vs female styles) 

Hands on

Installing Stylo

  1. open R console 
  2. install.packages("stylo")
  3. library("stylo")

Setting working directory

  1. unzip archive to D:/
  2. getwd() 
  3. setwd ("D:/stylo/exp1")

First experiment:

comparing Brontë sisters

  1. stylo()

Second experiment:

Brontës meet... Ivanhoe

  1. setwd ("../exp2")
  2. stylo()

Third experiment:

Russians are coming

  1. setwd ("../exp3")
  2. stylo()
  3. classify ()

Fourth experiment:

Exposing J.K. Rowling

  1. data ("galbraith")
  2. stylo(frequencies = galbraith)
Made with Slides.com