def update_memory(self, memory_bank, add_state, e_outputs, attn, query_s):
    remove_prob = torch.sigmoid(self.remove_gate(query_s[(- 1)])).unsqueeze((- 1))
    add_prob = torch.sigmoid(self.add_gate(query_s[(- 1)])).unsqueeze((- 1))
    temp = torch.softmax(torch.tensor(decay1[(20 - len(attn)):]).cuda(), dim=(- 1))
    attn = sum([(attn[i] * temp[i]) for i in range(len(attn))]).unsqueeze((- 1))
    query_s = sum([(query_s[i] * temp[i]) for i in range(len(query_s))])
    sim = torch.sigmoid(torch.matmul(memory_bank, self.q_linear(query_s).unsqueeze((- 1))))
    memory_bank = (memory_bank * (1 - ((remove_prob * attn) * sim)))
    last_ctx = (e_outputs * attn).sum(dim=1, keepdim=True)
    next_attn = torch.sigmoid(self.next_attn(torch.cat([e_outputs, last_ctx.expand_as(e_outputs)], dim=(- 1))))
    memory_bank = (memory_bank + ((e_outputs * (1 - add_state)) * (add_prob * next_attn)))
    add_state = (add_state + ((1 - add_state) * (add_prob * next_attn)))
    return (memory_bank, add_state)
def update_memory(self, memory_bank, add_state, e_outputs, attn, query_s):
    remove_prob = torch.sigmoid(self.remove_gate(query_s[(- 1)])).unsqueeze((- 1))
    add_prob = torch.sigmoid(self.add_gate(query_s[(- 1)])).unsqueeze((- 1))
    temp = torch.softmax(torch.tensor(decay1[(20 - len(attn)):]).cuda(), dim=(- 1))
    attn = sum([(attn[i] * temp[i]) for i in range(len(attn))]).unsqueeze((- 1))
    query_s = sum([(query_s[i] * temp[i]) for i in range(len(query_s))])
    sim = torch.sigmoid(torch.matmul(memory_bank, self.q_linear(query_s).unsqueeze((- 1))))
    memory_bank = (memory_bank * (1 - ((remove_prob * attn) * sim)))
    last_ctx = (e_outputs * attn).sum(dim=1, keepdim=True)
    next_attn = torch.sigmoid(self.next_attn(torch.cat([e_outputs, last_ctx.expand_as(e_outputs)], dim=(- 1))))
    memory_bank = (memory_bank + ((e_outputs * (1 - add_state)) * (add_prob * next_attn)))
    add_state = (add_state + ((1 - add_state) * (add_prob * next_attn)))
    return (memory_bank, add_state)