vertebrae.extractors.sentence_transformers

Optional sentence-transformers extractor.

Classes

SentenceTransformerExtractor

Sentence-transformers embedding extractor.

Module Contents

class vertebrae.extractors.sentence_transformers.SentenceTransformerExtractor(name, model_id, batch_size=64, normalize_embeddings=True, device=None, show_progress_bar=False, model_kwargs=None, encode_kwargs=None, checkpoint_paths=None, revision=None, cache_identity=None)[source]

Sentence-transformers embedding extractor.

Parameters:
  • name (str) – User-facing extractor name.

  • model_id (str) – Sentence-transformers model identifier or local path.

  • batch_size (int) – Batch size passed to model.encode.

  • normalize_embeddings (bool) – Whether sentence-transformers should normalize outputs.

  • device (Optional[str]) – Optional device string.

  • show_progress_bar (bool) – Whether to show sentence-transformers progress output.

  • model_kwargs (Optional[Dict[str, Any]]) – Extra keyword arguments for SentenceTransformer.

  • encode_kwargs (Optional[Dict[str, Any]]) – Extra keyword arguments for model.encode.

  • checkpoint_paths (Optional[Sequence[str]])

  • revision (Optional[str])

  • cache_identity (Optional[str])

fit(X, y=None)[source]

No-op fit for frozen sentence-transformers models.

Parameters:
  • X (Any) – Input text samples.

  • y (Any) – Optional labels.

Returns:

This extractor.

Return type:

SentenceTransformerExtractor

transform(X)[source]

Encode text inputs into dense embeddings.

Parameters:

X (Any) – Sequence of strings.

Returns:

Dense numeric embedding matrix.

Raises:
  • ImportError – If sentence-transformers is not installed.

  • ValueError – If inputs are not strings or output is invalid.

Return type:

numpy.ndarray

fit_transform(X, y=None)[source]

Encode text inputs into dense embeddings.

Parameters:
  • X (Any) – Sequence of strings.

  • y (Any) – Optional labels.

Returns:

Dense numeric embedding matrix.

Return type:

numpy.ndarray

recipe()[source]

Return a serializable sentence-transformers recipe.

Returns:

JSON-compatible recipe dictionary.

Return type:

Dict[str, Any]