display_pca: Display PCA of Embeddings

Description Usage Arguments Value Examples

View source: R/visualize_embeddings.R

Description

Display a 2D PCA plot of a collection of embedding vectors.

Usage

1
2
3
4
5
6
display_pca(
  embedding_df,
  project_vectors = embedding_df,
  color_field = NULL,
  disambiguate_tokens = TRUE
)

Arguments

embedding_df

A tbl_df of embedding vectors; from the output of extract_features.

project_vectors

A tbl_df of embedding vectors to be used for calculating the PCA projection matrix. Defaults to embedding_df. This makes it possible to more consistently select the PCA "perspective", even as the set of vectors may change.

color_field

Character scalar; optional column name to assign to color aesthetic in the plot.

disambiguate_tokens

Logical; whether to append example and token index to the literal token for display purposes.

Value

A ggplot2 plot of the embedding vectors projected onto two principal axes.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
# assuming something like the following has been run:
# feats <- RBERT::extract_features(...) # See RBERT documentation
# Then:
feats$output %>%
    filter_layer_embeddings(layer_indices = 12L) %>%
    keep_tokens("[CLS]") %>%
    display_pca()

## End(Not run)

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