{'fraction_non_alphanumeric': 0.029137713202779532, 'fraction_numerical': 0.008765003158559697, 'mean_word_length': 5.1630170316301705, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Character-to-Character Sentiment Analysis in Shakespeare's Plays

We present an automatic method for analyzing sentiment dynamics between characters in plays. This literary format’s structured dialogue allows us to make assumptions about who is participating in a conversation. Once we have an idea of who a character is speaking to, the sentiment in his or her speech can be attributed accordingly, allowing us to generate lists of a character’s enemies and allies as well as pinpoint scenes critical to a character’s emotional development. Results of experiments on Shakespeare’s plays are presented along with discussion of how this work can be extended to unstructured texts (i.e. novels).


Introduction
Insightful analysis of literary fiction often challenges trained human readers let alone machines. In fact, some humanists believe literary analysis is so closely tied to the human condition that it is impossible for computers to perform. In his book Reading Machines: Toward an Algorithmic Criticism, Stephen Ramsay (2011) states: Tools that can adjudicate the hermeneutical parameters of human reading experiences...stretch considerably beyond the most ambitious fantasies of artificial intelligence.
Antonio Roque (2012) has challenged Ramsay's claim, and certainly there has been successful work done in the computational analysis and modeling of narratives, as we will review in the next section. However, we believe that most previous work (except possibly (Elsner, 2012)) has failed to directly address the root cause of Ramsay's skepticism: can computers extract the emotions encoded in a narrative? For example, can the love that Shakespeare's Juliet feels for Romeo be computationally tracked? Empathizing with characters along their journeys to emotional highs and lows is often what makes a narrative compelling for a reader, and therefore we believe mapping these journeys is the first step in capturing the human reading experience.
Unfortunately but unsurprisingly, computational modeling of the emotional relationships described in natural language text remains a daunting technical challenge. The reason this task is so difficult is that emotions are indistinct and often subtly conveyed, especially in text with literary merit. Humans typically achieve no greater than 80% accuracy in sentiment classification experiments involving product reviews (Pang et al., 2002) (Gamon, 2004. Similar experiments on fiction texts would presumably yield even higher error rates. In order to attack this open problem and make further progress towards refuting Ramsay's claim, we turn to shallow statistical approaches. Sentiment analysis (Pang and Lee, 2008) has been successfully applied to mine social media data for emotional responses to events, public figures, and consumer products just by using emotion lexicons-lists that map words to polarity values (+1 for positive sentiment, -1 for negative) or valence values that try to capture degrees of polarity. In the following paper, we describe our attempts to use modern sentiment lexicons and dialogue structure to algorithmically track and model-with no domain-specific customization-the emotion dynamics between characters in Shakespeare's plays. 1

Sentiment Analysis and Related Work
Sentiment analysis (SA) is now widely used commercially to infer user opinions from product reviews and social-media messages (Pang and   . Traditional machine learning techniques on n-grams, parts of speech, and other bag of words features can be used when the data is labeled (e.g. IMDB's user reviews are labeled with one to ten stars, which are assumed to correlate with the text's polarity) (Pang et al., 2002). But text annotated with its true sentiments is hard to come by so often labels must be obtained via crowdsourcing.
Knowledge-based methods (which also typically rely on crowdsourcing) provide an alternative to using labeled data (Andreevskaia and Bergler, 2007). These methods are driven by sentiment lexicons, fixed lists associating words with "valences" (signed integers representing positive and negative feelings) (Kim and Hovy, 2004). Some lexicons allow for analysis of specific emotions by associating words with degrees of fear, joy, surprise, anger, anticipation, etc. (Strapparava and Valitutti, 2004) (Mohammad and Turney, 2008). Unsurprisingly, methods which, like these, lack deep understanding often work more reliably as the length of the input text increases.
Turning our attention now to automatic semantic analysis of fiction, it seems that narrative modeling and summarization has been the most intensively studied application. Chambers and Jurafsky (2009) described a system that can learn (without supervision) the sequence of events described in a narrative, and Elson and McKeown (2009) created a platform that can symbolically represent and reason over narratives.
Narrative structure has also been studied by representing character interactions as networks. Mutton (2004) adapted methods for extracting social networks from Internet Relay Chat (IRC) to mine Shakespeare's plays for their networks. Extending this line of work to novels,  developed a reliable method for speech attribution in unstructured texts, and then used this method to successfully extract social networks from Victorian novels )(Agarwal et al., 2012. While structure is undeniably important, we believe analyzing a narrative's emotions is essential to capturing the 'reading experience,' which is a view others have held. Alm and Sproat (2005) analyzed Brothers Grimm fairy tales for their 'emotional trajectories,' finding emotion typically increases as a story progresses. Mohammad (2011) scaled-up their work by using a crowdsourced emotion lexicon to track emotion dynam-ics over the course of many novels and plays, including Shakespeare's. In the most recent work we are aware of, Elsner (2012)   We attempt to further Elsner's line of work by leveraging text structure (as Mutton and Elson did) and knowlege-based SA to track the emotional trajectories of interpersonal relationships rather than of a whole text or an isolated character. To extract these relationships, we mined for characterto-character sentiment by summing the valence values (provided by the AFINN sentiment lexicon (Nielsen, 2011)) over each instance of continuous speech and then assumed that sentiment was directed towards the character that spoke immediately before the current speaker. This assumption doesn't always hold; it is not uncommon to find a scene in which two characters are expressing feelings about someone offstage. Yet our initial results on Shakespeare's plays show that the instances of face-to-face dialogue produce a strong enough signal to generate sentiment rankings that match our expectations.
For example, Hamlet's sentiment rankings upon the conclusion of his play are shown in Figure 1. Not surprisingly, Claudius draws the most negative sentiment from Hamlet, receiving a score of -27. On the other hand, Gertrude is very well liked by Hamlet (+24), which is unexpected (at least to us) since Hamlet suspects that his mother was involved in murdering King Hamlet.

Peering into the Queen's Closet
To gain more insight into this mother-son relationship, we examined how their feelings towards one another change over the course of the play. Figure 2 shows the results of dynamic characterto-character sentiment analysis on Gertrude and Hamlet. The running total of Hamlet's sentiment valence toward Gertrude is tracked by the black line, and Gertrude's feelings toward her son are tracked by the opposite boundary of the light/dark gray area. The line graph shows a dramatic swing in sentiment around line 2,250, which corresponds to Act iii, Scene iv.
In this scene, entitled The Queen's Closet, Hamlet confronts his mother about her involvement in King Hamlet's death. Gertrude is shocked at the accusation, revealing she never suspected Hamlet's father was murdered. King Hamlet's ghost even points this out to his son: "But, look, amazement on thy mother sits" (3.4.109). Hamlet then comes to the realization that his mother had no involvement in the murder and probably married Claudius more so to preserve stability in the state. As a result, Hamlet's affection towards his mother grows, as exhibited in the sentiment jump from -1 to 22. But this scene has the opposite affect on Gertrude: she sees her son murder an innocent man (Polonius) and talk to an invisible presence (she cannot see King Hamlet's ghost). Gertrude is coming to the understanding that Hamlet is not just depressed but possibly mad and on a revenge mission. Because of Gertrude's realization, it is only natural that her sentiment undergoes a sharply negative change (1 to -19). After running this automatic analysis on all of Shakespeare's plays, not all the results examined were as enlightening as the Hamlet vs. Gertrude example. Instead, the majority supported our already held interpretations. We will now present what the technique revealed about three of Shakespeare's best known relationships. Figure 3 shows Othello vs. Desdemona sentiment dynamics. We clearly see Othello's love for his new bride climaxes in the first third of the play and then rapidly degrades due to Iago's deceit while Desdemona's feelings for Othello stay positive until the very end of the play when it is clear Othello's love for her has become poisoned. For an example of a contrasting relationship, Figure 4 shows Romeo vs. Juliet. As expected, the two exhibit rapidly increasing positive sentiment for each other that only tapers when the play takes a tragic course in the latter half. Lastly, Figure 5 shows Petruchio vs. Katharina (from The Taming of the Shrew). The phases of Petruchio's courtship can be seen: first he is neutral to her, then 'tames' her with a period of negative sentiment, and finally she embraces him, as shown by the increasingly positive sentiment exhibited in both directions. Figure 4: Juliet's sentiment for Romeo is denoted by the black line, and Romeo's for Juliet is marked by the opposite boundary of the gray area. Aligning with our expectations, both characters exhibit strong positive sentiment towards the other throughout the play.

Analyzing Shakespeare's Most Famous Couples
Unfortunately, we do not have room in this paper to discuss further examples, but a visualization of sentiment dynamics between any pair of characters in any of Shakespeare's plays can be seen at www.lehigh.edu/∼etn212/ShakespeareExplorer.html.

Future Work
While this paper presents experiments on just Shakespeare's plays, note that the described technique can be extended to any work of fiction writ-ten since the Elizabethan Period. The sentiment lexicon we used, AFINN, is designed for modern English; thus, it should only provide better analysis on works written after Shakespeare's. Furthermore, character-to-character analysis should be able to be applied to novels (and other unstructured fiction) if  speaker attribution technique is first run on the work.
Not only can these techniques be extended to novels but also be made more precise. For instance, the assumption that the current speaker's sentiment is directed toward the previous speaker is rather naive. A speech could be analyzed for context clues that signal that the character speaking is not talking about someone present but about someone out of the scene. The sentiment could then be redirected to the not-present character. Furthermore, detecting subtle rhetorical features such as irony and deceit would markedly improve the accuracy of the analysis on some plays. For example, our character-to-character analysis fails to detect that Iago hates Othello because Iago gives his commander constant lip service in order to manipulate him-only revealing his true feelings at the play's conclusion.

Conclusions
As demonstrated, shallow, un-customized sentiment analysis can be used in conjunction with text structure to analyze interpersonal relationships described within a play and output an interpretation that matches reader expectations. This character-to-character sentiment analysis can be done statically as well as dynamically to possibly pinpoint influential moments in the narrative (which is how we noticed the importance of Hamlet's Act 3, Scene 4 to the Hamlet-Gertrude relationship). Yet, we believe the most noteworthy aspect of this work lies not in the details of our technique but rather in the demonstration that detailed emotion dynamics can be extracted with simplistic approaches-which in turn gives promise to the future work of robust analysis of interpersonal relationships in short stories and novels.