I use .jsonnet
file as a template for AllenNLP model config
I search through hyperparameter space with Optuna package and evaluate that template on each step with suggested hyperparameters as extVar
s. Then I train a model and save it to an archive.
The problem is, apart from hyperparameters, some parts of my .jsonnet
config include file paths relative to a extVar
variable(a dir inside my package). Those file paths get rendered, too and in the end I have absolute paths in my model.tar.gz
, which is wrong, as they may even not exist on a machine loading that archive
.jsonnet:
{
...
"train_data_path": std.extVar("TRAIN_DATA_PATH"),
"validation_data_path": std.extVar("VALID_DATA_PATH"),
...
}
rendered.json :
{
...
"train_data_path": "/home/user/datasets/train.json",
"validation_data_path": "/home/user/datasets/valid.json",
...
}
So I would like to save the original path expression instead and supply an environment variable on loading, but I haven`t found a way to serialize a .jsonnet file in python, only .json