プリンキピア

第19章ハイパーパラメータ最適化

19.2.8. Exercises19.2.8 練習問題

  1. The goal of this exercise is to implement the objective function for a slightly more challenging HPO problem, and to run more realistic experiments. We will use the two hidden layer MLP DropoutMLP implemented in Section 5.6.
    英語のヒント
    この練習問題の目標は、少し難しいHPOの問題の目的関数を実装し、もっと現実的な実験を実行することである。5.6節で実装した、隠れ層が二つのMLPDropoutMLPを使う。
    1. Code up the objective function, which should depend on all hyperparameters of the model and batch_size. Use max_epochs=50. GPUs do not help here, so num_gpus=0. Hint: Modify hpo_objective_lenet.
      英語のヒント
      モデルのすべてのハイパーパラメータとbatch_sizeに依存する目的関数を書け。max_epochs=50を使え。ここではGPUは役に立たないので、num_gpus=0とする。ヒント:hpo_objective_lenetを変更せよ。
    2. Choose a sensible search space, where num_hiddens_1, num_hiddens_2 are integers in [8,1024], and dropout values lie in [0,0.95], while batch_size lies in [16,384]. Provide code for config_space, using sensible distributions from scipy.stats.
      英語のヒント
      num_hiddens_1とnum_hiddens_2は[8,1024]の整数、ドロップアウトの値は[0,0.95]の中、batch_sizeは[16,384]の中にある、妥当な探索空間を選べ。scipy.statsの妥当な分布を使って、config_spaceのコードを書け。
    3. Run random search on this example with number_of_trials=20 and plot the results. Make sure to first evaluate the default configuration of Section 5.6, which is initial_config = {'num_hiddens_1': 256, 'num_hiddens_2': 256, 'dropout_1': 0.5, 'dropout_2': 0.5, 'lr': 0.1, 'batch_size': 256}.
      英語のヒント
      この例で、number_of_trials=20としてランダム探索を実行し、結果をプロットせよ。まず5.6節の既定の設定、つまりinitial_config = {'num_hiddens_1': 256, 'num_hiddens_2': 256, 'dropout_1': 0.5, 'dropout_2': 0.5, 'lr': 0.1, 'batch_size': 256}を評価するようにせよ。
  2. In this exercise, you will implement a new searcher (subclass of HPOSearcher) which makes decisions based on past data. It depends on parameters probab_local, num_init_random. Its sample_configuration method works as follows. For the first num_init_random calls, do the same as RandomSearcher.sample_configuration. Otherwise, with probability 1 - probab_local, do the same as RandomSearcher.sample_configuration. Otherwise, pick the configuration which attained the smallest validation error so far, select one of its hyperparameters at random, and sample its value randomly like in RandomSearcher.sample_configuration, but leave all other values the same. Return this configuration, which is identical to the best configuration so far, except in this one hyperparameter.
    英語のヒント
    この練習問題では、過去のデータにもとづいて決定を下す新しいサーチャー(HPOSearcherのサブクラス)を実装する。これはパラメータprobab_localとnum_init_randomに依存する。そのsample_configurationメソッドは次のように働く。最初のnum_init_random回の呼び出しでは、RandomSearcher.sample_configurationと同じことをする。そうでなければ、確率1 - probab_localでRandomSearcher.sample_configurationと同じことをする。そうでもなければ、これまでで最も小さい検証誤差を達成した設定を選び、そのハイパーパラメータの一つをランダムに選んで、RandomSearcher.sample_configurationと同じようにその値をランダムに抜き出すが、ほかの値はすべてそのままにする。この一つのハイパーパラメータを除けばこれまでの最良の設定と同一であるこの設定を返す。
    1. Code up this new LocalSearcher. Hint: Your searcher requires config_space as argument at construction. Feel free to use a member of type RandomSearcher. You will also have to implement the update method.
      英語のヒント
      この新しいLocalSearcherを書け。ヒント:このサーチャーは、作るときに引数としてconfig_spaceを必要とする。RandomSearcher型のメンバーを自由に使ってよい。updateメソッドも実装しなければならない。
    2. Re-run the experiment from the previous exercise, but using your new searcher instead of RandomSearcher. Experiment with different values for probab_local, num_init_random. However, note that a proper comparison between different HPO methods requires repeating experiments several times, and ideally considering a number of benchmark tasks.
      英語のヒント
      前の練習問題の実験を、RandomSearcherの代わりに新しいサーチャーを使って実行し直せ。probab_localとnum_init_randomの値をいろいろ変えて実験せよ。しかし、異なるHPOの方法を適切に比較するには、実験を何度も繰り返し、理想的にはいくつものベンチマークのタスクを考える必要があることに注意しよう。