repo stringlengths 7 54 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 20 28.4k | docstring stringlengths 1 46.3k | docstring_tokens listlengths 1 1.66k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value | summary stringlengths 4 350 | obf_code stringlengths 7.85k 764k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
deepmind/sonnet | sonnet/python/modules/util.py | custom_getter_router | def custom_getter_router(custom_getter_map, name_fn):
"""Creates a custom getter than matches requests to dict of custom getters.
Custom getters are callables which implement the
[custom getter API]
(https://www.tensorflow.org/versions/r1.0/api_docs/python/tf/get_variable).
The returned custom getter dispat... | python | def custom_getter_router(custom_getter_map, name_fn):
"""Creates a custom getter than matches requests to dict of custom getters.
Custom getters are callables which implement the
[custom getter API]
(https://www.tensorflow.org/versions/r1.0/api_docs/python/tf/get_variable).
The returned custom getter dispat... | [
"def",
"custom_getter_router",
"(",
"custom_getter_map",
",",
"name_fn",
")",
":",
"for",
"custom_getter",
"in",
"custom_getter_map",
".",
"values",
"(",
")",
":",
"if",
"not",
"callable",
"(",
"custom_getter",
")",
":",
"raise",
"TypeError",
"(",
"\"Given custo... | Creates a custom getter than matches requests to dict of custom getters.
Custom getters are callables which implement the
[custom getter API]
(https://www.tensorflow.org/versions/r1.0/api_docs/python/tf/get_variable).
The returned custom getter dispatches calls based on pattern matching the
name of the requ... | [
"Creates",
"a",
"custom",
"getter",
"than",
"matches",
"requests",
"to",
"dict",
"of",
"custom",
"getters",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L300-L368 | train | Creates a custom getter that routes to a specific pattern matching the requested variable name. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | get_normalized_variable_map | def get_normalized_variable_map(scope_or_module,
collection=tf.GraphKeys.GLOBAL_VARIABLES,
context=None,
group_sliced_variables=True):
"""Builds map of `tf.Variable`s in scope or module with normalized names.
The names ... | python | def get_normalized_variable_map(scope_or_module,
collection=tf.GraphKeys.GLOBAL_VARIABLES,
context=None,
group_sliced_variables=True):
"""Builds map of `tf.Variable`s in scope or module with normalized names.
The names ... | [
"def",
"get_normalized_variable_map",
"(",
"scope_or_module",
",",
"collection",
"=",
"tf",
".",
"GraphKeys",
".",
"GLOBAL_VARIABLES",
",",
"context",
"=",
"None",
",",
"group_sliced_variables",
"=",
"True",
")",
":",
"scope_name",
"=",
"get_variable_scope_name",
"(... | Builds map of `tf.Variable`s in scope or module with normalized names.
The names of the variables are normalized to remove the scope prefix.
Args:
scope_or_module: Scope or module to build map from.
collection: Collection to restrict query to. By default this is
`tf.Graphkeys.GLOBAL_VARIABLES`, wh... | [
"Builds",
"map",
"of",
"tf",
".",
"Variable",
"s",
"in",
"scope",
"or",
"module",
"with",
"normalized",
"names",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L371-L425 | train | Returns a dictionary mapping normalized variable names to tf. Variables. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | get_saver | def get_saver(scope, collections=(tf.GraphKeys.GLOBAL_VARIABLES,), # pylint: disable=redefined-outer-name
context=None, **kwargs):
"""Builds a `tf.train.Saver` for the scope or module, with normalized names.
The names of the variables are normalized to remove the scope prefix.
This allows the same... | python | def get_saver(scope, collections=(tf.GraphKeys.GLOBAL_VARIABLES,), # pylint: disable=redefined-outer-name
context=None, **kwargs):
"""Builds a `tf.train.Saver` for the scope or module, with normalized names.
The names of the variables are normalized to remove the scope prefix.
This allows the same... | [
"def",
"get_saver",
"(",
"scope",
",",
"collections",
"=",
"(",
"tf",
".",
"GraphKeys",
".",
"GLOBAL_VARIABLES",
",",
")",
",",
"# pylint: disable=redefined-outer-name",
"context",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"variable_map",
"=",
"{",
"}"... | Builds a `tf.train.Saver` for the scope or module, with normalized names.
The names of the variables are normalized to remove the scope prefix.
This allows the same variables to be restored into another similar scope or
module using a complementary `tf.train.Saver` object.
Args:
scope: Scope or module. Va... | [
"Builds",
"a",
"tf",
".",
"train",
".",
"Saver",
"for",
"the",
"scope",
"or",
"module",
"with",
"normalized",
"names",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L428-L453 | train | Builds a tf. train. Saver object for the given scope or module. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | variable_map_items | def variable_map_items(variable_map):
"""Yields an iterator over (string, variable) pairs in the variable map.
In general, variable maps map variable names to either a `tf.Variable`, or
list of `tf.Variable`s (in case of sliced variables).
Args:
variable_map: dict, variable map over which to iterate.
Y... | python | def variable_map_items(variable_map):
"""Yields an iterator over (string, variable) pairs in the variable map.
In general, variable maps map variable names to either a `tf.Variable`, or
list of `tf.Variable`s (in case of sliced variables).
Args:
variable_map: dict, variable map over which to iterate.
Y... | [
"def",
"variable_map_items",
"(",
"variable_map",
")",
":",
"for",
"key",
",",
"var_or_vars",
"in",
"six",
".",
"iteritems",
"(",
"variable_map",
")",
":",
"if",
"isinstance",
"(",
"var_or_vars",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"for",
"var... | Yields an iterator over (string, variable) pairs in the variable map.
In general, variable maps map variable names to either a `tf.Variable`, or
list of `tf.Variable`s (in case of sliced variables).
Args:
variable_map: dict, variable map over which to iterate.
Yields:
(string, tf.Variable) pairs. | [
"Yields",
"an",
"iterator",
"over",
"(",
"string",
"variable",
")",
"pairs",
"in",
"the",
"variable",
"map",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L471-L488 | train | Yields an iterator over ( string tf. Variable pairs in variable map. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | _get_vars_to_collections | def _get_vars_to_collections(variables):
"""Returns a dict mapping variables to the collections they appear in."""
var_to_collections = collections.defaultdict(lambda: [])
if isinstance(variables, dict):
variables = list(v for _, v in variable_map_items(variables))
for graph in set(v.graph for v in variable... | python | def _get_vars_to_collections(variables):
"""Returns a dict mapping variables to the collections they appear in."""
var_to_collections = collections.defaultdict(lambda: [])
if isinstance(variables, dict):
variables = list(v for _, v in variable_map_items(variables))
for graph in set(v.graph for v in variable... | [
"def",
"_get_vars_to_collections",
"(",
"variables",
")",
":",
"var_to_collections",
"=",
"collections",
".",
"defaultdict",
"(",
"lambda",
":",
"[",
"]",
")",
"if",
"isinstance",
"(",
"variables",
",",
"dict",
")",
":",
"variables",
"=",
"list",
"(",
"v",
... | Returns a dict mapping variables to the collections they appear in. | [
"Returns",
"a",
"dict",
"mapping",
"variables",
"to",
"the",
"collections",
"they",
"appear",
"in",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L491-L506 | train | Returns a dict mapping variables to the collections they appear in. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | _format_device | def _format_device(var):
"""Returns the device with an annotation specifying `ResourceVariable`.
"legacy" means a normal tf.Variable while "resource" means a ResourceVariable.
For example:
`(legacy)`
`(resource)`
`/job:learner/task:0/device:CPU:* (legacy)`
`/job:learner/task:0/device:CPU:* (resource)`
... | python | def _format_device(var):
"""Returns the device with an annotation specifying `ResourceVariable`.
"legacy" means a normal tf.Variable while "resource" means a ResourceVariable.
For example:
`(legacy)`
`(resource)`
`/job:learner/task:0/device:CPU:* (legacy)`
`/job:learner/task:0/device:CPU:* (resource)`
... | [
"def",
"_format_device",
"(",
"var",
")",
":",
"if",
"var",
".",
"dtype",
".",
"name",
".",
"endswith",
"(",
"\"_ref\"",
")",
":",
"resource_var_annotation",
"=",
"\"(legacy)\"",
"else",
":",
"resource_var_annotation",
"=",
"\"(resource)\"",
"if",
"var",
".",
... | Returns the device with an annotation specifying `ResourceVariable`.
"legacy" means a normal tf.Variable while "resource" means a ResourceVariable.
For example:
`(legacy)`
`(resource)`
`/job:learner/task:0/device:CPU:* (legacy)`
`/job:learner/task:0/device:CPU:* (resource)`
Args:
var: The Tensorflo... | [
"Returns",
"the",
"device",
"with",
"an",
"annotation",
"specifying",
"ResourceVariable",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L509-L531 | train | Formats the device with an annotation specifying ResourceVariable. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | format_variables | def format_variables(variables, join_lines=True):
"""Takes a collection of variables and formats it as a table."""
rows = []
rows.append(("Variable", "Shape", "Type", "Collections", "Device"))
var_to_collections = _get_vars_to_collections(variables)
for var in sorted(variables, key=lambda var: var.op.name):
... | python | def format_variables(variables, join_lines=True):
"""Takes a collection of variables and formats it as a table."""
rows = []
rows.append(("Variable", "Shape", "Type", "Collections", "Device"))
var_to_collections = _get_vars_to_collections(variables)
for var in sorted(variables, key=lambda var: var.op.name):
... | [
"def",
"format_variables",
"(",
"variables",
",",
"join_lines",
"=",
"True",
")",
":",
"rows",
"=",
"[",
"]",
"rows",
".",
"append",
"(",
"(",
"\"Variable\"",
",",
"\"Shape\"",
",",
"\"Type\"",
",",
"\"Collections\"",
",",
"\"Device\"",
")",
")",
"var_to_c... | Takes a collection of variables and formats it as a table. | [
"Takes",
"a",
"collection",
"of",
"variables",
"and",
"formats",
"it",
"as",
"a",
"table",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L534-L547 | train | Takes a collection of variables and formats it as a table. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | format_variable_map | def format_variable_map(variable_map, join_lines=True):
"""Takes a key-to-variable map and formats it as a table."""
rows = []
rows.append(("Key", "Variable", "Shape", "Type", "Collections", "Device"))
var_to_collections = _get_vars_to_collections(variable_map)
sort_key = lambda item: (item[0], item[1].name)... | python | def format_variable_map(variable_map, join_lines=True):
"""Takes a key-to-variable map and formats it as a table."""
rows = []
rows.append(("Key", "Variable", "Shape", "Type", "Collections", "Device"))
var_to_collections = _get_vars_to_collections(variable_map)
sort_key = lambda item: (item[0], item[1].name)... | [
"def",
"format_variable_map",
"(",
"variable_map",
",",
"join_lines",
"=",
"True",
")",
":",
"rows",
"=",
"[",
"]",
"rows",
".",
"append",
"(",
"(",
"\"Key\"",
",",
"\"Variable\"",
",",
"\"Shape\"",
",",
"\"Type\"",
",",
"\"Collections\"",
",",
"\"Device\"",... | Takes a key-to-variable map and formats it as a table. | [
"Takes",
"a",
"key",
"-",
"to",
"-",
"variable",
"map",
"and",
"formats",
"it",
"as",
"a",
"table",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L550-L562 | train | Takes a key - to - variable map and formats it as a table. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | log_variables | def log_variables(variables=None):
"""Logs variable information.
This function logs the name, shape, type, collections, and device for either
all variables or a given iterable of variables. In the "Device" columns,
the nature of the variable (legacy or resource (for ResourceVariables)) is
also specified in p... | python | def log_variables(variables=None):
"""Logs variable information.
This function logs the name, shape, type, collections, and device for either
all variables or a given iterable of variables. In the "Device" columns,
the nature of the variable (legacy or resource (for ResourceVariables)) is
also specified in p... | [
"def",
"log_variables",
"(",
"variables",
"=",
"None",
")",
":",
"if",
"variables",
"is",
"None",
":",
"variables",
"=",
"tf",
".",
"global_variables",
"(",
")",
"+",
"tf",
".",
"local_variables",
"(",
")",
"for",
"row",
"in",
"format_variables",
"(",
"v... | Logs variable information.
This function logs the name, shape, type, collections, and device for either
all variables or a given iterable of variables. In the "Device" columns,
the nature of the variable (legacy or resource (for ResourceVariables)) is
also specified in parenthesis.
Args:
variables: iter... | [
"Logs",
"variable",
"information",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L565-L580 | train | Logs variables for either
or all variables. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | _num_bytes_to_human_readable | def _num_bytes_to_human_readable(num_bytes):
"""Returns human readable string of how much memory `num_bytes` fills."""
if num_bytes < (2 ** 10):
return "%d B" % num_bytes
elif num_bytes < (2 ** 20):
return "%.3f KB" % (float(num_bytes) / (2 ** 10))
elif num_bytes < (2 ** 30):
return "%.3f MB" % (flo... | python | def _num_bytes_to_human_readable(num_bytes):
"""Returns human readable string of how much memory `num_bytes` fills."""
if num_bytes < (2 ** 10):
return "%d B" % num_bytes
elif num_bytes < (2 ** 20):
return "%.3f KB" % (float(num_bytes) / (2 ** 10))
elif num_bytes < (2 ** 30):
return "%.3f MB" % (flo... | [
"def",
"_num_bytes_to_human_readable",
"(",
"num_bytes",
")",
":",
"if",
"num_bytes",
"<",
"(",
"2",
"**",
"10",
")",
":",
"return",
"\"%d B\"",
"%",
"num_bytes",
"elif",
"num_bytes",
"<",
"(",
"2",
"**",
"20",
")",
":",
"return",
"\"%.3f KB\"",
"%",
"("... | Returns human readable string of how much memory `num_bytes` fills. | [
"Returns",
"human",
"readable",
"string",
"of",
"how",
"much",
"memory",
"num_bytes",
"fills",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L583-L592 | train | Returns human readable string of how much memory num_bytes fills. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | summarize_variables | def summarize_variables(variables=None):
"""Logs a summary of variable information.
This function groups Variables by dtype and prints out the number of Variables
and the total number of scalar values for each datatype, as well as the total
memory consumed.
For Variables of type tf.string, the memory usage ... | python | def summarize_variables(variables=None):
"""Logs a summary of variable information.
This function groups Variables by dtype and prints out the number of Variables
and the total number of scalar values for each datatype, as well as the total
memory consumed.
For Variables of type tf.string, the memory usage ... | [
"def",
"summarize_variables",
"(",
"variables",
"=",
"None",
")",
":",
"variable_counts",
"=",
"count_variables_by_type",
"(",
"variables",
"=",
"variables",
")",
"total_num_scalars",
"=",
"0",
"total_num_bytes",
"=",
"0",
"# Sort by string representation of type name, so... | Logs a summary of variable information.
This function groups Variables by dtype and prints out the number of Variables
and the total number of scalar values for each datatype, as well as the total
memory consumed.
For Variables of type tf.string, the memory usage cannot be accurately
calculated from the Gra... | [
"Logs",
"a",
"summary",
"of",
"variable",
"information",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L595-L627 | train | Logs a summary of the number of variables comprising scalars and total memory consumed. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | count_variables_by_type | def count_variables_by_type(variables=None):
"""Returns a dict mapping dtypes to number of variables and scalars.
Args:
variables: iterable of `tf.Variable`s, or None. If None is passed, then all
global and local variables in the current graph are used.
Returns:
A dict mapping tf.dtype keys to a d... | python | def count_variables_by_type(variables=None):
"""Returns a dict mapping dtypes to number of variables and scalars.
Args:
variables: iterable of `tf.Variable`s, or None. If None is passed, then all
global and local variables in the current graph are used.
Returns:
A dict mapping tf.dtype keys to a d... | [
"def",
"count_variables_by_type",
"(",
"variables",
"=",
"None",
")",
":",
"if",
"variables",
"is",
"None",
":",
"variables",
"=",
"tf",
".",
"global_variables",
"(",
")",
"+",
"tf",
".",
"local_variables",
"(",
")",
"unique_types",
"=",
"set",
"(",
"v",
... | Returns a dict mapping dtypes to number of variables and scalars.
Args:
variables: iterable of `tf.Variable`s, or None. If None is passed, then all
global and local variables in the current graph are used.
Returns:
A dict mapping tf.dtype keys to a dict containing the keys 'num_scalars' and
'n... | [
"Returns",
"a",
"dict",
"mapping",
"dtypes",
"to",
"number",
"of",
"variables",
"and",
"scalars",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L630-L657 | train | Returns a dict mapping dtypes to number of variables and scalars. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | reuse_variables | def reuse_variables(method):
"""Wraps an arbitrary method so it does variable sharing.
This decorator creates variables the first time it calls `method`, and reuses
them for subsequent calls. The object that calls `method` provides a
`tf.VariableScope`, either as a `variable_scope` attribute or as the return
... | python | def reuse_variables(method):
"""Wraps an arbitrary method so it does variable sharing.
This decorator creates variables the first time it calls `method`, and reuses
them for subsequent calls. The object that calls `method` provides a
`tf.VariableScope`, either as a `variable_scope` attribute or as the return
... | [
"def",
"reuse_variables",
"(",
"method",
")",
":",
"initialized_variable_scopes_eager",
"=",
"set",
"(",
")",
"initialized_variable_scopes_graph",
"=",
"weakref",
".",
"WeakKeyDictionary",
"(",
")",
"# Ensure that the argument passed in is really a method by checking that the",
... | Wraps an arbitrary method so it does variable sharing.
This decorator creates variables the first time it calls `method`, and reuses
them for subsequent calls. The object that calls `method` provides a
`tf.VariableScope`, either as a `variable_scope` attribute or as the return
value of an `_enter_variable_scop... | [
"Wraps",
"an",
"arbitrary",
"method",
"so",
"it",
"does",
"variable",
"sharing",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L660-L878 | train | A decorator that creates variables that are used by the object that calls method and reuses them for subsequent calls. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | name_for_callable | def name_for_callable(func):
"""Returns a module name for a callable or `None` if no name can be found."""
if isinstance(func, functools.partial):
return name_for_callable(func.func)
try:
name = func.__name__
except AttributeError:
return None
if name == "<lambda>":
return None
else:
r... | python | def name_for_callable(func):
"""Returns a module name for a callable or `None` if no name can be found."""
if isinstance(func, functools.partial):
return name_for_callable(func.func)
try:
name = func.__name__
except AttributeError:
return None
if name == "<lambda>":
return None
else:
r... | [
"def",
"name_for_callable",
"(",
"func",
")",
":",
"if",
"isinstance",
"(",
"func",
",",
"functools",
".",
"partial",
")",
":",
"return",
"name_for_callable",
"(",
"func",
".",
"func",
")",
"try",
":",
"name",
"=",
"func",
".",
"__name__",
"except",
"Att... | Returns a module name for a callable or `None` if no name can be found. | [
"Returns",
"a",
"module",
"name",
"for",
"a",
"callable",
"or",
"None",
"if",
"no",
"name",
"can",
"be",
"found",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L881-L894 | train | Returns a module name for a callable or None if no name can be found. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | to_snake_case | def to_snake_case(camel_case):
"""Returns a CamelCase string as a snake_case string."""
if not re.match(r"^[A-Za-z_]\w*$", camel_case):
raise ValueError(
"Input string %s is not a valid Python identifier." % camel_case)
# Add underscore at word start and ends.
underscored = re.sub(r"([A-Z][a-z])", ... | python | def to_snake_case(camel_case):
"""Returns a CamelCase string as a snake_case string."""
if not re.match(r"^[A-Za-z_]\w*$", camel_case):
raise ValueError(
"Input string %s is not a valid Python identifier." % camel_case)
# Add underscore at word start and ends.
underscored = re.sub(r"([A-Z][a-z])", ... | [
"def",
"to_snake_case",
"(",
"camel_case",
")",
":",
"if",
"not",
"re",
".",
"match",
"(",
"r\"^[A-Za-z_]\\w*$\"",
",",
"camel_case",
")",
":",
"raise",
"ValueError",
"(",
"\"Input string %s is not a valid Python identifier.\"",
"%",
"camel_case",
")",
"# Add undersco... | Returns a CamelCase string as a snake_case string. | [
"Returns",
"a",
"CamelCase",
"string",
"as",
"a",
"snake_case",
"string",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L897-L909 | train | Converts a string to a snake_case string. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | notify_about_new_variables | def notify_about_new_variables(callback):
"""Calls `callback(var)` for all newly created variables.
Callback should not modify the variable passed in. Use cases that require
variables to be modified should use `variable_creator_scope` directly and sit
within the variable creator stack.
>>> variables = []
... | python | def notify_about_new_variables(callback):
"""Calls `callback(var)` for all newly created variables.
Callback should not modify the variable passed in. Use cases that require
variables to be modified should use `variable_creator_scope` directly and sit
within the variable creator stack.
>>> variables = []
... | [
"def",
"notify_about_new_variables",
"(",
"callback",
")",
":",
"def",
"_tracking_creator",
"(",
"getter",
",",
"*",
"*",
"kwargs",
")",
":",
"v",
"=",
"getter",
"(",
"*",
"*",
"kwargs",
")",
"callback",
"(",
"v",
")",
"return",
"v",
"with",
"tf",
".",... | Calls `callback(var)` for all newly created variables.
Callback should not modify the variable passed in. Use cases that require
variables to be modified should use `variable_creator_scope` directly and sit
within the variable creator stack.
>>> variables = []
>>> with notify_about_variables(variables.appen... | [
"Calls",
"callback",
"(",
"var",
")",
"for",
"all",
"newly",
"created",
"variables",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L941-L966 | train | Calls callback for all newly created variables. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | _recursive_getattr | def _recursive_getattr(module, path):
"""Recursively gets attributes inside `module` as specified by `path`."""
if "." not in path:
return getattr(module, path)
else:
first, rest = path.split(".", 1)
return _recursive_getattr(getattr(module, first), rest) | python | def _recursive_getattr(module, path):
"""Recursively gets attributes inside `module` as specified by `path`."""
if "." not in path:
return getattr(module, path)
else:
first, rest = path.split(".", 1)
return _recursive_getattr(getattr(module, first), rest) | [
"def",
"_recursive_getattr",
"(",
"module",
",",
"path",
")",
":",
"if",
"\".\"",
"not",
"in",
"path",
":",
"return",
"getattr",
"(",
"module",
",",
"path",
")",
"else",
":",
"first",
",",
"rest",
"=",
"path",
".",
"split",
"(",
"\".\"",
",",
"1",
... | Recursively gets attributes inside `module` as specified by `path`. | [
"Recursively",
"gets",
"attributes",
"inside",
"module",
"as",
"specified",
"by",
"path",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L975-L981 | train | Recursively gets attributes inside module as specified by path. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | parse_string_to_constructor | def parse_string_to_constructor(ctor_string):
"""Returns a callable which corresponds to the constructor string.
Various modules (eg, ConvNet2D) take constructor arguments which are
callables, indicating a submodule to build. These can be passed as
actual constructors, eg `snt.LayerNorm`, however that makes th... | python | def parse_string_to_constructor(ctor_string):
"""Returns a callable which corresponds to the constructor string.
Various modules (eg, ConvNet2D) take constructor arguments which are
callables, indicating a submodule to build. These can be passed as
actual constructors, eg `snt.LayerNorm`, however that makes th... | [
"def",
"parse_string_to_constructor",
"(",
"ctor_string",
")",
":",
"orig_ctor_string",
"=",
"ctor_string",
"if",
"\".\"",
"not",
"in",
"ctor_string",
":",
"# No module specified - assume part of Sonnet",
"ctor_string",
"=",
"\"sonnet.\"",
"+",
"ctor_string",
"if",
"ctor_... | Returns a callable which corresponds to the constructor string.
Various modules (eg, ConvNet2D) take constructor arguments which are
callables, indicating a submodule to build. These can be passed as
actual constructors, eg `snt.LayerNorm`, however that makes the config
for that module not trivially serializab... | [
"Returns",
"a",
"callable",
"which",
"corresponds",
"to",
"the",
"constructor",
"string",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L984-L1024 | train | Converts a string representation of a module in Sonnet to a callable which corresponds to the string representation of a module. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | supports_kwargs | def supports_kwargs(module_or_fn, kwargs_list):
"""Determines whether the provided callable supports all the kwargs.
This is useful when you have a module that might or might not support a
kwarg such as `is_training`. Rather than calling the module and catching the
error, risking the potential modification of ... | python | def supports_kwargs(module_or_fn, kwargs_list):
"""Determines whether the provided callable supports all the kwargs.
This is useful when you have a module that might or might not support a
kwarg such as `is_training`. Rather than calling the module and catching the
error, risking the potential modification of ... | [
"def",
"supports_kwargs",
"(",
"module_or_fn",
",",
"kwargs_list",
")",
":",
"if",
"isinstance",
"(",
"kwargs_list",
",",
"six",
".",
"string_types",
")",
":",
"kwargs_list",
"=",
"[",
"kwargs_list",
"]",
"# If it's not a function or method, then assume it's a module, s... | Determines whether the provided callable supports all the kwargs.
This is useful when you have a module that might or might not support a
kwarg such as `is_training`. Rather than calling the module and catching the
error, risking the potential modification of underlying state, this function
introspects the mod... | [
"Determines",
"whether",
"the",
"provided",
"callable",
"supports",
"all",
"the",
"kwargs",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L1039-L1099 | train | Determines whether the provided callable supports all the kwargs. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/util.py | remove_unsupported_kwargs | def remove_unsupported_kwargs(module_or_fn, all_kwargs_dict):
"""Removes any kwargs not supported by `module_or_fn` from `all_kwargs_dict`.
A new dict is return with shallow copies of keys & values from
`all_kwargs_dict`, as long as the key is accepted by module_or_fn. The
returned dict can then be used to con... | python | def remove_unsupported_kwargs(module_or_fn, all_kwargs_dict):
"""Removes any kwargs not supported by `module_or_fn` from `all_kwargs_dict`.
A new dict is return with shallow copies of keys & values from
`all_kwargs_dict`, as long as the key is accepted by module_or_fn. The
returned dict can then be used to con... | [
"def",
"remove_unsupported_kwargs",
"(",
"module_or_fn",
",",
"all_kwargs_dict",
")",
":",
"if",
"all_kwargs_dict",
"is",
"None",
":",
"all_kwargs_dict",
"=",
"{",
"}",
"if",
"not",
"isinstance",
"(",
"all_kwargs_dict",
",",
"dict",
")",
":",
"raise",
"ValueErro... | Removes any kwargs not supported by `module_or_fn` from `all_kwargs_dict`.
A new dict is return with shallow copies of keys & values from
`all_kwargs_dict`, as long as the key is accepted by module_or_fn. The
returned dict can then be used to connect `module_or_fn` (along with some
other inputs, ie non-keyword... | [
"Removes",
"any",
"kwargs",
"not",
"supported",
"by",
"module_or_fn",
"from",
"all_kwargs_dict",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/util.py#L1102-L1137 | train | Removes any kwargs not supported by module_or_fn from all_kwargs_dict. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | merge_leading_dims | def merge_leading_dims(array_or_tensor, n_dims=2):
"""Merge the first dimensions of a tensor.
Args:
array_or_tensor: Tensor to have its first dimensions merged. Can also
be an array or numerical value, which will be converted to a tensor
for batch application, if needed.
n_dims: Number of d... | python | def merge_leading_dims(array_or_tensor, n_dims=2):
"""Merge the first dimensions of a tensor.
Args:
array_or_tensor: Tensor to have its first dimensions merged. Can also
be an array or numerical value, which will be converted to a tensor
for batch application, if needed.
n_dims: Number of d... | [
"def",
"merge_leading_dims",
"(",
"array_or_tensor",
",",
"n_dims",
"=",
"2",
")",
":",
"tensor",
"=",
"tf",
".",
"convert_to_tensor",
"(",
"array_or_tensor",
")",
"tensor_shape_static",
"=",
"tensor",
".",
"get_shape",
"(",
")",
"# Check if the rank of the input te... | Merge the first dimensions of a tensor.
Args:
array_or_tensor: Tensor to have its first dimensions merged. Can also
be an array or numerical value, which will be converted to a tensor
for batch application, if needed.
n_dims: Number of dimensions to merge.
Returns:
Either the input val... | [
"Merge",
"the",
"first",
"dimensions",
"of",
"a",
"tensor",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L38-L89 | train | Merge the first dimensions of a tensor. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | split_leading_dim | def split_leading_dim(tensor, inputs, n_dims=2):
"""Split the first dimension of a tensor.
Args:
tensor: Tensor to have its first dimension split.
inputs: Original reference input to look the dimensions of.
n_dims: Number of dimensions to split.
Returns:
The input tensor, with its first dimensio... | python | def split_leading_dim(tensor, inputs, n_dims=2):
"""Split the first dimension of a tensor.
Args:
tensor: Tensor to have its first dimension split.
inputs: Original reference input to look the dimensions of.
n_dims: Number of dimensions to split.
Returns:
The input tensor, with its first dimensio... | [
"def",
"split_leading_dim",
"(",
"tensor",
",",
"inputs",
",",
"n_dims",
"=",
"2",
")",
":",
"input_shape_static",
"=",
"inputs",
".",
"get_shape",
"(",
")",
"input_shape_list",
"=",
"input_shape_static",
".",
"as_list",
"(",
")",
"tensor_shape_static",
"=",
"... | Split the first dimension of a tensor.
Args:
tensor: Tensor to have its first dimension split.
inputs: Original reference input to look the dimensions of.
n_dims: Number of dimensions to split.
Returns:
The input tensor, with its first dimension split. | [
"Split",
"the",
"first",
"dimension",
"of",
"a",
"tensor",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L92-L120 | train | Splits the first dimension of a tensor. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | create_linear_initializer | def create_linear_initializer(input_size, dtype=tf.float32):
"""Returns a default initializer for weights of a linear module."""
stddev = 1 / math.sqrt(input_size)
return tf.truncated_normal_initializer(stddev=stddev, dtype=dtype) | python | def create_linear_initializer(input_size, dtype=tf.float32):
"""Returns a default initializer for weights of a linear module."""
stddev = 1 / math.sqrt(input_size)
return tf.truncated_normal_initializer(stddev=stddev, dtype=dtype) | [
"def",
"create_linear_initializer",
"(",
"input_size",
",",
"dtype",
"=",
"tf",
".",
"float32",
")",
":",
"stddev",
"=",
"1",
"/",
"math",
".",
"sqrt",
"(",
"input_size",
")",
"return",
"tf",
".",
"truncated_normal_initializer",
"(",
"stddev",
"=",
"stddev",... | Returns a default initializer for weights of a linear module. | [
"Returns",
"a",
"default",
"initializer",
"for",
"weights",
"of",
"a",
"linear",
"module",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L123-L126 | train | Returns a default initializer for weights of a linear module. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | calculate_bias_shape | def calculate_bias_shape(input_shape, bias_dims):
"""Calculate `bias_shape` based on the `input_shape` and `bias_dims`.
Args:
input_shape: Shape of the input being passed into the module. The leading
dimension is the minibatch size.
bias_dims: The dimensions that bias should be applied over. The re... | python | def calculate_bias_shape(input_shape, bias_dims):
"""Calculate `bias_shape` based on the `input_shape` and `bias_dims`.
Args:
input_shape: Shape of the input being passed into the module. The leading
dimension is the minibatch size.
bias_dims: The dimensions that bias should be applied over. The re... | [
"def",
"calculate_bias_shape",
"(",
"input_shape",
",",
"bias_dims",
")",
":",
"input_rank",
"=",
"len",
"(",
"input_shape",
")",
"# If None, default is to use all dimensions.",
"if",
"bias_dims",
"is",
"None",
":",
"return",
"input_shape",
"[",
"1",
":",
"]",
"# ... | Calculate `bias_shape` based on the `input_shape` and `bias_dims`.
Args:
input_shape: Shape of the input being passed into the module. The leading
dimension is the minibatch size.
bias_dims: The dimensions that bias should be applied over. The remaining
dimensions will get broadcasted over.
... | [
"Calculate",
"bias_shape",
"based",
"on",
"the",
"input_shape",
"and",
"bias_dims",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L464-L502 | train | Calculate the bias_shape based on the input_shape and bias_dims. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | Linear._build | def _build(self, inputs):
"""Connects the Linear module into the graph, with input Tensor `inputs`.
If this is not the first time the module has been connected to the graph,
the Tensor provided here must have the same final dimension, in order for
the existing variables to be the correct size for the m... | python | def _build(self, inputs):
"""Connects the Linear module into the graph, with input Tensor `inputs`.
If this is not the first time the module has been connected to the graph,
the Tensor provided here must have the same final dimension, in order for
the existing variables to be the correct size for the m... | [
"def",
"_build",
"(",
"self",
",",
"inputs",
")",
":",
"input_shape",
"=",
"tuple",
"(",
"inputs",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
")",
"if",
"len",
"(",
"input_shape",
")",
"!=",
"2",
":",
"raise",
"base",
".",
"IncompatibleSha... | Connects the Linear module into the graph, with input Tensor `inputs`.
If this is not the first time the module has been connected to the graph,
the Tensor provided here must have the same final dimension, in order for
the existing variables to be the correct size for the multiplication. The
batch size... | [
"Connects",
"the",
"Linear",
"module",
"into",
"the",
"graph",
"with",
"input",
"Tensor",
"inputs",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L197-L265 | train | Connects the Linear module into the graph with input Tensor inputs. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | Linear.output_size | def output_size(self):
"""Returns the module output size."""
if callable(self._output_size):
self._output_size = self._output_size()
return self._output_size | python | def output_size(self):
"""Returns the module output size."""
if callable(self._output_size):
self._output_size = self._output_size()
return self._output_size | [
"def",
"output_size",
"(",
"self",
")",
":",
"if",
"callable",
"(",
"self",
".",
"_output_size",
")",
":",
"self",
".",
"_output_size",
"=",
"self",
".",
"_output_size",
"(",
")",
"return",
"self",
".",
"_output_size"
] | Returns the module output size. | [
"Returns",
"the",
"module",
"output",
"size",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L300-L304 | train | Returns the module output size. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | Linear.clone | def clone(self, name=None):
"""Returns a cloned `Linear` module.
Args:
name: Optional string assigning name of cloned module. The default name
is constructed by appending "_clone" to `self.module_name`.
Returns:
Cloned `Linear` module.
"""
if name is None:
name = self.m... | python | def clone(self, name=None):
"""Returns a cloned `Linear` module.
Args:
name: Optional string assigning name of cloned module. The default name
is constructed by appending "_clone" to `self.module_name`.
Returns:
Cloned `Linear` module.
"""
if name is None:
name = self.m... | [
"def",
"clone",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"module_name",
"+",
"\"_clone\"",
"return",
"Linear",
"(",
"output_size",
"=",
"self",
".",
"output_size",
",",
"use_bias",
"=",... | Returns a cloned `Linear` module.
Args:
name: Optional string assigning name of cloned module. The default name
is constructed by appending "_clone" to `self.module_name`.
Returns:
Cloned `Linear` module. | [
"Returns",
"a",
"cloned",
"Linear",
"module",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L326-L343 | train | Returns a cloned Linear module. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | ConcatLinear._build | def _build(self, inputs_list):
"""Connects the module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided here must have the same final dimensions as when called
the first time, in order for the existing variables to be the correct size
for... | python | def _build(self, inputs_list):
"""Connects the module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided here must have the same final dimensions as when called
the first time, in order for the existing variables to be the correct size
for... | [
"def",
"_build",
"(",
"self",
",",
"inputs_list",
")",
":",
"outputs",
"=",
"[",
"]",
"for",
"idx",
",",
"tensor",
"in",
"enumerate",
"(",
"inputs_list",
")",
":",
"outputs",
".",
"append",
"(",
"Linear",
"(",
"self",
".",
"_output_size",
",",
"initial... | Connects the module into the graph.
If this is not the first time the module has been connected to the graph,
the Tensors provided here must have the same final dimensions as when called
the first time, in order for the existing variables to be the correct size
for the multiplication. The batch size ma... | [
"Connects",
"the",
"module",
"into",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L436-L461 | train | Connects the module into the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | AddBias._build | def _build(self, inputs, multiplier=1):
"""Connects the Add module into the graph, with input Tensor `inputs`.
Args:
inputs: A Tensor of size `[batch_size, input_size1, ...]`.
multiplier: A scalar or Tensor which the bias term is multiplied by
before adding it to `inputs`. Anything which wo... | python | def _build(self, inputs, multiplier=1):
"""Connects the Add module into the graph, with input Tensor `inputs`.
Args:
inputs: A Tensor of size `[batch_size, input_size1, ...]`.
multiplier: A scalar or Tensor which the bias term is multiplied by
before adding it to `inputs`. Anything which wo... | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"multiplier",
"=",
"1",
")",
":",
"input_shape",
"=",
"tuple",
"(",
"inputs",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
")",
"bias_shape",
"=",
"calculate_bias_shape",
"(",
"input_shape",
",",... | Connects the Add module into the graph, with input Tensor `inputs`.
Args:
inputs: A Tensor of size `[batch_size, input_size1, ...]`.
multiplier: A scalar or Tensor which the bias term is multiplied by
before adding it to `inputs`. Anything which works in the expression
`bias * multiplie... | [
"Connects",
"the",
"Add",
"module",
"into",
"the",
"graph",
"with",
"input",
"Tensor",
"inputs",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L603-L672 | train | Connects the Add module into the graph with input Tensor inputs. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | AddBias.transpose | def transpose(self, name=None):
"""Returns transposed `AddBias` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.module_name`.
Returns:
Transposed `AddBias` module.
"""
if name is None:... | python | def transpose(self, name=None):
"""Returns transposed `AddBias` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.module_name`.
Returns:
Transposed `AddBias` module.
"""
if name is None:... | [
"def",
"transpose",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"module_name",
"+",
"\"_transpose\"",
"return",
"AddBias",
"(",
"output_shape",
"=",
"lambda",
":",
"self",
".",
"_input_shape... | Returns transposed `AddBias` module.
Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.module_name`.
Returns:
Transposed `AddBias` module. | [
"Returns",
"transposed",
"AddBias",
"module",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L696-L713 | train | Returns a transpose of the add bias module. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | BatchReshape._infer_shape | def _infer_shape(self, dimensions):
"""Replaces the -1 wildcard in the output shape vector.
This function infers the correct output shape given the input dimensions.
Args:
dimensions: List of input non-batch dimensions.
Returns:
Tuple of non-batch output dimensions.
"""
# Size of ... | python | def _infer_shape(self, dimensions):
"""Replaces the -1 wildcard in the output shape vector.
This function infers the correct output shape given the input dimensions.
Args:
dimensions: List of input non-batch dimensions.
Returns:
Tuple of non-batch output dimensions.
"""
# Size of ... | [
"def",
"_infer_shape",
"(",
"self",
",",
"dimensions",
")",
":",
"# Size of input",
"n",
"=",
"np",
".",
"prod",
"(",
"dimensions",
")",
"# Size of output where defined",
"m",
"=",
"np",
".",
"prod",
"(",
"abs",
"(",
"np",
".",
"array",
"(",
"self",
".",... | Replaces the -1 wildcard in the output shape vector.
This function infers the correct output shape given the input dimensions.
Args:
dimensions: List of input non-batch dimensions.
Returns:
Tuple of non-batch output dimensions. | [
"Replaces",
"the",
"-",
"1",
"wildcard",
"in",
"the",
"output",
"shape",
"vector",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L759-L777 | train | Infer the output shape vector given the input dimensions. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | BatchReshape._build | def _build(self, inputs):
"""Connects the module into the graph, with input Tensor `inputs`.
Args:
inputs: A Tensor of shape [b_1, b_2, ..., b_preserve_dims,
b_preserve_dims+1, ...].
Returns:
A Tensor of shape [b_1, b_2, ..., b_preserve_dims,
... | python | def _build(self, inputs):
"""Connects the module into the graph, with input Tensor `inputs`.
Args:
inputs: A Tensor of shape [b_1, b_2, ..., b_preserve_dims,
b_preserve_dims+1, ...].
Returns:
A Tensor of shape [b_1, b_2, ..., b_preserve_dims,
... | [
"def",
"_build",
"(",
"self",
",",
"inputs",
")",
":",
"full_input_shape",
"=",
"inputs",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"if",
"len",
"(",
"full_input_shape",
")",
"<",
"self",
".",
"_preserve_dims",
":",
"raise",
"ValueError",
"("... | Connects the module into the graph, with input Tensor `inputs`.
Args:
inputs: A Tensor of shape [b_1, b_2, ..., b_preserve_dims,
b_preserve_dims+1, ...].
Returns:
A Tensor of shape [b_1, b_2, ..., b_preserve_dims,
b_reshape_1, b_reshape_2, ... | [
"Connects",
"the",
"module",
"into",
"the",
"graph",
"with",
"input",
"Tensor",
"inputs",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L779-L860 | train | Connects the module into the graph with input Tensor inputs. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | BatchReshape.transpose | def transpose(self, name=None):
"""Returns transpose batch reshape."""
if name is None:
name = self.module_name + "_transpose"
return BatchReshape(shape=lambda: self.input_shape,
preserve_dims=self._preserve_dims,
name=name) | python | def transpose(self, name=None):
"""Returns transpose batch reshape."""
if name is None:
name = self.module_name + "_transpose"
return BatchReshape(shape=lambda: self.input_shape,
preserve_dims=self._preserve_dims,
name=name) | [
"def",
"transpose",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"module_name",
"+",
"\"_transpose\"",
"return",
"BatchReshape",
"(",
"shape",
"=",
"lambda",
":",
"self",
".",
"input_shape",
... | Returns transpose batch reshape. | [
"Returns",
"transpose",
"batch",
"reshape",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L868-L874 | train | Returns transpose batch reshape. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | TrainableVariable._build | def _build(self):
"""Connects the TrainableTensor module into the graph.
Returns:
A Tensor of shape as determined in the constructor.
"""
if "w" not in self._initializers:
stddev = 1 / math.sqrt(np.prod(self._shape))
self._initializers["w"] = tf.truncated_normal_initializer(stddev=std... | python | def _build(self):
"""Connects the TrainableTensor module into the graph.
Returns:
A Tensor of shape as determined in the constructor.
"""
if "w" not in self._initializers:
stddev = 1 / math.sqrt(np.prod(self._shape))
self._initializers["w"] = tf.truncated_normal_initializer(stddev=std... | [
"def",
"_build",
"(",
"self",
")",
":",
"if",
"\"w\"",
"not",
"in",
"self",
".",
"_initializers",
":",
"stddev",
"=",
"1",
"/",
"math",
".",
"sqrt",
"(",
"np",
".",
"prod",
"(",
"self",
".",
"_shape",
")",
")",
"self",
".",
"_initializers",
"[",
... | Connects the TrainableTensor module into the graph.
Returns:
A Tensor of shape as determined in the constructor. | [
"Connects",
"the",
"TrainableTensor",
"module",
"into",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L983-L999 | train | Connects the TrainableTensor module into the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | BatchApply._build | def _build(self, *args, **kwargs):
"""Connects the BatchApply module into the graph.
Args:
*args: a Tensor or a nested list or dictionary of Tensors. The input
tensors will have their first dimensions merged, then an op or a
module will be called on the input. The first dimension of t... | python | def _build(self, *args, **kwargs):
"""Connects the BatchApply module into the graph.
Args:
*args: a Tensor or a nested list or dictionary of Tensors. The input
tensors will have their first dimensions merged, then an op or a
module will be called on the input. The first dimension of t... | [
"def",
"_build",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"flattened",
"=",
"nest",
".",
"flatten",
"(",
"[",
"args",
",",
"kwargs",
"]",
")",
"merged_flattened",
"=",
"[",
"merge_leading_dims",
"(",
"inp",
",",
"self",
".",
... | Connects the BatchApply module into the graph.
Args:
*args: a Tensor or a nested list or dictionary of Tensors. The input
tensors will have their first dimensions merged, then an op or a
module will be called on the input. The first dimension of the output
tensor(s) will be spli... | [
"Connects",
"the",
"BatchApply",
"module",
"into",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L1063-L1100 | train | Connects the BatchApply module into the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | SliceByDim._build | def _build(self, inputs):
"""Connects the SliceByDim module into the graph.
Args:
inputs: `Tensor` to slice. Its rank must be greater than the maximum
dimension specified in `dims` (plus one as python is 0 indexed).
Returns:
The sliced tensor.
Raises:
ValueError: If `input... | python | def _build(self, inputs):
"""Connects the SliceByDim module into the graph.
Args:
inputs: `Tensor` to slice. Its rank must be greater than the maximum
dimension specified in `dims` (plus one as python is 0 indexed).
Returns:
The sliced tensor.
Raises:
ValueError: If `input... | [
"def",
"_build",
"(",
"self",
",",
"inputs",
")",
":",
"shape_inputs",
"=",
"inputs",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"rank",
"=",
"len",
"(",
"shape_inputs",
")",
"# Checks that the rank of the tensor.",
"max_dim",
"=",
"np",
".",
"m... | Connects the SliceByDim module into the graph.
Args:
inputs: `Tensor` to slice. Its rank must be greater than the maximum
dimension specified in `dims` (plus one as python is 0 indexed).
Returns:
The sliced tensor.
Raises:
ValueError: If `inputs` tensor has insufficient rank. | [
"Connects",
"the",
"SliceByDim",
"module",
"into",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L1167-L1197 | train | Connects the SliceByDim module into the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | TileByDim._build | def _build(self, inputs):
"""Connects the `TileByDim` module into the graph.
Args:
inputs: `Tensor` to tile.
Returns:
The tiled tensor.
"""
shape_inputs = inputs.get_shape().as_list()
rank = len(shape_inputs)
# Builds default lists for multiples to pass to `tf.tile`.
full_... | python | def _build(self, inputs):
"""Connects the `TileByDim` module into the graph.
Args:
inputs: `Tensor` to tile.
Returns:
The tiled tensor.
"""
shape_inputs = inputs.get_shape().as_list()
rank = len(shape_inputs)
# Builds default lists for multiples to pass to `tf.tile`.
full_... | [
"def",
"_build",
"(",
"self",
",",
"inputs",
")",
":",
"shape_inputs",
"=",
"inputs",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"rank",
"=",
"len",
"(",
"shape_inputs",
")",
"# Builds default lists for multiples to pass to `tf.tile`.",
"full_multiples"... | Connects the `TileByDim` module into the graph.
Args:
inputs: `Tensor` to tile.
Returns:
The tiled tensor. | [
"Connects",
"the",
"TileByDim",
"module",
"into",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L1252-L1271 | train | Connects the TileByDim module into the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/basic.py | MergeDims._build | def _build(self, inputs):
"""Connects the MergeDims module into the graph.
Args:
inputs: Tensor or a nested list of Tensors to merge. Its rank must be
greater than or equal to `start` + `size`.
Returns:
The merged Tensor or a nested list of merged Tensors.
Raises:
ValueErr... | python | def _build(self, inputs):
"""Connects the MergeDims module into the graph.
Args:
inputs: Tensor or a nested list of Tensors to merge. Its rank must be
greater than or equal to `start` + `size`.
Returns:
The merged Tensor or a nested list of merged Tensors.
Raises:
ValueErr... | [
"def",
"_build",
"(",
"self",
",",
"inputs",
")",
":",
"if",
"nest",
".",
"is_sequence",
"(",
"inputs",
")",
":",
"merged_tensors",
"=",
"[",
"self",
".",
"_merge",
"(",
"tensor",
")",
"for",
"tensor",
"in",
"nest",
".",
"flatten",
"(",
"inputs",
")"... | Connects the MergeDims module into the graph.
Args:
inputs: Tensor or a nested list of Tensors to merge. Its rank must be
greater than or equal to `start` + `size`.
Returns:
The merged Tensor or a nested list of merged Tensors.
Raises:
ValueError: If any of the `inputs` tensor... | [
"Connects",
"the",
"MergeDims",
"module",
"into",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/basic.py#L1354-L1372 | train | Connects the MergeDims module into the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/relational_memory.py | RelationalMemory.initial_state | def initial_state(self, batch_size, trainable=False):
"""Creates the initial memory.
We should ensure each row of the memory is initialized to be unique,
so initialize the matrix to be the identity. We then pad or truncate
as necessary so that init_state is of size
(batch_size, self._mem_slots, sel... | python | def initial_state(self, batch_size, trainable=False):
"""Creates the initial memory.
We should ensure each row of the memory is initialized to be unique,
so initialize the matrix to be the identity. We then pad or truncate
as necessary so that init_state is of size
(batch_size, self._mem_slots, sel... | [
"def",
"initial_state",
"(",
"self",
",",
"batch_size",
",",
"trainable",
"=",
"False",
")",
":",
"init_state",
"=",
"tf",
".",
"eye",
"(",
"self",
".",
"_mem_slots",
",",
"batch_shape",
"=",
"[",
"batch_size",
"]",
")",
"# Pad the matrix with zeros.",
"if",... | Creates the initial memory.
We should ensure each row of the memory is initialized to be unique,
so initialize the matrix to be the identity. We then pad or truncate
as necessary so that init_state is of size
(batch_size, self._mem_slots, self._mem_size).
Args:
batch_size: The size of the ba... | [
"Creates",
"the",
"initial",
"memory",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/relational_memory.py#L92-L118 | train | Creates the initial state of the memory. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/relational_memory.py | RelationalMemory._multihead_attention | def _multihead_attention(self, memory):
"""Perform multi-head attention from 'Attention is All You Need'.
Implementation of the attention mechanism from
https://arxiv.org/abs/1706.03762.
Args:
memory: Memory tensor to perform attention on.
Returns:
new_memory: New memory tensor.
"... | python | def _multihead_attention(self, memory):
"""Perform multi-head attention from 'Attention is All You Need'.
Implementation of the attention mechanism from
https://arxiv.org/abs/1706.03762.
Args:
memory: Memory tensor to perform attention on.
Returns:
new_memory: New memory tensor.
"... | [
"def",
"_multihead_attention",
"(",
"self",
",",
"memory",
")",
":",
"key_size",
"=",
"self",
".",
"_key_size",
"value_size",
"=",
"self",
".",
"_head_size",
"qkv_size",
"=",
"2",
"*",
"key_size",
"+",
"value_size",
"total_size",
"=",
"qkv_size",
"*",
"self"... | Perform multi-head attention from 'Attention is All You Need'.
Implementation of the attention mechanism from
https://arxiv.org/abs/1706.03762.
Args:
memory: Memory tensor to perform attention on.
Returns:
new_memory: New memory tensor. | [
"Perform",
"multi",
"-",
"head",
"attention",
"from",
"Attention",
"is",
"All",
"You",
"Need",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/relational_memory.py#L120-L161 | train | Perform multi - head attention from Attention is All You Need. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/relational_memory.py | RelationalMemory._create_gates | def _create_gates(self, inputs, memory):
"""Create input and forget gates for this step using `inputs` and `memory`.
Args:
inputs: Tensor input.
memory: The current state of memory.
Returns:
input_gate: A LSTM-like insert gate.
forget_gate: A LSTM-like forget gate.
"""
# We... | python | def _create_gates(self, inputs, memory):
"""Create input and forget gates for this step using `inputs` and `memory`.
Args:
inputs: Tensor input.
memory: The current state of memory.
Returns:
input_gate: A LSTM-like insert gate.
forget_gate: A LSTM-like forget gate.
"""
# We... | [
"def",
"_create_gates",
"(",
"self",
",",
"inputs",
",",
"memory",
")",
":",
"# We'll create the input and forget gates at once. Hence, calculate double",
"# the gate size.",
"num_gates",
"=",
"2",
"*",
"self",
".",
"_calculate_gate_size",
"(",
")",
"memory",
"=",
"tf",... | Create input and forget gates for this step using `inputs` and `memory`.
Args:
inputs: Tensor input.
memory: The current state of memory.
Returns:
input_gate: A LSTM-like insert gate.
forget_gate: A LSTM-like forget gate. | [
"Create",
"input",
"and",
"forget",
"gates",
"for",
"this",
"step",
"using",
"inputs",
"and",
"memory",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/relational_memory.py#L184-L210 | train | Create input and forget gates for this step using inputs and memory. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/relational_memory.py | RelationalMemory._attend_over_memory | def _attend_over_memory(self, memory):
"""Perform multiheaded attention over `memory`.
Args:
memory: Current relational memory.
Returns:
The attended-over memory.
"""
attention_mlp = basic.BatchApply(
mlp.MLP([self._mem_size] * self._attention_mlp_layers))
for _ in range(se... | python | def _attend_over_memory(self, memory):
"""Perform multiheaded attention over `memory`.
Args:
memory: Current relational memory.
Returns:
The attended-over memory.
"""
attention_mlp = basic.BatchApply(
mlp.MLP([self._mem_size] * self._attention_mlp_layers))
for _ in range(se... | [
"def",
"_attend_over_memory",
"(",
"self",
",",
"memory",
")",
":",
"attention_mlp",
"=",
"basic",
".",
"BatchApply",
"(",
"mlp",
".",
"MLP",
"(",
"[",
"self",
".",
"_mem_size",
"]",
"*",
"self",
".",
"_attention_mlp_layers",
")",
")",
"for",
"_",
"in",
... | Perform multiheaded attention over `memory`.
Args:
memory: Current relational memory.
Returns:
The attended-over memory. | [
"Perform",
"multiheaded",
"attention",
"over",
"memory",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/relational_memory.py#L212-L234 | train | Perform multiheaded attention over memory. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/relational_memory.py | RelationalMemory._build | def _build(self, inputs, memory, treat_input_as_matrix=False):
"""Adds relational memory to the TensorFlow graph.
Args:
inputs: Tensor input.
memory: Memory output from the previous time step.
treat_input_as_matrix: Optional, whether to treat `input` as a sequence
of matrices. Default... | python | def _build(self, inputs, memory, treat_input_as_matrix=False):
"""Adds relational memory to the TensorFlow graph.
Args:
inputs: Tensor input.
memory: Memory output from the previous time step.
treat_input_as_matrix: Optional, whether to treat `input` as a sequence
of matrices. Default... | [
"def",
"_build",
"(",
"self",
",",
"inputs",
",",
"memory",
",",
"treat_input_as_matrix",
"=",
"False",
")",
":",
"if",
"treat_input_as_matrix",
":",
"inputs",
"=",
"basic",
".",
"BatchFlatten",
"(",
"preserve_dims",
"=",
"2",
")",
"(",
"inputs",
")",
"inp... | Adds relational memory to the TensorFlow graph.
Args:
inputs: Tensor input.
memory: Memory output from the previous time step.
treat_input_as_matrix: Optional, whether to treat `input` as a sequence
of matrices. Defaulta to False, in which case the input is flattened
into a vector... | [
"Adds",
"relational",
"memory",
"to",
"the",
"TensorFlow",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/relational_memory.py#L236-L272 | train | Builds the graph for the time step. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/mnist_mlp.py | train_and_eval | def train_and_eval(train_batch_size, test_batch_size, num_hidden, learning_rate,
num_train_steps, report_every, test_every):
"""Creates a basic MNIST model using Sonnet, then trains and evaluates it."""
data_dict = dataset_mnist.get_data("mnist", train_batch_size, test_batch_size)
train_data =... | python | def train_and_eval(train_batch_size, test_batch_size, num_hidden, learning_rate,
num_train_steps, report_every, test_every):
"""Creates a basic MNIST model using Sonnet, then trains and evaluates it."""
data_dict = dataset_mnist.get_data("mnist", train_batch_size, test_batch_size)
train_data =... | [
"def",
"train_and_eval",
"(",
"train_batch_size",
",",
"test_batch_size",
",",
"num_hidden",
",",
"learning_rate",
",",
"num_train_steps",
",",
"report_every",
",",
"test_every",
")",
":",
"data_dict",
"=",
"dataset_mnist",
".",
"get_data",
"(",
"\"mnist\"",
",",
... | Creates a basic MNIST model using Sonnet, then trains and evaluates it. | [
"Creates",
"a",
"basic",
"MNIST",
"model",
"using",
"Sonnet",
"then",
"trains",
"and",
"evaluates",
"it",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/mnist_mlp.py#L43-L96 | train | Creates a basic MNIST model using Sonnet. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/rnn_core.py | _single_learnable_state | def _single_learnable_state(state, state_id=0, learnable=True):
"""Returns an initial (maybe learnable) state.
This function does not create any variable scopes, and it should be called
from a Sonnet module. This function also makes sure that all the rows of its
`state` argument have the same value.
Args:
... | python | def _single_learnable_state(state, state_id=0, learnable=True):
"""Returns an initial (maybe learnable) state.
This function does not create any variable scopes, and it should be called
from a Sonnet module. This function also makes sure that all the rows of its
`state` argument have the same value.
Args:
... | [
"def",
"_single_learnable_state",
"(",
"state",
",",
"state_id",
"=",
"0",
",",
"learnable",
"=",
"True",
")",
":",
"unpacked_state",
"=",
"tf",
".",
"unstack",
"(",
"state",
")",
"# Assert that all rows have the same values.",
"assert_rows_equal",
"=",
"[",
"tf",... | Returns an initial (maybe learnable) state.
This function does not create any variable scopes, and it should be called
from a Sonnet module. This function also makes sure that all the rows of its
`state` argument have the same value.
Args:
state: initial value of the initial state. It should be a tensor o... | [
"Returns",
"an",
"initial",
"(",
"maybe",
"learnable",
")",
"state",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/rnn_core.py#L44-L89 | train | Returns an initial learnable state. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/rnn_core.py | trainable_initial_state | def trainable_initial_state(batch_size, state_size, dtype, initializers=None,
regularizers=None, name=None):
"""Creates an initial state consisting of trainable variables.
The trainable variables are created with the same shapes as the elements of
`state_size` and are tiled to produce... | python | def trainable_initial_state(batch_size, state_size, dtype, initializers=None,
regularizers=None, name=None):
"""Creates an initial state consisting of trainable variables.
The trainable variables are created with the same shapes as the elements of
`state_size` and are tiled to produce... | [
"def",
"trainable_initial_state",
"(",
"batch_size",
",",
"state_size",
",",
"dtype",
",",
"initializers",
"=",
"None",
",",
"regularizers",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"flat_state_size",
"=",
"nest",
".",
"flatten",
"(",
"state_size",
"... | Creates an initial state consisting of trainable variables.
The trainable variables are created with the same shapes as the elements of
`state_size` and are tiled to produce an initial state.
Args:
batch_size: An int, or scalar int32 Tensor representing the batch size.
state_size: A `TensorShape` or nes... | [
"Creates",
"an",
"initial",
"state",
"consisting",
"of",
"trainable",
"variables",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/rnn_core.py#L92-L167 | train | Returns an initial state consisting of trainable variables. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/rnn_core.py | with_doc | def with_doc(fn_with_doc_to_copy):
"""Returns a decorator to copy documentation from the given function.
Docstring is copied, including *args and **kwargs documentation.
Args:
fn_with_doc_to_copy: Function whose docstring, including *args and
**kwargs documentation, is to be copied.
Returns:
De... | python | def with_doc(fn_with_doc_to_copy):
"""Returns a decorator to copy documentation from the given function.
Docstring is copied, including *args and **kwargs documentation.
Args:
fn_with_doc_to_copy: Function whose docstring, including *args and
**kwargs documentation, is to be copied.
Returns:
De... | [
"def",
"with_doc",
"(",
"fn_with_doc_to_copy",
")",
":",
"def",
"decorator",
"(",
"wrapper_init",
")",
":",
"# Wrap the target class's constructor (to assume its docstring),",
"# but invoke the wrapper class's constructor.",
"@",
"wrapt",
".",
"decorator",
"def",
"wrapping_fn",... | Returns a decorator to copy documentation from the given function.
Docstring is copied, including *args and **kwargs documentation.
Args:
fn_with_doc_to_copy: Function whose docstring, including *args and
**kwargs documentation, is to be copied.
Returns:
Decorated version of `wrapper_init` with d... | [
"Returns",
"a",
"decorator",
"to",
"copy",
"documentation",
"from",
"the",
"given",
"function",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/rnn_core.py#L385-L407 | train | Returns a decorator to copy documentation from the given function. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/rnn_core.py | TrainableInitialState._build | def _build(self):
"""Connects the module to the graph.
Returns:
The learnable state, which has the same type, structure and shape as
the `initial_state` passed to the constructor.
"""
flat_initial_state = nest.flatten(self._initial_state)
if self._mask is not None:
flat_mask = n... | python | def _build(self):
"""Connects the module to the graph.
Returns:
The learnable state, which has the same type, structure and shape as
the `initial_state` passed to the constructor.
"""
flat_initial_state = nest.flatten(self._initial_state)
if self._mask is not None:
flat_mask = n... | [
"def",
"_build",
"(",
"self",
")",
":",
"flat_initial_state",
"=",
"nest",
".",
"flatten",
"(",
"self",
".",
"_initial_state",
")",
"if",
"self",
".",
"_mask",
"is",
"not",
"None",
":",
"flat_mask",
"=",
"nest",
".",
"flatten",
"(",
"self",
".",
"_mask... | Connects the module to the graph.
Returns:
The learnable state, which has the same type, structure and shape as
the `initial_state` passed to the constructor. | [
"Connects",
"the",
"module",
"to",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/rnn_core.py#L331-L349 | train | Connects the module to the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/layer_norm.py | LayerNorm._build | def _build(self, inputs):
"""Connects the LayerNorm module into the graph.
Args:
inputs: a Tensor of dimensionality >= 2.
Returns:
normalized: layer normalized outputs with same shape as inputs.
Raises:
base.NotSupportedError: If `inputs` has less than 2 dimensions.
"""
if ... | python | def _build(self, inputs):
"""Connects the LayerNorm module into the graph.
Args:
inputs: a Tensor of dimensionality >= 2.
Returns:
normalized: layer normalized outputs with same shape as inputs.
Raises:
base.NotSupportedError: If `inputs` has less than 2 dimensions.
"""
if ... | [
"def",
"_build",
"(",
"self",
",",
"inputs",
")",
":",
"if",
"self",
".",
"_axis",
"is",
"None",
":",
"axis",
"=",
"list",
"(",
"range",
"(",
"1",
",",
"inputs",
".",
"shape",
".",
"ndims",
")",
")",
"else",
":",
"axis",
"=",
"self",
".",
"_axi... | Connects the LayerNorm module into the graph.
Args:
inputs: a Tensor of dimensionality >= 2.
Returns:
normalized: layer normalized outputs with same shape as inputs.
Raises:
base.NotSupportedError: If `inputs` has less than 2 dimensions. | [
"Connects",
"the",
"LayerNorm",
"module",
"into",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/layer_norm.py#L115-L179 | train | Connects the LayerNorm module into the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/attention.py | AttentiveRead._build | def _build(self, memory, query, memory_mask=None):
"""Perform a differentiable read.
Args:
memory: [batch_size, memory_size, memory_word_size]-shaped Tensor of
dtype float32. This represents, for each example and memory slot, a
single embedding to attend over.
query: [batch_size, qu... | python | def _build(self, memory, query, memory_mask=None):
"""Perform a differentiable read.
Args:
memory: [batch_size, memory_size, memory_word_size]-shaped Tensor of
dtype float32. This represents, for each example and memory slot, a
single embedding to attend over.
query: [batch_size, qu... | [
"def",
"_build",
"(",
"self",
",",
"memory",
",",
"query",
",",
"memory_mask",
"=",
"None",
")",
":",
"if",
"len",
"(",
"memory",
".",
"get_shape",
"(",
")",
")",
"!=",
"3",
":",
"raise",
"base",
".",
"IncompatibleShapeError",
"(",
"\"memory must have sh... | Perform a differentiable read.
Args:
memory: [batch_size, memory_size, memory_word_size]-shaped Tensor of
dtype float32. This represents, for each example and memory slot, a
single embedding to attend over.
query: [batch_size, query_word_size]-shaped Tensor of dtype float32.
Rep... | [
"Perform",
"a",
"differentiable",
"read",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/attention.py#L60-L183 | train | Builds the list of attention outputs for a differentiable read. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/batch_norm_v2.py | BatchNormV2._build_statistics | def _build_statistics(self, input_batch, use_batch_stats, stat_dtype):
"""Builds the statistics part of the graph when using moving variance.
Args:
input_batch: Input batch Tensor.
use_batch_stats: Boolean to indicate if batch statistics should be
calculated, otherwise moving averages are r... | python | def _build_statistics(self, input_batch, use_batch_stats, stat_dtype):
"""Builds the statistics part of the graph when using moving variance.
Args:
input_batch: Input batch Tensor.
use_batch_stats: Boolean to indicate if batch statistics should be
calculated, otherwise moving averages are r... | [
"def",
"_build_statistics",
"(",
"self",
",",
"input_batch",
",",
"use_batch_stats",
",",
"stat_dtype",
")",
":",
"# Set up our moving statistics. When connecting in parallel, this is shared.",
"if",
"self",
".",
"MOVING_MEAN",
"not",
"in",
"self",
".",
"_initializers",
"... | Builds the statistics part of the graph when using moving variance.
Args:
input_batch: Input batch Tensor.
use_batch_stats: Boolean to indicate if batch statistics should be
calculated, otherwise moving averages are returned.
stat_dtype: TensorFlow datatype to use for the moving mean and ... | [
"Builds",
"the",
"statistics",
"part",
"of",
"the",
"graph",
"when",
"using",
"moving",
"variance",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/batch_norm_v2.py#L217-L285 | train | Builds the statistics part of the graph when using moving mean and variance. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/batch_norm_v2.py | BatchNormV2._build_update_ops | def _build_update_ops(self, mean, variance, is_training):
"""Builds the moving average update ops when using moving variance.
Args:
mean: The mean value to update with.
variance: The variance value to update with.
is_training: Boolean Tensor to indicate if we're currently in
training ... | python | def _build_update_ops(self, mean, variance, is_training):
"""Builds the moving average update ops when using moving variance.
Args:
mean: The mean value to update with.
variance: The variance value to update with.
is_training: Boolean Tensor to indicate if we're currently in
training ... | [
"def",
"_build_update_ops",
"(",
"self",
",",
"mean",
",",
"variance",
",",
"is_training",
")",
":",
"def",
"build_update_ops",
"(",
")",
":",
"\"\"\"Builds the exponential moving average update ops.\"\"\"",
"update_mean_op",
"=",
"moving_averages",
".",
"assign_moving_av... | Builds the moving average update ops when using moving variance.
Args:
mean: The mean value to update with.
variance: The variance value to update with.
is_training: Boolean Tensor to indicate if we're currently in
training mode.
Returns:
Tuple of `(update_mean_op, update_varia... | [
"Builds",
"the",
"moving",
"average",
"update",
"ops",
"when",
"using",
"moving",
"variance",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/batch_norm_v2.py#L287-L334 | train | Builds the update ops for moving average. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/batch_norm_v2.py | BatchNormV2._fused_batch_norm_op | def _fused_batch_norm_op(self, input_batch, mean, variance, use_batch_stats):
"""Creates a fused batch normalization op."""
# Store the original shape of the mean and variance.
mean_shape = mean.get_shape()
variance_shape = variance.get_shape()
# The fused batch norm expects the mean, variance, gamm... | python | def _fused_batch_norm_op(self, input_batch, mean, variance, use_batch_stats):
"""Creates a fused batch normalization op."""
# Store the original shape of the mean and variance.
mean_shape = mean.get_shape()
variance_shape = variance.get_shape()
# The fused batch norm expects the mean, variance, gamm... | [
"def",
"_fused_batch_norm_op",
"(",
"self",
",",
"input_batch",
",",
"mean",
",",
"variance",
",",
"use_batch_stats",
")",
":",
"# Store the original shape of the mean and variance.",
"mean_shape",
"=",
"mean",
".",
"get_shape",
"(",
")",
"variance_shape",
"=",
"varia... | Creates a fused batch normalization op. | [
"Creates",
"a",
"fused",
"batch",
"normalization",
"op",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/batch_norm_v2.py#L336-L404 | train | Creates a fused batch normalization op. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/batch_norm_v2.py | BatchNormV2._build | def _build(self,
input_batch,
is_training,
test_local_stats=False):
"""Connects the BatchNormV2 module into the graph.
Args:
input_batch: A Tensor of the same dimension as `len(data_format)`.
is_training: A boolean to indicate if the module should be connected... | python | def _build(self,
input_batch,
is_training,
test_local_stats=False):
"""Connects the BatchNormV2 module into the graph.
Args:
input_batch: A Tensor of the same dimension as `len(data_format)`.
is_training: A boolean to indicate if the module should be connected... | [
"def",
"_build",
"(",
"self",
",",
"input_batch",
",",
"is_training",
",",
"test_local_stats",
"=",
"False",
")",
":",
"input_shape",
"=",
"input_batch",
".",
"get_shape",
"(",
")",
"if",
"not",
"self",
".",
"_data_format",
":",
"if",
"len",
"(",
"input_sh... | Connects the BatchNormV2 module into the graph.
Args:
input_batch: A Tensor of the same dimension as `len(data_format)`.
is_training: A boolean to indicate if the module should be connected in
training mode, meaning the moving averages are updated. Can be a Tensor.
test_local_stats: A boo... | [
"Connects",
"the",
"BatchNormV2",
"module",
"into",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/batch_norm_v2.py#L496-L583 | train | Connects the BatchNormV2 module into the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/dilation.py | _range_along_dimension | def _range_along_dimension(range_dim, shape):
"""Construct a Tensor whose values are the index along a dimension.
Construct a Tensor that counts the distance along a single dimension. This is
useful, for example, when constructing an identity matrix,
>>> x = _range_along_dimension(0, [2, 2]).eval()
>>> ... | python | def _range_along_dimension(range_dim, shape):
"""Construct a Tensor whose values are the index along a dimension.
Construct a Tensor that counts the distance along a single dimension. This is
useful, for example, when constructing an identity matrix,
>>> x = _range_along_dimension(0, [2, 2]).eval()
>>> ... | [
"def",
"_range_along_dimension",
"(",
"range_dim",
",",
"shape",
")",
":",
"rank",
"=",
"len",
"(",
"shape",
")",
"if",
"range_dim",
">=",
"rank",
":",
"raise",
"ValueError",
"(",
"\"Cannot calculate range along non-existent index.\"",
")",
"indices",
"=",
"tf",
... | Construct a Tensor whose values are the index along a dimension.
Construct a Tensor that counts the distance along a single dimension. This is
useful, for example, when constructing an identity matrix,
>>> x = _range_along_dimension(0, [2, 2]).eval()
>>> x
array([[0, 0],
[1, 1]], dtype=int3... | [
"Construct",
"a",
"Tensor",
"whose",
"values",
"are",
"the",
"index",
"along",
"a",
"dimension",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/dilation.py#L32-L70 | train | Construct a Tensor that counts the distance along a single dimension. This is a helper function for calculating the range along a single dimension. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/dilation.py | identity_kernel_initializer | def identity_kernel_initializer(shape, dtype=tf.float32, partition_info=None):
"""An initializer for constructing identity convolution kernels.
Constructs a convolution kernel such that applying it is the same as an
identity operation on the input. Formally, the kernel has entry [i, j, in,
out] = 1 if in equal... | python | def identity_kernel_initializer(shape, dtype=tf.float32, partition_info=None):
"""An initializer for constructing identity convolution kernels.
Constructs a convolution kernel such that applying it is the same as an
identity operation on the input. Formally, the kernel has entry [i, j, in,
out] = 1 if in equal... | [
"def",
"identity_kernel_initializer",
"(",
"shape",
",",
"dtype",
"=",
"tf",
".",
"float32",
",",
"partition_info",
"=",
"None",
")",
":",
"if",
"len",
"(",
"shape",
")",
"!=",
"4",
":",
"raise",
"ValueError",
"(",
"\"Convolution kernels must be rank 4.\"",
")... | An initializer for constructing identity convolution kernels.
Constructs a convolution kernel such that applying it is the same as an
identity operation on the input. Formally, the kernel has entry [i, j, in,
out] = 1 if in equals out and i and j are the middle of the kernel and 0
otherwise.
Args:
shape... | [
"An",
"initializer",
"for",
"constructing",
"identity",
"convolution",
"kernels",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/dilation.py#L74-L118 | train | An initializer for constructing identity convolution kernels. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/dilation.py | noisy_identity_kernel_initializer | def noisy_identity_kernel_initializer(base_num_channels, stddev=1e-8):
"""Build an initializer for constructing near-identity convolution kernels.
Construct a convolution kernel where in_channels and out_channels are
multiples of base_num_channels, but need not be equal. This initializer is
essentially the sam... | python | def noisy_identity_kernel_initializer(base_num_channels, stddev=1e-8):
"""Build an initializer for constructing near-identity convolution kernels.
Construct a convolution kernel where in_channels and out_channels are
multiples of base_num_channels, but need not be equal. This initializer is
essentially the sam... | [
"def",
"noisy_identity_kernel_initializer",
"(",
"base_num_channels",
",",
"stddev",
"=",
"1e-8",
")",
":",
"# pylint: disable=unused-argument",
"def",
"_noisy_identity_kernel_initializer",
"(",
"shape",
",",
"dtype",
"=",
"tf",
".",
"float32",
",",
"partition_info",
"=... | Build an initializer for constructing near-identity convolution kernels.
Construct a convolution kernel where in_channels and out_channels are
multiples of base_num_channels, but need not be equal. This initializer is
essentially the same as identity_kernel_initializer, except that magnitude
is "spread out" ac... | [
"Build",
"an",
"initializer",
"for",
"constructing",
"near",
"-",
"identity",
"convolution",
"kernels",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/dilation.py#L121-L194 | train | Constructs an initializer function for constructing a noisy identity convolution kernels. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/dilation.py | Dilation._build | def _build(self, images):
"""Build dilation module.
Args:
images: Tensor of shape [batch_size, height, width, depth]
and dtype float32. Represents a set of images with an arbitrary depth.
Note that when using the default initializer, depth must equal
num_output_classes.
Retur... | python | def _build(self, images):
"""Build dilation module.
Args:
images: Tensor of shape [batch_size, height, width, depth]
and dtype float32. Represents a set of images with an arbitrary depth.
Note that when using the default initializer, depth must equal
num_output_classes.
Retur... | [
"def",
"_build",
"(",
"self",
",",
"images",
")",
":",
"num_classes",
"=",
"self",
".",
"_num_output_classes",
"if",
"len",
"(",
"images",
".",
"get_shape",
"(",
")",
")",
"!=",
"4",
":",
"raise",
"base",
".",
"IncompatibleShapeError",
"(",
"\"'images' mus... | Build dilation module.
Args:
images: Tensor of shape [batch_size, height, width, depth]
and dtype float32. Represents a set of images with an arbitrary depth.
Note that when using the default initializer, depth must equal
num_output_classes.
Returns:
Tensor of shape [batch_... | [
"Build",
"dilation",
"module",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/dilation.py#L257-L319 | train | Builds the dilation module. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/dilation.py | Dilation._dilated_conv_layer | def _dilated_conv_layer(self, output_channels, dilation_rate, apply_relu,
name):
"""Create a dilated convolution layer.
Args:
output_channels: int. Number of output channels for each pixel.
dilation_rate: int. Represents how many pixels each stride offset will
move... | python | def _dilated_conv_layer(self, output_channels, dilation_rate, apply_relu,
name):
"""Create a dilated convolution layer.
Args:
output_channels: int. Number of output channels for each pixel.
dilation_rate: int. Represents how many pixels each stride offset will
move... | [
"def",
"_dilated_conv_layer",
"(",
"self",
",",
"output_channels",
",",
"dilation_rate",
",",
"apply_relu",
",",
"name",
")",
":",
"layer_components",
"=",
"[",
"conv",
".",
"Conv2D",
"(",
"output_channels",
",",
"[",
"3",
",",
"3",
"]",
",",
"initializers",... | Create a dilated convolution layer.
Args:
output_channels: int. Number of output channels for each pixel.
dilation_rate: int. Represents how many pixels each stride offset will
move. A value of 1 indicates a standard convolution.
apply_relu: bool. If True, a ReLU non-linearlity is added.
... | [
"Create",
"a",
"dilated",
"convolution",
"layer",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/dilation.py#L321-L345 | train | Create a dilated convolution layer. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/ops/nest.py | with_deprecation_warning | def with_deprecation_warning(fn, extra_message=''):
"""Wraps the function and prints a warn-once (per `extra_message`) warning."""
def new_fn(*args, **kwargs):
if extra_message not in _DONE_WARN:
tf.logging.warning(
'Sonnet nest is deprecated. Please use '
'tf.contrib.framework.nest in... | python | def with_deprecation_warning(fn, extra_message=''):
"""Wraps the function and prints a warn-once (per `extra_message`) warning."""
def new_fn(*args, **kwargs):
if extra_message not in _DONE_WARN:
tf.logging.warning(
'Sonnet nest is deprecated. Please use '
'tf.contrib.framework.nest in... | [
"def",
"with_deprecation_warning",
"(",
"fn",
",",
"extra_message",
"=",
"''",
")",
":",
"def",
"new_fn",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"extra_message",
"not",
"in",
"_DONE_WARN",
":",
"tf",
".",
"logging",
".",
"warning",
... | Wraps the function and prints a warn-once (per `extra_message`) warning. | [
"Wraps",
"the",
"function",
"and",
"prints",
"a",
"warn",
"-",
"once",
"(",
"per",
"extra_message",
")",
"warning",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/ops/nest.py#L33-L44 | train | Wraps the function and prints a warning - once per extra_message. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/module_with_build_args.py | custom_build | def custom_build(inputs, is_training, keep_prob):
"""A custom build method to wrap into a sonnet Module."""
outputs = snt.Conv2D(output_channels=32, kernel_shape=4, stride=2)(inputs)
outputs = snt.BatchNorm()(outputs, is_training=is_training)
outputs = tf.nn.relu(outputs)
outputs = snt.Conv2D(output_channels=... | python | def custom_build(inputs, is_training, keep_prob):
"""A custom build method to wrap into a sonnet Module."""
outputs = snt.Conv2D(output_channels=32, kernel_shape=4, stride=2)(inputs)
outputs = snt.BatchNorm()(outputs, is_training=is_training)
outputs = tf.nn.relu(outputs)
outputs = snt.Conv2D(output_channels=... | [
"def",
"custom_build",
"(",
"inputs",
",",
"is_training",
",",
"keep_prob",
")",
":",
"outputs",
"=",
"snt",
".",
"Conv2D",
"(",
"output_channels",
"=",
"32",
",",
"kernel_shape",
"=",
"4",
",",
"stride",
"=",
"2",
")",
"(",
"inputs",
")",
"outputs",
"... | A custom build method to wrap into a sonnet Module. | [
"A",
"custom",
"build",
"method",
"to",
"wrap",
"into",
"a",
"sonnet",
"Module",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/module_with_build_args.py#L41-L52 | train | A custom build method to wrap into a sonnet Module. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/base.py | _get_or_create_stack | def _get_or_create_stack(name):
"""Returns a thread local stack uniquified by the given name."""
stack = getattr(_LOCAL_STACKS, name, None)
if stack is None:
stack = []
setattr(_LOCAL_STACKS, name, stack)
return stack | python | def _get_or_create_stack(name):
"""Returns a thread local stack uniquified by the given name."""
stack = getattr(_LOCAL_STACKS, name, None)
if stack is None:
stack = []
setattr(_LOCAL_STACKS, name, stack)
return stack | [
"def",
"_get_or_create_stack",
"(",
"name",
")",
":",
"stack",
"=",
"getattr",
"(",
"_LOCAL_STACKS",
",",
"name",
",",
"None",
")",
"if",
"stack",
"is",
"None",
":",
"stack",
"=",
"[",
"]",
"setattr",
"(",
"_LOCAL_STACKS",
",",
"name",
",",
"stack",
")... | Returns a thread local stack uniquified by the given name. | [
"Returns",
"a",
"thread",
"local",
"stack",
"uniquified",
"by",
"the",
"given",
"name",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/base.py#L60-L66 | train | Returns a thread local stack uniquified by the given name. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/custom_getters/bayes_by_backprop.py | diagonal_gaussian_posterior_builder | def diagonal_gaussian_posterior_builder(
getter, name, shape=None, *args, **kwargs):
"""A pre-canned builder for diagonal gaussian posterior distributions.
Given a true `getter` function and arguments forwarded from `tf.get_variable`,
return a distribution object for a diagonal posterior over a variable of t... | python | def diagonal_gaussian_posterior_builder(
getter, name, shape=None, *args, **kwargs):
"""A pre-canned builder for diagonal gaussian posterior distributions.
Given a true `getter` function and arguments forwarded from `tf.get_variable`,
return a distribution object for a diagonal posterior over a variable of t... | [
"def",
"diagonal_gaussian_posterior_builder",
"(",
"getter",
",",
"name",
",",
"shape",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Please see the documentation for",
"# `tfp.distributions.param_static_shapes`.",
"parameter_shapes",
"=",
"tfp",
... | A pre-canned builder for diagonal gaussian posterior distributions.
Given a true `getter` function and arguments forwarded from `tf.get_variable`,
return a distribution object for a diagonal posterior over a variable of the
requisite shape.
Args:
getter: The `getter` passed to a `custom_getter`. Please se... | [
"A",
"pre",
"-",
"canned",
"builder",
"for",
"diagonal",
"gaussian",
"posterior",
"distributions",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/bayes_by_backprop.py#L148-L183 | train | A pre - canned builder for diagonal gaussian posterior distributions. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/custom_getters/bayes_by_backprop.py | fixed_gaussian_prior_builder | def fixed_gaussian_prior_builder(
getter, name, dtype=None, *args, **kwargs):
"""A pre-canned builder for fixed gaussian prior distributions.
Given a true `getter` function and arguments forwarded from `tf.get_variable`,
return a distribution object for a scalar-valued fixed gaussian prior which
will be br... | python | def fixed_gaussian_prior_builder(
getter, name, dtype=None, *args, **kwargs):
"""A pre-canned builder for fixed gaussian prior distributions.
Given a true `getter` function and arguments forwarded from `tf.get_variable`,
return a distribution object for a scalar-valued fixed gaussian prior which
will be br... | [
"def",
"fixed_gaussian_prior_builder",
"(",
"getter",
",",
"name",
",",
"dtype",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"del",
"getter",
"# Unused.",
"del",
"args",
"# Unused.",
"del",
"kwargs",
"# Unused.",
"loc",
"=",
"tf",
"... | A pre-canned builder for fixed gaussian prior distributions.
Given a true `getter` function and arguments forwarded from `tf.get_variable`,
return a distribution object for a scalar-valued fixed gaussian prior which
will be broadcast over a variable of the requisite shape.
Args:
getter: The `getter` passe... | [
"A",
"pre",
"-",
"canned",
"builder",
"for",
"fixed",
"gaussian",
"prior",
"distributions",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/bayes_by_backprop.py#L188-L214 | train | A pre - canned builder for fixed gaussian prior distributions. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/custom_getters/bayes_by_backprop.py | adaptive_gaussian_prior_builder | def adaptive_gaussian_prior_builder(
getter, name, *args, **kwargs):
"""A pre-canned builder for adaptive scalar gaussian prior distributions.
Given a true `getter` function and arguments forwarded from `tf.get_variable`,
return a distribution object for a scalar-valued adaptive gaussian prior
which will b... | python | def adaptive_gaussian_prior_builder(
getter, name, *args, **kwargs):
"""A pre-canned builder for adaptive scalar gaussian prior distributions.
Given a true `getter` function and arguments forwarded from `tf.get_variable`,
return a distribution object for a scalar-valued adaptive gaussian prior
which will b... | [
"def",
"adaptive_gaussian_prior_builder",
"(",
"getter",
",",
"name",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"[",
"\"shape\"",
"]",
"=",
"(",
")",
"loc_var",
"=",
"getter",
"(",
"name",
"+",
"\"_prior_loc\"",
",",
"*",
"args",
"... | A pre-canned builder for adaptive scalar gaussian prior distributions.
Given a true `getter` function and arguments forwarded from `tf.get_variable`,
return a distribution object for a scalar-valued adaptive gaussian prior
which will be broadcast over a variable of the requisite shape. This prior's
parameters ... | [
"A",
"pre",
"-",
"canned",
"builder",
"for",
"adaptive",
"scalar",
"gaussian",
"prior",
"distributions",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/bayes_by_backprop.py#L218-L247 | train | A pre - canned builder for adaptive scalar gaussian prior distributions. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/custom_getters/bayes_by_backprop.py | stochastic_kl_builder | def stochastic_kl_builder(posterior, prior, sample):
"""A pre-canned builder for a ubiquitous stochastic KL estimator."""
return tf.subtract(
tf.reduce_sum(posterior.log_prob(sample)),
tf.reduce_sum(prior.log_prob(sample))) | python | def stochastic_kl_builder(posterior, prior, sample):
"""A pre-canned builder for a ubiquitous stochastic KL estimator."""
return tf.subtract(
tf.reduce_sum(posterior.log_prob(sample)),
tf.reduce_sum(prior.log_prob(sample))) | [
"def",
"stochastic_kl_builder",
"(",
"posterior",
",",
"prior",
",",
"sample",
")",
":",
"return",
"tf",
".",
"subtract",
"(",
"tf",
".",
"reduce_sum",
"(",
"posterior",
".",
"log_prob",
"(",
"sample",
")",
")",
",",
"tf",
".",
"reduce_sum",
"(",
"prior"... | A pre-canned builder for a ubiquitous stochastic KL estimator. | [
"A",
"pre",
"-",
"canned",
"builder",
"for",
"a",
"ubiquitous",
"stochastic",
"KL",
"estimator",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/bayes_by_backprop.py#L250-L254 | train | A pre - canned builder for a ubiquitous stochastic KL estimator. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/custom_getters/bayes_by_backprop.py | analytic_kl_builder | def analytic_kl_builder(posterior, prior, sample):
"""A pre-canned builder for the analytic kl divergence."""
del sample
return tf.reduce_sum(tfp.distributions.kl_divergence(posterior, prior)) | python | def analytic_kl_builder(posterior, prior, sample):
"""A pre-canned builder for the analytic kl divergence."""
del sample
return tf.reduce_sum(tfp.distributions.kl_divergence(posterior, prior)) | [
"def",
"analytic_kl_builder",
"(",
"posterior",
",",
"prior",
",",
"sample",
")",
":",
"del",
"sample",
"return",
"tf",
".",
"reduce_sum",
"(",
"tfp",
".",
"distributions",
".",
"kl_divergence",
"(",
"posterior",
",",
"prior",
")",
")"
] | A pre-canned builder for the analytic kl divergence. | [
"A",
"pre",
"-",
"canned",
"builder",
"for",
"the",
"analytic",
"kl",
"divergence",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/bayes_by_backprop.py#L257-L260 | train | A pre - canned builder for the analytic kl divergence. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/custom_getters/bayes_by_backprop.py | bayes_by_backprop_getter | def bayes_by_backprop_getter(
posterior_builder=diagonal_gaussian_posterior_builder,
prior_builder=fixed_gaussian_prior_builder,
kl_builder=stochastic_kl_builder,
sampling_mode_tensor=None,
fresh_noise_per_connection=True,
keep_control_dependencies=False):
"""Creates a custom getter which does... | python | def bayes_by_backprop_getter(
posterior_builder=diagonal_gaussian_posterior_builder,
prior_builder=fixed_gaussian_prior_builder,
kl_builder=stochastic_kl_builder,
sampling_mode_tensor=None,
fresh_noise_per_connection=True,
keep_control_dependencies=False):
"""Creates a custom getter which does... | [
"def",
"bayes_by_backprop_getter",
"(",
"posterior_builder",
"=",
"diagonal_gaussian_posterior_builder",
",",
"prior_builder",
"=",
"fixed_gaussian_prior_builder",
",",
"kl_builder",
"=",
"stochastic_kl_builder",
",",
"sampling_mode_tensor",
"=",
"None",
",",
"fresh_noise_per_c... | Creates a custom getter which does Bayes by Backprop.
Please see `tf.get_variable` for general documentation on custom getters.
All arguments are optional. If nothing is configued, then a diagonal gaussian
posterior will be used, and a fixed N(0, 0.01) prior will be used. Please
see the default `posterior_bui... | [
"Creates",
"a",
"custom",
"getter",
"which",
"does",
"Bayes",
"by",
"Backprop",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/bayes_by_backprop.py#L263-L452 | train | Creates a custom getter which does Bayes by Backprop. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/custom_getters/bayes_by_backprop.py | _produce_posterior_estimate | def _produce_posterior_estimate(posterior_dist, posterior_estimate_mode,
raw_var_name):
"""Create tensor representing estimate of posterior.
Args:
posterior_dist: An instance of `tfp.distributions.Distribution`.
The variational posterior from which to produce an estimate... | python | def _produce_posterior_estimate(posterior_dist, posterior_estimate_mode,
raw_var_name):
"""Create tensor representing estimate of posterior.
Args:
posterior_dist: An instance of `tfp.distributions.Distribution`.
The variational posterior from which to produce an estimate... | [
"def",
"_produce_posterior_estimate",
"(",
"posterior_dist",
",",
"posterior_estimate_mode",
",",
"raw_var_name",
")",
":",
"conds",
"=",
"[",
"tf",
".",
"equal",
"(",
"posterior_estimate_mode",
",",
"tf",
".",
"constant",
"(",
"EstimatorModes",
".",
"sample",
")"... | Create tensor representing estimate of posterior.
Args:
posterior_dist: An instance of `tfp.distributions.Distribution`.
The variational posterior from which to produce an estimate of the
variable in question.
posterior_estimate_mode: A `Tensor` of dtype `tf.string`, which
determines ... | [
"Create",
"tensor",
"representing",
"estimate",
"of",
"posterior",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/bayes_by_backprop.py#L455-L505 | train | Create a tensor representing an estimate of the posterior. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/custom_getters/bayes_by_backprop.py | get_total_kl_cost | def get_total_kl_cost(name="total_kl_cost", filter_by_name_substring=None):
"""Get the total cost for all (or a subset of) the stochastic variables.
Args:
name: A name for the tensor representing the total kl cost.
filter_by_name_substring: A string used to filter which variables count
toward the tot... | python | def get_total_kl_cost(name="total_kl_cost", filter_by_name_substring=None):
"""Get the total cost for all (or a subset of) the stochastic variables.
Args:
name: A name for the tensor representing the total kl cost.
filter_by_name_substring: A string used to filter which variables count
toward the tot... | [
"def",
"get_total_kl_cost",
"(",
"name",
"=",
"\"total_kl_cost\"",
",",
"filter_by_name_substring",
"=",
"None",
")",
":",
"all_variable_metadata",
"=",
"get_variable_metadata",
"(",
"filter_by_name_substring",
")",
"if",
"not",
"all_variable_metadata",
":",
"tf",
".",
... | Get the total cost for all (or a subset of) the stochastic variables.
Args:
name: A name for the tensor representing the total kl cost.
filter_by_name_substring: A string used to filter which variables count
toward the total KL cost. By default, this argument is `None`, and all
variables trained ... | [
"Get",
"the",
"total",
"cost",
"for",
"all",
"(",
"or",
"a",
"subset",
"of",
")",
"the",
"stochastic",
"variables",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/custom_getters/bayes_by_backprop.py#L508-L527 | train | Returns the total KL cost for all variables in the current graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/block_matrix.py | BlockTriangularMatrix.output_shape | def output_shape(self):
"""The shape of the output matrix."""
return (self._block_shape[0] * self._block_rows,
self._block_shape[1] * self._block_rows) | python | def output_shape(self):
"""The shape of the output matrix."""
return (self._block_shape[0] * self._block_rows,
self._block_shape[1] * self._block_rows) | [
"def",
"output_shape",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"_block_shape",
"[",
"0",
"]",
"*",
"self",
".",
"_block_rows",
",",
"self",
".",
"_block_shape",
"[",
"1",
"]",
"*",
"self",
".",
"_block_rows",
")"
] | The shape of the output matrix. | [
"The",
"shape",
"of",
"the",
"output",
"matrix",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/block_matrix.py#L106-L109 | train | The shape of the output matrix. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/block_matrix.py | BlockTriangularMatrix._left_zero_blocks | def _left_zero_blocks(self, r):
"""Number of blocks with zeros from the left in block row `r`."""
if not self._include_off_diagonal:
return r
elif not self._upper:
return 0
elif self._include_diagonal:
return r
else:
return r + 1 | python | def _left_zero_blocks(self, r):
"""Number of blocks with zeros from the left in block row `r`."""
if not self._include_off_diagonal:
return r
elif not self._upper:
return 0
elif self._include_diagonal:
return r
else:
return r + 1 | [
"def",
"_left_zero_blocks",
"(",
"self",
",",
"r",
")",
":",
"if",
"not",
"self",
".",
"_include_off_diagonal",
":",
"return",
"r",
"elif",
"not",
"self",
".",
"_upper",
":",
"return",
"0",
"elif",
"self",
".",
"_include_diagonal",
":",
"return",
"r",
"e... | Number of blocks with zeros from the left in block row `r`. | [
"Number",
"of",
"blocks",
"with",
"zeros",
"from",
"the",
"left",
"in",
"block",
"row",
"r",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/block_matrix.py#L160-L169 | train | Number of blocks with zeros from the left in block row r. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/block_matrix.py | BlockTriangularMatrix._right_zero_blocks | def _right_zero_blocks(self, r):
"""Number of blocks with zeros from the right in block row `r`."""
if not self._include_off_diagonal:
return self._block_rows - r - 1
elif self._upper:
return 0
elif self._include_diagonal:
return self._block_rows - r - 1
else:
return self._bl... | python | def _right_zero_blocks(self, r):
"""Number of blocks with zeros from the right in block row `r`."""
if not self._include_off_diagonal:
return self._block_rows - r - 1
elif self._upper:
return 0
elif self._include_diagonal:
return self._block_rows - r - 1
else:
return self._bl... | [
"def",
"_right_zero_blocks",
"(",
"self",
",",
"r",
")",
":",
"if",
"not",
"self",
".",
"_include_off_diagonal",
":",
"return",
"self",
".",
"_block_rows",
"-",
"r",
"-",
"1",
"elif",
"self",
".",
"_upper",
":",
"return",
"0",
"elif",
"self",
".",
"_in... | Number of blocks with zeros from the right in block row `r`. | [
"Number",
"of",
"blocks",
"with",
"zeros",
"from",
"the",
"right",
"in",
"block",
"row",
"r",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/block_matrix.py#L171-L180 | train | Number of blocks with zeros from the right in block row r. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/block_matrix.py | BlockTriangularMatrix._content_blocks | def _content_blocks(self, r):
"""Number of content blocks in block row `r`."""
return (self._block_rows - self._left_zero_blocks(r)
- self._right_zero_blocks(r)) | python | def _content_blocks(self, r):
"""Number of content blocks in block row `r`."""
return (self._block_rows - self._left_zero_blocks(r)
- self._right_zero_blocks(r)) | [
"def",
"_content_blocks",
"(",
"self",
",",
"r",
")",
":",
"return",
"(",
"self",
".",
"_block_rows",
"-",
"self",
".",
"_left_zero_blocks",
"(",
"r",
")",
"-",
"self",
".",
"_right_zero_blocks",
"(",
"r",
")",
")"
] | Number of content blocks in block row `r`. | [
"Number",
"of",
"content",
"blocks",
"in",
"block",
"row",
"r",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/block_matrix.py#L182-L185 | train | Number of content blocks in block row r. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/rmc_nth_farthest.py | build_and_train | 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... | python | 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",
")",
":",
"# Test mode settings.",
"batch_size",
"=",
"2",
"if",
"test",
"else",
"FLAGS",
".",
"batch_size",
"num_mems",
"=",
"2",
"if",
"test",
"else",
"FLAGS",
".",
... | Construct the data, model, loss and optimizer then train. | [
"Construct",
"the",
"data",
"model",
"loss",
"and",
"optimizer",
"then",
"train",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/rmc_nth_farthest.py#L93-L202 | train | Construct the data model loss and optimizer then train. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/rmc_nth_farthest.py | SequenceModel._build | 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... | python | 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",
")",
":",
"batch_size",
"=",
"inputs",
".",
"get_shape",
"(",
")",
"[",
"0",
"]",
"output_sequence",
",",
"_",
"=",
"tf",
".",
"nn",
".",
"dynamic_rnn",
"(",
"cell",
"=",
"self",
".",
"_core",
",",
"inpu... | 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. | [
"Dynamic",
"unroll",
"across",
"input",
"objects",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/rmc_nth_farthest.py#L70-L90 | train | Dynamic unroll across input objects. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/clip_gradient.py | _clip_gradient_op | 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.
... | python | 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",
")",
":",
"def",
"clip_gradient_backward",
"(",
"op",
",",
"grad",
")",
":",
"clip_value_min",
"=",
"op",
".",
"inputs",
"[",
"1",
"]",
"clip_value_max",
"=",
"op",
".",
"inputs",
"[",
"2",
"]",
"clipped_grad",
"... | 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... | [
"Create",
"an",
"op",
"that",
"clips",
"gradients",
"using",
"a",
"Defun",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/clip_gradient.py#L25-L59 | train | Create an op that clips gradients using a Defun. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/clip_gradient.py | clip_gradient | 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... | python | 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",
")",
":",
"if",
"not",
"net",
".",
"dtype",
".",
"is_floating",
":",
"raise",
"ValueError",
"(",
"\"clip_gradient does not support non-float `net` inputs.\"",... | 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`... | [
"Clips",
"respective",
"gradients",
"of",
"a",
"given",
"tensor",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/clip_gradient.py#L62-L94 | train | Clips respective gradients of a given tensor. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/ptb_reader.py | ptb_raw_data | 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... | python | 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",
")",
":",
"train_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"data_path",
",",
"\"ptb.train.txt\"",
")",
"valid_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"data_path",
",",
"\"ptb.valid.txt\"",
")",
"test... | 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... | [
"Load",
"PTB",
"raw",
"data",
"from",
"data",
"directory",
"data_path",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/ptb_reader.py#L55-L82 | train | Loads PTB raw data from data directory data_path. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/convnet.py | ConvNet2D._check_and_assign_normalization_members | 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... | python | 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",
")",
":",
"if",
"isinstance",
"(",
"normalization_ctor",
",",
"six",
".",
"string_types",
")",
":",
"normalization_ctor",
"=",
"util",
".",
"parse_st... | Checks that the normalization constructor is callable. | [
"Checks",
"that",
"the",
"normalization",
"constructor",
"is",
"callable",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L252-L262 | train | Checks that the normalization constructor is callable and assigns the normalization members to the object. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/convnet.py | ConvNet2D._parse_normalization_kwargs | 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... | python | 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",
")",
":",
"if",
"use_batch_norm",
"is",
"not",
"None",
":",
"# Delete this whole block when deprecation is done.",
"ut... | Sets up normalization, checking old and new flags. | [
"Sets",
"up",
"normalization",
"checking",
"old",
"and",
"new",
"flags",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L264-L286 | train | Sets up normalization checking old and new flags. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/convnet.py | ConvNet2D._instantiate_layers | 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... | python | 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",
")",
":",
"# 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 ... | Instantiates all the convolutional modules used in the network. | [
"Instantiates",
"all",
"the",
"convolutional",
"modules",
"used",
"in",
"the",
"network",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L288-L309 | train | Instantiates all the convolutional modules used in the network. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/convnet.py | ConvNet2D._build | 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... | python | 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",
")",
":",
"if",
"(",
"self",
".",
"_normalization_ctor",
"in",
"{",
"batch_norm",
".",
"BatchNorm",
",",
"batch_norm_v2",
".",
"BatchNormV2",
"}",
"and",
"\"is_training\"... | 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_... | [
"Assembles",
"the",
"ConvNet2D",
"and",
"connects",
"it",
"to",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L311-L361 | train | Assembles the ConvNet2D and connects it to the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/convnet.py | ConvNet2D._transpose | def _transpose(self,
transpose_constructor,
name=None,
output_channels=None,
kernel_shapes=None,
strides=None,
paddings=None,
activation=None,
activate_final=None,
nor... | python | 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",
","... | 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 ... | [
"Returns",
"transposed",
"version",
"of",
"this",
"network",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L445-L585 | train | Returns a new version of the network with the specified parameters. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/convnet.py | ConvNet2D.transpose | def transpose(self,
name=None,
output_channels=None,
kernel_shapes=None,
strides=None,
paddings=None,
activation=None,
activate_final=None,
normalization_ctor=None,
normalizati... | python | 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",
"=",
"Non... | 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... | [
"Returns",
"transposed",
"version",
"of",
"this",
"network",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L588-L712 | train | Returns a new version of the network with the same name and parameters. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/nets/convnet.py | ConvNet2DTranspose.transpose | def transpose(self,
name=None,
output_channels=None,
kernel_shapes=None,
strides=None,
paddings=None,
activation=None,
activate_final=None,
normalization_ctor=None,
normalizati... | python | 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",
"=",
"Non... | 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... | [
"Returns",
"transposed",
"version",
"of",
"this",
"network",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/nets/convnet.py#L880-L994 | train | Returns a new version of the network with the same name and parameters. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/brnn_ptb.py | _get_raw_data | 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... | python | 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",
")",
":",
"raw_data",
"=",
"_LOADED",
".",
"get",
"(",
"subset",
")",
"if",
"raw_data",
"is",
"not",
"None",
":",
"return",
"raw_data",
",",
"_LOADED",
"[",
"\"vocab\"",
"]",
"else",
":",
"train_data",
",",
"valid_d... | Loads the data or reads it from cache. | [
"Loads",
"the",
"data",
"or",
"reads",
"it",
"from",
"cache",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L89-L103 | train | Loads the data or reads it from cache. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/brnn_ptb.py | custom_scale_mixture_prior_builder | 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... | python | 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",
")",
":",
"# This specific prior formulation doesn't need any of the arguments forwarded",
"# from `get_variable`.",
"del",
"getter",
"del",
"name",
"del",
... | 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... | [
"A",
"builder",
"for",
"the",
"gaussian",
"scale",
"-",
"mixture",
"prior",
"of",
"Fortunato",
"et",
"al",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L181-L204 | train | A custom scale - mixture prior of Fortunato et al. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/brnn_ptb.py | lstm_posterior_builder | 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... | python | 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",
")",
":",
"del",
"args",
"parameter_shapes",
"=",
"tfp",
".",
"distributions",
".",
"Normal",
".",
"param_static_shapes",
"(",
"kwargs",
"[",
"\"shape\"",... | 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... | [
"A",
"builder",
"for",
"a",
"particular",
"diagonal",
"gaussian",
"posterior",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L207-L245 | train | A builder for a particular diagonal gaussian posterior. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/brnn_ptb.py | build_modules | 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... | python | 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 custom getter which implements Bayes by Backprop.",
"if",
"is_training",
":",
"estimator_mode",
"=",
"tf",
".",
"constant",
"(",
"bbb",
".",
"EstimatorModes",
".",
"sample",
")",
... | Construct the modules used in the graph. | [
"Construct",
"the",
"modules",
"used",
"in",
"the",
"graph",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L289-L330 | train | Construct the modules used in the graph. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/brnn_ptb.py | build_logits | 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... | python | 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",
")",
":",
"# Embed the input index sequence.",
"embedded_input_seq",
"=",
"snt",
".",
"BatchApply",
"(",
"embed_layer",
",",
"name",
"=",
"\"input_... | 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... | [
"This",
"is",
"the",
"core",
"model",
"logic",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L333-L376 | train | This function builds the logits for a sequence of n - dimensional RNNs. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/brnn_ptb.py | build_loss | 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... | python | 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",
")",
":",
"time_major_shape",
"=",
"[",
"FLAGS",
".",
"unroll_steps",
",",
"FLAGS",
".",
"batch_size",
"]",
"flat_batch_shape",
"=",
"[",
"FLAGS",
".",
"unroll_steps",
"*",
"FLAGS",
".",
"batch_s... | Compute the log loss given predictions and targets. | [
"Compute",
"the",
"log",
"loss",
"given",
"predictions",
"and",
"targets",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L379-L390 | train | Compute the log loss given predictions and targets. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/brnn_ptb.py | train | 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... | python | 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",
")",
":",
"ptb_train",
"=",
"PTB",
"(",
"name",
"=",
"\"ptb_train\"",
",",
"subset",
"=",
"\"train\"",
",",
"seq_len",
"=",
"FLAGS",
".",
"unroll_steps",
",",
"batch_size",
"=",
"FLAGS",
".",
"batch_size",
")",
"# Connect to ... | Run a network on the PTB training set, checkpointing the weights. | [
"Run",
"a",
"network",
"on",
"the",
"PTB",
"training",
"set",
"checkpointing",
"the",
"weights",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/brnn_ptb.py#L393-L541 | train | Run a PTB training set checkpointing the weights. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/__init__.py | _ensure_dependency_available_at_version | 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... | python | 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",
")",
":",
"try",
":",
"pkg",
"=",
"importlib",
".",
"import_module",
"(",
"package_name",
")",
"except",
"ImportError",
":",
"pip_name",
"=",
"package_name",
".",
"replace",
... | Throw helpful error if required dependencies not available. | [
"Throw",
"helpful",
"error",
"if",
"required",
"dependencies",
"not",
"available",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/__init__.py#L43-L61 | train | Throw helpful error if required dependencies not available at the given version. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/scale_gradient.py | _scale_gradient_op | 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... | python | 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",
")",
":",
"def",
"scale_gradient_backward",
"(",
"op",
",",
"grad",
")",
":",
"scale",
"=",
"op",
".",
"inputs",
"[",
"1",
"]",
"scaled_grad",
"=",
"grad",
"*",
"scale",
"return",
"scaled_grad",
",",
"None",
"# ... | 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 ... | [
"Create",
"an",
"op",
"that",
"scales",
"gradients",
"using",
"a",
"Defun",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/scale_gradient.py#L27-L61 | train | Create an op that scales gradients using a Defun. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/scale_gradient.py | scale_gradient | 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 ... | python | 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\"",
")",
":",
"if",
"tf",
".",
"executing_eagerly",
"(",
")",
":",
"if",
"not",
"callable",
"(",
"net",
")",
":",
"raise",
"ValueError",
"(",
"\"In eager mode `net` must b... | 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... | [
"Scales",
"gradients",
"for",
"the",
"backwards",
"pass",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/scale_gradient.py#L64-L113 | train | Scales gradients on the backwards pass. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/rmc_learn_to_execute.py | build_and_train | 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... | python | 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",
")",
":",
"# Test mode settings.",
"batch_size",
"=",
"2",
"if",
"test",
"else",
"FLAGS",
".",
"batch_size",
"num_mems",
"=",
"2",
"if",
"test",
"else",
"FLAGS",
".",
... | Construct the data, model, loss and optimizer then train. | [
"Construct",
"the",
"data",
"model",
"loss",
"and",
"optimizer",
"then",
"train",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/rmc_learn_to_execute.py#L110-L227 | train | Construct the data model loss and optimizer then train. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/examples/rmc_learn_to_execute.py | SequenceModel._build | 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
... | python | 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",
")",
":",
"# Connect decoding steps.",
"batch_size",
"=",
"inputs",
".",
"get_shape",
"(",
")",
"[",
"1",
"]",
"initial_state",
"=",
"self",... | 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
... | [
"Dynamic",
"unroll",
"across",
"input",
"objects",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/examples/rmc_learn_to_execute.py#L69-L107 | train | Builds the seq2seq model. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/gated_rnn.py | lstm_with_recurrent_dropout | 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, ... | python | 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",
"=",
"LSTM",
"(",
"hidden_size",
",",
"*",
"*",
"kwargs",
")",
"return",
"RecurrentDropoutWrapper",
"(",
"lstm",
",",
"LSTMStat... | 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... | [
"LSTM",
"with",
"recurrent",
"dropout",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L433-L448 | train | Returns a new LSTM with recurrent dropout enabled. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
deepmind/sonnet | sonnet/python/modules/gated_rnn.py | lstm_with_zoneout | 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 ... | python | 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",
"=",
"LSTM",
"(",
"hidden_size",
",",
"*",
"*",
"kwargs",
")",
"keep_probs",
"=",
"LSTMState",
"("... | 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... | [
"LSTM",
"with",
"recurrent",
"dropout",
"."
] | 00612ca3178964d86b556e062694d808ff81fcca | https://github.com/deepmind/sonnet/blob/00612ca3178964d86b556e062694d808ff81fcca/sonnet/python/modules/gated_rnn.py#L519-L540 | train | Returns a new LSTM with recurrent dropout enabled for training and test LSTM. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.