vertebrae.extractors.huggingface_text

Optional Hugging Face text embedding extractor.

Classes

HFTextExtractor

Hugging Face text backbone extractor with explicit pooling.

Module Contents

class vertebrae.extractors.huggingface_text.HFTextExtractor(name, model_id, pooling='mean', hidden_layer=None, outputs=None, structured_outputs=None, batch_size=32, max_length=512, device=None, revision=None, trust_remote_code=False, tokenizer_kwargs=None, model_kwargs=None, checkpoint_paths=None, cache_identity=None)[source]

Hugging Face text backbone extractor with explicit pooling.

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

  • model_id (str) – Hugging Face model identifier or local path.

  • pooling (str) – Pooling mode: “mean”, “cls”, or “last_token”.

  • hidden_layer (Optional[int]) – Optional hidden-state layer index to pool from. Defaults to the model’s final output.

  • batch_size (int) – Number of texts encoded per batch.

  • max_length (int) – Tokenizer truncation length.

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

  • revision (Optional[str]) – Optional model revision.

  • trust_remote_code (bool) – Whether to allow remote model code.

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

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

  • outputs (Optional[List[Dict[str, Any]]])

  • structured_outputs (Optional[List[Dict[str, Any]]])

  • checkpoint_paths (Optional[List[str]])

  • cache_identity (Optional[str])

fit(X, y=None)[source]

No-op fit for frozen Hugging Face text models.

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

  • y (Any) – Optional labels.

Returns:

This extractor.

Return type:

HFTextExtractor

transform(X)[source]

Encode text inputs into dense embeddings.

Parameters:

X (Any) – Sequence of strings.

Returns:

Dense float32 embedding matrix.

Raises:
  • ImportError – If optional Hugging Face dependencies are missing.

  • ValueError – If inputs are 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 float32 embedding matrix.

Return type:

numpy.ndarray

recipe()[source]

Return a serializable Hugging Face text recipe.

Returns:

JSON-compatible recipe dictionary.

Return type:

Dict[str, Any]

get_resource_profile_adapter()[source]

Return Torch profiling hooks without forcing model loading.

Return type:

Any