Paper · 2017-03-07 · cs.CL, cs.AI, cs.IR
Unsupervised Learning of Sentence Embeddings using Compositional n-Gram Features
Sent2Vec: a sentence vector is the mean of learned unigram and bigram embeddings, trained with a C-BOW-style negative-sampling objective that predicts each word from its sentence. Author-reported: 82.0 average on six supervised tasks (unigram+bigram, Toronto books), second only to ordered-sentence SkipThought, and the best unsupervised similarity average among unordered models.
Text embeddingWord embeddingSkip-gram with negative sampling (SGNS)sentence-embeddingsunsupervised-learningword-embeddingsn-grams
arXivPDFCodeMarkdown19 min read
AI-compiled by claude-haiku-5-5 on 2026-10-24, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Getting one useful vector for a whole sentence, without any labels, is harder than getting one for a single word. Word vectors are cheap to learn from huge piles of text. Sentence encoders built from neural sequence models are much slower to train. The authors ask whether something as simple as averaging word vectors can be trained to work well for sentences.
Their model, Sent2Vec, learns the vectors and the averaging together. It is a close relative of a classic word-learning method: hide one word of a sentence and train the model to guess it from the rest of the sentence. The sentence's vector is the average of learned pieces, which are single words plus pairs of neighbouring words. The pairs let the vector pick up some meaning that single words miss, such as "not good".
Because the model is just averages and dot products, it is fast to train and fast to run on new sentences. The authors compare it with other unsupervised sentence models on classification and similarity benchmarks. It comes out ahead of the other unsupervised models on the averages they report, except SkipThought on classification.
TL;DR
Sent2Vec gives each sentence a vector with no labels: the mean of learned embeddings for its unigrams and bigrams. Training predicts each word from the rest of its sentence with negative sampling, so the work per word is a constant number of vector operations §1. The author-reported headline is an 82.0 average on six supervised tasks for the unigram+bigram model trained on Toronto books, second only to SkipThought on ordered sentences tab. 1. The released code (BSD-3-Clause) differs from the paper in several training details; see "Paper vs code".
Problem
Word embeddings can be learned unsupervised from very large text, but sentence representations were harder to get. Strong neural sentence models are slow to train on large corpora. Averaging word vectors was shown to beat LSTMs on sentence tasks, but that composition is fixed rather than learned together with the vectors §1. The authors want general-purpose sentence vectors that are unsupervised and as cheap to train and run as averages §1. The method needs a large unlabelled corpus with one sentence per line README.md. Beyond adjacent word pairs it ignores word order; order-using baselines such as SkipThought are still in the comparison tab. 1.
Method
Overview. The model is a bilinear model over a bag of unigram and bigram features, trained with a C-BOW-style objective whose context is the whole sentence rather than a fixed window §2 §2.3.
-
Bilinear view. Word and n-gram models of this family minimise an objective of the form in eq. 1, with a source matrix V (columns are source vectors v_w) and a target matrix U (columns are target vectors u_w). The sentence indicator is a bag-of-features vector §2.
\min_{U,V} \sum_{S \in C} f_S(U V \mathbb{1}_S) eq. 1
-
Sentence vector. The sentence vector is the mean of the source vectors of every feature in R(S), which holds the unigrams and the n-grams present in S §2.1 eq. 2. The paper's model uses unigrams and bigrams. Bigram features are hashed into a fixed number of buckets with the hashing trick §2.2. The released code hashes vocabulary ids, not strings dictionary.cc.
v_S := \frac{1}{|R(S)|} \sum_{w \in R(S)} v_w eq. 2
-
Objective. For each word w_t in S, the model predicts w_t from the sentence without w_t, i.e. from S \ {w_t} §2.1. It uses a binary logistic loss ℓ(x) = log(1 + e^(−x)) with negative sampling §2.1. Summed over the corpus, the training objective is eq. 3.
\min_{U,V} \sum_{S \in C} \sum_{w_t \in S} \Big( q_p(w_t)\, \ell\big(u_{w_t}^\top v_{S \setminus \{w_t\}}\big) + |N_{w_t}| \sum_{w' \in \mathcal{V}} q_n(w')\, \ell\big(-u_{w'}^\top v_{S \setminus \{w_t\}}\big) \Big) eq. 3
N_{w_t} is the set of negatives sampled for w_t §2.1. The paper's C-BOW comparison is in §2.3: C-BOW uses dynamic windows and subsamples tokens before forming context, and the authors argue both break the n-gram features a sentence embedding needs.
-
Target subsampling. A word w is kept as a target with probability q_p(w) = min{1, sqrt(t / f_w) + t / f_w}, where f_w is its normalised corpus frequency and t is the subsampling parameter §2.1. Subsampling applies to targets only; the context keeps every word §2.4.
-
Negative distribution. Negatives are drawn with probability q_n(w) = sqrt(f_w) / Σ_{w_i} sqrt(f_{w_i}) §2.1. A negative equal to the target is excluded §2.1. The number of negatives per target is 10 in every configuration tab. 5.
-
Bigram dropout. For each sentence, K n-grams with n > 1 are dropped during training, which the authors found to work better than dropping tokens at a fixed rate §2.4. The per-model K is in tab. 5. Unigrams are never dropped by this step.
-
Optional L1 penalty. The paper adds an L1 penalty τ(‖u‖₁ + ‖v‖₁) to each term and applies it with a proximal soft-threshold step after each SGD update §2.4 app. B. The modified objective, update and operator are eq. 4, eq. 5 and eq. 6. The soft-threshold per step is τ·lr′/|R(S \ {w_t})| for source vectors and τ·lr′ for target vectors, where lr′ is the current learning rate app. B. The paper reports τ = 0.0005 for the Wikipedia and Toronto-books unigram+bigram models app. B. The released code does not contain this step (see "Paper vs code").
\min_{U,V} \sum_{S \in C} \sum_{w_t \in S} q_p(w_t) \Big( \ell\big(u_{w_t}^\top v_{S \setminus \{w_t\}}\big) + \tau\big(\|u_{w_t}\|_1 + \|v_{S \setminus \{w_t\}}\|_1\big) \Big) + |N_{w_t}| \sum_{w' \in \mathcal{V}} q_n(w') \Big( \ell\big(-u_{w'}^\top v_{S \setminus \{w_t\}}\big) + \tau \|u_{w'}\|_1 \Big) eq. 4
z_{n+1} = \mathrm{prox}_{\alpha, g}\big(z_{n+\frac{1}{2}}\big) eq. 5
\mathrm{prox}_{\alpha, g}(x) = \mathrm{sign}(x) \odot \max(|x_n| - \alpha, 0) eq. 6
Here z_{n+1/2} is the value after a gradient step on z_n, and α is the proximal parameter app. B. Eq. 6 is written with |x_n| where x is meant (see Pitfalls).
-
Optimisation. Training picks one sentence at a time and runs SGD over every target, with a learning rate that decays linearly §2.4. The released trainer applies the decay as lr · (1 − progress) over all tokens in all epochs fasttext.cc.
-
Training data. Three corpora: Toronto books, Wikipedia sentences and tweets §2.4. Each corpus gives one unigram model and one unigram+bigram model §2.4 tab. 5. Books and Wikipedia were tokenised with the Stanford NLP library, and tweets with the NLTK tweet tokenizer §2.4. The paper does not say whether text is lowercased (see Pitfalls).
-
Inference. The sentence vector is the mean of the source vectors of all unigrams and bigrams of the sentence, with no subsampling and no dropout §2.2 eq. 2. Computing it costs |S|·h floating-point operations per sentence §2.2.
Training pass over one sentence, as the paper describes it. The released code differs at the target position and in dropout (see Paper vs code):
# Sent2Vec training pass over one sentence [§2.1] [§2.4] [eq. 3]
# Input: sentence (list of word ids), source matrix V (vocab, h),
# target matrix U (vocab, h), learning rate lr,
# K (bigrams dropped), neg (negatives per target)
# Output: V and U updated in place
def train_sentence(sentence, V, U, lr, K, neg):
# Each position becomes a target with probability q_p(word) [§2.1]
for position, target in enumerate(sentence):
if random_uniform() > keep_probability[target]:
continue
# Context is every unigram and bigram of the sentence except
# those containing the target position [§2.1] [eq. 3]
context = ngram_ids(sentence, skip=position)
# Drop K bigrams at random for this context; unigrams stay [§2.4]
context = drop_bigrams(context, num_drop=K)
# Sentence vector: mean of the context source vectors [eq. 2]
sentence_vec = mean(V[context], axis=0) # (h,)
# Positive term: target vector scores the sentence vector [eq. 3]
score = dot(U[target], sentence_vec)
grad = (1 - sigmoid(score)) * U[target] # (h,)
U[target] += lr * (1 - sigmoid(score)) * sentence_vec
# Negatives drawn from count^0.5, never equal to the target [§2.1]
for negative in sample_negatives(num=neg, exclude=target):
score = dot(U[negative], sentence_vec)
grad -= sigmoid(score) * U[negative]
U[negative] -= lr * sigmoid(score) * sentence_vec
# Every context entry receives its share of the averaged gradient
# [eq. 2]; duplicate entries accumulate
V[context] += lr * grad / len(context)Inference, as in the paper. The released code's handling of out-of-vocabulary tokens is an addition the paper does not state:
# Sentence embedding at inference [eq. 2] [§2.2]
# Input: tokens (list of strings), vocab (string -> word id),
# source matrix V (vocab + buckets, h)
# Output: vector of length h
def embed_sentence(tokens, vocab, V):
# Remove out-of-vocabulary tokens first, so bigrams can join words
# that were not adjacent in the text [code: src/dictionary.cc#L436-L441]
ids = [vocab[t] for t in tokens if t in vocab]
# All unigrams and bigrams, no dropout [eq. 2]
# [code: src/fasttext.cc#L656-L658]
features = ids + bigram_ids(ids)
# Mean over all features, repeats included [eq. 2]
return mean(V[features], axis=0) # (h,)Hyperparameters
Per-model training configuration from the paper tab. 5. Learning rate is 0.2 and negatives are 10 for every model. Subsampling and K vary by model.
| Model (corpus) | Dim | Min word count | Min target count | Initial lr | Epochs | Subsampling t | Bigrams dropped per sentence (K) | Negatives |
|---|---|---|---|---|---|---|---|---|
| Sent2Vec uni (Toronto books) | 700 | 5 | 8 | 0.2 | 13 | 1e-5 | - | 10 |
| Sent2Vec uni+bi (Toronto books) | 700 | 5 | 5 | 0.2 | 12 | 5e-6 | 7 | 10 |
| Sent2Vec uni (Wikipedia) | 600 | 8 | 20 | 0.2 | 9 | 1e-5 | - | 10 |
| Sent2Vec uni+bi (Wikipedia) | 700 | 8 | 20 | 0.2 | 9 | 5e-6 | 4 | 10 |
| Sent2Vec uni (Twitter) | 700 | 20 | 20 | 0.2 | 3 | 1e-6 | - | 10 |
| Sent2Vec uni+bi (Twitter) | 700 | 20 | 20 | 0.2 | 3 | 1e-6 | 3 | 10 |
tab. 5. "Min target count" is the paper's column name. The text never explains it; the released code applies it to target positions only (see Paper vs code).
Other settings:
| Name | Value | Where | Notes |
|---|---|---|---|
| Learning-rate schedule | linear decay | §2.4 | Released trainer: lr · (1 − progress) fasttext.cc |
| Negative table | count^0.5 | §2.1 | Released table has 10^7 entries model.h |
| L1 weight τ | 0.0005 | app. B | Wikipedia and Toronto-books uni+bi only; not in released code |
| Soft-threshold step | τ·lr′ divided by the n-gram count of S∖{w_t} for source vectors; τ·lr′ for targets | app. B | Not in released code |
| Hash buckets for n-grams | not stated | §2.2 | Released default 2,000,000 args.cc; README example 4,000,000 README.md |
| Sentence order | random sentence | §2.4 | Released trainer reads in file order (see Paper vs code) |
| Logistic regression L2 | tuned by cross-validation | §4 | Nested CV for four datasets, predefined split for MSRP and TREC |
| Window size | not used | §2.1 | The sentence is the context; no window |
| Hardware | 2× Xeon E5-2680v3, 12 cores, 2.5 GHz | §5 | Used for all Sent2Vec timings |
The README example trains the Wikipedia uni+bi configuration
(-dim 700 -epoch 9 -lr 0.2 -minCount 8 -minCountLabel 20 -t 0.000005 -dropoutK 4)
README.md, matching tab. 5. Bucket count and vocabulary cap are
extra arguments the paper does not state.
Results
Author-reported. Setup §4 §5: supervised tasks are MSR paraphrase (MSRP), movie reviews (MR), product reviews (CR), subjectivity (SUBJ), opinion polarity (MPQA) and question type (TREC). Sentence embeddings go into logistic regression. MSRP uses the concatenation of |v₁ − v₂| and v₁ ⊙ v₂. Unsupervised similarity is cosine similarity against human judgements on STS 2014 and SICK 2014, with Spearman and Pearson correlation. Corpora: Toronto books, 70M sentences and 0.9B words tab. 1; Wikipedia, 69M sentences and 1.7B words tab. 6; Twitter, 1.2B sentences and 19.7B words tab. 6. Baselines are described in §3 and §5. Sentence-length statistics for the evaluation sets are in tab. 8.
Headline numbers:
| Setting | Metric | Baseline | This paper | Source |
|---|---|---|---|---|
| Toronto books, six supervised tasks | average accuracy (MSRP counted by accuracy) | 80.7 Unigram TF-IDF (best other unordered); 83.8 SkipThought (ordered) | 82.0 Sent2Vec uni+bi; 81.4 Sent2Vec uni | tab. 1 |
| Toronto books, STS 2014 + SICK 2014 | average Spearman / Pearson | 0.63 / 0.67 C-PHRASE (uses parse info and 2.8B words) | 0.65 / 0.68 Sent2Vec uni; 0.65 / 0.67 uni+bi | tab. 2 |
| Twitter 19.7B words, macro average | average of supervised and unsupervised averages | 73.7 DictRep (semi-supervised), 63.1 SkipThought | 75.9 Sent2Vec uni+bi; 75.6 uni | tab. 3 |
| Arora et al. comparison, Pearson | STS 2014 / SICK 2014 / supervised average | 0.685 / 0.722 / 0.815 unsupervised GloVe + WR | 0.701 / 0.715 / 0.835 Sent2Vec uni+bi (Twitter) | tab. 4 |
Full supervised results tab. 1. Metric: accuracy, MSRP as Acc / F1. The paper's table also marks best scores in bold and underline, which are omitted here.
| Model | Training data | MSRP | MR | CR | SUBJ | MPQA | TREC | Avg. |
|---|---|---|---|---|---|---|---|---|
| SAE | unordered, Toronto books | 74.3 / 81.7 | 62.6 | 68.0 | 86.1 | 76.8 | 80.2 | 74.7 |
| SAE + embs. | unordered, Toronto books | 70.6 / 77.9 | 73.2 | 75.3 | 89.8 | 86.2 | 80.4 | 79.3 |
| SDAE | unordered, Toronto books | 76.4 / 83.4 | 67.6 | 74.0 | 89.3 | 81.3 | 77.7 | 78.3 |
| SDAE + embs. | unordered, Toronto books | 73.7 / 80.7 | 74.6 | 78.0 | 90.8 | 86.9 | 78.4 | 80.4 |
| ParagraphVec DBOW | unordered, Toronto books | 72.9 / 81.1 | 60.2 | 66.9 | 76.3 | 70.7 | 59.4 | 67.7 |
| ParagraphVec DM | unordered, Toronto books | 73.6 / 81.9 | 61.5 | 68.6 | 76.4 | 78.1 | 55.8 | 69.0 |
| Skipgram | unordered, Toronto books | 69.3 / 77.2 | 73.6 | 77.3 | 89.2 | 85.0 | 82.2 | 78.5 |
| C-BOW | unordered, Toronto books | 67.6 / 76.1 | 73.6 | 77.3 | 89.1 | 85.0 | 82.2 | 79.1 |
| Unigram TF-IDF | unordered, Toronto books | 73.6 / 81.7 | 73.7 | 79.2 | 90.3 | 82.4 | 85.0 | 80.7 |
| Sent2Vec uni. | unordered, Toronto books | 72.2 / 80.3 | 75.1 | 80.2 | 90.6 | 86.3 | 83.8 | 81.4 |
| Sent2Vec uni.+bi. | unordered, Toronto books | 72.5 / 80.8 | 75.8 | 80.3 | 91.2 | 85.9 | 86.4 | 82.0 |
| SkipThought | ordered, Toronto books | 73.0 / 82.0 | 76.5 | 80.1 | 93.6 | 87.1 | 92.2 | 83.8 |
| FastSent | ordered, Toronto books | 72.2 / 80.3 | 70.8 | 78.4 | 88.7 | 80.6 | 76.8 | 77.9 |
| FastSent+AE | ordered, Toronto books | 71.2 / 79.1 | 71.8 | 76.7 | 88.8 | 81.5 | 80.4 | 78.4 |
| C-PHRASE | 2.8B words, with parse info | 72.2 / 79.6 | 75.7 | 78.8 | 91.1 | 86.2 | 78.8 | 80.5 |
Full unsupervised similarity results tab. 2. Spearman / Pearson correlation. Columns are the STS 2014 subsets and SICK 2014 (test + train).
| Model | News | Forum | WordNet | Images | Headlines | SICK | Avg. | |
|---|---|---|---|---|---|---|---|---|
| SAE | .17/.16 | .12/.12 | .30/.23 | .28/.22 | .49/.46 | .13/.11 | .32/.31 | .26/.23 |
| SAE + embs. | .52/.54 | .22/.23 | .60/.55 | .60/.60 | .64/.64 | .41/.41 | .47/.49 | .50/.49 |
| SDAE | .07/.04 | .11/.13 | .33/.24 | .44/.42 | .44/.38 | .36/.36 | .46/.46 | .31/.29 |
| SDAE + embs. | .51/.54 | .29/.29 | .56/.50 | .57/.58 | .59/.59 | .43/.44 | .46/.46 | .49/.49 |
| ParagraphVec DBOW | .31/.34 | .32/.32 | .53/.50 | .43/.46 | .46/.44 | .39/.41 | .42/.46 | .41/.42 |
| ParagraphVec DM | .42/.46 | .33/.34 | .51/.48 | .54/.57 | .32/.30 | .46/.47 | .44/.40 | .43/.43 |
| Skipgram | .56/.59 | .42/.42 | .73/.70 | .71/.74 | .65/.67 | .55/.58 | .60/.69 | .60/.63 |
| C-BOW | .57/.61 | .43/.44 | .72/.69 | .71/.75 | .71/.73 | .55/.59 | .60/.69 | .60/.65 |
| Unigram TF-IDF | .48/.48 | .40/.38 | .60/.59 | .63/.65 | .72/.74 | .49/.49 | .52/.58 | .55/.56 |
| Sent2Vec uni. | .62/.67 | .49/.49 | .75/.72 | .70/.75 | .78/.82 | .61/.63 | .61/.70 | .65/.68 |
| Sent2Vec uni.+bi. | .62/.67 | .51/.51 | .71/.68 | .70/.75 | .75/.79 | .59/.62 | .62/.70 | .65/.67 |
| SkipThought | .44/.45 | .14/.15 | .39/.34 | .42/.43 | .55/.60 | .43/.44 | .57/.60 | .42/.43 |
| FastSent | .58/.59 | .41/.36 | .74/.70 | .63/.66 | .74/.78 | .57/.59 | .61/.72 | .61/.63 |
| FastSent+AE | .56/.59 | .41/.40 | .69/.64 | .70/.74 | .63/.65 | .58/.60 | .60/.65 | .60/.61 |
| Siamese C-BOW | .58/.59 | .42/.41 | .66/.61 | .71/.73 | .65/.65 | .63/.64 | - | - |
| C-PHRASE | .69/.71 | .43/.41 | .76/.73 | .60/.65 | .75/.79 | .60/.65 | .60/.72 | .63/.67 |
The paper says the Sent2Vec unsupervised results beat all unsupervised models trained on the Toronto corpus on most tasks, with the best average §5 tab. 2. It also reports that Sent2Vec models on average outperform or match C-PHRASE, which uses parse information and about three times the text of the Toronto corpus §5 tab. 2.
Training time and macro average tab. 3. Macro average is the mean of the supervised and unsupervised averages.
| Type | Training corpus | Method | Supervised avg. | Unsupervised avg. | Macro avg. | Training time (h) |
|---|---|---|---|---|---|---|
| unsupervised | Twitter (19.7B words) | Sent2Vec uni.+bi. | 83.5 | 68.3 | 75.9 | 6.5 (single node, 30 threads) |
| unsupervised | Twitter (19.7B words) | Sent2Vec uni. | 82.2 | 69.0 | 75.6 | 3 (single node, 30 threads) |
| unsupervised | Wikipedia (1.7B words) | Sent2Vec uni.+bi. | 83.3 | 66.2 | 74.8 | 2 (single node, 30 threads) |
| unsupervised | Wikipedia (1.7B words) | Sent2Vec uni. | 82.4 | 66.3 | 74.3 | 3.5 (single node, 30 threads) |
| unsupervised | Toronto books (0.9B words) | Sent2Vec books uni. | 81.4 | 66.7 | 74.0 | 1 (single node, 30 threads) |
| unsupervised | Toronto books (0.9B words) | Sent2Vec books uni.+bi. | 82.0 | 65.9 | 74.0 | 1.2 (single node, 30 threads) |
| semi-supervised | structured dictionary dataset | DictRep BOW + emb | 80.5 | 66.9 | 73.7 | 24 (GPU) |
| unsupervised | 2.8B words + parse info | C-PHRASE | 80.5 | 64.9 | 72.7 | - |
| unsupervised | Toronto books (0.9B words) | C-BOW | 79.1 | 62.8 | 70.2 | 2 |
| unsupervised | Toronto books (0.9B words) | FastSent | 77.9 | 62.0 | 70.0 | 2 |
| unsupervised | Toronto books (0.9B words) | SkipThought | 83.8 | 42.5 | 63.1 | 336 (GPU) |
Comparison with Arora et al. tab. 4. Unsupervised columns are Pearson correlation. The supervised row is the supervised average from tab. 1. The GloVe corpus is 42 times larger than the paper's Twitter corpus §5.
| Metric | GloVe + WR (unsupervised) | PSL + WR (semi-supervised) | Sent2Vec uni (Twitter) | Sent2Vec uni+bi (Twitter) |
|---|---|---|---|---|
| STS 2014 | 0.685 | 0.735 | 0.710 | 0.701 |
| SICK 2014 | 0.722 | 0.729 | 0.710 | 0.715 |
| Supervised average | 0.815 | 0.807 | 0.822 | 0.835 |
Appendix supervised results, Sent2Vec rows only tab. 6. Other rows (CaptionRep, DictRep) are omitted here.
| Model | MSRP | MR | CR | SUBJ | MPQA | TREC | Avg. |
|---|---|---|---|---|---|---|---|
| Books uni | 72.2 / 80.3 | 75.1 | 80.2 | 90.6 | 86.3 | 83.8 | 81.4 |
| Books uni+bi | 72.5 / 80.8 | 75.8 | 80.3 | 91.2 | 85.9 | 86.4 | 82.0 |
| Books uni+bi, L1 | 71.6 / 80.1 | 76.1 | 80.9 | 91.1 | 86.1 | 86.8 | 82.1 |
| Wikipedia uni | 71.8 / 80.2 | 77.3 | 80.3 | 92.0 | 87.4 | 85.4 | 82.4 |
| Wikipedia uni+bi | 72.4 / 80.8 | 77.9 | 80.9 | 92.6 | 86.9 | 89.2 | 83.3 |
| Wikipedia uni+bi, L1 | 73.6 / 81.5 | 78.1 | 81.5 | 92.8 | 87.2 | 87.4 | 83.4 |
| Twitter uni | 71.5 / 80.0 | 77.1 | 81.3 | 90.8 | 87.3 | 85.4 | 82.2 |
| Twitter uni+bi | 72.4 / 80.6 | 78.0 | 82.1 | 91.8 | 86.7 | 89.8 | 83.5 |
Appendix unsupervised results, Sent2Vec rows only tab. 7. Spearman / Pearson.
| Model | News | Forum | WordNet | Images | Headlines | SICK | Avg. | |
|---|---|---|---|---|---|---|---|---|
| Books uni | .62/.67 | .49/.49 | .75/.72 | .70/.75 | .78/.82 | .61/.63 | .61/.70 | .65/.68 |
| Books uni+bi | .62/.67 | .51/.51 | .71/.68 | .70/.75 | .75/.79 | .59/.62 | .62/.70 | .65/.67 |
| Books uni+bi, L1 | .62/.68 | .51/.52 | .72/.70 | .69/.75 | .76/.81 | .60/.63 | .62/.71 | .66/.68 |
| Wikipedia uni | .66/.71 | .47/.47 | .70/.68 | .68/.72 | .76/.79 | .63/.67 | .64/.71 | .65/.68 |
| Wikipedia uni+bi | .68/.74 | .50/.50 | .66/.64 | .67/.72 | .75/.79 | .62/.67 | .63/.71 | .65/.68 |
| Wikipedia uni+bi, L1 | .69/.75 | .52/.52 | .72/.69 | .67/.72 | .76/.80 | .61/.66 | .63/.72 | .66/.69 |
| Twitter uni | .67/.74 | .52/.53 | .75/.72 | .72/.78 | .77/.81 | .64/.68 | .62/.71 | .67/.71 |
| Twitter uni+bi | .68/.74 | .54/.54 | .72/.69 | .70/.77 | .76/.79 | .62/.67 | .63/.72 | .66/.70 |
The paper's figure fig. 1 shows two profiles. The left panel plots the learned L2 norm of each vocabulary word's vector against the log of its frequency. The right panel shows the static weight a/(a + f_w) used by Arora et al. The authors read the learned norms as the model down-weighting very frequent and very rare words, roughly in line with Luhn's mid-rank hypothesis §5.
The paper also reports that the L1 variants give small gains on supervised tasks (82.1 and 83.4 averages, tab. 6). The authors' explanation for the bigram gains on supervised tasks is that bigrams capture some non-compositional meaning, such as "not good" §5.
Paper vs code
Repository: the paper links https://github.com/epfml/sent2vec in a footnote §1, so it is the official code. This card cites commit 9efbc2dd69f6c737c3a752c9dc5fbb4843d578b6. The repository's LICENSE is the BSD text for fastText, copyright Facebook LICENSE. The code is built on fastText, which the paper acknowledges §2.4.
-
Learning rate default. Paper: 0.2 for every model tab. 5. The README help lists 0.2 README.md and its example passes
-lr 0.2README.md. The releasedsent2veccommand sets 0.05 when no-lris given args.cc. Pass-lr 0.2explicitly. -
Bigram default. The paper's unigram+bigram models use n-grams up to length 2 tab. 5. The released default is
wordNgrams = 1, which trains a unigram model args.cc; the README help lists 2 README.md. Pass-wordNgrams 2. -
Target position in the context. Paper: the context is S \ {w_t}, the sentence without the target §2.1 eq. 3. Released code: the target is overwritten with a placeholder id and stays in the context fasttext.cc. The placeholder is the first vocabulary entry, a dedicated
<PLACEHOLDER>word with its count reset to zero dictionary.cc. Its row is trained like any other model.cc. The effect is that the average includes one placeholder vector and up to two bigrams that touch the target position. -
Dropout granularity. Paper: K n-grams are dropped "for each sentence" §2.4. Released code: a fresh random set of K token positions is drawn for each kept target fasttext.cc. A dropped position removes the bigrams that touch it, so one position can remove up to two bigrams dictionary.cc. Unigrams are never removed. For short sentences the loop stops once two positions remain, so fewer than K positions may be dropped dictionary.cc.
-
Sentence order. Paper: "select a sentence randomly" §2.4. Released trainer: each thread reads the input file in order from its byte offset fasttext.cc. There is no shuffle, so shuffle the input file yourself if you want random order.
-
L1 penalty. Paper: the L1 variant with τ = 0.0005 app. B tab. 6. Released code: a search of
src/for L1, proximal and soft-threshold code found none. The L1 rows in tab. 6 and tab. 7 cannot be reproduced from this release. -
Min target count. Paper: column "Minimum Target word Count" tab. 5, not explained in the text. Released code:
-minCountLabelskips a position as a target when its count is below the value, but the word stays in the context fasttext.cc. The vocabulary cut uses-minCountdictionary.cc. The help text calls the option the minimum "label occurences" args.cc. -
Subsampling formula. Paper: q_p = min{1, sqrt(t/f) + t/f} §2.1. Released code: the probability is sqrt(t/f) + t/f without the min dictionary.cc. This is equivalent, because a value of at least 1 always keeps the word.
-
Hashing. Paper: the bigram hashing uses "the same hashing function as FastText" §2.2. Released code: a bigram's id is the vocabulary size plus (first_id · 116049371 + second_id) mod bucket, computed on vocabulary ids dictionary.cc. The FNV string hash is used for character n-grams dictionary.cc, which the sentence vector does not use fasttext.cc.
-
Negative sampling. Paper: a weighted sum over the vocabulary in eq. 3. Released code: for each kept target it draws
negnegatives from the count^0.5 table and rejects the target model.cc model.cc. The table has 10^7 entries model.h. This is a sampled estimate of eq. 3. -
Gradient normalisation. Paper: the sentence vector is an average eq. 2, but the gradient scaling is not stated. Released code: after each update it divides the shared gradient by the number of context features model.cc.
-
Tokenisation and case. Paper: Stanford and NLTK tokenisers §2.4; case handling not stated. Released code: the trainer does no tokenisation or lowercasing README.md. The Wikipedia and tweet scripts lowercase by default wikiTokenize.py tweetTokenize.py.
-
Evaluation code. Paper: the classifiers use the code of SkipThought §4. The repository has no evaluation scripts; its files are the trainer, the Python wrapper and tokenisers.
Checked and matching: the negative-sampling distribution §2.1 and the linear learning-rate decay §2.4.
Pitfalls
- Learning rate and bigram flags are not the defaults. The
sent2veccommand with only-inputand-outputtrains a unigram model at learning rate 0.05 args.cc args.cc. Set-lr 0.2 -wordNgrams 2and the other table values tab. 5. - Bigram ids depend on vocabulary order. Bigram buckets are computed from
vocabulary ids, and ids are assigned by sorted count dictionary.cc
dictionary.cc. A different
-minCountor vocabulary cut changes which bigram hits which bucket. To match released vectors, reproduce the vocabulary and its ids. - Bucket size is not stated. The input matrix has (vocabulary + buckets) rows
of
dimvalues fasttext.cc. The README example's 4,000,000 buckets at 700 dimensions is 2.8 billion values before the vocabulary rows (arithmetic from the README example), so memory is set by the bucket count. - Out-of-vocabulary tokens are deleted before bigrams form. Their neighbours become bigram partners dictionary.cc. A sentence with no in-vocabulary token gets a zero vector because the mean is skipped fasttext.cc. The paper says nothing about either case.
- Repeats are counted. The paper's R(S) is called a "list" §2.1. The code counts every occurrence, so a repeated word or bigram is counted again dictionary.cc. Do not deduplicate.
- Sigmoid and log are lookup tables. The sigmoid table has 512 entries over [−8, 8] and returns 0 or 1 outside that range model.cc model.h. The log is also tabulated model.cc. Exact-math reimplementations will differ slightly; the paper gives no tolerance.
- Learning-rate decay runs over all epochs. Progress is measured against the total token count across all epochs, not per epoch fasttext.cc.
- Long sentences are not truncated. The 1024-token line cap is skipped for
sent2vecdictionary.cc. A newline ends a sentence dictionary.cc. - Equation 6 has a typo. It writes |x_n| where x is meant eq. 6 app. B.
- Averages are not comparable across tables. The Table 1 average counts MSRP by accuracy only tab. 1. The macro average in tab. 3 is a different quantity.
- Corpus-size comparisons. Arora et al. used GloVe trained on a corpus 42 times larger than the paper's Twitter corpus, which the authors say favours that baseline §5 tab. 4.
- The STS 2017 claim has no numbers. The paper says the model "significantly outperforms" C-PHRASE on the official STS 2017 benchmark §5, but gives no figures.
- Costs the abstract leaves out. Training on the 19.7B-word Twitter corpus took 6.5 hours on a single node with 30 threads tab. 3. Inference costs |S|·h operations per sentence §2.2.
Lineage
- Builds on: C-BOW (Mikolov et al. 2013), whose context window is extended to the whole sentence §2.3; unsupervised word embeddings, GloVe §1; the FastText work of Bojanowski et al. and Joulin et al., whose negative sampling, subsampling and hashing are reused §2.1 §2.2. None has a card on this wiki.
- Compared against: SkipThought (Kiros et al. 2015), SDAE and SAE (Hill et al. 2016), ParagraphVector (Le et al. 2014), FastSent, Siamese C-BOW (Kenter et al. 2016), C-PHRASE (Pham et al. 2015), DictRep and CaptionRep, and the averaging approach of Arora et al. 2017 §3 §5. None has a card on this wiki.
- Extended by: Bi-Sent2vec, a cross-lingual extension linked from the repository README (arXiv:1912.12481) README.md. Not compiled here.
- Superseded by: not stated in this wiki.
Source and license
Adapted from “Unsupervised Learning of Sentence Embeddings using Compositional n-Gram Features” by Matteo Pagliardini, Prakhar Gupta, Martin Jaggi (arXiv:1703.02507), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/epfml/sent2vec at commit 9efbc2dd69f6 (BSD-3-Clause). Any quoted code is shown under that license.