6 ms·
If the word embedding is, say, 400 dimensions, are you averaging the vectors of all the words in the document to get a document vector?
by ppod 9y ago
If the word embedding is, say, 400 dimensions, are you averaging the vectors of all the words in the document to get a document vector?
- isoprophlex 9y agoJust piping in to say that I'm very curious as well! How do you go from word vectors to a description of the document?
- useracd 9y agoOften the w2v embedding layer will be the first layer of a network, through which a document of word representations will be passed. The output of the embedding layer will be a 2 dimensional tensor with the embedding dimension in one direction and the number of input words in the other. The next step is often to apply zero or more convolutional units over the word direction before some kind of pooling to get a 1 dimensional output. The output of the pooling layer will be a document representation based upon the word vectors. Other approaches like doc2vec are also used.
- ppod 9y agoThank you for this very helpful information, and I have just one more question: "Often the w2v embedding layer will be the first layer of a network, through which a document of word representations will be passed. The output of the embedding layer will be a 2 dimensional tensor with the embedding dimension in one direction and the number of input words in the other. The next step is often to apply zero or more convolutional units over the word direction before some kind of pooling to get a 1 dimensional output. The output of the pooling layer will be a document representation based upon the word vectors. Other approaches like doc2vec are also used." I thought the approach you described was doc2vec. If not, then does it have a name/citation?
- aglionby 9y agoDoc2vec is the name of the gensim implementation of this paper [0]. Briefly, it creates document embeddings (document being anything on the level of phrases, to sentences, to paragraphs and beyond) on the basis of either predicting a word given the context words (distributed memory -- DM), or predicting the context words given a word (distributed bag of words -- DBOW). [0] https://arxiv.org/abs/1405.4053 https://arxiv.org/abs/1405.4053
- isoprophlex 9y agoSo in simple terms, you concatenate the word vectors and feed them to further network layers to arrive at a reduced-D representation? Either way... Very nice, thanks!
- IanCal 9y agoThe simplest thing, and one that apparently works fairly well with fasttext vectors, is just to average them.
- isoprophlex 9y agoI'm surprised (and delighted) you say that such a straightforward approach works well, thanks.
- aglionby 9y agoCombining word embeddings to get a single representation of a sentence in general is a pretty hard problem. Point-wise averaging, addition or summation [0] works alright, but it's not great. Some more recent work looks a using RNNs to combine them; most of the literature I've seen is pretty application-specific, but try [1][2] for flavour. [0] http://www.aclweb.org/anthology/P/P08/P08-1028 http://www.aclweb.org/anthology/P/P08/P08-1028 [1] http://arxiv.org/abs/1409.3215 http://arxiv.org/abs/1409.3215 [2] http://arxiv.org/abs/1409.0473 http://arxiv.org/abs/1409.0473
- homarp 9y ago[0] link should be http://www.aclweb.org/anthology/P/P08/P08-1028.pdf http://www.aclweb.org/anthology/P/P08/P08-1028.pdf Jeff Mitchell; Mirella Lapata - Vector-based Models of Semantic Composition
- wenc 9y agoFor the CNN model I was using Magpie [0] which takes a sum of the vectors (so yes, equivalent to unweighted average) to represent the document. For the FastText model, it would be whatever FastText is doing under the hood. I haven't peeked at the code to see what it is doing, but Section 2 of the paper I cited above seems to imply that an average is taken. [0] https://github.com/inspirehep/magpie https://github.com/inspirehep/magpie
- useracd 9y agoYou're correct! The keras example implementation of FastText uses a global average pooling is used to reduce the dimensionality [0]. [0] https://github.com/keras-team/keras/blob/master/examples/imdb_fasttext.py#L123 https://github.com/keras-team/keras/blob/master/examples/imd...
- ppod 9y agoInteresting. I had heard specifically that word vectors weren't a game-changer for document classification, because the averaging method didn't work well. But the difference between word2vec and FastText must be important. I think your baseline of Naive Bayes + TF-IDF would do a lot better if it was SVM and TF-IDF, but I didn't expect the big jump between word2vec and FastText.
- wenc 9y ago> I had heard specifically that word vectors weren't a game-changer for document classification, because the averaging method didn't work well. As with anything, your mileage may vary. One aspect of FastText that definitely helped in my case was n-gram support (both word and character, tunable via command-line arguments). In my corpus, I have short fragments of sentences containing misspelled words, incorrect grammar etc. plus my test set has out-of-vocabulary words. n-grams are more robust to these than Word2Vec which uses a static vocabulary.
- swsieber 9y agoI thanked your top level comment, but this whole thread is great. I fond my self worth data that sounds like yours. I'm excited to try fast text.