Dr. Jiang and I discussed trying to create a makerspace dictionary/lexicon for my final project. I decided to use this week’s Independent Analysis project to start exploring dictionary creation and how it might tie into some of the other text analysis techniques we’ve been practicing. The first part of this analysis will explain what I’ve found and tested so far for my dictionary creation project, which I plan to use on both my MakerFest dataset (local to BeAM) and my ISAM Papers dataset (international conference.) In the second part, I will test out bigram and word net analysis on the ISAM Papers dataset.
From my initial literature review, this is a complicated process that doesn’t exactly have a great ‘how-to’ guide. For example, I mentioned Chris Bail’s “Dictionary-Based Text Analysis” video in the discussion forum. I went back and watched the video again, new shiny RMD file at the ready to walk through the steps of creating a makerspace dictionary. However, I quickly realized that he was explaining at a very zoomed-out level, to give a general overview of dictionary creation, and that video would not be a strong enough reference for me to generate my own dictionary.
After searching a bit more, I managed to find a 2019 paper written by three Psychology researchers from Princeton (‘AutomatedDictionaryCreationForTextAnalysis’ in the ‘From SADCAT’ folder). I did a little bit of digging, and found out a little bit more about the authors. The primary author is Gandalf Nicolas, who was a postdoc at Princeton at the time, but has since moved on to Rutgers as a professor. Xuechunzi Bai is listed as a current graduate student at Princeton and an advisee to the final author, Susan Fiske. This seemed like a trustworthy place to start based on the authors’ credentials, especially since I don’t have a lot of other sources to go off of.
The authors created a public GitHub for their project, which was originally named Automated Dictionary Creation for Text Analysis (ADCAT), but seems to have been renamed to ‘SADCAT’ at some point. They mention an existing SADCAT r package and provided the code below, but I can’t seem to remotely install it so I’m going to look into that another day. In the meantime, I downloaded all of the RMD files from GitHub and have been combing through them to start building my own how-to guide. (These RMD files are all stored in the ‘From SADCAT’ folder.)
#install.packages("devtools")
#library(devtools)
#install_github("gandalfnicolas/SADCAT")
#library(SADCAT)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.1 ✔ purrr 1.0.1
## ✔ tibble 3.1.8 ✔ dplyr 1.1.0
## ✔ tidyr 1.3.0 ✔ stringr 1.5.0
## ✔ readr 2.1.4 ✔ forcats 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(tidytext)
library(dplyr)
library(ggplot2)
library(SnowballC)
library(topicmodels)
library(stm)
## stm v1.3.6 successfully loaded. See ?stm for help.
## Papers, resources, and other materials at structuraltopicmodel.com
library(ldatuning)
library(knitr)
library(LDAvis)
library(tidyr)
library(igraph)
##
## Attaching package: 'igraph'
##
## The following objects are masked from 'package:dplyr':
##
## as_data_frame, groups, union
##
## The following objects are masked from 'package:purrr':
##
## compose, simplify
##
## The following object is masked from 'package:tidyr':
##
## crossing
##
## The following object is masked from 'package:tibble':
##
## as_data_frame
##
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
##
## The following object is masked from 'package:base':
##
## union
library(ggraph)
Based on what I’ve read, particularly starting on p.16 of the article, my first step is to assemble a seed dictionary with the following columns: dictionary, term, PoS (part of speech), sense, and direction. I won’t spend too much time on generating this document for this Independent Analysis, but I do want to at least get a document started using the ‘Seed Dictionaries.csv’ document in the ‘From SADCAT’ folder as a template.
For my ‘Dictionary’ column right now, I’ll draw categories from the UTA Maker Competencies (there are 10 of them, but I’ll just use the first one for now - “identify a need to create,” which I’ll label “identify”.) I’ll populate the ‘term’ column with some of the salient terms pulled from each of the competency description. I’ll create the PoS/sense/direction columns, but from what I understand from my reading, the researchers generated those values through Wordnet (which does have an R package!)
Dictionary <- c('Identify')
Term <- c('articulate', 'recognize', 'need', 'solve', 'evaluate', 'tinker', 'hack', 'isolate', 'issue', 'focus')
maker.dictionary <- data.frame(Dictionary, Term, stringsAsFactors=FALSE) %>%
add_column(PoS = NA, Sense = NA, Direction = NA)
maker.dictionary
## Dictionary Term PoS Sense Direction
## 1 Identify articulate NA NA NA
## 2 Identify recognize NA NA NA
## 3 Identify need NA NA NA
## 4 Identify solve NA NA NA
## 5 Identify evaluate NA NA NA
## 6 Identify tinker NA NA NA
## 7 Identify hack NA NA NA
## 8 Identify isolate NA NA NA
## 9 Identify issue NA NA NA
## 10 Identify focus NA NA NA
Okay, we’re on the right track. I’m going to take a break from this project and switch to my other task - performing bigram and word net analysis on my ISAMPapers dataset.
ISAMPapers <- read.csv("~/RStudioProjects/Data/ISAMPapers.csv")
ISAMPaperBigrams <- ISAMPapers %>%
unnest_tokens(bigram, Text, token = "ngrams", n = 2)
bigrams_separated <- ISAMPaperBigrams %>%
separate(bigram, c("word1", "word2"), sep = " ")
my_stopwords <- c("abstract", "introduction", "fig", "1", "2", "3", "4","5","6", "7", "8", "9", "0", "10", "11")
bigrams_filtered <- bigrams_separated %>%
filter(!word1 %in% stop_words$word) %>%
filter(!word2 %in% stop_words$word) %>%
filter(!word1 %in% my_stopwords) %>%
filter(!word2 %in% my_stopwords)
bigram_counts <- bigrams_filtered %>%
count(word1, word2, sort = TRUE)
bigrams_united <- bigram_counts %>%
unite(bigram, word1, word2, sep = " ") %>%
mutate(bigram_counts, ID = row_number()) %>%
select(bigram, ID, n)
bigrams_united$bigram[1]
## [1] "maker movement"
bigrams_united$bigram[2]
## [1] "academic makerspaces"
Neat! It’s not surprising that “maker movement” and “academic makerspaces” are two of the most used bigrams at an academic makerspace conference, but it’s cool to see it confirmed. Now let’s start seeing if we can visualize the word networks in the ISAM Papers dataset. My first time around, I filtered n>1 and got several thousand edges, so I fiddled with my n value until I got the edges down to a number that seemed more reasonable (37 edges.)
bigram_graph_filtered <- bigram_counts %>%
filter(n > 40) %>%
graph_from_data_frame()
bigram_graph_filtered
## IGRAPH 0dea015 DN-- 49 37 --
## + attr: name (v/c), n (e/n)
## + edges from 0dea015 (vertex names):
## [1] maker ->movement academic ->makerspaces 3d ->printing
## [4] 3d ->printers invention ->studio design ->thinking
## [7] laser ->cutter academic ->makerspace maker ->based
## [10] fab ->lab maker ->space data ->collection
## [13] maker ->education 3d ->printer ccc ->maker
## [16] graduate ->students learning ->outcomes mechanical ->engineering
## [19] movement ->elements design ->process academic ->library
## [22] engineering->students library ->makerspaces student ->staff
## + ... omitted several edges
There we go! Now instead of crashing my computer trying to graph thousands of edges onto the same network graph, we get a much more reasonably graph of the edges. I kept the arrows in because I like seeing the directionality. For example, note the one-way arrow from fab to lab - you would never call a makerspace a labfab!
set.seed(100)
a <- grid::arrow(type = "open", length = unit(.2, "inches"))
ggraph(bigram_graph_filtered, layout = "fr") +
geom_edge_link(aes(edge_alpha = n), show.legend = FALSE,
arrow = a, end_cap = circle(.05, 'inches')) +
geom_node_point(color = "purple",
size = 3) +
geom_node_text(aes(label = name), vjust = 1, hjust = 1) +
theme_void()
## Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.
There were a few other things that I found interesting in the Chris Bail video that I wanted to try out before I wrap up this analysis. First was a visualization he used that I liked the look of and wanted to replicate.
bigrams_united %>%
slice(1:20) %>%
ggplot(aes(x=reorder(bigram, -n), y=n, fill=bigram))+
geom_bar(stat="identity")+
theme_minimal()+
theme(axis.text.x =
element_text(angle = 60, hjust = 1, size = 13))+
theme(plot.title =
element_text(hjust = 0.5, size=18))+
ylab("Frequency")+
xlab("")+
ggtitle("Most Frequent Bigrams in ISAM Papers")+
guides(fill=FALSE)
## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
## of ggplot2 3.3.4.
Second was his use of Inverse Document Frequency to look at the most unusual words. I want to see if I can find the most unusual bigrams using the same method.
tfidf_ISAMPapers <- bigrams_united %>%
bind_tf_idf(ID, bigram, n)
top_tfidf<-tfidf_ISAMPapers %>%
arrange(desc(tf_idf))
top_tfidf$word[1]
## NULL
top_tfidf$word[2]
## NULL
Hmm, nope! It doesn’t seem to like that. I’m sure there’s a piece missing or something I haven’t learned yet, so I’ll move on. Let’s try running it on a unigram version of ISAMPapers.
my_stopwords <- c("abstract", "introduction", "fig", "1", "2", "3", "4","5","6", "7", "8", "9", "0", "10", "11")
tfidf_ISAMPapers2 <- ISAMPapers %>%
select(ID,Text) %>%
unnest_tokens("word", Text) %>%
anti_join(stop_words) %>%
filter(!word %in% my_stopwords) %>%
count(word, ID) %>%
bind_tf_idf(word, ID, n)
## Joining with `by = join_by(word)`
top_tfidf2<-tfidf_ISAMPapers2 %>%
arrange(desc(tf_idf))
top_tfidf2$word[1]
## [1] "hyflex"
top_tfidf2$word[2]
## [1] "f2f"
Interesting. It looks like the top two are ‘hyflex’ and ‘f2f’, both of which I immediately interpret as relative to discussions about flexible learning environments in the COVID era.