
Retrieve Token Embeddings
emb.RdRetrieve Token Embeddings
Arguments
- x
an embeddings object made by
load_embeddings()oras.embeddings()- newdata
a character vector of tokens
- drop
logical. If
TRUE(the default) and the result is one-dimensional (e.g. a single row), the output will be a (named) vector.- .keep_missing
logical. What should be done about items in
newdatathat are not present in the embeddings object? IfFALSE(the default), they will be ignored. IfTRUE, they will be returned asNA.
Details
Duplicated items in newdata will result in duplicated rows in the output.
If an item in newdata matches multiple rows in x, the last one will
be returned.
Value
Either an embeddings object with a row for each item in newdata, or, when
newdata is of length 1, a named numeric vector.
Examples
words <- c("happy", "sad")
texts_embeddings <- emb(glove_twitter_25d, words)
texts_embeddings
#> # 25-dimensional embeddings with 2 rows
#> dim_1 dim_2 dim_3 dim_4 dim_5 dim_6 dim_7 dim_8 dim_9 dim..
#> happy -1.23 0.48 0.14 -0.03 -0.65 -0.19 2.10 1.75 -1.30 -0.32 ...
#> sad 0.04 -0.19 0.44 -0.15 -0.60 0.05 1.47 0.14 -0.72 0.43 ...