Modeladvanced
Paragraph vector
Also called doc2vec.
Le and Mikolov's model that learns a vector per document jointly with word vectors, by predicting the words of the document from it.
The paragraph vector model, often called doc2vec, learns a vector for each document of a corpus together with the word vectors. It extends the word2vec objectives: in PV-DM the document vector joins the context words that predict the next word, as in continuous bag of words, and in PV-DBOW the document vector alone predicts words sampled from the document, as in skip-gram. A document not seen in training gets its vector by gradient steps with all other weights fixed. It is one answer to the sentence embedding problem, and the two pages overlap: that page states the task and compares the methods, this page defines the model.
The machine
Parameters. There are paragraphs (any span of text: a sentence, a paragraph or a document), each with an id, and a vocabulary of words. The paragraph matrix has a column for each paragraph . The word matrix has a column for each word. The output layer has weights and biases , one row per word.
PV-DM (distributed memory). A training example is a window of words of paragraph and the next word . The input is the concatenation of size (a mean or a sum is the other choice, with ). The model is
The paragraph vector is shared by all windows of the same paragraph, and the word vectors are shared by all paragraphs. It acts as a memory of what the context words leave out, the topic of the paragraph.
PV-DBOW (distributed bag of words). The input is alone. A training example samples a window of the paragraph and then a word from it, and the model is . Word order inside the paragraph is ignored, and no word vectors are needed.
Training. Stochastic gradient descent with backpropagation maximizes the sum of the log probabilities of all training examples over , , and . The full softmax over words is replaced by hierarchical softmax or negative sampling, as in word2vec.
Inference. For a new paragraph, a column is added to and trained by gradient steps on the windows of that paragraph, with , and fixed. The vector then goes to a separate classifier, such as logistic regression.
Standing assumptions. Paragraphs are bags of windows; the model sees no order beyond the window in PV-DM and none in PV-DBOW. The vocabulary is fixed, and an unknown word is dropped.
What it counts
The model assigns the probability of each target word given the paragraph id and, for PV-DM, the window. The vector it returns for a paragraph is the column .
- Parameters. for the paragraphs, for the words in PV-DM, and about for the output layer with concatenation. The paragraph matrix grows with the corpus, unlike the other parameters.
- One example. With concatenation, the PV-DM input has size , and one example costs with hierarchical softmax, or with negative samples, against for the full softmax. PV-DBOW costs or .
- Inference. A new paragraph of words costs the per-example cost times times the number of passes over it. This is more than one forward pass of an encoder, and the result depends on the learning rate, the number of passes and the random start.
Relation to other models
- Word2vec. PV-DM is continuous bag of words with one more context token, the paragraph id, which is the same for every window of the paragraph. PV-DBOW is skip-gram with the paragraph id as the input word. Many tools train word vectors by skip-gram at the same time as PV-DBOW, so that the two share one space.
- Topic models and matrix factorization. Latent semantic analysis and latent Dirichlet allocation also give each document a low-dimensional vector from its word counts. As a heuristic view, PV-DBOW fits a low-rank model of the matrix of paragraphs by words with a softmax link.
- Bag of words. A tf-idf vector of a document is a sparse vector of size with no training. With a linear classifier and word bigrams, it is a strong baseline for sentiment on long reviews (see the Mesnil et al. result below).
- Weighted averages. SIF builds a sentence vector from fixed word vectors with no gradient steps per sentence, and the same sentence always gets the same vector.
- Trained encoders. Sentence-BERT and SimCSE compute a vector by one forward pass of a network, for any new text.
Known results in the model
- Inference is a concave problem (theorem). With , and fixed, the score is an affine function of , in PV-DM as in PV-DBOW. The log softmax is concave in , because the log-sum-exp function is convex (see the log-sum-exp trick). An affine map keeps concavity, and a sum of concave functions is concave. So the inference objective is concave in and has no local maximum that is not global. The same holds for hierarchical softmax and negative sampling, whose terms are , also concave. The maximum need not be reached at a finite point; for example, a paragraph of one word has the supremum 0 only in the limit. So the result depends on the number of steps, and practical tools stop after a fixed number of passes.
- Reported sentiment results (measurement). Le and Mikolov 2014 reported an error rate of 12.2% on the coarse and 51.3% on the fine-grained Stanford Sentiment Treebank task, and 7.42% on IMDB, with the PV-DM and PV-DBOW vectors concatenated, 400 dimensions each, and windows of 8 and 10 words. They recommended the combination of the two models.
- The IMDB result was not reproduced (measurement). Mesnil, Mikolov, Ranzato and Bengio 2015 trained paragraph vectors alone on IMDB and got 88.73% accuracy, an error of 11.27%. Their footnote 2 reports that, with hierarchical softmax, the 92.6% accuracy of the original result appears only when the training and test data are not shuffled, and they consider that result invalid. In the same paper, a bag of word n-grams with a linear model was better than paragraph vectors.
- Vectors depend on the run (a property of the method). Inference starts from a random vector and uses a finite number of stochastic steps, so two runs give different vectors for the same text. Test a downstream use with several runs.
References
- Le and Mikolov 2014, Section 2.2 (PV-DM), Section 2.3 (PV-DBOW), and the experiments on the Stanford Sentiment Treebank and IMDB
- Mesnil et al. 2015, Table 2 (paragraph vectors alone at 88.73% accuracy on IMDB) and footnote 2 (the 92.6% result appears only without shuffling of the data)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag ZV1QWA Edit this page History Report an error Markdown