jina.optimizers¶

class jina.optimizers.EvaluationCallback(eval_name=None)[source]¶

Bases: object

Callback for storing and calculating evaluation metric.

Parameters

eval_name (Optional[str]) – evaluation name as required by evaluator. Not needed if only 1 evaluator is used

get_fresh_callback()[source]¶

Creates a new callback

get_mean_evaluation()[source]¶

Returns mean evaluation value on the eval_name.

class jina.optimizers.OptunaResultProcessor(study)[source]¶

Bases: object

Result processor for Optuna

Parameters

study (optuna.study.Study) – optuna study object

save_parameters(filepath='config/best_config.yml')[source]¶
Parameters

filepath (str) – path where the best parameter config will be saved

class jina.optimizers.OptunaOptimizer(multi_flow, parameter_yaml, workspace_base_dir='', workspace_env='JINA_WORKSPACE', eval_flow_index=-1)[source]¶

Bases: object

Optimizer which uses Optuna to run flows and choose best parameters.

Parameters
  • multi_flow (MultiFlowRunner) – MultiFlowRunner object which contains the flows to be run.

  • parameter_yaml (str) – yaml container the parameters to be optimized

  • workspace_env (str) – workspace env name as referred in pods and flows yaml

  • eval_flow_index (int) – index of the evaluation flow in the sequence of flows in MultiFlowRunner

optimize_flow(n_trials, sampler='TPESampler', direction='maximize', seed=42, result_processor=<class 'jina.optimizers.OptunaResultProcessor'>, **kwargs)[source]¶
Parameters
  • n_trials (int) – evaluation trials to be run

  • sampler (str) – optuna sampler

  • direction (str) – direction of the optimization from either of maximize or minimize

  • seed (int) – random seed for reproducibility

  • kwargs – extra parameters for optuna sampler