partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
flatten_all_but_last
Flatten all dimensions of a except the last.
tensor2tensor/utils/expert_utils.py
def flatten_all_but_last(a): """Flatten all dimensions of a except the last.""" ret = tf.reshape(a, [-1, tf.shape(a)[-1]]) if not tf.executing_eagerly(): ret.set_shape([None] + a.get_shape().as_list()[-1:]) return ret
def flatten_all_but_last(a): """Flatten all dimensions of a except the last.""" ret = tf.reshape(a, [-1, tf.shape(a)[-1]]) if not tf.executing_eagerly(): ret.set_shape([None] + a.get_shape().as_list()[-1:]) return ret
[ "Flatten", "all", "dimensions", "of", "a", "except", "the", "last", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L986-L991
[ "def", "flatten_all_but_last", "(", "a", ")", ":", "ret", "=", "tf", ".", "reshape", "(", "a", ",", "[", "-", "1", ",", "tf", ".", "shape", "(", "a", ")", "[", "-", "1", "]", "]", ")", "if", "not", "tf", ".", "executing_eagerly", "(", ")", ":...
272500b6efe353aeb638d2745ed56e519462ca31
train
local_moe
Call a local mixture of experts. Args: x: a tensors with shape [... , input_size] train: a boolean scalar. expert_fn: a function. num_experts: an integer - number of experts k: an integer - how many experts to use for each batch element loss_coef: a scalar - multiplier on load-balancing losse...
tensor2tensor/utils/expert_utils.py
def local_moe(x, train, expert_fn, num_experts, k=1, loss_coef=1e-2, hparams=None, pass_x=True, pass_gates=False, additional_dispatch_params=None, name=None): """Call a local mix...
def local_moe(x, train, expert_fn, num_experts, k=1, loss_coef=1e-2, hparams=None, pass_x=True, pass_gates=False, additional_dispatch_params=None, name=None): """Call a local mix...
[ "Call", "a", "local", "mixture", "of", "experts", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L994-L1074
[ "def", "local_moe", "(", "x", ",", "train", ",", "expert_fn", ",", "num_experts", ",", "k", "=", "1", ",", "loss_coef", "=", "1e-2", ",", "hparams", "=", "None", ",", "pass_x", "=", "True", ",", "pass_gates", "=", "False", ",", "additional_dispatch_param...
272500b6efe353aeb638d2745ed56e519462ca31
train
local_moe_tpu
Local mixture of experts that works well on TPU. See https://arxiv.org/abs/1701.06538 There are num_experts expert networks, each containing a relu-activated hidden layer of size hidden_size, followed by an output projection. The number of parameters is thus: num_experts * (input_size * hidden_size + hid...
tensor2tensor/utils/expert_utils.py
def local_moe_tpu(inputs, hidden_size, output_size, num_experts, loss_coef=1e-3, overhead=1.0): """Local mixture of experts that works well on TPU. See https://arxiv.org/abs/1701.06538 There are num_experts expert networks...
def local_moe_tpu(inputs, hidden_size, output_size, num_experts, loss_coef=1e-3, overhead=1.0): """Local mixture of experts that works well on TPU. See https://arxiv.org/abs/1701.06538 There are num_experts expert networks...
[ "Local", "mixture", "of", "experts", "that", "works", "well", "on", "TPU", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L1217-L1411
[ "def", "local_moe_tpu", "(", "inputs", ",", "hidden_size", ",", "output_size", ",", "num_experts", ",", "loss_coef", "=", "1e-3", ",", "overhead", "=", "1.0", ")", ":", "batch", ",", "length", ",", "input_size", "=", "common_layers", ".", "shape_list", "(", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
reduce_by_device
Reduces data per device. This can be useful, for example, if we want to all-reduce n tensors on k<n devices (like during eval when we have only one device). We call reduce_by_device() to first sum the tensors per device, then call our usual all-reduce operation to create one sum per device, followed by expa...
tensor2tensor/utils/expert_utils.py
def reduce_by_device(parallelism, data, reduce_fn): """Reduces data per device. This can be useful, for example, if we want to all-reduce n tensors on k<n devices (like during eval when we have only one device). We call reduce_by_device() to first sum the tensors per device, then call our usual all-reduce o...
def reduce_by_device(parallelism, data, reduce_fn): """Reduces data per device. This can be useful, for example, if we want to all-reduce n tensors on k<n devices (like during eval when we have only one device). We call reduce_by_device() to first sum the tensors per device, then call our usual all-reduce o...
[ "Reduces", "data", "per", "device", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L1414-L1443
[ "def", "reduce_by_device", "(", "parallelism", ",", "data", ",", "reduce_fn", ")", ":", "unique_devices", "=", "[", "]", "device_to_data", "=", "{", "}", "for", "dev", ",", "datum", "in", "zip", "(", "parallelism", ".", "devices", ",", "data", ")", ":", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
expand_by_device
Opposite of reduce_by_device(). Args: original_parallelism: a expert_utils.Parallelism object. device_parallelism: a expert_utils.Parallelism object. data: a list of tensors with length device_parallelism.n Returns: a list of Tensors with length original_parallelism.n
tensor2tensor/utils/expert_utils.py
def expand_by_device(original_parallelism, device_parallelism, data): """Opposite of reduce_by_device(). Args: original_parallelism: a expert_utils.Parallelism object. device_parallelism: a expert_utils.Parallelism object. data: a list of tensors with length device_parallelism.n Returns: a list ...
def expand_by_device(original_parallelism, device_parallelism, data): """Opposite of reduce_by_device(). Args: original_parallelism: a expert_utils.Parallelism object. device_parallelism: a expert_utils.Parallelism object. data: a list of tensors with length device_parallelism.n Returns: a list ...
[ "Opposite", "of", "reduce_by_device", "()", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L1446-L1460
[ "def", "expand_by_device", "(", "original_parallelism", ",", "device_parallelism", ",", "data", ")", ":", "device_to_datum", "=", "{", "device_parallelism", ".", "devices", "[", "i", "]", ":", "data", "[", "i", "]", "for", "i", "in", "range", "(", "device_pa...
272500b6efe353aeb638d2745ed56e519462ca31
train
all_reduce_ring
Compute the sum of all Tensors and put the result everywhere. Assumes that the devices are connected in a ring. Args: x: a list of Tensors with length parallelism.n parallelism: a expert_utils.Parallelism object. maybe_reduce: a boolean - first reduce per device. use_bfloat16: a boolean - saves ba...
tensor2tensor/utils/expert_utils.py
def all_reduce_ring(x, parallelism, maybe_reduce=True, use_bfloat16=True): """Compute the sum of all Tensors and put the result everywhere. Assumes that the devices are connected in a ring. Args: x: a list of Tensors with length parallelism.n parallelism: a expert_utils.Parallelism object. maybe_red...
def all_reduce_ring(x, parallelism, maybe_reduce=True, use_bfloat16=True): """Compute the sum of all Tensors and put the result everywhere. Assumes that the devices are connected in a ring. Args: x: a list of Tensors with length parallelism.n parallelism: a expert_utils.Parallelism object. maybe_red...
[ "Compute", "the", "sum", "of", "all", "Tensors", "and", "put", "the", "result", "everywhere", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L1463-L1537
[ "def", "all_reduce_ring", "(", "x", ",", "parallelism", ",", "maybe_reduce", "=", "True", ",", "use_bfloat16", "=", "True", ")", ":", "if", "parallelism", ".", "n", "==", "1", ":", "return", "x", "if", "maybe_reduce", ":", "original_parallelism", "=", "par...
272500b6efe353aeb638d2745ed56e519462ca31
train
Parallelism._maybe_repeat
Utility function for processing arguments that are singletons or lists. Args: x: either a list of self.n elements, or not a list. Returns: a list of self.n elements.
tensor2tensor/utils/expert_utils.py
def _maybe_repeat(self, x): """Utility function for processing arguments that are singletons or lists. Args: x: either a list of self.n elements, or not a list. Returns: a list of self.n elements. """ if isinstance(x, list): assert len(x) == self.n return x else: ...
def _maybe_repeat(self, x): """Utility function for processing arguments that are singletons or lists. Args: x: either a list of self.n elements, or not a list. Returns: a list of self.n elements. """ if isinstance(x, list): assert len(x) == self.n return x else: ...
[ "Utility", "function", "for", "processing", "arguments", "that", "are", "singletons", "or", "lists", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L251-L264
[ "def", "_maybe_repeat", "(", "self", ",", "x", ")", ":", "if", "isinstance", "(", "x", ",", "list", ")", ":", "assert", "len", "(", "x", ")", "==", "self", ".", "n", "return", "x", "else", ":", "return", "[", "x", "]", "*", "self", ".", "n" ]
272500b6efe353aeb638d2745ed56e519462ca31
train
PadRemover.remove
Remove padding from the given tensor. Args: x (tf.Tensor): of shape [dim_origin,...] Returns: a tensor of shape [dim_compressed,...] with dim_compressed <= dim_origin
tensor2tensor/utils/expert_utils.py
def remove(self, x): """Remove padding from the given tensor. Args: x (tf.Tensor): of shape [dim_origin,...] Returns: a tensor of shape [dim_compressed,...] with dim_compressed <= dim_origin """ with tf.name_scope("pad_reduce/remove"): x_shape = x.get_shape().as_list() x = ...
def remove(self, x): """Remove padding from the given tensor. Args: x (tf.Tensor): of shape [dim_origin,...] Returns: a tensor of shape [dim_compressed,...] with dim_compressed <= dim_origin """ with tf.name_scope("pad_reduce/remove"): x_shape = x.get_shape().as_list() x = ...
[ "Remove", "padding", "from", "the", "given", "tensor", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L624-L643
[ "def", "remove", "(", "self", ",", "x", ")", ":", "with", "tf", ".", "name_scope", "(", "\"pad_reduce/remove\"", ")", ":", "x_shape", "=", "x", ".", "get_shape", "(", ")", ".", "as_list", "(", ")", "x", "=", "tf", ".", "gather_nd", "(", "x", ",", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
PadRemover.restore
Add padding back to the given tensor. Args: x (tf.Tensor): of shape [dim_compressed,...] Returns: a tensor of shape [dim_origin,...] with dim_compressed >= dim_origin. The dim is restored from the original reference tensor
tensor2tensor/utils/expert_utils.py
def restore(self, x): """Add padding back to the given tensor. Args: x (tf.Tensor): of shape [dim_compressed,...] Returns: a tensor of shape [dim_origin,...] with dim_compressed >= dim_origin. The dim is restored from the original reference tensor """ with tf.name_scope("pad_redu...
def restore(self, x): """Add padding back to the given tensor. Args: x (tf.Tensor): of shape [dim_compressed,...] Returns: a tensor of shape [dim_origin,...] with dim_compressed >= dim_origin. The dim is restored from the original reference tensor """ with tf.name_scope("pad_redu...
[ "Add", "padding", "back", "to", "the", "given", "tensor", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L645-L661
[ "def", "restore", "(", "self", ",", "x", ")", ":", "with", "tf", ".", "name_scope", "(", "\"pad_reduce/restore\"", ")", ":", "x", "=", "tf", ".", "scatter_nd", "(", "indices", "=", "self", ".", "nonpad_ids", ",", "updates", "=", "x", ",", "shape", "=...
272500b6efe353aeb638d2745ed56e519462ca31
train
SparseDispatcher.dispatch
Create one input Tensor for each expert. The `Tensor` for a expert `i` contains the slices of `inp` corresponding to the batch elements `b` where `gates[b, i] > 0`. Args: inp: a `Tensor` of shape "[batch_size, <extra_input_dims>]` Returns: a list of `num_experts` `Tensor`s with shapes ...
tensor2tensor/utils/expert_utils.py
def dispatch(self, inp): """Create one input Tensor for each expert. The `Tensor` for a expert `i` contains the slices of `inp` corresponding to the batch elements `b` where `gates[b, i] > 0`. Args: inp: a `Tensor` of shape "[batch_size, <extra_input_dims>]` Returns: a list of `num_exp...
def dispatch(self, inp): """Create one input Tensor for each expert. The `Tensor` for a expert `i` contains the slices of `inp` corresponding to the batch elements `b` where `gates[b, i] > 0`. Args: inp: a `Tensor` of shape "[batch_size, <extra_input_dims>]` Returns: a list of `num_exp...
[ "Create", "one", "input", "Tensor", "for", "each", "expert", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L794-L807
[ "def", "dispatch", "(", "self", ",", "inp", ")", ":", "inp", "=", "tf", ".", "gather", "(", "inp", ",", "self", ".", "_batch_index", ")", "return", "tf", ".", "split", "(", "inp", ",", "self", ".", "_part_sizes_tensor", ",", "0", ",", "num", "=", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
SparseDispatcher.combine
Sum together the expert output, weighted by the gates. The slice corresponding to a particular batch element `b` is computed as the sum over all experts `i` of the expert output, weighted by the corresponding gate values. If `multiply_by_gates` is set to False, the gate values are ignored. Args: ...
tensor2tensor/utils/expert_utils.py
def combine(self, expert_out, multiply_by_gates=True): """Sum together the expert output, weighted by the gates. The slice corresponding to a particular batch element `b` is computed as the sum over all experts `i` of the expert output, weighted by the corresponding gate values. If `multiply_by_gates`...
def combine(self, expert_out, multiply_by_gates=True): """Sum together the expert output, weighted by the gates. The slice corresponding to a particular batch element `b` is computed as the sum over all experts `i` of the expert output, weighted by the corresponding gate values. If `multiply_by_gates`...
[ "Sum", "together", "the", "expert", "output", "weighted", "by", "the", "gates", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L810-L833
[ "def", "combine", "(", "self", ",", "expert_out", ",", "multiply_by_gates", "=", "True", ")", ":", "# see comments on convert_gradient_to_tensor", "stitched", "=", "common_layers", ".", "convert_gradient_to_tensor", "(", "tf", ".", "concat", "(", "expert_out", ",", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
SparseDispatcher.expert_to_gates
Gate values corresponding to the examples in the per-expert `Tensor`s. Returns: a list of `num_experts` one-dimensional `Tensor`s with type `tf.float32` and shapes `[expert_batch_size_i]`
tensor2tensor/utils/expert_utils.py
def expert_to_gates(self): """Gate values corresponding to the examples in the per-expert `Tensor`s. Returns: a list of `num_experts` one-dimensional `Tensor`s with type `tf.float32` and shapes `[expert_batch_size_i]` """ return tf.split( self._nonzero_gates, self._part_sizes_te...
def expert_to_gates(self): """Gate values corresponding to the examples in the per-expert `Tensor`s. Returns: a list of `num_experts` one-dimensional `Tensor`s with type `tf.float32` and shapes `[expert_batch_size_i]` """ return tf.split( self._nonzero_gates, self._part_sizes_te...
[ "Gate", "values", "corresponding", "to", "the", "examples", "in", "the", "per", "-", "expert", "Tensor", "s", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L835-L843
[ "def", "expert_to_gates", "(", "self", ")", ":", "return", "tf", ".", "split", "(", "self", ".", "_nonzero_gates", ",", "self", ".", "_part_sizes_tensor", ",", "0", ",", "num", "=", "self", ".", "_num_experts", ")" ]
272500b6efe353aeb638d2745ed56e519462ca31
train
SparseDispatcher.expert_to_batch_indices
Batch indices corresponding to the examples in the per-expert `Tensor`s. Returns: a list of `num_experts` one-dimensional `Tensor`s with type `tf.int64` and shapes `[expert_batch_size_i]`
tensor2tensor/utils/expert_utils.py
def expert_to_batch_indices(self): """Batch indices corresponding to the examples in the per-expert `Tensor`s. Returns: a list of `num_experts` one-dimensional `Tensor`s with type `tf.int64` and shapes `[expert_batch_size_i]` """ return tf.split( self._batch_index, self._part_si...
def expert_to_batch_indices(self): """Batch indices corresponding to the examples in the per-expert `Tensor`s. Returns: a list of `num_experts` one-dimensional `Tensor`s with type `tf.int64` and shapes `[expert_batch_size_i]` """ return tf.split( self._batch_index, self._part_si...
[ "Batch", "indices", "corresponding", "to", "the", "examples", "in", "the", "per", "-", "expert", "Tensor", "s", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L845-L853
[ "def", "expert_to_batch_indices", "(", "self", ")", ":", "return", "tf", ".", "split", "(", "self", ".", "_batch_index", ",", "self", ".", "_part_sizes_tensor", ",", "0", ",", "num", "=", "self", ".", "_num_experts", ")" ]
272500b6efe353aeb638d2745ed56e519462ca31
train
DistributedSparseDispatcher.dispatch
Create one input Tensor for each expert. Args: inp: a list of length num_datashards `Tensor`s with shapes `[batch_size[d], <extra_input_dims>]`. Returns: a list of `num_experts` `Tensor`s with shapes `[num_examples[i], <extra_input_dims>]`.
tensor2tensor/utils/expert_utils.py
def dispatch(self, inp): """Create one input Tensor for each expert. Args: inp: a list of length num_datashards `Tensor`s with shapes `[batch_size[d], <extra_input_dims>]`. Returns: a list of `num_experts` `Tensor`s with shapes `[num_examples[i], <extra_input_dims>]`. """ ...
def dispatch(self, inp): """Create one input Tensor for each expert. Args: inp: a list of length num_datashards `Tensor`s with shapes `[batch_size[d], <extra_input_dims>]`. Returns: a list of `num_experts` `Tensor`s with shapes `[num_examples[i], <extra_input_dims>]`. """ ...
[ "Create", "one", "input", "Tensor", "for", "each", "expert", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L890-L905
[ "def", "dispatch", "(", "self", ",", "inp", ")", ":", "dispatched", "=", "self", ".", "_dp", "(", "lambda", "a", ",", "b", ":", "a", ".", "dispatch", "(", "b", ")", ",", "self", ".", "_dispatchers", ",", "inp", ")", "ret", "=", "self", ".", "_e...
272500b6efe353aeb638d2745ed56e519462ca31
train
DistributedSparseDispatcher.combine
Sum together the expert output, multiplied by the corresponding gates. Args: expert_out: a list of `num_experts` `Tensor`s, each with shape `[expert_batch_size_i, <extra_output_dims>]`. multiply_by_gates: a boolean. Returns: a list of num_datashards `Tensor`s with shapes `[ba...
tensor2tensor/utils/expert_utils.py
def combine(self, expert_out, multiply_by_gates=True): """Sum together the expert output, multiplied by the corresponding gates. Args: expert_out: a list of `num_experts` `Tensor`s, each with shape `[expert_batch_size_i, <extra_output_dims>]`. multiply_by_gates: a boolean. Returns: ...
def combine(self, expert_out, multiply_by_gates=True): """Sum together the expert output, multiplied by the corresponding gates. Args: expert_out: a list of `num_experts` `Tensor`s, each with shape `[expert_batch_size_i, <extra_output_dims>]`. multiply_by_gates: a boolean. Returns: ...
[ "Sum", "together", "the", "expert", "output", "multiplied", "by", "the", "corresponding", "gates", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L907-L930
[ "def", "combine", "(", "self", ",", "expert_out", ",", "multiply_by_gates", "=", "True", ")", ":", "expert_part_sizes", "=", "tf", ".", "unstack", "(", "tf", ".", "stack", "(", "[", "d", ".", "part_sizes", "for", "d", "in", "self", ".", "_dispatchers", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
DistributedSparseDispatcher.expert_to_gates
Gate values corresponding to the examples in the per-expert `Tensor`s. Returns: a list of `num_experts` one-dimensional `Tensor`s of type `tf.float32`.
tensor2tensor/utils/expert_utils.py
def expert_to_gates(self): """Gate values corresponding to the examples in the per-expert `Tensor`s. Returns: a list of `num_experts` one-dimensional `Tensor`s of type `tf.float32`. """ return self._ep( tf.concat, transpose_list_of_lists( self._dp(lambda d: d.expert_to...
def expert_to_gates(self): """Gate values corresponding to the examples in the per-expert `Tensor`s. Returns: a list of `num_experts` one-dimensional `Tensor`s of type `tf.float32`. """ return self._ep( tf.concat, transpose_list_of_lists( self._dp(lambda d: d.expert_to...
[ "Gate", "values", "corresponding", "to", "the", "examples", "in", "the", "per", "-", "expert", "Tensor", "s", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L932-L941
[ "def", "expert_to_gates", "(", "self", ")", ":", "return", "self", ".", "_ep", "(", "tf", ".", "concat", ",", "transpose_list_of_lists", "(", "self", ".", "_dp", "(", "lambda", "d", ":", "d", ".", "expert_to_gates", "(", ")", ",", "self", ".", "_dispat...
272500b6efe353aeb638d2745ed56e519462ca31
train
TruncatingDispatcher.dispatch
Send the inputs to the experts. Args: inp: a `Tensor` of shape "[batch, length, depth]` Returns: a tensor with shape [batch, num_experts, expert_capacity, depth]
tensor2tensor/utils/expert_utils.py
def dispatch(self, inp): """Send the inputs to the experts. Args: inp: a `Tensor` of shape "[batch, length, depth]` Returns: a tensor with shape [batch, num_experts, expert_capacity, depth] """ inp = tf.reshape(inp, [self._batch * self._length, -1]) # [batch, num_experts, expert_cap...
def dispatch(self, inp): """Send the inputs to the experts. Args: inp: a `Tensor` of shape "[batch, length, depth]` Returns: a tensor with shape [batch, num_experts, expert_capacity, depth] """ inp = tf.reshape(inp, [self._batch * self._length, -1]) # [batch, num_experts, expert_cap...
[ "Send", "the", "inputs", "to", "the", "experts", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L1158-L1169
[ "def", "dispatch", "(", "self", ",", "inp", ")", ":", "inp", "=", "tf", ".", "reshape", "(", "inp", ",", "[", "self", ".", "_batch", "*", "self", ".", "_length", ",", "-", "1", "]", ")", "# [batch, num_experts, expert_capacity, depth]", "ret", "=", "tf...
272500b6efe353aeb638d2745ed56e519462ca31
train
TruncatingDispatcher.combine
Return the output from the experts. When one example goes to multiple experts, the outputs are summed. Args: x: a Tensor with shape [batch, num_experts, expert_capacity, depth] Returns: a `Tensor` with shape `[batch, length, depth]
tensor2tensor/utils/expert_utils.py
def combine(self, x): """Return the output from the experts. When one example goes to multiple experts, the outputs are summed. Args: x: a Tensor with shape [batch, num_experts, expert_capacity, depth] Returns: a `Tensor` with shape `[batch, length, depth] """ depth = tf.shape(x)[...
def combine(self, x): """Return the output from the experts. When one example goes to multiple experts, the outputs are summed. Args: x: a Tensor with shape [batch, num_experts, expert_capacity, depth] Returns: a `Tensor` with shape `[batch, length, depth] """ depth = tf.shape(x)[...
[ "Return", "the", "output", "from", "the", "experts", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L1172-L1188
[ "def", "combine", "(", "self", ",", "x", ")", ":", "depth", "=", "tf", ".", "shape", "(", "x", ")", "[", "-", "1", "]", "x", "*=", "tf", ".", "expand_dims", "(", "self", ".", "_nonpadding", ",", "-", "1", ")", "ret", "=", "tf", ".", "unsorted...
272500b6efe353aeb638d2745ed56e519462ca31
train
make_env
Factory function for envs.
tensor2tensor/rl/evaluator.py
def make_env(env_type, real_env, sim_env_kwargs): """Factory function for envs.""" return { "real": lambda: real_env.new_like( # pylint: disable=g-long-lambda batch_size=sim_env_kwargs["batch_size"], store_rollouts=False, ), "simulated": lambda: rl_utils.SimulatedBatchGymEnvWi...
def make_env(env_type, real_env, sim_env_kwargs): """Factory function for envs.""" return { "real": lambda: real_env.new_like( # pylint: disable=g-long-lambda batch_size=sim_env_kwargs["batch_size"], store_rollouts=False, ), "simulated": lambda: rl_utils.SimulatedBatchGymEnvWi...
[ "Factory", "function", "for", "envs", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/rl/evaluator.py#L240-L250
[ "def", "make_env", "(", "env_type", ",", "real_env", ",", "sim_env_kwargs", ")", ":", "return", "{", "\"real\"", ":", "lambda", ":", "real_env", ".", "new_like", "(", "# pylint: disable=g-long-lambda", "batch_size", "=", "sim_env_kwargs", "[", "\"batch_size\"", "]...
272500b6efe353aeb638d2745ed56e519462ca31
train
make_agent
Factory function for Agents.
tensor2tensor/rl/evaluator.py
def make_agent( agent_type, env, policy_hparams, policy_dir, sampling_temp, sim_env_kwargs_fn=None, frame_stack_size=None, rollout_agent_type=None, batch_size=None, inner_batch_size=None, env_type=None, **planner_kwargs ): """Factory function for Agents.""" if batch_size is None: batch_size = env.ba...
def make_agent( agent_type, env, policy_hparams, policy_dir, sampling_temp, sim_env_kwargs_fn=None, frame_stack_size=None, rollout_agent_type=None, batch_size=None, inner_batch_size=None, env_type=None, **planner_kwargs ): """Factory function for Agents.""" if batch_size is None: batch_size = env.ba...
[ "Factory", "function", "for", "Agents", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/rl/evaluator.py#L253-L277
[ "def", "make_agent", "(", "agent_type", ",", "env", ",", "policy_hparams", ",", "policy_dir", ",", "sampling_temp", ",", "sim_env_kwargs_fn", "=", "None", ",", "frame_stack_size", "=", "None", ",", "rollout_agent_type", "=", "None", ",", "batch_size", "=", "None...
272500b6efe353aeb638d2745ed56e519462ca31
train
collect_frames_for_random_starts
Collects frames from real env for random starts of simulated env.
tensor2tensor/rl/evaluator.py
def collect_frames_for_random_starts( storage_env, stacked_env, agent, frame_stack_size, random_starts_step_limit, log_every_steps=None ): """Collects frames from real env for random starts of simulated env.""" del frame_stack_size storage_env.start_new_epoch(0) tf.logging.info( "Collecting %d fra...
def collect_frames_for_random_starts( storage_env, stacked_env, agent, frame_stack_size, random_starts_step_limit, log_every_steps=None ): """Collects frames from real env for random starts of simulated env.""" del frame_stack_size storage_env.start_new_epoch(0) tf.logging.info( "Collecting %d fra...
[ "Collects", "frames", "from", "real", "env", "for", "random", "starts", "of", "simulated", "env", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/rl/evaluator.py#L280-L297
[ "def", "collect_frames_for_random_starts", "(", "storage_env", ",", "stacked_env", ",", "agent", ",", "frame_stack_size", ",", "random_starts_step_limit", ",", "log_every_steps", "=", "None", ")", ":", "del", "frame_stack_size", "storage_env", ".", "start_new_epoch", "(...
272500b6efe353aeb638d2745ed56e519462ca31
train
make_agent_from_hparams
Creates an Agent from hparams.
tensor2tensor/rl/evaluator.py
def make_agent_from_hparams( agent_type, base_env, stacked_env, loop_hparams, policy_hparams, planner_hparams, model_dir, policy_dir, sampling_temp, video_writers=() ): """Creates an Agent from hparams.""" def sim_env_kwargs_fn(): return rl.make_simulated_env_kwargs( base_env, loop_hparams, batc...
def make_agent_from_hparams( agent_type, base_env, stacked_env, loop_hparams, policy_hparams, planner_hparams, model_dir, policy_dir, sampling_temp, video_writers=() ): """Creates an Agent from hparams.""" def sim_env_kwargs_fn(): return rl.make_simulated_env_kwargs( base_env, loop_hparams, batc...
[ "Creates", "an", "Agent", "from", "hparams", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/rl/evaluator.py#L300-L321
[ "def", "make_agent_from_hparams", "(", "agent_type", ",", "base_env", ",", "stacked_env", ",", "loop_hparams", ",", "policy_hparams", ",", "planner_hparams", ",", "model_dir", ",", "policy_dir", ",", "sampling_temp", ",", "video_writers", "=", "(", ")", ")", ":", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
make_eval_fn_with_agent
Returns an out-of-graph eval_fn using the Agent API.
tensor2tensor/rl/evaluator.py
def make_eval_fn_with_agent( agent_type, eval_mode, planner_hparams, model_dir, log_every_steps=None, video_writers=(), random_starts_step_limit=None ): """Returns an out-of-graph eval_fn using the Agent API.""" def eval_fn(env, loop_hparams, policy_hparams, policy_dir, sampling_temp): """Eval function....
def make_eval_fn_with_agent( agent_type, eval_mode, planner_hparams, model_dir, log_every_steps=None, video_writers=(), random_starts_step_limit=None ): """Returns an out-of-graph eval_fn using the Agent API.""" def eval_fn(env, loop_hparams, policy_hparams, policy_dir, sampling_temp): """Eval function....
[ "Returns", "an", "out", "-", "of", "-", "graph", "eval_fn", "using", "the", "Agent", "API", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/rl/evaluator.py#L324-L372
[ "def", "make_eval_fn_with_agent", "(", "agent_type", ",", "eval_mode", ",", "planner_hparams", ",", "model_dir", ",", "log_every_steps", "=", "None", ",", "video_writers", "=", "(", ")", ",", "random_starts_step_limit", "=", "None", ")", ":", "def", "eval_fn", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
evaluate_world_model
Evaluates the world model.
tensor2tensor/rl/evaluator.py
def evaluate_world_model( agent_type, loop_hparams, planner_hparams, model_dir, policy_dir, random_starts_step_limit, debug_video_path, log_every_steps ): """Evaluates the world model.""" if debug_video_path: debug_video_path = os.path.join(debug_video_path, "0.avi") storage_env = rl_utils.setup_env(...
def evaluate_world_model( agent_type, loop_hparams, planner_hparams, model_dir, policy_dir, random_starts_step_limit, debug_video_path, log_every_steps ): """Evaluates the world model.""" if debug_video_path: debug_video_path = os.path.join(debug_video_path, "0.avi") storage_env = rl_utils.setup_env(...
[ "Evaluates", "the", "world", "model", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/rl/evaluator.py#L375-L400
[ "def", "evaluate_world_model", "(", "agent_type", ",", "loop_hparams", ",", "planner_hparams", ",", "model_dir", ",", "policy_dir", ",", "random_starts_step_limit", ",", "debug_video_path", ",", "log_every_steps", ")", ":", "if", "debug_video_path", ":", "debug_video_pa...
272500b6efe353aeb638d2745ed56e519462ca31
train
evaluate
Evaluate.
tensor2tensor/rl/evaluator.py
def evaluate( loop_hparams, planner_hparams, policy_dir, model_dir, eval_metrics_dir, agent_type, eval_mode, eval_with_learner, log_every_steps, debug_video_path, num_debug_videos=1, random_starts_step_limit=None, report_fn=None, report_metric=None ): """Evaluate.""" if eval_with_learner: assert...
def evaluate( loop_hparams, planner_hparams, policy_dir, model_dir, eval_metrics_dir, agent_type, eval_mode, eval_with_learner, log_every_steps, debug_video_path, num_debug_videos=1, random_starts_step_limit=None, report_fn=None, report_metric=None ): """Evaluate.""" if eval_with_learner: assert...
[ "Evaluate", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/rl/evaluator.py#L403-L461
[ "def", "evaluate", "(", "loop_hparams", ",", "planner_hparams", ",", "policy_dir", ",", "model_dir", ",", "eval_metrics_dir", ",", "agent_type", ",", "eval_mode", ",", "eval_with_learner", ",", "log_every_steps", ",", "debug_video_path", ",", "num_debug_videos", "=", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
get_game_for_worker
Get game for the given worker (directory) id.
tensor2tensor/rl/evaluator.py
def get_game_for_worker(map_name, directory_id): """Get game for the given worker (directory) id.""" if map_name == "v100unfriendly": games = ["chopper_command", "boxing", "asterix", "seaquest"] worker_per_game = 5 elif map_name == "human_nice": games = gym_env.ATARI_GAMES_WITH_HUMAN_SCORE_NICE wo...
def get_game_for_worker(map_name, directory_id): """Get game for the given worker (directory) id.""" if map_name == "v100unfriendly": games = ["chopper_command", "boxing", "asterix", "seaquest"] worker_per_game = 5 elif map_name == "human_nice": games = gym_env.ATARI_GAMES_WITH_HUMAN_SCORE_NICE wo...
[ "Get", "game", "for", "the", "given", "worker", "(", "directory", ")", "id", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/rl/evaluator.py#L464-L477
[ "def", "get_game_for_worker", "(", "map_name", ",", "directory_id", ")", ":", "if", "map_name", "==", "\"v100unfriendly\"", ":", "games", "=", "[", "\"chopper_command\"", ",", "\"boxing\"", ",", "\"asterix\"", ",", "\"seaquest\"", "]", "worker_per_game", "=", "5",...
272500b6efe353aeb638d2745ed56e519462ca31
train
get_open_spaces
Given a representation of the board, returns a list of open spaces.
tensor2tensor/envs/tic_tac_toe_env.py
def get_open_spaces(board): """Given a representation of the board, returns a list of open spaces.""" open_spaces = [] for i in range(3): for j in range(3): if board[i][j] == 0: open_spaces.append(encode_pos(i, j)) return open_spaces
def get_open_spaces(board): """Given a representation of the board, returns a list of open spaces.""" open_spaces = [] for i in range(3): for j in range(3): if board[i][j] == 0: open_spaces.append(encode_pos(i, j)) return open_spaces
[ "Given", "a", "representation", "of", "the", "board", "returns", "a", "list", "of", "open", "spaces", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/envs/tic_tac_toe_env.py#L46-L53
[ "def", "get_open_spaces", "(", "board", ")", ":", "open_spaces", "=", "[", "]", "for", "i", "in", "range", "(", "3", ")", ":", "for", "j", "in", "range", "(", "3", ")", ":", "if", "board", "[", "i", "]", "[", "j", "]", "==", "0", ":", "open_s...
272500b6efe353aeb638d2745ed56e519462ca31
train
get_reward_and_done
Given a representation of the board, returns reward and done.
tensor2tensor/envs/tic_tac_toe_env.py
def get_reward_and_done(board): """Given a representation of the board, returns reward and done.""" # Returns (reward, done) where: # reward: -1 means lost, +1 means win, 0 means draw or continuing. # done: True if the game is over, i.e. someone won or it is a draw. # Sum all rows ... all_sums = [np.sum(bo...
def get_reward_and_done(board): """Given a representation of the board, returns reward and done.""" # Returns (reward, done) where: # reward: -1 means lost, +1 means win, 0 means draw or continuing. # done: True if the game is over, i.e. someone won or it is a draw. # Sum all rows ... all_sums = [np.sum(bo...
[ "Given", "a", "representation", "of", "the", "board", "returns", "reward", "and", "done", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/envs/tic_tac_toe_env.py#L56-L80
[ "def", "get_reward_and_done", "(", "board", ")", ":", "# Returns (reward, done) where:", "# reward: -1 means lost, +1 means win, 0 means draw or continuing.", "# done: True if the game is over, i.e. someone won or it is a draw.", "# Sum all rows ...", "all_sums", "=", "[", "np", ".", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
decode_hparams
Hyperparameters for decoding.
tensor2tensor/utils/decoding.py
def decode_hparams(overrides=""): """Hyperparameters for decoding.""" hp = hparam.HParams( save_images=False, log_results=True, extra_length=100, min_length_ratio=0.0, batch_size=0, beam_size=4, alpha=0.6, eos_penalty=0.0, block_size=0, guess_and_check_top...
def decode_hparams(overrides=""): """Hyperparameters for decoding.""" hp = hparam.HParams( save_images=False, log_results=True, extra_length=100, min_length_ratio=0.0, batch_size=0, beam_size=4, alpha=0.6, eos_penalty=0.0, block_size=0, guess_and_check_top...
[ "Hyperparameters", "for", "decoding", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L47-L101
[ "def", "decode_hparams", "(", "overrides", "=", "\"\"", ")", ":", "hp", "=", "hparam", ".", "HParams", "(", "save_images", "=", "False", ",", "log_results", "=", "True", ",", "extra_length", "=", "100", ",", "min_length_ratio", "=", "0.0", ",", "batch_size...
272500b6efe353aeb638d2745ed56e519462ca31
train
log_decode_results
Log inference results.
tensor2tensor/utils/decoding.py
def log_decode_results(inputs, outputs, problem_name, prediction_idx, inputs_vocab, targets_vocab, targets=None, save_images=False, outp...
def log_decode_results(inputs, outputs, problem_name, prediction_idx, inputs_vocab, targets_vocab, targets=None, save_images=False, outp...
[ "Log", "inference", "results", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L104-L170
[ "def", "log_decode_results", "(", "inputs", ",", "outputs", ",", "problem_name", ",", "prediction_idx", ",", "inputs_vocab", ",", "targets_vocab", ",", "targets", "=", "None", ",", "save_images", "=", "False", ",", "output_dir", "=", "None", ",", "identity_outpu...
272500b6efe353aeb638d2745ed56e519462ca31
train
decode_from_dataset
Perform decoding from dataset.
tensor2tensor/utils/decoding.py
def decode_from_dataset(estimator, problem_name, hparams, decode_hp, decode_to_file=None, dataset_split=None, checkpoint_path=None): """Perform decoding from dataset.""" tf...
def decode_from_dataset(estimator, problem_name, hparams, decode_hp, decode_to_file=None, dataset_split=None, checkpoint_path=None): """Perform decoding from dataset.""" tf...
[ "Perform", "decoding", "from", "dataset", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L173-L242
[ "def", "decode_from_dataset", "(", "estimator", ",", "problem_name", ",", "hparams", ",", "decode_hp", ",", "decode_to_file", "=", "None", ",", "dataset_split", "=", "None", ",", "checkpoint_path", "=", "None", ")", ":", "tf", ".", "logging", ".", "info", "(...
272500b6efe353aeb638d2745ed56e519462ca31
train
decode_once
Decodes once. Args: estimator: tf.estimator.Estimator instance. Used to generate encoded predictions. problem_name: str. Name of problem. hparams: HParams instance. HParams for model training. infer_input_fn: zero-arg function. Input function for estimator. decode_hp: HParams instance. See ...
tensor2tensor/utils/decoding.py
def decode_once(estimator, problem_name, hparams, infer_input_fn, decode_hp, decode_to_file, output_dir, log_results=True, checkpoint_path=None): """Decodes once. Args: estimator: tf....
def decode_once(estimator, problem_name, hparams, infer_input_fn, decode_hp, decode_to_file, output_dir, log_results=True, checkpoint_path=None): """Decodes once. Args: estimator: tf....
[ "Decodes", "once", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L245-L391
[ "def", "decode_once", "(", "estimator", ",", "problem_name", ",", "hparams", ",", "infer_input_fn", ",", "decode_hp", ",", "decode_to_file", ",", "output_dir", ",", "log_results", "=", "True", ",", "checkpoint_path", "=", "None", ")", ":", "# Get the predictions a...
272500b6efe353aeb638d2745ed56e519462ca31
train
decode_from_file
Compute predictions on entries in filename and write them out.
tensor2tensor/utils/decoding.py
def decode_from_file(estimator, filename, hparams, decode_hp, decode_to_file=None, checkpoint_path=None): """Compute predictions on entries in filename and write them out.""" if not decode_hp.batch_size: dec...
def decode_from_file(estimator, filename, hparams, decode_hp, decode_to_file=None, checkpoint_path=None): """Compute predictions on entries in filename and write them out.""" if not decode_hp.batch_size: dec...
[ "Compute", "predictions", "on", "entries", "in", "filename", "and", "write", "them", "out", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L394-L559
[ "def", "decode_from_file", "(", "estimator", ",", "filename", ",", "hparams", ",", "decode_hp", ",", "decode_to_file", "=", "None", ",", "checkpoint_path", "=", "None", ")", ":", "if", "not", "decode_hp", ".", "batch_size", ":", "decode_hp", ".", "batch_size",...
272500b6efe353aeb638d2745ed56e519462ca31
train
_decode_filename
Generates decode filename. Args: base_filename: A string, base of the decode filename. problem_name: A string, name of the problem. decode_hp: HParams for decoding. Returns: A string, produced decode filename.
tensor2tensor/utils/decoding.py
def _decode_filename(base_filename, problem_name, decode_hp): """Generates decode filename. Args: base_filename: A string, base of the decode filename. problem_name: A string, name of the problem. decode_hp: HParams for decoding. Returns: A string, produced decode filename. """ if decode_hp....
def _decode_filename(base_filename, problem_name, decode_hp): """Generates decode filename. Args: base_filename: A string, base of the decode filename. problem_name: A string, name of the problem. decode_hp: HParams for decoding. Returns: A string, produced decode filename. """ if decode_hp....
[ "Generates", "decode", "filename", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L573-L598
[ "def", "_decode_filename", "(", "base_filename", ",", "problem_name", ",", "decode_hp", ")", ":", "if", "decode_hp", ".", "shards", ">", "1", ":", "base_filename", "=", "_add_shard_to_filename", "(", "base_filename", ",", "decode_hp", ")", "if", "(", "\"beam{bea...
272500b6efe353aeb638d2745ed56e519462ca31
train
make_input_fn_from_generator
Use py_func to yield elements from the given generator.
tensor2tensor/utils/decoding.py
def make_input_fn_from_generator(gen): """Use py_func to yield elements from the given generator.""" first_ex = six.next(gen) flattened = tf.contrib.framework.nest.flatten(first_ex) types = [t.dtype for t in flattened] shapes = [[None] * len(t.shape) for t in flattened] first_ex_list = [first_ex] def py_...
def make_input_fn_from_generator(gen): """Use py_func to yield elements from the given generator.""" first_ex = six.next(gen) flattened = tf.contrib.framework.nest.flatten(first_ex) types = [t.dtype for t in flattened] shapes = [[None] * len(t.shape) for t in flattened] first_ex_list = [first_ex] def py_...
[ "Use", "py_func", "to", "yield", "elements", "from", "the", "given", "generator", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L601-L622
[ "def", "make_input_fn_from_generator", "(", "gen", ")", ":", "first_ex", "=", "six", ".", "next", "(", "gen", ")", "flattened", "=", "tf", ".", "contrib", ".", "framework", ".", "nest", ".", "flatten", "(", "first_ex", ")", "types", "=", "[", "t", ".",...
272500b6efe353aeb638d2745ed56e519462ca31
train
decode_interactively
Interactive decoding.
tensor2tensor/utils/decoding.py
def decode_interactively(estimator, hparams, decode_hp, checkpoint_path=None): """Interactive decoding.""" is_image = "image" in hparams.problem.name is_text2class = isinstance(hparams.problem, text_problems.Text2ClassProblem) skip_eos_postprocess = ( is_image or is_text2clas...
def decode_interactively(estimator, hparams, decode_hp, checkpoint_path=None): """Interactive decoding.""" is_image = "image" in hparams.problem.name is_text2class = isinstance(hparams.problem, text_problems.Text2ClassProblem) skip_eos_postprocess = ( is_image or is_text2clas...
[ "Interactive", "decoding", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L625-L666
[ "def", "decode_interactively", "(", "estimator", ",", "hparams", ",", "decode_hp", ",", "checkpoint_path", "=", "None", ")", ":", "is_image", "=", "\"image\"", "in", "hparams", ".", "problem", ".", "name", "is_text2class", "=", "isinstance", "(", "hparams", "....
272500b6efe353aeb638d2745ed56e519462ca31
train
_decode_batch_input_fn
Generator to produce batches of inputs.
tensor2tensor/utils/decoding.py
def _decode_batch_input_fn(num_decode_batches, sorted_inputs, vocabulary, batch_size, max_input_size, task_id=-1, has_input=True): """Generator to produce batches of inputs.""" tf.logging.info(" batch %d" % num_decode_batches) for b in range(num_decode_batches...
def _decode_batch_input_fn(num_decode_batches, sorted_inputs, vocabulary, batch_size, max_input_size, task_id=-1, has_input=True): """Generator to produce batches of inputs.""" tf.logging.info(" batch %d" % num_decode_batches) for b in range(num_decode_batches...
[ "Generator", "to", "produce", "batches", "of", "inputs", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L669-L697
[ "def", "_decode_batch_input_fn", "(", "num_decode_batches", ",", "sorted_inputs", ",", "vocabulary", ",", "batch_size", ",", "max_input_size", ",", "task_id", "=", "-", "1", ",", "has_input", "=", "True", ")", ":", "tf", ".", "logging", ".", "info", "(", "\"...
272500b6efe353aeb638d2745ed56e519462ca31
train
_interactive_input_fn
Generator that reads from the terminal and yields "interactive inputs". Due to temporary limitations in tf.learn, if we don't want to reload the whole graph, then we are stuck encoding all of the input as one fixed-size numpy array. We yield int32 arrays with shape [const_array_size]. The format is: [num_s...
tensor2tensor/utils/decoding.py
def _interactive_input_fn(hparams, decode_hp): """Generator that reads from the terminal and yields "interactive inputs". Due to temporary limitations in tf.learn, if we don't want to reload the whole graph, then we are stuck encoding all of the input as one fixed-size numpy array. We yield int32 arrays wit...
def _interactive_input_fn(hparams, decode_hp): """Generator that reads from the terminal and yields "interactive inputs". Due to temporary limitations in tf.learn, if we don't want to reload the whole graph, then we are stuck encoding all of the input as one fixed-size numpy array. We yield int32 arrays wit...
[ "Generator", "that", "reads", "from", "the", "terminal", "and", "yields", "interactive", "inputs", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L700-L779
[ "def", "_interactive_input_fn", "(", "hparams", ",", "decode_hp", ")", ":", "num_samples", "=", "decode_hp", ".", "num_samples", "if", "decode_hp", ".", "num_samples", ">", "0", "else", "1", "decode_length", "=", "decode_hp", ".", "extra_length", "input_type", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
save_video
Save frames of the videos into files.
tensor2tensor/utils/decoding.py
def save_video(video, save_path_template): """Save frames of the videos into files.""" try: from PIL import Image # pylint: disable=g-import-not-at-top except ImportError as e: tf.logging.warning( "Showing and saving an image requires PIL library to be " "installed: %s", e) raise NotI...
def save_video(video, save_path_template): """Save frames of the videos into files.""" try: from PIL import Image # pylint: disable=g-import-not-at-top except ImportError as e: tf.logging.warning( "Showing and saving an image requires PIL library to be " "installed: %s", e) raise NotI...
[ "Save", "frames", "of", "the", "videos", "into", "files", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L782-L795
[ "def", "save_video", "(", "video", ",", "save_path_template", ")", ":", "try", ":", "from", "PIL", "import", "Image", "# pylint: disable=g-import-not-at-top", "except", "ImportError", "as", "e", ":", "tf", ".", "logging", ".", "warning", "(", "\"Showing and saving...
272500b6efe353aeb638d2745ed56e519462ca31
train
show_and_save_image
Shows an image using matplotlib and saves it.
tensor2tensor/utils/decoding.py
def show_and_save_image(img, save_path): """Shows an image using matplotlib and saves it.""" try: import matplotlib.pyplot as plt # pylint: disable=g-import-not-at-top except ImportError as e: tf.logging.warning( "Showing and saving an image requires matplotlib to be " "installed: %s", e)...
def show_and_save_image(img, save_path): """Shows an image using matplotlib and saves it.""" try: import matplotlib.pyplot as plt # pylint: disable=g-import-not-at-top except ImportError as e: tf.logging.warning( "Showing and saving an image requires matplotlib to be " "installed: %s", e)...
[ "Shows", "an", "image", "using", "matplotlib", "and", "saves", "it", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L798-L809
[ "def", "show_and_save_image", "(", "img", ",", "save_path", ")", ":", "try", ":", "import", "matplotlib", ".", "pyplot", "as", "plt", "# pylint: disable=g-import-not-at-top", "except", "ImportError", "as", "e", ":", "tf", ".", "logging", ".", "warning", "(", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
_get_language_modeling_inputs
Read a file of partial texts to continue. The purpose of append_space_to_final_punctionation is that SubwordTokenizer groups punctuation and the ensuing space in the same token. Adding a space causes the token to be completed. Args: filename: a string delimiter: a string repeat: an integer - we r...
tensor2tensor/utils/decoding.py
def _get_language_modeling_inputs(filename, delimiter="\n", repeat=1, append_space_to_final_punctionation=True): """Read a file of partial texts to continue. The purpose of append_space_to_final_punctionation is t...
def _get_language_modeling_inputs(filename, delimiter="\n", repeat=1, append_space_to_final_punctionation=True): """Read a file of partial texts to continue. The purpose of append_space_to_final_punctionation is t...
[ "Read", "a", "file", "of", "partial", "texts", "to", "continue", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L812-L840
[ "def", "_get_language_modeling_inputs", "(", "filename", ",", "delimiter", "=", "\"\\n\"", ",", "repeat", "=", "1", ",", "append_space_to_final_punctionation", "=", "True", ")", ":", "with", "tf", ".", "gfile", ".", "Open", "(", "filename", ")", "as", "f", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
_get_sorted_inputs
Returning inputs sorted according to decreasing length. This causes inputs of similar lengths to be processed in the same batch, facilitating early stopping for short sequences. Longer sequences are sorted first so that if you're going to get OOMs, you'll see it in the first batch. Args: filename: path...
tensor2tensor/utils/decoding.py
def _get_sorted_inputs(filename, delimiter="\n"): """Returning inputs sorted according to decreasing length. This causes inputs of similar lengths to be processed in the same batch, facilitating early stopping for short sequences. Longer sequences are sorted first so that if you're going to get OOMs, you'll...
def _get_sorted_inputs(filename, delimiter="\n"): """Returning inputs sorted according to decreasing length. This causes inputs of similar lengths to be processed in the same batch, facilitating early stopping for short sequences. Longer sequences are sorted first so that if you're going to get OOMs, you'll...
[ "Returning", "inputs", "sorted", "according", "to", "decreasing", "length", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L843-L876
[ "def", "_get_sorted_inputs", "(", "filename", ",", "delimiter", "=", "\"\\n\"", ")", ":", "tf", ".", "logging", ".", "info", "(", "\"Getting sorted inputs\"", ")", "with", "tf", ".", "gfile", ".", "Open", "(", "filename", ")", "as", "f", ":", "text", "="...
272500b6efe353aeb638d2745ed56e519462ca31
train
_save_until_eos
Strips everything after the first <EOS> token, which is normally 1.
tensor2tensor/utils/decoding.py
def _save_until_eos(ids, skip=False): """Strips everything after the first <EOS> token, which is normally 1.""" ids = ids.flatten() if skip: return ids try: index = list(ids).index(text_encoder.EOS_ID) return ids[0:index] except ValueError: # No EOS_ID: return the array as-is. return ids
def _save_until_eos(ids, skip=False): """Strips everything after the first <EOS> token, which is normally 1.""" ids = ids.flatten() if skip: return ids try: index = list(ids).index(text_encoder.EOS_ID) return ids[0:index] except ValueError: # No EOS_ID: return the array as-is. return ids
[ "Strips", "everything", "after", "the", "first", "<EOS", ">", "token", "which", "is", "normally", "1", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L879-L889
[ "def", "_save_until_eos", "(", "ids", ",", "skip", "=", "False", ")", ":", "ids", "=", "ids", ".", "flatten", "(", ")", "if", "skip", ":", "return", "ids", "try", ":", "index", "=", "list", "(", "ids", ")", ".", "index", "(", "text_encoder", ".", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
_interactive_input_tensor_to_features_dict
Convert the interactive input format (see above) to a dictionary. Args: feature_map: dict with inputs. hparams: model hyperparameters Returns: a features dictionary, as expected by the decoder.
tensor2tensor/utils/decoding.py
def _interactive_input_tensor_to_features_dict(feature_map, hparams): """Convert the interactive input format (see above) to a dictionary. Args: feature_map: dict with inputs. hparams: model hyperparameters Returns: a features dictionary, as expected by the decoder. """ inputs = tf.convert_to_te...
def _interactive_input_tensor_to_features_dict(feature_map, hparams): """Convert the interactive input format (see above) to a dictionary. Args: feature_map: dict with inputs. hparams: model hyperparameters Returns: a features dictionary, as expected by the decoder. """ inputs = tf.convert_to_te...
[ "Convert", "the", "interactive", "input", "format", "(", "see", "above", ")", "to", "a", "dictionary", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L892-L930
[ "def", "_interactive_input_tensor_to_features_dict", "(", "feature_map", ",", "hparams", ")", ":", "inputs", "=", "tf", ".", "convert_to_tensor", "(", "feature_map", "[", "\"inputs\"", "]", ")", "input_is_image", "=", "False", "if", "len", "(", "inputs", ".", "g...
272500b6efe353aeb638d2745ed56e519462ca31
train
_decode_input_tensor_to_features_dict
Convert the interactive input format (see above) to a dictionary. Args: feature_map: dict with inputs. hparams: model hyperparameters Returns: a features dictionary, as expected by the decoder.
tensor2tensor/utils/decoding.py
def _decode_input_tensor_to_features_dict(feature_map, hparams): """Convert the interactive input format (see above) to a dictionary. Args: feature_map: dict with inputs. hparams: model hyperparameters Returns: a features dictionary, as expected by the decoder. """ inputs = tf.convert_to_tensor(...
def _decode_input_tensor_to_features_dict(feature_map, hparams): """Convert the interactive input format (see above) to a dictionary. Args: feature_map: dict with inputs. hparams: model hyperparameters Returns: a features dictionary, as expected by the decoder. """ inputs = tf.convert_to_tensor(...
[ "Convert", "the", "interactive", "input", "format", "(", "see", "above", ")", "to", "a", "dictionary", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L933-L960
[ "def", "_decode_input_tensor_to_features_dict", "(", "feature_map", ",", "hparams", ")", ":", "inputs", "=", "tf", ".", "convert_to_tensor", "(", "feature_map", "[", "\"inputs\"", "]", ")", "input_is_image", "=", "False", "x", "=", "inputs", "p_hparams", "=", "h...
272500b6efe353aeb638d2745ed56e519462ca31
train
run_postdecode_hooks
Run hooks after decodes have run.
tensor2tensor/utils/decoding.py
def run_postdecode_hooks(decode_hook_args, dataset_split): """Run hooks after decodes have run.""" hooks = decode_hook_args.problem.decode_hooks if not hooks: return global_step = latest_checkpoint_step(decode_hook_args.estimator.model_dir) if global_step is None: tf.logging.info( "Skipping de...
def run_postdecode_hooks(decode_hook_args, dataset_split): """Run hooks after decodes have run.""" hooks = decode_hook_args.problem.decode_hooks if not hooks: return global_step = latest_checkpoint_step(decode_hook_args.estimator.model_dir) if global_step is None: tf.logging.info( "Skipping de...
[ "Run", "hooks", "after", "decodes", "have", "run", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/decoding.py#L982-L1008
[ "def", "run_postdecode_hooks", "(", "decode_hook_args", ",", "dataset_split", ")", ":", "hooks", "=", "decode_hook_args", ".", "problem", ".", "decode_hooks", "if", "not", "hooks", ":", "return", "global_step", "=", "latest_checkpoint_step", "(", "decode_hook_args", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
StyleTransferProblemShakespeare.dataset_splits
Splits of data to produce and number of output shards for each.
tensor2tensor/data_generators/style_transfer.py
def dataset_splits(self): """Splits of data to produce and number of output shards for each.""" return [{ "split": problem.DatasetSplit.TRAIN, "shards": _TRAIN_SHARDS, }, { "split": problem.DatasetSplit.EVAL, "shards": _DEV_SHARDS, }]
def dataset_splits(self): """Splits of data to produce and number of output shards for each.""" return [{ "split": problem.DatasetSplit.TRAIN, "shards": _TRAIN_SHARDS, }, { "split": problem.DatasetSplit.EVAL, "shards": _DEV_SHARDS, }]
[ "Splits", "of", "data", "to", "produce", "and", "number", "of", "output", "shards", "for", "each", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/style_transfer.py#L87-L95
[ "def", "dataset_splits", "(", "self", ")", ":", "return", "[", "{", "\"split\"", ":", "problem", ".", "DatasetSplit", ".", "TRAIN", ",", "\"shards\"", ":", "_TRAIN_SHARDS", ",", "}", ",", "{", "\"split\"", ":", "problem", ".", "DatasetSplit", ".", "EVAL", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
local_attention1d_spatial_decoder
Image Transformer decoder with local1D spatial layers.
tensor2tensor/models/mtf_image_transformer.py
def local_attention1d_spatial_decoder(x, kv_dim, heads_dim, feedforward_dim, hparams): """Image Transformer decoder with local1D spatial layers.""" batch_dim, length_dim, model_dim = x.shape.dims blocks_w_dim = mtf.Dimension("blocksw", hparams.block_length) num_w_blocks_dim...
def local_attention1d_spatial_decoder(x, kv_dim, heads_dim, feedforward_dim, hparams): """Image Transformer decoder with local1D spatial layers.""" batch_dim, length_dim, model_dim = x.shape.dims blocks_w_dim = mtf.Dimension("blocksw", hparams.block_length) num_w_blocks_dim...
[ "Image", "Transformer", "decoder", "with", "local1D", "spatial", "layers", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L252-L283
[ "def", "local_attention1d_spatial_decoder", "(", "x", ",", "kv_dim", ",", "heads_dim", ",", "feedforward_dim", ",", "hparams", ")", ":", "batch_dim", ",", "length_dim", ",", "model_dim", "=", "x", ".", "shape", ".", "dims", "blocks_w_dim", "=", "mtf", ".", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
local_attention2d_spatial_decoder
Image Transformer decoder with local2D spatial layers.
tensor2tensor/models/mtf_image_transformer.py
def local_attention2d_spatial_decoder(x, kv_dim, heads_dim, feedforward_dim, hparams): """Image Transformer decoder with local2D spatial layers.""" batch_dim, length_dim, model_dim = x.shape.dims blocks_h_dim = mtf.Dimension("blocksh", hparams.block_height) blocks_w_dim = m...
def local_attention2d_spatial_decoder(x, kv_dim, heads_dim, feedforward_dim, hparams): """Image Transformer decoder with local2D spatial layers.""" batch_dim, length_dim, model_dim = x.shape.dims blocks_h_dim = mtf.Dimension("blocksh", hparams.block_height) blocks_w_dim = m...
[ "Image", "Transformer", "decoder", "with", "local2D", "spatial", "layers", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L286-L331
[ "def", "local_attention2d_spatial_decoder", "(", "x", ",", "kv_dim", ",", "heads_dim", ",", "feedforward_dim", ",", "hparams", ")", ":", "batch_dim", ",", "length_dim", ",", "model_dim", "=", "x", ".", "shape", ".", "dims", "blocks_h_dim", "=", "mtf", ".", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
local_attention1d_masked_decoder
Image Transformer decoder with local1D masked layers.
tensor2tensor/models/mtf_image_transformer.py
def local_attention1d_masked_decoder(x, kv_dim, heads_dim, feedforward_dim, hparams): """Image Transformer decoder with local1D masked layers.""" print(x) _, length_dim, model_dim = x.shape.dims for layer in range(hparams.num_decoder_layers): layer_name = "decoder_layer_...
def local_attention1d_masked_decoder(x, kv_dim, heads_dim, feedforward_dim, hparams): """Image Transformer decoder with local1D masked layers.""" print(x) _, length_dim, model_dim = x.shape.dims for layer in range(hparams.num_decoder_layers): layer_name = "decoder_layer_...
[ "Image", "Transformer", "decoder", "with", "local1D", "masked", "layers", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L334-L362
[ "def", "local_attention1d_masked_decoder", "(", "x", ",", "kv_dim", ",", "heads_dim", ",", "feedforward_dim", ",", "hparams", ")", ":", "print", "(", "x", ")", "_", ",", "length_dim", ",", "model_dim", "=", "x", ".", "shape", ".", "dims", "for", "layer", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_base
Set of hyperparameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_base(): """Set of hyperparameters.""" hparams = common_hparams.basic_params1() hparams.no_data_parallelism = True hparams.use_fixed_batch_size = True hparams.batch_size = 1 hparams.max_length = 3072 hparams.hidden_size = 256 hparams.label_smoothing = 0.0 # 8-way model-paralle...
def mtf_image_transformer_base(): """Set of hyperparameters.""" hparams = common_hparams.basic_params1() hparams.no_data_parallelism = True hparams.use_fixed_batch_size = True hparams.batch_size = 1 hparams.max_length = 3072 hparams.hidden_size = 256 hparams.label_smoothing = 0.0 # 8-way model-paralle...
[ "Set", "of", "hyperparameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L366-L412
[ "def", "mtf_image_transformer_base", "(", ")", ":", "hparams", "=", "common_hparams", ".", "basic_params1", "(", ")", "hparams", ".", "no_data_parallelism", "=", "True", "hparams", ".", "use_fixed_batch_size", "=", "True", "hparams", ".", "batch_size", "=", "1", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_tiny
Catch bugs locally...
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_tiny(): """Catch bugs locally...""" hparams = mtf_image_transformer_base() hparams.hidden_size = 128 hparams.d_ff = 256 hparams.batch_size = 4 hparams.num_encoder_layers = 1 hparams.num_decoder_layers = 4 hparams.num_heads = 4 hparams.attention_key_size = 128 hparams.attent...
def mtf_image_transformer_tiny(): """Catch bugs locally...""" hparams = mtf_image_transformer_base() hparams.hidden_size = 128 hparams.d_ff = 256 hparams.batch_size = 4 hparams.num_encoder_layers = 1 hparams.num_decoder_layers = 4 hparams.num_heads = 4 hparams.attention_key_size = 128 hparams.attent...
[ "Catch", "bugs", "locally", "..." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L416-L431
[ "def", "mtf_image_transformer_tiny", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base", "(", ")", "hparams", ".", "hidden_size", "=", "128", "hparams", ".", "d_ff", "=", "256", "hparams", ".", "batch_size", "=", "4", "hparams", ".", "num_encoder_layers...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_single
Small single parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_single(): """Small single parameters.""" hparams = mtf_image_transformer_tiny() hparams.mesh_shape = "" hparams.layout = "" hparams.hidden_size = 32 hparams.filter_size = 32 hparams.batch_size = 1 hparams.num_encoder_layers = 1 hparams.num_decoder_layers = 1 hparams.num_hea...
def mtf_image_transformer_single(): """Small single parameters.""" hparams = mtf_image_transformer_tiny() hparams.mesh_shape = "" hparams.layout = "" hparams.hidden_size = 32 hparams.filter_size = 32 hparams.batch_size = 1 hparams.num_encoder_layers = 1 hparams.num_decoder_layers = 1 hparams.num_hea...
[ "Small", "single", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L435-L449
[ "def", "mtf_image_transformer_single", "(", ")", ":", "hparams", "=", "mtf_image_transformer_tiny", "(", ")", "hparams", ".", "mesh_shape", "=", "\"\"", "hparams", ".", "layout", "=", "\"\"", "hparams", ".", "hidden_size", "=", "32", "hparams", ".", "filter_size...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_base_single
Small single parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_base_single(): """Small single parameters.""" hparams = mtf_image_transformer_base() hparams.num_decoder_layers = 6 hparams.filter_size = 256 hparams.block_length = 128 hparams.mesh_shape = "" hparams.layout = "" return hparams
def mtf_image_transformer_base_single(): """Small single parameters.""" hparams = mtf_image_transformer_base() hparams.num_decoder_layers = 6 hparams.filter_size = 256 hparams.block_length = 128 hparams.mesh_shape = "" hparams.layout = "" return hparams
[ "Small", "single", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L453-L461
[ "def", "mtf_image_transformer_base_single", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base", "(", ")", "hparams", ".", "num_decoder_layers", "=", "6", "hparams", ".", "filter_size", "=", "256", "hparams", ".", "block_length", "=", "128", "hparams", "."...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_tiny_spatial1d
Small single parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_tiny_spatial1d(): """Small single parameters.""" hparams = mtf_image_transformer_tiny() hparams.num_decoder_layers = 6 hparams.filter_size = 128 hparams.block_height = 8 hparams.block_width = 8 hparams.attention_type = "local1d_spatial" hparams.mesh_shape = "" hparams.layout ...
def mtf_image_transformer_tiny_spatial1d(): """Small single parameters.""" hparams = mtf_image_transformer_tiny() hparams.num_decoder_layers = 6 hparams.filter_size = 128 hparams.block_height = 8 hparams.block_width = 8 hparams.attention_type = "local1d_spatial" hparams.mesh_shape = "" hparams.layout ...
[ "Small", "single", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L465-L475
[ "def", "mtf_image_transformer_tiny_spatial1d", "(", ")", ":", "hparams", "=", "mtf_image_transformer_tiny", "(", ")", "hparams", ".", "num_decoder_layers", "=", "6", "hparams", ".", "filter_size", "=", "128", "hparams", ".", "block_height", "=", "8", "hparams", "....
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_base_cifar
Data parallel CIFAR parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_base_cifar(): """Data parallel CIFAR parameters.""" hparams = mtf_image_transformer_base() hparams.mesh_shape = "batch:8" hparams.layout = "batch:batch" hparams.learning_rate_decay_steps = 13600 # one epoch hparams.batch_size = 32 hparams.num_heads = 4 hparams.num_decoder_laye...
def mtf_image_transformer_base_cifar(): """Data parallel CIFAR parameters.""" hparams = mtf_image_transformer_base() hparams.mesh_shape = "batch:8" hparams.layout = "batch:batch" hparams.learning_rate_decay_steps = 13600 # one epoch hparams.batch_size = 32 hparams.num_heads = 4 hparams.num_decoder_laye...
[ "Data", "parallel", "CIFAR", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L493-L510
[ "def", "mtf_image_transformer_base_cifar", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base", "(", ")", "hparams", ".", "mesh_shape", "=", "\"batch:8\"", "hparams", ".", "layout", "=", "\"batch:batch\"", "hparams", ".", "learning_rate_decay_steps", "=", "136...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_cifar_4x
Data parallel CIFAR parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_cifar_4x(): """Data parallel CIFAR parameters.""" hparams = mtf_image_transformer_base_cifar() hparams.mesh_shape = "batch:32" hparams.layout = "batch:batch" hparams.batch_size = 128 return hparams
def mtf_image_transformer_cifar_4x(): """Data parallel CIFAR parameters.""" hparams = mtf_image_transformer_base_cifar() hparams.mesh_shape = "batch:32" hparams.layout = "batch:batch" hparams.batch_size = 128 return hparams
[ "Data", "parallel", "CIFAR", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L514-L520
[ "def", "mtf_image_transformer_cifar_4x", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base_cifar", "(", ")", "hparams", ".", "mesh_shape", "=", "\"batch:32\"", "hparams", ".", "layout", "=", "\"batch:batch\"", "hparams", ".", "batch_size", "=", "128", "retu...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_cifar_mp_4x
Data parallel CIFAR parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_cifar_mp_4x(): """Data parallel CIFAR parameters.""" hparams = mtf_image_transformer_base_cifar() hparams.mesh_shape = "model:4;batch:8" hparams.layout = "batch:batch;d_ff:model;heads:model" hparams.batch_size = 32 hparams.num_heads = 8 hparams.d_ff = 8192 return hparams
def mtf_image_transformer_cifar_mp_4x(): """Data parallel CIFAR parameters.""" hparams = mtf_image_transformer_base_cifar() hparams.mesh_shape = "model:4;batch:8" hparams.layout = "batch:batch;d_ff:model;heads:model" hparams.batch_size = 32 hparams.num_heads = 8 hparams.d_ff = 8192 return hparams
[ "Data", "parallel", "CIFAR", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L524-L532
[ "def", "mtf_image_transformer_cifar_mp_4x", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base_cifar", "(", ")", "hparams", ".", "mesh_shape", "=", "\"model:4;batch:8\"", "hparams", ".", "layout", "=", "\"batch:batch;d_ff:model;heads:model\"", "hparams", ".", "bat...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_base_imagenet
Data parallel CIFAR parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_base_imagenet(): """Data parallel CIFAR parameters.""" hparams = mtf_image_transformer_base_cifar() hparams.mesh_shape = "batch:32" hparams.layout = "batch:batch" hparams.batch_size = 128 hparams.d_ff = 2048 hparams.hidden_size = 512 hparams.num_decoder_layers = 12 hparams.le...
def mtf_image_transformer_base_imagenet(): """Data parallel CIFAR parameters.""" hparams = mtf_image_transformer_base_cifar() hparams.mesh_shape = "batch:32" hparams.layout = "batch:batch" hparams.batch_size = 128 hparams.d_ff = 2048 hparams.hidden_size = 512 hparams.num_decoder_layers = 12 hparams.le...
[ "Data", "parallel", "CIFAR", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L536-L551
[ "def", "mtf_image_transformer_base_imagenet", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base_cifar", "(", ")", "hparams", ".", "mesh_shape", "=", "\"batch:32\"", "hparams", ".", "layout", "=", "\"batch:batch\"", "hparams", ".", "batch_size", "=", "128", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_base_imagenet_mp
Model parallel ImageNet parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_base_imagenet_mp(): """Model parallel ImageNet parameters.""" hparams = mtf_image_transformer_base_imagenet() hparams.mesh_shape = "model:4;batch:8" hparams.layout = "batch:batch;d_ff:model;heads:model" hparams.batch_size = 32 hparams.num_heads = 8 hparams.d_ff = 8192 hparams.l...
def mtf_image_transformer_base_imagenet_mp(): """Model parallel ImageNet parameters.""" hparams = mtf_image_transformer_base_imagenet() hparams.mesh_shape = "model:4;batch:8" hparams.layout = "batch:batch;d_ff:model;heads:model" hparams.batch_size = 32 hparams.num_heads = 8 hparams.d_ff = 8192 hparams.l...
[ "Model", "parallel", "ImageNet", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L555-L565
[ "def", "mtf_image_transformer_base_imagenet_mp", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base_imagenet", "(", ")", "hparams", ".", "mesh_shape", "=", "\"model:4;batch:8\"", "hparams", ".", "layout", "=", "\"batch:batch;d_ff:model;heads:model\"", "hparams", "."...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_base_imagenet_mp128
Model parallel ImageNet parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_base_imagenet_mp128(): """Model parallel ImageNet parameters.""" hparams = mtf_image_transformer_base_imagenet() hparams.mesh_shape = "model:8;batch:4" hparams.layout = "batch:batch;d_ff:model;heads:model" hparams.batch_size = 8 hparams.img_len = 128 hparams.block_length = 128 ...
def mtf_image_transformer_base_imagenet_mp128(): """Model parallel ImageNet parameters.""" hparams = mtf_image_transformer_base_imagenet() hparams.mesh_shape = "model:8;batch:4" hparams.layout = "batch:batch;d_ff:model;heads:model" hparams.batch_size = 8 hparams.img_len = 128 hparams.block_length = 128 ...
[ "Model", "parallel", "ImageNet", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L569-L583
[ "def", "mtf_image_transformer_base_imagenet_mp128", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base_imagenet", "(", ")", "hparams", ".", "mesh_shape", "=", "\"model:8;batch:4\"", "hparams", ".", "layout", "=", "\"batch:batch;d_ff:model;heads:model\"", "hparams", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_base_imagenet_mp_sp
Model parallel ImageNet parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_base_imagenet_mp_sp(): """Model parallel ImageNet parameters.""" hparams = mtf_image_transformer_base_imagenet_mp128() hparams.mesh_shape = "model:8;batch:4" hparams.layout = "batch:batch;d_ff:model;num_wblocks:model" hparams.batch_size = 8 hparams.img_len = 128 hparams.block_len...
def mtf_image_transformer_base_imagenet_mp_sp(): """Model parallel ImageNet parameters.""" hparams = mtf_image_transformer_base_imagenet_mp128() hparams.mesh_shape = "model:8;batch:4" hparams.layout = "batch:batch;d_ff:model;num_wblocks:model" hparams.batch_size = 8 hparams.img_len = 128 hparams.block_len...
[ "Model", "parallel", "ImageNet", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L587-L596
[ "def", "mtf_image_transformer_base_imagenet_mp_sp", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base_imagenet_mp128", "(", ")", "hparams", ".", "mesh_shape", "=", "\"model:8;batch:4\"", "hparams", ".", "layout", "=", "\"batch:batch;d_ff:model;num_wblocks:model\"", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
mtf_image_transformer_base_imagenet_mp64
Model parallel ImageNet parameters.
tensor2tensor/models/mtf_image_transformer.py
def mtf_image_transformer_base_imagenet_mp64(): """Model parallel ImageNet parameters.""" hparams = mtf_image_transformer_base_imagenet() hparams.mesh_shape = "model:8;batch:4" hparams.layout = "batch:batch;d_ff:model;heads:model" hparams.batch_size = 8 hparams.img_len = 64 hparams.num_decoder_layers = 8 ...
def mtf_image_transformer_base_imagenet_mp64(): """Model parallel ImageNet parameters.""" hparams = mtf_image_transformer_base_imagenet() hparams.mesh_shape = "model:8;batch:4" hparams.layout = "batch:batch;d_ff:model;heads:model" hparams.batch_size = 8 hparams.img_len = 64 hparams.num_decoder_layers = 8 ...
[ "Model", "parallel", "ImageNet", "parameters", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/mtf_image_transformer.py#L600-L608
[ "def", "mtf_image_transformer_base_imagenet_mp64", "(", ")", ":", "hparams", "=", "mtf_image_transformer_base_imagenet", "(", ")", "hparams", ".", "mesh_shape", "=", "\"model:8;batch:4\"", "hparams", ".", "layout", "=", "\"batch:batch;d_ff:model;heads:model\"", "hparams", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
create_degrees
Returns a list of degree vectors, one for each input and hidden layer. A unit with degree d can only receive input from units with degree < d. Output units always have the same degree as their associated input unit. Args: input_dim: Number of inputs. hidden_dims: list with the number of hidden units per...
tensor2tensor/layers/reversible_layers.py
def create_degrees(input_dim, hidden_dims, input_order='left-to-right', hidden_order='left-to-right'): """Returns a list of degree vectors, one for each input and hidden layer. A unit with degree d can only receive input from units with degree < d. Output ...
def create_degrees(input_dim, hidden_dims, input_order='left-to-right', hidden_order='left-to-right'): """Returns a list of degree vectors, one for each input and hidden layer. A unit with degree d can only receive input from units with degree < d. Output ...
[ "Returns", "a", "list", "of", "degree", "vectors", "one", "for", "each", "input", "and", "hidden", "layer", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/reversible_layers.py#L218-L269
[ "def", "create_degrees", "(", "input_dim", ",", "hidden_dims", ",", "input_order", "=", "'left-to-right'", ",", "hidden_order", "=", "'left-to-right'", ")", ":", "if", "(", "isinstance", "(", "input_order", ",", "str", ")", "and", "input_order", "not", "in", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
create_masks
Returns a list of binary mask matrices respecting autoregressive ordering. Args: input_dim: Number of inputs. hidden_dims: list with the number of hidden units per layer. It does not include the output layer; those number of units will always be set to input_dim downstream. Each hidden unit size ...
tensor2tensor/layers/reversible_layers.py
def create_masks(input_dim, hidden_dims, input_order='left-to-right', hidden_order='left-to-right'): """Returns a list of binary mask matrices respecting autoregressive ordering. Args: input_dim: Number of inputs. hidden_dims: list with the number of hidde...
def create_masks(input_dim, hidden_dims, input_order='left-to-right', hidden_order='left-to-right'): """Returns a list of binary mask matrices respecting autoregressive ordering. Args: input_dim: Number of inputs. hidden_dims: list with the number of hidde...
[ "Returns", "a", "list", "of", "binary", "mask", "matrices", "respecting", "autoregressive", "ordering", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/reversible_layers.py#L272-L302
[ "def", "create_masks", "(", "input_dim", ",", "hidden_dims", ",", "input_order", "=", "'left-to-right'", ",", "hidden_order", "=", "'left-to-right'", ")", ":", "degrees", "=", "create_degrees", "(", "input_dim", ",", "hidden_dims", ",", "input_order", ",", "hidden...
272500b6efe353aeb638d2745ed56e519462ca31
train
sinkhorn
Performs incomplete Sinkhorn normalization to inputs. By a theorem by Sinkhorn and Knopp [1], a sufficiently well-behaved matrix with positive entries can be turned into a doubly-stochastic matrix (i.e. its rows and columns add up to one) via the succesive row and column normalization. -To ensure positivity...
tensor2tensor/layers/reversible_layers.py
def sinkhorn(inputs, n_iters=20): """Performs incomplete Sinkhorn normalization to inputs. By a theorem by Sinkhorn and Knopp [1], a sufficiently well-behaved matrix with positive entries can be turned into a doubly-stochastic matrix (i.e. its rows and columns add up to one) via the succesive row and column ...
def sinkhorn(inputs, n_iters=20): """Performs incomplete Sinkhorn normalization to inputs. By a theorem by Sinkhorn and Knopp [1], a sufficiently well-behaved matrix with positive entries can be turned into a doubly-stochastic matrix (i.e. its rows and columns add up to one) via the succesive row and column ...
[ "Performs", "incomplete", "Sinkhorn", "normalization", "to", "inputs", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/reversible_layers.py#L319-L358
[ "def", "sinkhorn", "(", "inputs", ",", "n_iters", "=", "20", ")", ":", "vocab_size", "=", "tf", ".", "shape", "(", "inputs", ")", "[", "-", "1", "]", "log_alpha", "=", "tf", ".", "reshape", "(", "inputs", ",", "[", "-", "1", ",", "vocab_size", ",...
272500b6efe353aeb638d2745ed56e519462ca31
train
TransformedRandomVariable
Random variable for f(x), where x ~ p(x) and f is reversible.
tensor2tensor/layers/reversible_layers.py
def TransformedRandomVariable(random_variable, # pylint: disable=invalid-name reversible_layer, name=None, sample_shape=(), value=None): """Random variable for f(x), where x ~ p(x) and f is reversi...
def TransformedRandomVariable(random_variable, # pylint: disable=invalid-name reversible_layer, name=None, sample_shape=(), value=None): """Random variable for f(x), where x ~ p(x) and f is reversi...
[ "Random", "variable", "for", "f", "(", "x", ")", "where", "x", "~", "p", "(", "x", ")", "and", "f", "is", "reversible", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/reversible_layers.py#L447-L458
[ "def", "TransformedRandomVariable", "(", "random_variable", ",", "# pylint: disable=invalid-name", "reversible_layer", ",", "name", "=", "None", ",", "sample_shape", "=", "(", ")", ",", "value", "=", "None", ")", ":", "return", "ed", ".", "RandomVariable", "(", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
ActNorm.log_det_jacobian
Returns log det | dx / dy | = num_events * sum log | scale |.
tensor2tensor/layers/reversible_layers.py
def log_det_jacobian(self, inputs): """Returns log det | dx / dy | = num_events * sum log | scale |.""" del inputs # unused # Number of events is number of all elements excluding the batch and # channel dimensions. num_events = tf.reduce_prod(tf.shape(inputs)[1:-1]) log_det_jacobian = num_event...
def log_det_jacobian(self, inputs): """Returns log det | dx / dy | = num_events * sum log | scale |.""" del inputs # unused # Number of events is number of all elements excluding the batch and # channel dimensions. num_events = tf.reduce_prod(tf.shape(inputs)[1:-1]) log_det_jacobian = num_event...
[ "Returns", "log", "det", "|", "dx", "/", "dy", "|", "=", "num_events", "*", "sum", "log", "|", "scale", "|", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/reversible_layers.py#L94-L101
[ "def", "log_det_jacobian", "(", "self", ",", "inputs", ")", ":", "del", "inputs", "# unused", "# Number of events is number of all elements excluding the batch and", "# channel dimensions.", "num_events", "=", "tf", ".", "reduce_prod", "(", "tf", ".", "shape", "(", "inp...
272500b6efe353aeb638d2745ed56e519462ca31
train
DiscreteBottleneck.slice_hidden
Slice encoder hidden state into block_dim. Args: x: Encoder hidden state of shape [-1, hidden_size]. Returns: Sliced states of shape [-1, num_blocks, block_dim].
tensor2tensor/layers/vq_discrete.py
def slice_hidden(self, x): """Slice encoder hidden state into block_dim. Args: x: Encoder hidden state of shape [-1, hidden_size]. Returns: Sliced states of shape [-1, num_blocks, block_dim]. """ x_sliced = tf.reshape( x, shape=[-1, self.hparams.num_blocks, self.hparams.blo...
def slice_hidden(self, x): """Slice encoder hidden state into block_dim. Args: x: Encoder hidden state of shape [-1, hidden_size]. Returns: Sliced states of shape [-1, num_blocks, block_dim]. """ x_sliced = tf.reshape( x, shape=[-1, self.hparams.num_blocks, self.hparams.blo...
[ "Slice", "encoder", "hidden", "state", "into", "block_dim", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/vq_discrete.py#L61-L72
[ "def", "slice_hidden", "(", "self", ",", "x", ")", ":", "x_sliced", "=", "tf", ".", "reshape", "(", "x", ",", "shape", "=", "[", "-", "1", ",", "self", ".", "hparams", ".", "num_blocks", ",", "self", ".", "hparams", ".", "block_dim", "]", ")", "r...
272500b6efe353aeb638d2745ed56e519462ca31
train
DiscreteBottleneck.nearest_neighbor
Find the nearest element in means to elements in x. Args: x: Batch of encoder continuous latent states sliced/projected into shape [-1, num_blocks, block_dim]. means: Embedding means of shape. Returns: Tensor with nearest element in mean encoded in one-hot notation.
tensor2tensor/layers/vq_discrete.py
def nearest_neighbor(self, x, means): """Find the nearest element in means to elements in x. Args: x: Batch of encoder continuous latent states sliced/projected into shape [-1, num_blocks, block_dim]. means: Embedding means of shape. Returns: Tensor with nearest element in...
def nearest_neighbor(self, x, means): """Find the nearest element in means to elements in x. Args: x: Batch of encoder continuous latent states sliced/projected into shape [-1, num_blocks, block_dim]. means: Embedding means of shape. Returns: Tensor with nearest element in...
[ "Find", "the", "nearest", "element", "in", "means", "to", "elements", "in", "x", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/vq_discrete.py#L74-L120
[ "def", "nearest_neighbor", "(", "self", ",", "x", ",", "means", ")", ":", "x_norm_sq", "=", "tf", ".", "reduce_sum", "(", "tf", ".", "square", "(", "x", ")", ",", "axis", "=", "-", "1", ",", "keep_dims", "=", "True", ")", "means_norm_sq", "=", "tf"...
272500b6efe353aeb638d2745ed56e519462ca31
train
DiscreteBottleneck.embedding_lookup
Compute nearest neighbors and loss for training the embeddings. Args: x: Batch of encoder continuous latent states sliced/projected into shape [-1, num_blocks, block_dim]. means: Embedding means. Returns: The nearest neighbor in one hot form, the nearest neighbor ...
tensor2tensor/layers/vq_discrete.py
def embedding_lookup(self, x, means): """Compute nearest neighbors and loss for training the embeddings. Args: x: Batch of encoder continuous latent states sliced/projected into shape [-1, num_blocks, block_dim]. means: Embedding means. Returns: The nearest neighbor...
def embedding_lookup(self, x, means): """Compute nearest neighbors and loss for training the embeddings. Args: x: Batch of encoder continuous latent states sliced/projected into shape [-1, num_blocks, block_dim]. means: Embedding means. Returns: The nearest neighbor...
[ "Compute", "nearest", "neighbors", "and", "loss", "for", "training", "the", "embeddings", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/vq_discrete.py#L122-L145
[ "def", "embedding_lookup", "(", "self", ",", "x", ",", "means", ")", ":", "x_means_hot", "=", "self", ".", "nearest_neighbor", "(", "x", ",", "means", ")", "x_means_hot_flat", "=", "tf", ".", "reshape", "(", "x_means_hot", ",", "[", "-", "1", ",", "sel...
272500b6efe353aeb638d2745ed56e519462ca31
train
DiscreteBottleneck.int_to_bit
Turn x_int representing numbers into a bitwise (lower-endian) tensor. Args: x_int: Tensor containing integer to be converted into base notation. num_bits: Number of bits in the representation. base: Base of the representation. Returns: Corresponding number expressed in ...
tensor2tensor/layers/vq_discrete.py
def int_to_bit(self, x_int, num_bits, base=2): """Turn x_int representing numbers into a bitwise (lower-endian) tensor. Args: x_int: Tensor containing integer to be converted into base notation. num_bits: Number of bits in the representation. base: Base of the representation. ...
def int_to_bit(self, x_int, num_bits, base=2): """Turn x_int representing numbers into a bitwise (lower-endian) tensor. Args: x_int: Tensor containing integer to be converted into base notation. num_bits: Number of bits in the representation. base: Base of the representation. ...
[ "Turn", "x_int", "representing", "numbers", "into", "a", "bitwise", "(", "lower", "-", "endian", ")", "tensor", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/vq_discrete.py#L167-L187
[ "def", "int_to_bit", "(", "self", ",", "x_int", ",", "num_bits", ",", "base", "=", "2", ")", ":", "x_l", "=", "tf", ".", "to_int32", "(", "tf", ".", "expand_dims", "(", "x_int", ",", "axis", "=", "-", "1", ")", ")", "# pylint: disable=g-complex-compreh...
272500b6efe353aeb638d2745ed56e519462ca31
train
DiscreteBottleneck.embed
Embedding function that takes discrete latent and returns embedding. Args: x: Input to the discretization bottleneck. Returns: Continuous embedding to be passed on to the decoder. Raises: ValueError: For unknown or missing arguments.
tensor2tensor/layers/vq_discrete.py
def embed(self, x): """Embedding function that takes discrete latent and returns embedding. Args: x: Input to the discretization bottleneck. Returns: Continuous embedding to be passed on to the decoder. Raises: ValueError: For unknown or missing arguments. """ shape_x =...
def embed(self, x): """Embedding function that takes discrete latent and returns embedding. Args: x: Input to the discretization bottleneck. Returns: Continuous embedding to be passed on to the decoder. Raises: ValueError: For unknown or missing arguments. """ shape_x =...
[ "Embedding", "function", "that", "takes", "discrete", "latent", "and", "returns", "embedding", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/vq_discrete.py#L189-L223
[ "def", "embed", "(", "self", ",", "x", ")", ":", "shape_x", "=", "common_layers", ".", "shape_list", "(", "x", ")", "x_flat", "=", "tf", ".", "reshape", "(", "x", ",", "[", "-", "1", ",", "1", "]", ")", "c", "=", "self", ".", "int_to_bit", "(",...
272500b6efe353aeb638d2745ed56e519462ca31
train
DiscreteBottleneck.discrete_bottleneck
Discretization bottleneck for latent variables. Args: x: Input to the discretization bottleneck. Returns: Embedding to pass to the decoder, discrete latent, loss, and the embedding function. Raises: ValueError: If projection_tensors is None for reshape_method ...
tensor2tensor/layers/vq_discrete.py
def discrete_bottleneck(self, x): """Discretization bottleneck for latent variables. Args: x: Input to the discretization bottleneck. Returns: Embedding to pass to the decoder, discrete latent, loss, and the embedding function. Raises: ValueError: If projection...
def discrete_bottleneck(self, x): """Discretization bottleneck for latent variables. Args: x: Input to the discretization bottleneck. Returns: Embedding to pass to the decoder, discrete latent, loss, and the embedding function. Raises: ValueError: If projection...
[ "Discretization", "bottleneck", "for", "latent", "variables", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/vq_discrete.py#L225-L310
[ "def", "discrete_bottleneck", "(", "self", ",", "x", ")", ":", "x_reshaped", "=", "self", ".", "slice_hidden", "(", "x", ")", "x_means_hot", "=", "[", "]", "x_means", "=", "0", "loss", "=", "0", "x_means_hot", ",", "x_means", ",", "q_loss", ",", "e_los...
272500b6efe353aeb638d2745ed56e519462ca31
train
mimic_adam_with_adafactor
Switch from Adam to Adafactor, approximating the behavior of Adam. Some minor things may be different, like epsilon and beta1 correction. Args: hparams: model hyperparameters where "adam" in hparams.optimizer
tensor2tensor/models/research/adafactor_experiments.py
def mimic_adam_with_adafactor(hparams): """Switch from Adam to Adafactor, approximating the behavior of Adam. Some minor things may be different, like epsilon and beta1 correction. Args: hparams: model hyperparameters where "adam" in hparams.optimizer """ assert "adam" in hparams.optimizer hparams.opt...
def mimic_adam_with_adafactor(hparams): """Switch from Adam to Adafactor, approximating the behavior of Adam. Some minor things may be different, like epsilon and beta1 correction. Args: hparams: model hyperparameters where "adam" in hparams.optimizer """ assert "adam" in hparams.optimizer hparams.opt...
[ "Switch", "from", "Adam", "to", "Adafactor", "approximating", "the", "behavior", "of", "Adam", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/research/adafactor_experiments.py#L27-L42
[ "def", "mimic_adam_with_adafactor", "(", "hparams", ")", ":", "assert", "\"adam\"", "in", "hparams", ".", "optimizer", "hparams", ".", "optimizer", "=", "\"adafactor\"", "hparams", ".", "optimizer_adafactor_beta1", "=", "hparams", ".", "optimizer_adam_beta1", "hparams...
272500b6efe353aeb638d2745ed56e519462ca31
train
afx_adam
Old version - Adam.
tensor2tensor/models/research/adafactor_experiments.py
def afx_adam(): """Old version - Adam.""" hparams = transformer.transformer_base_v2() hparams.optimizer_adam_beta1 = 0.9 hparams.optimizer_adam_beta2 = 0.999 hparams.symbol_modality_num_shards = 1 hparams.batch_size = 2048 hparams.optimizer = "adam" hparams.learning_rate_schedule = ( "constant*rsq...
def afx_adam(): """Old version - Adam.""" hparams = transformer.transformer_base_v2() hparams.optimizer_adam_beta1 = 0.9 hparams.optimizer_adam_beta2 = 0.999 hparams.symbol_modality_num_shards = 1 hparams.batch_size = 2048 hparams.optimizer = "adam" hparams.learning_rate_schedule = ( "constant*rsq...
[ "Old", "version", "-", "Adam", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/research/adafactor_experiments.py#L46-L57
[ "def", "afx_adam", "(", ")", ":", "hparams", "=", "transformer", ".", "transformer_base_v2", "(", ")", "hparams", ".", "optimizer_adam_beta1", "=", "0.9", "hparams", ".", "optimizer_adam_beta2", "=", "0.999", "hparams", ".", "symbol_modality_num_shards", "=", "1",...
272500b6efe353aeb638d2745ed56e519462ca31
train
afx_adafactor
Adafactor with recommended learning rate schedule.
tensor2tensor/models/research/adafactor_experiments.py
def afx_adafactor(): """Adafactor with recommended learning rate schedule.""" hparams = afx_adam() hparams.optimizer = "Adafactor" hparams.learning_rate_schedule = "rsqrt_decay" hparams.learning_rate_warmup_steps = 10000 return hparams
def afx_adafactor(): """Adafactor with recommended learning rate schedule.""" hparams = afx_adam() hparams.optimizer = "Adafactor" hparams.learning_rate_schedule = "rsqrt_decay" hparams.learning_rate_warmup_steps = 10000 return hparams
[ "Adafactor", "with", "recommended", "learning", "rate", "schedule", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/research/adafactor_experiments.py#L167-L173
[ "def", "afx_adafactor", "(", ")", ":", "hparams", "=", "afx_adam", "(", ")", "hparams", ".", "optimizer", "=", "\"Adafactor\"", "hparams", ".", "learning_rate_schedule", "=", "\"rsqrt_decay\"", "hparams", ".", "learning_rate_warmup_steps", "=", "10000", "return", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
afx_small
Small transformer model with small batch size for fast step times.
tensor2tensor/models/research/adafactor_experiments.py
def afx_small(): """Small transformer model with small batch size for fast step times.""" hparams = transformer.transformer_tpu() hparams.filter_size = 1024 hparams.num_heads = 4 hparams.num_hidden_layers = 3 hparams.batch_size = 512 return hparams
def afx_small(): """Small transformer model with small batch size for fast step times.""" hparams = transformer.transformer_tpu() hparams.filter_size = 1024 hparams.num_heads = 4 hparams.num_hidden_layers = 3 hparams.batch_size = 512 return hparams
[ "Small", "transformer", "model", "with", "small", "batch", "size", "for", "fast", "step", "times", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/research/adafactor_experiments.py#L177-L184
[ "def", "afx_small", "(", ")", ":", "hparams", "=", "transformer", ".", "transformer_tpu", "(", ")", "hparams", ".", "filter_size", "=", "1024", "hparams", ".", "num_heads", "=", "4", "hparams", ".", "num_hidden_layers", "=", "3", "hparams", ".", "batch_size"...
272500b6efe353aeb638d2745ed56e519462ca31
train
next_frame_emily
Emily's model hparams.
tensor2tensor/models/video/emily.py
def next_frame_emily(): """Emily's model hparams.""" hparams = sv2p_params.next_frame_sv2p() hparams.video_num_input_frames = 2 hparams.video_num_target_frames = 10 hparams.learning_rate_constant = 1e-4 seq_length = hparams.video_num_input_frames + hparams.video_num_target_frames # The latent_loss_multipl...
def next_frame_emily(): """Emily's model hparams.""" hparams = sv2p_params.next_frame_sv2p() hparams.video_num_input_frames = 2 hparams.video_num_target_frames = 10 hparams.learning_rate_constant = 1e-4 seq_length = hparams.video_num_input_frames + hparams.video_num_target_frames # The latent_loss_multipl...
[ "Emily", "s", "model", "hparams", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/models/video/emily.py#L447-L475
[ "def", "next_frame_emily", "(", ")", ":", "hparams", "=", "sv2p_params", ".", "next_frame_sv2p", "(", ")", "hparams", ".", "video_num_input_frames", "=", "2", "hparams", ".", "video_num_target_frames", "=", "10", "hparams", ".", "learning_rate_constant", "=", "1e-...
272500b6efe353aeb638d2745ed56e519462ca31
train
main
Convert a file to examples.
tensor2tensor/data_generators/inspect_tfrecord.py
def main(_): """Convert a file to examples.""" if FLAGS.subword_text_encoder_filename: encoder = text_encoder.SubwordTextEncoder( FLAGS.subword_text_encoder_filename) elif FLAGS.token_text_encoder_filename: encoder = text_encoder.TokenTextEncoder(FLAGS.token_text_encoder_filename) elif FLAGS.byt...
def main(_): """Convert a file to examples.""" if FLAGS.subword_text_encoder_filename: encoder = text_encoder.SubwordTextEncoder( FLAGS.subword_text_encoder_filename) elif FLAGS.token_text_encoder_filename: encoder = text_encoder.TokenTextEncoder(FLAGS.token_text_encoder_filename) elif FLAGS.byt...
[ "Convert", "a", "file", "to", "examples", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/inspect_tfrecord.py#L48-L93
[ "def", "main", "(", "_", ")", ":", "if", "FLAGS", ".", "subword_text_encoder_filename", ":", "encoder", "=", "text_encoder", ".", "SubwordTextEncoder", "(", "FLAGS", ".", "subword_text_encoder_filename", ")", "elif", "FLAGS", ".", "token_text_encoder_filename", ":",...
272500b6efe353aeb638d2745ed56e519462ca31
train
RenderedEnvProblem.example_reading_spec
Return a mix of env and video data fields and decoders.
tensor2tensor/envs/rendered_env_problem.py
def example_reading_spec(self): """Return a mix of env and video data fields and decoders.""" video_fields, video_decoders = ( video_utils.VideoProblem.example_reading_spec(self)) env_fields, env_decoders = env_problem.EnvProblem.example_reading_spec(self) # Remove raw observations field since ...
def example_reading_spec(self): """Return a mix of env and video data fields and decoders.""" video_fields, video_decoders = ( video_utils.VideoProblem.example_reading_spec(self)) env_fields, env_decoders = env_problem.EnvProblem.example_reading_spec(self) # Remove raw observations field since ...
[ "Return", "a", "mix", "of", "env", "and", "video", "data", "fields", "and", "decoders", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/envs/rendered_env_problem.py#L66-L85
[ "def", "example_reading_spec", "(", "self", ")", ":", "video_fields", ",", "video_decoders", "=", "(", "video_utils", ".", "VideoProblem", ".", "example_reading_spec", "(", "self", ")", ")", "env_fields", ",", "env_decoders", "=", "env_problem", ".", "EnvProblem",...
272500b6efe353aeb638d2745ed56e519462ca31
train
RenderedEnvProblem._generate_time_steps
Transforms time step observations to frames of a video.
tensor2tensor/envs/rendered_env_problem.py
def _generate_time_steps(self, trajectory_list): """Transforms time step observations to frames of a video.""" for time_step in env_problem.EnvProblem._generate_time_steps( self, trajectory_list): # Convert the rendered observations from numpy to png format. frame_np = np.array(time_step.pop...
def _generate_time_steps(self, trajectory_list): """Transforms time step observations to frames of a video.""" for time_step in env_problem.EnvProblem._generate_time_steps( self, trajectory_list): # Convert the rendered observations from numpy to png format. frame_np = np.array(time_step.pop...
[ "Transforms", "time", "step", "observations", "to", "frames", "of", "a", "video", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/envs/rendered_env_problem.py#L87-L108
[ "def", "_generate_time_steps", "(", "self", ",", "trajectory_list", ")", ":", "for", "time_step", "in", "env_problem", ".", "EnvProblem", ".", "_generate_time_steps", "(", "self", ",", "trajectory_list", ")", ":", "# Convert the rendered observations from numpy to png for...
272500b6efe353aeb638d2745ed56e519462ca31
train
txt_line_iterator
Iterate through lines of file.
tensor2tensor/data_generators/text_problems.py
def txt_line_iterator(txt_path): """Iterate through lines of file.""" with tf.gfile.Open(txt_path) as f: for line in f: yield line.strip()
def txt_line_iterator(txt_path): """Iterate through lines of file.""" with tf.gfile.Open(txt_path) as f: for line in f: yield line.strip()
[ "Iterate", "through", "lines", "of", "file", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L607-L611
[ "def", "txt_line_iterator", "(", "txt_path", ")", ":", "with", "tf", ".", "gfile", ".", "Open", "(", "txt_path", ")", "as", "f", ":", "for", "line", "in", "f", ":", "yield", "line", ".", "strip", "(", ")" ]
272500b6efe353aeb638d2745ed56e519462ca31
train
text2text_txt_iterator
Yield dicts for Text2TextProblem.generate_samples from lines of files.
tensor2tensor/data_generators/text_problems.py
def text2text_txt_iterator(source_txt_path, target_txt_path): """Yield dicts for Text2TextProblem.generate_samples from lines of files.""" for inputs, targets in zip( txt_line_iterator(source_txt_path), txt_line_iterator(target_txt_path)): yield {"inputs": inputs, "targets": targets}
def text2text_txt_iterator(source_txt_path, target_txt_path): """Yield dicts for Text2TextProblem.generate_samples from lines of files.""" for inputs, targets in zip( txt_line_iterator(source_txt_path), txt_line_iterator(target_txt_path)): yield {"inputs": inputs, "targets": targets}
[ "Yield", "dicts", "for", "Text2TextProblem", ".", "generate_samples", "from", "lines", "of", "files", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L614-L618
[ "def", "text2text_txt_iterator", "(", "source_txt_path", ",", "target_txt_path", ")", ":", "for", "inputs", ",", "targets", "in", "zip", "(", "txt_line_iterator", "(", "source_txt_path", ")", ",", "txt_line_iterator", "(", "target_txt_path", ")", ")", ":", "yield"...
272500b6efe353aeb638d2745ed56e519462ca31
train
text2text_distill_iterator
Yield dicts for Text2TextProblem.generate_samples from lines of files.
tensor2tensor/data_generators/text_problems.py
def text2text_distill_iterator(source_txt_path, target_txt_path, distill_txt_path): """Yield dicts for Text2TextProblem.generate_samples from lines of files.""" for inputs, targets, dist_targets in zip( txt_line_iterator(source_txt_path), txt_line_iterator(target_txt_path), ...
def text2text_distill_iterator(source_txt_path, target_txt_path, distill_txt_path): """Yield dicts for Text2TextProblem.generate_samples from lines of files.""" for inputs, targets, dist_targets in zip( txt_line_iterator(source_txt_path), txt_line_iterator(target_txt_path), ...
[ "Yield", "dicts", "for", "Text2TextProblem", ".", "generate_samples", "from", "lines", "of", "files", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L621-L627
[ "def", "text2text_distill_iterator", "(", "source_txt_path", ",", "target_txt_path", ",", "distill_txt_path", ")", ":", "for", "inputs", ",", "targets", ",", "dist_targets", "in", "zip", "(", "txt_line_iterator", "(", "source_txt_path", ")", ",", "txt_line_iterator", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
text2class_txt_iterator
Yield dicts for Text2ClassProblem.generate_samples from lines of files. Args: source_txt_path: txt file with record per line. label_txt_path: txt file with label per line, either as int or str. If string, must provide class_strs. class_strs: list<str> of class label names. Must be in correct order ...
tensor2tensor/data_generators/text_problems.py
def text2class_txt_iterator(source_txt_path, label_txt_path, class_strs=None): """Yield dicts for Text2ClassProblem.generate_samples from lines of files. Args: source_txt_path: txt file with record per line. label_txt_path: txt file with label per line, either as int or str. If string, must provide c...
def text2class_txt_iterator(source_txt_path, label_txt_path, class_strs=None): """Yield dicts for Text2ClassProblem.generate_samples from lines of files. Args: source_txt_path: txt file with record per line. label_txt_path: txt file with label per line, either as int or str. If string, must provide c...
[ "Yield", "dicts", "for", "Text2ClassProblem", ".", "generate_samples", "from", "lines", "of", "files", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L635-L657
[ "def", "text2class_txt_iterator", "(", "source_txt_path", ",", "label_txt_path", ",", "class_strs", "=", "None", ")", ":", "if", "class_strs", ":", "class_strs", "=", "dict", "(", "[", "(", "s", ",", "i", ")", "for", "i", ",", "s", "in", "enumerate", "("...
272500b6efe353aeb638d2745ed56e519462ca31
train
text2text_txt_tab_iterator
Yield dicts for Text2TextProblem.generate_samples from lines of txt_path. Args: txt_path: path to txt file with a record per line, source and target are tab-separated. Yields: {"inputs": inputs, "targets": targets}
tensor2tensor/data_generators/text_problems.py
def text2text_txt_tab_iterator(txt_path): """Yield dicts for Text2TextProblem.generate_samples from lines of txt_path. Args: txt_path: path to txt file with a record per line, source and target are tab-separated. Yields: {"inputs": inputs, "targets": targets} """ for line in txt_line_iterator(...
def text2text_txt_tab_iterator(txt_path): """Yield dicts for Text2TextProblem.generate_samples from lines of txt_path. Args: txt_path: path to txt file with a record per line, source and target are tab-separated. Yields: {"inputs": inputs, "targets": targets} """ for line in txt_line_iterator(...
[ "Yield", "dicts", "for", "Text2TextProblem", ".", "generate_samples", "from", "lines", "of", "txt_path", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L660-L674
[ "def", "text2text_txt_tab_iterator", "(", "txt_path", ")", ":", "for", "line", "in", "txt_line_iterator", "(", "txt_path", ")", ":", "if", "line", "and", "\"\\t\"", "in", "line", ":", "parts", "=", "line", ".", "split", "(", "\"\\t\"", ",", "1", ")", "in...
272500b6efe353aeb638d2745ed56e519462ca31
train
text2text_generate_encoded
Encode Text2Text samples from the generator with the vocab.
tensor2tensor/data_generators/text_problems.py
def text2text_generate_encoded(sample_generator, vocab, targets_vocab=None, has_inputs=True, inputs_prefix="", targets_prefix=""): """Encode Text2Text samples from...
def text2text_generate_encoded(sample_generator, vocab, targets_vocab=None, has_inputs=True, inputs_prefix="", targets_prefix=""): """Encode Text2Text samples from...
[ "Encode", "Text2Text", "samples", "from", "the", "generator", "with", "the", "vocab", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L677-L691
[ "def", "text2text_generate_encoded", "(", "sample_generator", ",", "vocab", ",", "targets_vocab", "=", "None", ",", "has_inputs", "=", "True", ",", "inputs_prefix", "=", "\"\"", ",", "targets_prefix", "=", "\"\"", ")", ":", "targets_vocab", "=", "targets_vocab", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
Text2TextProblem._pack_fn
For packed datasets, returns a function to pack examples. Returns: None or a function from list of TFRecords to list of TFRecords
tensor2tensor/data_generators/text_problems.py
def _pack_fn(self): """For packed datasets, returns a function to pack examples. Returns: None or a function from list of TFRecords to list of TFRecords """ if not self.packed_length: return None def my_fn(records): """Function from list of TFRecords to list of TFRecords.""" ...
def _pack_fn(self): """For packed datasets, returns a function to pack examples. Returns: None or a function from list of TFRecords to list of TFRecords """ if not self.packed_length: return None def my_fn(records): """Function from list of TFRecords to list of TFRecords.""" ...
[ "For", "packed", "datasets", "returns", "a", "function", "to", "pack", "examples", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L263-L287
[ "def", "_pack_fn", "(", "self", ")", ":", "if", "not", "self", ".", "packed_length", ":", "return", "None", "def", "my_fn", "(", "records", ")", ":", "\"\"\"Function from list of TFRecords to list of TFRecords.\"\"\"", "examples", "=", "[", "]", "for", "record", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
Text2TextProblem._maybe_pack_examples
Wraps generator with packer if self.packed_length.
tensor2tensor/data_generators/text_problems.py
def _maybe_pack_examples(self, generator): """Wraps generator with packer if self.packed_length.""" if not self.packed_length: return generator return generator_utils.pack_examples( generator, self.has_inputs, self.packed_length, spacing=self.packed_spacing, cho...
def _maybe_pack_examples(self, generator): """Wraps generator with packer if self.packed_length.""" if not self.packed_length: return generator return generator_utils.pack_examples( generator, self.has_inputs, self.packed_length, spacing=self.packed_spacing, cho...
[ "Wraps", "generator", "with", "packer", "if", "self", ".", "packed_length", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L289-L298
[ "def", "_maybe_pack_examples", "(", "self", ",", "generator", ")", ":", "if", "not", "self", ".", "packed_length", ":", "return", "generator", "return", "generator_utils", ".", "pack_examples", "(", "generator", ",", "self", ".", "has_inputs", ",", "self", "."...
272500b6efe353aeb638d2745ed56e519462ca31
train
ChoppedTextProblem.text_filepaths_for_task
List of input filepaths for a particular training or dev shard. Args: tmp_dir: a string task_id: an integer less than self.num_shards Returns: a list of tuples (filepath, start_pos, num_bytes)
tensor2tensor/data_generators/text_problems.py
def text_filepaths_for_task(self, tmp_dir, task_id): """List of input filepaths for a particular training or dev shard. Args: tmp_dir: a string task_id: an integer less than self.num_shards Returns: a list of tuples (filepath, start_pos, num_bytes) """ assert task_id >= 0 asse...
def text_filepaths_for_task(self, tmp_dir, task_id): """List of input filepaths for a particular training or dev shard. Args: tmp_dir: a string task_id: an integer less than self.num_shards Returns: a list of tuples (filepath, start_pos, num_bytes) """ assert task_id >= 0 asse...
[ "List", "of", "input", "filepaths", "for", "a", "particular", "training", "or", "dev", "shard", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L831-L851
[ "def", "text_filepaths_for_task", "(", "self", ",", "tmp_dir", ",", "task_id", ")", ":", "assert", "task_id", ">=", "0", "assert", "task_id", "<", "self", ".", "num_train_shards", "+", "self", ".", "num_dev_shards", "if", "task_id", "<", "self", ".", "num_tr...
272500b6efe353aeb638d2745ed56e519462ca31
train
ChoppedTextProblem.filepath_to_unicode_strings
Read text out of an input file. The default just reads the text, converts to unicode and yields one unicode string. Subclasses can override this function in order to preprocess, and can yield any number of strings. Args: filepath: a string Yields: unicode strings.
tensor2tensor/data_generators/text_problems.py
def filepath_to_unicode_strings(self, filepath): """Read text out of an input file. The default just reads the text, converts to unicode and yields one unicode string. Subclasses can override this function in order to preprocess, and can yield any number of strings. Args: filepath: a st...
def filepath_to_unicode_strings(self, filepath): """Read text out of an input file. The default just reads the text, converts to unicode and yields one unicode string. Subclasses can override this function in order to preprocess, and can yield any number of strings. Args: filepath: a st...
[ "Read", "text", "out", "of", "an", "input", "file", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L853-L869
[ "def", "filepath_to_unicode_strings", "(", "self", ",", "filepath", ")", ":", "f", "=", "tf", ".", "gfile", ".", "Open", "(", "filepath", ")", "b", "=", "f", ".", "read", "(", ")", "yield", "text_encoder", ".", "to_unicode_ignore_errors", "(", "b", ")" ]
272500b6efe353aeb638d2745ed56e519462ca31
train
ChoppedTextProblem.file_generator
Read complete text of input files and yield unicode strings. By default, one unicode string is produced per file, but this is not guaranteed, since subclasses can override filepath_to_unicode_strings(). max_chars_per_file and max_chars_total can also be specified, in which case some strings may be...
tensor2tensor/data_generators/text_problems.py
def file_generator(self, filepaths, max_chars_per_file=None, max_chars_total=None): """Read complete text of input files and yield unicode strings. By default, one unicode string is produced per file, but this is not guaranteed, since subclasse...
def file_generator(self, filepaths, max_chars_per_file=None, max_chars_total=None): """Read complete text of input files and yield unicode strings. By default, one unicode string is produced per file, but this is not guaranteed, since subclasse...
[ "Read", "complete", "text", "of", "input", "files", "and", "yield", "unicode", "strings", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L871-L909
[ "def", "file_generator", "(", "self", ",", "filepaths", ",", "max_chars_per_file", "=", "None", ",", "max_chars_total", "=", "None", ")", ":", "chars_total", "=", "0", "for", "fname", "in", "filepaths", ":", "chars_this_file", "=", "0", "tf", ".", "logging",...
272500b6efe353aeb638d2745ed56e519462ca31
train
ChoppedTextProblem.example_generator
Generator for examples. Args: encoder: a TextEncoder tmp_dir: a string task_id: an integer Yields: feature dictionaries
tensor2tensor/data_generators/text_problems.py
def example_generator(self, encoder, tmp_dir, task_id): """Generator for examples. Args: encoder: a TextEncoder tmp_dir: a string task_id: an integer Yields: feature dictionaries """ filepaths = self.text_filepaths_for_task(tmp_dir, task_id) if task_id >= self.num_train_...
def example_generator(self, encoder, tmp_dir, task_id): """Generator for examples. Args: encoder: a TextEncoder tmp_dir: a string task_id: an integer Yields: feature dictionaries """ filepaths = self.text_filepaths_for_task(tmp_dir, task_id) if task_id >= self.num_train_...
[ "Generator", "for", "examples", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L911-L943
[ "def", "example_generator", "(", "self", ",", "encoder", ",", "tmp_dir", ",", "task_id", ")", ":", "filepaths", "=", "self", ".", "text_filepaths_for_task", "(", "tmp_dir", ",", "task_id", ")", "if", "task_id", ">=", "self", ".", "num_train_shards", ":", "# ...
272500b6efe353aeb638d2745ed56e519462ca31
train
ChoppedTextProblem.prepare_to_generate
Make sure that the data is prepared and the vocab is generated.
tensor2tensor/data_generators/text_problems.py
def prepare_to_generate(self, data_dir, tmp_dir): """Make sure that the data is prepared and the vocab is generated.""" self.get_or_create_vocab(data_dir, tmp_dir) self.train_text_filepaths(tmp_dir) self.dev_text_filepaths(tmp_dir)
def prepare_to_generate(self, data_dir, tmp_dir): """Make sure that the data is prepared and the vocab is generated.""" self.get_or_create_vocab(data_dir, tmp_dir) self.train_text_filepaths(tmp_dir) self.dev_text_filepaths(tmp_dir)
[ "Make", "sure", "that", "the", "data", "is", "prepared", "and", "the", "vocab", "is", "generated", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L954-L958
[ "def", "prepare_to_generate", "(", "self", ",", "data_dir", ",", "tmp_dir", ")", ":", "self", ".", "get_or_create_vocab", "(", "data_dir", ",", "tmp_dir", ")", "self", ".", "train_text_filepaths", "(", "tmp_dir", ")", "self", ".", "dev_text_filepaths", "(", "t...
272500b6efe353aeb638d2745ed56e519462ca31
train
ChoppedTextProblem.generate_data
Generates training/dev data. Args: data_dir: a string tmp_dir: a string task_id: an optional integer Returns: shard or shards for which data was generated.
tensor2tensor/data_generators/text_problems.py
def generate_data(self, data_dir, tmp_dir, task_id=-1): """Generates training/dev data. Args: data_dir: a string tmp_dir: a string task_id: an optional integer Returns: shard or shards for which data was generated. """ tf.logging.info("generate_data task_id=%s" % task_id) ...
def generate_data(self, data_dir, tmp_dir, task_id=-1): """Generates training/dev data. Args: data_dir: a string tmp_dir: a string task_id: an optional integer Returns: shard or shards for which data was generated. """ tf.logging.info("generate_data task_id=%s" % task_id) ...
[ "Generates", "training", "/", "dev", "data", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L965-L987
[ "def", "generate_data", "(", "self", ",", "data_dir", ",", "tmp_dir", ",", "task_id", "=", "-", "1", ")", ":", "tf", ".", "logging", ".", "info", "(", "\"generate_data task_id=%s\"", "%", "task_id", ")", "encoder", "=", "self", ".", "get_or_create_vocab", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
ConvBlock
ResNet convolutional striding block.
tensor2tensor/trax/models/resnet.py
def ConvBlock(kernel_size, filters, strides): """ResNet convolutional striding block.""" ks = kernel_size filters1, filters2, filters3 = filters main = layers.Serial( layers.Conv(filters1, (1, 1), strides), layers.BatchNorm(), layers.Relu(), layers.Conv(filters2, (ks, ks), padding='SAME'...
def ConvBlock(kernel_size, filters, strides): """ResNet convolutional striding block.""" ks = kernel_size filters1, filters2, filters3 = filters main = layers.Serial( layers.Conv(filters1, (1, 1), strides), layers.BatchNorm(), layers.Relu(), layers.Conv(filters2, (ks, ks), padding='SAME'...
[ "ResNet", "convolutional", "striding", "block", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/trax/models/resnet.py#L25-L48
[ "def", "ConvBlock", "(", "kernel_size", ",", "filters", ",", "strides", ")", ":", "ks", "=", "kernel_size", "filters1", ",", "filters2", ",", "filters3", "=", "filters", "main", "=", "layers", ".", "Serial", "(", "layers", ".", "Conv", "(", "filters1", "...
272500b6efe353aeb638d2745ed56e519462ca31
train
IdentityBlock
ResNet identical size block.
tensor2tensor/trax/models/resnet.py
def IdentityBlock(kernel_size, filters): """ResNet identical size block.""" ks = kernel_size filters1, filters2, filters3 = filters main = layers.Serial( layers.Conv(filters1, (1, 1)), layers.BatchNorm(), layers.Relu(), layers.Conv(filters2, (ks, ks), padding='SAME'), layers.BatchN...
def IdentityBlock(kernel_size, filters): """ResNet identical size block.""" ks = kernel_size filters1, filters2, filters3 = filters main = layers.Serial( layers.Conv(filters1, (1, 1)), layers.BatchNorm(), layers.Relu(), layers.Conv(filters2, (ks, ks), padding='SAME'), layers.BatchN...
[ "ResNet", "identical", "size", "block", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/trax/models/resnet.py#L51-L70
[ "def", "IdentityBlock", "(", "kernel_size", ",", "filters", ")", ":", "ks", "=", "kernel_size", "filters1", ",", "filters2", ",", "filters3", "=", "filters", "main", "=", "layers", ".", "Serial", "(", "layers", ".", "Conv", "(", "filters1", ",", "(", "1"...
272500b6efe353aeb638d2745ed56e519462ca31
train
Resnet50
ResNet. Args: hidden_size: the size of the first hidden layer (multiplied later). num_output_classes: how many classes to distinguish. mode: whether we are training or evaluating or doing inference. Returns: The ResNet model with the given layer and output sizes.
tensor2tensor/trax/models/resnet.py
def Resnet50(hidden_size=64, num_output_classes=1001, mode='train'): """ResNet. Args: hidden_size: the size of the first hidden layer (multiplied later). num_output_classes: how many classes to distinguish. mode: whether we are training or evaluating or doing inference. Returns: The ResNet model...
def Resnet50(hidden_size=64, num_output_classes=1001, mode='train'): """ResNet. Args: hidden_size: the size of the first hidden layer (multiplied later). num_output_classes: how many classes to distinguish. mode: whether we are training or evaluating or doing inference. Returns: The ResNet model...
[ "ResNet", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/trax/models/resnet.py#L73-L106
[ "def", "Resnet50", "(", "hidden_size", "=", "64", ",", "num_output_classes", "=", "1001", ",", "mode", "=", "'train'", ")", ":", "del", "mode", "return", "layers", ".", "Serial", "(", "layers", ".", "Conv", "(", "hidden_size", ",", "(", "7", ",", "7", ...
272500b6efe353aeb638d2745ed56e519462ca31
train
WideResnetBlock
WideResnet convolutational block.
tensor2tensor/trax/models/resnet.py
def WideResnetBlock(channels, strides=(1, 1), channel_mismatch=False): """WideResnet convolutational block.""" main = layers.Serial(layers.BatchNorm(), layers.Relu(), layers.Conv(channels, (3, 3), strides, padding='SAME'), layers.BatchNorm(), layers.Relu(), ...
def WideResnetBlock(channels, strides=(1, 1), channel_mismatch=False): """WideResnet convolutational block.""" main = layers.Serial(layers.BatchNorm(), layers.Relu(), layers.Conv(channels, (3, 3), strides, padding='SAME'), layers.BatchNorm(), layers.Relu(), ...
[ "WideResnet", "convolutational", "block", "." ]
tensorflow/tensor2tensor
python
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/trax/models/resnet.py#L109-L118
[ "def", "WideResnetBlock", "(", "channels", ",", "strides", "=", "(", "1", ",", "1", ")", ",", "channel_mismatch", "=", "False", ")", ":", "main", "=", "layers", ".", "Serial", "(", "layers", ".", "BatchNorm", "(", ")", ",", "layers", ".", "Relu", "("...
272500b6efe353aeb638d2745ed56e519462ca31