I appreciate word2vec is used more to find the semantic similarities between words in a corpus, but here is my idea.

  1. Train the word2vec model on a corpus

  2. For each document in the corpus, find the Term Frequency (Tf) of each word (the same Tf in TfIDF)

  3. Multiply the Tf of each word in a document by its corresponding word vector. Do this for each document

  4. Sum the word vectors together element wise to get a single vector and return the $L2$ norm of this vector

Essentially, we are weighing and summing the word vectors for each word in a document.

Each document is now represented by an $N\times 1$ dimensional vector, where $N$ is the number of features chosen in word2vec (the dimensionality hyperparamter - and I have mine set quite low at 150).

Now that all documents create a sort of unit ball in the $N$ dimensional space, we can now find clusters of similar documents / the most similar documents given an input query document, using k-nearest neighbors or k-means.

My question is, is this method viable? I have tried doc2vec, TfIDF, LDA and used appropriate similarity metrics for each (with good results), but my documents are quite short (20-100 tokens) and word2vec has worked very well alone. So I want to know if I can apply the method above or is there anything blatantly wrong with what I am doing here? Any other tips + advice would also be much appreciated.

up vote 1 down vote accepted

Some time ago I tried this idea on 20 newsgroups data. I used GloVe embeddings from the authors site (Wikipedia ones).

Aggregating word embeddings using TF-IDF doesn't give good results. It is actually worse than just using TF-IDF features. See results in this notebook (Accuracy on tfidf data vs Accuracy on weighted embedded words).

I also made plots of truncated SVD/PCA of the encoded documents - it seems like aggregated embeddings just make everything close to everything. To illustrate this I tried to find closest words for document encodings in Word embeddings space - it seems like they just lie close to common words (see Closest $10$ words to mean-aggregated texts).

That being said, This notebook is just a toy example and it only suggests that the simplest approach won't work for this data. For instance I didn't try to filter out common words based on some threshold. Also maybe it would make more sense to first extract summaries from the documents first (for example TextRank sort of retrieves most informative paragraphs based partly on TF-IDF score of their words).

If you want to try more elaborate techniques, I think that Gensim covers much of this stuff (for example extractive summarization via TextRank and similar algorithms).

There is nothing wrong with the method, it has been explored in the literature a lot. This is for instance the way that many papers use to evaluate extrinsically word embeddings with tasks like classification. One would expect however to lose in terms of accuracy as the length of the documents increases. Models like doc2vec have been proposed to address such limitations, but it is always better to test them in your benchmark.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.