{"id":746,"date":"2017-07-24T16:13:13","date_gmt":"2017-07-24T20:13:13","guid":{"rendered":"http:\/\/wwp.northeastern.edu\/blog\/?p=746"},"modified":"2017-07-25T14:46:19","modified_gmt":"2017-07-25T18:46:19","slug":"supervised-models","status":"publish","type":"post","link":"https:\/\/wwp.northeastern.edu\/blog\/supervised-models\/","title":{"rendered":"Word Embedding Models Are the New Topic Models"},"content":{"rendered":"<h3 style=\"text-align: left;\">By\u00a0Jonathan Fitzgerald, Ph.D. Candidate in English, Northeastern University<\/h3>\n<p><span style=\"font-weight: 400;\">I remember the first time I trained a topic model. It was in a course called Humanities Data Analysis, taught by Ben Schmidt. He provided us a corpus of the <em>Federalist Papers<\/em> and some code that he adapted from David Mimno, contributor to the original MALLET package and author of the R implementation of MALLET. After the initial confusion\u2013\u201ctopics\u201d aren\u2019t topics in the traditional sense, after all\u2013it felt like magic. The computer read the corpus and derived some topics!<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Enthusiasm for topic modelling remains strong in DH in part because it is a useful way to reduce a corpus down to manageable chunks and to get a sense as to what individual documents are \u201cabout.\u201d That said, in the years since my first experiments with the <em>Federalist Papers<\/em>, I\u2019ve come to believe that topic modelling is perhaps most useful as part of a workflow aimed at some goal beyond identifying topics in a corpus. To that end, I\u2019ve been using topics to seed a <\/span><a href=\"http:\/\/jonathandfitzgerald.com\/blog\/2016\/07\/13\/keystone-paper.html\"><span style=\"font-weight: 400;\">genre classifier<\/span><\/a><span style=\"font-weight: 400;\"> in my work with the <\/span><a href=\"http:\/\/viraltexts.org\/\"><span style=\"font-weight: 400;\">Viral Texts Project<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">While I\u2019ve been working with topic models these past few years, a new modelling craze has taken DH by storm\u2026relatively speaking. That is, thanks in large part to <\/span><a href=\"http:\/\/bookworm.benschmidt.org\/posts\/2015-10-25-Word-Embeddings.html\"><span style=\"font-weight: 400;\">this<\/span><\/a><span style=\"font-weight: 400;\"> post by Ben Schmidt, DH&#8217;ers have enthusiastically adopted word embedding models (WEMs), particularly the most popular manifestation, <\/span><a href=\"https:\/\/code.google.com\/archive\/p\/word2vec\/\"><span style=\"font-weight: 400;\">word2vec<\/span><\/a><span style=\"font-weight: 400;\">, created by Tomas Mikolov and his colleagues at Google. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">In a post in which we announced our current project \u201c<\/span><a href=\"http:\/\/wwp.northeastern.edu\/blog\/word-vector-analysis-project\/\"><span style=\"font-weight: 400;\">Word Vector Analysis for TEI\/XML: A user-Friendly Toolkit<\/span><\/a><span style=\"font-weight: 400;\">,\u201d my colleague Liz Polcha offers a helpful introduction to word embedding models and the way we plan to use them with data from Women Writers Online. As part of that effort, I\u2019ve been tasked with experimenting with word2vec and our corpus, as well as with imagining a way to provide an interactive online user interface. All this work is in progress, but as a part of those efforts, I\u2019ve been thinking about what we can actually <\/span><i><span style=\"font-weight: 400;\">do<\/span><\/i><span style=\"font-weight: 400;\"> with word embedding models. Just as my experience with topic models led me to the conclusion that they are most helpful on the way to some other interpretive exercise, my sense is that the same may be true for word embedding models.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This sense is born out of my own experiments with word2vec, but also from the existing literature on word embedding models. That is, you probably won\u2019t read a write-up on word2vec that doesn\u2019t provide the classic analogy example about <\/span><a href=\"http:\/\/ryanheuser.org\/word-vectors-1\/\"><span style=\"font-weight: 400;\">kings and queens<\/span><\/a><span style=\"font-weight: 400;\">. And, to be sure, it\u2019s cool. That word vectors seem to reflect expected relationships between words is solid evidence for their potential usefulness. But beyond seeing words related to other words and parsing out analogous relationships between terms, what can we do with word embedding models?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">I have a few ideas. For one, to stay on the <\/span><i><span style=\"font-weight: 400;\">topic<\/span><\/i><span style=\"font-weight: 400;\"> of this post (pun!), though word embedding models are unsupervised algorithms, we can work with the models in a way that is akin to a kind of supervised topic modelling. Topic modelling derives \u201ctopics\u201d from a corpus starting with a random seed word and grouping words that frequently co-occur within a document; working with the output of a word embedding model, on the other hand, lets us set that seed, so to speak. As Ben Schmidt writes, \u201cYou could think of this as a supervised form of topic modeling: it lets you assemble a list of words that typically appear in similar contexts.\u201d A significant difference between topic models and word embedding models is that \u00a0topics are generated with an awareness of the documents in a corpus. Word embedding models, on the other hand, look across an entire corpus for word collocations within a narrowly defined context, sometimes referred to as a \u201cwindow.\u201d Or, as Schmidt defines the difference, \u201cA topic model aims to reduce words down [to] some core meaning so you can see what each individual document in a library is really about. Effectively, this is about getting rid of words so we can understand documents more clearly. WEMs do nearly the opposite: they try to ignore information about individual documents so that you can better understand the relationships between words.\u201d<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Schmidt\u2019s food example from the <\/span><i><span style=\"font-weight: 400;\">Chronicling America<\/span><\/i><span style=\"font-weight: 400;\"> corpus illustrates the way we can use the relationship between words to build a kind of supervised topic. He starts with one food word, \u201coysters,\u201d and finds other food words that appear in similar semantic contexts: \u201cham,\u201d \u201cbread,\u201d \u201cchicken.\u201d Then, he adds these terms to the original vector and runs the search again, adding even more food words. In a way, he is building a \u201cfood\u201d topic. The process is, of course, different from what topic modelling does, but the end result is a list of words that have a meaningful relationship within a corpus of texts\u2014except the topics are created rather than derived.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In unsupervised machine learning, the algorithm does not explicitly \u201cknow\u201d what we are searching for; in the above example, it does not know that \u201coysters\u201d, \u201cham\u201d, and \u201cbread\u201d are foods. It just knows they cooccur. But when a human researcher intentionally selects and combines these words into a vector that she describes as food words, the unsupervised algorithm is being used in a supervised way.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This notion of creating topics through a supervised process of selecting and combining also works to allay an anxiety I have about the opaqueness of unsupervised modelling (particularly for a humanist who is new to computational modelling!). Ted Underwood frames the issue in a recent blog <\/span><a href=\"https:\/\/tedunderwood.com\/2017\/07\/13\/were-probably-due-for-another-discussion-of-stanley-fish\/\"><span style=\"font-weight: 400;\">post<\/span><\/a><span style=\"font-weight: 400;\"> in which he argues, among other things, that we should \u201cmake quantitative methods more explicit about their grounding in interpretive communities.\u201d That is, we shouldn\u2019t let computational models stand in for humanistic interpretation. Underwood writes: \u201cResearchers are attracted to unsupervised methods like topic modeling in part because those methods seem to generate analytic categories that are entirely untainted by arbitrary human choices. But as [Stanley] Fish explained, you can\u2019t escape making choices.\u201d<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Underwood emphasizes the importance of grounding these choices (or, interpretations) in \u201cinterpretive communities.\u201d And, for his part, Underwood notes that one way to do this is to favor supervised modelling methods; he writes:<\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\">I have been leaning on supervised algorithms a lot lately\u2014not because they\u2019re easier to test or more reliable than unsupervised ones\u2014but because they explicitly acknowledge that interpretation has to be anchored in human history. <\/span><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">I like this notion of relying on human judgment and generating interpretations \u201canchored in human history.\u201d That is, after all, what makes us humanists, right? To that end\u2014and again acknowledging that word2vec is an unsupervised algorithm\u2014I\u2019ve been thinking about the ways we can ground our work with unsupervised models in human interpretation. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Particularly, I&#8217;m interested in the potential for examining if and how word usage might reflect broad cultural trends over time. In the WWO corpus, which covers the 16th through 19th centuries, it might be interesting to consider how the use of the word \u201cfreedom\u201d reflects the culture of the authors who use the word. I approached this question by dividing our corpus up by century and creating \u201csupervised topics\u201d based on the word \u201cfreedom.\u201d<span id='easy-footnote-1-746' class='easy-footnote-margin-adjust'><\/span><span class='easy-footnote'><a href='https:\/\/wwp.northeastern.edu\/blog\/supervised-models\/#easy-footnote-bottom-1-746' title='Following Schmidt\u2019s example, I searched first for the word \u201cfreedom,\u201d and then iteratively selected additional words that made contextual sense\u2014so, in the 17th-century corpus, \u201cliberty\u201d is in, \u201cdisdain\u201d is out.'><sup>1<\/sup><\/a><\/span><\/span><\/p>\n<p>In the 16th and 17th centuries,<span id='easy-footnote-2-746' class='easy-footnote-margin-adjust'><\/span><span class='easy-footnote'><a href='https:\/\/wwp.northeastern.edu\/blog\/supervised-models\/#easy-footnote-bottom-2-746' title=' Women Writers Online contains texts with publication dates from 1525 to 1850; there are 30 texts from the 16th century and 170 from the 17th, so for the purposes of this analysis, I combined these texts.'><sup>2<\/sup><\/a><\/span> freedom seems to be a more personal affair; words that show up in the same vector space as \u201cfreedom\u201d include \u201chappiness,\u201d \u201cfriendship,\u201d and \u201cwedlock.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-753\" src=\"http:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c17_dendrogram-208x300.png\" alt=\"\" width=\"400\" height=\"577\" srcset=\"https:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c17_dendrogram-208x300.png 208w, https:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c17_dendrogram-187x270.png 187w, https:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c17_dendrogram.png 600w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>In the eighteenth century, freedom takes on a particularly revolutionary bent: \u201cpatriots,\u201d \u201crights,\u201d \u201ctriumph,\u201d \u201ccountry\u2019s,\u201d and \u201ctyrants,\u201d for example.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-754\" src=\"http:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c18_dendrogram.png\" alt=\"\" width=\"400\" height=\"577\" srcset=\"https:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c18_dendrogram.png 600w, https:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c18_dendrogram-208x300.png 208w, https:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c18_dendrogram-187x270.png 187w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Finally, in the nineteenth century, the revolutionary language remains (\u201crights,\u201d \u201ctyranny\u201d)\u2014though diminishes some\u2014and a new kind of freedom (or lack thereof) appears in the form of words like \u201cslave,\u201d \u201cslaves,\u201d \u201censlave,\u201d \u201cdegrading,\u201d \u201cminority.\u201d<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-755\" src=\"http:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c19_dendrogram.png\" alt=\"\" width=\"400\" height=\"577\" srcset=\"https:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c19_dendrogram.png 600w, https:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c19_dendrogram-208x300.png 208w, https:\/\/wwp.northeastern.edu\/blog\/wp-content\/uploads\/2017\/07\/c19_dendrogram-187x270.png 187w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">I considered that these shifts might be geographically-contingent; after all, only one work in our corpus from the 17th century was published in the colonies. However, in the 18th century, when we see a lot of what I\u2019ve described as \u201crevolutionary\u201d language, Europe still dominates as place of publication. It\u2019s not until the 19th century that the number of works published in the United States even begins to come close to those published in Europe (34 in the U.S. and 54 in Europe). So it seems that geography does not have a significant impact on the way the word \u201cfreedom\u201d is used in our corpus across three centuries, if only because of the collection&#8217;s own unevenness in its inclusion of works published outside of the United Kingdom.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Treating these vectors like supervised topics allows us to consider interesting cultural questions through the lens of the WWO corpus. But, typically word embedding models are deployed to tell us something about the words themselves. In this sense we can use a similar process to consider the way a word\u2019s usage shifted over time. My colleague Sarah Connell suggested that \u201cgrace\u201d might make for an interesting test case. And indeed, when compared across centuries, \u201cgrace\u201d moves from a word typically used in religious contexts in relation to God\u2019s grace (e.g., \u201cmercie,\u201d \u201cwisdome,\u201d \u201cfatherlie,\u201d \u201credeemer,\u201d \u201calmightie\u201d; note the archaic spellings) to secular contexts in relation to women\u2019s beauty (e.g., \u201cbeauty,\u201d \u201ccharms,\u201d \u201cfair,\u201d \u201cvirtue,\u201d \u201csweetness,\u201d \u201csmile,\u201d \u201clovely\u201d). Of course, the meaning of the word hasn\u2019t changed, but its application has. And, as with \u201cfreedom,\u201d this can tell us something about shifting cultural contexts\u2014in this case secularization.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In fact, this shift toward secularization is confirmed in our corpus using another method. The WWP\u2019s previous experimentation with markup-based exploration has already shown how growing literary secularization manifests in the collection after the seventeenth century. For one example, of the 3,228 bibliographic citations in the WWP\u2019s sixteenth- and seventeenth-century materials, 3,689 (86%) contain biblical references; by contrast, 256 (15%) of the 1,742 eighteenth-century bibliographic citations are biblical references.<span id='easy-footnote-3-746' class='easy-footnote-margin-adjust'><\/span><span class='easy-footnote'><a href='https:\/\/wwp.northeastern.edu\/blog\/supervised-models\/#easy-footnote-bottom-3-746' title='Taking genre into account by restricting the search to texts marked in the WWP&amp;#8217;s metadata as containing verse still reveals considerable differences between periods; 778 (92%) out of 873 pre-eighteenth-century citations are biblical references while 240 (34%) out of 705 eighteenth-century citations are biblical.'><sup>3<\/sup><\/a><\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;\">In both examples, word2vec gives us words that appear in similar contexts to our seed words, but it is up to us to recognize these similarities as significant, intentionally group them into ever more expansive topics, and then to theorize what (if anything) these collocation patterns might mean. Thus, we can work with an unsupervised model in a way that acknowledges, to quote Underwood once more, \u201cwe\u2019re no longer just modeling language; we can model interpretive communities at the same time.\u201d<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We\u2019re still early on in our explorations of word embedding models and literary corpora, both at the WWP and in DH in general. But that, in part, is what makes this project so interesting to us: it\u2019s an opportunity to explore word embedding models on a corpus that is focused on gender, relatively free of digitization errors, and easily transformed into markup-based subcorpora using XSLT and XQuery. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">As we continue to work with this corpus, it\u2019d be helpful to know what potential users might be interested in. If you have any suggestions for possible use-cases, please let us know in the comments.<\/span><\/p>\n<p><strong>Notes.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By\u00a0Jonathan Fitzgerald, Ph.D. Candidate in English, Northeastern University I remember the first time I trained a topic model. It was in a course called Humanities Data Analysis, taught by Ben Schmidt. He provided us a corpus of the Federalist Papers and some code that he adapted from David Mimno, contributor to the original MALLET package and author of the R implementation of MALLET. After the initial confusion\u2013\u201ctopics\u201d aren\u2019t topics in the traditional sense, after all\u2013it felt like magic. The computer&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/wwp.northeastern.edu\/blog\/supervised-models\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[],"class_list":["post-746","post","type-post","status-publish","format-standard","hentry","category-text-analysis"],"_links":{"self":[{"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/posts\/746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/comments?post=746"}],"version-history":[{"count":14,"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/posts\/746\/revisions"}],"predecessor-version":[{"id":764,"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/posts\/746\/revisions\/764"}],"wp:attachment":[{"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/media?parent=746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/categories?post=746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wwp.northeastern.edu\/blog\/wp-json\/wp\/v2\/tags?post=746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}