Heads
Configuration Classes
pytorch_tabular.models.common.heads.LinearHeadConfig
dataclass
A model class for Linear Head configuration; serves as a template and documentation. The models take a dictionary as input, but if there are keys which are not present in this model class, it'll throw an exception.
PARAMETER | DESCRIPTION |
---|---|
layers |
Hyphen-separated number of layers and units in the classification/regression head. eg. 32-64-32. Default is just a mapping from intput dimension to output dimension
TYPE:
|
activation |
The activation type in the classification head. The default activaion in PyTorch like ReLU, TanH, LeakyReLU, etc. https://pytorch.org/docs/stable/nn.html#non-linear-activations- weighted-sum-nonlinearity
TYPE:
|
dropout |
probability of an classification element to be zeroed.
TYPE:
|
use_batch_norm |
Flag to include a BatchNorm layer after each Linear Layer+DropOut
TYPE:
|
initialization |
Initialization scheme for the linear layers. Defaults to
TYPE:
|
pytorch_tabular.models.common.heads.MixtureDensityHeadConfig
dataclass
MixtureDensityHead configuration
PARAMETER | DESCRIPTION |
---|---|
num_gaussian |
Number of Gaussian Distributions in the mixture model. Defaults to 1
TYPE:
|
sigma_bias_flag |
Whether to have a bias term in the sigma layer. Defaults to False
TYPE:
|
mu_bias_init |
To initialize the bias parameter of the mu layer to predefined cluster centers. Should be a list with the same length as number of gaussians in the mixture model. It is highly recommended to set the parameter to combat mode collapse. Defaults to None
TYPE:
|
weight_regularization |
Whether to apply L1 or L2 Norm to the MDN layers. Defaults
to L2. Choices are: [
TYPE:
|
lambda_sigma |
The regularization constant for weight regularization of sigma layer. Defaults to 0.1
TYPE:
|
lambda_pi |
The regularization constant for weight regularization of pi layer. Defaults to 0.1
TYPE:
|
lambda_mu |
The regularization constant for weight regularization of mu layer. Defaults to 0
TYPE:
|
softmax_temperature |
The temperature to be used in the gumbel softmax of the mixing coefficients. Values less than one leads to sharper transition between the multiple components. Defaults to 1
TYPE:
|
n_samples |
Number of samples to draw from the posterior to get prediction. Defaults to 100
TYPE:
|
central_tendency |
Which measure to use to get the point prediction. Defaults to mean. Choices
are: [
TYPE:
|
speedup_training |
Turning on this parameter does away with sampling during training which speeds up training, but also doesn't give you visibility on train metrics. Defaults to False
TYPE:
|
log_debug_plot |
Turning on this parameter plots histograms of the mu, sigma, and pi layers in addition to the logits(if log_logits is turned on in experment config). Defaults to False
TYPE:
|
input_dim |
The input dimensions to the head. This will be automatically filled in while
initializing from the
TYPE:
|
Head Classes
pytorch_tabular.models.common.heads.LinearHead(in_units, output_dim, config, **kwargs)
Bases: Head
Source code in src/pytorch_tabular/models/common/heads/blocks.py
pytorch_tabular.models.common.heads.MixtureDensityHead(config, **kwargs)
Bases: nn.Module
Source code in src/pytorch_tabular/models/common/heads/blocks.py
gaussian_probability(sigma, mu, target, log=False)
Returns the probability of target
given MoG parameters sigma
and mu
.
PARAMETER | DESCRIPTION |
---|---|
sigma |
The standard deviation of the Gaussians. B is the batch size, G is the number of Gaussians, and O is the number of dimensions per Gaussian.
TYPE:
|
mu |
The means of the Gaussians. B is the batch size, G is the number of Gaussians, and O is the number of dimensions per Gaussian.
TYPE:
|
target |
A batch of target. B is the batch size and I is the number of input dimensions.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
probabilities
|
The probability of each point in the probability of the distribution in the corresponding sigma/mu index.
TYPE:
|
Source code in src/pytorch_tabular/models/common/heads/blocks.py
sample(pi, sigma, mu)
Draw samples from a MoG.