d = as_embed(demodata, normalize=TRUE)
plot_wordvec(d[1:10])
dt = get_wordvec(d, cc("king, queen, man, woman"))
dt[, QUEEN := king - man + woman]
dt[, QUEEN := QUEEN / sqrt(sum(QUEEN^2))] # normalize
names(dt)[5] = "king - man + woman"
plot_wordvec(dt[, c(1,3,4,5,2)], dims=1:50)
dt = get_wordvec(d, cc("boy, girl, he, she"))
dt[, GIRL := boy - he + she]
dt[, GIRL := GIRL / sqrt(sum(GIRL^2))] # normalize
names(dt)[5] = "boy - he + she"
plot_wordvec(dt[, c(1,3,4,5,2)], dims=1:50)
dt = get_wordvec(d, cc("
male, man, boy, he, his,
female, woman, girl, she, her"))
p = plot_wordvec(dt, dims=1:100)
# if you want to change something:
p + theme(legend.key.height=unit(0.1, "npc"))
# or to save the plot:
ggsave(p, 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