tensorflow/models · error · ValueError

PositionEmbedding must have `use_dynamic_slicing` set to Tru

Error message

PositionEmbedding must have `use_dynamic_slicing` set to True (and max_sequence_length set) when the sequence (1st) dimension of the input is None.

What it means

Error "PositionEmbedding must have `use_dynamic_slicing` set to True (and max_sequence_length set) when the sequence (1st) dimension of the input is None." thrown in tensorflow/models.

Source

Thrown at official/nlp/modeling/networks/packed_sequence_embedding.py:256

    }
    base_config = super().get_config()
    return dict(list(base_config.items()) + list(config.items()))

  def build(self, input_shape):
    """Implements build() for the layer."""
    dimension_list = input_shape.as_list()

    if len(dimension_list) != 3:
      raise ValueError('PositionEmbedding expects a 3-dimensional input tensor '
                       'of shape [batch, sequence, width]')
    seq_length = dimension_list[1]
    width = dimension_list[2]

    # If we are not using dynamic slicing, we must assume that the sequence
    # length is fixed and max_sequence_length should not be specified.
    if not self._use_dynamic_slicing:
      if seq_length is None:
        raise ValueError(
            'PositionEmbedding must have `use_dynamic_slicing` set '
            'to True (and max_sequence_length set) when the '
            'sequence (1st) dimension of the input is None.')
      if self._max_sequence_length is not None:
        raise ValueError(
            'When `use_dynamic_slicing` is False, max_sequence_length should '
            'not be specified and we ought to use seq_length to get the '
            'variable shape.')

    if self._max_sequence_length is not None:
      weight_sequence_length = self._max_sequence_length
    else:
      weight_sequence_length = seq_length

    self._position_embeddings = self.add_weight(
        'embeddings',
        shape=[weight_sequence_length, width],
        initializer=self._initializer)

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/nlp/modeling/networks/packed_sequence_embedding.py:256 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24). Data as JSON: /api/errors/5d3ded825f6f21ca. Report an issue: GitHub.