InputEncoder ¶
Bases: Module
Base class for input encoders.
All input encoders should subclass this class and implement the forward
method.
forward ¶
Encode the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
The input tensor to encode. |
required |
single_eval_pos |
int
|
The position to use for single evaluation. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The encoded tensor. |
SequentialEncoder ¶
Bases: Sequential
, InputEncoder
An encoder that applies a sequence of encoder steps.
SequentialEncoder allows building an encoder from a sequence of EncoderSteps. The input is passed through each step in the provided order.
__init__ ¶
Initialize the SequentialEncoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
A list of SeqEncStep instances to apply in order. |
()
|
|
output_key |
str
|
The key to use for the output of the encoder in the state dict.
Defaults to "output", i.e. |
'output'
|
**kwargs |
Additional keyword arguments passed to |
{}
|
forward ¶
Apply the sequence of encoder steps to the input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
dict
|
The input state dictionary. If the input is not a dict and the first layer expects one input key, the input tensor is mapped to the key expected by the first layer. |
required |
**kwargs |
Additional keyword arguments passed to each encoder step. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The output of the final encoder step. |
LinearInputEncoderStep ¶
Bases: SeqEncStep
A simple linear input encoder step.
__init__ ¶
__init__(
num_features: int,
emsize: int,
replace_nan_by_zero: bool = False,
bias: bool = True,
in_keys: tuple[str] = ("main"),
out_keys: tuple[str] = ("output"),
)
Initialize the LinearInputEncoderStep.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_features |
int
|
The number of input features. |
required |
emsize |
int
|
The embedding size, i.e. the number of output features. |
required |
replace_nan_by_zero |
bool
|
Whether to replace NaN values in the input by zero. Defaults to False. |
False
|
bias |
bool
|
Whether to use a bias term in the linear layer. Defaults to True. |
True
|
in_keys |
tuple[str]
|
The keys of the input tensors. Defaults to ("main",). |
('main')
|
out_keys |
tuple[str]
|
The keys to assign the output tensors to. Defaults to ("output",). |
('output')
|
forward ¶
Perform the forward pass of the encoder step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
dict
|
The input state dictionary containing the input tensors. |
required |
cache_trainset_representation |
bool
|
Whether to cache the training set representation. Only supported for _fit and _transform (not _forward). |
False
|
**kwargs |
Additional keyword arguments passed to the encoder step. |
{}
|
Returns:
Type | Description |
---|---|
The updated state dictionary with the output tensors assigned to the output keys. |
NanHandlingEncoderStep ¶
Bases: SeqEncStep
Encoder step to handle NaN and infinite values in the input.
__init__ ¶
__init__(
keep_nans: bool = True,
in_keys: tuple[str] = ("main"),
out_keys: tuple[str] = ("main", "nan_indicators"),
)
Initialize the NanHandlingEncoderStep.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep_nans |
bool
|
Whether to keep NaN values as separate indicators. Defaults to True. |
True
|
in_keys |
tuple[str]
|
The keys of the input tensors. Must be a single key. |
('main')
|
out_keys |
tuple[str]
|
The keys to assign the output tensors to. Defaults to ("main", "nan_indicators"). |
('main', 'nan_indicators')
|
forward ¶
Perform the forward pass of the encoder step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
dict
|
The input state dictionary containing the input tensors. |
required |
cache_trainset_representation |
bool
|
Whether to cache the training set representation. Only supported for _fit and _transform (not _forward). |
False
|
**kwargs |
Additional keyword arguments passed to the encoder step. |
{}
|
Returns:
Type | Description |
---|---|
The updated state dictionary with the output tensors assigned to the output keys. |