Read word embedding from file
reads the pretrained word embedding stored in text file or zip file
emb = readWordEmbedding(
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.
If the word embedding file contains duplicate words, then the software uses the word vector corresponding to the last duplicate entry.
Read Word Embedding from Text File
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: ["utc" "first" "new" "two" "time" "up" "school" "article" "world" "years" "university" "talk" "many" "national" "later" "state" "made" "born" "city" "de" "united" ... ]
Explore the word embedding using
king = word2vec(emb,"king"); man = word2vec(emb,"man"); woman = word2vec(emb,"woman"); word = vec2word(emb,king - man + woman)
word = "queen"
filename — Name of file
string scalar | character vector | 1-by-1 cell array containing a character vector
Name of the file, specified as a string scalar, character vector, or a 1-by-1 cell array containing a character vector.
emb — Output word embedding
Output word embedding, returned as a
Introduced in R2017b