d = as_embed(demodata, normalize=TRUE)
get_wordvec(d, c("China", "Japan", "Korea"))
get_wordvec(d, cc(" China, Japan; Korea "))
## specify `pattern`:
get_wordvec(d, pattern="Chin[ae]|Japan|Korea")
## plot word vectors:
get_wordvec(d, cc("China, Japan, Korea,
Mac, Linux, Windows"),
plot=TRUE, plot.dims=1:100)
## a more complex example:
words = cc("
China
Chinese
Japan
Japanese
good
bad
great
terrible
morning
evening
king
queen
man
woman
he
she
cat
dog
")
dt = get_wordvec(
d, words,
plot=TRUE,
plot.dims=1:100,
plot.step=0.06)
# if you want to change something:
attr(dt, "ggplot") +
scale_fill_viridis_b(n.breaks=10, show.limits=TRUE) +
theme(legend.key.height=unit(0.1, "npc"))
# or to save the plot:
ggsave(attr(dt, "ggplot"),
filename="wordvecs.png",
width=8, height=5, dpi=500)
unlink("wordvecs.png") # delete file for code check
Run the code above in your browser using DataLab