class_docstr: Generic processors for the sequence samples.
class_docstr_tok: ["Generic","processors","for","the","sequence","samples","."]
code: def transform(
      self,
      samples: TextSamplesVar,
      *,
      seq_length: int = None,
      max_position: int = None,
      segment: bool = False,
  ) -> np.ndarray:
      seq_length_from = ""
  
      # An ugly patch for tf-serving use case.
      if (
          seq_length is None
          and self._sequence_length_from_saved_model is not None
      ):
          seq_length = self._sequence_length_from_saved_model
  
      if seq_length is None:
          seq_length_from = "max length of the samples"
          seq_length = max([len(i) for i in samples]) + 2
      if max_position is not None and max_position < seq_length:
          seq_length_from = "max embedding seq length"
          seq_length = max_position
  
      if seq_length_from and not self._showed_seq_len_warning:
          logger.warning(
              f"Sequence length is None, will use the {seq_length_from}, which is {seq_length}"
          )
          self._showed_seq_len_warning = True
  
      numerized_samples = []
      for seq in samples:
          if self.token_bos in self.vocab2idx:
              seq = [self.token_bos] + seq + [self.token_eos]
          else:
              seq = [self.token_pad] + seq + [self.token_pad]
          if self.token_unk in self.vocab2idx:
              unk_index = self.vocab2idx[self.token_unk]
              numerized_samples.append(
                  [
                      self.vocab2idx.get(token, unk_index)
                      for token in seq
                  ]
              )
          else:
              numerized_samples.append(
                  [self.vocab2idx[token] for token in seq]
              )
  
      sample_index = pad_sequences(
          numerized_samples,
          seq_length,
          padding="post",
          truncating="post",
      )
      token_ids = np.array(sample_index)
  
      if segment:
          segment_ids = np.zeros(token_ids.shape, dtype=np.int32)
          return token_ids, segment_ids
      else:
          return token_ids
  
file_path: Kashgari/kashgari/processors/sequence_processor.py
imports: import collections
  import operator
  from typing import Dict, List, Any, Optional, Union
  import numpy
  import tqdm
  from tensorflow.keras.preprocessing.sequence import pad_sequences
  from kashgari.generators import CorpusGenerator
  from kashgari.logger import logger
  from kashgari.processors.abc_processor import ABCProcessor
  from kashgari.types import TextSamplesVar
label_desc: Use image node_id 4 for calling the SequenceProcessor obj's underlying member method code with example usage: obj.transform(samples) and returns: token_ids,  segment_ids, token_ids