parameters: (self, army_feat, hist_inst, hist_inst_len, hist_inst_diff)
return_statement: return inst_feat, sum_inst
docstring: army_feat: [batch, num_unit, feat_dim]
          hist_inst: [batch, num_hist, sentence_len]
docstring_summary: army_feat: [batch, num_unit, feat_dim]
          hist_inst: [batch, num_hist, sentence_len]
docstring_tokens: army_feat : [ batch num_unit feat_dim ] hist_inst : [ batch num_hist sentence_len ]
function: def forward(self, army_feat, hist_inst, hist_inst_len, hist_inst_diff):
          """
          army_feat: [batch, num_unit, feat_dim]
          hist_inst: [batch, num_hist, sentence_len]
          """
          batch, num_hist = hist_inst.size()[:2]
          hist_inst = hist_inst.view(batch * num_hist, -1)
          hist_inst_len = hist_inst_len.view(batch * num_hist)
          hist_feat = self.encoder(hist_inst, hist_inst_len)
          hist_feat = hist_feat.view(batch, num_hist, -1)
          # hist_feat: [batch, num_hist, inst_dim]
          pos_emb = self.emb.weight.unsqueeze(0).repeat(batch, 1, 1)
          hist_inst_diff = hist_inst_diff.clamp(max=self.max_hist_diff)
          diff_emb = self.diff_emb(hist_inst_diff)
          # print(diff_emb.size(), pos_emb.size(), hist_feat.size())
  
          hist_feat = torch.cat([hist_feat, pos_emb, diff_emb], 2)
          # print('hist feat', hist_feat.size())
          sum_inst = hist_feat[:, -1]
          # print('sum_inst:', sum_inst.size())
  
          num_army = army_feat.size(1)
          hist_feat = hist_feat.unsqueeze(1).repeat(1, num_army, 1, 1)
  
          proj_army = self.proj(army_feat)
          proj_army = proj_army.unsqueeze(2).repeat(1, 1, num_hist, 1)
  
          # print(hist_feat.size())
          dot_prod = (proj_army * hist_feat).sum(3)
          # dot_prod: [batch, num_army, num_hist]
          att_score = nn.functional.softmax(dot_prod, 2)
          # att_score: [batch, num_army, num_hist]
          # hist_feat: [batch, num_army, num_hist, hist_dim]
          inst_feat = (att_score.unsqueeze(3) * hist_feat).sum(2)
          # inst_feat: [batch, num_army, hist_dim]
          return inst_feat, sum_inst
function_tokens: def forward ( self , army_feat , hist_inst , hist_inst_len , hist_inst_diff ) : batch , num_hist = hist_inst . size ( ) [ : 2 ] hist_inst = hist_inst . view ( batch * num_hist , - 1 ) hist_inst_len = hist_inst_len . view ( batch * num_hist ) hist_feat = self . encoder ( hist_inst , hist_inst_len ) hist_feat = hist_feat . view ( batch , num_hist , - 1 ) # hist_feat: [batch, num_hist, inst_dim] pos_emb = self . emb . weight . unsqueeze ( 0 ) . repeat ( batch , 1 , 1 ) hist_inst_diff = hist_inst_diff . clamp ( max = self . max_hist_diff ) diff_emb = self . diff_emb ( hist_inst_diff ) # print(diff_emb.size(), pos_emb.size(), hist_feat.size()) hist_feat = torch . cat ( [ hist_feat , pos_emb , diff_emb ] , 2 ) # print('hist feat', hist_feat.size()) sum_inst = hist_feat [ : , - 1 ] # print('sum_inst:', sum_inst.size()) num_army = army_feat . size ( 1 ) hist_feat = hist_feat . unsqueeze ( 1 ) . repeat ( 1 , num_army , 1 , 1 ) proj_army = self . proj ( army_feat ) proj_army = proj_army . unsqueeze ( 2 ) . repeat ( 1 , 1 , num_hist , 1 ) # print(hist_feat.size()) dot_prod = ( proj_army * hist_feat ) . sum ( 3 ) # dot_prod: [batch, num_army, num_hist] att_score = nn . functional . softmax ( dot_prod , 2 ) # att_score: [batch, num_army, num_hist] # hist_feat: [batch, num_army, num_hist, hist_dim] inst_feat = ( att_score . unsqueeze ( 3 ) * hist_feat ) . sum ( 2 ) # inst_feat: [batch, num_army, hist_dim] return inst_feat , sum_inst