Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
baxtree committed May 7, 2020
1 parent 1c6843b commit baedb51
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ formats: all
# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.6
install:
- requirements: site/requirements-docs.txt
# install:
# - requirements: site/requirements-docs.txt
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pydoc: clean-doc ## generate pydoc HTML documentation based on docstrings
cat requirements.txt | xargs -L 1 .venv/bin/pip install; \
.venv/bin/python -m pydoc -w subaligner; mv subaligner.html docs/index.html
.venv/bin/python -m pydoc -w subaligner.embedder; mv subaligner.embedder.html docs
.venv/bin/python -m pydoc -w subaligner.hparam_tuner; mv subaligner.hparam_tuner.html docs
.venv/bin/python -m pydoc -w subaligner.hyperparameters; mv subaligner.hyperparameters.html docs
.venv/bin/python -m pydoc -w subaligner.media_helper; mv subaligner.media_helper.html docs
.venv/bin/python -m pydoc -w subaligner.network; mv subaligner.network.html docs
Expand Down
Empty file added docs/.gitkeep
Empty file.
3 changes: 2 additions & 1 deletion site/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
psutil==5.6.6
hyperopt==0.2.4
psutil==5.6.6
2 changes: 2 additions & 0 deletions site/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@
"absl-py",
"aeneas",
"h5py",
"hyperopt",
"librosa",
"matplotlib",
"numpy",
"psutil",
"pycaption",
"pysrt",
"sklearn",
Expand Down
14 changes: 14 additions & 0 deletions subaligner/hparam_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


class HyperParameterTuner(object):
"""Hyper parameter tuning using the Bayesian Optimizer"""

SEARCH_SPACE = {
"learning_rate": hp.loguniform("learning_rate", np.log(0.00001), np.log(0.1)),
Expand All @@ -25,6 +26,17 @@ def __init__(self,
training_dump_dir,
num_of_trials=5,
tuning_epochs=5):
"""Hyper parameter tuner initialiser
Arguments:
av_file_paths {list} -- A list of paths to the input audio/video files.
subtitle_file_paths {list} -- A list of paths to the subtitle files.
training_dump_dir {string} -- The directory of the training data dump file.
Keyword Arguments:
num_of_trials {int} -- The number of trials for tuning (default: {5}).
tuning_epochs {int} -- The number of training epochs for each trial (default: {5}).
"""
self.__trainer = Trainer(FeatureEmbedder())
self.__av_file_paths = av_file_paths
self.__subtitle_file_paths = subtitle_file_paths
Expand All @@ -40,6 +52,8 @@ def hyperparameters(self):
return self.__hyperparameters.clone()

def tune_hyperparameters(self):
"""Tune the hyper parameters"""

trials = hyperopt.Trials()
minimised = hyperopt.fmin(fn=self.__get_val_loss,
space=self.SEARCH_SPACE,
Expand Down
35 changes: 35 additions & 0 deletions subaligner/hyperparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Hyperparameters(object):
"""

def __init__(self):
"""Hyper parameters initialiser setting default values"""

self.__learning_rate = 0.001
self.__hidden_size = {
"front_layers": [64],
Expand All @@ -26,6 +28,8 @@ def __init__(self):
self.__network_type = "lstm"

def __eq__(self, other):
"""Comparator for Hyperparameters objects"""

if isinstance(other, Hyperparameters):
return all([
self.__learning_rate == other.learning_rate,
Expand Down Expand Up @@ -172,22 +176,53 @@ def network_type(self, value):
self.__network_type = value

def to_json(self):
"""Serialise hyper parameters into JSON string
Returns:
string -- The serialised hyper parameters in JSON
"""
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)

def to_file(self, file_path):
"""Serialise hyper parameters into JSON and save the content to a file
Arguments:
file_path {string} -- The path to the file containing saved hyper parameters.
"""
with open(file_path, "w", encoding="utf8") as file:
file.write(self.to_json())

def clone(self):
"""Make a cloned hyper parameters object
Returns:
Hyperparameters -- The cloned Hyperparameters object.
"""
return self.from_json(self.to_json())

@classmethod
def from_json(cls, json_str):
"""Deserialise JSON string into a Hyperparameters object
Arguments:
json_str {string} -- Hyper parameters in JSON.
Returns:
Hyperparameters -- The deserialised Hyperparameters object.
"""
hp = cls()
hp.__dict__ = json.loads(json_str)
return hp

@classmethod
def from_file(cls, file_path):
"""Deserialise a file content into a Hyperparameters object
Arguments:
file_path {string} -- The path to the file containing hyper parameters.
Returns:
Hyperparameters -- The deserialised Hyperparameters object.
"""
with open(file_path, "r", encoding="utf8") as file:
return cls.from_json(file.read())

0 comments on commit baedb51

Please sign in to comment.