Computational Exploration of the Origin of Mood in Literary Texts (2022)

Abstract: This paper is a methodological exploration of the origin of mood in early modern and modern Finnish literary texts using computational methods. We discuss the pre-processing steps as well as the various natural language processing tools used to try to pinpoint where mood can be best detected in text. We also share several tools and resources developed during this process. Our early attempts suggest that overall mood can be computationally detected in the first three paragraphs of a book.

## introduction this paper aims to provide a short exploratory study into a very specific literary concept: mood. mood is the general atmosphere that the author creates through their word choices, style and use of imagery and can sometimes even include tone. mood is about how the reader feels about the text, and the related concept of tone is about how the implied author feels about it and uses words to convey their attitude towards a topic or subject foot_0 @xcite . we use various natural language processing (nlp) tools and methods to attempt to identify the origins and location of mood. for this purpose we have collected a corpus of 975 literary works written in finnish. our paper utilizes many tried and tested nlp and computational literary studies methods, but to our knowledge it is the first to combine emotion detection / sentiment analysis with traditional literary affect studies exploring tone and mood. since the choice of words is of the utmost importance when creating both of these sometimes entangled concepts in literary works, mood, and to some extent tone, detection are perfect subjects for analyzing the use of emotion-associated words in text. it is not easy to determine where specifically mood is created in a text. does mood reside everywhere, or is it most strongly present in the first chapter of books, or perhaps the first few paragraphs of each chapter? in a larger sense mood is not reducible to a single aspect, but generated by a set of textual elements. we suggest that the computational study of the valence of the lexicon can be valuable in providing an accurate picture on the distribution of the positive and negative valence in a text-continuum, and thus help us to better understand the relationship between the linguistic qualities of a text and its perceived emotional effects, particularly the mood of a text. ## previous work literature can be considered a domain where the affective functions of language are of principal importance @xcite . research on literature and emotions is an active field in traditional literary studies, particularly after the "affective turn"; a shift in attitude towards how affect is perceived in literary theory that took place about two decades ago (see e.g @xcite . research topics range from the study of literature and empathy @xcite to the study of literature and cognition (hogan, 2011)), negative affects and tone in texts @xcite to empirical perspectives @xcite , and even emotions specific to finnish literature @xcite . recently, the question of a text's overall emotional tone or mood has aroused vivid interest (e.g. @xcite lyytikäinen (2017), and rossi (2020) ). yet a systematic theory of how tone and mood are created and triggered is still under construction. we suggest that a study of the emotional valence of the lexicon measured quantitatively provides a new approach that can help with understanding the components of a text's mood @xcite . ## data we downloaded the first 1000 books from project gutenberg foot_1 , where (1) the language was finnish, and ( 2 ) the text was in utf-8 plain text format. as far as we are aware, there is no way of filtering out texts by their original language, so our dataset includes many translated works. we used the simple gutenberg-cleaner foot_2 to get rid of the preamble and the legal text at the end of the book, then we created a regex to extract key information such as the title, the name of the author, the year of publication, and whether the book was originally written in finnish. the translation status of the book was extracted based on whether the terms suomentaja, suomennettu, suomentanut, or any version of kääntäjä/käännös/käännetty etc. were present within the first ten lines of text after the preamble was removed. due to encoding issues, our final corpus consists of 975 books of which roughly half were originally written in finnish. a vast majority (95+%) were written or translated between the years 1850 and 1925 and over 90% after 1880, with only a few instances of older texts meaning that the language used in the texts can be considered modern finnish @xcite . the final data consists of 2,938,032 sentences and 41,417,116 tokens. ## method finnish is a great language to work with in terms of nlp. numerous resources not only exist but are also well-curated. there are several researchers and research groups who actively develop new tools and improve upon old ones, and most of these tools are open source @xcite . thus we had the opportunity to test several different lemmatizers and tokenizers. we further add to this list of tools by having created a finnish version of the chapterize foot_3 package. after the project gutenberg added information was removed, the texts were lemmatized, split into paragraphs, and tokenized. first, we tried finetuning finnish bert @xcite to work with our texts (as per @xcite , but the results were not promising and require further work (particuarly the vocabulary was not improved sufficiently). we subsequently tried multiple different lemmatization tools, including the turku neural parser @xcite , murre @xcite , and both the experimental and news finnish spacy models. in the end we settled for the turku neural parser as the results were the most accurate (see incidentally, in the dissertation of airio (2009) kahviansa is discussed as an example of "parasite words" since it can be mistakenly split into kahvi (coffee) and ansa (trap), something none of the lemmatizers did. with careful optimism, we take this as a demonstration of how good lemmatizers for morphologically complex languages have become in the past decade. after pre-processing the texts, we identified the first three paragraphs of each book. this was trickier than expected as despite removing the preambles/headers, some metadata remains in the text files and this metadata is of various shapes without uniformity or even commonly recurring pattern of where the actual text of the book starts. for this reason, we created a finnish version of the chapterize package for python and used the chapter splits to help recognize opening paragraphs together with sentence and paragraph ids provided by the conllu metadata.we used two different text sections as targets for overall mood detection: the first three paragraphs of each book, and the first 200 tokens from each chapter in each book. from previous studies @xcite we know that certain words can quickly overwhelm the results; when analyzing the novel rautatie by juhani aho, the term rautatie (railroad) in the lexicon was associated with trust and because the store takes place on the railroad and is about the railroad the levels of trust in the results were not representative of the level of trust in the novel itself. as feil contains mostly contemporary words and their contemporary emotion associations we needed to make sure that (1) the most common words in our texts that in our opinion have an emotion association are indeed in the lexicon, and (2) that the most common emotion word matches represent the correct emotions at reasonable intensities. these steps are iterative and continuous in that they should be repeated whenever the lexicon or lemmatization is altered. the removal of non-emotion associated words is straightforward and fairly uncontroversial. however, re-labeling emotion words or adding new words to the lexicon should be done with utmost care, ideally using multiple annotators who are not the authors and cross-checking the results using inter-annotator agreement scores @xcite . in this vein, we did not want to bias the lexicon with our own interpretations of emotion intensities so instead we created a large word2vec model of our corpus and used it to look up words in the lexicon with high cosine similarity to the words we wanted to introduce to the lexicon (as per e.g. @xcite @xcite . this lead to the association for e.g. the words kirkas, valkoinen, and valkea to be identical. as the words that needed to be added were relatively few, we manually checked that the emotion associations and intensities made sense. for future projects we intend to employ human annotators in addition to this approach, however, this approach alone showed a lot of promise and was very accurate within the small sample size. after completing steps (1) and (2), we removed 128 entries from the lexicon and added 203 tokens including rakastaa, to love. the exclusion of such an important term from the lexicon exemplifies some of the issues with using a lexicon that was originally created for english where the noun and verb forms are often the same unlike in finnish where the forms are distinct (cf. to love/ a love, to run/a run vs. rakastaa/rakkaus, juosta/juoksu). some of these issues were fixed in feil by adding both the finnish noun and verb forms of a single english entry, but many such examples remain @xcite . we used this domain-and periodspecific version of feil to tabulate normalized (per token count for inter-text comparability), intensity scores for each target text. other future projects should include checking that both noun and verb forms are found in the lexicon. if we are looking at purely the word choices of the author, tone and mood can be difficult to distinguish from each other and can be intertwined to different degrees. however, the tone of a literary text tends to shift much more even within a chapter and therefore by focusing on the first paragraphs of each chapter, or even the opening paragraphs of the first chapter only, we can get a fairly accurate idea of the mood of the text, with less of a risk of it being confused with tone. although the tone of the text may vary within one work (due to e.g. changes in the narrative point of view or mover from description to dialogue narration) the analysis of the beginnings of a text may be indicative of the overall tone of a text. namely from the perspective of the reader, the beginnings tend to shape the experience of reading. theories of perception (e.g. @xcite argue that the openings play a crucial role in creating a text's overall emotional disposition: as in everyday life, the first impression matters in reading, too. the emotion effects created in the beginning of a text modify and adjust the reader's general emotional orientation by shaping up modes of perception and organization of information. for instance, the melancholic translation the provost sits down in his rocking chair, stands his pipe on the floor against the table leg, and starts drinking his coffee original rovasti istuutuu keinutuoliinsa, panee piippunsa lattialle pöydän jalkaa vasten pystyyn ja rupeaa juomaan kahvians murre (hist) (öljy)movasti istua keinutuoli panna pippu latija pöytä jalka vaste pystyä ja ruveta juoma kahvis spacy (news_lg) rovasti istuutua keinutuoliinsa panee piippu lattia pöytä jalka vasten pystyyn ja rupeata juoda kahvians spacy (exp. /w voikko) rovasti istuutua keinutuoli panna piippu lattia pöytä jalka vasten pystyyn ja ruveta juoda kahvians uralicnlp rovasti|rovasti istuutua panna piippu lattia pöytä jalka vasten pystyyn|pysty ja ruveta juoma|juoda turku neural parser rovasti istuutua keinu#tuoli panna piippu lattia pöytä jalka vasten pystyyn ja ruveta juoda kahvi ## the mood in selected texts the results are difficult to present in a small space as they list all the emotion scores per text, therefore we are focusing here on qualitatively evaluating a small subset of the data. the selection is pragmatic, and based on the second author's area of expertise. ## discussion we find that the preliminary results correspond well with established interpretations of mood in select texts when comparing to the emotion word distribution of the first three paragraphs of a literary text. comparing the valency and intensity of emotions in the opening paragraphs of the book and the opening paragraphs of all chapters, we can see that when looking at all chapters, the emotions approach the distribution of emotion in the lexicon, i.e. they become muddled even though there are some idiosyncrasies that can be assumed to be because of the author's style. furthermore, the differences between the different texts are also evened out in the all-chapters approach. this could also be in part because the focus becomes more varied and therefore the results average out and start to converge on the distribution of emotions in the lexicon. we recommend that the quest for mood should begin with the opening paragraphs of a text. it is important to note that evoking emotional effects in literature is not restricted to emotion words or to direct descriptions of the character's emotions. all aspects of the narrative, from description of objects to narrative point of view and style, including tropes and even the rhythm of the text are important aspects in triggering emotional effects in the reader. for instance, the melancholic tone of juhani aho's text is not generated by themes of separation and loss alone but also by aho's style, which favors fragmentation and loosening of syntax, with a recurring mannerism of three points "..." , as a sign of hesitation and withdrawal, even evoking a depressive loss of contact. the qualitative analysis demonstrates that the selected texts depict and trigger negative emotions in particular: feelings of deception, fear, anxiety, disgust and hatred, anger, moral indignation and melancholia. on one hand, this can be explained by genre-specific emotional effects: a critical naturalist novel tends to shock and challenge its reader by representing and inciting strong negative emotions, which confirm the effect of reality of a text and direct the reader's attention to the social defects described. for instance, the emotion of disgust, which is a genre-specific emotion of the naturalist novel, is a named emotion and salient in sillanpää's and canth's novels in particular @xcite @xcite . the salience of negative emotions can be explained by the importance of negative emotions in literature and art in general. as discussed by @xcite negative emotions are an important resource for the arts, since negative emotions have been shown to be particularly powerful in securing attention, intense emotional involvement, and high memorability, and hence is precisely what artworks strive for. this dataset will be used for more robust detection of tone and mood in finnish literature. our preliminary studies show that the "big data" results support qualitative analyses and further justifies the use of purely lexicon-based methods when dealing with larger collections of text where word choice is an important factor of creating affective states in the reader. specifically, we can see that the choice of emotion associated words in the first three paragraphs correlates highly with established analyses of mood in the selected texts. we hope to add established emotion categories from literary affect studies (see e.g. hogan 2011) to the lexicon as a measure to further improve the usability of the feil lexicon for the literary domain @xcite . additionally, we would like to expand on the methodologies used in this exploratory study and hopefully create more and more robust approaches to tone and mood detection in literature.