neulab/docprompting-conala huggingface dataset:
tf.sparse.expand_dims     View source on GitHub    Returns a tensor with an length 1 axis inserted at index axis.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.expand_dims  
tf.sparse.expand_dims(
    sp_input, axis=None, name=None
)
 Given a tensor input, this operation inserts a dimension of length 1 at the dimension index axis of input's shape. The dimension index follows python indexing rules: It's zero-based, a negative index it is counted backward from the end. This operation is useful to:  Add an outer "batch" dimension to a single element. Align axes for broadcasting. To add an inner vector length axis to a tensor of scalars.  For example: If you have a sparse tensor with shape [height, width, depth]: 
sp = tf.sparse.SparseTensor(indices=[[3,4,1]], values=[7,],
                            dense_shape=[10,10,3])
 You can add an outer batch axis by passing axis=0: 
tf.sparse.expand_dims(sp, axis=0).shape.as_list()
[1, 10, 10, 3]
 The new axis location matches Python list.insert(axis, 1): 
tf.sparse.expand_dims(sp, axis=1).shape.as_list()
[10, 1, 10, 3]
 Following standard python indexing rules, a negative axis counts from the end so axis=-1 adds an inner most dimension: 
tf.sparse.expand_dims(sp, axis=-1).shape.as_list()
[10, 10, 3, 1]
 
Note: Unlike tf.expand_dims this function includes a default value for the axis: -1. So if `axis is not specified, an inner dimension is added.
 
sp.shape.as_list()
[10, 10, 3]
tf.sparse.expand_dims(sp).shape.as_list()
[10, 10, 3, 1]
 This operation requires that axis is a valid index for input.shape, following python indexing rules: -1-tf.rank(input) <= axis <= tf.rank(input)
 This operation is related to:  
tf.expand_dims, which provides this functionality for dense tensors. 
tf.squeeze, which removes dimensions of size 1, from dense tensors. 
tf.sparse.reshape, which provides more flexible reshaping capability. 
 


 Args
  sp_input   A SparseTensor.  
  axis   0-D (scalar). Specifies the dimension index at which to expand the shape of input. Must be in the range [-rank(sp_input) - 1, rank(sp_input)]. Defaults to -1.  
  name   The name of the output SparseTensor.   
 


 Returns   A SparseTensor with the same data as sp_input, but its shape has an additional dimension of size 1 added.
tf.sparse.eye     View source on GitHub    Creates a two-dimensional sparse tensor with ones along the diagonal.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.eye  
tf.sparse.eye(
    num_rows, num_columns=None, dtype=tf.dtypes.float32, name=None
)

 


 Args
  num_rows   Non-negative integer or int32 scalar tensor giving the number of rows in the resulting matrix.  
  num_columns   Optional non-negative integer or int32 scalar tensor giving the number of columns in the resulting matrix. Defaults to num_rows.  
  dtype   The type of element in the resulting Tensor.  
  name   A name for this Op. Defaults to "eye".   
 


 Returns   A SparseTensor of shape [num_rows, num_columns] with ones along the diagonal.
tf.sparse.fill_empty_rows     View source on GitHub    Fills empty rows in the input 2-D SparseTensor with a default value.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.fill_empty_rows, tf.compat.v1.sparse_fill_empty_rows  
tf.sparse.fill_empty_rows(
    sp_input, default_value, name=None
)
 This op adds entries with the specified default_value at index [row, 0] for any row in the input that does not already have a value. For example, suppose sp_input has shape [5, 6] and non-empty values: [0, 1]: a
[0, 3]: b
[2, 0]: c
[3, 1]: d
 Rows 1 and 4 are empty, so the output will be of shape [5, 6] with values: [0, 1]: a
[0, 3]: b
[1, 0]: default_value
[2, 0]: c
[3, 1]: d
[4, 0]: default_value
 Note that the input may have empty columns at the end, with no effect on this op. The output SparseTensor will be in row-major order and will have the same shape as the input. This op also returns an indicator vector such that empty_row_indicator[i] = True iff row i was an empty row.

 


 Args
  sp_input   A SparseTensor with shape [N, M].  
  default_value   The value to fill for empty rows, with the same type as sp_input.  
  name   A name prefix for the returned tensors (optional)   
 


 Returns
  sp_ordered_output   A SparseTensor with shape [N, M], and with all empty rows filled in with default_value.  
  empty_row_indicator   A bool vector of length N indicating whether each input row was empty.   
 


 Raises
  TypeError   If sp_input is not a SparseTensor.
tf.sparse.from_dense     View source on GitHub    Converts a dense tensor into a sparse tensor.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.from_dense  
tf.sparse.from_dense(
    tensor, name=None
)
 Only elements not equal to zero will be present in the result. The resulting SparseTensor has the same dtype and shape as the input.
 


 Args
  tensor   A dense Tensor to be converted to a SparseTensor.  
  name   Optional name for the op.   
 


 Returns   The SparseTensor.
tf.sparse.map_values Applies op to the .values tensor of one or more SparseTensors. 
tf.sparse.map_values(
    op, *args, **kwargs
)
 Replaces any SparseTensor in args or kwargs with its values tensor (which contains the non-default values for the SparseTensor), and then calls op. Returns a SparseTensor that is constructed from the input SparseTensors' indices, dense_shape, and the value returned by the op. If the input arguments contain multiple SparseTensors, then they must have equal indices and dense shapes. Examples: 
s = tf.sparse.from_dense([[1, 2, 0],
                          [0, 4, 0],
                          [1, 0, 0]])
tf.sparse.to_dense(tf.sparse.map_values(tf.ones_like, s)).numpy()
array([[1, 1, 0],
       [0, 1, 0],
       [1, 0, 0]], dtype=int32)
 
tf.sparse.to_dense(tf.sparse.map_values(tf.multiply, s, s)).numpy()
array([[ 1,  4,  0],
       [ 0, 16,  0],
       [ 1,  0,  0]], dtype=int32)
 
tf.sparse.to_dense(tf.sparse.map_values(tf.add, s, 5)).numpy()
array([[6, 7, 0],
       [0, 9, 0],
       [6, 0, 0]], dtype=int32)
 
Note: even though tf.add(0, 5) != 0, implicit zeros will remain unchanged. However, if the sparse tensor contains any explict zeros, these will be affected by the mapping!

 


 Args
  op   The operation that should be applied to the SparseTensor values. op is typically an element-wise operation (such as math_ops.add), but any operation that preserves the shape can be used.  
  *args   Arguments for op.  
  **kwargs   Keyword arguments for op.   
 


 Returns   A SparseTensor whose indices and dense_shape matches the indices and dense_shape of all input SparseTensors.  

 


 Raises
  ValueError   If args contains no SparseTensor, or if the indices or dense_shapes of the input SparseTensors are not equal.
tf.sparse.mask     View source on GitHub    Masks elements of IndexedSlices.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.mask, tf.compat.v1.sparse_mask  
tf.sparse.mask(
    a, mask_indices, name=None
)
 Given an IndexedSlices instance a, returns another IndexedSlices that contains a subset of the slices of a. Only the slices at indices not specified in mask_indices are returned. This is useful when you need to extract a subset of slices in an IndexedSlices object. For example: # `a` contains slices at indices [12, 26, 37, 45] from a large tensor
# with shape [1000, 10]
a.indices  # [12, 26, 37, 45]
tf.shape(a.values)  # [4, 10]

# `b` will be the subset of `a` slices at its second and third indices, so
# we want to mask its first and last indices (which are at absolute
# indices 12, 45)
b = tf.sparse.mask(a, [12, 45])

b.indices  # [26, 37]
tf.shape(b.values)  # [2, 10]

 


 Args
  a   An IndexedSlices instance.  
  mask_indices   Indices of elements to mask.  
  name   A name for the operation (optional).   
 


 Returns   The masked IndexedSlices instance.
tf.sparse.maximum     View source on GitHub    Returns the element-wise max of two SparseTensors.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.maximum, tf.compat.v1.sparse_maximum  
tf.sparse.maximum(
    sp_a, sp_b, name=None
)
 Assumes the two SparseTensors have the same shape, i.e., no broadcasting. Example: sp_zero = sparse_tensor.SparseTensor([[0]], [0], [7])
sp_one = sparse_tensor.SparseTensor([[1]], [1], [7])
res = tf.sparse.maximum(sp_zero, sp_one).eval()
# "res" should be equal to SparseTensor([[0], [1]], [0, 1], [7]).

 


 Args
  sp_a   a SparseTensor operand whose dtype is real, and indices lexicographically ordered.  
  sp_b   the other SparseTensor operand with the same requirements (and the same shape).  
  name   optional name of the operation.   
 


 Returns
  output   the output SparseTensor.
tf.sparse.minimum     View source on GitHub    Returns the element-wise min of two SparseTensors.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.minimum, tf.compat.v1.sparse_minimum  
tf.sparse.minimum(
    sp_a, sp_b, name=None
)
 Assumes the two SparseTensors have the same shape, i.e., no broadcasting. Example: sp_zero = sparse_tensor.SparseTensor([[0]], [0], [7])
sp_one = sparse_tensor.SparseTensor([[1]], [1], [7])
res = tf.sparse.minimum(sp_zero, sp_one).eval()
# "res" should be equal to SparseTensor([[0], [1]], [0, 0], [7]).

 


 Args
  sp_a   a SparseTensor operand whose dtype is real, and indices lexicographically ordered.  
  sp_b   the other SparseTensor operand with the same requirements (and the same shape).  
  name   optional name of the operation.   
 


 Returns
  output   the output SparseTensor.
tf.sparse.reduce_max     View source on GitHub    Computes the max of elements across dimensions of a SparseTensor. 
tf.sparse.reduce_max(
    sp_input, axis=None, keepdims=None, output_is_sparse=False, name=None
)
 This Op takes a SparseTensor and is the sparse counterpart to tf.reduce_max(). In particular, this Op also returns a dense Tensor if output_is_sparse is False, or a SparseTensor if output_is_sparse is True. 
Note: A gradient is not defined for this function, so it can't be used in training models that need gradient descent.
 Reduces sp_input along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keepdims is true, the reduced dimensions are retained with length 1. If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned. Additionally, the axes can be negative, similar to the indexing rules in Python. The values not defined in sp_input don't participate in the reduce max, as opposed to be implicitly assumed 0 -- hence it can return negative values for sparse axis. But, in case there are no values in axis, it will reduce to 0. See second example below. For example: # 'x' represents [[1, ?, 2]
#                 [?, 3, ?]]
# where ? is implicitly-zero.
tf.sparse.reduce_max(x) ==> 3
tf.sparse.reduce_max(x, 0) ==> [1, 3, 2]
tf.sparse.reduce_max(x, 1) ==> [2, 3]  # Can also use -1 as the axis.
tf.sparse.reduce_max(x, 1, keepdims=True) ==> [[2], [3]]
tf.sparse.reduce_max(x, [0, 1]) ==> 3

# 'y' represents [[-7, ?]
#                 [ 4, 3]
#                 [ ?, ?]
tf.sparse.reduce_max(x, 1) ==> [-7, 4, 0]

 


 Args
  sp_input   The SparseTensor to reduce. Should have numeric type.  
  axis   The dimensions to reduce; list or scalar. If None (the default), reduces all dimensions.  
  keepdims   If true, retain reduced dimensions with length 1.  
  output_is_sparse   If true, returns a SparseTensor instead of a dense Tensor (the default).  
  name   A name for the operation (optional).   
 


 Returns   The reduced Tensor or the reduced SparseTensor if output_is_sparse is True.
tf.sparse.reduce_sum     View source on GitHub    Computes the sum of elements across dimensions of a SparseTensor. 
tf.sparse.reduce_sum(
    sp_input, axis=None, keepdims=None, output_is_sparse=False, name=None
)
 This Op takes a SparseTensor and is the sparse counterpart to tf.reduce_sum(). In particular, this Op also returns a dense Tensor if output_is_sparse is False, or a SparseTensor if output_is_sparse is True. 
Note: if output_is_sparse is True, a gradient is not defined for this function, so it can't be used in training models that need gradient descent.
 Reduces sp_input along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keepdims is true, the reduced dimensions are retained with length 1. If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned. Additionally, the axes can be negative, similar to the indexing rules in Python. For example: # 'x' represents [[1, ?, 1]
#                 [?, 1, ?]]
# where ? is implicitly-zero.
tf.sparse.reduce_sum(x) ==> 3
tf.sparse.reduce_sum(x, 0) ==> [1, 1, 1]
tf.sparse.reduce_sum(x, 1) ==> [2, 1]  # Can also use -1 as the axis.
tf.sparse.reduce_sum(x, 1, keepdims=True) ==> [[2], [1]]
tf.sparse.reduce_sum(x, [0, 1]) ==> 3

 


 Args
  sp_input   The SparseTensor to reduce. Should have numeric type.  
  axis   The dimensions to reduce; list or scalar. If None (the default), reduces all dimensions.  
  keepdims   If true, retain reduced dimensions with length 1.  
  output_is_sparse   If true, returns a SparseTensor instead of a dense Tensor (the default).  
  name   A name for the operation (optional).   
 


 Returns   The reduced Tensor or the reduced SparseTensor if output_is_sparse is True.
tf.sparse.reorder     View source on GitHub    Reorders a SparseTensor into the canonical, row-major ordering.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.reorder, tf.compat.v1.sparse_reorder  
tf.sparse.reorder(
    sp_input, name=None
)
 Note that by convention, all sparse ops preserve the canonical ordering along increasing dimension number. The only time ordering can be violated is during manual manipulation of the indices and values to add entries. Reordering does not affect the shape of the SparseTensor. For example, if sp_input has shape [4, 5] and indices / values: [0, 3]: b
[0, 1]: a
[3, 1]: d
[2, 0]: c
 then the output will be a SparseTensor of shape [4, 5] and indices / values: [0, 1]: a
[0, 3]: b
[2, 0]: c
[3, 1]: d

 


 Args
  sp_input   The input SparseTensor.  
  name   A name prefix for the returned tensors (optional)   
 


 Returns   A SparseTensor with the same shape and non-empty values, but in canonical ordering.  

 


 Raises
  TypeError   If sp_input is not a SparseTensor.
tf.sparse.reset_shape     View source on GitHub    Resets the shape of a SparseTensor with indices and values unchanged.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.reset_shape, tf.compat.v1.sparse_reset_shape  
tf.sparse.reset_shape(
    sp_input, new_shape=None
)
 If new_shape is None, returns a copy of sp_input with its shape reset to the tight bounding box of sp_input. This will be a shape consisting of all zeros if sp_input has no values. If new_shape is provided, then it must be larger or equal in all dimensions compared to the shape of sp_input. When this condition is met, the returned SparseTensor will have its shape reset to new_shape and its indices and values unchanged from that of sp_input. For example: Consider a sp_input with shape [2, 3, 5]:  It is an error to set new_shape as [3, 7] since this represents a rank-2 tensor while sp_input is rank-3. This is either a ValueError during graph construction (if both shapes are known) or an OpError during run time. Setting new_shape as [2, 3, 6] will be fine as this shape is larger or equal in every dimension compared to the original shape [2, 3, 5]. On the other hand, setting new_shape as [2, 3, 4] is also an error: The third dimension is smaller than the original shape 2, 3, 5. If new_shape is None, the returned SparseTensor will have a shape [2, 3, 4], which is the tight bounding box of sp_input. 
 


 Args
  sp_input   The input SparseTensor.  
  new_shape   None or a vector representing the new shape for the returned SparseTensor.   
 


 Returns   A SparseTensor indices and values unchanged from input_sp. Its shape is new_shape if that is set. Otherwise it is the tight bounding box of input_sp  

 


 Raises
  TypeError   If sp_input is not a SparseTensor.  
  ValueError   If new_shape represents a tensor with a different rank from that of sp_input (if shapes are known when graph is constructed).  
  ValueError   If new_shape is determined during graph build to have dimension sizes that are too small.  
  OpError    If new_shape has dimension sizes that are too small. If shapes are not known during graph construction time, and during run time it is found out that the ranks do not match.
tf.sparse.reshape     View source on GitHub    Reshapes a SparseTensor to represent values in a new dense shape.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.reshape, tf.compat.v1.sparse_reshape  
tf.sparse.reshape(
    sp_input, shape, name=None
)
 This operation has the same semantics as reshape on the represented dense tensor. The indices of non-empty values in sp_input are recomputed based on the new dense shape, and a new SparseTensor is returned containing the new indices and new shape. The order of non-empty values in sp_input is unchanged. If one component of shape is the special value -1, the size of that dimension is computed so that the total dense size remains constant. At most one component of shape can be -1. The number of dense elements implied by shape must be the same as the number of dense elements originally represented by sp_input. For example, if sp_input has shape [2, 3, 6] and indices / values: [0, 0, 0]: a
[0, 0, 1]: b
[0, 1, 0]: c
[1, 0, 0]: d
[1, 2, 3]: e
 and shape is [9, -1], then the output will be a SparseTensor of shape [9, 4] and indices / values: [0, 0]: a
[0, 1]: b
[1, 2]: c
[4, 2]: d
[8, 1]: e

 


 Args
  sp_input   The input SparseTensor.  
  shape   A 1-D (vector) int64 Tensor specifying the new dense shape of the represented SparseTensor.  
  name   A name prefix for the returned tensors (optional)   
 


 Returns   A SparseTensor with the same non-empty values but with indices calculated by the new dense shape.  

 


 Raises
  TypeError   If sp_input is not a SparseTensor.  
  ValueError   If argument shape requests a SparseTensor with a different number of elements than sp_input.  
  ValueError   If shape has more than one inferred (== -1) dimension.
tf.sparse.retain     View source on GitHub    Retains specified non-empty values within a SparseTensor.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.sparse.retain, tf.compat.v1.sparse_retain  
tf.sparse.retain(
    sp_input, to_retain
)
 For example, if sp_input has shape [4, 5] and 4 non-empty string values: [0, 1]: a
[0, 3]: b
[2, 0]: c
[3, 1]: d
 and to_retain = [True, False, False, True], then the output will be a SparseTensor of shape [4, 5] with 2 non-empty values: [0, 1]: a
[3, 1]: d

 


 Args
  sp_input   The input SparseTensor with N non-empty elements.  
  to_retain   A bool vector of length N with M true values.   
 


 Returns   A SparseTensor with the same shape as the input and M non-empty elements corresponding to the true positions in to_retain.  

 


 Raises
  TypeError   If sp_input is not a SparseTensor.
tf.sparse.segment_mean     View source on GitHub    Computes the mean along sparse segments of a tensor. 
tf.sparse.segment_mean(
    data, indices, segment_ids, num_segments=None, name=None
)
 Read the section on segmentation for an explanation of segments. Like tf.math.segment_mean, but segment_ids can have rank less than data's first dimension, selecting a subset of dimension 0, specified by indices. segment_ids is allowed to have missing ids, in which case the output will be zeros at those indices. In those cases num_segments is used to determine the size of the output.
 


 Args
  data   A Tensor with data that will be assembled in the output.  
  indices   A 1-D Tensor with indices into data. Has same rank as segment_ids.  
  segment_ids   A 1-D Tensor with indices into the output Tensor. Values should be sorted and can be repeated.  
  num_segments   An optional int32 scalar. Indicates the size of the output Tensor.  
  name   A name for the operation (optional).   
 


 Returns   A tensor of the shape as data, except for dimension 0 which has size k, the number of segments specified via num_segments or inferred for the last element in segments_ids.
tf.sparse.segment_sqrt_n     View source on GitHub    Computes the sum along sparse segments of a tensor divided by the sqrt(N). 
tf.sparse.segment_sqrt_n(
    data, indices, segment_ids, num_segments=None, name=None
)
 Read the section on segmentation for an explanation of segments. Like tf.sparse.segment_mean, but instead of dividing by the size of the segment, N, divide by sqrt(N) instead.
 


 Args
  data   A Tensor with data that will be assembled in the output.  
  indices   A 1-D Tensor with indices into data. Has same rank as segment_ids.  
  segment_ids   A 1-D Tensor with indices into the output Tensor. Values should be sorted and can be repeated.  
  num_segments   An optional int32 scalar. Indicates the size of the output Tensor.  
  name   A name for the operation (optional).   
 


 Returns   A tensor of the shape as data, except for dimension 0 which has size k, the number of segments specified via num_segments or inferred for the last element in segments_ids.
tf.sparse.segment_sum     View source on GitHub    Computes the sum along sparse segments of a tensor. 
tf.sparse.segment_sum(
    data, indices, segment_ids, num_segments=None, name=None
)
 Read the section on segmentation for an explanation of segments. Like tf.math.segment_sum, but segment_ids can have rank less than data's first dimension, selecting a subset of dimension 0, specified by indices. segment_ids is allowed to have missing ids, in which case the output will be zeros at those indices. In those cases num_segments is used to determine the size of the output. For example: c = tf.constant([[1,2,3,4], [-1,-2,-3,-4], [5,6,7,8]])

# Select two rows, one segment.
tf.sparse.segment_sum(c, tf.constant([0, 1]), tf.constant([0, 0]))
# => [[0 0 0 0]]

# Select two rows, two segment.
tf.sparse.segment_sum(c, tf.constant([0, 1]), tf.constant([0, 1]))
# => [[ 1  2  3  4]
#     [-1 -2 -3 -4]]

# With missing segment ids.
tf.sparse.segment_sum(c, tf.constant([0, 1]), tf.constant([0, 2]),
                      num_segments=4)
# => [[ 1  2  3  4]
#     [ 0  0  0  0]
#     [-1 -2 -3 -4]
#     [ 0  0  0  0]]

# Select all rows, two segments.
tf.sparse.segment_sum(c, tf.constant([0, 1, 2]), tf.constant([0, 0, 1]))
# => [[0 0 0 0]
#     [5 6 7 8]]

# Which is equivalent to:
tf.math.segment_sum(c, tf.constant([0, 0, 1]))

 


 Args
  data   A Tensor with data that will be assembled in the output.  
  indices   A 1-D Tensor with indices into data. Has same rank as segment_ids.  
  segment_ids   A 1-D Tensor with indices into the output Tensor. Values should be sorted and can be repeated.  
  num_segments   An optional int32 scalar. Indicates the size of the output Tensor.  
  name   A name for the operation (optional).   
 


 Returns   A tensor of the shape as data, except for dimension 0 which has size k, the number of segments specified via num_segments or inferred for the last element in segments_ids.