Embedding-based pairwise construct-redundancy screen
Source:R/embedding.R
tf_embedding_redundancy.RdFor every unordered pair of constructs, embeds each definition with the
supplied embedder and computes the cosine similarity (rounded to 6
decimals). Returns a data frame sorted by descending cosine then
(a, b), flagging pairs at or above threshold for review. This
assistive screen complements the deterministic lexical
tf_redundancy_check(), and its results are only as reproducible as the
supplied embedder.
Arguments
- theory
A theory object (named list), e.g. from
tf_read().- embedder
A function mapping a definition string to a numeric vector.
- threshold
Cosine threshold for the
"review"flag; defaults to the checklist'sredundancy_similarity_max.
Examples
theory <- tf_theory("demo-1", "A demonstration theory") |>
tf_add_construct("c_arousal", "Arousal", "bodily activation") |>
tf_add_construct("c_threat", "Threat", "appraised danger")
# A toy deterministic embedder: bag-of-words counts over a fixed vocabulary.
vocab <- c("bodily", "activation", "appraised", "danger")
embedder <- function(def) {
words <- strsplit(tolower(def), "\\s+")[[1]]
vapply(vocab, function(w) sum(words == w), numeric(1))
}
tf_embedding_redundancy(theory, embedder)
#> a b cosine flag
#> 1 c_arousal c_threat 0 ok