Datasets:

ArXiv:
File size: 1,210 Bytes
884b8f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# marble/core/base_decoder.py

import torch
from abc import ABCMeta, abstractmethod
from typing import Optional

class BaseDecoder(torch.nn.Module, metaclass=ABCMeta):
    """
    Abstract base class for decoders. Subclasses need to implement the forward method to decode feature representations 
    back to task-specific outputs (e.g., logits for classification, continuous vectors for regression).
    """
    def __init__(self, in_dim: int, out_dim: int, **kwargs):
        super().__init__()
        self.in_dim = in_dim
        self.out_dim = out_dim
        # Optionally initialize layers based on input/output dimensions

    @abstractmethod
    def forward(self, emb: torch.Tensor, emb_len: Optional[torch.Tensor] = None) -> torch.Tensor:
        """
        Forward method to map the embeddings and their lengths to task-specific outputs.

        Args:
            emb: Tensor of shape [batch, time_steps, in_dim]
            emb_len: Optional tensor of sequence lengths for each input in the batch.

        Returns:
            Tensor of shape [batch, time_steps, out_dim] or [batch, out_dim] for task outputs
        """
        raise NotImplementedError("Subclasses must implement this method")