Path4.Mod3.b - Perform Hyperparameter Tuning - Sweep Job Sampling Methods (Sampling) Flashcards

1
Q

Grid Sampling defined
The prerequisite for Grid Sampling

A

Creates a grid of all possible combinations of values in order to try each one. Only applicable when ALL hyperparameter values are discrete.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain Grid Sampling code:

from azure.ai.ml.sweep import Choice

command_job_for_sweep = command_job(
    batch_size=Choice(values=[16, 32, 64]),
    learning_rate=Choice(values=[0.01, 0.1, 1.0]),
)

sweep_job = command_job_for_sweep.sweep(
    sampling_algorithm = "grid",
    ...
)
A

Creates a command_job instance using a Choice of values for batch_size and learning_rate hyperparameters. Then when creating the sweep, the sample_algorithm is set to “grid”. This tells the job to use all possible combinations of each hyperparameter, one per trial.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Grid Sampling - Pros and Cons

A

Pro: Simplest approach, ensures our trained models gets most of its patterns from the dataset
Con: Suffers when data has high dimensional space (the total number of combinations grows exponentially)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Random Sampling defined
- RandomSamplingAlgorithm class, values for rule parameter
- Define Sobol and why it’s useful.

A

Randomly choose values from the search space. Can be discreet or continuous values.
- RandomSamplingAlgorithm accepts a rule value as a string “sobol” or its default “random”
- Sobol: Add a seed to random sampling to make results reproducible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain Random Sampling code

from azure.ai.ml.sweep import Normal, Uniform

command_job_for_sweep = command_job(
    batch_size=Choice(values=[16, 32, 64]),   
    learning_rate=Normal(mu=10, sigma=3),
)

sweep_job = command_job_for_sweep.sweep(
    sampling_algorithm = "random",
    ...
)
A

Creates a command_job instance using a Choice of values (discrete) for batch_size and a Normal (continuous) distribution for learning_rate hyperparameters. Then when creating the sweep, the sample_algorithm is set to “random”. This tells the job to use a random pairing of batch_size with a value from the Normal Distro , one per trial.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain Random Sobol Sampling variation code:

from azure.ai.ml.sweep import RandomParameterSampling

command_job_for_sweep = command_job(
    batch_size=Choice(values=[16, 32, 64]),   
    learning_rate=Normal(mu=10, sigma=3),

sweep_job = command_job_for_sweep.sweep(
    sampling_algorithm = RandomParameterSampling(seed=123, rule="sobol"),
    ...
)
A

Creates a command_job instance using a Choice of values (discrete) for batch_size and a Normal distribution (continuous) for learning_rate hyperparameters. Then when creating the sweep, the sample_algorithm is set to an instance of RandomParameterSampling set to use the “sobol” rule with a seed value. This tells the job to use a random pairing of batch_size + a value starting at the seed value for the Normally Distributed value , one per trial.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Random Sampling - Pros and Cons

A

Pro: Instead of trying all possible combinations from the sample space, it’ll try only a random subset, which allows you to use a mix of Discrete and Continuous values.
Con: Selection is random rather than based on the previous experiments, making it difficult to predict the next set of experiments, and to reproduce results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Bayesian Sampling defined

A

Choose new values based on previous results. Also allows a mix of Discrete and Continuous values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain Bayesian Sampling code:

from azure.ai.ml.sweep import Uniform, Choice

command_job_for_sweep = job(
    batch_size=Choice(values=[16, 32, 64]),    
    learning_rate=Uniform(min_value=0.05, max_value=0.1),
)

sweep_job = command_job_for_sweep.sweep(
    sampling_algorithm = "bayesian",
    ...
)
A

Creates a command_job instance using a Choice of values (discrete) for batch_size and a Uniform (continuous) distribution for learning_rate hyperparameters. Then when creating the sweep, the sample_algorithm is set to “bayesian”. This tells the job to select parameter combinations that will result in improved performance from the previous selection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Bayesian Sampling - Pros and Cons

A

Pro: Improved performance based on previous selections
Con:
- Cannot be used in combination with Early Termination Policy.
- Limited parameter expression methods options: Choice, Uniform, and QUniform

Limited to Uniform/QUniform for simplicity and computational efficiency. Bayesian methods can get complex quickly, and using simple distributions like Uniform/QUniform makes it easier for the algorithm to make smart guesses without taking too much time or computational power.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly