class_docstr: 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:
  
  ```python
  # 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
  ```
  
  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:
  
  ```python
  # Define a command line flag to pass name=value pairs.
  # For example using argparse:
  import argparse
  parser = argparse.ArgumentParser(description='Train my model.')
  parser.add_argument('--hparams', type=str,
                      help='Comma separated list of "name=value" pairs.')
  args = parser.parse_args()
  ...
  def my_program():
    # Create a HParams object specifying the names and values of the
    # model hyperparameters:
    hparams = tf.HParams(learning_rate=0.1, num_hidden_units=100,
                         activations=['relu', 'tanh'])
  
    # Override hyperparameters values by parsing the command line
    hparams.parse(args.hparams)
  
    # If the user passed `--hparams=learning_rate=0.3` on the command line
    # then 'hparams' has the following attributes:
    hparams.learning_rate ==> 0.3
    hparams.num_hidden_units ==> 100
    hparams.activations ==> ['relu', 'tanh']
  
    # If the hyperparameters are in json format use parse_json:
    hparams.parse_json('{"learning_rate": 0.3, "activations": "relu"}')
  ```
class_docstr_tok: ["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",":","``","`","python","#","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","``","`","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",":","``","`","python","#","Define","a","command","line","flag","to","pass","name=value","pairs",".","#","For","example","using","argparse",":","import","argparse","parser","=","argparse.ArgumentParser","(","description='Train","my","model",".","'",")","parser.add_argument","(","'","--","hparams","'",",","type=str",",","help='Comma","separated","list","of","``","name=value","''","pairs",".","'",")","args","=","parser.parse_args","(",")","...","def","my_program","(",")",":","#","Create","a","HParams","object","specifying","the","names","and","values","of","the","#","model","hyperparameters",":","hparams","=","tf.HParams","(","learning_rate=0.1",",","num_hidden_units=100",",","activations=","[","'relu","'",",","'tanh","'","]",")","#","Override","hyperparameters","values","by","parsing","the","command","line","hparams.parse","(","args.hparams",")","#","If","the","user","passed","`","--","hparams=learning_rate=0.3","`","on","the","command","line","#","then","'hparams","'","has","the","following","attributes",":","hparams.learning_rate","==",">","0.3","hparams.num_hidden_units","==",">","100","hparams.activations","==",">","[","'relu","'",",","'tanh","'","]","#","If","the","hyperparameters","are","in","json","format","use","parse_json",":","hparams.parse_json","(","'","{","``","learning_rate","''",":","0.3",",","``","activations","''",":","``","relu","''","}","'",")","``","`"]
docstr: Adds {name, value} pair to hyperparameters.
  
  Args:
    name: Name of the hyperparameter.
    value: Value of the hyperparameter. Can be one of the following types:
      int, float, string, int list, float list, or string list.
  
  Raises:
    ValueError: if one of the arguments is invalid.
docstr_tok: ["Adds","{","name",",","value","}","pair","to","hyperparameters",".","Args",":","name",":","Name","of","the","hyperparameter",".","value",":","Value","of","the","hyperparameter",".","Can","be","one","of","the","following","types",":","int",",","float",",","string",",","int","list",",","float","list",",","or","string","list",".","Raises",":","ValueError",":","if","one","of","the","arguments","is","invalid","."]
code: def add_hparam(self, name, value):
      """Adds {name, value} pair to hyperparameters.
  
      Args:
        name: Name of the hyperparameter.
        value: Value of the hyperparameter. Can be one of the following types:
          int, float, string, int list, float list, or string list.
  
      Raises:
        ValueError: if one of the arguments is invalid.
      """
      # Keys in kwargs are unique, but 'name' could the name of a pre-existing
      # attribute of this object.  In that case we refuse to use it as a
      # hyperparameter name.
      if getattr(self, name, None) is not None:
          raise ValueError("Hyperparameter name is reserved: %s" % name)
      if isinstance(value, (list, tuple)):
          if not value:
              raise ValueError(
                  "Multi-valued hyperparameters cannot be empty: %s"
                  % name
              )
          self._hparam_types[name] = (type(value[0]), True)
      else:
          self._hparam_types[name] = (type(value), False)
      setattr(self, name, value)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import json
  import numbers
  import re
  import six
label_desc: Use image node_id 2 for calling the HParams obj's underlying member method code with example usage: obj.add_hparam(name, value) without return types