Download Latest Version v4.1.0 - ONNX and OpenVINO backends offering 2-3x speedups_ improved hard negatives mining source code.tar.gz (12.9 MB)
Email in envelope

Get an email when there's a new version of SentenceTransformers

Home / v3.4.0
Name Modified Size InfoDownloads / Week
Parent folder
README.md 2025-01-23 12.0 kB
v3.4.0 - Resolved memory leak when deleting a model _ trainer_ add Matryoshka _ Cached loss compatibility_ small features _ bug fixes source code.tar.gz 2025-01-23 12.7 MB
v3.4.0 - Resolved memory leak when deleting a model _ trainer_ add Matryoshka _ Cached loss compatibility_ small features _ bug fixes source code.zip 2025-01-23 13.0 MB
Totals: 3 Items   25.7 MB 0

This release resolves a memory leak when deleting a model & trainer, adds compatibility between the Cached... losses and the Matryoshka loss modifier, resolves numerous bugs, and adds several small features.

Install this version with

:::bash
# Training + Inference
pip install sentence-transformers[train]==3.4.0

# Inference only, use one of:
pip install sentence-transformers==3.4.0
pip install sentence-transformers[onnx-gpu]==3.4.0
pip install sentence-transformers[onnx]==3.4.0
pip install sentence-transformers[openvino]==3.4.0

Matryoshka & Cached loss compatibility (#3068, [#3107])

It is now possible to combine the strong Cached losses (CachedMultipleNegativesRankingLoss, CachedGISTEmbedLoss, CachedMultipleNegativesSymmetricRankingLoss) with the Matryoshka loss modifier:

:::python
from sentence_transformers import SentenceTransformer, SentenceTransformerTrainer, losses
from datasets import Dataset

model = SentenceTransformer("microsoft/mpnet-base")
train_dataset = Dataset.from_dict({
    "anchor": ["It's nice weather outside today.", "He drove to work."],
    "positive": ["It's so sunny.", "He took the car to the office."],
})
loss = losses.CachedMultipleNegativesRankingLoss(model, mini_batch_size=16)
loss = losses.MatryoshkaLoss(model, loss, [768, 512, 256, 128, 64])

trainer = SentenceTransformerTrainer(
    model=model,
    train_dataset=train_dataset,
    loss=loss,
)
trainer.train()

See for example tomaarsen/mpnet-base-gooaq-cmnrl-mrl which was trained with CachedMultipleNegativesRankingLoss (CMNRL) with the Matryoshka loss modifier (MRL).

Resolve memory leak when Model and Trainer are reinitialized (#3144)

Due to a circular dependency in the SentenceTransformerTrainer -> SentenceTransformer -> SentenceTransformerModelCardData -> SentenceTransformerTrainer, deleting the trainer and model still doesn't clear them up via garbage disposal. I've moved a lot of components around, and now SentenceTransformerModelCardData does not need to store the SentenceTransformerTrainer, breaking the cycle.

We ran the seed optimization script (which frequently creates and deletes models and trainers): * Before: Approximate highest recorded VRAM: 16332MiB / 24576MiB * After: Approximate highest recorded VRAM: 8222MiB / 24576MiB

Small Features

  • Add Matthews Correlation Coefficient to the BinaryClassificationEvaluator in [#3051].
  • Add a triplet margin parameter to the TripletEvaluator in [#2862].
  • Put dataset information in the automatically generated model card in "expanding sections" blocks if there are many datasets in [#3088].
  • Add multi-GPU (and CPU multi-process) support for mine_hard_negatives in [#2967].

Notable Bug Fixes

  • Subsequent batches were identical when using the no_duplicates Batch Sampler (#3069). This has been resolved in [#3073]
  • The old-style model.fit() training with write_csv on an evaluator would crash (#3062). This has been resolved in [#3066].
  • The output types of some evaluators were np.float instead of float (#3075). This has been resolved in [#3076] and [#3096].
  • It was not possible to specify a revision or cache_dir when loading a PEFT Adapter model (#3061). This has been resolved in [#3079] and [#3174].
  • The CrossEncoder was lazily placed on the incorrect device, did not respond to model.to (#3078). This has been resolved in [#3104].
  • If a model used a custom module with custom kwargs, those kwargs keys were not saved in modules.json correctly, e.g. relevant for jina-embeddings-v3 (#3111). This has been resolved in [#3112].
  • HfArgumentParser(SentenceTransformerTrainingArguments) would crash due to prompts typing (#3090). This has been resolved in [#3178].

Example Updates

  • Update the quantization script in [#3070].
  • Update the seed optimization script in [#3092].
  • Update the TSDAE scripts in [#3137].
  • Add PEFT Adapter script in [#3180].

Documentation Updates

All Changes

New Contributors

An explicit thanks to @JINO-ROHIT who has made a large amount of contributions in this release.

Full Changelog: https://github.com/UKPLab/sentence-transformers/compare/v3.3.1...v3.4.0

Source: README.md, updated 2025-01-23