def get_sequence_dense_tensor(self, transformation_cache, state_manager):
    """Returns a `TensorSequenceLengthPair`.

    Args:
      transformation_cache: A `FeatureTransformationCache` object to access
        features.
      state_manager: A `StateManager` to create / access resources such as
        lookup tables.
    """
    sp_tensor = transformation_cache.get(self, state_manager)
    dense_tensor = sparse_ops.sparse_tensor_to_dense(
        sp_tensor, default_value=self.default_value)
    # Reshape into [batch_size, T, variable_shape].
    dense_shape = array_ops.concat(
        [array_ops.shape(dense_tensor)[:1], [-1], self.variable_shape],
        axis=0)
    dense_tensor = array_ops.reshape(dense_tensor, shape=dense_shape)

    # Get the number of timesteps per example
    # For the 2D case, the raw values are grouped according to num_elements;
    # for the 3D case, the grouping happens in the third dimension, and
    # sequence length is not affected.
    num_elements = (self.variable_shape.num_elements()
                    if sp_tensor.shape.ndims == 2 else 1)
    seq_length = fc_old._sequence_length_from_sparse_tensor(
        sp_tensor, num_elements=num_elements)

    return fc.SequenceDenseColumn.TensorSequenceLengthPair(
        dense_tensor=dense_tensor, sequence_length=seq_length)
  def _get_sequence_dense_tensor(
      self, inputs, weight_collections=None, trainable=None):
    # Do nothing with weight_collections and trainable since no variables are
    # created in this function.
    del weight_collections
    del trainable
    sp_tensor = inputs.get(self)
    dense_tensor = sparse_ops.sparse_tensor_to_dense(
        sp_tensor, default_value=self.default_value)
    # Reshape into [batch_size, T, variable_shape].
    dense_shape = array_ops.concat(
        [array_ops.shape(dense_tensor)[:1], [-1], self._variable_shape],
        axis=0)
    dense_tensor = array_ops.reshape(dense_tensor, shape=dense_shape)

    # Get the number of timesteps per example
    # For the 2D case, the raw values are grouped according to num_elements;
    # for the 3D case, the grouping happens in the third dimension, and
    # sequence length is not affected.
    num_elements = (self._variable_shape.num_elements()
                    if sp_tensor.shape.ndims == 2 else 1)
    seq_length = fc._sequence_length_from_sparse_tensor(
        sp_tensor, num_elements=num_elements)

    return fc._SequenceDenseColumn.TensorSequenceLengthPair(
        dense_tensor=dense_tensor, sequence_length=seq_length)
Example #3
0
    def get_sequence_dense_tensor(self, transformation_cache, state_manager):
        """Returns a `TensorSequenceLengthPair`.

    Args:
      transformation_cache: A `FeatureTransformationCache` object to access
        features.
      state_manager: A `StateManager` to create / access resources such as
        lookup tables.
    """
        sp_tensor = transformation_cache.get(self, state_manager)
        dense_tensor = sparse_ops.sparse_tensor_to_dense(
            sp_tensor, default_value=self.default_value)
        # Reshape into [batch_size, T, variable_shape].
        dense_shape = array_ops.concat(
            [array_ops.shape(dense_tensor)[:1], [-1], self.variable_shape],
            axis=0)
        dense_tensor = array_ops.reshape(dense_tensor, shape=dense_shape)

        # Get the number of timesteps per example
        # For the 2D case, the raw values are grouped according to num_elements;
        # for the 3D case, the grouping happens in the third dimension, and
        # sequence length is not affected.
        num_elements = (self.variable_shape.num_elements()
                        if sp_tensor.shape.ndims == 2 else 1)
        seq_length = fc_old._sequence_length_from_sparse_tensor(
            sp_tensor, num_elements=num_elements)

        return fc.SequenceDenseColumn.TensorSequenceLengthPair(
            dense_tensor=dense_tensor, sequence_length=seq_length)
    def _get_sequence_dense_tensor(self,
                                   inputs,
                                   weight_collections=None,
                                   trainable=None):
        # Do nothing with weight_collections and trainable since no variables are
        # created in this function.
        del weight_collections
        del trainable
        sp_tensor = inputs.get(self)
        dense_tensor = sparse_ops.sparse_tensor_to_dense(
            sp_tensor, default_value=self.default_value)
        # Reshape into [batch_size, T, variable_shape].
        dense_shape = array_ops.concat(
            [array_ops.shape(dense_tensor)[:1], [-1], self._variable_shape],
            axis=0)
        dense_tensor = array_ops.reshape(dense_tensor, shape=dense_shape)

        # Get the number of timesteps per example
        # For the 2D case, the raw values are grouped according to num_elements;
        # for the 3D case, the grouping happens in the third dimension, and
        # sequence length is not affected.
        num_elements = (self._variable_shape.num_elements()
                        if sp_tensor.shape.ndims == 2 else 1)
        seq_length = fc._sequence_length_from_sparse_tensor(
            sp_tensor, num_elements=num_elements)

        return fc._SequenceDenseColumn.TensorSequenceLengthPair(
            dense_tensor=dense_tensor, sequence_length=seq_length)
Example #5
0
    def _get_sequence_dense_tensor(self,
                                   inputs,
                                   weight_collections=None,
                                   trainable=None):
        del weight_collections, trainable

        if self.signature != 'sequence':
            raise ValueError(
                'Column {} could not be used as sequence feature column. '
                'Use sequence_text_embedding_column instead'.format(self.name))

        sparse_keys = inputs.get(self)
        sparse_keys.shape.with_rank_at_least(2)
        sparse_keys.shape.with_rank_at_most(3)

        batch_size, max_length = sparse_keys.dense_shape[
            0], sparse_keys.dense_shape[1]
        sparse_keys = tf.sparse_reshape(sparse_keys,
                                        shape=tf.stack(
                                            [batch_size, max_length, -1]))

        dense_tensor = self._hub_module(sparse_keys, signature=self.signature)
        sequence_length = feature_column._sequence_length_from_sparse_tensor(
            inputs.get(self))

        return feature_column._SequenceDenseColumn.TensorSequenceLengthPair(
            dense_tensor=dense_tensor, sequence_length=sequence_length)
Example #6
0
 def _get_sequence_dense_tensor(
     self, inputs, weight_collections=None, trainable=None):
   # Do nothing with weight_collections and trainable since no variables are
   # created in this function.
   del weight_collections
   del trainable
   sp_tensor = inputs.get(self)
   dense_tensor = sparse_ops.sparse_tensor_to_dense(
       sp_tensor, default_value=self.default_value)
   # Reshape into [batch_size, T, variable_shape].
   dense_shape = array_ops.concat(
       [array_ops.shape(dense_tensor)[:1], [-1], self._variable_shape],
       axis=0)
   dense_tensor = array_ops.reshape(dense_tensor, shape=dense_shape)
   sequence_length = fc._sequence_length_from_sparse_tensor(
       sp_tensor, num_elements=self._variable_shape.num_elements())
   return fc._SequenceDenseColumn.TensorSequenceLengthPair(
       dense_tensor=dense_tensor, sequence_length=sequence_length)
 def _get_sequence_dense_tensor(
     self, inputs, weight_collections=None, trainable=None):
   # Do nothing with weight_collections and trainable since no variables are
   # created in this function.
   del weight_collections
   del trainable
   sp_tensor = inputs.get(self)
   dense_tensor = sparse_ops.sparse_tensor_to_dense(
       sp_tensor, default_value=self.default_value)
   # Reshape into [batch_size, T, variable_shape].
   dense_shape = array_ops.concat(
       [array_ops.shape(dense_tensor)[:1], [-1], self._variable_shape],
       axis=0)
   dense_tensor = array_ops.reshape(dense_tensor, shape=dense_shape)
   sequence_length = fc._sequence_length_from_sparse_tensor(
       sp_tensor, num_elements=self._variable_shape.num_elements())
   return fc._SequenceDenseColumn.TensorSequenceLengthPair(
       dense_tensor=dense_tensor, sequence_length=sequence_length)