Stylometry

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

Стил(о|е)метрия

Agenda for today

  • What is stylometry 
  • X-men Stylometry Origins
  • State of the art & applications
  • (finally!) Stylo 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
  • Co-authorship studies
  • Exploring gender/age differences
  • Capturing human stylome/idiostyle
  • Translation studies
  • 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.А. Зализняк. "Слово о полку Игореве": взгляд лингвиста.

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

tvkultura.ru

А какие случаи спорного или поддельного авторства знаете вы?

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

wikipedia.org

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 — Морозов Н.А. Лингвистические спектры (likely inspired by Lutoslawski)

  • Acknowledges the importance of function words (see pic.)

Потрясающий Н. А. Морозов

Потрясающий Н.А. Морозов

И этот человек написал "Лингвистические спектры"!

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

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

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 

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

Meanwhile in (Soviet) Russia

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

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

Modern stylometry

state of the art

Кто написал "Убить пересмешника"? 

Харпер Ли

Харпер ли?

Две книги

Харпер Ли и другие

Tay Hohoff, редактор

Truman Capote, писатель и друг Харпер Ли

Харпер Ли и другие

Maciej Eder, Jan Rybicki (2016)

Харпер Ли и другие

Maciej Eder, Jan Rybicki (2016)

But the study of literature and authorship is not only who wrote what, and who didn’t: it can be also about similarities and differences between texts by different authors

Maciej Eder, Jan Rybicki (2016). Go Set A Watchman while we Kill the Mockingbird in Cold Blood, with Cats and Other People

 

Харпер Ли и другие

Maciej Eder, Jan Rybicki (2016)

Но следы редактора видны в динамике:

Maciej Eder, Jan Rybicki (2016)

Элена Ферранте

Maciej Eder, Jan Rybicki

И конечно, он!

Maciej Eder, Jan Rybicki

Или он...

Maciej Eder, Jan Rybicki

Генрих VI

Maciej Eder, Jan Rybicki

Now it's official!

Jim Jarmusch. Only Lovers Left Alive (2013)

Немного хайпа

Nerd is the new sexy  

now in stylometry!

Modern Stylometry:
NOT limited to attribution

  • Exploring genre styles
  • Dating texts & tracking literary evolution
  • Author demographics (age, gender) 
  • Internal evolution of style
  • Originals and translations
  • Co-authorship problems

Stylochronometry

Maciej Eder, Jan Rybicki

Эволюция английской прозы

Maciej Eder, Jan Rybicki

Оригиналы и переводы

Оригиналы

Maciej Eder, Jan Rybicki

Переводы на английский

Maciej Eder, Jan Rybicki

Переводы на польский

Maciej Eder, Jan Rybicki

Переводы на польский

Maciej Eder, Jan Rybicki

Night and Day

by Virginia Woolf

Anna Kołyszko -> Magda Heydel

Maciej Eder, Jan Rybicki

Набоков

Jan Rybicki

Modern Stylometry:
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 =)

И даже по стилю кода! :-0

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: основные функции

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

stylo () function

  • explanatory analysis with stylometric features
    • Clustering
    • Principal Component Analysis
    • MDS, tSNE and other beasts
    • Consensus Tree (филогенетическое дерево)
  • 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. скачать архив
    goo.gl/pXVpmH

  2. распаковать в любую папку
  3. getwd() 
  4. setwd ("адрес папки")

Windows

  • разархивировать в D:\
  • >setwd ("D:\\stylo")

Mac/Linux

  • разархивировать в 'Users/Vasya/stylo'
  • >setwd ("/Users/Vasya/stylo")

 

Пример 

Проверить, какая у вас сейчас рабочая директория (папка):

  • getwd() 

goo.gl/pXVpmH

Материалы

First experiment:

Exposing J.K. Rowling

  • data ("galbraith")
  • stylo(frequencies = galbraith)

Second experiment:

Russians are coming

  1. >setwd ("2")
  2. >stylo()

Third experiment:

comparing Brontë sisters

  1. (виндоус) >setwd ("..\\3")
  2. (мак/linux) >setwd ("../3")
  3. >stylo()

Fourth experiment:

Brontës meet... Ivanhoe

  1. (виндоус) >setwd ("..\\4")
  2. (мак/linux) >setwd ("../4")
  3. >stylo()

Fifth experiment:

authorship with classify()

  1. (виндоус) >setwd ("..\\5")
  2. (мак/linux) >setwd ("../5")
  3. >classify()

Если на Mac не отображается кириллица

  • Открыть Terminal и выполнить там:

defaults write org.R-project.R force.LANG en_US.UTF-8 

  • ...либо прямо в R выполнить вот это:

>system("defaults write org.R-project.R force.LANG en_US.UTF-8")

Made with Slides.com