class_docstr: seq2seq recurrent neural network, implemented using TFLearn.
class_docstr_tok: ["seq2seq","recurrent","neural","network",",","implemented","using","TFLearn","."]
docstr: Build tensor specifying graph of operations for the seq2seq neural network model.
  
  mode = string, either "train" or "predict"
  cell_type = attribute of rnn_cell specifying which RNN cell type to use
  cell_size = size for the hidden layer in the RNN cell
  num_layers = number of RNN cell layers to use
  
  Return TFLearn model instance.  Use DNN model for this.
docstr_tok: ["Build","tensor","specifying","graph","of","operations","for","the","seq2seq","neural","network","model",".","mode","=","string",",","either","``","train","''","or","``","predict","''","cell_type","=","attribute","of","rnn_cell","specifying","which","RNN","cell","type","to","use","cell_size","=","size","for","the","hidden","layer","in","the","RNN","cell","num_layers","=","number","of","RNN","cell","layers","to","use","Return","TFLearn","model","instance",".","Use","DNN","model","for","this","."]
code: def model(
      self,
      mode="train",
      num_layers=1,
      cell_size=32,
      cell_type="BasicLSTMCell",
      embedding_size=20,
      learning_rate=0.0001,
      tensorboard_verbose=0,
      checkpoint_path=None,
  ):
      """
      Build tensor specifying graph of operations for the seq2seq neural network model.
  
      mode = string, either "train" or "predict"
      cell_type = attribute of rnn_cell specifying which RNN cell type to use
      cell_size = size for the hidden layer in the RNN cell
      num_layers = number of RNN cell layers to use
  
      Return TFLearn model instance.  Use DNN model for this.
      """
      assert mode in ["train", "predict"]
  
      checkpoint_path = checkpoint_path or (
          "%s%ss2s_checkpoint.tfl"
          % (self.data_dir or "", "/" if self.data_dir else "")
      )
      GO_VALUE = (
          self.out_max_int + 1
      )  # unique integer value used to trigger decoder outputs in the seq2seq RNN
  
      network = tflearn.input_data(
          shape=[None, self.in_seq_len + self.out_seq_len],
          dtype=tf.int32,
          name="XY",
      )
      encoder_inputs = tf.slice(
          network, [0, 0], [-1, self.in_seq_len], name="enc_in"
      )  # get encoder inputs
      encoder_inputs = tf.unstack(
          encoder_inputs, axis=1
      )  # transform into list of self.in_seq_len elements, each [-1]
  
      decoder_inputs = tf.slice(
          network,
          [0, self.in_seq_len],
          [-1, self.out_seq_len],
          name="dec_in",
      )  # get decoder inputs
      decoder_inputs = tf.unstack(
          decoder_inputs, axis=1
      )  # transform into list of self.out_seq_len elements, each [-1]
  
      go_input = tf.multiply(
          tf.ones_like(decoder_inputs[0], dtype=tf.int32), GO_VALUE
      )  # insert "GO" symbol as the first decoder input; drop the last decoder input
      decoder_inputs = [go_input] + decoder_inputs[
          : self.out_seq_len - 1
      ]  # insert GO as first; drop last decoder input
  
      feed_previous = not (mode == "train")
  
      if self.verbose > 3:
          print("feed_previous = %s" % str(feed_previous))
          print("encoder inputs: %s" % str(encoder_inputs))
          print("decoder inputs: %s" % str(decoder_inputs))
          print("len decoder inputs: %s" % len(decoder_inputs))
  
      self.n_input_symbols = (
          self.in_max_int + 1
      )  # default is integers from 0 to 9
      self.n_output_symbols = (
          self.out_max_int + 2
      )  # extra "GO" symbol for decoder inputs
  
      single_cell = getattr(rnn_cell, cell_type)(
          cell_size, state_is_tuple=True
      )
      if num_layers == 1:
          cell = single_cell
      else:
          cell = rnn_cell.MultiRNNCell([single_cell] * num_layers)
  
      if self.seq2seq_model == "embedding_rnn":
          model_outputs, states = seq2seq.embedding_rnn_seq2seq(
              encoder_inputs,  # encoder_inputs: A list of 2D Tensors [batch_size, input_size].
              decoder_inputs,
              cell,
              num_encoder_symbols=self.n_input_symbols,
              num_decoder_symbols=self.n_output_symbols,
              embedding_size=embedding_size,
              feed_previous=feed_previous,
          )
      elif self.seq2seq_model == "embedding_attention":
          model_outputs, states = seq2seq.embedding_attention_seq2seq(
              encoder_inputs,  # encoder_inputs: A list of 2D Tensors [batch_size, input_size].
              decoder_inputs,
              cell,
              num_encoder_symbols=self.n_input_symbols,
              num_decoder_symbols=self.n_output_symbols,
              embedding_size=embedding_size,
              num_heads=1,
              initial_state_attention=False,
              feed_previous=feed_previous,
          )
      else:
          raise Exception(
              "[TFLearnSeq2Seq] Unknown seq2seq model %s"
              % self.seq2seq_model
          )
  
      tf.add_to_collection(
          tf.GraphKeys.LAYER_VARIABLES + "/" + "seq2seq_model",
          model_outputs,
      )  # for TFLearn to know what to save and restore
  
      # model_outputs: list of the same length as decoder_inputs of 2D Tensors with shape [batch_size x output_size] containing the generated outputs.
      if self.verbose > 2:
          print("model outputs: %s" % model_outputs)
      network = tf.stack(
          model_outputs, axis=1
      )  # shape [-1, n_decoder_inputs (= self.out_seq_len), num_decoder_symbols]
      if self.verbose > 2:
          print("packed model outputs: %s" % network)
  
      if self.verbose > 3:
          all_vars = tf.get_collection(tf.GraphKeys.VARIABLES)
          print("all_vars = %s" % all_vars)
  
      with tf.name_scope(
          "TargetsData"
      ):  # placeholder for target variable (i.e. trainY input)
          targetY = tf.placeholder(
              shape=[None, self.out_seq_len], dtype=tf.int32, name="Y"
          )
  
      network = tflearn.regression(
          network,
          placeholder=targetY,
          optimizer="adam",
          learning_rate=learning_rate,
          loss=self.sequence_loss,
          metric=self.accuracy,
          name="Y",
      )
  
      model = tflearn.DNN(
          network,
          tensorboard_verbose=tensorboard_verbose,
          checkpoint_path=checkpoint_path,
      )
      return model
  
imports: from __future__ import division, print_function
  import os
  import sys
  import tflearn
  import argparse
  import json
  import numpy
  import tensorflow.compat.v1
  from tensorflow.contrib.legacy_seq2seq.python.ops import seq2seq
  from tensorflow.python.ops import rnn_cell
label_desc: Use image node_id 5 for calling the TFLearnSeq2Seq obj's underlying member method code with example usage: obj.model(mode, num_layers, cell_size, cell_type, embedding_size, learning_rate, tensorboard_verbose, checkpoint_path) and returns: model