get_wordvec {PsychWordVec} | R Documentation |
Extract word vector(s).
Description
Extract word vector(s), using either a list of words or a regular expression.
Usage
get_wordvec(
data,
words = NULL,
pattern = NULL,
plot = FALSE,
plot.dims = NULL,
plot.step = 0.05,
plot.border = "white"
)
Arguments
data |
A |
words |
[Option 1] Character string(s). |
pattern |
[Option 2] Regular expression (see |
plot |
Generate a plot to illustrate the word vectors? Defaults to |
plot.dims |
Dimensions to be plotted (e.g., |
plot.step |
Step for value breaks. Defaults to |
plot.border |
Color of tile border. Defaults to |
Value
A data.table
with words as columns and dimensions as rows.
Download
Download pre-trained word vectors data (.RData
):
https://psychbruce.github.io/WordVector_RData.pdf
See Also
Examples
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