espnet2.enh.extractor.abs_extractor.AbsExtractor
espnet2.enh.extractor.abs_extractor.AbsExtractor
class espnet2.enh.extractor.abs_extractor.AbsExtractor(*args, **kwargs)
Bases: Module
, ABC
Abstract base class for feature extractors in the ESPnet2 framework.
This class defines the interface for all feature extractors that are implemented in the ESPnet2 speech enhancement toolkit. Subclasses must provide a concrete implementation of the forward method, which processes input tensors and returns extracted features along with additional metadata.
None
- Parameters:
- input (torch.Tensor) – The input tensor containing the features to be processed.
- ilens (torch.Tensor) – A tensor containing the lengths of the input sequences.
- input_aux (torch.Tensor) – An auxiliary input tensor, if needed for processing.
- ilens_aux (torch.Tensor) – A tensor containing the lengths of the auxiliary input sequences.
- suffix_tag (str , optional) – An optional suffix tag to be used in the processing, default is an empty string.
- additional (Optional *[*Dict ] , optional) – A dictionary of additional parameters that can be passed to the extractor, default is None.
- Returns: A tuple : containing:
- A tuple of torch.Tensor objects representing the extracted
features.
- A tensor containing additional output, such as attention weights.
- An OrderedDict with additional metadata about the extraction process.
- Return type: Tuple[Tuple[torch.Tensor], torch.Tensor, OrderedDict]
- Raises:
- NotImplementedError – If the forward method is not implemented in
- a subclass. –
####### Examples
Example of a subclass implementing the forward method
class MyExtractor(AbsExtractor):
def forward(self, input, ilens, input_aux, ilens_aux, : > suffix_tag=””, additional=None): <br/>
Implementation of feature extraction
pass
NOTE
This is an abstract class and cannot be instantiated directly.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
abstract forward(input: Tensor, ilens: Tensor, input_aux: Tensor, ilens_aux: Tensor, suffix_tag: str = '', additional: Dict | None = None) → Tuple[Tuple[Tensor], Tensor, OrderedDict]
Computes the forward pass of the extractor model.
This method processes the input tensors and produces the desired output tensors along with an ordered dictionary containing additional information relevant to the model’s operation.
- Parameters:
- input (torch.Tensor) – The primary input tensor to the model.
- ilens (torch.Tensor) – A tensor containing the lengths of the input sequences.
- input_aux (torch.Tensor) – An auxiliary input tensor for additional data.
- ilens_aux (torch.Tensor) – A tensor containing the lengths of the auxiliary input sequences.
- suffix_tag (str , optional) – An optional suffix tag for naming or categorization purposes. Defaults to an empty string.
- additional (Optional *[*Dict ] , optional) – A dictionary for any additional parameters or settings needed for the forward computation. Defaults to None.
- Returns: A tuple containing: : - A tuple of output tensors generated by the model.
- A tensor containing the final output features.
- An OrderedDict with additional information about the processing.
- Return type: Tuple[Tuple[torch.Tensor], torch.Tensor, OrderedDict]
- Raises:NotImplementedError – If the method is not overridden in a subclass.
####### Examples
Example usage of the forward method
model = SomeConcreteExtractor() # Some subclass of AbsExtractor input_tensor = torch.randn(10, 20) # Example input tensor ilens_tensor = torch.tensor([20] * 10) # Lengths of the input sequences input_aux_tensor = torch.randn(10, 15) # Example auxiliary input tensor ilens_aux_tensor = torch.tensor([15] * 10) # Lengths of the auxiliary inputs suffix = “example” additional_params = dict(param1=”value1”)
output, final_features, info = model.forward( : input_tensor, ilens_tensor, input_aux_tensor, ilens_aux_tensor, suffix, additional_params
)