Type HParams
Namespace tensorflow.contrib.training
Parent PythonObjectContainer
Interfaces IHParams
Class to hold a set of hyperparameters as name-value pairs. A `HParams` object holds hyperparameters used to build and train a model,
such as the number of hidden units in a neural net layer or the learning rate
to use when training. You first create a `HParams` object by specifying the names and values of the
hyperparameters. To make them easily accessible the parameter names are added as direct
attributes of the class. A typical usage is as follows:
Hyperparameters have type, which is inferred from the type of their value
passed at construction type. The currently supported types are: integer,
float, boolean, string, and list of integer, float, boolean, or string. You can override hyperparameter values by calling the
[`parse()`](#HParams.parse) method, passing a string of comma separated
`name=value` pairs. This is intended to make it possible to override
any hyperparameter values from a single command-line flag to which
the user passes 'hyper-param=value' pairs. It avoids having to define
one flag for each hyperparameter. The syntax expected for each value depends on the type of the parameter.
See `parse()` for a description of the syntax. Example:
Show Example
# Create a HParams object specifying names and values of the model # hyperparameters: hparams = HParams(learning_rate=0.1, num_hidden_units=100) # The hyperparameter are available as attributes of the HParams object: hparams.learning_rate ==> 0.1 hparams.num_hidden_units ==> 100
Methods
- __contains___dyn
- add_hparam
- add_hparam
- add_hparam
- add_hparam
- add_hparam
- add_hparam
- add_hparam
- add_hparam
- add_hparam
- add_hparam_dyn
- del_hparam
- del_hparam_dyn
- get
- get
- get
- get
- get
- get_dyn
- get_model_structure
- get_model_structure_dyn
- override_from_dict
- override_from_dict
- override_from_dict_dyn
- parse
- parse
- parse_dyn
- parse_json
- parse_json_dyn
- set_from_map
- set_from_map_dyn
- set_hparam
- set_hparam
- set_hparam
- set_hparam
- set_hparam
- set_hparam
- set_hparam_dyn
- set_model_structure
- set_model_structure_dyn
- to_json
- to_json_dyn
Properties
Public instance methods
object __contains___dyn(object key)
void add_hparam(string name, string value)
Adds {name, value} pair to hyperparameters.
Parameters
-
string
name - Name of the hyperparameter.
-
string
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
void add_hparam(string name, int value)
Adds {name, value} pair to hyperparameters.
Parameters
-
string
name - Name of the hyperparameter.
-
int
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
void add_hparam(string name, DType value)
Adds {name, value} pair to hyperparameters.
Parameters
-
string
name - Name of the hyperparameter.
-
DType
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
void add_hparam(string name, ValueTuple<int, int, object> value)
Adds {name, value} pair to hyperparameters.
Parameters
-
string
name - Name of the hyperparameter.
-
ValueTuple<int, int, object>
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
void add_hparam(string name, bool value)
Adds {name, value} pair to hyperparameters.
Parameters
-
string
name - Name of the hyperparameter.
-
bool
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
void add_hparam(string name, IEnumerable<double> value)
Adds {name, value} pair to hyperparameters.
Parameters
-
string
name - Name of the hyperparameter.
-
IEnumerable<double>
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
void add_hparam(string name, double value)
Adds {name, value} pair to hyperparameters.
Parameters
-
string
name - Name of the hyperparameter.
-
double
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
void add_hparam(string name, Byte[] value)
Adds {name, value} pair to hyperparameters.
Parameters
-
string
name - Name of the hyperparameter.
-
Byte[]
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
void add_hparam(string name, ValueTuple<IEnumerable<object>, object> value)
Adds {name, value} pair to hyperparameters.
Parameters
-
string
name - Name of the hyperparameter.
-
ValueTuple<IEnumerable<object>, object>
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
object add_hparam_dyn(object name, object value)
Adds {name, value} pair to hyperparameters.
Parameters
-
object
name - Name of the hyperparameter.
-
object
value - Value of the hyperparameter. Can be one of the following types: int, float, string, int list, float list, or string list.
void del_hparam(string name)
Removes the hyperparameter with key 'name'. Does nothing if it isn't present.
Parameters
-
string
name - Name of the hyperparameter.
object del_hparam_dyn(object name)
Removes the hyperparameter with key 'name'. Does nothing if it isn't present.
Parameters
-
object
name - Name of the hyperparameter.
object get(string key, string default)
Returns the value of `key` if it exists, else `default`.
object get(string key, int default)
Returns the value of `key` if it exists, else `default`.
object get(string key, IEnumerable<double> default)
Returns the value of `key` if it exists, else `default`.
object get(string key, double default)
Returns the value of `key` if it exists, else `default`.
object get(string key, bool default)
Returns the value of `key` if it exists, else `default`.
object get_dyn(object key, object default)
Returns the value of `key` if it exists, else `default`.
object get_model_structure()
object get_model_structure_dyn()
HParams override_from_dict(IDictionary<string, object> values_dict)
Override existing hyperparameter values, parsing new values from a dictionary.
Parameters
-
IDictionary<string, object>
values_dict - Dictionary of name:value pairs.
Returns
-
HParams
- The `HParams` instance.
HParams override_from_dict(object values_dict)
Override existing hyperparameter values, parsing new values from a dictionary.
Parameters
-
object
values_dict - Dictionary of name:value pairs.
Returns
-
HParams
- The `HParams` instance.
object override_from_dict_dyn(object values_dict)
Override existing hyperparameter values, parsing new values from a dictionary.
Parameters
-
object
values_dict - Dictionary of name:value pairs.
Returns
-
object
- The `HParams` instance.
HParams parse(IEnumerable<string> values)
Override existing hyperparameter values, parsing new values from a string. See parse_values for more detail on the allowed format for values.
Parameters
-
IEnumerable<string>
values - String. Comma separated list of `name=value` pairs where 'value' must follow the syntax described above.
Returns
-
HParams
- The `HParams` instance.
HParams parse(string values)
Override existing hyperparameter values, parsing new values from a string. See parse_values for more detail on the allowed format for values.
Parameters
-
string
values - String. Comma separated list of `name=value` pairs where 'value' must follow the syntax described above.
Returns
-
HParams
- The `HParams` instance.
object parse_dyn(object values)
Override existing hyperparameter values, parsing new values from a string. See parse_values for more detail on the allowed format for values.
Parameters
-
object
values - String. Comma separated list of `name=value` pairs where 'value' must follow the syntax described above.
Returns
-
object
- The `HParams` instance.
HParams parse_json(string values_json)
Override existing hyperparameter values, parsing new values from a json object.
Parameters
-
string
values_json - String containing a json object of name:value pairs.
Returns
-
HParams
- The `HParams` instance.
object parse_json_dyn(object values_json)
Override existing hyperparameter values, parsing new values from a json object.
Parameters
-
object
values_json - String containing a json object of name:value pairs.
Returns
-
object
- The `HParams` instance.
HParams set_from_map(object values_map)
DEPRECATED. Use override_from_dict. (deprecated) Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version.
Instructions for updating:
Use `override_from_dict`.
object set_from_map_dyn(object values_map)
DEPRECATED. Use override_from_dict. (deprecated) Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version.
Instructions for updating:
Use `override_from_dict`.
void set_hparam(string name, string value)
Set the value of an existing hyperparameter. This function verifies that the type of the value matches the type of the
existing hyperparameter.
Parameters
-
string
name - Name of the hyperparameter.
-
string
value - New value of the hyperparameter.
void set_hparam(string name, Object value)
Set the value of an existing hyperparameter. This function verifies that the type of the value matches the type of the
existing hyperparameter.
Parameters
-
string
name - Name of the hyperparameter.
-
Object
value - New value of the hyperparameter.
void set_hparam(string name, int value)
Set the value of an existing hyperparameter. This function verifies that the type of the value matches the type of the
existing hyperparameter.
Parameters
-
string
name - Name of the hyperparameter.
-
int
value - New value of the hyperparameter.
void set_hparam(string name, IEnumerable<double> value)
Set the value of an existing hyperparameter. This function verifies that the type of the value matches the type of the
existing hyperparameter.
Parameters
-
string
name - Name of the hyperparameter.
-
IEnumerable<double>
value - New value of the hyperparameter.
void set_hparam(string name, double value)
Set the value of an existing hyperparameter. This function verifies that the type of the value matches the type of the
existing hyperparameter.
Parameters
-
string
name - Name of the hyperparameter.
-
double
value - New value of the hyperparameter.
void set_hparam(string name, bool value)
Set the value of an existing hyperparameter. This function verifies that the type of the value matches the type of the
existing hyperparameter.
Parameters
-
string
name - Name of the hyperparameter.
-
bool
value - New value of the hyperparameter.
object set_hparam_dyn(object name, object value)
Set the value of an existing hyperparameter. This function verifies that the type of the value matches the type of the
existing hyperparameter.
Parameters
-
object
name - Name of the hyperparameter.
-
object
value - New value of the hyperparameter.
void set_model_structure(object model_structure)
object set_model_structure_dyn(object model_structure)
string to_json(Nullable<int> indent, Nullable<ValueTuple<string, string>> separators, bool sort_keys)
Serializes the hyperparameters into JSON.
Parameters
-
Nullable<int>
indent - If a non-negative integer, JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0, or negative, will only insert newlines. `None` (the default) selects the most compact representation.
-
Nullable<ValueTuple<string, string>>
separators - Optional `(item_separator, key_separator)` tuple. Default is `(', ', ': ')`.
-
bool
sort_keys - If `True`, the output dictionaries will be sorted by key.
Returns
-
string
- A JSON string.
object to_json_dyn(object indent, object separators, ImplicitContainer<T> sort_keys)
Serializes the hyperparameters into JSON.
Parameters
-
object
indent - If a non-negative integer, JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0, or negative, will only insert newlines. `None` (the default) selects the most compact representation.
-
object
separators - Optional `(item_separator, key_separator)` tuple. Default is `(', ', ': ')`.
-
ImplicitContainer<T>
sort_keys - If `True`, the output dictionaries will be sorted by key.
Returns
-
object
- A JSON string.