Demonstration for using Optuna with AllenNLP integration.
# create virtual environment
python3 -m venv venv
. venv/bin/activate
# install libraries
pip install -r requirements.txt
# train a model using AllenNLP cli
allennlp train -s result/allennlp config/imdb_baseline.jsonnet
# run hyperparameter optimization
python optuna_train.py
# define-and-run style example
python optuna_train_custom_trainer.py --device 0 --target_metric accuracy --base_serialization_dir result
You can use allennlp-optuna
, an AllenNLP plugin for hyperparameter optimization.
# Installation
pip install allennlp-optuna
# You need to register allennlp-optuna to allennlp using .allennlp_plugins
# It is not required if .allennlp_plugins already exists on your working directory
echo 'allennlp_optuna' >> .allennlp_plugins
# optimization
allennlp tune config/imdb_optuna.jsonnet config/hparams.json --serialization-dir result
Demonstration uses GPU.
If you want to run the scripts in this repository,
please update cuda_device = -1
in allennlp config and optuna_config.
- Japanese: https://medium.com/p/41ad5e8b2d1a
- English: https://medium.com/p/54b4bfecd78b