code: def string_to_semi_redundant_sequences(
      string, seq_maxlen=25, redun_step=3, char_idx=None
  ):
      """string_to_semi_redundant_sequences.
  
      Vectorize a string and returns parsed sequences and targets, along with
      the associated dictionary.
  
      Arguments:
          string: `str`. Lower-case text from input text file.
          seq_maxlen: `int`. Maximum length of a sequence. Default: 25.
          redun_step: `int`. Redundancy step. Default: 3.
          char_idx: 'dict'. A dictionary to convert chars to positions. Will be automatically generated if None
  
      Returns:
          A tuple: (inputs, targets, dictionary)
      """
  
      print("Vectorizing text...")
  
      if char_idx is None:
          char_idx = chars_to_dictionary(string)
  
      len_chars = len(char_idx)
  
      sequences = []
      next_chars = []
      for i in range(0, len(string) - seq_maxlen, redun_step):
          sequences.append(string[i : i + seq_maxlen])
          next_chars.append(string[i + seq_maxlen])
  
      X = np.zeros(
          (len(sequences), seq_maxlen, len_chars), dtype=np.bool
      )
      Y = np.zeros((len(sequences), len_chars), dtype=np.bool)
      for i, seq in enumerate(sequences):
          for t, char in enumerate(seq):
              X[i, t, char_idx[char]] = 1
          Y[i, char_idx[next_chars[i]]] = 1
  
      print("Text total length: {:,}".format(len(string)))
      print("Distinct chars   : {:,}".format(len_chars))
      print("Total sequences  : {:,}".format(len(sequences)))
  
      return X, Y, char_idx
  
imports: from __future__ import division, print_function, absolute_import
  import os
  import random
  import numpy
  from PIL import Image
  import pickle
  import csv
  import warnings
  import tensorflow.compat.v1
  from io import BytesIO
label_desc: Use image node_id 3 for calling a global function with example usage: string_to_semi_redundant_sequences(string, seq_maxlen, redun_step, char_idx) and returns: X,  Y,  char_idx