class documentation

Mixin for Model classes that can generate embeddings for their predictions.

This mixin allows for the possibility that only some instances of a class are capable of generating embeddings, per the value of the has_embeddings property.

Method embed Generates an embedding for the given data.
Method embed_all Generates embeddings for the given iterable of data.
Method get_embeddings Returns the embeddings generated by the last forward pass of the model.
Property has_embeddings Whether this instance has embeddings.
def embed(self, arg): (source)

Generates an embedding for the given data.

Subclasses can override this method to increase efficiency, but, by default, this method simply calls predict and then returns get_embeddings.

Parameters
argthe data. See predict for details
Returns
a numpy array containing the embedding
def embed_all(self, args): (source)

Generates embeddings for the given iterable of data.

Subclasses can override this method to increase efficiency, but, by default, this method simply iterates over the data and applies embed to each.

Parameters
argsan iterable of data. See predict_all for details
Returns
a numpy array containing the embeddings stacked along axis 0
def get_embeddings(self): (source)

Returns the embeddings generated by the last forward pass of the model.

By convention, this method should always return an array whose first axis represents batch size (which will always be 1 when predict was last used).

Returns
a numpy array containing the embedding(s)