The DualEncoder is an abstract base class (ABC) that defines the interface for models capable of encoding both vision (images) and text into a shared embedding space. This is useful for multimodal retrieval tasks where images and text need to be compared using similarity metrics.
To implement a custom dual encoder, you must provide implementations for:
encode_vision(file: Path) -> torch.Tensorencode_text(text: str) -> torch.Tensorlogit_scale() -> torch.Tensor
from abc import ABC, abstractmethod
from pathlib import Path
import torch
class DualEncoder(ABC):
@abstractmethod
def encode_vision(self, file: Path) -> torch.Tensor:
pass
@abstractmethod
def encode_text(self, text: str) -> torch.Tensor:
pass
@abstractmethod
def logit_scale(self) -> torch.Tensor:
pass