m = word2vec(emb,words)
returns the embedding vectors of words in the embedding
emb. if a word is not in the embedding vocabulary, then the
function returns a row of nans. the function, by default, is case
sensitive.
m = word2vec(emb,words,'ignorecase',true)
returns the embedding vectors of words ignoring case using any
of the previous syntaxes. if multiple words in the embedding differ only in case,
then the function returns the vector corresponding to one of them and does not
return any particular vector.
examples
map words to vectors and back
load a pretrained word embedding using fasttextwordembedding. this function requires text analytics toolbox™ model for fasttext english 16 billion token word embedding support package. if this support package is not installed, then the function provides a download link.
emb = fasttextwordembedding
emb =
wordembedding with properties:
dimension: 300
vocabulary: [1×1000000 string]
map the words "italy", "rome", and "paris" to vectors using word2vec.
italy = word2vec(emb,"italy");
rome = word2vec(emb,"rome");
paris = word2vec(emb,"paris");
map the vector italy - rome paris to a word using vec2word.
word = vec2word(emb,italy - rome paris)
word =
"france"
input arguments
emb — input word embedding wordembedding object
input word embedding, specified as a object.
words — input words string vector | character vector | cell array of character vectors
input words, specified as a string vector, character vector, or cell array of character vectors. if you specify words as a character vector, then the function treats the argument as a single word.
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.