neulab/docprompting-conala huggingface dataset:
tf.nn.weighted_cross_entropy_with_logits     View source on GitHub    Computes a weighted cross entropy. 
tf.nn.weighted_cross_entropy_with_logits(
    labels, logits, pos_weight, name=None
)
 This is like sigmoid_cross_entropy_with_logits() except that pos_weight, allows one to trade off recall and precision by up- or down-weighting the cost of a positive error relative to a negative error. The usual cross-entropy cost is defined as: labels * -log(sigmoid(logits)) +
    (1 - labels) * -log(1 - sigmoid(logits))
 A value pos_weight > 1 decreases the false negative count, hence increasing the recall. Conversely setting pos_weight < 1 decreases the false positive count and increases the precision. This can be seen from the fact that pos_weight is introduced as a multiplicative coefficient for the positive labels term in the loss expression: labels * -log(sigmoid(logits)) * pos_weight +
    (1 - labels) * -log(1 - sigmoid(logits))
 For brevity, let x = logits, z = labels, q = pos_weight. The loss is:   qz * -log(sigmoid(x)) + (1 - z) * -log(1 - sigmoid(x))
= qz * -log(1 / (1 + exp(-x))) + (1 - z) * -log(exp(-x) / (1 + exp(-x)))
= qz * log(1 + exp(-x)) + (1 - z) * (-log(exp(-x)) + log(1 + exp(-x)))
= qz * log(1 + exp(-x)) + (1 - z) * (x + log(1 + exp(-x))
= (1 - z) * x + (qz +  1 - z) * log(1 + exp(-x))
= (1 - z) * x + (1 + (q - 1) * z) * log(1 + exp(-x))
 Setting l = (1 + (q - 1) * z), to ensure stability and avoid overflow, the implementation uses (1 - z) * x + l * (log(1 + exp(-abs(x))) + max(-x, 0))
 logits and labels must have the same type and shape.
 


 Args
  labels   A Tensor of the same type and shape as logits.  
  logits   A Tensor of type float32 or float64.  
  pos_weight   A coefficient to use on the positive examples.  
  name   A name for the operation (optional).   
 


 Returns   A Tensor of the same shape as logits with the componentwise weighted logistic losses.  

 


 Raises
  ValueError   If logits and labels do not have the same shape.
tf.nn.weighted_moments     View source on GitHub    Returns the frequency-weighted mean and variance of x. 
tf.nn.weighted_moments(
    x, axes, frequency_weights, keepdims=False, name=None
)

 


 Args
  x   A tensor.  
  axes   1-d tensor of int32 values; these are the axes along which to compute mean and variance.  
  frequency_weights   A tensor of positive weights which can be broadcast with x.  
  keepdims   Produce moments with the same dimensionality as the input.  
  name   Name used to scope the operation.   
 


 Returns   Two tensors: weighted_mean and weighted_variance.
tf.nondifferentiable_batch_function     View source on GitHub    Batches the computation done by the decorated function.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.nondifferentiable_batch_function  
tf.nondifferentiable_batch_function(
    num_batch_threads, max_batch_size, batch_timeout_micros,
    allowed_batch_sizes=None, max_enqueued_batches=10, autograph=True,
    enable_large_batch_splitting=True
)
 So, for example, in the following code @batch_function(1, 2, 3)
def layer(a):
  return tf.matmul(a, a)

b = layer(w)
 if more than one session.run call is simultaneously trying to compute b the values of w will be gathered, non-deterministically concatenated along the first axis, and only one thread will run the computation. See the documentation of the Batch op for more details. Assumes that all arguments of the decorated function are Tensors which will be batched along their first dimension. SparseTensor is not supported. The return value of the decorated function must be a Tensor or a list/tuple of Tensors.
 


 Args
  num_batch_threads   Number of scheduling threads for processing batches of work. Determines the number of batches processed in parallel.  
  max_batch_size   Batch sizes will never be bigger than this.  
  batch_timeout_micros   Maximum number of microseconds to wait before outputting an incomplete batch.  
  allowed_batch_sizes   Optional list of allowed batch sizes. If left empty, does nothing. Otherwise, supplies a list of batch sizes, causing the op to pad batches up to one of those sizes. The entries must increase monotonically, and the final entry must equal max_batch_size.  
  max_enqueued_batches   The maximum depth of the batch queue. Defaults to 10.  
  autograph   Whether to use autograph to compile python and eager style code for efficient graph-mode execution.  
  enable_large_batch_splitting   The value of this option doesn't affect processing output given the same input; it affects implementation details as stated below: 1. Improve batching efficiency by eliminating unnecessary adding. 2.max_batch_size specifies the limit of input and allowed_batch_sizes specifies the limit of a task to be processed. API user can give an input of size 128 when 'max_execution_batch_size' is 32 -> implementation can split input of 128 into 4 x 32, schedule concurrent processing, and then return concatenated results corresponding to 128.   
 


 Returns   The decorated function will return the unbatched computation output Tensors.
tf.norm     View source on GitHub    Computes the norm of vectors, matrices, and tensors.  View aliases  Main aliases 
tf.linalg.norm  
tf.norm(
    tensor, ord='euclidean', axis=None, keepdims=None, name=None
)
 This function can compute several different vector norms (the 1-norm, the Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).
 


 Args
  tensor   Tensor of types float32, float64, complex64, complex128  
  ord   Order of the norm. Supported values are 'fro', 'euclidean', 1, 2, np.inf and any positive real number yielding the corresponding p-norm. Default is 'euclidean' which is equivalent to Frobenius norm if tensor is a matrix and equivalent to 2-norm for vectors. Some restrictions apply: a) The Frobenius norm 'fro' is not defined for vectors, b) If axis is a 2-tuple (matrix norm), only 'euclidean', 'fro', 1, 2, np.inf are supported. See the description of axis on how to compute norms for a batch of vectors or matrices stored in a tensor.  
  axis   If axis is None (the default), the input is considered a vector and a single vector norm is computed over the entire set of values in the tensor, i.e. norm(tensor, ord=ord) is equivalent to norm(reshape(tensor, [-1]), ord=ord). If axis is a Python integer, the input is considered a batch of vectors, and axis determines the axis in tensor over which to compute vector norms. If axis is a 2-tuple of Python integers it is considered a batch of matrices and axis determines the axes in tensor over which to compute a matrix norm. Negative indices are supported. Example: If you are passing a tensor that can be either a matrix or a batch of matrices at runtime, pass axis=[-2,-1] instead of axis=None to make sure that matrix norms are computed.  
  keepdims   If True, the axis indicated in axis are kept with size 1. Otherwise, the dimensions in axis are removed from the output shape.  
  name   The name of the op.   
 


 Returns
  output   A Tensor of the same type as tensor, containing the vector or matrix norms. If keepdims is True then the rank of output is equal to the rank of tensor. Otherwise, if axis is none the output is a scalar, if axis is an integer, the rank of output is one less than the rank of tensor, if axis is a 2-tuple the rank of output is two less than the rank of tensor.   
 


 Raises
  ValueError   If ord or axis is invalid.    Numpy Compatibility Mostly equivalent to numpy.linalg.norm. Not supported: ord <= 0, 2-norm for matrices, nuclear norm. Other differences: a) If axis is None, treats the flattened tensor as a vector regardless of rank. b) Explicitly supports 'euclidean' norm as the default, including for higher order tensors.
tf.no_gradient     View source on GitHub    Specifies that ops of type op_type is not differentiable.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.NoGradient, tf.compat.v1.NotDifferentiable, tf.compat.v1.no_gradient  
tf.no_gradient(
    op_type
)
 This function should not be used for operations that have a well-defined gradient that is not yet implemented. This function is only used when defining a new op type. It may be used for ops such as tf.size() that are not differentiable. For example: tf.no_gradient("Size")
 The gradient computed for 'op_type' will then propagate zeros. For ops that have a well-defined gradient but are not yet implemented, no declaration should be made, and an error must be thrown if an attempt to request its gradient is made.
 


 Args
  op_type   The string type of an operation. This corresponds to the OpDef.name field for the proto that defines the operation.   
 


 Raises
  TypeError   If op_type is not a string.
tf.no_op Does nothing. Only useful as a placeholder for control edges.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.no_op  
tf.no_op(
    name=None
)

 


 Args
  name   A name for the operation (optional).   
 


 Returns   The created Operation.
tf.numpy_function     View source on GitHub    Wraps a python function and uses it as a TensorFlow op.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.numpy_function  
tf.numpy_function(
    func, inp, Tout, name=None
)
 Given a python function func wrap this function as an operation in a TensorFlow function. func must take numpy arrays as its arguments and return numpy arrays as its outputs. The following example creates a TensorFlow graph with np.sinh() as an operation in the graph: 
def my_numpy_func(x):
  # x will be a numpy array with the contents of the input to the
  # tf.function
  return np.sinh(x)
@tf.function(input_signature=[tf.TensorSpec(None, tf.float32)])
def tf_function(input):
  y = tf.numpy_function(my_numpy_func, [input], tf.float32)
  return y * y
tf_function(tf.constant(1.))
<tf.Tensor: shape=(), dtype=float32, numpy=1.3810978>
 Comparison to tf.py_function: tf.py_function and tf.numpy_function are very similar, except that tf.numpy_function takes numpy arrays, and not tf.Tensors. If you want the function to contain tf.Tensors, and have any TensorFlow operations executed in the function be differentiable, please use tf.py_function. 
Note: The tf.numpy_function operation has the following known limitations:
  The body of the function (i.e. func) will not be serialized in a tf.SavedModel. Therefore, you should not use this function if you need to serialize your model and restore it in a different environment. The operation must run in the same address space as the Python program that calls tf.numpy_function(). If you are using distributed TensorFlow, you must run a tf.distribute.Server in the same process as the program that calls tf.numpy_function you must pin the created operation to a device in that server (e.g. using with tf.device():). Since the function takes numpy arrays, you cannot take gradients through a numpy_function. If you require something that is differentiable, please consider using tf.py_function. The resulting function is assumed stateful and will never be optimized. 
 


 Args
  func   A Python function, which accepts numpy.ndarray objects as arguments and returns a list of numpy.ndarray objects (or a single numpy.ndarray). This function must accept as many arguments as there are tensors in inp, and these argument types will match the corresponding tf.Tensor objects in inp. The returns numpy.ndarrays must match the number and types defined Tout. Important Note: Input and output numpy.ndarrays of func are not guaranteed to be copies. In some cases their underlying memory will be shared with the corresponding TensorFlow tensors. In-place modification or storing func input or return values in python datastructures without explicit (np.)copy can have non-deterministic consequences.  
  inp   A list of tf.Tensor objects.  
  Tout   A list or tuple of tensorflow data types or a single tensorflow data type if there is only one, indicating what func returns.  
  name   (Optional) A name for the operation.   
 


 Returns   Single or list of tf.Tensor which func computes.
tf.ones     View source on GitHub    Creates a tensor with all elements set to one (1).  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.ones  
tf.ones(
    shape, dtype=tf.dtypes.float32, name=None
)
 See also tf.ones_like, tf.zeros, tf.fill, tf.eye. This operation returns a tensor of type dtype with shape shape and all elements set to one. 
tf.ones([3, 4], tf.int32)
<tf.Tensor: shape=(3, 4), dtype=int32, numpy=
array([[1, 1, 1, 1],
       [1, 1, 1, 1],
       [1, 1, 1, 1]], dtype=int32)>

 


 Args
  shape   A list of integers, a tuple of integers, or a 1-D Tensor of type int32.  
  dtype   Optional DType of an element in the resulting Tensor. Default is tf.float32.  
  name   Optional string. A name for the operation.   
 


 Returns   A Tensor with all elements set to one (1).
tf.ones_initializer Initializer that generates tensors initialized to 1. Initializers allow you to pre-specify an initialization strategy, encoded in the Initializer object, without knowing the shape and dtype of the variable being initialized. Examples: 
def make_variables(k, initializer):
  return (tf.Variable(initializer(shape=[k], dtype=tf.float32)),
          tf.Variable(initializer(shape=[k, k], dtype=tf.float32)))
v1, v2 = make_variables(3, tf.ones_initializer())
v1
<tf.Variable ... shape=(3,) ... numpy=array([1., 1., 1.], dtype=float32)>
v2
<tf.Variable ... shape=(3, 3) ... numpy=
array([[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]], dtype=float32)>
make_variables(4, tf.random_uniform_initializer(minval=-1., maxval=1.))
(<tf.Variable...shape=(4,) dtype=float32...>, <tf.Variable...shape=(4, 4) ...
 Methods from_config View source 
@classmethod
from_config(
    config
)
 Instantiates an initializer from a configuration dictionary. Example: initializer = RandomUniform(-1, 1)
config = initializer.get_config()
initializer = RandomUniform.from_config(config)

 


 Args
  config   A Python dictionary. It will typically be the output of get_config.   
 


 Returns   An Initializer instance.  
 get_config View source 
get_config()
 Returns the configuration of the initializer as a JSON-serializable dict.
 


 Returns   A JSON-serializable Python dict.  
 __call__ View source 
__call__(
    shape, dtype=tf.dtypes.float32, **kwargs
)
 Returns a tensor object initialized as specified by the initializer.
 


 Args
  shape   Shape of the tensor.  
  dtype   Optional dtype of the tensor. Only numeric or boolean dtypes are supported.  
  **kwargs   Additional keyword arguments.   
 


 Raises
  ValuesError   If the dtype is not numeric or boolean.
tf.ones_like     View source on GitHub    Creates a tensor of all ones that has the same shape as the input. 
tf.ones_like(
    input, dtype=None, name=None
)
 See also tf.ones. Given a single tensor (tensor), this operation returns a tensor of the same type and shape as tensor with all elements set to 1. Optionally, you can use dtype to specify a new type for the returned tensor. For example: 
tensor = tf.constant([[1, 2, 3], [4, 5, 6]])
tf.ones_like(tensor)
<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
  array([[1, 1, 1],
         [1, 1, 1]], dtype=int32)>

 


 Args
  input   A Tensor.  
  dtype   A type for the returned Tensor. Must be float16, float32, float64, int8, uint8, int16, uint16, int32, int64, complex64, complex128, bool or string.  
  name   A name for the operation (optional).   
 


 Returns   A Tensor with all elements set to one.
tf.OptionalSpec     View source on GitHub    Type specification for tf.experimental.Optional. Inherits From: TypeSpec  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.OptionalSpec, tf.compat.v1.data.experimental.OptionalStructure  
tf.OptionalSpec(
    element_spec
)
 For instance, tf.OptionalSpec can be used to define a tf.function that takes tf.experimental.Optional as an input argument: 
@tf.function(input_signature=[tf.OptionalSpec(
  tf.TensorSpec(shape=(), dtype=tf.int32, name=None))])
def maybe_square(optional):
  if optional.has_value():
    x = optional.get_value()
    return x * x
  return -1
optional = tf.experimental.Optional.from_value(5)
print(maybe_square(optional))
tf.Tensor(25, shape=(), dtype=int32)

 


 Attributes
  element_spec   A nested structure of TypeSpec objects that represents the type specification of the optional element.  
  value_type   The Python type for values that are compatible with this TypeSpec. In particular, all values that are compatible with this TypeSpec must be an instance of this type. 
   Methods from_value View source 
@staticmethod
from_value(
    value
)
 is_compatible_with View source 
is_compatible_with(
    spec_or_value
)
 Returns true if spec_or_value is compatible with this TypeSpec. most_specific_compatible_type View source 
most_specific_compatible_type(
    other
)
 Returns the most specific TypeSpec compatible with self and other.
 


 Args
  other   A TypeSpec.   
 


 Raises
  ValueError   If there is no TypeSpec that is compatible with both self and other.    __eq__ View source 
__eq__(
    other
)
 Return self==value. __ne__ View source 
__ne__(
    other
)
 Return self!=value.
tf.pad     View source on GitHub    Pads a tensor. 
tf.pad(
    tensor, paddings, mode='CONSTANT', constant_values=0, name=None
)
 This operation pads a tensor according to the paddings you specify. paddings is an integer tensor with shape [n, 2], where n is the rank of tensor. For each dimension D of input, paddings[D, 0] indicates how many values to add before the contents of tensor in that dimension, and paddings[D, 1] indicates how many values to add after the contents of tensor in that dimension. If mode is "REFLECT" then both paddings[D, 0] and paddings[D, 1] must be no greater than tensor.dim_size(D) - 1. If mode is "SYMMETRIC" then both paddings[D, 0] and paddings[D, 1] must be no greater than tensor.dim_size(D). The padded size of each dimension D of the output is: paddings[D, 0] + tensor.dim_size(D) + paddings[D, 1] For example: t = tf.constant([[1, 2, 3], [4, 5, 6]])
paddings = tf.constant([[1, 1,], [2, 2]])
# 'constant_values' is 0.
# rank of 't' is 2.
tf.pad(t, paddings, "CONSTANT")  # [[0, 0, 0, 0, 0, 0, 0],
                                 #  [0, 0, 1, 2, 3, 0, 0],
                                 #  [0, 0, 4, 5, 6, 0, 0],
                                 #  [0, 0, 0, 0, 0, 0, 0]]

tf.pad(t, paddings, "REFLECT")  # [[6, 5, 4, 5, 6, 5, 4],
                                #  [3, 2, 1, 2, 3, 2, 1],
                                #  [6, 5, 4, 5, 6, 5, 4],
                                #  [3, 2, 1, 2, 3, 2, 1]]

tf.pad(t, paddings, "SYMMETRIC")  # [[2, 1, 1, 2, 3, 3, 2],
                                  #  [2, 1, 1, 2, 3, 3, 2],
                                  #  [5, 4, 4, 5, 6, 6, 5],
                                  #  [5, 4, 4, 5, 6, 6, 5]]

 


 Args
  tensor   A Tensor.  
  paddings   A Tensor of type int32.  
  mode   One of "CONSTANT", "REFLECT", or "SYMMETRIC" (case-insensitive)  
  constant_values   In "CONSTANT" mode, the scalar pad value to use. Must be same type as tensor.  
  name   A name for the operation (optional).   
 


 Returns   A Tensor. Has the same type as tensor.  

 


 Raises
  ValueError   When mode is not one of "CONSTANT", "REFLECT", or "SYMMETRIC".
tf.parallel_stack     View source on GitHub    Stacks a list of rank-R tensors into one rank-(R+1) tensor in parallel.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.parallel_stack  
tf.parallel_stack(
    values, name='parallel_stack'
)
 Requires that the shape of inputs be known at graph construction time. Packs the list of tensors in values into a tensor with rank one higher than each tensor in values, by packing them along the first dimension. Given a list of length N of tensors of shape (A, B, C); the output tensor will have the shape (N, A, B, C). For example: x = tf.constant([1, 4])
y = tf.constant([2, 5])
z = tf.constant([3, 6])
tf.parallel_stack([x, y, z])  # [[1, 4], [2, 5], [3, 6]]
 The difference between stack and parallel_stack is that stack requires all the inputs be computed before the operation will begin but doesn't require that the input shapes be known during graph construction. parallel_stack will copy pieces of the input into the output as they become available, in some situations this can provide a performance benefit. Unlike stack, parallel_stack does NOT support backpropagation. This is the opposite of unstack. The numpy equivalent is tf.parallel_stack([x, y, z]) = np.asarray([x, y, z])

 


 Args
  values   A list of Tensor objects with the same shape and type.  
  name   A name for this operation (optional).   
 


 Returns
  output   A stacked Tensor with the same type as values.
Module: tf.profiler Public API for tf.profiler namespace. Modules experimental module: Public API for tf.profiler.experimental namespace.
Module: tf.profiler.experimental Public API for tf.profiler.experimental namespace. Modules client module: Public API for tf.profiler.experimental.client namespace. server module: Public API for tf.profiler.experimental.server namespace. Classes class Profile: Context-manager profile API. class ProfilerOptions: Options for finer control over the profiler. class Trace: Context manager that generates a trace event in the profiler. Functions start(...): Start profiling TensorFlow performance. stop(...): Stops the current profiling session.
Module: tf.profiler.experimental.client Public API for tf.profiler.experimental.client namespace. Functions monitor(...): Sends grpc requests to profiler server to perform on-demand monitoring. trace(...): Sends gRPC requests to one or more profiler servers to perform on-demand profiling.
tf.profiler.experimental.client.monitor Sends grpc requests to profiler server to perform on-demand monitoring. 
tf.profiler.experimental.client.monitor(
    service_addr, duration_ms, level=1
)
 The monitoring result is a light weight performance summary of your model execution. This method will block the caller thread until it receives the monitoring result. This method currently supports Cloud TPU only.
 


 Args
  service_addr   gRPC address of profiler service e.g. grpc://10.0.0.2:8466.  
  duration_ms   Duration of monitoring in ms.  
  level   Choose a monitoring level between 1 and 2 to monitor your job. Level 2 is more verbose than level 1 and shows more metrics.   
 


 Returns   A string of monitoring output.  
 Example usage: # Continuously send gRPC requests to the Cloud TPU to monitor the model
# execution.

for query in range(0, 100):
  print(
    tf.profiler.experimental.client.monitor('grpc://10.0.0.2:8466', 1000))
tf.profiler.experimental.Profile Context-manager profile API. 
tf.profiler.experimental.Profile(
    logdir, options=None
)
 Profiling will start when entering the scope, and stop and save the results to the logdir when exits the scope. Open TensorBoard profile tab to view results. Example usage: with tf.profiler.experimental.Profile("/path/to/logdir"):
  # do some work

 


 Args
  logdir   profile data will save to this directory.  
  options   An optional tf.profiler.ProfilerOptions can be provided to fine tune the profiler's behavior.    Methods __enter__ View source 
__enter__()
 __exit__ View source 
__exit__(
    typ, value, tb
)