View source: R/embed-all-the-things.R
starspace_save_model | R Documentation |
Save a starspace model as a binary or a tab-delimited TSV file
starspace_save_model( object, file = "textspace.ruimtehol", method = c("ruimtehol", "tsv-data.table", "binary", "tsv-starspace"), labels = data.frame(code = character(), label = character(), stringsAsFactors = FALSE) )
object |
an object of class |
file |
character string with the path to the file where to save the model |
method |
character indicating the method of saving. Possible values are 'ruimtehol', 'binary', 'tsv-starspace' and 'tsv-data.table'. Defaults to 'ruimtehol'.
|
labels |
a data.frame with at least columns code and label which will be saved in case |
invisibly, the character string with the file of the saved object
It is advised to always use method 'ruimtehol' method as it works nicely together with the
starspace_load_model
function. It is the advised method unless you need to provide non-R users the models
and you prefer using the methods provided by the Starspace authors instead of the faster and more portable 'ruimtehol' method.
starspace_load_model
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") starspace_save_model(model, file = "embeddings.tsv", method = "tsv-data.table") ## clean up for cran file.remove("textspace.ruimtehol") file.remove("embeddings.tsv")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.