MCPcopy
hub / github.com/cs230-stanford/cs230-code-examples / Params

Class Params

tensorflow/nlp/model/utils.py:7–35  ·  view source on GitHub ↗

Class that loads hyperparameters from a json file. Example: ``` params = Params(json_path) print(params.learning_rate) params.learning_rate = 0.5 # change the value of learning_rate in params ```

Source from the content-addressed store, hash-verified

5
6
7class Params():
8 """Class that loads hyperparameters from a json file.
9
10 Example:
11 ```
12 params = Params(json_path)
13 print(params.learning_rate)
14 params.learning_rate = 0.5 # change the value of learning_rate in params
15 ```
16 """
17
18 def __init__(self, json_path):
19 self.update(json_path)
20
21 def save(self, json_path):
22 """Saves parameters to json file"""
23 with open(json_path, 'w') as f:
24 json.dump(self.__dict__, f, indent=4)
25
26 def update(self, json_path):
27 """Loads parameters from json file"""
28 with open(json_path) as f:
29 params = json.load(f)
30 self.__dict__.update(params)
31
32 @property
33 def dict(self):
34 """Gives dict-like access to Params instance by `params.dict['learning_rate']`"""
35 return self.__dict__
36
37
38def set_logger(log_path):

Callers 3

train.pyFile · 0.90
evaluate.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected