A Computational Analysis of the Voices of Shakespeare’s Characters (2023)

Abstract: In this paper we propose a study of a relatively novel problem in authorship attribution research: that of classifying the stylome of characters in a literary work. We choose as a case study the plays of William Shakespeare, presumably the most renowned and respected dramatist in the history of literature. Previous research in the field of authorship attribution has shown that the writing style of an author can be characterized and distinguished from that of other authors automatically. The question we propose to answer is a related but different one: can the styles of different characters be distinguished? We aim to verify in this way if an author managed to create believable characters with individual styles, and focus on Shakespeare’s iconic characters. We present our experiments using various features and models, including an SVM and a neural network, show that characters in Shakespeare’s plays can be classified with up to 50% accuracy.

## introduction the problem of authorship identification is based on the assumption that there exist stylistic features that can help distinguish the real author of a text from any other theoretical author, and that these can be computationally measured and exploited in order to automatically identify the true author of a text. automated authorship attribution has a long and rich history (starting from the early 20th century @xcite ) and has since then been extensively studied and elaborated upon. one of the most influential studies in authorship attribution is the study of @xcite on the federalist papers, in which the authors try to determine the real author of a few of these papers which have disputed paternity. in this work, they both introduce a standard dataset and propose an effective method for distinguishing between the author's styles, based on function words frequencies, that is still relevant and used to this day. many types of features have been proposed and successfully used in subsequent studies to determine the author of a text. these types of features generally contrast with the content words commonly used in text categorization by topic, and are said to be used unconsciously and harder to control by the author. such features are, for example, function words @xcite , grammatical structures @xcite , part-of-speech n-grams @xcite , lexical richness (tweedie and @xcite , or even the more general feature of character n-grams @xcite . recent studies focusing on stylistic variation within the writings of a single author combine traditional function word features with stylistic markers such as lexical richness and readability, as well as topic modelling, to compare the importance of the the stylome and the topics discussed in in the evolution of an author's writing @xcite . a related problem that has been approached much less in computational linguistics and even in digital humanities scientific literature is that of distinguishing between the writing styles of fictional people, namely literary characters. this problem may be interesting to study from the point of view of analyzing whether an author managed to create characters that are believable as separate people with individual styles, especially since style is a feature of speech that is hard to consciously control. shakespeare, as arguably the most renowned dramatist in the history of literature, is the ideal case study for understanding whether it is possible to create characters that are as individualized as humans are. one of the first authors to study literary characters stylistically is john @xcite shows that jane austen's characters show strong individual styles, then later burrows and craig (2012) look at a corpus of seventeenthcentury plays and tries to cluster them by character and by playwright. another recent study @xcite analyzes the works of two epistolary novels authors, who are known to have written their books together, and tries to distinguish automatically between passages written by each author, and between styles of each character in the novel. @xcite propose an experiment on classifying the characters in the epistolary novel les liaisons dangereuses, showing that the characters can be automatically distinguished stylistically even using simple models and features. @xcite propose a metric for characterizing spoken dialogue in the novel, which they call "dialogism", and @xcite publish a study reporting automatic measures of dialogism in plays from the nineteenth and twentieth centuries by automatically classifying their characters. in this paper we take a look at one of the most interesting authors in literary history: william shakespeare. shakespeare is seen by scholars and readers alike as one of the greatest dramatists in the history of literature. his characters are iconic, with strong well defined personalities. the question we propose to answer in this study is whether a computational analysis would lead to the same conclusion -did shakespeare manage to write distinct characters with unique speaking styles, and can we measure that? moreover, are the features that distinguish characters the same as the features that distinguish between different authors? shakespeare's characters have also been the subject of a few previous studies, such as nalisnick and baird (2013), where the authors try to map the relationships between characters. @xcite study keyness, and use shakespeare's romeo and juliet as a case study. in @xcite , the authors investigate the interesting problem of strength of characterization of a character, using plays of four authors, including shakespeare. they use text similarity methods to measure how similar a character's utterances are to the lines of the other characters in the same play and in other plays, proposing that stronger characters are most selfsimilar compared to other characters and plays. we are also interested in how individualized and realistic the characters are in their construction, but we assume that the strength of a character relies in how belivable it is as a unique person, and that this can be measured by the ability to distinguish characters the same as we do humans, from the perspective of their writing style. ## data and methodology we constructed our set of labeled texts by first splitting each of shakespeare's plays into individual lines, labeled with the characters that speak them, and excluding characters with less than 500 lines, and were left with a total of 50 characters. since it can be difficult to extract meaningful information from the short individual lines, we further concatenated them in groups of 10 lines (spoken by the same character) and used the resulted texts as our data points. we artificially balanced the number of datapoints pertaining to each class during training, using oversampling. ## classification experiments we formulated the problem as a supervised learning problem, and trained several models using various features to try and understand how well a machine learning model can predict a character based on its utterances within a play, and what are the features that help shape characters the most. we start by tokenizing the texts in our dataset and encoding them using a bag-of-words representation, which we further use to extract features for our classifiers. we perform different kinds of feature selection in order to then compare their performance and conclude on which are the most in some of our experiments, we try to limit our features to only function words, in order to understand whether these are as useful in distinguishing between characters as they are for distinguishing between different authors. ## results and analysis the overall accuracy for each of the experiments is shown in we take a closer look at the landscape of shakespeare's characters as represented by our model, by reducing our bag-of-words representation to two dimensions using principal component analysis. figure 1 illustrates this, showing that, even in this lower dimensional space, lines of the same character cluster together for some of the characters. furthermore, it is interesting to see which characters are more similar by looking at their relative feature set accuracy svm with all words 30% svm with k-best (100) 20% svm with content words 39% svm with stopwords 8% svm with character n-grams (2-10) 24% neural network with all words 20% our results suggest lines spoken by different characters can be distinguished, especially through the content words used in them. a question raised by this is whether we are truly capturing features specific to the characters, or predicting something else, such as the play they belong to. to tackle this problem, we perform a second experiment where we try to predict the play a book belongs to, using the same models, features and experimental settings as in our character classification experiment. the results for classifying texts by play are shown in we also replicate the visualization experiment, plotting in 2 dimensions lines belonging to top 10 (most prolific) characters in the top 5 plays (longest), shown in figure 2 . here too the distinction between lines in different plays is visible even in 2d, though less apparent than in the case of characters, which suggest characters may be more separable than plays. the results of the classification experiments do suggest that identifying the play it belongs to is a factor in determining which character utters a line. nevertheless, the classifier can still distinguish between characters of the same play, so other factors may contribute as well. we further try to understand how easy it is to classify between the characters to belonging the same play. only 4 of the 32 plays have more than 2 characters in our class set: the tragedy of othello, the moor of venice, the first part of henry the fourth the tragedy of antony and cleopatra and the history of troilus and cressida. for each of the mentioned plays, we perform an experiment to classify between its characters, using the setting that performed best at both character and play classification: an svm with content words as features. we average the accuracy per character for each play, then average the obtained accuracy per play, and get an average accuracy of 58.5% (almost double compared to the 30% accuracy that would be obtained by a random choice classifier). results also show that overall, content seems to be more predictive of the character, and that function words don't seem to capture a character's style in the same way they do an author's, in the case of shakespeare. nevertheless, the accuracy above chance obtained with function word features show they are not entirely unhelpful, confirming previous results in literary character classification @xcite . finally, we perform a last experiment where we select only the 4 plays with more than 3 prolific characters and group them together into a set of 12 total characters that we try to classify. looking at the errors the algorithm makes, whether or not it tends to mistake characters with other characters of the same play, should help us understand to what degree it learns to classify characters versus plays. ## conclusions and future directions our experiments have shown that it is possible to automatically distinguish between the characters of shakespeare's plays using a machine learning model. the texts were most successfully classified using content words, not function words, that are known to capture the stylistic dimension of a text. this suggests the question shakespeare's characters mostly differ in the topics they approach, and less in style, as defined in authorship attribution. we have also compared character classification to play classification, and have shown that, while the play a character belongs to is a useful indicator to its identity in classification, it is not the only factor which helps tell characters apart. it might be interesting to further explore other features such as sentiment or emotion features, or to use a more powerful classifier (such as a convolutional/recurrent neural network). many of the challenges of this analysis stemmed from the scarceness of data (many characters were discarded, lines were grouped together), so a learning algorithm that would be able to better handle small data might help expand the set of possible experiments and give more insight into the issue. in the future it may also be interesting to look at how various authors pertaining to different periods and literary currents compare in terms of their ability (and desire) to create individual, stylistically independent characters. literary theory @xcite tells us that the practice of giving characters strongly individual voices is a rather modern idea, and that characters evolved with time and literary current from the classical figures, who represented a typology, to the realist characters, who are pictured with strong individualities. this would be interesting to confirm experimentally, by extending the study to perform a diachronic analysis of characters in literary works. further, the analogous problem to author profiling could be tackled with regard to literary characters. separately of whether characters are easy to distinguish stylistically from one another, it may be interesting to see if an author managed to belivably build a character's style that is consistent with features of the character's personality: such as age or gender. cncs/cccdi-uefiscdi, cotohili project, project number 108, within pncdi iii.