vmfstream.projection
From sentence embeddings to points on the unit sphere.
Classes
| Name | Description |
|---|---|
Projection | Centre, keep the leading principal directions, and scale to unit length. |
Projectionclass#
class Projection(dim: int = 256)Centre, keep the leading principal directions, and scale to unit length.
Sentence embeddings share a large common component that would put every text on the same side of the sphere; removing the mean of a reference sample takes it away. The projection is fitted once, by principal components, on data that is not the stream to be read.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
dim | int | 256 | Number of principal directions kept, the dimension d of the sphere. |
Attributes
componentsattributeinstance attribute#
components: np.ndarray | None = Nonedimattributeinstance attribute#
dim = dimexplainedattributeinstance attribute#
explained: np.ndarray | None = Nonemeanattributeinstance attribute#
mean: np.ndarray | None = Nonefitmethod#
def fit(embeddings: np.ndarray) -> ProjectionFit the mean and the dim leading principal directions of a sample.
Parameters
| Name | Type | Description |
|---|---|---|
embeddings | np.ndarray | Reference sample [n, D], for instance a development stream. |
loadmethodclassmethod#
def load(path: str | Path) -> Projectionsavemethod#
def save(path: str | Path) -> Nonetransformmethod#
def transform(embeddings: np.ndarray) -> np.ndarrayProject embeddings [n, D] (or one [D]) to unit vectors [n, d] (or [d]).