filter_layer_embeddings: Filter and Combine Embedding Vectors

Description Usage Arguments Value Examples

View source: R/visualize_embeddings.R

Description

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.

Usage

1
filter_layer_embeddings(embedding_df, layer_indices = 12L, sum_fun = mean)

Arguments

embedding_df

A tbl_df of embedding vectors; the "output" component of extract_features.

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 .funs argument to summarize_at. By default, mean is used, but other functions are possible. If this parameter is given a NULL value, no summarizing will be done, and only the filtered tbl_df will be returned.

Value

The input tbl_df of embedding vectors, with the specified filtering and summarizing applied.

Examples

 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)

jonathanbratt/RBERTviz documentation built on June 19, 2021, 6:27 p.m.