class_docstr: 这是一个基于论文 `A structured self-attentive sentence embedding <https://arxiv.org/pdf/1703.03130.pdf>`_
  的 **Self Attention Module** 。
  
  :param  input_size: 输入 tensor 的 hidden 维度
  :param attention_unit: 输出 tensor 的 hidden 维度
  :param attention_hops:
  :param drop: dropout 概率
class_docstr_tok: ["\u8fd9\u662f\u4e00\u4e2a\u57fa\u4e8e\u8bba\u6587","`","A","structured","self-attentive","sentence","embedding","<","https",":","\/\/arxiv.org\/pdf\/1703.03130.pdf",">","`","_","\u7684","*","*","Self","Attention","Module","*","*","\u3002",":","param","input_size",":","\u8f93\u5165","tensor","\u7684","hidden","\u7ef4\u5ea6",":","param","attention_unit",":","\u8f93\u51fa","tensor","\u7684","hidden","\u7ef4\u5ea6",":","param","attention_hops",":",":","param","drop",":","dropout","\u6982\u7387"]
docstr: compute the penalization term for attention module
docstr_tok: ["compute","the","penalization","term","for","attention","module"]
code: def _penalization(self, attention):
      r"""
      compute the penalization term for attention module
      """
      baz = attention.size(0)
      size = self.I.size()
      if len(size) != 3 or size[0] != baz:
          self.I = self.I_origin.expand(baz, -1, -1)
          self.I = self.I.to(device=attention.device)
      attention_t = torch.transpose(attention, 1, 2).contiguous()
      mat = (
          torch.bmm(attention, attention_t)
          - self.I[: attention.size(0)]
      )
      ret = (
          torch.sum(torch.sum((mat**2), 2), 1).squeeze() + 1e-10
      ) ** 0.5
      return torch.sum(ret) / size[0]
  
imports: import math
  import torch
  import torch.nn.functional
  from torch import nn
  from .decoder.seq2seq_state import TransformerState
label_desc: Use image node_id 2 for calling the SelfAttention obj's underlying member method code with example usage: obj._penalization(attention) and returns: unknown