Extract layers and aggregate them to word embeddings, for all character variables in a given dataframe.

textEmbed(
x,
model = "bert-base-uncased",
layers = 11:12,
contexts = TRUE,
context_layers = layers,
context_aggregation_layers = "concatenate",
context_aggregation_tokens = "mean",
context_tokens_select = NULL,
context_tokens_deselect = NULL,
decontexts = TRUE,
decontext_layers = layers,
decontext_aggregation_layers = "concatenate",
decontext_aggregation_tokens = "mean",
decontext_tokens_select = NULL,
decontext_tokens_deselect = NULL
)

## Arguments

x A character variable or a tibble/dataframe with at least one character variable. Character string specifying pre-trained language model (default 'bert-base-uncased'). For full list of options see pretrained models at HuggingFace. For example use "bert-base-multilingual-cased", "openai-gpt", "gpt2", "ctrl", "transfo-xl-wt103", "xlnet-base-cased", "xlm-mlm-enfr-1024", "distilbert-base-cased", "roberta-base", or "xlm-roberta-base". Specify the layers that should be extracted (default 11:12). It is more efficient to only extract the layers that you need (e.g., 12). Layer 0 is the decontextualized input layer (i.e., not comprising hidden states) and thus advised to not use. These layers can then be aggregated in the textEmbedLayerAggregation function. If you want all layers then use 'all'. Provide word embeddings based on word contexts (standard method; default = TRUE). Specify the layers that should be aggregated (default the number of layers extracted above). Layer 0 is the decontextualized input layer (i.e., not comprising hidden states) and thus advised not to be used. Method to aggregate the contextualized layers (e.g., "mean", "min" or "max, which takes the minimum, maximum or mean, respectively, across each column; or "concatenate", which links together each word embedding layer to one long row. Method to aggregate the contextualized tokens (e.g., "mean", "min" or "max, which takes the minimum, maximum or mean, respectively, across each column; or "concatenate", which links together each word embedding layer to one long row. Option to select word embeddings linked to specific tokens such as [CLS] and [SEP] for the context embeddings. Option to deselect embeddings linked to specific tokens such as [CLS] and [SEP] for the context embeddings. Provide word embeddings of single words as input (embeddings, e.g., used for plotting; default = TRUE). Layers to aggregate for the decontext embeddings the number of layers extracted above. Method to aggregate the decontextualized layers (e.g., "mean", "min" or "max, which takes the minimum, maximum or mean, respectively, across each column; or "concatenate", which links together each word embedding layer to one long row. Method to aggregate the decontextualized tokens (e.g., "mean", "min" or "max, which takes the minimum, maximum or mean, respectively, across each column; or "concatenate", which links together each word embedding layer to one long row. Option to select embeddings linked to specific tokens such as [CLS] and [SEP] for the decontext embeddings. option to deselect embeddings linked to specific tokens such as [CLS] and [SEP] for the decontext embeddings.

## Value

A tibble with tokens, a column for layer identifier and word embeddings. Note that layer 0 is the input embedding to the transformer

see textEmbedLayerAggregation and textEmbedLayersOutput
# \donttest{
comment(wordembeddings$satisfactionwords)#> [1] "Information about the embeddings. textEmbedLayersOutput: model: bert-base-uncased layers: 9 10 11 . textEmbedLayerAggregation: layers = 11 aggregate_layers = concatenate aggregate_tokens = mean tokens_select = tokens_deselect = "comment(wordembeddings$singlewords_we)#> [1] "Information about the embeddings. textEmbedLayersOutput:  bert-base-uncased layers: 9 10 11 . textEmbedLayerAggregation: layers =  9 aggregate_layers =  concatenate aggregate_tokens =  mean tokens_select =   tokens_deselect =  "comment(wordembeddings)#> [1] "Duration to embed text: 20.362975 secs; Date created: 2021-04-22 14:59:37"# Example 2
# }
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.15210464596748352, "perplexity": 11088.891039488226}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-21/segments/1620243988882.94/warc/CC-MAIN-20210508151721-20210508181721-00561.warc.gz"}