write.paragraph2vec: Save a paragraph2vec model to disk

Description Usage Arguments Value See Also Examples

View source: R/paragraph2vec.R

Description

Save a paragraph2vec model as a binary file to disk

Usage

1

Arguments

x

an object of class paragraph2vec or paragraph2vec_trained as returned by paragraph2vec

file

the path to the file where to store the model

Value

invisibly a logical if the resulting file exists and has been written on your hard disk

See Also

paragraph2vec

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(tokenizers.bpe)
data(belgium_parliament, package = "tokenizers.bpe")
x <- subset(belgium_parliament, language %in% "french")
x <- subset(x, nchar(text) > 0 & txt_count_words(text) < 1000)


model <- paragraph2vec(x = x, type = "PV-DM",   dim = 100, iter = 20)
model <- paragraph2vec(x = x, type = "PV-DBOW", dim = 100, iter = 20)


path <- "mymodel.bin"

write.paragraph2vec(model, file = path)
model <- read.paragraph2vec(file = path)

vocab <- summary(model, type = "vocabulary", which = "docs")
vocab <- summary(model, type = "vocabulary", which = "words")
embedding <- as.matrix(model, which = "docs")
embedding <- as.matrix(model, which = "words")

doc2vec documentation built on March 28, 2021, 1:09 a.m.