code: def encode_sequences(
      sequences: List[str],
      vocab: str,
      target_size: Optional[int] = None,
      eos: int = -1,
      sos: Optional[int] = None,
      pad: Optional[int] = None,
      dynamic_seq_length: bool = False,
  ) -> np.ndarray:
      """Encode character sequences using a given vocab as mapping
  
      Args:
      ----
          sequences: the list of character sequences of size N
          vocab: the ordered vocab to use for encoding
          target_size: maximum length of the encoded data
          eos: encoding of End Of String
          sos: optional encoding of Start Of String
          pad: optional encoding for padding. In case of padding, all sequences are followed by 1 EOS then PAD
          dynamic_seq_length: if `target_size` is specified, uses it as upper bound and enables dynamic sequence size
  
      Returns:
      -------
          the padded encoded data as a tensor
      """
      if 0 <= eos < len(vocab):
          raise ValueError(
              "argument 'eos' needs to be outside of vocab possible indices"
          )
  
      if not isinstance(target_size, int) or dynamic_seq_length:
          # Maximum string length + EOS
          max_length = max(len(w) for w in sequences) + 1
          if isinstance(sos, int):
              max_length += 1
          if isinstance(pad, int):
              max_length += 1
          target_size = (
              max_length
              if not isinstance(target_size, int)
              else min(max_length, target_size)
          )
  
      # Pad all sequences
      if isinstance(pad, int):  # pad with padding symbol
          if 0 <= pad < len(vocab):
              raise ValueError(
                  "argument 'pad' needs to be outside of vocab possible indices"
              )
          # In that case, add EOS at the end of the word before padding
          default_symbol = pad
      else:  # pad with eos symbol
          default_symbol = eos
      encoded_data: np.ndarray = np.full(
          [len(sequences), target_size], default_symbol, dtype=np.int32
      )
  
      # Encode the strings
      for idx, seq in enumerate(
          map(partial(encode_string, vocab=vocab), sequences)
      ):
          if isinstance(pad, int):  # add eos at the end of the sequence
              seq.append(eos)
          encoded_data[idx, : min(len(seq), target_size)] = seq[
              : min(len(seq), target_size)
          ]
  
      if isinstance(
          sos, int
      ):  # place sos symbol at the beginning of each sequence
          if 0 <= sos < len(vocab):
              raise ValueError(
                  "argument 'sos' needs to be outside of vocab possible indices"
              )
          encoded_data = np.roll(encoded_data, 1)
          encoded_data[:, 0] = sos
  
      return encoded_data
  
file_path: doctr/doctr/datasets/utils.py
imports: import string
  import unicodedata
  from collections.abc import Sequence
  from functools import partial
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Tuple, TypeVar, Union
  from typing import Sequence
  import numpy
  from PIL import Image
  from doctr.io.image import get_img_shape
  from doctr.utils.geometry import convert_to_relative_coords, extract_crops, extract_rcrops
  from .vocabs import VOCABS
label_desc: Use image node_id 4 for calling a global function with example usage: encode_sequences(sequences, vocab, target_size, eos, sos, pad, dynamic_seq_length) and returns: encoded_data