Paper commentary
Universal Sentence Encoder
Sentence-level embeddings often transfer better than word embeddings to small NLP tasks
- Problem Many NLP tasks have small labelled datasets, and pretrained word vectors say little about whole sentences.
- Method Universal Sentence Encoder (USE) has two encoders, one transformer and one deep averaging network, that map a sentence to a 512-dimensional vector.
- Results USE T reached 84.85 on SST with 1,000 training examples, against 67.98 for a CNN with learned word embeddings.
Why reuse at the sentence level
Many NLP tasks have only small labelled datasets, while deep learning models need a lot of data to train well. A common workaround is to start from pretrained word vectors such as word2vec or GloVe. These vectors supply lexical information but say little about how a whole sentence is composed.
Recent work moved the reuse one level up, to embeddings that represent entire sentences. The paper builds two encoders in this direction and releases them through TF Hub, with experiments that vary how much task-specific training data is available.
Two questions follow from this setup. The first is whether sentence-level reuse beats word-level reuse on the same task, and the second is how much task data is needed before the reuse pays off.
Two encoders behind one interface
Both encoders accept an English string and return one fixed-size vector. The input is lowercased and PTB tokenized before encoding, and the output has 512 dimensions in both encoders. A short Python snippet in the paper shows that a single call to the hub module yields a tensor holding the embedding, which can be used directly or placed inside a larger graph.
The transformer encoder takes the encoding sub-graph of a transformer. Attention gives each word a representation that depends on the order and identity of the other words in the sentence.
The deep averaging network takes the average of the input embeddings for words and bi-grams and passes that average through a feedforward network. Because the averaging step costs time that grows linearly with the input, this encoder is built for efficient inference.
The two encoders are designed for different goals. The transformer variant aims at higher accuracy and pays for it with more model complexity and resource use, while the deep averaging variant accepts slightly lower accuracy for speed.
What shapes the shared embeddings
One encoder is trained for several downstream objectives at once, which is a form of multi-task learning. This lets a single set of sentence embeddings feed different tasks. For the transformer variant, the unsupervised objective is a Skip-Thought style task learned from running text. In this version the LSTM of the original formulation is replaced by a transformer-based model.
A conversational input-response objective and classification objectives on supervised data complete the set.
Supervised data from the SNLI corpus is added, and the authors observed that training on SNLI improves transfer performance.
Scoring sentence pairs by angle
For pairwise semantic similarity, no extra classifier is trained. The cosine similarity of the two embeddings is computed and then converted into an angular distance with arccos. The score is written as follows.
\[ \mathrm{sim}(u,v) = \left(1 - \frac{\arccos\left(\frac{u\cdot v}{\lVert u\rVert\,\lVert v\rVert}\right)}{\pi}\right) \]
Tasks, baselines and protocol
The evaluation covers six sentence classification datasets, MR, CR, SUBJ, MPQA, TREC and SST, plus the STS Benchmark for similarity. For SST, the training set has 67,349 examples, the dev set 872 and the test set 1,821. The STS Benchmark has 5,749 training, 1,500 dev and 1,379 test pairs.
Word-level baselines feed word2vec skip-gram embeddings trained on news data into a CNN or a DAN. Other baselines learn randomly initialized embeddings from the task data alone. Combined models concatenate the sentence-level representation with the word-level one before the task layers.
Hyperparameters are tuned on dev sets where they exist, and otherwise by cross-validation on the training data. When neither training nor dev data are given, the test data are used for tuning. Each transfer model is trained ten times with different random initial weights, and the reported scores are averages over those runs.
Accuracy across transfer tasks
USE T is usually as accurate as or more accurate than USE D. The simpler USE D still matches or beats USE T on some tasks. On MR, USE T reached 81.44 and USE D reached 74.45, which shows the gap in a single task.
Sentence-level models often beat models that use only word-level transfer. On MR, USE T scored 81.44 against 75.10 for the CNN with word2vec embeddings. The pattern is not uniform. On SST, the DAN with word2vec embeddings scored 80.24, above USE D's 77.62.
The best scores on most tasks come from models that combine sentence-level and word-level transfer. On TREC, the USE T plus CNN model with word2vec embeddings reached 98.07.
On the STS Benchmark test set, USE T reached a Pearson correlation of 0.782 and USE D reached 0.719. Their dev scores were 0.814 and 0.763. These similarity scores come from the angular scoring of the sentence embeddings directly, with no task-specific layer trained on the STS pairs.
Effect of training-set size on SST
SST training subsets range from 1k examples up to the full 67.3k set. Each subset is evaluated for models with and without transfer learning.
With 1,000 training examples, USE T reached 84.85, close to its 85.38 on the full training set. USE D showed a similar flat curve, moving from 77.47 at 1k to 77.62 at 67.3k.
Word-level models without pretraining start far lower. The CNN with learned word embeddings reached 67.98 at 1k and 84.90 on the full set. As the training set grows, the models without transfer learning approach the other models, so the advantage of sentence-level transfer is largest when data is scarce.
Bias probes with WEAT
WEAT compares sets of target words with sets of attribute words and summarizes the association by an effect size and a one-tailed p-value. The authors compare USE D against GloVe results taken from earlier work on the same word lists.
On the flowers versus insects probe, USE D gives a Cohen's d of 1.38, against 1.50 for GloVe, and both reach p-values of 10−7 with the attribute pleasantness split. The authors read this as the encoder reproducing the same human-like associations that GloVe shows for that probe.
For probes aimed at ageism, racism and sexism, USE D shows weaker associations than GloVe.
Compute and memory as sentences grow
Compute time for the transformer grows as \(O(n^2)\) in sentence length, while the DAN grows as \(O(n)\). For short sentences the transformer is only moderately slower than the DAN. As sentences get longer, the transformer's time rises noticeably, while the DAN's time stays nearly constant.
The authors note that GPU use over CPU use will often matter more for the transformer than for the DAN, given how cheap the DAN is.
Memory follows the same split. The transformer's space scales quadratically with sentence length, while the DAN's memory does not depend on length. For the DAN, memory is dominated by the stored unigram and bigram embeddings. The transformer stores only unigram embeddings, so for short sequences it needs nearly half the memory of the DAN.
Limitations
At the time of writing, the DAN encoder was available for download, and the transformer encoder was to be released at a later point.
The transformer's higher accuracy comes with compute and memory costs that rise sharply as sentences get longer.
The WEAT analysis covers the probes the authors chose, and their explanation for the weaker associations was not tested in a separate experiment.
Paper info
- Authors
- Daniel Cer, Yinfei Yang, Sheng-yi Kong, Nan Hua, Nicole Limtiaco, Rhomni St. John, Noah Constant, Mario Guajardo-Cespedes, Steve Yuan, Chris Tar, Yun-Hsuan Sung, Brian Strope, Ray Kurzweil
- Venue
- arXiv · Preprint
- First published
- 2018-3-29
- Added
- 2026-11-12
- Updated
- 2018-4-12
- Version
- v2
- arXiv
- 1803.11175
- Category
- cs.CL
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Daniel Cer, Yinfei Yang, Sheng-yi Kong, Nan Hua, Nicole Limtiaco, Rhomni St. John, Noah Constant, Mario Guajardo-Cespedes, Steve Yuan, Chris Tar, Yun-Hsuan Sung, Brian Strope, Ray Kurzweil (2018). Universal Sentence Encoder. arXiv:1803.11175v2. https://arxiv.org/abs/1803.11175v2
BibTeX
@misc{cer2018universal,
title = {{Universal Sentence Encoder}},
author = {Daniel Cer and Yinfei Yang and Sheng-yi Kong and Nan Hua and Nicole Limtiaco and Rhomni St. John and Noah Constant and Mario Guajardo-Cespedes and Steve Yuan and Chris Tar and Yun-Hsuan Sung and Brian Strope and Ray Kurzweil},
year = {2018},
eprint = {1803.11175},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1803.11175v2}
}