-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from inikdom/dev
Dev
- Loading branch information
Showing
4 changed files
with
90 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
''' | ||
This is the main logic for serializing and deserializing dictionaries | ||
of hyperparameters (for use in checkpoint restoration and sampling) | ||
''' | ||
import os | ||
import pickle | ||
|
||
class HyperParameterHandler(object): | ||
def __init__(self, path): | ||
self.file_path = os.path.join(path, "hyperparams.p") | ||
|
||
def saveParams(self, dic): | ||
with open(self.file_path, 'wb') as handle: | ||
pickle.dump(dic, handle) | ||
|
||
def getParams(self): | ||
with open(self.file_path, 'rb') as handle: | ||
return pickle.load(handle) | ||
|
||
def checkExists(self): | ||
''' | ||
Checks if hyper parameter file exists | ||
''' | ||
return os.path.exists(self.file_path) | ||
|
||
def checkChanged(self, new_params): | ||
if self.checkExists(): | ||
old_params = self.getParams() | ||
return old_params["num_layers"] != new_params["num_layers"] or\ | ||
old_params["hidden_size"] != new_params["hidden_size"] or\ | ||
old_params["max_seq_length"] != new_params["max_seq_length"] or\ | ||
old_params["max_vocab_size"] != new_params["max_vocab_size"] | ||
else: | ||
return False |