def METHOD_NAME(self, context_w, memories_w, context_segments=None):
    """
    Encode the context and memories.
    """
    # [batch, d]
    if context_w is None:
        # it's possible that only candidates were passed into the
        # forward function, return None here for LHS representation
        return None, None
    context_h = self.context_encoder(context_w, segments=context_segments)
    if memories_w is None:
        return [], context_h
    bsz = memories_w.size(0)
    memories_w = memories_w.view(-1, memories_w.size(-1))
    memories_h = self.memory_transformer(memories_w)
    memories_h = memories_h.view(bsz, -1, memories_h.size(-1))
    context_h = context_h.unsqueeze(1)
    context_h, weights = self.attender(context_h, memories_h)
    return weights, context_h