Change8

v5.4.1

Breaking Changes
📦 sentence-transformersView on GitHub →
1 breaking1 features🐛 2 fixes🔧 4 symbols

Summary

This patch release enhances input handling for numpy string/object arrays in `encode()` and `predict()` and introduces a critical security fix by restricting activation function loading in the `Dense` module.

⚠️ Breaking Changes

  • Loading of activation functions in the `Dense` module is now restricted. Previously, any importable Python callable specified in a model's config could be loaded. Now, only activation functions whose import path starts with `torch.` are loaded by default. To load models with custom (non-torch) activation functions, you must explicitly set `trust_remote_code=True` during model initialization.

Migration Steps

  1. If loading a model that uses a custom (non-torch) activation function in its `Dense` layers, initialize the model with `trust_remote_code=True` (e.g., `SentenceTransformer("model_name", trust_remote_code=True)`).
  2. If relying on the old behavior where `model.encode(df["text"].to_numpy())` was treated as a single input when the numpy array was 1D string/object type, this behavior has changed; it is now treated as a batch of inputs.

✨ New Features

  • The `encode()` and `predict()` methods now correctly handle 1D numpy arrays with string (`U`) or object (`O`) dtypes as batches of inputs, rather than treating them as a single input. For `CrossEncoder`, a 1D numpy string array is still treated as a single pair.

🐛 Bug Fixes

  • Fixed an issue where 1D numpy string/object arrays passed to `encode()` or `predict()` were silently treated as a single input, leading to incorrect output shapes/results.
  • Replaced instances of `evaluation_strategy` with `eval_strategy` in internal code.

Affected Symbols