Description Usage Arguments Value Examples
View source: R/visualize_embeddings.R
Applies a filter + summarize to the given table of embeddings. Can be used to filter to specific layer outputs, or to average the outputs from multiple layers.
1 | filter_layer_embeddings(embedding_df, layer_indices = 12L, sum_fun = mean)
|
embedding_df |
A tbl_df of embedding vectors; the "output" component of
|
layer_indices |
Integer vector; which layers embeddings to keep. |
sum_fun |
A summarizing function to apply to the embedding vector
components of the retained layers. Will be passed as the |
The input tbl_df of embedding vectors, with the specified filtering and summarizing applied.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ## Not run:
# assuming something like the following has been run:
# feats <- RBERT::extract_features(...) # See RBERT documentation
# Then:
embeddings <- feats$output
embeddings_layer1 <- embeddings %>%
filter_layer_embeddings(layer_indices = 1L)
# To keep the layer_index column, use sum_fun = NULL:
embeddings_layer1b <- embeddings %>%
filter_layer_embeddings(layer_indices = 1L, sum_fun = NULL)
# Take the component-wise mean of the embeddings across layers 10-12.
embeddings_layer_mean <- embeddings %>%
filter_layer_embeddings(layer_indices = 10:12)
# Take the component-wise maximum of the embeddings across layers 8-12.
# (Why would we do this? I don't know.)
embeddings_layer_max <- embeddings %>%
filter_layer_embeddings(layer_indices = 8:12, sum_fun = max)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.