def sample(self, src, src_mask, decoding='greedy'):
    init_tok = 2
    eos_tok = 3
    if self.config.keyframes:
        (e_outputs, src_mask) = self.encoder.get_keyframes(src, src_mask)
    else:
        (e_outputs, _, _) = self.encoder(src, src_mask)
    add_state = torch.tensor((decay2[:e_outputs.size(1)] + ([0] * max(0, (e_outputs.size(1) - 50))))).cuda().unsqueeze(0).unsqueeze((- 1))
    memory_bank = (e_outputs * add_state)
    outputs = torch.ones(src.size(0), 1).fill_(init_tok).long().cuda()
    seqLogprobs = torch.zeros(src.size(0), 60).cuda()
    (attn_weights, d_output) = ([], [])
    for i in range(1, 60):
        trg_mask = self.nopeak_mask(i)
        (word, attn, _) = self.decoder(outputs[:, (- 1)].unsqueeze(1), memory_bank, src_mask, trg_mask[:, (- 1), (- 1)].unsqueeze(1), step=(i - 1))
        attn_weights.append(attn[:, :, (- 1)].mean(dim=1))
        d_output.append(word[:, (- 1)])
        out = self.logit(word)
        logprobs = F.log_softmax(out[:, (- 1)], dim=(- 1))
        if (decoding == 'greedy'):
            (_, next_word) = torch.max(logprobs, dim=1)
            next_word = next_word.unsqueeze((- 1))
        else:
            probs = torch.exp(logprobs.data).cpu()
            next_word = torch.multinomial(probs, 1).cuda()
            seqLogprobs[:, i] = logprobs.gather(1, next_word).view((- 1))
        outputs = torch.cat([outputs, next_word], dim=1)
        (memory_bank, add_state) = self.update_memory(memory_bank, add_state, e_outputs, attn_weights[(- 20):], d_output[(- 20):])
    attn_weights = torch.cat([_.unsqueeze(1) for _ in attn_weights], dim=1)
    return (outputs, seqLogprobs, attn_weights)
def sample(self, src, src_mask, decoding='greedy'):
    init_tok = 2
    eos_tok = 3
    if self.config.keyframes:
        (e_outputs, src_mask) = self.encoder.get_keyframes(src, src_mask)
    else:
        (e_outputs, _, _) = self.encoder(src, src_mask)
    add_state = torch.tensor((decay2[:e_outputs.size(1)] + ([0] * max(0, (e_outputs.size(1) - 50))))).cuda().unsqueeze(0).unsqueeze((- 1))
    memory_bank = (e_outputs * add_state)
    outputs = torch.ones(src.size(0), 1).fill_(init_tok).long().cuda()
    seqLogprobs = torch.zeros(src.size(0), 60).cuda()
    (attn_weights, d_output) = ([], [])
    for i in range(1, 60):
        trg_mask = self.nopeak_mask(i)
        (word, attn, _) = self.decoder(outputs[:, (- 1)].unsqueeze(1), memory_bank, src_mask, trg_mask[:, (- 1), (- 1)].unsqueeze(1), step=(i - 1))
        attn_weights.append(attn[:, :, (- 1)].mean(dim=1))
        d_output.append(word[:, (- 1)])
        out = self.logit(word)
        logprobs = F.log_softmax(out[:, (- 1)], dim=(- 1))
        if (decoding == 'greedy'):
            (_, next_word) = torch.max(logprobs, dim=1)
            next_word = next_word.unsqueeze((- 1))
        else:
            probs = torch.exp(logprobs.data).cpu()
            next_word = torch.multinomial(probs, 1).cuda()
            seqLogprobs[:, i] = logprobs.gather(1, next_word).view((- 1))
        outputs = torch.cat([outputs, next_word], dim=1)
        (memory_bank, add_state) = self.update_memory(memory_bank, add_state, e_outputs, attn_weights[(- 20):], d_output[(- 20):])
    attn_weights = torch.cat([_.unsqueeze(1) for _ in attn_weights], dim=1)
    return (outputs, seqLogprobs, attn_weights)