code: def textgenrnn_sample(preds, temperature, interactive=False, top_n=3):
      """
      Samples predicted probabilities of the next character to allow
      for the network to show "creativity."
      """
  
      preds = np.asarray(preds).astype("float64")
  
      if temperature is None or temperature == 0.0:
          return np.argmax(preds)
  
      preds = np.log(preds + K.epsilon()) / temperature
      exp_preds = np.exp(preds)
      preds = exp_preds / np.sum(exp_preds)
      probas = np.random.multinomial(1, preds, 1)
  
      if not interactive:
          index = np.argmax(probas)
  
          # prevent function from being able to choose 0 (placeholder)
          # choose 2nd best index from preds
          if index == 0:
              index = np.argsort(preds)[-2]
      else:
          # return list of top N chars/words
          # descending order, based on probability
          index = (-preds).argsort()[:top_n]
  
      return index
  
imports: import csv
  import re
  from random import shuffle
  import numpy
  from tensorflow.keras import backend
  from tensorflow.keras.callbacks import Callback
  from tensorflow.keras.models import Model
  from tensorflow.keras.preprocessing import sequence
  from tqdm import trange
label_desc: Use image node_id 1 for calling a global function with example usage: textgenrnn_sample(preds, temperature, interactive, top_n) and returns: index, np