torch_frame.nn.encoder.StypeEncoder — pytorch-frame documentation (original) (raw)
class StypeEncoder(out_channels: int | None = None, stats_list: list[dict[StatType, Any]] | None = None, stype: stype | None = None, post_module: torch.nn.Module | None = None, na_strategy: NAStrategy | None = None)[source]
Bases: Module
, ABC
Base class for stype encoder. This module transforms tensor of a specific stype, i.e., TensorFrame.feat_dict[stype.xxx] into 3-dimensional column-wise tensor that is input into TableConv
.
Parameters:
- out_channels (int) – The output channel dimensionality
- stats_list (list[_dict[_torch_frame.data.stats.StatType, Any ] ]) – The list of stats for each column within the same stype.
- stype (stype) – The stype of the encoder input.
- post_module (Module , optional) – The post-hoc module applied to the output, such as activation function and normalization. Must preserve the shape of the output. If None, no module will be applied to the output. (default: None)
- na_strategy (NAStrategy, optional) – The strategy for imputing NaN values. If na_strategy is None, then it outputs non-learnable all-zero embedding for
NaN
category. (default: None)
abstract reset_parameters()[source]
Initialize the parameters of post_module.
forward(feat: TensorData, col_names: list[str] | None = None) → Tensor[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
abstract encode_forward(feat: TensorData, col_names: list[str] | None = None) → Tensor[source]
The main forward function. Maps input feat
from TensorFrame (shape [batch_size, num_cols]) into output x
of shape[batch_size, num_cols, out_channels]
.
post_forward(out: Tensor) → Tensor[source]
Post-forward function applied to out
of shape [batch_size, num_cols, channels]. It also returns out
of the same shape.
na_forward(feat: Union[Tensor, MultiNestedTensor, MultiEmbeddingTensor, dict[str, torch_frame.data.multi_nested_tensor.MultiNestedTensor]]) → Union[Tensor, MultiNestedTensor, MultiEmbeddingTensor, dict[str, torch_frame.data.multi_nested_tensor.MultiNestedTensor]][source]
Replace NaN values in input TensorData
givenna_strategy
.
Parameters:
feat (TensorData) – Input TensorData
.
Returns:
Output TensorData
with NaNs replaced given
na_strategy
.
Return type:
TensorData