Paper commentary
A Structured Self-attentive Sentence Embedding
Self-attention lets sentence embeddings focus on several parts of a sentence
- Problem Sentence encoders squeeze a whole sentence into one vector, which can strain on long inputs. Attention over time steps needs an extra source of guidance, so single-sentence models usually pool across all positions instead.
- Method The Structured Self-attentive Embedding adds a self-attention step over bidirectional LSTM states. Several attention rows each pick out a different part of the sentence, and a penalty keeps the rows distinct.
- Results The model reaches 80.45% accuracy on the Age test set and 64.21% on the Yelp test set. These beat the biLSTM with max pooling at 77.40% and 61.99%.
Why single pooled vectors strain
Word embeddings are well established, but sentence-level representations are less settled, and existing methods fall into two groups. One group learns general-purpose sentence vectors without labels, while the other trains encoders inside a supervised task and usually performs better on that task.
Supervised sentence encoders built on recurrent, recursive or convolutional networks typically turn the sequence into one vector, either from the last hidden state or from pooling over positions. For single-sentence inputs, attention cannot draw on an extra source of guidance, so the usual fix is a pooling step across all time steps.
The authors argue that keeping every piece of meaning alive across all time steps of a recurrent model is hard and unnecessary. They replace pooling with a self-attention step whose several weight vectors can pick out different aspects of the sentence, and the attention also lets the final embedding read earlier hidden states directly.
From token sequence to attention matrix
The input sentence of n tokens is a matrix of word embeddings with n rows and d columns, and a bidirectional LSTM runs over it in both directions. The forward and backward hidden states at each position are concatenated, giving an n-by-2u matrix H, where u is the hidden size of each unidirectional LSTM.
The attention step maps H through a weight matrix and a tanh, followed by a softmax, to give the annotation matrix A. With the formula written as \(A = \mathrm{softmax}(W_{s2}\tanh(W_{s1}H^{T}))\), W_s1 has size d_a by 2u and W_s2 has size r by d_a, and d_a is a hyperparameter that can be set freely. The softmax runs along the position dimension, so each of the r rows of A sums to one over the n tokens.
The sentence embedding is the matrix product \(M = AH\), so each of the r rows of M is a weighted sum of the LSTM hidden states. The authors use several rows because a long sentence can contain several components, such as two clauses joined by a conjunction, that a single weighted sum would blend. In the Age model d_a is 350 and r is 30.
Why a penalty on overlapping rows
If the attention always gives similar weights to all rows, the matrix embedding becomes redundant. A Kullback Leibler divergence between pairs of weight vectors was the natural diversity measure, but the authors found it unstable, because maximizing many divergences drives many attention entries toward zero.
The penalty used instead is the squared Frobenius norm of AA^T minus the identity, written as \(P = \lVert AA^{T} - I \rVert_F^{2}\), multiplied by a coefficient and minimized together with the task loss. The authors report that this term costs about one third of the computation of the KL penalty.
Each off-diagonal entry of AA^T is the sum of elementwise products of two rows of A, and it is zero when the two rows do not overlap. It reaches its largest value when two rows are identical and concentrate on one word.
Subtracting the identity pushes the diagonal toward one, so each row is pushed to focus on as few words as possible. Pushing the off-diagonal entries toward zero penalizes overlap between different rows.
Reading rows as heat maps
Each row of the embedding has its own annotation vector, and each element of that vector gives how much a token's hidden state contributes to that row. Drawing these weights over the tokens of the sentence gives one heat map per row.
Summing all annotation vectors and normalizing the result to sum to one gives a single overall view of which words the embedding uses most and which it skips. These maps are qualitative views of the learned weights, and the paper uses them to interpret the examples discussed in the experiments.
Age and Yelp accuracy against the baselines
The Age dataset is built from English Twitter tweets with five age ranges, and the split used is 68485 training tweets with 4000 development and 4000 test tweets. Accuracy is the metric throughout.
The biLSTM baseline pools its states with max pooling and feeds a two-layer ReLU MLP with 3000 hidden units, while the CNN baseline swaps the recurrent layer for one one-dimensional convolutional layer. The proposed model keeps the same training settings, uses a two-layer ReLU output MLP with 2000 hidden units on Age, and uses 3000 hidden units on Yelp.
On the Age test set the proposed model reaches 80.45%, against 77.40% for biLSTM with max pooling and 78.15% for the CNN. On the Yelp test set it reaches 64.21%, against 61.99% for biLSTM and 62.05% for the CNN.
The Yelp data consists of 2.7M reviews, and the model uses 500K review-star pairs for training with 2000 development and 2000 test examples. The authors took the five-star and one-star reviews on which the model was most confident, above 0.8, and drew their heat maps.
For short reviews the model picks up the key factors behind an extreme score, while on longer reviews it misses some of them. The authors describe one five-star review where most attention falls on a single phrase, with other key points getting little weight.
SNLI with sentence-encoding comparison
The SNLI corpus contains 570k human-written sentence pairs labelled as entailment, contradiction or neutral, and accuracy is the metric. The hypothesis and premise are processed independently, and their relation is extracted with multiplicative interactions following Memisevic (2013), feeding a two-layer ReLU output MLP with 4000 hidden units.
The biLSTM has 300 dimensions in each direction, the attention MLP has 150 hidden units, and both sentence embeddings have 30 rows. The penalty coefficient is 0.3, the word vectors are 300-dimensional GloVe, and AdaGrad is used with a learning rate of 0.01 without dropout or L2 normalization. Training converges after 4 epochs.
The comparison is restricted to methods that encode each sentence before any information is exchanged between hypothesis and premise. The proposed method reaches 84.4% test accuracy, which is at least 1% above the other listed encoders except the 300D NSE encoders, which reach 84.6%. The authors describe the 0.2 point gap to the NSE encoders as small compared with the differences among the other methods.
What the penalty changes
Two identical Age models were trained, one with penalization coefficient 1.0 and one with no penalty, and their attention was plotted for one test tweet. Only 6 of the 30 hops are shown, since the authors judge that they represent the rest.
Without the penalty, the rows are highly redundant and the overall attention concentrates on the token it, which the authors consider unrelated to the age of the author. With the penalty, the hops vary more, and the overall embedding attends to the phrase about mail-reply spam.
On Yelp the authors observe a similar effect, with the penalized model focusing more on the important parts of the review. They attribute this to the diagonal of AA^T being pushed toward one by the penalty.
With coefficient 1.0 the model reaches 64.21% on Yelp and 80.45% on Age, while coefficient 0.0 gives 61.74% and 79.27%. The authors state that models trained with the penalty outperform their counterparts without it.
On SNLI the penalty still encourages diverse rows and focused attention, but its quantitative effect is not obvious, and both models yield similar test accuracies.
How the number of rows matters
The authors varied r from 1 to 30 on Age and SNLI and trained 10 models independently, and r = 1 reduces the embedding to an ordinary vector. The curves are plotted against training epochs for each r.
With one row the model performs on par with competing vector embeddings. Moving from one row to several gives a clear difference in accuracy.
The curves for values of r between 10 and 30 are comparable, so the model is fairly insensitive to r in that range.
Limitations
The training method depends on the downstream application, so the model cannot currently be trained without labels. Unsupervised training would need a sequential decoder on top of the embedding, and the authors note that the rows would have to be divided and reorganized, which is hard to specify in advance.
The main experiments cover three tasks, namely author profiling on Age, sentiment classification on Yelp and textual entailment on SNLI. The gain from the penalty is not obvious on SNLI, and the authors do not establish it there.
The authors claim the model could handle longer texts such as paragraphs and articles without modification, but treat that as beyond the scope of this paper.
Paper info
- Authors
- Zhouhan Lin, Minwei Feng, Cicero Nogueira dos Santos, Mo Yu, Bing Xiang, Bowen Zhou, Yoshua Bengio
- Venue
- arXiv · Preprint
- First published
- 2017-3-9
- Added
- 2026-11-12
- Updated
- 2017-3-9
- Version
- v1
- arXiv
- 1703.03130
- Category
- cs.CL · cs.AI · cs.LG · cs.NE
- 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
Zhouhan Lin, Minwei Feng, Cicero Nogueira dos Santos, Mo Yu, Bing Xiang, Bowen Zhou, Yoshua Bengio (2017). A Structured Self-attentive Sentence Embedding. arXiv:1703.03130v1. https://arxiv.org/abs/1703.03130v1
BibTeX
@misc{lin2017structured,
title = {{A Structured Self-attentive Sentence Embedding}},
author = {Zhouhan Lin and Minwei Feng and Cicero Nogueira dos Santos and Mo Yu and Bing Xiang and Bowen Zhou and Yoshua Bengio},
year = {2017},
eprint = {1703.03130},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1703.03130v1}
}