Shortcuts

Tuner

This section highlight the key point when using the built-in grid search algorithm.

The tuner class is used to tweak (or tune) hyper parameters, or PyTorch’s module.

from sentarget import Tuner


# Hyper parameters to tune
params = {'epochs': [150],                              # Number of epochs to try
          'lr': np.arange(0.001, 0.3, 0.01).tolist(),   # Make sure to convert it to a list (for saving after)
          'optimizer': ['torch.metrics.Adam'],
          'criterion': ['torch.nn.CrossEntropyLoss']}

# Parameters affecting the models
params_model = {'hidden_dim': [100, 150, 200, 250],      # Model attribute
                'n_layers': [1, 2, 3],                   # Model attribute
                'bidirectional': [False, True],          # Model attribute
                'LSTM.dropout': [0.2, 0.3, 0.4, 0.6],    # Modify all LSTM dropout
                # some other inner parameters, depending on your models...
                }

# Default parameters that will be used to initialize the criterion and optimizer
params_loss = {'ignore_index': PAD_IDX}
params_optim = {}

tuner = Tuner(params, params_loss=params_loss, params_optim=params_optim)

# Run the grid Search
tuner.fit([sentarget.nn.models.gru.BiGRU, sentarget.nn.models.lstm.BiLSTM], train_iterator, eval_iterator)

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Check the GitHub page and contribute to the project

View GitHub