Learn R Programming

doc2vec (version 0.1.1)

read.paragraph2vec: Read a binary paragraph2vec model from disk

Description

Read a binary paragraph2vec model from disk

Usage

read.paragraph2vec(file)

Arguments

file

the path to the model file

Value

an object of class paragraph2vec which is a list with elements

  • model: a Rcpp pointer to the model

  • model_path: the path to the model on disk

  • dim: the dimension of the embedding matrix

Examples

Run this code
# NOT RUN {
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)

# }
# NOT RUN {
model <- paragraph2vec(x = x, type = "PV-DM",   dim = 100, iter = 20)
model <- paragraph2vec(x = x, type = "PV-DBOW", dim = 100, iter = 20)
# }
# NOT RUN {
path <- "mymodel.bin"
# }
# NOT RUN {
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")
# }

Run the code above in your browser using DataLab