frameR is an R package for measuring emphasis frames in political text using transformer-based sentence embeddings and cosine similarity. Rather than classifying sentences into frame categories, which measures frame salience, frameR measures the semantic association between issue-relevant discourse and theoretically specified frame categories. This operationalizes emphasis frames as the political communication literature conceptualizes them: as semantic links between a core issue and peripheral evaluative considerations.
The package implements a four-step pipeline: (1) embed a corpus with a sentence embedding model; (2) identify issue-relevant sentences by keyword matching, semantic similarity, or both; (3) specify theoretically motivated frame categories as keyword sets and embed them; and (4) measure frame strength as cosine similarity between issue discourse and frame keywords, with bootstrap uncertainty and permutation tests.
frameR is designed for cross-national and cross-lingual research. It accepts any model from the sentence-transformers library and includes utilities for adapting models to political text. The method is described in my working paper Frames as Semantic Associations: Measuring Emphasis Frames in Embedding Space.
Installation
# Install from GitHub
devtools::install_github("spenccorp/frameR")
# One-time Python setup (restart R when prompted)
library(frameR)
install_frameR()
Quick start
library(frameR)
model <- load_model()
sentences <- c("Immigrants take jobs from native workers.",
"Our culture and values are under threat.",
"Border security is essential for public safety.")
years <- c(2002, 2012, 2017)
embeddings <- embed_corpus(sentences, model)
topic_mask <- identify_topic_sentences(
sentences = sentences, embeddings = embeddings,
anchor_words = c("immigration", "immigrant"), model = model)
frames <- list(Economic = c("economy", "jobs", "welfare"),
Cultural = c("culture", "values", "identity"),
Security = c("crime", "border", "security"))
keyword_embeddings <- embed_keywords(frames, model)
results <- measure_frames(embeddings, topic_mask, keyword_embeddings,
periods = list(Early = 2002, Late = c(2012, 2017)), years = years)
plot(results)
Full documentation and examples are on GitHub.