parameters: (self, x, y, context)
return_statement: return logps
docstring: compute logp given input
  
          args:
              x: [num_inst, max_len]
              context: [batch, context_dim]
docstring_summary: compute logp given input
docstring_tokens: compute logp given input
function: def compute_prob2(self, x, y, context):
          """compute logp given input
  
          args:
              x: [num_inst, max_len]
              context: [batch, context_dim]
          """
          emb = self.word_emb(x)
          # emb: [num_inst, emb_dim]
          # logit = []
          # logp = []
          logps = []
          for i in range(context.size(0)):
              context_  = context[i].unsqueeze(0).unsqueeze(1).repeat(
                  emb.size(0), emb.size(1), 1)
              # print(emb.size())
              # print(context_.size())
              input_ = torch.cat([emb, context_], 2)
              output, _ = self.rnn(input_)
              # logit.append(self.decoder(output))
              logit = self.decoder(output)
              # logit: [num_inst, max_len, vocab_size]
              logp = nn.functional.log_softmax(logit, 2)#.sum(2)
              # print(logp.size())
              # print(y[i].size())
              logp = logp.gather(2, y.unsqueeze(2)).squeeze(2)
              logp = logp.sum(1)
              logps.append(logp)
  
          # logit = torch.stack(logit, 0)
          # print('>>>', logit.size())
          # logp = nn.functional.log_softmax(logit, 3)
          logps = torch.stack(logps, 0)
          print(logps.size())
          logps = nn.functional.softmax(logps, 1)
          return logps
function_tokens: def compute_prob2 ( self , x , y , context ) : emb = self . word_emb ( x ) # emb: [num_inst, emb_dim] # logit = [] # logp = [] logps = [ ] for i in range ( context . size ( 0 ) ) : context_ = context [ i ] . unsqueeze ( 0 ) . unsqueeze ( 1 ) . repeat ( emb . size ( 0 ) , emb . size ( 1 ) , 1 ) # print(emb.size()) # print(context_.size()) input_ = torch . cat ( [ emb , context_ ] , 2 ) output , _ = self . rnn ( input_ ) # logit.append(self.decoder(output)) logit = self . decoder ( output ) # logit: [num_inst, max_len, vocab_size] logp = nn . functional . log_softmax ( logit , 2 ) #.sum(2) # print(logp.size()) # print(y[i].size()) logp = logp . gather ( 2 , y . unsqueeze ( 2 ) ) . squeeze ( 2 ) logp = logp . sum ( 1 ) logps . append ( logp ) # logit = torch.stack(logit, 0) # print('>>>', logit.size()) # logp = nn.functional.log_softmax(logit, 3) logps = torch . stack ( logps , 0 ) print ( logps . size ( ) ) logps = nn . functional . softmax ( logps , 1 ) return logps