News for hackers. Stuff that matters.
Re:Understanding word vectors by ppod on Friday March 02, 2018 @10:48AM (#16502401)
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?
Re:Understanding word vectors by wenc on Friday March 02, 2018 @11:41AM (#16503070)
For 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

Re:Understanding word vectors by useracd on Friday March 02, 2018 @11:50AM (#16503184)
You'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/imd...

Re:Understanding word vectors by ppod on Friday March 02, 2018 @12:27PM (#16503634)
Interesting. 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.
Re:Understanding word vectors by wenc on Friday March 02, 2018 @12:51PM (#16503917)
> 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.

Re:Understanding word vectors by swsieber on Friday March 02, 2018 @09:10PM (#16507434)
I 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.
Re:Understanding word vectors by sp332 on Friday March 02, 2018 @02:57PM (#16505106)
I think it's important to use the right "average" operation. word2vec puts words on the surface of a hypersphere, so "adding" vectors means turning around the sphere.
Re:Understanding word vectors by isoprophlex on Friday March 02, 2018 @11:00AM (#16502565)
Just piping in to say that I'm very curious as well! How do you go from word vectors to a description of the document?
Re:Understanding word vectors by aglionby on Friday March 02, 2018 @02:45PM (#16504962)
Combining 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

[1] http://arxiv.org/abs/1409.3215

[2] http://arxiv.org/abs/1409.0473

Re:Understanding word vectors by homarp on Saturday March 03, 2018 @03:35AM (#16508469)
[0] link should be http://www.aclweb.org/anthology/P/P08/P08-1028.pdf Jeff Mitchell; Mirella Lapata - Vector-based Models of Semantic Composition
Re:Understanding word vectors by useracd on Friday March 02, 2018 @11:48AM (#16503148)
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.

Re:Understanding word vectors by ppod on Friday March 02, 2018 @12:29PM (#16503662)
Thank 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?

Re:Understanding word vectors by aglionby on Friday March 02, 2018 @02:35PM (#16504886)
Doc2vec 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

Re:Understanding word vectors by isoprophlex on Friday March 02, 2018 @01:20PM (#16504240)
So 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!

Re:Understanding word vectors by IanCal on Friday March 02, 2018 @11:59AM (#16503327)
The simplest thing, and one that apparently works fairly well with fasttext vectors, is just to average them.
Re:Understanding word vectors by isoprophlex on Friday March 02, 2018 @01:21PM (#16504244)
I'm surprised (and delighted) you say that such a straightforward approach works well, thanks.