Do a random search instead of a grid search

This commit is contained in:
Mario Bourgoin 2018-11-07 14:05:18 +00:00
Родитель 655f8e6444
Коммит 8d89795f40
1 изменённых файлов: 10 добавлений и 10 удалений

Просмотреть файл

@ -8,7 +8,7 @@
"Perform a hyperparameter search.\n",
"\n",
"The steps are\n",
"- [import lirbaries and dotenv parameters](#import)\n",
"- [import libraries and dotenv parameters](#import)\n",
"- [create a Batch AI client](#client),\n",
"- [create the Batch AI job configuration parameters](#parameters),\n",
"- [generate combinations of hyperparameter values](#combinations),\n",
@ -46,7 +46,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In the next cell are the names of various files and services used or created in this notebook."
"In the next cell are the names of various file paths and services shared between notebooks."
]
},
{
@ -251,15 +251,15 @@
" ),\n",
" DiscreteParameter(\n",
" parameter_name=\"NGRAMS\",\n",
" values=[1, 2, 3, 4]\n",
" values=list(range(1, 5))\n",
" ),\n",
" DiscreteParameter(\n",
" parameter_name=\"MATCH\",\n",
" values=[10, 20, 30, 40]\n",
" values=list(range(2, 41))\n",
" ),\n",
" DiscreteParameter(\n",
" parameter_name=\"MIN_CHILD_SAMPLES\",\n",
" values=[5, 10, 20]\n",
" values=list(range(1, 31))\n",
" ),\n",
" DiscreteParameter(\n",
" parameter_name=\"WEIGHT\",\n",
@ -274,7 +274,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We define the command line arguments that will be passed to the training script. We will use the parameter substitution object to specify where we would like to substitute the values of the hyperparameters in the command line. Note that `parameters` is used like a dict, with the `parameter_name` being used as the key to specify which parameter to substitute. When `parameters.generate_jobs` is called below, the `parameters[name]` variables will be replaced with actual values."
"We define the command line arguments that will be passed to the training script. We will use the parameter substitution object to specify where we would like to substitute the values of the hyperparameters in the command line. Note that `parameters` is used like a dict, with the `parameter_name` being used as the key to specify which parameter to substitute. When the job generation method is called below, the `parameters[name]` variables will be replaced with actual values."
]
},
{
@ -353,8 +353,7 @@
" output_directories=output_directories,\n",
" mount_volumes=mount_volumes,\n",
" container_settings=container_settings,\n",
" custom_toolkit_settings=custom_toolkit_settings\n",
" )"
" custom_toolkit_settings=custom_toolkit_settings)"
]
},
{
@ -372,7 +371,8 @@
},
"outputs": [],
"source": [
"jobs_to_submit, param_combinations = parameters.generate_jobs(jcp)\n",
"num_configs = 96\n",
"jobs_to_submit, param_combinations = parameters.generate_jobs_random_search(jcp, num_configs)\n",
"print('{:,} configurations.'.format(len(param_combinations)))\n",
"print('The command line of the first job is\\n{}'.format(jobs_to_submit[0].custom_toolkit_settings.command_line))"
]
@ -538,7 +538,7 @@
"metadata": {},
"outputs": [],
"source": [
"best_params = {ev.name[len('PARAM_'):]:ev.value for ev in job_accuracies[0]['job'].environment_variables}\n",
"best_params = {ev.name[len('PARAM_'):]: ev.value for ev in job_accuracies[0]['job'].environment_variables}\n",
"print(\"Best job: {0} with parameters:\".format(job_accuracies[0]['job_name']))\n",
"pd.Series(best_params, name='Value').to_frame()"
]