PyTorchTabularModelsZoo Module¶
Collection of PyTorch tabular models and helper utilities for tabular datasets.
- class HMB.PyTorchTabularModelsZoo.MLPModel(inputSize, numClasses, hiddenSizes=None, dropout=0.2)[source]¶
Bases:
ModuleMulti-layer perceptron for tabular classification.
Builds a stack of Linear -> BatchNorm -> ReLU -> Dropout blocks followed by a final linear classification layer.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.TCNModel(inputSize, numClasses, channels=None, kernelSize=3, dropout=0.2)[source]¶
Bases:
ModuleTemporal convolutional network style model for tabular data treated as a 1D sequence of features.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.TabTransformerModel(inputSize, numClasses, embedDim=64, numHeads=4, numLayers=2)[source]¶
Bases:
ModuleTransformer-based model that embeds each numeric feature as a token and applies a Transformer encoder across features for classification.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.FTTransformerModel(inputSize, numClasses, embedDim=64, numHeads=4, numLayers=2, dropout=0.1)[source]¶
Bases:
ModuleLightweight FT-Transformer style model embedding each feature as a token.
A CLS token is prepended and the classification is performed from the CLS token embedding after Transformer encoding.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.GANDALFModel(inputSize, numClasses, hidden=128, gate_hidden=64)[source]¶
Bases:
ModuleGANDALF-inspired gated feature learning model.
The model applies a per-feature gating network followed by a shared encoder and a classification head.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.HybridCNNTransformerModel(inputSize, numClasses, cnnChannels=None, kernelSize=3, embedDim=128, numHeads=4, numLayers=2, dropout=0.2)[source]¶
Bases:
ModuleHybrid CNN + Transformer model for tabular inputs treated as feature sequences.
The convolutional front-end extracts local feature patterns and the Transformer provides global context before classification.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.VAEAnomalyDetector(inputSize, latentDim=32, hiddenSizes=None)[source]¶
Bases:
ModuleVariational autoencoder for anomaly detection on tabular features.
Trains as an autoencoder and uses reconstruction error as an anomaly score.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- reparameterize(mu, logvar)[source]¶
Reparameterization trick to sample z ~ N(mu, sigma^2) from parameters.
- Parameters:
mu (torch.Tensor) – Latent mean tensor.
logvar (torch.Tensor) – Latent log-variance tensor.
- Returns:
Sampled latent tensor.
- Return type:
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
tuple[Tensor,Tensor,Tensor]Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- reconstruction_error(x)[source]¶
Compute per-sample reconstruction error used for anomaly scoring.
- Parameters:
x (torch.Tensor) – Input batch of shape (batch, inputSize).
- Returns:
Per-sample MSE reconstruction error of shape (batch,).
- Return type:
- class HMB.PyTorchTabularModelsZoo.VAEClassifier(inputSize, numClasses, latentDim=32)[source]¶
Bases:
ModuleHybrid model combining a VAE for feature learning with a classifier head. The VAE learns a latent representation of the input features, and the classifier operates on the VAE’s reconstruction to perform classification.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.ContrastiveEncoder(inputSize, embDim=128, projDim=64, hiddenSizes=None)[source]¶
Bases:
ModuleLightweight encoder + projection head for contrastive pretraining (SimCLR style). Outputs normalized embeddings and a projection vector suitable for contrastive loss.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
tuple[Tensor,Tensor]Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.ContrastiveClassifier(inputSize, numClasses, embDim=128)[source]¶
Bases:
ModuleSimple classifier that uses the ContrastiveEncoder for feature extraction. The encoder can be pretrained with a contrastive loss and then fine-tuned for classification.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.GNNModel(inputSize, numClasses, hiddenDim=128, numLayers=2, dropout=0.2, useResidual=True)[source]¶
Bases:
ModuleGraph Neural Network for tabular data with graph structure. Supports both adjacency matrix and edge index formats. Implements basic message passing with optional residual connections. For production use with complex graphs, consider PyTorch Geometric or DGL.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- Parameters:
- forward(x, adj=None, edgeIndex=None, edgeWeight=None, batch=None)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.GraphConvLayer(inChannels, outChannels, dropout=0.2)[source]¶
Bases:
ModuleSingle graph convolution layer with optional edge weights.
Implements: h_i’ = W_1 * h_i + W_2 * sum_{j in N(i)} (edge_weight_ij * h_j).
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x, adj=None, edgeIndex=None, edgeWeight=None)[source]¶
Forward pass performing message passing with optional adjacency formats.
- Parameters:
x (torch.Tensor) – Node feature matrix of shape (numNodes, inChannels).
adj (torch.Tensor or None) – Dense adjacency matrix of shape (numNodes, numNodes).
edgeIndex (torch.Tensor or None) – Edge index tensor of shape (2, numEdges).
edgeWeight (torch.Tensor or None) – Optional edge weights of shape (numEdges,) or compatible.
- Returns:
Updated node embeddings of shape (numNodes, outChannels).
- Return type:
- class HMB.PyTorchTabularModelsZoo.ResidualBlock(inFeatures, outFeatures, dropout=0.2)[source]¶
Bases:
ModuleResidual block for tabular data with skip connection.
Implements: output = activation(norm(linear(activation(norm(linear(input)))))) + input
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.ResNetTabularModel(inputSize, numClasses, blockChannels=None, dropout=0.2)[source]¶
Bases:
ModuleResidual network for tabular data with skip connections.
Implements residual blocks: y = F(x) + x to enable deeper networks without vanishing gradients. Suitable for high-dimensional tabular data.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.AutoIntAttentionLayer(embedDim, numHeads, dropout=0.1)[source]¶
Bases:
ModuleMulti-head self-attention layer for feature interaction modeling.
Implements attention over feature tokens to capture explicit high-order feature interactions at different subspaces.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.AutoIntModel(inputSize, numClasses, embedDim=32, numAttentionLayers=3, numHeads=2, dropout=0.1)[source]¶
Bases:
ModuleAttentional Interaction Network for explicit feature crossing.
Uses multi-head self-attention to model feature interactions at different representation subspaces, followed by classification.
- Parameters:
inputSize (int) – Number of input features.
numClasses (int) – Number of output classes.
embedDim (int) – Embedding dimension per feature token.
numAttentionLayers (int) – Number of attention interaction layers.
numHeads (int) – Number of attention heads per layer.
dropout (float) – Dropout probability in attention layers.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.SAINTIntersampleAttention(embedDim, numHeads, dropout=0.1)[source]¶
Bases:
ModuleIntersample attention module for batch-level feature refinement.
Computes attention across samples in a batch to enable few-shot generalization and context-aware representations.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.SAINTModel(inputSize, numClasses, embedDim=32, numHeads=2, numFeatureLayers=2, numIntersampleLayers=1, useIntersampleAttention=True, dropout=0.1)[source]¶
Bases:
ModuleSAINT: Self-Attention and Intersample Attention Transformer.
Combines intra-sample feature attention with inter-sample attention across the batch for few-shot generalization.
- Parameters:
inputSize (int) – Number of input features.
numClasses (int) – Number of output classes.
embedDim (int) – Token embedding dimension.
numHeads (int) – Number of attention heads.
numFeatureLayers (int) – Number of intra-sample attention layers.
numIntersampleLayers (int) – Number of inter-sample attention layers.
useIntersampleAttention (bool) – Enable batch-level attention.
dropout (float) – Dropout probability in attention layers.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.ShapeFunctionNet(hiddenSize, outputDim=1, dropout=0.1)[source]¶
Bases:
ModuleSmall subnetwork that processes a single feature for additive modeling.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.NeuralAdditiveModel(inputSize, numClasses, shapeFunctionHidden=32, dropout=0.1)[source]¶
Bases:
ModuleInterpretable neural additive model for tabular data.
Each feature is processed by an independent subnetwork; outputs are summed for final prediction enabling interpretability.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.CrossLayer(inputSize)[source]¶
Bases:
ModuleCross network layer for explicit polynomial feature crossing.
Implements: x_{l+1} = x_0 * (x_l^T * w_l + b_l) + x_l where x_0 is the original input and w_l, b_l are learned parameters.
- Parameters:
inputSize (int) – Number of input features (must match original input).
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x0, xl)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class HMB.PyTorchTabularModelsZoo.DeepCrossNetwork(inputSize, numClasses, crossLayers=3, deepHiddenSizes=None, dropout=0.2)[source]¶
Bases:
ModuleDeep Cross Network for explicit low- and high-order feature crossing.
Combines a cross network (polynomial feature interactions) with a deep network (non-linear transformations) in parallel.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.