repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
inverse_exp_decay
def inverse_exp_decay(max_step, min_value=0.01, step=None): """Inverse-decay exponentially from 0.01 to 1.0 reached at max_step.""" inv_base = tf.exp(tf.log(min_value) / float(max_step)) if step is None: step = tf.train.get_global_step() if step is None: return 1.0 step = to_float(step) return inv_b...
python
def inverse_exp_decay(max_step, min_value=0.01, step=None): """Inverse-decay exponentially from 0.01 to 1.0 reached at max_step.""" inv_base = tf.exp(tf.log(min_value) / float(max_step)) if step is None: step = tf.train.get_global_step() if step is None: return 1.0 step = to_float(step) return inv_b...
[ "def", "inverse_exp_decay", "(", "max_step", ",", "min_value", "=", "0.01", ",", "step", "=", "None", ")", ":", "inv_base", "=", "tf", ".", "exp", "(", "tf", ".", "log", "(", "min_value", ")", "/", "float", "(", "max_step", ")", ")", "if", "step", ...
Inverse-decay exponentially from 0.01 to 1.0 reached at max_step.
[ "Inverse", "-", "decay", "exponentially", "from", "0", ".", "01", "to", "1", ".", "0", "reached", "at", "max_step", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L155-L163
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
inverse_lin_decay
def inverse_lin_decay(max_step, min_value=0.01, step=None): """Inverse-decay linearly from 0.01 to 1.0 reached at max_step.""" if step is None: step = tf.train.get_global_step() if step is None: return 1.0 step = to_float(step) progress = tf.minimum(step / float(max_step), 1.0) return progress * (1....
python
def inverse_lin_decay(max_step, min_value=0.01, step=None): """Inverse-decay linearly from 0.01 to 1.0 reached at max_step.""" if step is None: step = tf.train.get_global_step() if step is None: return 1.0 step = to_float(step) progress = tf.minimum(step / float(max_step), 1.0) return progress * (1....
[ "def", "inverse_lin_decay", "(", "max_step", ",", "min_value", "=", "0.01", ",", "step", "=", "None", ")", ":", "if", "step", "is", "None", ":", "step", "=", "tf", ".", "train", ".", "get_global_step", "(", ")", "if", "step", "is", "None", ":", "retu...
Inverse-decay linearly from 0.01 to 1.0 reached at max_step.
[ "Inverse", "-", "decay", "linearly", "from", "0", ".", "01", "to", "1", ".", "0", "reached", "at", "max_step", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L166-L174
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
shakeshake2_py
def shakeshake2_py(x, y, equal=False, individual=False): """The shake-shake sum of 2 tensors, python version.""" if equal: alpha = 0.5 elif individual: alpha = tf.random_uniform(tf.get_shape(x)[:1]) else: alpha = tf.random_uniform([]) return alpha * x + (1.0 - alpha) * y
python
def shakeshake2_py(x, y, equal=False, individual=False): """The shake-shake sum of 2 tensors, python version.""" if equal: alpha = 0.5 elif individual: alpha = tf.random_uniform(tf.get_shape(x)[:1]) else: alpha = tf.random_uniform([]) return alpha * x + (1.0 - alpha) * y
[ "def", "shakeshake2_py", "(", "x", ",", "y", ",", "equal", "=", "False", ",", "individual", "=", "False", ")", ":", "if", "equal", ":", "alpha", "=", "0.5", "elif", "individual", ":", "alpha", "=", "tf", ".", "random_uniform", "(", "tf", ".", "get_sh...
The shake-shake sum of 2 tensors, python version.
[ "The", "shake", "-", "shake", "sum", "of", "2", "tensors", "python", "version", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L177-L186
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
shakeshake2_grad
def shakeshake2_grad(x1, x2, dy): """Overriding gradient for shake-shake of 2 tensors.""" y = shakeshake2_py(x1, x2) dx = tf.gradients(ys=[y], xs=[x1, x2], grad_ys=[dy]) return dx
python
def shakeshake2_grad(x1, x2, dy): """Overriding gradient for shake-shake of 2 tensors.""" y = shakeshake2_py(x1, x2) dx = tf.gradients(ys=[y], xs=[x1, x2], grad_ys=[dy]) return dx
[ "def", "shakeshake2_grad", "(", "x1", ",", "x2", ",", "dy", ")", ":", "y", "=", "shakeshake2_py", "(", "x1", ",", "x2", ")", "dx", "=", "tf", ".", "gradients", "(", "ys", "=", "[", "y", "]", ",", "xs", "=", "[", "x1", ",", "x2", "]", ",", "...
Overriding gradient for shake-shake of 2 tensors.
[ "Overriding", "gradient", "for", "shake", "-", "shake", "of", "2", "tensors", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L190-L194
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
shakeshake2_indiv_grad
def shakeshake2_indiv_grad(x1, x2, dy): """Overriding gradient for shake-shake of 2 tensors.""" y = shakeshake2_py(x1, x2, individual=True) dx = tf.gradients(ys=[y], xs=[x1, x2], grad_ys=[dy]) return dx
python
def shakeshake2_indiv_grad(x1, x2, dy): """Overriding gradient for shake-shake of 2 tensors.""" y = shakeshake2_py(x1, x2, individual=True) dx = tf.gradients(ys=[y], xs=[x1, x2], grad_ys=[dy]) return dx
[ "def", "shakeshake2_indiv_grad", "(", "x1", ",", "x2", ",", "dy", ")", ":", "y", "=", "shakeshake2_py", "(", "x1", ",", "x2", ",", "individual", "=", "True", ")", "dx", "=", "tf", ".", "gradients", "(", "ys", "=", "[", "y", "]", ",", "xs", "=", ...
Overriding gradient for shake-shake of 2 tensors.
[ "Overriding", "gradient", "for", "shake", "-", "shake", "of", "2", "tensors", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L198-L202
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
shakeshake2_equal_grad
def shakeshake2_equal_grad(x1, x2, dy): """Overriding gradient for shake-shake of 2 tensors.""" y = shakeshake2_py(x1, x2, equal=True) dx = tf.gradients(ys=[y], xs=[x1, x2], grad_ys=[dy]) return dx
python
def shakeshake2_equal_grad(x1, x2, dy): """Overriding gradient for shake-shake of 2 tensors.""" y = shakeshake2_py(x1, x2, equal=True) dx = tf.gradients(ys=[y], xs=[x1, x2], grad_ys=[dy]) return dx
[ "def", "shakeshake2_equal_grad", "(", "x1", ",", "x2", ",", "dy", ")", ":", "y", "=", "shakeshake2_py", "(", "x1", ",", "x2", ",", "equal", "=", "True", ")", "dx", "=", "tf", ".", "gradients", "(", "ys", "=", "[", "y", "]", ",", "xs", "=", "[",...
Overriding gradient for shake-shake of 2 tensors.
[ "Overriding", "gradient", "for", "shake", "-", "shake", "of", "2", "tensors", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L206-L210
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
shakeshake
def shakeshake(xs, equal_grad=False): """Multi-argument shake-shake, currently approximated by sums of 2.""" if len(xs) == 1: return xs[0] div = (len(xs) + 1) // 2 arg1 = shakeshake(xs[:div], equal_grad=equal_grad) arg2 = shakeshake(xs[div:], equal_grad=equal_grad) if equal_grad: return shakeshake2_...
python
def shakeshake(xs, equal_grad=False): """Multi-argument shake-shake, currently approximated by sums of 2.""" if len(xs) == 1: return xs[0] div = (len(xs) + 1) // 2 arg1 = shakeshake(xs[:div], equal_grad=equal_grad) arg2 = shakeshake(xs[div:], equal_grad=equal_grad) if equal_grad: return shakeshake2_...
[ "def", "shakeshake", "(", "xs", ",", "equal_grad", "=", "False", ")", ":", "if", "len", "(", "xs", ")", "==", "1", ":", "return", "xs", "[", "0", "]", "div", "=", "(", "len", "(", "xs", ")", "+", "1", ")", "//", "2", "arg1", "=", "shakeshake"...
Multi-argument shake-shake, currently approximated by sums of 2.
[ "Multi", "-", "argument", "shake", "-", "shake", "currently", "approximated", "by", "sums", "of", "2", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L230-L239
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
convert_rgb_to_real
def convert_rgb_to_real(x): """Conversion of pixel values to real numbers.""" with tf.name_scope("rgb_to_real", values=[x]): x = to_float(x) x /= 255.0 return x
python
def convert_rgb_to_real(x): """Conversion of pixel values to real numbers.""" with tf.name_scope("rgb_to_real", values=[x]): x = to_float(x) x /= 255.0 return x
[ "def", "convert_rgb_to_real", "(", "x", ")", ":", "with", "tf", ".", "name_scope", "(", "\"rgb_to_real\"", ",", "values", "=", "[", "x", "]", ")", ":", "x", "=", "to_float", "(", "x", ")", "x", "/=", "255.0", "return", "x" ]
Conversion of pixel values to real numbers.
[ "Conversion", "of", "pixel", "values", "to", "real", "numbers", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L242-L247
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
convert_rgb_to_symmetric_real
def convert_rgb_to_symmetric_real(x): """Conversion of pixel values to real numbers.""" with tf.name_scope("rgb_to_real", values=[x]): x = to_float(x) # Convert each pixel intensity in [0, 1, 2, ..., 255] into a real number in # the range [-1, 1]. x = (x / 127.5) - 1 return x
python
def convert_rgb_to_symmetric_real(x): """Conversion of pixel values to real numbers.""" with tf.name_scope("rgb_to_real", values=[x]): x = to_float(x) # Convert each pixel intensity in [0, 1, 2, ..., 255] into a real number in # the range [-1, 1]. x = (x / 127.5) - 1 return x
[ "def", "convert_rgb_to_symmetric_real", "(", "x", ")", ":", "with", "tf", ".", "name_scope", "(", "\"rgb_to_real\"", ",", "values", "=", "[", "x", "]", ")", ":", "x", "=", "to_float", "(", "x", ")", "# Convert each pixel intensity in [0, 1, 2, ..., 255] into a rea...
Conversion of pixel values to real numbers.
[ "Conversion", "of", "pixel", "values", "to", "real", "numbers", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L250-L257
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
expand_squeeze_to_nd
def expand_squeeze_to_nd(x, n, squeeze_dim=2, expand_dim=-1): """Make x n-d with squeeze and expand_dims.""" if len(x.shape) > n: while len(x.shape) != n: x = tf.squeeze(x, [squeeze_dim]) else: while len(x.shape) != n: x = tf.expand_dims(x, expand_dim) return x
python
def expand_squeeze_to_nd(x, n, squeeze_dim=2, expand_dim=-1): """Make x n-d with squeeze and expand_dims.""" if len(x.shape) > n: while len(x.shape) != n: x = tf.squeeze(x, [squeeze_dim]) else: while len(x.shape) != n: x = tf.expand_dims(x, expand_dim) return x
[ "def", "expand_squeeze_to_nd", "(", "x", ",", "n", ",", "squeeze_dim", "=", "2", ",", "expand_dim", "=", "-", "1", ")", ":", "if", "len", "(", "x", ".", "shape", ")", ">", "n", ":", "while", "len", "(", "x", ".", "shape", ")", "!=", "n", ":", ...
Make x n-d with squeeze and expand_dims.
[ "Make", "x", "n", "-", "d", "with", "squeeze", "and", "expand_dims", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L267-L275
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
standardize_images
def standardize_images(x): """Image standardization on batches and videos.""" with tf.name_scope("standardize_images", values=[x]): x_shape = shape_list(x) x = to_float(tf.reshape(x, [-1] + x_shape[-3:])) x_mean = tf.reduce_mean(x, axis=[1, 2], keepdims=True) x_variance = tf.reduce_mean( tf....
python
def standardize_images(x): """Image standardization on batches and videos.""" with tf.name_scope("standardize_images", values=[x]): x_shape = shape_list(x) x = to_float(tf.reshape(x, [-1] + x_shape[-3:])) x_mean = tf.reduce_mean(x, axis=[1, 2], keepdims=True) x_variance = tf.reduce_mean( tf....
[ "def", "standardize_images", "(", "x", ")", ":", "with", "tf", ".", "name_scope", "(", "\"standardize_images\"", ",", "values", "=", "[", "x", "]", ")", ":", "x_shape", "=", "shape_list", "(", "x", ")", "x", "=", "to_float", "(", "tf", ".", "reshape", ...
Image standardization on batches and videos.
[ "Image", "standardization", "on", "batches", "and", "videos", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L278-L288
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
flatten4d3d
def flatten4d3d(x): """Flatten a 4d-tensor into a 3d-tensor by joining width and height.""" xshape = shape_list(x) result = tf.reshape(x, [xshape[0], xshape[1] * xshape[2], xshape[3]]) return result
python
def flatten4d3d(x): """Flatten a 4d-tensor into a 3d-tensor by joining width and height.""" xshape = shape_list(x) result = tf.reshape(x, [xshape[0], xshape[1] * xshape[2], xshape[3]]) return result
[ "def", "flatten4d3d", "(", "x", ")", ":", "xshape", "=", "shape_list", "(", "x", ")", "result", "=", "tf", ".", "reshape", "(", "x", ",", "[", "xshape", "[", "0", "]", ",", "xshape", "[", "1", "]", "*", "xshape", "[", "2", "]", ",", "xshape", ...
Flatten a 4d-tensor into a 3d-tensor by joining width and height.
[ "Flatten", "a", "4d", "-", "tensor", "into", "a", "3d", "-", "tensor", "by", "joining", "width", "and", "height", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L291-L295
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
gather
def gather(params, indices, dtype=tf.float32): """Version of tf.gather that works faster on tpu.""" if not is_xla_compiled(): return tf.gather(params, indices) vocab_size = params.get_shape().as_list()[0] indices_flat = tf.reshape(indices, [-1]) out = tf.matmul(tf.one_hot(indices_flat, vocab_size, dtype=d...
python
def gather(params, indices, dtype=tf.float32): """Version of tf.gather that works faster on tpu.""" if not is_xla_compiled(): return tf.gather(params, indices) vocab_size = params.get_shape().as_list()[0] indices_flat = tf.reshape(indices, [-1]) out = tf.matmul(tf.one_hot(indices_flat, vocab_size, dtype=d...
[ "def", "gather", "(", "params", ",", "indices", ",", "dtype", "=", "tf", ".", "float32", ")", ":", "if", "not", "is_xla_compiled", "(", ")", ":", "return", "tf", ".", "gather", "(", "params", ",", "indices", ")", "vocab_size", "=", "params", ".", "ge...
Version of tf.gather that works faster on tpu.
[ "Version", "of", "tf", ".", "gather", "that", "works", "faster", "on", "tpu", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L299-L307
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
cumsum
def cumsum(x, axis=0, exclusive=False): """TPU hack for tf.cumsum. This is equivalent to tf.cumsum and is faster on TPU as of 04/2018 unless the axis dimension is very large. Args: x: a Tensor axis: an integer exclusive: a boolean Returns: Tensor of the same shape as x. """ if not is_xl...
python
def cumsum(x, axis=0, exclusive=False): """TPU hack for tf.cumsum. This is equivalent to tf.cumsum and is faster on TPU as of 04/2018 unless the axis dimension is very large. Args: x: a Tensor axis: an integer exclusive: a boolean Returns: Tensor of the same shape as x. """ if not is_xl...
[ "def", "cumsum", "(", "x", ",", "axis", "=", "0", ",", "exclusive", "=", "False", ")", ":", "if", "not", "is_xla_compiled", "(", ")", ":", "return", "tf", ".", "cumsum", "(", "x", ",", "axis", "=", "axis", ",", "exclusive", "=", "exclusive", ")", ...
TPU hack for tf.cumsum. This is equivalent to tf.cumsum and is faster on TPU as of 04/2018 unless the axis dimension is very large. Args: x: a Tensor axis: an integer exclusive: a boolean Returns: Tensor of the same shape as x.
[ "TPU", "hack", "for", "tf", ".", "cumsum", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L311-L340
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
dropout_no_scaling
def dropout_no_scaling(x, keep_prob): """Like tf.nn.dropout, but does not scale up. Works on integers also. Args: x: a Tensor keep_prob: a floating point number Returns: Tensor of the same shape as x. """ if keep_prob == 1.0: return x mask = tf.less(tf.random_uniform(tf.shape(x)), keep_pr...
python
def dropout_no_scaling(x, keep_prob): """Like tf.nn.dropout, but does not scale up. Works on integers also. Args: x: a Tensor keep_prob: a floating point number Returns: Tensor of the same shape as x. """ if keep_prob == 1.0: return x mask = tf.less(tf.random_uniform(tf.shape(x)), keep_pr...
[ "def", "dropout_no_scaling", "(", "x", ",", "keep_prob", ")", ":", "if", "keep_prob", "==", "1.0", ":", "return", "x", "mask", "=", "tf", ".", "less", "(", "tf", ".", "random_uniform", "(", "tf", ".", "shape", "(", "x", ")", ")", ",", "keep_prob", ...
Like tf.nn.dropout, but does not scale up. Works on integers also. Args: x: a Tensor keep_prob: a floating point number Returns: Tensor of the same shape as x.
[ "Like", "tf", ".", "nn", ".", "dropout", "but", "does", "not", "scale", "up", ".", "Works", "on", "integers", "also", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L343-L356
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
embedding
def embedding(x, vocab_size, dense_size, name=None, reuse=None, multiplier=1.0, symbol_dropout_rate=0.0, embedding_var=None, dtype=tf.float32): """Embed x of type int64 into dense vectors, reducing to max 4...
python
def embedding(x, vocab_size, dense_size, name=None, reuse=None, multiplier=1.0, symbol_dropout_rate=0.0, embedding_var=None, dtype=tf.float32): """Embed x of type int64 into dense vectors, reducing to max 4...
[ "def", "embedding", "(", "x", ",", "vocab_size", ",", "dense_size", ",", "name", "=", "None", ",", "reuse", "=", "None", ",", "multiplier", "=", "1.0", ",", "symbol_dropout_rate", "=", "0.0", ",", "embedding_var", "=", "None", ",", "dtype", "=", "tf", ...
Embed x of type int64 into dense vectors, reducing to max 4 dimensions.
[ "Embed", "x", "of", "type", "int64", "into", "dense", "vectors", "reducing", "to", "max", "4", "dimensions", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L359-L387
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
shift_right
def shift_right(x, pad_value=None): """Shift the second dimension of x right by one.""" if pad_value is None: shifted_targets = tf.pad(x, [[0, 0], [1, 0], [0, 0], [0, 0]])[:, :-1, :, :] else: shifted_targets = tf.concat([pad_value, x], axis=1)[:, :-1, :, :] return shifted_targets
python
def shift_right(x, pad_value=None): """Shift the second dimension of x right by one.""" if pad_value is None: shifted_targets = tf.pad(x, [[0, 0], [1, 0], [0, 0], [0, 0]])[:, :-1, :, :] else: shifted_targets = tf.concat([pad_value, x], axis=1)[:, :-1, :, :] return shifted_targets
[ "def", "shift_right", "(", "x", ",", "pad_value", "=", "None", ")", ":", "if", "pad_value", "is", "None", ":", "shifted_targets", "=", "tf", ".", "pad", "(", "x", ",", "[", "[", "0", ",", "0", "]", ",", "[", "1", ",", "0", "]", ",", "[", "0",...
Shift the second dimension of x right by one.
[ "Shift", "the", "second", "dimension", "of", "x", "right", "by", "one", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L390-L396
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
shift_right_3d
def shift_right_3d(x, pad_value=None): """Shift the second dimension of x right by one.""" if pad_value is None: shifted_targets = tf.pad(x, [[0, 0], [1, 0], [0, 0]])[:, :-1, :] else: shifted_targets = tf.concat([pad_value, x], axis=1)[:, :-1, :] return shifted_targets
python
def shift_right_3d(x, pad_value=None): """Shift the second dimension of x right by one.""" if pad_value is None: shifted_targets = tf.pad(x, [[0, 0], [1, 0], [0, 0]])[:, :-1, :] else: shifted_targets = tf.concat([pad_value, x], axis=1)[:, :-1, :] return shifted_targets
[ "def", "shift_right_3d", "(", "x", ",", "pad_value", "=", "None", ")", ":", "if", "pad_value", "is", "None", ":", "shifted_targets", "=", "tf", ".", "pad", "(", "x", ",", "[", "[", "0", ",", "0", "]", ",", "[", "1", ",", "0", "]", ",", "[", "...
Shift the second dimension of x right by one.
[ "Shift", "the", "second", "dimension", "of", "x", "right", "by", "one", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L399-L405
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
shift_right_2d
def shift_right_2d(x, pad_value=None): """Shift the second dimension of x right by one.""" if pad_value is None: shifted_targets = tf.pad(x, [[0, 0], [1, 0]])[:, :-1] else: shifted_targets = tf.concat([pad_value, x], axis=1)[:, :-1] return shifted_targets
python
def shift_right_2d(x, pad_value=None): """Shift the second dimension of x right by one.""" if pad_value is None: shifted_targets = tf.pad(x, [[0, 0], [1, 0]])[:, :-1] else: shifted_targets = tf.concat([pad_value, x], axis=1)[:, :-1] return shifted_targets
[ "def", "shift_right_2d", "(", "x", ",", "pad_value", "=", "None", ")", ":", "if", "pad_value", "is", "None", ":", "shifted_targets", "=", "tf", ".", "pad", "(", "x", ",", "[", "[", "0", ",", "0", "]", ",", "[", "1", ",", "0", "]", "]", ")", "...
Shift the second dimension of x right by one.
[ "Shift", "the", "second", "dimension", "of", "x", "right", "by", "one", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L408-L414
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_stride2_multistep
def conv_stride2_multistep(x, nbr_steps, output_filters, name=None, reuse=None): """Use a strided convolution to downsample x by 2, `nbr_steps` times. We use stride and filter size 2 to avoid the checkerboard problem of deconvs. As detailed in http://distill.pub/2016/deconv-checkerboard/. Args: x: a `Tens...
python
def conv_stride2_multistep(x, nbr_steps, output_filters, name=None, reuse=None): """Use a strided convolution to downsample x by 2, `nbr_steps` times. We use stride and filter size 2 to avoid the checkerboard problem of deconvs. As detailed in http://distill.pub/2016/deconv-checkerboard/. Args: x: a `Tens...
[ "def", "conv_stride2_multistep", "(", "x", ",", "nbr_steps", ",", "output_filters", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "with", "tf", ".", "variable_scope", "(", "name", ",", "default_name", "=", "\"conv_stride2_multistep\"", ",", ...
Use a strided convolution to downsample x by 2, `nbr_steps` times. We use stride and filter size 2 to avoid the checkerboard problem of deconvs. As detailed in http://distill.pub/2016/deconv-checkerboard/. Args: x: a `Tensor` with shape `[batch, spatial, depth]` or `[batch, spatial_1, spatial_2, depth]...
[ "Use", "a", "strided", "convolution", "to", "downsample", "x", "by", "2", "nbr_steps", "times", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L417-L450
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
deconv_stride2_multistep
def deconv_stride2_multistep(x, nbr_steps, output_filters, name=None, reuse=None): """Use a deconvolution to upsample x by 2**`nbr_steps`. Args: x: a `Tensor` with shape `[batch, spatial, depth]`...
python
def deconv_stride2_multistep(x, nbr_steps, output_filters, name=None, reuse=None): """Use a deconvolution to upsample x by 2**`nbr_steps`. Args: x: a `Tensor` with shape `[batch, spatial, depth]`...
[ "def", "deconv_stride2_multistep", "(", "x", ",", "nbr_steps", ",", "output_filters", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "with", "tf", ".", "variable_scope", "(", "name", ",", "default_name", "=", "\"deconv_stride2_multistep\"", ","...
Use a deconvolution to upsample x by 2**`nbr_steps`. Args: x: a `Tensor` with shape `[batch, spatial, depth]` or `[batch, spatial_1, spatial_2, depth]` nbr_steps: an int specifying the number of doubling upsample rounds to apply. output_filters: an int specifying the filter count for the deconv...
[ "Use", "a", "deconvolution", "to", "upsample", "x", "by", "2", "**", "nbr_steps", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L453-L513
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_internal
def conv_internal(conv_fn, inputs, filters, kernel_size, **kwargs): """Conditional conv_fn making kernel 1d or 2d depending on inputs shape.""" static_shape = inputs.get_shape() if not static_shape or len(static_shape) != 4: raise ValueError("Inputs to conv must have statically known rank 4. " ...
python
def conv_internal(conv_fn, inputs, filters, kernel_size, **kwargs): """Conditional conv_fn making kernel 1d or 2d depending on inputs shape.""" static_shape = inputs.get_shape() if not static_shape or len(static_shape) != 4: raise ValueError("Inputs to conv must have statically known rank 4. " ...
[ "def", "conv_internal", "(", "conv_fn", ",", "inputs", ",", "filters", ",", "kernel_size", ",", "*", "*", "kwargs", ")", ":", "static_shape", "=", "inputs", ".", "get_shape", "(", ")", "if", "not", "static_shape", "or", "len", "(", "static_shape", ")", "...
Conditional conv_fn making kernel 1d or 2d depending on inputs shape.
[ "Conditional", "conv_fn", "making", "kernel", "1d", "or", "2d", "depending", "on", "inputs", "shape", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L516-L551
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
subseparable_conv
def subseparable_conv(inputs, filters, kernel_size, **kwargs): """Sub-separable convolution. If separability == 0 it's a separable_conv.""" def conv_fn(inputs, filters, kernel_size, **kwargs): """Sub-separable convolution, splits into separability-many blocks.""" separability = None if "separability" i...
python
def subseparable_conv(inputs, filters, kernel_size, **kwargs): """Sub-separable convolution. If separability == 0 it's a separable_conv.""" def conv_fn(inputs, filters, kernel_size, **kwargs): """Sub-separable convolution, splits into separability-many blocks.""" separability = None if "separability" i...
[ "def", "subseparable_conv", "(", "inputs", ",", "filters", ",", "kernel_size", ",", "*", "*", "kwargs", ")", ":", "def", "conv_fn", "(", "inputs", ",", "filters", ",", "kernel_size", ",", "*", "*", "kwargs", ")", ":", "\"\"\"Sub-separable convolution, splits i...
Sub-separable convolution. If separability == 0 it's a separable_conv.
[ "Sub", "-", "separable", "convolution", ".", "If", "separability", "==", "0", "it", "s", "a", "separable_conv", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L579-L614
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
tpu_conv1d
def tpu_conv1d(inputs, filters, kernel_size, padding="SAME", name="tpu_conv1d"): """Version of conv1d that works on TPU (as of 11/2017). Args: inputs: a Tensor with shape [batch, length, input_depth]. filters: an integer. kernel_size: an integer. padding: a string - "SAME" or "LEFT". name: a st...
python
def tpu_conv1d(inputs, filters, kernel_size, padding="SAME", name="tpu_conv1d"): """Version of conv1d that works on TPU (as of 11/2017). Args: inputs: a Tensor with shape [batch, length, input_depth]. filters: an integer. kernel_size: an integer. padding: a string - "SAME" or "LEFT". name: a st...
[ "def", "tpu_conv1d", "(", "inputs", ",", "filters", ",", "kernel_size", ",", "padding", "=", "\"SAME\"", ",", "name", "=", "\"tpu_conv1d\"", ")", ":", "if", "kernel_size", "==", "1", ":", "return", "dense", "(", "inputs", ",", "filters", ",", "name", "="...
Version of conv1d that works on TPU (as of 11/2017). Args: inputs: a Tensor with shape [batch, length, input_depth]. filters: an integer. kernel_size: an integer. padding: a string - "SAME" or "LEFT". name: a string. Returns: a Tensor with shape [batch, length, filters].
[ "Version", "of", "conv1d", "that", "works", "on", "TPU", "(", "as", "of", "11", "/", "2017", ")", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L617-L648
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
layer_norm_vars
def layer_norm_vars(filters): """Create Variables for layer norm.""" scale = tf.get_variable( "layer_norm_scale", [filters], initializer=tf.ones_initializer()) bias = tf.get_variable( "layer_norm_bias", [filters], initializer=tf.zeros_initializer()) return scale, bias
python
def layer_norm_vars(filters): """Create Variables for layer norm.""" scale = tf.get_variable( "layer_norm_scale", [filters], initializer=tf.ones_initializer()) bias = tf.get_variable( "layer_norm_bias", [filters], initializer=tf.zeros_initializer()) return scale, bias
[ "def", "layer_norm_vars", "(", "filters", ")", ":", "scale", "=", "tf", ".", "get_variable", "(", "\"layer_norm_scale\"", ",", "[", "filters", "]", ",", "initializer", "=", "tf", ".", "ones_initializer", "(", ")", ")", "bias", "=", "tf", ".", "get_variable...
Create Variables for layer norm.
[ "Create", "Variables", "for", "layer", "norm", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L651-L657
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
layer_norm_compute
def layer_norm_compute(x, epsilon, scale, bias, layer_collection=None): """Layer norm raw computation.""" # Save these before they get converted to tensors by the casting below params = (scale, bias) epsilon, scale, bias = [cast_like(t, x) for t in [epsilon, scale, bias]] mean = tf.reduce_mean(x, axis=[-1],...
python
def layer_norm_compute(x, epsilon, scale, bias, layer_collection=None): """Layer norm raw computation.""" # Save these before they get converted to tensors by the casting below params = (scale, bias) epsilon, scale, bias = [cast_like(t, x) for t in [epsilon, scale, bias]] mean = tf.reduce_mean(x, axis=[-1],...
[ "def", "layer_norm_compute", "(", "x", ",", "epsilon", ",", "scale", ",", "bias", ",", "layer_collection", "=", "None", ")", ":", "# Save these before they get converted to tensors by the casting below", "params", "=", "(", "scale", ",", "bias", ")", "epsilon", ",",...
Layer norm raw computation.
[ "Layer", "norm", "raw", "computation", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L660-L675
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
layer_norm
def layer_norm(x, filters=None, epsilon=1e-6, name=None, reuse=None, layer_collection=None): """Layer normalize the tensor x, averaging over the last dimension.""" if filters is None: filters = shape_list(x)[-1] with tf.variable_scope(...
python
def layer_norm(x, filters=None, epsilon=1e-6, name=None, reuse=None, layer_collection=None): """Layer normalize the tensor x, averaging over the last dimension.""" if filters is None: filters = shape_list(x)[-1] with tf.variable_scope(...
[ "def", "layer_norm", "(", "x", ",", "filters", "=", "None", ",", "epsilon", "=", "1e-6", ",", "name", "=", "None", ",", "reuse", "=", "None", ",", "layer_collection", "=", "None", ")", ":", "if", "filters", "is", "None", ":", "filters", "=", "shape_l...
Layer normalize the tensor x, averaging over the last dimension.
[ "Layer", "normalize", "the", "tensor", "x", "averaging", "over", "the", "last", "dimension", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L678-L691
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
group_norm
def group_norm(x, filters=None, num_groups=8, epsilon=1e-5): """Group normalization as in https://arxiv.org/abs/1803.08494.""" x_shape = shape_list(x) if filters is None: filters = x_shape[-1] assert len(x_shape) == 4 assert filters % num_groups == 0 # Prepare variables. scale = tf.get_variable( ...
python
def group_norm(x, filters=None, num_groups=8, epsilon=1e-5): """Group normalization as in https://arxiv.org/abs/1803.08494.""" x_shape = shape_list(x) if filters is None: filters = x_shape[-1] assert len(x_shape) == 4 assert filters % num_groups == 0 # Prepare variables. scale = tf.get_variable( ...
[ "def", "group_norm", "(", "x", ",", "filters", "=", "None", ",", "num_groups", "=", "8", ",", "epsilon", "=", "1e-5", ")", ":", "x_shape", "=", "shape_list", "(", "x", ")", "if", "filters", "is", "None", ":", "filters", "=", "x_shape", "[", "-", "1...
Group normalization as in https://arxiv.org/abs/1803.08494.
[ "Group", "normalization", "as", "in", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1803", ".", "08494", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L694-L712
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
noam_norm
def noam_norm(x, epsilon=1.0, name=None): """One version of layer normalization.""" with tf.name_scope(name, default_name="noam_norm", values=[x]): shape = x.get_shape() ndims = len(shape) return (tf.nn.l2_normalize(x, ndims - 1, epsilon=epsilon) * tf.sqrt( to_float(shape[-1])))
python
def noam_norm(x, epsilon=1.0, name=None): """One version of layer normalization.""" with tf.name_scope(name, default_name="noam_norm", values=[x]): shape = x.get_shape() ndims = len(shape) return (tf.nn.l2_normalize(x, ndims - 1, epsilon=epsilon) * tf.sqrt( to_float(shape[-1])))
[ "def", "noam_norm", "(", "x", ",", "epsilon", "=", "1.0", ",", "name", "=", "None", ")", ":", "with", "tf", ".", "name_scope", "(", "name", ",", "default_name", "=", "\"noam_norm\"", ",", "values", "=", "[", "x", "]", ")", ":", "shape", "=", "x", ...
One version of layer normalization.
[ "One", "version", "of", "layer", "normalization", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L715-L721
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
l2_norm
def l2_norm(x, filters=None, epsilon=1e-6, name=None, reuse=None): """Layer normalization with l2 norm.""" if filters is None: filters = shape_list(x)[-1] with tf.variable_scope(name, default_name="l2_norm", values=[x], reuse=reuse): scale = tf.get_variable( "l2_norm_scale", [filters], initializer...
python
def l2_norm(x, filters=None, epsilon=1e-6, name=None, reuse=None): """Layer normalization with l2 norm.""" if filters is None: filters = shape_list(x)[-1] with tf.variable_scope(name, default_name="l2_norm", values=[x], reuse=reuse): scale = tf.get_variable( "l2_norm_scale", [filters], initializer...
[ "def", "l2_norm", "(", "x", ",", "filters", "=", "None", ",", "epsilon", "=", "1e-6", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "if", "filters", "is", "None", ":", "filters", "=", "shape_list", "(", "x", ")", "[", "-", "1", ...
Layer normalization with l2 norm.
[ "Layer", "normalization", "with", "l2", "norm", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L724-L738
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
apply_spectral_norm
def apply_spectral_norm(x): """Normalizes x using the spectral norm. The implementation follows Algorithm 1 of https://arxiv.org/abs/1802.05957. If x is not a 2-D Tensor, then it is reshaped such that the number of channels (last-dimension) is the same. Args: x: Tensor with the last dimension equal to t...
python
def apply_spectral_norm(x): """Normalizes x using the spectral norm. The implementation follows Algorithm 1 of https://arxiv.org/abs/1802.05957. If x is not a 2-D Tensor, then it is reshaped such that the number of channels (last-dimension) is the same. Args: x: Tensor with the last dimension equal to t...
[ "def", "apply_spectral_norm", "(", "x", ")", ":", "weights_shape", "=", "shape_list", "(", "x", ")", "other", ",", "num_filters", "=", "tf", ".", "reduce_prod", "(", "weights_shape", "[", ":", "-", "1", "]", ")", ",", "weights_shape", "[", "-", "1", "]...
Normalizes x using the spectral norm. The implementation follows Algorithm 1 of https://arxiv.org/abs/1802.05957. If x is not a 2-D Tensor, then it is reshaped such that the number of channels (last-dimension) is the same. Args: x: Tensor with the last dimension equal to the number of filters. Returns:...
[ "Normalizes", "x", "using", "the", "spectral", "norm", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L741-L778
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
apply_norm
def apply_norm(x, norm_type, depth, epsilon, layer_collection=None): """Apply Normalization.""" if layer_collection is not None: assert norm_type == "layer" if norm_type == "layer": return layer_norm( x, filters=depth, epsilon=epsilon, layer_collection=layer_collection) if norm_type == "group": ...
python
def apply_norm(x, norm_type, depth, epsilon, layer_collection=None): """Apply Normalization.""" if layer_collection is not None: assert norm_type == "layer" if norm_type == "layer": return layer_norm( x, filters=depth, epsilon=epsilon, layer_collection=layer_collection) if norm_type == "group": ...
[ "def", "apply_norm", "(", "x", ",", "norm_type", ",", "depth", ",", "epsilon", ",", "layer_collection", "=", "None", ")", ":", "if", "layer_collection", "is", "not", "None", ":", "assert", "norm_type", "==", "\"layer\"", "if", "norm_type", "==", "\"layer\"",...
Apply Normalization.
[ "Apply", "Normalization", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L781-L799
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
zero_add
def zero_add(previous_value, x, name=None, reuse=None): """Resnet connection with zero initialization. Another type of resnet connection which returns previous_value + gamma * x. gamma is a trainable scalar and initialized with zero. It is useful when a module is plugged into a trained model and we want to mak...
python
def zero_add(previous_value, x, name=None, reuse=None): """Resnet connection with zero initialization. Another type of resnet connection which returns previous_value + gamma * x. gamma is a trainable scalar and initialized with zero. It is useful when a module is plugged into a trained model and we want to mak...
[ "def", "zero_add", "(", "previous_value", ",", "x", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "with", "tf", ".", "variable_scope", "(", "name", ",", "default_name", "=", "\"zero_add\"", ",", "reuse", "=", "reuse", ")", ":", "gamma"...
Resnet connection with zero initialization. Another type of resnet connection which returns previous_value + gamma * x. gamma is a trainable scalar and initialized with zero. It is useful when a module is plugged into a trained model and we want to make sure it matches the original model's performance. Args...
[ "Resnet", "connection", "with", "zero", "initialization", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L802-L821
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
layer_prepostprocess
def layer_prepostprocess(previous_value, x, sequence, dropout_rate, norm_type, depth, epsilon, default_name, name=None, ...
python
def layer_prepostprocess(previous_value, x, sequence, dropout_rate, norm_type, depth, epsilon, default_name, name=None, ...
[ "def", "layer_prepostprocess", "(", "previous_value", ",", "x", ",", "sequence", ",", "dropout_rate", ",", "norm_type", ",", "depth", ",", "epsilon", ",", "default_name", ",", "name", "=", "None", ",", "dropout_broadcast_dims", "=", "None", ",", "layer_collectio...
Apply a sequence of functions to the input or output of a layer. The sequence is specified as a string which may contain the following characters: a: add previous_value n: apply normalization d: apply dropout z: zero add For example, if sequence=="dna", then the output is previous_value + no...
[ "Apply", "a", "sequence", "of", "functions", "to", "the", "input", "or", "output", "of", "a", "layer", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L824-L881
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
layer_preprocess
def layer_preprocess(layer_input, hparams, layer_collection=None): """Apply layer preprocessing. See layer_prepostprocess() for details. A hyperparameters object is passed for convenience. The hyperparameters that may be used are: layer_preprocess_sequence layer_prepostprocess_dropout norm_type ...
python
def layer_preprocess(layer_input, hparams, layer_collection=None): """Apply layer preprocessing. See layer_prepostprocess() for details. A hyperparameters object is passed for convenience. The hyperparameters that may be used are: layer_preprocess_sequence layer_prepostprocess_dropout norm_type ...
[ "def", "layer_preprocess", "(", "layer_input", ",", "hparams", ",", "layer_collection", "=", "None", ")", ":", "assert", "\"a\"", "not", "in", "hparams", ".", "layer_preprocess_sequence", ",", "(", "\"No residual connections allowed in hparams.layer_preprocess_sequence\"", ...
Apply layer preprocessing. See layer_prepostprocess() for details. A hyperparameters object is passed for convenience. The hyperparameters that may be used are: layer_preprocess_sequence layer_prepostprocess_dropout norm_type hidden_size norm_epsilon Args: layer_input: a Tensor ...
[ "Apply", "layer", "preprocessing", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L884-L922
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
layer_postprocess
def layer_postprocess(layer_input, layer_output, hparams): """Apply layer postprocessing. See layer_prepostprocess() for details. A hyperparameters object is passed for convenience. The hyperparameters that may be used are: layer_postprocess_sequence layer_prepostprocess_dropout norm_type hi...
python
def layer_postprocess(layer_input, layer_output, hparams): """Apply layer postprocessing. See layer_prepostprocess() for details. A hyperparameters object is passed for convenience. The hyperparameters that may be used are: layer_postprocess_sequence layer_prepostprocess_dropout norm_type hi...
[ "def", "layer_postprocess", "(", "layer_input", ",", "layer_output", ",", "hparams", ")", ":", "return", "layer_prepostprocess", "(", "layer_input", ",", "layer_output", ",", "sequence", "=", "hparams", ".", "layer_postprocess_sequence", ",", "dropout_rate", "=", "h...
Apply layer postprocessing. See layer_prepostprocess() for details. A hyperparameters object is passed for convenience. The hyperparameters that may be used are: layer_postprocess_sequence layer_prepostprocess_dropout norm_type hidden_size norm_epsilon Args: layer_input: a Tensor ...
[ "Apply", "layer", "postprocessing", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L925-L957
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_block_internal
def conv_block_internal(conv_fn, inputs, filters, dilation_rates_and_kernel_sizes, first_relu=True, use_elu=False, separabilities=None, **kwargs): """...
python
def conv_block_internal(conv_fn, inputs, filters, dilation_rates_and_kernel_sizes, first_relu=True, use_elu=False, separabilities=None, **kwargs): """...
[ "def", "conv_block_internal", "(", "conv_fn", ",", "inputs", ",", "filters", ",", "dilation_rates_and_kernel_sizes", ",", "first_relu", "=", "True", ",", "use_elu", "=", "False", ",", "separabilities", "=", "None", ",", "*", "*", "kwargs", ")", ":", "name", ...
A block of convolutions. Args: conv_fn: convolution function, e.g. conv or separable_conv. inputs: a Tensor filters: an Integer dilation_rates_and_kernel_sizes: a list of tuples (dilation, (k_w, k_h)) first_relu: whether to do a relu at start (defaults to True) use_elu: whether to use ELUs in...
[ "A", "block", "of", "convolutions", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L960-L1028
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_block
def conv_block(inputs, filters, dilation_rates_and_kernel_sizes, **kwargs): """A block of standard 2d convolutions.""" return conv_block_internal(conv, inputs, filters, dilation_rates_and_kernel_sizes, **kwargs)
python
def conv_block(inputs, filters, dilation_rates_and_kernel_sizes, **kwargs): """A block of standard 2d convolutions.""" return conv_block_internal(conv, inputs, filters, dilation_rates_and_kernel_sizes, **kwargs)
[ "def", "conv_block", "(", "inputs", ",", "filters", ",", "dilation_rates_and_kernel_sizes", ",", "*", "*", "kwargs", ")", ":", "return", "conv_block_internal", "(", "conv", ",", "inputs", ",", "filters", ",", "dilation_rates_and_kernel_sizes", ",", "*", "*", "kw...
A block of standard 2d convolutions.
[ "A", "block", "of", "standard", "2d", "convolutions", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1031-L1034
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv1d_block
def conv1d_block(inputs, filters, dilation_rates_and_kernel_sizes, **kwargs): """A block of standard 1d convolutions.""" return conv_block_internal(conv1d, inputs, filters, dilation_rates_and_kernel_sizes, **kwargs)
python
def conv1d_block(inputs, filters, dilation_rates_and_kernel_sizes, **kwargs): """A block of standard 1d convolutions.""" return conv_block_internal(conv1d, inputs, filters, dilation_rates_and_kernel_sizes, **kwargs)
[ "def", "conv1d_block", "(", "inputs", ",", "filters", ",", "dilation_rates_and_kernel_sizes", ",", "*", "*", "kwargs", ")", ":", "return", "conv_block_internal", "(", "conv1d", ",", "inputs", ",", "filters", ",", "dilation_rates_and_kernel_sizes", ",", "*", "*", ...
A block of standard 1d convolutions.
[ "A", "block", "of", "standard", "1d", "convolutions", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1037-L1040
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
separable_conv_block
def separable_conv_block(inputs, filters, dilation_rates_and_kernel_sizes, **kwargs): """A block of separable convolutions.""" return conv_block_internal(separable_conv, inputs, filters, dilation_rates_and_kernel_sizes, **kwargs)
python
def separable_conv_block(inputs, filters, dilation_rates_and_kernel_sizes, **kwargs): """A block of separable convolutions.""" return conv_block_internal(separable_conv, inputs, filters, dilation_rates_and_kernel_sizes, **kwargs)
[ "def", "separable_conv_block", "(", "inputs", ",", "filters", ",", "dilation_rates_and_kernel_sizes", ",", "*", "*", "kwargs", ")", ":", "return", "conv_block_internal", "(", "separable_conv", ",", "inputs", ",", "filters", ",", "dilation_rates_and_kernel_sizes", ",",...
A block of separable convolutions.
[ "A", "block", "of", "separable", "convolutions", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1043-L1047
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
subseparable_conv_block
def subseparable_conv_block(inputs, filters, dilation_rates_and_kernel_sizes, **kwargs): """A block of separable convolutions.""" return conv_block_internal(subseparable_conv, inputs, filters, dilation_rates_and_kernel_sizes, **kwargs)
python
def subseparable_conv_block(inputs, filters, dilation_rates_and_kernel_sizes, **kwargs): """A block of separable convolutions.""" return conv_block_internal(subseparable_conv, inputs, filters, dilation_rates_and_kernel_sizes, **kwargs)
[ "def", "subseparable_conv_block", "(", "inputs", ",", "filters", ",", "dilation_rates_and_kernel_sizes", ",", "*", "*", "kwargs", ")", ":", "return", "conv_block_internal", "(", "subseparable_conv", ",", "inputs", ",", "filters", ",", "dilation_rates_and_kernel_sizes", ...
A block of separable convolutions.
[ "A", "block", "of", "separable", "convolutions", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1050-L1054
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
pool
def pool(inputs, window_size, pooling_type, padding, strides=(1, 1)): """Pooling (supports "LEFT").""" with tf.name_scope("pool", values=[inputs]): static_shape = inputs.get_shape() if not static_shape or len(static_shape) != 4: raise ValueError("Inputs to conv must have statically known rank 4.") ...
python
def pool(inputs, window_size, pooling_type, padding, strides=(1, 1)): """Pooling (supports "LEFT").""" with tf.name_scope("pool", values=[inputs]): static_shape = inputs.get_shape() if not static_shape or len(static_shape) != 4: raise ValueError("Inputs to conv must have statically known rank 4.") ...
[ "def", "pool", "(", "inputs", ",", "window_size", ",", "pooling_type", ",", "padding", ",", "strides", "=", "(", "1", ",", "1", ")", ")", ":", "with", "tf", ".", "name_scope", "(", "\"pool\"", ",", "values", "=", "[", "inputs", "]", ")", ":", "stat...
Pooling (supports "LEFT").
[ "Pooling", "(", "supports", "LEFT", ")", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1057-L1080
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_block_downsample
def conv_block_downsample(x, kernel, strides, padding, separability=0, name=None, reuse=None): """Implements a downwards-striding conv block, like Xception exit f...
python
def conv_block_downsample(x, kernel, strides, padding, separability=0, name=None, reuse=None): """Implements a downwards-striding conv block, like Xception exit f...
[ "def", "conv_block_downsample", "(", "x", ",", "kernel", ",", "strides", ",", "padding", ",", "separability", "=", "0", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "with", "tf", ".", "variable_scope", "(", "name", ",", "default_name", ...
Implements a downwards-striding conv block, like Xception exit flow.
[ "Implements", "a", "downwards", "-", "striding", "conv", "block", "like", "Xception", "exit", "flow", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1083-L1130
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
get_timing_signal
def get_timing_signal(length, min_timescale=1, max_timescale=1e4, num_timescales=16): """Create Tensor of sinusoids of different frequencies. Args: length: Length of the Tensor to create, i.e. Number of steps. min_timescale: a float max_...
python
def get_timing_signal(length, min_timescale=1, max_timescale=1e4, num_timescales=16): """Create Tensor of sinusoids of different frequencies. Args: length: Length of the Tensor to create, i.e. Number of steps. min_timescale: a float max_...
[ "def", "get_timing_signal", "(", "length", ",", "min_timescale", "=", "1", ",", "max_timescale", "=", "1e4", ",", "num_timescales", "=", "16", ")", ":", "positions", "=", "to_float", "(", "tf", ".", "range", "(", "length", ")", ")", "log_timescale_increment"...
Create Tensor of sinusoids of different frequencies. Args: length: Length of the Tensor to create, i.e. Number of steps. min_timescale: a float max_timescale: a float num_timescales: an int Returns: Tensor of shape (length, 2*num_timescales)
[ "Create", "Tensor", "of", "sinusoids", "of", "different", "frequencies", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1133-L1154
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
add_timing_signal
def add_timing_signal(x, min_timescale=1, max_timescale=1e4, num_timescales=16): """Adds a bunch of sinusoids of different frequencies to a Tensor. This allows attention to learn to use absolute and relative positions. The timing signal should be added to some precursor of both the source and the target of the...
python
def add_timing_signal(x, min_timescale=1, max_timescale=1e4, num_timescales=16): """Adds a bunch of sinusoids of different frequencies to a Tensor. This allows attention to learn to use absolute and relative positions. The timing signal should be added to some precursor of both the source and the target of the...
[ "def", "add_timing_signal", "(", "x", ",", "min_timescale", "=", "1", ",", "max_timescale", "=", "1e4", ",", "num_timescales", "=", "16", ")", ":", "length", "=", "shape_list", "(", "x", ")", "[", "1", "]", "depth", "=", "shape_list", "(", "x", ")", ...
Adds a bunch of sinusoids of different frequencies to a Tensor. This allows attention to learn to use absolute and relative positions. The timing signal should be added to some precursor of both the source and the target of the attention. The use of relative position is possible because sin(x+y) and cos(x+y) ...
[ "Adds", "a", "bunch", "of", "sinusoids", "of", "different", "frequencies", "to", "a", "Tensor", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1157-L1188
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
mask_from_embedding
def mask_from_embedding(emb): """Input embeddings -> padding mask. We have hacked symbol_modality to return all-zero embeddings for padding. Returns a mask with 0.0 in the padding positions and 1.0 elsewhere. Args: emb: a Tensor with shape [batch, width, height, depth]. Returns: a 0.0/1.0 Tensor wit...
python
def mask_from_embedding(emb): """Input embeddings -> padding mask. We have hacked symbol_modality to return all-zero embeddings for padding. Returns a mask with 0.0 in the padding positions and 1.0 elsewhere. Args: emb: a Tensor with shape [batch, width, height, depth]. Returns: a 0.0/1.0 Tensor wit...
[ "def", "mask_from_embedding", "(", "emb", ")", ":", "return", "weights_nonzero", "(", "tf", ".", "reduce_sum", "(", "tf", ".", "abs", "(", "emb", ")", ",", "axis", "=", "3", ",", "keepdims", "=", "True", ")", ")" ]
Input embeddings -> padding mask. We have hacked symbol_modality to return all-zero embeddings for padding. Returns a mask with 0.0 in the padding positions and 1.0 elsewhere. Args: emb: a Tensor with shape [batch, width, height, depth]. Returns: a 0.0/1.0 Tensor with shape [batch, width, height, 1].
[ "Input", "embeddings", "-", ">", "padding", "mask", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1191-L1202
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
length_from_embedding
def length_from_embedding(emb): """Compute the length of each sequence in the batch. Args: emb: a sequence embedding Tensor with shape [batch, max_time, 1, depth]. Returns: a Tensor with shape [batch]. """ return tf.cast(tf.reduce_sum(mask_from_embedding(emb), [1, 2, 3]), tf.int32)
python
def length_from_embedding(emb): """Compute the length of each sequence in the batch. Args: emb: a sequence embedding Tensor with shape [batch, max_time, 1, depth]. Returns: a Tensor with shape [batch]. """ return tf.cast(tf.reduce_sum(mask_from_embedding(emb), [1, 2, 3]), tf.int32)
[ "def", "length_from_embedding", "(", "emb", ")", ":", "return", "tf", ".", "cast", "(", "tf", ".", "reduce_sum", "(", "mask_from_embedding", "(", "emb", ")", ",", "[", "1", ",", "2", ",", "3", "]", ")", ",", "tf", ".", "int32", ")" ]
Compute the length of each sequence in the batch. Args: emb: a sequence embedding Tensor with shape [batch, max_time, 1, depth]. Returns: a Tensor with shape [batch].
[ "Compute", "the", "length", "of", "each", "sequence", "in", "the", "batch", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1205-L1213
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
relu_density_logit
def relu_density_logit(x, reduce_dims): """logit(density(x)). Useful for histograms. Args: x: a Tensor, typically the output of tf.relu reduce_dims: a list of dimensions Returns: a Tensor """ frac = tf.reduce_mean(to_float(x > 0.0), reduce_dims) scaled = tf.log(frac + math.exp(-10)) - tf.lo...
python
def relu_density_logit(x, reduce_dims): """logit(density(x)). Useful for histograms. Args: x: a Tensor, typically the output of tf.relu reduce_dims: a list of dimensions Returns: a Tensor """ frac = tf.reduce_mean(to_float(x > 0.0), reduce_dims) scaled = tf.log(frac + math.exp(-10)) - tf.lo...
[ "def", "relu_density_logit", "(", "x", ",", "reduce_dims", ")", ":", "frac", "=", "tf", ".", "reduce_mean", "(", "to_float", "(", "x", ">", "0.0", ")", ",", "reduce_dims", ")", "scaled", "=", "tf", ".", "log", "(", "frac", "+", "math", ".", "exp", ...
logit(density(x)). Useful for histograms. Args: x: a Tensor, typically the output of tf.relu reduce_dims: a list of dimensions Returns: a Tensor
[ "logit", "(", "density", "(", "x", "))", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1233-L1247
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
maybe_zero_out_padding
def maybe_zero_out_padding(inputs, kernel_size, nonpadding_mask): """If necessary, zero out inputs to a conv for padding positions. Args: inputs: a Tensor with shape [batch, length, ...] kernel_size: an integer or pair of integers nonpadding_mask: a Tensor with shape [batch, length] Returns: Ten...
python
def maybe_zero_out_padding(inputs, kernel_size, nonpadding_mask): """If necessary, zero out inputs to a conv for padding positions. Args: inputs: a Tensor with shape [batch, length, ...] kernel_size: an integer or pair of integers nonpadding_mask: a Tensor with shape [batch, length] Returns: Ten...
[ "def", "maybe_zero_out_padding", "(", "inputs", ",", "kernel_size", ",", "nonpadding_mask", ")", ":", "if", "(", "kernel_size", "!=", "1", "and", "kernel_size", "!=", "(", "1", ",", "1", ")", "and", "nonpadding_mask", "is", "not", "None", ")", ":", "while"...
If necessary, zero out inputs to a conv for padding positions. Args: inputs: a Tensor with shape [batch, length, ...] kernel_size: an integer or pair of integers nonpadding_mask: a Tensor with shape [batch, length] Returns: Tensor of the same shape as inputs.
[ "If", "necessary", "zero", "out", "inputs", "to", "a", "conv", "for", "padding", "positions", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1250-L1267
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
dense_relu_dense
def dense_relu_dense(inputs, filter_size, output_size, output_activation=None, dropout=0.0, dropout_broadcast_dims=None, layer_collection=None, name=None): """Hidden layer...
python
def dense_relu_dense(inputs, filter_size, output_size, output_activation=None, dropout=0.0, dropout_broadcast_dims=None, layer_collection=None, name=None): """Hidden layer...
[ "def", "dense_relu_dense", "(", "inputs", ",", "filter_size", ",", "output_size", ",", "output_activation", "=", "None", ",", "dropout", "=", "0.0", ",", "dropout_broadcast_dims", "=", "None", ",", "layer_collection", "=", "None", ",", "name", "=", "None", ")"...
Hidden layer with RELU activation followed by linear projection.
[ "Hidden", "layer", "with", "RELU", "activation", "followed", "by", "linear", "projection", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1270-L1300
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
dense_dropconnect
def dense_dropconnect(inputs, output_size, dropconnect_dropout=0.0, name="dense_dropconnect", **kwargs): """Dense layer with dropconnect.""" if dropconnect_dropout != 0.0: tf.logging.info("Applying dropconnect as the kernel...
python
def dense_dropconnect(inputs, output_size, dropconnect_dropout=0.0, name="dense_dropconnect", **kwargs): """Dense layer with dropconnect.""" if dropconnect_dropout != 0.0: tf.logging.info("Applying dropconnect as the kernel...
[ "def", "dense_dropconnect", "(", "inputs", ",", "output_size", ",", "dropconnect_dropout", "=", "0.0", ",", "name", "=", "\"dense_dropconnect\"", ",", "*", "*", "kwargs", ")", ":", "if", "dropconnect_dropout", "!=", "0.0", ":", "tf", ".", "logging", ".", "in...
Dense layer with dropconnect.
[ "Dense", "layer", "with", "dropconnect", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1303-L1315
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_relu_conv
def conv_relu_conv(inputs, filter_size, output_size, first_kernel_size=3, second_kernel_size=3, padding="SAME", nonpadding_mask=None, dropout=0.0, name=None, ...
python
def conv_relu_conv(inputs, filter_size, output_size, first_kernel_size=3, second_kernel_size=3, padding="SAME", nonpadding_mask=None, dropout=0.0, name=None, ...
[ "def", "conv_relu_conv", "(", "inputs", ",", "filter_size", ",", "output_size", ",", "first_kernel_size", "=", "3", ",", "second_kernel_size", "=", "3", ",", "padding", "=", "\"SAME\"", ",", "nonpadding_mask", "=", "None", ",", "dropout", "=", "0.0", ",", "n...
Hidden layer with RELU activation followed by linear projection. Args: inputs: A tensor. filter_size: An integer. output_size: An integer. first_kernel_size: An integer. second_kernel_size: An integer. padding: A string. nonpadding_mask: A tensor. dropout: A float. name: A string....
[ "Hidden", "layer", "with", "RELU", "activation", "followed", "by", "linear", "projection", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1318-L1382
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
sepconv_relu_sepconv
def sepconv_relu_sepconv(inputs, filter_size, output_size, first_kernel_size=(1, 1), second_kernel_size=(1, 1), padding="LEFT", nonpadding_mask=None, ...
python
def sepconv_relu_sepconv(inputs, filter_size, output_size, first_kernel_size=(1, 1), second_kernel_size=(1, 1), padding="LEFT", nonpadding_mask=None, ...
[ "def", "sepconv_relu_sepconv", "(", "inputs", ",", "filter_size", ",", "output_size", ",", "first_kernel_size", "=", "(", "1", ",", "1", ")", ",", "second_kernel_size", "=", "(", "1", ",", "1", ")", ",", "padding", "=", "\"LEFT\"", ",", "nonpadding_mask", ...
Hidden layer with RELU activation followed by linear projection.
[ "Hidden", "layer", "with", "RELU", "activation", "followed", "by", "linear", "projection", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1385-L1416
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_hidden_relu
def conv_hidden_relu(inputs, hidden_size, output_size, kernel_size=(1, 1), second_kernel_size=(1, 1), dropout=0.0, **kwargs): """Hidden layer with RELU activation followed by linear projection...
python
def conv_hidden_relu(inputs, hidden_size, output_size, kernel_size=(1, 1), second_kernel_size=(1, 1), dropout=0.0, **kwargs): """Hidden layer with RELU activation followed by linear projection...
[ "def", "conv_hidden_relu", "(", "inputs", ",", "hidden_size", ",", "output_size", ",", "kernel_size", "=", "(", "1", ",", "1", ")", ",", "second_kernel_size", "=", "(", "1", ",", "1", ")", ",", "dropout", "=", "0.0", ",", "*", "*", "kwargs", ")", ":"...
Hidden layer with RELU activation followed by linear projection.
[ "Hidden", "layer", "with", "RELU", "activation", "followed", "by", "linear", "projection", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1420-L1449
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_gru
def conv_gru(x, kernel_size, filters, padding="SAME", dilation_rate=(1, 1), name=None, reuse=None): """Convolutional GRU in 1 dimension.""" # Let's make a shorthand for conv call first. def do_conv(args, name, bias_start, padding): ...
python
def conv_gru(x, kernel_size, filters, padding="SAME", dilation_rate=(1, 1), name=None, reuse=None): """Convolutional GRU in 1 dimension.""" # Let's make a shorthand for conv call first. def do_conv(args, name, bias_start, padding): ...
[ "def", "conv_gru", "(", "x", ",", "kernel_size", ",", "filters", ",", "padding", "=", "\"SAME\"", ",", "dilation_rate", "=", "(", "1", ",", "1", ")", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "# Let's make a shorthand for conv call fir...
Convolutional GRU in 1 dimension.
[ "Convolutional", "GRU", "in", "1", "dimension", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1452-L1478
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
gru_feedfwd
def gru_feedfwd(a_t, h_prev, filters, name=None): """position-wise Feed-fwd GRU gates following the MPNN. Args: a_t: Tensor of shape [batch, length, depth] of current input h_prev: Tensor of shape [batch, length, depth] of prev input filters: an integer specifying number of dimensions of the filters ...
python
def gru_feedfwd(a_t, h_prev, filters, name=None): """position-wise Feed-fwd GRU gates following the MPNN. Args: a_t: Tensor of shape [batch, length, depth] of current input h_prev: Tensor of shape [batch, length, depth] of prev input filters: an integer specifying number of dimensions of the filters ...
[ "def", "gru_feedfwd", "(", "a_t", ",", "h_prev", ",", "filters", ",", "name", "=", "None", ")", ":", "with", "tf", ".", "variable_scope", "(", "name", ",", "default_name", "=", "\"GRU\"", ",", "values", "=", "[", "a_t", ",", "h_prev", "]", ")", ":", ...
position-wise Feed-fwd GRU gates following the MPNN. Args: a_t: Tensor of shape [batch, length, depth] of current input h_prev: Tensor of shape [batch, length, depth] of prev input filters: an integer specifying number of dimensions of the filters name: A string Returns: h_t: [batch, length, fi...
[ "position", "-", "wise", "Feed", "-", "fwd", "GRU", "gates", "following", "the", "MPNN", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1481-L1510
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_lstm
def conv_lstm(x, kernel_size, filters, padding="SAME", dilation_rate=(1, 1), name=None, reuse=None): """Convolutional LSTM in 1 dimension.""" with tf.variable_scope( name, default_name="conv_lstm", values=[x], reuse=reuse): ...
python
def conv_lstm(x, kernel_size, filters, padding="SAME", dilation_rate=(1, 1), name=None, reuse=None): """Convolutional LSTM in 1 dimension.""" with tf.variable_scope( name, default_name="conv_lstm", values=[x], reuse=reuse): ...
[ "def", "conv_lstm", "(", "x", ",", "kernel_size", ",", "filters", ",", "padding", "=", "\"SAME\"", ",", "dilation_rate", "=", "(", "1", ",", "1", ")", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "with", "tf", ".", "variable_scope",...
Convolutional LSTM in 1 dimension.
[ "Convolutional", "LSTM", "in", "1", "dimension", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1513-L1531
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
diagonal_conv_gru
def diagonal_conv_gru(x, kernel_size, filters, dropout=0.0, name=None, reuse=None): """Diagonal Convolutional GRU as in https://arxiv.org/abs/1702.08727.""" # Let's make a shorthand for conv call first. ...
python
def diagonal_conv_gru(x, kernel_size, filters, dropout=0.0, name=None, reuse=None): """Diagonal Convolutional GRU as in https://arxiv.org/abs/1702.08727.""" # Let's make a shorthand for conv call first. ...
[ "def", "diagonal_conv_gru", "(", "x", ",", "kernel_size", ",", "filters", ",", "dropout", "=", "0.0", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "# Let's make a shorthand for conv call first.", "def", "do_conv", "(", "args", ",", "name", ...
Diagonal Convolutional GRU as in https://arxiv.org/abs/1702.08727.
[ "Diagonal", "Convolutional", "GRU", "as", "in", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1702", ".", "08727", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1534-L1573
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
pad_to_same_length
def pad_to_same_length(x, y, final_length_divisible_by=1, axis=1): """Pad tensors x and y on axis 1 so that they have the same length.""" if axis not in [1, 2]: raise ValueError("Only axis=1 and axis=2 supported for now.") with tf.name_scope("pad_to_same_length", values=[x, y]): x_length = shape_list(x)[a...
python
def pad_to_same_length(x, y, final_length_divisible_by=1, axis=1): """Pad tensors x and y on axis 1 so that they have the same length.""" if axis not in [1, 2]: raise ValueError("Only axis=1 and axis=2 supported for now.") with tf.name_scope("pad_to_same_length", values=[x, y]): x_length = shape_list(x)[a...
[ "def", "pad_to_same_length", "(", "x", ",", "y", ",", "final_length_divisible_by", "=", "1", ",", "axis", "=", "1", ")", ":", "if", "axis", "not", "in", "[", "1", ",", "2", "]", ":", "raise", "ValueError", "(", "\"Only axis=1 and axis=2 supported for now.\""...
Pad tensors x and y on axis 1 so that they have the same length.
[ "Pad", "tensors", "x", "and", "y", "on", "axis", "1", "so", "that", "they", "have", "the", "same", "length", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1576-L1613
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
pad_with_zeros
def pad_with_zeros(logits, labels): """Pad labels on the length dimension to match logits length.""" with tf.name_scope("pad_with_zeros", values=[logits, labels]): logits, labels = pad_to_same_length(logits, labels) if len(labels.shape) == 3: # 2-d labels. logits, labels = pad_to_same_length(logits, ...
python
def pad_with_zeros(logits, labels): """Pad labels on the length dimension to match logits length.""" with tf.name_scope("pad_with_zeros", values=[logits, labels]): logits, labels = pad_to_same_length(logits, labels) if len(labels.shape) == 3: # 2-d labels. logits, labels = pad_to_same_length(logits, ...
[ "def", "pad_with_zeros", "(", "logits", ",", "labels", ")", ":", "with", "tf", ".", "name_scope", "(", "\"pad_with_zeros\"", ",", "values", "=", "[", "logits", ",", "labels", "]", ")", ":", "logits", ",", "labels", "=", "pad_to_same_length", "(", "logits",...
Pad labels on the length dimension to match logits length.
[ "Pad", "labels", "on", "the", "length", "dimension", "to", "match", "logits", "length", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1616-L1622
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
weights_prepend_inputs_to_targets
def weights_prepend_inputs_to_targets(labels): """Assign weight 1.0 to only the "targets" portion of the labels. Weight 1.0 is assigned to all nonzero labels past the first zero. See prepend_mode in common_hparams.py Args: labels: A Tensor of int32s. Returns: A Tensor of floats. """ past_first_...
python
def weights_prepend_inputs_to_targets(labels): """Assign weight 1.0 to only the "targets" portion of the labels. Weight 1.0 is assigned to all nonzero labels past the first zero. See prepend_mode in common_hparams.py Args: labels: A Tensor of int32s. Returns: A Tensor of floats. """ past_first_...
[ "def", "weights_prepend_inputs_to_targets", "(", "labels", ")", ":", "past_first_zero", "=", "tf", ".", "cumsum", "(", "to_float", "(", "tf", ".", "equal", "(", "labels", ",", "0", ")", ")", ",", "axis", "=", "1", ")", "nonzero", "=", "to_float", "(", ...
Assign weight 1.0 to only the "targets" portion of the labels. Weight 1.0 is assigned to all nonzero labels past the first zero. See prepend_mode in common_hparams.py Args: labels: A Tensor of int32s. Returns: A Tensor of floats.
[ "Assign", "weight", "1", ".", "0", "to", "only", "the", "targets", "portion", "of", "the", "labels", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1630-L1644
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
check_nonnegative
def check_nonnegative(value): """Check that the value is nonnegative.""" if isinstance(value, tf.Tensor): with tf.control_dependencies([tf.assert_greater_equal(value, 0)]): value = tf.identity(value) elif value < 0: raise ValueError("Value must be non-negative.") return value
python
def check_nonnegative(value): """Check that the value is nonnegative.""" if isinstance(value, tf.Tensor): with tf.control_dependencies([tf.assert_greater_equal(value, 0)]): value = tf.identity(value) elif value < 0: raise ValueError("Value must be non-negative.") return value
[ "def", "check_nonnegative", "(", "value", ")", ":", "if", "isinstance", "(", "value", ",", "tf", ".", "Tensor", ")", ":", "with", "tf", ".", "control_dependencies", "(", "[", "tf", ".", "assert_greater_equal", "(", "value", ",", "0", ")", "]", ")", ":"...
Check that the value is nonnegative.
[ "Check", "that", "the", "value", "is", "nonnegative", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1647-L1654
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
weights_multi_problem
def weights_multi_problem(labels, taskid=-1): """Assign weight 1.0 to only the "targets" portion of the labels. Weight 1.0 is assigned to all labels past the taskid. Args: labels: A Tensor of int32s. taskid: an int32 representing the task id for a problem. Returns: A Tensor of floats. Raises: ...
python
def weights_multi_problem(labels, taskid=-1): """Assign weight 1.0 to only the "targets" portion of the labels. Weight 1.0 is assigned to all labels past the taskid. Args: labels: A Tensor of int32s. taskid: an int32 representing the task id for a problem. Returns: A Tensor of floats. Raises: ...
[ "def", "weights_multi_problem", "(", "labels", ",", "taskid", "=", "-", "1", ")", ":", "taskid", "=", "check_nonnegative", "(", "taskid", ")", "past_taskid", "=", "tf", ".", "cumsum", "(", "to_float", "(", "tf", ".", "equal", "(", "labels", ",", "taskid"...
Assign weight 1.0 to only the "targets" portion of the labels. Weight 1.0 is assigned to all labels past the taskid. Args: labels: A Tensor of int32s. taskid: an int32 representing the task id for a problem. Returns: A Tensor of floats. Raises: ValueError: The Task ID must be valid.
[ "Assign", "weight", "1", ".", "0", "to", "only", "the", "targets", "portion", "of", "the", "labels", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1657-L1677
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
weights_multi_problem_all
def weights_multi_problem_all(labels, taskid=-1): """Assign weight 1.0 to only examples from the given task.""" taskid = check_nonnegative(taskid) weights = to_float(tf.not_equal(labels, 0)) past_taskid = tf.cumsum(to_float(tf.equal(labels, taskid)), axis=1) # Additionally zero out the task id location past...
python
def weights_multi_problem_all(labels, taskid=-1): """Assign weight 1.0 to only examples from the given task.""" taskid = check_nonnegative(taskid) weights = to_float(tf.not_equal(labels, 0)) past_taskid = tf.cumsum(to_float(tf.equal(labels, taskid)), axis=1) # Additionally zero out the task id location past...
[ "def", "weights_multi_problem_all", "(", "labels", ",", "taskid", "=", "-", "1", ")", ":", "taskid", "=", "check_nonnegative", "(", "taskid", ")", "weights", "=", "to_float", "(", "tf", ".", "not_equal", "(", "labels", ",", "0", ")", ")", "past_taskid", ...
Assign weight 1.0 to only examples from the given task.
[ "Assign", "weight", "1", ".", "0", "to", "only", "examples", "from", "the", "given", "task", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1680-L1693
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
weights_multi_problem_input
def weights_multi_problem_input(labels, taskid=-1): """Assign weight 1.0 to only the inputs for the given task.""" taskid = check_nonnegative(taskid) weights_all_tokens = weights_multi_problem_all(labels, taskid) weights_target = weights_multi_problem(labels, taskid) return weights_all_tokens - weights_target
python
def weights_multi_problem_input(labels, taskid=-1): """Assign weight 1.0 to only the inputs for the given task.""" taskid = check_nonnegative(taskid) weights_all_tokens = weights_multi_problem_all(labels, taskid) weights_target = weights_multi_problem(labels, taskid) return weights_all_tokens - weights_target
[ "def", "weights_multi_problem_input", "(", "labels", ",", "taskid", "=", "-", "1", ")", ":", "taskid", "=", "check_nonnegative", "(", "taskid", ")", "weights_all_tokens", "=", "weights_multi_problem_all", "(", "labels", ",", "taskid", ")", "weights_target", "=", ...
Assign weight 1.0 to only the inputs for the given task.
[ "Assign", "weight", "1", ".", "0", "to", "only", "the", "inputs", "for", "the", "given", "task", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1696-L1701
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
weights_concatenated
def weights_concatenated(labels): """Assign weight 1.0 to the "target" part of the concatenated labels. The labels look like: source English I love you . ID1 target French Je t'aime . ID1 source English the cat ID1 target French le chat ID1 source English ... We want to assign weight 1.0 to all words ...
python
def weights_concatenated(labels): """Assign weight 1.0 to the "target" part of the concatenated labels. The labels look like: source English I love you . ID1 target French Je t'aime . ID1 source English the cat ID1 target French le chat ID1 source English ... We want to assign weight 1.0 to all words ...
[ "def", "weights_concatenated", "(", "labels", ")", ":", "eos_mask", "=", "tf", ".", "to_int32", "(", "tf", ".", "equal", "(", "labels", ",", "1", ")", ")", "sentence_num", "=", "tf", ".", "cumsum", "(", "eos_mask", ",", "axis", "=", "1", ",", "exclus...
Assign weight 1.0 to the "target" part of the concatenated labels. The labels look like: source English I love you . ID1 target French Je t'aime . ID1 source English the cat ID1 target French le chat ID1 source English ... We want to assign weight 1.0 to all words in the target text (including the ID1...
[ "Assign", "weight", "1", ".", "0", "to", "the", "target", "part", "of", "the", "concatenated", "labels", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1709-L1735
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
padded_cross_entropy
def padded_cross_entropy(logits, labels, label_smoothing, weights_fn=weights_nonzero, reduce_sum=True, cutoff=0.0, gaussian=False): """Compute cross-entropy assuming 0s...
python
def padded_cross_entropy(logits, labels, label_smoothing, weights_fn=weights_nonzero, reduce_sum=True, cutoff=0.0, gaussian=False): """Compute cross-entropy assuming 0s...
[ "def", "padded_cross_entropy", "(", "logits", ",", "labels", ",", "label_smoothing", ",", "weights_fn", "=", "weights_nonzero", ",", "reduce_sum", "=", "True", ",", "cutoff", "=", "0.0", ",", "gaussian", "=", "False", ")", ":", "if", "isinstance", "(", "logi...
Compute cross-entropy assuming 0s are padding. Computes a loss numerator (the sum of losses), and loss denominator (the number of non-padding tokens). Args: logits: a `Tensor` with shape `[batch, timesteps, vocab_size]`. optionally a FactoredTensor. labels: an integer `Tensor` with shape `[batch, ...
[ "Compute", "cross", "-", "entropy", "assuming", "0s", "are", "padding", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1738-L1800
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
padded_cross_entropy_mixture
def padded_cross_entropy_mixture(logits, labels, label_smoothing, num_mixtures, weights_fn=weights_nonzero, reduce_sum=False, ...
python
def padded_cross_entropy_mixture(logits, labels, label_smoothing, num_mixtures, weights_fn=weights_nonzero, reduce_sum=False, ...
[ "def", "padded_cross_entropy_mixture", "(", "logits", ",", "labels", ",", "label_smoothing", ",", "num_mixtures", ",", "weights_fn", "=", "weights_nonzero", ",", "reduce_sum", "=", "False", ",", "cutoff", "=", "0.0", ",", "gaussian", "=", "False", ",", "return_b...
Compute cross-entropy assuming 0s are padding. Computes a loss numerator (the sum of losses), and loss denominator (the number of non-padding tokens). Computes cross-entropy for each mixture, and returns the corresponding values for the mixture with the highest probability Args: logits: `Tensor` with s...
[ "Compute", "cross", "-", "entropy", "assuming", "0s", "are", "padding", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1803-L1897
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
dml_loss
def dml_loss(pred, labels, weights_fn=_weights_one_third, reduce_sum=True): """Discretized mixture of logistics loss. Args: pred: A [batch, height, width, num_mixtures*10] tensor of floats comprising one unconstrained mixture probability, three means (one per channel), three standard deviations (on...
python
def dml_loss(pred, labels, weights_fn=_weights_one_third, reduce_sum=True): """Discretized mixture of logistics loss. Args: pred: A [batch, height, width, num_mixtures*10] tensor of floats comprising one unconstrained mixture probability, three means (one per channel), three standard deviations (on...
[ "def", "dml_loss", "(", "pred", ",", "labels", ",", "weights_fn", "=", "_weights_one_third", ",", "reduce_sum", "=", "True", ")", ":", "real_labels", "=", "convert_rgb_to_symmetric_real", "(", "labels", ")", "dml_loss_value", "=", "discretized_mix_logistic_loss", "(...
Discretized mixture of logistics loss. Args: pred: A [batch, height, width, num_mixtures*10] tensor of floats comprising one unconstrained mixture probability, three means (one per channel), three standard deviations (one per channel), and three coefficients which linearly parameterize dependen...
[ "Discretized", "mixture", "of", "logistics", "loss", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1905-L1934
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
split_to_discretized_mix_logistic_params
def split_to_discretized_mix_logistic_params(inputs): """Splits input tensor into parameters of discretized mixture logistic. Args: inputs: A [batch, height, width, num_mixtures*10] tensor of floats comprising one unconstrained mixture probability, three means (one per channel), three standard devi...
python
def split_to_discretized_mix_logistic_params(inputs): """Splits input tensor into parameters of discretized mixture logistic. Args: inputs: A [batch, height, width, num_mixtures*10] tensor of floats comprising one unconstrained mixture probability, three means (one per channel), three standard devi...
[ "def", "split_to_discretized_mix_logistic_params", "(", "inputs", ")", ":", "batch", ",", "height", ",", "width", ",", "output_dim", "=", "shape_list", "(", "inputs", ")", "# pylint: disable=unbalanced-tuple-unpacking", "num_mixtures", "=", "output_dim", "//", "10", "...
Splits input tensor into parameters of discretized mixture logistic. Args: inputs: A [batch, height, width, num_mixtures*10] tensor of floats comprising one unconstrained mixture probability, three means (one per channel), three standard deviations (one per channel), and three coefficients whic...
[ "Splits", "input", "tensor", "into", "parameters", "of", "discretized", "mixture", "logistic", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1937-L1967
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
discretized_mix_logistic_loss
def discretized_mix_logistic_loss(pred, labels): """Computes negative log probability for the discretized mixture of logistics. The distribution of a whole pixel is a mixture of 3-dimensional discretized logistic distributions. The 3-D discretized logistic factorizes as 3 1-D discretized logistic distributions...
python
def discretized_mix_logistic_loss(pred, labels): """Computes negative log probability for the discretized mixture of logistics. The distribution of a whole pixel is a mixture of 3-dimensional discretized logistic distributions. The 3-D discretized logistic factorizes as 3 1-D discretized logistic distributions...
[ "def", "discretized_mix_logistic_loss", "(", "pred", ",", "labels", ")", ":", "logits", ",", "locs", ",", "log_scales", ",", "coeffs", "=", "split_to_discretized_mix_logistic_params", "(", "pred", ")", "# Tile labels to broadcast compute across the mixture dimension.", "bat...
Computes negative log probability for the discretized mixture of logistics. The distribution of a whole pixel is a mixture of 3-dimensional discretized logistic distributions. The 3-D discretized logistic factorizes as 3 1-D discretized logistic distributions, one for each channel. It defines ```none P(X = ...
[ "Computes", "negative", "log", "probability", "for", "the", "discretized", "mixture", "of", "logistics", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L1970-L2051
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
sample_from_discretized_mix_logistic
def sample_from_discretized_mix_logistic(pred, seed=None): """Sampling from a discretized mixture of logistics. Args: pred: A [batch, height, width, num_mixtures*10] tensor of floats comprising one unconstrained mixture probability, three means (one per channel), three standard deviations (one per ...
python
def sample_from_discretized_mix_logistic(pred, seed=None): """Sampling from a discretized mixture of logistics. Args: pred: A [batch, height, width, num_mixtures*10] tensor of floats comprising one unconstrained mixture probability, three means (one per channel), three standard deviations (one per ...
[ "def", "sample_from_discretized_mix_logistic", "(", "pred", ",", "seed", "=", "None", ")", ":", "logits", ",", "locs", ",", "log_scales", ",", "coeffs", "=", "split_to_discretized_mix_logistic_params", "(", "pred", ")", "# Sample mixture indicator given logits using the g...
Sampling from a discretized mixture of logistics. Args: pred: A [batch, height, width, num_mixtures*10] tensor of floats comprising one unconstrained mixture probability, three means (one per channel), three standard deviations (one per channel), and three coefficients which linearly parameteri...
[ "Sampling", "from", "a", "discretized", "mixture", "of", "logistics", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2054-L2100
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
smoothing_cross_entropy
def smoothing_cross_entropy(logits, labels, vocab_size, confidence, gaussian=False): """Cross entropy with label smoothing to limit over-confidence. Args: logits: Tensor of shape [batch_size, ?, ?, ?...
python
def smoothing_cross_entropy(logits, labels, vocab_size, confidence, gaussian=False): """Cross entropy with label smoothing to limit over-confidence. Args: logits: Tensor of shape [batch_size, ?, ?, ?...
[ "def", "smoothing_cross_entropy", "(", "logits", ",", "labels", ",", "vocab_size", ",", "confidence", ",", "gaussian", "=", "False", ")", ":", "with", "tf", ".", "name_scope", "(", "\"smoothing_cross_entropy\"", ",", "values", "=", "[", "logits", ",", "labels"...
Cross entropy with label smoothing to limit over-confidence. Args: logits: Tensor of shape [batch_size, ?, ?, ?, vocab_size]. labels: Tensor of shape [batch_size, ?, ?, ?]. vocab_size: Tensor representing the size of the vocabulary. confidence: Used to determine on and off values for label smoothing....
[ "Cross", "entropy", "with", "label", "smoothing", "to", "limit", "over", "-", "confidence", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2103-L2149
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
global_pool_1d
def global_pool_1d(inputs, pooling_type="MAX", mask=None): """Pool elements across the last dimension. Useful to convert a list of vectors into a single vector so as to get a representation of a set. Args: inputs: A tensor of shape [batch_size, sequence_length, input_dims] containing the sequences o...
python
def global_pool_1d(inputs, pooling_type="MAX", mask=None): """Pool elements across the last dimension. Useful to convert a list of vectors into a single vector so as to get a representation of a set. Args: inputs: A tensor of shape [batch_size, sequence_length, input_dims] containing the sequences o...
[ "def", "global_pool_1d", "(", "inputs", ",", "pooling_type", "=", "\"MAX\"", ",", "mask", "=", "None", ")", ":", "with", "tf", ".", "name_scope", "(", "\"global_pool\"", ",", "values", "=", "[", "inputs", "]", ")", ":", "if", "mask", "is", "not", "None...
Pool elements across the last dimension. Useful to convert a list of vectors into a single vector so as to get a representation of a set. Args: inputs: A tensor of shape [batch_size, sequence_length, input_dims] containing the sequences of input vectors. pooling_type: the pooling type to use, MAX ...
[ "Pool", "elements", "across", "the", "last", "dimension", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2152-L2186
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
running_global_pool_1d
def running_global_pool_1d(inputs, pooling_type="MAX"): """Same global pool, but only for the elements up to the current element. Useful for outputs where the state of future elements is not known. Takes no mask as all elements up to the current element are assumed to exist. Currently only supports maximum. Eq...
python
def running_global_pool_1d(inputs, pooling_type="MAX"): """Same global pool, but only for the elements up to the current element. Useful for outputs where the state of future elements is not known. Takes no mask as all elements up to the current element are assumed to exist. Currently only supports maximum. Eq...
[ "def", "running_global_pool_1d", "(", "inputs", ",", "pooling_type", "=", "\"MAX\"", ")", ":", "del", "pooling_type", "with", "tf", ".", "name_scope", "(", "\"running_global_pool\"", ",", "values", "=", "[", "inputs", "]", ")", ":", "scan_fct", "=", "tf", "....
Same global pool, but only for the elements up to the current element. Useful for outputs where the state of future elements is not known. Takes no mask as all elements up to the current element are assumed to exist. Currently only supports maximum. Equivalent to using a lower triangle bias. Args: inputs:...
[ "Same", "global", "pool", "but", "only", "for", "the", "elements", "up", "to", "the", "current", "element", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2189-L2214
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
gated_linear_unit_layer
def gated_linear_unit_layer(x, name=None): """Gated linear unit layer. Paper: Language Modeling with Gated Convolutional Networks. Link: https://arxiv.org/abs/1612.08083 x = Wx * sigmoid(W'x). Args: x: A tensor name: A string Returns: A tensor of the same shape as x. """ with tf.variable_...
python
def gated_linear_unit_layer(x, name=None): """Gated linear unit layer. Paper: Language Modeling with Gated Convolutional Networks. Link: https://arxiv.org/abs/1612.08083 x = Wx * sigmoid(W'x). Args: x: A tensor name: A string Returns: A tensor of the same shape as x. """ with tf.variable_...
[ "def", "gated_linear_unit_layer", "(", "x", ",", "name", "=", "None", ")", ":", "with", "tf", ".", "variable_scope", "(", "name", ",", "default_name", "=", "\"glu_layer\"", ",", "values", "=", "[", "x", "]", ")", ":", "depth", "=", "shape_list", "(", "...
Gated linear unit layer. Paper: Language Modeling with Gated Convolutional Networks. Link: https://arxiv.org/abs/1612.08083 x = Wx * sigmoid(W'x). Args: x: A tensor name: A string Returns: A tensor of the same shape as x.
[ "Gated", "linear", "unit", "layer", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2217-L2235
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
sru_with_scan
def sru_with_scan(x, num_layers=2, activation=None, initial_state=None, name=None, reuse=None): """SRU cell as in https://arxiv.org/abs/1709.02755. This implementation uses tf.scan and can incur overhead, see the full SRU f...
python
def sru_with_scan(x, num_layers=2, activation=None, initial_state=None, name=None, reuse=None): """SRU cell as in https://arxiv.org/abs/1709.02755. This implementation uses tf.scan and can incur overhead, see the full SRU f...
[ "def", "sru_with_scan", "(", "x", ",", "num_layers", "=", "2", ",", "activation", "=", "None", ",", "initial_state", "=", "None", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "if", "num_layers", "<", "1", ":", "raise", "ValueError", ...
SRU cell as in https://arxiv.org/abs/1709.02755. This implementation uses tf.scan and can incur overhead, see the full SRU function doc for details and an implementation that is sometimes faster. Args: x: A tensor of shape [batch, ..., channels] ; ... is treated as time. num_layers: How many SRU layers;...
[ "SRU", "cell", "as", "in", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1709", ".", "02755", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2238-L2298
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
sru
def sru(x, num_layers=2, activation=None, initial_state=None, name=None, reuse=None): """SRU cell as in https://arxiv.org/abs/1709.02755. As defined in the paper: (1) x'_t = W x_t (2) f_t = sigmoid(Wf x_t + bf) (3) r_t = sigmoid(Wr x_t + br) (4) c_t = f_t * c_{t-1} +...
python
def sru(x, num_layers=2, activation=None, initial_state=None, name=None, reuse=None): """SRU cell as in https://arxiv.org/abs/1709.02755. As defined in the paper: (1) x'_t = W x_t (2) f_t = sigmoid(Wf x_t + bf) (3) r_t = sigmoid(Wr x_t + br) (4) c_t = f_t * c_{t-1} +...
[ "def", "sru", "(", "x", ",", "num_layers", "=", "2", ",", "activation", "=", "None", ",", "initial_state", "=", "None", ",", "name", "=", "None", ",", "reuse", "=", "None", ")", ":", "if", "num_layers", "<", "1", ":", "raise", "ValueError", "(", "\...
SRU cell as in https://arxiv.org/abs/1709.02755. As defined in the paper: (1) x'_t = W x_t (2) f_t = sigmoid(Wf x_t + bf) (3) r_t = sigmoid(Wr x_t + br) (4) c_t = f_t * c_{t-1} + (1 - f_t) * x'_t (5) h_t = r_t * activation(c_t) + (1 - r_t) * x_t This version uses functional ops to be faster on GPUs with...
[ "SRU", "cell", "as", "in", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1709", ".", "02755", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2322-L2386
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
linear_set_layer
def linear_set_layer(layer_size, inputs, context=None, activation_fn=tf.nn.relu, dropout=0.0, name=None): """Basic layer type for doing funky things with sets. Applies a linear transformation to each element in...
python
def linear_set_layer(layer_size, inputs, context=None, activation_fn=tf.nn.relu, dropout=0.0, name=None): """Basic layer type for doing funky things with sets. Applies a linear transformation to each element in...
[ "def", "linear_set_layer", "(", "layer_size", ",", "inputs", ",", "context", "=", "None", ",", "activation_fn", "=", "tf", ".", "nn", ".", "relu", ",", "dropout", "=", "0.0", ",", "name", "=", "None", ")", ":", "with", "tf", ".", "variable_scope", "(",...
Basic layer type for doing funky things with sets. Applies a linear transformation to each element in the input set. If a context is supplied, it is concatenated with the inputs. e.g. One can use global_pool_1d to get a representation of the set which can then be used as the context for the next layer. ...
[ "Basic", "layer", "type", "for", "doing", "funky", "things", "with", "sets", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2389-L2440
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
ravanbakhsh_set_layer
def ravanbakhsh_set_layer(layer_size, inputs, mask=None, sequential=False, activation_fn=tf.nn.tanh, dropout=0.0, name=None): """Layer from Deep Sets paper: https...
python
def ravanbakhsh_set_layer(layer_size, inputs, mask=None, sequential=False, activation_fn=tf.nn.tanh, dropout=0.0, name=None): """Layer from Deep Sets paper: https...
[ "def", "ravanbakhsh_set_layer", "(", "layer_size", ",", "inputs", ",", "mask", "=", "None", ",", "sequential", "=", "False", ",", "activation_fn", "=", "tf", ".", "nn", ".", "tanh", ",", "dropout", "=", "0.0", ",", "name", "=", "None", ")", ":", "del",...
Layer from Deep Sets paper: https://arxiv.org/abs/1611.04500 . More parameter-efficient version of a linear-set-layer with context. Args: layer_size: Dimension to transform the input vectors to. inputs: A tensor of shape [batch_size, sequence_length, vector] containing the sequences of input vectors...
[ "Layer", "from", "Deep", "Sets", "paper", ":", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1611", ".", "04500", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2443-L2483
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
fn_device_dependency_dict
def fn_device_dependency_dict(): """State container for fn_device_dependency.""" default_graph = tf.get_default_graph() if not hasattr(default_graph, "dependency_dict"): default_graph.dependency_dict = collections.defaultdict(list) return default_graph.dependency_dict
python
def fn_device_dependency_dict(): """State container for fn_device_dependency.""" default_graph = tf.get_default_graph() if not hasattr(default_graph, "dependency_dict"): default_graph.dependency_dict = collections.defaultdict(list) return default_graph.dependency_dict
[ "def", "fn_device_dependency_dict", "(", ")", ":", "default_graph", "=", "tf", ".", "get_default_graph", "(", ")", "if", "not", "hasattr", "(", "default_graph", ",", "\"dependency_dict\"", ")", ":", "default_graph", ".", "dependency_dict", "=", "collections", ".",...
State container for fn_device_dependency.
[ "State", "container", "for", "fn_device_dependency", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2486-L2491
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
fn_device_dependency
def fn_device_dependency(name, device=""): """Add control deps for name and device.""" key = name + "_" + device outs = [] def body(): with tf.control_dependencies(fn_device_dependency_dict()[key]): yield outs assert outs deps = outs if isinstance(outs[0], (list, tuple)): a...
python
def fn_device_dependency(name, device=""): """Add control deps for name and device.""" key = name + "_" + device outs = [] def body(): with tf.control_dependencies(fn_device_dependency_dict()[key]): yield outs assert outs deps = outs if isinstance(outs[0], (list, tuple)): a...
[ "def", "fn_device_dependency", "(", "name", ",", "device", "=", "\"\"", ")", ":", "key", "=", "name", "+", "\"_\"", "+", "device", "outs", "=", "[", "]", "def", "body", "(", ")", ":", "with", "tf", ".", "control_dependencies", "(", "fn_device_dependency_...
Add control deps for name and device.
[ "Add", "control", "deps", "for", "name", "and", "device", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2495-L2515
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
underlying_variable_ref
def underlying_variable_ref(t): """Find the underlying variable ref. Traverses through Identity, ReadVariableOp, and Enter ops. Stops when op type has Variable or VarHandle in name. Args: t: a Tensor Returns: a Tensor that is a variable ref, or None on error. """ while t.op.type in ["Identity",...
python
def underlying_variable_ref(t): """Find the underlying variable ref. Traverses through Identity, ReadVariableOp, and Enter ops. Stops when op type has Variable or VarHandle in name. Args: t: a Tensor Returns: a Tensor that is a variable ref, or None on error. """ while t.op.type in ["Identity",...
[ "def", "underlying_variable_ref", "(", "t", ")", ":", "while", "t", ".", "op", ".", "type", "in", "[", "\"Identity\"", ",", "\"ReadVariableOp\"", ",", "\"Enter\"", "]", ":", "t", "=", "t", ".", "op", ".", "inputs", "[", "0", "]", "op_type", "=", "t",...
Find the underlying variable ref. Traverses through Identity, ReadVariableOp, and Enter ops. Stops when op type has Variable or VarHandle in name. Args: t: a Tensor Returns: a Tensor that is a variable ref, or None on error.
[ "Find", "the", "underlying", "variable", "ref", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2518-L2537
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
underlying_variable
def underlying_variable(t): """Find the underlying tf.Variable object. Args: t: a Tensor Returns: tf.Variable. """ t = underlying_variable_ref(t) assert t is not None # make sure that the graph has a variable index and that it is up-to-date if not hasattr(tf.get_default_graph(), "var_index"): ...
python
def underlying_variable(t): """Find the underlying tf.Variable object. Args: t: a Tensor Returns: tf.Variable. """ t = underlying_variable_ref(t) assert t is not None # make sure that the graph has a variable index and that it is up-to-date if not hasattr(tf.get_default_graph(), "var_index"): ...
[ "def", "underlying_variable", "(", "t", ")", ":", "t", "=", "underlying_variable_ref", "(", "t", ")", "assert", "t", "is", "not", "None", "# make sure that the graph has a variable index and that it is up-to-date", "if", "not", "hasattr", "(", "tf", ".", "get_default_...
Find the underlying tf.Variable object. Args: t: a Tensor Returns: tf.Variable.
[ "Find", "the", "underlying", "tf", ".", "Variable", "object", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2540-L2557
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
approximate_split
def approximate_split(x, num_splits, axis=0): """Split approximately equally into num_splits parts. Args: x: a Tensor num_splits: an integer axis: an integer. Returns: a list of num_splits Tensors. """ size = shape_list(x)[axis] size_splits = [tf.div(size + i, num_splits) for i in range(nu...
python
def approximate_split(x, num_splits, axis=0): """Split approximately equally into num_splits parts. Args: x: a Tensor num_splits: an integer axis: an integer. Returns: a list of num_splits Tensors. """ size = shape_list(x)[axis] size_splits = [tf.div(size + i, num_splits) for i in range(nu...
[ "def", "approximate_split", "(", "x", ",", "num_splits", ",", "axis", "=", "0", ")", ":", "size", "=", "shape_list", "(", "x", ")", "[", "axis", "]", "size_splits", "=", "[", "tf", ".", "div", "(", "size", "+", "i", ",", "num_splits", ")", "for", ...
Split approximately equally into num_splits parts. Args: x: a Tensor num_splits: an integer axis: an integer. Returns: a list of num_splits Tensors.
[ "Split", "approximately", "equally", "into", "num_splits", "parts", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2560-L2573
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
smoothing_cross_entropy_factored_grad
def smoothing_cross_entropy_factored_grad(op, dy): """Gradient function for smoothing_cross_entropy_factored.""" a = op.inputs[0] b = op.inputs[1] labels = op.inputs[2] confidence = op.inputs[3] num_splits = 16 vocab_size = shape_list(b)[0] labels = approximate_split(labels, num_splits) a = approximat...
python
def smoothing_cross_entropy_factored_grad(op, dy): """Gradient function for smoothing_cross_entropy_factored.""" a = op.inputs[0] b = op.inputs[1] labels = op.inputs[2] confidence = op.inputs[3] num_splits = 16 vocab_size = shape_list(b)[0] labels = approximate_split(labels, num_splits) a = approximat...
[ "def", "smoothing_cross_entropy_factored_grad", "(", "op", ",", "dy", ")", ":", "a", "=", "op", ".", "inputs", "[", "0", "]", "b", "=", "op", ".", "inputs", "[", "1", "]", "labels", "=", "op", ".", "inputs", "[", "2", "]", "confidence", "=", "op", ...
Gradient function for smoothing_cross_entropy_factored.
[ "Gradient", "function", "for", "smoothing_cross_entropy_factored", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2625-L2653
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
smoothing_cross_entropy_factored
def smoothing_cross_entropy_factored(a, b, labels, confidence): """Memory-efficient computation of smoothing cross-entropy. Avoids realizing the entire logits matrix at once. Args: a: a Tensor with shape [batch, inner_dim] b: a Tensor with shape [vocab_size, inner_dim] labels: an integer Tensor with...
python
def smoothing_cross_entropy_factored(a, b, labels, confidence): """Memory-efficient computation of smoothing cross-entropy. Avoids realizing the entire logits matrix at once. Args: a: a Tensor with shape [batch, inner_dim] b: a Tensor with shape [vocab_size, inner_dim] labels: an integer Tensor with...
[ "def", "smoothing_cross_entropy_factored", "(", "a", ",", "b", ",", "labels", ",", "confidence", ")", ":", "num_splits", "=", "16", "vocab_size", "=", "shape_list", "(", "b", ")", "[", "0", "]", "labels", "=", "approximate_split", "(", "labels", ",", "num_...
Memory-efficient computation of smoothing cross-entropy. Avoids realizing the entire logits matrix at once. Args: a: a Tensor with shape [batch, inner_dim] b: a Tensor with shape [vocab_size, inner_dim] labels: an integer Tensor with shape [batch] confidence: a float Returns: A Tensor with ...
[ "Memory", "-", "efficient", "computation", "of", "smoothing", "cross", "-", "entropy", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2661-L2685
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
padded_cross_entropy_factored
def padded_cross_entropy_factored(factored_logits, labels, label_smoothing, weights_fn=weights_nonzero, reduce_sum=True): """Memory-efficient computation of smoothing cross-entropy. ...
python
def padded_cross_entropy_factored(factored_logits, labels, label_smoothing, weights_fn=weights_nonzero, reduce_sum=True): """Memory-efficient computation of smoothing cross-entropy. ...
[ "def", "padded_cross_entropy_factored", "(", "factored_logits", ",", "labels", ",", "label_smoothing", ",", "weights_fn", "=", "weights_nonzero", ",", "reduce_sum", "=", "True", ")", ":", "a", "=", "factored_logits", ".", "a", "b", "=", "factored_logits", ".", "...
Memory-efficient computation of smoothing cross-entropy. Avoids realizing the entire logits matrix at once. Args: factored_logits: a `FactoredTensor` representing a Tensor with shape `[batch, timesteps, vocab_size]`. labels: an integer `Tensor` with shape `[batch, timesteps]`. label_smoothing: ...
[ "Memory", "-", "efficient", "computation", "of", "smoothing", "cross", "-", "entropy", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2688-L2721
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
fn_with_custom_grad
def fn_with_custom_grad(grad_fn, use_global_vars=False): """Decorator to create a subgraph with a custom gradient function. The subgraph created by the decorated function is NOT put in a Defun and so does not suffer from the limitations of the Defun (all subgraph ops on the same device, no summaries). Args:...
python
def fn_with_custom_grad(grad_fn, use_global_vars=False): """Decorator to create a subgraph with a custom gradient function. The subgraph created by the decorated function is NOT put in a Defun and so does not suffer from the limitations of the Defun (all subgraph ops on the same device, no summaries). Args:...
[ "def", "fn_with_custom_grad", "(", "grad_fn", ",", "use_global_vars", "=", "False", ")", ":", "def", "dec", "(", "fn", ")", ":", "@", "functools", ".", "wraps", "(", "fn", ")", "def", "wrapped", "(", "*", "args", ")", ":", "return", "_fn_with_custom_grad...
Decorator to create a subgraph with a custom gradient function. The subgraph created by the decorated function is NOT put in a Defun and so does not suffer from the limitations of the Defun (all subgraph ops on the same device, no summaries). Args: grad_fn: function with signature (inputs, variables...
[ "Decorator", "to", "create", "a", "subgraph", "with", "a", "custom", "gradient", "function", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2724-L2751
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
_fn_with_custom_grad
def _fn_with_custom_grad(fn, inputs, grad_fn, use_global_vars=False): """Create a subgraph with a custom gradient. Args: fn: function that takes inputs as arguments and produces 1 or more Tensors. inputs: list<Tensor>, will be passed as fn(*inputs). grad_fn: function with signature (inputs, vars,...
python
def _fn_with_custom_grad(fn, inputs, grad_fn, use_global_vars=False): """Create a subgraph with a custom gradient. Args: fn: function that takes inputs as arguments and produces 1 or more Tensors. inputs: list<Tensor>, will be passed as fn(*inputs). grad_fn: function with signature (inputs, vars,...
[ "def", "_fn_with_custom_grad", "(", "fn", ",", "inputs", ",", "grad_fn", ",", "use_global_vars", "=", "False", ")", ":", "vs", "=", "tf", ".", "get_variable_scope", "(", ")", "get_vars_fn", "=", "(", "vs", ".", "global_variables", "if", "use_global_vars", "e...
Create a subgraph with a custom gradient. Args: fn: function that takes inputs as arguments and produces 1 or more Tensors. inputs: list<Tensor>, will be passed as fn(*inputs). grad_fn: function with signature (inputs, vars, outputs, output_grads) -> (grad_inputs, grad_vars), all of which are...
[ "Create", "a", "subgraph", "with", "a", "custom", "gradient", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2754-L2817
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
conv_hidden_relu_memory_efficient
def conv_hidden_relu_memory_efficient(x, filter_size, epsilon=1e-6, forget=True, test_vars=None, name=None): """LayerNorm, Conv,...
python
def conv_hidden_relu_memory_efficient(x, filter_size, epsilon=1e-6, forget=True, test_vars=None, name=None): """LayerNorm, Conv,...
[ "def", "conv_hidden_relu_memory_efficient", "(", "x", ",", "filter_size", ",", "epsilon", "=", "1e-6", ",", "forget", "=", "True", ",", "test_vars", "=", "None", ",", "name", "=", "None", ")", ":", "io_size", "=", "x", ".", "get_shape", "(", ")", ".", ...
LayerNorm, Conv, ReLU, Conv. All convolutions have kernel size 1. returns conv(relu(conv(layer_norm(x)))) Args: x: input Tensor with shape [batch, length, io_size] filter_size: an integer - size of the hidden layer. epsilon: a float (for layer norm) forget: a boolean - forget forwards activatio...
[ "LayerNorm", "Conv", "ReLU", "Conv", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2823-L2930
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
shape_list
def shape_list(x): """Return list of dims, statically where possible.""" x = tf.convert_to_tensor(x) # If unknown rank, return dynamic shape if x.get_shape().dims is None: return tf.shape(x) static = x.get_shape().as_list() shape = tf.shape(x) ret = [] for i, dim in enumerate(static): if dim ...
python
def shape_list(x): """Return list of dims, statically where possible.""" x = tf.convert_to_tensor(x) # If unknown rank, return dynamic shape if x.get_shape().dims is None: return tf.shape(x) static = x.get_shape().as_list() shape = tf.shape(x) ret = [] for i, dim in enumerate(static): if dim ...
[ "def", "shape_list", "(", "x", ")", ":", "x", "=", "tf", ".", "convert_to_tensor", "(", "x", ")", "# If unknown rank, return dynamic shape", "if", "x", ".", "get_shape", "(", ")", ".", "dims", "is", "None", ":", "return", "tf", ".", "shape", "(", "x", ...
Return list of dims, statically where possible.
[ "Return", "list", "of", "dims", "statically", "where", "possible", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2933-L2949
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
sample_with_temperature
def sample_with_temperature(logits, temperature, sampling_keep_top_k=-1): """Either argmax or random sampling. Args: logits: a Tensor. temperature: a float 0.0=argmax 1.0=random sampling_keep_top_k: If not -1, only sample from the top k logits. Returns: a Tensor with one fewer dimension than log...
python
def sample_with_temperature(logits, temperature, sampling_keep_top_k=-1): """Either argmax or random sampling. Args: logits: a Tensor. temperature: a float 0.0=argmax 1.0=random sampling_keep_top_k: If not -1, only sample from the top k logits. Returns: a Tensor with one fewer dimension than log...
[ "def", "sample_with_temperature", "(", "logits", ",", "temperature", ",", "sampling_keep_top_k", "=", "-", "1", ")", ":", "if", "temperature", "==", "0.0", ":", "# TF argmax doesn't handle >5 dimensions, so we reshape here.", "logits_shape", "=", "shape_list", "(", "log...
Either argmax or random sampling. Args: logits: a Tensor. temperature: a float 0.0=argmax 1.0=random sampling_keep_top_k: If not -1, only sample from the top k logits. Returns: a Tensor with one fewer dimension than logits.
[ "Either", "argmax", "or", "random", "sampling", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2959-L2997
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
ones_matrix_band_part
def ones_matrix_band_part(rows, cols, num_lower, num_upper, out_shape=None): """Matrix band part of ones. Args: rows: int determining number of rows in output cols: int num_lower: int, maximum distance backward. Negative values indicate unlimited. num_upper: int, maximum distance forward. Neg...
python
def ones_matrix_band_part(rows, cols, num_lower, num_upper, out_shape=None): """Matrix band part of ones. Args: rows: int determining number of rows in output cols: int num_lower: int, maximum distance backward. Negative values indicate unlimited. num_upper: int, maximum distance forward. Neg...
[ "def", "ones_matrix_band_part", "(", "rows", ",", "cols", ",", "num_lower", ",", "num_upper", ",", "out_shape", "=", "None", ")", ":", "if", "all", "(", "[", "isinstance", "(", "el", ",", "int", ")", "for", "el", "in", "[", "rows", ",", "cols", ",", ...
Matrix band part of ones. Args: rows: int determining number of rows in output cols: int num_lower: int, maximum distance backward. Negative values indicate unlimited. num_upper: int, maximum distance forward. Negative values indicate unlimited. out_shape: shape to reshape output by. ...
[ "Matrix", "band", "part", "of", "ones", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L3000-L3034
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
reshape_like_all_dims
def reshape_like_all_dims(a, b): """Reshapes a to match the shape of b.""" ret = tf.reshape(a, tf.shape(b)) if not tf.executing_eagerly(): ret.set_shape(b.get_shape()) return ret
python
def reshape_like_all_dims(a, b): """Reshapes a to match the shape of b.""" ret = tf.reshape(a, tf.shape(b)) if not tf.executing_eagerly(): ret.set_shape(b.get_shape()) return ret
[ "def", "reshape_like_all_dims", "(", "a", ",", "b", ")", ":", "ret", "=", "tf", ".", "reshape", "(", "a", ",", "tf", ".", "shape", "(", "b", ")", ")", "if", "not", "tf", ".", "executing_eagerly", "(", ")", ":", "ret", ".", "set_shape", "(", "b", ...
Reshapes a to match the shape of b.
[ "Reshapes", "a", "to", "match", "the", "shape", "of", "b", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L3037-L3042
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
recompute_grad
def recompute_grad(fn): """Decorator that recomputes the function on the backwards pass. Args: fn: a function that takes Tensors (all as positional arguments) and returns a tuple of Tensors. Returns: A wrapped fn that is identical to fn when called, but its activations will be discarded and re...
python
def recompute_grad(fn): """Decorator that recomputes the function on the backwards pass. Args: fn: a function that takes Tensors (all as positional arguments) and returns a tuple of Tensors. Returns: A wrapped fn that is identical to fn when called, but its activations will be discarded and re...
[ "def", "recompute_grad", "(", "fn", ")", ":", "@", "functools", ".", "wraps", "(", "fn", ")", "def", "wrapped", "(", "*", "args", ")", ":", "return", "_recompute_grad", "(", "fn", ",", "args", ")", "return", "wrapped" ]
Decorator that recomputes the function on the backwards pass. Args: fn: a function that takes Tensors (all as positional arguments) and returns a tuple of Tensors. Returns: A wrapped fn that is identical to fn when called, but its activations will be discarded and recomputed on the backwards pas...
[ "Decorator", "that", "recomputes", "the", "function", "on", "the", "backwards", "pass", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L3045-L3062
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
_recompute_grad
def _recompute_grad(fn, args): """See recompute_grad.""" cached_vs = [] cached_arg_scope = [] def grad_fn(inputs, variables, outputs, output_grads): """Recompute outputs for gradient computation.""" del outputs variables = [underlying_variable_ref(v) for v in variables] # Recompute outputs ...
python
def _recompute_grad(fn, args): """See recompute_grad.""" cached_vs = [] cached_arg_scope = [] def grad_fn(inputs, variables, outputs, output_grads): """Recompute outputs for gradient computation.""" del outputs variables = [underlying_variable_ref(v) for v in variables] # Recompute outputs ...
[ "def", "_recompute_grad", "(", "fn", ",", "args", ")", ":", "cached_vs", "=", "[", "]", "cached_arg_scope", "=", "[", "]", "def", "grad_fn", "(", "inputs", ",", "variables", ",", "outputs", ",", "output_grads", ")", ":", "\"\"\"Recompute outputs for gradient c...
See recompute_grad.
[ "See", "recompute_grad", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L3065-L3100
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
dense
def dense(x, units, **kwargs): """Identical to layers.dense.""" layer_collection = kwargs.pop("layer_collection", None) activations = layers().Dense(units, **kwargs)(x) if layer_collection: # We need to find the layer parameters using scope name for the layer, so # check that the layer is named. Otherwi...
python
def dense(x, units, **kwargs): """Identical to layers.dense.""" layer_collection = kwargs.pop("layer_collection", None) activations = layers().Dense(units, **kwargs)(x) if layer_collection: # We need to find the layer parameters using scope name for the layer, so # check that the layer is named. Otherwi...
[ "def", "dense", "(", "x", ",", "units", ",", "*", "*", "kwargs", ")", ":", "layer_collection", "=", "kwargs", ".", "pop", "(", "\"layer_collection\"", ",", "None", ")", "activations", "=", "layers", "(", ")", ".", "Dense", "(", "units", ",", "*", "*"...
Identical to layers.dense.
[ "Identical", "to", "layers", ".", "dense", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L3103-L3141
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
batch_dense
def batch_dense(inputs, units, activation=None, kernel_initializer=None, reuse=None, name=None): """Multiply a batch of input matrices by a batch of parameter matrices. Each input matrix is multiplied by the corresponding parameter mat...
python
def batch_dense(inputs, units, activation=None, kernel_initializer=None, reuse=None, name=None): """Multiply a batch of input matrices by a batch of parameter matrices. Each input matrix is multiplied by the corresponding parameter mat...
[ "def", "batch_dense", "(", "inputs", ",", "units", ",", "activation", "=", "None", ",", "kernel_initializer", "=", "None", ",", "reuse", "=", "None", ",", "name", "=", "None", ")", ":", "inputs_shape", "=", "shape_list", "(", "inputs", ")", "if", "len", ...
Multiply a batch of input matrices by a batch of parameter matrices. Each input matrix is multiplied by the corresponding parameter matrix. This is useful in a mixture-of-experts where the batch represents different experts with different inputs. Args: inputs: a Tensor with shape [batch, length, input_un...
[ "Multiply", "a", "batch", "of", "input", "matrices", "by", "a", "batch", "of", "parameter", "matrices", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L3144-L3195
train
tensorflow/tensor2tensor
tensor2tensor/layers/common_layers.py
mix
def mix(x1, x2, steps, is_training, min_prob=0.0, max_prob=1.0, mode="lin", simple=False, broadcast_last=False): """Mix starting with x2, mixing mixing, going towards x1.""" with tf.name_scope("mix"): if not is_training: if max_prob >= 1.0: ...
python
def mix(x1, x2, steps, is_training, min_prob=0.0, max_prob=1.0, mode="lin", simple=False, broadcast_last=False): """Mix starting with x2, mixing mixing, going towards x1.""" with tf.name_scope("mix"): if not is_training: if max_prob >= 1.0: ...
[ "def", "mix", "(", "x1", ",", "x2", ",", "steps", ",", "is_training", ",", "min_prob", "=", "0.0", ",", "max_prob", "=", "1.0", ",", "mode", "=", "\"lin\"", ",", "simple", "=", "False", ",", "broadcast_last", "=", "False", ")", ":", "with", "tf", "...
Mix starting with x2, mixing mixing, going towards x1.
[ "Mix", "starting", "with", "x2", "mixing", "mixing", "going", "towards", "x1", "." ]
272500b6efe353aeb638d2745ed56e519462ca31
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L3198-L3251
train