[CVPR 2021] Official PyTorch implementation for Transformer Interpretability Beyond Attention Visualization, a novel method to visualize classifications by Transformer based networks.
def safe_divide(a, b):
den = b.clamp(min=1e-9) + b.clamp(max=1e-9) # ???
den = den + den.eq(0).type(den.type()) * 1e-9
return a / den * b.ne(0).type(b.type())
and