Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/huggingface/sentence-transformers
/ functions
Functions
4,575 in github.com/huggingface/sentence-transformers
⨍
Functions
4,575
◇
Types & classes
516
↳
Endpoints
81
Function
test_mask_keep_only_token_ids_none_is_noop
Default ``keep_only_token_ids=None`` means no allowlist: matches pre-P1.2 behavior exactly.
tests/multi_vector_encoder/test_model.py:363
Function
test_mask_keep_only_token_ids_restricts_document_mask
``keep_only_token_ids`` (P1.2 / colpali-engine ``mask_non_image_embeddings``) restricts the document attention_mask to the allowlisted IDs only. T
tests/multi_vector_encoder/test_model.py:345
Function
test_mask_repads_flash_attention_flattened_features
Under FA2 unpadding the encoder hands the mask a flat ``(1, sum_lens, ...)`` batch described by ``cu_seq_lens_q`` and no ``attention_mask``. The m
tests/multi_vector_encoder/test_model.py:393
Function
test_mask_skiplist_all_unresolvable_yields_none
When every skiplist word resolves to ``unk_token_id`` (none are real vocab tokens), the resolved tensor is ``None`` rather than empty, so ``forwar
tests/multi_vector_encoder/test_model.py:461
Function
test_mask_skiplist_drops_unk_resolving_words
``resolve_with_tokenizer`` drops skiplist words that ``convert_tokens_to_ids`` resolves to ``unk_token_id``. Otherwise every real ``[UNK]`` docume
tests/multi_vector_encoder/test_model.py:422
Function
test_mask_skiplist_keeps_explicit_unk_token
A user who explicitly puts the tokenizer's UNK token in the skiplist gets what they asked for (the unk_token_id stays in ``_skiplist_ids``). The d
tests/multi_vector_encoder/test_model.py:444
Function
test_mask_skiplist_tasks_gate
``skiplist_tasks`` is an allowlist (default documents only, no task counts as document): a custom task is no longer skiplisted unless listed, and
tests/multi_vector_encoder/test_model.py:371
Function
test_mask_skiplist_tasks_round_trips_through_config
(tmp_path)
tests/multi_vector_encoder/test_model.py:415
Method
test_matching_sampling_rates_do_not_raise
(self)
tests/base/test_modality.py:724
Function
test_matching_torch_module_settings
(model, activation)
tests/test_merging.py:339
Function
test_matryoshka_dims_can_exceed_token_embedding_dimension
( architecture: str, truncate_dim: int | None, loss_cls )
tests/sentence_transformer/losses/test_matryoshka.py:227
Function
test_matryoshka_does_not_truncate_kd_labels
()
tests/multi_vector_encoder/losses/test_matryoshka.py:123
Function
test_matryoshka_equals_manual_sum_of_truncated_losses
(build_inner, use_generator: bool)
tests/multi_vector_encoder/losses/test_matryoshka.py:89
Function
test_matryoshka_on_a_real_model
(mve_bert_tiny_model, build_inner, truncate_dim: int | None)
tests/multi_vector_encoder/losses/test_matryoshka.py:201
Function
test_matryoshka_outside_token_pooling_raises
(build_inner)
tests/multi_vector_encoder/losses/test_token_pooling.py:237
Function
test_matryoshka_replays_merged_forwards_from_cache
MatryoshkaLoss caches model outputs by call order and replays them for the smaller dimensions. With merging, each dimension pass makes fewer calls
tests/sentence_transformer/losses/test_merged_forward.py:137
Function
test_max_active_dims_invalid
(max_active_dims: int | float | str, from_config: bool, tmp_path)
tests/sparse_encoder/test_model.py:391
Function
test_max_active_dims_save_load
(model_fixture: str, override: int | None, request: pytest.FixtureRequest, tmp_path)
tests/sparse_encoder/test_model.py:356
Function
test_max_active_dims_set_init
(splade_bert_tiny_model: SparseEncoder, csr_bert_tiny_model: SparseEncoder, tmp_path)
tests/sparse_encoder/test_model.py:332
Function
test_max_length
( reranker_bert_tiny_model: CrossEncoder, tmp_path: Path, tokenizer_max_length: int, expected_max_length:
tests/cross_encoder/test_model.py:900
Function
test_max_length_override_loses_to_expansion_wins_elsewhere
The trainer's max_length cap (forwarded by the data collator) must lose to the expansion width: expansion queries always tokenize to exactly the e
tests/multi_vector_encoder/test_model.py:1864
Method
test_max_list_length_truncates_tensor_labels_in_step
(self, queries: Dataset, documents: Dataset)
tests/util/test_dataset.py:420
Method
test_max_seq_length_capped_by_max_position_embeddings
(self, bert_tiny_transformer)
tests/base/modules/test_transformer.py:460
Method
test_max_seq_length_fallback_to_config
When tokenizer is None, max_seq_length should fall back to config.max_position_embeddings.
tests/base/modules/test_transformer.py:465
Method
test_max_seq_length_from_tokenizer
(self, bert_tiny_transformer)
tests/base/modules/test_transformer.py:443
Method
test_max_seq_length_init_kwarg
(self)
tests/base/modules/test_transformer.py:456
Method
test_max_seq_length_save_and_load
A custom max_seq_length should be preserved after save/load.
tests/base/modules/test_transformer.py:1894
Method
test_max_seq_length_setter
(self, bert_tiny_transformer)
tests/base/modules/test_transformer.py:448
Method
test_max_seq_length_setter_noop_without_tokenizer
Setting max_seq_length when tokenizer is None should be a no-op.
tests/base/modules/test_transformer.py:473
Method
test_max_seq_length_truncation
Inputs longer than max_seq_length should be truncated during preprocessing.
tests/base/modules/test_transformer.py:479
Method
test_max_tokens_must_exceed_protected_tokens
(self)
tests/multi_vector_encoder/modules/test_token_pooling.py:560
Function
test_maxsim_basic_shapes
()
tests/multi_vector_encoder/test_model.py:1724
Function
test_maxsim_budget_bounds_the_live_chunk_elements
The budget bounds the query and document padding plus the 4D score intermediate. A small query side against a wide embedding dim, where the padde
tests/util/test_similarity.py:1095
Function
test_maxsim_chunking_preserves_shared_masks
( chunk_elements: int, pairwise: bool, length_normalize: bool, mask_dtype: torch.dtype, mask_name: str )
tests/util/test_similarity.py:1421
Function
test_maxsim_device_bounds_residency_by_element_budget
With a device override, only one element-budget chunk of documents occupies the device at a time, so a corpus far larger than the budget never has
tests/util/test_similarity.py:1282
Function
test_maxsim_device_is_a_pure_compute_knob
maxsim's device override moves the arithmetic only: scores still return on the documents' device, identically for the plain and length-normalized
tests/util/test_similarity.py:1259
Function
test_maxsim_document_chunking_matches_unchunked
``maxsim(chunk_elements=N)`` chunks the document-axis einsum to bound the 4D scoring intermediate, but must return the same scores as the single-c
tests/multi_vector_encoder/test_model.py:1751
Function
test_maxsim_document_chunking_matches_unchunked
The chunked path masks and sums per chunk (bounding peak memory), which must be numerically identical to the single-einsum path, including with qu
tests/util/test_similarity.py:596
Function
test_maxsim_document_mask_excludes_padding_tokens
A masked-out document token must not participate in the max, even with the highest similarity.
tests/util/test_similarity.py:323
Function
test_maxsim_element_budget_matches_single_chunk
A tiny element budget (many chunks, outlier isolated) must score identically to a huge budget (one chunk), for ragged lists, with a caller mask, a
tests/util/test_similarity.py:741
Function
test_maxsim_empty_document_set_returns_empty_scores
An empty document or query set, as an empty list or a 0-batch tensor, scores as an empty (num_queries, num_documents) matrix instead of crashing i
tests/util/test_similarity.py:935
Function
test_maxsim_fully_masked_document_scores_sentinel
A document without any unmasked token scores the -1e9 sentinel instead of overflowing to -inf, other documents stay unaffected, and a one-shot war
tests/util/test_similarity.py:811
Function
test_maxsim_generated_masks_support_boolean_mask_providers
(loader, monkeypatch, embeddings, padded, pairwise)
tests/test_kernels.py:149
Function
test_maxsim_half_precision_accumulates_in_float32
Summing the query-token maxima in bf16 collapses documents onto the coarse bf16 grid: the accumulation runs in float32 and the scores stay float32
tests/util/test_similarity.py:771
Function
test_maxsim_integer_embeddings_upcast
Quantized integer embeddings (encode(precision="int8")) are upcast to float so einsum and the finfo-based masking work, and the scores match float
tests/util/test_similarity.py:693
Function
test_maxsim_isolation_masks_and_chunking
(loader, embeddings, normalize)
tests/test_kernels.py:124
Function
test_maxsim_length_normalize_divides_by_real_query_tokens
length_normalize (MeanMaxSim) divides each score by the count of real query tokens: item lengths on the list path, mask sums on the padded path, i
tests/util/test_similarity.py:1194
Function
test_maxsim_list_documents_chunking_pads_per_chunk
Ragged document lists are padded per chunk, so one long outlier document no longer sizes the padding of every chunk (the multi-GB-allocation failu
tests/util/test_similarity.py:614
Function
test_maxsim_list_matches_masked_padded_tensor
The ragged-list path auto-derives a length mask. It must match an explicitly padded + masked 3D tensor.
tests/util/test_similarity.py:308
Function
test_maxsim_mismatched_mask_width_raises
A caller mask not matching the padded width is a construction bug and raises up front, in both chunk settings and both functions (the chunk loops
tests/util/test_similarity.py:957
Function
test_maxsim_moves_masks_onto_the_scoring_device
A caller mask left on the cpu alongside cuda embeddings is moved onto the scoring device instead of crashing inside the masked_fill and einsum ker
tests/util/test_similarity.py:1172
Function
test_maxsim_moves_queries_to_the_documents_device
Mixed-device inputs reconcile onto the documents' device instead of raising, on every maxsim path (unchunked, chunked, list documents) and both ma
tests/util/test_similarity.py:1016
Function
test_maxsim_narrow_mask_raises_value_error
A mask narrower than the padded width raises ValueError up front in both paths.
tests/util/test_similarity.py:992
Function
test_maxsim_negative_similarities_survive_padding
A padding token (from a shorter document) must not inflate a negative MaxSim score to 0.
tests/util/test_similarity.py:337
Function
test_maxsim_numpy_documents_follow_the_queries_device
numpy documents carry no device, so scoring stays on the queries' device rather than silently dragging a gpu workload onto the cpu.
tests/util/test_similarity.py:1150
Function
test_maxsim_numpy_queries_score_against_tensor_documents_on_cpu
The cpu mix of numpy queries and tensor documents keeps working and matches all-tensor scoring.
tests/util/test_similarity.py:1005
Function
test_maxsim_padded_tensor_without_mask_excludes_zero_rows
Without a mask, a pre-padded 3D tensor had its zero-pad rows counted as real tokens whose dot product 0 could win the max over negative similariti
tests/multi_vector_encoder/test_model.py:1733
Function
test_maxsim_pairwise_budget_counts_the_padded_queries
Long queries against short documents: the padded query tensor grows with the chunk size, so leaving it out of the budget overshoots several-fold (
tests/util/test_similarity.py:1126
Function
test_maxsim_pairwise_derives_padding_mask_from_zero_rows
Pre-padded 3D input without a mask must have its zero rows excluded from the max, both in the per-pair loop (mixed list + 3D, whose 2D slices keep
tests/util/test_similarity.py:676
Function
test_maxsim_pairwise_empty_document_scores_sentinel
Empty pair entries (zero-width, all-masked, tensor mask row) score the sentinel on both pairwise paths, other pairs stay finite, and it warns.
tests/util/test_similarity.py:838
Function
test_maxsim_pairwise_empty_inputs_return_empty_scores
Zero pairs, as empty lists or 0-batch tensors on both sides, score as shape (0,) instead of crashing in torch.stack.
tests/util/test_similarity.py:948
Function
test_maxsim_pairwise_half_precision_accumulates_in_float32
Both maxsim_pairwise paths (tensor and per-pair list) accumulate in float32.
tests/util/test_similarity.py:795
Function
test_maxsim_pairwise_length_mismatch_raises
Unequal query and document counts raise instead of scoring min(len(a), len(b)) pairs: the chunk ranges come from the document side, so a longer qu
tests/util/test_similarity.py:1083
Function
test_maxsim_pairwise_matches_maxsim_diagonal
maxsim_pairwise(q, d) must equal the diagonal of the full maxsim(q, d) matrix, even with padding.
tests/util/test_similarity.py:359
Function
test_maxsim_pairwise_never_pads_the_batch_to_the_global_width
A long outlier pair sizes only its own chunk, so peak memory stays near the budget instead of padding every pair to the outlier's width (a ~800x r
tests/util/test_similarity.py:1056
Function
test_maxsim_pairwise_scores_are_independent_of_chunk_elements
Chunking the pair batch is a memory strategy only: every budget scores identically, including the one-pair-per-chunk floor and a ragged batch with
tests/util/test_similarity.py:1041
Function
test_maxsim_pairwise_singular_inputs_score_as_batch_of_one
maxsim_pairwise must auto-batch singular inputs just like maxsim, so a user who reaches for similarity_pairwise on singular encode outputs does no
tests/util/test_similarity.py:656
Function
test_maxsim_per_item_mask_lists_match_padded_masks
Per-item 1D mask lists are padded to the batch and score identically to the equivalent padded 2D mask, in both scoring functions.
tests/util/test_similarity.py:975
Function
test_maxsim_query_chunking_bounds_padding_and_scores
( monkeypatch: pytest.MonkeyPatch, input_type: str, use_masks: bool, length_normalize: bool,
tests/util/test_similarity.py:1328
Function
test_maxsim_query_chunking_preserves_gradients
(device: str)
tests/util/test_similarity.py:1391
Function
test_maxsim_query_mask_excludes_query_tokens
MaxSim sums over query tokens. Masking a query token drops its contribution from the sum.
tests/util/test_similarity.py:350
Function
test_maxsim_ragged_and_empty_inputs
(loader, embeddings)
tests/test_kernels.py:138
Function
test_maxsim_ragged_list_entry_types
Ragged list entries may be plain nested lists, not only arrays or tensors. Measuring their widths for the element budget must not assume a .shape
tests/util/test_similarity.py:926
Function
test_maxsim_ragged_matrix_hand_computed
MaxSim of ragged (variable-length) inputs, with a hand-computed (2, 2) score matrix.
tests/util/test_similarity.py:290
Function
test_maxsim_singular_inputs_score_as_batch_of_one
Mirrors the dense family's similarity, where a singular (unbatched) embedding auto-batches: a bare 2D (tokens, dim) input, e.g. from a singular en
tests/util/test_similarity.py:640
Function
test_maxsim_takes_no_data_dependent_branch
The unconditional sentinel fill keeps maxsim fullgraph-capturable (and free of per-call device syncs), which compiling the scoring hot path relies
tests/util/test_similarity.py:905
Function
test_mean_colbert_scores_divide_by_query_tokens
The mean_colbert_* callables are the length-normalized form of their colbert_* counterparts, so a loss can name MeanMaxSim scoring instead of bind
tests/multi_vector_encoder/losses/test_misc.py:898
Function
test_mean_maxsim_denominator_follows_the_scoring_mask
MeanMaxSim divides by whatever the scoring counted as real. A genuinely zero query row (token pooling can emit one) is padding to the mask a bare
tests/util/test_similarity.py:1237
Function
test_mean_maxsim_matches_length_normalized_maxsim
The named MeanMaxSim functions are the length_normalize=True form of their MaxSim counterparts (with length_normalize=False recovering the plain f
tests/util/test_similarity.py:1214
Method
test_media_collection_matches_single_input_content
(self, modality, container, with_text)
tests/base/test_modality.py:1348
Method
test_media_collection_preserves_sample_boundaries
(self, modality, container, with_text)
tests/base/test_modality.py:1104
Function
test_mega_batch_margin_adaptive_layer_warns
AdaptiveLayerLoss calls its base loss once per layer, and the mini-batched loss defers its backward pass to a hook, so the combination is unsuppor
tests/sentence_transformer/losses/test_mega_batch_margin.py:271
Function
test_mega_batch_margin_matryoshka
MatryoshkaLoss must route the mini-batched loss through its ``CachedLossDecorator``. The mini-batched loss back-propagates from a hook, which fir
tests/sentence_transformer/losses/test_mega_batch_margin.py:241
Function
test_mega_batch_margin_mini_batched_matches_non_mini_batched
``mini_batch_size`` only bounds memory, so it must change neither the loss nor the gradient. The mini-batched version embeds each mini-batch with
tests/sentence_transformer/losses/test_mega_batch_margin.py:45
Function
test_mega_batch_margin_preserves_training_mode
The loss must not change the mode it found the model in. It used to call ``self.model.train()`` unconditionally, which left the model in training
tests/sentence_transformer/losses/test_mega_batch_margin.py:168
Function
test_mega_batch_margin_rejects_static_embedding
StaticEmbedding features are an EmbeddingBag (``input_ids``, ``offsets``) with no batch dimension to slice along, so the mini-batched version must
tests/sentence_transformer/losses/test_mega_batch_margin.py:288
Function
test_mega_batch_margin_rejects_static_embedding_behind_a_router
A Router keeps its input modules one level down, so a guard that only inspects ``model[0]`` waves a StaticEmbedding straight through, and ``_get_b
tests/sentence_transformer/losses/test_mega_batch_margin.py:297
Function
test_mega_batch_margin_replays_dropout_in_the_backward_pass
The backward pass must re-embed exactly what the forward pass embedded, dropout included. The cached gradients are taken wrt. the embeddings of t
tests/sentence_transformer/losses/test_mega_batch_margin.py:75
Function
test_mega_batch_margin_requires_exactly_two_columns
The loss mines its negatives from the other positives in the batch, so it takes exactly 2 columns. Rewriting the two forward passes dropped the `
tests/sentence_transformer/losses/test_mega_batch_margin.py:218
Function
test_mega_batch_margin_scales_with_the_outer_backward
Every mini-batch must be scaled by whatever the outer backward pass passes in. The trainer divides the loss by ``gradient_accumulation_steps`` an
tests/sentence_transformer/losses/test_mega_batch_margin.py:184
Function
test_mega_batch_margin_token_budget_matches_non_mini_batched
Packing the embedding passes by token count must not change the loss or the gradient.
tests/sentence_transformer/losses/test_mega_batch_margin.py:311
Function
test_mega_batch_margin_two_forwards_before_one_backward
Each forward pass must hand its own cached gradients to its own backward hook. The cache used to live on the loss module, so a second forward pas
tests/sentence_transformer/losses/test_mega_batch_margin.py:114
Function
test_mega_batch_margin_under_no_grad
The loss must be computable under ``torch.no_grad``, as the trainer does when computing the eval loss. The in-loop ``backward()`` used to fire re
tests/sentence_transformer/losses/test_mega_batch_margin.py:147
Function
test_merge_carries_a_shared_prompt_and_refuses_per_column_prompts
Pooling with ``include_prompt`` disabled applies one prompt length to the whole batch, so only columns sharing the prompt length may share a forwa
tests/sentence_transformer/losses/test_merged_forward.py:216
Function
test_merge_refuses_flattened_features
FA2-flattened columns pack their rows into one sequence described by ``cu_seq_lens_q``. Concatenating those offsets end to end describes nothing,
tests/multi_vector_encoder/losses/test_misc.py:747
Function
test_merge_refuses_flattened_token_streams
StaticEmbedding preprocesses to a flattened 1D token stream with per-row offsets. With one token per row every tensor is coincidentally batch-leng
tests/sentence_transformer/losses/test_merged_forward.py:310
Function
test_merge_refuses_inside_column_merging_disabled
Wrapper losses that call an inner loss repeatedly with the same feature dicts (AdaptiveLayerLoss) pass state through those dicts, which fresh merg
tests/multi_vector_encoder/losses/test_misc.py:726
Function
test_merge_refuses_mixed_modalities
Same tensor keys isolate the metadata guard: real image and text columns usually differ in their tensor keys as well.
tests/sentence_transformer/losses/test_merged_forward.py:303
Function
test_merge_refuses_mixed_router_tasks_and_carries_a_shared_task
Columns stamped with different router tasks route through different modules, which is a genuinely different forward pass per column.
tests/sentence_transformer/losses/test_merged_forward.py:291
Function
test_merge_refuses_non_tensor_values_that_do_not_compare
A custom preprocess_fn can put values in the batch whose ``!=`` returns an array rather than a bool. Those cannot be shown equal across columns, s
tests/multi_vector_encoder/losses/test_misc.py:736
← previous
next →
3,201–3,300 of 4,575, ranked by callers