def _get_prediction_length(predictions_dict):
    """Returns the length of the prediction based on the index
  of the first SEQUENCE_END token.
  """
    tokens_iter = enumerate(predictions_dict["predicted_tokens"])
    return next(((i + 1) for i, _ in tokens_iter if _ == "SEQUENCE_END"),
                len(predictions_dict["predicted_tokens"]))