Heads
Configuration Classes¶
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layers |
str
|
Hyphen-separated number of layers and units in the classification/regression head. E.g. 32-64-32. Default is just a mapping from intput dimension to output dimension |
''
|
activation |
str
|
The activation type in the classification head. The default activation in PyTorch like ReLU, TanH, LeakyReLU, etc. https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity |
'ReLU'
|
dropout |
float
|
probability of a classification element to be zeroed. |
0.0
|
use_batch_norm |
bool
|
Flag to include a BatchNorm layer after each Linear Layer+DropOut |
False
|
initialization |
str
|
Initialization scheme for the linear layers. Defaults to |
'kaiming'
|
Source code in src/pytorch_tabular/models/common/heads/config.py
MixtureDensityHead configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_gaussian |
int
|
Number of Gaussian Distributions in the mixture model. Defaults to 1 |
1
|
sigma_bias_flag |
bool
|
Whether to have a bias term in the sigma layer. Defaults to False |
False
|
mu_bias_init |
Optional[List]
|
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 |
None
|
weight_regularization |
Optional[int]
|
Whether to apply L1 or L2 Norm to the MDN layers. Defaults
to L2. Choices are: [ |
2
|
lambda_sigma |
Optional[float]
|
The regularization constant for weight regularization of sigma layer. Defaults to 0.1 |
0.1
|
lambda_pi |
Optional[float]
|
The regularization constant for weight regularization of pi layer. Defaults to 0.1 |
0.1
|
lambda_mu |
Optional[float]
|
The regularization constant for weight regularization of mu layer. Defaults to 0 |
0
|
softmax_temperature |
Optional[float]
|
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 |
1
|
n_samples |
int
|
Number of samples to draw from the posterior to get prediction. Defaults to 100 |
100
|
central_tendency |
str
|
Which measure to use to get the point prediction. Defaults to mean. Choices
are: [ |
'mean'
|
speedup_training |
bool
|
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 |
False
|
log_debug_plot |
bool
|
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 |
False
|
input_dim |
int
|
The input dimensions to the head. This will be automatically filled in while
initializing from the |
None
|
Source code in src/pytorch_tabular/models/common/heads/config.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
Head Classes¶
Bases: Head
Source code in src/pytorch_tabular/models/common/heads/blocks.py
Bases: Module
Source code in src/pytorch_tabular/models/common/heads/blocks.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
gaussian_probability(sigma, mu, target, log=False)
¶
Returns the probability of target
given MoG parameters sigma
and mu
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sigma |
BxGxO
|
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. |
required |
mu |
BxGxO
|
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. |
required |
target |
BxI
|
A batch of target. B is the batch size and I is the number of input dimensions. |
required |
Returns: probabilities (BxG): The probability of each point in the probability of the distribution in the corresponding sigma/mu index.
Source code in src/pytorch_tabular/models/common/heads/blocks.py
sample(pi, sigma, mu)
¶
Draw samples from a MoG.