<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="../../../_utils/schema/yaps.rnc" type="application/relax-ng-compact-syntax"?>
<?xml-model href="../../../_utils/schema/yaps.isosch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<?xml-stylesheet type="text/css" href="../../../_utils/stylesheets/yaps-tei.css"?>
<!-- $Id: word_vectors_hands-on.xml 51709 2026-05-28 23:29:13Z syd $ -->
<TEI xmlns="http://www.wwp.northeastern.edu/ns/yaps" version="5.0">
   <teiHeader>
      <fileDesc>
         <titleStmt>
            <title>Word Vectors: Walkthroughs and Hands-on Practice</title>
            <author>Sarah Connell</author>
            <author>Julia Flanders</author>
         </titleStmt>
         <editionStmt>
            <edition>Word Vectors for the Thoughtful Humanist</edition>
         </editionStmt>
         <publicationStmt>
            <distributor>Women Writers Project (via website)</distributor>
            <address>
               <addrLine>url:mailto:wwp@northeastern.edu</addrLine>
            </address>
            <date when="2021-06-29"/>
            <availability status="restricted">
               <p>Copyright 20121 Syd Bauman, Julia Flanders, Sarah Connell, and the Women Writers
                  Project</p>
               <p>This TEI-encoded XML file is available under the terms of the <ref
                     target="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
                     Attribution-ShareAlike 3.0 (Unported)</ref> license.</p>
            </availability>
            <pubPlace>Boston, MA USA</pubPlace>
         </publicationStmt>
         <sourceDesc>
            <p>Slides for walkthroughs and hands-on practice.</p>
         </sourceDesc>
      </fileDesc>
      <revisionDesc>
         <change when="2021-06-29" who="sconnell.yuw">Initial draft</change>
      </revisionDesc>
   </teiHeader>
   <text>
      <presentation>

         <sectionGrp>
            <head>Conceptual Orientation and R Basics </head>
            <section>
               <head>R, RStudio, RMarkdown</head>
               <slide>
                  <p>
                     <emph>Walkthrough file:</emph>
                     <q>Introduction to R and RStudio</q>
                  </p>
                  <p><emph>R</emph> is a programming language that can be used for a wide range of
                     both textual and statistical analyses.</p>

                  <p><emph>RStudio</emph> is an environment for editing and running R code, as well
                     as other related files. It is available both in a <emph>Desktop</emph> version
                     that can be downloaded and installed on your computer locally and a
                        <emph>Server</emph> version that can be accessed using a web browser.</p>

                  <p><emph>RMarkdown</emph> is a type of document that combines executable code with
                     formatted text. In this seminar, we will be using several RMarkdown
                        <q>walkthroughs</q> that have code and explanations. </p>
               </slide>
               <lectureNote>
                  <p>Let’s start with some brief orientation in the language, software, and files
                     we’ll be using: <list>
                        <item> R is a computer programming language; it was designed for statistics,
                           but can also be used for text analysis by digital humanists.</item>
                        <item>To access R, we will be using a program called RStudio. We’re using a
                           hosted version called RStudio Server because it engineers out a great
                           many potential complexities and points of failure, but you are also
                           welcome to download R and and the RStudio Desktop version on your own
                           computers. Working on RStudio Server is slower and has significant limits
                           on file size, so you might want a more powerful version, particularly if
                           you want to work with a corpus of more than 4 million words. </item>
                        <item>RStudio can run R code in many different types of formats; we’ll be
                           using one specific kind, called RMarkdown. These files combine executable
                           code with lightly formatted text, expressed using <term>Markdown</term>.
                           Markdown is a lightweight markup language that lets you add formatting to
                           plain text documents, for example by using asterisks to indicate italics.
                        </item>
                     </list>
                  </p>
               </lectureNote>
               <tutorial>
                  <p>This tutorial assumes that you have downloaded and installed R and RStudio, and that you have opened the WordVectors project, and navigated to and opened the “Introduction-to-R-and-RStudio.Rmd” file. 
                    See <ref target="https://github.com/NEU-DSG/wwp-public-code-share/blob/main/WordVectors/Model-Loading-and-Training.md">this guide</ref> for more information on on getting yourself set up.</p>
                  <p>Before we jump into some hands on work, let’s start with some brief orientation in the language, software, and files
                     we’ll be using: <list>
                        <item> R is a computer programming language; it was designed for statistics,
                           but can also be used for text analysis by digital humanists. We will be using R to train our word embedding models</item>
                        <item>To access R, we will be using a program called RStudio. RStudio can run R code in many different types of formats; we’ll be
                           using one specific kind, called RMarkdown. These files combine executable
                           code with lightly formatted text, expressed using <term>Markdown</term>.
                           Markdown is a lightweight markup language that lets you add formatting to
                           plain text documents, for example by using asterisks to indicate italics.
                        </item>
                     </list>
                  </p>
               </tutorial>
            </section>
            <section>
               <head>Tour of RStudio Server </head>
               <slide>
                  <list>
                     <item><emph>Source:</emph> where you open, write, and interact with
                        files</item>
                     <item><emph>Console:</emph> where the code from the Source pane is run</item>
                     <item><emph>Environment:</emph> where you can view the <q>data objects</q> that
                        you create</item>
                     <item><emph>Files:</emph> where you can navigate files/folders and view
                        plots</item>
                  </list>
                  <figure>
                     <graphic height="500px" url="../../../_utils/gfx/w2v_rstudio-environment.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>Here's a quick tour of the RStudio interface. By default, RStudio is divided
                     into four panes, each of which has a different function; this lets us keep
                     track of all our essential information at one glance. <list>
                        <item>In the top left, we have the <term>Source</term> pane where we can
                           open and read files, and also run code from them. </item>
                        <item>In the bottom left, we have what’s called the <term>Console</term>,
                           which is where the code is actually being run. </item>
                        <item> We also have an <term>Environment</term> section in the top right:
                           you’ll be creating some data objects, such as functions and variables
                           (more on those soon) and those will appear in your Environment. </item>
                        <item>Finally, in the bottom right, is where you can actually navigate your
                           files. When you create charts and visualizations, that’s where those will
                           appear. And, you can use this pane to access documentation and help
                           files. </item>
                     </list>
                  </p>
               </lectureNote>
               <tutorial>
                  <p>Here's a quick tour of the RStudio interface. By default, RStudio is divided
                     into four panes, each of which has a different function; this lets us keep
                     track of all our essential information at one glance. <list>
                        <item>In the top left, we have the <term>Source</term> pane where we can
                           open and read files, and also run code from them. </item>
                        <item>In the bottom left, we have what’s called the <term>Console</term>,
                           which is where the code is actually being run. </item>
                        <item> We also have an <term>Environment</term> section in the top right:
                           you’ll be creating some data objects, such as functions and variables
                           (more on those soon) and those will appear in your Environment. </item>
                        <item>Finally, in the bottom right, is where you can actually navigate your
                           files. When you create charts and visualizations, that’s where those will
                           appear. And, you can use this pane to access documentation and help
                           files. </item>
                     </list>
                  </p>
               </tutorial>
            </section>

            <section>
               <head>Orienting yourself—projects and working directories</head>
               <slide>
                  <p><emph>Projects</emph> are a way of organizing your work in RStudio. We will be
                     using a <q>WordVectors</q> project throughout this seminar. </p>
                  <p>The <emph>working directory</emph> is the starting point for your interactions
                     with the files and folders in your RStudio workspace. </p>
                  <figure>
                     <graphic height="600px" url="../../../_utils/gfx/working_directory.png"/>
                  </figure>

               </slide>
               <lectureNote>
                  <p>Now, we’ll cover two other important aspects of orienting ourselves in RStudio
                     Server. First: <term>projects</term> are a way to organize your workspace. They
                     establish which files you’re working with by default, and also can control some
                     settings. </p>
                  <p> When you’re first getting started, it can be helpful to start with a tested
                     environment where everything is already set up, so that you can focus on the
                     new things you’re learning, and not have too much unnecessary and potentially
                     confusing variation. As you get farther along, you’ll be comfortable with more
                     experimentation and flexibility. But, when you get started, it helps to have a
                     strong framework that lets you focus on essential tasks. </p>
                  <p> We’ve set up a <term>wordVectors</term> project that will serve as our
                     navigational framework. One of the things that the project controls is what’s
                     called our <term>working directory</term>. The working directory is essentially
                     the starting point for all of our interactions with the files we’ll be using. </p>
                  <p> To think metaphorically about this: imagine that I’m giving you directions
                     from my house to the playground. I might tell you to go south for a block, then
                     east for another block, and then south for one more block. And then you’re at
                     the playground! But, if you were starting at someone else’s house, the path
                     you’d have to take would be different. The starting place is really essential
                     for thinking about directions. In the same way, if you were working with these
                     files and you needed to get into the <q>novels</q> folder, you’d first need to
                     go down into the data folder, and from there into <q>novels</q>. You have to go
                     down two levels because of where your starting point is. If your working
                     directory were the <q>data</q> folder instead, you’d only go down one level. If
                     you were in <q>output</q> you’d need to go up a level and then down again. </p>
                  <p> There are some pragmatic implications of these points: <list>
                        <item>First, at the start of every session, you should open the WordVectors
                           project</item>
                        <item>Second, you should also check your working directory</item>
                        <item>If you hit an error, the very first thing you want to do is make sure
                           you have that project file open, since that is one of the likeliest
                           culprits for issues. </item>
                     </list></p>
               </lectureNote>
               <tutorial>
                  <p>Now, we’ll cover two other important aspects of orienting ourselves in RStudio
                     Server. First: <term>projects</term> are a way to organize your workspace. They
                     establish which files you’re working with by default, and also can control some
                     settings. In a nutshell, projects are the environment that your files and data live in.</p>
                  <p> When you’re first getting started, it can be helpful to start with a tested
                     environment where everything is already set up, so that you can focus on the
                     new things you’re learning, and not have too much unnecessary and potentially
                     confusing variation. As you get farther along, you’ll be comfortable with more
                     experimentation and flexibility. But, when you get started, it helps to have a
                     strong framework that lets you focus on essential tasks. </p>
                  <p> This walkthrough references a <term>wordVectors</term> project we have set up and which will serve as our
                     navigational framework. his initial project is available for you to download and work from on your own, if you would like to follow along more precisely.
                     One of the things that the project controls is what’s
                     called our <term>working directory</term>. The working directory is essentially
                     the starting point for all of our interactions with the files we’ll be using and should be thought of as the primary folder which holds our materials.</p>
                  <p> Your working directory has a designated pathway which allows the computer to navigate to it, and once the computer gets there, it can access
                     everything inside. Think of your working directory as a box filled with everything that you need to train your model.
                     Once the computer knows where the box is, it can unpack that box to find, for instance, the second box inside called <q>data</q> that has a bag inside labeled <q>novels</q>.
                     In order for the computer to find that bag of novels, it must first know where you've placed the outermost box (your working directory) and then it needs to find the <q>data</q> box within.
                     The better organized your working directory is, for instance relevant files are put together in their own boxes and labeled neatly, the easier it is for the computer to find things. 
                     This same logic is true in real life, as well. Locating a box in a cluttered environment will always be more difficult than one that is neatly organized.</p>
                  <p>
                     The starting location is also really essential for thinking about how the computer can find your files. If your working directory is a folder which contains 
                     a <q>data</q> folder and an <q>output</q> folder and you needed to get into the <q>novels</q> folder, you would first need to open the <q>data</q> folder, and from there
                     go into <q>novels</q>. You have to go
                     down two levels because of where your starting point is. If your working
                     directory were the <q>data</q> folder instead, you’d only go down one level. If
                     you were in <q>output</q> you’d need to go up a level (to return to the main working directory) and then down again. </p>
                  <p> There are some pragmatic implications of these points: <list>
                     <item>First, at the start of every coding session, you should open the WordVectors
                        project. Opening the project tells your computer what your coding environment is</item>
                     <item>Second, you should also check your working directory to verify that your computer is in the right location</item>
                     <item>If you hit an error, the very first thing you want to do is make sure
                        you have that project file open, since that is one of the likeliest
                        culprits for issues. </item>
                  </list></p>
               </tutorial>
            </section>

            <section>
               <head>Running code in RStudio</head>
               <slide>
                  <p>Within the Source pane:</p>
                  <list>
                     <item>Put your cursor within the line of code you want to run and hit
                           <q>Command + Enter</q> or <q>Control + Enter</q></item>
                     <item>Select the exact section of code you want to run and hit <q>Command +
                           Enter</q> or <q>Control + Enter</q></item>
                     <item>Hit the green <q>Play</q> triangle in the top-right to run all the code
                        in a segment</item>
                  </list>
                  <p>In the Console:</p>
                  <list>
                     <item>Type or paste in the code you want to run and hit <q>Enter</q></item>
                  </list>
                  <figure>
                     <graphic height="300px" url="../../../_utils/gfx/w2v_running-code.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>
                     <list>
                        <item>RMarkdown files have code chunks, which can contain multiple lines of
                           code</item>
                        <item>Sometimes you want to run the whole chunk, sometimes you want to run a
                           single line, or section of lines</item>
                        <item>If you just want to run a line of code from within an RMarkdown file
                           in the Source pane, put your cursor anywhere in that line and hit
                           command-enter or control-enter.</item>
                        <item>If you want to run a specific section of code, you can select the
                           section you want and hit command- or control-enter</item>
                        <item>If you want to run the whole chunk at once, you can hit the green
                           triangle on the right hand side. You can also run code directly in the
                           console, by typing or pasting it in and just hitting enter. </item>
                        <item>If you want to save the code for later, it’s better to type it into
                           the RMarkdown file, since that’s something you can save and come back to.
                           If you just want to run the code, it might be better to put that in the
                           console, so you’re not cluttering your actual file up with inscrutable
                           experiments and tests. </item>
                     </list>
                  </p>
               </lectureNote>
               <tutorial>
                  <p>
                     <list>
                        <item>RMarkdown files include a mixture of prose and code chunks, which can contain multiple lines of
                           code</item>
                        <item>Sometimes you want to run the whole chunk, sometimes you want to run a
                           single line, or section of lines</item>
                        <item>If you just want to run a line of code from within an RMarkdown file
                           in the Source pane, put your cursor anywhere in that line and hit
                           command-enter or control-enter.</item>
                        <item>If you want to run a specific section of code, you can select the
                           section you want and hit command- or control-enter</item>
                        <item>If you want to run the whole chunk at once, you can hit the green
                           triangle on the right hand side. You can also run code directly in the
                           console, by typing or pasting it in and just hitting enter. </item>
                        <item>If you want to save the code for later, it’s better to type it into
                           the RMarkdown file, since that’s something you can save and come back to.
                           If you just want to run the code, it might be better to put that in the
                           console, so you’re not cluttering your actual file up with inscrutable
                           experiments and tests. </item>
                     </list>
                  </p>
               </tutorial>
            </section>
            <section>
               <head>Functions</head>
               <slide>
                  <p><emph>Functions</emph> are pieces of code that accomplish a specific task. For
                     example, there are functions that can:</p>
                  <list>
                     <item>print out a string of text</item>
                     <item>add a set of numbers</item>
                     <item>check your working directory</item>
                  </list>
                  <p>The things that functions act on are called <emph>arguments</emph>. Arguments
                     are enclosed in parentheses, and sometimes also in quotation marks.</p>
                  <figure>
                     <graphic height="300px" url="../../../_utils/gfx/w2v_functions-arguments.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>So far, we’ve talked about running code, projects, and our working directories.
                     Now let’s talk about a couple more key concepts: functions and variables.</p>
                  <p> Functions are pieces of code in R that are designed to perform some specific
                     task. <list>
                        <item>Functions are like recipes that will convert one or more inputs into
                           some output. The inputs for functions—the things that the functions act
                           on—are called arguments. </item>
                        <item>For example, you might want to print out a string of text, or add a
                           set of numbers together, or check your working directory. There are
                           specific functions that can accomplish each of these things. </item>
                        <item>Functions have a precise syntax; you have the name of the function,
                           followed by the argument or arguments in parentheses. </item>
                     </list>
                  </p>
                  <p>For example, at the top of this slide we have the sum function being used to
                     add a set of numbers separated by commas. The second example shows the print
                     function to print out a string of text. Because this is a string, you’ll see
                     that it’s enclosed in quotation marks. <list>
                        <item>As this second example suggests, there’s a lot of potential for the
                           syntax to get more complicated, but that’s not something to focus on at
                           this point. </item>
                        <item>For now, it’s enough to remember that functions are bits of code that
                           perform specific tasks, and that they act on things that are called
                           arguments, which are enclosed in parentheses.</item>
                     </list>
                  </p>
               </lectureNote>
               <tutorial>
                  <p>So far, we’ve talked about running code, projects, and our working directories.
                     Now let’s talk about a couple more key concepts: functions and variables.</p>
                  <p> Functions are pieces of code in R that are designed to perform some specific
                     task. <list>
                        <item>Functions are like recipes that will convert one or more inputs into
                           some output. The inputs for functions—the things that the functions act
                           on—are called arguments. </item>
                        <item>For example, you might want to print out a string of text, or add a
                           set of numbers together, or check your working directory. There are
                           specific functions that can accomplish each of these things. </item>
                        <item>Functions have a precise syntax; you have the name of the function,
                           followed by the argument or arguments in parentheses. </item>
                     </list>
                  </p>
                  <p>For example, at the top of this slide we have the sum function being used to
                     add a set of numbers separated by commas. The second example shows the print
                     function to print out a string of text. Because this is a string, you’ll see
                     that it’s enclosed in quotation marks. <list>
                        <item>As this second example suggests, there’s a lot of potential for the
                           syntax to get more complicated, but that’s not something to focus on at
                           this point. </item>
                        <item>For now, it’s enough to remember that functions are bits of code that
                           perform specific tasks, and that they act on things that are called
                           arguments, which are enclosed in parentheses.</item>
                     </list>
                  </p>
               </tutorial>
            </section>

            <section>
               <head>Variables</head>
               <slide>
                  <p><emph>Variables</emph> are like containers for storing data. You create
                     variables by giving them names and assigning them values. </p>
                  <p> Variables are stored in what’s called <q>working memory,</q> which means that
                     they are saved for the length of your session, but not saved on your hard
                     drive.</p>
                  <p>To assign a value to a variable, you can use either <code>=</code> or
                        <code>&lt;-</code></p>
                  <figure>
                     <graphic height="300px" url="../../../_utils/gfx/w2v_variables.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>Our last key concept is <term>variables</term>. <list>
                        <item>Variables are like containers that you can use to store different
                           kinds of data. They’re a way of making your code more efficient, because
                           they let you <emph>define</emph> and name pieces of data or code that you
                           will need to reuse later. If you want to refer to the same thing multiple
                           times, which you often will, you can create a variable, give it a name,
                           and then refer back to it by that name anytime you need to.</item>
                        <item>When you create a variable, it is stored in what’s called
                              <term>working memory</term>. That means that it will exist for the
                           duration of your session, but it’s not saved to your hard drive. </item>
                        <item>The examples on this slide show what it looks like to create a
                           variable. You can either use an equal sign or a less-than sign combined
                           with a hyphen to make a little arrow. We prefer the latter option because
                           the equal sign is also used for other things.</item>
                        <item>You put the variable <term>name</term> on the left, and the
                              <term>value</term> on the right.</item>
                        <item>You can create many different kinds of variables: in these two
                           examples, we have a numeric variable and also a string of text. Because
                           the second example is a string, it is enclosed within quotation marks,
                           just as we saw with the print function above. </item>
                     </list></p>

               </lectureNote>
               <tutorial>
                  <p>Our last key concept is <term>variables</term>. <list>
                     <item>Variables are like containers that you can use to store different
                        kinds of data. They’re a way of making your code more efficient, because
                        they let you <emph>define</emph> and name pieces of data or code that you
                        will need to reuse later. If you want to refer to the same thing multiple
                        times, which you often will, you can create a variable, give it a name,
                        and then refer back to it by that name anytime you need to.</item>
                     <item>When you create a variable, it is stored in what’s called
                        <term>working memory</term>. That means that it will exist for the
                        duration of your session, but it’s not saved to your hard drive. </item>
                     <item>The examples on this slide show what it looks like to create a
                        variable. You can either use an equal sign or a less-than sign combined
                        with a hyphen to make a little arrow. We prefer the latter option because
                        the equal sign is also used for other things.</item>
                     <item>You put the variable <term>name</term> on the left, and the
                        <term>value</term> on the right.</item>
                     <item>You can create many different kinds of variables: in these two
                        examples, we have a numeric variable and also a string of text. Because
                        the second example is a string, it is enclosed within quotation marks,
                        just as we saw with the print function on the slide. </item>
                  </list></p>
                  
               </tutorial>
            </section>
         </sectionGrp>


         <sectionGrp>
            <head>Querying an Existing Model</head>
            <section>
               <head>Roadmap: querying an existing model</head>
               <slide>
                  <p>
                     <emph>Walkthrough file:</emph>
                     <q>Word Vectors Starter Queries</q>
                  </p>
                  <list>
                     <item>Open RStudio Server</item>
                     <item>Open the <q>WordVectors.RProj</q> project file</item>
                     <item>Check your working directory</item>
                     <item>Load in the packages you will need with the <code>library()</code>
                        function</item>
                     <item>Read in the model with the <code>read.vectors()</code> function</item>
                     <item>Start querying!</item>
                  </list>
               </slide>
               <lectureNote>
                  <p> Here’s a roadmap for querying an existing model: <list>
                        <item>First we open RStudio Server and then, as always, open the project
                           file and check our working directory.</item>
                        <item> Then, we’ll have a new step that will also be necessary at the start
                           of all our RStudio sessions: loading in the <q>packages</q> we’ll need
                           using the <code>library()</code> function</item>
                     </list></p>
                  <p> Packages are bundles of code, data, and documentation that let you access
                     additional functionalities in R. They essentially allow you to do more advanced
                     or specialized things than the ones you get for free from R.</p>
                  <p> This is kind of like if you have a Kitchenaid mixer. When you get the mixer,
                     it comes with about three basic attachments for things like dough or eggs. But,
                     if you want the grain mill, or the pasta sheet roller, or the fruit and
                     vegetable spiralizer, or the <q>food processor with commercial style dicing
                        kit</q>, you’re going to need to acquire those separately. </p>
                  <p> We didn’t need to do this earlier because we were doing some core tasks with
                     essential functions, basically the equivalent of beating dough for chocolate
                     chip cookies.</p>
                  <p> But now that we’ll be working with word2vec models, we’ll need to bring in a
                     few packages with more specialized capabilities.</p>
                  <p> Normally, you have to install packages before you use them, but we’ll be
                     working in RStudio Server, so the packages are pre-installed.</p>
                  <p> However, we still need to load them in with the <code>library()</code>
                     function at the start of each session.</p>
                  <p>Once we’ve done that prep work, we can load in a model file, with a new
                     function, called <code>read.vectors()</code>—we get this function from one of
                     the new packages we’ll be loading in. </p>
                  <p> And finally, we’re ready to query a model!</p>
                  <p> Before we show you how to run that code, let’s talk about some of the query
                     operations you can try. </p>
               </lectureNote>
               <tutorial>
                  <p> Here’s a roadmap for querying an existing model: <list>
                     <item>First we open RStudio and then, as always, open the project
                        file and check that our working directory is correct.</item>
                     <item> Our next step is also necessary at the start
                        of all our RStudio sessions: loading in the <q>packages</q> we’ll need
                        using the <code>library()</code> function</item>
                  </list></p>
                  <p> Packages are bundles of code, data, and documentation that let you access
                     additional functionalities in R. They essentially allow you to do more advanced
                     or specialized things than the ones you get for free from R.</p>
                  <p> This is kind of like if you have a Kitchenaid mixer. When you get the mixer,
                     it comes with about three basic attachments for things like dough or eggs. But,
                     if you want the grain mill, or the pasta sheet roller, or the fruit and
                     vegetable spiralizer, or the <q>food processor with commercial style dicing
                        kit</q>, you’re going to need to acquire those separately. </p>
                  <p> For basic, built-in functinos (like the print function) you don't need to bring in separate packages since those come pre-installed with RStudio in order
                     to perform core or basic tasks, basically the equivalent of beating dough for chocolate
                     chip cookies.</p>
                  <p> But now that we’ll be working with word2vec models, we’ll need to bring in a
                     few packages with more specialized capabilities.</p>
                  <p> Normally, packages have to be installed before you can use them. If you are working in RStudio Server, then these packages may already be pre-installed.</p>
                  <p> However, we still need to load them in with the <code>library()</code>
                     function at the start of each session. The packages may be installed, but RStudio isn't aware that they exist until you actually load them.</p>
                  <p>Once we’ve done that prep work, we can load in an existing model file, with a new
                     function, called <code>read.vectors()</code>—we get this function from one of
                     the new packages we’ll be loading in. </p>
                  <p> And finally, we’re ready to query a model!</p>
                  <p> Before we show you how to run that code, let’s talk about some of the query
                     operations you can try. </p>
               </tutorial>
            </section>
            <section>
               <head>Clusters</head>
               <slide>
                  <figure>
                     <graphic height="500px" url="../../../_utils/gfx/w2v_clustering3.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p> We’re using a specific clustering algorithm called <term>k-means</term>; this
                     method asks you to set a number of <term>centers</term> for locating the dense
                     semantic spaces in your model. You’re essentially saying: <said>find me
                           <emph>n</emph> many places where larger numbers of terms cluster
                        together</said> where you get to decide what <emph>n</emph> is. And, then
                     the algorithm iterates over your model, in each case doing a better job of
                     finding where those densely-populated centers are, and what terms are located
                     around them. </p>
                  <p> Then, you can ask to see the terms closest to some of those centers, to get a
                     sense of some meaningful domains for your corpus. In the Toolkit, you can
                     choose how many words to see, and also request different random selections of
                     clusters from the model.</p>
                  <p> Working directly on the code, there’s more you can control: the number of
                     centers, how many clusters to select and view, and how many words to see from
                     each of those clusters. </p>
               </lectureNote>
               <tutorial>
                  <p> For this walkthrough, we’re using a specific clustering algorithm called <term>k-means</term>; this
                     method asks you to set a number of <term>centers</term> for locating the dense
                     semantic spaces in your model. You’re essentially saying: <said>find me
                        <emph>n</emph> many places where larger numbers of terms cluster
                        together</said> where you get to decide what <emph>n</emph> is. And, then
                     the algorithm iterates over your model in order to determine where those densely-populated centers are, and what terms are located
                     around them, each iteration getting better and better at locating them. </p>
                  <p> Then, you can ask to see the terms closest to some of those centers, to get a
                     sense of some meaningful domains for your corpus. In the WWP Vector Toolkit, you can
                     choose how many words to see, and also request different random selections of
                     clusters from the model.</p>
                  <p> Working directly on the code, there’s more you can control: the number of
                     centers, how many clusters to select and view, and how many words to see from
                     each of those clusters. Each of these parameters is going to impact how the algorithm performs with your data, generating different results with each iteration.</p>
               </tutorial>
            </section>
            
            <section>
               <head>Closest to</head>
               <slide>
                  <figure>
                     <graphic height="500px"
                        url="../../../_utils/gfx/w2v_rstudio-sandbox-similarity.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>As we've seen, the words closest to a word in vector space are those with the
                     highest cosine similarities. They’re not necessarily synonyms but instead words
                     that the model predicts are likely to appear in the same contexts. And, indeed,
                     the closest words are often antonyms: think how often words like
                        <mentioned>good and evil</mentioned> or <mentioned>happy and sad</mentioned>
                     appear together. </p>
                  <p> Nobody would ever expect that <mentioned>tuesday</mentioned> is a synonym for
                        <mentioned>friday</mentioned>, but those two terms and the other days of the
                     week are especially likely to be used in similar ways, and in the same kinds of
                     places within your texts, so they have fairly high cosine similarities. </p>
                  <p> As a rough rule, any cosine over .5 is probably worth paying attention to.</p>
                  <p> All the examples here are coming from the regularized Women Writers Online
                     corpus. It’s likely that many of you will get similar results when you query
                     your own models if you look at the days of the week. If you do get different
                     results, that is probably telling you something interesting about your corpus.
                  </p>
               </lectureNote>
               <tutorial>
                  <p>As we've seen, the words closest to a word in vector space are those with the
                     highest cosine similarities. They’re not necessarily synonyms but instead words
                     that the model predicts are likely to appear in the same contexts. And, indeed,
                     the closest words are often antonyms: think how often words like
                     <mentioned>good and evil</mentioned> or <mentioned>happy and sad</mentioned>
                     appear together. </p>
                  <p> Nobody would ever expect that <mentioned>tuesday</mentioned> is a synonym for
                     <mentioned>friday</mentioned>, but those two terms and the other days of the
                     week are especially likely to be used in similar ways, and in the same kinds of
                     places within your texts, so they have fairly high cosine similarities. </p>
                  <p> As a rough rule, any cosine over .5 is probably worth paying attention to and is a good baseline for significance.</p>
                  <p> All the examples on the slide here are coming from the regularized Women Writers Online
                     corpus. It’s likely that many of you will get similar results when you query
                     your own models if you look at the days of the week. If you do get different
                     results, that is probably telling you something interesting about your corpus.
                     Performing these initial, baseline queries are a good method for determining if the model is performing as anticipated.
                  </p>
               </tutorial>
            </section>
            <section>
               <head>Addition</head>
               <slide>
                  <figure>
                     <graphic height="500px"
                        url="../../../_utils/gfx/w2v_rstudio-sandbox-addition.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>What’s great about vectors is that you can also do math with them, as we
                     explored a bit earlier. For example, you can add two or more terms together, to
                     amplify their semantic connections.</p>
                  <p> In this example, I’m adding oranges to grapes, to focus in on the
                        <mentioned>fruit</mentioned> meaning of the word.</p>
                  <p> If I switched to add <mentioned>oranges</mentioned> and
                        <mentioned>blue</mentioned> I would still get some fruits, but I would also
                     get more colors: for example, the Women Writers Online model has:
                        <mentioned>red</mentioned>, <mentioned>yellow</mentioned>, and
                        <mentioned>lilac</mentioned> which is also both a plant and a color.</p>
                  <p> This example only shows two terms, but it is often useful to add a much larger
                     number of terms together. If you’re looking at a complicated concept like
                        <q>the natural word, as distinct from human industry</q>, you can’t just
                     stick in <q>bird + tree</q> and really get at the complexity there, but a
                     larger number of terms would get you closer. </p>
               </lectureNote>
               <tutorial>
                  <p>One of the great strengths of working with word vectors, is that you can also do math with them, as we
                     explored a bit earlier. For example, you can add two or more terms together, to
                     amplify their semantic connections.</p>
                  <p> In this example on the slide, I’m adding oranges to grapes, to focus in on the
                     <mentioned>fruit</mentioned> meaning of the word.</p>
                  <p> If I switched to add <mentioned>oranges</mentioned> and
                     <mentioned>blue</mentioned> I would still get some fruits, but I would also
                     get more colors: for example, the Women Writers Online model has:
                     <mentioned>red</mentioned>, <mentioned>yellow</mentioned>, and
                     <mentioned>lilac</mentioned> which is also both a plant and a color.</p>
                  <p> This example only shows two terms, but it is often useful to add a much larger
                     number of terms together. If you’re looking at a complicated concept like
                     <q>the natural word, as distinct from human industry</q>, you can’t just
                     stick in <q>bird + tree</q> and really get at the complexity there, but a
                     larger number of terms would get you closer. </p>
               </tutorial>
            </section>
            <section>
               <head>Subtraction</head>
               <slide>
                  <figure>
                     <graphic height="500px"
                        url="../../../_utils/gfx/w2v_rstudio-sandbox-subtraction.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>Finally, you can also subtract vectors from each other. This can be really
                     helpful if you want to get at specific associations for words that have
                     multiple meanings. Or, if you’re looking for <q>this concept as distinct from
                        this other one,</q> such as <q>wealth as distinct from poverty</q>.</p>
                  <p> In this example, we’re subtracting <mentioned>books</mentioned> from
                        <mentioned>library</mentioned> to get at the library as a physical building,
                     which has associations with other kinds of buildings, especially public ones
                     like hotels, hospitals, palaces, and even spunging houses, which were sort of
                     like debtors prisons. </p>
                  <p> As you’ll see here, the cosine similarities are overall lower; that’s often
                     the case with subtraction. </p>
               </lectureNote>
               <tutorial>
                  <p>Finally, you can also subtract vectors from each other. This can be really
                     helpful if you want to get at specific associations for words that have
                     multiple meanings. Or, if you’re looking for <q>this concept as distinct from
                        this other one,</q> such as <q>wealth as distinct from poverty</q>.</p>
                  <p> In this example, we’re subtracting <mentioned>books</mentioned> from
                     <mentioned>library</mentioned> to get at the library as a physical building,
                     which has associations with other kinds of buildings, especially public ones
                     like hotels, hospitals, palaces, and even spunging houses, which were sort of
                     like debtors prisons. </p>
                  <p> As you’ll see here, the cosine similarities are overall lower; that’s often
                     the case with subtraction. </p>
               </tutorial>
            </section>

         </sectionGrp>



         <section>
            <head>Outline of Model Training in RStudio Server</head>

            <slide>
               <p>
                  <emph>Walkthrough file:</emph>
                  <q>Word Vectors Training, Querying, and Validation</q>
               </p>
               <p>Roadmap: training a new model</p>
               <list>
                  <item>Open RStudio Server</item>
                  <item>Open the <q>WordVectors.RProj</q> project file</item>
                  <item>Check your working directory</item>
                  <item>Load in the packages you will need with the <code>library()</code>
                     function</item>
                  <item>Upload the files you want to use</item>
                  <item>Define and run a function to read in your texts</item>
                  <item>Choose a name for your model and set up the variables you will need in
                     working with your model files</item>
                  <item>Combine your texts into a single file, then prepare the combined file with
                     the <code>prep_word2vec()</code> function</item>
                  <item>Set your parameters</item>
                  <item>Train the model!</item>
               </list>
               <p>See the <ref
                     target="https://github.com/NEU-DSG/wwp-public-code-share/blob/WordVectors/WordVectors/Model-Loading-and-Training.md"
                     >Model Loading &amp; Training Processes</ref> file for more details.</p>
            </slide>
            <lectureNote>
               <p>Here’s a roadmap for training a model.</p>
               <list>
                  <item>We’ll be working in a new walkthrough file: <title>Word Vectors Training,
                        Querying, and Validation.</title> The first four steps are familiar at this
                     point: opening RStudio Server, opening the project, checking the working
                     directory, then loading the packages.</item>
                  <item>Then, we need to upload the files that we want to use to our data folder;
                     this brings the files into our working space so we can access them, but it
                     doesn’t yet read them into the R session itself. That’s the next step.</item>
                  <item>We’ll create a new function that’s custom-built to read in files in a way
                     that is suited for the WordVectors package. When we run that function, it will
                     go to the folder you specify and actually read its contents into your R
                     session. At that point, the files aren’t just inside of a folder in your data
                     folder; they’re actually in your global environment, where they’ll stay for the
                     rest of your session. </item>
                  <item>The next step is to create a set of variables that you’ll use for working
                     with your model. We’ll talk about this more soon, but the short version is that
                     training a model will generate a few files for different versions of your
                     texts, as well as the model file itself. The code is set up so that you can
                     decide what to name your model, then create a set of variables based on that
                     name. That way, whenever you want to set up a new model, you only need to
                     define its name once, and that will get propagated out to all the related
                     files. </item>
                  <item>We then combine up our texts and run the <code>prep_word2vec</code> function
                     on them. That will default to lowercasing the texts and removing most
                     punctuation. There are also a few other things you can adjust, which we’ll
                     discuss later. </item>
                  <item> Finally, you can set your parameters, tweaking the knobs on that
                     metaphorical spaghetti machine, after which you’re ready to train the model.
                  </item>
               </list>
               <p>So, that’s a birds-eye view of model training; now let’s run through the full
                  process, starting with a pre-loaded sample folder with a small number of texts.
               </p>
            </lectureNote>
            <tutorial>
               <p>Here’s a roadmap for training a model.</p>
               <list>
                  <item>We're now going to switching over to a new walkthrough file in RStudio: <title>Word Vectors Training,
                     Querying, and Validation.</title> We recommend downloading and opening this project in RStudio if you want to follow along. The first four steps are familiar at this
                     point: opening RStudio Server, opening the project, checking the working
                     directory, then loading the packages.</item>
                  <item>Now, we need to upload the plain-text files that we want to use to our data folder;
                     this brings the files into our working space so we can access them, but it
                     doesn’t yet read them into the R session itself. That’s the next step.</item>
                  <item>We’ll create a new function that’s custom-built to read in files in a way
                     that is suited for the WordVectors package. When we run that function, it will
                     go to the folder you specify and actually read its contents into your R
                     session. At that point, the files aren’t just inside of a folder in your data
                     folder; they’re actually in your global environment, where they’ll stay for the
                     rest of your session. </item>
                  <item>The next step is to create a set of variables that you’ll use for working
                     with your model. We’ll talk about this more soon, but the short version is that
                     training a model will generate a few files for different versions of your
                     texts, as well as the model file itself. The code is set up so that you can
                     decide what to name your model, then create a set of variables based on that
                     name. That way, whenever you want to set up a new model, you only need to
                     define its name once, and that will get propagated out to all the related
                     files. </item>
                  <item>We then combine up our texts and run the <code>prep_word2vec</code> function
                     on them. That will default to lowercasing the texts and removing most
                     punctuation. There are also a few other things you can adjust, which we’ll
                     discuss later. </item>
                  <item> Finally, you can set your parameters, tweaking the knobs on that
                     metaphorical spaghetti machine, after which you’re ready to train the model.
                  </item>
               </list>
               <p>So, that’s a birds-eye view of model training; now let’s run through the full
                  process, starting with a pre-loaded sample folder with a small number of texts.
               </p>
            </tutorial>
         </section>

         <sectionGrp>
            <head>Model training detail</head>
            <section>
               <head>Loading your texts: process overview</head>
               <slide>
                  <p>
                     <emph>Walkthrough file:</emph>
                     <q>Word Vectors Training, Querying, and Validation</q>
                  </p>
                  <p>Now we will look in greater detail at how to load files into RStudio Server,
                     and prepare them for training.</p>
                  <list>
                     <item>Collect your texts and save them in a single folder as .txt files</item>
                     <item>Compress your folder</item>
                     <item>Upload the folder to RStudio Server, inside the <q>data</q> folder</item>
                     <item>Define the <code>readTextFiles()</code> function, and run it on the
                        folder you uploaded to read your files into R</item>
                     <item>Define a set of variables to name your model and its associated corpus
                        files</item>
                     <item>Combine your texts, then lowercase and remove punctuation with the
                           <code>prep_word2vec()</code> function</item>
                  </list>
               </slide>
               <lectureNote>
                  <p>Now that we have a sense of the overall steps involved in training a model,
                     let’s focus in on the processes for reading in your own corpora. </p>
                  <p> These instructions are designed for RStudio Server; if you’re working in
                     RStudio Desktop, you don’t need to compress your texts or upload them, just
                     move the folder with your texts into your <q>data</q> folder.</p>

                  <p> Here’s our roadmap for reading in texts of our own: <list>
                        <item>The first three steps outlined here are the ones that are new: the
                           other steps are ones that we just saw in the full view of the model
                           training process.</item>
                        <item> Our additional steps are: to collect the plain text files in a single
                           folder, compress that folder, and then upload it to RStudio
                           Server.</item>
                     </list> Let’s look at these steps in more detail before we get to the hands-on.
                  </p>
               </lectureNote>
               <tutorial>
                  <p>Now that we have a sense of the overall steps involved in training a model,
                     let’s focus in on the processes for reading in your own corpora. </p>
                  <p> These instructions are designed for RStudio Server; if you’re working in
                     RStudio Desktop, you don’t need to compress your texts or upload them, just
                     move the folder with your texts into your <q>data</q> folder.</p>
                  
                  <p> Here’s our roadmap for reading in texts of our own: <list>
                     <item>The first three steps outlined here are the ones that are new: the
                        other steps are ones that we just saw in the full view of the model
                        training process.</item>
                     <item> Our additional steps are: to collect the plain text files in a single
                        folder, compress that folder, and then upload it to RStudio
                        Server.</item>
                  </list> Let’s look at these steps in more detail before we get to the hands-on.
                  </p>
               </tutorial>
            </section>
            <section>
               <head>Step one: Collect your texts</head>
               <slide>
                  <p>Put all your texts in a single folder, either with each saved as a .txt file or
                     with all the texts in a single .txt file. Make sure not to use any spaces in
                     the folder name, and do not put your texts in any subfolders</p>
                  <figure>
                     <graphic height="400px" url="../../../_utils/gfx/w2v_input-corpus.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p> The first step is to collect your texts, thinking about all the considerations
                     we discussed earlier on what to include, how much to regularize, what to
                     correct, and so on. </p>
                  <p> The particular code we’re using requires that all the text be saved as .txt
                     files in a single folder. Saving everything as a single large text file will
                     work, but you don’t want any subfolders. </p>
                  <p> As a good general practice, you should make sure not to include any spaces in
                     the folder name. </p>
               </lectureNote>
               <tutorial>
                  <p> The first step is to collect your texts, thinking about all the considerations
                     we discussed earlier on what to include, how much to regularize, what to
                     correct, and so on. </p>
                  <p> The particular code we’re using requires that all the text be saved as .txt (plain-text)
                     files in a single folder. Saving everything as a single large text file will
                     work, but you don’t want any subfolders. </p>
                  <p> As a good general practice, you should make sure not to include any spaces in
                     the folder name. </p>
               </tutorial>
            </section>
            <section>
               <head>Step two: Compress your folder</head>
               <slide>
                  <p>On Macs: control-click and select <q>Compress</q></p>

                  <p>On Windows: right-click on the folder, select <q>Send to,</q> and then select
                        <q>Compressed (zipped) folder</q></p>
                  <figure>
                     <graphic height="450px" url="../../../_utils/gfx/w2v_compressing-corpus.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>The next step is to compress the folder, so it can be read in as a single file.
                     This process is different for Apple and Windows machines. </p>
               </lectureNote>
               <tutorial>
                  <p>The next step is to compress the folder, so it can be read in as a single file.
                     This process is different for Apple and Windows machines. </p>
               </tutorial>
            </section>
            <section>
               <head>Step three: Upload the folder</head>
               <slide>
                  <p>In RStudio Server, after you have opened the project, loaded the packages, and
                     checked your working directory:</p>

                  <p>Click into the <q>data</q> folder from the file browser pane in the
                     bottom-right and hit the <q>upload</q> button, then navigate to and upload the
                     file with your compressed folder. <emph>Make sure that you are in the data
                        folder before you upload the file</emph>.</p>
                  <figure>
                     <graphic height="400px"
                        url="../../../_utils/gfx/w2v_uploading-compressed-file.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>Next, we’ll go into RStudio Server and upload the folder. </p>
                  <p> The main thing here is to make sure that you’re in the <q>data</q> folder
                     before you do the upload. You can move the folder after you upload it, so it’s
                     not a major concern, but if you put the folder in a different location and
                     don’t notice, you’ll get an error message that could potentially be confusing. </p>
                  <p> When you upload the compressed folder, RStudio Server will automatically
                     expand it. </p>
               </lectureNote>
               <tutorial>
                  <p>Next, we’ll go into RStudio Server and upload the folder. </p>
                  <p> The main thing here is to make sure that you’re in the <q>data</q> folder
                     before you do the upload. You can move the folder after you upload it, so it’s
                     not a major concern, but if you put the folder in a different location and
                     don’t notice, you’ll get an error message that could potentially be confusing. </p>
                  <p> When you upload the compressed folder, RStudio Server will automatically
                     expand it. </p>
               </tutorial>
            </section>
            <section>
               <head>Step four: Read your files into R</head>
               <slide>
                  <p><emph>First</emph>, run the code to define a variable that indicates which
                     folder contains your files, <emph>then</emph> create a new function called
                        <code>readTextFiles()</code>. When you run this function, it will read the
                     files in and create a two-column <q>tibble</q> called <q>combinedTexts</q>,
                     with the name of each file in one column and the full contents of each file in
                     the other. (A <q>tibble</q> is a kind of data frame: an organized space where
                     data can be structured and viewed, a bit similar to a <q>table</q>.)</p>

                  <figure>
                     <graphic height="400px" url="../../../_utils/gfx/w2v_combinedTexts.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>In the RMD file, we’ll define a variable that points to the folder we just
                     uploaded, and then create the specialized function that will read our texts in.
                     When we run the function, we’ll get a <q>tibble</q> with two columns, as in the
                     screenshot here, one listing the names of each file and another where each row
                     contains the full text of every file in the folder. </p>
               </lectureNote>
               <tutorial>
                  <p>In the RMD file, we’ll define a variable that points to the folder we just
                     uploaded, and then create the specialized function that will read our texts in.
                     When we run the function, we’ll get a <q>tibble</q> with two columns, as in the
                     screenshot here, one listing the names of each file and another where each row
                     contains the full text of every file in the folder. </p>
               </tutorial>
            </section>
            <section>
               <head>Step five: Name your model and combine your texts</head>
               <slide>
                  <p>Choose a name that will clearly identify your model and then run the code that
                     will define a set of variables for: </p>
                  <list>
                     <item>The <q>input</q> file with the full contents of your corpus, excluding
                        file names, as a single .txt file</item>
                     <item>The <q>cleaned</q> file, lowercased and without punctuation</item>
                     <item>The model file itself (with a .bin extension) </item>
                  </list>
                  <figure>
                     <graphic height="150px" url="../../../_utils/gfx/w2v_model-variables.png"/>
                  </figure>
                  <p>Running the last line in this code block will create the <q>input</q> file,
                     comibining all of your texts in a single .txt file, without file names.</p>
               </slide>
               <lectureNote>
                  <p>The next block of code is where you supply a name for your model file and the
                     associated text files that are created during preparation and training. </p>
                  <p> You define a variable called <q>baseFile</q> and then use that to derive the
                     names and contents for: <list>
                        <item>an <q>input</q> file that contains all your texts combined into a
                           single .txt file,</item>
                        <item>a <q>cleaned</q> file, which is the one on which the
                              <code>prep_word2vec()</code> function has been run, and</item>
                        <item>the model file itself, which will end an a .bin extension </item>
                     </list></p>
                  <p>The final line in this code block is what creates that <q>input</q> file of
                     combined texts. </p>
               </lectureNote>
               <tutorial>
                  <p>The next block of code is where you supply a name for your model file and the
                     associated text files that are created during preparation and training. </p>
                  <p> You define a variable called <q>baseFile</q> and then use that to derive the
                     names and contents for: <list>
                        <item>an <q>input</q> file that contains all your texts combined into a
                           single .txt file,</item>
                        <item>a <q>cleaned</q> file, which is the one on which the
                           <code>prep_word2vec()</code> function has been run, and</item>
                        <item>the model file itself, which will end an a .bin extension </item>
                     </list></p>
                  <p>The final line in this code block is what creates that <q>input</q> file of
                     combined texts. </p>
               </tutorial>
            </section>
            <section>
               <head>Step six: Prepare your texts</head>
               <slide>
                  <p>Running <code>prep_word2vec</code> will lowercase your texts and remove most
                     punctuation. You can also choose to automatically combine commonly-occuring
                     bigrams or trigrams, like <q>united states</q> or <q>dunkin donuts</q>. </p>

                  <figure>
                     <graphic height="400px" url="../../../_utils/gfx/w2v_prepared-text-files.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>prep_word2vec is a built-in command that makes it possible to do some light
                     text cleaning within the R code itself. It’s far from the only way to prepare
                     texts, and you might find that you want to have more control over this part of
                     the process, or that you’d prefer to do the final text processing in a program
                     you’re used to working in. But, this is useful for our purposes because it’s
                     built right into the package we’re already using, and because the default text
                     preparation it does is likely to be applicable in most contexts.</p>
                  <p> That is, this command will lowercase all the text so that <q>Rabbit</q> and
                        <q>rabbit</q> are treated as the same token. Or, to put this another way, so
                     that it doesn’t matter whether words might happen to appear at the beginning of
                     sentences, in titles, or in other contexts that lead to capitalization. </p>
                  <p> This step also removes most punctuation. Notably, it does not remove
                     apostrophes, so contractions and possessives will remain unchanged, and
                     contractions will be treated as single tokens. It also leaves underscores,
                     which can be useful if you want to do any preprocessing on your texts to
                     combine up particular phrases, by replacing the spaces between words with
                     underscores.</p>
                  <p> Related to that last point, the command can also do some automatic recognition
                     of multiword phrases that represent a single concept—such as <q>united
                        states</q> or <q>dunkin donuts</q>—by looking for two- or three-word strings
                     that often appear together. In fact, there’s no limit for how many word strings
                     you can instruct the prep_word2vec function to try and recognize, but even 2 or
                     3 will get fairly mixed results in terms of accurately detecting words that
                     should be understood as a single token. </p>
                  <p> After that, your text is ready and you can adjust your parameters as needed
                     and train the model. </p>

               </lectureNote>
               <tutorial>
                  <p>prep_word2vec is a built-in command that makes it possible to do some light
                     text cleaning within the R code itself. It’s far from the only way to prepare
                     texts, and you might find that you want to have more control over this part of
                     the process, or that you’d prefer to do the final text processing in a program
                     you’re used to working in. But, this is useful for our purposes because it’s
                     built right into the package we’re already using, and because the default text
                     preparation it does is likely to be applicable in most contexts.</p>
                  <p> That is, this command will lowercase all the text so that <q>Rabbit</q> and
                     <q>rabbit</q> are treated as the same token. Or, to put this another way, so
                     that it doesn’t matter whether words might happen to appear at the beginning of
                     sentences, in titles, or in other contexts that lead to capitalization. </p>
                  <p> This step also removes most punctuation. Notably, it does not remove
                     apostrophes, so contractions and possessives will remain unchanged, and
                     contractions will be treated as single tokens. It also leaves underscores,
                     which can be useful if you want to do any preprocessing on your texts to
                     combine up particular phrases, by replacing the spaces between words with
                     underscores.</p>
                  <p> Related to that last point, the command can also do some automatic recognition
                     of multiword phrases that represent a single concept—such as <q>united
                        states</q> or <q>dunkin donuts</q>—by looking for two- or three-word strings
                     that often appear together. In fact, there’s no limit for how many word strings
                     you can instruct the prep_word2vec function to try and recognize, but even 2 or
                     3 will get fairly mixed results in terms of accurately detecting words that
                     should be understood as a single token. </p>
                  <p> After that, your text is ready and you can adjust your parameters as needed
                     and train the model. </p>
               </tutorial>
            </section>

         </sectionGrp>
         <section>
            <head>Exporting results from clusters and queries</head>

            <slide>
               <p>
                  <emph>Walkthrough file:</emph>
                  <q>Word Vectors Training, Querying, and Validation</q>
               </p>
               <p>First: run the code to export your query in RStudio Server</p>
               <figure>
                  <graphic height="175px" url="../../../_utils/gfx/w2v_export-query1.png"/>
               </figure>
               <p>Second: navigate to the export file in your <q>output</q> folder, select it, then
                  click on the <q>More</q> gear and choose <q>Export</q></p>
               <figure>
                  <graphic height="175px" url="../../../_utils/gfx/w2v_export-query2.png"/>
               </figure>
               <p>Third: Rename the file, if you would like, and then hit <q>Download</q></p>
               <figure>
                  <graphic height="175px" url="../../../_utils/gfx/w2v_export-query3.png"/>
               </figure>
            </slide>
            <lectureNote>
               <p>Before we turn to the hands-on practice, there’s one more skill to cover:
                  exporting the results of your queries. </p>
               <p> When we get to the RMD file, we’ll be using some code that’s set up to allow you
                  to export both queries and clusters. After you run the code, you’ll get a CSV file
                  with the results in your <q>output</q> folder. As a quick reminder, CSV (or comma
                  separated value) files are a plain text format for storing tabular data.</p>
               <p> If you’re working in RStudio Server, there’s one additional step after you run
                  the code: exporting the CSV files from RStudio Server onto your own computer. You
                  can select the file, then use the <q>Export</q> option to download it. After that,
                  you can open the file with any software you prefer for working with CSV files.
               </p>
            </lectureNote>
            <tutorial>
               <p>Before you try this out for yourself, there’s one more skill to cover:
                  exporting the results of your queries. </p>
               <p> When we get to the RMD file, we’ll be using some code that’s set up to allow you
                  to export both queries and clusters. After you run the code, you’ll get a CSV file
                  with the results in your <q>output</q> folder. As a quick reminder, CSV (or comma
                  separated value) files are a plain text format for storing tabular data.</p>
               <p> If you’re working in RStudio Server, there’s one additional step after you run
                  the code: exporting the CSV files from RStudio Server onto your own computer. You
                  can select the file, then use the <q>Export</q> option to download it. After that,
                  you can open the file with any software you prefer for working with CSV files.
               </p>
            </tutorial>
         </section>

         <sectionGrp>
            <head>Model training, preparation, and validation</head>
            <section>
               <head>Validation</head>
               <slide>
                  <p>
                     <emph>Walkthrough file:</emph>
                     <q>Word Vectors Training, Querying, and Validation</q>
                  </p>
                  <figure>
                     <graphic height="400px" url="../../../_utils/gfx/w2v_model-validation.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p> As we’ve just discussed, there are many different ways that researchers have
                     tried to answer the very important questions questions of: <list>
                        <item><q>are my corpus preparation and model training processes producing
                              acceptably consistent results?</q> and</item>
                        <item><q>does the model reflect a reasonable sense of reality and match what
                              I know to be true about my corpus?</q></item>
                     </list></p>
                  <p>What we’ll be showing now is a fairly minimalist testing process, but one that
                     should enable you to do an initial sniff test of your models’ performance and
                     consistency, while also illustrating some of the principles at stake behind
                     more robust testing methods. </p>
                  <p>The code we’ll be showing will enable you to define a set of word pairs that
                     you expect to have fairly high cosine similarities within your model. </p>
                  <p> When you run the code, your results will look a bit like this (depending on
                     which program you use to open the resulting file). You’ll see each of the word
                     pairs, along with their cosine similarity scores. These particular word pairs
                     are ones that are likely to be close in many different models, but you can
                     improve on these substantially! The code template provides a test set of word
                     pairs that is both very short and very generalized. You’ll get much better
                     results with a longer set of test terms, and ones that are specific to your
                     model. </p>

               </lectureNote>
               <tutorial>
                  <p> As we’ve just discussed, there are many different ways that researchers have
                     tried to answer the very important questions questions of: <list>
                        <item><q>are my corpus preparation and model training processes producing
                           acceptably consistent results?</q> and</item>
                        <item><q>does the model reflect a reasonable sense of reality and match what
                           I know to be true about my corpus?</q></item>
                     </list></p>
                  <p>What we’ll be showing now is a fairly minimalist testing process for validating your model, but one that
                     should enable you to do an initial sniff test of your models’ performance and
                     consistency, while also illustrating some of the principles at stake behind
                     more robust testing methods. </p>
                  <p>The code we’ll be showing will enable you to define a set of word pairs that
                     you expect to have fairly high cosine similarities within your model. </p>
                  <p> When you run the code, your results will look a bit like what is featured on the slide (depending on
                     which program you use to open the resulting file). You’ll see each of the word
                     pairs, along with their cosine similarity scores. These particular word pairs
                     are ones that are likely to be close in many different models, but you can
                     improve on these substantially! The code template provides a test set of word
                     pairs that is both very short and very generalized. You’ll get much better
                     results with a longer set of test terms, and ones that are specific to your
                     model. </p>
               </tutorial>
            </section>
            <section>
               <head>Setting up a testing folder</head>
               <slide>
                  <p>The validation code will run on all the .bin files in your working directory.
                     If you would like to test a smaller set of files, you can move them into a
                     subfolder and temporarily change your working directory to that folder.</p>
                  <p>Navigate into the <q>data</q> folder and select <q>New Folder</q>:</p>
                  <figure>
                     <graphic height="250px" url="../../../_utils/gfx/w2v_create-folder.png"/>
                  </figure>
                  <p>Give your new folder a name:</p>
                  <figure>
                     <graphic height="150px" url="../../../_utils/gfx/w2v_name-folder.png"/>
                  </figure>
                  <p>Select the file or files you want to move, then hit the gear icon and choose
                        <q>Move</q>:</p>
                  <figure>
                     <graphic height="150px" url="../../../_utils/gfx/w2v_move-file1.png"/>
                  </figure>
                  <p>Select the folder you created and hit <q>Choose</q>:</p>
                  <figure>
                     <graphic height="250px" url="../../../_utils/gfx/w2v_move-file2.png"/>
                  </figure>
                  <p>You can follow the last two steps to move the file back into the main
                        <q>data</q> folder later.</p>
               </slide>
               <lectureNote>
                  <p>Before we get to running the validation code, there’s an additional step we’ll
                     want to take: setting up a test folder that will contain only the models we
                     want to validate, and changing the working directory to that folder.</p>
                  <p> This is necessary because the validation code is designed to run on all the
                     files contained within the working directory, even those in subfolders.</p>
                  <p> If you forget or skip this step, that’s fine—you’ll just end up with a lot of
                     extra models in your test results and the code will take longer to run.</p>
                  <p> This slide shows the first two steps for setting up the test folder <list>
                        <item>First, create a new folder within your data folder and give it a name
                           like <q>testing</q></item>
                        <item> Then, select any model files you want to test and move them to the
                           folder you just created </item>
                     </list></p>
               </lectureNote>
               <tutorial>
                  <p>Before we get to running the validation code, there’s an additional step we’ll
                     want to take: setting up a test folder that will contain only the models we
                     want to validate, and changing the working directory to that folder.</p>
                  <p> This is necessary because the validation code is designed to run on all the
                     files contained within the working directory, even those in subfolders.</p>
                  <p> If you forget or skip this step, that’s fine—you’ll just end up with a lot of
                     extra models in your test results and the code will take longer to run.</p>
                  <p> This slide shows the first two steps for setting up the test folder <list>
                     <item>First, create a new folder within your data folder and give it a name
                        like <q>testing</q></item>
                     <item> Then, select any model files you want to test and move them to the
                        folder you just created </item>
                  </list></p>
               </tutorial>
            </section>
            <section>
               <head>Changing your working directory</head>
               <slide>
                  <p>The easiest way to change your working directory is first to run
                        <code>getwd()</code> and copy the file path from the Console. Then, you can
                     use <code>setwd()</code> and modify the file path to the directory you want to
                     choose. Just make sure to change the working directory back to <q>Word
                        Vectors</q> when you are done with testing!</p>
                  <table>
                     <row>
                        <cell>
                           <figure>
                              <graphic height="400px"
                                 url="../../../_utils/gfx/w2v_change-working-directory.png"/>
                           </figure>
                        </cell>
                        <cell>
                           <figure>
                              <graphic height="500px"
                                 url="../../../_utils/gfx/w2v_working_directory_validation.png"/>
                           </figure>
                        </cell>
                     </row>
                  </table>
               </slide>
               <lectureNote>
                  <p>Now, we have a folder with our specific files, and our next step is to change
                     the working directory temporarily to that folder. </p>
                  <p> The screenshots on the left show the code you can use to change your working
                     directory without losing track of where you are. <list>
                        <item>First, check your working directory with <code>getwd()</code>; this
                           will give you a file path that you can copy</item>
                        <item> Then, use <code>setwd()</code> to change the working directory to
                           your testing folder. You can paste in the file path you copied and then
                           use tab completion to navigate down to the folder you created.</item>
                        <item> Once you’ve changed the working directory, you can run as many tests
                           as you like, and they will only operate on the models you’ve selected for
                           testing</item>
                        <item> When you’re done, you can use the same tactic to change your working
                           directory back to the main folder.</item>
                        <item> Use <code>getwd()</code> to get a file path to copy, then use
                              <code>setwd()</code> and paste the file path in. This time, you’ll
                           delete the subfolders to choose the main <q>WordVectors</q> folder again. </item>
                        <item> Then, you can run <code>getwd()</code> one more time, just to confirm
                           that you’re back where you want to be. </item>
                     </list></p>
                  <p>The two images on the right show a before-and-after for what we’ll be doing in
                     this step. On the left, the working directory is <q>WordVectors</q> and the
                     model validation code will run on any of the model files in any of these
                     subfolders, including the data folder and anything it might contain. On the
                     right, we see the outcome of what happens when we use <code>setwd()</code> to
                     change to the testing folder. That becomes the working directory and the model
                     validation code will run only on the files in that folder. </p>
               </lectureNote>
               <tutorial>
                  <p>Now, we have a folder with the specific model files that we want to test out, and our next step is to change
                     the working directory temporarily to that folder. </p>
                  <p> The screenshots on the left show the code you can use to change your working
                     directory without losing track of where you are. <list>
                        <item>First, check your working directory with <code>getwd()</code>; this
                           will give you a file path that you can copy</item>
                        <item> Then, use <code>setwd()</code> to change the working directory to
                           your testing folder. You can paste in the file path you copied and then
                           use tab completion to navigate down to the folder you created.</item>
                        <item> Once you’ve changed the working directory, you can run as many tests
                           as you like, and they will only operate on the models you’ve selected for
                           testing</item>
                        <item> When you’re done, you can use the same tactic to change your working
                           directory back to the main folder.</item>
                        <item> Use <code>getwd()</code> to get a file path to copy, then use
                           <code>setwd()</code> and paste the file path in. This time, you’ll
                           delete the subfolders to choose the main <q>WordVectors</q> folder again. </item>
                        <item> Then, you can run <code>getwd()</code> one more time, just to confirm
                           that you’re back where you want to be. </item>
                     </list></p>
                  <p>The two images on the right show a before-and-after for what we’ll be doing in
                     this step. On the left, the working directory is <q>WordVectors</q> and the
                     model validation code will run on any of the model files in any of these
                     subfolders, including the data folder and anything it might contain. On the
                     right, we see the outcome of what happens when we use <code>setwd()</code> to
                     change to the testing folder. That becomes the working directory and the model
                     validation code will run only on the files in that folder. </p>
               </tutorial>
            </section>
            <section>
               <head>Exporting results</head>
               <slide>
                  <p>You can view the <q>results</q> table generated in the code at line 369 by
                     using the <code>View()</code> function or by clicking on <q>results</q> in your
                     Global Environment</p>
                  <p>If you would like to view the test results in another program, the last line of
                     code in this chunk will export <q>results</q> as a <q>comma separatead
                        value</q> (CSV) file.</p>
                  <p>Note that the default code assumes that you have an <q>output</q> folder in
                     your current working directory. If you run this when your working directory is
                     a folder that does not contain an <q>output</q> folder, you will get an
                     error.</p>
                  <figure>
                     <graphic height="200px" url="../../../_utils/gfx/w2v_test-results.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>The next-to-last line of code in this section will generate a table called
                        <q>results</q>, which you can view right in RStudio by using the
                        <code>view()</code> function or by clicking on <q>results</q> in your Global
                     Environment</p>
                  <p>You may also want to export this file and view it in another program; if so,
                     you can use the final line of code. You will likely want to update the file
                     name (the part before the <q>.csv</q> extension), and you should remember that
                     the code as it stands assumes that you have an <q>output</q> folder in your
                     current working directory.</p>
               </lectureNote>
               <tutorial>
                  <p>The next-to-last line of code in this section will generate a table called
                     <q>results</q>, which you can view right in RStudio by using the
                     <code>view()</code> function or by clicking on <q>results</q> in your Global
                     Environment</p>
                  <p>You may also want to export this file and view it in another program; if so,
                     you can use the final line of code. You will likely want to update the file
                     name (the part before the <q>.csv</q> extension), and you should remember that
                     the code as it stands assumes that you have an <q>output</q> folder in your
                     current working directory.</p>
               </tutorial>
            </section>

         </sectionGrp>







         <sectionGrp>
            <head>Exploration and analysis</head>
            <section>
               <head>Visualizing semantic spaces</head>
               <slide>
                  <p>
                     <emph>Walkthrough file:</emph>
                     <q>Word Vectors Visualization</q>
                  </p>
                  <p>Visualizations:</p>
                  <list>
                     <item>Can help provide a <q>bigger picture</q> sense of the interactions
                        between words in your corpus, and of the model as a whole</item>
                     <item>Make it possible to examine domains and conceptual spaces in your
                        model</item>
                     <item>Let you move away from the linear approach provided by lists of words and
                        their cosine similarities to think about your model in new ways</item>
                     <item>Can also be misleading! Make sure to try different terms and settings to
                        see how your results vary</item>
                  </list>
               </slide>
               <lectureNote>
                  <p>The goal of this session is to briefly share a few options for generating plots
                     with word vector models. One of the most useful capabilities that
                     visualizations provide is that they can offer new ways to see and think about
                     our data. As we’ve already observed, it can be hard to get a sense of the
                     wholeness of a model by reviewing individual lists of cosine similarities for
                     query terms.</p>
                  <p> The same is true for the conceptual spaces we are using models to explore: you
                     can add a lot of gendered terms together to try and get at the domain of
                        <q>nineteenth-century conceptions of femininity</q> but if the only tool you
                     have to examine those connections is a static list of terms and cosine
                     similarities, it can be hard to feel as if you’re really getting the full
                     picture. </p>
                  <p> Visualizations can also move us away from the tempting positivism engendered
                     through lists: we can get a sense of how words are in proximity to each other,
                     without getting caught up in whether they are seventh or eight on a list.</p>
                  <p> But, it’s also worth remembering that visualizations have a rhetoric of their
                     own, and that the choices you make in generating these plots can have a
                     dramatic impact on what they seem to be showing. For that reason, it’s
                     essential to vary your settings and query terms, and then evaluate how your
                     results change. </p>
               </lectureNote>
               <tutorial>
                  <p>The goal of this section of the walkthrough is to briefly share a few options for generating plots
                     with word vector models. One of the most useful capabilities that
                     visualizations provide is that they can offer new ways to see and think about
                     our data. As we’ve already observed, it can be hard to get a sense of the
                     wholeness of a model by reviewing individual lists of cosine similarities for
                     query terms.</p>
                  <p> The same is true for the conceptual spaces we are using models to explore: you
                     can add a lot of gendered terms together to try and get at the domain of
                     <q>nineteenth-century conceptions of femininity</q> but if the only tool you
                     have to examine those connections is a static list of terms and cosine
                     similarities, it can be hard to feel as if you’re really getting the full
                     picture. </p>
                  <p> Visualizations can also move us away from the tempting positivism engendered
                     through lists: we can get a sense of how words are in proximity to each other,
                     without getting caught up in whether they are seventh or eight on a list.</p>
                  <p> But, it’s also worth remembering that visualizations have a rhetoric of their
                     own, and that the choices you make in generating these plots can have a
                     dramatic impact on what they seem to be showing. For that reason, it’s
                     essential to vary your settings and query terms, and then evaluate how your
                     results change. </p>
               </tutorial>
            </section>
            <section>
               <head>Principal component analysis</head>
               <slide>
                  <p>One popular method of visualizing complex data is through principal component
                     analysis. <emph>Principal component analysis</emph> (PCA) is a method that
                     attempts to reduce the complexity in large data sets while keeping as much
                     information as possible about the variation in that data set. The goal is to
                     hone in on a small number of <q>principal components</q> that can still account
                     for the largest possible amount of variation in the original data. </p>
                  <p>Here’s a <emph>very</emph> simplified way of thinking about this. If you wanted
                     to classify the items below, how might you divide them up? Are there other
                     characteristics they possess that might not capture as much information about
                     the differences among the group as a whole? </p>
                  <figure>
                     <graphic height="350px" url="../../../_utils/gfx/w2v_pca-simplified.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>Several of the visualizations we’ll be demonstrating use principal component
                     analysis, usually abbreviated PCA. This is a powerful and flexible method that
                     is often used to simplify complex datasets and make it possible to discover
                     patterns and relationships in the data.</p>
                  <p> PCA is one of a set of methods designed for dimensionality reduction. We’ve
                     already seen another one: in the TSNE plot that produced the flattened word
                     cloud showing the most common words in a model. PCA is another approach for
                     taking something large and complex with many dimensions and reducing its
                     complexity in order to enable us as humans to understand and analyze it. </p>
                  <p> The core idea here is that the PCA reduces the dimensionality of complex
                     datasets by transforming a large number of variables into a smaller one that
                     can still contain most of the information in the larger dataset. That is, the
                     main goal of PCA is to reduce the number of variables while still preserving as
                     much information as possible. </p>
                  <p> This is an unsupervised machine learning method that identifies a set of
                        <q>principal components</q>: the first principal component can account for
                     the largest amount of variation, the second principal component accounts for
                     the next largest amount, and so on. </p>
                  <p> Here’s a very simplified way to think about how principal components operate.
                     Looking at this imaginary dataset, what might be the primary difference between
                     the items on the top and the ones on the bottom? What about the ones on the
                     left and the right? What are some other characteristics of these items that
                     might also be used to categorize them? </p>
                  <p> Of course, if we treat this dataset as one comprising elements that can be
                     primarily categorized as plants and animals, or as land or sea life, there’s a
                     lot of complexity we’ll lose. For example, some of these items are food for
                     humans, and others aren’t. Some have teeth and others don’t. They also vary
                     significantly in their sizes, their colors, and their geographic distributions.
                     All of that information is important! But, if we’re focused on organizing these
                     items by just two kinds of variables, those other types of information aren’t
                     going to cover as much of the variety in our data.</p>
                  <p> We really need to emphasize that this is a simplification, and that the
                     principal components won’t map neatly onto human concepts like <q>sea and land
                        life</q>. But, hopefully, this example can help to illuminate the key goal
                     of PCA: reducing variables without losing information. </p>
               </lectureNote>
               <tutorial>
                  <p>Several of the visualizations we’ll be demonstrating use principal component
                     analysis, usually abbreviated PCA. This is a powerful and flexible method that
                     is often used to simplify complex datasets and make it possible to discover
                     patterns and relationships in the data.</p>
                  <p> PCA is one of a set of methods designed for dimensionality reduction. We’ve
                     already seen another one: in the TSNE plot that produced the flattened word
                     cloud showing the most common words in a model. PCA is another approach for
                     taking something large and complex with many dimensions and reducing its
                     complexity in order to enable us as humans to understand and analyze it. </p>
                  <p> The core idea here is that the PCA reduces the dimensionality of complex
                     datasets by transforming a large number of variables into a smaller one that
                     can still contain most of the information in the larger dataset. That is, the
                     main goal of PCA is to reduce the number of variables while still preserving as
                     much information as possible. </p>
                  <p> This is an unsupervised machine learning method that identifies a set of
                     <q>principal components</q>: the first principal component can account for
                     the largest amount of variation, the second principal component accounts for
                     the next largest amount, and so on. </p>
                  <p> Here’s a very simplified way to think about how principal components operate.
                     Looking at this imaginary dataset, what might be the primary difference between
                     the items on the top and the ones on the bottom? What about the ones on the
                     left and the right? What are some other characteristics of these items that
                     might also be used to categorize them? </p>
                  <p> Of course, if we treat this dataset as one comprising elements that can be
                     primarily categorized as plants and animals, or as land or sea life, there’s a
                     lot of complexity we’ll lose. For example, some of these items are food for
                     humans, and others aren’t. Some have teeth and others don’t. They also vary
                     significantly in their sizes, their colors, and their geographic distributions.
                     All of that information is important! But, if we’re focused on organizing these
                     items by just two kinds of variables, those other types of information aren’t
                     going to cover as much of the variety in our data.</p>
                  <p> We really need to emphasize that this is a simplification, and that the
                     principal components won’t map neatly onto human concepts like <q>sea and land
                        life</q>. But, hopefully, this example can help to illuminate the key goal
                     of PCA: reducing variables without losing information. </p>
               </tutorial>
            </section>
            <section>
               <head>Visualization example 1: PCA plotting of closest terms</head>
               <slide>
                  <p>This PCA plot shows the words closest to: <q>dog</q>, <q>pig</q>, <q>horse</q>,
                        <q>cat</q>, <q>fish</q>, <q>goose</q>, <q>lion</q> and <q>tiger</q> in a
                     model trained on the regularized Women Writers Online corpus. </p>
                  <figure>
                     <graphic height="500px" url="../../../_utils/gfx/w2v_pca-animals-wwo.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>Now, we’ll go through three example plots, before demonstrating the code to
                     create them.</p>
                  <p> This first example shows the closest words to a set of animal-based query
                     terms plotted according to principal component analysis. </p>
                  <p> This example and all the ones that follow are for the regularized Women
                     Writers Online model.</p>
                  <p>
                     <list>
                        <item>Are there any observations you might be able to make about this plot? </item>
                        <item>What might we note about the words on the right hand side, those that
                           have higher scores for the first principal component? </item>
                        <item> Are there any clear differences between the words that have very high
                           or very low scores on the second principal component?</item>
                     </list>
                  </p>
               </lectureNote>
               <tutorial>
                  <p>Now, we’ll go through three example plots, before demonstrating the code to
                     create them.</p>
                  <p> This first example shows the closest words to a set of animal-based query
                     terms plotted according to principal component analysis. </p>
                  <p> This example and all the ones that follow are for the regularized Women
                     Writers Online model.</p>
                  <p>
                     <list>
                        <item>Are there any observations you might be able to make about this plot? </item>
                        <item>What might we note about the words on the right hand side, those that
                           have higher scores for the first principal component? </item>
                        <item> Are there any clear differences between the words that have very high
                           or very low scores on the second principal component?</item>
                     </list>
                  </p>
               </tutorial>
            </section>
            <section>
               <head>Visualization example 2: Exploring clusters with dendrograms</head>
               <slide>
                  <p><q>Dendrograms</q> make it possible to examine hierarchical clusters of
                     words.</p>
                  <p>This plot shows clusters for a set of the terms closest to: <q>dress</q>,
                        <q>lace</q>, <q>frock</q>, <q>silk</q>, and <q>hat</q> in the regularized
                     WWO corpus.</p>
                  <figure>
                     <graphic height="550px" url="../../../_utils/gfx/w2v-dendrogram.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>This next example demonstrates a <q>dendrogram</q>, or tree diagram. This is
                     showing levels of connectedness or closeness among a set of terms, organized
                     hierarchically. </p>
                  <p>To read the dendrogram, look at where different terms branch off from each
                     other. The more steps up the tree you need to go to find their branching point,
                     the farther away from each other they are. For example, <q>lace</q> and
                        <q>ribband</q> on the left only branch up one level, so they are quite
                     close.</p>
               </lectureNote>
               <tutorial>
                  <p>This next example demonstrates a <q>dendrogram</q>, or tree diagram. This is
                     showing levels of connectedness or closeness among a set of terms, organized
                     hierarchically. </p>
                  <p>To read the dendrogram, look at where different terms branch off from each
                     other. The more steps up the tree you need to go to find their branching point,
                     the farther away from each other they are. For example, <q>lace</q> and
                     <q>ribband</q> on the left only branch up one level, so they are quite
                     close.</p>
               </tutorial>
            </section>
            <section>
               <head>Visualization example 3: Comparing cosine similarities for word pairs</head>
               <slide>
                  <p>Comparing cosine similarities visually can make it easier to see overall
                     patterns in the relationships between words.</p>
                  <p>This plot shows the cosine similarities for the words closest to <q>happy</q>
                     and <q>sad</q> in the regularized WWO corpus.</p>
                  <figure>
                     <graphic height="550px" url="../../../_utils/gfx/w2v_happy-sad-wwo.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>This next example might look complicated, but it’s actually relying much more
                     directly on methods you’re already familiar with. This plots the terms closest
                     to a pair of query terms—in this case, happy and sad—according to their cosine
                     similarities.</p>
                  <p> For example, the word <q>accomplished</q> has a cosine similarity of around
                     0.5 relative to the word <q>happy</q> but a cosine similarity of almost zero
                     relative to <q>sad</q>. By contrast, the word <q>mournful</q> has a cosine
                     similarity of around 0.8 relative to <q>sad</q> and a cosine similarity of
                     around 0.3 relative to <q>happy</q>.</p>
                  <p> What’s particularly interesting are the words in the middle, those that are
                     fairly close to both terms: <q>wretched</q>, <q>unhappy</q>, <q>pleasing</q>,
                     and <q>miserable</q>. This helps to reinforce our awareness that close terms
                     aren’t necessarily synonyms, and also shows which words from this corpus’s
                     discourse around happiness are also used in contexts related to sadness, and
                     which terms aren’t. </p>
               </lectureNote>
               <tutorial>
                  <p>This next example might look complicated, but it’s actually relying much more
                     directly on methods you’re already familiar with. This plots the terms closest
                     to a pair of query terms—in this case, happy and sad—according to their cosine
                     similarities.</p>
                  <p> For example, the word <q>accomplished</q> has a cosine similarity of around
                     0.5 relative to the word <q>happy</q> but a cosine similarity of almost zero
                     relative to <q>sad</q>. By contrast, the word <q>mournful</q> has a cosine
                     similarity of around 0.8 relative to <q>sad</q> and a cosine similarity of
                     around 0.3 relative to <q>happy</q>.</p>
                  <p> What’s particularly interesting are the words in the middle, those that are
                     fairly close to both terms: <q>wretched</q>, <q>unhappy</q>, <q>pleasing</q>,
                     and <q>miserable</q>. This helps to reinforce our awareness that close terms
                     aren’t necessarily synonyms, and also shows which words from this corpus’s
                     discourse around happiness are also used in contexts related to sadness, and
                     which terms aren’t. </p>
               </tutorial>
            </section>
            <section>
               <head>Visualization example 4: Plotting terms associated with multiple
                  keywords</head>
               <slide>
                  <p>You may want to explore more complex word relationships for cases in which the
                     concepts you wish to examine are better expressed with more than two
                     keywords.</p>
                  <p>This example uses principal component analysis to plot the words closest to
                        <q>touch</q>, <q>taste</q>, <q>sight</q>, <q>smell</q> and <q>hearing</q> in
                     the regularized WWO corpus.</p>
                  <figure>
                     <graphic height="550px"
                        url="../../../_utils/gfx/w2v_plot_multiple_keywords.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>You might also find that it’s useful to look at relationships among more than
                     two terms. This example will let you plot the terms closest to multiple input
                     terms using principal component analysis.</p>
                  <p>As we’ve seen before, we focus on a subset of words that are closest in terms
                     of cosine similarity to a group of terms that we can choose. Then, we use
                     principal component analysis to plot these. This allows us to discover both how
                     our individual query terms relate to each other, and also patterns in the
                     relationships among their closely related terms.</p>
               </lectureNote>
               <tutorial>
                  <p>You might also find that it’s useful to look at relationships among more than
                     two terms. This example will let you plot the terms closest to multiple input
                     terms using principal component analysis.</p>
                  <p>As we’ve seen before, we focus on a subset of words that are closest in terms
                     of cosine similarity to a group of terms that we can choose. Then, we use
                     principal component analysis to plot these. This allows us to discover both how
                     our individual query terms relate to each other, and also patterns in the
                     relationships among their closely related terms.</p>
               </tutorial>
            </section>
            <section>
               <head>Visualization example 5: Plotting a conceptual domain across two
                  binaries</head>
               <slide>
                  <p>In a more complex example, we can query the words closest to a set of terms
                     related to clothing (e.g., <q>dress</q>, <q>frock</q>, <q>gown</q>,
                     <q>coat</q>, and <q>linen</q>) and then plot those against two axes for
                        <q>wealth</q> and <q>gender</q>.</p>
                  <p>This plot shows 300 words related to clothing mapped against two binary
                     vectors, one representing the distinction between wealth and poverty and
                     another representing the distinction between maleness and femaleness.</p>
                  <figure>
                     <graphic height="600px"
                        url="../../../_utils/gfx/w2v_clothing-wealth-gender-wwo.png"/>
                  </figure>
               </slide>
               <lectureNote>
                  <p>This last example is more complex. Here, we’re pulling out a set of terms
                     related to a conceptual domain, and then plotting those terms across two
                     binaries. </p>
                  <p> We’ve selected a group of terms related to clothing—words like <q>dress</q>,
                        <q>frock</q>, and <q>coat</q>—and then plotted these out in a space where
                     the vertical dimension relates to gender and the horizontal one to wealth. </p>
                  <p> We use multiple terms to establish each of the poles for our paired binaries,
                     just as we do for the clothing words. In this example, the terms related to the
                     concept of <q>poverty</q> are: <q>poor</q>, <q>poorer</q>, <q>poverty</q>, and
                        <q>indigence</q>. </p>
                  <p> We can see that the terms overall lean slightly toward maleness and wealth;
                     that’s a result of the input terms that we chose, and we could try adding to or
                     changing the query terms to see how the plot might vary. There are also some
                     interesting patterns that emerge for individual words. We get a sense of the
                     materials used to make expensive clothing for both women and men, such as
                     ermine, satin, and silks. We can also see that ribbons are more associated with
                     wealthy women but trimmings are more associated with wealthy men. Handkerchiefs
                     for women and shirts for men are interestingly wealth-neutral. </p>
                  <p> As these examples have hopefully shown, visualizations can open up very
                     productive opportunities for analyzing and exploring word vector models. </p>
               </lectureNote>
               <tutorial>
                  <p>This last example is more complex. Here, we’re pulling out a set of terms
                     related to a conceptual domain, and then plotting those terms across two
                     binaries. </p>
                  <p> We’ve selected a group of terms related to clothing—words like <q>dress</q>,
                     <q>frock</q>, and <q>coat</q>—and then plotted these out in a space where
                     the vertical dimension relates to gender and the horizontal one to wealth. </p>
                  <p> We use multiple terms to establish each of the poles for our paired binaries,
                     just as we do for the clothing words. In this example, the terms related to the
                     concept of <q>poverty</q> are: <q>poor</q>, <q>poorer</q>, <q>poverty</q>, and
                     <q>indigence</q>. </p>
                  <p> We can see that the terms overall lean slightly toward maleness and wealth;
                     that’s a result of the input terms that we chose, and we could try adding to or
                     changing the query terms to see how the plot might vary. There are also some
                     interesting patterns that emerge for individual words. We get a sense of the
                     materials used to make expensive clothing for both women and men, such as
                     ermine, satin, and silks. We can also see that ribbons are more associated with
                     wealthy women but trimmings are more associated with wealthy men. Handkerchiefs
                     for women and shirts for men are interestingly wealth-neutral. </p>
                  <p> As these examples have hopefully shown, visualizations can open up very
                     productive opportunities for analyzing and exploring word vector models. </p>
               </tutorial>
            </section>
         </sectionGrp>


      </presentation>
   </text>
</TEI>
