# What if the Sentence Transformers library raises warnings or deprecation messages — how should I update my code or environment to fix those?

Source: https://zilliz.com/ai-faq/what-if-the-sentence-transformers-library-raises-warnings-or-deprecation-messages-how-should-i-update-my-code-or-environment-to-fix-those
Author: zilliz

When the Sentence Transformers library raises warnings or deprecation messages, the first step is to identify the specific cause. Warnings often include details about deprecated parameters, outdated dependencies, or changes in function behavior. For example, a common warning might indicate that a method like `encode()` now expects different arguments, or that a model loading syntax (e.g., `from_pretrained`) has been updated. Start by reading the warning message carefully—it usually points to the exact line of code and the deprecated feature. Cross-reference this with the library’s [documentation](https://www.sbert.net/) or [release notes](https://github.com/UKPLab/sentence-transformers/releases) to confirm the recommended replacement.

Next, update your code to align with the library’s current API. For instance, if a warning mentions that `model.save(path)` is deprecated in favor of `save_to_hub`, modify your model-saving logic accordingly. Similarly, if you’re using older model names (e.g., `bert-base-nli-mean-tokens`), replace them with newer alternatives (e.g., `all-mpnet-base-v2`). Dependency-related warnings (e.g., PyTorch or Transformers version mismatches) often require updating packages via `pip install --upgrade transformers torch`. If the warning stems from internal library code (e.g., `sentence_transformers.util` modules being refactored), check if the functionality has moved to a new submodule, like `sentence_transformers.models` or `sentence_transformers.losses`.

Finally, adopt proactive measures to avoid future issues. Pin library versions in your `requirements.txt` (e.g., `sentence-transformers==2.2.2`) to ensure compatibility. Use tools like `warnings.filterwarnings("ignore")` sparingly—only for temporary workarounds—and prioritize resolving root causes. If you’re stuck, search the library’s GitHub issues for similar reports or post a question with a minimal reproducible example. For example, a deprecation warning about the `evaluate` function might require switching to a newer evaluation pipeline provided in the `SentenceTransformer` class. Regularly test your code against updated dependencies in a isolated environment to catch issues early.
