docstr: Validates the spans with respect to the tokens.
  
  If necessary, also performs an automatic correction of the spans.
  
  Args:
      span_utils: Helper class to perform the checks.
      annotation: Contains the spans to validate.
  
  Raises:
      ValidationError: If spans are not valid or misaligned.
docstr_tok: ["Validates","the","spans","with","respect","to","the","tokens",".","If","necessary",",","also","performs","an","automatic","correction","of","the","spans",".","Args",":","span_utils",":","Helper","class","to","perform","the","checks",".","annotation",":","Contains","the","spans","to","validate",".","Raises",":","ValidationError",":","If","spans","are","not","valid","or","misaligned","."]
code: def _validate_spans(
      self, annotation: ServiceTokenClassificationAnnotation
  ):
      """Validates the spans with respect to the tokens.
  
      If necessary, also performs an automatic correction of the spans.
  
      Args:
          span_utils: Helper class to perform the checks.
          annotation: Contains the spans to validate.
  
      Raises:
          ValidationError: If spans are not valid or misaligned.
      """
      spans = [
          (ent.label, ent.start, ent.end) for ent in annotation.entities
      ]
      try:
          self._span_utils.validate(spans)
      except ValueError:
          corrected_spans = self._span_utils.correct(spans)
          self._span_utils.validate(corrected_spans)
          for ent, span in zip(annotation.entities, corrected_spans):
              ent.start, ent.end = span[1], span[2]
  
imports: from typing import Dict, List, Optional, Set, Tuple
  from argilla.server.commons.models import PredictionStatus, TaskType
  from argilla.server.constants import DEFAULT_MAX_KEYWORD_LENGTH
  from argilla.server.pydantic_v1 import BaseModel, Field, validator
  from argilla.server.services.search.model import ServiceBaseRecordsQuery, ServiceScoreRange
  from argilla.server.services.tasks.commons import ServiceBaseAnnotation, ServiceBaseRecord
  from argilla.utils import SpanUtils
label_desc: Use image node_id 2 for calling the ServiceTokenClassificationRecord obj's underlying member method code with example usage: obj._validate_spans(annotation) without return types