code: def pad_sentences(
      sequences: np.ndarray,
      max_length: int = None,
      padding_value: int = 0,
      padding_style="post",
  ) -> np.ndarray:
      """
      Pad input sequences up to max_length
      values are aligned to the right
  
      Args:
          sequences (iter): a 2D matrix (np.array) to pad
          max_length (int, optional): max length of resulting sequences
          padding_value (int, optional): padding value
          padding_style (str, optional): add padding values as prefix (use with 'pre')
              or postfix (use with 'post')
  
      Returns:
          input sequences padded to size 'max_length'
      """
      if isinstance(sequences, list) and len(sequences) > 0:
          try:
              sequences = np.asarray(sequences)
          except ValueError:
              print("cannot convert sequences into numpy array")
      assert hasattr(sequences, "shape")
      if len(sequences) < 1:
          return sequences
      if max_length is None:
          max_length = np.max([len(s) for s in sequences])
      elif max_length < 1:
          raise ValueError("max sequence length must be > 0")
      if max_length < 1:
          return sequences
      padded_sequences = (
          np.ones((len(sequences), max_length), dtype=np.int32)
          * padding_value
      )
      for i, sent in enumerate(sequences):
          if padding_style == "post":
              trunc = sent[-max_length:]
              padded_sequences[i, : len(trunc)] = trunc
          elif padding_style == "pre":
              trunc = sent[:max_length]
              padded_sequences[i, -trunc:] = trunc
      return padded_sequences.astype(dtype=np.int32)
  
file_path: nlp-architect/nlp_architect/utils/generic.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import re
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: pad_sentences(sequences, max_length, padding_value, padding_style) and returns: padded_sequences, sequences, sequences