optuna_integration.AllenNLPExecutor
- class optuna_integration.AllenNLPExecutor(trial, config_file, serialization_dir, metrics='best_validation_accuracy', *, include_package=None, force=False, file_friendly_logging=False)[source]
AllenNLP extension to use optuna with Jsonnet config file.
See the examples of objective function.
You can also see the tutorial of our AllenNLP integration on AllenNLP Guide.
Note
From Optuna v2.1.0, users have to cast their parameters by using methods in Jsonnet. Call
std.parseInt
for integer, orstd.parseJson
for floating point. Please see the example configuration.Note
In
AllenNLPExecutor
, you can pass parameters to AllenNLP by either defining a search space using Optuna suggest methods or setting environment variables just like AllenNLP CLI. If a value is set in both a search space in Optuna and the environment variables, the executor will use the value specified in the search space in Optuna.- Parameters:
trial (optuna.Trial) – A
Trial
corresponding to the current evaluation of the objective function.config_file (str) – Config file for AllenNLP. Hyperparameters should be masked with
std.extVar
. Please refer to the config example.serialization_dir (str) – A path which model weights and logs are saved.
metrics (str) – An evaluation metric. GradientDescrentTrainer.train() of AllenNLP returns a dictionary containing metrics after training.
AllenNLPExecutor
accesses the dictionary by the keymetrics
you specify and use it as a objective value.force (bool) – If
True
, an executor overwrites the output directory if it exists.file_friendly_logging (bool) – If
True
, tqdm status is printed on separate lines and slows tqdm refresh rate.include_package (str | list[str] | None) – Additional packages to include. For more information, please see AllenNLP documentation.
Warning
Deprecated in v3.5.0. This feature will be removed in the future. The removal of this feature is currently scheduled for v5.0.0, but this schedule is subject to change. See https://github.com/optuna/optuna/releases/tag/v3.5.0.
Methods
run
()Train a model using AllenNLP.