The decomposable attention model of Parikh et al. classifies a premise A=(a1,…,am) and a hypothesis B=(b1,…,bn), both sequences of word embeddings in RE, as entailment, contradiction or neutral, using only MLPs and attention:
- Attend: eij=f(ai)⊤f(bj); βi=∑jsoftmaxj(ei⋅)bj (softmax over j) and αj=∑isoftmaxi(e⋅j)ai (softmax over i).
- Compare: vA,i=g([ai,βi]) and vB,j=g([bj,αj]), with [⋅,⋅] concatenation.
- Aggregate: vA=∑ivA,i, vB=∑jvB,j, and y^=h([vA,vB]).
Each of f, g, h is a two-layer MLP given as a dict with W1, b1, W2, b2, computing mlp(x)=W2ReLU(W1x+b1)+b2 (applied to each row independently).
Implement decomposable_nli(A, B, f, g, h) with A of shape (m, E) and B of shape (n, E), returning a dict with "logits" (shape (3,)), "E" (the (m, n) matrix eij), "beta" ((m, E)) and "alpha" ((n, E)). Use numerically stable softmaxes.