Datasets:

ArXiv:
bbench-dep-marble / marble /core /base_encoder.py
Archit00's picture
mirror sync @ 2026-05-27T11:23:00Z
884b8f8 verified
# marble/core/base_decoder.py
import torch
from abc import ABCMeta, abstractmethod
from typing import Optional
class BaseEncoder(torch.nn.Module, metaclass=ABCMeta):
"""
Abstract base class for encoders. Subclasses need to implement the forward method to encode raw audio or spectrogram
into a feature representation.
Output shape: [batch, time_steps, feature_dim]
"""
def __init__(self, **kwargs):
super().__init__()
# Optionally initialize layers or parameters based on kwargs
@abstractmethod
def forward(self, input_tensor: torch.Tensor, input_len: Optional[torch.Tensor] = None) -> torch.Tensor:
"""
Forward method to map the input (audio, spectrogram, or mel-spectrogram) to high-dimensional features.
Args:
input_tensor: Tensor of shape [batch, time] for audio, or [batch, time_steps, feature_dim] for spectrograms
input_len: Optional tensor of sequence lengths for each input in the batch.
Returns:
Tensor of shape [batch, time_steps, feature_dim]
"""
raise NotImplementedError("Subclasses must implement this method")