class_docstr: Sequence-to-sequence base class.
class_docstr_tok: ["Sequence-to-sequence","base","class","."]
docstr: Subclass must implement this method.
  
  Creates a sequence-to-sequence model with dynamic RNN decoder API.
  Args:
    hparams: Hyperparameter configurations.
    scope: VariableScope for the created subgraph; default "dynamic_seq2seq".
  
  Returns:
    A tuple of the form (logits, loss_tuple, final_context_state, sample_id),
    where:
      logits: float32 Tensor [batch_size x num_decoder_symbols].
      loss: loss = the total loss / batch_size.
      final_context_state: the final state of decoder RNN.
      sample_id: sampling indices.
  
  Raises:
    ValueError: if encoder_type differs from mono and bi, or
      attention_option is not (luong | scaled_luong |
      bahdanau | normed_bahdanau).
docstr_tok: ["Subclass","must","implement","this","method",".","Creates","a","sequence-to-sequence","model","with","dynamic","RNN","decoder","API",".","Args",":","hparams",":","Hyperparameter","configurations",".","scope",":","VariableScope","for","the","created","subgraph",";","default","``","dynamic_seq2seq","''",".","Returns",":","A","tuple","of","the","form","(","logits",",","loss_tuple",",","final_context_state",",","sample_id",")",",","where",":","logits",":","float32","Tensor","[","batch_size","x","num_decoder_symbols","]",".","loss",":","loss","=","the","total","loss","\/","batch_size",".","final_context_state",":","the","final","state","of","decoder","RNN",".","sample_id",":","sampling","indices",".","Raises",":","ValueError",":","if","encoder_type","differs","from","mono","and","bi",",","or","attention_option","is","not","(","luong","|","scaled_luong","|","bahdanau","|","normed_bahdanau",")","."]
code: def build_graph(self, hparams, scope=None):
      """Subclass must implement this method.
  
      Creates a sequence-to-sequence model with dynamic RNN decoder API.
      Args:
        hparams: Hyperparameter configurations.
        scope: VariableScope for the created subgraph; default "dynamic_seq2seq".
  
      Returns:
        A tuple of the form (logits, loss_tuple, final_context_state, sample_id),
        where:
          logits: float32 Tensor [batch_size x num_decoder_symbols].
          loss: loss = the total loss / batch_size.
          final_context_state: the final state of decoder RNN.
          sample_id: sampling indices.
  
      Raises:
        ValueError: if encoder_type differs from mono and bi, or
          attention_option is not (luong | scaled_luong |
          bahdanau | normed_bahdanau).
      """
      utils.print_out("# Creating %s graph ..." % self.mode)
  
      # Projection
      if not self.extract_encoder_layers:
          with tf.variable_scope(scope or "build_network"):
              with tf.variable_scope("decoder/output_projection"):
                  if hparams.projection_type == "sparse":
                      self.output_layer = (
                          core_layers.MaskedFullyConnected(
                              hparams.tgt_vocab_size,
                              use_bias=False,
                              name="output_projection",
                          )
                      )
                  elif hparams.projection_type == "dense":
                      self.output_layer = tf.layers.Dense(
                          hparams.tgt_vocab_size,
                          use_bias=False,
                          name="output_projection",
                      )
                  else:
                      raise ValueError(
                          "Unknown projection type %s!"
                          % hparams.projection_type
                      )
  
      with tf.variable_scope(
          scope or "dynamic_seq2seq", dtype=self.dtype
      ):
          # Encoder
          if hparams.language_model:  # no encoder for language modeling
              utils.print_out("  language modeling: no encoder")
              self.encoder_outputs = None
              encoder_state = None
          else:
              self.encoder_outputs, encoder_state = self._build_encoder(
                  hparams
              )
  
          # Skip decoder if extracting only encoder layers
          if self.extract_encoder_layers:
              return
  
          # Decoder
          (
              logits,
              decoder_cell_outputs,
              sample_id,
              final_context_state,
          ) = self._build_decoder(
              self.encoder_outputs, encoder_state, hparams
          )
  
          # Loss
          if self.mode != tf.contrib.learn.ModeKeys.INFER:
              with tf.device(
                  model_helper.get_device_str(
                      self.num_encoder_layers - 1, self.num_gpus
                  )
              ):
                  loss = self._compute_loss(
                      logits, decoder_cell_outputs
                  )
          else:
              loss = tf.constant(0.0)
  
          # model pruning
          if hparams.pruning_hparams is not None:
              pruning_hparams = pruning.get_pruning_hparams().parse(
                  hparams.pruning_hparams
              )
              self.p = pruning.Pruning(
                  pruning_hparams, global_step=self.global_step
              )
              self.mask_update_op = self.p.conditional_mask_update_op()
              masks = get_masks()
              thresholds = get_thresholds()
              masks_s = []
              for index, mask in enumerate(masks):
                  masks_s.append(
                      tf.summary.scalar(
                          mask.name + "/sparsity",
                          tf.nn.zero_fraction(mask),
                      )
                  )
                  masks_s.append(
                      tf.summary.scalar(
                          thresholds[index].op.name + "/threshold",
                          thresholds[index],
                      )
                  )
                  masks_s.append(
                      tf.summary.histogram(
                          mask.name + "/mask_tensor", mask
                      )
                  )
              self.pruning_summary = tf.summary.merge(
                  [
                      tf.summary.scalar("sparsity", self.p._sparsity),
                      tf.summary.scalar(
                          "last_mask_update_step",
                          self.p._last_update_step,
                      ),
                  ]
                  + masks_s
              )
          else:
              self.mask_update_op = tf.no_op()
              self.pruning_summary = tf.no_op()
  
          return logits, loss, final_context_state, sample_id
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  import collections
  import tensorflow
  from tensorflow.contrib.model_pruning import get_masks, get_thresholds
  from tensorflow.contrib.model_pruning.python import pruning
  from tensorflow.contrib.model_pruning.python.layers import core_layers
  from .None import model_helper
  from .utils import misc_utils, iterator_utils
label_desc: Use image node_id 11 for calling the BaseModel obj's underlying member method code with example usage: obj.build_graph(hparams, scope) and returns: logits,  loss,  final_context_state,  sample_id