tf.PoolerLayerV2 module

tf.PoolerLayerV2 module

class tf.PoolerLayerV2.PoolerLayerV2(*args: Any, **kwargs: Any)

Bases: modelzoo.common.layers.tf.BaseLayer.BaseLayer

The pooler layer. Usually used for pooling or summarizing the sequence data.

This layer is added as a workaround to the existing pooler layer for additional masking support. The plan is to use this layer for kernel matching and integ bring up. After we have full support for this layer, we should deprecate the old PoolerLayer.

Parameters
  • pooler_type (str) – Type of pooling. Currently supports the following

  • types (pooler) –

    • "mean": Mean reduction.

    • "max": Max reduction.

    • "first": First slice in the axis dimension.

    • "last": Last slice in the axis dimension (Not yet supported)

    • "sum": Takes the sum over the axis dimension. Defaults to the entire Tensor.

  • axis (int) – The dimensions to reduce. If None (the default), reduces all dimensions.

  • boundary_casting (bool) – If True, outputs the values in half precision and casts the input values up to full precision.

  • tf_summary (bool) – If True, saves the activations with summary_layer.

call(inputs, padding_mask=None)

Apply pooling with optional masking.

Parameters
  • inputs (Tensor) – Input tensor.

  • padding_mask (Tensor) – The padding mask tensor. Assumed to be 1-based, i.e., has 1 in the non-padded positions and 0 elsewhere. If the input tensor is of the shape [d0, d1, ..., d_{k-1}, d_{axis}, d_{k+1}, ... d_n], then the padding_mask must have the shape [d0, d1, ..., d_{k-1}, axis] or [d0, d1, ..., d_{k-1}, axis, 1, ..., 1]. If None (the default), a padding mask of all 1’s is used.