Read word embedding from file


emb = readWordEmbedding(filename)



emb = readWordEmbedding(filename) reads the pretrained word embedding stored in text file or zip file filename. The input file must be a text file with UTF-8 encoding in either the word2vec or GloVe text embedding format, or a zip file containing a text file of this format.


collapse all

Read the example word embedding. This model was derived by analyzing text from Wikipedia.

filename = "exampleWordEmbedding.vec";
emb = readWordEmbedding(filename)
emb = 
  wordEmbedding with properties:

     Dimension: 50
    Vocabulary: [1x9999 string]

Explore the word embedding using word2vec and vec2word.

king = word2vec(emb,"king");
man = word2vec(emb,"man");
woman = word2vec(emb,"woman");
word = vec2word(emb,king - man + woman)
word = 

Input Arguments

collapse all

Name of the file, specified as a string scalar or character vector.

Data Types: string | char

Output Arguments

collapse all

Output word embedding, returned as a wordEmbedding object.

Introduced in R2017b