ml_grid.model_classes.tabtransformerClassifier

Classes

TabTransformerClassifier

Initializes the TabTransformerClassifier.

Module Contents

class ml_grid.model_classes.tabtransformerClassifier.TabTransformerClassifier(categories: Tuple[int, Ellipsis], num_continuous: int, dim: int = 32, dim_out: int = 1, depth: int = 6, heads: int = 8, attn_dropout: float = 0.1, ff_dropout: float = 0.1, mlp_hidden_mults: Tuple[int, Ellipsis] = (4, 2), mlp_act: torch.nn.Module | None = None, continuous_mean_std: torch.Tensor | None = None)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.ClassifierMixin

Initializes the TabTransformerClassifier.

Parameters:
  • categories (Tuple[int, ...]) – A tuple containing the number of unique categories for each categorical feature.

  • num_continuous (int) – The number of continuous features.

  • dim (int) – The dimension of embeddings.

  • dim_out (int) – The output dimension of the model.

  • depth (int) – The number of transformer layers.

  • heads (int) – The number of attention heads.

  • attn_dropout (float) – Dropout rate for attention layers.

  • ff_dropout (float) – Dropout rate for the feed-forward network.

  • mlp_hidden_mults (Tuple[int, ...]) – A tuple defining the multipliers for the hidden layers of the MLP.

  • mlp_act (Optional[nn.Module]) – The activation function for the MLP. Defaults to nn.ReLU().

  • continuous_mean_std (Optional[torch.Tensor]) – A tensor of shape (num_continuous, 2) for normalizing continuous features. Defaults to None.

categories[source]
num_continuous[source]
dim = 32[source]
dim_out = 1[source]
depth = 6[source]
heads = 8[source]
attn_dropout = 0.1[source]
ff_dropout = 0.1[source]
mlp_hidden_mults = (4, 2)[source]
mlp_act = None[source]
continuous_mean_std = None[source]
model[source]
fit(X: Any, y: Any) TabTransformerClassifier[source]

A no-op fit method to comply with the scikit-learn API.

Parameters:
  • X (Any) – Ignored.

  • y (Any) – Ignored.

Returns:

The instance itself.

Return type:

TabTransformerClassifier

predict_proba(X: Tuple[torch.Tensor, torch.Tensor]) numpy.ndarray[source]

Predicts class probabilities for samples in X.

Parameters:

X (Tuple[torch.Tensor, torch.Tensor]) – A tuple containing the categorical features tensor and the continuous features tensor.

Returns:

The predicted class probabilities.

Return type:

np.ndarray

predict(X: Tuple[torch.Tensor, torch.Tensor]) numpy.ndarray[source]

Predicts class labels for samples in X.

Parameters:

X (Tuple[torch.Tensor, torch.Tensor]) – A tuple containing the categorical features tensor and the continuous features tensor.

Returns:

The predicted class labels (0 or 1).

Return type:

np.ndarray