|
| 1 | +******************** |
| 2 | +SpeechBrain |
| 3 | +******************** |
| 4 | + |
| 5 | +In this short tutorial, we're going to demonstrate how Oríon can be integrated to a `SpeechBrain |
| 6 | +<https://speechbrain.github.io/>`_ speech recognition model. |
| 7 | +The files mentioned in this tutorial are available in the `Oríon |
| 8 | +<https://github.com/Epistimio/orion/tree/develop/examples>`_ repository. |
| 9 | + |
| 10 | +Installation and setup |
| 11 | +====================== |
| 12 | + |
| 13 | +Make sure Oríon is installed (:doc:`/install/core`). |
| 14 | + |
| 15 | +Then install SpeechBrain using ``$ pip install speechbrain`` |
| 16 | + |
| 17 | +Code used in this tutorial |
| 18 | +========================== |
| 19 | + |
| 20 | +In this tutorial, we are going to use some code from the `SpeechBrain |
| 21 | +<https://github.com/speechbrain/speechbrain>` repository. More specifically, a speech recognition |
| 22 | +template made as an example. We will repurpose this example to adapt it for Oríon. The template |
| 23 | +used for creating this tutorial can be found `here |
| 24 | +<https://github.com/speechbrain/speechbrain/tree/develop/templates/speech_recognition/ASR>`. |
| 25 | +You can also directly see the code modified for this example here : |
| 26 | +``examples/speechbrain_tutorial``. |
| 27 | + |
| 28 | +We used the ``train.py`` file, but created a ``main.py``, with the ``main`` function, |
| 29 | +which we slightly modified for optimizing the hyperparamers with Oríon. |
| 30 | + |
| 31 | +Adapting the Speechbrain for Oríon |
| 32 | +================================== |
| 33 | + |
| 34 | +The Adaptation for using Oríon is quite simple. |
| 35 | + |
| 36 | +1) We first need to import ``orion.report_objective()`` into the project. |
| 37 | + |
| 38 | +.. code-block:: python |
| 39 | +
|
| 40 | + from orion.client import report_objective |
| 41 | +
|
| 42 | +2) We then need to change the evaluation from the training data to the validation data. |
| 43 | +The evaluation method should look like this. It returns the validation loss. |
| 44 | + |
| 45 | +.. literalinclude:: /../../examples/speechbrain_tutorial/main.py |
| 46 | + :language: python |
| 47 | + :lines: 75-80 |
| 48 | + |
| 49 | +3) Finally, we call ``report_objective`` at the end to return the final objective value, |
| 50 | +the validation loss, to Oríon. |
| 51 | + |
| 52 | +.. code-block:: python |
| 53 | +
|
| 54 | + report_objective(valid_stats) |
| 55 | +
|
| 56 | +The code is now adapted and ready to be used with Oríon. |
| 57 | + |
| 58 | +Execution |
| 59 | +========= |
| 60 | + |
| 61 | +We are now going to call the ``orion hunt`` command. |
| 62 | +Notice that we still need to give the ``train.yaml`` |
| 63 | +file to speechbrain, since the general configuration is in there. However, we are going to specify |
| 64 | +the hyperparameters that we want to optimize in the command line, |
| 65 | +which will automatically overrides the ones set in the ``train.yaml``. When an argument |
| 66 | +is defined both in the yaml configuration file and in command line, SpeechBrain |
| 67 | +gives precedence to values provided in command line. Thus, defining the hyperparamers through |
| 68 | +the command line for Oríon allows overriding the values in ``train.yaml`` in SpeechBrain. |
| 69 | + |
| 70 | +.. code-block:: bash |
| 71 | +
|
| 72 | + orion hunt \ |
| 73 | + --enable-evc -n <experiment_name> \ |
| 74 | + python main.py train.yaml \ |
| 75 | + --lr~'loguniform(0.05, 0.2)' \ |
| 76 | + --ctc_weight~'loguniform(0.25, 0.75)' \ |
| 77 | + --label_smoothing~'loguniform(1e-10, 10e-5)' \ |
| 78 | + --coverage_penalty~'loguniform(1.0, 2.0)' \ |
| 79 | + --temperature~'loguniform(1.0, 1.5)' \ |
| 80 | + --temperature_lm~'loguniform(1.0, 1.5)' |
| 81 | +
|
| 82 | +Results |
| 83 | +======= |
| 84 | + |
| 85 | +When an experiment reaches its termination criterion, basically ``max-trials``, |
| 86 | +you can see the results using the following command: |
| 87 | + |
| 88 | +.. code-block:: bash |
| 89 | +
|
| 90 | + $ orion info -n <experiment_name> |
| 91 | +
|
| 92 | +Which outputs the following statistics: |
| 93 | + |
| 94 | +.. code-block:: bash |
| 95 | +
|
| 96 | + Stats |
| 97 | + ===== |
| 98 | + completed: True |
| 99 | + trials completed: 209 |
| 100 | + best trial: |
| 101 | + id: 8675cfcfba768243e1ed1ac7825c69b6 |
| 102 | + evaluation: 0.13801406680803444 |
| 103 | + params: |
| 104 | + /coverage_penalty: 1.396 |
| 105 | + /ctc_weight: 0.389 |
| 106 | + /label_smoothing: 2.044e-10 |
| 107 | + /lr: 0.06462 |
| 108 | + /temperature: 1.175 |
| 109 | + /temperature_lm: 1.087 |
| 110 | + start time: 2022-09-29 14:37:41.048314 |
| 111 | + finish time: 2022-09-30 20:08:07.384765 |
| 112 | + duration: 1 day, 5:30:26.336451 |
0 commit comments