class_docstr: Text CNN.
docstr: TextCNN main model_fn.
  
  Args:
    features: Map of features to the model. Should contain the following:
        "inputs": Text inputs.
            [batch_size, input_length, 1, hidden_dim].
        "targets": Target encoder outputs.
            [batch_size, 1, 1, hidden_dim]
  Returns:
    Final encoder representation. [batch_size, 1, 1, hidden_dim]
code: def body(self, features):
      """TextCNN main model_fn.
  
      Args:
        features: Map of features to the model. Should contain the following:
            "inputs": Text inputs.
                [batch_size, input_length, 1, hidden_dim].
            "targets": Target encoder outputs.
                [batch_size, 1, 1, hidden_dim]
      Returns:
        Final encoder representation. [batch_size, 1, 1, hidden_dim]
      """
      hparams = self._hparams
      inputs = features["inputs"]
  
      xshape = common_layers.shape_list(inputs)
  
      vocab_size = xshape[3]
      inputs = tf.reshape(
          inputs, [xshape[0], xshape[1], xshape[3], xshape[2]]
      )
  
      pooled_outputs = []
      for _, filter_size in enumerate(hparams.filter_sizes):
          with tf.name_scope("conv-maxpool-%s" % filter_size):
              filter_shape = [
                  filter_size,
                  vocab_size,
                  1,
                  hparams.num_filters,
              ]
              filter_var = tf.Variable(
                  tf.truncated_normal(filter_shape, stddev=0.1),
                  name="W",
              )
              filter_bias = tf.Variable(
                  tf.constant(0.1, shape=[hparams.num_filters]),
                  name="b",
              )
              conv = tf.nn.conv2d(
                  inputs,
                  filter_var,
                  strides=[1, 1, 1, 1],
                  padding="VALID",
                  name="conv",
              )
              conv_outputs = tf.nn.relu(
                  tf.nn.bias_add(conv, filter_bias), name="relu"
              )
              pooled = tf.math.reduce_max(
                  conv_outputs, axis=1, keepdims=True, name="max"
              )
              pooled_outputs.append(pooled)
  
      num_filters_total = hparams.num_filters * len(
          hparams.filter_sizes
      )
      h_pool = tf.concat(pooled_outputs, 3)
      h_pool_flat = tf.reshape(h_pool, [-1, num_filters_total])
  
      # Add dropout
      output = tf.nn.dropout(h_pool_flat, 1 - hparams.output_dropout)
      output = tf.reshape(output, [-1, 1, 1, num_filters_total])
  
      return output
  
file_path: tensor2tensor/tensor2tensor/models/text_cnn.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling the TextCNN obj's underlying member method code with example usage: obj.body(features) and returns: output