neulab/docprompting-conala huggingface dataset:
tf.bitwise.left_shift Elementwise computes the bitwise left-shift of x and y.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.bitwise.left_shift  
tf.bitwise.left_shift(
    x, y, name=None
)
 If y is negative, or greater than or equal to the width of x in bits the result is implementation defined. Example: import tensorflow as tf
from tensorflow.python.ops import bitwise_ops
import numpy as np
dtype_list = [tf.int8, tf.int16, tf.int32, tf.int64]

for dtype in dtype_list:
  lhs = tf.constant([-1, -5, -3, -14], dtype=dtype)
  rhs = tf.constant([5, 0, 7, 11], dtype=dtype)

  left_shift_result = bitwise_ops.left_shift(lhs, rhs)

  print(left_shift_result)

# This will print:
# tf.Tensor([ -32   -5 -128    0], shape=(4,), dtype=int8)
# tf.Tensor([   -32     -5   -384 -28672], shape=(4,), dtype=int16)
# tf.Tensor([   -32     -5   -384 -28672], shape=(4,), dtype=int32)
# tf.Tensor([   -32     -5   -384 -28672], shape=(4,), dtype=int64)

lhs = np.array([-2, 64, 101, 32], dtype=np.int8)
rhs = np.array([-1, -5, -3, -14], dtype=np.int8)
bitwise_ops.left_shift(lhs, rhs)
# <tf.Tensor: shape=(4,), dtype=int8, numpy=array([ -2,  64, 101,  32], dtype=int8)>

 


 Args
  x   A Tensor. Must be one of the following types: int8, int16, int32, int64, uint8, uint16, uint32, uint64.  
  y   A Tensor. Must have the same type as x.  
  name   A name for the operation (optional).   
 


 Returns   A Tensor. Has the same type as x.
tf.bitwise.right_shift Elementwise computes the bitwise right-shift of x and y.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.bitwise.right_shift  
tf.bitwise.right_shift(
    x, y, name=None
)
 Performs a logical shift for unsigned integer types, and an arithmetic shift for signed integer types. If y is negative, or greater than or equal to than the width of x in bits the result is implementation defined. Example: import tensorflow as tf
from tensorflow.python.ops import bitwise_ops
import numpy as np
dtype_list = [tf.int8, tf.int16, tf.int32, tf.int64]

for dtype in dtype_list:
  lhs = tf.constant([-1, -5, -3, -14], dtype=dtype)
  rhs = tf.constant([5, 0, 7, 11], dtype=dtype)

  right_shift_result = bitwise_ops.right_shift(lhs, rhs)

  print(right_shift_result)

# This will print:
# tf.Tensor([-1 -5 -1 -1], shape=(4,), dtype=int8)
# tf.Tensor([-1 -5 -1 -1], shape=(4,), dtype=int16)
# tf.Tensor([-1 -5 -1 -1], shape=(4,), dtype=int32)
# tf.Tensor([-1 -5 -1 -1], shape=(4,), dtype=int64)

lhs = np.array([-2, 64, 101, 32], dtype=np.int8)
rhs = np.array([-1, -5, -3, -14], dtype=np.int8)
bitwise_ops.right_shift(lhs, rhs)
# <tf.Tensor: shape=(4,), dtype=int8, numpy=array([ -2,  64, 101,  32], dtype=int8)>

 


 Args
  x   A Tensor. Must be one of the following types: int8, int16, int32, int64, uint8, uint16, uint32, uint64.  
  y   A Tensor. Must have the same type as x.  
  name   A name for the operation (optional).   
 


 Returns   A Tensor. Has the same type as x.
tf.boolean_mask     View source on GitHub    Apply boolean mask to tensor. 
tf.boolean_mask(
    tensor, mask, axis=None, name='boolean_mask'
)
 Numpy equivalent is tensor[mask]. In general, 0 < dim(mask) = K <= dim(tensor), and mask's shape must match the first K dimensions of tensor's shape. We then have: boolean_mask(tensor, mask)[i, j1,...,jd] = tensor[i1,...,iK,j1,...,jd] where (i1,...,iK) is the ith True entry of mask (row-major order). The axis could be used with mask to indicate the axis to mask from. In that case, axis + dim(mask) <= dim(tensor) and mask's shape must match the first axis + dim(mask) dimensions of tensor's shape. See also: tf.ragged.boolean_mask, which can be applied to both dense and ragged tensors, and can be used if you need to preserve the masked dimensions of tensor (rather than flattening them, as tf.boolean_mask does). Examples: 
tensor = [0, 1, 2, 3]  # 1-D example
mask = np.array([True, False, True, False])
tf.boolean_mask(tensor, mask)
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([0, 2], dtype=int32)>
 
tensor = [[1, 2], [3, 4], [5, 6]] # 2-D example
mask = np.array([True, False, True])
tf.boolean_mask(tensor, mask)
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[1, 2],
       [5, 6]], dtype=int32)>

 


 Args
  tensor   N-D Tensor.  
  mask   K-D boolean Tensor, K <= N and K must be known statically.  
  axis   A 0-D int Tensor representing the axis in tensor to mask from. By default, axis is 0 which will mask from the first dimension. Otherwise K + axis <= N.  
  name   A name for this operation (optional).   
 


 Returns   (N-K+1)-dimensional tensor populated by entries in tensor corresponding to True values in mask.  

 


 Raises
  ValueError   If shapes do not conform.    Examples: # 2-D example
tensor = [[1, 2], [3, 4], [5, 6]]
mask = np.array([True, False, True])
boolean_mask(tensor, mask)  # [[1, 2], [5, 6]]
tf.broadcast_dynamic_shape     View source on GitHub    Computes the shape of a broadcast given symbolic shapes.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.broadcast_dynamic_shape  
tf.broadcast_dynamic_shape(
    shape_x, shape_y
)
 When shape_x and shape_y are Tensors representing shapes (i.e. the result of calling tf.shape on another Tensor) this computes a Tensor which is the shape of the result of a broadcasting op applied in tensors of shapes shape_x and shape_y. This is useful when validating the result of a broadcasting operation when the tensors do not have statically known shapes. Example: 
shape_x = (1, 2, 3)
shape_y = (5, 1, 3)
tf.broadcast_dynamic_shape(shape_x, shape_y)
<tf.Tensor: shape=(3,), dtype=int32, numpy=array([5, 2, 3], ...>

 


 Args
  shape_x   A rank 1 integer Tensor, representing the shape of x.  
  shape_y   A rank 1 integer Tensor, representing the shape of y.   
 


 Returns   A rank 1 integer Tensor representing the broadcasted shape.  

 


 Raises
  InvalidArgumentError   If the two shapes are incompatible for broadcasting.
tf.broadcast_static_shape     View source on GitHub    Computes the shape of a broadcast given known shapes.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.broadcast_static_shape  
tf.broadcast_static_shape(
    shape_x, shape_y
)
 When shape_x and shape_y are fully known TensorShapes this computes a TensorShape which is the shape of the result of a broadcasting op applied in tensors of shapes shape_x and shape_y. For example, if shape_x is TensorShape([1, 2, 3]) and shape_y is TensorShape([5, 1, 3]), the result is a TensorShape whose value is TensorShape([5, 2, 3]). This is useful when validating the result of a broadcasting operation when the tensors have statically known shapes. Example: 
shape_x = tf.TensorShape([1, 2, 3])
shape_y = tf.TensorShape([5, 1 ,3])
tf.broadcast_static_shape(shape_x, shape_y)
TensorShape([5, 2, 3])

 


 Args
  shape_x   A TensorShape  
  shape_y   A TensorShape   
 


 Returns   A TensorShape representing the broadcasted shape.  

 


 Raises
  ValueError   If the two shapes can not be broadcasted.
tf.broadcast_to Broadcast an array for a compatible shape.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.broadcast_to  
tf.broadcast_to(
    input, shape, name=None
)
 Broadcasting is the process of making arrays to have compatible shapes for arithmetic operations. Two shapes are compatible if for each dimension pair they are either equal or one of them is one. When trying to broadcast a Tensor to a shape, it starts with the trailing dimensions, and works its way forward. For example, 
x = tf.constant([1, 2, 3])
y = tf.broadcast_to(x, [3, 3])
print(y)
tf.Tensor(
    [[1 2 3]
     [1 2 3]
     [1 2 3]], shape=(3, 3), dtype=int32)
 In the above example, the input Tensor with the shape of [1, 3] is broadcasted to output Tensor with shape of [3, 3]. When doing broadcasted operations such as multiplying a tensor by a scalar, broadcasting (usually) confers some time or space benefit, as the broadcasted tensor is never materialized. However, broadcast_to does not carry with it any such benefits. The newly-created tensor takes the full memory of the broadcasted shape. (In a graph context, broadcast_to might be fused to subsequent operation and then be optimized away, however.)
 


 Args
  input   A Tensor. A Tensor to broadcast.  
  shape   A Tensor. Must be one of the following types: int32, int64. An 1-D int Tensor. The shape of the desired output.  
  name   A name for the operation (optional).   
 


 Returns   A Tensor. Has the same type as input.
tf.case     View source on GitHub    Create a case operation. 
tf.case(
    pred_fn_pairs, default=None, exclusive=False, strict=False,
    name='case'
)
 See also tf.switch_case. The pred_fn_pairs parameter is a list of pairs of size N. Each pair contains a boolean scalar tensor and a python callable that creates the tensors to be returned if the boolean evaluates to True. default is a callable generating a list of tensors. All the callables in pred_fn_pairs as well as default (if provided) should return the same number and types of tensors. If exclusive==True, all predicates are evaluated, and an exception is thrown if more than one of the predicates evaluates to True. If exclusive==False, execution stops at the first predicate which evaluates to True, and the tensors generated by the corresponding function are returned immediately. If none of the predicates evaluate to True, this operation returns the tensors generated by default. tf.case supports nested structures as implemented in tf.contrib.framework.nest. All of the callables must return the same (possibly nested) value structure of lists, tuples, and/or named tuples. Singleton lists and tuples form the only exceptions to this: when returned by a callable, they are implicitly unpacked to single values. This behavior is disabled by passing strict=True. Example 1: Pseudocode: if (x < y) return 17;
else return 23;
 Expressions: f1 = lambda: tf.constant(17)
f2 = lambda: tf.constant(23)
r = tf.case([(tf.less(x, y), f1)], default=f2)
 Example 2: Pseudocode: if (x < y && x > z) raise OpError("Only one predicate may evaluate to True");
if (x < y) return 17;
else if (x > z) return 23;
else return -1;
 Expressions: def f1(): return tf.constant(17)
def f2(): return tf.constant(23)
def f3(): return tf.constant(-1)
r = tf.case([(tf.less(x, y), f1), (tf.greater(x, z), f2)],
         default=f3, exclusive=True)

 


 Args
  pred_fn_pairs   List of pairs of a boolean scalar tensor and a callable which returns a list of tensors.  
  default   Optional callable that returns a list of tensors.  
  exclusive   True iff at most one predicate is allowed to evaluate to True.  
  strict   A boolean that enables/disables 'strict' mode; see above.  
  name   A name for this operation (optional).   
 


 Returns   The tensors returned by the first pair whose predicate evaluated to True, or those returned by default if none does.  

 


 Raises
  TypeError   If pred_fn_pairs is not a list/tuple.  
  TypeError   If pred_fn_pairs is a list but does not contain 2-tuples.  
  TypeError   If fns[i] is not callable for any i, or default is not callable.    V2 Compatibility pred_fn_pairs could be a dictionary in v1. However, tf.Tensor and tf.Variable are no longer hashable in v2, so cannot be used as a key for a dictionary. Please use a list or a tuple instead.
tf.cast     View source on GitHub    Casts a tensor to a new type.  View aliases  Main aliases 
tf.dtypes.cast Compat aliases for migration See Migration guide for more details. tf.compat.v1.cast, tf.compat.v1.dtypes.cast  
tf.cast(
    x, dtype, name=None
)
 The operation casts x (in case of Tensor) or x.values (in case of SparseTensor or IndexedSlices) to dtype. For example: 
x = tf.constant([1.8, 2.2], dtype=tf.float32)
tf.dtypes.cast(x, tf.int32)
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([1, 2], dtype=int32)>
 The operation supports data types (for x and dtype) of uint8, uint16, uint32, uint64, int8, int16, int32, int64, float16, float32, float64, complex64, complex128, bfloat16. In case of casting from complex types (complex64, complex128) to real types, only the real part of x is returned. In case of casting from real types to complex types (complex64, complex128), the imaginary part of the returned value is set to 0. The handling of complex types here matches the behavior of numpy. Note casting nan and inf values to integral types has undefined behavior.
 


 Args
  x   A Tensor or SparseTensor or IndexedSlices of numeric type. It could be uint8, uint16, uint32, uint64, int8, int16, int32, int64, float16, float32, float64, complex64, complex128, bfloat16.  
  dtype   The destination type. The list of supported dtypes is the same as x.  
  name   A name for the operation (optional).   
 


 Returns   A Tensor or SparseTensor or IndexedSlices with same shape as x and same type as dtype.  

 


 Raises
  TypeError   If x cannot be cast to the dtype.
tf.clip_by_global_norm     View source on GitHub    Clips values of multiple tensors by the ratio of the sum of their norms.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.clip_by_global_norm  
tf.clip_by_global_norm(
    t_list, clip_norm, use_norm=None, name=None
)
 Given a tuple or list of tensors t_list, and a clipping ratio clip_norm, this operation returns a list of clipped tensors list_clipped and the global norm (global_norm) of all tensors in t_list. Optionally, if you've already computed the global norm for t_list, you can specify the global norm with use_norm. To perform the clipping, the values t_list[i] are set to: t_list[i] * clip_norm / max(global_norm, clip_norm)
 where: global_norm = sqrt(sum([l2norm(t)**2 for t in t_list]))
 If clip_norm > global_norm then the entries in t_list remain as they are, otherwise they're all shrunk by the global ratio. If global_norm == infinity then the entries in t_list are all set to NaN to signal that an error occurred. Any of the entries of t_list that are of type None are ignored. This is the correct way to perform gradient clipping (Pascanu et al., 2012). However, it is slower than clip_by_norm() because all the parameters must be ready before the clipping operation can be performed.
 


 Args
  t_list   A tuple or list of mixed Tensors, IndexedSlices, or None.  
  clip_norm   A 0-D (scalar) Tensor > 0. The clipping ratio.  
  use_norm   A 0-D (scalar) Tensor of type float (optional). The global norm to use. If not provided, global_norm() is used to compute the norm.  
  name   A name for the operation (optional).   
 


 Returns
  list_clipped   A list of Tensors of the same type as list_t.  
  global_norm   A 0-D (scalar) Tensor representing the global norm.   
 


 Raises
  TypeError   If t_list is not a sequence.    References: On the difficulty of training Recurrent Neural Networks: Pascanu et al., 2012 (pdf)
tf.clip_by_norm     View source on GitHub    Clips tensor values to a maximum L2-norm.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.clip_by_norm  
tf.clip_by_norm(
    t, clip_norm, axes=None, name=None
)
 Given a tensor t, and a maximum clip value clip_norm, this operation normalizes t so that its L2-norm is less than or equal to clip_norm, along the dimensions given in axes. Specifically, in the default case where all dimensions are used for calculation, if the L2-norm of t is already less than or equal to clip_norm, then t is not modified. If the L2-norm is greater than clip_norm, then this operation returns a tensor of the same type and shape as t with its values set to: t * clip_norm / l2norm(t) In this case, the L2-norm of the output tensor is clip_norm. As another example, if t is a matrix and axes == [1], then each row of the output will have L2-norm less than or equal to clip_norm. If axes == [0] instead, each column of the output will be clipped. Code example: 
some_nums = tf.constant([[1, 2, 3, 4, 5]], dtype=tf.float32)
tf.clip_by_norm(some_nums, 2.0).numpy()
array([[0.26967996, 0.5393599 , 0.80903983, 1.0787199 , 1.3483998 ]],
      dtype=float32)
 This operation is typically used to clip gradients before applying them with an optimizer. Most gradient data is a collection of different shaped tensors for different parts of the model. Thus, this is a common usage: # Get your gradients after training
loss_value, grads = grad(model, features, labels)

# Apply some clipping
grads = [tf.clip_by_norm(g, norm)
             for g in grads]

# Continue on with training
optimizer.apply_gradients(grads)

 


 Args
  t   A Tensor or IndexedSlices. This must be a floating point type.  
  clip_norm   A 0-D (scalar) Tensor > 0. A maximum clipping value, also floating point  
  axes   A 1-D (vector) Tensor of type int32 containing the dimensions to use for computing the L2-norm. If None (the default), uses all dimensions.  
  name   A name for the operation (optional).   
 


 Returns   A clipped Tensor or IndexedSlices.  

 


 Raises
  ValueError   If the clip_norm tensor is not a 0-D scalar tensor.  
  TypeError   If dtype of the input is not a floating point or complex type.
tf.clip_by_value     View source on GitHub    Clips tensor values to a specified min and max.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.clip_by_value  
tf.clip_by_value(
    t, clip_value_min, clip_value_max, name=None
)
 Given a tensor t, this operation returns a tensor of the same type and shape as t with its values clipped to clip_value_min and clip_value_max. Any values less than clip_value_min are set to clip_value_min. Any values greater than clip_value_max are set to clip_value_max. 
Note: clip_value_min needs to be smaller or equal to clip_value_max for correct results.
 For example: Basic usage passes a scalar as the min and max value. 
t = tf.constant([[-10., -1., 0.], [0., 2., 10.]])
t2 = tf.clip_by_value(t, clip_value_min=-1, clip_value_max=1)
t2.numpy()
array([[-1., -1.,  0.],
       [ 0.,  1.,  1.]], dtype=float32)
 The min and max can be the same size as t, or broadcastable to that size. 
t = tf.constant([[-1, 0., 10.], [-1, 0, 10]])
clip_min = [[2],[1]]
t3 = tf.clip_by_value(t, clip_value_min=clip_min, clip_value_max=100)
t3.numpy()
array([[ 2.,  2., 10.],
       [ 1.,  1., 10.]], dtype=float32)
 Broadcasting fails, intentionally, if you would expand the dimensions of t 
t = tf.constant([[-1, 0., 10.], [-1, 0, 10]])
clip_min = [[[2, 1]]] # Has a third axis
t4 = tf.clip_by_value(t, clip_value_min=clip_min, clip_value_max=100)
Traceback (most recent call last):

InvalidArgumentError: Incompatible shapes: [2,3] vs. [1,1,2]
 It throws a TypeError if you try to clip an int to a float value (tf.cast the input to float first). 
t = tf.constant([[1, 2], [3, 4]], dtype=tf.int32)
t5 = tf.clip_by_value(t, clip_value_min=-3.1, clip_value_max=3.1)
Traceback (most recent call last):

TypeError: Cannot convert ...

 


 Args
  t   A Tensor or IndexedSlices.  
  clip_value_min   The minimum value to clip to. A scalar Tensor or one that is broadcastable to the shape of t.  
  clip_value_max   The maximum value to clip to. A scalar Tensor or one that is broadcastable to the shape of t.  
  name   A name for the operation (optional).   
 


 Returns   A clipped Tensor or IndexedSlices.  

 


 Raises   tf.errors.InvalidArgumentError: If the clip tensors would trigger array broadcasting that would make the returned tensor larger than the input.     TypeError   If dtype of the input is int32 and dtype of the clip_value_min or clip_value_max is float32
Module: tf.compat Compatibility functions. The tf.compat module contains two sets of compatibility functions. Tensorflow 1.x and 2.x APIs The compat.v1 and compat.v2 submodules provide a complete copy of both the v1 and v2 APIs for backwards and forwards compatibility across TensorFlow versions 1.x and 2.x. See the migration guide for details. Utilities for writing compatible code Aside from the compat.v1 and compat.v2 submodules, tf.compat also contains a set of helper functions for writing code that works in both:  TensorFlow 1.x and 2.x Python 2 and 3  Type collections The compatibility module also provides the following aliases for common sets of python types:  bytes_or_text_types complex_types integral_types real_types  Modules v1 module: Bring in all of the public TensorFlow interface into this module. Functions as_bytes(...): Converts bytearray, bytes, or unicode python input types to bytes. as_str(...) as_str_any(...): Converts input to str type. as_text(...): Converts any string-like python input types to unicode. dimension_at_index(...): Compatibility utility required to allow for both V1 and V2 behavior in TF. dimension_value(...): Compatibility utility required to allow for both V1 and V2 behavior in TF. forward_compatibility_horizon(...): Context manager for testing forward compatibility of generated graphs. forward_compatible(...): Return true if the forward compatibility window has expired. path_to_str(...): Converts input which is a PathLike object to str type.
 


 Other Members
  bytes_or_text_types  
 
  complex_types  
 
  integral_types  
 
  real_types
tf.compat.as_bytes     View source on GitHub    Converts bytearray, bytes, or unicode python input types to bytes.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.compat.as_bytes  
tf.compat.as_bytes(
    bytes_or_text, encoding='utf-8'
)
 Uses utf-8 encoding for text by default.
 


 Args
  bytes_or_text   A bytearray, bytes, str, or unicode object.  
  encoding   A string indicating the charset for encoding unicode.   
 


 Returns   A bytes object.  

 


 Raises
  TypeError   If bytes_or_text is not a binary or unicode string.
tf.compat.as_str  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.compat.as_str  
tf.compat.as_str(
    bytes_or_text, encoding='utf-8'
)
tf.compat.as_str_any     View source on GitHub    Converts input to str type.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.compat.as_str_any  
tf.compat.as_str_any(
    value
)
 Uses str(value), except for bytes typed inputs, which are converted using as_str.
 


 Args
  value   A object that can be converted to str.   
 


 Returns   A str object.
tf.compat.as_text     View source on GitHub    Converts any string-like python input types to unicode.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.compat.as_text  
tf.compat.as_text(
    bytes_or_text, encoding='utf-8'
)
 Returns the input as a unicode string. Uses utf-8 encoding for text by default.
 


 Args
  bytes_or_text   A bytes, str, or unicode object.  
  encoding   A string indicating the charset for decoding unicode.   
 


 Returns   A unicode (Python 2) or str (Python 3) object.  

 


 Raises
  TypeError   If bytes_or_text is not a binary or unicode string.