Skip to content

Commit baedb51

Browse files
committed
update docs
1 parent 1c6843b commit baedb51

File tree

7 files changed

+56
-3
lines changed

7 files changed

+56
-3
lines changed

.readthedocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ formats: all
1919
# Optionally set the version of Python and requirements required to build your docs
2020
python:
2121
version: 3.6
22-
install:
23-
- requirements: site/requirements-docs.txt
22+
# install:
23+
# - requirements: site/requirements-docs.txt

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pydoc: clean-doc ## generate pydoc HTML documentation based on docstrings
5454
cat requirements.txt | xargs -L 1 .venv/bin/pip install; \
5555
.venv/bin/python -m pydoc -w subaligner; mv subaligner.html docs/index.html
5656
.venv/bin/python -m pydoc -w subaligner.embedder; mv subaligner.embedder.html docs
57+
.venv/bin/python -m pydoc -w subaligner.hparam_tuner; mv subaligner.hparam_tuner.html docs
5758
.venv/bin/python -m pydoc -w subaligner.hyperparameters; mv subaligner.hyperparameters.html docs
5859
.venv/bin/python -m pydoc -w subaligner.media_helper; mv subaligner.media_helper.html docs
5960
.venv/bin/python -m pydoc -w subaligner.network; mv subaligner.network.html docs

docs/.gitkeep

Whitespace-only changes.

site/requirements-docs.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
psutil==5.6.6
1+
hyperopt==0.2.4
2+
psutil==5.6.6

site/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@
7070
"absl-py",
7171
"aeneas",
7272
"h5py",
73+
"hyperopt",
7374
"librosa",
7475
"matplotlib",
7576
"numpy",
77+
"psutil",
7678
"pycaption",
7779
"pysrt",
7880
"sklearn",

subaligner/hparam_tuner.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
class HyperParameterTuner(object):
11+
"""Hyper parameter tuning using the Bayesian Optimizer"""
1112

1213
SEARCH_SPACE = {
1314
"learning_rate": hp.loguniform("learning_rate", np.log(0.00001), np.log(0.1)),
@@ -25,6 +26,17 @@ def __init__(self,
2526
training_dump_dir,
2627
num_of_trials=5,
2728
tuning_epochs=5):
29+
"""Hyper parameter tuner initialiser
30+
31+
Arguments:
32+
av_file_paths {list} -- A list of paths to the input audio/video files.
33+
subtitle_file_paths {list} -- A list of paths to the subtitle files.
34+
training_dump_dir {string} -- The directory of the training data dump file.
35+
36+
Keyword Arguments:
37+
num_of_trials {int} -- The number of trials for tuning (default: {5}).
38+
tuning_epochs {int} -- The number of training epochs for each trial (default: {5}).
39+
"""
2840
self.__trainer = Trainer(FeatureEmbedder())
2941
self.__av_file_paths = av_file_paths
3042
self.__subtitle_file_paths = subtitle_file_paths
@@ -40,6 +52,8 @@ def hyperparameters(self):
4052
return self.__hyperparameters.clone()
4153

4254
def tune_hyperparameters(self):
55+
"""Tune the hyper parameters"""
56+
4357
trials = hyperopt.Trials()
4458
minimised = hyperopt.fmin(fn=self.__get_val_loss,
4559
space=self.SEARCH_SPACE,

subaligner/hyperparameters.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class Hyperparameters(object):
77
"""
88

99
def __init__(self):
10+
"""Hyper parameters initialiser setting default values"""
11+
1012
self.__learning_rate = 0.001
1113
self.__hidden_size = {
1214
"front_layers": [64],
@@ -26,6 +28,8 @@ def __init__(self):
2628
self.__network_type = "lstm"
2729

2830
def __eq__(self, other):
31+
"""Comparator for Hyperparameters objects"""
32+
2933
if isinstance(other, Hyperparameters):
3034
return all([
3135
self.__learning_rate == other.learning_rate,
@@ -172,22 +176,53 @@ def network_type(self, value):
172176
self.__network_type = value
173177

174178
def to_json(self):
179+
"""Serialise hyper parameters into JSON string
180+
181+
Returns:
182+
string -- The serialised hyper parameters in JSON
183+
"""
175184
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
176185

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

181195
def clone(self):
196+
"""Make a cloned hyper parameters object
197+
198+
Returns:
199+
Hyperparameters -- The cloned Hyperparameters object.
200+
"""
182201
return self.from_json(self.to_json())
183202

184203
@classmethod
185204
def from_json(cls, json_str):
205+
"""Deserialise JSON string into a Hyperparameters object
206+
207+
Arguments:
208+
json_str {string} -- Hyper parameters in JSON.
209+
210+
Returns:
211+
Hyperparameters -- The deserialised Hyperparameters object.
212+
"""
186213
hp = cls()
187214
hp.__dict__ = json.loads(json_str)
188215
return hp
189216

190217
@classmethod
191218
def from_file(cls, file_path):
219+
"""Deserialise a file content into a Hyperparameters object
220+
221+
Arguments:
222+
file_path {string} -- The path to the file containing hyper parameters.
223+
224+
Returns:
225+
Hyperparameters -- The deserialised Hyperparameters object.
226+
"""
192227
with open(file_path, "r", encoding="utf8") as file:
193228
return cls.from_json(file.read())

0 commit comments

Comments
 (0)