This Add-on provides a pre-trained word embedding and sentence classification model using FastText for use in machine learning and deep learning algorithms. FastText is an open-source library which provides efficient and scalable libraries for text analytics. For more information on the pre-trained word vector model see : https://fasttext.cc/docs/en/english-vectors.html
Opening the fasttext.mlpkginstall file from your operating system or from within MATLAB will initiate the installation process for the release you have.
This mlpkginstall file is functional for R2018a and beyond.
% Load the trained model
emb = fasttextenglishembedding()
% Convert the words king, man, and woman to vectors using word2vec
king = word2vec(emb,"king");
man = word2vec(emb,"man");
woman = word2vec(emb,"woman");
% Compute the vector given by king - man + woman
vec = king - man + woman
Find the closest words in the embedding to vec using vec2word
word = vec2word(emb,vec)
To add words to the embedding vocabulary, follow the steps below to create a new embedding object after reading it in:
>> emb = fasttextenglishembedding();
>> vocab = emb.Vocabulary;
>> mat = word2vec(emb,vocab);
>> newvocab = [vocab "sample 1" "sample 2"];
>> newmat = [mat ; randn(2,300)];
>> newemb = wordEmbedding(newvocab,newmat);
Is it possible to add additional words to the pretrained vocabulary? If so, how is this done?
Create scripts with code, output, and formatted text in a single executable document.