@@ -58,6 +58,7 @@ <h2>Learning Objectives</h2>
5858 < section class ="content-box ">
5959 < h2 > Objective 01 - Describe the Major Hyperparameters to Tune</ h2 >
6060 < h3 > Overview</ h3 >
61+
6162 < p > We have already experimented with hyperparameter tuning in Unit 2, using the scikit-learn GridSearchCV
6263 method. Remember that a hyperparameter is a parameter set before we begin training our model; parameters
6364 are what the model learns.</ p >
@@ -154,8 +155,8 @@ <h3>Follow Along</h3>
154155</ code > </ pre >
155156 < pre > < code > # Scikit-learn wrappers for keras
156157from keras.wrappers.scikit_learn import KerasClassifier
157- neural_network = KerasClassifier(build_fn=make_network, verbose=0)
158- # Define hyperparameter space over which to search
158+ neural_network = KerasClassifier(build_fn=make_network, verbose=0)</ code > </ pre >
159+ < pre > < code > # Define hyperparameter space over which to search
159160epochs = [10, 25]
160161batches = [4, 8, 32]
161162optimizers = ['rmsprop', 'adam']
@@ -183,14 +184,19 @@ <h3>Challenge</h3>
183184 difference in the best-fit parameters returned.</ p >
184185 < h3 > Additional Resources</ h3 >
185186 < ul >
186- < li > Tuning Neural Network Hyperparameters< span > Links to an external site.</ span > </ li >
187- < li > Simple Guide to Hyperparameter Tuning in Neural Networks</ li >
187+ < li > < a href ="https://www.analyticsvidhya.com/blog/2021/05/tuning-the-hyperparameters-and-layers-of-neural-network-deep-learning/ "
188+ target ="_blank " rel ="noopener noreferrer "> Tuning Neural Network Hyperparameters</ a > </ li >
189+ < li > < a href ="https://towardsdatascience.com/simple-guide-to-hyperparameter-tuning-in-neural-networks-3fe03dad8594 "
190+ target ="_blank " rel ="noopener noreferrer "> Simple Guide to Hyperparameter Tuning in Neural
191+ Networks</ a > </ li >
188192 </ ul >
189193 </ section >
190194
191195 < section class ="content-box ">
192196 < h2 > Objective 02 - Implement an Experiment Tracking Framework</ h2 >
197+
193198 < h3 > Overview</ h3 >
199+
194200 < p > In the previous modules and objectives, we know how complicated neural networks can be and the number of
195201 hyperparameters that need to be tuned. Fortunately, there are tools to assist us in understanding how
196202 our model is affected by different hyperparameters.</ p >
@@ -219,16 +225,19 @@ <h3>Follow Along</h3>
219225x_train, x_test, y_train, y_test = train_test_split(
220226 features, target, test_size=0.25, random_state=42)
221227</ code > </ pre >
222- < p > The following example is from the Tensorflow example found here.< em > Links to an external site.</ em > </ p >
223- < p > Links to an external site. The next step is to set up the parameters we would like to tune over. In the
224- following example, the parameters are:</ p >
228+ < p > The following example is from the Tensorflow example found < a
229+ href ="https://www.tensorflow.org/tensorboard/hyperparameter_tuning_with_hparams " target ="_blank "
230+ rel ="noopener noreferrer "> here</ a > .</ p >
231+ < p > < a href ="https://www.tensorflow.org/tensorboard/hyperparameter_tuning_with_hparams " target ="_blank "
232+ rel ="noopener noreferrer "> The next step</ a > is to set up the parameters we would like to tune over.
233+ In the following example, the parameters are:</ p >
225234 < ul >
226235 < li > Number of units in the first dense layer</ li >
227236 < li > Dropout rate in the dropout layer</ li >
228237 < li > Optimizer</ li >
229238 </ ul >
230- < pre > < code > %load_ext tensorboard
231- # Imports
239+ < pre > < code > %load_ext tensorboard</ code > </ pre >
240+ < pre > < code > # Imports
232241import tensorflow as tf
233242from tensorboard.plugins.hparams import api as hp
234243
@@ -247,7 +256,7 @@ <h3>Follow Along</h3>
247256 metrics=[hp.Metric(METRIC_ACCURACY, display_name='Accuracy')],
248257 )
249258</ code > </ pre >
250- < p > Adapt TensorFlow runs to log hyperparameters and metrics</ p >
259+ < h3 > Adapt TensorFlow runs to log hyperparameters and metrics</ h3 >
251260 < pre > < code > # Write the function to create the model with the
252261# specified hyperparameter tuning
253262def train_test_model(hparams):
@@ -268,14 +277,14 @@ <h3>Follow Along</h3>
268277 _, accuracy = model.evaluate(x_test, y_test)
269278 return accuracy
270279</ code > </ pre >
271- < p > Log an hparams summary with the hyperparameters and final accuracy:</ p >
280+ < h4 > Log an hparams summary with the hyperparameters and final accuracy:</ h4 >
272281 < pre > < code > def run(run_dir, hparams):
273282 with tf.summary.create_file_writer(run_dir).as_default():
274283 hp.hparams(hparams) # record the values used in this trial
275284 accuracy = train_test_model(hparams)
276285 tf.summary.scalar(METRIC_ACCURACY, accuracy, step=1)
277286</ code > </ pre >
278- < p > Start runs and log them all under one parent directory</ p >
287+ < h3 > Start runs and log them all under one parent directory</ h3 >
279288 < pre > < code > session_num = 0
280289
281290for num_units in HP_NUM_UNITS.domain.values:
@@ -327,17 +336,18 @@ <h3>Follow Along</h3>
327336</ code > </ pre >
328337 < h4 > Visualize the results in TensorBoard's HParams plugin</ h4 >
329338 < pre > < code > # Uncomment the following line to display the output
330- #%tensorboard --logdir logs/hparam_tuning
331- mod3_obj2_tensorboard.png
332- </ code > </ pre >
339+ #%tensorboard --logdir logs/hparam_tuning</ code > </ pre >
340+ < p > < img src =" https://raw.githubusercontent.com/bloominstituteoftechnology/data-science-canvas-images/main/unit_4/sprint_2/ mod3_obj2_tensorboard.png"
341+ alt =" mod3_obj2_tensorboard.png " loading =" lazy " > </ p >
333342 < h3 > Challenge</ h3 >
334343 < p > There are a lot of parameters to adjust. For this challenge, try to reproduce the code exactly, either
335344 from the above or the link at the top and below. First, make sure you can get the Tensorboard running
336345 and then familiarize yourself with the output. Then, if you feel comfortable with that, try adjusting
337346 some of the parameters in the tuning function and see how they change the results.</ p >
338347 < h3 > Additional Resources</ h3 >
339348 < ul >
340- < li > Tensorboard: Tuning with hparams< em > Links to an external site.</ em > </ li >
349+ < li > < a href ="https://www.tensorflow.org/tensorboard/hyperparameter_tuning_with_hparams " target ="_blank "
350+ rel ="noopener noreferrer "> Tensorboard: Tuning with hparams</ a > </ li >
341351 </ ul >
342352 </ section >
343353
0 commit comments