Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/huggingface/sentence-transformers
/ functions
Functions
3,759 in github.com/huggingface/sentence-transformers
⨍
Functions
3,759
◇
Types & classes
446
↳
Endpoints
48
↓ 169 callers
Method
get
(self, key, default=None)
tests/base/modules/test_router.py:101
↓ 123 callers
Method
save_pretrained
Saves a model and its configuration files to a directory, so that it can be loaded again. Args: path (str): Path on disk
sentence_transformers/base/model.py:776
↓ 116 callers
Method
preprocess
(self, inputs, prompt=None, task=None, **kwargs)
tests/base/modules/test_router.py:84
↓ 116 callers
Method
push_to_hub
Uploads all elements of this model to a HuggingFace Hub repository, creating it if it doesn't exist. Args: repo_id (str)
sentence_transformers/base/model.py:918
↓ 78 callers
Method
encode
(self, sentences, **kwargs)
tests/sentence_transformer/evaluation/test_information_retrieval_evaluator.py:49
↓ 67 callers
Method
save
(self, output_path: str, *args, safe_serialization: bool = True, **kwargs)
tests/base/test_model.py:1186
↓ 66 callers
Function
resolve_ids
Build a batched transform that resolves ID columns to their values via a join against lookup datasets. Useful for IR datasets that store query / d
sentence_transformers/util/dataset.py:240
↓ 60 callers
Function
mine_hard_negatives
Add hard negatives to a dataset of (anchor, positive) pairs to create (anchor, positive, negative) triplets or (anchor, positive, negative_1,
sentence_transformers/util/hard_negatives.py:25
↓ 57 callers
Method
encode
( self, inputs: TextInput, prompt_name: str | None = ..., prompt: str | None =
sentence_transformers/sparse_encoder/model.py:504
↓ 53 callers
Function
infer_modality
Infer the modality of a single input sample by inspecting its type/structure. Pure type-based detection, does not require a processor or tokenize
sentence_transformers/base/modality.py:722
↓ 51 callers
Method
parse_inputs
Parse inputs and group by modality. Analyzes a list of inputs to detect their modality (text, image, audio, video, message) and group
sentence_transformers/base/modality.py:341
↓ 50 callers
Method
predict
( self, inputs: Sequence[PairInput] | PairInput, prompt_name: str | None = ...,
sentence_transformers/cross_encoder/model.py:473
↓ 46 callers
Method
encode
( self, inputs: Sequence[SingleInput] | SingleInput, prompt_name: str | None = ...,
sentence_transformers/sentence_transformer/model.py:565
↓ 37 callers
Method
get_embedding_dimension
(self)
tests/sentence_transformer/losses/test_matryoshka.py:87
↓ 37 callers
Method
mean
(self)
sentence_transformers/base/model_card.py:90
↓ 36 callers
Function
is_datasets_available
Returns True if the Huggingface datasets library is available.
sentence_transformers/util/environment.py:107
↓ 35 callers
Function
batch_to_device
Send a PyTorch batch (i.e., a dictionary of string keys to Tensors) to a device (e.g. "cpu", "cuda", "mps"). Args: batch (Dict[str,
sentence_transformers/util/tensor.py:304
↓ 35 callers
Function
maxsim
Computes the MaxSim (late-interaction) score between two collections of multi-vector embeddings. For each query in ``a`` and document in ``b
sentence_transformers/util/similarity.py:376
↓ 33 callers
Function
_make_model_card_data
Create a BaseModelCardData instance with common defaults for testing.
tests/base/test_model_card.py:56
↓ 31 callers
Method
generate_usage_snippet
Generate the Python usage code snippet for the model card. Returns the code block (including \\`\\`\\` delimiters) showing how to use this mo
sentence_transformers/base/model_card.py:1634
↓ 31 callers
Method
get_embedding_dimension
(self)
sentence_transformers/base/modules/dense.py:97
↓ 30 callers
Method
from_pretrained
(cls, *args, **kwargs)
tests/base/modules/test_transformer.py:1522
↓ 29 callers
Method
decode
Decode a sparse embedding into (token, weight) pairs sorted by descending weight. Args: embeddings (torch.Tensor): Spars
sentence_transformers/sparse_encoder/model.py:1444
↓ 28 callers
Method
load
( cls, model_name_or_path: str, subfolder: str = "", token: bool | str | None
tests/base/test_model.py:1190
↓ 27 callers
Method
get_embedding_dimension
(self)
tests/base/modules/test_router.py:1118
↓ 27 callers
Method
save
(self, output_path: str, *args, safe_serialization: bool = True, **kwargs)
tests/base/modules/test_router.py:41
↓ 25 callers
Function
make_collator
Create a BaseDataCollator with a simple preprocess_fn that returns fixed tensors.
tests/base/test_data_collator.py:11
↓ 25 callers
Method
prefix_name_to_metrics
(self, metrics: dict[str, float], name: str)
sentence_transformers/base/evaluation/evaluator.py:48
↓ 24 callers
Function
fullname
Gives a full name (package_name.class_name) for a class / object in Python. Will be used to load the correct classes from JSON files Arg
sentence_transformers/util/misc.py:20
↓ 24 callers
Function
maxsim_pairwise
Computes the pairwise MaxSim (late-interaction) score between each query-document pair. For each ``i``, computes the MaxSim score between ``
sentence_transformers/util/similarity.py:525
↓ 23 callers
Method
encode_document
( self, inputs: SingleInput, prompt_name: str | None = ..., prompt: str | None
sentence_transformers/multi_vector_encoder/model.py:401
↓ 23 callers
Method
encode_query
( self, inputs: SingleInput, prompt_name: str | None = ..., prompt: str | None
sentence_transformers/multi_vector_encoder/model.py:225
↓ 23 callers
Method
get_embedding_dimension
Get the output embedding dimension from the transformer model. Returns: int: The hidden dimension size of the model's embeddings.
sentence_transformers/base/modules/transformer.py:1698
↓ 22 callers
Function
disable_dropout
Disable every dropout, so that gradient-equivalence tests are deterministic. transformers<5 keeps the SDPA attention dropout as a plain float att
tests/sentence_transformer/losses/utils.py:9
↓ 22 callers
Method
pool
( self, embeddings: list[Tensor], *, task: str | None = ..., attention
sentence_transformers/multi_vector_encoder/modules/token_pooling.py:115
↓ 21 callers
Method
model
(self)
sentence_transformers/cross_encoder/model.py:430
↓ 20 callers
Function
_make_pil_image
Create a small dummy PIL image.
tests/base/test_model_card.py:62
↓ 20 callers
Function
merge_feature_batches
Pad and concatenate homogeneous per-column feature batches into one flat batch. Running ``N`` columns through the model one by one means ``N`` fo
sentence_transformers/base/losses/merged_forward.py:53
↓ 19 callers
Function
assert_trained
Guard against a vacuous comparison: an empty or all-zero gradient dict passes any assert_close loop.
tests/sentence_transformer/losses/utils.py:44
↓ 19 callers
Method
encode_document
(self, texts, **kwargs)
tests/util/test_hard_negatives.py:1680
↓ 19 callers
Method
save_config
Save the configuration of the module to a JSON file. Args: output_path (str): The path to the directory where the config
sentence_transformers/base/modules/module.py:418
↓ 17 callers
Function
_normed
(shape: tuple[int, int])
tests/multi_vector_encoder/test_token_pooling.py:18
↓ 17 callers
Function
_patch_video_decoder
Patch ``model_card.VideoDecoder`` so ``_MockVideoDecoder`` instances pass ``isinstance`` checks.
tests/base/test_model_card.py:1049
↓ 17 callers
Method
batch_to_message
Convert a batch of modality-specific inputs into the unified message format. Args: modality: The modality key (string) or tuple o
sentence_transformers/base/modality.py:581
↓ 17 callers
Function
generate_model_card
(model: BaseModel)
sentence_transformers/base/model_card.py:2029
↓ 16 callers
Function
quantize_embeddings
Quantizes embeddings to a lower precision. This can be used to reduce the memory footprint and increase the speed of similarity search. The s
sentence_transformers/util/quantization.py:390
↓ 16 callers
Method
similarity_fct
(self)
sentence_transformers/sentence_transformer/losses/cached_multiple_negatives_ranking.py:221
↓ 15 callers
Function
_create_minibatch
Create a mini-batch from sentence features, handling padded, flattened, and VLM inputs. With padded inputs, this slices along the batch dimension
sentence_transformers/base/losses/gradcache.py:84
↓ 15 callers
Function
_minibatch_ranges
Compute the ``(begin, end)`` sequence ranges that split a batch into mini-batches. If ``mini_batch_num_tokens`` is None, every range spans ``mini
sentence_transformers/base/losses/gradcache.py:210
↓ 15 callers
Method
compute_dataset_metrics
Given a dataset, compute the following: * Dataset Size * Dataset Columns * Dataset Stats - Strings: min,
sentence_transformers/base/model_card.py:1156
↓ 15 callers
Function
embed_columns
Embed each input column, sharing one merged forward pass across columns when possible. Returns one ``sentence_embedding`` tensor per column. When
sentence_transformers/base/losses/merged_forward.py:171
↓ 15 callers
Method
encode_query
( self, inputs: TextInput, prompt_name: str | None = ..., prompt: str | None =
sentence_transformers/sparse_encoder/model.py:207
↓ 15 callers
Method
is_singular_input
Check if the input represents a single example or a batch of examples. A list is the batch axis, with one exception: a conversation
sentence_transformers/base/model.py:654
↓ 15 callers
Function
load_file_path
Loads a file from a local or remote location. Args: model_name_or_path (str): The model name or path. filename (str): The na
sentence_transformers/util/file_io.py:73
↓ 15 callers
Method
preprocess
Preprocesses the inputs for the model. Args: inputs (Sequence[SingleInput | PairInput]): A list of inputs to be preproce
sentence_transformers/base/model.py:587
↓ 15 callers
Method
preprocess
Preprocess inputs into model-ready features. Args: inputs: List of inputs. Can contain strings, dicts with modality keys, PIL ima
sentence_transformers/base/modules/transformer.py:1229
↓ 15 callers
Method
save_usage_example_assets
Save non-text items in :attr:`usage_examples` as files in an ``assets/`` subdirectory. After saving, :attr:`usage_examples_display` is set wi
sentence_transformers/base/model_card.py:716
↓ 15 callers
Method
start_multi_process_pool
Starts a multi-process pool to infer with several independent processes. This method is recommended if you want to predict on multip
sentence_transformers/base/model.py:1537
↓ 15 callers
Method
stop_multi_process_pool
Stops all processes started with start_multi_process_pool. Args: pool (Dict[str, object]): A dictionary containing the i
sentence_transformers/base/model.py:1588
↓ 14 callers
Function
column_merging_disabled
Force :func:`merge_feature_batches` to refuse for the duration of the block. For wrapper losses that call an inner loss several times with the *s
sentence_transformers/base/losses/merged_forward.py:37
↓ 14 callers
Method
device
Get torch.device from module, assuming that the whole module has one device. In case there are no PyTorch parameters, fall back to CP
sentence_transformers/base/model.py:1510
↓ 14 callers
Method
encode_query
(self, sentences, **kwargs)
tests/sentence_transformer/evaluation/test_information_retrieval_evaluator.py:52
↓ 14 callers
Function
gradients
(model: BaseModel)
tests/sentence_transformer/losses/utils.py:40
↓ 14 callers
Function
is_image_url_or_path
Check if a string is an image URL, file path, or data URI.
sentence_transformers/base/modality.py:76
↓ 14 callers
Function
is_training_available
Returns True if we have the required dependencies for training Sentence Transformers models, i.e. Huggingface datasets and Huggingface accele
sentence_transformers/util/environment.py:114
↓ 14 callers
Method
similarity
Compute the similarity between two collections of embeddings. The output will be a matrix with the similarity scores between all embe
sentence_transformers/sparse_encoder/model.py:853
↓ 14 callers
Function
xtr_scores
XTR (eXtendable Token Retrieval) contrastive scoring with global top-k token retrieval. For each query token, the top-k matches are selected glob
sentence_transformers/multi_vector_encoder/scoring/xtr.py:10
↓ 13 callers
Function
_convert_to_tensor
Converts the input `a` to a PyTorch tensor if it is not already a tensor. Lists are stacked into one tensor: a list of sparse tensors keeps i
sentence_transformers/util/tensor.py:27
↓ 13 callers
Function
_is_non_text_pair
Check if a sample is a non-text pair (2-element tuple/list with at least one non-string element). Text pairs ``(str, str)`` are handled natively
sentence_transformers/base/modality.py:111
↓ 13 callers
Method
_set_multimodal_usage_examples
Override :attr:`usage_examples` with multimodal inputs when the model supports non-text modalities. Respects the distinction between models t
sentence_transformers/base/model_card.py:614
↓ 13 callers
Function
check_version_requirements
Verifies that the installed packages satisfy the version requirements declared by a model. Requirements that can't be interpreted (e.g. an i
sentence_transformers/util/environment.py:142
↓ 13 callers
Method
get_backend
Return the backend used for inference, which can be one of "torch", "onnx", or "openvino". Returns: str: The backend used for inf
sentence_transformers/base/model.py:371
↓ 13 callers
Method
pair_roles_failure
Why the chat template cannot carry a ``query``/``document`` pair, or None when it can. Decided by rendering probe pairs and diffing the outpu
sentence_transformers/base/modality.py:461
↓ 13 callers
Function
similarity_fct_name
Readable config-dict rendering of a loss's scoring callable: objects exposing ``get_config_dict`` (e.g. configured metric classes) and :func:`func
sentence_transformers/util/misc.py:48
↓ 12 callers
Function
_disable_dropout
(model: CrossEncoder)
tests/cross_encoder/losses/test_cached_multiple_negatives_ranking.py:27
↓ 12 callers
Method
_format_example_value
Format a dataset example value for the model card examples table.
sentence_transformers/base/model_card.py:1814
↓ 12 callers
Function
_make_data
(**kwargs)
tests/multi_vector_encoder/test_model_card.py:55
↓ 12 callers
Function
_make_feature
(t_tokens: int, batch: int, dim: int, seed: int)
tests/multi_vector_encoder/losses/test_misc.py:39
↓ 12 callers
Method
encode_document
( self, inputs: TextInput, prompt_name: str | None = ..., prompt: str | None =
sentence_transformers/sparse_encoder/model.py:354
↓ 12 callers
Method
is_text_only_messages
Check whether all messages in a batch contain only text content. Works with both flat format (``{"content": "hello"}``) and structured format
sentence_transformers/base/modality.py:616
↓ 12 callers
Method
pair_to_messages
Convert a pair of inputs to query/document message format. Each element of the pair is wrapped in a message with role ``"query"`` (first elem
sentence_transformers/base/modality.py:514
↓ 12 callers
Function
semantic_search
This function performs by default a cosine similarity search between a list of query embeddings and a list of corpus embeddings. It can be u
sentence_transformers/util/retrieval.py:167
↓ 12 callers
Method
tokenizer
Property to get the tokenizer that is used by this model
sentence_transformers/base/model.py:1628
↓ 11 callers
Method
get_embedding_dimension
Returns the number of dimensions in the output of :meth:`SentenceTransformer.encode`. Returns: Optional[int]: The number
sentence_transformers/sentence_transformer/model.py:1237
↓ 11 callers
Function
infer_batch_modality
Infer the modality of a batch of input samples. If all samples share the same modality, that modality is returned. If the batch contains mixe
sentence_transformers/base/modality.py:834
↓ 11 callers
Function
is_video_url_or_path
Check if a string is a video URL or file path.
sentence_transformers/base/modality.py:83
↓ 11 callers
Method
store_metrics_in_model_card_data
(self, *args, **kwargs)
sentence_transformers/sentence_transformer/evaluation/nano_beir.py:523
↓ 10 callers
Function
_columns
( model: SentenceTransformer, columns: Sequence[Sequence[str]], prompt: str | None = None )
tests/sentence_transformer/losses/test_merged_forward.py:42
↓ 10 callers
Function
community_detection
Function for Fast Community Detection. Finds in the embeddings all communities, i.e. embeddings that are close (closer than threshold).
sentence_transformers/util/retrieval.py:258
↓ 10 callers
Method
encode_query
(self, texts, **kwargs)
tests/util/test_hard_negatives.py:1677
↓ 10 callers
Method
for_query_document
Creates a Router model specifically for query and document modules, allowing convenient usage via `model.encode_query` and `model.enc
sentence_transformers/base/modules/router.py:430
↓ 10 callers
Method
forward
(self, task=None, modality=None, **kwargs)
tests/base/modules/test_transformer.py:880
↓ 10 callers
Method
forward
(self, features)
tests/base/modules/test_router.py:35
↓ 10 callers
Function
get_n_patches
Infer the ``(n_patches_x, n_patches_y)`` = ``(n_cols, n_rows)`` image-patch grid that ``model``'s processor produces for an image of ``image_size`
sentence_transformers/multi_vector_encoder/interpretability.py:91
↓ 10 callers
Function
http_get
Download a URL to a local file with a progress bar. The content is streamed in chunks and first written to a temporary ``"<path>_part"`` file
sentence_transformers/util/file_io.py:205
↓ 10 callers
Function
import_module_class
Resolve a module class reference to a class object. For class refs in the ``sentence_transformers.*`` namespace, this imports directly via
sentence_transformers/util/misc.py:158
↓ 10 callers
Function
load_dir_path
Loads the subfolder path for a given model name or path. Args: model_name_or_path (str): The name or path of the model. subf
sentence_transformers/util/file_io.py:133
↓ 10 callers
Method
load_torch_weights
A utility function to load the PyTorch weights of a model from a checkpoint. The checkpoint can be either a local directory or a mode
sentence_transformers/base/modules/module.py:311
↓ 10 callers
Method
sparsity
Calculate sparsity statistics for the given embeddings, including the mean number of active (non-zero) dimensions and the mean sparsi
sentence_transformers/sparse_encoder/model.py:1229
↓ 9 callers
Function
_model_stub
Duck-typed stand-in for ``MultiVectorEncoder``: ``get_n_patches`` only reads ``model.processor``.
tests/multi_vector_encoder/test_interpretability.py:186
next →
1–100 of 3,759, ranked by callers