Loads a previously saved embeddings matrix from an RDS file and attaches it to the corpus. Only embeddings for works present in the corpus are loaded; mismatches are reported.
The loaded embeddings replace any the corpus had, and so does the record
of their model (corpus$metadata$embedding, see sm_corpus()): the
cache's record when it describes the cached matrix, else none, so the
model of embeddings from an older cache or a bare matrix counts as not
recorded ("unknown" in sm_certificate()).
Usage
sm_embed_load(corpus, path, call = rlang::caller_env())Arguments
- corpus
An sm_corpus object.
- path
Character; file path to read embeddings from (an
.rdsfile created bysm_embed_save()).- call
Caller environment for error reporting.
Value
The input corpus with corpus$embeddings and
corpus$metadata$embedding updated. Works without a cached row get no
row, so the clustering functions give them no cluster (NA).
See also
Other embedding:
sm_embed_save(),
sm_embed_works()
Examples
path <- tempfile(fileext = ".rds")
sm_embed_save(sm_example_corpus(with_embeddings = TRUE), path)
#> ✔ Embeddings saved to /tmp/RtmpicujyO/file1c54544723b5.rds.
#> ℹ 200 works x 64 dimensions, embeddings whose model is not recorded.
corpus <- sm_example_corpus(with_embeddings = FALSE)
corpus <- sm_embed_load(corpus, path)
#> ✔ Embeddings loaded: 200 works x 64 dimensions.
#> ℹ These are embeddings whose model is not recorded.
dim(corpus$embeddings)
#> [1] 200 64
unlink(path)