class_docstr: **Bi Attention module**
  
  对于给定的两个向量序列 :math:`a_i` 和 :math:`b_j` , :class:`BiAttention` 模块将通过以下的公式来计算 attention 结果
  
  .. math::
  
      \begin{array}{ll} \\
          e_{ij} = {a}^{\mathrm{T}}_{i}{b}_{j} \\
          {\hat{a}}_{i} = \sum_{j=1}^{\mathcal{l}_{b}}{\frac{\mathrm{exp}(e_{ij})}{\sum_{k=1}^{\mathcal{l}_{b}}{\mathrm{exp}(e_{ik})}}}{b}_{j} \\
          {\hat{b}}_{j} = \sum_{i=1}^{\mathcal{l}_{a}}{\frac{\mathrm{exp}(e_{ij})}{\sum_{k=1}^{\mathcal{l}_{a}}{\mathrm{exp}(e_{ik})}}}{a}_{i} \\
      \end{array}
class_docstr_tok: ["*","*","Bi","Attention","module","*","*","\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u4e24\u4e2a\u5411\u91cf\u5e8f\u5217",":","math",":","`","a_i","`","\u548c",":","math",":","`","b_j","`",",",":","class",":","`","BiAttention","`","\u6a21\u5757\u5c06\u901a\u8fc7\u4ee5\u4e0b\u7684\u516c\u5f0f\u6765\u8ba1\u7b97","attention","\u7ed3\u679c","..","math",":",":","\\begin","{","array","}","{","ll","}","\\\\","e_","{","ij","}","=","{","a","}","^","{","\\mathrm","{","T","}","}","_","{","i","}","{","b","}","_","{","j","}","\\\\","{","\\hat","{","a","}","}","_","{","i","}","=","\\sum_","{","j=1","}","^","{","\\mathcal","{","l","}","_","{","b","}","}","{","\\frac","{","\\mathrm","{","exp","}","(","e_","{","ij","}",")","}","{","\\sum_","{","k=1","}","^","{","\\mathcal","{","l","}","_","{","b","}","}","{","\\mathrm","{","exp","}","(","e_","{","ik","}",")","}","}","}","{","b","}","_","{","j","}","\\\\","{","\\hat","{","b","}","}","_","{","j","}","=","\\sum_","{","i=1","}","^","{","\\mathcal","{","l","}","_","{","a","}","}","{","\\frac","{","\\mathrm","{","exp","}","(","e_","{","ij","}",")","}","{","\\sum_","{","k=1","}","^","{","\\mathcal","{","l","}","_","{","a","}","}","{","\\mathrm","{","exp","}","(","e_","{","ik","}",")","}","}","}","{","a","}","_","{","i","}","\\\\","\\end","{","array","}"]
docstr: :param premise_batch: ``[batch_size, a_seq_len, hidden_size]``
  :param premise_mask: ``[batch_size, a_seq_len]``
  :param hypothesis_batch: ``[batch_size, b_seq_len, hidden_size]``
  :param hypothesis_mask: ``[batch_size, b_seq_len]``
  :return: 一个包含两个张量的元组，分别为：
  
          - ``attended_premises`` : ``[batch_size, a_seq_len, hidden_size]``
          - ``attended_hypotheses`` : ``[batch_size, b_seq_len, hidden_size]``
docstr_tok: [":","param","premise_batch",":","``","[","batch_size",",","a_seq_len",",","hidden_size","]","``",":","param","premise_mask",":","``","[","batch_size",",","a_seq_len","]","``",":","param","hypothesis_batch",":","``","[","batch_size",",","b_seq_len",",","hidden_size","]","``",":","param","hypothesis_mask",":","``","[","batch_size",",","b_seq_len","]","``",":","return",":","\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a\u5f20\u91cf\u7684\u5143\u7ec4\uff0c\u5206\u522b\u4e3a\uff1a","-","``","attended_premises","``",":","``","[","batch_size",",","a_seq_len",",","hidden_size","]","``","-","``","attended_hypotheses","``",":","``","[","batch_size",",","b_seq_len",",","hidden_size","]","``"]
code: def forward(
      self,
      premise_batch,
      premise_mask,
      hypothesis_batch,
      hypothesis_mask,
  ):
      r"""
      :param premise_batch: ``[batch_size, a_seq_len, hidden_size]``
      :param premise_mask: ``[batch_size, a_seq_len]``
      :param hypothesis_batch: ``[batch_size, b_seq_len, hidden_size]``
      :param hypothesis_mask: ``[batch_size, b_seq_len]``
      :return: 一个包含两个张量的元组，分别为：
  
              - ``attended_premises`` : ``[batch_size, a_seq_len, hidden_size]``
              - ``attended_hypotheses`` : ``[batch_size, b_seq_len, hidden_size]``
      """
      similarity_matrix = premise_batch.bmm(
          hypothesis_batch.transpose(2, 1).contiguous()
      )
  
      prem_hyp_attn = _masked_softmax(
          similarity_matrix, hypothesis_mask
      )
      hyp_prem_attn = _masked_softmax(
          similarity_matrix.transpose(1, 2).contiguous(), premise_mask
      )
  
      attended_premises = _weighted_sum(
          hypothesis_batch, prem_hyp_attn, premise_mask
      )
      attended_hypotheses = _weighted_sum(
          premise_batch, hyp_prem_attn, hypothesis_mask
      )
  
      return attended_premises, attended_hypotheses
  
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 1 for calling the BiAttention obj's underlying member method code with example usage: obj.forward(premise_batch, premise_mask, hypothesis_batch, hypothesis_mask) and returns: attended_premises,  attended_hypotheses