File size: 1,036 Bytes
d7013e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
from abc import ABC, abstractmethod
from typing import Any, Self

import torch


class IModel(ABC):
    """Interface for the trainable model."""

    @abstractmethod
    def build(self) -> Self:
        """Build / initialize the model architecture."""
        ...

    @abstractmethod
    def train(self, train_loader: Any, val_loader: Any, epochs: int) -> Self:
        """Train the model."""
        ...

    @abstractmethod
    def test(self, test_loader: Any) -> dict:
        """Evaluate on test set. Returns metrics dict."""
        ...

    @abstractmethod
    def fit(self, dataset: Any) -> Self:
        """Convenience: preprocess + train + validate in one call."""
        ...

    @abstractmethod
    def predict(self, audio: torch.Tensor) -> str:
        """Transcribe audio tensor to text."""
        ...

    @abstractmethod
    def save(self, path: str) -> Self:
        """Save model checkpoint."""
        ...

    @abstractmethod
    def load(self, path: str) -> Self:
        """Load model checkpoint."""
        ...