Skip to content

Getting Started#

Getting started with NePS involves a straightforward yet powerful process, centering around its three main components. This approach ensures flexibility and efficiency in evaluating different architecture and hyperparameter configurations for your problem.

NePS requires Python 3.8 or higher. You can install it via pip or from source.

pip install neural-pipeline-search

The 3 Main Components#

  1. Execute with neps.run(): Optimize your run_pipeline= over the pipeline_space= using this function. For a thorough overview of the arguments and their explanations, check out the detailed documentation.

  2. Define a run_pipeline= Function: This function is essential for evaluating different configurations. You'll implement the specific logic for your problem within this function. For detailed instructions on initializing and effectively using run_pipeline=, refer to the guide.

  3. Establish a pipeline_space=: Your search space for defining parameters. You can structure this in various formats, including dictionaries, YAML, or ConfigSpace. The guide offers insights into defining and configuring your search space.

By following these steps and utilizing the extensive resources provided in the guides, you can tailor NePS to meet your specific requirements, ensuring a streamlined and effective optimization process.

Basic Usage#

In code, the usage pattern can look like this:

import neps
import logging


def run_pipeline(  # (1)!
        hyperparameter_a: float,
        hyperparameter_b: int,
        architecture_parameter: str,
) -> dict:
    # insert here your own model
    model = MyModel(architecture_parameter)

    # insert here your training/evaluation pipeline
    validation_error, training_error = train_and_eval(
        model, hyperparameter_a, hyperparameter_b
    )

    return {
        "loss": validation_error,  # ! (2)
        "info_dict": {
            "training_error": training_error
            # + Other metrics
        },
    }


pipeline_space = {  # (3)!
    "hyperparameter_b": neps.Integer(1, 42, is_fidelity=True),  # ! (4)
    "hyperparameter_a": neps.Float(1e-3, 1e-1, log=True)  # ! (5)
    "architecture_parameter": neps.Categorical(["option_a", "option_b", "option_c"]),
}

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    neps.run(
        run_pipeline=run_pipeline,
        pipeline_space=pipeline_space,
        root_directory="path/to/save/results",  # Replace with the actual path.
        max_evaluations_total=100,
        searcher="hyperband"  # Optional specifies the search strategy,
        # otherwise NePs decides based on your data.
    )
  1. Define a function that accepts hyperparameters and computes the validation error.
  2. Return a dictionary with the objective to minimize and any additional information.
  3. Define a search space of the parameters of interest; ensure that the names are consistent with those defined in the run_pipeline function.
  4. Use is_fidelity=True for a multi-fidelity approach.
  5. Use log=True for a log-spaced hyperparameter.

Tip

Please visit the full reference for a more comprehensive walkthrough of defining budgets, optimizers, YAML configuration, parallelism, and more.

Examples#

Discover the features of NePS through these practical examples: