Learn R Programming

word2vec (version 0.4.0)

write.word2vec: Save a word2vec model to disk

Description

Save a word2vec model as a binary file to disk or as a text file

Usage

write.word2vec(x, file, type = c("bin", "txt"), encoding = "UTF-8")

Value

a logical indicating if the save process succeeded

Arguments

x

an object of class w2v or w2v_trained as returned by word2vec

file

the path to the file where to store the model

type

either 'bin' or 'txt' to write respectively the file as binary or as a text file. Defaults to 'bin'.

encoding

encoding to use when writing a file with type 'txt' to disk. Defaults to 'UTF-8'

See Also

word2vec

Examples

Run this code
path  <- system.file(package = "word2vec", "models", "example.bin")
model <- read.word2vec(path)


## Save the model to hard disk as a binary file
path <- "mymodel.bin"
# \dontshow{
path <- tempfile(pattern = "w2v", fileext = ".bin")
# }
write.word2vec(model, file = path)
# \dontshow{
file.remove(path)
# }

if(require(udpipe)){
## Save the model to hard disk as a text file (uses package udpipe)
library(udpipe)
path <- "mymodel.txt"
# \dontshow{
path <- tempfile(pattern = "w2v", fileext = ".txt")
# }
write.word2vec(model, file = path, type = "txt")
# \dontshow{
file.remove(path)
# }
} # End of main if statement running only if the required packages are installed

Run the code above in your browser using DataLab