code: def validate_modify_label(
      labels: Optional[TTextLabel],
      task_type: TaskType,
      expected_size: int,
      tokenized_text: Optional[Sequence[Sequence[str]]],
  ) -> Optional[TTextLabel]:
      """Validate and process label to accepted formats."""
      if label_is_null(labels):
          return None
  
      if not is_sequence_not_str(labels):
          raise DeepchecksValueError("label must be a Sequence")
      if not len(labels) == expected_size:
          raise DeepchecksValueError(
              f"Label length ({len(labels)}) does not match expected length ({expected_size})"
          )
  
      if task_type == TaskType.TEXT_CLASSIFICATION:
          if all(
              is_sequence_not_str(x) or is_label_none(x) for x in labels
          ):  # Multilabel
              multilabel_error = "multilabel was identified. It must be a Sequence of Sequences of 0 or 1."
              if not all(
                  all(y in (0, 1) for y in x)
                  for x in labels
                  if not is_label_none(x)
              ):
                  raise DeepchecksValueError(multilabel_error)
              if any(
                  len(labels[0]) != len(labels[i])
                  for i in range(len(labels))
                  if not is_label_none(labels[i])
              ):
                  raise DeepchecksValueError(
                      "All multilabel entries must be of the same length, which is the number"
                      " of possible classes."
                  )
              labels = [
                  [None] * len(labels[0])
                  if is_label_none(label_per_sample)
                  else [int(x) for x in label_per_sample]
                  for label_per_sample in labels
              ]
          elif any(
              not isinstance(x, (str, np.integer, int))
              and not pd.isna(x)
              for x in labels
          ):
              raise DeepchecksValueError(
                  "label must be a Sequence of strings or ints (multiclass classification) "
                  "or a Sequence of Sequences of strings or ints (multilabel classification)"
              )
          else:
              labels = [None if pd.isna(x) else str(x) for x in labels]
      elif task_type == TaskType.TOKEN_CLASSIFICATION:
          token_class_error = "label must be a Sequence of Sequences of either strings or integers."
          if not is_sequence_not_str(labels):
              raise DeepchecksValueError(token_class_error)
  
          result = []
          for idx, (tokens, label) in enumerate(
              zip(tokenized_text, labels)
          ):  # TODO: Runs on all labels, very costly
              if is_label_none(label):
                  result.append([None] * len(tokens))
              else:
                  if not is_sequence_not_str(label):
                      raise DeepchecksValueError(
                          token_class_error
                          + f" label at {idx} was of type {type(label)}"
                      )
                  if len(tokens) != len(label):
                      raise DeepchecksValueError(
                          f"label must be the same length as tokenized_text. "
                          f"However, for sample index {idx} received token list of length "
                          f"{len(tokens)} and label list of length {len(label)}"
                      )
                  result.append([str(x) for x in label])
          labels = result
  
      return np.asarray(labels, dtype=object)
  
imports: import collections
  from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Optional, Sequence, Set, Tuple, Type, cast
  import numpy
  import pandas
  from deepchecks.core.errors import DeepchecksValueError, ValidationError
  from deepchecks.nlp.task_type import TaskType, TTextLabel
  from deepchecks.utils.logger import get_logger
  from deepchecks.utils.metrics import is_label_none
  from deepchecks.utils.type_inference import infer_categorical_features, infer_numerical_features
  from deepchecks.utils.validation import is_sequence_not_str
label_desc: Use image node_id 4 for calling a global function with example usage: validate_modify_label(labels, task_type, expected_size, tokenized_text) and returns: np, None