%% Initialize Word Embedding Layer with Pretrained Word Embedding
% To initialize a word embedding layer in a deep learning network with the weights from a pretrained word embedding, use the word2vec function to extract the layer weights and set the 'Weights' name-value pair of the wordEmbeddingLayer function. The word embedding layer expects columns of word vectors, so you must transpose the output of the word2vec function.

emb = fastTextWordEmbedding;

words = emb.Vocabulary;
dimension = emb.Dimension;
numWords = numel(words);

layer = wordEmbeddingLayer(dimension,numWords,...
    'Weights',word2vec(emb,words)')

% To create the corresponding word encoding from the word embedding, input the word embedding vocabulary to the wordEncoding function as a list of words.

enc = wordEncoding(words)

% Copyright 2019 The MathWorks, Inc.
%