Write a list of individual embeddings to a CSV file
write_embedding_list.RdConverts a named list of embedding matrices — as returned by the
$individual element of run_embeddings_from_list — into
a flat CSV file with one row per item per participant.
Arguments
- embedding_list
A named list of numeric matrices, one per participant. Each matrix must have item names as row names and embedding dimension columns named
dim_0,dim_1, etc. This is the format of the$individualelement returned byrun_embeddings_from_list.- file
Path to the output CSV file. The parent directory must already exist.
Output format
The CSV has one row per (participant, item) combination and the following columns:
worker_idParticipant identifier, taken from the names of
embedding_list.itemItem name, taken from the row names of each matrix.
dim_0,dim_1, …Embedding coordinates. Column names are taken directly from the column names of each matrix.
Examples
if (FALSE) { # \dontrun{
results <- run_embeddings_from_list(
triplet_list = icon_triplets,
output_dir = "embeddings_output",
d = 3L
)
# Write individual embeddings to a single flat CSV
write_embedding_list(results$individual, "embeddings_individual.csv")
# Read back and reconstruct the named list
df <- read.csv("embeddings_individual.csv")
dim_cols <- grep("^dim_", names(df), value = TRUE)
embedding_list <- lapply(
split(df, df$worker_id),
function(sub) {
m <- as.matrix(sub[, dim_cols])
row.names(m) <- sub$item
m
}
)
} # }