main content

map word to embedding vector -凯发k8网页登录

map word to embedding vector

description

example

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

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

input word embedding, specified as a object.

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.

data types: string | char | cell

output arguments

matrix of word embedding vectors.

version history

introduced in r2017b

网站地图