starspace_load_model: Load a Starspace model

View source: R/embed-all-the-things.R

starspace_load_modelR Documentation

Load a Starspace model

Description

Load a Starspace model

Usage

starspace_load_model(
  object,
  method = c("ruimtehol", "tsv-data.table", "binary"),
  ...
)

Arguments

object

the path to a Starspace model on disk

method

character indicating the method of loading. Possible values are 'ruimtehol', 'binary' and 'tsv-data.table'. Defaults to 'ruimtehol'.

  • method 'ruimtehol' loads the model, embeddings and labels which were saved with saveRDS by calling starspace_save_model and re-initilises a new Starspace model with the embeddings and the same parameters used to build the model

  • method 'binary' loads the embedding which were saved as a as a binary file using the original methods of the Starspace authors - see starspace_save_model

  • method 'tsv-data.table' loads the embedding which were saved as a tab-delimited flat file using the fast data.table fread function - see starspace_save_model

...

further arguments passed on to starspace in case of method 'tsv-data.table'

Value

an object of class textspace

See Also

starspace_save_model

Examples

data(dekamer, package = "ruimtehol")
dekamer$text <- strsplit(dekamer$question, "\\W")
dekamer$text <- lapply(dekamer$text, FUN = function(x) x[x != ""])
dekamer$text <- sapply(dekamer$text, 
                       FUN = function(x) paste(x, collapse = " "))

dekamer$target <- as.factor(dekamer$question_theme_main)
codes <- data.frame(code = seq_along(levels(dekamer$target)), 
                    label = levels(dekamer$target), stringsAsFactors = FALSE)
dekamer$target <- as.integer(dekamer$target)
set.seed(123456789)
model <- embed_tagspace(x = dekamer$text, 
                        y = dekamer$target, 
                        early_stopping = 0.8,
                        dim = 10, minCount = 5)
starspace_save_model(model, file = "textspace.ruimtehol", method = "ruimtehol",
                     labels = codes)
model <- starspace_load_model("textspace.ruimtehol", method = "ruimtehol")


## clean up for cran
file.remove("textspace.ruimtehol")

ruimtehol documentation built on Jan. 7, 2023, 1:25 a.m.