torch_frame.nn.encoder.StypeEncoder
- class StypeEncoder(out_channels: Optional[int] = None, stats_list: Optional[list[dict[torch_frame.data.stats.StatType, Any]]] = None, stype: Optional[stype] = None, post_module: Optional[Module] = None, na_strategy: Optional[NAStrategy] = None)[source]
Bases:
Module,ABCBase 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
NaNcategory. (default:None)
- forward(feat: torch.Tensor | torch_frame.data.multi_nested_tensor.MultiNestedTensor | torch_frame.data.multi_embedding_tensor.MultiEmbeddingTensor | dict[str, torch_frame.data.multi_nested_tensor.MultiNestedTensor], col_names: Optional[list[str]] = 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- abstract encode_forward(feat: torch.Tensor | torch_frame.data.multi_nested_tensor.MultiNestedTensor | torch_frame.data.multi_embedding_tensor.MultiEmbeddingTensor | dict[str, torch_frame.data.multi_nested_tensor.MultiNestedTensor], col_names: Optional[list[str]] = None) Tensor[source]
The main forward function. Maps input
featfrom TensorFrame (shape [batch_size, num_cols]) into outputxof shape[batch_size, num_cols, out_channels].
- post_forward(out: Tensor) Tensor[source]
Post-forward function applied to
outof shape [batch_size, num_cols, channels]. It also returnsoutof the same shape.
- na_forward(feat: torch.Tensor | torch_frame.data.multi_nested_tensor.MultiNestedTensor | torch_frame.data.multi_embedding_tensor.MultiEmbeddingTensor | dict[str, torch_frame.data.multi_nested_tensor.MultiNestedTensor]) torch.Tensor | torch_frame.data.multi_nested_tensor.MultiNestedTensor | torch_frame.data.multi_embedding_tensor.MultiEmbeddingTensor | dict[str, torch_frame.data.multi_nested_tensor.MultiNestedTensor][source]
Replace NaN values in input
TensorDatagivenna_strategy.- Parameters:
feat (TensorData) – Input
TensorData.- Returns:
- Output
TensorDatawith NaNs replaced given na_strategy.
- Output
- Return type:
TensorData