Principal Component Analysis for Literary Genre Stylistics
Last week, we had our little digital humanities conference here in Würzburg, called <philtag n=”11″/> because this was the eleventh annual edition of the event. It was a great event, with plenty of wonderful talks about digital editing of manuscripts, immersive virtual reality, 3D laser-scans of cuneiform writing, network analysis of drama, and a lot more. For me, it was an occasion to present the small progress I have been making in stylometry for genre stylistics, small because tropical fish and exotic administrative forms have kept me busy over the last couple of weeks (and don’t ask what took the most time, the fish or the forms).
Anyway, following a lead by Hugh Craig, I explored a little bit further how Principal Component Analysis can be of help for the analysis of dramatic genres like comedy and tragedy. The following is only a small continuation of the things I started to discuss in my talk at DH2013. I stay with my classical example of thirthy-two plays written by Thomas and Pierre Corneille, with each author contributing both comedies and tragedies to the set. This is perfect material for PCA, but let’s go one step back to a simple analysis of distinctive words in this set.
The first graph shows the three most distinctive words the Voyant Tools find for a set of four composite texts, comedies by Pierre, tragedies by Pierre, comedies by Thomas, and tragedies by Pierre Corneille, all in verse. I love this example despite the fact that it simplifies to the point of caricature. As you can see, there are some words which are typical for tragedy and a-typical for comedy, such as “mort” (death). Other words are typical for Pierre Corneille and a-typical for his brother Thomas, such as “ces” (these). These examples, of which there are many more, seem to indicate that genre is defined by thematic words (with “mort” being an obvious marker of tragedy) while authorship is connected to specific patterns in function words (with “ces” clearly not connected to any kind of content). Still other words, however, such as “frère” (brother) in this example, have distributions which go against this neat trend and are common in a mixed set of plays (tragedies by Pierre and comedies by Thomas Corneille) and uncommon in the other mixed set. Previous experiments have shown things are indeed not as simple as equating function words with the top of the wordlist and with an authorship signal vs. equating content words with the lower ranges of the wordlist and with a genre signal. But it does prove that the frequency of (some) words do relate to genre as opposed to authorship and that they may be discovered.
Hugh Craig suggested I try our Principal Component Analysis on this set, so I did. Here are the results, and I think they are beautiful. The two first PCs cover about 23 and 15 percent of the total variance, respectively, which is average. But what is remarkable is how closely these two components seem to be related one to authorship and one to genre. Most plays in the left half are by Pierre Corneille, with some exceptions especially for the tragedies in the lower half. Most plays on the right side are by Thomas Corneille, again with some exceptions especially in the lower half. So the first component (horizontal axis) seems to be correlated with authorship.
The second component (vertical axis), on the contrary, seems to be correlated with genre. Most plays in the upper half of the graph are comedies, and most plays in the lower half of the graph are tragedies. Only a few tragedies by Pierre Corneille and even less by Thomas Corneille appear in the upper half of the graph. So, did PCA discover, without being told anything about the categories, two independent variables corresponding to genre and authorship? Well, not exactly, and a simple test of the strength of the correlations shows this. If we do a correlation test (cor.test in R) between each plays’ value on the horizontal axis and their values for author (Pierre or Thomas) and genre (comedy and tragedy), this is what we get: PC1 and authorship are clearly correlated (with a value of .58), while PC1 and genre hardly correlate at all (-.07). PC2, on the other hand, is very strongly correlated with genre (-0.80), but it is also somewhat correlated with authorship (-0.20). So while PC1 is a clear-cut case, PC2 is a mixed bag again. Still, this is a nice way of looking at this distribution of plays in a way that is more precise and lends itself more readily to comparison with other similar distributions than just evaluating the graph through visual inspection.
There is one more interesting thing about this graph. The dispersion of the data points (or plays) seems to be greater across PC1 for comedies than for tragedies. The tragedies are somewhat lumped together and authorship distinctions are actually hard to make just on the basis of PC1, so much overlap is there! This is not the case for the comedies in the upper half, where overlap seems to be much weaker. Again, this can be inspected in more detail using a combination of boxplots (which are great to visualize data dispersion) and standard deviation (which puts a number on the degree of dispersion). And yes, the standard deviation for comedies in the upper half is indeed much higher (sd = 1.185) than the standard deviation for tragedies in the lower half (sd = 0.671).
The boxplot shown here also confirms this, basically in a way that abstracts a little bit from the PCA plot. The beauty of this lies in the fact that we can relate these findings to things we know about seventheenth-century drama from textbooks or reference works: the thematic scope and stylistic conventions are much narrower for a genre as important as tragedy, while the themes and stylistic conventions are somewhat more relaxed for comedy. This gives authors of comedy a larger range of stylistic options, and they do seem to make use of that room for movement, since the authorial style of the same two authors is more distinct for comedies than it is for tragedies.
Now, this is already very nice, but can we further relate these results to things we know about comedy and tragedy, not just as a bulk distribution but on the level of the actual words making a difference here? PCA also lends itself to this by letting you inspect the loadings, that is in our case the words (i.e. the original dimensions before PCA reduced the dimensionality of the frequency matrix) most strongly associated with specific principal components.
The graph shown here indicates the loadings in a space on the plot that correponds to their association with either one of the first two principal components. It is a low-res crop of the graph produced by R. Most words cluster at the center, indicating they have little distinguishing power. But a few move away in specific directions. “Vous”, for example, at the extreme right (but at medium height) seems to be a strong marker for Thomas Corneille (but not for genre), while “je” at the upper right seems to be a Thomas Corneille comedy marker, as opposed to “tu” which seems to be a Pierre Corneille comedy marker. An interesting pair are “seigneur” (towards the bottom but in a middle position as to PC1) and “monsieur” (higher up but also in the middle for PC1), something which indicates that “seigneur” is a marker for tragedy regardless of authorship and “monsieur” a marker of comedy regardless of authorship. This is particularly interesting because we are dealing here with near synonyms mainly distinguished by the register they belong to. The higher-register word is associated with tragedy which is traditionally bound to “style noble”, while the lower-register word is associated with comedy, which can readily make use of “style bas / familier”.
What these results promise, on the more methodological level, is the possiblity to use such preliminary results for “feature generalization”. It seems that personal pronouns are a key to distinguishing comedy and tragedy, as are terms of address or reference between people. Indeed, the loadings and distinctiveness tests such as Burrows’ Zeta (also implemented in the “stylo” package for R as the “oppose” function) seem to show that personal pronouns and the like (vous, je, tu, te, toi, il, etc.) as well as terms of address or interpersonal relations (monsieur, seigneur, but also père, fils, prince, maîtresse) seem to be important for the author / genre distinction. What if we did a classical Delta distance measure and cluster analysis, or PCA, based only on an exhaustive list of personal pronouns and terms of interpersonal address? I’ll find out as soon as I can, but if you have done this, please report your results!Notes
- The following paper gives a general introduction to the use of PCA in literary stylometry: Binongo and Smith, “The Application of Principal Component Analysis to Stylometry”, Literary and Linguistic Computing 14.4, 1999, 445-466. doi:10.1093/llc/14.4.445. For a brief introduction to PCA for genre analysis, see the beginning of Hugh Craig’s contribution to the Companion to Digital Humanities, “Stylistic Analysis and Authorship Studies”, 2004, URL: http://nora.lis.uiuc.edu:3030/companion/view?docId=blackwell/9781405103213/9781405103213.xml&chunk.id=ss1-4-1&toc.id=0&brand=default .