Load a pretrained word embedding usingfastTextWordEmbedding. This function requires Text Analytics Toolbox™ Modelfor fastText English 16 Billion Token Word Embeddingsupport 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 usingword2vec.
italy = word2vec(emb,"Italy"); rome = word2vec(emb,"Rome"); paris = word2vec(emb,"Paris");
Map the vectoritaly - rome + paristo a word usingvec2word.
Find the top five closest words to a word embedding vector and their distances.
Load a pretrained word embedding usingfastTextWordEmbedding. This function requires Text Analytics Toolbox™ Modelfor fastText English 16 Billion Token Word Embeddingsupport package. If this support package is not installed, then the function provides a download link.
emb = fastTextWordEmbedding;
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 vectoritaly - rome + paristo a word usingvec2word. Find the top five closest words using the Euclidean distance metric.
k = 5; M = italy - rome + paris; [words,dist] = vec2word(emb,M,k,'Distance','euclidean');
条形图中的单词和距离。
figure; bar(dist) xticklabels(words) xlabel("Word") ylabel("Distance") title("Distances to Vector")
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.