torch_frame.nn.encoder.StypeEncoder — pytorch-frame documentation (original) (raw)

pytorch-frame

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:

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