    def _copy_state(
        state: ConstraintStateType,
        batch_size: int,
        beam_size: int,
        last_backpointer: Optional[torch.Tensor] = None,
    ) -> ConstraintStateType:
        """
        Copies the `state` . This method copies the data in `state` using `copy.deepcopy()`. If this
        is not appropriate for your constraint, you will need to implement the copying yourself.
        """
        new_state = []
        for i in range(batch_size):
            batch_state = []
            for j in range(beam_size):
                if last_backpointer is None:
                    # This is the first prediction, so the backpointer is 0
                    backpointer = 0
                else:
                    backpointer = last_backpointer[i, j].item()
                batch_state.append(copy.deepcopy(state[i][backpointer]))
            new_state.append(batch_state)
        return new_state
Copies the `state` . This method copies the data in `state` using `copy.deepcopy()`. If this
is not appropriate for your constraint, you will need to implement the copying yourself.
allennlp/nn/beam_search.py