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 | build_and_train | Construct the data, model, loss and optimizer then train. | sonnet/examples/rmc_nth_farthest.py | def build_and_train(iterations, log_stride, test=False):
"""Construct the data, model, loss and optimizer then train."""
# Test mode settings.
batch_size = 2 if test else FLAGS.batch_size
num_mems = 2 if test else FLAGS.num_mems
num_heads = 1 if test else FLAGS.num_mems
num_blocks = 1 if test else FLAGS.nu... | def build_and_train(iterations, log_stride, test=False):
"""Construct the data, model, loss and optimizer then train."""
# Test mode settings.
batch_size = 2 if test else FLAGS.batch_size
num_mems = 2 if test else FLAGS.num_mems
num_heads = 1 if test else FLAGS.num_mems
num_blocks = 1 if test else FLAGS.nu... | [
"Construct",
"the",
"data",
"model",
"loss",
"and",
"optimizer",
"then",
"train",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/rmc_nth_farthest.py#L93-L202 | [
"def",
"build_and_train",
"(",
"iterations",
",",
"log_stride",
",",
"test",
"=",
"False",
")",
":",
"# Test mode settings.",
"batch_size",
"=",
"2",
"if",
"test",
"else",
"FLAGS",
".",
"batch_size",
"num_mems",
"=",
"2",
"if",
"test",
"else",
"FLAGS",
".",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | SequenceModel._build | Dynamic unroll across input objects.
Args:
inputs: tensor (batch x num_objects x feature). Objects to sort.
Returns:
Tensor (batch x num_objects); logits indicating the reference objects. | sonnet/examples/rmc_nth_farthest.py | def _build(self, inputs):
"""Dynamic unroll across input objects.
Args:
inputs: tensor (batch x num_objects x feature). Objects to sort.
Returns:
Tensor (batch x num_objects); logits indicating the reference objects.
"""
batch_size = inputs.get_shape()[0]
output_sequence, _ = tf.nn... | def _build(self, inputs):
"""Dynamic unroll across input objects.
Args:
inputs: tensor (batch x num_objects x feature). Objects to sort.
Returns:
Tensor (batch x num_objects); logits indicating the reference objects.
"""
batch_size = inputs.get_shape()[0]
output_sequence, _ = tf.nn... | [
"Dynamic",
"unroll",
"across",
"input",
"objects",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/rmc_nth_farthest.py#L70-L90 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
")",
":",
"batch_size",
"=",
"inputs",
".",
"get_shape",
"(",
")",
"[",
"0",
"]",
"output_sequence",
",",
"_",
"=",
"tf",
".",
"nn",
".",
"dynamic_rnn",
"(",
"cell",
"=",
"self",
".",
"_core",
",",
"inpu... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _clip_gradient_op | Create an op that clips gradients using a Defun.
The tensorflow Defun decorator creates an op and tensorflow caches these op
automatically according to `func_name`. Using a Defun decorator twice with the
same `func_name` does not create a new op, instead the cached op is used.
This method produces a new op th... | sonnet/python/modules/clip_gradient.py | def _clip_gradient_op(dtype):
"""Create an op that clips gradients using a Defun.
The tensorflow Defun decorator creates an op and tensorflow caches these op
automatically according to `func_name`. Using a Defun decorator twice with the
same `func_name` does not create a new op, instead the cached op is used.
... | def _clip_gradient_op(dtype):
"""Create an op that clips gradients using a Defun.
The tensorflow Defun decorator creates an op and tensorflow caches these op
automatically according to `func_name`. Using a Defun decorator twice with the
same `func_name` does not create a new op, instead the cached op is used.
... | [
"Create",
"an",
"op",
"that",
"clips",
"gradients",
"using",
"a",
"Defun",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/clip_gradient.py#L25-L59 | [
"def",
"_clip_gradient_op",
"(",
"dtype",
")",
":",
"def",
"clip_gradient_backward",
"(",
"op",
",",
"grad",
")",
":",
"clip_value_min",
"=",
"op",
".",
"inputs",
"[",
"1",
"]",
"clip_value_max",
"=",
"op",
".",
"inputs",
"[",
"2",
"]",
"clipped_grad",
"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | clip_gradient | Clips respective gradients of a given tensor.
Acts as identity for the forward pass, but clips gradient tensor element-wise
by value during the backward pass. Any gradient values less than
`clip_value_min` or greater than `clip_values_max` are set to the respective
limit values.
Args:
net: A `tf.Tensor`... | sonnet/python/modules/clip_gradient.py | def clip_gradient(net, clip_value_min, clip_value_max, name=None):
"""Clips respective gradients of a given tensor.
Acts as identity for the forward pass, but clips gradient tensor element-wise
by value during the backward pass. Any gradient values less than
`clip_value_min` or greater than `clip_values_max` a... | def clip_gradient(net, clip_value_min, clip_value_max, name=None):
"""Clips respective gradients of a given tensor.
Acts as identity for the forward pass, but clips gradient tensor element-wise
by value during the backward pass. Any gradient values less than
`clip_value_min` or greater than `clip_values_max` a... | [
"Clips",
"respective",
"gradients",
"of",
"a",
"given",
"tensor",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/clip_gradient.py#L62-L94 | [
"def",
"clip_gradient",
"(",
"net",
",",
"clip_value_min",
",",
"clip_value_max",
",",
"name",
"=",
"None",
")",
":",
"if",
"not",
"net",
".",
"dtype",
".",
"is_floating",
":",
"raise",
"ValueError",
"(",
"\"clip_gradient does not support non-float `net` inputs.\"",... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ptb_raw_data | Load PTB raw data from data directory "data_path".
Reads PTB text files, converts strings to integer ids,
and performs mini-batching of the inputs.
The PTB dataset comes from Tomas Mikolov's webpage:
http://www.fit.vutbr.cz/~imikolov/rnnlm/simple-examples.tgz
Args:
data_path: string path to the direct... | sonnet/examples/ptb_reader.py | def ptb_raw_data(data_path):
"""Load PTB raw data from data directory "data_path".
Reads PTB text files, converts strings to integer ids,
and performs mini-batching of the inputs.
The PTB dataset comes from Tomas Mikolov's webpage:
http://www.fit.vutbr.cz/~imikolov/rnnlm/simple-examples.tgz
Args:
da... | def ptb_raw_data(data_path):
"""Load PTB raw data from data directory "data_path".
Reads PTB text files, converts strings to integer ids,
and performs mini-batching of the inputs.
The PTB dataset comes from Tomas Mikolov's webpage:
http://www.fit.vutbr.cz/~imikolov/rnnlm/simple-examples.tgz
Args:
da... | [
"Load",
"PTB",
"raw",
"data",
"from",
"data",
"directory",
"data_path",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/ptb_reader.py#L55-L82 | [
"def",
"ptb_raw_data",
"(",
"data_path",
")",
":",
"train_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"data_path",
",",
"\"ptb.train.txt\"",
")",
"valid_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"data_path",
",",
"\"ptb.valid.txt\"",
")",
"test... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ConvNet2D._check_and_assign_normalization_members | Checks that the normalization constructor is callable. | sonnet/python/modules/nets/convnet.py | def _check_and_assign_normalization_members(self, normalization_ctor,
normalization_kwargs):
"""Checks that the normalization constructor is callable."""
if isinstance(normalization_ctor, six.string_types):
normalization_ctor = util.parse_string_to_constructor... | def _check_and_assign_normalization_members(self, normalization_ctor,
normalization_kwargs):
"""Checks that the normalization constructor is callable."""
if isinstance(normalization_ctor, six.string_types):
normalization_ctor = util.parse_string_to_constructor... | [
"Checks",
"that",
"the",
"normalization",
"constructor",
"is",
"callable",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L252-L262 | [
"def",
"_check_and_assign_normalization_members",
"(",
"self",
",",
"normalization_ctor",
",",
"normalization_kwargs",
")",
":",
"if",
"isinstance",
"(",
"normalization_ctor",
",",
"six",
".",
"string_types",
")",
":",
"normalization_ctor",
"=",
"util",
".",
"parse_st... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ConvNet2D._parse_normalization_kwargs | Sets up normalization, checking old and new flags. | sonnet/python/modules/nets/convnet.py | def _parse_normalization_kwargs(self, use_batch_norm, batch_norm_config,
normalization_ctor, normalization_kwargs):
"""Sets up normalization, checking old and new flags."""
if use_batch_norm is not None:
# Delete this whole block when deprecation is done.
util.depre... | def _parse_normalization_kwargs(self, use_batch_norm, batch_norm_config,
normalization_ctor, normalization_kwargs):
"""Sets up normalization, checking old and new flags."""
if use_batch_norm is not None:
# Delete this whole block when deprecation is done.
util.depre... | [
"Sets",
"up",
"normalization",
"checking",
"old",
"and",
"new",
"flags",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L264-L286 | [
"def",
"_parse_normalization_kwargs",
"(",
"self",
",",
"use_batch_norm",
",",
"batch_norm_config",
",",
"normalization_ctor",
",",
"normalization_kwargs",
")",
":",
"if",
"use_batch_norm",
"is",
"not",
"None",
":",
"# Delete this whole block when deprecation is done.",
"ut... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ConvNet2D._instantiate_layers | Instantiates all the convolutional modules used in the network. | sonnet/python/modules/nets/convnet.py | def _instantiate_layers(self):
"""Instantiates all the convolutional modules used in the network."""
# Here we are entering the module's variable scope to name our submodules
# correctly (not to create variables). As such it's safe to not check
# whether we're in the same graph. This is important if we... | def _instantiate_layers(self):
"""Instantiates all the convolutional modules used in the network."""
# Here we are entering the module's variable scope to name our submodules
# correctly (not to create variables). As such it's safe to not check
# whether we're in the same graph. This is important if we... | [
"Instantiates",
"all",
"the",
"convolutional",
"modules",
"used",
"in",
"the",
"network",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L288-L309 | [
"def",
"_instantiate_layers",
"(",
"self",
")",
":",
"# Here we are entering the module's variable scope to name our submodules",
"# correctly (not to create variables). As such it's safe to not check",
"# whether we're in the same graph. This is important if we're constructing",
"# the module in ... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ConvNet2D._build | Assembles the `ConvNet2D` and connects it to the graph.
Args:
inputs: A 4D Tensor of shape `[batch_size, input_height, input_width,
input_channels]`.
**normalization_build_kwargs: kwargs passed to the normalization module
at _build time.
Returns:
A 4D Tensor of shape `[batch_... | sonnet/python/modules/nets/convnet.py | def _build(self, inputs, **normalization_build_kwargs):
"""Assembles the `ConvNet2D` and connects it to the graph.
Args:
inputs: A 4D Tensor of shape `[batch_size, input_height, input_width,
input_channels]`.
**normalization_build_kwargs: kwargs passed to the normalization module
at... | def _build(self, inputs, **normalization_build_kwargs):
"""Assembles the `ConvNet2D` and connects it to the graph.
Args:
inputs: A 4D Tensor of shape `[batch_size, input_height, input_width,
input_channels]`.
**normalization_build_kwargs: kwargs passed to the normalization module
at... | [
"Assembles",
"the",
"ConvNet2D",
"and",
"connects",
"it",
"to",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L311-L361 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"*",
"*",
"normalization_build_kwargs",
")",
":",
"if",
"(",
"self",
".",
"_normalization_ctor",
"in",
"{",
"batch_norm",
".",
"BatchNorm",
",",
"batch_norm_v2",
".",
"BatchNormV2",
"}",
"and",
"\"is_training\"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ConvNet2D._transpose | Returns transposed version of this network.
Args:
transpose_constructor: A method that creates an instance of the transposed
network type. The method must accept the same kwargs as this methods
with the exception of the `transpose_constructor` argument.
name: Optional string specifying ... | sonnet/python/modules/nets/convnet.py | def _transpose(self,
transpose_constructor,
name=None,
output_channels=None,
kernel_shapes=None,
strides=None,
paddings=None,
activation=None,
activate_final=None,
nor... | def _transpose(self,
transpose_constructor,
name=None,
output_channels=None,
kernel_shapes=None,
strides=None,
paddings=None,
activation=None,
activate_final=None,
nor... | [
"Returns",
"transposed",
"version",
"of",
"this",
"network",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L445-L585 | [
"def",
"_transpose",
"(",
"self",
",",
"transpose_constructor",
",",
"name",
"=",
"None",
",",
"output_channels",
"=",
"None",
",",
"kernel_shapes",
"=",
"None",
",",
"strides",
"=",
"None",
",",
"paddings",
"=",
"None",
",",
"activation",
"=",
"None",
","... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ConvNet2D.transpose | Returns transposed version of this network.
Args:
name: Optional string specifying the name of the transposed module. The
default name is constructed by appending "_transpose"
to `self.module_name`.
output_channels: Optional iterable of numbers of output channels.
kernel_shapes: O... | sonnet/python/modules/nets/convnet.py | def transpose(self,
name=None,
output_channels=None,
kernel_shapes=None,
strides=None,
paddings=None,
activation=None,
activate_final=None,
normalization_ctor=None,
normalizati... | def transpose(self,
name=None,
output_channels=None,
kernel_shapes=None,
strides=None,
paddings=None,
activation=None,
activate_final=None,
normalization_ctor=None,
normalizati... | [
"Returns",
"transposed",
"version",
"of",
"this",
"network",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L588-L712 | [
"def",
"transpose",
"(",
"self",
",",
"name",
"=",
"None",
",",
"output_channels",
"=",
"None",
",",
"kernel_shapes",
"=",
"None",
",",
"strides",
"=",
"None",
",",
"paddings",
"=",
"None",
",",
"activation",
"=",
"None",
",",
"activate_final",
"=",
"Non... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ConvNet2DTranspose.transpose | Returns transposed version of this network.
Args:
name: Optional string specifying the name of the transposed module. The
default name is constructed by appending "_transpose"
to `self.module_name`.
output_channels: Optional iterable of numbers of output channels.
kernel_shapes: O... | sonnet/python/modules/nets/convnet.py | def transpose(self,
name=None,
output_channels=None,
kernel_shapes=None,
strides=None,
paddings=None,
activation=None,
activate_final=None,
normalization_ctor=None,
normalizati... | def transpose(self,
name=None,
output_channels=None,
kernel_shapes=None,
strides=None,
paddings=None,
activation=None,
activate_final=None,
normalization_ctor=None,
normalizati... | [
"Returns",
"transposed",
"version",
"of",
"this",
"network",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L880-L994 | [
"def",
"transpose",
"(",
"self",
",",
"name",
"=",
"None",
",",
"output_channels",
"=",
"None",
",",
"kernel_shapes",
"=",
"None",
",",
"strides",
"=",
"None",
",",
"paddings",
"=",
"None",
",",
"activation",
"=",
"None",
",",
"activate_final",
"=",
"Non... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _get_raw_data | Loads the data or reads it from cache. | sonnet/examples/brnn_ptb.py | def _get_raw_data(subset):
"""Loads the data or reads it from cache."""
raw_data = _LOADED.get(subset)
if raw_data is not None:
return raw_data, _LOADED["vocab"]
else:
train_data, valid_data, test_data, vocab = ptb_reader.ptb_raw_data(
FLAGS.data_path)
_LOADED.update({
"train": np.ar... | def _get_raw_data(subset):
"""Loads the data or reads it from cache."""
raw_data = _LOADED.get(subset)
if raw_data is not None:
return raw_data, _LOADED["vocab"]
else:
train_data, valid_data, test_data, vocab = ptb_reader.ptb_raw_data(
FLAGS.data_path)
_LOADED.update({
"train": np.ar... | [
"Loads",
"the",
"data",
"or",
"reads",
"it",
"from",
"cache",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L89-L103 | [
"def",
"_get_raw_data",
"(",
"subset",
")",
":",
"raw_data",
"=",
"_LOADED",
".",
"get",
"(",
"subset",
")",
"if",
"raw_data",
"is",
"not",
"None",
":",
"return",
"raw_data",
",",
"_LOADED",
"[",
"\"vocab\"",
"]",
"else",
":",
"train_data",
",",
"valid_d... | 00612ca3178964d86b556e062694d808ff81fcca |
train | custom_scale_mixture_prior_builder | A builder for the gaussian scale-mixture prior of Fortunato et al.
Please see https://arxiv.org/abs/1704.02798, section 7.1
Args:
getter: The `getter` passed to a `custom_getter`. Please see the
documentation for `tf.get_variable`.
name: The `name` argument passed to `tf.get_variable`.
*args: Po... | sonnet/examples/brnn_ptb.py | def custom_scale_mixture_prior_builder(getter, name, *args, **kwargs):
"""A builder for the gaussian scale-mixture prior of Fortunato et al.
Please see https://arxiv.org/abs/1704.02798, section 7.1
Args:
getter: The `getter` passed to a `custom_getter`. Please see the
documentation for `tf.get_variabl... | def custom_scale_mixture_prior_builder(getter, name, *args, **kwargs):
"""A builder for the gaussian scale-mixture prior of Fortunato et al.
Please see https://arxiv.org/abs/1704.02798, section 7.1
Args:
getter: The `getter` passed to a `custom_getter`. Please see the
documentation for `tf.get_variabl... | [
"A",
"builder",
"for",
"the",
"gaussian",
"scale",
"-",
"mixture",
"prior",
"of",
"Fortunato",
"et",
"al",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L181-L204 | [
"def",
"custom_scale_mixture_prior_builder",
"(",
"getter",
",",
"name",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# This specific prior formulation doesn't need any of the arguments forwarded",
"# from `get_variable`.",
"del",
"getter",
"del",
"name",
"del",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | lstm_posterior_builder | A builder for a particular diagonal gaussian posterior.
Args:
getter: The `getter` passed to a `custom_getter`. Please see the
documentation for `tf.get_variable`.
name: The `name` argument passed to `tf.get_variable`.
*args: Positional arguments forwarded by `tf.get_variable`.
**kwargs: Keywor... | sonnet/examples/brnn_ptb.py | def lstm_posterior_builder(getter, name, *args, **kwargs):
"""A builder for a particular diagonal gaussian posterior.
Args:
getter: The `getter` passed to a `custom_getter`. Please see the
documentation for `tf.get_variable`.
name: The `name` argument passed to `tf.get_variable`.
*args: Positiona... | def lstm_posterior_builder(getter, name, *args, **kwargs):
"""A builder for a particular diagonal gaussian posterior.
Args:
getter: The `getter` passed to a `custom_getter`. Please see the
documentation for `tf.get_variable`.
name: The `name` argument passed to `tf.get_variable`.
*args: Positiona... | [
"A",
"builder",
"for",
"a",
"particular",
"diagonal",
"gaussian",
"posterior",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L207-L245 | [
"def",
"lstm_posterior_builder",
"(",
"getter",
",",
"name",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"del",
"args",
"parameter_shapes",
"=",
"tfp",
".",
"distributions",
".",
"Normal",
".",
"param_static_shapes",
"(",
"kwargs",
"[",
"\"shape\"",... | 00612ca3178964d86b556e062694d808ff81fcca |
train | build_modules | Construct the modules used in the graph. | sonnet/examples/brnn_ptb.py | def build_modules(is_training, vocab_size):
"""Construct the modules used in the graph."""
# Construct the custom getter which implements Bayes by Backprop.
if is_training:
estimator_mode = tf.constant(bbb.EstimatorModes.sample)
else:
estimator_mode = tf.constant(bbb.EstimatorModes.mean)
lstm_bbb_cus... | def build_modules(is_training, vocab_size):
"""Construct the modules used in the graph."""
# Construct the custom getter which implements Bayes by Backprop.
if is_training:
estimator_mode = tf.constant(bbb.EstimatorModes.sample)
else:
estimator_mode = tf.constant(bbb.EstimatorModes.mean)
lstm_bbb_cus... | [
"Construct",
"the",
"modules",
"used",
"in",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L289-L330 | [
"def",
"build_modules",
"(",
"is_training",
",",
"vocab_size",
")",
":",
"# Construct the custom getter which implements Bayes by Backprop.",
"if",
"is_training",
":",
"estimator_mode",
"=",
"tf",
".",
"constant",
"(",
"bbb",
".",
"EstimatorModes",
".",
"sample",
")",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | build_logits | This is the core model logic.
Unrolls a Bayesian RNN over the given sequence.
Args:
data_ops: A `sequence_data.SequenceDataOps` namedtuple.
embed_layer: A `snt.Embed` instance.
rnn_core: A `snt.RNNCore` instance.
output_linear: A `snt.Linear` instance.
name_prefix: A string to use to prefix lo... | sonnet/examples/brnn_ptb.py | def build_logits(data_ops, embed_layer, rnn_core, output_linear, name_prefix):
"""This is the core model logic.
Unrolls a Bayesian RNN over the given sequence.
Args:
data_ops: A `sequence_data.SequenceDataOps` namedtuple.
embed_layer: A `snt.Embed` instance.
rnn_core: A `snt.RNNCore` instance.
o... | def build_logits(data_ops, embed_layer, rnn_core, output_linear, name_prefix):
"""This is the core model logic.
Unrolls a Bayesian RNN over the given sequence.
Args:
data_ops: A `sequence_data.SequenceDataOps` namedtuple.
embed_layer: A `snt.Embed` instance.
rnn_core: A `snt.RNNCore` instance.
o... | [
"This",
"is",
"the",
"core",
"model",
"logic",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L333-L376 | [
"def",
"build_logits",
"(",
"data_ops",
",",
"embed_layer",
",",
"rnn_core",
",",
"output_linear",
",",
"name_prefix",
")",
":",
"# Embed the input index sequence.",
"embedded_input_seq",
"=",
"snt",
".",
"BatchApply",
"(",
"embed_layer",
",",
"name",
"=",
"\"input_... | 00612ca3178964d86b556e062694d808ff81fcca |
train | build_loss | Compute the log loss given predictions and targets. | sonnet/examples/brnn_ptb.py | def build_loss(model_logits, sparse_targets):
"""Compute the log loss given predictions and targets."""
time_major_shape = [FLAGS.unroll_steps, FLAGS.batch_size]
flat_batch_shape = [FLAGS.unroll_steps * FLAGS.batch_size, -1]
xent = tf.nn.sparse_softmax_cross_entropy_with_logits(
logits=tf.reshape(model_lo... | def build_loss(model_logits, sparse_targets):
"""Compute the log loss given predictions and targets."""
time_major_shape = [FLAGS.unroll_steps, FLAGS.batch_size]
flat_batch_shape = [FLAGS.unroll_steps * FLAGS.batch_size, -1]
xent = tf.nn.sparse_softmax_cross_entropy_with_logits(
logits=tf.reshape(model_lo... | [
"Compute",
"the",
"log",
"loss",
"given",
"predictions",
"and",
"targets",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L379-L390 | [
"def",
"build_loss",
"(",
"model_logits",
",",
"sparse_targets",
")",
":",
"time_major_shape",
"=",
"[",
"FLAGS",
".",
"unroll_steps",
",",
"FLAGS",
".",
"batch_size",
"]",
"flat_batch_shape",
"=",
"[",
"FLAGS",
".",
"unroll_steps",
"*",
"FLAGS",
".",
"batch_s... | 00612ca3178964d86b556e062694d808ff81fcca |
train | train | Run a network on the PTB training set, checkpointing the weights. | sonnet/examples/brnn_ptb.py | def train(logdir):
"""Run a network on the PTB training set, checkpointing the weights."""
ptb_train = PTB(
name="ptb_train",
subset="train",
seq_len=FLAGS.unroll_steps,
batch_size=FLAGS.batch_size)
# Connect to training set.
data_ops = ptb_train()
embed_layer, rnn_core, output_linea... | def train(logdir):
"""Run a network on the PTB training set, checkpointing the weights."""
ptb_train = PTB(
name="ptb_train",
subset="train",
seq_len=FLAGS.unroll_steps,
batch_size=FLAGS.batch_size)
# Connect to training set.
data_ops = ptb_train()
embed_layer, rnn_core, output_linea... | [
"Run",
"a",
"network",
"on",
"the",
"PTB",
"training",
"set",
"checkpointing",
"the",
"weights",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L393-L541 | [
"def",
"train",
"(",
"logdir",
")",
":",
"ptb_train",
"=",
"PTB",
"(",
"name",
"=",
"\"ptb_train\"",
",",
"subset",
"=",
"\"train\"",
",",
"seq_len",
"=",
"FLAGS",
".",
"unroll_steps",
",",
"batch_size",
"=",
"FLAGS",
".",
"batch_size",
")",
"# Connect to ... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ensure_dependency_available_at_version | Throw helpful error if required dependencies not available. | sonnet/__init__.py | def _ensure_dependency_available_at_version(package_name, min_version):
"""Throw helpful error if required dependencies not available."""
try:
pkg = importlib.import_module(package_name)
except ImportError:
pip_name = package_name.replace('_', '-')
raise SystemError(
'Sonnet requires %s (mini... | def _ensure_dependency_available_at_version(package_name, min_version):
"""Throw helpful error if required dependencies not available."""
try:
pkg = importlib.import_module(package_name)
except ImportError:
pip_name = package_name.replace('_', '-')
raise SystemError(
'Sonnet requires %s (mini... | [
"Throw",
"helpful",
"error",
"if",
"required",
"dependencies",
"not",
"available",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/__init__.py#L43-L61 | [
"def",
"_ensure_dependency_available_at_version",
"(",
"package_name",
",",
"min_version",
")",
":",
"try",
":",
"pkg",
"=",
"importlib",
".",
"import_module",
"(",
"package_name",
")",
"except",
"ImportError",
":",
"pip_name",
"=",
"package_name",
".",
"replace",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _scale_gradient_op | Create an op that scales gradients using a Defun.
The tensorflow Defun decorator creates an op and tensorflow caches these ops
automatically according to `func_name`. Using a Defun decorator twice with the
same `func_name` does not create a new op, instead the cached op is used.
This method produces a new op ... | sonnet/python/modules/scale_gradient.py | def _scale_gradient_op(dtype):
"""Create an op that scales gradients using a Defun.
The tensorflow Defun decorator creates an op and tensorflow caches these ops
automatically according to `func_name`. Using a Defun decorator twice with the
same `func_name` does not create a new op, instead the cached op is use... | def _scale_gradient_op(dtype):
"""Create an op that scales gradients using a Defun.
The tensorflow Defun decorator creates an op and tensorflow caches these ops
automatically according to `func_name`. Using a Defun decorator twice with the
same `func_name` does not create a new op, instead the cached op is use... | [
"Create",
"an",
"op",
"that",
"scales",
"gradients",
"using",
"a",
"Defun",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/scale_gradient.py#L27-L61 | [
"def",
"_scale_gradient_op",
"(",
"dtype",
")",
":",
"def",
"scale_gradient_backward",
"(",
"op",
",",
"grad",
")",
":",
"scale",
"=",
"op",
".",
"inputs",
"[",
"1",
"]",
"scaled_grad",
"=",
"grad",
"*",
"scale",
"return",
"scaled_grad",
",",
"None",
"# ... | 00612ca3178964d86b556e062694d808ff81fcca |
train | scale_gradient | Scales gradients for the backwards pass.
This might be used to, for example, allow one part of a model to learn at a
lower rate than the rest.
WARNING: Think carefully about how your optimizer works. If, for example, you
use rmsprop, the gradient is always rescaled (with some additional epsilon)
towards uni... | sonnet/python/modules/scale_gradient.py | def scale_gradient(net, scale, name="scale_gradient"):
"""Scales gradients for the backwards pass.
This might be used to, for example, allow one part of a model to learn at a
lower rate than the rest.
WARNING: Think carefully about how your optimizer works. If, for example, you
use rmsprop, the gradient is ... | def scale_gradient(net, scale, name="scale_gradient"):
"""Scales gradients for the backwards pass.
This might be used to, for example, allow one part of a model to learn at a
lower rate than the rest.
WARNING: Think carefully about how your optimizer works. If, for example, you
use rmsprop, the gradient is ... | [
"Scales",
"gradients",
"for",
"the",
"backwards",
"pass",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/scale_gradient.py#L64-L113 | [
"def",
"scale_gradient",
"(",
"net",
",",
"scale",
",",
"name",
"=",
"\"scale_gradient\"",
")",
":",
"if",
"tf",
".",
"executing_eagerly",
"(",
")",
":",
"if",
"not",
"callable",
"(",
"net",
")",
":",
"raise",
"ValueError",
"(",
"\"In eager mode `net` must b... | 00612ca3178964d86b556e062694d808ff81fcca |
train | build_and_train | Construct the data, model, loss and optimizer then train. | sonnet/examples/rmc_learn_to_execute.py | def build_and_train(iterations, log_stride, test=False):
"""Construct the data, model, loss and optimizer then train."""
# Test mode settings.
batch_size = 2 if test else FLAGS.batch_size
num_mems = 2 if test else FLAGS.num_mems
num_heads = 1 if test else FLAGS.num_mems
num_blocks = 1 if test else FLAGS.nu... | def build_and_train(iterations, log_stride, test=False):
"""Construct the data, model, loss and optimizer then train."""
# Test mode settings.
batch_size = 2 if test else FLAGS.batch_size
num_mems = 2 if test else FLAGS.num_mems
num_heads = 1 if test else FLAGS.num_mems
num_blocks = 1 if test else FLAGS.nu... | [
"Construct",
"the",
"data",
"model",
"loss",
"and",
"optimizer",
"then",
"train",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/rmc_learn_to_execute.py#L110-L227 | [
"def",
"build_and_train",
"(",
"iterations",
",",
"log_stride",
",",
"test",
"=",
"False",
")",
":",
"# Test mode settings.",
"batch_size",
"=",
"2",
"if",
"test",
"else",
"FLAGS",
".",
"batch_size",
"num_mems",
"=",
"2",
"if",
"test",
"else",
"FLAGS",
".",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | SequenceModel._build | Dynamic unroll across input objects.
Args:
inputs: tensor (input_sequence_length x batch x feature_size). Encoder
sequence.
targets: tensor (output_sequence_length x batch x feature_size). Decoder
sequence.
input_sequence_length: tensor (batch). Size of each batched input
... | sonnet/examples/rmc_learn_to_execute.py | def _build(
self, inputs, targets, input_sequence_length, output_sequence_length):
"""Dynamic unroll across input objects.
Args:
inputs: tensor (input_sequence_length x batch x feature_size). Encoder
sequence.
targets: tensor (output_sequence_length x batch x feature_size). Decoder
... | def _build(
self, inputs, targets, input_sequence_length, output_sequence_length):
"""Dynamic unroll across input objects.
Args:
inputs: tensor (input_sequence_length x batch x feature_size). Encoder
sequence.
targets: tensor (output_sequence_length x batch x feature_size). Decoder
... | [
"Dynamic",
"unroll",
"across",
"input",
"objects",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/rmc_learn_to_execute.py#L69-L107 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"targets",
",",
"input_sequence_length",
",",
"output_sequence_length",
")",
":",
"# Connect decoding steps.",
"batch_size",
"=",
"inputs",
".",
"get_shape",
"(",
")",
"[",
"1",
"]",
"initial_state",
"=",
"self",... | 00612ca3178964d86b556e062694d808ff81fcca |
train | lstm_with_recurrent_dropout | LSTM with recurrent dropout.
Args:
hidden_size: the LSTM hidden size.
keep_prob: the probability to keep an entry when applying dropout.
**kwargs: Extra keyword arguments to pass to the LSTM.
Returns:
A tuple (train_lstm, test_lstm) where train_lstm is an LSTM with
recurrent dropout enabled to... | sonnet/python/modules/gated_rnn.py | def lstm_with_recurrent_dropout(hidden_size, keep_prob=0.5, **kwargs):
"""LSTM with recurrent dropout.
Args:
hidden_size: the LSTM hidden size.
keep_prob: the probability to keep an entry when applying dropout.
**kwargs: Extra keyword arguments to pass to the LSTM.
Returns:
A tuple (train_lstm, ... | def lstm_with_recurrent_dropout(hidden_size, keep_prob=0.5, **kwargs):
"""LSTM with recurrent dropout.
Args:
hidden_size: the LSTM hidden size.
keep_prob: the probability to keep an entry when applying dropout.
**kwargs: Extra keyword arguments to pass to the LSTM.
Returns:
A tuple (train_lstm, ... | [
"LSTM",
"with",
"recurrent",
"dropout",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L433-L448 | [
"def",
"lstm_with_recurrent_dropout",
"(",
"hidden_size",
",",
"keep_prob",
"=",
"0.5",
",",
"*",
"*",
"kwargs",
")",
":",
"lstm",
"=",
"LSTM",
"(",
"hidden_size",
",",
"*",
"*",
"kwargs",
")",
"return",
"RecurrentDropoutWrapper",
"(",
"lstm",
",",
"LSTMStat... | 00612ca3178964d86b556e062694d808ff81fcca |
train | lstm_with_zoneout | LSTM with recurrent dropout.
Args:
hidden_size: the LSTM hidden size.
keep_prob_c: the probability to use the new value of the cell state rather
than freezing it.
keep_prob_h: the probability to use the new value of the hidden state
rather than freezing it.
**kwargs: Extra keyword argumen... | sonnet/python/modules/gated_rnn.py | def lstm_with_zoneout(hidden_size, keep_prob_c=0.5, keep_prob_h=0.95, **kwargs):
"""LSTM with recurrent dropout.
Args:
hidden_size: the LSTM hidden size.
keep_prob_c: the probability to use the new value of the cell state rather
than freezing it.
keep_prob_h: the probability to use the new value ... | def lstm_with_zoneout(hidden_size, keep_prob_c=0.5, keep_prob_h=0.95, **kwargs):
"""LSTM with recurrent dropout.
Args:
hidden_size: the LSTM hidden size.
keep_prob_c: the probability to use the new value of the cell state rather
than freezing it.
keep_prob_h: the probability to use the new value ... | [
"LSTM",
"with",
"recurrent",
"dropout",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L519-L540 | [
"def",
"lstm_with_zoneout",
"(",
"hidden_size",
",",
"keep_prob_c",
"=",
"0.5",
",",
"keep_prob_h",
"=",
"0.95",
",",
"*",
"*",
"kwargs",
")",
":",
"lstm",
"=",
"LSTM",
"(",
"hidden_size",
",",
"*",
"*",
"kwargs",
")",
"keep_probs",
"=",
"LSTMState",
"("... | 00612ca3178964d86b556e062694d808ff81fcca |
train | highway_core_with_recurrent_dropout | Highway core with recurrent dropout.
Args:
hidden_size: (int) Hidden size dimensionality.
num_layers: (int) Number of highway layers.
keep_prob: the probability to keep an entry when applying dropout.
**kwargs: Extra keyword arguments to pass to the highway core.
Returns:
A tuple (train_core, ... | sonnet/python/modules/gated_rnn.py | def highway_core_with_recurrent_dropout(
hidden_size,
num_layers,
keep_prob=0.5,
**kwargs):
"""Highway core with recurrent dropout.
Args:
hidden_size: (int) Hidden size dimensionality.
num_layers: (int) Number of highway layers.
keep_prob: the probability to keep an entry when applying ... | def highway_core_with_recurrent_dropout(
hidden_size,
num_layers,
keep_prob=0.5,
**kwargs):
"""Highway core with recurrent dropout.
Args:
hidden_size: (int) Hidden size dimensionality.
num_layers: (int) Number of highway layers.
keep_prob: the probability to keep an entry when applying ... | [
"Highway",
"core",
"with",
"recurrent",
"dropout",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L1748-L1768 | [
"def",
"highway_core_with_recurrent_dropout",
"(",
"hidden_size",
",",
"num_layers",
",",
"keep_prob",
"=",
"0.5",
",",
"*",
"*",
"kwargs",
")",
":",
"core",
"=",
"HighwayCore",
"(",
"hidden_size",
",",
"num_layers",
",",
"*",
"*",
"kwargs",
")",
"return",
"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | LSTM.get_possible_initializer_keys | Returns the keys the dictionary of variable initializers may contain.
The set of all possible initializer keys are:
w_gates: weight for gates
b_gates: bias of gates
w_f_diag: weight for prev_cell -> forget gate peephole
w_i_diag: weight for prev_cell -> input gate peephole
w_o_diag:... | sonnet/python/modules/gated_rnn.py | def get_possible_initializer_keys(cls, use_peepholes=False,
use_projection=False):
"""Returns the keys the dictionary of variable initializers may contain.
The set of all possible initializer keys are:
w_gates: weight for gates
b_gates: bias of gates
w_f_... | def get_possible_initializer_keys(cls, use_peepholes=False,
use_projection=False):
"""Returns the keys the dictionary of variable initializers may contain.
The set of all possible initializer keys are:
w_gates: weight for gates
b_gates: bias of gates
w_f_... | [
"Returns",
"the",
"keys",
"the",
"dictionary",
"of",
"variable",
"initializers",
"may",
"contain",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L178-L207 | [
"def",
"get_possible_initializer_keys",
"(",
"cls",
",",
"use_peepholes",
"=",
"False",
",",
"use_projection",
"=",
"False",
")",
":",
"possible_keys",
"=",
"cls",
".",
"POSSIBLE_INITIALIZER_KEYS",
".",
"copy",
"(",
")",
"if",
"not",
"use_peepholes",
":",
"possi... | 00612ca3178964d86b556e062694d808ff81fcca |
train | LSTM._build | Connects the LSTM module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as inputs and state must have the same final
dimension, in order for the existing variables to be the correct size for
their corresponding multiplications. The batch s... | sonnet/python/modules/gated_rnn.py | def _build(self, inputs, prev_state):
"""Connects the LSTM module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as inputs and state must have the same final
dimension, in order for the existing variables to be the correct size for
the... | def _build(self, inputs, prev_state):
"""Connects the LSTM module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as inputs and state must have the same final
dimension, in order for the existing variables to be the correct size for
the... | [
"Connects",
"the",
"LSTM",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L209-L276 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"prev_state",
")",
":",
"prev_hidden",
",",
"prev_cell",
"=",
"prev_state",
"# pylint: disable=invalid-unary-operand-type",
"if",
"self",
".",
"_hidden_clip_value",
"is",
"not",
"None",
":",
"prev_hidden",
"=",
"tf... | 00612ca3178964d86b556e062694d808ff81fcca |
train | LSTM._create_gate_variables | Initialize the variables used for the gates. | sonnet/python/modules/gated_rnn.py | def _create_gate_variables(self, input_shape, dtype):
"""Initialize the variables used for the gates."""
if len(input_shape) != 2:
raise ValueError(
"Rank of shape must be {} not: {}".format(2, len(input_shape)))
equiv_input_size = self._hidden_state_size + input_shape.dims[1].value
ini... | def _create_gate_variables(self, input_shape, dtype):
"""Initialize the variables used for the gates."""
if len(input_shape) != 2:
raise ValueError(
"Rank of shape must be {} not: {}".format(2, len(input_shape)))
equiv_input_size = self._hidden_state_size + input_shape.dims[1].value
ini... | [
"Initialize",
"the",
"variables",
"used",
"for",
"the",
"gates",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L278-L310 | [
"def",
"_create_gate_variables",
"(",
"self",
",",
"input_shape",
",",
"dtype",
")",
":",
"if",
"len",
"(",
"input_shape",
")",
"!=",
"2",
":",
"raise",
"ValueError",
"(",
"\"Rank of shape must be {} not: {}\"",
".",
"format",
"(",
"2",
",",
"len",
"(",
"inp... | 00612ca3178964d86b556e062694d808ff81fcca |
train | LSTM._create_peephole_variables | Initialize the variables used for the peephole connections. | sonnet/python/modules/gated_rnn.py | def _create_peephole_variables(self, dtype):
"""Initialize the variables used for the peephole connections."""
self._w_f_diag = tf.get_variable(
self.W_F_DIAG,
shape=[self._hidden_size],
dtype=dtype,
initializer=self._initializers.get(self.W_F_DIAG),
partitioner=self._par... | def _create_peephole_variables(self, dtype):
"""Initialize the variables used for the peephole connections."""
self._w_f_diag = tf.get_variable(
self.W_F_DIAG,
shape=[self._hidden_size],
dtype=dtype,
initializer=self._initializers.get(self.W_F_DIAG),
partitioner=self._par... | [
"Initialize",
"the",
"variables",
"used",
"for",
"the",
"peephole",
"connections",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L312-L334 | [
"def",
"_create_peephole_variables",
"(",
"self",
",",
"dtype",
")",
":",
"self",
".",
"_w_f_diag",
"=",
"tf",
".",
"get_variable",
"(",
"self",
".",
"W_F_DIAG",
",",
"shape",
"=",
"[",
"self",
".",
"_hidden_size",
"]",
",",
"dtype",
"=",
"dtype",
",",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | LSTM.state_size | Tuple of `tf.TensorShape`s indicating the size of state tensors. | sonnet/python/modules/gated_rnn.py | def state_size(self):
"""Tuple of `tf.TensorShape`s indicating the size of state tensors."""
return LSTMState(tf.TensorShape([self._hidden_state_size]),
tf.TensorShape([self._hidden_size])) | def state_size(self):
"""Tuple of `tf.TensorShape`s indicating the size of state tensors."""
return LSTMState(tf.TensorShape([self._hidden_state_size]),
tf.TensorShape([self._hidden_size])) | [
"Tuple",
"of",
"tf",
".",
"TensorShape",
"s",
"indicating",
"the",
"size",
"of",
"state",
"tensors",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L337-L340 | [
"def",
"state_size",
"(",
"self",
")",
":",
"return",
"LSTMState",
"(",
"tf",
".",
"TensorShape",
"(",
"[",
"self",
".",
"_hidden_state_size",
"]",
")",
",",
"tf",
".",
"TensorShape",
"(",
"[",
"self",
".",
"_hidden_size",
"]",
")",
")"
] | 00612ca3178964d86b556e062694d808ff81fcca |
train | RecurrentDropoutWrapper.initial_state | Builds the default start state tensor of zeros. | sonnet/python/modules/gated_rnn.py | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state tensor of zeros."""
core_initial_state = self._core.initial_state(
batch_size, dtype=dtyp... | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state tensor of zeros."""
core_initial_state = self._core.initial_state(
batch_size, dtype=dtyp... | [
"Builds",
"the",
"default",
"start",
"state",
"tensor",
"of",
"zeros",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L404-L422 | [
"def",
"initial_state",
"(",
"self",
",",
"batch_size",
",",
"dtype",
"=",
"tf",
".",
"float32",
",",
"trainable",
"=",
"False",
",",
"trainable_initializers",
"=",
"None",
",",
"trainable_regularizers",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"co... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ZoneoutWrapper.initial_state | Builds the default start state tensor of zeros. | sonnet/python/modules/gated_rnn.py | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state tensor of zeros."""
return self._core.initial_state(
batch_size, dtype=dtype, trainable=t... | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state tensor of zeros."""
return self._core.initial_state(
batch_size, dtype=dtype, trainable=t... | [
"Builds",
"the",
"default",
"start",
"state",
"tensor",
"of",
"zeros",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L501-L508 | [
"def",
"initial_state",
"(",
"self",
",",
"batch_size",
",",
"dtype",
"=",
"tf",
".",
"float32",
",",
"trainable",
"=",
"False",
",",
"trainable_initializers",
"=",
"None",
",",
"trainable_regularizers",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"re... | 00612ca3178964d86b556e062694d808ff81fcca |
train | BatchNormLSTM.with_batch_norm_control | Wraps this RNNCore with the additional control input to the `BatchNorm`s.
Example usage:
lstm = snt.BatchNormLSTM(4)
is_training = tf.placeholder(tf.bool)
rnn_input = ...
my_rnn = rnn.rnn(lstm.with_batch_norm_control(is_training), rnn_input)
Args:
is_training: Boolean that indic... | sonnet/python/modules/gated_rnn.py | def with_batch_norm_control(self, is_training, test_local_stats=True):
"""Wraps this RNNCore with the additional control input to the `BatchNorm`s.
Example usage:
lstm = snt.BatchNormLSTM(4)
is_training = tf.placeholder(tf.bool)
rnn_input = ...
my_rnn = rnn.rnn(lstm.with_batch_norm_con... | def with_batch_norm_control(self, is_training, test_local_stats=True):
"""Wraps this RNNCore with the additional control input to the `BatchNorm`s.
Example usage:
lstm = snt.BatchNormLSTM(4)
is_training = tf.placeholder(tf.bool)
rnn_input = ...
my_rnn = rnn.rnn(lstm.with_batch_norm_con... | [
"Wraps",
"this",
"RNNCore",
"with",
"the",
"additional",
"control",
"input",
"to",
"the",
"BatchNorm",
"s",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L742-L767 | [
"def",
"with_batch_norm_control",
"(",
"self",
",",
"is_training",
",",
"test_local_stats",
"=",
"True",
")",
":",
"return",
"BatchNormLSTM",
".",
"CoreWithExtraBuildArgs",
"(",
"self",
",",
"is_training",
"=",
"is_training",
",",
"test_local_stats",
"=",
"test_loca... | 00612ca3178964d86b556e062694d808ff81fcca |
train | BatchNormLSTM.get_possible_initializer_keys | Returns the keys the dictionary of variable initializers may contain.
The set of all possible initializer keys are:
w_gates: weight for gates
b_gates: bias of gates
w_f_diag: weight for prev_cell -> forget gate peephole
w_i_diag: weight for prev_cell -> input gate peephole
w_o_diag:... | sonnet/python/modules/gated_rnn.py | def get_possible_initializer_keys(
cls, use_peepholes=False, use_batch_norm_h=True, use_batch_norm_x=False,
use_batch_norm_c=False):
"""Returns the keys the dictionary of variable initializers may contain.
The set of all possible initializer keys are:
w_gates: weight for gates
b_gates:... | def get_possible_initializer_keys(
cls, use_peepholes=False, use_batch_norm_h=True, use_batch_norm_x=False,
use_batch_norm_c=False):
"""Returns the keys the dictionary of variable initializers may contain.
The set of all possible initializer keys are:
w_gates: weight for gates
b_gates:... | [
"Returns",
"the",
"keys",
"the",
"dictionary",
"of",
"variable",
"initializers",
"may",
"contain",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L770-L814 | [
"def",
"get_possible_initializer_keys",
"(",
"cls",
",",
"use_peepholes",
"=",
"False",
",",
"use_batch_norm_h",
"=",
"True",
",",
"use_batch_norm_x",
"=",
"False",
",",
"use_batch_norm_c",
"=",
"False",
")",
":",
"possible_keys",
"=",
"cls",
".",
"POSSIBLE_INITIA... | 00612ca3178964d86b556e062694d808ff81fcca |
train | BatchNormLSTM._build | Connects the LSTM module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as inputs and state must have the same final
dimension, in order for the existing variables to be the correct size for
their corresponding multiplications. The batch s... | sonnet/python/modules/gated_rnn.py | def _build(self, inputs, prev_state, is_training=None, test_local_stats=True):
"""Connects the LSTM module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as inputs and state must have the same final
dimension, in order for the existing var... | def _build(self, inputs, prev_state, is_training=None, test_local_stats=True):
"""Connects the LSTM module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as inputs and state must have the same final
dimension, in order for the existing var... | [
"Connects",
"the",
"LSTM",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L816-L920 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"prev_state",
",",
"is_training",
"=",
"None",
",",
"test_local_stats",
"=",
"True",
")",
":",
"if",
"is_training",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"Boolean is_training flag must be explicitly spec... | 00612ca3178964d86b556e062694d808ff81fcca |
train | BatchNormLSTM._create_batch_norm_variables | Initialize the variables used for the `BatchNorm`s (if any). | sonnet/python/modules/gated_rnn.py | def _create_batch_norm_variables(self, dtype):
"""Initialize the variables used for the `BatchNorm`s (if any)."""
# The paper recommends a value of 0.1 for good gradient flow through the
# tanh nonlinearity (although doesn't say whether this is for all gammas,
# or just some).
gamma_initializer = tf... | def _create_batch_norm_variables(self, dtype):
"""Initialize the variables used for the `BatchNorm`s (if any)."""
# The paper recommends a value of 0.1 for good gradient flow through the
# tanh nonlinearity (although doesn't say whether this is for all gammas,
# or just some).
gamma_initializer = tf... | [
"Initialize",
"the",
"variables",
"used",
"for",
"the",
"BatchNorm",
"s",
"(",
"if",
"any",
")",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L922-L959 | [
"def",
"_create_batch_norm_variables",
"(",
"self",
",",
"dtype",
")",
":",
"# The paper recommends a value of 0.1 for good gradient flow through the",
"# tanh nonlinearity (although doesn't say whether this is for all gammas,",
"# or just some).",
"gamma_initializer",
"=",
"tf",
".",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | BatchNormLSTM._create_gate_variables | Initialize the variables used for the gates. | sonnet/python/modules/gated_rnn.py | def _create_gate_variables(self, input_shape, dtype):
"""Initialize the variables used for the gates."""
if len(input_shape) != 2:
raise ValueError(
"Rank of shape must be {} not: {}".format(2, len(input_shape)))
input_size = input_shape.dims[1].value
b_shape = [4 * self._hidden_size]
... | def _create_gate_variables(self, input_shape, dtype):
"""Initialize the variables used for the gates."""
if len(input_shape) != 2:
raise ValueError(
"Rank of shape must be {} not: {}".format(2, len(input_shape)))
input_size = input_shape.dims[1].value
b_shape = [4 * self._hidden_size]
... | [
"Initialize",
"the",
"variables",
"used",
"for",
"the",
"gates",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L961-L1002 | [
"def",
"_create_gate_variables",
"(",
"self",
",",
"input_shape",
",",
"dtype",
")",
":",
"if",
"len",
"(",
"input_shape",
")",
"!=",
"2",
":",
"raise",
"ValueError",
"(",
"\"Rank of shape must be {} not: {}\"",
".",
"format",
"(",
"2",
",",
"len",
"(",
"inp... | 00612ca3178964d86b556e062694d808ff81fcca |
train | BatchNormLSTM.initial_state | Builds the default start state tensor of zeros.
Args:
batch_size: An int, float or scalar Tensor representing the batch size.
dtype: The data type to use for the state.
trainable: Boolean that indicates whether to learn the initial state.
trainable_initializers: An optional pair of initiali... | sonnet/python/modules/gated_rnn.py | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state tensor of zeros.
Args:
batch_size: An int, float or scalar Tensor representing the batch s... | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state tensor of zeros.
Args:
batch_size: An int, float or scalar Tensor representing the batch s... | [
"Builds",
"the",
"default",
"start",
"state",
"tensor",
"of",
"zeros",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L1028-L1074 | [
"def",
"initial_state",
"(",
"self",
",",
"batch_size",
",",
"dtype",
"=",
"tf",
".",
"float32",
",",
"trainable",
"=",
"False",
",",
"trainable_initializers",
"=",
"None",
",",
"trainable_regularizers",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"if... | 00612ca3178964d86b556e062694d808ff81fcca |
train | BatchNormLSTM.state_size | Tuple of `tf.TensorShape`s indicating the size of state tensors. | sonnet/python/modules/gated_rnn.py | def state_size(self):
"""Tuple of `tf.TensorShape`s indicating the size of state tensors."""
if self._max_unique_stats == 1:
return (tf.TensorShape([self._hidden_size]),
tf.TensorShape([self._hidden_size]))
else:
return (tf.TensorShape([self._hidden_size]),
tf.TensorS... | def state_size(self):
"""Tuple of `tf.TensorShape`s indicating the size of state tensors."""
if self._max_unique_stats == 1:
return (tf.TensorShape([self._hidden_size]),
tf.TensorShape([self._hidden_size]))
else:
return (tf.TensorShape([self._hidden_size]),
tf.TensorS... | [
"Tuple",
"of",
"tf",
".",
"TensorShape",
"s",
"indicating",
"the",
"size",
"of",
"state",
"tensors",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L1077-L1085 | [
"def",
"state_size",
"(",
"self",
")",
":",
"if",
"self",
".",
"_max_unique_stats",
"==",
"1",
":",
"return",
"(",
"tf",
".",
"TensorShape",
"(",
"[",
"self",
".",
"_hidden_size",
"]",
")",
",",
"tf",
".",
"TensorShape",
"(",
"[",
"self",
".",
"_hidd... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ConvLSTM._new_convolution | Returns new convolution.
Args:
use_bias: Use bias in convolutions. If False, clean_dict removes bias
entries from initializers, partitioners and regularizers passed to
the constructor of the convolution. | sonnet/python/modules/gated_rnn.py | def _new_convolution(self, use_bias):
"""Returns new convolution.
Args:
use_bias: Use bias in convolutions. If False, clean_dict removes bias
entries from initializers, partitioners and regularizers passed to
the constructor of the convolution.
"""
def clean_dict(input_dict):
... | def _new_convolution(self, use_bias):
"""Returns new convolution.
Args:
use_bias: Use bias in convolutions. If False, clean_dict removes bias
entries from initializers, partitioners and regularizers passed to
the constructor of the convolution.
"""
def clean_dict(input_dict):
... | [
"Returns",
"new",
"convolution",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L1321-L1345 | [
"def",
"_new_convolution",
"(",
"self",
",",
"use_bias",
")",
":",
"def",
"clean_dict",
"(",
"input_dict",
")",
":",
"if",
"input_dict",
"and",
"not",
"use_bias",
":",
"cleaned_dict",
"=",
"input_dict",
".",
"copy",
"(",
")",
"cleaned_dict",
".",
"pop",
"(... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ConvLSTM.state_size | Tuple of `tf.TensorShape`s indicating the size of state tensors. | sonnet/python/modules/gated_rnn.py | def state_size(self):
"""Tuple of `tf.TensorShape`s indicating the size of state tensors."""
hidden_size = tf.TensorShape(
self._input_shape[:-1] + (self._output_channels,))
return (hidden_size, hidden_size) | def state_size(self):
"""Tuple of `tf.TensorShape`s indicating the size of state tensors."""
hidden_size = tf.TensorShape(
self._input_shape[:-1] + (self._output_channels,))
return (hidden_size, hidden_size) | [
"Tuple",
"of",
"tf",
".",
"TensorShape",
"s",
"indicating",
"the",
"size",
"of",
"state",
"tensors",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L1352-L1356 | [
"def",
"state_size",
"(",
"self",
")",
":",
"hidden_size",
"=",
"tf",
".",
"TensorShape",
"(",
"self",
".",
"_input_shape",
"[",
":",
"-",
"1",
"]",
"+",
"(",
"self",
".",
"_output_channels",
",",
")",
")",
"return",
"(",
"hidden_size",
",",
"hidden_si... | 00612ca3178964d86b556e062694d808ff81fcca |
train | GRU._build | Connects the GRU module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as inputs and state must have the same final
dimension, in order for the existing variables to be the correct size for
their corresponding multiplications. The batch si... | sonnet/python/modules/gated_rnn.py | def _build(self, inputs, prev_state):
"""Connects the GRU module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as inputs and state must have the same final
dimension, in order for the existing variables to be the correct size for
thei... | def _build(self, inputs, prev_state):
"""Connects the GRU module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as inputs and state must have the same final
dimension, in order for the existing variables to be the correct size for
thei... | [
"Connects",
"the",
"GRU",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L1509-L1583 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"prev_state",
")",
":",
"input_size",
"=",
"inputs",
".",
"get_shape",
"(",
")",
"[",
"1",
"]",
"weight_shape",
"=",
"(",
"input_size",
",",
"self",
".",
"_hidden_size",
")",
"u_shape",
"=",
"(",
"self"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | HighwayCore.get_possible_initializer_keys | Returns the keys the dictionary of variable initializers may contain.
The set of all possible initializer keys are:
wt: weight for input -> T gate
wh: weight for input -> H gate
wtL: weight for prev state -> T gate for layer L (indexed from 0)
whL: weight for prev state -> H gate for layer ... | sonnet/python/modules/gated_rnn.py | def get_possible_initializer_keys(cls, num_layers):
"""Returns the keys the dictionary of variable initializers may contain.
The set of all possible initializer keys are:
wt: weight for input -> T gate
wh: weight for input -> H gate
wtL: weight for prev state -> T gate for layer L (indexed fr... | def get_possible_initializer_keys(cls, num_layers):
"""Returns the keys the dictionary of variable initializers may contain.
The set of all possible initializer keys are:
wt: weight for input -> T gate
wh: weight for input -> H gate
wtL: weight for prev state -> T gate for layer L (indexed fr... | [
"Returns",
"the",
"keys",
"the",
"dictionary",
"of",
"variable",
"initializers",
"may",
"contain",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L1661-L1686 | [
"def",
"get_possible_initializer_keys",
"(",
"cls",
",",
"num_layers",
")",
":",
"keys",
"=",
"[",
"cls",
".",
"WT",
",",
"cls",
".",
"WH",
"]",
"for",
"layer_index",
"in",
"xrange",
"(",
"num_layers",
")",
":",
"layer_str",
"=",
"str",
"(",
"layer_index... | 00612ca3178964d86b556e062694d808ff81fcca |
train | HighwayCore._build | Connects the highway core module into the graph.
Args:
inputs: Tensor of size `[batch_size, input_size]`.
prev_state: Tensor of size `[batch_size, hidden_size]`.
Returns:
A tuple (output, next_state) where `output` is a Tensor of size
`[batch_size, hidden_size]` and `next_state` is a T... | sonnet/python/modules/gated_rnn.py | def _build(self, inputs, prev_state):
"""Connects the highway core module into the graph.
Args:
inputs: Tensor of size `[batch_size, input_size]`.
prev_state: Tensor of size `[batch_size, hidden_size]`.
Returns:
A tuple (output, next_state) where `output` is a Tensor of size
`[batc... | def _build(self, inputs, prev_state):
"""Connects the highway core module into the graph.
Args:
inputs: Tensor of size `[batch_size, input_size]`.
prev_state: Tensor of size `[batch_size, hidden_size]`.
Returns:
A tuple (output, next_state) where `output` is a Tensor of size
`[batc... | [
"Connects",
"the",
"highway",
"core",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L1688-L1737 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"prev_state",
")",
":",
"input_size",
"=",
"inputs",
".",
"get_shape",
"(",
")",
"[",
"1",
"]",
"weight_shape",
"=",
"(",
"input_size",
",",
"self",
".",
"_hidden_size",
")",
"u_shape",
"=",
"(",
"self"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _get_flat_core_sizes | Obtains the list flattened output sizes of a list of cores.
Args:
cores: list of cores to get the shapes from.
Returns:
List of lists that, for each core, contains the list of its output
dimensions. | sonnet/python/modules/basic_rnn.py | def _get_flat_core_sizes(cores):
"""Obtains the list flattened output sizes of a list of cores.
Args:
cores: list of cores to get the shapes from.
Returns:
List of lists that, for each core, contains the list of its output
dimensions.
"""
core_sizes_lists = []
for core in cores:
flat_out... | def _get_flat_core_sizes(cores):
"""Obtains the list flattened output sizes of a list of cores.
Args:
cores: list of cores to get the shapes from.
Returns:
List of lists that, for each core, contains the list of its output
dimensions.
"""
core_sizes_lists = []
for core in cores:
flat_out... | [
"Obtains",
"the",
"list",
"flattened",
"output",
"sizes",
"of",
"a",
"list",
"of",
"cores",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic_rnn.py#L39-L54 | [
"def",
"_get_flat_core_sizes",
"(",
"cores",
")",
":",
"core_sizes_lists",
"=",
"[",
"]",
"for",
"core",
"in",
"cores",
":",
"flat_output_size",
"=",
"nest",
".",
"flatten",
"(",
"core",
".",
"output_size",
")",
"core_sizes_lists",
".",
"append",
"(",
"[",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _get_shape_without_batch_dimension | Converts Tensor nest to a TensorShape nest, removing batch dimension. | sonnet/python/modules/basic_rnn.py | def _get_shape_without_batch_dimension(tensor_nest):
"""Converts Tensor nest to a TensorShape nest, removing batch dimension."""
def _strip_batch_and_convert_to_shape(tensor):
return tensor.get_shape()[1:]
return nest.map_structure(_strip_batch_and_convert_to_shape, tensor_nest) | def _get_shape_without_batch_dimension(tensor_nest):
"""Converts Tensor nest to a TensorShape nest, removing batch dimension."""
def _strip_batch_and_convert_to_shape(tensor):
return tensor.get_shape()[1:]
return nest.map_structure(_strip_batch_and_convert_to_shape, tensor_nest) | [
"Converts",
"Tensor",
"nest",
"to",
"a",
"TensorShape",
"nest",
"removing",
"batch",
"dimension",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic_rnn.py#L57-L61 | [
"def",
"_get_shape_without_batch_dimension",
"(",
"tensor_nest",
")",
":",
"def",
"_strip_batch_and_convert_to_shape",
"(",
"tensor",
")",
":",
"return",
"tensor",
".",
"get_shape",
"(",
")",
"[",
"1",
":",
"]",
"return",
"nest",
".",
"map_structure",
"(",
"_str... | 00612ca3178964d86b556e062694d808ff81fcca |
train | VanillaRNN._build | Connects the VanillaRNN module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as input_ and state must have the same final
dimension, in order for the existing variables to be the correct size for
their corresponding multiplications. The b... | sonnet/python/modules/basic_rnn.py | def _build(self, input_, prev_state):
"""Connects the VanillaRNN module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as input_ and state must have the same final
dimension, in order for the existing variables to be the correct size for
... | def _build(self, input_, prev_state):
"""Connects the VanillaRNN module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as input_ and state must have the same final
dimension, in order for the existing variables to be the correct size for
... | [
"Connects",
"the",
"VanillaRNN",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic_rnn.py#L110-L149 | [
"def",
"_build",
"(",
"self",
",",
"input_",
",",
"prev_state",
")",
":",
"self",
".",
"_in_to_hidden_linear",
"=",
"basic",
".",
"Linear",
"(",
"self",
".",
"_hidden_size",
",",
"name",
"=",
"\"in_to_hidden\"",
",",
"initializers",
"=",
"self",
".",
"_ini... | 00612ca3178964d86b556e062694d808ff81fcca |
train | DeepRNN._check_cores_output_sizes | Checks the output_sizes of the cores of the DeepRNN module.
Raises:
ValueError: if the outputs of the cores cannot be concatenated along their
first dimension. | sonnet/python/modules/basic_rnn.py | def _check_cores_output_sizes(self):
"""Checks the output_sizes of the cores of the DeepRNN module.
Raises:
ValueError: if the outputs of the cores cannot be concatenated along their
first dimension.
"""
for core_sizes in zip(*tuple(_get_flat_core_sizes(self._cores))):
first_core_li... | def _check_cores_output_sizes(self):
"""Checks the output_sizes of the cores of the DeepRNN module.
Raises:
ValueError: if the outputs of the cores cannot be concatenated along their
first dimension.
"""
for core_sizes in zip(*tuple(_get_flat_core_sizes(self._cores))):
first_core_li... | [
"Checks",
"the",
"output_sizes",
"of",
"the",
"cores",
"of",
"the",
"DeepRNN",
"module",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic_rnn.py#L294-L309 | [
"def",
"_check_cores_output_sizes",
"(",
"self",
")",
":",
"for",
"core_sizes",
"in",
"zip",
"(",
"*",
"tuple",
"(",
"_get_flat_core_sizes",
"(",
"self",
".",
"_cores",
")",
")",
")",
":",
"first_core_list",
"=",
"core_sizes",
"[",
"0",
"]",
"[",
"1",
":... | 00612ca3178964d86b556e062694d808ff81fcca |
train | DeepRNN._build | Connects the DeepRNN module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as input_ and state must have the same final
dimension, in order for the existing variables to be the correct size for
their corresponding multiplications. The batc... | sonnet/python/modules/basic_rnn.py | def _build(self, inputs, prev_state, **kwargs):
"""Connects the DeepRNN module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as input_ and state must have the same final
dimension, in order for the existing variables to be the correct siz... | def _build(self, inputs, prev_state, **kwargs):
"""Connects the DeepRNN module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as input_ and state must have the same final
dimension, in order for the existing variables to be the correct siz... | [
"Connects",
"the",
"DeepRNN",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic_rnn.py#L311-L370 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"prev_state",
",",
"*",
"*",
"kwargs",
")",
":",
"current_input",
"=",
"inputs",
"next_states",
"=",
"[",
"]",
"outputs",
"=",
"[",
"]",
"recurrent_idx",
"=",
"0",
"concatenate",
"=",
"lambda",
"*",
"ar... | 00612ca3178964d86b556e062694d808ff81fcca |
train | DeepRNN.initial_state | Builds the default start state for a DeepRNN.
Args:
batch_size: An int, float or scalar Tensor representing the batch size.
dtype: The data type to use for the state.
trainable: Boolean that indicates whether to learn the initial state.
trainable_initializers: An initializer function or nes... | sonnet/python/modules/basic_rnn.py | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state for a DeepRNN.
Args:
batch_size: An int, float or scalar Tensor representing the batch siz... | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state for a DeepRNN.
Args:
batch_size: An int, float or scalar Tensor representing the batch siz... | [
"Builds",
"the",
"default",
"start",
"state",
"for",
"a",
"DeepRNN",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic_rnn.py#L372-L426 | [
"def",
"initial_state",
"(",
"self",
",",
"batch_size",
",",
"dtype",
"=",
"tf",
".",
"float32",
",",
"trainable",
"=",
"False",
",",
"trainable_initializers",
"=",
"None",
",",
"trainable_regularizers",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"in... | 00612ca3178964d86b556e062694d808ff81fcca |
train | ModelRNN._build | Connects the ModelRNN module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as input_ and state must have the same final
dimension, in order for the existing variables to be the correct size for
their corresponding multiplications. The bat... | sonnet/python/modules/basic_rnn.py | def _build(self, inputs, prev_state):
"""Connects the ModelRNN module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as input_ and state must have the same final
dimension, in order for the existing variables to be the correct size for
... | def _build(self, inputs, prev_state):
"""Connects the ModelRNN module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided as input_ and state must have the same final
dimension, in order for the existing variables to be the correct size for
... | [
"Connects",
"the",
"ModelRNN",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic_rnn.py#L517-L537 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"prev_state",
")",
":",
"next_state",
"=",
"self",
".",
"_model",
"(",
"prev_state",
")",
"# For ModelRNN, the next state of the RNN is the same as the output",
"return",
"next_state",
",",
"next_state"
] | 00612ca3178964d86b556e062694d808ff81fcca |
train | BidirectionalRNN._build | Connects the BidirectionalRNN module into the graph.
Args:
input_sequence: tensor (time, batch, [feature_1, ..]). It must be
time_major.
state: tuple of states for the forward and backward cores.
Returns:
A dict with forward/backard states and output sequences:
"outputs":{... | sonnet/python/modules/basic_rnn.py | def _build(self, input_sequence, state):
"""Connects the BidirectionalRNN module into the graph.
Args:
input_sequence: tensor (time, batch, [feature_1, ..]). It must be
time_major.
state: tuple of states for the forward and backward cores.
Returns:
A dict with forward/backard s... | def _build(self, input_sequence, state):
"""Connects the BidirectionalRNN module into the graph.
Args:
input_sequence: tensor (time, batch, [feature_1, ..]). It must be
time_major.
state: tuple of states for the forward and backward cores.
Returns:
A dict with forward/backard s... | [
"Connects",
"the",
"BidirectionalRNN",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic_rnn.py#L583-L649 | [
"def",
"_build",
"(",
"self",
",",
"input_sequence",
",",
"state",
")",
":",
"input_shape",
"=",
"input_sequence",
".",
"get_shape",
"(",
")",
"if",
"input_shape",
"[",
"0",
"]",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"Time dimension of input (dim 0)... | 00612ca3178964d86b556e062694d808ff81fcca |
train | BidirectionalRNN.initial_state | Builds the default start state for a BidirectionalRNN.
The Bidirectional RNN flattens the states of its forward and backward cores
and concatentates them.
Args:
batch_size: An int, float or scalar Tensor representing the batch size.
dtype: The data type to use for the state.
trainable: B... | sonnet/python/modules/basic_rnn.py | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state for a BidirectionalRNN.
The Bidirectional RNN flattens the states of its forward and backward co... | def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
trainable_initializers=None, trainable_regularizers=None,
name=None):
"""Builds the default start state for a BidirectionalRNN.
The Bidirectional RNN flattens the states of its forward and backward co... | [
"Builds",
"the",
"default",
"start",
"state",
"for",
"a",
"BidirectionalRNN",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic_rnn.py#L651-L686 | [
"def",
"initial_state",
"(",
"self",
",",
"batch_size",
",",
"dtype",
"=",
"tf",
".",
"float32",
",",
"trainable",
"=",
"False",
",",
"trainable_initializers",
"=",
"None",
",",
"trainable_regularizers",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"na... | 00612ca3178964d86b556e062694d808ff81fcca |
train | MLP._instantiate_layers | Instantiates all the linear modules used in the network.
Layers are instantiated in the constructor, as opposed to the build
function, because MLP implements the Transposable interface, and the
transpose function can be called before the module is actually connected
to the graph and build is called.
... | sonnet/python/modules/nets/mlp.py | def _instantiate_layers(self):
"""Instantiates all the linear modules used in the network.
Layers are instantiated in the constructor, as opposed to the build
function, because MLP implements the Transposable interface, and the
transpose function can be called before the module is actually connected
... | def _instantiate_layers(self):
"""Instantiates all the linear modules used in the network.
Layers are instantiated in the constructor, as opposed to the build
function, because MLP implements the Transposable interface, and the
transpose function can be called before the module is actually connected
... | [
"Instantiates",
"all",
"the",
"linear",
"modules",
"used",
"in",
"the",
"network",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/mlp.py#L112-L139 | [
"def",
"_instantiate_layers",
"(",
"self",
")",
":",
"# Here we are entering the module's variable scope to name our submodules",
"# correctly (not to create variables). As such it's safe to not check",
"# whether we're in the same graph. This is important if we're constructing",
"# the module in ... | 00612ca3178964d86b556e062694d808ff81fcca |
train | MLP._build | Assembles the `MLP` and connects it to the graph.
Args:
inputs: A 2D Tensor of size `[batch_size, input_size]`.
is_training: A bool or tf.Bool Tensor. Indicates whether we are
currently training. Defaults to `True`.
dropout_keep_prob: The probability that each element is kept when
... | sonnet/python/modules/nets/mlp.py | def _build(self, inputs, is_training=True, dropout_keep_prob=0.5):
"""Assembles the `MLP` and connects it to the graph.
Args:
inputs: A 2D Tensor of size `[batch_size, input_size]`.
is_training: A bool or tf.Bool Tensor. Indicates whether we are
currently training. Defaults to `True`.
... | def _build(self, inputs, is_training=True, dropout_keep_prob=0.5):
"""Assembles the `MLP` and connects it to the graph.
Args:
inputs: A 2D Tensor of size `[batch_size, input_size]`.
is_training: A bool or tf.Bool Tensor. Indicates whether we are
currently training. Defaults to `True`.
... | [
"Assembles",
"the",
"MLP",
"and",
"connects",
"it",
"to",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/mlp.py#L145-L174 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"is_training",
"=",
"True",
",",
"dropout_keep_prob",
"=",
"0.5",
")",
":",
"self",
".",
"_input_shape",
"=",
"tuple",
"(",
"inputs",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
")",
"net",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | MLP.output_sizes | Returns a tuple of all output sizes of all the layers. | sonnet/python/modules/nets/mlp.py | def output_sizes(self):
"""Returns a tuple of all output sizes of all the layers."""
return tuple([l() if callable(l) else l for l in self._output_sizes]) | def output_sizes(self):
"""Returns a tuple of all output sizes of all the layers."""
return tuple([l() if callable(l) else l for l in self._output_sizes]) | [
"Returns",
"a",
"tuple",
"of",
"all",
"output",
"sizes",
"of",
"all",
"the",
"layers",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/mlp.py#L182-L184 | [
"def",
"output_sizes",
"(",
"self",
")",
":",
"return",
"tuple",
"(",
"[",
"l",
"(",
")",
"if",
"callable",
"(",
"l",
")",
"else",
"l",
"for",
"l",
"in",
"self",
".",
"_output_sizes",
"]",
")"
] | 00612ca3178964d86b556e062694d808ff81fcca |
train | MLP.transpose | Returns transposed `MLP`.
Args:
name: Optional string specifying the name of the transposed module. The
default name is constructed by appending "_transpose"
to `self.module_name`.
activate_final: Optional boolean determining if the activation and batch
normalization, if turned ... | sonnet/python/modules/nets/mlp.py | def transpose(self, name=None, activate_final=None):
"""Returns transposed `MLP`.
Args:
name: Optional string specifying the name of the transposed module. The
default name is constructed by appending "_transpose"
to `self.module_name`.
activate_final: Optional boolean determining i... | def transpose(self, name=None, activate_final=None):
"""Returns transposed `MLP`.
Args:
name: Optional string specifying the name of the transposed module. The
default name is constructed by appending "_transpose"
to `self.module_name`.
activate_final: Optional boolean determining i... | [
"Returns",
"transposed",
"MLP",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/mlp.py#L237-L265 | [
"def",
"transpose",
"(",
"self",
",",
"name",
"=",
"None",
",",
"activate_final",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"module_name",
"+",
"\"_transpose\"",
"if",
"activate_final",
"is",
"None",
":",
"activate... | 00612ca3178964d86b556e062694d808ff81fcca |
train | MLP.clone | Creates a new MLP with the same structure.
Args:
name: Optional string specifying the name of the new module. The default
name is constructed by appending "_clone" to the original name.
Returns:
A cloned `MLP` module. | sonnet/python/modules/nets/mlp.py | def clone(self, name=None):
"""Creates a new MLP with the same structure.
Args:
name: Optional string specifying the name of the new module. The default
name is constructed by appending "_clone" to the original name.
Returns:
A cloned `MLP` module.
"""
if name is None:
n... | def clone(self, name=None):
"""Creates a new MLP with the same structure.
Args:
name: Optional string specifying the name of the new module. The default
name is constructed by appending "_clone" to the original name.
Returns:
A cloned `MLP` module.
"""
if name is None:
n... | [
"Creates",
"a",
"new",
"MLP",
"with",
"the",
"same",
"structure",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/mlp.py#L267-L289 | [
"def",
"clone",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"module_name",
"+",
"\"_clone\"",
"return",
"MLP",
"(",
"name",
"=",
"name",
",",
"output_sizes",
"=",
"self",
".",
"output_si... | 00612ca3178964d86b556e062694d808ff81fcca |
train | AlexNet._calc_min_size | Calculates the minimum size of the input layer.
Given a set of convolutional layers, calculate the minimum value of
the `input_height` and `input_width`, i.e. such that the output has
size 1x1. Assumes snt.VALID padding.
Args:
conv_layers: List of tuples `(output_channels, (kernel_size, stride),... | sonnet/python/modules/nets/alexnet.py | def _calc_min_size(self, conv_layers):
"""Calculates the minimum size of the input layer.
Given a set of convolutional layers, calculate the minimum value of
the `input_height` and `input_width`, i.e. such that the output has
size 1x1. Assumes snt.VALID padding.
Args:
conv_layers: List of tu... | def _calc_min_size(self, conv_layers):
"""Calculates the minimum size of the input layer.
Given a set of convolutional layers, calculate the minimum value of
the `input_height` and `input_width`, i.e. such that the output has
size 1x1. Assumes snt.VALID padding.
Args:
conv_layers: List of tu... | [
"Calculates",
"the",
"minimum",
"size",
"of",
"the",
"input",
"layer",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/alexnet.py#L154-L179 | [
"def",
"_calc_min_size",
"(",
"self",
",",
"conv_layers",
")",
":",
"input_size",
"=",
"1",
"for",
"_",
",",
"conv_params",
",",
"max_pooling",
"in",
"reversed",
"(",
"conv_layers",
")",
":",
"if",
"max_pooling",
"is",
"not",
"None",
":",
"kernel_size",
",... | 00612ca3178964d86b556e062694d808ff81fcca |
train | AlexNet._build | Connects the AlexNet module into the graph.
The is_training flag only controls the batch norm settings, if `False` it
does not force no dropout by overriding any input `keep_prob`. To avoid any
confusion this may cause, if `is_training=False` and `keep_prob` would cause
dropout to be applied, an error ... | sonnet/python/modules/nets/alexnet.py | def _build(self, inputs, keep_prob=None, is_training=None,
test_local_stats=True):
"""Connects the AlexNet module into the graph.
The is_training flag only controls the batch norm settings, if `False` it
does not force no dropout by overriding any input `keep_prob`. To avoid any
confusion ... | def _build(self, inputs, keep_prob=None, is_training=None,
test_local_stats=True):
"""Connects the AlexNet module into the graph.
The is_training flag only controls the batch norm settings, if `False` it
does not force no dropout by overriding any input `keep_prob`. To avoid any
confusion ... | [
"Connects",
"the",
"AlexNet",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/alexnet.py#L181-L291 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"keep_prob",
"=",
"None",
",",
"is_training",
"=",
"None",
",",
"test_local_stats",
"=",
"True",
")",
":",
"# Check input shape",
"if",
"(",
"self",
".",
"_use_batch_norm",
"or",
"keep_prob",
"is",
"not",
"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | NthFarthest._get_single_set | Generate one input sequence and output label.
Each sequences of objects has a feature that consists of the feature vector
for that object plus the encoding for its ID, the reference vector ID and
the n-th value relative ID for a total feature size of:
`num_objects` * 3 + `num_features`
Args:
... | sonnet/examples/dataset_nth_farthest.py | def _get_single_set(self, num_objects, num_features):
"""Generate one input sequence and output label.
Each sequences of objects has a feature that consists of the feature vector
for that object plus the encoding for its ID, the reference vector ID and
the n-th value relative ID for a total feature siz... | def _get_single_set(self, num_objects, num_features):
"""Generate one input sequence and output label.
Each sequences of objects has a feature that consists of the feature vector
for that object plus the encoding for its ID, the reference vector ID and
the n-th value relative ID for a total feature siz... | [
"Generate",
"one",
"input",
"sequence",
"and",
"output",
"label",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/dataset_nth_farthest.py#L51-L97 | [
"def",
"_get_single_set",
"(",
"self",
",",
"num_objects",
",",
"num_features",
")",
":",
"# Generate random binary vectors",
"data",
"=",
"np",
".",
"random",
".",
"uniform",
"(",
"-",
"1",
",",
"1",
",",
"size",
"=",
"(",
"num_objects",
",",
"num_features"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | NthFarthest._get_batch_data | Assembles a batch of input tensors and output labels.
Args:
batch_size: int. number of sequence batches.
num_objects: int. number of objects in the sequence.
num_features: int. feature size of each object.
Returns:
1. np.ndarray (`batch_size`, `num_objects`,
(`num_... | sonnet/examples/dataset_nth_farthest.py | def _get_batch_data(self, batch_size, num_objects, num_features):
"""Assembles a batch of input tensors and output labels.
Args:
batch_size: int. number of sequence batches.
num_objects: int. number of objects in the sequence.
num_features: int. feature size of each object.
Returns:
... | def _get_batch_data(self, batch_size, num_objects, num_features):
"""Assembles a batch of input tensors and output labels.
Args:
batch_size: int. number of sequence batches.
num_objects: int. number of objects in the sequence.
num_features: int. feature size of each object.
Returns:
... | [
"Assembles",
"a",
"batch",
"of",
"input",
"tensors",
"and",
"output",
"labels",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/dataset_nth_farthest.py#L99-L120 | [
"def",
"_get_batch_data",
"(",
"self",
",",
"batch_size",
",",
"num_objects",
",",
"num_features",
")",
":",
"all_inputs",
"=",
"[",
"]",
"all_labels",
"=",
"[",
"]",
"for",
"_",
"in",
"six",
".",
"moves",
".",
"range",
"(",
"batch_size",
")",
":",
"in... | 00612ca3178964d86b556e062694d808ff81fcca |
train | NthFarthest.get_batch | Returns set of nth-farthest input tensors and labels.
Returns:
1. tf.Tensor (`batch_size`, `num_objects`,
(`num_features` + 3 * `num_objects`)).
2. tf.Tensor (`batch_size`). Output object reference label. | sonnet/examples/dataset_nth_farthest.py | def get_batch(self):
"""Returns set of nth-farthest input tensors and labels.
Returns:
1. tf.Tensor (`batch_size`, `num_objects`,
(`num_features` + 3 * `num_objects`)).
2. tf.Tensor (`batch_size`). Output object reference label.
"""
params = [self._batch_size, self._num... | def get_batch(self):
"""Returns set of nth-farthest input tensors and labels.
Returns:
1. tf.Tensor (`batch_size`, `num_objects`,
(`num_features` + 3 * `num_objects`)).
2. tf.Tensor (`batch_size`). Output object reference label.
"""
params = [self._batch_size, self._num... | [
"Returns",
"set",
"of",
"nth",
"-",
"farthest",
"input",
"tensors",
"and",
"labels",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/dataset_nth_farthest.py#L122-L136 | [
"def",
"get_batch",
"(",
"self",
")",
":",
"params",
"=",
"[",
"self",
".",
"_batch_size",
",",
"self",
".",
"_num_objects",
",",
"self",
".",
"_num_features",
"]",
"inputs",
",",
"labels",
"=",
"tf",
".",
"py_func",
"(",
"self",
".",
"_get_batch_data",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _default_transpose_size | Returns default (maximal) output shape for a transpose convolution.
In general, there are multiple possible output shapes that a transpose
convolution with a given `input_shape` can map to. This function returns the
output shape which evenly divides the stride to produce the input shape in
a forward convolutio... | sonnet/python/modules/conv.py | def _default_transpose_size(input_shape, stride, kernel_shape=None,
padding=SAME):
"""Returns default (maximal) output shape for a transpose convolution.
In general, there are multiple possible output shapes that a transpose
convolution with a given `input_shape` can map to. This func... | def _default_transpose_size(input_shape, stride, kernel_shape=None,
padding=SAME):
"""Returns default (maximal) output shape for a transpose convolution.
In general, there are multiple possible output shapes that a transpose
convolution with a given `input_shape` can map to. This func... | [
"Returns",
"default",
"(",
"maximal",
")",
"output",
"shape",
"for",
"a",
"transpose",
"convolution",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L63-L107 | [
"def",
"_default_transpose_size",
"(",
"input_shape",
",",
"stride",
",",
"kernel_shape",
"=",
"None",
",",
"padding",
"=",
"SAME",
")",
":",
"if",
"not",
"input_shape",
":",
"raise",
"TypeError",
"(",
"\"input_shape is None; if using Sonnet, are you sure you \"",
"\"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _fill_shape | Converts a dimension to a tuple of dimensions of a given size.
This is used to allow shorthand notation for various configuration parameters.
A user can provide either, for example, `2` or `[2, 2]` as a kernel shape, and
this function returns `(2, 2)` in both cases. Passing `[1, 2]` will return
`(1, 2)`.
Ar... | sonnet/python/modules/conv.py | def _fill_shape(x, n):
"""Converts a dimension to a tuple of dimensions of a given size.
This is used to allow shorthand notation for various configuration parameters.
A user can provide either, for example, `2` or `[2, 2]` as a kernel shape, and
this function returns `(2, 2)` in both cases. Passing `[1, 2]` w... | def _fill_shape(x, n):
"""Converts a dimension to a tuple of dimensions of a given size.
This is used to allow shorthand notation for various configuration parameters.
A user can provide either, for example, `2` or `[2, 2]` as a kernel shape, and
this function returns `(2, 2)` in both cases. Passing `[1, 2]` w... | [
"Converts",
"a",
"dimension",
"to",
"a",
"tuple",
"of",
"dimensions",
"of",
"a",
"given",
"size",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L110-L145 | [
"def",
"_fill_shape",
"(",
"x",
",",
"n",
")",
":",
"if",
"not",
"isinstance",
"(",
"n",
",",
"numbers",
".",
"Integral",
")",
"or",
"n",
"<",
"1",
":",
"raise",
"TypeError",
"(",
"\"n must be a positive integer\"",
")",
"if",
"(",
"isinstance",
"(",
"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _fill_and_verify_parameter_shape | Expands x if necessary into a `n`-D kernel shape and reports errors. | sonnet/python/modules/conv.py | def _fill_and_verify_parameter_shape(x, n, parameter_label):
"""Expands x if necessary into a `n`-D kernel shape and reports errors."""
try:
return _fill_shape(x, n)
except TypeError as e:
raise base.IncompatibleShapeError("Invalid " + parameter_label + " shape: "
"{}... | def _fill_and_verify_parameter_shape(x, n, parameter_label):
"""Expands x if necessary into a `n`-D kernel shape and reports errors."""
try:
return _fill_shape(x, n)
except TypeError as e:
raise base.IncompatibleShapeError("Invalid " + parameter_label + " shape: "
"{}... | [
"Expands",
"x",
"if",
"necessary",
"into",
"a",
"n",
"-",
"D",
"kernel",
"shape",
"and",
"reports",
"errors",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L148-L154 | [
"def",
"_fill_and_verify_parameter_shape",
"(",
"x",
",",
"n",
",",
"parameter_label",
")",
":",
"try",
":",
"return",
"_fill_shape",
"(",
"x",
",",
"n",
")",
"except",
"TypeError",
"as",
"e",
":",
"raise",
"base",
".",
"IncompatibleShapeError",
"(",
"\"Inva... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _fill_and_verify_padding | Verifies that the provided padding is supported and expands to size n.
Args:
padding: One of ALLOWED_PADDINGS, or an iterable of them.
n: An integer, the size of the desired output list.
Returns:
If `padding` is one of ALLOWED_PADDINGS, a tuple of size `n` containing `n`
copies of `padding`.
I... | sonnet/python/modules/conv.py | def _fill_and_verify_padding(padding, n):
"""Verifies that the provided padding is supported and expands to size n.
Args:
padding: One of ALLOWED_PADDINGS, or an iterable of them.
n: An integer, the size of the desired output list.
Returns:
If `padding` is one of ALLOWED_PADDINGS, a tuple of size `n... | def _fill_and_verify_padding(padding, n):
"""Verifies that the provided padding is supported and expands to size n.
Args:
padding: One of ALLOWED_PADDINGS, or an iterable of them.
n: An integer, the size of the desired output list.
Returns:
If `padding` is one of ALLOWED_PADDINGS, a tuple of size `n... | [
"Verifies",
"that",
"the",
"provided",
"padding",
"is",
"supported",
"and",
"expands",
"to",
"size",
"n",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L176-L206 | [
"def",
"_fill_and_verify_padding",
"(",
"padding",
",",
"n",
")",
":",
"if",
"not",
"isinstance",
"(",
"n",
",",
"numbers",
".",
"Integral",
")",
"or",
"n",
"<",
"1",
":",
"raise",
"TypeError",
"(",
"\"n must be a positive integer\"",
")",
"if",
"isinstance"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _padding_to_conv_op_padding | Whether to use SAME or VALID for the underlying convolution op.
Args:
padding: A tuple of members of ALLOWED_PADDINGS, e.g. as returned from
`_fill_and_verify_padding`.
Returns:
One of CONV_OP_ALLOWED_PADDINGS, the padding method to use for the
underlying convolution op.
Raises:
ValueErro... | sonnet/python/modules/conv.py | def _padding_to_conv_op_padding(padding):
"""Whether to use SAME or VALID for the underlying convolution op.
Args:
padding: A tuple of members of ALLOWED_PADDINGS, e.g. as returned from
`_fill_and_verify_padding`.
Returns:
One of CONV_OP_ALLOWED_PADDINGS, the padding method to use for the
unde... | def _padding_to_conv_op_padding(padding):
"""Whether to use SAME or VALID for the underlying convolution op.
Args:
padding: A tuple of members of ALLOWED_PADDINGS, e.g. as returned from
`_fill_and_verify_padding`.
Returns:
One of CONV_OP_ALLOWED_PADDINGS, the padding method to use for the
unde... | [
"Whether",
"to",
"use",
"SAME",
"or",
"VALID",
"for",
"the",
"underlying",
"convolution",
"op",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L209-L233 | [
"def",
"_padding_to_conv_op_padding",
"(",
"padding",
")",
":",
"if",
"not",
"isinstance",
"(",
"padding",
",",
"tuple",
")",
":",
"raise",
"ValueError",
"(",
"\"padding should be a tuple.\"",
")",
"if",
"all",
"(",
"p",
"==",
"SAME",
"for",
"p",
"in",
"padd... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _fill_and_one_pad_stride | Expands the provided stride to size n and pads it with 1s. | sonnet/python/modules/conv.py | def _fill_and_one_pad_stride(stride, n, data_format=DATA_FORMAT_NHWC):
"""Expands the provided stride to size n and pads it with 1s."""
if isinstance(stride, numbers.Integral) or (
isinstance(stride, collections.Iterable) and len(stride) <= n):
if data_format.startswith("NC"):
return (1, 1,) + _fill... | def _fill_and_one_pad_stride(stride, n, data_format=DATA_FORMAT_NHWC):
"""Expands the provided stride to size n and pads it with 1s."""
if isinstance(stride, numbers.Integral) or (
isinstance(stride, collections.Iterable) and len(stride) <= n):
if data_format.startswith("NC"):
return (1, 1,) + _fill... | [
"Expands",
"the",
"provided",
"stride",
"to",
"size",
"n",
"and",
"pads",
"it",
"with",
"1s",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L236-L253 | [
"def",
"_fill_and_one_pad_stride",
"(",
"stride",
",",
"n",
",",
"data_format",
"=",
"DATA_FORMAT_NHWC",
")",
":",
"if",
"isinstance",
"(",
"stride",
",",
"numbers",
".",
"Integral",
")",
"or",
"(",
"isinstance",
"(",
"stride",
",",
"collections",
".",
"Iter... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _verify_inputs | Verifies `inputs` is semantically correct.
Args:
inputs: An input tensor provided by the user.
channel_index: The index of the channel dimension.
data_format: The format of the data in `inputs`.
Raises:
base.IncompatibleShapeError: If the shape of `inputs` doesn't match
`data_format`.
ba... | sonnet/python/modules/conv.py | def _verify_inputs(inputs, channel_index, data_format):
"""Verifies `inputs` is semantically correct.
Args:
inputs: An input tensor provided by the user.
channel_index: The index of the channel dimension.
data_format: The format of the data in `inputs`.
Raises:
base.IncompatibleShapeError: If th... | def _verify_inputs(inputs, channel_index, data_format):
"""Verifies `inputs` is semantically correct.
Args:
inputs: An input tensor provided by the user.
channel_index: The index of the channel dimension.
data_format: The format of the data in `inputs`.
Raises:
base.IncompatibleShapeError: If th... | [
"Verifies",
"inputs",
"is",
"semantically",
"correct",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L256-L292 | [
"def",
"_verify_inputs",
"(",
"inputs",
",",
"channel_index",
",",
"data_format",
")",
":",
"# Check shape.",
"input_shape",
"=",
"tuple",
"(",
"inputs",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
")",
"if",
"len",
"(",
"input_shape",
")",
"!=",... | 00612ca3178964d86b556e062694d808ff81fcca |
train | create_weight_initializer | Returns a default initializer for the weights of a convolutional module. | sonnet/python/modules/conv.py | def create_weight_initializer(fan_in_shape, dtype=tf.float32):
"""Returns a default initializer for the weights of a convolutional module."""
stddev = 1 / math.sqrt(np.prod(fan_in_shape))
return tf.truncated_normal_initializer(stddev=stddev, dtype=dtype) | def create_weight_initializer(fan_in_shape, dtype=tf.float32):
"""Returns a default initializer for the weights of a convolutional module."""
stddev = 1 / math.sqrt(np.prod(fan_in_shape))
return tf.truncated_normal_initializer(stddev=stddev, dtype=dtype) | [
"Returns",
"a",
"default",
"initializer",
"for",
"the",
"weights",
"of",
"a",
"convolutional",
"module",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L295-L298 | [
"def",
"create_weight_initializer",
"(",
"fan_in_shape",
",",
"dtype",
"=",
"tf",
".",
"float32",
")",
":",
"stddev",
"=",
"1",
"/",
"math",
".",
"sqrt",
"(",
"np",
".",
"prod",
"(",
"fan_in_shape",
")",
")",
"return",
"tf",
".",
"truncated_normal_initiali... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _find_channel_index | Returns the index of the channel dimension.
Args:
data_format: A string of characters corresponding to Tensor dimensionality.
Returns:
channel_index: An integer indicating the channel dimension.
Raises:
ValueError: If no channel dimension was found. | sonnet/python/modules/conv.py | def _find_channel_index(data_format):
"""Returns the index of the channel dimension.
Args:
data_format: A string of characters corresponding to Tensor dimensionality.
Returns:
channel_index: An integer indicating the channel dimension.
Raises:
ValueError: If no channel dimension was found.
"""
... | def _find_channel_index(data_format):
"""Returns the index of the channel dimension.
Args:
data_format: A string of characters corresponding to Tensor dimensionality.
Returns:
channel_index: An integer indicating the channel dimension.
Raises:
ValueError: If no channel dimension was found.
"""
... | [
"Returns",
"the",
"index",
"of",
"the",
"channel",
"dimension",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L306-L322 | [
"def",
"_find_channel_index",
"(",
"data_format",
")",
":",
"for",
"i",
",",
"c",
"in",
"enumerate",
"(",
"data_format",
")",
":",
"if",
"c",
"==",
"\"C\"",
":",
"return",
"i",
"raise",
"ValueError",
"(",
"\"data_format requires a channel dimension. Got: {}\"",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _apply_bias | Initialize and apply a bias to the outputs.
Figures out the shape of the bias vector, initialize it, and applies it.
Args:
inputs: A Tensor of shape `data_format`.
outputs: A Tensor of shape `data_format`.
channel_index: The index of the channel dimension in `inputs`.
data_format: Format of `input... | sonnet/python/modules/conv.py | def _apply_bias(inputs, outputs, channel_index, data_format, output_channels,
initializers, partitioners, regularizers):
"""Initialize and apply a bias to the outputs.
Figures out the shape of the bias vector, initialize it, and applies it.
Args:
inputs: A Tensor of shape `data_format`.
... | def _apply_bias(inputs, outputs, channel_index, data_format, output_channels,
initializers, partitioners, regularizers):
"""Initialize and apply a bias to the outputs.
Figures out the shape of the bias vector, initialize it, and applies it.
Args:
inputs: A Tensor of shape `data_format`.
... | [
"Initialize",
"and",
"apply",
"a",
"bias",
"to",
"the",
"outputs",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L325-L369 | [
"def",
"_apply_bias",
"(",
"inputs",
",",
"outputs",
",",
"channel_index",
",",
"data_format",
",",
"output_channels",
",",
"initializers",
",",
"partitioners",
",",
"regularizers",
")",
":",
"bias_shape",
"=",
"(",
"output_channels",
",",
")",
"if",
"\"b\"",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvND._build | Connects the _ConvND module into the graph, with input Tensor `inputs`.
If this is not the first time the module has been connected to the graph,
the input Tensor provided here must have the same number of channels, in
order for the existing variables to be the correct size for the
multiplication; the ... | sonnet/python/modules/conv.py | def _build(self, inputs):
"""Connects the _ConvND module into the graph, with input Tensor `inputs`.
If this is not the first time the module has been connected to the graph,
the input Tensor provided here must have the same number of channels, in
order for the existing variables to be the correct size... | def _build(self, inputs):
"""Connects the _ConvND module into the graph, with input Tensor `inputs`.
If this is not the first time the module has been connected to the graph,
the input Tensor provided here must have the same number of channels, in
order for the existing variables to be the correct size... | [
"Connects",
"the",
"_ConvND",
"module",
"into",
"the",
"graph",
"with",
"input",
"Tensor",
"inputs",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L520-L570 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
")",
":",
"_verify_inputs",
"(",
"inputs",
",",
"self",
".",
"_channel_index",
",",
"self",
".",
"_data_format",
")",
"self",
".",
"_input_shape",
"=",
"tuple",
"(",
"inputs",
".",
"get_shape",
"(",
")",
".",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvND._pad_input | Pad input in case the desired padding type requires it.
VALID and SAME padding types are directly supported by tensorflow
convolution ops, so don't require us to pad input ourselves, at least
in cases where the same method is used for all dimensions.
Other padding types (FULL, CAUSAL, REVERSE_CAUSAL) ... | sonnet/python/modules/conv.py | def _pad_input(self, inputs):
"""Pad input in case the desired padding type requires it.
VALID and SAME padding types are directly supported by tensorflow
convolution ops, so don't require us to pad input ourselves, at least
in cases where the same method is used for all dimensions.
Other padding ... | def _pad_input(self, inputs):
"""Pad input in case the desired padding type requires it.
VALID and SAME padding types are directly supported by tensorflow
convolution ops, so don't require us to pad input ourselves, at least
in cases where the same method is used for all dimensions.
Other padding ... | [
"Pad",
"input",
"in",
"case",
"the",
"desired",
"padding",
"type",
"requires",
"it",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L572-L626 | [
"def",
"_pad_input",
"(",
"self",
",",
"inputs",
")",
":",
"if",
"all",
"(",
"p",
"==",
"self",
".",
"_conv_op_padding",
"for",
"p",
"in",
"self",
".",
"_padding",
")",
":",
"# All axes require the same padding type that we're going to use for the",
"# underlying co... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvND._apply_conv | Apply a convolution operation on `inputs` using variable `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A weight matrix of the same type as `inputs`.
Returns:
outputs: The result of the convolution operation on `inputs... | sonnet/python/modules/conv.py | def _apply_conv(self, inputs, w):
"""Apply a convolution operation on `inputs` using variable `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A weight matrix of the same type as `inputs`.
Returns:
outputs: The resul... | def _apply_conv(self, inputs, w):
"""Apply a convolution operation on `inputs` using variable `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A weight matrix of the same type as `inputs`.
Returns:
outputs: The resul... | [
"Apply",
"a",
"convolution",
"operation",
"on",
"inputs",
"using",
"variable",
"w",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L628-L643 | [
"def",
"_apply_conv",
"(",
"self",
",",
"inputs",
",",
"w",
")",
":",
"outputs",
"=",
"tf",
".",
"nn",
".",
"convolution",
"(",
"inputs",
",",
"w",
",",
"strides",
"=",
"self",
".",
"_stride",
",",
"padding",
"=",
"self",
".",
"_conv_op_padding",
","... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvND._apply_mask | Applies the passed-in mask to the convolution matrix.
Returns:
w: A copy of the convolution matrix that has had the mask applied.
Raises:
base.IncompatibleShapeError: If the mask shape has more dimensions than
the weight matrix.
base.IncompatibleShapeError: If the mask and the weig... | sonnet/python/modules/conv.py | def _apply_mask(self):
"""Applies the passed-in mask to the convolution matrix.
Returns:
w: A copy of the convolution matrix that has had the mask applied.
Raises:
base.IncompatibleShapeError: If the mask shape has more dimensions than
the weight matrix.
base.IncompatibleShapeE... | def _apply_mask(self):
"""Applies the passed-in mask to the convolution matrix.
Returns:
w: A copy of the convolution matrix that has had the mask applied.
Raises:
base.IncompatibleShapeError: If the mask shape has more dimensions than
the weight matrix.
base.IncompatibleShapeE... | [
"Applies",
"the",
"passed",
"-",
"in",
"mask",
"to",
"the",
"convolution",
"matrix",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L673-L710 | [
"def",
"_apply_mask",
"(",
"self",
")",
":",
"w",
"=",
"self",
".",
"_w",
"w_shape",
"=",
"w",
".",
"get_shape",
"(",
")",
"mask_shape",
"=",
"self",
".",
"_mask",
".",
"get_shape",
"(",
")",
"if",
"mask_shape",
".",
"ndims",
">",
"w_shape",
".",
"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvND.output_channels | Returns the number of output channels. | sonnet/python/modules/conv.py | def output_channels(self):
"""Returns the number of output channels."""
if callable(self._output_channels):
self._output_channels = self._output_channels()
# Channel must be integer.
self._output_channels = int(self._output_channels)
return self._output_channels | def output_channels(self):
"""Returns the number of output channels."""
if callable(self._output_channels):
self._output_channels = self._output_channels()
# Channel must be integer.
self._output_channels = int(self._output_channels)
return self._output_channels | [
"Returns",
"the",
"number",
"of",
"output",
"channels",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L713-L719 | [
"def",
"output_channels",
"(",
"self",
")",
":",
"if",
"callable",
"(",
"self",
".",
"_output_channels",
")",
":",
"self",
".",
"_output_channels",
"=",
"self",
".",
"_output_channels",
"(",
")",
"# Channel must be integer.",
"self",
".",
"_output_channels",
"="... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvND.padding | Returns the padding algorithm used, if this is the same for all dims.
Use `.paddings` if you want a tuple with the padding algorithm used for each
dimension.
Returns:
The padding algorithm used, if this is the same for all dimensions.
Raises:
ValueError: If different padding algorithms ar... | sonnet/python/modules/conv.py | def padding(self):
"""Returns the padding algorithm used, if this is the same for all dims.
Use `.paddings` if you want a tuple with the padding algorithm used for each
dimension.
Returns:
The padding algorithm used, if this is the same for all dimensions.
Raises:
ValueError: If diffe... | def padding(self):
"""Returns the padding algorithm used, if this is the same for all dims.
Use `.paddings` if you want a tuple with the padding algorithm used for each
dimension.
Returns:
The padding algorithm used, if this is the same for all dimensions.
Raises:
ValueError: If diffe... | [
"Returns",
"the",
"padding",
"algorithm",
"used",
"if",
"this",
"is",
"the",
"same",
"for",
"all",
"dims",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L739-L759 | [
"def",
"padding",
"(",
"self",
")",
":",
"# This is for backwards compatibility -- previously only a single",
"# padding setting was supported across all dimensions.",
"if",
"all",
"(",
"p",
"==",
"self",
".",
"_padding",
"[",
"0",
"]",
"for",
"p",
"in",
"self",
".",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvND.clone | Returns a cloned `_ConvND` module.
Args:
name: Optional string assigning name of cloned module. The default name
is constructed by appending "_clone" to `self.module_name`.
Returns:
A copy of the current class. | sonnet/python/modules/conv.py | def clone(self, name=None):
"""Returns a cloned `_ConvND` module.
Args:
name: Optional string assigning name of cloned module. The default name
is constructed by appending "_clone" to `self.module_name`.
Returns:
A copy of the current class.
"""
if name is None:
name = se... | def clone(self, name=None):
"""Returns a cloned `_ConvND` module.
Args:
name: Optional string assigning name of cloned module. The default name
is constructed by appending "_clone" to `self.module_name`.
Returns:
A copy of the current class.
"""
if name is None:
name = se... | [
"Returns",
"a",
"cloned",
"_ConvND",
"module",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L839-L864 | [
"def",
"clone",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"module_name",
"+",
"\"_clone\"",
"return",
"type",
"(",
"self",
")",
"(",
"output_channels",
"=",
"self",
".",
"output_channels... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvNDTranspose._build | Connects the _ConvNDTranspose module into the graph.
If this is not the first time the module has been connected to the graph,
the input Tensor provided here must have the same final N dimensions, in
order for the existing variables to be the correct size for the
multiplication. The batch size may diff... | sonnet/python/modules/conv.py | def _build(self, inputs):
"""Connects the _ConvNDTranspose module into the graph.
If this is not the first time the module has been connected to the graph,
the input Tensor provided here must have the same final N dimensions, in
order for the existing variables to be the correct size for the
multip... | def _build(self, inputs):
"""Connects the _ConvNDTranspose module into the graph.
If this is not the first time the module has been connected to the graph,
the input Tensor provided here must have the same final N dimensions, in
order for the existing variables to be the correct size for the
multip... | [
"Connects",
"the",
"_ConvNDTranspose",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L994-L1093 | [
"def",
"_build",
"(",
"self",
",",
"inputs",
")",
":",
"_verify_inputs",
"(",
"inputs",
",",
"self",
".",
"_channel_index",
",",
"self",
".",
"_data_format",
")",
"self",
".",
"_input_shape",
"=",
"tuple",
"(",
"inputs",
".",
"get_shape",
"(",
")",
".",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvNDTranspose._infer_all_output_dims | Calculate the output shape for `inputs` after a deconvolution.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
Returns:
output_shape: A tensor of shape (`batch_size`, `conv_output_shape`). | sonnet/python/modules/conv.py | def _infer_all_output_dims(self, inputs):
"""Calculate the output shape for `inputs` after a deconvolution.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
Returns:
output_shape: A tensor of shape (`batch_size`, `conv_output_shap... | def _infer_all_output_dims(self, inputs):
"""Calculate the output shape for `inputs` after a deconvolution.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
Returns:
output_shape: A tensor of shape (`batch_size`, `conv_output_shap... | [
"Calculate",
"the",
"output",
"shape",
"for",
"inputs",
"after",
"a",
"deconvolution",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L1128-L1157 | [
"def",
"_infer_all_output_dims",
"(",
"self",
",",
"inputs",
")",
":",
"# Use tensorflow shape op to manipulate inputs shape, so that unknown batch",
"# size - which can happen when using input placeholders - is handled",
"# correcly.",
"batch_size",
"=",
"tf",
".",
"expand_dims",
"(... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvNDTranspose._recover_shape_information | Recover output tensor shape value to enable shape inference.
The batch size of `inputs` isn't preserved by the convolution op. Calculate
what the proper output shape will be for `outputs`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`... | sonnet/python/modules/conv.py | def _recover_shape_information(self, inputs, outputs):
"""Recover output tensor shape value to enable shape inference.
The batch size of `inputs` isn't preserved by the convolution op. Calculate
what the proper output shape will be for `outputs`.
Args:
inputs: A Tensor of shape `data_format` and... | def _recover_shape_information(self, inputs, outputs):
"""Recover output tensor shape value to enable shape inference.
The batch size of `inputs` isn't preserved by the convolution op. Calculate
what the proper output shape will be for `outputs`.
Args:
inputs: A Tensor of shape `data_format` and... | [
"Recover",
"output",
"tensor",
"shape",
"value",
"to",
"enable",
"shape",
"inference",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L1159-L1183 | [
"def",
"_recover_shape_information",
"(",
"self",
",",
"inputs",
",",
"outputs",
")",
":",
"batch_size_value",
"=",
"inputs",
".",
"get_shape",
"(",
")",
"[",
"0",
"]",
"if",
"self",
".",
"_data_format",
".",
"startswith",
"(",
"\"NC\"",
")",
":",
"output_... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _ConvNDTranspose.output_shape | Returns the output shape. | sonnet/python/modules/conv.py | def output_shape(self):
"""Returns the output shape."""
if self._output_shape is None:
self._ensure_is_connected()
if callable(self._output_shape):
self._output_shape = tuple(self._output_shape())
return self._output_shape | def output_shape(self):
"""Returns the output shape."""
if self._output_shape is None:
self._ensure_is_connected()
if callable(self._output_shape):
self._output_shape = tuple(self._output_shape())
return self._output_shape | [
"Returns",
"the",
"output",
"shape",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L1205-L1211 | [
"def",
"output_shape",
"(",
"self",
")",
":",
"if",
"self",
".",
"_output_shape",
"is",
"None",
":",
"self",
".",
"_ensure_is_connected",
"(",
")",
"if",
"callable",
"(",
"self",
".",
"_output_shape",
")",
":",
"self",
".",
"_output_shape",
"=",
"tuple",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | Conv1DTranspose.transpose | Returns matching `Conv1D` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.
Returns:
`Conv1D` module. | sonnet/python/modules/conv.py | def transpose(self, name=None):
"""Returns matching `Conv1D` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.
Returns:
`Conv1D` module.
"""
if name is None:
name = self.module... | def transpose(self, name=None):
"""Returns matching `Conv1D` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.
Returns:
`Conv1D` module.
"""
if name is None:
name = self.module... | [
"Returns",
"matching",
"Conv1D",
"module",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L1517-L1545 | [
"def",
"transpose",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"module_name",
"+",
"\"_transpose\"",
"if",
"self",
".",
"_data_format",
"==",
"DATA_FORMAT_NWC",
":",
"stride",
"=",
"self",
... | 00612ca3178964d86b556e062694d808ff81fcca |
train | Conv2D.transpose | Returns matching `Conv2DTranspose` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.
Returns:
`Conv2DTranspose` module.
Raises:
base.NotSupportedError: If `rate` in any dimension > 1. | sonnet/python/modules/conv.py | def transpose(self, name=None):
"""Returns matching `Conv2DTranspose` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.
Returns:
`Conv2DTranspose` module.
Raises:
base.NotSupported... | def transpose(self, name=None):
"""Returns matching `Conv2DTranspose` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.
Returns:
`Conv2DTranspose` module.
Raises:
base.NotSupported... | [
"Returns",
"matching",
"Conv2DTranspose",
"module",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L1760-L1802 | [
"def",
"transpose",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"any",
"(",
"x",
">",
"1",
"for",
"x",
"in",
"self",
".",
"_rate",
")",
":",
"raise",
"base",
".",
"NotSupportedError",
"(",
"\"Cannot transpose a dilated convolution module.\"",
")... | 00612ca3178964d86b556e062694d808ff81fcca |
train | Conv2DTranspose.transpose | Returns matching `Conv2D` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.
Returns:
`Conv2D` module. | sonnet/python/modules/conv.py | def transpose(self, name=None):
"""Returns matching `Conv2D` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.
Returns:
`Conv2D` module.
"""
if name is None:
name = self.modu... | def transpose(self, name=None):
"""Returns matching `Conv2D` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.
Returns:
`Conv2D` module.
"""
if name is None:
name = self.modu... | [
"Returns",
"matching",
"Conv2D",
"module",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L1892-L1920 | [
"def",
"transpose",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"module_name",
"+",
"\"_transpose\"",
"if",
"self",
".",
"_data_format",
"==",
"DATA_FORMAT_NHWC",
":",
"stride",
"=",
"self",... | 00612ca3178964d86b556e062694d808ff81fcca |
train | InPlaneConv2D._construct_w | Construct the convolution weight matrix.
Figures out the shape of the weight matrix, initialize it, and return it.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
Returns:
w: A weight matrix of the same type as `inputs` and of s... | sonnet/python/modules/conv.py | def _construct_w(self, inputs):
"""Construct the convolution weight matrix.
Figures out the shape of the weight matrix, initialize it, and return it.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
Returns:
w: A weight matri... | def _construct_w(self, inputs):
"""Construct the convolution weight matrix.
Figures out the shape of the weight matrix, initialize it, and return it.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
Returns:
w: A weight matri... | [
"Construct",
"the",
"convolution",
"weight",
"matrix",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L2270-L2295 | [
"def",
"_construct_w",
"(",
"self",
",",
"inputs",
")",
":",
"weight_shape",
"=",
"self",
".",
"_kernel_shape",
"+",
"(",
"1",
",",
"1",
")",
"if",
"\"w\"",
"not",
"in",
"self",
".",
"_initializers",
":",
"self",
".",
"_initializers",
"[",
"\"w\"",
"]"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | InPlaneConv2D._apply_conv | Apply a depthwise_conv2d operation on `inputs` using variable `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A weight matrix of the same type as `inputs`.
Returns:
outputs: The result of the convolution operation on `i... | sonnet/python/modules/conv.py | def _apply_conv(self, inputs, w):
"""Apply a depthwise_conv2d operation on `inputs` using variable `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A weight matrix of the same type as `inputs`.
Returns:
outputs: The ... | def _apply_conv(self, inputs, w):
"""Apply a depthwise_conv2d operation on `inputs` using variable `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A weight matrix of the same type as `inputs`.
Returns:
outputs: The ... | [
"Apply",
"a",
"depthwise_conv2d",
"operation",
"on",
"inputs",
"using",
"variable",
"w",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L2297-L2314 | [
"def",
"_apply_conv",
"(",
"self",
",",
"inputs",
",",
"w",
")",
":",
"tiled_weights",
"=",
"tf",
".",
"tile",
"(",
"w",
",",
"[",
"1",
",",
"1",
",",
"self",
".",
"_input_channels",
",",
"1",
"]",
")",
"outputs",
"=",
"tf",
".",
"nn",
".",
"de... | 00612ca3178964d86b556e062694d808ff81fcca |
train | SeparableConv2D._construct_w | Connects the module into the graph, with input Tensor `inputs`.
Args:
inputs: A 4D Tensor of shape:
[batch_size, input_height, input_width, input_channels]
and of type `tf.float16`, `tf.bfloat16` or `tf.float32`.
Returns:
A tuple of two 4D Tensors, each with the same dtype as `... | sonnet/python/modules/conv.py | def _construct_w(self, inputs):
"""Connects the module into the graph, with input Tensor `inputs`.
Args:
inputs: A 4D Tensor of shape:
[batch_size, input_height, input_width, input_channels]
and of type `tf.float16`, `tf.bfloat16` or `tf.float32`.
Returns:
A tuple of two 4D... | def _construct_w(self, inputs):
"""Connects the module into the graph, with input Tensor `inputs`.
Args:
inputs: A 4D Tensor of shape:
[batch_size, input_height, input_width, input_channels]
and of type `tf.float16`, `tf.bfloat16` or `tf.float32`.
Returns:
A tuple of two 4D... | [
"Connects",
"the",
"module",
"into",
"the",
"graph",
"with",
"input",
"Tensor",
"inputs",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L2631-L2677 | [
"def",
"_construct_w",
"(",
"self",
",",
"inputs",
")",
":",
"depthwise_weight_shape",
"=",
"self",
".",
"_kernel_shape",
"+",
"(",
"self",
".",
"_input_channels",
",",
"self",
".",
"_channel_multiplier",
")",
"pointwise_input_size",
"=",
"self",
".",
"_channel_... | 00612ca3178964d86b556e062694d808ff81fcca |
train | SeparableConv2D._apply_conv | Apply a `separable_conv2d` operation on `inputs` using `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A tuple of weight matrices of the same type as `inputs`, the first
being the depthwise weight matrix, and the second be... | sonnet/python/modules/conv.py | def _apply_conv(self, inputs, w):
"""Apply a `separable_conv2d` operation on `inputs` using `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A tuple of weight matrices of the same type as `inputs`, the first
being the d... | def _apply_conv(self, inputs, w):
"""Apply a `separable_conv2d` operation on `inputs` using `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A tuple of weight matrices of the same type as `inputs`, the first
being the d... | [
"Apply",
"a",
"separable_conv2d",
"operation",
"on",
"inputs",
"using",
"w",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L2679-L2700 | [
"def",
"_apply_conv",
"(",
"self",
",",
"inputs",
",",
"w",
")",
":",
"w_dw",
",",
"w_pw",
"=",
"w",
"outputs",
"=",
"tf",
".",
"nn",
".",
"separable_conv2d",
"(",
"inputs",
",",
"w_dw",
",",
"w_pw",
",",
"rate",
"=",
"self",
".",
"_rate",
",",
"... | 00612ca3178964d86b556e062694d808ff81fcca |
train | SeparableConv1D._apply_conv | Apply a `separable_conv2d` operation on `inputs` using `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A tuple of weight matrices of the same type as `inputs`, the first
being the depthwise weight matrix, and the second be... | sonnet/python/modules/conv.py | def _apply_conv(self, inputs, w):
"""Apply a `separable_conv2d` operation on `inputs` using `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A tuple of weight matrices of the same type as `inputs`, the first
being the d... | def _apply_conv(self, inputs, w):
"""Apply a `separable_conv2d` operation on `inputs` using `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A tuple of weight matrices of the same type as `inputs`, the first
being the d... | [
"Apply",
"a",
"separable_conv2d",
"operation",
"on",
"inputs",
"using",
"w",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/conv.py#L2905-L2940 | [
"def",
"_apply_conv",
"(",
"self",
",",
"inputs",
",",
"w",
")",
":",
"if",
"self",
".",
"_data_format",
"==",
"DATA_FORMAT_NWC",
":",
"h_dim",
"=",
"1",
"two_dim_conv_data_format",
"=",
"DATA_FORMAT_NHWC",
"else",
":",
"h_dim",
"=",
"2",
"two_dim_conv_data_fo... | 00612ca3178964d86b556e062694d808ff81fcca |
train | Sequential._build | Connects the Sequential module into the graph.
Args:
*args: A tuple of inputs, to be unpacked as the arguments to the first
layer.
Returns:
The output value of the last layer. | sonnet/python/modules/sequential.py | def _build(self, *args):
"""Connects the Sequential module into the graph.
Args:
*args: A tuple of inputs, to be unpacked as the arguments to the first
layer.
Returns:
The output value of the last layer.
"""
net = args
if not self._layers:
# If the sequential is pa... | def _build(self, *args):
"""Connects the Sequential module into the graph.
Args:
*args: A tuple of inputs, to be unpacked as the arguments to the first
layer.
Returns:
The output value of the last layer.
"""
net = args
if not self._layers:
# If the sequential is pa... | [
"Connects",
"the",
"Sequential",
"module",
"into",
"the",
"graph",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/sequential.py#L79-L107 | [
"def",
"_build",
"(",
"self",
",",
"*",
"args",
")",
":",
"net",
"=",
"args",
"if",
"not",
"self",
".",
"_layers",
":",
"# If the sequential is passed a single arg, this will end up being",
"# wrapped in an extra layer of tuple by *args. Normally we internally",
"# handle thi... | 00612ca3178964d86b556e062694d808ff81fcca |
train | Sequential.get_variables | Provide a warning that get_variables on Sequential always returns (). | sonnet/python/modules/sequential.py | def get_variables(self, *args, **kwargs):
"""Provide a warning that get_variables on Sequential always returns ()."""
tf.logging.warning(
"Calling Sequential.get_variables, which will always return an empty "
"tuple. get_variables() can only return variables created directly by "
"a Modu... | def get_variables(self, *args, **kwargs):
"""Provide a warning that get_variables on Sequential always returns ()."""
tf.logging.warning(
"Calling Sequential.get_variables, which will always return an empty "
"tuple. get_variables() can only return variables created directly by "
"a Modu... | [
"Provide",
"a",
"warning",
"that",
"get_variables",
"on",
"Sequential",
"always",
"returns",
"()",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/sequential.py#L113-L124 | [
"def",
"get_variables",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"tf",
".",
"logging",
".",
"warning",
"(",
"\"Calling Sequential.get_variables, which will always return an empty \"",
"\"tuple. get_variables() can only return variables created directl... | 00612ca3178964d86b556e062694d808ff81fcca |
train | override_args | Creates a custom getter that applies specified named arguments.
Args:
**kwargs: Overriding arguments for the custom getter to use in preference
the named arguments it's called with.
Returns:
Custom getter. | sonnet/python/custom_getters/override_args.py | def override_args(**kwargs):
"""Creates a custom getter that applies specified named arguments.
Args:
**kwargs: Overriding arguments for the custom getter to use in preference
the named arguments it's called with.
Returns:
Custom getter.
"""
override_kwargs = kwargs
def custom_getter(gette... | def override_args(**kwargs):
"""Creates a custom getter that applies specified named arguments.
Args:
**kwargs: Overriding arguments for the custom getter to use in preference
the named arguments it's called with.
Returns:
Custom getter.
"""
override_kwargs = kwargs
def custom_getter(gette... | [
"Creates",
"a",
"custom",
"getter",
"that",
"applies",
"specified",
"named",
"arguments",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/override_args.py#L24-L52 | [
"def",
"override_args",
"(",
"*",
"*",
"kwargs",
")",
":",
"override_kwargs",
"=",
"kwargs",
"def",
"custom_getter",
"(",
"getter",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Custom getter with certain named arguments overridden.\n\n Args:\n g... | 00612ca3178964d86b556e062694d808ff81fcca |
train | override_default_args | Creates a custom getter that applies specified named arguments.
The returned custom getter treats the specified named arguments as revised
defaults, and does not override any non-`None` argument values supplied by
the original get_variable call (or by a nested scope's custom getter).
Args:
**kwargs: Overr... | sonnet/python/custom_getters/override_args.py | def override_default_args(**kwargs):
"""Creates a custom getter that applies specified named arguments.
The returned custom getter treats the specified named arguments as revised
defaults, and does not override any non-`None` argument values supplied by
the original get_variable call (or by a nested scope's cu... | def override_default_args(**kwargs):
"""Creates a custom getter that applies specified named arguments.
The returned custom getter treats the specified named arguments as revised
defaults, and does not override any non-`None` argument values supplied by
the original get_variable call (or by a nested scope's cu... | [
"Creates",
"a",
"custom",
"getter",
"that",
"applies",
"specified",
"named",
"arguments",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/override_args.py#L55-L89 | [
"def",
"override_default_args",
"(",
"*",
"*",
"kwargs",
")",
":",
"override_default_kwargs",
"=",
"kwargs",
"def",
"custom_getter",
"(",
"getter",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Custom getter with certain named arguments overridden.\n\n ... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _build_migrated_variables | Builds the TensorFlow variables of the migrated checkpoint.
Args:
checkpoint_reader: A `tf.train.NewCheckPointReader` of the checkpoint to
be read from.
name_value_fn: Function taking two arguments, `name` and `value`, which
returns the pair of new name and value for that a variable of that name.... | sonnet/util/migrate_checkpoint.py | def _build_migrated_variables(checkpoint_reader, name_value_fn):
"""Builds the TensorFlow variables of the migrated checkpoint.
Args:
checkpoint_reader: A `tf.train.NewCheckPointReader` of the checkpoint to
be read from.
name_value_fn: Function taking two arguments, `name` and `value`, which
re... | def _build_migrated_variables(checkpoint_reader, name_value_fn):
"""Builds the TensorFlow variables of the migrated checkpoint.
Args:
checkpoint_reader: A `tf.train.NewCheckPointReader` of the checkpoint to
be read from.
name_value_fn: Function taking two arguments, `name` and `value`, which
re... | [
"Builds",
"the",
"TensorFlow",
"variables",
"of",
"the",
"migrated",
"checkpoint",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/util/migrate_checkpoint.py#L33-L62 | [
"def",
"_build_migrated_variables",
"(",
"checkpoint_reader",
",",
"name_value_fn",
")",
":",
"names_to_shapes",
"=",
"checkpoint_reader",
".",
"get_variable_to_shape_map",
"(",
")",
"new_name_to_variable",
"=",
"{",
"}",
"name_to_new_name",
"=",
"{",
"}",
"for",
"nam... | 00612ca3178964d86b556e062694d808ff81fcca |
train | _to_proto_sparse_tensor | Serializes a `tf.SparseTensor` into `nested_proto`.
Args:
sparse_tensor: An instance of `tf.SparseTensor`.
nested_proto: A `module_pb2.NestedData` instance to be filled from
`sparse_tensor`.
process_leafs: A function to be applied to the leaf valued of the nested
structure.
already_proces... | sonnet/python/modules/base_info.py | def _to_proto_sparse_tensor(sparse_tensor, nested_proto,
process_leafs, already_processed):
"""Serializes a `tf.SparseTensor` into `nested_proto`.
Args:
sparse_tensor: An instance of `tf.SparseTensor`.
nested_proto: A `module_pb2.NestedData` instance to be filled from
`spa... | def _to_proto_sparse_tensor(sparse_tensor, nested_proto,
process_leafs, already_processed):
"""Serializes a `tf.SparseTensor` into `nested_proto`.
Args:
sparse_tensor: An instance of `tf.SparseTensor`.
nested_proto: A `module_pb2.NestedData` instance to be filled from
`spa... | [
"Serializes",
"a",
"tf",
".",
"SparseTensor",
"into",
"nested_proto",
"."
] | deepmind/sonnet | python | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/base_info.py#L99-L116 | [
"def",
"_to_proto_sparse_tensor",
"(",
"sparse_tensor",
",",
"nested_proto",
",",
"process_leafs",
",",
"already_processed",
")",
":",
"already_processed",
".",
"add",
"(",
"id",
"(",
"sparse_tensor",
")",
")",
"nested_proto",
".",
"named_tuple",
".",
"name",
"=",... | 00612ca3178964d86b556e062694d808ff81fcca |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.