Skip to content

Embedding Model

Bases: ABC

Use an embedding model to calculate embeddings for use in classification.

Source code in autodistill/core/embedding_model.py
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
@dataclass
class EmbeddingModel(ABC):
    """
    Use an embedding model to calculate embeddings for use in classification.
    """

    ontology: Ontology

    def set_ontology(self, ontology: Ontology):
        """
        Set the ontology for the model.
        """
        self.ontology = ontology

    @abstractmethod
    def embed_image(self, input: Any) -> np.array:
        """
        Calculate an image embedding for an image.
        """
        pass

    @abstractmethod
    def embed_text(self, input: Any) -> np.array:
        """
        Calculate a text embedding for an image.
        """
        pass

embed_image(input) abstractmethod

Calculate an image embedding for an image.

Source code in autodistill/core/embedding_model.py
24
25
26
27
28
29
@abstractmethod
def embed_image(self, input: Any) -> np.array:
    """
    Calculate an image embedding for an image.
    """
    pass

embed_text(input) abstractmethod

Calculate a text embedding for an image.

Source code in autodistill/core/embedding_model.py
31
32
33
34
35
36
@abstractmethod
def embed_text(self, input: Any) -> np.array:
    """
    Calculate a text embedding for an image.
    """
    pass

set_ontology(ontology)

Set the ontology for the model.

Source code in autodistill/core/embedding_model.py
18
19
20
21
22
def set_ontology(self, ontology: Ontology):
    """
    Set the ontology for the model.
    """
    self.ontology = ontology