def METHOD_NAME(self, states):
    if len(states.units.source) == 0:
        return
    src_indices = [
        self.dict['src'].index(x)
        for x in states.units.source.value
    ]
    if states.finish_read():
        # Append the eos index when the prediction is over
        src_indices += [self.dict["tgt"].eos_index]
    src_indices = self.to_device(
        torch.LongTensor(src_indices).unsqueeze(0)
    )
    src_lengths = self.to_device(
        torch.LongTensor([src_indices.size(1)])
    )
    states.encoder_states = self.model.encoder(src_indices, src_lengths)
    torch.cuda.empty_cache()