class_docstr: An encoder that pools over embeddings, as described in
  https://arxiv.org/abs/1611.02344. The encoder supports optional positions
  embeddings and a configurable pooling window.
  
  Params:
    dropout_keep_prob: Dropout keep probability applied to the embeddings.
    pooling_fn: The 1-d pooling function to use, e.g.
      `tensorflow.layers.average_pooling1d`.
    pool_size: The pooling window, passed as `pool_size` to
      the pooling function.
    strides: The stride during pooling, passed as `strides`
      the pooling function.
    position_embeddings.enable: If true, add position embeddings to the
      inputs before pooling.
    position_embeddings.combiner_fn: Function used to combine the
      position embeddings with the inputs. For example, `tensorflow.add`.
    position_embeddings.num_positions: Size of the position embedding matrix.
      This should be set to the maximum sequence length of the inputs.
class_docstr_tok: ["An","encoder","that","pools","over","embeddings",",","as","described","in","https",":","\/\/arxiv.org\/abs\/1611.02344",".","The","encoder","supports","optional","positions","embeddings","and","a","configurable","pooling","window",".","Params",":","dropout_keep_prob",":","Dropout","keep","probability","applied","to","the","embeddings",".","pooling_fn",":","The","1-d","pooling","function","to","use",",","e.g",".","`","tensorflow.layers.average_pooling1d","`",".","pool_size",":","The","pooling","window",",","passed","as","`","pool_size","`","to","the","pooling","function",".","strides",":","The","stride","during","pooling",",","passed","as","`","strides","`","the","pooling","function",".","position_embeddings.enable",":","If","true",",","add","position","embeddings","to","the","inputs","before","pooling",".","position_embeddings.combiner_fn",":","Function","used","to","combine","the","position","embeddings","with","the","inputs",".","For","example",",","`","tensorflow.add","`",".","position_embeddings.num_positions",":","Size","of","the","position","embedding","matrix",".","This","should","be","set","to","the","maximum","sequence","length","of","the","inputs","."]
code: def encode(self, inputs, sequence_length):
      if self.params["position_embeddings.enable"]:
          positions_embed = _create_position_embedding(
              embedding_dim=inputs.get_shape().as_list()[-1],
              num_positions=self.params[
                  "position_embeddings.num_positions"
              ],
              lengths=sequence_length,
              maxlen=tf.shape(inputs)[1],
          )
          inputs = self._combiner_fn(inputs, positions_embed)
  
      # Apply dropout
      inputs = tf.contrib.layers.dropout(
          inputs=inputs,
          keep_prob=self.params["dropout_keep_prob"],
          is_training=self.mode == tf.contrib.learn.ModeKeys.TRAIN,
      )
  
      outputs = self._pooling_fn(
          inputs=inputs,
          pool_size=self.params["pool_size"],
          strides=self.params["strides"],
          padding="SAME",
      )
  
      # Final state is the average representation of the pooled embeddings
      final_state = tf.reduce_mean(outputs, 1)
  
      return EncoderOutput(
          outputs=outputs,
          final_state=final_state,
          attention_values=inputs,
          attention_values_length=sequence_length,
      )
  
file_path: seq2seq/seq2seq/encoders/pooling_encoder.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from pydoc import locate
  import numpy
  import tensorflow
  from seq2seq.encoders.encoder import Encoder, EncoderOutput
label_desc: Use image node_id 3 for calling the PoolingEncoder obj's underlying member method code with example usage: obj.encode(inputs, sequence_length) and returns: EncoderOutput