Aspect-Based Sentiment Analysis
"Revenue rose, but costs climbed" holds two opinions, and no reader of the sentence alone gets both. One attention layer whose query is the aspect is a signed vote over the words: it can stretch a word's vote but never flip it, which decides what it can read and what it cannot. Its attention weights are not an explanation, and read aspect by aspect the corpus gives back the document tone that every document-level reader missed
Overview & Motivation
The lexicon topic ended on sentences no word list can read. “Costs rose 5 percent” has no polar word, so a lexicon abstains; “costs exceeded expectations” is bad news written with a good word; and a sentence that praises one thing and faults another has no single polarity to give. Each of these has a target. Here is a test sentence from the synthetic filings of the last two topics:
Liquidity declined 11 percent in rebateware, a trend executives characterized as disappointing, but net sales in clinicing midroutes were healthy.
The corpus annotates two aspects in it: liquidity, negative, and net sales, positive. Aspect-based sentiment reads one polarity per aspect, and that changes the question a classifier answers. This page asks which models can represent the answer, using the aspect annotations as gold. In order:
- The aspect-blind ceiling. What any reader that ignores the aspect must get wrong.
- One layer, one vote. An attention layer whose query is the aspect is a signed vote over the words.
- Valence. Why “rose” and “fell” must vote the same way in such a layer, and what lifts that.
- Negation. What no such layer can read, on any data.
- Attention is not the explanation. Decisions do not pin down attention weights.
- From aspects to tone. Reading aspect by aspect gives back the document tone that the earlier topics missed.
On this corpus an aspect’s polarity is a deterministic function of its clause and its category, so the aspect-level Bayes accuracy is . Every limit on this page is a limit of representation, not of data.
An opinion has a target
Definition 1 (Aspect-level sentiment).
A sentence and an aspect : a span of with a category and a valence . Valence means a rise is good for the company (revenue, margin, demand, liquidity) and means a rise is bad (costs, tax, liabilities). The aspect’s polarity is . Aspect sentiment classification predicts from .
On the corpus the polarity is written in a few ways. A direction clause (“costs rose 5 percent”) has for the move . An evaluative adjective or noun (“margins were solid”) carries itself. “Not” before an adjective reverses it. A verb of expectation carries times its own sign, so “costs exceeded expectations” is negative. Finding the aspect spans in the first place is span labeling, which the extraction topics take up; here the spans and categories come from the gold annotation. Hu and Liu (2004) attached opinions to product features in this way, and SemEval-2014 Task 4 (Pontiki and colleagues 2014) fixed the split into finding terms and classifying their polarity.
The test filings hold aspects, per filing: negative, neutral, positive. Of them, sit two to a sentence, joined by “but”, and in every such sentence the two polarities are opposite. That alone limits any reader that ignores which aspect it was asked about.
Proposition 1 (The aspect-blind ceiling).
Let a test set of aspects contain aspects that sit two to a sentence with opposite polarities. Every classifier of the sentence alone has accuracy at most .
Proof.
Both aspects of such a sentence present with the same input and different labels, so equals at most one of them. At least aspects are misread.
∎Here , so the ceiling is . Two aspect-blind readers sit under it. Topic 18’s lexicon with its one-token negation scope, read on the whole sentence, scores and gets of the contrast aspects right. A logistic regression on the sentence’s words and word pairs, trained on the training aspects with the previous topics’ Newton solver, scores and gets exactly of the contrast aspects: on each pair it reads the side whose words dominate. It also fails sentences like “Costs in intertariffs transcargos exceeded expectations”, reading of the cost-like verbs, because the cost word and the verb are not adjacent, so no word pair carries their interaction. That is Proposition 4 of the linear classifiers topic, the exclusive-or of valence and direction, back again.
One layer, one vote
The standard repair, since Tang, Qin, and Liu (2016) and Wang and colleagues (2016), is to let the aspect choose which words to read: an attention layer whose query is the aspect. Proposition 1 of the attention topic says such a layer is a Nadaraya–Watson smoother, a kernel-weighted average of the words’ values. Picture each word of the sentence as a bar, its vote for “positive over negative”, pointing up or down. The aspect’s attention stretches every bar by a positive factor, and the layer’s decision is the sign of the total. The factor can be tiny or huge. It is never negative.
Definition 2 (An aspect-query attention layer).
The items of are its tokens and, with bigram items, each pair of adjacent tokens, placed at its right token. Item has a type and an offset from the aspect span ( inside it). The layer scores each item by a content part and a position part, , and sets . Values live in logit space, , and the logits are . With shared votes, and do not depend on the aspect, so the aspect enters only through the scores; with aspect-conditioned values, .
The content score is a query against a key, and is a kernel in the distance to the aspect, the location weighting of Tang, Qin, and Liu. A value in logit space is the usual value vector after the output layer. For classes and , write
for the vote of item for over .
Theorem 1 (One layer is a signed vote).
(a) For every pair of classes, , so . For a fixed aspect, every decision is a linear threshold function of the bag of items, whose weights are positive rescalings of signed votes.
(b) Valence needs votes that depend on the aspect. Let and be aspects of valence and , let and be a rise word and a fall word, and consider four sentences that differ only in the aspect and in the direction word, which sits at the same offset: , , , , labeled . Take shared votes and their positive-over-negative part ; for each aspect , let be the summed vote of the words its two sentences share and the factor of direction word . The layer gets all four positive-over-negative comparisons right exactly when
So a layer reads all four only if and are nonzero with the same sign, each aspect’s other words vote the opposite way, and the signed weights put above for and below it for . Those three conditions are necessary, not sufficient. The displayed ones are sufficient: any factors, votes, and context sums that satisfy them are realized by a layer that reads all four, with value vectors whose neutral entry is . With aspect-conditioned values, the votes are allowed as well.
(c) Substitution is monotone. For a fixed aspect, replacing the item type by at offset changes by , where , and the sign of that change depends neither on the rest of the sentence nor on . Hence no layer with single-token items reads all four of “T was ADJ₊” (), “T was ADJ₋” (), “T was not ADJ₊” (), and “T was not ADJ₋” ().
(d) With bigram items, some layer reads all four.
Proof.
(a) Since , . Multiplying by gives the sign identity. For a fixed aspect, , , and depend only on each item’s type and offset, so the sum is linear in the counts of (type, offset) pairs.
(b) Getting both sentences right on positive over negative means , and both sentences ; rearranged, these are the displayed inequalities. They give and , the stated order of the signed weights. If , the second order fails, since its left side is at least and its right side at most ; if , the first fails. So the two votes are nonzero with one sign. If it is positive, and ; the negative case is the mirror image. The three conditions do not give back the displayed ones: with , , , and , all three can hold while "" sums to . Conversely, take factors, votes, and context sums that satisfy the displayed inequalities, give each item with vote the value , and set the bias to . Then , so the decision is the sign of the vote sum, neutral loses whenever that sum is nonzero, and the inequalities make the sign right in all four sentences. With aspect-conditioned values, and are separate unknowns, and the votes under can carry their meaning.
(c) The sum is additive over items, and only the replaced item’s term changes, from to ; the factor is positive. Write for the positive-over-negative sum. Reading “T was ADJ₊” and “T was ADJ₋” needs to fall when ADJ₊ becomes ADJ₋, so . Reading the two negated sentences needs to rise under the same replacement, so . The adjective sits at offset in the first pair and in the second, which changes only the positive factor.
(d) Give every item score , the adjectives votes and , the bigram items “not ADJ₊” and “not ADJ₋” votes and , and every other item vote , each realized as in (b) by the value with bias . With items the four vote sums are , , , and , so each sentence’s decision is the sign of its sum and neutral never wins.
∎Part (a) is Topic 9’s kernel reading made sharp for a classifier. The attention decides how much each word counts, the value decides which way, and only the value can change the way. Parts (b) and (c) are what follows from that.
We trained three such layers on the training aspects, with nothing tuned: shared votes over single tokens, aspect-conditioned values over single tokens, and aspect-conditioned values over tokens and bigrams. Each takes full-batch steps of Adam and a few seconds, and the gradient code was checked against complex-step derivatives at random parameters. The Read a sentence tab shows each one’s attention and votes, word by word, on seven test aspects. The two aspects of the opening sentence read the same words: declined carries a large negative vote for liquidity, and healthy a positive one for net sales.
The vote bars sum to the logit gap. Attention only stretches them: switch layers on the bare direction or the negated adjective to see which words a vote can and cannot turn around.
Valence: the words that cannot mean what they say
With shared votes, “rose” votes the same way whichever aspect asks. Part (b) says what that forces: to read “revenue rose” as good news and “costs rose” as bad, the layer cannot let rose and fell vote opposite ways. Both direction words must vote the same way, positive or negative, and the query must turn the volume of one of them up for revenue and of the other up for costs, against a backdrop of other words that vote the opposite way and whose summed vote falls strictly between the two weighted direction votes. A linear program over the nine sign patterns of finds exactly the two same-sign patterns feasible.
The trained shared layer found that configuration for one family of words only. Its positive-over-negative votes, the shared bias included, are for rose, for fell, for declined, and for decreased, but for increased and for climbed. On the test sentences it reads of the bare-direction aspects. To see the theorem rather than an accuracy, take every one of the single-aspect test sentences that give a one-word term a bare direction, such as “Taxes increased 5 percent in cargopoint.” (all six direction words occur), set its aspect to revenue or costs and its direction word to each of the (rise, fall) pairs, and ask for all four sentences of each quadruple right, following Gardner and colleagues (2020) on contrast sets. The shared layer reads of the quadruples: of the built on the pairs out of whose words vote the same way (every miss is the costs sentence with the fall word), and none of the other , which part (b) guarantees it cannot read.
Aspect-conditioned values let a word’s vote depend on the aspect, which is what ATAE-LSTM (Wang and colleagues 2016) does by appending the aspect’s embedding to every input. That layer reads all quadruples, of the bare directions and of the cost-like verbs, and of the contrast aspects, against the blind regression’s .
Negation: what a vote cannot do
Part (c) is the sharper limit, because it holds for any values whatsoever. Replacing one word by another at a fixed place moves the vote in a direction that no surrounding words can reverse. Negation is precisely a surrounding word that reverses an adjective’s effect, so it is out of reach: this is the exclusive-or of Topic 17’s Proposition 4 again, now between two words of the same sentence rather than between the aspect and a word.
The aspect-conditioned layer reads every other construction at or better, and of the negated adjectives. That is no coin flip: it calls of the negated aspects positive, and on the single-aspect ones its attention sits on this (), not on not (). For a contrast set, take each of the test sentences of the form “T was not ADJ this period”, set the adjective to each of the pairs of a positive and a negative adjective, and keep or delete “not”. Both single-token layers read none of the quadruples, as part (c) requires of every layer in their class. The layer with bigram items reads all of them, and of the negated test aspects.
Both aspect-blind readers read every negation quadruple too. Topic 18’s scope rule, “a negator within one token flips the sign”, is a bigram feature written by hand, and the blind regression has “not strong” and “not weak” among its word pairs. Neither reads a single valence quadruple: the lexicon has no direction words and the regression has no aspect. Each family repairs a different exclusive-or. The bigram layer has both repairs and misreads of the test aspects. The What one layer can read tab lays out every reader against every construction and both contrast sets.
Attention is not the explanation
Aspect-level models are often presented with a heat map of their attention, as if it showed what the model read. Theorem 1 says a decision depends on the products , attention times vote, and not on either factor alone. That freedom is exact.
Theorem 2 (Decisions do not determine attention).
Take a layer as in Definition 2 and a positive weight for each item type. Define a second layer by and , with everything else unchanged. For every input, with . Therefore:
(a) every decision, the argmax and every pairwise comparison, is unchanged;
(b) every item’s contribution is multiplied by the same , so the profile of contributions is unchanged;
(c) for a set of types present in every sentence, setting on that set moves the attention on it to as ;
(d) the probabilities are , a temperature that depends on the input, so they are not preserved.
Proof.
The new scores are , so the new attention is , and
Since , (a) follows, and (b) is the same computation term by term. For (c), the attention on the set is , where and sum over the items in and out of the set, and this tends to . Part (d) is immediate.
∎If the values are for an output matrix of full row rank, the same map is realized by solving . On the trained bigram layer, the attention on the words of aspect terms averages over the test aspects: the layer reads the words around the aspect, not the aspect itself. Setting on those words gives a layer that puts of its attention on them, and at least in every sentence, and makes the same decision on all test aspects. Those are all the aspect-term words in the sentence, of included: on the asked-about aspect’s own words the share is , and in a contrast sentence only , with on the other aspect’s term. A heat map of the first layer and a heat map of the second tell opposite stories about one function.
Part (d) is the honest limit. The rescaling shrinks the logits, by factors between about and at , so the probabilities flatten toward : the temperature of the calibration topic, here varying with the input. The decisions are identified, the attention is not, and the contribution profile is the invariant, the logit-space version of what Kobayashi and colleagues (2020) propose measuring, the norm of the weighted, transformed vector. Jain and Wallace (2019) found alternative attention distributions with nearly unchanged predictions in trained models, and Wiegreffe and Pinter (2019) asked when such alternatives undercut an explanation; Theorem 2 is the exact version of the first observation for one layer. The Attention isn’t the explanation tab moves from to on the second aspect of the opening sentence.
From aspects to tone
Where this sits
The aspect-level models of 2016–2017 (Wang and colleagues; Tang, Qin, and Liu; Ma and colleagues 2017) were one or two attention layers over recurrent states, with the aspect in the query. Jiang and colleagues (2019) built MAMS from sentences like this page’s contrast sentences, every one with two aspects of different polarity, because those were the ones that separated the models. Sun, Huang, and Qiu (2019) fed the aspect to a pretrained encoder as a second sentence, which escapes Theorem 1 the deep way: every word’s value is already a function of its neighbors and of the aspect. The next topic, fine-tuning, trains such an encoder. The extraction topics find the aspect spans that this page took as given, and the capstone reads earnings calls aspect by aspect.
Honest caveats
Implementation
The companion notebook (notebookPath) imports aspect_based_sentiment.py, which owns every number on this page. That module imports the lexicon topic’s module for the stand-in lexicon, its negation scope, its construction labels, and, through it, the linear classifiers topic’s split, features, Newton solver, and Bayes ceiling; and it imports the attention topic’s module for its attention function and Topic 5’s complex-step checker. Its harness checks:
- that every gold aspect is a row, with its span on an aspect term, and that two-aspect sentences have opposite polarities;
- Proposition 1’s bound, at most one aspect per contrast pair for both aspect-blind readers, and the regression’s ;
- the layer against the attention topic’s attention function, and the gradient code against complex-step derivatives at random parameters;
- Theorem 1(a) on random layers to , (b) and (c) as linear programs, and both on the trained layers through the contrast sets;
- Theorem 2 on random layers with random weights, and on the trained bigram layer over the whole test split;
- the tone-bearing sentences against the generator, Proposition 2’s bound, and the aggregation within two standard errors of the ceiling;
- the EDGAR readings.
The laboratory reads its data from a JSON file that one of the harness’s tests requires to equal the module’s viz_payload() exactly, so the figure cannot drift from the code.
References & Further Reading
- paper Mining and Summarizing Customer Reviews — Minqing Hu and Bing Liu (2004) Proceedings of the 10th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 168–77. Opinions attached to product features, the origin of feature-based (aspect) sentiment
- paper SemEval-2014 Task 4: Aspect Based Sentiment Analysis — Maria Pontiki, Dimitrios Galanis, John Pavlopoulos, Harris Papageorgiou, Ion Androutsopoulos, and Suresh Manandhar (2014) Proceedings of the 8th International Workshop on Semantic Evaluation, 27–35. The benchmark that split the field into term extraction, term polarity, category detection, and category polarity
- paper Attention-based LSTM for Aspect-level Sentiment Classification — Yequan Wang, Minlie Huang, Xiaoyan Zhu, and Li Zhao (2016) Proceedings of EMNLP 2016, 606–15. ATAE-LSTM: the aspect embedding steers the attention and is appended to every input, the move this page's aspect-conditioned values make
- paper Aspect Level Sentiment Classification with Deep Memory Network — Duyu Tang, Bing Qin, and Ting Liu (2016) Proceedings of EMNLP 2016, 214–24. Attention hops over the context with the aspect as the query, and location weighting by distance to the aspect
- paper Interactive Attention Networks for Aspect-Level Sentiment Classification — Dehong Ma, Sujian Li, Xiaodong Zhang, and Houfeng Wang (2017) Proceedings of the 26th International Joint Conference on Artificial Intelligence, 4068–74. The aspect attends to the context and the context to the aspect
- paper A Challenge Dataset and Effective Models for Aspect-Based Sentiment Analysis — Qingnan Jiang, Lei Chen, Ruifeng Xu, Xiang Ao, and Min Yang (2019) Proceedings of EMNLP-IJCNLP 2019, 6280–85. MAMS, whose every sentence holds at least two aspects with different polarities: this page's contrast sentences, as a benchmark
- paper Utilizing BERT for Aspect-Based Sentiment Analysis via Constructing Auxiliary Sentence — Chi Sun, Luyao Huang, and Xipeng Qiu (2019) Proceedings of NAACL-HLT 2019, 380–85. The aspect as a second sentence for a pretrained encoder, the deep escape from Theorem 1
- paper Attention is not Explanation — Sarthak Jain and Byron C. Wallace (2019) Proceedings of NAACL-HLT 2019, 3543–56. Adversarial attention distributions that leave predictions nearly unchanged
- paper Attention is not not Explanation — Sarah Wiegreffe and Yuval Pinter (2019) Proceedings of EMNLP-IJCNLP 2019, 11–20. When an alternative attention distribution counts as an explanation, and tests for it
- paper Attention is Not Only a Weight: Analyzing Transformers with Vector Norms — Goro Kobayashi, Tatsuki Kuribayashi, Sho Yokoi, and Kentaro Inui (2020) Proceedings of EMNLP 2020, 7057–75. Measure the weighted transformed vector, attention times the transformed input, rather than attention alone: Theorem 2's invariant
- paper Evaluating Models' Local Decision Boundaries via Contrast Sets — Matt Gardner, Yoav Artzi, Victoria Basmov, Jonathan Berant, Ben Bogin, Sihao Chen, Pradeep Dasigi, et al. (2020) Findings of EMNLP 2020, 1307–23. Small, label-changing edits of test examples, the method of this page's quadruples
- paper WWW'18 Open Challenge: Financial Opinion Mining and Question Answering — Macedo Maia, Siegfried Handschuh, André Freitas, Brian Davis, Ross McDermott, Manel Zarrouk, and Alexandra Balahur (2018) Companion Proceedings of The Web Conference 2018, 1941–42. FiQA, whose Task 1 is aspect-based sentiment on financial microblogs and headlines
- paper Neural Machine Translation by Jointly Learning to Align and Translate — Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio (2015) ICLR 2015. Soft attention as a learned alignment, the mechanism the aspect-level models adopted