main content

pretrained fasttext word embedding -凯发k8网页登录

pretrained fasttext word embedding

description

emb = fasttextwordembedding returns a 300-dimensional pretrained word embedding for 1 million english words.

this function requires the text analytics toolbox™ model for fasttext english 16 billion token word embedding support package. if this support package is not installed, the function provides a download link.

examples

download and install the text analytics toolbox model for fasttext english 16 billion token word embedding support package.

type fasttextwordembedding at the command line.

fasttextwordembedding

if the text analytics toolbox model for fasttext english 16 billion token word embedding support package is not installed, then the function provides a link to the required support package in the add-on explorer. to install the support package, click the link, and then click install. check that the installation is successful by typing emb = fasttextwordembedding at the command line.

emb = fasttextwordembedding
emb = 
  wordembedding with properties:
     dimension: 300
    vocabulary: [1×1000000 string]

if the required support package is installed, then the function returns a wordembedding object.

load a pretrained word embedding using fasttextwordembedding. this function requires text analytics toolbox™ model for fasttext english 16 billion token word embedding support 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 using word2vec.

italy = word2vec(emb,"italy");
rome = word2vec(emb,"rome");
paris = word2vec(emb,"paris");

map the vector italy - rome paris to a word using vec2word.

word = vec2word(emb,italy - rome   paris)
word = 
"france"

convert an array of tokenized documents to sequences of word vectors using a pretrained word embedding.

load a pretrained word embedding using the fasttextwordembedding function. this function requires text analytics toolbox™ model for fasttext english 16 billion token word embedding support package. if this support package is not installed, then the function provides a download link.

emb = fasttextwordembedding;

load the factory reports data and create a tokenizeddocument array.

filename = "factoryreports.csv";
data = readtable(filename,'texttype','string');
textdata = data.description;
documents = tokenizeddocument(textdata);

convert the documents to sequences of word vectors using doc2sequence. the doc2sequence function, by default, left-pads the sequences to have the same length. when converting large collections of documents using a high-dimensional word embedding, padding can require large amounts of memory. to prevent the function from padding the data, set the 'paddingdirection' option to 'none'. alternatively, you can control the amount of padding using the 'length' option.

sequences = doc2sequence(emb,documents,'paddingdirection','none');

view the sizes of the first 10 sequences. each sequence is d-by-s matrix, where d is the embedding dimension, and s is the number of word vectors in the sequence.

sequences(1:10)
ans=10×1 cell array
    {300×10 single}
    {300×11 single}
    {300×11 single}
    {300×6  single}
    {300×5  single}
    {300×10 single}
    {300×8  single}
    {300×9  single}
    {300×7  single}
    {300×13 single}

output arguments

pretrained word embedding, returned as a wordembedding object.

version history

introduced in r2018a

网站地图