TabICL is a transformer-based architecture for in-context learning on tabular data. This class is the underlying raw torch module.
Usage
TabICLv2(
config,
max_classes = 10L,
col_affine = FALSE,
col_feature_group = "same",
col_feature_group_size = 3L,
col_target_aware = TRUE,
col_ssmax = "qassmax-mlp-elementwise",
row_rope_base = 1e+05,
row_rope_interleaved = FALSE,
icl_ssmax = "qassmax-mlp-elementwise",
ff_factor = 2L,
dropout = 0,
activation = "gelu",
norm_first = TRUE,
bias_free_ln = FALSE,
recompute = FALSE
)Arguments
- config
A
tab_icl2_configobject providingembed_dimInteger, default128L. Model dimension.num_quantilesInteger, default999L. Number of quantiles for regression.col_n_blockInteger, default3L.col_n_headInteger, default8L.col_n_clsInteger, default128L.col_feature_group_sizeInteger, default3L.row_n_blockInteger, default3L.row_n_headInteger, default8L.row_n_clsInteger, default4L.icl_n_blockInteger, default12L.icl_n_headInteger, default8L.
- max_classes
Integer, default
10L. 0 for regression.- col_affine
Logical, default
FALSE.- col_feature_group
Character, default
"same".- col_target_aware
Logical, default
TRUE.- col_ssmax
Character, default
"qassmax-mlp-elementwise".- row_rope_base
Float, default
100000.- row_rope_interleaved
Logical, default
FALSE.- icl_ssmax
Character, default
"qassmax-mlp-elementwise".- ff_factor
Integer, default
2L.- dropout
Float, default
0.- activation
Character, default
"gelu".- norm_first
Logical, default
TRUE.- bias_free_ln
Logical, default
FALSE.- recompute
Logical, default
FALSE.
Details
TabICL: A Tabular In-Context Learning Foundation Model
TabICL is a transformer-based architecture for in-context learning on tabular data to make predictions without fine-tuning. It processes tabular data through three sequential stages:
Column-wise embedding creates distribution-aware embeddings.
Row-wise interaction captures interactions between features within each row.
Dataset-wise in-context learning to learn patterns from labeled examples and make predictions.
This class is the underlying raw torch module for TabICL. It is not intended to be
used directly. Instead, use the classes from the top-level tabicl package
such as TabICLClassifier or TabICLRegressor that wrap this class to
include the necessary preprocessing of input features and postprocessing of
predictions.
Methods
Usage
model <- TabICL$new(max_classes = 10L)
model$forward(X, y_train)
model$predict_stats(X, y_train, output_type = "mean")
model$forward_with_cache(X_train, y_train, store_cache = TRUE)
model$predict_stats_with_cache(X_test = X_test, use_cache = TRUE)
model$has_cache()
model$clear_cache()forward(X, y_train, d, embed_with_test, feature_shuffles,
return_logits, softmax_temperature, inference_config)
Column-wise embedding -> row-wise interaction -> dataset-wise in-context learning.
Dispatches to train_forward() in training mode and inference_forward()
in evaluation mode.
X: Input tensor of shape(B, TT, H)where B is the number of tables, TT is the number of samples (rows), and H is the number of features (columns). The firsttrain_sizepositions contain training samples, and the remaining positions contain test samples.y_train: Training labels of shape(B, train_size).d: Optional tensor. The number of features per dataset. Used only in training mode.embed_with_test: Logical, defaultFALSE. IfTRUE, allow training samples to attend to test samples during embedding.feature_shuffles: Optional list of integer vectors. Feature shuffle patterns for each table in the batch. Used only in inference mode.return_logits: Logical, defaultTRUE. IfTRUE, return raw logits instead of probabilities. Used only in inference mode.softmax_temperature: Float, default0.9. Temperature for the softmax function. Used only in inference mode.inference_config: Aninference_configobject. Used only in inference mode.
Returns a tensor. For training mode: predictions of shape (B, test_size, out_dim).
For inference mode: logits or probabilities of shape (B, test_size, num_classes) for
classification, or predictions of shape (B, test_size, num_quantiles) for regression.
predict_stats(X, y_train, output_type, alphas,
embed_with_test, inference_config)
Compute summary statistics from predicted quantiles. Only applicable for regression
tasks (max_classes = 0).
output_type: Character string or character vector. Supported values:"mean","variance","median","quantiles","raw_quantiles". If a vector, returns a named list.alphas: Optional numeric vector. Probability levels for quantile output. Default:c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9).
Returns a tensor (single output type) or a named list of tensors (multiple output types).
Output shapes: "mean", "variance", "median" return
(B, test_size); "quantiles" returns (B, test_size, len(alphas));
"raw_quantiles" returns (B, test_size, num_quantiles).
forward_with_cache(X_train, y_train, X_test, return_logits,
softmax_temperature, use_cache, store_cache, cache, cache_mode,
inference_config)
Forward pass with caching support for efficient inference. Two caching modes are supported:
"kv": Cache KV projections from both column embedding and ICL transformer layers. Fastest inference but uses more memory."repr": Cache column embedding KV projections and row interaction outputs. Uses approximately 24x less memory for the ICL part, at the cost of re-running the ICL transformer.
Exactly one of use_cache or store_cache must be TRUE. When
store_cache = TRUE, requires X_train and y_train. When
use_cache = TRUE, requires X_test and a populated cache.
X_train: Optional tensor of shape(B, train_size, H). Required whenstore_cache = TRUE.y_train: Optional tensor of shape(B, train_size). Required whenstore_cache = TRUE.X_test: Optional tensor of shape(B, test_size, H). Required whenuse_cache = TRUE.return_logits: Logical, defaultTRUE.softmax_temperature: Float, default0.9.use_cache: Logical, defaultFALSE.store_cache: Logical, defaultTRUE.cache: OptionalTabICLCache. If provided, equivalent to settinguse_cache = TRUEandstore_cache = FALSE.cache_mode: Character string, default"kv". Caching strategy.inference_config: Optionalinference_config.
Returns predictions of shape (B, test_size, out_dim), or NULL if
store_cache = TRUE and X_test is not provided.
predict_stats_with_cache(X_train, y_train, X_test, output_type,
alphas, use_cache, store_cache, cache, cache_mode, inference_config)
Compute summary statistics from predicted quantiles with KV caching. Only applicable
for regression tasks (max_classes = 0). Parameters and return value are the same
as predict_stats(), with additional caching parameters matching
forward_with_cache(). Returns NULL if store_cache = TRUE and
X_test is not provided.